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) Effects on an audio track ring out after Stop (#469)
Chris Laupamad57d86dc8394
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f8acdb62..17524429 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -247,6 +247,11 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.returns, then the master.### Fixed+- **Effects on an audio track ring out after Stop** (#449): a reverb or delay placed on an+ audio track used to fall silent the instant the transport stopped, while the same reverb on+ a return track rang on. The track's effects now keep playing on silence until their output+ has died away (3 seconds under −100 dB), then the track costs nothing again. Plug-ins on it+ also get stopped blocks now, so one that acts on Stop (PitchNet finishing a capture) does.- **Duplicating a track keeps its plug-ins** (#454): Duplicate track, a copied and pastedplug-in effect and a copied rack now bring their VST3 plug-ins along, with every setting.The copy used to come back without them, because a running plug-in describes itself by thediff --git a/src/native/nota.engine/src/engine/Engine.cpp b/src/native/nota.engine/src/engine/Engine.cppindex 2171cf22..5abeaf01 100644--- a/src/native/nota.engine/src/engine/Engine.cpp+++ b/src/native/nota.engine/src/engine/Engine.cpp@@ -689,7 +689,7 @@ std::shared_ptr<Track> Engine::cloneTrack(const Track& t) const {nt->ccRoutesDirty = true; // Arp CC routes (specs/044): rebuilt when publishednt->nextModId = t.nextModId;nt->sessionPlayer = t.sessionPlayer; // shared — playback state persists (M5-2)- nt->liveHeld = t.liveHeld; // shared — held live notes persist (#366)+ nt->liveHeld = t.liveHeld; // shared — held live notes (#366) and effect tail (#449) persistnt->setFrozen(t.frozen()); // M7: freeze state + buffer (shared by pointer)nt->frozenBuf = t.frozenBuf;nt->frozenSpb = t.frozenSpb;diff --git a/src/native/nota.engine/src/engine/Engine.h b/src/native/nota.engine/src/engine/Engine.hindex 892f50df..fe7270e4 100644--- a/src/native/nota.engine/src/engine/Engine.h+++ b/src/native/nota.engine/src/engine/Engine.h@@ -2254,7 +2254,15 @@ class Engine {std::vector<float> mixTmp_;// Parallel Pass 1 : per-leaf work items, sized on the message// thread (no audio-thread allocation).- enum class LeafPath : uint8_t { Skip, Frozen, Monitor, SessionInst, SessionAudio, Instrument, AudioClips };+ enum class LeafPath : uint8_t { Skip, Frozen, Monitor, SessionInst, SessionAudio, Instrument, AudioClips, Tail };+ // A stopped audio track's effects ring out (#449, LeafPath::Tail) while its output is over+ // kTailFloor (-100 dBFS) or a device still holds sound. Built-in devices say when they have+ // settled (Device::isIdle, which counts a delay's time in flight); a hosted plug-in can't,+ // so for it the output has to stay quiet kTailQuietSeconds; and a device that never reports+ // idle (an LFO's clock) lets the track go after kTailMaxQuietSeconds of quiet.+ static constexpr double kTailQuietSeconds = 3.0;+ static constexpr double kTailMaxQuietSeconds = 30.0;+ static constexpr float kTailFloor = 1.0e-5f;struct LeafWork {Track* t = nullptr;bool audible = false, capturing = false, feeding = false, toMix = false;diff --git a/src/native/nota.engine/src/engine/Engine_Render.cpp b/src/native/nota.engine/src/engine/Engine_Render.cppindex 58e2df31..d0eee2d4 100644--- a/src/native/nota.engine/src/engine/Engine_Render.cpp+++ b/src/native/nota.engine/src/engine/Engine_Render.cpp@@ -243,6 +243,33 @@ void playEvents(Instrument& inst, float* dst, int32_t frames, const MidiEv* evs,inst.offSettled.store(true, std::memory_order_relaxed);}}++// Something on the track that holds sound after its input stops: a device that runs, or a+// plug-in delay compensation line that is delaying (#449).+bool hasLiveDevice(const Track& t) {+ if (t.pdc && !t.pdc->isIdle()) return true;+ for (const auto& d : t.devices)+ if (d && !d->bypassed()) return true;+ return false;+}++// How settled a track's chain is once its output has gone quiet (#449): every live device+// reports idle (Settled); some are hosted plug-ins, whose state the host can't see, and the+// rest are idle (Opaque); or a built-in device still holds sound or never reports idle (Busy).+enum class ChainRest : uint8_t { Settled, Opaque, Busy };+ChainRest chainRest(const Track& t) {+ if (t.pdc && !t.pdc->isIdle()) return ChainRest::Busy;+ ChainRest r = ChainRest::Settled;+ for (const auto& d : t.devices) {+ if (!d || d->bypassed() || d->isIdle()) continue;+ // Only a hosted plug-in itself is opaque (builtinKind < 0); a rack that holds one is+ // built-in and still busy while its own delays hold sound. Audio-thread safe.+ if (d->builtinKind() >= 0) return ChainRest::Busy;+ r = ChainRest::Opaque;+ }+ return r;+}+} // namespacevoid Engine::noteExprEvents(@@ -2043,6 +2070,7 @@ void Engine::renderLeafDry(Track& t, float* dst, const LeafWork& w, Graph* g, inif (t.instrument) t.instrument->setPartTaps(nullptr, 0);break;case LeafPath::AudioClips: renderAudioClipsRaw(t.clips, dst, frames, blockStart, spb); break;+ case LeafPath::Tail: std::fill_n(dst, frames * 2, 0.0f); break; // the chain alone rings oncase LeafPath::Skip: break; // unreachable (pre-pass filters Skip out)}}@@ -2344,6 +2372,7 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, bt.sessionPlayer->localBeats += frames / spb;sessionPostRender(t, frames / spb);}+ t.tailQuiet() = -1; // muted: its tail is gone, not saved for the unmutet.setMeter(0, 0, 0, 0);t.stereoFold(0, 0, 0, frames, stereoA);continue;@@ -2376,11 +2405,14 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, bw.path = LeafPath::Instrument;} else if (playing && arrangementActive) {w.path = LeafPath::AudioClips;+ } else if (t.tailQuiet() >= 0 && hasLiveDevice(t)) {+ w.path = LeafPath::Tail; // its effects ring out on silence (#449)} else {+ t.tailQuiet() = -1;t.setMeter(0, 0, 0, 0);t.stereoFold(0, 0, 0, frames, stereoA);continue;- } // stopped / session-only audio track: nothing to do+ } // stopped / session-only audio track, its tail played out: nothing to do// Destination: this leaf's parent group's submix bus, else the master mix.const int destSlot = slotOf(t.groupId());@@ -2526,6 +2558,24 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, b}if (!parallelDsp) processLeafDevices(t, scratch_.data(), w, g, frames, blockStart, spb, playing, ti);+ // 2b') Effect tails (#449): a block an audio track plays (re)starts its tail; on+ // the tail path the chain's output is watched until it has been quiet long+ // enough, and the track goes back to costing nothing.+ if (w.path == LeafPath::Tail) {+ int64_t& quiet = t.tailQuiet();+ if (simd_audio::peakAbs(post, frames * 2) > kTailFloor) quiet = 0;+ else quiet += frames;+ if (quiet > 0) {+ const double sr = transport_.sampleRate();+ const ChainRest rest = chainRest(t);+ if (rest == ChainRest::Settled ||+ (rest == ChainRest::Opaque && quiet >= static_cast<int64_t>(kTailQuietSeconds * sr)) ||+ quiet >= static_cast<int64_t>(kTailMaxQuietSeconds * sr))+ quiet = -1;+ }+ } else if (w.path == LeafPath::AudioClips || w.path == LeafPath::SessionAudio || w.path == LeafPath::Monitor)+ t.tailQuiet() = 0;+// 2c) Freeze capture (M7): stash this track's post-device, pre-fader signal// into the freeze buffer. Sequential from a seek(0) render, so the write// cursor tracks the playhead frame.diff --git a/src/native/nota.engine/src/engine/Track.h b/src/native/nota.engine/src/engine/Track.hindex f8da19ec..b5eed90b 100644--- a/src/native/nota.engine/src/engine/Track.h+++ b/src/native/nota.engine/src/engine/Track.h@@ -217,6 +217,14 @@ class Track {// isn't sent again every block. Audio thread only.bool sessionSilentReleased = false;+ // Effects on an audio track ring out after the track stops sounding (#449): -1 when there+ // is no tail to play, else how long (frames) the chain's output has been silent. Set to 0+ // by every block the track plays; the chain then runs on silence until its devices have+ // settled (see Engine::kTailQuietSeconds). Audio thread only; shared by every version of+ // the track (edits, undo), so an edit while a tail rings doesn't cut it. Kept in LiveHeld+ // (below) so a clone shares one allocation rather than making a second.+ int64_t& tailQuiet() { return liveHeld->tailQuiet; }+// The untargeted live notes (keyboard, MIDI) the track was given and not yet the note-off// of, and whether it was disarmed with them down (#366): released on its next render.// Shared by every version of the track (edits, undo) and with no other track, so it@@ -224,6 +232,7 @@ class Track {struct LiveHeld {uint64_t bits[2] = {0, 0};bool release = false;+ int64_t tailQuiet = -1; // see tailQuiet() above};std::shared_ptr<LiveHeld> liveHeld = std::make_shared<LiveHeld>();diff --git a/tests/Nota.SmokeTest/AudioTailTests.cs b/tests/Nota.SmokeTest/AudioTailTests.csnew file mode 100644index 00000000..b628e3bb--- /dev/null+++ b/tests/Nota.SmokeTest/AudioTailTests.cs@@ -0,0 +1,158 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// Effects on an audio track ring out after Stop (#449). A stopped audio track used to skip+// its whole chain, so a reverb on it fell to digital silence the instant the transport+// stopped, and a plug-in never saw a stopped block. Now the chain runs on silence until its+// output has been quiet for a moment, then the track goes back to costing nothing.+// Also runnable alone: `dotnet Nota.SmokeTest.dll --audio-tails`.++using Nota.Application;+using Nota.Infrastructure;++namespace Nota.SmokeTest;++internal static class AudioTailTests+{+ private const int Rate = 44100, Block = 512, Reverb = 2, Delay = 3;++ public static IEnumerable<(bool ok, string label)> Run()+ {+ string wav = Wav();+ try+ {+ // Play 1 s of a 2 s tone through a long reverb, stop, listen 1 s.+ var (wet, wetQuiet) = AfterStop(wav, withReverb: true, seconds: 1, thenSeconds: 40);+ double tail = Rms(wet, 0, Rate / 4), later = Rms(wet, Rate / 2, Rate);+ yield return (tail > 1e-3 && later > 0 && later < tail,+ $"a reverb on an audio track rings out after Stop (first 0.25 s rms {tail:F4}, 0.5–1 s {later:G3})");+ yield return (wetQuiet,+ "…and the track falls to exact silence once the tail has died away");++ var (dry, _) = AfterStop(wav, withReverb: false, seconds: 1, thenSeconds: 0);+ yield return (Rms(dry, 0, Rate) == 0, "an audio track without effects is silent at once after Stop");++ yield return (NeverPlayed(), "an audio track with a reverb that never played stays silent while stopped");++ // Greptile on #469: an edit after Stop makes a new version of the track; the tail+ // has to ring on through it rather than reset.+ var (edited, _) = AfterStop(wav, withReverb: true, seconds: 1, thenSeconds: 0, editAfterStop: true);+ yield return (Rms(edited, Rate / 2, Rate) > 1e-4,+ $"…and keeps ringing when a clip is edited after Stop (0.5–1 s rms {Rms(edited, Rate / 2, Rate):G3})");++ // Two 2 s delays in series: the first echo comes out about 4 s after the input, so+ // more than 3 s of silence at the output is not the end of the tail.+ double late = LateEcho(wav);+ yield return (late > 1e-3, $"two 2 s delays in series still sound their echo ~4 s after Stop (rms {late:F4})");+ }+ finally { try { File.Delete(wav); } catch { } }+ }++ // The first second after Stop, and whether the last 2 s of `thenSeconds` more are all zero.+ private static (float[] After, bool QuietAtEnd) AfterStop(string wav, bool withReverb, int seconds, int thenSeconds,+ bool editAfterStop = false)+ {+ using var e = new NotaEngine();+ e.SetBpm(120);+ int t = e.AddAudioTrack();+ e.AddAudioClip(t, wav, 0.0);+ if (withReverb)+ {+ int d = e.AddBuiltinDevice(t, Reverb);+ SetByName(e, t, d, "decay", 0.95f);+ SetByName(e, t, d, "dry/wet", 0.6f);+ }+ e.Seek(0.0);+ e.Play();+ Render(e, seconds * Rate);+ e.StopTransport();+ if (editAfterStop)+ {+ Render(e, Block);+ e.SetClipGain(t, 0, 0.5f);+ }+ var after = Render(e, Rate);+ bool quiet = true;+ if (thenSeconds > 0)+ {+ Render(e, (thenSeconds - 2) * Rate);+ var end = Render(e, 2 * Rate);+ quiet = end.All(v => v == 0f);+ }+ return (after, quiet);+ }++ // RMS of the 3.5–4.5 s after Stop, with 0.25 s of the tone played into two delays in series.+ private static double LateEcho(string wav)+ {+ using var e = new NotaEngine();+ e.SetBpm(120);+ int t = e.AddAudioTrack();+ e.AddAudioClip(t, wav, 0.0);+ for (int k = 0; k < 2; k++)+ {+ int d = e.AddBuiltinDevice(t, Delay);+ SetByName(e, t, d, "sync", 0f);+ SetByName(e, t, d, "time l", 1f);+ SetByName(e, t, d, "time r", 1f);+ SetByName(e, t, d, "feedback", 0f);+ SetByName(e, t, d, "wow depth", 0f);+ SetByName(e, t, d, "wet only", 1f);+ }+ e.Seek(0.0);+ e.Play();+ Render(e, Rate / 4);+ e.StopTransport();+ var after = Render(e, 5 * Rate);+ return Rms(after, Rate * 7 / 2, Rate * 9 / 2);+ }++ private static bool NeverPlayed()+ {+ using var e = new NotaEngine();+ int t = e.AddAudioTrack();+ e.AddBuiltinDevice(t, Reverb);+ return Render(e, Rate).All(v => v == 0f);+ }++ private static void SetByName(NotaEngine e, int t, int d, string name, float norm)+ {+ for (int p = 0; p < e.DeviceParamCount(t, d); p++)+ if (e.DeviceParamName(t, d, p).Contains(name, StringComparison.OrdinalIgnoreCase))+ {+ float lo = e.DeviceParamMin(t, d, p), hi = e.DeviceParamMax(t, d, p);+ e.DeviceSetParam(t, d, p, lo + (hi - lo) * norm);+ return;+ }+ }++ private static float[] Render(NotaEngine e, int frames)+ {+ var all = new float[frames * 2];+ var b = new float[Block * 2];+ for (int done = 0; done < frames; done += Block)+ {+ int n = Math.Min(Block, frames - done);+ e.RenderOffline(b, n);+ Array.Copy(b, 0, all, done * 2, n * 2);+ }+ return all;+ }++ private static double Rms(float[] st, int fromFrame, int toFrame)+ {+ double s = 0;+ int n = 0;+ for (int i = fromFrame * 2; i < toFrame * 2 && i < st.Length; i++) { s += st[i] * (double)st[i]; n++; }+ return Math.Sqrt(s / Math.Max(1, n));+ }++ private static string Wav()+ {+ var path = Path.Combine(Path.GetTempPath(), $"nota-tail-{Guid.NewGuid():N}.wav");+ var x = new float[Rate * 2 * 2];+ for (int i = 0; i < x.Length / 2; i++) x[2 * i] = x[2 * i + 1] = 0.4f * (float)Math.Sin(2 * Math.PI * 330 * i / Rate);+ using (var w = new Nota.Infrastructure.WavWriter(path, Rate, 2, WavBitDepth.Float32)) w.WriteFrames(x, x.Length / 2);+ return path;+ }+}diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex 9e46658c..c261ae5e 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -542,7 +542,14 @@ if (args.Length >= 1 && args[0] == "--instrument-chain")Console.WriteLine(failures == 0 ? "INSTRUMENT CHAIN PASSED" : $"INSTRUMENT CHAIN FAILED ({failures})");return failures == 0 ? 0 : 1;}-// Drum Rack one-shot pads, pad audition, warp off/on alone: `--pad-warp`. Also part of the full run.+// Audio-track effect tails after Stop (#449) alone: `--audio-tails`. Also part of the full run.+if (args.Length >= 1 && args[0] == "--audio-tails")+{+ Console.WriteLine("-- audio-track tails after Stop --");+ foreach (var (ok, label) in AudioTailTests.Run()) Check(ok, label);+ Console.WriteLine(failures == 0 ? "AUDIO TAILS PASSED" : $"AUDIO TAILS FAILED ({failures})");+ return failures == 0 ? 0 : 1;+}// Opt-in (needs a VST3 built and scanned): `--hosted-plugin <vst3 folder> <nota-scanworker>`.if (args.Length >= 3 && args[0] == "--hosted-plugin"){@@ -551,7 +558,7 @@ if (args.Length >= 3 && args[0] == "--hosted-plugin")Console.WriteLine(failures == 0 ? "HOSTED PLUGIN PASSED" : $"HOSTED PLUGIN FAILED ({failures})");return failures == 0 ? 0 : 1;}-+// Drum Rack one-shot pads, pad audition, warp off/on alone: `--pad-warp`. Also part of the full run.if (args.Length >= 1 && args[0] == "--pad-warp"){Console.WriteLine("-- pads + warp toggle --");@@ -15569,6 +15576,8 @@ Console.WriteLine("-- device remove undo --");foreach (var (ok, label) in DeviceRemoveUndoTests.Run()) Check(ok, label);Console.WriteLine("-- device copy + rack undo --");foreach (var (ok, label) in DeviceCopyTests.Run()) Check(ok, label);+Console.WriteLine("-- audio-track tails after Stop --");+foreach (var (ok, label) in AudioTailTests.Run()) Check(ok, label);Console.WriteLine("-- instrument chain --");foreach (var (ok, label) in InstrumentChainTests.Run()) Check(ok, label);foreach (var (ok, label) in DeviceGroupTests.Run()) Check(ok, label);diff --git a/tests/perf/nota_perf.cpp b/tests/perf/nota_perf.cppindex 5e3067d2..c5614195 100644--- a/tests/perf/nota_perf.cpp+++ b/tests/perf/nota_perf.cpp@@ -202,6 +202,9 @@ std::vector<Scenario> scenarios() {for (int n : {1, 4, 8, 16, 32}) s.push_back({"mix-" + std::to_string(n), std::to_string(n) + " tracks, all playing"});s.push_back({"sparse-32", "32 tracks, 1 in 4 playing"});s.push_back({"silent-32", "32 tracks, no clips"});+ // Stopped after playing: the audio tracks' Reverb + Delay ring out (#449), then must cost+ // nothing again; this measures the stopped engine once the tails are over.+ s.push_back({"audio-tails-8", "8 audio tracks with Reverb + Delay, stopped, tails over"});s.push_back({"audio-warp-split", "Warped audio clip split in 8, playing"});// An edit, not a render: the measured loop splits a warped clip 8 times and undoes it (#299).s.push_back({"edit-warp-split", "Split a warped 8 s clip 8x + undo (ms per edit)"});@@ -260,6 +263,18 @@ bool build(NotaEngine* e, const std::string& id) {}return true;}+ if (id == "audio-tails-8") {+ const std::string wav = warpTestWav();+ bool ok = true;+ for (int i = 0; i < 8 && ok; ++i) {+ const int t = nota_engine_add_audio_track(e);+ ok = t >= 0 && nota_track_add_audio_clip(e, t, wav.c_str(), 0.0) == 0 &&+ nota_track_add_builtin_device(e, t, 2) >= 0 && nota_track_add_builtin_device(e, t, 3) >= 0;+ }+ std::error_code ec;+ std::filesystem::remove(wav, ec);+ return ok;+ }if (id == "audio-warp-split" || id == "edit-warp-split") {const int t = warpedClipTrack(e);if (t < 0) return false;@@ -332,6 +347,12 @@ int run(const std::string& id, double seconds) {for (int i = 0; i < (int)(0.25 * kSampleRate / kBlock); ++i) // warm-up: voices, caches, pool threadsnota_engine_render_offline_at(e, buf.data(), kBlock, kSampleRate);+ if (id == "audio-tails-8") { // stop while the clips sound, then let the tails ring out (not measured)+ nota_transport_stop(e);+ for (int i = 0; i < (int)(20.0 * kSampleRate / kBlock); ++i)+ nota_engine_render_offline_at(e, buf.data(), kBlock, kSampleRate);+ }+const int blocks = std::max(1, (int)(seconds * kSampleRate / kBlock));float peak = 0.0f;const auto t0 = std::chrono::steady_clock::now();