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) Armed audio tracks meter their input; Mixer and Modular follow the Arrangement's track order (#389)
Egor Khindikaynen535da00f62da
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c41fdf8c..c2d05b51 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -148,6 +148,13 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.returns, then the master.### Fixed+- **An armed audio track meters its input with monitoring off** (nota-daw/nota#352): arm a+ track and its meter shows the level coming in (hardware input, or the source track it+ records from) before and during a take, without hearing it. The meter reads the input+ pre-fader; with monitoring on it still shows what the track plays.+- **Modular lists tracks in the Arrangement's order** (nota-daw/nota#374): a new track no+ longer shows up after the return tracks in the Track sidebar or as a Global island until+ the tracks are reordered (the Mixer already follows the arrangement).- **Window buttons on Windows** — minimize, maximize and close in the title bar showed asgrey rounded tiles with an always-red close button, plus an extra fullscreen button. Theyare flat again, as in other Windows apps: the hover tone under the pointer, red only whilediff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.csindex 3c1f0bfa..75d71fcd 100644--- a/src/managed/Nota.App/ArrangementView.cs+++ b/src/managed/Nota.App/ArrangementView.cs@@ -3250,6 +3250,17 @@ public sealed partial class ArrangementView : UserControl/// <summary>Colour index for a return bus (0/1).</summary>internal static int ReturnColorIndex(int returnIdx) => ReturnColorBase + (Math.Max(0, returnIdx) % NotaPalette.ReturnColors.Length);+ /// <summary>The engine's track indices in the order the arrangement lists them: regular+ /// tracks first, then the returns. A new track is appended after the returns in the+ /// engine, so views walking the raw order showed it below them (#374).</summary>+ internal static IEnumerable<int> DisplayOrder(IAudioEngine eng)+ {+ int n = eng.TrackCount;+ for (int pass = 0; pass < 2; pass++)+ for (int i = 0; i < n; i++)+ if (eng.TryGetTrackInfo(i, out var ti) && ti.IsReturn == (pass == 1)) yield return i;+ }+/// <summary>The effective palette index for a track: its stored colour if set, else its/// group's hue (shaded per sibling), else the automatic colour for its position. Shared by/// every view so a user-picked colour shows consistently in the arrangement, mixer anddiff --git a/src/managed/Nota.App/MixerView.cs b/src/managed/Nota.App/MixerView.csindex 4ffbd1b9..374cf46d 100644--- a/src/managed/Nota.App/MixerView.cs+++ b/src/managed/Nota.App/MixerView.cs@@ -199,13 +199,12 @@ public sealed class MixerView : UserControlint returns = _engine.ReturnTrackCount;int n = _engine.TrackCount;// As in the arrangement: the tracks in their order, then the returns, then the master.- foreach (bool wantReturns in new[] { false, true })- for (int i = 0; i < n; i++)- {- if (!_engine.TryGetTrackInfo(i, out var ti) || ti.IsReturn != wantReturns) continue;- var c = ArrangementView.TrackBrush(ArrangementView.EffectiveColorIndex(_engine, ti.Id));- _row.Children.Add(Strip(ti, c, returns));- }+ foreach (int i in ArrangementView.DisplayOrder(_engine))+ {+ if (!_engine.TryGetTrackInfo(i, out var ti)) continue;+ var c = ArrangementView.TrackBrush(ArrangementView.EffectiveColorIndex(_engine, ti.Id));+ _row.Children.Add(Strip(ti, c, returns));+ }_row.Children.Add(MasterStrip());_shownLaw = null; // the strips are new: repaint the law state onto themSyncPanLaw();diff --git a/src/managed/Nota.App/ModularView.cs b/src/managed/Nota.App/ModularView.csindex 7ae76029..2f28a424 100644--- a/src/managed/Nota.App/ModularView.cs+++ b/src/managed/Nota.App/ModularView.cs@@ -264,8 +264,7 @@ public sealed partial class ModularView : UserControl_emptyHint.IsVisible = !_global && _trackId <= 0; // the hint is Track view's; Global has islandsif (_global) return;_sidebar.Children.Clear();- int n = _engine.TrackCount;- for (int i = 0; i < n; i++)+ foreach (int i in ArrangementView.DisplayOrder(_engine))if (_engine.TryGetTrackInfo(i, out var ti) && !ti.IsGroup)_sidebar.Children.Add(TrackRow(ti.Id, ti));if (_sidebar.Children.Count == 0)@@ -550,10 +549,9 @@ public sealed partial class ModularView : UserControl{double y = 60;int islands = 0;- int n = _engine.TrackCount;var islandByTrack = new Dictionary<int, GNode>();var trackIds = new List<int>();- for (int i = 0; i < n; i++)+ foreach (int i in ArrangementView.DisplayOrder(_engine)){if (!_engine.TryGetTrackInfo(i, out var ti) || ti.IsGroup) continue;var isl = IslandNode(ti.Id, i, ti);diff --git a/src/native/nota.engine/src/engine/Engine.h b/src/native/nota.engine/src/engine/Engine.hindex dd3525ae..dbd5a3bd 100644--- a/src/native/nota.engine/src/engine/Engine.h+++ b/src/native/nota.engine/src/engine/Engine.h@@ -908,8 +908,9 @@ class Engine {bool partIdAt(int32_t sourceTrackId, int32_t index, uint64_t* part) const;template <typename Consumer>int32_t applySidechainKey(Consumer& c, int32_t src, uint64_t part, bool routed = true);+ // meters = false leaves out the meter-only keys (an armed, unmonitored audio track, #352).template <typename Fn>- void forEachRouteKey(Fn&& fn) const;+ void forEachRouteKey(Fn&& fn, bool meters = true) const;// Open/close a hosted plugin's native GUI. deviceIndex < 0 = the instrument;// otherwise the effect at that chain position. Message thread only.void openTrackEditor(int32_t trackId, int32_t deviceIndex);diff --git a/src/native/nota.engine/src/engine/Engine_Devices.cpp b/src/native/nota.engine/src/engine/Engine_Devices.cppindex fe34da9d..cecc4f7e 100644--- a/src/native/nota.engine/src/engine/Engine_Devices.cpp+++ b/src/native/nota.engine/src/engine/Engine_Devices.cpp@@ -1584,8 +1584,10 @@ void Engine::recomputeRouting() {// Every route a consumer asks for, in claim order: track instruments and devices (and keyed// children inside their racks, specs/044), then a monitoring audio track's input source.+// Meter-only keys (an armed audio track that isn't monitoring, #352) come after every audible+// one, so with the pool full arming a track never takes a route a device or monitor hears.template <typename Fn>-void Engine::forEachRouteKey(Fn&& fn) const {+void Engine::forEachRouteKey(Fn&& fn, bool meters) const {for (auto& t : authoring_->tracks) {auto children = [&](const RackCore& r) {r.forEachChildDevice([&](Device& c) { fn(c.sidechainSourceTrackId(), c.sidechainPart()); });@@ -1601,8 +1603,13 @@ void Engine::forEachRouteKey(Fn&& fn) const {if (auto* r = d->asRack()) children(*r);}// A monitoring audio track hears its source track's post-fader tap.- if (t->type() == TrackType::Audio && t->monitor() && t->recordInputSource() > 0) fn(t->recordInputSource(), uint64_t{0});+ if (t->type() == TrackType::Audio && t->monitor() && t->recordInputSource() > 0)+ fn(t->recordInputSource(), uint64_t{0});}+ if (!meters) return;+ for (auto& t : authoring_->tracks) // an armed one meters it (#352): last, see above+ if (t->type() == TrackType::Audio && t->armed() && !t->monitor() && t->recordInputSource() > 0)+ fn(t->recordInputSource(), uint64_t{0});}// ---- Sidechain sub-sources (specs/050) -------------------------------------------------@@ -1659,12 +1666,16 @@ int32_t Engine::applySidechainKey(Consumer& c, int32_t src, uint64_t part, boolc.setSidechainPart(part);recomputeRouting();bool kept = routeSlotFor(src, part) >= 0;- bool oldHeld = false; // does anyone still listen to the old key?- forEachRouteKey([&](int32_t t, uint64_t p) { oldHeld = oldHeld || (t == oldSrc && p == oldPart); });+ // Does a device, instrument or monitor still listen to a key? A route only an armed track's+ // meter reads may go (#352); so may the old key's when this was its only listener.+ auto heard = [&](int32_t ts, uint64_t ps) {+ bool h = false;+ forEachRouteKey([&](int32_t t, uint64_t p) { h = h || (t == ts && p == ps); }, false);+ return h;+ };for (int32_t s = 0; kept && s < nBefore; ++s) {const auto [t, p] = before[s];- // The old key's route may go when this was its only listener; every other must stay.- if (routeSlotFor(t, p) < 0 && (oldHeld || !(t == oldSrc && p == oldPart))) kept = false;+ if (routeSlotFor(t, p) < 0 && heard(t, p)) kept = false; // every other route must stay}if (kept) return 0;c.setSidechainSourceTrackId(oldSrc);diff --git a/src/native/nota.engine/src/engine/Engine_Recording.cpp b/src/native/nota.engine/src/engine/Engine_Recording.cppindex c4dcda4f..bc0d85eb 100644--- a/src/native/nota.engine/src/engine/Engine_Recording.cpp+++ b/src/native/nota.engine/src/engine/Engine_Recording.cpp@@ -17,6 +17,10 @@ void Engine::setTrackArmed(int32_t trackId, bool armed) {auto t = findTrackAuthoring(trackId);const bool wasArmed = t && t->armed();if (t) t->setArmed(armed);+ if (t && t->type() == TrackType::Audio && armed != wasArmed) {+ recomputeRouting(); // an armed track meters its source track's tap (#352)+ updateMonitorInput(); // ... or the hardware input: open / close the capture device+ }if (armed) return;// A key still held from live input loses its note-off once the track stops taking live// notes (#366): the audio thread releases the live notes this track is sounding. The key@@ -40,10 +44,10 @@ void Engine::setTrackRecordInput(int32_t trackId, int32_t source) {auto t = findTrackAuthoring(trackId);if (!t) return;t->setRecordInputSource(source);- if (t->monitor()) {+ if (t->monitor() || t->armed()) {recomputeRouting();updateMonitorInput();- } // monitored source moved+ } // monitored / metered source moved}int32_t Engine::trackRecordInput(int32_t trackId) const {auto t = findTrackAuthoring(trackId);@@ -106,12 +110,13 @@ void Engine::releaseAudioInputIfIdle() {}// Keep the capture device open exactly while some audio track monitors the hardware-// input. Only acts on a change, so a failed open isn't retried on every edit.+// input, or is armed on it and meters it (#352). Only acts on a change, so a failed open+// isn't retried on every edit.void Engine::updateMonitorInput() {bool want = false;if (authoring_)for (auto& t : authoring_->tracks)- if (t->type() == TrackType::Audio && t->monitor() && t->recordInputSource() == 0) {+ if (t->type() == TrackType::Audio && (t->monitor() || t->armed()) && t->recordInputSource() == 0) {want = true;break;}diff --git a/src/native/nota.engine/src/engine/Engine_Render.cpp b/src/native/nota.engine/src/engine/Engine_Render.cppindex c52afa06..2ac5c7be 100644--- a/src/native/nota.engine/src/engine/Engine_Render.cpp+++ b/src/native/nota.engine/src/engine/Engine_Render.cpp@@ -2534,6 +2534,40 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, bpkL, pkR, static_cast<float>(std::sqrt(sqL / frames)), static_cast<float>(std::sqrt(sqR / frames)));}+ // An armed audio track that isn't monitoring meters its input instead (#352): the+ // level to set before a take, without hearing it. Pre-fader, like a console's input+ // meter; a monitoring track already meters what it hears. Nothing here is heard, so+ // the sources monitoring refuses (they would feed back) meter too: the master (its+ // previous block's level) and a group the track sits in (its post-fader tap).+ for (auto& tptr : g->tracks) {+ Track& t = *tptr;+ if (t.type() != TrackType::Audio || !t.armed() || (t.frozen() && t.frozenBuf)) continue;+ if (t.monitor() && t.id() != capTrackId) continue;+ const int32_t src = t.recordInputSource();+ if (src == -1) {+ t.setMeter(masterPeakL_.load(std::memory_order_relaxed), masterPeakR_.load(std::memory_order_relaxed),+ masterRmsL_.load(std::memory_order_relaxed), masterRmsR_.load(std::memory_order_relaxed));+ continue;+ }+ const float* in = scratch_.data();+ if (src > 0 && src != t.id()) {+ const int32_t slot = routeSlotForTrack(src);+ if (slot >= 0) in = routeBus_[slot].data();+ else std::fill_n(scratch_.data(), frames * 2, 0.0f);+ } else renderMonitorInput(g, t, scratch_.data(), frames);+ float pkL = 0.0f, pkR = 0.0f;+ double sqL = 0.0, sqR = 0.0;+ for (int32_t i = 0; i < frames; ++i) {+ const float l = in[i * 2], r = in[i * 2 + 1];+ pkL = std::max(pkL, std::fabs(l));+ pkR = std::max(pkR, std::fabs(r));+ sqL += l * (double)l;+ sqR += r * (double)r;+ }+ t.setMeter(+ pkL, pkR, static_cast<float>(std::sqrt(sqL / frames)), static_cast<float>(std::sqrt(sqR / frames)));+ }+// Pass 1.5: group submixes. Process deepest-first so a nested group folds into its// parent's bus before the parent reads it; top-level groups fold into the master.for (int depth = maxDepth; depth >= 1; --depth)diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex 4c8dc3b0..65960960 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -13183,6 +13183,75 @@ Console.WriteLine("-- input monitoring --");me.SetTrackMonitor(mon, false);me.RenderOffline(mbuf, 2048);Check(Rms(mbuf, 2048) < 1e-4f, $"monitor off silences the input (RMS {Rms(mbuf, 2048):F5})");++ // Armed without monitoring (#352): the meter shows the input, nothing is heard.+ me.TryGetTrackMeter(mon, out var offMeter);+ Check(offMeter.Peak < 1e-4f, $"an unarmed, unmonitored track meters nothing (peak {offMeter.Peak:F5})");+ me.SetTrackArmed(mon, true);+ me.PushMonitorFramesForTest(sine, 8192);+ me.RenderOffline(mbuf, 2048);+ me.TryGetTrackMeter(mon, out var armMeter);+ Check(armMeter.Peak > 0.1f, $"an armed track meters its hardware input without monitoring (peak {armMeter.Peak:F3})");+ Check(Rms(mbuf, 2048) < 1e-4f, $"... and the input stays unheard (RMS {Rms(mbuf, 2048):F5})");+ me.SetTrackVolume(mon, 0f);+ me.RenderOffline(mbuf, 2048);+ me.TryGetTrackMeter(mon, out var preMeter);+ Check(preMeter.Peak > 0.1f, $"the armed input meter is pre-fader (peak {preMeter.Peak:F3})");+ me.SetTrackVolume(mon, 1f);+ me.SetTrackArmed(mon, false);+ me.RenderOffline(mbuf, 2048);+ me.TryGetTrackMeter(mon, out var disarmMeter);+ Check(disarmMeter.Peak < 1e-4f, $"disarming drops the input meter (peak {disarmMeter.Peak:F5})");++ // An internal source: an armed track meters its source track's output.+ me.SetTrackRecordInput(mon, minst);+ me.SetTrackSolo(mon, false);+ me.SetTrackArmed(mon, true);+ me.Seek(0); me.Play();+ for (int b = 0; b < 4; b++) me.RenderOffline(mbuf, 2048);+ me.TryGetTrackMeter(mon, out var srcMeter);+ Check(srcMeter.Peak > 0.001f, $"an armed track meters its source track without monitoring (peak {srcMeter.Peak:F3})");++ // The sources monitoring refuses (they would feed back) still meter: nothing is heard.+ me.SetTrackRecordInput(mon, -1);+ for (int b = 0; b < 4; b++) me.RenderOffline(mbuf, 2048);+ me.TryGetTrackMeter(mon, out var masterMeter);+ Check(masterMeter.Peak > 0.001f, $"an armed track meters the master it records from (peak {masterMeter.Peak:F3})");+ int monGroup = me.CreateGroup(new[] { minst, mon });+ me.SetTrackRecordInput(mon, monGroup);+ for (int b = 0; b < 4; b++) me.RenderOffline(mbuf, 2048);+ me.TryGetTrackMeter(mon, out var groupMeter);+ Check(groupMeter.Peak > 0.001f, $"an armed track meters the group it sits in (peak {groupMeter.Peak:F3})");+ me.StopTransport();+ me.SetTrackArmed(mon, false);+}++// ============ an armed track's input meter never takes a sidechain route (#352) ============+Console.WriteLine("-- armed input meter and the sidechain route pool --");+{+ using var re = new NotaEngine();+ int armed = re.AddAudioTrack(); // first in track order: claims would start here+ int host = re.AddAudioTrack();+ var keyed = new System.Collections.Generic.List<(int dev, int src)>();+ for (int i = 0; i < 16; i++)+ {+ int d = re.AddBuiltinDevice(host, 1);+ int s = re.AddAudioTrack();+ re.SetDeviceSidechainKey(host, d, s, -1);+ keyed.Add((d, s));+ }+ int metered = re.AddAudioTrack();+ re.SetTrackRecordInput(armed, metered);+ re.SetTrackArmed(armed, true);+ Check(re.SidechainRoutesFree() == 0 && keyed.TrueForAll(k => re.SidechainRouteInUse(k.src, -1)) && !re.SidechainRouteInUse(metered, -1),+ "arming a track with the route pool full leaves every sidechain route in place");+ re.SetDeviceSidechainKey(host, keyed[15].dev, -1, -1); // a free route: the meter takes it+ Check(re.SidechainRouteInUse(metered, -1), "the armed track's meter takes a route once one is free");+ int late = re.AddAudioTrack();+ int r = re.SetDeviceSidechainKey(host, keyed[15].dev, late, -1);+ Check(r == 0 && re.SidechainRouteInUse(late, -1) && !re.SidechainRouteInUse(metered, -1),+ $"a new sidechain key takes the route back from the meter (result {r})");+ re.SetTrackArmed(armed, false);}// ============ input monitoring survives a project round-trip ===============