Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(fix) Device undo, Session take display, Mosaic Init, palette/window-move crash (#174)

Chris Laupamaa4b4ed04c4ea
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b42d75d9..e68ed0d8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -147,6 +147,25 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
- **Stop also stops Session clips** (nota-daw/nota#139): the transport's Stop (Return, or
Space while playing) now stops the clips launched in the Session view right away, as Stop
all clips does. Before, they stayed launched and started again on the next Play.
+- **Undo brings a removed device back where you can see it** (nota-daw/nota#109): removing a
+ device and pressing Undo now shows it again in the Devices panel for the track the panel
+ is showing (the Master, a track other than the selected one), and in Modular. Before, the
+ device came back in the engine but the panel kept the old chain until you clicked away.
+ Undo and Redo also restore the delay compensation a look-ahead device adds, so the other
+ tracks line up again. Devices inside a rack still aren't covered by undo.
+- **A Session take shows its notes when recording stops** (nota-daw/nota#156): stopping a
+ Session recording with the transport's Stop (or when the take ends on its own) now draws
+ the recorded clip and its notes in the slot right away, and in the piano roll if the slot
+ is open there. Before, the slot looked empty until you switched views.
+- **Mosaic: back to Init** (nota-daw/nota#165): choosing **Init** in a Nota Mosaic card's
+ preset list now empties the instrument, as on a freshly added Mosaic: no samples, every
+ parameter at its default. Before, Init reset the parameters but kept the multisample, so
+ the list jumped back to the preset's name.
+- **No crash when a panel moves between windows** (nota-daw/nota#164): opening the command
+ palette (⌘⇧P / Ctrl+Shift+P) from the Mixer window or a popped-out panel after using it in
+ the main window, opening or closing the Mixer, or popping the Devices or Clip panel out and
+ back, no longer crashes the app with "Attempt to call InvalidateArrange on wrong
+ LayoutManager".
### Added
- **Loop recording: Overdub or Replace** (nota-daw/nota#29): when you record MIDI in a loop,
diff --git a/FEATURES.md b/FEATURES.md
index 86eec46e..cd9dc94e 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -583,7 +583,7 @@ audio effects after it keep running and keep their settings; saved with the proj
and lists gaps, duplicates and guessed notes (browser folder menu, or files dropped on the
card). Installed sample packs become presets under Nota Mosaic → Packs. 11 factory presets
on built-in multisamples (felt piano with release samples, mallets, nylon guitar, brass, pad,
- music box) rendered on first use; MCP `read_mosaic`, `set_mosaic`, `set_mosaic_zone`,
+ music box) rendered on first use; Init in the card's preset list empties the instrument; MCP `read_mosaic`, `set_mosaic`, `set_mosaic_zone`,
`set_mosaic_group`, `import_sfz`, `create_multisample`, `list_mosaic_presets`,
`load_mosaic_preset`, `scan_sample_packs`.
diff --git a/src/managed/Nota.App/DeviceChainView.Instruments.cs b/src/managed/Nota.App/DeviceChainView.Instruments.cs
index 5d3e43f9..839b8ef4 100644
--- a/src/managed/Nota.App/DeviceChainView.Instruments.cs
+++ b/src/managed/Nota.App/DeviceChainView.Instruments.cs
@@ -63,7 +63,9 @@ public sealed partial class DeviceChainView
int t = _trackId;
var items = new System.Collections.Generic.List<(string, string)>();
foreach (var p in _factory.All())
- if (p.IsInstrument && p.BuiltinKind == Nota.Application.MosaicModel.Kind) items.Add(("factory:" + p.Id, p.DisplayName));
+ // The factory "Init" keeps the loaded program, so here it would read as the program's
+ // name again: the card's own Init (every default, no program) takes its place (#165).
+ if (p.IsInstrument && p.BuiltinKind == Nota.Application.MosaicModel.Kind && p.DisplayName != "Init") items.Add(("factory:" + p.Id, p.DisplayName));
if (_mosaic is not null)
foreach (var p in _mosaic.Presets()) items.Add((p.Path, $"{p.Folder} / {p.Name}"));
// A program that is no preset (an SFZ, dropped files) still names itself in the picker.
@@ -82,7 +84,7 @@ public sealed partial class DeviceChainView
if (id == "program:") return "";
if (id.StartsWith("factory:", StringComparison.Ordinal)) return _factory.ApplyInPlace(_engine, id["factory:".Length..], t, -1);
return _mosaic?.ApplyInPlace(_engine, id, t) ?? "Presets are unavailable.";
- });
+ }, Init: () => _factory.ResetInPlace(_engine, t, -1, false)); // every param to default, no program (#165)
}
// The Instrument Rack in the shared shell; the badge counts its chains.
diff --git a/src/managed/Nota.App/DeviceChainView.Shell.cs b/src/managed/Nota.App/DeviceChainView.Shell.cs
index 4e974018..c4d4a766 100644
--- a/src/managed/Nota.App/DeviceChainView.Shell.cs
+++ b/src/managed/Nota.App/DeviceChainView.Shell.cs
@@ -108,9 +108,11 @@ public sealed partial class DeviceChainView
/// <summary>A card's own preset list, in place of the factory presets for its kind — the
/// Drum Rack's kits, which load pads rather than set parameters. <paramref name="Current"/>
/// names the one the device holds now ("" when none fits); <paramref name="Apply"/> loads
- /// one by id and returns a warning, or "".</summary>
+ /// one by id and returns a warning, or "". <paramref name="Init"/>, when given, puts the
+ /// device back as freshly added and returns a warning, or "": the list gets an Init entry.</summary>
internal sealed record CardPresets(
- IReadOnlyList<(string Id, string Name)> Items, Func<string> Current, Func<string, string> Apply);
+ IReadOnlyList<(string Id, string Name)> Items, Func<string> Current, Func<string, string> Apply,
+ Func<string>? Init = null);
// Small tertiary caption / mono readout helpers.
private static TextBlock Caps(string t, double fs = 9) => new() { Text = NotaText.Label(t), FontSize = fs, FontWeight = FontWeight.Medium, Foreground = TextSecondary, VerticalAlignment = VerticalAlignment.Center };
@@ -202,7 +204,7 @@ public sealed partial class DeviceChainView
// Factory presets for this device (or the card's own list), and applying one in place.
List<(string Id, string Name)> presets;
Action<string> applyById;
- Action? resetToInit = null; // factory lists only: Init isn't a preset, it's every default (#57)
+ Action? resetToInit = null; // Init isn't a preset, it's every default (#57); an own list opts in (#165)
if (s.Presets is { } own)
{
presets = own.Items.ToList();
@@ -216,6 +218,13 @@ public sealed partial class DeviceChainView
if (warn.Length > 0) StatusMessage?.Invoke(warn);
Changed?.Invoke();
};
+ if (own.Init is { } init)
+ resetToInit = () =>
+ {
+ string warn = init();
+ if (warn.Length > 0) StatusMessage?.Invoke(warn);
+ Changed?.Invoke();
+ };
}
else
{
diff --git a/src/managed/Nota.App/MainWindow.Detail.cs b/src/managed/Nota.App/MainWindow.Detail.cs
index 354445ab..acb4d5e6 100644
--- a/src/managed/Nota.App/MainWindow.Detail.cs
+++ b/src/managed/Nota.App/MainWindow.Detail.cs
@@ -179,7 +179,7 @@ public partial class MainWindow
_patternScene = -1;
_sessionSlotTrack = -1;
_sessionSlotScene = -1;
- if (DetailFloating) _detailWindow!.ClipHost.Content = ClipPlaceholder();
+ if (DetailFloating) SetHost(_detailWindow!.ClipHost, ClipPlaceholder());
}
// The Clip tab targets the *currently selected* arrangement clip (MIDI or audio),
@@ -504,7 +504,16 @@ public partial class MainWindow
private void ReloadEditorNotes()
{
_patternView?.Reload(); // the step grid is a second view of the same notes
- if (_vm is null || _editorRoll is null || _editorTrackId < 0) return;
+ if (_vm is null || _editorRoll is null) return;
+ if (_editorTrackId < 0)
+ {
+ // A Session slot's piano roll follows a take recorded into it the same way (#156).
+ if (_sessionSlotTrack <= 0 || _sessionSlotScene < 0) return;
+ double slotLen = Engine.SessionSlotLength(_sessionSlotTrack, _sessionSlotScene);
+ _editorRoll.SetNotes(Engine.GetSessionNotes(_sessionSlotTrack, _sessionSlotScene),
+ slotLen > 0 ? slotLen : _editorRoll.LengthBeats);
+ return;
+ }
bool hasInfo = Engine.TryGetClipInfo(_editorTrackId, _editorClipIndex, out var ci);
double len = hasInfo && ci.LengthBeats > 0 ? ci.LengthBeats : _editorRoll.LengthBeats;
_editorRoll.SetNotes(Engine.GetClipNotes(_editorTrackId, _editorClipIndex), len);
diff --git a/src/managed/Nota.App/MainWindow.DetailWindow.cs b/src/managed/Nota.App/MainWindow.DetailWindow.cs
index 99ad876e..5bbceebb 100644
--- a/src/managed/Nota.App/MainWindow.DetailWindow.cs
+++ b/src/managed/Nota.App/MainWindow.DetailWindow.cs
@@ -9,6 +9,7 @@
using Avalonia;
using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
@@ -28,20 +29,29 @@ public partial class MainWindow
private ContentControl ClipDetailHost => _detailWindow?.ClipHost ?? DetailBody;
// Assign a control to a ContentControl host, detaching it from any previous host first
- // (a control can have only one parent). Moving to another window, the old window's
- // pending layout is run between the detach and the attach: each window keeps its own
- // layout queue (the detach itself queues the control there), and an entry left behind for
- // a control that now lives in the other window throws "InvalidateArrange on wrong
- // LayoutManager" on a later frame (seen on Linux/X11 popping out the piano roll).
+ // (a control can have only one parent). Each window keeps its own layout queue, and an
+ // entry left in one window's queue for a control that now lives in another throws
+ // "InvalidateArrange on wrong LayoutManager" on a later frame and aborts the app (#83 on
+ // Linux, #164 on macOS). So before the attach, every other open window runs its pending
+ // layout while the control is detached, which drops those entries. That covers more than
+ // the old host's window: the control may have left its previous host earlier (a tab switch
+ // detaches the clip editor, _lastClipEditor is re-hosted later), and Avalonia re-queues a
+ // control caught in a layout cycle after the pass without scheduling another one, so an
+ // entry can sit in a window's queue long after the control left it.
private static void SetHost(ContentControl host, Control? content)
{
- if (content?.Parent is ContentControl prev && !ReferenceEquals(prev, host))
- {
- var from = TopLevel.GetTopLevel(prev);
- prev.Content = null;
- if (from is not null && !ReferenceEquals(from, TopLevel.GetTopLevel(host))) from.UpdateLayout();
- }
- if (!ReferenceEquals(host.Content, content)) host.Content = content;
+ if (content?.Parent is ContentControl prev && !ReferenceEquals(prev, host)) prev.Content = null;
+ if (ReferenceEquals(host.Content, content)) return;
+ if (content is not null) FlushOtherWindows(TopLevel.GetTopLevel(host));
+ host.Content = content;
+ }
+
+ // Run the pending layout of every open window except `keep` (see SetHost).
+ private static void FlushOtherWindows(TopLevel? keep)
+ {
+ if (Avalonia.Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return;
+ foreach (var w in desktop.Windows)
+ if (!ReferenceEquals(w, keep)) w.UpdateLayout();
}
private void OnToggleDetailWindow(object? sender, RoutedEventArgs e)
diff --git a/src/managed/Nota.App/MainWindow.Menu.cs b/src/managed/Nota.App/MainWindow.Menu.cs
index 1b8f7578..42b84c25 100644
--- a/src/managed/Nota.App/MainWindow.Menu.cs
+++ b/src/managed/Nota.App/MainWindow.Menu.cs
@@ -63,8 +63,13 @@ public partial class MainWindow
{
Timeline.Refresh();
_session?.Refresh();
- if (_deviceChain?.IsVisible == true && Timeline.SelectedTrackId > 0)
- _deviceChain.Show(Timeline.SelectedTrackId); // reflect device-chain edits
+ // Reflect device-chain edits (a removed device coming back, #109) on the track the
+ // chain is showing, which isn't always the selected one (a peek, the master, nothing
+ // selected) — rebuilding the selected track's chain there showed the wrong devices.
+ if (_deviceChain is { TrackId: > 0 } chain)
+ chain.Show(chain.TrackId == Engine.MasterTrackId || TrackExists(chain.TrackId)
+ ? chain.TrackId : Timeline.SelectedTrackId); // its track was undone away
+ if (_modular?.IsVisible == true) _modular.Refresh();
ReloadEditorNotes(); // reflect clip/note edits
// Volume / pan / master steps (specs/009): the master volume lives on the view model
// (MST, Master row, Mixer and Remote follow it), the track strips in the Mixer rebuild.
diff --git a/src/managed/Nota.App/MainWindow.Palette.cs b/src/managed/Nota.App/MainWindow.Palette.cs
index a04a71cf..c9e30676 100644
--- a/src/managed/Nota.App/MainWindow.Palette.cs
+++ b/src/managed/Nota.App/MainWindow.Palette.cs
@@ -94,7 +94,9 @@ public partial class MainWindow
Panel layer = source is NotaWindow nw and (MixerWindow or DetailWindow) ? nw.OverlayLayer : PaletteLayer;
var host = source is MixerWindow or DetailWindow ? source : this;
if (_palette.Parent is Panel old && !ReferenceEquals(old, layer)) { old.Children.Remove(_palette); old.Children.Remove(_paletteToast); }
- if (_palette.Parent is null) { layer.Children.Add(_palette); layer.Children.Add(_paletteToast); }
+ // Moving to another window: let the other windows finish their layout pass first so no stale
+ // entry for the palette is left in the old window's queue (#164).
+ if (_palette.Parent is null) { FlushOtherWindows(TopLevel.GetTopLevel(layer)); layer.Children.Add(_palette); layer.Children.Add(_paletteToast); }
_paletteReturnFocus = TopLevel.GetTopLevel(host)?.FocusManager?.GetFocusedElement();
if (!ReferenceEquals(host, source) || source is null) Activate();
_palette.Open(ctx with { Window = host }, it => PaletteTargets.Check(it, ctx, id => ActionAvailability(id, ctx)),
diff --git a/src/managed/Nota.App/MixerWindow.cs b/src/managed/Nota.App/MixerWindow.cs
index 4a682bf5..8016c2f2 100644
--- a/src/managed/Nota.App/MixerWindow.cs
+++ b/src/managed/Nota.App/MixerWindow.cs
@@ -106,7 +106,10 @@ internal sealed class MixerWindow : NotaWindow
protected override void OnClosing(WindowClosingEventArgs e)
{
base.OnClosing(e);
- Host.Content = null; // detach the mixer so it can be re-hosted next time
+ // Detach the mixer so it can be re-hosted next time, then run this window's pending
+ // layout so no entry queued for it here outlives the move (see MainWindow.SetHost).
+ Host.Content = null;
+ UpdateLayout();
WindowClosed?.Invoke();
}
}
diff --git a/src/managed/Nota.App/SessionView.cs b/src/managed/Nota.App/SessionView.cs
index b26fad12..f7d50ecc 100644
--- a/src/managed/Nota.App/SessionView.cs
+++ b/src/managed/Nota.App/SessionView.cs
@@ -269,7 +269,12 @@ public sealed partial class SessionView : UserControl
/// <summary>Re-reads live slot state, progress and meters and repaints (no rebuild).</summary>
public void UpdateStates()
{
+ // A take that just ended (Stop / Space in the transport, a fixed length running out)
+ // leaves its cell drawing the notes it was built with — none, for a new slot — so
+ // rebuild that slot from what was recorded (#156).
+ int endedTrack = _recTrack, endedScene = _recScene;
ReadRecordTarget();
+ if (endedScene >= 0 && (endedTrack != _recTrack || endedScene != _recScene)) RefreshSlot(endedTrack, endedScene);
_blinkFrame++;
_blinkOn = (_blinkFrame / 8) % 2 == 0; // ~2 Hz at the 30 Hz UI clock
bool active = false;
diff --git a/src/managed/Nota.Infrastructure/Persistence/PresetService.cs b/src/managed/Nota.Infrastructure/Persistence/PresetService.cs
index 08038ac8..76b53ef8 100644
--- a/src/managed/Nota.Infrastructure/Persistence/PresetService.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/PresetService.cs
@@ -299,7 +299,13 @@ public static class PresetService
{
if (trackId <= 0) return "Select a track first.";
if (deviceIndex < 0)
- return ApplyInPlace(new PresetDocument { Type = "builtin-instrument", NamedParams = new() }, engine, trackId, -1);
+ {
+ string warn = ApplyInPlace(new PresetDocument { Type = "builtin-instrument", NamedParams = new() }, engine, trackId, -1);
+ // Mosaic's sound is its program, not its params: Init empties it, as on a fresh Mosaic (#165).
+ if (warn.Length == 0 && engine.TrackInstrumentKind(trackId) == MosaicModel.Kind && engine.MosaicProgram(trackId).Length > 0)
+ engine.MosaicSetProgram(trackId, "");
+ return warn;
+ }
if (midiEffect)
{
int pc = engine.MidiEffectParamCount(trackId, deviceIndex);
diff --git a/src/native/nota.engine/src/Engine.cpp b/src/native/nota.engine/src/Engine.cpp
index 0014e842..01f1578e 100644
--- a/src/native/nota.engine/src/Engine.cpp
+++ b/src/native/nota.engine/src/Engine.cpp
@@ -566,7 +566,9 @@ bool Engine::undo() {
undoStack_.pop_back();
bool applied = false;
redoStack_.push_back({e.graph ? authoring_ : nullptr, e.mix});
- if (e.graph) { publishRaw(std::move(e.graph)); applied = true; } // restore without a new checkpoint
+ // Restore without a new checkpoint; the restored chains may add or drop a latent
+ // device (a removed look-ahead coming back, #109), so compensation follows them.
+ if (e.graph) { publishRaw(std::move(e.graph)); recomputePdc(); applied = true; }
for (const auto& c : e.mix) applied |= applyMix(c, false);
if (applied) return true;
}
@@ -579,7 +581,7 @@ bool Engine::redo() {
redoStack_.pop_back();
bool applied = false;
undoStack_.push_back({e.graph ? authoring_ : nullptr, e.mix});
- if (e.graph) { publishRaw(std::move(e.graph)); applied = true; }
+ if (e.graph) { publishRaw(std::move(e.graph)); recomputePdc(); applied = true; }
for (const auto& c : e.mix) applied |= applyMix(c, true);
if (applied) return true;
}
diff --git a/tests/Nota.SmokeTest/DeviceRemoveUndoTests.cs b/tests/Nota.SmokeTest/DeviceRemoveUndoTests.cs
new file mode 100644
index 00000000..399ea678
--- /dev/null
+++ b/tests/Nota.SmokeTest/DeviceRemoveUndoTests.cs
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Undo of a removed device (#109): undo puts the very device back where it was, with its
+// parameter values and bypass, redo removes it again, and latency compensation follows both —
+// a removed look-ahead device that comes back delays the other tracks again.
+// Also runnable alone: `dotnet run --project tests/Nota.SmokeTest -- --device-undo`.
+
+using Nota.Application;
+using Nota.Infrastructure;
+
+namespace Nota.SmokeTest;
+
+internal static class DeviceRemoveUndoTests
+{
+ private const int Eq8 = 0, Compressor = 1, Reverb = 2, Arp = 0;
+ private const int Lookahead = 7; // Compressor look-ahead, ms (reported as latency)
+
+ public static IEnumerable<(bool ok, string label)> Run()
+ {
+ foreach (var r in Restore()) yield return r;
+ foreach (var r in Latency()) 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)> Restore()
+ {
+ using var e = new NotaEngine();
+ int t = e.AddInstrumentTrack();
+ e.SetTrackBuiltinInstrument(t, 0);
+ e.AddBuiltinDevice(t, Eq8);
+ int c = e.AddBuiltinDevice(t, Compressor);
+ e.AddBuiltinDevice(t, Reverb);
+ e.DeviceSetParam(t, c, 0, -30f); // threshold
+ e.DeviceSetParam(t, c, 1, 8f); // ratio
+ e.SetDeviceBypassed(t, c, true);
+ int m = e.AddMidiEffect(t, Arp);
+ e.MidiEffectSetParam(t, m, 1, 3f);
+ float arpParam = e.MidiEffectGetParam(t, m, 1);
+ string before = Chain(e, t);
+
+ e.RemoveDevice(t, c);
+ yield return (Chain(e, t) == "0,2", $"device undo: the Compressor is removed ({Chain(e, t)})");
+ yield return (e.Undo() && Chain(e, t) == before, $"device undo: undo puts it back in place ({Chain(e, t)} vs {before})");
+ yield return (Math.Abs(e.DeviceGetParam(t, c, 0) + 30f) < 1e-3 && Math.Abs(e.DeviceGetParam(t, c, 1) - 8f) < 1e-3 && e.DeviceBypassed(t, c),
+ $"device undo: with its values and bypass (thr {e.DeviceGetParam(t, c, 0):F1}, ratio {e.DeviceGetParam(t, c, 1):F1}, bypassed {e.DeviceBypassed(t, c)})");
+ yield return (e.Redo() && Chain(e, t) == "0,2", "device undo: redo removes it again");
+ e.Undo();
+
+ e.RemoveMidiEffect(t, m);
+ yield return (e.TrackMidiEffectCount(t) == 0 && e.Undo() && e.TrackMidiEffectCount(t) == 1
+ && Math.Abs(e.MidiEffectGetParam(t, m, 1) - arpParam) < 1e-3,
+ "device undo: a removed MIDI effect comes back with its values");
+ }
+
+ // Latency compensation: track B is held back by track A's look-ahead. Removing the
+ // Compressor drops that; undo (and redo) must recompute it, not keep the last value.
+ private static IEnumerable<(bool, string)> Latency()
+ {
+ using var e = new NotaEngine();
+ e.SetBpm(120);
+ e.SetMetronome(false);
+ int a = e.AddInstrumentTrack();
+ e.SetTrackBuiltinInstrument(a, 0);
+ int c = e.AddBuiltinDevice(a, Compressor);
+ e.DeviceSetParam(a, c, Lookahead, 10f);
+ e.SetTrackMute(a, true);
+ int b = e.AddInstrumentTrack();
+ e.SetTrackBuiltinInstrument(b, 0);
+ int clip = e.AddMidiClip(b, 0.0, 4.0);
+ e.SetClipNotes(b, clip, new[] { new NotaNote(60, 0.0, 2.0, 1.0f) });
+ int lat = e.TrackLatencySamples(a);
+
+ int Onset()
+ {
+ e.StopTransport();
+ e.Seek(0.0);
+ var buf = new float[256 * 2];
+ e.RenderOffline(buf, 256); // drain the stop / seek
+ e.RenderOffline(buf, 256);
+ e.Play();
+ for (int done = 0; done < 48000; done += 256)
+ {
+ e.RenderOffline(buf, 256);
+ for (int i = 0; i < 256; i++)
+ if (Math.Abs(buf[i * 2]) > 1e-4f) { e.StopTransport(); return done + i; }
+ }
+ e.StopTransport();
+ return -1;
+ }
+
+ int with = Onset();
+ e.RemoveDevice(a, c);
+ int without = Onset();
+ e.Undo();
+ int undone = Onset();
+ e.Redo();
+ int redone = Onset();
+ yield return (lat > 0 && Math.Abs(with - without - lat) <= 2,
+ $"device undo: the look-ahead delays the other track and removing it doesn't ({with} vs {without}, latency {lat})");
+ yield return (Math.Abs(undone - with) <= 2, $"device undo: undo brings the compensation back ({undone} vs {with})");
+ yield return (Math.Abs(redone - without) <= 2, $"device undo: redo drops it again ({redone} vs {without})");
+ }
+}
diff --git a/tests/Nota.SmokeTest/PresetInitTests.cs b/tests/Nota.SmokeTest/PresetInitTests.cs
index b9897318..dd08fc19 100644
--- a/tests/Nota.SmokeTest/PresetInitTests.cs
+++ b/tests/Nota.SmokeTest/PresetInitTests.cs
@@ -4,8 +4,10 @@
// Init in the preset list (#57): after a factory preset, ResetInPlace puts every parameter of a
// built-in instrument, audio effect or MIDI effect back to its default, as on a freshly added
// device, and keeps the card size (the instrument's view param, a MIDI effect's "View").
+// Nota Mosaic (#165): Init also empties its program, back to a fresh Mosaic, in one undo step.
using Nota.Application;
+using Nota.Application.Mosaic;
using Nota.Infrastructure;
namespace Nota.SmokeTest;
@@ -56,5 +58,19 @@ internal static class PresetInitTests
int mOff = Enumerable.Range(0, mc).Count(i => i != mView && Math.Abs(e.MidiEffectGetParam(t, m, i) - e.MidiEffectParamDefault(t, m, i)) > 1e-4);
yield return (mc > 0 && mOff == 0, $"Init puts every MIDI effect param back to its default ({mOff} of {mc} left off)");
yield return (mView < 0 || Math.Abs(e.MidiEffectGetParam(t, m, mView) - mViewBefore) < 1e-6, "Init keeps the MIDI effect card's size (View)");
+
+ // ---- Nota Mosaic: its sound is the program, so Init empties it (#165) ---------------
+ int ms = e.AddInstrumentTrack();
+ e.SetTrackBuiltinInstrument(ms, MosaicModel.Kind);
+ int msc = e.PluginParamCount(ms, -1), msView = InstrumentView.Index(e, ms);
+ e.MosaicSetProgram(ms, new MosaicProgram { Name = "Test Piano", SourceKind = "files" }.Serialize());
+ for (int i = 0; i < msc; i++)
+ if (i != msView) e.PluginParamSet(ms, -1, i, e.InstrumentParamDefault(ms, i) < 0.5f ? 0.9f : 0.1f);
+ bool held = e.MosaicProgram(ms).Length > 0;
+ yield return (cat.ResetInPlace(e, ms, -1, midiEffect: false).Length == 0, "Init on Mosaic reports no warning");
+ int msOff = Enumerable.Range(0, msc).Count(i => i != msView && Math.Abs(e.PluginParamGet(ms, -1, i) - e.InstrumentParamDefault(ms, i)) > 1e-4);
+ yield return (held && e.MosaicProgram(ms).Length == 0 && msOff == 0,
+ $"Init empties Mosaic's program and resets its params (program held before: {held}, {msOff} params left off)");
+ yield return (e.Undo() && MosaicProgram.Parse(e.MosaicProgram(ms)).Name == "Test Piano", "undo brings Mosaic's program back");
}
}
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index 3e126512..45e07832 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -317,6 +317,14 @@ if (args.Length >= 1 && args[0] == "--paramundo")
Console.WriteLine(failures == 0 ? "PARAMUNDO PASSED" : $"PARAMUNDO FAILED ({failures})");
return failures == 0 ? 0 : 1;
}
+// Undo of a removed device alone: `--device-undo`. Also part of the full run.
+if (args.Length >= 1 && args[0] == "--device-undo")
+{
+ Console.WriteLine("-- device remove undo --");
+ foreach (var (ok, label) in DeviceRemoveUndoTests.Run()) Check(ok, label);
+ Console.WriteLine(failures == 0 ? "DEVICE UNDO PASSED" : $"DEVICE UNDO FAILED ({failures})");
+ return failures == 0 ? 0 : 1;
+}
// Device fold alone: `--fold`. Also part of the full run.
if (args.Length >= 1 && args[0] == "--fold")
{
@@ -14837,6 +14845,8 @@ foreach (var (ok, label) in MixUndoTests.Run()) Check(ok, label);
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("-- stereo map --");
foreach (var (ok, label) in StereoMeasureTests.Run()) Check(ok, label);