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
Add live listen of ext source
Egor Khindikaynen30287a5db307
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c1b4cb53..a06e14c9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,6 +19,13 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.## [Unreleased]### Added+- **Input monitoring** on audio tracks: the headphones button right of the track's input+ selector lets you hear the input live through the track's effects and fader, whether or+ not the transport is playing, like Ableton's Monitor "In". The input can be your audio+ interface or microphone, another track, or a return. While monitoring is on, the track+ plays its input instead of its clips. Soloing the monitoring track doesn't mute the track+ it listens to. The Master input can't be monitored because it would feed back, so the+ button is dimmed when Master is selected. Monitoring is saved with the project.- Preferences → Audio: **Play test tone** plays a 440 Hz sine through the master so you cancheck the output, and **CPU check** measures the audio load for 5 seconds and tells youwhether the current buffer size leaves enough headroom. The test tone now fades in and outdiff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.csindex 46a01c3e..cc1c0862 100644--- a/src/managed/Nota.App/ArrangementView.cs+++ b/src/managed/Nota.App/ArrangementView.cs@@ -1534,13 +1534,22 @@ public sealed partial class ArrangementView : UserControlControl row2 = btnRow;if (isAudioTrack || t.IsInstrument){- var combo = isAudioTrack ? BuildInputCombo(t.Id) : BuildMidiSourceCombo(t.Id);- var g = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), Margin = new Thickness(0, 5, 0, 0), ColumnSpacing = 3};+ // Audio tracks: a monitor chip right of the input selector hears that input live.+ var monitor = isAudioTrack ? MonitorToggle(t.Id) : null;+ var combo = isAudioTrack ? BuildInputCombo(t.Id, monitor) : BuildMidiSourceCombo(t.Id);+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), Margin = new Thickness(0, 5, 0, 0), ColumnSpacing = 3};btnRow.Margin = new Thickness(0);Grid.SetColumn(btnRow, 0);Grid.SetColumn(combo, 1);g.Children.Add(btnRow);g.Children.Add(combo);+ if (monitor is not null)+ {+ combo.Margin = new Thickness(0);+ monitor.Chip.Margin = new Thickness(0, 0, 12, 0); // the row's right inset moves to the chip+ Grid.SetColumn(monitor.Chip, 2);+ g.Children.Add(monitor.Chip);+ }row2 = g;}@@ -1858,7 +1867,7 @@ public sealed partial class ArrangementView : UserControl// Compact record-input selector for an audio track header: Ext (hardware), Master,// or another track / send. Reflects and writes the track's stored input source.- private ComboBox BuildInputCombo(int trackId)+ private ComboBox BuildInputCombo(int trackId, MonitorChip? monitor = null){var cb = new ComboBox{@@ -1871,8 +1880,8 @@ public sealed partial class ArrangementView : UserControl// "In" pinned left (faded), the source name pinned right, so the name stands out.void Add(string value, int src){- var inTb = new TextBlock { Text = "In", FontSize = 9, Foreground = Brush("Brush.TextDisabled"), VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6, 0) };- var valTb = new TextBlock { Text = value, FontSize = 9, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Right, TextTrimming = TextTrimming.CharacterEllipsis, Margin = new Thickness(6, 0) };+ var inTb = new TextBlock { Text = "In", FontSize = 9, Foreground = Brush("Brush.TextDisabled"), VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(monitor is null ? 6 : 4, 0) };+ var valTb = new TextBlock { Text = value, FontSize = 9, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Right, TextTrimming = TextTrimming.CharacterEllipsis, Margin = new Thickness(monitor is null ? 6 : 4, 0) };// The closed box hoists this content out of its item, where it stops following the// theme foreground and keeps whatever it was built with — so on the paper variant// the name rendered near-white. A NotaPalette brush re-points on a variant change,@@ -1881,7 +1890,8 @@ public sealed partial class ArrangementView : UserControlDockPanel.SetDock(inTb, Dock.Left);// MinWidth so the closed selection box (which doesn't stretch its content in// Avalonia) still spreads In to the left edge and the name to the right.- var content = new DockPanel { LastChildFill = true, MinWidth = 84, Children = { inTb, valTb } };+ // Narrower with the monitor chip beside it, so the closed box still shows In + name.+ var content = new DockPanel { LastChildFill = true, MinWidth = monitor is null ? 84 : 58, Children = { inTb, valTb } };cb.Items.Add(new ComboBoxItem { Content = content, Padding = new Thickness(6, 2), MinHeight = 0, HorizontalContentAlignment = HorizontalAlignment.Stretch });sources.Add(src);}@@ -1892,14 +1902,58 @@ public sealed partial class ArrangementView : UserControlint cur = _engine?.GetTrackRecordInput(trackId) ?? 0;int sel = sources.IndexOf(cur);cb.SelectedIndex = sel >= 0 ? sel : 0;+ monitor?.SetSource(sel >= 0 ? cur : 0);cb.SelectionChanged += (_, _) =>{- if (cb.SelectedIndex >= 0 && cb.SelectedIndex < sources.Count)- _engine?.SetTrackRecordInput(trackId, sources[cb.SelectedIndex]);+ if (cb.SelectedIndex < 0 || cb.SelectedIndex >= sources.Count) return;+ _engine?.SetTrackRecordInput(trackId, sources[cb.SelectedIndex]);+ monitor?.SetSource(sources[cb.SelectedIndex]);};return cb;}+ // Input-monitor chip (Monitor "In"): while lit, the audio track plays whatever arrives on+ // its input — hardware, another track or a return — live through its devices and fader,+ // in place of its clips. Master can't be monitored (it would feed back), so the chip+ // fades out and explains itself while Master is the selected input.+ private sealed class MonitorChip+ {+ public required Border Chip { get; init; }+ public required Action<int> SetSource { get; init; }+ }++ private MonitorChip MonitorToggle(int trackId)+ {+ bool state = _engine?.GetTrackMonitor(trackId) ?? false;+ bool usable = true;+ var glyph = new Glyph(GlyphKind.Headphones, 10);+ var chip = new Border+ {+ Width = 18, Height = 16, CornerRadius = NotaRadius.Control, BorderThickness = new Thickness(1),+ Child = glyph, Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center,+ };+ void Paint()+ {+ // Engaged: the brass wash + edge of M/S; at rest a neutral chip.+ chip.Background = Brush(state ? "Brush.AccentSubtle" : "Brush.SurfaceRaised");+ chip.BorderBrush = Brush(state ? "Brush.BorderBrass" : "Brush.BorderDefault");+ glyph.Foreground = Brush(state ? "Brush.AccentHover" : "Brush.TextStrong");+ chip.Opacity = usable ? 1.0 : 0.4;+ ToolTip.SetTip(chip, usable+ ? (state ? "Monitoring input — click to stop" : "Monitor input: hear it live through this track")+ : "Master can't be monitored (it would feed back)");+ }+ Paint();+ chip.PointerPressed += (_, e) =>+ {+ if (!e.GetCurrentPoint(chip).Properties.IsLeftButtonPressed) return;+ e.Handled = true;+ state = !state; Paint();+ _engine?.SetTrackMonitor(trackId, state);+ };+ return new MonitorChip { Chip = chip, SetSource = src => { usable = src != -1; Paint(); } };+ }+// Compact MIDI-input selector for an instrument track header: None, or another instrument// track whose MIDI this one receives ("MIDI In"). Mirrors the record-input combo.private ComboBox BuildMidiSourceCombo(int trackId)diff --git a/src/managed/Nota.App/Controls/Glyph.cs b/src/managed/Nota.App/Controls/Glyph.csindex 82aba4fb..de03c04b 100644--- a/src/managed/Nota.App/Controls/Glyph.cs+++ b/src/managed/Nota.App/Controls/Glyph.cs@@ -23,6 +23,7 @@ internal enum GlyphKindChevronDown, ChevronUp, ChevronLeft, ChevronRight,StepLeft, StepRight, // filled small triangles (◀ ▶ as "move")Edit, Freeze, PopOut, Cycle, Dot, Bypass, Plus, Grip, Minus,+ Headphones, // input monitoring}internal sealed class Glyph : Control@@ -128,6 +129,23 @@ internal sealed class Glyph : Controlctx.DrawEllipse(ink, null, new Point(cx + j * dx, cy + i * dy), dr, dr);break;}+ case GlyphKind.Headphones:+ {+ // A headband arc over two ear cups.+ double rr = s * 0.36, top = cy + s * 0.06;+ var band = new StreamGeometry();+ using (var c = band.Open())+ {+ c.BeginFigure(new Point(cx - rr, top), false);+ c.ArcTo(new Point(cx + rr, top), new Size(rr, rr), 0, false, SweepDirection.Clockwise);+ c.EndFigure(false);+ }+ ctx.DrawGeometry(null, pen, band);+ double cw = s * 0.2, ch = s * 0.32;+ ctx.DrawRectangle(ink, null, new RoundedRect(new Rect(cx - rr - cw * 0.5, top, cw, ch), cw * 0.35));+ ctx.DrawRectangle(ink, null, new RoundedRect(new Rect(cx + rr - cw * 0.5, top, cw, ch), cw * 0.35));+ break;+ }case GlyphKind.Dot:ctx.DrawEllipse(ink, null, new Point(cx, cy), s * 0.3, s * 0.3);break;diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.csindex 1eeca1af..90b83eb4 100644--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs@@ -221,6 +221,10 @@ public interface IAudioEngine : IDisposable/// <summary>Audio-track record input source: 0 hardware, -1 master, >0 source track id.</summary>void SetTrackRecordInput(int trackId, int source);int GetTrackRecordInput(int trackId);+ /// <summary>Live input monitoring (audio tracks, Monitor "In"): play the record-input+ /// source through the track in place of its clips. A master source stays silent.</summary>+ void SetTrackMonitor(int trackId, bool on);+ bool GetTrackMonitor(int trackId);/// <summary>Set an instrument track's MIDI input source — receive another instrument track's/// MIDI output ("MIDI In"). sourceTrackId = -1 turns it off.</summary>void SetTrackMidiSource(int trackId, int sourceTrackId);diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.csindex dd609546..10227563 100644--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs@@ -240,6 +240,15 @@ internal static partial class NativeMethods[LibraryImport(Lib, EntryPoint = "nota_track_get_record_input")]internal static partial int TrackGetRecordInput(IntPtr engine, int trackId);+ [LibraryImport(Lib, EntryPoint = "nota_track_set_monitor")]+ internal static partial NotaResult TrackSetMonitor(IntPtr engine, int trackId, int on);++ [LibraryImport(Lib, EntryPoint = "nota_track_get_monitor")]+ internal static partial int TrackGetMonitor(IntPtr engine, int trackId);++ [LibraryImport(Lib, EntryPoint = "nota_engine_push_monitor_frames")]+ internal static partial void EnginePushMonitorFrames(IntPtr engine, float[] interleavedStereo, int frames);+[LibraryImport(Lib, EntryPoint = "nota_track_set_midi_source")]internal static partial NotaResult TrackSetMidiSource(IntPtr engine, int trackId, int sourceTrackId);diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.csindex 9221d8ca..5073f7e7 100644--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs@@ -355,6 +355,18 @@ public sealed partial class NotaEnginepublic int GetTrackRecordInput(int trackId){ ThrowIfDisposed(); return NativeMethods.TrackGetRecordInput(_handle, trackId); }+ /// <summary>Turns live input monitoring on/off for an audio track (hear its record input through the track).</summary>+ public void SetTrackMonitor(int trackId, bool on)+ { ThrowIfDisposed(); NativeMethods.TrackSetMonitor(_handle, trackId, on ? 1 : 0); }++ /// <summary>True when the audio track monitors its record input live.</summary>+ public bool GetTrackMonitor(int trackId)+ { ThrowIfDisposed(); return NativeMethods.TrackGetMonitor(_handle, trackId) != 0; }++ /// <summary>Test hook: feed the hardware-monitor ring without opening a capture device.</summary>+ public void PushMonitorFramesForTest(float[] interleavedStereo, int frames)+ { ThrowIfDisposed(); NativeMethods.EnginePushMonitorFrames(_handle, interleavedStereo, frames); }+/// <summary>Sets an instrument track's MIDI input source (receive that track's MIDI; -1 = off).</summary>public void SetTrackMidiSource(int trackId, int sourceTrackId){ ThrowIfDisposed(); NativeMethods.TrackSetMidiSource(_handle, trackId, sourceTrackId); }diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectModel.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectModel.csindex a7e02d4c..5a1e12fc 100644--- a/src/managed/Nota.Infrastructure/Persistence/ProjectModel.cs+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectModel.cs@@ -78,6 +78,7 @@ public sealed class TrackDto// Record input: 0 hardware, -1 master, or (2 + track-list index) for another track's// output (encoded so it survives id reassignment across save/load).public int RecordInput { get; set; }+ public bool Monitor { get; set; } // live input monitoring (audio tracks)// MIDI routing source ("MIDI In") as a doc-list index (survives id reassignment), or -1 = off.public int MidiFrom { get; set; } = -1;public float[] Sends { get; set; } = new float[4];diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectService.csindex 92596503..52575aa8 100644--- a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs@@ -88,6 +88,7 @@ public sealed class ProjectServiceRecordInput = engine.GetTrackRecordInput(ti.Id) is var rin && rin > 0? (idToIndex.TryGetValue(rin, out var rix) ? rix + 2 : 0) // track source → doc index + 2: rin, // 0 hardware / -1 master+ Monitor = engine.GetTrackMonitor(ti.Id),MidiFrom = engine.GetTrackMidiSource(ti.Id) is var mfrom && mfrom > 0&& idToIndex.TryGetValue(mfrom, out var mix) ? mix : -1, // source → doc index, else off};@@ -466,6 +467,7 @@ public sealed class ProjectServicevar scDeferred = new List<(int track, int dev, int srcIndex)>();var instScDeferred = new List<(int track, int srcIndex)>(); // instrument React source (Nota Flux)var recInputDeferred = new List<(int trackId, int encoded)>();+ var monitorDeferred = new List<(int trackId, bool on)>();var groupDeferred = new List<(int trackId, int parentDocIndex)>(); // group membershipvar midiFromDeferred = new List<(int trackId, int sourceDocIndex)>(); // MIDI routing source ("MIDI In")// CV links resolved after all tracks exist (cross-track targets are doc-indices).@@ -593,6 +595,7 @@ public sealed class ProjectServiceif (t.Name is { Length: > 0 } trackName) engine.SetTrackName(id, trackName);if (t.ColorIndex >= 0) engine.SetTrackColorIndex(id, t.ColorIndex);if (t.RecordInput != 0) recInputDeferred.Add((id, t.RecordInput)); // resolve after all tracks exist+ if (t.Monitor) monitorDeferred.Add((id, true)); // after record inputs resolveif (t.MidiFrom >= 0) midiFromDeferred.Add((id, t.MidiFrom)); // resolve after all tracks existfor (int b = 0; b < t.Sends.Length && b < 4; b++) engine.SetTrackSend(id, b, t.Sends[b]);@@ -792,6 +795,8 @@ public sealed class ProjectService: (enc >= 2 && enc - 2 < newTrackIds.Count && newTrackIds[enc - 2] > 0 ? newTrackIds[enc - 2] : 0);if (source != 0) engine.SetTrackRecordInput(trackId, source);}+ // Input monitoring last, so a track-source monitor never briefly opens the hardware input.+ foreach (var (trackId, on) in monitorDeferred) if (on) engine.SetTrackMonitor(trackId, true);// MIDI routing source ("MIDI In", stored as a doc index), now that every track exists.foreach (var (trackId, sourceDocIndex) in midiFromDeferred){diff --git a/src/managed/Nota.Mcp/Tools/MixerTools.cs b/src/managed/Nota.Mcp/Tools/MixerTools.csindex 84d7a871..bc909338 100644--- a/src/managed/Nota.Mcp/Tools/MixerTools.cs+++ b/src/managed/Nota.Mcp/Tools/MixerTools.cs@@ -50,4 +50,10 @@ public sealed class MixerTools(IAudioEngine engine, IEngineDispatch dispatch, IA[McpServerTool(Name = "get_record_input"), Description("Read a track's record-input source index.")]public Task<int> GetRecordInput(int trackId) => Read(() => E.GetTrackRecordInput(trackId));++ [McpServerTool(Name = "set_track_monitor"), Description("Turn live input monitoring on/off for an audio track: it plays its record-input source (hardware input, or another track's / return's output) through its devices and fader in real time, in place of its clips.")]+ public Task SetTrackMonitor(int trackId, bool on) => Mutate(() => E.SetTrackMonitor(trackId, on));++ [McpServerTool(Name = "get_track_monitor"), Description("Read whether an audio track is monitoring its record input live.")]+ public Task<bool> GetTrackMonitor(int trackId) => Read(() => E.GetTrackMonitor(trackId));}diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.hindex 502ead39..ff61628a 100644--- a/src/native/nota.engine/include/nota/nota_engine.h+++ b/src/native/nota.engine/include/nota/nota_engine.h@@ -797,6 +797,13 @@ NOTA_API int32_t nota_track_has_clipboard(NotaEngine* engine);* -1 = master bus, >0 = another track's post-fader output (by id). */NOTA_API NotaResult nota_track_set_record_input(NotaEngine* engine, int32_t track_id, int32_t source);NOTA_API int32_t nota_track_get_record_input(NotaEngine* engine, int32_t track_id);+/* Input monitoring (audio tracks, Monitor "In"): while on, the track plays its record-input+ * source live through its devices + fader instead of its clips. A master source stays+ * silent (it would feed back). push_monitor_frames feeds the hardware-monitor ring without+ * opening a capture device (tests only). */+NOTA_API NotaResult nota_track_set_monitor(NotaEngine* engine, int32_t track_id, int32_t on);+NOTA_API int32_t nota_track_get_monitor(NotaEngine* engine, int32_t track_id);+NOTA_API void nota_engine_push_monitor_frames(NotaEngine* engine, const float* interleaved_stereo, int32_t frames);/* MIDI routing: forward an instrument track's MIDI to another instrument track* (source_track_id = -1 turns it off). */diff --git a/src/native/nota.engine/src/CommandQueue.h b/src/native/nota.engine/src/CommandQueue.hindex 8a858af5..59e7c811 100644--- a/src/native/nota.engine/src/CommandQueue.h+++ b/src/native/nota.engine/src/CommandQueue.h@@ -66,6 +66,11 @@ public:return true;}+ // Approximate fill level. Exact from the consumer thread (the producer can only grow it).+ size_t size() const noexcept {+ return (head_.load(std::memory_order_acquire) - tail_.load(std::memory_order_relaxed)) & kMask;+ }+private:static constexpr size_t kMask = Capacity - 1;T buffer_[Capacity]{};diff --git a/src/native/nota.engine/src/Engine.cpp b/src/native/nota.engine/src/Engine.cppindex c0932b54..6c906ec4 100644--- a/src/native/nota.engine/src/Engine.cpp+++ b/src/native/nota.engine/src/Engine.cpp@@ -31,6 +31,7 @@ Engine::Engine()authoring_(std::make_shared<Graph>()) {authoring_->masterTrack = std::make_shared<Track>(kMasterTrackId, TrackType::Audio);scratch_.assign(kMaxBlock * 2, 0.0f);+ monitorHwBuf_.assign(kMaxBlock * 2, 0.0f);clipEnvScratch_.assign(kMaxBlock * 2, 0.0f);for (auto& b : returnBus_) b.assign(kMaxBlock * 2, 0.0f); // M6-1 send busesfor (auto& b : groupBus_) b.assign(kMaxBlock * 2, 0.0f); // group submix buses@@ -44,7 +45,10 @@ Engine::Engine()installRackPluginFactory(); // lets rack blobs rebuild hosted-plugin children on load}-Engine::~Engine() { stop(); }+Engine::~Engine() {+ stop();+ if (input_) input_->stop(); // monitoring can keep the capture device open until teardown+}bool Engine::start() {if (backend_->isRunning()) return true;@@ -144,7 +148,13 @@ bool Engine::applyAudioConfig() {stop();// Drop the cached input unit so the next capture re-opens the chosen device.if (input_) input_.reset();- return start();+ const bool ok = start();+ // Live monitoring held the old capture device open: reopen on the chosen one.+ hwRecordTap_.store(false, std::memory_order_relaxed);+ hwMonitorTap_.store(false, std::memory_order_relaxed);+ hwMonitorWanted_ = false;+ updateMonitorInput();+ return ok;}// --- MIDI device settings (M7-2) ---------------------------------------------@@ -306,6 +316,7 @@ std::shared_ptr<Track> Engine::cloneTrack(const Track& t) const {nt->setReturnIndex(t.returnIndex()); // M6-1nt->setGroupId(t.groupId()); // group membershipnt->setRecordInputSource(t.recordInputSource()); // internal record routing+ nt->setMonitor(t.monitor()); // live input monitoringnt->setMidiFromTrackId(t.midiFromTrackId()); // MIDI routingfor (int b = 0; b < kMaxReturns; ++b) nt->setSend(b, t.send(b)); // M6-1: send levelsnt->clips = t.clips;@@ -338,6 +349,7 @@ void Engine::publishRaw(std::shared_ptr<Graph> g) {retired_.push_back(g);liveGraph_.store(g.get(), std::memory_order_release);recomputeRouting(); // Phase B: refresh sidechain source-track → route-slot table+ updateMonitorInput(); // a monitoring track may have come or gone (undo, delete, load)}void Engine::pushUndo() {diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.hindex 56516634..0dd35fe1 100644--- a/src/native/nota.engine/src/Engine.h+++ b/src/native/nota.engine/src/Engine.h@@ -46,6 +46,7 @@ using RecordedQueue = SpscRingBuffer<RecordedNote, 1024>;// Captured input frame (input thread -> message), lock-free up-queue (M4-3).struct InputFrame { float l; float r; };using InputQueue = SpscRingBuffer<InputFrame, 1u << 17>; // ~3 s at 44.1 kHz — headroom for UI-thread drain stalls+using MonitorQueue = SpscRingBuffer<InputFrame, 1u << 14>; // input thread -> audio thread (live monitoring)// Incoming MIDI control event surfaced to the UI for MIDI-learn (MIDI thread ->// message thread, lock-free up-queue). kind: 0 = control-change, 1 = note-on.@@ -788,6 +789,10 @@ public:// -1 = master bus, >0 = another track's post-fader output (by id).void setTrackRecordInput(int32_t trackId, int32_t source);int32_t trackRecordInput(int32_t trackId) const;+ // Input monitoring (audio tracks): hear the record-input source live through the track.+ void setTrackMonitor(int32_t trackId, bool on);+ bool trackMonitor(int32_t trackId) const;+ void pushMonitorFramesForTest(const float* interleavedStereo, int32_t frames); // feed the hw monitor ring// MIDI routing: forward an instrument track's MIDI to another instrument track (-1 = off).void setTrackMidiSource(int32_t trackId, int32_t sourceTrackId);int32_t trackMidiSource(int32_t trackId) const;@@ -847,6 +852,7 @@ private:// automation + solo + send buses + track pass + return pass. processBlock// splits a block at loop boundaries and calls this per segment.void mixGraph(Graph* g, float* out, int32_t frames, double blockStartSamples, bool playing, double spb);+ void renderMonitorInput(Graph* g, const Track& t, float* dst, int32_t frames); // live input monitoringvoid drainCommands();void drainLiveMidi(double blockStartBeat, bool playing);void renderInstrumentRaw(Graph* g, Track& t, float* dst, int32_t frames,@@ -1099,6 +1105,23 @@ private:float recRoutedVel_[128] = {};void captureRoutedNotes(const MidiEv* evs, int n, double blockStart, double spb);+ // Live input monitoring: the input thread also feeds this ring while any audio track+ // monitors the hardware input; the audio thread pops one segment's worth per mixGraph+ // into monitorHwBuf_, holding a small cushion so the two device clocks don't click.+ // Declared before input_ so it outlives the capture thread on destruction.+ MonitorQueue monitorQueue_;+ std::vector<float> monitorHwBuf_; // audio thread, this segment's hw input+ bool monitorPrimed_ = false; // audio thread: cushion reached+ std::atomic<int32_t> inputBlockFrames_{0}; // largest capture callback seen (cushion size)+ std::atomic<bool> hwMonitorTap_{false}; // input thread -> monitorQueue_+ std::atomic<bool> hwRecordTap_{false}; // input thread -> inputQueue_ (hw take rolling)+ bool hwMonitorWanted_ = false; // message thread: some track monitors hw input+ bool inputTestMode_ = false; // tests: never open a real capture device+ bool ensureAudioInput(); // open the capture device once (shared)+ void releaseAudioInputIfIdle(); // close it when nothing records/monitors+ void updateMonitorInput(); // (re)evaluate hw monitoring after edits+ void pullMonitorInput(int32_t frames); // audio thread: ring -> monitorHwBuf_+// audio input recording (M4-3): input thread -> ring -> message-thread buffer.std::unique_ptr<AudioInput> input_;InputQueue inputQueue_;diff --git a/src/native/nota.engine/src/Engine_Devices.cpp b/src/native/nota.engine/src/Engine_Devices.cppindex 6fb81081..33d88331 100644--- a/src/native/nota.engine/src/Engine_Devices.cpp+++ b/src/native/nota.engine/src/Engine_Devices.cpp@@ -909,6 +909,9 @@ void Engine::recomputeRouting() {if (t->instrument) claim(t->instrument->sidechainSourceTrackId());for (auto& d : t->devices)if (d) claim(d->sidechainSourceTrackId());+ // A monitoring audio track hears its source track's post-fader tap.+ if (t->type() == TrackType::Audio && t->monitor() && t->recordInputSource() > 0)+ claim(t->recordInputSource());}}diff --git a/src/native/nota.engine/src/Engine_Recording.cpp b/src/native/nota.engine/src/Engine_Recording.cppindex e1097dfd..2a3e29a9 100644--- a/src/native/nota.engine/src/Engine_Recording.cpp+++ b/src/native/nota.engine/src/Engine_Recording.cpp@@ -36,12 +36,104 @@ void Engine::setTrackArmed(int32_t trackId, bool armed) {}}void Engine::setTrackRecordInput(int32_t trackId, int32_t source) {- if (auto t = findTrackAuthoring(trackId)) t->setRecordInputSource(source);+ auto t = findTrackAuthoring(trackId);+ if (!t) return;+ t->setRecordInputSource(source);+ if (t->monitor()) { recomputeRouting(); updateMonitorInput(); } // monitored source moved}int32_t Engine::trackRecordInput(int32_t trackId) const {auto t = findTrackAuthoring(trackId);return t ? t->recordInputSource() : 0;}++// --- live input monitoring ---------------------------------------------------+void Engine::setTrackMonitor(int32_t trackId, bool on) {+ auto t = findTrackAuthoring(trackId);+ if (!t || t->type() != TrackType::Audio) return;+ t->setMonitor(on);+ recomputeRouting(); // claim / release the source track's route tap+ updateMonitorInput(); // open / close the capture device for a hardware source+}+bool Engine::trackMonitor(int32_t trackId) const {+ auto t = findTrackAuthoring(trackId);+ return t && t->monitor();+}++// Open the capture device once; recording and monitoring share it, each gated by its own+// tap flag, so starting a take while monitoring doesn't reopen (or drop) the stream.+bool Engine::ensureAudioInput() {+ if (inputTestMode_) return true;+ if (input_ && input_->isRunning()) return true;+ if (!input_) input_ = createAudioInput();+ const uint32_t inputDev = resolveAudioDeviceId(config_.inputDeviceUid, /*inputScope=*/true);+ // The input thread only touches the lock-free rings (RT-safe).+ return input_->start([this](const float* s, int32_t n) {+ if (n > inputBlockFrames_.load(std::memory_order_relaxed))+ inputBlockFrames_.store(n, std::memory_order_relaxed);+ if (hwRecordTap_.load(std::memory_order_relaxed)) {+ int64_t dropped = 0;+ for (int32_t i = 0; i < n; ++i)+ if (!inputQueue_.push(InputFrame{ s[i * 2], s[i * 2 + 1] })) ++dropped;+ if (dropped) inputDroppedFrames_.fetch_add(dropped, std::memory_order_relaxed);+ }+ if (hwMonitorTap_.load(std::memory_order_relaxed))+ for (int32_t i = 0; i < n; ++i)+ if (!monitorQueue_.push(InputFrame{ s[i * 2], s[i * 2 + 1] })) break; // full: the audio thread trims+ }, inputDev);+}++void Engine::releaseAudioInputIfIdle() {+ if (hwRecordTap_.load(std::memory_order_relaxed) || hwMonitorTap_.load(std::memory_order_relaxed)) return;+ if (input_) input_->stop();+}++// 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.+void Engine::updateMonitorInput() {+ bool want = false;+ if (authoring_)+ for (auto& t : authoring_->tracks)+ if (t->type() == TrackType::Audio && t->monitor() && t->recordInputSource() == 0) { want = true; break; }+ if (want == hwMonitorWanted_) return;+ hwMonitorWanted_ = want;+ if (want) {+ if (ensureAudioInput()) hwMonitorTap_.store(true, std::memory_order_relaxed);+ } else {+ hwMonitorTap_.store(false, std::memory_order_relaxed);+ releaseAudioInputIfIdle();+ }+}++// Audio thread: pop this segment's hardware input into monitorHwBuf_. The capture and+// output devices run on separate clocks, so keep a cushion of about one capture block+// queued (re-primed after an underrun) and trim any excess so latency can't build up.+void Engine::pullMonitorInput(int32_t frames) {+ float* dst = monitorHwBuf_.data();+ std::fill_n(dst, frames * 2, 0.0f);+ if (!hwMonitorTap_.load(std::memory_order_relaxed)) { monitorPrimed_ = false; return; }+ const size_t cushion = static_cast<size_t>(std::clamp(inputBlockFrames_.load(std::memory_order_relaxed), 64, 4096));+ size_t avail = monitorQueue_.size();+ const size_t n = static_cast<size_t>(frames);+ InputFrame f;+ if (avail > n + cushion * 2 + 256) { // drifted / stalled: drop the stale backlog+ for (size_t k = avail - (n + cushion); k > 0 && monitorQueue_.pop(f); --k) {}+ avail = n + cushion;+ }+ if (!monitorPrimed_) {+ if (avail < n + cushion) return; // still filling the cushion: silence+ monitorPrimed_ = true;+ }+ size_t i = 0;+ for (; i < n && monitorQueue_.pop(f); ++i) { dst[i * 2] = f.l; dst[i * 2 + 1] = f.r; }+ if (i < n) monitorPrimed_ = false; // underrun: rebuild the cushion+}++void Engine::pushMonitorFramesForTest(const float* interleavedStereo, int32_t frames) {+ inputTestMode_ = true;+ hwMonitorTap_.store(true, std::memory_order_relaxed);+ for (int32_t i = 0; i < frames; ++i)+ monitorQueue_.push(InputFrame{ interleavedStereo[i * 2], interleavedStereo[i * 2 + 1] });+}void Engine::setTrackMidiSource(int32_t trackId, int32_t sourceTrackId) {if (sourceTrackId == trackId) sourceTrackId = -1; // no self-routingif (auto t = findTrackAuthoring(trackId)) t->setMidiFromTrackId(sourceTrackId);@@ -246,17 +338,12 @@ bool Engine::startAudioRecording(int32_t trackId) {return true;}- if (!input_) input_ = createAudioInput();- // The input thread only touches the lock-free ring (RT-safe).- const uint32_t inputDev = resolveAudioDeviceId(config_.inputDeviceUid, /*inputScope=*/true);- const bool ok = input_->start([this](const float* s, int32_t n) {- int64_t dropped = 0;- for (int32_t i = 0; i < n; ++i)- if (!inputQueue_.push(InputFrame{ s[i * 2], s[i * 2 + 1] })) ++dropped;- if (dropped) inputDroppedFrames_.fetch_add(dropped, std::memory_order_relaxed);- }, inputDev);- if (!ok) { audioRecordTrackId_ = 0; return false; }- audioRecordSampleRate_ = input_->sampleRate() > 0 ? input_->sampleRate() : transport_.sampleRate();+ // The device may already be open for monitoring: flush anything a previous take's+ // tap left behind, then start feeding the capture ring.+ if (!ensureAudioInput()) { audioRecordTrackId_ = 0; return false; }+ { InputFrame stale; while (inputQueue_.pop(stale)) {} }+ hwRecordTap_.store(true, std::memory_order_relaxed);+ audioRecordSampleRate_ = input_ && input_->sampleRate() > 0 ? input_->sampleRate() : transport_.sampleRate();beginCaptureLayout();audioRecording_ = true;// Arrangement takes rewind to the take start on stop; session takes manage@@ -273,7 +360,8 @@ void Engine::stopAudioRecording() {if (!audioRecording_) return;audioRecording_ = false;internalRecordSource_.store(0, std::memory_order_relaxed); // stop the mixGraph tap- if (input_) input_->stop();+ hwRecordTap_.store(false, std::memory_order_relaxed); // stop the capture tap+ releaseAudioInputIfIdle(); // keep it open if monitoringdrainInputQueue(); // pull whatever the input (or mix) thread pushed before it stoppedconst int32_t trackId = audioRecordTrackId_;diff --git a/src/native/nota.engine/src/Engine_Render.cpp b/src/native/nota.engine/src/Engine_Render.cppindex 4677e010..a83cc360 100644--- a/src/native/nota.engine/src/Engine_Render.cpp+++ b/src/native/nota.engine/src/Engine_Render.cpp@@ -795,6 +795,24 @@ void Engine::processBlock(float* out, int32_t numFrames) {masterRmsR_.store(numFrames ? static_cast<float>(std::sqrt(msqR / numFrames)) : 0.0f, std::memory_order_relaxed);}+// Fill `dst` with what a monitoring audio track hears: the hardware input pulled for this+// segment, or its source track's previous-block post-fader route tap. Guards against the+// obvious feedback loops (itself, master, or a group it sits inside) by staying silent.+void Engine::renderMonitorInput(Graph* g, const Track& t, float* dst, int32_t frames) {+ const int32_t src = t.recordInputSource();+ if (src == 0) { std::copy_n(monitorHwBuf_.data(), frames * 2, dst); return; }+ std::fill_n(dst, frames * 2, 0.0f);+ if (src < 0 || src == t.id()) return;+ for (int32_t a = t.groupId(), hops = 0; a >= 0 && hops < 64; ++hops) { // ancestor group?+ if (a == src) return;+ int32_t parent = -1;+ for (auto& o : g->tracks) if (o->id() == a) { parent = o->groupId(); break; }+ a = parent;+ }+ const int32_t slot = routeSlotForTrack(src);+ if (slot >= 0) std::copy_n(routeBus_[slot].data(), frames * 2, dst);+}+void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, bool playing, double spb) {{// Automation (M9): read-mode block-rate eval — write each active lane's@@ -819,6 +837,21 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, b// Internal resampling (record from another track/send/master): tap the source's// post-fader output into the input ring while a take is rolling.const int32_t recSrc = internalRecordSource_.load(std::memory_order_relaxed);++ // Live input monitoring: this segment's hardware input (shared by every track+ // monitoring it), and the set of tracks whose output some monitoring track hears —+ // those keep rendering while solo-gated, feeding only their route tap / record tap.+ pullMonitorInput(frames);+ constexpr int kMaxFeeds = 16;+ int32_t feedIds[kMaxFeeds]; int numFeeds = 0;+ if (recSrc > 0) feedIds[numFeeds++] = recSrc;+ for (auto& t : g->tracks)+ if (t->type() == TrackType::Audio && t->monitor() && t->recordInputSource() > 0 && numFeeds < kMaxFeeds)+ feedIds[numFeeds++] = t->recordInputSource();+ auto feedsMonitor = [&](int32_t id) {+ for (int i = 0; i < numFeeds; ++i) if (feedIds[i] == id) return true;+ return false;+ };bool anySolo = false;int32_t numReturns = 0;for (auto& t : g->tracks) {@@ -890,7 +923,10 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, b// — otherwise a soloed sibling would punch silent gaps into the buffer.const bool capturing = (t.id() == freezeCaptureTrackId_.load(std::memory_order_relaxed));const bool audible = !leafMute(t) && (!anySolo || leafSolo(t));- if (!audible && !capturing) { t.setMeter(0, 0, 0, 0); continue; }+ // Soloing a monitoring (or recording) track must not silence what it listens to.+ const bool feeding = !audible && !leafMute(t) && feedsMonitor(t.id());+ if (!audible && !capturing && !feeding) { t.setMeter(0, 0, 0, 0); continue; }+ const bool toMix = audible || capturing; // false: render only for the taps// Destination: this leaf's parent group's submix bus, else the master mix.const int destSlot = slotOf(t.groupId());float* dest = destSlot >= 0 ? groupBus_[destSlot].data() : out;@@ -898,8 +934,13 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, b// 0) Session view (M5-2): apply quantized launch/stop; a playing slot// overrides this track's arrangement content. (Skipped for a frozen or// capturing track — the buffer/arrangement is the source of truth.)+ // Input monitoring (Monitor "In"): the track plays its record-input source live+ // in place of its clips — hardware input this segment, or the source track's+ // post-fader tap from the previous one. Master (-1) would feed back: silent.+ const bool monitoring = !frozenActive && !capturing && t.type() == TrackType::Audio && t.monitor();+bool sessionActive = false;- if (!frozenActive && !capturing) if (auto& sp = t.sessionPlayer) {+ if (!frozenActive && !capturing && !monitoring) if (auto& sp = t.sessionPlayer) {if (sp->maybeApply(blockStart / spb, frames / spb, launchQuant_.load(std::memory_order_relaxed))) {if (t.instrument) t.instrument->allNotesOff();for (auto& md : t.midiEffects) if (md) md->reset(); // clock switch → flush arp@@ -922,7 +963,9 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, bt.instrument->setSidechain(s < 0 ? nullptr : routeBus_[s].data(), frames);}}- if (sessionActive && t.type() == TrackType::Instrument)+ if (monitoring)+ renderMonitorInput(g, t, scratch_.data(), frames);+ else if (sessionActive && t.type() == TrackType::Instrument)renderSessionSlotRaw(t, scratch_.data(), frames, spb);else if (sessionActive && t.type() == TrackType::Audio)renderSessionAudioSlotRaw(t, scratch_.data(), frames, spb);@@ -996,10 +1039,11 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, bfor (int32_t i = 0; i < frames; ++i) {const float l = scratch_[i * 2] * gl;const float r = scratch_[i * 2 + 1] * gr;- dest[i * 2] += l;- dest[i * 2 + 1] += r;if (tapRec && !inputQueue_.push(InputFrame{ l, r })) ++recDropped; // record this track's outputif (route) { route[i * 2] += l; route[i * 2 + 1] += r; } // tap post-fader → route bus+ if (!toMix) continue; // solo-gated feeder: taps only+ dest[i * 2] += l;+ dest[i * 2 + 1] += r;if (anySend)for (int b = 0; b < numReturns; ++b) if (sends[b] != 0.0f) {returnBus_[b][i * 2] += l * sends[b];@@ -1012,6 +1056,7 @@ void Engine::mixGraph(Graph* g, float* out, int32_t frames, double blockStart, bsqR += r * (double)r;}if (recDropped) inputDroppedFrames_.fetch_add(recDropped, std::memory_order_relaxed);+ if (!toMix) { t.setMeter(0, 0, 0, 0); continue; }t.setMeter(pkL, pkR,static_cast<float>(std::sqrt(sqL / frames)),static_cast<float>(std::sqrt(sqR / frames)));diff --git a/src/native/nota.engine/src/Engine_Tracks.cpp b/src/native/nota.engine/src/Engine_Tracks.cppindex c56e37de..1cb25e74 100644--- a/src/native/nota.engine/src/Engine_Tracks.cpp+++ b/src/native/nota.engine/src/Engine_Tracks.cpp@@ -2156,6 +2156,7 @@ std::shared_ptr<Track> Engine::deepCloneTrack(const Track& src, int32_t newId) {nt->setReturnIndex(src.returnIndex());nt->setGroupId(src.groupId()); // keep membership on duplicate (paste resets to top-level)nt->setRecordInputSource(src.recordInputSource());+ nt->setMonitor(src.monitor());nt->setMidiFromTrackId(src.midiFromTrackId());for (int b = 0; b < kMaxReturns; ++b) nt->setSend(b, src.send(b));nt->clips = src.clips; // sample buffers are shared_ptr (immutable) — finediff --git a/src/native/nota.engine/src/Track.h b/src/native/nota.engine/src/Track.hindex b42756dc..545fbfea 100644--- a/src/native/nota.engine/src/Track.h+++ b/src/native/nota.engine/src/Track.h@@ -179,6 +179,12 @@ public:int32_t recordInputSource() const { return recordInputSource_.load(std::memory_order_relaxed); }void setRecordInputSource(int32_t s) { recordInputSource_.store(s, std::memory_order_relaxed); }+ // Input monitoring (audio tracks, Ableton's Monitor "In"): while on, the track plays its+ // record-input source live — hardware input, or another track's / return's post-fader+ // output — through its own devices + fader instead of its clips, transport rolling or not.+ bool monitor() const { return monitor_.load(std::memory_order_relaxed); }+ void setMonitor(bool m) { monitor_.store(m, std::memory_order_relaxed); }+// MIDI routing: send this instrument track's note events (clips + live input) to// another instrument track's instrument as well. -1 = off. The destination reads// this while rendering, so it's atomic. One hop only (not transitive).@@ -247,6 +253,7 @@ private:int32_t returnIndex_ = -1; // >=0 for return tracksint32_t groupId_ = -1; // parent Group track id, or -1 (top-level)std::atomic<int32_t> recordInputSource_{0}; // 0 hardware, -1 master, >0 source track id+ std::atomic<bool> monitor_{false}; // live input monitoring (audio tracks)std::atomic<int32_t> midiFromTrackId_{-1}; // -1 off, >0 forward MIDI to this track idstd::atomic<bool> frozen_{false}; // M7: play frozenBuf instead of the live chain};diff --git a/src/native/nota.engine/src/nota_engine_track.cpp b/src/native/nota.engine/src/nota_engine_track.cppindex 3385af1d..9e19ccca 100644--- a/src/native/nota.engine/src/nota_engine_track.cpp+++ b/src/native/nota.engine/src/nota_engine_track.cpp@@ -501,6 +501,17 @@ NotaResult nota_track_set_record_input(NotaEngine* e, int32_t track_id, int32_tint32_t nota_track_get_record_input(NotaEngine* e, int32_t track_id) {return e ? CENG(e)->trackRecordInput(track_id) : 0;}+NotaResult nota_track_set_monitor(NotaEngine* e, int32_t track_id, int32_t on) {+ if (!e) return NOTA_ERR_INVALID_ARG;+ ENG(e)->setTrackMonitor(track_id, on != 0);+ return NOTA_OK;+}+int32_t nota_track_get_monitor(NotaEngine* e, int32_t track_id) {+ return (e && CENG(e)->trackMonitor(track_id)) ? 1 : 0;+}+void nota_engine_push_monitor_frames(NotaEngine* e, const float* interleaved_stereo, int32_t frames) {+ if (e && interleaved_stereo && frames > 0) ENG(e)->pushMonitorFramesForTest(interleaved_stereo, frames);+}NotaResult nota_track_set_midi_source(NotaEngine* e, int32_t track_id, int32_t source_track_id) {if (!e) return NOTA_ERR_INVALID_ARG;ENG(e)->setTrackMidiSource(track_id, source_track_id);diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex 27eb9498..51f87c2d 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -10695,6 +10695,72 @@ Console.WriteLine("-- record input project round-trip --");finally { try { if (System.IO.Directory.Exists(dir)) System.IO.Directory.Delete(dir, true); } catch { } }}+// ============ live input monitoring (Monitor "In") ==========================+Console.WriteLine("-- input monitoring --");+{+ using var me = new NotaEngine();+ me.SetBpm(120); me.SetTimeSignature(4, 4);+ int minst = me.AddBassSynthTrack();+ int monClip = me.AddMidiClip(minst, 0, 8);+ me.SetClipNotes(minst, monClip, new[] { new NotaNote(36, 0.0, 8.0, 1.0f) });+ int mon = me.AddAudioTrack();+ me.SetTrackRecordInput(mon, minst); // listen to the synth (no hardware device)+ me.SetTrackSolo(mon, true); // solo the (empty) audio track+ var mbuf = new float[2048 * 2];+ me.Seek(0); me.Play();+ for (int b = 0; b < 4; b++) me.RenderOffline(mbuf, 2048);+ Check(Rms(mbuf, 2048) < 1e-4f, $"soloed empty audio track is silent without monitoring (RMS {Rms(mbuf, 2048):F5})");++ me.SetTrackMonitor(mon, true);+ Check(me.GetTrackMonitor(mon), "monitor flag set");+ me.Seek(0); // retrigger the note (it began while the synth was gated)+ for (int b = 0; b < 4; b++) me.RenderOffline(mbuf, 2048);+ Check(Rms(mbuf, 2048) > 0.001f, $"monitoring track hears its solo-gated source (RMS {Rms(mbuf, 2048):F4})");++ me.SetTrackVolume(mon, 0f); // the signal really flows through its fader+ for (int b = 0; b < 2; b++) me.RenderOffline(mbuf, 2048);+ Check(Rms(mbuf, 2048) < 1e-4f, $"monitored signal follows the track fader (RMS {Rms(mbuf, 2048):F5})");+ me.SetTrackVolume(mon, 1f);++ me.SetTrackRecordInput(mon, -1); // master would feed back: stays silent+ for (int b = 0; b < 4; b++) me.RenderOffline(mbuf, 2048);+ Check(Rms(mbuf, 2048) < 1e-4f, $"master source is not monitored (RMS {Rms(mbuf, 2048):F5})");+ me.StopTransport();++ // Hardware input via the test hook (no capture device): heard with the transport stopped.+ var sine = new float[8192 * 2];+ for (int i = 0; i < 8192; i++) sine[i * 2] = sine[i * 2 + 1] = 0.5f * MathF.Sin(2f * MathF.PI * 440f * i / 44100f);+ me.PushMonitorFramesForTest(sine, 8192);+ me.SetTrackRecordInput(mon, 0);+ me.RenderOffline(mbuf, 2048);+ Check(Rms(mbuf, 2048) > 0.05f, $"hardware input monitored live while stopped (RMS {Rms(mbuf, 2048):F3})");+ me.SetTrackMonitor(mon, false);+ me.RenderOffline(mbuf, 2048);+ Check(Rms(mbuf, 2048) < 1e-4f, $"monitor off silences the input (RMS {Rms(mbuf, 2048):F5})");+}++// ============ input monitoring survives a project round-trip ===============+Console.WriteLine("-- input monitoring project round-trip --");+{+ using var src = new NotaEngine();+ int ms = src.AddBassSynthTrack();+ int mt = src.AddAudioTrack();+ src.SetTrackRecordInput(mt, ms);+ src.SetTrackMonitor(mt, true);+ string dir = Path.Combine(Path.GetTempPath(), "nota-monitor-" + Guid.NewGuid().ToString("N"));+ try+ {+ var w = new System.Collections.Generic.List<string>();+ var doc = ProjectService.Capture(src, new TransportState(120, 1, false, false), w);+ ProjectService.Save(doc, dir, src);+ using var dst = new NotaEngine();+ ProjectService.Apply(ProjectService.Load(dir), dst, dir);+ dst.TryGetTrackInfo(1, out var t1);+ Check(dst.GetTrackMonitor(t1.Id), "monitor state persisted");+ }+ finally { try { if (System.IO.Directory.Exists(dir)) System.IO.Directory.Delete(dir, true); } catch { } }+}+// ============ simultaneous instrument + audio recording ====================Console.WriteLine("-- simultaneous instrument + audio record --");{