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
(feat) Edit several MIDI clips at once (#48) (#222)
Egor Khindikaynen2d26c788689d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 38276a64..3f59cf6a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -32,7 +32,8 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.clip of its track moves into that clip. A strip under the ruler shows the open clips:click one to make it the active clip (its name, start, length and envelopes in theeditor), or lock it as a dimmed reference that cannot be changed by accident. New notes go- into the active clip.+ into the active clip. While the Clip tab is open it follows the selection in the+ arrangement.- **Nota Vocoder** (nota-daw/nota#113): a new audio effect with two inputs. The track itsits on is the voice; drop it on a vocal and you hear a robot voice straight away, from aninternal **Saw** (at a chosen **Pitch**). Switch the carrier to **Noise** for a whisper, or@@ -49,6 +50,9 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.small to read on a laptop screen, or 75 % to fit more tracks on a small one.### Fixed+- **⌘D in the piano roll no longer piles copies at the clip's end** when the selection is+ longer than the room left after it: copies continue into the next open clip of the track,+ and those with no clip to land in are left out.- **New project and Open ask before discarding unsaved changes** (nota-daw/nota#215): File →New, File → Open and opening a project from the browser now offer Save / Don't save /Cancel, like quitting does; Cancel keeps the current project. The detail panel also closesdiff --git a/FEATURES.md b/FEATURES.mdindex db1586d1..32ba14f0 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -269,8 +269,9 @@ track count and closes with Escape.whole edit; a note moved past the seam into the next open clip of its track moves intothat clip. A **clip strip** under the ruler shows the open clips: click one to make itthe active clip (header, inspector and envelopes follow it; new notes go into it), or- click its lock to keep it as a dimmed, read-only reference. The set stays as opened- while the arrangement selection changes.+ click its lock to keep it as a dimmed, read-only reference. While the Clip tab is+ open it follows the arrangement selection. ⌘D copies that run past a clip's end continue+ into the next open clip; past the last one they are left out.- **Clip tools (generate and transform)**: a **Tools** rail beside the piano roll withfifteen tools that write or rewrite notes. Six **generators** — *Rhythm* (a pattern thatleans on the strong beats), *Seed* (learns the clip's own intervals and rhythm, thendiff --git a/specs/029-multi-clip-editing/contracts/ui.md b/specs/029-multi-clip-editing/contracts/ui.mdindex f642a5c8..7352b73d 100644--- a/specs/029-multi-clip-editing/contracts/ui.md+++ b/specs/029-multi-clip-editing/contracts/ui.md@@ -7,7 +7,7 @@| Double-click a MIDI clip that is in a selection of ≥2 MIDI clips | All selected MIDI clips open; clicked clip active || Double-click a clip outside the selection / single selection | Single-clip editor (unchanged) || Command palette / arrangement clip context menu: **Edit selected clips** | All selected MIDI clips open; first in time active. Disabled with <2 MIDI clips selected |-| Change arrangement selection while a multi-clip editor is open | Editor unchanged |+| Change the arrangement selection while the Clip editor is on screen | Editor follows: ≥2 MIDI clips together, 1 clip alone, no MIDI clip → unchanged |No new keyboard shortcut is bound by default (the command is available to the shortcutbuilder). If one is added, run `nota-shortcuts`.diff --git a/specs/029-multi-clip-editing/quickstart.md b/specs/029-multi-clip-editing/quickstart.mdindex b309a038..a60e6ad3 100644--- a/specs/029-multi-clip-editing/quickstart.md+++ b/specs/029-multi-clip-editing/quickstart.md@@ -29,7 +29,8 @@ second track with a chord clip C (bars 1–8). Use `NOTA_DATA_DIR` to isolate da1. Select A, B, C; double-click B → three clips open, strip shows three bars, B active,ruler reads arrangement bars 1–8. (Story 1)-2. Click one clip only in the arrangement → editor unchanged. (FR-001a)+2. Click one clip only in the arrangement → editor shows that clip alone; ⇧-click a second+ → both at once. (FR-001a)3. Rubber-band notes over A and B, press ↑ → both clips change; ⌘Z once → both restored.(Story 2, FR-011)4. Drag a note of A so it starts in bar 5 → it lands in B; ⌘Z → back in A. (FR-006)diff --git a/specs/029-multi-clip-editing/research.md b/specs/029-multi-clip-editing/research.mdindex afc7074d..45504a8b 100644--- a/specs/029-multi-clip-editing/research.md+++ b/specs/029-multi-clip-editing/research.md@@ -81,9 +81,12 @@ also keep each clip's own length as the tool's boundary.**Finding**: Today `OnTrackSelected` resets the editor on a track switch and`OnDetailClip` re-points the Clip tab at the newly selected clip.-**Decision**: When the open set has more than one clip, both skip the reset/re-point; the-set only changes through `OpenClipEditor` (double-click / "Edit selected clips"). With one-clip, today's follow-the-selection behaviour stays (FR-002).+**Decision** (revised after review, bug06): the editor follows the selection. The+arrangement raises `ClipSelectionChanged` once per change (posted, deduplicated, from+`UpdateHeaderSelection`, which every selection path calls); while the Clip editor is on+screen the host opens the selected MIDI clips together, or the single clip when the+selection narrows to one. The first click of a double-click still narrows the selection;+`RestoreNarrowed` puts it back on the second click.## R8 — Following arrangement changes (FR-013)diff --git a/specs/029-multi-clip-editing/spec.md b/specs/029-multi-clip-editing/spec.mdindex ffd11a3b..f37055bb 100644--- a/specs/029-multi-clip-editing/spec.md+++ b/specs/029-multi-clip-editing/spec.md@@ -54,11 +54,21 @@ expectations), [`BUILD.md`](../../BUILD.md), [`DESIGN.md`](../../DESIGN.md),- Q: How does a set of clips get into the editor, and does it follow later arrangementselection changes? → A: Fixed at opening (double-click on a selected clip, or "Editselected clips"); later selection changes leave the editor as it is until it is opened- again.+ again. *(Reversed after review on 2026-10-20 — see below.)*- Q: Where does the user see the open clips and switch the active clip or referencemode? → A: A clip strip above the note grid (under the ruler): one bar per clip in itstrack colour over its time span; click makes it active, a lock icon toggles reference.+### Review 2026-10-20 (bug06.nota)++- Q: Should the editor follow the arrangement selection after all? → A: Yes. While the+ Clip editor is on screen, selecting two or more MIDI clips shows them together at once+ (the clicked clip active when it is one of them); narrowing to one clip shows it alone.+ This replaces the "fixed at opening" answer above.+- Q: Where do ⌘D copies go when the selection's span runs past its clip's end? → A: Where+ the shift puts them: copies that start in the next open clip of the track land in it (the+ move rule, FR-006); copies past every open clip are dropped, never piled up at the edge.+## User Scenarios & Testing *(mandatory)*### User Story 1 - Open several clips together and see them on one timeline (Priority: P1)@@ -89,9 +99,10 @@ arrangement bars, and the double-clicked clip is the active one.4. **Given** one clip is selected, or the user double-clicks a clip that is not part ofthe selection, **When** the editor opens, **Then** it behaves exactly as today(single clip) — no change for users who never select several clips.-5. **Given** a multi-clip editor is open, **When** the user selects other clips in the- arrangement with a single click, **Then** the editor keeps its clips; it changes only- when the user opens clips again.+5. **Given** the Clip editor is on screen, **When** the user selects two or more MIDI+ clips in the arrangement (⇧-click, ⌘-click, rubber band, select all), **Then** the editor+ shows them together at once; **When** the selection narrows to one clip, **Then** it+ shows that clip alone.6. **Given** a multi-clip editor is open, **When** the editor header is read, **Then** itnames the active clip and shows how many clips are open (e.g. "Bass 2 · +2 clips").@@ -227,9 +238,14 @@ velocity lane for notes of both clips.clips MUST open all selected MIDI clips together in the Clip editor, with thedouble-clicked clip active. A menu/command "Edit selected clips" MUST do the same, withthe first selected clip in time active.-- **FR-001a**: The open clip set MUST be fixed when the editor opens. Changing the- arrangement selection afterwards MUST NOT add, remove or re-activate clips in the- editor; only opening the editor again (FR-001) replaces the set.+- **FR-001a**: While the Clip editor is on screen, it MUST follow the arrangement+ selection: two or more selected MIDI clips open together (the clicked clip active when+ it is one of them, else the first in time); a selection of one MIDI clip shows that clip+ alone; a selection without MIDI clips leaves the editor as it is.+- **FR-005a**: Duplicate (⌘D) MUST shift the copies by the selection's span and place each+ where the shift lands it — in its own clip or, past the seam, in the next open clip of+ its track (as FR-006); a copy beyond every open clip MUST be dropped, never clamped to+ the clip's edge. This also applies to the single-clip editor.- **FR-002**: Opening a single clip, or a clip outside the selection, MUST behave exactlyas the current single-clip editor.- **FR-003**: In a multi-clip editor the roll's horizontal axis MUST be arrangement time:diff --git a/specs/029-multi-clip-editing/tasks.md b/specs/029-multi-clip-editing/tasks.mdindex 45fa8819..0f99c21b 100644--- a/specs/029-multi-clip-editing/tasks.md+++ b/specs/029-multi-clip-editing/tasks.md@@ -171,6 +171,13 @@ own result, Apply is one undo step.---+## Phase 9: Review fixes (bug06.nota, 2026-10-20)++- [X] T048 [US1] Follow the arrangement selection while the Clip editor is on screen (FR-001a revised): `ClipSelectionChanged` in `src/managed/Nota.App/ArrangementView.cs` (posted, deduplicated, from `UpdateHeaderSelection`), `FollowClipSelection` in `src/managed/Nota.App/MainWindow.Detail.cs`; drop the fixed-set guards in `OnTrackSelected` / `OnDetailClip`+- [X] T049 [US2] ⌘D places each copy by the move rule (FR-005a): `ClipSet.ShiftTarget` in `src/managed/Nota.Application/Editing/ClipSet.cs`, used by `DuplicateSelection` in `src/managed/Nota.App/PianoRollView.cs`; copies past the reach are dropped instead of clamped; checks in `tests/Nota.SmokeTest/MultiClipTests.cs`++---+## Dependencies & Execution Order### Phase Dependenciesdiff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.csindex 28724d5b..5c638190 100644--- a/src/managed/Nota.App/ArrangementView.cs+++ b/src/managed/Nota.App/ArrangementView.cs@@ -230,6 +230,26 @@ public sealed partial class ArrangementView : UserControlpublic event Action<int, int>? MidiClipActivated;/// <summary>"Edit selected clips together" from a clip's context menu (specs/029).</summary>public event Action? EditSelectedClipsRequested;+ /// <summary>The set of selected clips changed (click, ⌘-click, ⇧-click, marquee, select+ /// all, delete). Raised once per change, after the arrangement has settled its own state;+ /// the Clip editor follows it (specs/029).</summary>+ public event Action? ClipSelectionChanged;+ private (int, int)[] _notifiedSel = Array.Empty<(int, int)>();+ private bool _selNotifyQueued;++ private void QueueSelectionNotify()+ {+ if (_selNotifyQueued) return;+ _selNotifyQueued = true;+ Avalonia.Threading.Dispatcher.UIThread.Post(() =>+ {+ _selNotifyQueued = false;+ var now = _sel.OrderBy(s => s.track).ThenBy(s => s.clip).ToArray();+ if (now.SequenceEqual(_notifiedSel)) return;+ _notifiedSel = now;+ ClipSelectionChanged?.Invoke();+ });+ }/// <summary>Raised when an audio clip is double-clicked (trackId, clipIndex).</summary>public event Action<int, int>? AudioClipActivated;/// <summary>Raised when a track becomes selected (clip or header click).</summary>@@ -1875,6 +1895,7 @@ public sealed partial class ArrangementView : UserControl// instead of rebuilding the whole header column (faders, meters, combos) on every click.private void UpdateHeaderSelection(){+ QueueSelectionNotify(); // every clip-selection change repaints the headersforeach (var (id, h) in _headerCards){// Selected row (almanac § States): brass wash, the left stripe turns brass, name in Ink 1.diff --git a/src/managed/Nota.App/MainWindow.Detail.cs b/src/managed/Nota.App/MainWindow.Detail.csindex 9d129737..62f13026 100644--- a/src/managed/Nota.App/MainWindow.Detail.cs+++ b/src/managed/Nota.App/MainWindow.Detail.cs@@ -143,8 +143,7 @@ public partial class MainWindow// Switching to a different track abandons the previously edited clip. Reset the clip// editor to empty so a stale editor from the old track doesn't linger — most visible// in the popped-out Devices/Clip window, whose top pane isn't touched by ShowDevices.- // A multi-clip editor keeps its clips until it is opened again (specs/029 FR-001a).- if (_editorTrackId != trackId && _audioEditorTrackId != trackId && !MultiClipEditorOpen)+ if (_editorTrackId != trackId && _audioEditorTrackId != trackId)ResetClipEditor();// Selecting a clip in the arrangement also selects its track — including the select@@ -379,10 +378,37 @@ public partial class MainWindowreturn true;}- /// <summary>A Clip editor with several clips open — its set stays put while the- /// arrangement selection changes (specs/029 FR-001a).</summary>+ /// <summary>A Clip editor with several arrangement clips open.</summary>private bool MultiClipEditorOpen => _editorRoll is { Clips.IsMulti: true } && _clipEditor is not null && _editorTrackId > 0;+ // The Clip editor follows the arrangement selection while it is on screen (specs/029+ // FR-001a): two or more selected MIDI clips open together — the clicked clip active when+ // it is one of them — and narrowing back to one clip returns to the single-clip editor.+ // Selecting a lone clip on another track is already followed through OnTrackSelected.+ private void FollowClipSelection()+ {+ if (_session?.IsVisible == true || _vm is null) return;+ bool shown = DetailFloating+ ? _clipEditor is not null && ReferenceEquals(_lastClipEditor, _clipEditor)+ : DetailPanel.IsVisible && DetailBody.Content is ClipEditorView;+ if (!shown) return;+ var midi = Timeline.SelectedMidiClips();+ if (midi.Count >= 2)+ {+ var open = _editorRoll?.Clips.Clips.Select(c => (c.TrackId, c.ClipIndex)).OrderBy(x => x).ToList();+ if (open is not null && open.SequenceEqual(midi.OrderBy(x => x))) return; // already showing these+ var primary = (Timeline.SelectedTrackId, Timeline.SelectedClipIndex);+ var active = midi.Contains(primary) ? primary : midi[0];+ BuildClipEditor(midi, active.Item1, active.Item2);+ ShowClipPanel();+ }+ else if (midi.Count == 1 && MultiClipEditorOpen)+ {+ BuildClipEditor(midi[0].TrackId, midi[0].ClipIndex);+ ShowClipPanel();+ }+ }+// --- audio clip editor (M-audio-editor) --------------------------------private void OpenAudioClipEditor(int trackId, int clipIndex){@@ -679,7 +705,7 @@ public partial class MainWindow}if (isMidi){- if (_clipEditor is null || (!MultiClipEditorOpen && (_editorTrackId != tid || _editorClipIndex != ci)))+ if (_clipEditor is null || _editorTrackId != tid || _editorClipIndex != ci)BuildClipEditor(tid, ci);ShowClipPanel();}diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.csindex ab1ad618..6c62b21f 100644--- a/src/managed/Nota.App/MainWindow.axaml.cs+++ b/src/managed/Nota.App/MainWindow.axaml.cs@@ -202,6 +202,7 @@ public partial class MainWindow : WindowTimeline.RefreshStarting = PruneFreezeLinks; // drop links to deleted / undone tracksTimeline.MidiClipActivated += OpenClipEditor;Timeline.EditSelectedClipsRequested += () => EditSelectedClips();+ Timeline.ClipSelectionChanged += FollowClipSelection;Timeline.AudioClipActivated += OpenAudioClipEditor;Timeline.ItemDropped += OnArrangementDrop; // browser drag & drop (M7-5)Timeline.SampleToInstrument += (item, t) => { DropBrowserItem(item, t); Timeline.Select(t, -1); }; // audio clip → Grain / Drum Rack / Sampler… (that track becomes the selection)diff --git a/src/managed/Nota.App/PianoRollView.cs b/src/managed/Nota.App/PianoRollView.csindex 5414ec0a..4178d0fc 100644--- a/src/managed/Nota.App/PianoRollView.cs+++ b/src/managed/Nota.App/PianoRollView.cs@@ -767,8 +767,8 @@ public sealed partial class PianoRollView : UserControlpublic bool GridFocused => _gridControl.IsFocused;/// <summary>Duplicates the selected notes, shifted right by the selection span, and- /// selects the copies. Returns false if nothing was selected. Undoable (one Commit).- /// Each copy stays in its original's clip, never past that clip's end.</summary>+ /// selects the copies. Returns false if nothing was selected (or nothing fits). Undoable+ /// (one Commit). Copies follow the same reach as moved notes (specs/029).</summary>public bool DuplicateSelection(){SettlePlacement();@@ -781,12 +781,19 @@ public sealed partial class PianoRollView : UserControlvar copyOwners = new List<int>(sel.Count);foreach (int i in sel){+ // Each copy lands where the shift puts it: in its own clip, or — past the seam — in+ // the next open clip of its track (as a moved note would). Past every open clip it is+ // dropped, as a paste past the clip's end is, instead of piling up at the edge.var n = _notes[i];- double cap = Math.Max(_set.EditorStart(_owner[i]), _set.EditorEnd(_owner[i]) - SnapStep);- n.StartBeat = Math.Min(n.StartBeat + shift, cap);+ n.StartBeat += shift;+ int slot = _set.ShiftTarget(_owner[i], n.StartBeat);+ if (slot < 0) continue;+ double end = _set.EditorEnd(slot);+ if (n.StartBeat + n.LengthBeats > end) n.LengthBeats = Math.Max(MinNoteLen, end - n.StartBeat);copies.Add(n);- copyOwners.Add(_owner[i]);+ copyOwners.Add(slot);}+ if (copies.Count == 0) return false;// Like a duplicated clip in the arrangement, the copies overwrite what they land on// straight away, with the same rule a settled placement uses (NoteOverwrite).int baseIdx = _notes.Count;diff --git a/src/managed/Nota.Application/Editing/ClipSet.cs b/src/managed/Nota.Application/Editing/ClipSet.csindex 586dd4b6..587ec09e 100644--- a/src/managed/Nota.Application/Editing/ClipSet.cs+++ b/src/managed/Nota.Application/Editing/ClipSet.cs@@ -167,6 +167,17 @@ public sealed class ClipSetreturn best >= 0 ? best : slot;}+ /// <summary>Where a copy of a note of <paramref name="slot"/> lands when shifted to+ /// <paramref name="editorStart"/> (Duplicate): the clip that holds it within the note's+ /// reach — its own clip or the next open one of its track — or −1 past the reach, where+ /// the copy is dropped rather than piled up at the edge.</summary>+ public int ShiftTarget(int slot, double editorStart)+ {+ var (lo, hi) = Reach(slot);+ if (editorStart < lo - Eps || editorStart >= hi - Eps) return -1;+ return OwnerAfterMove(slot, editorStart);+ }+/// <summary>Where a pasted note goes (specs/029 FR-012): back into the clip it was copied/// from when that clip is open, else into the active clip — at its clip-relative beat/// <paramref name="localStart"/> either way. Returns the slot and the editor-beat start.</summary>diff --git a/tests/Nota.SmokeTest/MultiClipTests.cs b/tests/Nota.SmokeTest/MultiClipTests.csindex 4faf9c2f..d35a4004 100644--- a/tests/Nota.SmokeTest/MultiClipTests.cs+++ b/tests/Nota.SmokeTest/MultiClipTests.cs@@ -108,6 +108,14 @@ internal static class MultiClipTestsyield return (s.OwnerAfterMove(0, 30) == 2 && s.OwnerAfterMove(2, 9) == 0,"multiclip: notes never move to another track's clip");+ // Duplicate (bug06): a copy shifted past A's end lands in B; past B, in a gap or behind+ // a reference clip it is dropped (−1), never piled up at the edge.+ yield return (s.ShiftTarget(0, 15) == 0 && s.ShiftTarget(0, 17) == 2 && s.ShiftTarget(0, 33) == -1,+ "multiclip: a duplicated note lands in the clip its shift reaches, past the reach nowhere");+ var lone = ClipSet.Single(1, 0, 0, 4);+ yield return (lone.ShiftTarget(0, 3.25) == 0 && lone.ShiftTarget(0, 4.125) == -1,+ "multiclip: in one clip a copy past its end is dropped");+var gap = new ClipSet(new[] { new OpenClip(1, 0, 0, 16), new OpenClip(1, 1, 20, 16) }, 1, 0);var g = gap.Reach(0);yield return (Near(g.Start, 0) && Near(g.End, 16), "multiclip: a gap between clips is a wall");