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) Device copy, rack undo and grouping, Auto Filter drag, chain scrolling, Modular hints (#293)
Chris Laupama96f58eabfaca
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6306406b..24b99764 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,41 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.## [Unreleased]+### Added+- **Wrap a device in a rack with ⌘G** (nota-daw/nota#257): with a device selected in the chain,+ ⌘G puts it in an Audio Effect Rack in its place, settings and all, and ⌘⇧G takes the devices+ of a one-chain rack back out. Also in the device's right-click menu (**Group into rack** /+ **Ungroup rack**). A device with a sidechain key, automation or CV links stays where it is+ and the status line says why. ⌘G on tracks still groups tracks.++### Fixed+- **Copy, paste and duplicate keep every setting** (nota-daw/nota#238): a pasted device came+ back with only part of its settings (a pasted Compressor at its default threshold and ratio).+ Copy now takes the whole device — every parameter, its state, bypass and sidechain — and+ paste lands right after the selected device, on any track, as one undo step. Duplicating a+ MIDI effect keeps the Arp's CC modulation, Modular's ⌘D keeps everything too, and a+ duplicated track keeps its devices folded as they were.+- **Undo in Drum Rack and Instrument Rack** (nota-daw/nota#236): a sample dropped on a pad,+ a pad's note or name, an added or removed chain or chain device, a chain's instrument and a+ key or velocity zone are now each undoable, and a drop of several samples is one step.+- **Dragging a key range no longer duplicates the Instrument Rack** (nota-daw/nota#202):+ letting go of a key or velocity zone drag in the chain list left a second copy of the rack's+ card in the device chain.+- **Auto Filter's resonance follows the curve drag** (nota-daw/nota#260): dragging the+ response handle set the resonance from the pointer's height, so grabbing the handle at 10 %+ jumped it to about 80 % and dragging down didn't bring it back. The drag now moves the cutoff+ and resonance from where you grabbed them, and a click changes nothing.+- **Scrolling the device chain** (nota-daw/nota#262): the mouse wheel now scrolls the chain+ sideways anywhere over it. EQ-8 and Dynamic EQ-8 take the wheel only over a band's handle+ (to set its Q), and a trackpad swipe over a value box or an EQ steps once per notch of travel+ instead of running the value to its end.+- **Modular is easier to find your way around** (nota-daw/nota#261): the track's input,+ instrument and output nodes show a lock that says why they can't be deleted (Delete on them+ says so too); delete is a bin, not an ×, which read as "close"; an opened node has a+ **Show fewer** strip and Esc closes every opened node; Delete removes a selected modulator;+ an unwired Scope says it watches CV and how to patch it; and the hint names how to draw a+ cable.+## [0.57.1] — 2026-10-22### Addeddiff --git a/FEATURES.md b/FEATURES.mdindex de6a5440..a35b676f 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -911,7 +911,8 @@ audio effects after it keep running and keep their settings; saved with the proj**Nota Kits**, ready to drag anywhere a sample goes.- **Nota Audio Effect Rack** — **Parallel / Series / Select** modes (by input level),Dry/Wet + Gain, PDC, Fold, Save; chains with gain/meter/M·S; named macros and mappings;- the "+ Device" menu lists built-in effects and a Plug-ins submenu.+ the "+ Device" menu lists built-in effects and a Plug-ins submenu. ⌘G on a selected audio+ effect wraps it in a new rack (**Group into rack**); ⌘⇧G puts a one-chain rack's devices back.- Devices inside chains appear as cards with knobs, a **Full** button (the device'scomplete UI in a popup — the native GUI for a plugin, the tabbed editor for theSampler), a ✕ delete button, and drag-to-reorder.diff --git a/src/managed/Nota.App/Controls/AutoFilterCurve.cs b/src/managed/Nota.App/Controls/AutoFilterCurve.csindex 5852b7fd..fbaea776 100644--- a/src/managed/Nota.App/Controls/AutoFilterCurve.cs+++ b/src/managed/Nota.App/Controls/AutoFilterCurve.cs@@ -39,6 +39,8 @@ internal sealed class AutoFilterCurve : Controlprivate float _morph;private bool _slope24;private bool _drag;+ private Point _grab;+ private double _fc0, _res0; // the settings when the drag beganprivate double _liveCut = 0.5, _liveRes; // live modulated cutoff / resonance (normalized)private double _rangeLo = 0.5, _rangeHi = 0.5; // where the modulation can take the cutoffprivate bool _modAssigned;@@ -110,9 +112,9 @@ internal sealed class AutoFilterCurve : Control{if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;_drag = true;+ _grab = e.GetPosition(this); _fc0 = _fcNorm; _res0 = _res;GestureBegin?.Invoke();e.Pointer.Capture(this);- Apply(e.GetPosition(this));e.Handled = true;}@@ -136,12 +138,18 @@ internal sealed class AutoFilterCurve : Controlbase.OnPointerCaptureLost(e);}+ // The drag moves the settings from where they were when grabbed, so a click changes nothing.+ // The handle sits on the curve's peak, which isn't linear in resonance (and doesn't move at+ // all for band-pass), so resonance can't come from the pointer's height as it used to: a grab+ // at 10 % jumped it to ~80 %, and dragging down to where a low peak would be still left it+ // above 50 % — the resonance looked stuck (#260). Up raises it, the full range over 80 % of+ // the height; sideways moves the cutoff with the pointer, as the handle's x is linear in it.private void Apply(Point p){double w = Bounds.Width, h = Bounds.Height;if (w <= 0 || h <= 0) return;- _fcNorm = Math.Clamp(p.X / w, 0, 1);- _res = Math.Clamp(1 - p.Y / h, 0, 1);+ _fcNorm = Math.Clamp(_fc0 + (p.X - _grab.X) / w, 0, 1);+ _res = Math.Clamp(_res0 + (_grab.Y - p.Y) / (h * 0.8), 0, 1);CutoffChanged?.Invoke(_fcNorm);ResChanged?.Invoke(_res);InvalidateVisual();diff --git a/src/managed/Nota.App/Controls/DynamicEqCurve.cs b/src/managed/Nota.App/Controls/DynamicEqCurve.csindex 76e52fdf..968e7869 100644--- a/src/managed/Nota.App/Controls/DynamicEqCurve.cs+++ b/src/managed/Nota.App/Controls/DynamicEqCurve.cs@@ -268,12 +268,14 @@ public sealed class DynamicEqCurve : Controlprotected override void OnPointerWheelChanged(PointerWheelEventArgs e){base.OnPointerWheelChanged(e);+ // Only over a band's handle, and only a vertical wheel: anywhere else the wheel scrolls the+ // device chain. It used to take every event over the graph for the selected band, and a+ // trackpad's stream of pixel-sized events sent its Q to the end in one swipe (#262).int b = Hit(e.GetPosition(this));- if (b < 0) b = _selected;+ if (b < 0 || !WheelInput.IsVertical(e)) return;SelectedBand = b;bool fine = (e.KeyModifiers & (KeyModifiers.Shift | KeyModifiers.Control | KeyModifiers.Meta)) != 0;- double step = fine ? 1.03 : 1.15;- double q = Math.Clamp(P(b, DynEq.QF) * (e.Delta.Y > 0 ? step : 1 / step), 0.1, 18);+ double q = Math.Clamp(P(b, DynEq.QF) * WheelInput.ZoomFactor(e.Delta.Y, fine ? 1.03 : 1.15), 0.1, 18);Gesture(DynEq.P(b, DynEq.QF), () => SetP(b, DynEq.QF, q));Edited?.Invoke(); InvalidateVisual();e.Handled = true;diff --git a/src/managed/Nota.App/Controls/Eq8Views.cs b/src/managed/Nota.App/Controls/Eq8Views.csindex 3082ce68..ed2fa7a9 100644--- a/src/managed/Nota.App/Controls/Eq8Views.cs+++ b/src/managed/Nota.App/Controls/Eq8Views.cs@@ -274,12 +274,14 @@ public sealed class Eq8Curve : Controlprotected override void OnPointerWheelChanged(PointerWheelEventArgs e){base.OnPointerWheelChanged(e);+ // Only over a band's handle, and only a vertical wheel: anywhere else the wheel scrolls the+ // device chain. It used to take every event over the graph for the selected band, and a+ // trackpad's stream of pixel-sized events sent its Q to the end in one swipe (#262).int b = Hit(e.GetPosition(this));- if (b < 0) b = _selected;+ if (b < 0 || !WheelInput.IsVertical(e)) return;SelectedBand = b;bool fine = (e.KeyModifiers & (KeyModifiers.Shift | KeyModifiers.Control | KeyModifiers.Meta)) != 0;- double step = fine ? 1.03 : 1.15;- double q = Math.Clamp(P(b, Eq8.QF) * (e.Delta.Y > 0 ? step : 1 / step), 0.1, 18);+ double q = Math.Clamp(P(b, Eq8.QF) * WheelInput.ZoomFactor(e.Delta.Y, fine ? 1.03 : 1.15), 0.1, 18);Gesture(Eq8.P(b, Eq8.QF), () => SetP(b, Eq8.QF, q));Edited?.Invoke(); InvalidateVisual();e.Handled = true;diff --git a/src/managed/Nota.App/Controls/LensViews.cs b/src/managed/Nota.App/Controls/LensViews.csindex 51715a20..1f31cbe4 100644--- a/src/managed/Nota.App/Controls/LensViews.cs+++ b/src/managed/Nota.App/Controls/LensViews.cs@@ -620,7 +620,8 @@ internal sealed class LensVSlider : Control}protected override void OnPointerWheelChanged(PointerWheelEventArgs e){- Value = _value + e.Delta.Y * 0.02;+ if (!WheelInput.IsVertical(e)) return;+ Value = _value + WheelInput.Notches(e.Delta.Y) * 0.02;ValueChanged?.Invoke(_value);e.Handled = true;}diff --git a/src/managed/Nota.App/Controls/RhythmViews.cs b/src/managed/Nota.App/Controls/RhythmViews.csindex ad47b912..d329fae5 100644--- a/src/managed/Nota.App/Controls/RhythmViews.cs+++ b/src/managed/Nota.App/Controls/RhythmViews.cs@@ -392,9 +392,9 @@ internal sealed class RhythmStepStrip : Controlprotected override void OnPointerWheelChanged(PointerWheelEventArgs e){int s = StepAt(e.GetPosition(this).X);- if (!On[s]) return;- Put(s, true, (float)Math.Clamp(Vel[s] + (e.Delta.Y > 0 ? 0.05 : -0.05), 0.05, 1.0), Acc[s]);+ if (!On[s] || WheelInput.Step(e) is not { } dir) return;e.Handled = true;+ if (dir != 0) Put(s, true, (float)Math.Clamp(Vel[s] + dir * 0.05, 0.05, 1.0), Acc[s]);}public override void Render(DrawingContext ctx)diff --git a/src/managed/Nota.App/DeviceCards/Bodies/ValveDeviceBody.cs b/src/managed/Nota.App/DeviceCards/Bodies/ValveDeviceBody.csindex 34185058..20246e56 100644--- a/src/managed/Nota.App/DeviceCards/Bodies/ValveDeviceBody.cs+++ b/src/managed/Nota.App/DeviceCards/Bodies/ValveDeviceBody.cs@@ -251,8 +251,10 @@ internal sealed class ValveDeviceBody : IDeviceBody};box.PointerWheelChanged += (_, e) =>{- int m = Math.Clamp(Idx(p) + (e.Delta.Y < 0 ? 1 : -1), 0, names.Length - 1);- SetP(p, m); RefreshAll(); e.Handled = true;+ if (WheelInput.Step(e) is not { } s) return;+ e.Handled = true; if (s == 0) return;+ int m = Math.Clamp(Idx(p) - s, 0, names.Length - 1);+ SetP(p, m); RefreshAll();};return box;}diff --git a/src/managed/Nota.App/DeviceCards/Bodies/VintageDeviceBody.cs b/src/managed/Nota.App/DeviceCards/Bodies/VintageDeviceBody.csindex ea4acac2..7f2eb2da 100644--- a/src/managed/Nota.App/DeviceCards/Bodies/VintageDeviceBody.cs+++ b/src/managed/Nota.App/DeviceCards/Bodies/VintageDeviceBody.cs@@ -239,8 +239,10 @@ internal sealed class VintageDeviceBody : IDeviceBody};box.PointerWheelChanged += (_, e) =>{- int m = Math.Clamp(Sel(Mode, 6) + (e.Delta.Y < 0 ? 1 : -1), 0, 5);- SetP(Mode, m / 5f); RefreshAll(); e.Handled = true;+ if (WheelInput.Step(e) is not { } s) return;+ e.Handled = true; if (s == 0) return;+ int m = Math.Clamp(Sel(Mode, 6) - s, 0, 5);+ SetP(Mode, m / 5f); RefreshAll();};return box;}diff --git a/src/managed/Nota.App/DeviceCards/Instruments/GrainInstrumentCard.cs b/src/managed/Nota.App/DeviceCards/Instruments/GrainInstrumentCard.csindex 5df082c0..ef64c9bf 100644--- a/src/managed/Nota.App/DeviceCards/Instruments/GrainInstrumentCard.cs+++ b/src/managed/Nota.App/DeviceCards/Instruments/GrainInstrumentCard.cs@@ -310,7 +310,7 @@ internal sealed class GrainInstrumentCard : IInstrumentCardHeight = 17, MinWidth = 40, CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1), BorderBrush = BorderDef,Background = NotaPalette.BgSunken, Child = text,};- box.PointerWheelChanged += (_, e) => { SetRoot(rootNote + (e.Delta.Y > 0 ? 1 : -1)); e.Handled = true; };+ box.PointerWheelChanged += (_, e) => { if (WheelInput.Step(e) is not { } s) return; e.Handled = true; if (s != 0) SetRoot(rootNote + s); };// Double-click: the note the file name names, else C4.box.DoubleTapped += (_, e) => { SetRoot(SamplerModel.DetectRoot(sampleName) is var d and >= 0 ? d : 60); e.Handled = true; };ToolTip.SetTip(box, "The root — the key that plays the sample as recorded. Scroll to step it · double-click takes it from the file name (C4 if none)");diff --git a/src/managed/Nota.App/DeviceCards/Instruments/MosaicInstrumentCard.cs b/src/managed/Nota.App/DeviceCards/Instruments/MosaicInstrumentCard.csindex 43254ee9..985924ae 100644--- a/src/managed/Nota.App/DeviceCards/Instruments/MosaicInstrumentCard.cs+++ b/src/managed/Nota.App/DeviceCards/Instruments/MosaicInstrumentCard.cs@@ -300,7 +300,12 @@ internal sealed class MosaicInstrumentCard : IInstrumentCard};b.PointerReleased += (_, e) => { if (!drag) return; drag = false; e.Pointer.Capture(null); done?.Invoke(); };b.PointerCaptureLost += (_, _) => { if (!drag) return; drag = false; done?.Invoke(); };- b.PointerWheelChanged += (_, e) => { step(e.Delta.Y > 0 ? 1 : -1); tb.Text = text(); done?.Invoke(); Refresh(); e.Handled = true; };+ b.PointerWheelChanged += (_, e) =>+ {+ if (WheelInput.Step(e) is not { } s) return;+ e.Handled = true; if (s == 0) return;+ step(s); tb.Text = text(); done?.Invoke(); Refresh();+ };readouts.Add(() => { if (!drag) tb.Text = text(); });if (tip is not null) ToolTip.SetTip(b, tip);return b;diff --git a/src/managed/Nota.App/DeviceCards/Instruments/PendulumInstrumentCard.cs b/src/managed/Nota.App/DeviceCards/Instruments/PendulumInstrumentCard.csindex 56825cbb..25f8787a 100644--- a/src/managed/Nota.App/DeviceCards/Instruments/PendulumInstrumentCard.cs+++ b/src/managed/Nota.App/DeviceCards/Instruments/PendulumInstrumentCard.cs@@ -476,9 +476,11 @@ internal sealed class PendulumInstrumentCard : IInstrumentCard};scaleBox.PointerWheelChanged += (_, e) =>{+ if (WheelInput.Step(e) is not { } s) return;+ e.Handled = true; if (s == 0) return;int n = PendulumModel.ModeNames.Length;- int m = Math.Clamp(Sel("scalemode", n) + (e.Delta.Y < 0 ? 1 : -1), 0, n - 1);- Write("scalemode", m / (float)(n - 1)); Refresh(); e.Handled = true;+ int m = Math.Clamp(Sel("scalemode", n) - s, 0, n - 1);+ Write("scalemode", m / (float)(n - 1)); Refresh();};if (I("scalemode") is var smi and >= 0) MidiLearn.Bind(scaleBox, MidiTarget.PluginParam(track, -1, smi), engine.PluginParamName(track, -1, smi));var scaleRow = Row((Cap("SCALE"), "Auto"), (scaleBox, "*"));diff --git a/src/managed/Nota.App/DeviceCards/Instruments/SamplerInstrumentCard.cs b/src/managed/Nota.App/DeviceCards/Instruments/SamplerInstrumentCard.csindex 0cb57baa..662cbe42 100644--- a/src/managed/Nota.App/DeviceCards/Instruments/SamplerInstrumentCard.cs+++ b/src/managed/Nota.App/DeviceCards/Instruments/SamplerInstrumentCard.cs@@ -294,7 +294,12 @@ internal sealed class SamplerInstrumentCard : IInstrumentCardHeight = 17, MinWidth = 40, CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1), BorderBrush = BorderDef,Background = NotaPalette.BgSunken, Child = rootText,};- rootBox.PointerWheelChanged += (_, e) => { rootv = Math.Clamp(rootv + (e.Delta.Y > 0 ? 1 : -1), 0, 127); acc.SetRoot(rootv); Refresh(); e.Handled = true; };+ rootBox.PointerWheelChanged += (_, e) =>+ {+ if (WheelInput.Step(e) is not { } s) return;+ e.Handled = true; if (s == 0) return;+ rootv = Math.Clamp(rootv + s, 0, 127); acc.SetRoot(rootv); Refresh();+ };ToolTip.SetTip(rootBox, "The root note — scroll to step it");var rootStepper = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 4, Children = { StepBtn(GlyphKind.Minus, -1, "Root a semitone down"), rootBox, StepBtn(GlyphKind.Plus, +1, "Root a semitone up") } };int detected = SamplerModel.DetectRoot(sampleName);diff --git a/src/managed/Nota.App/DeviceCards/Midi/ChordMidiBody.cs b/src/managed/Nota.App/DeviceCards/Midi/ChordMidiBody.csindex 586c50b9..a07a3a44 100644--- a/src/managed/Nota.App/DeviceCards/Midi/ChordMidiBody.cs+++ b/src/managed/Nota.App/DeviceCards/Midi/ChordMidiBody.cs@@ -407,7 +407,7 @@ internal sealed class ChordMidiBody : IMidiDeviceBodyif (!ev.GetCurrentPoint(keyTb).Properties.IsLeftButtonPressed) return;StepKey(ev.KeyModifiers.HasFlag(KeyModifiers.Shift) ? -1 : 1); ev.Handled = true;};- keyTb.PointerWheelChanged += (_, ev) => { StepKey(ev.Delta.Y > 0 ? 1 : -1); ev.Handled = true; };+ keyTb.PointerWheelChanged += (_, ev) => { if (WheelInput.Step(ev) is not { } s) return; ev.Handled = true; if (s != 0) StepKey(s); };modeTb.PointerPressed += (_, ev) =>{if (!ev.GetCurrentPoint(modeTb).Properties.IsLeftButtonPressed) return;diff --git a/src/managed/Nota.App/DeviceCards/Midi/ScaleMidiBody.cs b/src/managed/Nota.App/DeviceCards/Midi/ScaleMidiBody.csindex 48ffc000..9cb10499 100644--- a/src/managed/Nota.App/DeviceCards/Midi/ScaleMidiBody.cs+++ b/src/managed/Nota.App/DeviceCards/Midi/ScaleMidiBody.cs@@ -351,7 +351,7 @@ internal sealed class ScaleMidiBody : IMidiDeviceBodyreadouts.Add(() => name.Text = Notes[Root()]);var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2, VerticalAlignment = VerticalAlignment.Center, Background = Brushes.Transparent,Children = { Arrow(GlyphKind.ChevronLeft, -1), name, Arrow(GlyphKind.ChevronRight, 1) } };- row.PointerWheelChanged += (_, ev) => { StepRoot(ev.Delta.Y > 0 ? 1 : -1); ev.Handled = true; };+ row.PointerWheelChanged += (_, ev) => { if (WheelInput.Step(ev) is not { } s) return; ev.Handled = true; if (s != 0) StepRoot(s); };ToolTip.SetTip(row, "Root — click the arrows or scroll");Learn(row, PRoot, "Root");return row;@@ -395,8 +395,10 @@ internal sealed class ScaleMidiBody : IMidiDeviceBody};box.PointerWheelChanged += (_, ev) =>{+ if (WheelInput.Step(ev) is not { } s) return;+ ev.Handled = true; if (s == 0) return;int at = Array.IndexOf(TypeRows, Sc()); if (at < 0) at = TypeRows.Length - 1;- PickType(TypeRows[Math.Clamp(at + (ev.Delta.Y < 0 ? 1 : -1), 0, TypeRows.Length - 1)]); ev.Handled = true;+ PickType(TypeRows[Math.Clamp(at - s, 0, TypeRows.Length - 1)]);};ToolTip.SetTip(box, "Scale type");Learn(box, PScale, "Scale");@@ -431,7 +433,7 @@ internal sealed class ScaleMidiBody : IMidiDeviceBodyvoid Stop() { if (!drag) return; drag = false; End(p); }valHit.PointerReleased += (_, ev) => { if (drag) ev.Pointer.Capture(null); Stop(); };valHit.PointerCaptureLost += (_, _) => Stop();- valHit.PointerWheelChanged += (_, ev) => { Begin(p); Put(Get() + (ev.Delta.Y > 0 ? 1 : -1)); End(p); ev.Handled = true; };+ valHit.PointerWheelChanged += (_, ev) => { if (WheelInput.Step(ev) is not { } s) return; ev.Handled = true; if (s != 0) { Begin(p); Put(Get() + s); End(p); } };readouts.Add(() => val.Text = DeviceCardKit.NoteName(Get()));var box = new Border{diff --git a/src/managed/Nota.App/DeviceCards/PluginCard.cs b/src/managed/Nota.App/DeviceCards/PluginCard.csindex 5786a75a..42554ace 100644--- a/src/managed/Nota.App/DeviceCards/PluginCard.cs+++ b/src/managed/Nota.App/DeviceCards/PluginCard.cs@@ -279,7 +279,7 @@ internal static class PluginCard// The page holds as many knobs as the section fits; wheel over it turns the page.var body = new Border { Background = Brushes.Transparent, Padding = new Thickness(0, 4, 0, 0), Child = host };- body.PointerWheelChanged += (_, ev) => { Step(ev.Delta.Y < 0 ? +1 : -1); ev.Handled = true; };+ body.PointerWheelChanged += (_, ev) => { if (WheelInput.Step(ev) is not { } s) return; ev.Handled = true; if (s != 0) Step(-s); };body.SizeChanged += (_, ev) =>{int cols = Math.Max(1, (int)(ev.NewSize.Width / CellW));diff --git a/src/managed/Nota.App/DeviceCards/Rack/RackCardView.Drum.cs b/src/managed/Nota.App/DeviceCards/Rack/RackCardView.Drum.csindex 13ccfa98..b3ed3d78 100644--- a/src/managed/Nota.App/DeviceCards/Rack/RackCardView.Drum.cs+++ b/src/managed/Nota.App/DeviceCards/Rack/RackCardView.Drum.cs@@ -292,8 +292,11 @@ internal sealed partial class RackCardViewpad.BorderBrush = restBorder;var items = BrowserView.DroppedItems(e);if (items.Count == 0) return;- // Several samples fill this pad and the ones after it, up to the bank's last.- for (int i = 0; i < items.Count && note + i < BankBase + 16; i++) DropOnPad(a, note + i, items[i]);+ // Several samples fill this pad and the ones after it, up to the bank's last; the+ // whole drop is one undo step (#236).+ E.BeginUndoGroup();+ try { for (int i = 0; i < items.Count && note + i < BankBase + 16; i++) DropOnPad(a, note + i, items[i]); }+ finally { E.EndUndoGroup(); }e.Handled = true;});return pad;@@ -752,6 +755,14 @@ internal sealed partial class RackCardView// A browser item dropped on a specific pad: sample → a Sampler on this note; instrument// → that instrument on this note. Either replaces what the pad held.private void DropOnPad(IRackAccess a, int note, Nota.Presentation.BrowserItem item)+ {+ // Remove + add + note + name is one gesture: one undo step (#236).+ E.BeginUndoGroup();+ try { DropOnPadSteps(a, note, item); }+ finally { E.EndUndoGroup(); }+ }++ private void DropOnPadSteps(IRackAccess a, int note, Nota.Presentation.BrowserItem item){int existing = ChainForNote(a, note);int added;@@ -813,8 +824,10 @@ internal sealed partial class RackCardViewvar mi = new MenuItem { Header = header };mi.Click += (_, _) =>{+ E.BeginUndoGroup(); // the chain and its note: one undo stepint c = a.AddChain(kind);if (c >= 0) { a.SetChainTriggerNote(c, note); Sel = c; }+ E.EndUndoGroup();_ctx.NotifyChanged();DeferRebuild();};diff --git a/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs b/src/managed/Nota.App/DeviceCards/Rack/RackCardView.csindex 32b0cf49..e8394338 100644--- a/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs+++ b/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs@@ -364,7 +364,7 @@ internal sealed partial class RackCardView(DeviceCardContext ctx)E.RackChainZone(T, c, out int kLo, out int kHi, out int vLo, out int vHi);if (_splitAxis == 0) E.RackSetChainZone(T, c, lo, hi, vLo, vHi);else E.RackSetChainZone(T, c, kLo, kHi, lo, hi);- _ctx.RequestRebuild();+ DeferRebuild(); // not from inside the map's own pointer handler (#202)};return new Border { Height = 38, Background = IrInset, BorderBrush = IrField, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Panel, Padding = new Thickness(4), Margin = new Thickness(0, 5, 0, 0), Child = map };}@@ -915,7 +915,7 @@ internal sealed partial class RackCardView(DeviceCardContext ctx)var los = new int[n]; var his = new int[n]; var cols = new IBrush[n];for (int c = 0; c < n; c++) { E.RackDevChainZone(T, di, c, out int lo, out int hi); los[c] = lo; his[c] = hi; cols[c] = ChainHue(c); }var map = new RackZoneMap(los, his, cols, Sel, keyMode: false);- map.RangeEdited += (c, lo, hi) => { E.RackDevSetChainZone(T, di, c, lo, hi); _ctx.RequestRebuild(); };+ map.RangeEdited += (c, lo, hi) => { E.RackDevSetChainZone(T, di, c, lo, hi); DeferRebuild(); };bool follow = E.RackDevSelFollow(T, di);var marker = new Border { Width = 1.5, Background = IrAmberLit, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Stretch };var mapHost = new Panel { Children = { map, marker } };@@ -1667,12 +1667,26 @@ internal sealed class RackZoneMap : Controle.Pointer.Capture(this); Apply(x); e.Handled = true;}protected override void OnPointerMoved(PointerEventArgs e) { if (_drag >= 0) Apply(e.GetPosition(this).X); }+ // The drag ends before the edit is reported: the handler rebuilds the device chain, which+ // takes this map out of the tree, and a drag still open then would report again from the+ // capture loss, inside that rebuild — leaving a second copy of the rack card (#202).protected override void OnPointerReleased(PointerReleasedEventArgs e)- { if (_drag >= 0) { RangeEdited?.Invoke(_drag, _lo[_drag], _hi[_drag]); _drag = -1; InvalidateVisual(); e.Pointer.Capture(null); } }+ {+ if (_drag < 0) return;+ int c = _drag; _drag = -1;+ e.Pointer.Capture(null); InvalidateVisual();+ RangeEdited?.Invoke(c, _lo[c], _hi[c]);+ }// Capture taken away mid-drag (the window deactivates): commit the range as it stands and drop the accent.protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)- { if (_drag >= 0) { RangeEdited?.Invoke(_drag, _lo[_drag], _hi[_drag]); _drag = -1; InvalidateVisual(); } base.OnPointerCaptureLost(e); }+ {+ base.OnPointerCaptureLost(e);+ if (_drag < 0) return;+ int c = _drag; _drag = -1;+ InvalidateVisual();+ RangeEdited?.Invoke(c, _lo[c], _hi[c]);+ }private void Apply(double x){diff --git a/src/managed/Nota.App/DeviceChainView.Clipboard.cs b/src/managed/Nota.App/DeviceChainView.Clipboard.csindex b859c042..b80005b9 100644--- a/src/managed/Nota.App/DeviceChainView.Clipboard.cs+++ b/src/managed/Nota.App/DeviceChainView.Clipboard.cs@@ -41,15 +41,13 @@ public sealed partial class DeviceChainView=> HasDeviceSelection && _selChainKind == kind && _selDeviceIndex == index;// ---- clipboard --------------------------------------------------------+ // The device itself is copied by the engine (#238): a full clone with every parameter,+ // its state blob, bypass and sidechain key (a rack or plug-in copies itself), so a paste+ // has the source's settings even after the source was cut or changed. Only what the UI+ // owns rides here: the domain and the card's preset label.private sealed class DeviceClip{public ChainKind Kind;- public int BuiltinKind; // effect: >=0 built-in, <0 hosted plugin- public string PluginId = ""; // hosted-plugin identity (recreated via the catalog)- public byte[]? State; // built-in device state / plugin state blob- public int MidiKind; // MIDI effect kind- public float[]? MidiParams; // MIDI effect param snapshot- public bool Bypassed;public string Preset = "", PresetId = ""; // the source card's preset label follows the paste}private DeviceClip? _clip;@@ -58,22 +56,15 @@ public sealed partial class DeviceChainView{if (!HasDeviceSelection) return;int di = _selDeviceIndex;- if (_selChainKind == ChainKind.Effect)+ bool ok = _selChainKind switch{- int kind = _engine.TrackDeviceBuiltinKind(_trackId, di);- var c = new DeviceClip { Kind = ChainKind.Effect, BuiltinKind = kind, Bypassed = _engine.DeviceBypassed(_trackId, di) };- if (kind >= 0) c.State = _engine.DeviceGetState(_trackId, di);- else { c.PluginId = _engine.TrackDevicePluginId(_trackId, di); c.State = _engine.GetPluginState(_trackId, di); }- _clip = c;- }- else if (_selChainKind == ChainKind.Midi)- {- int n = _engine.MidiEffectParamCount(_trackId, di);- var p = new float[n];- for (int i = 0; i < n; i++) p[i] = _engine.MidiEffectGetParam(_trackId, di, i);- _clip = new DeviceClip { Kind = ChainKind.Midi, MidiKind = _engine.MidiEffectKind(_trackId, di), MidiParams = p, Bypassed = _engine.MidiEffectBypassed(_trackId, di) };- }- if (_clip != null) { var ex = Extra(_selChainKind, di); _clip.Preset = ex.Preset; _clip.PresetId = ex.PresetId; }+ ChainKind.Effect => _engine.CopyDevice(_trackId, di),+ ChainKind.Midi => _engine.CopyMidiEffect(_trackId, di),+ _ => false,+ };+ if (!ok) return;+ var ex = Extra(_selChainKind, di);+ _clip = new DeviceClip { Kind = _selChainKind, Preset = ex.Preset, PresetId = ex.PresetId };}private void DeleteSelectedDevice()@@ -94,55 +85,75 @@ public sealed partial class DeviceChainView{if (_clip is null || _trackId <= 0) return;var c = _clip;- int newIdx = -1;- if (c.Kind == ChainKind.Effect)+ if (c.Kind != ChainKind.Effect && c.Kind != ChainKind.Midi) return;+ // Drop it right after the selected device of the same domain, else at the end.+ int at = _selChainKind == c.Kind && _selDeviceIndex >= 0 ? _selDeviceIndex + 1 : -1;+ int end = c.Kind == ChainKind.Midi ? _engine.TrackMidiEffectCount(_trackId) : _engine.TrackDeviceCount(_trackId);+ if (at > end) at = -1;+ int newIdx = c.Kind == ChainKind.Midi ? _engine.PasteMidiEffect(_trackId, at) : _engine.PasteDevice(_trackId, at);+ if (newIdx < 0) return;+ // A fresh slot: drop any stale entry, and let the extras after it shift up with their devices.+ if (newIdx < end) ExtrasMoved(c.Kind, end, newIdx);+ TrackExtras().Remove(ExtraKey(c.Kind, newIdx));+ var pasted = Extra(c.Kind, newIdx); pasted.Preset = c.Preset; pasted.PresetId = c.PresetId;+ _selChainKind = c.Kind;+ _selDeviceIndex = newIdx;+ Rebuild(); Changed?.Invoke();+ }++ // ---- ⌘G / ⌘⇧G: wrap the selected device in a rack / unwrap it (#257) ----+ // With the Devices panel focused these act on the device, never on the tracks: grouping+ // tracks stays ⌘G in the arrangement and the track headers.+ private bool SelectedIsRack => _selChainKind == ChainKind.Effect && _selDeviceIndex >= 0+ && _engine.TrackDeviceBuiltinKind(_trackId, _selDeviceIndex) == 5;++ private void GroupSelectedDevice()+ {+ if (!HasDeviceSelection) { StatusMessage?.Invoke("Select an audio effect to put it in a rack"); return; }+ if (_selChainKind == ChainKind.Midi) { StatusMessage?.Invoke("MIDI effects can't go in a rack"); return; }+ int di = _selDeviceIndex;+ string name = _engine.DeviceName(_trackId, di);+ if (_engine.WrapDeviceInRack(_trackId, di) < 0){- if (c.BuiltinKind >= 0)- {- newIdx = _engine.AddBuiltinDevice(_trackId, c.BuiltinKind);- if (newIdx >= 0 && c.State != null) _engine.DeviceSetState(_trackId, newIdx, c.State);- }- else if (_catalog != null && c.PluginId.Length > 0)- {- int cat = _catalog.IndexOfId(c.PluginId);- if (cat >= 0)- {- newIdx = _engine.AddTrackEffectPlugin(_trackId, cat);- if (newIdx >= 0 && c.State != null) _engine.SetPluginState(_trackId, newIdx, c.State);- }- }- if (newIdx < 0) return;- if (c.Bypassed) _engine.SetDeviceBypassed(_trackId, newIdx, true);- TrackExtras().Remove(ExtraKey(ChainKind.Effect, newIdx)); // a fresh slot: drop any stale entry- // Drop it right after the selected effect, else leave it appended.- if (_selChainKind == ChainKind.Effect && _selDeviceIndex >= 0 && _selDeviceIndex < newIdx)- { int to = _selDeviceIndex + 1; _engine.MoveDevice(_trackId, newIdx, to); ExtrasMoved(ChainKind.Effect, newIdx, to); newIdx = to; }- _selChainKind = ChainKind.Effect;+ StatusMessage?.Invoke($"{name} can't go in a rack: it has a sidechain key, automation or a modulation link");+ return;}- else if (c.Kind == ChainKind.Midi)+ TrackExtras().Remove(ExtraKey(ChainKind.Effect, di)); // its preset label stays with the device, now in the chain+ StatusMessage?.Invoke($"Put {name} in an Audio Effect Rack");+ Rebuild(); Changed?.Invoke();+ }++ private void UngroupSelectedDevice()+ {+ if (!SelectedIsRack) { StatusMessage?.Invoke("Select an Audio Effect Rack to take its devices out"); return; }+ int di = _selDeviceIndex;+ int end = _engine.TrackDeviceCount(_trackId);+ int n = _engine.UnwrapRack(_trackId, di);+ if (n < 0){- newIdx = _engine.AddMidiEffect(_trackId, c.MidiKind);- if (newIdx < 0) return;- if (c.MidiParams != null)- {- int n = Math.Min(c.MidiParams.Length, _engine.MidiEffectParamCount(_trackId, newIdx));- for (int i = 0; i < n; i++) _engine.MidiEffectSetParam(_trackId, newIdx, i, c.MidiParams[i]);- }- if (c.Bypassed) _engine.SetMidiEffectBypassed(_trackId, newIdx, true);- TrackExtras().Remove(ExtraKey(ChainKind.Midi, newIdx));- if (_selChainKind == ChainKind.Midi && _selDeviceIndex >= 0 && _selDeviceIndex < newIdx)- { int to = _selDeviceIndex + 1; _engine.MoveMidiEffect(_trackId, newIdx, to); ExtrasMoved(ChainKind.Midi, newIdx, to); newIdx = to; }- _selChainKind = ChainKind.Midi;+ StatusMessage?.Invoke("Only a rack with one chain can be ungrouped, and not while it is automated or modulated");+ return;}- else return;- var pasted = Extra(c.Kind, newIdx); pasted.Preset = c.Preset; pasted.PresetId = c.PresetId;- _selDeviceIndex = newIdx;+ // The rack's slot becomes its n devices; the cards after it shift with them.+ if (n == 0) ExtrasRemoved(ChainKind.Effect, di);+ else+ {+ TrackExtras().Remove(ExtraKey(ChainKind.Effect, di));+ for (int i = 1; i < n; i++) ExtrasMoved(ChainKind.Effect, end - 1 + i, di + i);+ }+ _selDeviceIndex = n > 0 ? di : -1;+ StatusMessage?.Invoke(n == 1 ? "Took the device out of the rack" : $"Took {n} devices out of the rack");Rebuild(); Changed?.Invoke();}protected override void OnKeyDown(KeyEventArgs e){bool mod = (e.KeyModifiers & (KeyModifiers.Meta | KeyModifiers.Control)) != 0;+ if (mod && e.Key == Key.G && (e.KeyModifiers & KeyModifiers.Alt) == 0)+ {+ if ((e.KeyModifiers & KeyModifiers.Shift) != 0) UngroupSelectedDevice(); else GroupSelectedDevice();+ e.Handled = true; return;+ }if (mod && e.Key == Key.C && HasDeviceSelection) { CopySelectedDevice(); e.Handled = true; return; }if (mod && e.Key == Key.X && HasDeviceSelection) { CutSelectedDevice(); e.Handled = true; return; }if (mod && e.Key == Key.V && _clip != null) { PasteDevice(); e.Handled = true; return; }@@ -181,6 +192,14 @@ public sealed partial class DeviceChainViewMenuKit.Item("Cut", GlyphKind.Cut, CutSelectedDevice, MenuKit.CutKey, selectable),MenuKit.Item("Paste", GlyphKind.Paste, PasteDevice, MenuKit.PasteKey, _clip != null),},+ kind == ChainKind.Effect+ ? new Control[]+ {+ _engine.TrackDeviceBuiltinKind(_trackId, di) == 5+ ? MenuKit.Item("Ungroup rack", GlyphKind.Ungroup, UngroupSelectedDevice, MenuKit.UngroupKey, _engine.RackDevChainCount(_trackId, di) == 1)+ : MenuKit.Item("Group into rack", GlyphKind.Folder, GroupSelectedDevice, MenuKit.GroupKey),+ }+ : Array.Empty<Control>(),new Control[] { MenuKit.Danger("Delete", GlyphKind.Trash, DeleteSelectedDevice, MenuKit.DeleteKey, selectable) });flyout.ShowAt(anchor, showAtPointer: true);}diff --git a/src/managed/Nota.App/DeviceChainView.cs b/src/managed/Nota.App/DeviceChainView.csindex 576dbe1e..2e15dd2e 100644--- a/src/managed/Nota.App/DeviceChainView.cs+++ b/src/managed/Nota.App/DeviceChainView.cs@@ -103,6 +103,17 @@ public sealed partial class DeviceChainView : UserControlHorizontalScrollBarVisibility = ScrollBarVisibility.Auto,VerticalScrollBarVisibility = ScrollBarVisibility.Disabled,};+ // The chain only scrolls sideways, and the scroller ignores a plain (vertical) mouse wheel,+ // so a wheel no card control took moves the chain instead of doing nothing (#262).+ scroller.PointerWheelChanged += (_, e) =>+ {+ if (e.Handled || !WheelInput.IsVertical(e)) return;+ double max = Math.Max(0, scroller.Extent.Width - scroller.Viewport.Width);+ double x = Math.Clamp(scroller.Offset.X - WheelInput.Pixels(e.Delta.Y), 0, max);+ if (Math.Abs(x - scroller.Offset.X) < 0.01) return;+ scroller.Offset = scroller.Offset.WithX(x);+ e.Handled = true;+ };Content = new Panel { Children = { scroller, _dropGlow, _dropLayer } };HookBrowserDrop();}@@ -149,7 +160,23 @@ public sealed partial class DeviceChainView : UserControlreturn false;}+ // Clearing the row takes cards out of the tree, and a card losing pointer capture can+ // ask for a rebuild from inside this one; the nested call then filled the row and this+ // one appended a second set of cards after it (#202). Run it once more afterwards instead.+ private bool _rebuilding, _rebuildAgain;+private void Rebuild()+ {+ if (_rebuilding) { _rebuildAgain = true; return; }+ _rebuilding = true;+ try+ {+ do { _rebuildAgain = false; RebuildRow(); } while (_rebuildAgain);+ }+ finally { _rebuilding = false; }+ }++ private void RebuildRow(){_row.Children.Clear();_instrumentCard = null;diff --git a/src/managed/Nota.App/ModularView.cs b/src/managed/Nota.App/ModularView.csindex ffe642ef..a67e1679 100644--- a/src/managed/Nota.App/ModularView.cs+++ b/src/managed/Nota.App/ModularView.cs@@ -126,7 +126,7 @@ public sealed class ModularView : UserControl// hint + minimap overlays (screen-space, not transformed)var hint = new TextBlock{- Text = MenuKit.Keys("Space + drag — pan · ⌘ + wheel — zoom · F — fit"),+ Text = MenuKit.Keys("Drag from a CV out onto a node to modulate it · Space + drag — pan · ⌘ + wheel — zoom · F — fit · Esc — show fewer"),FontSize = 9, Foreground = Text4,HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom,Margin = new Thickness(14, 0, 0, 14),@@ -1041,7 +1041,21 @@ public sealed class ModularView : UserControlint m = e.ModulatorScope(t, modId, buf);viz.Set(buf, m);});- var vizBox = new Border { Height = 76, Margin = new Thickness(9, 6), Child = viz };+ // Unwired, the scope says what it can watch: a modulator's CV, patched into its input. It+ // doesn't tap audio — a first-time user tried to hang it off a filter's output (#261). The hint+ // stands in for the trace, which would only draw a flat line through it.+ Control body = viz;+ if ((int)Math.Round(e.ModulatorGet(t, modId, 10)) < 0)+ {+ var hint = new TextBlock+ {+ Text = "Watches CV. Drag a modulator's CV out onto this node. For audio, put Lens on the chain.",+ FontSize = 9, Foreground = Text3, TextWrapping = TextWrapping.Wrap, TextAlignment = TextAlignment.Center,+ HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(8, 0),+ };+ body = hint;+ }+ var vizBox = new Border { Height = 76, Margin = new Thickness(9, 6), Child = body };col.Children.Add(Row(vizBox, 2));col.Children.Add(Row(PortsBlock(n), 3));WrapFrame(n, col, headBorder);@@ -1428,17 +1442,18 @@ public sealed class ModularView : UserControlactions.Children.Add(HeaderGlyph(GlyphKind.Bypass, n.Bypassed ? BrassBright : Text3, "Bypass (B)", () => ToggleBypass(n)));// Only offer expand when there are more params than the headline row shows,// otherwise the button reveals nothing (e.g. a plugin exposing few params).- if (CanExpand(n))- actions.Children.Add(HeaderGlyph(_expanded.Contains(n.Id) ? GlyphKind.ChevronUp : GlyphKind.ChevronDown, _expanded.Contains(n.Id) ? BrassBright : Text3, "Expand", () => ToggleExpand(n)));- actions.Children.Add(HeaderGlyph(GlyphKind.Close, Text3, "Delete", () => DeleteNode(n)));+ if (CanExpand(n) || _expanded.Contains(n.Id)) actions.Children.Add(ExpandGlyph(n));+ // A bin, not ×: an × reads as "close", and closing the opened knobs deleted the device (#261).+ actions.Children.Add(HeaderGlyph(GlyphKind.Trash, Text3, "Delete (⌫)", () => DeleteNode(n)));DockPanel.SetDock(actions, Dock.Right);head.Children.Add(actions);}- else if (n.Slot == Slot.Instrument && CanExpand(n))+ else if (n.Slot == Slot.Instrument){- // The instrument can't be bypassed/removed, but its params are expandable too.+ // The instrument can't be bypassed/removed (the lock says so), but its params are expandable too.var actions = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 4, VerticalAlignment = VerticalAlignment.Center };- actions.Children.Add(HeaderGlyph(_expanded.Contains(n.Id) ? GlyphKind.ChevronUp : GlyphKind.ChevronDown, _expanded.Contains(n.Id) ? BrassBright : Text3, "Expand", () => ToggleExpand(n)));+ if (CanExpand(n) || _expanded.Contains(n.Id)) actions.Children.Add(ExpandGlyph(n));+ actions.Children.Add(LockGlyph(n));DockPanel.SetDock(actions, Dock.Right);head.Children.Add(actions);}@@ -1446,15 +1461,18 @@ public sealed class ModularView : UserControl{var actions = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center };actions.Children.Add(new TextBlock { Text = string.IsNullOrEmpty(n.Badge) ? "LFO" : NotaText.Label(n.Badge), FontSize = 9, FontWeight = FontWeight.Medium, Foreground = Text3, VerticalAlignment = VerticalAlignment.Center });- actions.Children.Add(HeaderGlyph(GlyphKind.Close, Text3, "Delete", () => RemoveModulatorNode(n)));+ actions.Children.Add(HeaderGlyph(GlyphKind.Trash, Text3, "Delete (⌫)", () => RemoveModulatorNode(n)));DockPanel.SetDock(actions, Dock.Right);head.Children.Add(actions);}- else if (!string.IsNullOrEmpty(n.Badge))+ else if (!string.IsNullOrEmpty(n.Badge) || FixedReason(n) is not null){- var badge = new TextBlock { Text = NotaText.Label(n.Badge), FontSize = 9, FontWeight = FontWeight.Medium, Foreground = Text3, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(8, 0, 0, 0) };- DockPanel.SetDock(badge, Dock.Right);- head.Children.Add(badge);+ var actions = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(8, 0, 0, 0) };+ if (!string.IsNullOrEmpty(n.Badge))+ actions.Children.Add(new TextBlock { Text = NotaText.Label(n.Badge), FontSize = 9, FontWeight = FontWeight.Medium, Foreground = Text3, VerticalAlignment = VerticalAlignment.Center });+ if (FixedReason(n) is not null) actions.Children.Add(LockGlyph(n));+ DockPanel.SetDock(actions, Dock.Right);+ head.Children.Add(actions);}head.Children.Add(title);// Transparent (not null) background so the whole header strip is hit-testable —@@ -1483,7 +1501,7 @@ public sealed class ModularView : UserControlprivate void BuildNodeView(GNode n){- var col = new Grid { RowDefinitions = new RowDefinitions("3,32,Auto,Auto") };+ var col = new Grid { RowDefinitions = new RowDefinitions("3,32,Auto,Auto,Auto") };// type stripecol.Children.Add(Row(new Border { Background = n.Stripe, CornerRadius = NotaRadius.Top(NotaRadius.TileValue) }, 0));@@ -1518,9 +1536,29 @@ public sealed class ModularView : UserControl// ports blockcol.Children.Add(Row(PortsBlock(n), 3));+ // An opened node says how to close it: a strip under it, as well as the header chevron and Esc (#261).+ if (_expanded.Contains(n.Id)) col.Children.Add(Row(CollapseStrip(n), 4));+WrapFrame(n, col, headBorder);}+ private Control CollapseStrip(GNode n)+ {+ var text = new TextBlock { Text = "Show fewer", FontSize = 9, FontWeight = FontWeight.Medium, Foreground = Text3, VerticalAlignment = VerticalAlignment.Center };+ var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, HorizontalAlignment = HorizontalAlignment.Center,+ Children = { new Glyph(GlyphKind.ChevronUp, 8) { Foreground = Text3, VerticalAlignment = VerticalAlignment.Center }, text } };+ var strip = new Border+ {+ Height = 22, Background = Brushes.Transparent, BorderBrush = BorderInner, BorderThickness = new Thickness(0, 1, 0, 0),+ Cursor = new Cursor(StandardCursorType.Hand), Child = row,+ };+ ToolTip.SetTip(strip, "Hide the parameters that aren't modulated (Esc)");+ strip.PointerEntered += (_, _) => text.Foreground = Text1;+ strip.PointerExited += (_, _) => text.Foreground = Text3;+ strip.PointerPressed += (_, e) => { if (!e.GetCurrentPoint(strip).Properties.IsLeftButtonPressed) return; ToggleExpand(n); e.Handled = true; };+ return strip;+ }+private Control PortsBlock(GNode n){var stack = new StackPanel { Margin = new Thickness(0, 6, 0, 6) };@@ -1897,6 +1935,31 @@ public sealed class ModularView : UserControlreturn b;}+ // Nodes that belong to the track itself rather than its chain: they can't be deleted, and a+ // lock in the header says why (#261). Null for a node that can be deleted.+ private static string? FixedReason(GNode n) => n.Slot switch+ {+ Slot.Input => "Fixed — the track's clips and input enter the chain here, so it can't be deleted.",+ Slot.Output => "Fixed — the chain leaves the track for the mixer here, so it can't be deleted.",+ Slot.Instrument => "Fixed — the track's instrument takes its MIDI in. It can't be deleted; drop another instrument on the track to swap it.",+ _ => null,+ };++ private static Control LockGlyph(GNode n)+ {+ var g = new Glyph(GlyphKind.Lock, 9) { Foreground = Text3, VerticalAlignment = VerticalAlignment.Center };+ var b = new Border { Width = 16, Height = 16, Background = Brushes.Transparent, Child = g, VerticalAlignment = VerticalAlignment.Center };+ ToolTip.SetTip(b, FixedReason(n));+ return b;+ }++ private Control ExpandGlyph(GNode n)+ {+ bool open = _expanded.Contains(n.Id);+ return HeaderGlyph(open ? GlyphKind.ChevronUp : GlyphKind.ChevronDown, open ? BrassBright : Text3,+ open ? "Show fewer parameters (Esc)" : "Show all parameters", () => ToggleExpand(n));+ }+private GNode? Selected() { foreach (var n in _nodes) if (n.Selected) return n; return null; }private void ToggleBypass(GNode n)@@ -1923,34 +1986,13 @@ public sealed class ModularView : UserControlRebuild(); Changed?.Invoke();}+ // A full clone (every param, state, bypass, sidechain) right after the node, as the device+ // chain's copy / paste makes — copying the state blob alone lost the params (#238).private void DuplicateNode(GNode n){- if (n.Slot == Slot.Device)- {- int kind = _engine.TrackDeviceBuiltinKind(_trackId, n.SlotIndex);- if (kind < 0) return; // hosted plugins: not duplicated from the graph (Phase 2)- var state = _engine.DeviceGetState(_trackId, n.SlotIndex);- bool byp = _engine.DeviceBypassed(_trackId, n.SlotIndex);- int ni = _engine.AddBuiltinDevice(_trackId, kind);- if (ni < 0) return;- if (state != null) _engine.DeviceSetState(_trackId, ni, state);- if (byp) _engine.SetDeviceBypassed(_trackId, ni, true);- if (ni > n.SlotIndex) _engine.MoveDevice(_trackId, ni, n.SlotIndex + 1);- }- else if (n.Slot == Slot.MidiFx)- {- int kind = _engine.MidiEffectKind(_trackId, n.SlotIndex);- int pc = _engine.MidiEffectParamCount(_trackId, n.SlotIndex);- var p = new float[pc];- for (int i = 0; i < pc; i++) p[i] = _engine.MidiEffectGetParam(_trackId, n.SlotIndex, i);- bool byp = _engine.MidiEffectBypassed(_trackId, n.SlotIndex);- int ni = _engine.AddMidiEffect(_trackId, kind);- if (ni < 0) return;- for (int i = 0; i < Math.Min(pc, _engine.MidiEffectParamCount(_trackId, ni)); i++) _engine.MidiEffectSetParam(_trackId, ni, i, p[i]);- if (byp) _engine.SetMidiEffectBypassed(_trackId, ni, true);- if (ni > n.SlotIndex) _engine.MoveMidiEffect(_trackId, ni, n.SlotIndex + 1);- }- else return;+ int ni = n.Slot == Slot.Device ? _engine.DuplicateDevice(_trackId, n.SlotIndex)+ : n.Slot == Slot.MidiFx ? _engine.DuplicateMidiEffect(_trackId, n.SlotIndex) : -1;+ if (ni < 0) return;_savedPos.Clear();Rebuild(); Changed?.Invoke();}@@ -2090,6 +2132,9 @@ public sealed class ModularView : UserControlRemoveModInputEdge(me); e.Handled = true;}else if (!mod && (e.Key == Key.Delete || e.Key == Key.Back) && sel is { IsChainDevice: true }) { DeleteNode(sel); e.Handled = true; }+ else if (!mod && (e.Key == Key.Delete || e.Key == Key.Back) && sel is { Slot: Slot.Modulator }) { RemoveModulatorNode(sel); e.Handled = true; }+ else if (!mod && (e.Key == Key.Delete || e.Key == Key.Back) && sel is not null && FixedReason(sel) is { } why) { _status.Text = why; e.Handled = true; }+ else if (e.Key == Key.Escape && _expanded.Count > 0) { _expanded.Clear(); Rebuild(); e.Handled = true; }}private void OnKeyUp(object? sender, KeyEventArgs e)diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.csindex 0342540c..e5e879f2 100644--- a/src/managed/Nota.App/PreferencesWindow.cs+++ b/src/managed/Nota.App/PreferencesWindow.cs@@ -1165,7 +1165,7 @@ public sealed partial class PreferencesWindow : NotaWindow("⌘⇧M", "Toggle the Mixer view"),("Tab", "Cycle Devices / Pattern / Clip in the detail panel"),("Esc", "Cancel the current gesture / clear the selection · close the patch-bay overlay"),- ("⌘G ⌘⇧G", "Group / ungroup selected tracks"),+ ("⌘G ⌘⇧G", "Group / ungroup selected tracks · on a selected device: wrap it in a rack / take it out"),("⌘C ⌘X ⌘V", "Copy / cut / paste clips, a time range or an automation range · pastes onto the track clicked last"),("⌘⇧C", "Copy the selected clips to Session · the first scene row where they fit"),("⌘⇧V", "Paste the last range as audio rendered through its devices"),@@ -1193,6 +1193,21 @@ public sealed partial class PreferencesWindow : NotaWindow("⌘D", "Duplicate the selected tracks"),("Delete", "Delete the selected tracks · a group goes with its tracks"),}),+ ("Devices (after a click on a device)", new[]+ {+ ("⌘C ⌘X ⌘V", "Copy / cut / paste the device with all its settings · paste lands after the selected device, on any track"),+ ("⌘G", "Wrap the selected audio effect in an Audio Effect Rack"),+ ("⌘⇧G", "Take the devices out of a selected one-chain rack"),+ ("Delete", "Delete the selected device"),+ }),+ ("Modular (after a click on the canvas)", new[]+ {+ ("F", "Fit every node on screen"),+ ("B", "Bypass the selected device"),+ ("⌘D", "Duplicate the selected device with all its settings"),+ ("Delete", "Delete the selected device, modulator or cable · the track's input, instrument and output are fixed"),+ ("Esc", "Show fewer parameters on every opened node"),+ }),("Session (after a click in the grid)", new[]{("← → ↑ ↓", "Move the selection between slots and scenes"),@@ -1296,6 +1311,7 @@ public sealed partial class PreferencesWindow : NotaWindow("Drag an audio clip onto an instrument track", "Load its audio into the Sampler, Grain, Drum Rack (next free pad) or Instrument Rack · rest there to open its devices"),("Drag an audio clip out of the Arrangement", "Take it as a sample: drop on a pad, a Grain, a Rhythm voice, a Session slot — the clip stays put"),("Drag clip + ⌥", "Position freely, ignoring the grid for this drag (the magnet in the transport latches the same thing)"),+ ("Wheel over the device chain", "Scroll it sideways · over an EQ band's handle the wheel sets its Q, over a value box it steps the value"),("Drag knob", "Change a device value · hold ⌘ or ⇧ for fine steps"),("Drag slider", "Left / right (or up / down) changes the value · hold ⌘ or ⇧ for fine steps"),("⌥-click a knob, fader or slider", "Type a value (units like k, ms, dB, L / R work) · double-click its value does the same"),diff --git a/src/managed/Nota.App/WheelInput.cs b/src/managed/Nota.App/WheelInput.csindex 5b1b5957..cb912aa6 100644--- a/src/managed/Nota.App/WheelInput.cs+++ b/src/managed/Nota.App/WheelInput.cs@@ -10,6 +10,7 @@// feel proportional and can't teleport.using System;+using Avalonia.Input;namespace Nota.App;@@ -42,4 +43,29 @@ internal static class WheelInput/// mouse notch gives exactly <paramref name="perNotch"/> and a trackpad scales smoothly.</summary>public static double ZoomFactor(double delta, double perNotch)=> Math.Pow(perNotch, Notches(delta));++ /// <summary>The wheel is mostly vertical — a control may take it as an adjustment. A sideways+ /// (or mostly sideways) swipe is someone scrolling the view the control sits in: leave it+ /// unhandled so it reaches that view's scroller (#262).</summary>+ public static bool IsVertical(PointerWheelEventArgs e) => Math.Abs(e.Delta.Y) > Math.Abs(e.Delta.X);++ private static double _stepAcc;+ private static ulong _stepAt;++ /// <summary>One step of a stepper under the wheel: +1 up, −1 down, 0 for a trackpad event+ /// that hasn't travelled a full notch yet; null when the wheel is mostly sideways (leave the+ /// event unhandled). A mouse notch is one step; a trackpad steps once per notch of travel+ /// instead of once per event, which ran a box to its end on a single swipe.</summary>+ public static int? Step(PointerWheelEventArgs e)+ {+ if (!IsVertical(e)) return null;+ double n = Notches(e.Delta.Y);+ if (e.Timestamp - _stepAt > 300 || Math.Sign(n) != Math.Sign(_stepAcc)) _stepAcc = 0;+ _stepAt = e.Timestamp;+ _stepAcc += n;+ if (Math.Abs(_stepAcc) < 0.999) return 0;+ int s = Math.Sign(_stepAcc);+ _stepAcc -= s;+ return s;+ }}diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.csindex 3c35dff7..bb5284b0 100644--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs@@ -508,6 +508,19 @@ public interface IAudioEngine : IDisposableint AddBuiltinDevice(int trackId, int kind);void MoveDevice(int trackId, int fromIndex, int toIndex);void RemoveDevice(int trackId, int deviceIndex);+ // Device clipboard (#238): a full clone held by the engine; paste is one undo step.+ bool CopyDevice(int trackId, int deviceIndex);+ bool CopyMidiEffect(int trackId, int index);+ int DeviceClipboardKind(); // 0 empty, 1 audio effect, 2 MIDI effect+ int PasteDevice(int trackId, int atIndex); // atIndex -1 = end; new index or -1+ int PasteMidiEffect(int trackId, int atIndex);+ // A full clone right after the device / MIDI effect, one undo step; clipboard untouched.+ int DuplicateDevice(int trackId, int deviceIndex);+ int DuplicateMidiEffect(int trackId, int index);+ // ⌘G / ⌘⇧G on a device (#257): wrap an audio effect in an Audio Effect Rack (its index or+ // -1: keyed / automated / CV-linked devices stay out), unwrap a one-chain rack (count or -1).+ int WrapDeviceInRack(int trackId, int deviceIndex);+ int UnwrapRack(int trackId, int deviceIndex);string DeviceName(int trackId, int deviceIndex);int DeviceParamCount(int trackId, int deviceIndex);string DeviceParamName(int trackId, int deviceIndex, int paramIndex);diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Devices.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Devices.csindex 5301cf6d..6d867623 100644--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Devices.cs+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Devices.cs@@ -37,6 +37,33 @@ internal static partial class NativeMethods[LibraryImport(Lib, EntryPoint = "nota_track_remove_device")]internal static partial NotaResult RemoveDevice(IntPtr engine, int trackId, int deviceIndex);+ [LibraryImport(Lib, EntryPoint = "nota_track_copy_device")]+ internal static partial NotaResult CopyDevice(IntPtr engine, int trackId, int deviceIndex);++ [LibraryImport(Lib, EntryPoint = "nota_track_copy_midi_effect")]+ internal static partial NotaResult CopyMidiEffect(IntPtr engine, int trackId, int index);++ [LibraryImport(Lib, EntryPoint = "nota_device_clipboard_kind")]+ internal static partial int DeviceClipboardKind(IntPtr engine);++ [LibraryImport(Lib, EntryPoint = "nota_track_paste_device")]+ internal static partial int PasteDevice(IntPtr engine, int trackId, int atIndex);++ [LibraryImport(Lib, EntryPoint = "nota_track_paste_midi_effect")]+ internal static partial int PasteMidiEffect(IntPtr engine, int trackId, int atIndex);++ [LibraryImport(Lib, EntryPoint = "nota_track_duplicate_device")]+ internal static partial int DuplicateDevice(IntPtr engine, int trackId, int deviceIndex);++ [LibraryImport(Lib, EntryPoint = "nota_track_duplicate_midi_effect")]+ internal static partial int DuplicateMidiEffect(IntPtr engine, int trackId, int index);++ [LibraryImport(Lib, EntryPoint = "nota_track_wrap_device_in_rack")]+ internal static partial int WrapDeviceInRack(IntPtr engine, int trackId, int deviceIndex);++ [LibraryImport(Lib, EntryPoint = "nota_track_unwrap_rack")]+ internal static partial int UnwrapRack(IntPtr engine, int trackId, int deviceIndex);+[LibraryImport(Lib, EntryPoint = "nota_device_name")]internal static partial IntPtr DeviceName(IntPtr engine, int trackId, int deviceIndex);diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Devices.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Devices.csindex 59dc7513..3937a6d6 100644--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Devices.cs+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Devices.cs@@ -70,6 +70,37 @@ public sealed partial class NotaEnginepublic void RemoveDevice(int trackId, int deviceIndex){ ThrowIfDisposed(); Check(NativeMethods.RemoveDevice(_handle, trackId, deviceIndex)); }+ /// <summary>Copies a full clone of an audio effect to the engine's device clipboard (#238).</summary>+ public bool CopyDevice(int trackId, int deviceIndex)+ { ThrowIfDisposed(); return NativeMethods.CopyDevice(_handle, trackId, deviceIndex) == NativeMethods.NotaResult.Ok; }++ /// <summary>Copies a full clone of a MIDI effect to the engine's device clipboard.</summary>+ public bool CopyMidiEffect(int trackId, int index)+ { ThrowIfDisposed(); return NativeMethods.CopyMidiEffect(_handle, trackId, index) == NativeMethods.NotaResult.Ok; }++ /// <summary>0 = empty, 1 = an audio effect, 2 = a MIDI effect.</summary>+ public int DeviceClipboardKind() { ThrowIfDisposed(); return NativeMethods.DeviceClipboardKind(_handle); }++ /// <summary>Inserts a clone of the copied audio effect at atIndex (-1 = end), one undo step. New index or -1.</summary>+ public int PasteDevice(int trackId, int atIndex)+ { ThrowIfDisposed(); return NativeMethods.PasteDevice(_handle, trackId, atIndex); }++ /// <summary>Inserts a clone of the copied MIDI effect at atIndex (-1 = end), one undo step. New index or -1.</summary>+ public int PasteMidiEffect(int trackId, int atIndex)+ { ThrowIfDisposed(); return NativeMethods.PasteMidiEffect(_handle, trackId, atIndex); }+ public int DuplicateDevice(int trackId, int deviceIndex)+ { ThrowIfDisposed(); return NativeMethods.DuplicateDevice(_handle, trackId, deviceIndex); }+ public int DuplicateMidiEffect(int trackId, int index)+ { ThrowIfDisposed(); return NativeMethods.DuplicateMidiEffect(_handle, trackId, index); }++ /// <summary>Wraps an audio effect in a new Audio Effect Rack in its place (#257). The rack's index, or -1.</summary>+ public int WrapDeviceInRack(int trackId, int deviceIndex)+ { ThrowIfDisposed(); return NativeMethods.WrapDeviceInRack(_handle, trackId, deviceIndex); }++ /// <summary>Replaces a one-chain Audio Effect Rack with its chain's devices. Their count, or -1.</summary>+ public int UnwrapRack(int trackId, int deviceIndex)+ { ThrowIfDisposed(); return NativeMethods.UnwrapRack(_handle, trackId, deviceIndex); }+public string DeviceName(int trackId, int deviceIndex){ ThrowIfDisposed(); return Marshal.PtrToStringUTF8(NativeMethods.DeviceName(_handle, trackId, deviceIndex)) ?? ""; }diff --git a/src/managed/Nota.Infrastructure/Kits/DrumKitService.cs b/src/managed/Nota.Infrastructure/Kits/DrumKitService.csindex e602a915..4a0e5e2a 100644--- a/src/managed/Nota.Infrastructure/Kits/DrumKitService.cs+++ b/src/managed/Nota.Infrastructure/Kits/DrumKitService.cs@@ -57,10 +57,16 @@ public sealed class DrumKitService : IDrumKits{var kit = KitCatalog.ById(id);if (kit is null) { warning = "Unknown drum kit."; return -1; }- int track = engine.AddDrumRackTrack();- if (track <= 0) { warning = "Couldn't create a Drum Rack track."; return -1; }- Fill(engine, track, kit, out warning);- return track;+ // One undo step: the new track with its whole kit.+ engine.BeginUndoGroup();+ try+ {+ int track = engine.AddDrumRackTrack();+ if (track <= 0) { warning = "Couldn't create a Drum Rack track."; return -1; }+ Fill(engine, track, kit, out warning);+ return track;+ }+ finally { engine.EndUndoGroup(); }}public int CreateRhythmTrack(IAudioEngine engine, string id, out string warning)@@ -79,9 +85,14 @@ public sealed class DrumKitService : IDrumKitsif (kit is null) { warning = "Unknown drum kit."; return false; }if (engine.TrackInstrumentKind(trackId) == RhythmModel.Kind) { FillRhythm(engine, trackId, kit, out warning); return true; }// Clear the existing pads first — a kit replaces the rack's contents rather than- // layering onto whatever was there.- for (int c = engine.RackChainCount(trackId) - 1; c >= 0; c--) engine.RackRemoveChain(trackId, c);- Fill(engine, trackId, kit, out warning);+ // layering onto whatever was there. One undo step brings the old pads back.+ engine.BeginUndoGroup();+ try+ {+ for (int c = engine.RackChainCount(trackId) - 1; c >= 0; c--) engine.RackRemoveChain(trackId, c);+ Fill(engine, trackId, kit, out warning);+ }+ finally { engine.EndUndoGroup(); }return true;}diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.hindex 2316ffb7..a8f76947 100644--- a/src/native/nota.engine/include/nota/nota_engine.h+++ b/src/native/nota.engine/include/nota/nota_engine.h@@ -1437,6 +1437,25 @@ NOTA_API int32_t nota_track_add_builtin_device(NotaEngine* engine, int32_t t/* Reorder / remove a device in the track chain (M4.1-D). */NOTA_API NotaResult nota_track_move_device(NotaEngine* engine, int32_t track_id, int32_t from_index, int32_t to_index);NOTA_API NotaResult nota_track_remove_device(NotaEngine* engine, int32_t track_id, int32_t device_index);+/* Device clipboard (#238). Copy keeps a full clone of an audio effect (every param, its+ * state blob, bypass, sidechain key; a rack or plug-in copies itself) or a MIDI effect;+ * paste inserts a clone of it at at_index (-1 = the end) as one undo step and returns the+ * new index, or <0. clipboard_kind: 0 empty, 1 audio effect, 2 MIDI effect. */+NOTA_API NotaResult nota_track_copy_device(NotaEngine* engine, int32_t track_id, int32_t device_index);+NOTA_API NotaResult nota_track_copy_midi_effect(NotaEngine* engine, int32_t track_id, int32_t index);+NOTA_API int32_t nota_device_clipboard_kind(const NotaEngine* engine);+NOTA_API int32_t nota_track_paste_device(NotaEngine* engine, int32_t track_id, int32_t at_index);+NOTA_API int32_t nota_track_paste_midi_effect(NotaEngine* engine, int32_t track_id, int32_t at_index);+/* A full clone of the device / MIDI effect right after it, one undo step; the clipboard is left+ * alone. Returns the clone's index or -1. */+NOTA_API int32_t nota_track_duplicate_device(NotaEngine* engine, int32_t track_id, int32_t device_index);+NOTA_API int32_t nota_track_duplicate_midi_effect(NotaEngine* engine, int32_t track_id, int32_t index);+/* ⌘G on a device (#257): wrap the audio effect at device_index in a new Audio Effect Rack+ * in its place (one undo step). Returns the rack's index, or <0 when the device can't move+ * into a rack chain (not an effect; a sidechain key, automation or a CV link on it).+ * Unwrap replaces a one-chain rack with its chain's devices; returns their count, or <0. */+NOTA_API int32_t nota_track_wrap_device_in_rack(NotaEngine* engine, int32_t track_id, int32_t device_index);+NOTA_API int32_t nota_track_unwrap_rack(NotaEngine* engine, int32_t track_id, int32_t device_index);/* Device display name (built-ins: "EQ"/"Compressor"; plugins: plugin name). */NOTA_API const char* nota_device_name(const NotaEngine* engine, int32_t track_id, int32_t device_index);/* Generic float params (built-ins expose these; hosted plugins report 0). */diff --git a/src/native/nota.engine/src/abi/nota_engine_device.cpp b/src/native/nota.engine/src/abi/nota_engine_device.cppindex a47c51ab..bfeecde6 100644--- a/src/native/nota.engine/src/abi/nota_engine_device.cpp+++ b/src/native/nota.engine/src/abi/nota_engine_device.cpp@@ -59,6 +59,33 @@ NotaResult nota_track_remove_device(NotaEngine* e, int32_t track_id, int32_t devif (!e) return NOTA_ERR_INVALID_ARG;return ENG(e)->removeDevice(track_id, device_index) ? NOTA_OK : NOTA_ERR_INVALID_ARG;}+NotaResult nota_track_copy_device(NotaEngine* e, int32_t track_id, int32_t device_index) {+ if (!e) return NOTA_ERR_INVALID_ARG;+ return ENG(e)->copyDevice(track_id, device_index) ? NOTA_OK : NOTA_ERR_INVALID_ARG;+}+NotaResult nota_track_copy_midi_effect(NotaEngine* e, int32_t track_id, int32_t index) {+ if (!e) return NOTA_ERR_INVALID_ARG;+ return ENG(e)->copyMidiEffect(track_id, index) ? NOTA_OK : NOTA_ERR_INVALID_ARG;+}+int32_t nota_device_clipboard_kind(const NotaEngine* e) { return e ? CENG(e)->deviceClipboardKind() : 0; }+int32_t nota_track_paste_device(NotaEngine* e, int32_t track_id, int32_t at_index) {+ return e ? ENG(e)->pasteDevice(track_id, at_index) : -1;+}+int32_t nota_track_paste_midi_effect(NotaEngine* e, int32_t track_id, int32_t at_index) {+ return e ? ENG(e)->pasteMidiEffect(track_id, at_index) : -1;+}+int32_t nota_track_duplicate_device(NotaEngine* e, int32_t track_id, int32_t device_index) {+ return e ? ENG(e)->duplicateDevice(track_id, device_index) : -1;+}+int32_t nota_track_duplicate_midi_effect(NotaEngine* e, int32_t track_id, int32_t index) {+ return e ? ENG(e)->duplicateMidiEffect(track_id, index) : -1;+}+int32_t nota_track_wrap_device_in_rack(NotaEngine* e, int32_t track_id, int32_t device_index) {+ return e ? ENG(e)->wrapDeviceInRack(track_id, device_index) : -1;+}+int32_t nota_track_unwrap_rack(NotaEngine* e, int32_t track_id, int32_t device_index) {+ return e ? ENG(e)->unwrapRack(track_id, device_index) : -1;+}const char* nota_device_name(const NotaEngine* e, int32_t track_id, int32_t device_index) {return e ? CENG(e)->deviceName(track_id, device_index) : "";}diff --git a/src/native/nota.engine/src/devices/racks/RackCore.cpp b/src/native/nota.engine/src/devices/racks/RackCore.cppindex 1ee83412..55b343a1 100644--- a/src/native/nota.engine/src/devices/racks/RackCore.cpp+++ b/src/native/nota.engine/src/devices/racks/RackCore.cpp@@ -70,6 +70,49 @@ void RackCore::setRates(double sr, int32_t maxBlock) {}}+void RackCore::forkFrom(const RackCore& o) {+ auto ns = o.copyState();+ for (auto& c : ns->chains) {+ auto ctl = std::make_shared<ChainControls>();+ if (c.ctl) {+ const auto& s = *c.ctl;+ constexpr auto r = std::memory_order_relaxed;+ ctl->gain.store(s.gain.load(r), r);+ ctl->pan.store(s.pan.load(r), r);+ ctl->mute.store(s.mute.load(r), r);+ ctl->solo.store(s.solo.load(r), r);+ ctl->triggerNote.store(s.triggerNote.load(r), r);+ ctl->keyLo.store(s.keyLo.load(r), r);+ ctl->keyHi.store(s.keyHi.load(r), r);+ ctl->velLo.store(s.velLo.load(r), r);+ ctl->velHi.store(s.velHi.load(r), r);+ ctl->chokeGroup.store(s.chokeGroup.load(r), r);+ ctl->tune.store(s.tune.load(r), r);+ ctl->decay.store(s.decay.load(r), r);+ ctl->ampEnv = s.ampEnv; // a ringing pad keeps its level+ }+ c.ctl = std::move(ctl);+ }+ commit(ns);+ constexpr auto r = std::memory_order_relaxed;+ for (int32_t i = 0; i < kNumMacros; ++i) {+ macros_[i].store(o.macros_[i].load(r), r);+ macroNames_[i] = o.macroNames_[i];+ }+ rackVolume_.store(o.rackVolume_.load(r), r);+ glide_.store(o.glide_.load(r), r);+ swing_.store(o.swing_.load(r), r);+ humanize_.store(o.humanize_.load(r), r);+ mode_.store(o.mode_.load(r), r);+ dryWet_.store(o.dryWet_.load(r), r);+ pdc_.store(o.pdc_.load(r), r);+ chainSelect_.store(o.chainSelect_.load(r), r);+ selFollow_.store(o.selFollow_.load(r), r);+ liveSel_.store(o.liveSel_.load(r), r);+ sampleRate_ = o.sampleRate_;+ maxBlock_ = o.maxBlock_;+}+bool RackCore::setChainName(int32_t c, const std::string& name) {auto ns = copyState();if (c < 0 || c >= static_cast<int32_t>(ns->chains.size())) return false;diff --git a/src/native/nota.engine/src/devices/racks/RackCore.h b/src/native/nota.engine/src/devices/racks/RackCore.hindex 4b1b40e1..3fc7eb08 100644--- a/src/native/nota.engine/src/devices/racks/RackCore.h+++ b/src/native/nota.engine/src/devices/racks/RackCore.h@@ -311,6 +311,14 @@ class RackCore {return (st && i >= 0 && i < static_cast<int32_t>(st->mappings.size())) ? st->mappings[i].curve : 0;}+ // ---- undoable edits ---------------------------------------------------+ // Take over another rack's content (#236). The engine edits a copy of the rack instead+ // of the rack itself, so the graph snapshot on the undo stack keeps the old rack intact:+ // the same chain children (shared, so DSP and voice state survive the edit), fresh chain+ // controls holding the same values, the same mappings, macros and rack settings.+ // Message thread, on a fresh rack that nothing renders yet.+ void forkFrom(const RackCore& o);+// ---- persistence blob (shared format; instKind -1 = no instrument) ----std::vector<uint8_t> serialize() const;void deserialize(const uint8_t* data, int32_t size);diff --git a/src/native/nota.engine/src/engine/Engine.cpp b/src/native/nota.engine/src/engine/Engine.cppindex b1d243bb..f97509ba 100644--- a/src/native/nota.engine/src/engine/Engine.cpp+++ b/src/native/nota.engine/src/engine/Engine.cpp@@ -616,6 +616,17 @@ void Engine::publishRaw(std::shared_ptr<Graph> g) {void Engine::pushUndo() {if (!authoring_) return;+ // Inside an undo group only the first snapshot counts (endUndoGroup keeps the pre-group+ // graph), so later ones aren't stacked: a gesture of many edits (a kit filling a Drum+ // Rack's pads) would otherwise push the older history off the depth limit.+ if (undoGroupDepth_ > 0) {+ for (size_t i = undoGroupBase_; i < undoStack_.size(); ++i)+ if (undoStack_[i].graph) {+ ++undoPushCount_;+ redoStack_.clear();+ return;+ }+ }undoStack_.push_back({authoring_, {}}); // authoring_ is immutable after publish++undoPushCount_;if (undoStack_.size() > kMaxUndoDepth) {diff --git a/src/native/nota.engine/src/engine/Engine.h b/src/native/nota.engine/src/engine/Engine.hindex 67570c5c..61a7ce78 100644--- a/src/native/nota.engine/src/engine/Engine.h+++ b/src/native/nota.engine/src/engine/Engine.h@@ -726,6 +726,18 @@ class Engine {int32_t addTrackBuiltinDevice(int32_t trackId, int32_t kind); // 0=EQ, 1=Compressorbool moveDevice(int32_t trackId, int32_t fromIndex, int32_t toIndex);bool removeDevice(int32_t trackId, int32_t deviceIndex);+ // Device clipboard (#238): copy a full clone of an audio / MIDI effect (every param, its+ // state blob, bypass, sidechain key; a rack or plug-in copies itself), paste a clone of it+ // into a chain at atIndex (-1 = the end) as one undo step. Paste returns the new index or+ // -1. deviceClipboardKind: 0 empty, 1 audio effect, 2 MIDI effect.+ bool copyDevice(int32_t trackId, int32_t deviceIndex);+ bool copyMidiEffect(int32_t trackId, int32_t index);+ int32_t deviceClipboardKind() const;+ int32_t pasteDevice(int32_t trackId, int32_t atIndex);+ int32_t pasteMidiEffect(int32_t trackId, int32_t atIndex);+ // A clone of the device right after it (one undo step), clipboard untouched. Returns its index or -1.+ int32_t duplicateDevice(int32_t trackId, int32_t deviceIndex);+ int32_t duplicateMidiEffect(int32_t trackId, int32_t index);const char* deviceName(int32_t trackId, int32_t deviceIndex) const;int32_t deviceScope(int32_t trackId, int32_t deviceIndex, float* out, int32_t maxSamples) const;// Interactive-device command channel + per-layer waveform (the looper).@@ -839,6 +851,17 @@ class Engine {int32_t rackAddPluginInstrumentChain(int32_t trackId, int32_t deviceIndex, int32_t catalogIndex);int32_t rackAddPluginChainDevice(int32_t trackId, int32_t deviceIndex, int32_t chain, int32_t catalogIndex);RackCore* rackCoreAt(int32_t trackId, int32_t deviceIndex) const; // null if not a rack+ // The rack to apply an undoable edit to (#236): a fork of the rack at (trackId,+ // deviceIndex), republished in its track as one undo step. Null if not a rack.+ RackCore* rackForEdit(int32_t trackId, int32_t deviceIndex);+ // ⌘G on a device (#257): put the audio effect at deviceIndex into a new Audio Effect Rack+ // (one chain holding the device itself, so nothing restarts) in its place, one undo step;+ // returns the rack's index, or -1 (not an effect, or keyed / automated / CV-linked, which+ // can't follow it into a chain). ⌘⇧G: replace a one-chain rack with that chain's devices;+ // returns how many came out, or -1.+ int32_t wrapDeviceInRack(int32_t trackId, int32_t deviceIndex);+ int32_t unwrapRack(int32_t trackId, int32_t deviceIndex);+ bool deviceIsReferenced(const Track& t, int32_t deviceIndex) const;// Drum Rack pad note per chain (-1 = all notes; instrument/effect racks ignore it).int32_t rackChainTriggerNote(int32_t trackId, int32_t deviceIndex, int32_t chain) const;void rackSetChainTriggerNote(int32_t trackId, int32_t deviceIndex, int32_t chain, int32_t note);@@ -1203,6 +1226,10 @@ class Engine {std::shared_ptr<Instrument> cloneInstrument(const Track& src) const; // duplicateTrack helperstd::shared_ptr<Device> cloneDevice(const Device& src) const;std::shared_ptr<MidiDevice> cloneMidiDevice(const MidiDevice& src) const;+ std::shared_ptr<Device> clipDevice_; // device clipboard (#238): a clone of the copied audio effect+ std::shared_ptr<MidiDevice> clipMidi_;+ int32_t insertDeviceClone(int32_t trackId, std::shared_ptr<Device> dev, int32_t atIndex);+ int32_t insertMidiEffectClone(int32_t trackId, std::shared_ptr<MidiDevice> md, int32_t atIndex); // ... or of the copied MIDI effect (one of the two at a time)void recomputePdc(); // message thread: realign all tracksDevice* deviceAt(int32_t trackId, int32_t deviceIndex) const;MidiDevice* midiDeviceAt(int32_t trackId, int32_t index) const;diff --git a/src/native/nota.engine/src/engine/Engine_Devices.cpp b/src/native/nota.engine/src/engine/Engine_Devices.cppindex 92b84993..96c93092 100644--- a/src/native/nota.engine/src/engine/Engine_Devices.cpp+++ b/src/native/nota.engine/src/engine/Engine_Devices.cpp@@ -663,45 +663,22 @@ std::shared_ptr<Instrument> Engine::cloneInstrument(const Track& src) const {std::shared_ptr<Device> Engine::cloneDevice(const Device& src) const {const double sr = transport_.sampleRate() > 0 ? transport_.sampleRate() : 44100.0;- std::shared_ptr<Device> d;- switch (src.builtinKind()) { // built-ins- case 0: d = std::make_shared<Eq>(); break;- case 1: d = std::make_shared<Compressor>(); break;- case 2: d = std::make_shared<Reverb>(); break;- case 3: d = std::make_shared<Delay>(); break;- case 4: d = std::make_shared<Utility>(); break;- case 6: d = std::make_shared<Amp>(); break;- case 7: d = std::make_shared<AutoFilter>(); break;- case 8: d = std::make_shared<Vintage>(); break;- case 9: d = std::make_shared<AutoPan>(); break;- case 10: d = std::make_shared<AutoShift>(); break;- case 11: d = std::make_shared<BeatRepeat>(); break;- case 12: d = std::make_shared<Crush>(); break;- case 13: d = std::make_shared<DynamicEq>(); break;- case 14: d = std::make_shared<Ceiling>(); break;- case 15: d = std::make_shared<Strata>(); break;- case 16: d = std::make_shared<Eq3>(); break;- case 17: d = std::make_shared<Forge>(); break;- case 18: d = std::make_shared<AutoGain>(); break;- case 19: d = std::make_shared<Shutter>(); break;- case 20: d = std::make_shared<Chamber>(); break;- case 21: d = std::make_shared<Prism>(); break;- case 22: d = std::make_shared<Lens>(); break;- case 23: d = std::make_shared<Flanger>(); break;- case 24: d = std::make_shared<Phaser>(); break;- case 25: d = std::make_shared<Chorus>(); break;- case 26: d = std::make_shared<Vocoder>(); break;- default: d = src.clone(); break; // hosted plugin- }+ // A built-in starts fresh and takes the source's values below; a rack or hosted plugin+ // copies itself (its whole state). The factory is the same one AddBuiltinDevice's+ // defaults come from, so a new built-in kind can't be missed here (#238).+ std::shared_ptr<Device> d = makeBuiltinDevice(src.builtinKind());+ const bool builtin = d != nullptr;+ if (!d) d = src.clone();if (!d) return nullptr;d->setSampleRate(sr, kMaxBlock);- if (src.builtinKind() >= 0) { // copy generic params+ if (builtin) { // copy generic paramsconst int32_t pc = src.paramCount();for (int32_t p = 0; p < pc; ++p) d->setParam(p, src.getParam(p));auto st = src.getState(); // + any state blob (looper PCM)if (!st.empty()) d->setState(st.data(), (int32_t)st.size());}d->setBypassed(src.bypassed());+ d->setFolded(src.folded());d->setSidechainSourceTrackId(src.sidechainSourceTrackId()); // a keyed device keeps its keyd->setSidechainTapPre(src.sidechainTapPre());d->setSidechainGainDb(src.sidechainGainDb());@@ -773,11 +750,85 @@ std::shared_ptr<MidiDevice> Engine::cloneMidiDevice(const MidiDevice& src) constif (src.midiKind() >= 0) {const int32_t pc = src.paramCount();for (int32_t p = 0; p < pc; ++p) d->setParam(p, src.getParam(p));+ auto st = src.getState();+ if (!st.empty()) d->setState(st.data(), (int32_t)st.size());}+ d->setCcDest(src.ccDestDevice(), src.ccDestParam()); // the Arp's CC modulation (#238)+ d->setCcDepth(src.ccDepth());d->setBypassed(src.bypassed());+ d->setFolded(src.folded());return d; // live state starts fresh}+// ---- device clipboard (#238) ---------------------------------------------+// Copy holds a clone, not the device itself: a cut device can still be pasted, and later+// edits to the source don't reach the copy. Paste inserts another clone, so the clipboard+// can be pasted again; each paste is one undo step.+bool Engine::copyDevice(int32_t trackId, int32_t deviceIndex) {+ Device* src = deviceAt(trackId, deviceIndex);+ auto c = src ? cloneDevice(*src) : nullptr;+ if (!c) return false;+ clipDevice_ = std::move(c);+ clipMidi_.reset();+ return true;+}++bool Engine::copyMidiEffect(int32_t trackId, int32_t index) {+ MidiDevice* src = midiDeviceAt(trackId, index);+ auto c = src ? cloneMidiDevice(*src) : nullptr;+ if (!c) return false;+ clipMidi_ = std::move(c);+ clipDevice_.reset();+ return true;+}++int32_t Engine::deviceClipboardKind() const { return clipDevice_ ? 1 : clipMidi_ ? 2 : 0; }++int32_t Engine::pasteDevice(int32_t trackId, int32_t atIndex) {+ return clipDevice_ ? insertDeviceClone(trackId, cloneDevice(*clipDevice_), atIndex) : -1;+}++int32_t Engine::duplicateDevice(int32_t trackId, int32_t deviceIndex) {+ Device* src = deviceAt(trackId, deviceIndex);+ return src ? insertDeviceClone(trackId, cloneDevice(*src), deviceIndex + 1) : -1;+}++int32_t Engine::insertDeviceClone(int32_t trackId, std::shared_ptr<Device> dev, int32_t atIndex) {+ auto old = findTrackAuthoring(trackId);+ if (!old || !dev) return -1;+ auto nt = cloneTrack(*old);+ const int32_t end = static_cast<int32_t>(nt->devices.size());+ const int32_t at = (atIndex < 0 || atIndex > end) ? end : atIndex;+ nt->devices.insert(nt->devices.begin() + at, dev);+ // An insert is a move from just past the end: the lanes and CV links after it shift up.+ if (at != end) remapAutomationAfterDeviceChange(*nt, false, -1, end, at);+ republishWithTrack(trackId, nt);+ if (at != end) remapCvLinksAfterDeviceChange(trackId, -1, end, at);+ recomputePdc();+ return at;+}++int32_t Engine::pasteMidiEffect(int32_t trackId, int32_t atIndex) {+ return clipMidi_ ? insertMidiEffectClone(trackId, cloneMidiDevice(*clipMidi_), atIndex) : -1;+}++int32_t Engine::duplicateMidiEffect(int32_t trackId, int32_t index) {+ MidiDevice* src = midiDeviceAt(trackId, index);+ return src ? insertMidiEffectClone(trackId, cloneMidiDevice(*src), index + 1) : -1;+}++int32_t Engine::insertMidiEffectClone(int32_t trackId, std::shared_ptr<MidiDevice> md, int32_t atIndex) {+ auto old = findTrackAuthoring(trackId);+ if (!old || !md || old->type() != TrackType::Instrument) return -1;+ auto nt = cloneTrack(*old);+ const int32_t end = static_cast<int32_t>(nt->midiEffects.size());+ const int32_t at = (atIndex < 0 || atIndex > end) ? end : atIndex;+ nt->midiEffects.insert(nt->midiEffects.begin() + at, md);+ if (at != end) remapAutomationAfterDeviceChange(*nt, true, -1, end, at);+ republishWithTrack(trackId, nt);+ return at;+}+int32_t Engine::addTrackMidiEffect(int32_t trackId, int32_t kind) {auto old = findTrackAuthoring(trackId);if (!old) return -1;diff --git a/src/native/nota.engine/src/engine/Engine_Rack.cpp b/src/native/nota.engine/src/engine/Engine_Rack.cppindex 87ca6fe0..b7c2d7a6 100644--- a/src/native/nota.engine/src/engine/Engine_Rack.cpp+++ b/src/native/nota.engine/src/engine/Engine_Rack.cpp@@ -42,22 +42,22 @@ void Engine::installRackPluginFactory() {}int32_t Engine::rackAddPluginInstrumentChain(int32_t t, int32_t di, int32_t catalogIndex) {- auto* r = rackCoreAt(t, di);- if (!r) return -1;+ if (!rackCoreAt(t, di)) return -1;const double sr = transport_.sampleRate() > 0 ? transport_.sampleRate() : 44100.0;auto inst = createPluginInstrument(catalogIndex, sr, kMaxBlock);if (!inst) return -1;+ auto* r = rackForEdit(t, di);const int32_t idx = r->addChainInstrument(inst);recomputePdc();return idx;}int32_t Engine::rackAddPluginChainDevice(int32_t t, int32_t di, int32_t chain, int32_t catalogIndex) {- auto* r = rackCoreAt(t, di);- if (!r) return -1;+ if (!rackCoreAt(t, di)) return -1;const double sr = transport_.sampleRate() > 0 ? transport_.sampleRate() : 44100.0;auto dev = createPluginEffect(catalogIndex, sr, kMaxBlock);if (!dev) return -1;+ auto* r = rackForEdit(t, di);const int32_t idx = r->addChainDeviceInstance(chain, dev);recomputePdc();return idx;@@ -93,7 +93,9 @@ int32_t Engine::rackChainTriggerNote(int32_t t, int32_t di, int32_t c) const {return r ? r->chainTriggerNote(c) : -1;}void Engine::rackSetChainTriggerNote(int32_t t, int32_t di, int32_t c, int32_t note) {- if (auto* r = rackCoreAt(t, di)) r->setChainTriggerNote(c, note);+ auto* r = rackCoreAt(t, di);+ if (!r || c < 0 || c >= r->chainCount() || r->chainTriggerNote(c) == note) return;+ rackForEdit(t, di)->setChainTriggerNote(c, note);}std::string Engine::rackChainName(int32_t t, int32_t di, int32_t c) const {@@ -101,26 +103,27 @@ std::string Engine::rackChainName(int32_t t, int32_t di, int32_t c) const {return r ? r->chainName(c) : std::string{};}void Engine::rackSetChainName(int32_t t, int32_t di, int32_t c, const std::string& name) {- if (auto* r = rackCoreAt(t, di)) r->setChainName(c, name);+ auto* r = rackCoreAt(t, di);+ if (!r || c < 0 || c >= r->chainCount() || r->chainName(c) == name) return;+ rackForEdit(t, di)->setChainName(c, name);}int32_t Engine::rackAddSamplerChain(int32_t t, int32_t di, const std::string& path, int32_t rootNote, bool loop) {- auto* r = rackCoreAt(t, di);- if (!r) return -1;+ if (!rackCoreAt(t, di)) return -1;auto buf = decodeAudioFile(path);if (!buf || buf->empty()) return -1;auto sm = std::make_shared<Sampler>();sm->setSampleRate(transport_.sampleRate() > 0 ? transport_.sampleRate() : 44100.0);sm->setSample(buf, rootNote, loop);- return r->addChainInstrument(sm);+ return rackForEdit(t, di)->addChainInstrument(sm);}bool Engine::rackSetChainSamplerSample(int32_t t, int32_t di, int32_t chain, const std::string& path, int32_t rootNote) {auto* r = rackCoreAt(t, di);- if (!r) return false;+ if (!r || chain < 0 || chain >= r->chainCount()) return false;auto buf = decodeAudioFile(path);if (!buf || buf->empty()) return false;- return r->setChainInstrumentSample(chain, buf, rootNote, false);+ return rackForEdit(t, di)->setChainInstrumentSample(chain, buf, rootNote, false);}RackCore* Engine::rackCoreAt(int32_t trackId, int32_t deviceIndex) const {@@ -132,22 +135,128 @@ RackCore* Engine::rackCoreAt(int32_t trackId, int32_t deviceIndex) const {return nullptr;}+// Rack edits used to change the rack in place, and the rack object is shared by every+// graph snapshot, so undo had nothing to go back to (#236). An edit the user can undo+// forks the rack into a new object (chain children shared, so nothing restarts) and+// republishes the track with it; the snapshot on the undo stack keeps the old rack as it was.+RackCore* Engine::rackForEdit(int32_t trackId, int32_t deviceIndex) {+ auto old = findTrackAuthoring(trackId);+ if (!old || !rackCoreAt(trackId, deviceIndex)) return nullptr;+ auto nt = cloneTrack(*old);+ RackCore* fresh = nullptr;+ if (deviceIndex < 0) {+ auto* src = dynamic_cast<RackInstrument*>(old->instrument.get());+ if (!src) return nullptr;+ std::shared_ptr<RackInstrument> r;+ if (dynamic_cast<DrumRack*>(src)) r = std::make_shared<DrumRack>();+ else r = std::make_shared<RackInstrument>();+ r->forkFrom(*src);+ r->setBypassed(src->bypassed());+ r->folded = src->folded;+ r->offSettled = src->offSettled;+ r->pedalDown = src->pedalDown;+ r->pedalHeld[0] = src->pedalHeld[0];+ r->pedalHeld[1] = src->pedalHeld[1];+ for (int i = 0; i < kCtlCount; ++i)+ r->deliveredCtl[i].store(src->deliveredCtl[i].load(std::memory_order_relaxed), std::memory_order_relaxed);+ fresh = r.get();+ nt->instrument = std::move(r);+ } else {+ auto* src = dynamic_cast<RackDevice*>(old->devices[deviceIndex].get());+ if (!src) return nullptr;+ auto r = std::make_shared<RackDevice>();+ r->forkFrom(*src);+ r->setBypassed(src->bypassed());+ r->setFolded(src->folded());+ r->setSidechainSourceTrackId(src->sidechainSourceTrackId());+ r->setSidechainTapPre(src->sidechainTapPre());+ r->setSidechainGainDb(src->sidechainGainDb());+ r->setSidechainMix(src->sidechainMix());+ fresh = r.get();+ nt->devices[deviceIndex] = std::move(r);+ }+ republishWithTrack(trackId, nt);+ return fresh;+}++// ---- wrap a device in a rack / unwrap it (#257) ----------------------------+// Whether anything outside the device points at it by its chain index: automation lanes+// or CV links. Wrapping moves the device into a rack chain, where those can't follow it.+bool Engine::deviceIsReferenced(const Track& t, int32_t deviceIndex) const {+ for (auto& l : t.automation)+ if ((l.target == AutomationTarget::DeviceParam || l.target == AutomationTarget::PluginParam) && l.deviceIndex == deviceIndex)+ return true;+ for (auto& l : t.cvLinks)+ if (l.sourceKind == static_cast<int32_t>(CvSourceKind::Param) && l.sourceDevice == deviceIndex) return true;+ for (auto& ot : authoring_->tracks)+ for (auto& l : ot->cvLinks) {+ const int32_t tgt = l.targetTrack < 0 ? ot->id() : l.targetTrack;+ if (tgt == t.id() && l.targetKind == static_cast<int32_t>(CvTargetKind::Device) && l.targetDevice == deviceIndex)+ return true;+ }+ return false;+}++int32_t Engine::wrapDeviceInRack(int32_t trackId, int32_t deviceIndex) {+ auto old = findTrackAuthoring(trackId);+ if (!old || deviceIndex < 0 || deviceIndex >= static_cast<int32_t>(old->devices.size())) return -1;+ auto dev = old->devices[deviceIndex];+ if (!dev || dev->sidechainSourceTrackId() > 0 || deviceIsReferenced(*old, deviceIndex)) return -1;+ const double sr = transport_.sampleRate() > 0 ? transport_.sampleRate() : 44100.0;+ auto rack = std::make_shared<RackDevice>();+ rack->setSampleRate(sr, kMaxBlock);+ const int32_t chain = rack->addChain(-1);+ if (rack->addChainDeviceInstance(chain, dev) < 0) return -1; // the device itself: its state moves in+ auto nt = cloneTrack(*old);+ nt->devices[deviceIndex] = rack;+ republishWithTrack(trackId, nt);+ recomputePdc();+ return deviceIndex;+}++int32_t Engine::unwrapRack(int32_t trackId, int32_t deviceIndex) {+ auto old = findTrackAuthoring(trackId);+ if (!old || deviceIndex < 0 || deviceIndex >= static_cast<int32_t>(old->devices.size())) return -1;+ auto* rack = dynamic_cast<RackDevice*>(old->devices[deviceIndex].get());+ RackCore::RackState* st = rack ? rack->live() : nullptr;+ if (!st || st->chains.size() != 1 || deviceIsReferenced(*old, deviceIndex)) return -1;+ auto devs = st->chains[0].devices;+ auto nt = cloneTrack(*old);+ nt->devices.erase(nt->devices.begin() + deviceIndex);+ nt->devices.insert(nt->devices.begin() + deviceIndex, devs.begin(), devs.end());+ // The devices after the rack shift by (n - 1): their lanes and CV links follow.+ const int32_t n = static_cast<int32_t>(devs.size());+ if (n == 0) remapAutomationAfterDeviceChange(*nt, false, deviceIndex, -1, -1);+ for (int32_t i = 1; i < n; ++i)+ remapAutomationAfterDeviceChange(*nt, false, -1, static_cast<int32_t>(nt->devices.size()) - n + i, deviceIndex + i);+ republishWithTrack(trackId, nt);+ if (n == 0) remapCvLinksAfterDeviceChange(trackId, deviceIndex, -1, -1);+ for (int32_t i = 1; i < n; ++i)+ remapCvLinksAfterDeviceChange(trackId, -1, static_cast<int32_t>(nt->devices.size()) - n + i, deviceIndex + i);+ recomputePdc();+ return n;+}+// ---- chains --------------------------------------------------------------int32_t Engine::rackChainCount(int32_t t, int32_t di) const {auto* r = rackCoreAt(t, di);return r ? r->chainCount() : 0;}int32_t Engine::rackAddChain(int32_t t, int32_t di, int32_t k) {- auto* r = rackCoreAt(t, di);+ auto* r = rackForEdit(t, di);return r ? r->addChain(k) : -1;}bool Engine::rackRemoveChain(int32_t t, int32_t di, int32_t c) {auto* r = rackCoreAt(t, di);- return r && r->removeChain(c);+ if (!r || c < 0 || c >= r->chainCount()) return false;+ const bool ok = rackForEdit(t, di)->removeChain(c);+ recomputePdc(); // the chain may have held the rack's longest latency+ return ok;}bool Engine::rackSetChainInstrument(int32_t t, int32_t di, int32_t c, int32_t k) {auto* r = rackCoreAt(t, di);- return r && r->setChainInstrument(c, k);+ if (!r || c < 0 || c >= r->chainCount() || !RackCore::makeInstrument(k)) return false;+ return rackForEdit(t, di)->setChainInstrument(c, k);}int32_t Engine::rackChainInstrumentKind(int32_t t, int32_t di, int32_t c) const {auto* r = rackCoreAt(t, di);@@ -272,15 +381,19 @@ int32_t Engine::rackChainDeviceCount(int32_t t, int32_t di, int32_t c) const {}int32_t Engine::rackAddChainDevice(int32_t t, int32_t di, int32_t c, int32_t k) {auto* r = rackCoreAt(t, di);- return r ? r->addChainDevice(c, k) : -1;+ if (!r || c < 0 || c >= r->chainCount() || !makeChainDevice(k)) return -1;+ return rackForEdit(t, di)->addChainDevice(c, k);}bool Engine::rackRemoveChainDevice(int32_t t, int32_t di, int32_t c, int32_t d) {auto* r = rackCoreAt(t, di);- return r && r->removeChainDevice(c, d);+ if (!r || d < 0 || d >= r->chainDeviceCount(c)) return false;+ return rackForEdit(t, di)->removeChainDevice(c, d);}bool Engine::rackMoveChainDevice(int32_t t, int32_t di, int32_t c, int32_t from, int32_t to) {auto* r = rackCoreAt(t, di);- return r && r->moveChainDevice(c, from, to);+ if (!r || from < 0 || from >= r->chainDeviceCount(c)) return false;+ if (std::clamp(to, 0, r->chainDeviceCount(c) - 1) == from) return true;+ return rackForEdit(t, di)->moveChainDevice(c, from, to);}const char* Engine::rackChainDeviceName(int32_t t, int32_t di, int32_t c, int32_t d) const {auto* r = rackCoreAt(t, di);@@ -478,7 +591,8 @@ void Engine::rackMacroSet(int32_t t, int32_t di, int32_t m, float v) {int32_t Engine::rackAddMacroMapping(int32_t t, int32_t di, int32_t macro, int32_t chain, int32_t targetDevice,int32_t paramIndex, float rangeMin, float rangeMax) {auto* r = rackCoreAt(t, di);- return r ? r->addMacroMapping(macro, chain, targetDevice, paramIndex, rangeMin, rangeMax) : -1;+ if (!r || macro < 0 || macro >= RackCore::kNumMacros || chain < 0 || chain >= r->chainCount()) return -1;+ return rackForEdit(t, di)->addMacroMapping(macro, chain, targetDevice, paramIndex, rangeMin, rangeMax);}int32_t Engine::rackMappingCount(int32_t t, int32_t di) const {auto* r = rackCoreAt(t, di);@@ -499,7 +613,8 @@ bool Engine::rackMappingInfo(int32_t t, int32_t di, int32_t index, int32_t& macr}bool Engine::rackRemoveMapping(int32_t t, int32_t di, int32_t index) {auto* r = rackCoreAt(t, di);- return r && r->removeMapping(index);+ if (!r || index < 0 || index >= r->mappingCount()) return false;+ return rackForEdit(t, di)->removeMapping(index);}// ---- Instrument-Rack extras (zones / meter / names / rack out / macro-map) ----@@ -516,7 +631,13 @@ void Engine::rackChainZone(}void Engine::rackSetChainZone(int32_t t, int32_t di, int32_t c, int32_t keyLo, int32_t keyHi, int32_t velLo, int32_t velHi) {- if (auto* r = rackCoreAt(t, di)) r->setChainZone(c, keyLo, keyHi, velLo, velHi);+ auto* r = rackCoreAt(t, di);+ if (!r || c < 0 || c >= r->chainCount()) return;+ int32_t kl, kh, vl, vh;+ r->chainZone(c, kl, kh, vl, vh);+ auto cl = [](int32_t v) { return std::clamp(v, 0, 127); };+ if (kl == cl(keyLo) && kh == cl(keyHi) && vl == cl(velLo) && vh == cl(velHi)) return;+ rackForEdit(t, di)->setChainZone(c, keyLo, keyHi, velLo, velHi);}float Engine::rackChainMeter(int32_t t, int32_t di, int32_t c) const {auto* r = rackCoreAt(t, di);diff --git a/tests/Nota.SmokeTest/DeviceCopyTests.cs b/tests/Nota.SmokeTest/DeviceCopyTests.csnew file mode 100644index 00000000..25fb1a76--- /dev/null+++ b/tests/Nota.SmokeTest/DeviceCopyTests.cs@@ -0,0 +1,322 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// Device copy / duplicate audit (#238) and undo of rack edits (#236).+// - Copy/paste of every built-in audio effect, the Audio Effect Rack and every MIDI effect+// keeps all of its settings (every param, the state blob, bypass, sidechain mix, the Arp's+// CC modulation), survives a cut of the source, and is one undo step.+// - Duplicate track keeps every built-in instrument's params + state.+// - Drum Rack / Instrument Rack edits (a sample dropped on a pad, pad note + name, chains,+// chain devices, zones) are undoable, and a pad drop grouped as one gesture is one step.+// - ⌘G wraps a device in an Audio Effect Rack and ⌘⇧G takes it out again (#257), keeping the+// device's settings and the chain order, one undo step each.+// Also runnable alone: `dotnet run --project tests/Nota.SmokeTest -- --device-copy`.++using Nota.Application;+using Nota.Infrastructure;++namespace Nota.SmokeTest;++internal static class DeviceCopyTests+{+ private const int AudioEffectRack = 5, LastBuiltinEffect = 26, LastMidiEffect = 5, Arp = 0;+ private static readonly int[] InstrumentKinds = { 0, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };++ public static IEnumerable<(bool ok, string label)> Run()+ {+ foreach (var r in AudioEffects()) yield return r;+ foreach (var r in EffectRack()) yield return r;+ foreach (var r in MidiEffects()) yield return r;+ foreach (var r in DuplicateInstruments()) yield return r;+ foreach (var r in DrumRackUndo()) yield return r;+ foreach (var r in InstrumentRackUndo()) yield return r;+ foreach (var r in WrapInRack()) yield return r;+ }++ private static string Chain(NotaEngine e, int t)+ {+ var k = new int[e.TrackDeviceCount(t)];+ for (int i = 0; i < k.Length; i++) k[i] = e.TrackDeviceBuiltinKind(t, i);+ return string.Join(",", k);+ }++ private static IEnumerable<(bool, string)> WrapInRack()+ {+ using var e = new NotaEngine();+ int t = e.AddAudioTrack();+ e.AddBuiltinDevice(t, 0);+ int c = e.AddBuiltinDevice(t, 1);+ e.AddBuiltinDevice(t, 2);+ e.DeviceSetParam(t, c, 0, -30f);+ int r = e.WrapDeviceInRack(t, c);+ yield return (r == c && Chain(e, t) == "0,5,2" && e.RackDevChainCount(t, r) == 1 && e.RackDevChainDeviceCount(t, r, 0) == 1+ && e.RackDevChainDeviceBuiltinKind(t, r, 0, 0) == 1 && Same(e.RackDevChainDeviceParamGet(t, r, 0, 0, 0), -30f),+ $"wrap in rack: ⌘G puts the Compressor in a rack in its place, with its settings ({Chain(e, t)})");+ yield return (e.Undo() && Chain(e, t) == "0,1,2" && Same(e.DeviceGetParam(t, c, 0), -30f), "wrap in rack: undo takes it out again");+ e.Redo();+ e.RackDevAddChainDevice(t, r, 0, 3); // a Delay after it in the chain+ int n = e.UnwrapRack(t, r);+ yield return (n == 2 && Chain(e, t) == "0,1,3,2" && Same(e.DeviceGetParam(t, c, 0), -30f),+ $"wrap in rack: ⌘⇧G puts the chain's devices back in order ({Chain(e, t)})");+ yield return (e.Undo() && Chain(e, t) == "0,5,2", "wrap in rack: undo brings the rack back");++ // A keyed device stays out: a rack chain has no sidechain input.+ int src = e.AddAudioTrack();+ int keyed = e.AddBuiltinDevice(t, 1);+ e.SetDeviceSidechainSource(t, keyed, src);+ yield return (e.WrapDeviceInRack(t, keyed) < 0 && Chain(e, t) == "0,5,2,1", $"wrap in rack: a device with a sidechain key isn't wrapped ({Chain(e, t)})");+ // A rack with two chains isn't unwrapped (which chain would win?).+ e.RackDevAddChain(t, r, -1);+ yield return (e.UnwrapRack(t, r) < 0 && Chain(e, t) == "0,5,2,1", $"wrap in rack: a rack with two chains isn't unwrapped ({Chain(e, t)})");+ }++ // A value well inside the param's range and away from its default.+ private static float Off(float min, float max, float cur)+ {+ float v = min + 0.37f * (max - min);+ return Math.Abs(v - cur) < 1e-4f * Math.Max(1f, Math.Abs(max - min)) ? min + 0.71f * (max - min) : v;+ }++ private static bool Same(float a, float b) => Math.Abs(a - b) <= 1e-4f * Math.Max(1f, Math.Abs(a));++ private static float[] Params(NotaEngine e, int t, int d)+ {+ var p = new float[e.DeviceParamCount(t, d)];+ for (int i = 0; i < p.Length; i++) p[i] = e.DeviceGetParam(t, d, i);+ return p;+ }++ private static int FirstDiff(float[] a, float[] b)+ {+ if (a.Length != b.Length) return -2;+ for (int i = 0; i < a.Length; i++) if (!Same(a[i], b[i])) return i;+ return -1;+ }++ private static IEnumerable<(bool, string)> AudioEffects()+ {+ using var e = new NotaEngine();+ int a = e.AddAudioTrack(), b = e.AddAudioTrack();+ var bad = new List<string>();+ bool cutOk = true, undoOk = true;+ for (int kind = 0; kind <= LastBuiltinEffect; kind++)+ {+ if (kind == AudioEffectRack) continue;+ int d = e.AddBuiltinDevice(a, kind);+ if (d < 0) { bad.Add($"kind {kind}: not added"); continue; }+ for (int i = 0; i < e.DeviceParamCount(a, d); i++)+ e.DeviceSetParam(a, d, i, Off(e.DeviceParamMin(a, d, i), e.DeviceParamMax(a, d, i), e.DeviceGetParam(a, d, i)));+ e.SetDeviceBypassed(a, d, true);+ e.SetDeviceSidechainMix(a, d, 0.25f);+ var want = Params(e, a, d);+ var wantState = e.DeviceGetState(a, d);++ e.CopyDevice(a, d);+ e.RemoveDevice(a, d); // a cut: the clipboard holds its own copy+ int n = e.TrackDeviceCount(b);+ int p = e.PasteDevice(b, -1);+ if (p != n) { bad.Add($"kind {kind}: paste index {p}"); cutOk = false; continue; }+ int diff = FirstDiff(want, Params(e, b, p));+ if (diff != -1) bad.Add($"{e.DeviceName(b, p)} param {diff}");+ if (!wantState.AsSpan().SequenceEqual(e.DeviceGetState(b, p))) bad.Add($"{e.DeviceName(b, p)} state");+ if (!e.DeviceBypassed(b, p) || !Same(e.DeviceSidechainMix(b, p), 0.25f)) bad.Add($"{e.DeviceName(b, p)} bypass/sidechain");+ if (!(e.Undo() && e.TrackDeviceCount(b) == n && e.Redo() && e.TrackDeviceCount(b) == n + 1)) undoOk = false;+ }+ yield return (bad.Count == 0, $"device copy: every built-in audio effect pastes with all its settings ({string.Join("; ", bad)})");+ yield return (cutOk, "device copy: a cut device still pastes");+ yield return (undoOk, "device copy: a paste is one undo step");++ // Paste after the selected device: inserted at that index, the rest shift up.+ int t = e.AddAudioTrack();+ e.AddBuiltinDevice(t, 0); e.AddBuiltinDevice(t, 2);+ int c = e.AddBuiltinDevice(t, 1);+ e.DeviceSetParam(t, c, 0, -30f);+ e.CopyDevice(t, c);+ int at = e.PasteDevice(t, 1);+ yield return (at == 1 && e.TrackDeviceBuiltinKind(t, 1) == 1 && e.TrackDeviceBuiltinKind(t, 2) == 2+ && Same(e.DeviceGetParam(t, 1, 0), -30f),+ "device copy: a paste at an index lands there with its values");++ // Modular's ⌘D: a full clone right after the device, one undo step, clipboard untouched.+ int u = e.AddAudioTrack();+ e.AddBuiltinDevice(u, 0);+ int f = e.AddBuiltinDevice(u, 7);+ e.AddBuiltinDevice(u, 2);+ for (int i = 0; i < e.DeviceParamCount(u, f); i++)+ e.DeviceSetParam(u, f, i, Off(e.DeviceParamMin(u, f, i), e.DeviceParamMax(u, f, i), e.DeviceGetParam(u, f, i)));+ var fp = Params(e, u, f);+ int dup = e.DuplicateDevice(u, f);+ yield return (dup == f + 1 && Chain(e, u) == "0,7,7,2" && FirstDiff(fp, Params(e, u, dup)) == -1 && e.DeviceClipboardKind() == 1,+ $"device copy: duplicate puts a full clone right after the device ({Chain(e, u)})");+ yield return (e.Undo() && Chain(e, u) == "0,7,2", "device copy: a duplicate is one undo step");+ }++ private static IEnumerable<(bool, string)> EffectRack()+ {+ using var e = new NotaEngine();+ int a = e.AddAudioTrack(), b = e.AddAudioTrack();+ int r = e.AddBuiltinDevice(a, AudioEffectRack);+ int ch = e.RackDevAddChain(a, r, -1);+ int cd = e.RackDevAddChainDevice(a, r, ch, 1);+ e.RackDevChainDeviceParamSet(a, r, ch, cd, 0, -24f);+ var want = e.DeviceGetState(a, r);+ e.CopyDevice(a, r);+ int p = e.PasteDevice(b, -1);+ yield return (p == 0 && e.RackDevChainCount(b, p) == e.RackDevChainCount(a, r)+ && Same(e.RackDevChainDeviceParamGet(b, p, ch, cd, 0), -24f)+ && want.AsSpan().SequenceEqual(e.DeviceGetState(b, p)),+ "device copy: an Audio Effect Rack pastes with its chains and their devices");+ }++ private static IEnumerable<(bool, string)> MidiEffects()+ {+ using var e = new NotaEngine();+ int a = e.AddInstrumentTrack(), b = e.AddInstrumentTrack();+ e.SetTrackBuiltinInstrument(a, 0); e.SetTrackBuiltinInstrument(b, 0);+ var bad = new List<string>();+ for (int kind = 0; kind <= LastMidiEffect; kind++)+ {+ int m = e.AddMidiEffect(a, kind);+ int pc = e.MidiEffectParamCount(a, m);+ for (int i = 0; i < pc; i++)+ e.MidiEffectSetParam(a, m, i, Off(e.MidiEffectParamMin(a, m, i), e.MidiEffectParamMax(a, m, i), e.MidiEffectGetParam(a, m, i)));+ if (kind == Arp) { e.SetMidiEffectCcDest(a, m, -1, 3); e.SetMidiEffectCcDepth(a, m, 0.6f); }+ e.SetMidiEffectBypassed(a, m, true);+ var want = new float[pc];+ for (int i = 0; i < pc; i++) want[i] = e.MidiEffectGetParam(a, m, i);+ e.CopyMidiEffect(a, m);+ int p = e.PasteMidiEffect(b, -1);+ if (p < 0) { bad.Add($"kind {kind}: not pasted"); continue; }+ for (int i = 0; i < pc; i++)+ if (!Same(want[i], e.MidiEffectGetParam(b, p, i))) { bad.Add($"{e.MidiEffectName(b, p)} param {i}"); break; }+ if (!e.MidiEffectBypassed(b, p)) bad.Add($"{e.MidiEffectName(b, p)} bypass");+ if (kind == Arp && (e.MidiEffectCcDestParam(b, p) != 3 || !Same(e.MidiEffectCcDepth(b, p), 0.6f))) bad.Add("Arp CC modulation");+ }+ yield return (bad.Count == 0, $"device copy: every MIDI effect pastes with all its settings ({string.Join("; ", bad)})");+ int audio = e.AddAudioTrack();+ yield return (e.PasteMidiEffect(audio, -1) < 0, "device copy: a MIDI effect doesn't paste onto an audio track");+ int arp = 0;+ float rate = e.MidiEffectGetParam(a, arp, 1);+ int md = e.DuplicateMidiEffect(a, arp);+ yield return (md == 1 && e.MidiEffectKind(a, 1) == Arp && Same(e.MidiEffectGetParam(a, 1, 1), rate)+ && e.MidiEffectCcDestParam(a, 1) == 3 && e.MidiEffectBypassed(a, 1),+ "device copy: duplicating a MIDI effect keeps its settings and CC modulation");+ }++ private static IEnumerable<(bool, string)> DuplicateInstruments()+ {+ using var e = new NotaEngine();+ var bad = new List<string>();+ foreach (int kind in InstrumentKinds)+ {+ int t = e.AddInstrumentTrack();+ if (!e.SetTrackBuiltinInstrument(t, kind)) { bad.Add($"kind {kind}: not set"); continue; }+ int pc = e.PluginParamCount(t, -1);+ for (int i = 0; i < pc; i++)+ e.PluginParamSet(t, -1, i, Off(0f, 1f, e.PluginParamGet(t, -1, i)));+ var want = new float[pc];+ for (int i = 0; i < pc; i++) want[i] = e.PluginParamGet(t, -1, i);+ var wantState = e.GetPluginState(t, -1);+ int d = e.DuplicateTrack(t);+ string name = e.DeviceName(t, -1);+ if (d < 0 || e.PluginParamCount(d, -1) != pc) { bad.Add($"{name}: not duplicated"); continue; }+ for (int i = 0; i < pc; i++)+ if (!Same(want[i], e.PluginParamGet(d, -1, i))) { bad.Add($"{name} param {i}"); break; }+ if (!wantState.AsSpan().SequenceEqual(e.GetPluginState(d, -1))) bad.Add($"{name} state");+ }+ yield return (bad.Count == 0, $"device copy: duplicate track keeps every instrument's settings ({string.Join("; ", bad)})");+ }++ private static string Wav(float hz)+ {+ const int rate = 44100;+ var path = Path.Combine(Path.GetTempPath(), $"nota-pad-{Guid.NewGuid():N}.wav");+ var x = new float[rate / 4 * 2];+ for (int i = 0; i < x.Length / 2; i++) x[2 * i] = x[2 * i + 1] = 0.5f * (float)Math.Sin(2 * Math.PI * hz * i / rate);+ using (var w = new Nota.Infrastructure.WavWriter(path, rate, 2, WavBitDepth.Float32)) w.WriteFrames(x, x.Length / 2);+ return path;+ }++ private static IEnumerable<(bool, string)> DrumRackUndo()+ {+ using var e = new NotaEngine();+ int t = e.AddDrumRackTrack();+ string kick = Wav(60), snare = Wav(200);++ // An empty pad: the drop (add + note + name, one gesture) undoes in one step.+ e.BeginUndoGroup();+ int p = e.RackAddSamplerChain(t, kick, 36, false);+ e.RackSetChainTriggerNote(t, p, 36);+ e.RackSetChainName(t, p, "Kick");+ e.EndUndoGroup();+ yield return (e.RackChainCount(t) == 1 && e.RackChainName(t, 0) == "Kick", "rack undo: a sample dropped on an empty pad");+ yield return (e.Undo() && e.RackChainCount(t) == 0, "rack undo: one undo empties the pad again");+ yield return (e.Redo() && e.RackChainCount(t) == 1 && e.RackChainTriggerNote(t, 0) == 36 && e.RackChainName(t, 0) == "Kick",+ "rack undo: redo brings the sample back on its note with its name");++ // A replaced pad gets its previous sample back with its level, name and devices.+ e.RackSetChainGain(t, 0, 0.5f);+ e.RackAddChainDevice(t, 0, 1);+ e.RackChainSamplerInfo(t, 0, out var before);+ e.BeginUndoGroup();+ e.RackRemoveChain(t, 0);+ int q = e.RackAddSamplerChain(t, snare, 36, false);+ e.RackSetChainTriggerNote(t, q, 36);+ e.RackSetChainName(t, q, "Snare");+ e.EndUndoGroup();+ yield return (e.RackChainName(t, 0) == "Snare" && e.RackChainDeviceCount(t, 0) == 0, "rack undo: a sample dropped on a full pad replaces it");+ e.Undo();+ e.RackChainSamplerInfo(t, 0, out var back);+ yield return (e.RackChainCount(t) == 1 && e.RackChainName(t, 0) == "Kick" && Same(e.RackChainGain(t, 0), 0.5f)+ && e.RackChainDeviceCount(t, 0) == 1 && back.SampleId == before.SampleId,+ "rack undo: undo puts the previous sample back with its level, name and devices");++ // Single edits are their own steps: rename, note, a chain device.+ e.RackSetChainName(t, 0, "Kick 2");+ yield return (e.Undo() && e.RackChainName(t, 0) == "Kick", "rack undo: a pad rename");+ e.RackSetChainTriggerNote(t, 0, 38);+ yield return (e.Undo() && e.RackChainTriggerNote(t, 0) == 36, "rack undo: a pad note change");+ e.RackRemoveChainDevice(t, 0, 0);+ yield return (e.Undo() && e.RackChainDeviceCount(t, 0) == 1, "rack undo: a removed pad device");++ // A no-op edit (the same name) doesn't add an undo step.+ int depth = 0;+ e.RackSetChainName(t, 0, "Kick");+ while (e.Undo()) depth++;+ yield return (e.RackChainCount(t) == 0 && depth > 0, "rack undo: undo walks the whole pad history back");++ // It still plays after edits and undo/redo (the forked rack renders).+ while (e.Redo()) { }+ e.SetBpm(120); e.SetMetronome(false);+ int clip = e.AddMidiClip(t, 0.0, 1.0);+ e.SetClipNotes(t, clip, new[] { new NotaNote(36, 0.0, 0.5, 1.0f) });+ var buf = new float[512 * 2];+ float peak = 0f;+ e.Seek(0); e.Play();+ for (int i = 0; i < 20; i++) { e.RenderOffline(buf, 512, 44100); foreach (var s in buf) peak = Math.Max(peak, Math.Abs(s)); }+ e.StopTransport();+ yield return (peak > 0.05f, $"rack undo: the pad plays after undo/redo (peak {peak:F2})");+ File.Delete(kick); File.Delete(snare);+ }++ private static IEnumerable<(bool, string)> InstrumentRackUndo()+ {+ using var e = new NotaEngine();+ int t = e.AddInstrumentRackTrack();+ int c = e.RackAddChain(t, 0);+ yield return (e.RackChainCount(t) == 2 && e.Undo() && e.RackChainCount(t) == 1, "rack undo: an added Instrument Rack chain");+ e.RackSetChainZone(t, 0, 36, 60, 0, 127);+ e.RackChainZone(t, 0, out int lo, out int hi, out _, out _);+ bool set = lo == 36 && hi == 60;+ yield return (set && e.Undo() && Zone(e, t) == (0, 127), "rack undo: a key-zone edit");+ e.RackSetChainInstrument(t, 0, 2);+ yield return (e.RackChainInstrumentKind(t, 0) == 2 && e.Undo() && e.RackChainInstrumentKind(t, 0) != 2, "rack undo: a chain instrument swap");+ _ = c;+ }++ private static (int, int) Zone(NotaEngine e, int t)+ {+ e.RackChainZone(t, 0, out int lo, out int hi, out _, out _);+ return (lo, hi);+ }+}diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex f928e262..6341e7e4 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -385,6 +385,14 @@ if (args.Length >= 1 && args[0] == "--device-undo")Console.WriteLine(failures == 0 ? "DEVICE UNDO PASSED" : $"DEVICE UNDO FAILED ({failures})");return failures == 0 ? 0 : 1;}+// Device copy / duplicate audit + rack undo alone: `--device-copy`. Also part of the full run.+if (args.Length >= 1 && args[0] == "--device-copy")+{+ Console.WriteLine("-- device copy + rack undo --");+ foreach (var (ok, label) in DeviceCopyTests.Run()) Check(ok, label);+ Console.WriteLine(failures == 0 ? "DEVICE COPY PASSED" : $"DEVICE COPY FAILED ({failures})");+ return failures == 0 ? 0 : 1;+}// Device fold alone: `--fold`. Also part of the full run.if (args.Length >= 1 && args[0] == "--fold"){@@ -15070,6 +15078,8 @@ Console.WriteLine("-- param + section undo --");foreach (var (ok, label) in ParamSectionUndoTests.Run()) Check(ok, label);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("-- stereo map --");foreach (var (ok, label) in StereoMeasureTests.Run()) Check(ok, label);