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) Return tracks can be deleted in the arrangement

Egor Khindikaynenc3029623403c
diff --git a/.specify/bugs/return-track-delete/assessment.md b/.specify/bugs/return-track-delete/assessment.md
new file mode 100644
index 00000000..9225ecdf
--- /dev/null
+++ b/.specify/bugs/return-track-delete/assessment.md
@@ -0,0 +1,116 @@
+# Bug Assessment: Return track can't be deleted in the arrangement
+
+- **Slug**: return-track-delete
+- **Created**: 2026-10-13
+- **Source**: pasted text (user report)
+- **Verdict**: valid
+- **Severity**: medium
+
+## Report (verbatim or summarized)
+
+> Заметил проблему, что нельзя через контекстное меню или delete / backspace (на мак) удалить return дорожку на аранжировке
+
+## Symptom
+
+A return (send/aux) track shown in the arrangement's footer rows can't be deleted: its context
+menu has only Rename + Colour, and Delete / Backspace with the return selected does nothing.
+Expected: the same "Delete track" path regular tracks have (menu item + key, one undo step).
+
+## Reproduction
+
+1. New project (template creates Reverb + Delay returns).
+2. Arrangement → right-click the "Reverb" row in the footer → no "Delete track" item.
+3. Left-click the return row (it gets selected) → press Delete / Backspace → nothing happens.
+
+## Suspected Code Paths
+
+- `src/managed/Nota.App/ArrangementView.cs:2513` `ShowFooterMenu` — return/master menu builds
+ only Rename + Colour; no Delete item (comment says returns "have no clips to copy/duplicate",
+ delete was simply left out).
+- `src/managed/Nota.App/ArrangementView.Tracks.cs:25` `SelectedTrackIds()` — enumerates `_tracks`
+ only; returns live in `_returns`, so `DeleteSelectedTracks()` gets an empty list → returns false.
+- `src/managed/Nota.App/ArrangementView.Tracks.cs:30` `IsInTrackHeaders` — requires the event to
+ be inside `_scroller`; the footer (`_footer`, `ArrangementView.cs:379`) is docked outside it,
+ so clicking a return row never sets `_trackHeadersFocused` (`MainWindow.axaml.cs:425`), and the
+ key path in `MainWindow.Input.cs:168/360` / `MainWindow.Menu.cs:181` is never reached.
+- **Engine** `src/native/nota.engine/src/Engine_Tracks.cpp:2700 removeTrack`, `:2919 removeTracks`
+ — drop the track but do not touch return-bus numbering. Return buses are addressed by
+ `Track::returnIndex_` (assigned as `returnTrackCount()` in `addReturnTrack`, `:875`) and every
+ track's `send_[bus]` is indexed by that slot.
+- `src/native/nota.engine/src/Engine_Render.cpp:1093–1098, 1376` — renderer clears
+ `numReturns = count(returns)` buses and skips a return whose `returnIndex >= numReturns`.
+
+## Root Cause Hypothesis
+
+Two layers (confidence: high).
+
+1. **UI**: delete was never wired for footer rows — no menu item, selection helpers ignore
+ `_returns`, and the footer is outside the area that routes track keys.
+2. **Engine (latent, exposed once UI allows it — and already reachable via MCP `remove_track`)**:
+ removing a return leaves a gap in `returnIndex`. With returns {0: Reverb, 1: Delay}, deleting
+ Reverb leaves Delay at index 1 while `numReturns` becomes 1 → the render pass skips Delay
+ (`bus >= numReturns`): **the remaining return goes silent** and its meter reads 0. A later
+ `addReturnTrack` assigns index `count()==1` → collides with Delay. Sends on other tracks to the
+ deleted bus keep their level and now (after collision) feed the wrong return. Save/load re-adds
+ returns sequentially (`ProjectService.cs:461`) while sends are saved by bus index (`:101/:593`),
+ so a gap also misroutes sends after reload.
+
+## Proposed Remediation
+
+**Preferred**:
+
+*Engine* — in `removeTrack`/`removeTracks`, when the dropped set contains returns, compact the
+remaining returns: renumber their `returnIndex` to 0..n-1 in order, and for every surviving
+non-return track remap `send_[old] → send_[new]` (dropping the deleted buses' levels, zeroing
+the tail). Because `Track` objects are shared with undo snapshots, renumbered/re-sent tracks must
+be cloned (`cloneTrack`) into the new `Graph`, not mutated in place, so undo restores the
+original numbering and send levels exactly. Factor this into one helper used by both functions.
+The master can never be removed (already not in `authoring_->tracks`; keep a guard).
+
+*UI* —
+- `ShowFooterMenu`: add a separator + "Delete track" (`GlyphKind.Trash`, `MenuKit.DeleteKey`) for
+ returns only (not the master), calling `DeleteTracks(new[]{trackId})`.
+- `SelectedTrackIds()`: also include a selected return (`_returns` where `IsTrackMultiSelected`).
+- `IsInTrackHeaders`: also return true when the event lands in the footer header panel
+ (`_footerHeaders`), so Delete/Backspace (and Cmd+Backspace via Edit ▸ Delete) route to
+ `DeleteSelectedTracks()`. Copy/Cut/Duplicate/Paste already skip returns in the engine
+ (`insertTrackClones`), so including returns in the selection is safe for those, but Cut should
+ not delete a return it can't paste back — filter returns out in `CutTracks`/`CopySelectedTracks`.
+
+**Alternatives**:
+- UI-only fix (no engine compaction): smaller, but deleting the first return silences the others
+ and corrupts sends — not acceptable.
+- Make the renderer clear/iterate all `kMaxReturns` buses and keep gaps: fixes the silence, but
+ `addReturnTrack` collision and save/load misrouting remain; the "Return N" naming would show gaps.
+
+**Files likely to change**:
+- `src/native/nota.engine/src/Engine_Tracks.cpp` (+ `Engine.h` for the helper)
+- `src/managed/Nota.App/ArrangementView.cs` (`ShowFooterMenu`)
+- `src/managed/Nota.App/ArrangementView.Tracks.cs` (`SelectedTrackIds`, `IsInTrackHeaders`, `CutTracks`)
+- engine tests (C++), smoke test if it covers returns
+- `CHANGELOG.md` [Unreleased] → Fixed
+
+**Tests to add or update**:
+- Engine: two returns, track A sends 0.5 → R0 and 0.7 → R1; remove R0 → remaining return has
+ index 0, A's send[0]==0.7, send[1]==0; rendering a tone through A's send yields signal on the
+ remaining return. Undo → both returns back with original indices and sends.
+- Engine: remove R0, then `addReturnTrack` → new return gets index 1, no collision.
+- Save → load round-trip after deleting a return keeps sends on the right return.
+
+## Risks & Considerations
+
+- Undo snapshot sharing: in-place mutation of `send_`/`returnIndex_` would corrupt history — clone.
+- RT safety: all work happens on the message thread when building the new `Graph`; the render
+ path is unchanged.
+- Device-chain / mixer / session views cache "Return N" labels and send-knob counts — they must
+ refresh after the delete (`AfterTrackEdit()` + existing track-list refresh should cover it; verify).
+- Sidechain / route slots keyed by track id (`recomputeRouting`) are unaffected by renumbering.
+- Shortcuts pane: no new binding (Delete already listed) — `nota-shortcuts` not needed; `nota-docs`
+ may mention deleting returns.
+
+## Open Questions
+
+- Should deleting a return that other tracks still send to ask for confirmation? (Proposed: no —
+ it's one undo step, like regular tracks.)
+- Session view / mixer: should returns be deletable there too? Out of scope for this bug unless
+ the same gap exists — [NEEDS CLARIFICATION].
diff --git a/.specify/bugs/return-track-delete/fix.md b/.specify/bugs/return-track-delete/fix.md
new file mode 100644
index 00000000..d5a57281
--- /dev/null
+++ b/.specify/bugs/return-track-delete/fix.md
@@ -0,0 +1,74 @@
+# Bug Fix: Return track can't be deleted in the arrangement
+
+- **Slug**: return-track-delete
+- **Fixed**: 2026-10-13
+- **Assessment**: ./assessment.md
+- **Status**: applied
+
+## Summary
+
+The engine now compacts return buses when a return is removed (survivors renumbered 0..n-1,
+every track's sends remapped, changed tracks cloned so undo is exact), and the arrangement
+lets you delete a Return from its footer row — "Delete track" in the context menu, and
+Delete / Backspace once the row is selected.
+
+## Changes
+
+| File | Change | Notes |
+|------|--------|-------|
+| `src/native/nota.engine/src/Engine.h` | modified | declares `compactReturns(Graph&)` |
+| `src/native/nota.engine/src/Engine_Tracks.cpp` | modified | `compactReturns`; called from `removeTrack` / `removeTracks` only when a return is dropped |
+| `src/managed/Nota.App/ArrangementView.cs` | modified | `ShowFooterMenu`: separator + "Delete track" for returns (not the master) |
+| `src/managed/Nota.App/ArrangementView.Tracks.cs` | modified | `IsInTrackHeaders` counts the footer headers; `DeleteSelectedTracks` takes the selected return |
+| `tests/Nota.SmokeTest/ReturnDeleteTests.cs` | added test | engine-level regression (compaction, sound, undo, new return, save/load) |
+| `tests/Nota.SmokeTest/Program.cs` | modified | runs the new tests in the full smoke run + `--returns` |
+| `CHANGELOG.md` | modified | [Unreleased] → Fixed |
+
+## Diff Highlights
+
+```cpp
+// removeTracks: …
+if (anyReturn) compactReturns(*g);
+publish(std::move(g));
+```
+
+```csharp
+public bool DeleteSelectedTracks()
+{
+ var ids = SelectedTrackIds();
+ if (ids.Count == 0 && _returns.Any(r => r.Id == SelTrackId)) ids.Add(SelTrackId);
+ return DeleteTracks(ids);
+}
+```
+
+## Tests Added or Updated
+
+- `ReturnDeleteTests.Run` — two returns + sends 0.5/0.7: deleting return 0 moves the survivor to
+ bus 0, the 0.7 send follows it, the survivor still has signal; undo restores indices + sends;
+ `RemoveTrack` compacts too; a new return then takes bus 1 unfed; save/load keeps each send on
+ its return.
+
+## Local Verification
+
+- `cmake --build src/native/nota.engine/build` → OK
+- `dotnet build Nota.sln -c Release` → 0 errors
+- `dotnet run --project tests/Nota.SmokeTest -c Release` → SMOKE TEST PASSED (10/10 new checks pass)
+- Headless UI harness (`/tmp/returnharness`, real MainWindow + default template, synthetic
+ pointer/key events): Backspace and Delete on a selected Return delete it; footer row disappears,
+ status "Deleted track(s)"; undo restores it; Reverb context menu shows Rename…, Color, Delete
+ track and the item deletes it; Master menu has no Delete. All checks PASS.
+
+## Deviations from Assessment
+
+- `SelectedTrackIds()` was left rows-only and Cut/Copy were not touched: a Return is only ever
+ selected alone (the footer click replaces the selection), so including it only in
+ `DeleteSelectedTracks` is enough and keeps Copy/Cut/Duplicate from ever seeing a return.
+- `compactReturns` runs only when a return is among the deleted tracks, so deleting a regular
+ track never rewrites anyone's sends.
+
+## Follow-ups
+
+- Session view / mixer: returns still can't be deleted there (open question in the assessment).
+- `dotnet run … --no-build -- --template|--returns` falls through to the full run (pre-existing,
+ affects all the solo flags in that invocation form).
+- nota-docs: the tracks page could mention deleting Returns.
diff --git a/.specify/bugs/return-track-delete/test.md b/.specify/bugs/return-track-delete/test.md
new file mode 100644
index 00000000..12105637
--- /dev/null
+++ b/.specify/bugs/return-track-delete/test.md
@@ -0,0 +1,59 @@
+# Bug Verification: Return track can't be deleted in the arrangement
+
+- **Slug**: return-track-delete
+- **Tested**: 2026-10-13
+- **Assessment**: ./assessment.md
+- **Fix**: ./fix.md
+- **Result**: verified
+
+## Summary
+
+The reproduction from the assessment no longer reproduces: in the real MainWindow with the
+default template, a Return is deleted by Backspace, by Delete and by the context menu's
+"Delete track", and undo brings it back. The engine keeps the surviving Return sounding with
+its sends intact. Full `scripts/build.sh` (universal engine + solution + smoke test) passes with
+no failures.
+
+## Checks Performed
+
+| Check | Command / Action | Result | Notes |
+|-------|------------------|--------|-------|
+| Reproduction (post-fix) | headless harness `/tmp/returnharness` (`NOTA_DATA_DIR=/tmp/returnharness/data dotnet run`): real MainWindow + template, synthetic pointer clicks on the footer rows, KeyDown Back/Delete on the window, right-click → flyout item Click | pass | 10/10 checks; Master menu has no Delete |
+| New tests | `scripts/build.sh` → smoke section `-- return delete --` | pass | 10/10 (`ReturnDeleteTests`) |
+| Regression suite | `scripts/build.sh` (full smoke test) | pass | exit 0, `SMOKE TEST PASSED`, 0 `[FAIL]` lines |
+| Build / type-check | `scripts/build.sh` (cmake universal + `dotnet build Nota.sln -c Release`) | pass | 0 errors; dylib arm64 + x86_64 |
+
+## Output Excerpts
+
+```
+-- return delete --
+ [PASS] returns: the survivor moves to bus 0 (index 0)
+ [PASS] returns: the send follows its bus (0,70, 0,00)
+ [PASS] returns: the surviving return still sounds (peak=0,030)
+ [PASS] returns: undo restores both buses and both sends
+ [PASS] returns: save/load keeps each send on its return
+SMOKE TEST PASSED
+```
+
+```
+[PASS] Backspace on the selected Reverb row deletes it
+[PASS] Delete on the selected Delay row deletes only Delay
+menu items found: Rename…, Color, Delete track
+[PASS] the menu item deletes Reverb
+master menu: Rename…, Color
+[PASS] the master row's menu has no Delete
+```
+
+## Residual Risks
+
+- UI input was synthetic (headless Avalonia), not a physical mouse/keyboard on the running
+ macOS app: the native Edit-menu accelerator path (`OnMenuDelete`, same `_trackHeadersFocused`
+ gate) was not exercised directly. A 10-second manual check in the app would close this.
+- The pre-fix failure of the new engine test was not demonstrated (it would require reverting
+ source); the pre-fix behaviour is established by code reading in the assessment.
+- Session view / mixer still offer no Return deletion (out of scope, open question).
+
+## Recommendation
+
+Close the bug — verified end-to-end through the real window in headless mode and by the
+engine regression tests; optionally confirm once by hand in the running app before release.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 041f7c6a..2fb937d0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,11 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
+### Fixed
+- **Return tracks can be deleted in the arrangement:** the Return row's context menu has
+ Delete track, and Delete / Backspace removes a selected Return, in one undo step. The
+ Returns that stay keep sounding, and every track's sends stay on the same Returns.
+
## [0.52.1] — 2026-10-13
### Added
diff --git a/src/managed/Nota.App/ArrangementView.Tracks.cs b/src/managed/Nota.App/ArrangementView.Tracks.cs
index 39b0f49b..42f0eed0 100644
--- a/src/managed/Nota.App/ArrangementView.Tracks.cs
+++ b/src/managed/Nota.App/ArrangementView.Tracks.cs
@@ -26,10 +26,14 @@ public sealed partial class ArrangementView
=> _tracks.Where(t => IsTrackMultiSelected(t.Id)).Select(t => t.Id).ToList();
/// <summary>True when the pointer event landed in the track-header column (the header
- /// cards or the empty column below them) — MainWindow routes the track keys there.</summary>
+ /// cards, the empty column below them, or the return/master headers in the footer) —
+ /// MainWindow routes the track keys there.</summary>
internal bool IsInTrackHeaders(PointerEventArgs e)
{
- if (e.Source is not Visual v || !v.GetSelfAndVisualAncestors().Contains(_scroller)) return false;
+ if (e.Source is not Visual v) return false;
+ var chain = v.GetSelfAndVisualAncestors();
+ if (chain.Contains(_footerHeaders)) return true;
+ if (!chain.Contains(_scroller)) return false;
double x = e.GetPosition(_headers).X;
return x >= 0 && x < HeaderW;
}
@@ -90,7 +94,14 @@ public sealed partial class ArrangementView
public bool DuplicateSelectedTracks() => DuplicateTracks(SelectedTrackIds());
- public bool DeleteSelectedTracks() => DeleteTracks(SelectedTrackIds());
+ /// <summary>Delete over the headers: the selected rows, or the selected return (a return
+ /// is only ever selected on its own, from the footer).</summary>
+ public bool DeleteSelectedTracks()
+ {
+ var ids = SelectedTrackIds();
+ if (ids.Count == 0 && _returns.Any(r => r.Id == SelTrackId)) ids.Add(SelTrackId);
+ return DeleteTracks(ids);
+ }
private bool CutTracks(IReadOnlyList<int> ids)
{
diff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.cs
index 5dae9e6a..450beb33 100644
--- a/src/managed/Nota.App/ArrangementView.cs
+++ b/src/managed/Nota.App/ArrangementView.cs
@@ -2509,7 +2509,8 @@ public sealed partial class ArrangementView : UserControl
}
// Context menu for a send/return or the master row: rename + colour (the same edits
- // regular tracks get; returns/master have no clips to copy/duplicate).
+ // regular tracks get; returns/master have no clips to copy/duplicate), and Delete for a
+ // return (the master stays).
private void ShowFooterMenu(Control anchor, int trackId)
{
if (_engine is null) return;
@@ -2518,6 +2519,11 @@ public sealed partial class ArrangementView : UserControl
rename.Click += (_, _) => PromptRenameTrack(anchor, trackId);
flyout.Items.Add(rename);
flyout.Items.Add(BuildColorSubmenu(new[] { trackId }));
+ if (_returns.Any(r => r.Id == trackId))
+ {
+ flyout.Items.Add(new Separator());
+ flyout.Items.Add(MenuKit.Item("Delete track", GlyphKind.Trash, () => DeleteTracks(new[] { trackId }), MenuKit.DeleteKey));
+ }
flyout.ShowAt(anchor, showAtPointer: true);
}
diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.h
index de44c840..cc0d9263 100644
--- a/src/native/nota.engine/src/Engine.h
+++ b/src/native/nota.engine/src/Engine.h
@@ -1217,6 +1217,7 @@ private:
std::shared_ptr<Track> deepCloneTrack(const Track& src, int32_t newId);
// The tracks in ids plus every descendant of a group among them, in engine order.
std::vector<std::shared_ptr<Track>> expandTrackSet(const int32_t* ids, int32_t n) const;
+ void compactReturns(Graph& g) const; // renumber return buses 0..n-1 + remap sends (after a delete)
// Publishes fresh deep clones of src (returns skipped) after afterId, or before the
// returns when afterId isn't a regular track. Group links inside the set follow the
// copies; a member whose group is outside the set keeps it (keepParent) or joins rootParent.
diff --git a/src/native/nota.engine/src/Engine_Tracks.cpp b/src/native/nota.engine/src/Engine_Tracks.cpp
index 9420aa06..0e70c3fd 100644
--- a/src/native/nota.engine/src/Engine_Tracks.cpp
+++ b/src/native/nota.engine/src/Engine_Tracks.cpp
@@ -2715,6 +2715,7 @@ bool Engine::removeTrack(int32_t trackId) {
g->tracks.reserve(authoring_->tracks.size());
for (auto& t : authoring_->tracks)
if (t->id() != trackId) g->tracks.push_back(t);
+ if (rt->type() == TrackType::Return) compactReturns(*g);
publish(std::move(g));
recomputePdc();
return true;
@@ -2866,6 +2867,40 @@ std::vector<std::shared_ptr<Track>> Engine::expandTrackSet(const int32_t* ids, i
return out;
}
+// Deleting a return leaves a hole in the bus slots, but the renderer only runs buses
+// 0..count-1 and addReturnTrack hands out slot `count` — so the survivors move down to
+// 0..n-1 (in track order) and every send follows its bus; sends to a deleted bus go.
+// Changed tracks are cloned, never edited in place: the old graph is the undo snapshot.
+void Engine::compactReturns(Graph& g) const {
+ int32_t remap[kMaxReturns];
+ std::fill(std::begin(remap), std::end(remap), -1);
+ int32_t n = 0;
+ for (auto& t : g.tracks) {
+ if (t->type() != TrackType::Return) continue;
+ const int32_t old = t->returnIndex();
+ if (old >= 0 && old < kMaxReturns) remap[old] = n++;
+ }
+ for (auto& t : g.tracks) {
+ if (t->type() == TrackType::Return) {
+ const int32_t old = t->returnIndex();
+ const int32_t idx = (old >= 0 && old < kMaxReturns) ? remap[old] : -1;
+ if (idx < 0 || idx == old) continue;
+ auto nt = cloneTrack(*t);
+ nt->setReturnIndex(idx);
+ t = std::move(nt);
+ continue;
+ }
+ float sends[kMaxReturns] = {};
+ for (int32_t b = 0; b < kMaxReturns; ++b) if (remap[b] >= 0) sends[remap[b]] = t->send(b);
+ bool changed = false;
+ for (int32_t b = 0; b < kMaxReturns; ++b) if (sends[b] != t->send(b)) changed = true;
+ if (!changed) continue;
+ auto nt = cloneTrack(*t);
+ for (int32_t b = 0; b < kMaxReturns; ++b) nt->setSend(b, sends[b]);
+ t = std::move(nt);
+ }
+}
+
std::vector<int32_t> Engine::insertTrackClones(const std::vector<std::shared_ptr<Track>>& src,
int32_t afterId, int32_t rootParent, bool keepParent) {
std::map<int32_t, int32_t> remap; // source id -> copy id
@@ -2920,7 +2955,9 @@ bool Engine::removeTracks(const int32_t* ids, int32_t n) {
auto set = expandTrackSet(ids, n);
if (set.empty()) return false;
std::set<int32_t> drop;
+ bool anyReturn = false;
for (auto& t : set) {
+ anyReturn |= t->type() == TrackType::Return;
// Plugin windows shouldn't outlive the track (it survives in undo history, so only hide).
if (t->instrument) t->instrument->closeEditor();
for (auto& d : t->devices) if (d) d->closeEditor();
@@ -2934,6 +2971,7 @@ bool Engine::removeTracks(const int32_t* ids, int32_t n) {
g->tracks.reserve(authoring_->tracks.size());
for (auto& t : authoring_->tracks)
if (!drop.count(t->id())) g->tracks.push_back(t);
+ if (anyReturn) compactReturns(*g);
publish(std::move(g));
recomputePdc();
return true;
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index b436e99a..515a6e8c 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -239,6 +239,14 @@ if (args.Length >= 1 && args[0] == "--template")
Console.WriteLine(failures == 0 ? "TEMPLATE PASSED" : $"TEMPLATE FAILED ({failures})");
return failures == 0 ? 0 : 1;
}
+// Deleting a return track alone: `--returns`. Also part of the full run.
+if (args.Length >= 1 && args[0] == "--returns")
+{
+ Console.WriteLine("-- return delete --");
+ foreach (var (ok, label) in ReturnDeleteTests.Run()) Check(ok, label);
+ Console.WriteLine(failures == 0 ? "RETURNS PASSED" : $"RETURNS FAILED ({failures})");
+ return failures == 0 ? 0 : 1;
+}
// What Nota Mosaic makes of a real library: `--mosaic-dump <file.sfz | folder>`.
if (args.Length >= 2 && args[0] == "--mosaic-dump")
{
@@ -14565,6 +14573,9 @@ foreach (var (ok, label) in SnapGridTests.Run()) Check(ok, label);
Console.WriteLine("-- default project template --");
foreach (var (ok, label) in ProjectTemplateTests.Run()) Check(ok, label);
+Console.WriteLine("-- return delete --");
+foreach (var (ok, label) in ReturnDeleteTests.Run()) Check(ok, label);
+
Console.WriteLine("-- filter knob glide --");
foreach (var (ok, label) in FilterGlideTests.Run()) Check(ok, label);
diff --git a/tests/Nota.SmokeTest/ReturnDeleteTests.cs b/tests/Nota.SmokeTest/ReturnDeleteTests.cs
new file mode 100644
index 00000000..01b774aa
--- /dev/null
+++ b/tests/Nota.SmokeTest/ReturnDeleteTests.cs
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Deleting a return track (.specify/bugs/return-track-delete): the surviving returns move
+// down to bus slots 0..n-1, every send follows its bus, the survivor keeps sounding, undo
+// restores the old numbering and sends, a new return takes a free slot, and the result
+// survives save/load. Also runnable alone: `dotnet run --project tests/Nota.SmokeTest -- --returns`.
+
+using Nota.Application;
+using Nota.Infrastructure;
+
+namespace Nota.SmokeTest;
+
+internal static class ReturnDeleteTests
+{
+ private const int Utility = 4; // unity gain, no tail: a bus is either fed or silent
+
+ public static IEnumerable<(bool ok, string label)> Run()
+ {
+ using var eng = new NotaEngine();
+ int src = eng.AddInstrumentTrack();
+ int clip = eng.AddMidiClip(src, 0.0, 4.0);
+ eng.SetClipNotes(src, clip, new[] { new NotaNote(60, 0.0, 4.0, 0.9f) });
+ int r0 = eng.AddReturnTrack(), r1 = eng.AddReturnTrack();
+ eng.AddBuiltinDevice(r0, Utility);
+ eng.AddBuiltinDevice(r1, Utility);
+ eng.SetTrackSend(src, 0, 0.5f);
+ eng.SetTrackSend(src, 1, 0.7f);
+ yield return (eng.TrackReturnIndex(r0) == 0 && eng.TrackReturnIndex(r1) == 1, "returns: two returns on buses 0 and 1");
+
+ yield return (eng.RemoveTracks(new[] { r0 }), "returns: delete the first return");
+ yield return (eng.ReturnTrackCount == 1 && eng.TrackReturnIndex(r1) == 0,
+ $"returns: the survivor moves to bus 0 (index {eng.TrackReturnIndex(r1)})");
+ yield return (Near(eng.GetTrackSend(src, 0), 0.7f) && eng.GetTrackSend(src, 1) == 0f,
+ $"returns: the send follows its bus ({eng.GetTrackSend(src, 0):F2}, {eng.GetTrackSend(src, 1):F2})");
+ float peak = Peak(eng, r1);
+ yield return (peak > 0.001f, $"returns: the surviving return still sounds (peak={peak:F3})");
+
+ yield return (eng.Undo(), "returns: undo the delete");
+ yield return (eng.TrackReturnIndex(r0) == 0 && eng.TrackReturnIndex(r1) == 1
+ && Near(eng.GetTrackSend(src, 0), 0.5f) && Near(eng.GetTrackSend(src, 1), 0.7f),
+ "returns: undo restores both buses and both sends");
+
+ // The single-track path does the same; a new return then takes the free slot.
+ yield return (eng.RemoveTrack(r0) && eng.TrackReturnIndex(r1) == 0, "returns: RemoveTrack compacts too");
+ int r2 = eng.AddReturnTrack();
+ yield return (eng.TrackReturnIndex(r2) == 1 && eng.GetTrackSend(src, 1) == 0f,
+ $"returns: a new return takes bus 1, unfed (index {eng.TrackReturnIndex(r2)})");
+
+ // Save/load: the reloaded returns line up with the saved sends.
+ eng.SetTrackSend(src, 1, 0.3f);
+ eng.SetTrackName(r1, "Kept");
+ string dir = Path.Combine(Path.GetTempPath(), "nota-returns-" + Guid.NewGuid().ToString("N"));
+ try
+ {
+ var doc = ProjectService.Capture(eng, new TransportState(120, 1, false, false), new List<string>());
+ ProjectService.Save(doc, dir, eng);
+ using var eng2 = new NotaEngine();
+ ProjectService.Apply(ProjectService.Load(dir), eng2, dir);
+ int kept = -1, inst = -1;
+ for (int i = 0; i < eng2.TrackCount; i++)
+ if (eng2.TryGetTrackInfo(i, out var t))
+ {
+ if (t.IsReturn && eng2.GetTrackName(t.Id) == "Kept") kept = t.Id;
+ else if (t.IsInstrument) inst = t.Id;
+ }
+ yield return (kept > 0 && eng2.TrackReturnIndex(kept) == 0
+ && Near(eng2.GetTrackSend(inst, 0), 0.7f) && Near(eng2.GetTrackSend(inst, 1), 0.3f),
+ "returns: save/load keeps each send on its return");
+ }
+ finally
+ {
+ try { if (Directory.Exists(dir)) Directory.Delete(dir, recursive: true); } catch (IOException) { }
+ }
+ }
+
+ private static bool Near(float a, float b) => Math.Abs(a - b) < 1e-6f;
+
+ private static float Peak(NotaEngine eng, int trackId)
+ {
+ var buf = new float[4096 * 2];
+ eng.Seek(0);
+ eng.Play();
+ eng.RenderOffline(buf, 4096);
+ eng.StopTransport();
+ eng.TryGetTrackMeter(trackId, out var m);
+ return m.Peak;
+ }
+}