Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
(fix) Session: recording into a slot from stop counts in (#173)
Chris Laupama385f58e2c8ab
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e68ed0d8..64b8d22e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -82,6 +82,12 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.Windows and Linux) always starts a new track.### Fixed+- **Session recording counts in** (nota-daw/nota#158): recording into a Session slot (or a+ scene) with the transport stopped now plays the metronome count-in first, with the slot+ blinking "Rec in…", and the take starts when it ends. A note you start during the count-in+ and still hold when the take begins is kept, from the take's start. Stop cancels the+ count-in and leaves the slot empty, with no undo step. With the transport already+ running, nothing changes: the take starts on the launch quantization.- **No more benign IBus errors in the system log on Linux** (nota-daw/nota#36): with theIBus input method (Linux Mint with Cinnamon, some Ubuntu and Fedora setups), the systemlog filled up with `[IME] Error while destroying the context` entries — a harmless D-Busdiff --git a/FEATURES.md b/FEATURES.mdindex cd9dc94e..e9c826e9 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -83,7 +83,7 @@ JUCE module; the engine core is JUCE-free.- **Loop region** (on/off and range; Cmd/Ctrl+L loops the selection). Notes held across theloop seam keep sounding and release tails ring into the next pass; an arpeggiator keeps itspattern going across the seam.-- **Metronome** and **count-in** before recording (notes played on the count-in are recorded).+- **Metronome** and **count-in** before recording, Session slot takes from stop included (notes played on the count-in are recorded).- **Transport shortcuts** (Space play/stop, Enter stop, R/M/A, clip copy-paste, typingnotes, undo/redo) work in detached windows too.diff --git a/src/native/nota.engine/src/Engine.cpp b/src/native/nota.engine/src/Engine.cppindex 01f1578e..77fece71 100644--- a/src/native/nota.engine/src/Engine.cpp+++ b/src/native/nota.engine/src/Engine.cpp@@ -404,6 +404,9 @@ void Engine::transportPlayCountIn() {const int32_t bars = countInBars();if (bars <= 0 || transport_.uiIsPlaying()) { transportPlay(); return; }arrangementActive_.store(true, std::memory_order_relaxed);+ startCountIn(bars);+}+void Engine::startCountIn(int32_t bars) {captureGate_.store(false, std::memory_order_relaxed);// Mirror it now so a poll before the audio thread picks the command up already sees// the count-in (Play pressed again = stop, not a second start).diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.hindex 49beca92..4dac45e6 100644--- a/src/native/nota.engine/src/Engine.h+++ b/src/native/nota.engine/src/Engine.h@@ -1144,6 +1144,7 @@ private:// Click the count-in for numFrames and advance it; true once it has run out.bool renderCountIn(float* out, int32_t numFrames, double spb);void endCountIn(); // audio thread: drop the count-in state and reopen the capture gate+ void launchCountInSlot(); // audio thread: start the Session slot a count-in was waiting forvoid renderClick(float* out, int32_t i, int clickLen, double sr); // one sample of the click voicevoid renderTone(float* out, int32_t numFrames);void applyAutomation(Graph* g, double beat); // M9: eval lanes -> target atomics@@ -1435,6 +1436,18 @@ private:std::atomic<bool> captureGate_{true};bool recordCountIn_ = false; // setRecording → startAudioRecording: count-in pendingvoid playClock(); // push a TransportPlay command without touching arrangementActive_+ // Click `bars` of count-in, then roll the clock (arrangementActive_ untouched). Message thread.+ void startCountIn(int32_t bars);+ // A Session take started from stop counts in first (#158). sessionCountIn_: this take+ // started the count-in (message thread). countInLaunchScene_: the slot the audio thread+ // launches on recordSlotPlayer_ the moment the count-in runs out, -1 once launched or+ // cancelled. sessionCountInUndo_: undoPushCount_ right after a fresh take's empty clip was+ // added, so a take stopped during its count-in can take that clip back out.+ bool sessionCountIn_ = false;+ std::atomic<int32_t> countInLaunchScene_{-1};+ bool sessionCountInFresh_ = false;+ uint64_t sessionCountInUndo_ = 0;+ void cancelSessionCountIn();void finalizeSessionRecord(bool relaunch); // materialise an in-progress session take// Build a fresh graph with a new scene count, cloning tracks so slot vectors resize safely.std::shared_ptr<Graph> rebuildScenes(int32_t newCount,diff --git a/src/native/nota.engine/src/Engine_Render.cpp b/src/native/nota.engine/src/Engine_Render.cppindex d4b891ac..dfd0efea 100644--- a/src/native/nota.engine/src/Engine_Render.cpp+++ b/src/native/nota.engine/src/Engine_Render.cpp@@ -362,6 +362,13 @@ void Engine::poll() {Note n; n.pitch = r.pitch;n.startBeat = std::fmod(r.startBeat < 0 ? 0 : r.startBeat, L);n.lengthBeats = r.lengthBeats > 0.0 ? r.lengthBeats : 0.1;+ // Played on the count-in (#158): a slot has nothing before its start, so a note+ // released before the take began is dropped and one held into it starts there.+ if (r.startBeat < 0.0) {+ const double end = r.startBeat + r.lengthBeats;+ if (end <= 1e-9) { Note gone; attachRecordedExpr(gone, r.pitch, r.startBeat); continue; }+ n.lengthBeats = end;+ }n.velocity = r.velocity;attachRecordedExpr(n, r.pitch, r.startBeat);s.midi.notes.push_back(n);@@ -716,6 +723,13 @@ void Engine::endCountIn() {captureGate_.store(true, std::memory_order_relaxed);}+// A Session take counted in (#158): its slot starts as the transport rolls, on that sample,+// rather than on the next launch quantum. No-op when no take is waiting.+void Engine::launchCountInSlot() {+ if (const int32_t sc = countInLaunchScene_.exchange(-1, std::memory_order_acq_rel); sc >= 0)+ if (auto* sp = recordSlotPlayer_.load(std::memory_order_acquire)) sp->requestLaunch(sc, 0.0);+}+void Engine::drainCommands() {Command c;while (commands_.pop(c)) {@@ -732,6 +746,7 @@ void Engine::drainCommands() {} else {endCountIn();transport_.play();+ launchCountInSlot(); // Play pressed during a Session take's count-in}break;case CommandType::TransportStop: endCountIn(); transport_.stop(); break;@@ -787,11 +802,13 @@ void Engine::drainLiveMidi(double blockStartBeat, bool playing) {// When recording into a Session slot, time notes against the slot's own loop// clock (localBeats holds this block's start position) instead of the global// transport, so overdubs land at the right spot in the loop. During a count-in the- // transport holds still and notes are timed back from the take start (#56).+ // transport holds still and notes are timed back from the take start (#56) — for a slot+ // take, back from the slot's start (#158).SessionPlayer* slot = recordSlotPlayer_.load(std::memory_order_acquire);const double slotLen = recordSlotLen_.load(std::memory_order_relaxed);const bool timed = playing || countInActive_; // the timeline has a position for an event- const double nowBeat = slot ? (slotLen > 0.0 ? std::fmod(slot->localBeats, slotLen) : slot->localBeats)+ const double nowBeat = slot ? (countInActive_ ? countInClockOffset()+ : slotLen > 0.0 ? std::fmod(slot->localBeats, slotLen) : slot->localBeats): blockStartBeat + countInClockOffset();captureNow_ = nowBeat;@@ -1571,6 +1588,7 @@ void Engine::processBlock(float* out, int32_t numFrames) {if (countInDone) {endCountIn();transport_.play();+ launchCountInSlot();// Let the metronome click the beat we launch on (not when starting mid-beat).const double b = transport_.playheadSamples() / spb;const int64_t fb = static_cast<int64_t>(std::floor(b));diff --git a/src/native/nota.engine/src/Engine_Session.cpp b/src/native/nota.engine/src/Engine_Session.cppindex 7f8eefa2..4ddb110e 100644--- a/src/native/nota.engine/src/Engine_Session.cpp+++ b/src/native/nota.engine/src/Engine_Session.cpp@@ -274,6 +274,12 @@ void Engine::recordSessionSlot(int32_t trackId, int32_t scene) {auto t = findTrackAuthoring(trackId);if (!t) return;if (scene < 0 || scene >= authoring_->sceneCount) return;+ // From stop, a take counts in first when a count-in is set (#158), as an Arrangement take+ // does; with the transport already rolling it starts on the launch quantum as before.+ const bool countIn = !transport_.uiIsPlaying() && uiCountIn_.load(std::memory_order_relaxed) <= 0.0+ && countInBars() > 0;+ sessionCountIn_ = false;+ sessionCountInFresh_ = false;// Audio track: capture input into the slot (M5-4). Reuses the M4-3 input// pipeline; stopSessionRecord() materialises the take into slot.audio.@@ -281,9 +287,13 @@ void Engine::recordSessionSlot(int32_t trackId, int32_t scene) {recordSessionTrackId_ = trackId;recordSessionScene_ = scene;recordSessionAudio_ = true;- if (startAudioRecording(trackId)) {+ recordCountIn_ = countIn; // startAudioRecording leaves rolling the transport to us+ const bool ok = startAudioRecording(trackId);+ recordCountIn_ = false;+ if (ok) {recordStartStatus_ = 0;recording_.store(true, std::memory_order_relaxed); // drives slot state = recording+ if (countIn) { sessionCountIn_ = true; transportPlayCountIn(); } // the capture tap stays gated meanwhile} else {recordStartStatus_ = 2;recordSessionAudio_ = false;@@ -304,14 +314,27 @@ void Engine::recordSessionSlot(int32_t trackId, int32_t scene) {recordSessionGrowing_ = sessionRecordLen_ <= 0.0;addSessionMidiClip(trackId, scene, recordSessionGrowing_ ? kGrowingTakeBeats : sessionRecordLen_);t = findTrackAuthoring(trackId); if (!t) return;+ sessionCountInFresh_ = true;+ sessionCountInUndo_ = undoPushCount_;}resetCtlFold();recordSessionTrackId_ = trackId;recordSessionScene_ = scene;recordSlotLen_.store(t->sessionSlots[scene].lengthBeats, std::memory_order_relaxed);- launchSlot(trackId, scene); // play + loop the slot (also auto-starts transport)recordSlotPlayer_.store(t->sessionPlayer.get(), std::memory_order_release);+ if (countIn && t->sessionPlayer) {+ // The slot waits for the count-in: the audio thread launches it the moment the+ // clicks run out (Engine_Render). Session-only, like any launch from stop.+ sessionCountIn_ = true;+ if (t->sessionPlayer->pending.load(std::memory_order_relaxed) != SessionPlayer::kNone)+ t->sessionPlayer->requestStopNow(); // no earlier request may start it before then+ countInLaunchScene_.store(scene, std::memory_order_release);+ arrangementActive_.store(false, std::memory_order_relaxed);+ startCountIn(countInBars());+ } else {+ launchSlot(trackId, scene); // play + loop the slot (also auto-starts transport)+ }recording_.store(true, std::memory_order_relaxed);}@@ -322,6 +345,15 @@ void Engine::stopSessionRecord() { finalizeSessionRecord(true); }// so the take isn't lost). No-op when nothing is recording into a session slot.void Engine::finalizeSessionRecord(bool relaunch) {if (recordSessionScene_ < 0 && !recordSessionAudio_) return; // not a session record+ // Stopped while still counting in (#158): nothing was recorded, so put things back.+ if (sessionCountIn_) {+ sessionCountIn_ = false;+ const bool pendingSlot = countInLaunchScene_.exchange(-1, std::memory_order_acq_rel) >= 0;+ if (pendingSlot || (recordSessionAudio_ && uiCountIn_.load(std::memory_order_relaxed) > 0.0)) {+ cancelSessionCountIn();+ return;+ }+ }// Audio take: materialise into the slot (reads recordSession* + clears the audio flags).if (recordSessionAudio_) {const int32_t tid = recordSessionTrackId_, sc = recordSessionScene_;@@ -351,6 +383,40 @@ void Engine::finalizeSessionRecord(bool relaunch) {recordSlotPlayer_.store(nullptr, std::memory_order_release);recordSessionScene_ = -1;recordSessionTrackId_ = 0;+ recordSessionAudio_ = false; // also when the take captured nothing (stopAudioRecording left it)+}++// A Session take stopped during its count-in: stop the clicks (the transport never rolled),+// drop the capture, and take a fresh take's empty clip back out when nothing was edited since+// it went in, so the slot is as it was.+void Engine::cancelSessionCountIn() {+ const int32_t tid = recordSessionTrackId_, sc = recordSessionScene_;+ if (recordSessionAudio_) stopAudioRecording(); // nothing captured: the tap was gated+ resetCtlFold();+ recording_.store(false, std::memory_order_relaxed);+ recordSlotPlayer_.store(nullptr, std::memory_order_release);+ recordSessionScene_ = -1;+ recordSessionTrackId_ = 0;+ recordSessionAudio_ = false;+ recordSessionGrowing_ = false;+ arrangementActive_.store(false, std::memory_order_relaxed);+ uiCountIn_.store(0.0, std::memory_order_relaxed);+ Command c; c.type = CommandType::TransportStop; commands_.push(c); // also reopens the capture gate+ if (sessionCountInFresh_ && undoPushCount_ == sessionCountInUndo_ && !undoStack_.empty() && undoStack_.back().graph) {+ // The last checkpoint is the empty clip going in: drop it, and give the slot back+ // what it held before (only the slot — anything else published since stays).+ auto before = std::move(undoStack_.back().graph);+ undoStack_.pop_back();+ const SessionSlot* was = nullptr;+ for (auto& bt : before->tracks)+ if (bt->id() == tid && sc >= 0 && sc < static_cast<int32_t>(bt->sessionSlots.size())) was = &bt->sessionSlots[sc];+ if (auto old = findTrackAuthoring(tid); old && sc >= 0 && sc < static_cast<int32_t>(old->sessionSlots.size())) {+ auto nt = cloneTrack(*old);+ nt->sessionSlots[sc] = was ? *was : SessionSlot{};+ republishWithTrackRaw(tid, nt);+ }+ }+ sessionCountInFresh_ = false;}// A take's loop length: the recorded beats rounded to whole launch quanta (bars whendiff --git a/tests/Nota.SmokeTest/LiveRecordTests.cs b/tests/Nota.SmokeTest/LiveRecordTests.csindex f81092c9..f8742da9 100644--- a/tests/Nota.SmokeTest/LiveRecordTests.cs+++ b/tests/Nota.SmokeTest/LiveRecordTests.cs@@ -27,6 +27,7 @@ internal static class LiveRecordTestsforeach (var r in SessionSlot()) yield return r;foreach (var r in RoutedHeldAcrossRecord()) yield return r;foreach (var r in SessionAudioTake()) yield return r;+ foreach (var r in SessionCountIn()) yield return r;}// Render about `beats` beats in small chunks (events are timed per block).@@ -361,4 +362,86 @@ internal static class LiveRecordTestse.StopAllSession();e.StopTransport();}+ // Recording into a Session slot from stop counts in first (#158): the clicks run with the+ // transport and the slot still, the slot starts on the sample the count-in runs out (not a+ // launch quantum later), a note held into the take starts the slot and one released in+ // the count-in is dropped. Stop during the count-in leaves the slot as it was; a take+ // started while the transport rolls doesn't count in.+ private static IEnumerable<(bool, string)> SessionCountIn()+ {+ using (var e = Armed(out int t))+ {+ e.SetLaunchQuant(4.0);+ e.Seek(16.0);+ Beats(e, 0.01);+ e.SetCountIn(1);+ e.RecordSessionSlot(t, 0);+ yield return (e.CountInBeats > 0 && !e.IsPlaying, $"session count-in: armed from stop ({e.CountInBeats:F2} beats)");+ Beats(e, 1.0);+ e.NoteOn(64, 0.8f); // played and released inside the count-in+ Beats(e, 0.5);+ e.NoteOff(64);+ Beats(e, 2.0); // 3.5 beats into the bar+ e.TryGetSessionRecordTarget(out _, out _, out double waiting);+ yield return (!e.IsPlaying && e.SessionPlayingSlot(t) < 0 && waiting == 0.0,+ $"session count-in: slot and transport wait (playing={e.IsPlaying}, slot={e.SessionPlayingSlot(t)}, elapsed={waiting:F2})");+ e.NoteOn(60, 0.8f); // a pickup held into the take+ Beats(e, 1.0); // the count-in ran out half a beat ago+ e.NoteOff(60);+ e.TryGetSessionRecordTarget(out _, out _, out double el);+ yield return (e.IsPlaying && e.SessionPlayingSlot(t) == 0 && Near(el, 0.5),+ $"session count-in: the slot starts as it runs out, not a quantum later (elapsed {el:F2})");+ Beats(e, 0.25);+ e.NoteOn(67, 0.8f);+ Beats(e, 0.25);+ e.NoteOff(67);+ Beats(e, 0.1);+ e.Poll();+ e.StopSessionRecord();+ e.Poll();+ var notes = e.GetSessionNotes(t, 0);+ var pickup = notes.FirstOrDefault(x => x.Pitch == 60);+ yield return (notes.Any(x => x.Pitch == 60) && Near(pickup.StartBeat, 0.0) && Near(pickup.LengthBeats, 0.5),+ $"session count-in: a note held into the take starts the slot (start {pickup.StartBeat:F2}, length {pickup.LengthBeats:F2})");+ yield return (!notes.Any(x => x.Pitch == 64) && notes.Any(x => x.Pitch == 67),+ $"session count-in: a note over before the take is dropped, the take records ({string.Join(",", notes.Select(x => x.Pitch))})");+ e.StopAllSession();+ e.StopTransport();+ }++ using (var e = Armed(out int t))+ {+ e.Seek(0.0);+ Beats(e, 0.01);+ e.SetCountIn(1);+ bool couldUndo = e.CanUndo;+ e.RecordSessionSlot(t, 0);+ Beats(e, 1.0);+ e.StopTransport(); // Stop during the count-in cancels the take+ Beats(e, 0.1);+ yield return (!e.IsPlaying && e.CountInBeats == 0 && !e.IsRecording && e.SessionSlotLength(t, 0) == 0.0,+ $"session count-in: Stop cancels it and the slot is empty again (len {e.SessionSlotLength(t, 0):F2})");+ yield return (e.CanUndo == couldUndo, "session count-in: a cancelled take leaves no undo step");+ Beats(e, 4.0);+ yield return (!e.IsPlaying && e.SessionPlayingSlot(t) < 0, "session count-in: a cancelled count-in never starts the slot");++ e.RecordSessionSlot(t, 0);+ Beats(e, 1.0);+ e.StopSessionRecord(); // the slot's own stop, too+ Beats(e, 0.1);+ yield return (!e.IsPlaying && e.CountInBeats == 0 && e.SessionSlotLength(t, 0) == 0.0,+ "session count-in: stopping the take from the slot cancels it too");++ e.SetLaunchQuant(0.0);+ e.Play();+ Beats(e, 0.5);+ e.RecordSessionSlot(t, 0); // transport rolling: no count-in+ Beats(e, 0.1);+ yield return (e.CountInBeats == 0 && e.SessionPlayingSlot(t) == 0, "session count-in: none while the transport rolls");+ e.StopSessionRecord();+ e.StopAllSession();+ e.StopTransport();+ e.SetCountIn(0);+ }+ }}