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) Clips between the Arrangement and Session
Egor Khindikaynen0b5bb49b155d
diff --git a/.claude/skills/nota-shortcuts/SKILL.md b/.claude/skills/nota-shortcuts/SKILL.mdindex 0a5f876e..416d537b 100644--- a/.claude/skills/nota-shortcuts/SKILL.md+++ b/.claude/skills/nota-shortcuts/SKILL.md@@ -54,7 +54,7 @@ map changes, update the `PLAY NOTES` group (white vs. black keys, and the starti5. Visually verify (see [nota-ui-verify] memory): the pane can't be reached by a click in aheadless run, so temporarily open it via an env-guarded hook in`MainWindow.OnDataContextChanged` (`new PreferencesWindow(new SettingsViewModel(settings),- _vm).Show(this)`), and select the Shortcuts section (index 7) — e.g. a temporary env read+ _vm).Show(this)`), and select the Shortcuts section (index 8 — count the sidebar entries, it moves as pages are added) — e.g. a temporary env readin front of the constructor's `Select(0)`. Screenshot with `screencapture -x -o -l<winid>`(get the id from the `winlist` swift helper), check the rows read correctly, then **revertthe temp hooks** and rebuild.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7585e96a..714f62ad 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,6 +19,14 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.## [Unreleased]### Added+- **Clips between the Arrangement and Session:** copy MIDI and audio clips across with the+ clipboard — ⌘C (or ⌘X) on the timeline, then ⌘V on a session slot, and the other way round.+ **⌘⇧C** (and **Copy to Session** / **Copy to Arrangement** in the right-click menus and the+ Edit menu) sends the selection straight across: arrangement clips land in the first scene+ row where they all fit, each track's clips down its column in time order (or from a scene+ you pick via **Copy to Scene**), adding scenes when needed; a session clip, group slot or+ a whole scene lands on the timeline at the playhead without covering existing clips. Notes,+ clip envelopes, names, warp, pitch and gain come along; each copy is one undo step.- **Type a slider's value:** double-click the number next to a slider in a device card,the clip editor or a rack macro and type the value you want — "−6", "1.5k", "250 ms","L 30", "1/16". Return sets it, Esc cancels.diff --git a/src/managed/Nota.App/ArrangementView.LaneControl.cs b/src/managed/Nota.App/ArrangementView.LaneControl.csindex c2a747c3..0913970c 100644--- a/src/managed/Nota.App/ArrangementView.LaneControl.cs+++ b/src/managed/Nota.App/ArrangementView.LaneControl.cs@@ -1132,21 +1132,24 @@ public sealed partial class ArrangementViewflyout.Items.Add(convert);}- // M5-6: copy a clip (MIDI or audio) into a session slot (choose the scene).+ // M5-6: copy the clip selection into session slots — the first scene row where it+ // fits (⌘⇧C), or from a chosen scene down.if (_o._engine is { } eng){- bool midi = clip.IsMidi;- var toSession = new MenuItem { Header = "Copy to session", Icon = MenuKit.Icon(GlyphKind.Grid) };+ var toSession = new MenuItem { Header = inGroup ? "Copy selection to Session" : "Copy to Session", Icon = MenuKit.Icon(GlyphKind.Grid), InputGesture = MenuKit.CopyToOtherViewKey };+ toSession.Click += (_, _) => { EnsureSelected(); _o.CopySelectionToSession(); };+ var toScene = new MenuItem { Header = "Copy to Scene", Icon = MenuKit.Icon(GlyphKind.Grid) };for (int s = 0; s < eng.SceneCount; s++){int sc = s;- var it = new MenuItem { Header = $"Scene {sc + 1}" };- if (midi) it.Click += (_, _) => { eng.ArrangementClipToSession(trackId, idx, sc); _o.SessionChanged?.Invoke(); };- else it.Click += (_, _) => { eng.ArrangementAudioClipToSession(trackId, idx, sc); _o.SessionChanged?.Invoke(); };- toSession.Items.Add(it);+ string name = eng.GetSceneName(sc);+ var it = new MenuItem { Header = name.Length > 0 ? $"{sc + 1} · {name}" : $"Scene {sc + 1}" };+ it.Click += (_, _) => { EnsureSelected(); _o.CopySelectionToSession(sc); };+ toScene.Items.Add(it);}flyout.Items.Add(new Separator());flyout.Items.Add(toSession);+ flyout.Items.Add(toScene);}flyout.ShowAt(this, showAtPointer: true);}diff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.csindex 24fb052d..0bbf9140 100644--- a/src/managed/Nota.App/ArrangementView.cs+++ b/src/managed/Nota.App/ArrangementView.cs@@ -954,7 +954,9 @@ public sealed partial class ArrangementView : UserControl{if (_engine is null) return false;var sel = SelectionBlock();- return sel.Length > 0 && _engine.CopyClipBlock(sel);+ if (sel.Length == 0 || !_engine.CopyClipBlock(sel)) return false;+ ClipTransfer.TookFromArrangement();+ return true;}/// <summary>Cuts the whole clip selection: copies the block to the clipboard, then removes@@ -964,37 +966,81 @@ public sealed partial class ArrangementView : UserControlif (_engine is null) return false;var sel = SelectionBlock();if (sel.Length == 0 || !_engine.CutClipBlock(sel)) return false;+ ClipTransfer.TookFromArrangement();Select(-1, -1);Refresh();return true;}/// <summary>Pastes the block clipboard at <paramref name="atBeat"/>, remapped so its top- /// track lands on <paramref name="trackId"/> (single clip → that track). Selects the paste.</summary>+ /// track lands on <paramref name="trackId"/> (single clip → that track). Selects the paste.+ /// A slot copied in the Session view lands the same way.</summary>public bool PasteClipboardAt(int trackId, double atBeat){if (_engine is null || trackId <= 0) return false;+ if (ClipTransfer.FromSession) return PasteSessionSlot(atBeat, trackId);if (_engine.PasteClipBlock(atBeat, trackId) <= 0) return false;Refresh();ReselectPlaced();return true;}- /// <summary>Keyboard paste: the block lands on its source tracks at the playhead.</summary>+ /// <summary>Keyboard paste: the block lands on its source tracks at the playhead (a slot+ /// copied in the Session view: on its own track).</summary>public bool PasteClipboard(){- if (_engine is null || _engine.ClipboardBlockCount() == 0) return false;+ if (_engine is null) return false;+ if (ClipTransfer.FromSession) return PasteSessionSlot(Math.Max(0.0, _playheadBeats), -1);+ if (_engine.ClipboardBlockCount() == 0) return false;if (_engine.PasteClipBlock(Math.Max(0.0, _playheadBeats), -1) <= 0) return false;Refresh();ReselectPlaced();return true;}- /// <summary>True when the block clipboard holds at least one clip (drives menu enablement).</summary>- public bool HasClipClipboard => _engine?.ClipboardBlockCount() > 0;+ // The session clipboard's slot onto the timeline (destTrackId -1 = its own track); a cut+ // slot moves, emptying its slot in the same undo step.+ private bool PasteSessionSlot(double atBeat, int destTrackId)+ {+ if (_engine is null || ClipTransfer.Slot is not { } src) return false;+ _engine.BeginUndoGroup();+ int placed;+ try+ {+ placed = _engine.SessionSlotsToArrangement(new[] { (src.TrackId, src.Scene) }, atBeat, destTrackId);+ if (placed > 0 && src.Cut) _engine.ClearSessionSlot(src.TrackId, src.Scene);+ }+ finally { _engine.EndUndoGroup(); }+ if (placed <= 0)+ {+ StatusMessage?.Invoke("Paste a MIDI clip onto a MIDI track, audio onto audio.");+ return true;+ }+ if (src.Cut) { ClipTransfer.SlotMoved(null); SessionChanged?.Invoke(); }+ Refresh();+ ReselectPlaced();+ return true;+ }++ /// <summary>True when ⌘V has something to paste onto the timeline (drives menu enablement).</summary>+ public bool HasClipClipboard => _engine is not null && (ClipTransfer.FromSession || _engine.ClipboardBlockCount() > 0);- /// <summary>Clipboard clip kind: -1 empty, else 0 (block clipboard has content).</summary>- public int ClipboardClipKind() => HasClipClipboard ? 0 : -1;+ /// <summary>Copy to Session (⌘⇧C): the clip selection into session slots — each track's clips,+ /// in time order, down consecutive slots of one scene row; <paramref name="startScene"/> -1 =+ /// the first row where they all fit (new rows are added when needed). Returns the first row+ /// filled, or -1 when nothing was copied.</summary>+ public int CopySelectionToSession(int startScene = -1)+ {+ if (_engine is null) return -1;+ var sel = SelectionBlock();+ if (sel.Length == 0) return -1;+ int scene = _engine.ArrangementClipsToSession(sel, startScene);+ if (scene < 0) return -1;+ SessionChanged?.Invoke();+ StatusMessage?.Invoke(sel.Length == 1 ? $"Copied clip to session scene {scene + 1}"+ : $"Copied {sel.Length} clips to the session from scene {scene + 1}");+ return scene;+ }internal double Snap(double beat)=> _snapEnabled && _snapBeats > 0 ? Math.Round(beat / _snapBeats) * _snapBeats : beat;diff --git a/src/managed/Nota.App/ClipTransfer.cs b/src/managed/Nota.App/ClipTransfer.csnew file mode 100644index 00000000..b39689c1--- /dev/null+++ b/src/managed/Nota.App/ClipTransfer.cs@@ -0,0 +1,42 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// The clip clipboard shared by the Arrangement and the Session view. Each view keeps its own+// kind of copy — the arrangement's is the engine's block clipboard (a snapshot, so a cut+// survives), the session's a reference to a slot (a cut moves it on paste) — and the last+// copy or cut decides which one ⌘V takes from in either view. So clips copied on the+// timeline paste into session slots, and a slot copied in the grid pastes onto the timeline.++using Nota.Application;++namespace Nota.App;++internal static class ClipTransfer+{+ internal enum Source { None, Arrangement, Session }++ /// <summary>The view the last clip copy / cut came from.</summary>+ public static Source Last { get; private set; }++ /// <summary>The session clipboard: a slot; a cut moves it on paste.</summary>+ public static (int TrackId, int Scene, bool Cut)? Slot { get; private set; }++ public static void TookFromArrangement() => Last = Source.Arrangement;++ public static void TookSlot(int trackId, int scene, bool cut)+ {+ Slot = (trackId, scene, cut);+ Last = Source.Session;+ }++ /// <summary>After a cut slot was pasted: it now lives at its new place (or nowhere).</summary>+ public static void SlotMoved((int TrackId, int Scene)? to)+ => Slot = to is { } t ? (t.TrackId, t.Scene, false) : null;++ /// <summary>⌘V should paste the session slot.</summary>+ public static bool FromSession => Last == Source.Session && Slot is not null;++ /// <summary>⌘V should paste the arrangement's block clipboard.</summary>+ public static bool FromArrangement(IAudioEngine engine)+ => Last == Source.Arrangement && engine.ClipboardBlockCount() > 0;+}diff --git a/src/managed/Nota.App/MainWindow.Input.cs b/src/managed/Nota.App/MainWindow.Input.csindex 1703c35e..961dd70b 100644--- a/src/managed/Nota.App/MainWindow.Input.cs+++ b/src/managed/Nota.App/MainWindow.Input.cs@@ -180,6 +180,18 @@ public partial class MainWindowreturn;}+ // ⌘⇧C / ⌃⇧C = Copy to Session (Arrangement) / Copy to Arrangement (Session) — also the+ // Edit menu's accelerator, which gets there first on macOS. The focused Session grid+ // handles the key itself; the piano-roll grid keeps it for its notes.+ if (e.Key == Key.C && ArrangementView.IsPrimaryDown(e.KeyModifiers)+ && (e.KeyModifiers & KeyModifiers.Shift) != 0 && (e.KeyModifiers & KeyModifiers.Alt) == 0+ && _editorRoll is not { GridFocused: true })+ {+ OnMenuCopyToOtherView(this, EventArgs.Empty);+ e.Handled = true;+ return;+ }+// ⌘/⌃ + C/X/V = copy/cut/paste the selected arrangement clip. Skipped while the// piano-roll grid is focused (it copies/pastes notes) and when nothing is// actionable, so the event falls through to other handlers.diff --git a/src/managed/Nota.App/MainWindow.Menu.cs b/src/managed/Nota.App/MainWindow.Menu.csindex 07f59c21..880a0c33 100644--- a/src/managed/Nota.App/MainWindow.Menu.cs+++ b/src/managed/Nota.App/MainWindow.Menu.cs@@ -152,6 +152,18 @@ public partial class MainWindowif (ActiveRoll() is { } roll && roll.PasteClipboard()) { _vm.StatusText = "Pasted notes"; return; }if (Timeline.PasteClipboard()) { _session?.Refresh(); _vm.StatusText = "Pasted clip"; }}+ // ⌘⇧C: the Arrangement's selected clips go to session slots, the Session view's selected+ // slot / scene goes onto the timeline at the playhead — whichever view is on screen.+ private void OnMenuCopyToOtherView(object? sender, EventArgs e)+ {+ if (_vm is null) return;+ if (_session?.IsVisible == true)+ {+ if (!_session.CopySelectionToArrangement()) _vm.StatusText = "Select a clip or a scene to copy to the arrangement.";+ }+ else if (Timeline.IsVisible && Timeline.CopySelectionToSession() < 0)+ _vm.StatusText = "Select clips to copy to the session.";+ }private void OnMenuDeleteSel(object? sender, EventArgs e){if (_vm is null) return;diff --git a/src/managed/Nota.App/MainWindow.axaml b/src/managed/Nota.App/MainWindow.axamlindex 49b59391..2f45062e 100644--- a/src/managed/Nota.App/MainWindow.axaml+++ b/src/managed/Nota.App/MainWindow.axaml@@ -51,6 +51,7 @@<NativeMenuItem Header="Copy" Click="OnMenuCopy"/><NativeMenuItem Header="Paste" Click="OnMenuPaste"/><NativeMenuItem Header="Paste Bounced Audio" Click="OnMenuPasteBounced" Gesture="Shift+Cmd+V"/>+ <NativeMenuItem Header="Copy Clips to Session / Arrangement" Click="OnMenuCopyToOtherView" Gesture="Shift+Cmd+C"/><NativeMenuItem Header="Delete" Click="OnMenuDeleteSel"/></NativeMenu></NativeMenuItem.Menu>diff --git a/src/managed/Nota.App/MenuKit.cs b/src/managed/Nota.App/MenuKit.csindex 86200e77..9ce884f1 100644--- a/src/managed/Nota.App/MenuKit.cs+++ b/src/managed/Nota.App/MenuKit.cs@@ -25,6 +25,8 @@ internal static class MenuKitpublic static readonly KeyGesture PasteKey = Cmd(Key.V);public static readonly KeyGesture PasteBouncedKey = Cmd(Key.V, shift: true);public static readonly KeyGesture DuplicateKey = Cmd(Key.D);+ // Arrangement: Copy to Session · Session: Copy to Arrangement.+ public static readonly KeyGesture CopyToOtherViewKey = Cmd(Key.C, shift: true);public static readonly KeyGesture SplitKey = Cmd(Key.E);public static readonly KeyGesture ConsolidateKey = Cmd(Key.J);public static readonly KeyGesture LoopKey = Cmd(Key.L);diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.csindex 6f3070ec..6f171bf4 100644--- a/src/managed/Nota.App/PreferencesWindow.cs+++ b/src/managed/Nota.App/PreferencesWindow.cs@@ -969,7 +969,8 @@ public sealed partial class PreferencesWindow : NotaWindow("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"),- ("⌘C ⌘X ⌘V", "Copy / cut / paste clip (or automation range)"),+ ("⌘C ⌘X ⌘V", "Copy / cut / paste clip (or automation range) · a clip copied in Session pastes here"),+ ("⌘⇧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"),("⌘D", "Duplicate the selected clip(s) / range"),("⌘E", "Split at the playhead · at the range edges"),@@ -988,7 +989,8 @@ public sealed partial class PreferencesWindow : NotaWindow{("← → ↑ ↓", "Move the selection between slots and scenes"),("Return", "Launch the selected clip or scene"),- ("⌘C ⌘X ⌘V", "Copy / cut / paste a clip · a cut clip moves when pasted"),+ ("⌘C ⌘X ⌘V", "Copy / cut / paste a clip · a cut clip moves when pasted · clips copied in the Arrangement paste here"),+ ("⌘⇧C", "Copy the selected clip, group slot or scene to the Arrangement at the playhead"),("⌘D", "Duplicate a clip into the slot below · a scene below itself"),("⌘I", "Insert a scene below the selection"),("F2", "Rename the selected clip or scene"),diff --git a/src/managed/Nota.App/SessionView.Grid.cs b/src/managed/Nota.App/SessionView.Grid.csindex 4d41bb3e..5caab8ed 100644--- a/src/managed/Nota.App/SessionView.Grid.cs+++ b/src/managed/Nota.App/SessionView.Grid.cs@@ -828,11 +828,11 @@ public sealed partial class SessionViewf.Items.Add(MenuKit.Item("Copy", GlyphKind.Copy, () => CopySelection(), MenuKit.CopyKey));f.Items.Add(MenuKit.Item("Cut", GlyphKind.Cut, () => CutSelection(), MenuKit.CutKey));}- f.Items.Add(MenuKit.Item("Paste", GlyphKind.Paste, () => PasteSelection(), MenuKit.PasteKey, _clip is not null));+ f.Items.Add(MenuKit.Item("Paste", GlyphKind.Paste, () => PasteSelection(), MenuKit.PasteKey, CanPaste));if (filled){f.Items.Add(MenuKit.Item("Duplicate", GlyphKind.Duplicate, () => DuplicateSelection(), MenuKit.DuplicateKey));- f.Items.Add(MenuKit.Item("Copy to arrangement (at playhead)", GlyphKind.Arrow, () => ToArrangement(c.TrackId, scene)));+ f.Items.Add(MenuKit.Item("Copy to Arrangement", GlyphKind.Arrow, () => CopySelectionToArrangement(), MenuKit.CopyToOtherViewKey));f.Items.Add(new Separator());f.Items.Add(MenuKit.Item("Delete", GlyphKind.Trash, () => DeleteSelection(), MenuKit.DeleteKey));}@@ -901,6 +901,8 @@ public sealed partial class SessionViewf.Items.Add(MenuKit.Item("Insert scene below", GlyphKind.Plus, () => InsertSceneAtSelection(), MenuKit.Cmd(Key.I)));f.Items.Add(MenuKit.Item("Duplicate scene", GlyphKind.Duplicate, () => DuplicateSelection(), MenuKit.DuplicateKey));f.Items.Add(MenuKit.Item("Capture playing clips below", GlyphKind.Copy, CaptureScene));+ f.Items.Add(MenuKit.Item("Paste", GlyphKind.Paste, () => PasteSelection(), MenuKit.PasteKey, ClipTransfer.FromArrangement(_engine)));+ f.Items.Add(MenuKit.Item("Copy scene to Arrangement", GlyphKind.Arrow, () => CopySelectionToArrangement(), MenuKit.CopyToOtherViewKey, SelectedSlots().Length > 0));f.Items.Add(new Separator());f.Items.Add(MenuKit.Item("Delete scene", GlyphKind.Trash, () => DeleteSelection(), MenuKit.DeleteKey, _sceneCount > 1));f.ShowAt(anchor, showAtPointer: true);diff --git a/src/managed/Nota.App/SessionView.Inspector.cs b/src/managed/Nota.App/SessionView.Inspector.csindex f7548e3e..90f9f1ff 100644--- a/src/managed/Nota.App/SessionView.Inspector.cs+++ b/src/managed/Nota.App/SessionView.Inspector.cs@@ -54,7 +54,7 @@ public sealed partial class SessionViewvar hint = new TextBlock{- Text = "Click selects · the triangle launches · Enter launches the selection\n←↑↓→ move · ⌘C ⌘V ⌘D · ⌫ delete · ⌘I insert scene",+ Text = "Click selects · the triangle launches · Enter launches the selection\n←↑↓→ move · ⌘C ⌘V ⌘D · ⌫ delete · ⌘I insert scene\n⌘⇧C copy to arrangement · ⌘V pastes clips copied there",FontSize = 9, LineHeight = 15, Foreground = NotaPalette.TextDisabled, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(16),};hint.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");@@ -319,7 +319,7 @@ public sealed partial class SessionViews.Children.Add(Actions(("Duplicate", "⌘D", () => DuplicateSelection()),("Rename", "F2", () => RenameSelection()),- ("To Arrangement", "", () => ToArrangement(id, scene)),+ ("To Arrangement", "⌘⇧C", () => CopySelectionToArrangement()),("Edit", "", () => SlotEditRequested?.Invoke(id, scene)),("Delete", "⌫", () => DeleteSelection())));}@@ -400,6 +400,7 @@ public sealed partial class SessionView("Insert below", "⌘I", () => InsertSceneAtSelection()),("Duplicate", "⌘D", () => DuplicateSelection()),("Rename", "F2", () => RenameSelection()),+ ("To Arrangement", "⌘⇧C", () => CopySelectionToArrangement()),("Delete", "⌫", () => DeleteSelection())));}@@ -422,7 +423,7 @@ public sealed partial class SessionViewif (c.IsInstrument) actions.Add(("Insert MIDI clip", "", () => InsertMidiClip(c.TrackId, scene)));actions.Add(rec ? ("Stop recording", "", () => { _engine.StopSessionRecord(); Refresh(); }): ("Record here", "", () => { _engine.RecordSessionSlot(c.TrackId, scene); Refresh(); }));- if (_clip is not null) actions.Add(("Paste", "⌘V", () => PasteSelection()));+ if (CanPaste) actions.Add(("Paste", "⌘V", () => PasteSelection()));s.Children.Add(Actions(actions.ToArray()));}@@ -434,7 +435,8 @@ public sealed partial class SessionViewText = "Launches every track's slot in this scene. The stop button stops them all.",FontSize = 11, LineHeight = 16, Foreground = NotaPalette.TextTertiary, TextWrapping = TextWrapping.Wrap,});- s.Children.Add(Actions(("Launch group slot", "↵", () => LaunchGroup(g, scene)), ("Stop group", "", () => StopColumn(g))));+ s.Children.Add(Actions(("Launch group slot", "↵", () => LaunchGroup(g, scene)), ("Stop group", "", () => StopColumn(g)),+ ("To Arrangement", "⌘⇧C", () => CopySelectionToArrangement())));}/// <summary>The selected clip's notes / waveform with a live playhead.</summary>diff --git a/src/managed/Nota.App/SessionView.cs b/src/managed/Nota.App/SessionView.csindex 3d4b71cc..f79662dc 100644--- a/src/managed/Nota.App/SessionView.cs+++ b/src/managed/Nota.App/SessionView.cs@@ -60,9 +60,6 @@ public sealed partial class SessionView : UserControlprivate bool _selectNextOnLaunch;private Selection _sel = new(SelKind.Slot, 0, 0);- // Clipboard: a reference to a slot; a cut moves it on paste.- private (int TrackId, int Scene, bool Cut)? _clip;-private int _blinkFrame;private bool _blinkOn = true;private bool _sessionActive;@@ -74,7 +71,7 @@ public sealed partial class SessionView : UserControlpublic event Action<int, int>? SlotEditRequested;/// <summary>Raised when the selection lands on a track's slot (trackId, scene).</summary>public event Action<int, int>? SlotSelected;- /// <summary>Raised after a slot is copied into the arrangement (M5-6) or a track is renamed.</summary>+ /// <summary>Raised after slots are copied / moved into the arrangement (M5-6) or a track is renamed.</summary>public event Action? ArrangementChanged;/// <summary>A context menu asked for a new track (kind, the track to place it after, or -1 = at the end).</summary>public event Action<NewTrackKind, int>? AddTrackRequested;@@ -370,7 +367,7 @@ public sealed partial class SessionView : UserControlpublic bool CopySelection(){if (_sel.Kind != SelKind.Slot || !SlotFilled(_sel.TrackId, _sel.Scene)) return false;- _clip = (_sel.TrackId, _sel.Scene, false);+ ClipTransfer.TookSlot(_sel.TrackId, _sel.Scene, cut: false);Say("Copied clip");return true;}@@ -379,15 +376,19 @@ public sealed partial class SessionView : UserControlpublic bool CutSelection(){if (_sel.Kind != SelKind.Slot || !SlotFilled(_sel.TrackId, _sel.Scene)) return false;- _clip = (_sel.TrackId, _sel.Scene, true);+ ClipTransfer.TookSlot(_sel.TrackId, _sel.Scene, cut: true);Say("Cut clip — paste to move it");return true;}- /// <summary>⌘V onto the selected slot.</summary>+ /// <summary>True when ⌘V has something to paste: a slot, or clips copied in the arrangement.</summary>+ private bool CanPaste => ClipTransfer.FromArrangement(_engine) || ClipTransfer.Slot is not null;++ /// <summary>⌘V onto the selected slot (clips copied in the arrangement: also onto a scene row).</summary>public bool PasteSelection(){- if (_sel.Kind != SelKind.Slot || _clip is not { } src) return false;+ if (ClipTransfer.FromArrangement(_engine)) return PasteFromArrangement();+ if (_sel.Kind != SelKind.Slot || ClipTransfer.Slot is not { } src) return false;if (ColumnFor(_sel.TrackId) is not { Kind: ColKind.Track }) return false;bool move = src.Cut && (src.TrackId, src.Scene) != (_sel.TrackId, _sel.Scene);if (!MoveOrCopySlot(src.TrackId, src.Scene, _sel.TrackId, _sel.Scene, move))@@ -395,11 +396,29 @@ public sealed partial class SessionView : UserControlSay("Paste a MIDI clip onto a MIDI track, audio onto audio.");return true;}- if (move) _clip = (_sel.TrackId, _sel.Scene, false);+ if (move) ClipTransfer.SlotMoved((_sel.TrackId, _sel.Scene));Say(move ? "Moved clip" : "Pasted clip");return true;}+ // The arrangement's clip clipboard into slots from the selected scene down: its top track+ // lands on the selected track column (a scene row or group selected: the clips' own tracks),+ // each track's clips in time order down consecutive slots.+ private bool PasteFromArrangement()+ {+ int dest = _sel.Kind == SelKind.Slot && ColumnFor(_sel.TrackId) is { Kind: ColKind.Track } c ? c.TrackId : -1;+ int n = _engine.ClipboardBlockCount();+ int first = _engine.PasteClipBlockToSession(dest, _sel.Scene);+ if (first < 0)+ {+ Say("Paste a MIDI clip onto a MIDI track, audio onto audio.");+ return true;+ }+ Refresh(); // the paste may have added scene rows+ if (dest > 0) Select(new Selection(SelKind.Slot, dest, first));+ Say(n == 1 ? "Pasted clip from the arrangement" : $"Pasted {n} clips from the arrangement");+ return true;+ }// Copy a slot onto another (same track kind), and for a move clear the source — one undo// step either way. Repaints just the two cells.private bool MoveOrCopySlot(int fromTrack, int fromScene, int toTrack, int toScene, bool move)@@ -491,11 +510,28 @@ public sealed partial class SessionView : UserControlSay("Captured the playing clips into a new scene");}- private void ToArrangement(int trackId, int scene)+ // The filled slots a selection covers: a track's slot, a group's slots in that scene, or a+ // whole scene row (every track, folded groups' tracks included).+ private (int trackId, int scene)[] SelectedSlots(){- if (_engine.SessionSlotToArrangement(trackId, scene, _engine.PositionBeats) < 0) return;+ IEnumerable<int> tracks = _sel.Kind == SelKind.Scene+ ? NavCols.SelectMany(c => c.Kind == ColKind.Group ? c.Children : new List<int> { c.TrackId })+ : ColumnFor(_sel.TrackId) is { } col ? (col.Kind == ColKind.Group ? col.Children : new List<int> { col.TrackId }) : Enumerable.Empty<int>();+ return tracks.Distinct().Where(t => SlotFilled(t, _sel.Scene)).Select(t => (t, _sel.Scene)).ToArray();+ }++ /// <summary>Copy to Arrangement (⌘⇧C): the selected slot, group slot or scene onto the timeline+ /// at the playhead, each clip on its own track — pasted, so it never covers existing clips.</summary>+ public bool CopySelectionToArrangement()+ {+ var slots = SelectedSlots();+ if (slots.Length == 0) return false;+ int placed = _engine.SessionSlotsToArrangement(slots, _engine.PositionBeats);+ if (placed <= 0) return false;ArrangementChanged?.Invoke();- Say("Copied clip to the arrangement at the playhead");+ Say(placed == 1 ? "Copied clip to the arrangement at the playhead"+ : $"Copied {placed} clips to the arrangement at the playhead");+ return true;}protected override void OnKeyDown(KeyEventArgs e)@@ -521,6 +557,9 @@ public sealed partial class SessionView : UserControlcase Key.F2 when !mod:RenameSelection();return true;+ case Key.C when mod && e.KeyModifiers.HasFlag(KeyModifiers.Shift) && !e.KeyModifiers.HasFlag(KeyModifiers.Alt):+ CopySelectionToArrangement();+ return true;}if (!mod || other) return false;return e.Key switchdiff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.csindex 7d8a4f2f..e1d93b8a 100644--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs@@ -270,6 +270,17 @@ public interface IAudioEngine : IDisposabledouble DuplicateClipBlock((int trackId, int clipIndex)[] sel);/// <summary>Number of clips in the block clipboard (0 = empty).</summary>int ClipboardBlockCount();+ /// <summary>Copies arrangement clips into session slots: each track's clips, in time order, fill+ /// consecutive slots from startScene (-1 = the first scene row where every slot needed is empty;+ /// missing rows are appended). One undo step. Returns the first scene row filled, or -1.</summary>+ int ArrangementClipsToSession((int trackId, int clipIndex)[] sel, int startScene = -1);+ /// <summary>Pastes the block clipboard into session slots, its top track remapped onto destTrackId+ /// (-1 = the source tracks). Returns the first scene row filled, or -1.</summary>+ int PasteClipBlockToSession(int destTrackId, int startScene);+ /// <summary>Copies session slots (trackId, scene) into the arrangement: each track's slots, in scene+ /// order, land back to back from atBeat, placed like a paste (no overlap) and remapped onto destTrackId+ /// (-1 = their own tracks). One undo step; LastPlacedClips reports them. Returns clips placed.</summary>+ int SessionSlotsToArrangement((int trackId, int scene)[] slots, double atBeat, int destTrackId = -1);/// <summary>The (trackId, clipIndex) of every clip the last block paste/duplicate produced.</summary>(int trackId, int clipIndex)[] LastPlacedClips();/// <summary>Sets/gets a clip's user-facing name (empty = default).</summary>diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.csindex a2eeb887..7469c772 100644--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs@@ -192,6 +192,15 @@ internal static partial class NativeMethods[LibraryImport(Lib, EntryPoint = "nota_clips_block_paste")]internal static partial int ClipsBlockPaste(IntPtr engine, double atBeat, int destTrackId);+ [LibraryImport(Lib, EntryPoint = "nota_clips_to_session")]+ internal static partial int ClipsToSession(IntPtr engine, [In] int[] trackIds, [In] int[] clipIndices, int count, int startScene);++ [LibraryImport(Lib, EntryPoint = "nota_clips_block_paste_to_session")]+ internal static partial int ClipsBlockPasteToSession(IntPtr engine, int destTrackId, int startScene);++ [LibraryImport(Lib, EntryPoint = "nota_session_slots_to_arrangement")]+ internal static partial int SessionSlotsToArrangement(IntPtr engine, [In] int[] trackIds, [In] int[] scenes, int count, double atBeat, int destTrackId);+[LibraryImport(Lib, EntryPoint = "nota_clips_block_duplicate")]internal static partial double ClipsBlockDuplicate(IntPtr engine, [In] int[] trackIds, [In] int[] clipIndices, int count);diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.csindex 211f60bc..cee25f27 100644--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs@@ -338,6 +338,27 @@ public sealed partial class NotaEnginepublic int ClipboardBlockCount(){ ThrowIfDisposed(); return NativeMethods.ClipsBlockCount(_handle); }+ /// <summary>Copies arrangement clips into session slots: each track's clips, in time order,+ /// fill consecutive slots from <paramref name="startScene"/> (-1 = the first scene row where+ /// every slot needed is empty; missing rows are appended). One undo step. Returns the first+ /// scene row filled, or -1 when nothing landed.</summary>+ public int ArrangementClipsToSession((int trackId, int clipIndex)[] sel, int startScene = -1)+ { ThrowIfDisposed(); var (t, c) = SplitSel(sel); return NativeMethods.ClipsToSession(_handle, t, c, sel.Length, startScene); }++ /// <summary>Pastes the block clipboard into session slots, remapped so its top track lands on+ /// <paramref name="destTrackId"/> (-1 = the source tracks); slots fill as in+ /// <see cref="ArrangementClipsToSession"/>. Returns the first scene row filled, or -1.</summary>+ public int PasteClipBlockToSession(int destTrackId, int startScene)+ { ThrowIfDisposed(); return NativeMethods.ClipsBlockPasteToSession(_handle, destTrackId, startScene); }++ /// <summary>Copies session slots (trackId, scene) into the arrangement: each track's slots, in+ /// scene order, land back to back from <paramref name="atBeat"/>, placed like a paste (shifted+ /// right as a whole until nothing overlaps) and remapped onto <paramref name="destTrackId"/>+ /// (-1 = their own tracks). One undo step; <see cref="LastPlacedClips"/> reports the new clips.+ /// Returns the number of clips placed.</summary>+ public int SessionSlotsToArrangement((int trackId, int scene)[] slots, double atBeat, int destTrackId = -1)+ { ThrowIfDisposed(); var (t, s) = SplitSel(slots); return NativeMethods.SessionSlotsToArrangement(_handle, t, s, slots.Length, atBeat, destTrackId); }+/// <summary>The (trackId, clipIndex) of every clip the last block paste/duplicate produced.</summary>public (int trackId, int clipIndex)[] LastPlacedClips(){diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.hindex 23fb8b25..8f849fcb 100644--- a/src/native/nota.engine/include/nota/nota_engine.h+++ b/src/native/nota.engine/include/nota/nota_engine.h@@ -1015,6 +1015,19 @@ NOTA_API int32_t nota_clips_block_paste(NotaEngine* engine, double at_beat, iNOTA_API double nota_clips_block_duplicate(NotaEngine* engine, const int32_t* track_ids, const int32_t* clip_indices, int32_t count);NOTA_API int32_t nota_clips_block_count(NotaEngine* engine);NOTA_API int32_t nota_clips_last_placed(NotaEngine* engine, int32_t* out_track_ids, int32_t* out_clip_indices, int32_t cap);+/* Arrangement clips -> session slots. Each track's clips, in time order, fill consecutive+ * slots from start_scene; start_scene -1 = the first scene row where every slot needed is+ * empty. Missing scene rows are appended; clips on tracks without slots are skipped. One undo+ * step. to_session takes a selection; block_paste_to_session takes the block clipboard,+ * remapped so its top track lands on dest_track_id (-1 = the source tracks). Both return the+ * first scene row filled, or -1 when nothing landed. */+NOTA_API int32_t nota_clips_to_session(NotaEngine* engine, const int32_t* track_ids, const int32_t* clip_indices, int32_t count, int32_t start_scene);+NOTA_API int32_t nota_clips_block_paste_to_session(NotaEngine* engine, int32_t dest_track_id, int32_t start_scene);+/* Session slots (track_ids[i], scenes[i]) -> arrangement clips: each track's slots, in scene+ * order, land back to back from at_beat, all tracks together, placed like a paste (the whole+ * block shifts right until it overlaps nothing) and remapped onto dest_track_id (-1 = their+ * own tracks). One undo step; nota_clips_last_placed reports the new clips. -> clips placed. */+NOTA_API int32_t nota_session_slots_to_arrangement(NotaEngine* engine, const int32_t* track_ids, const int32_t* scenes, int32_t count, double at_beat, int32_t dest_track_id);/* Clip / track UI metadata: names (UTF-8) + track colour (palette slot, -1 = auto).* get_* write up to cap-1 chars + NUL into out and return the full length. */NOTA_API NotaResult nota_clip_set_name(NotaEngine* engine, int32_t track_id, int32_t clip_index, const char* name_utf8);diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.hindex 9eb9f42d..a18fad45 100644--- a/src/native/nota.engine/src/Engine.h+++ b/src/native/nota.engine/src/Engine.h@@ -514,6 +514,21 @@ public:int32_t clipboardBlockCount() const { return static_cast<int32_t>(clipboardBlock_.size()); }const std::vector<std::pair<int32_t,int32_t>>& lastPlaced() const { return lastPlaced_; }+ // Arrangement -> Session for a set of clips (a multi-selection, or the block clipboard+ // remapped so its top track lands on destTrackId like a paste). Each track's clips, in+ // time order, fill consecutive slots from startScene; startScene -1 picks the first scene+ // row where every slot needed is empty. Scene rows run out -> new ones are appended. A+ // clip whose track has no slots is skipped. One undo step. Returns the first scene row+ // filled, or -1 when nothing landed.+ int32_t arrangementClipsToSession(const std::vector<std::pair<int32_t,int32_t>>& sel, int32_t startScene);+ int32_t pasteClipBlockToSession(int32_t destTrackId, int32_t startScene);+ // Session -> Arrangement for a set of slots (trackId, scene): every track's slots, in scene+ // order, land back to back from atBeat, all tracks starting together. The block is placed+ // like a paste — shifted right as a whole until it overlaps nothing — and, with+ // destTrackId >= 0, remapped so its top track lands there. One undo step; lastPlaced()+ // reports the new clips. Returns the number of clips placed.+ int32_t sessionSlotsToArrangement(const std::vector<std::pair<int32_t,int32_t>>& slots, double atBeat, int32_t destTrackId);+// Clip / track UI metadata (name + track colour). Names are user-facing; colorIndex// is a palette slot (-1 = auto). clipName/trackName write into out (up to cap-1 chars// + NUL) and return the full length.@@ -1118,6 +1133,13 @@ private:std::vector<BlockClip> captureBlock(const std::vector<std::pair<int32_t,int32_t>>& sel,double& blockLen) const;void placeBlock(const std::vector<BlockClip>& items, double placedStart, bool overwrite = false);+ // Remap a block by the track-index delta from its top track to destTrackId, dropping+ // clips that fall off the track list or onto a track of the other kind.+ std::vector<BlockClip> remapBlock(const std::vector<BlockClip>& items, int32_t destTrackId) const;+ int32_t landBlockInSession(const std::vector<BlockClip>& items, int32_t startScene);+ // A fresh slot looping one arrangement clip (see Engine_Session.cpp).+ SessionSlot slotFromMidiClip(const MidiClip& m) const;+ SessionSlot slotFromAudioClip(const AudioClip& a);// Build a fully independent copy of a track (fresh id + cloned instrument/devices).std::shared_ptr<Track> deepCloneTrack(const Track& src, int32_t newId);diff --git a/src/native/nota.engine/src/Engine_Session.cpp b/src/native/nota.engine/src/Engine_Session.cppindex 44163f51..35702e74 100644--- a/src/native/nota.engine/src/Engine_Session.cpp+++ b/src/native/nota.engine/src/Engine_Session.cpp@@ -17,6 +17,7 @@#include <algorithm>#include <chrono>+#include <map>#include <cmath>namespace nota {@@ -377,11 +378,11 @@ int32_t Engine::sessionSlotToArrangement(int32_t trackId, int32_t scene, doublerepublishWithTrack(trackId, nt);return idx;}- MidiClip c;+ MidiClip c = s.midi; // notes + clip envelopes, already relative to clip startc.name = s.name;c.startBeat = startBeat < 0.0 ? 0.0 : startBeat;c.lengthBeats = s.lengthBeats > 0 ? s.lengthBeats : 4.0;- c.notes = s.midi.notes; // slot notes are already relative to clip start+ c.active = true;nt->midiClips.push_back(c);const int32_t idx = static_cast<int32_t>(nt->midiClips.size()) - 1;republishWithTrack(trackId, nt);@@ -396,13 +397,7 @@ bool Engine::arrangementClipToSession(int32_t trackId, int32_t clipIndex, int32_auto nt = cloneTrack(*old);if (static_cast<int32_t>(nt->sessionSlots.size()) < authoring_->sceneCount)nt->sessionSlots.resize(authoring_->sceneCount);- const MidiClip src = nt->midiClips[clipIndex]; // copy before mutating the track- SessionSlot& s = nt->sessionSlots[scene];- s.hasClip = true;- s.lengthBeats = src.lengthBeats > 0 ? src.lengthBeats : 4.0;- s.midi = src;- s.midi.startBeat = 0.0; // slot content is relative to slot start- s.name = src.name;+ nt->sessionSlots[scene] = slotFromMidiClip(old->midiClips[clipIndex]);republishWithTrack(trackId, nt);return true;}@@ -416,19 +411,39 @@ bool Engine::arrangementAudioClipToSession(int32_t trackId, int32_t clipIndex, iauto nt = cloneTrack(*old);if (static_cast<int32_t>(nt->sessionSlots.size()) < authoring_->sceneCount)nt->sessionSlots.resize(authoring_->sceneCount);- // The whole clip comes along — its region, warp, pitch, reverse, gain and envelopes —- // and the slot loops exactly what the clip plays.- SessionSlot& s = nt->sessionSlots[scene];+ nt->sessionSlots[scene] = slotFromAudioClip(old->clips[clipIndex]);+ republishWithTrack(trackId, nt);+ return true;+}++// A fresh slot looping one arrangement MIDI clip: its notes and clip envelopes, its name,+// and its length as the loop.+SessionSlot Engine::slotFromMidiClip(const MidiClip& m) const {+ SessionSlot s;s.hasClip = true;- s.midi = MidiClip{};- s.audio = nt->clips[clipIndex];+ s.midi = m;+ s.midi.startBeat = 0.0; // slot content is relative to slot start+ s.midi.active = true; // a slot has no deactivate; it would just stay silent+ s.lengthBeats = m.lengthBeats > 0 ? m.lengthBeats : 4.0;+ s.midi.lengthBeats = s.lengthBeats;+ s.name = m.name;+ return s;+}++// A fresh slot looping one arrangement audio clip. The whole clip comes along — its region,+// warp, pitch, reverse, gain and envelopes — and the slot loops exactly what the clip plays.+SessionSlot Engine::slotFromAudioClip(const AudioClip& a) {+ SessionSlot s;+ s.hasClip = true;+ s.audio = a;s.audio.startBeat = 0.0;s.audio.active = true;- s.name = s.audio.name;- s.lengthBeats = 4.0;- syncSessionAudioSlot(*nt, sessionClipIndex(scene));- republishWithTrack(trackId, nt);- return true;+ if (s.audio.warpEnabled && !s.audio.warpCache) // a clipboard copy dropped its cache+ configureClipWarp(s.audio, transport_.samplesPerBeat(), transport_.sampleRate());+ s.name = a.name;+ const double beats = audioClipBeats(s.audio);+ s.lengthBeats = beats > 0.0 ? beats : 4.0;+ return s;}bool Engine::addSessionMidiClip(int32_t trackId, int32_t scene, double lengthBeats) {@@ -668,6 +683,113 @@ bool Engine::copySessionSlot(int32_t srcTrack, int32_t srcScene, int32_t dstTracreturn true;}+// --- Arrangement clips -> session slots (a selection or the clip clipboard) -------------++int32_t Engine::arrangementClipsToSession(const std::vector<std::pair<int32_t,int32_t>>& sel, int32_t startScene) {+ double len = 0.0;+ return landBlockInSession(captureBlock(sel, len), startScene);+}++int32_t Engine::pasteClipBlockToSession(int32_t destTrackId, int32_t startScene) {+ if (clipboardBlock_.empty() || !authoring_) return -1;+ return landBlockInSession(destTrackId >= 0 ? remapBlock(clipboardBlock_, destTrackId) : clipboardBlock_, startScene);+}++int32_t Engine::sessionSlotsToArrangement(const std::vector<std::pair<int32_t,int32_t>>& slots, double atBeat, int32_t destTrackId) {+ lastPlaced_.clear();+ if (!authoring_) return 0;+ std::map<int32_t, std::vector<int32_t>> byTrack; // track -> scenes, in order+ for (const auto& [tid, scene] : slots) byTrack[tid].push_back(scene);+ std::vector<BlockClip> items;+ for (auto& [tid, scenes] : byTrack) {+ auto t = findTrackAuthoring(tid);+ if (!t || !sessionLaunchable(*t)) continue;+ std::sort(scenes.begin(), scenes.end());+ scenes.erase(std::unique(scenes.begin(), scenes.end()), scenes.end());+ double at = 0.0;+ for (int32_t scene : scenes) {+ const SessionSlot* sl = slotAt(*t, scene);+ if (!sl || !sl->hasClip) continue;+ BlockClip b;+ b.trackId = tid;+ b.relStart = at;+ if (t->type() == TrackType::Instrument) {+ b.kind = 1;+ b.midi = sl->midi; // notes + clip envelopes, relative to the slot start+ b.midi.name = sl->name;+ b.midi.active = true;+ b.midi.lengthBeats = sl->lengthBeats > 0 ? sl->lengthBeats : 4.0;+ b.len = b.midi.lengthBeats;+ } else {+ if (!sl->audio.sample) continue;+ b.kind = 0; // an audio take lands as one pass of its loop+ b.audio = sl->audio;+ b.audio.name = sl->name;+ b.audio.active = true;+ b.audio.warpCache = nullptr; // placeBlock rebuilds it+ b.len = audioClipBeats(b.audio);+ }+ at += b.len;+ items.push_back(std::move(b));+ }+ }+ if (destTrackId >= 0) items = remapBlock(items, destTrackId);+ if (items.empty()) return 0;+ placeBlock(items, atBeat);+ return static_cast<int32_t>(lastPlaced_.size());+}++// Each track's clips, in time order, fill consecutive slots from one shared scene row, so+// clips that played together in the arrangement share a scene and a sequence reads down+// the column. One undo step, scene rows appended included.+int32_t Engine::landBlockInSession(const std::vector<BlockClip>& items, int32_t startScene) {+ if (!authoring_) return -1;+ std::map<int32_t, std::vector<const BlockClip*>> byTrack;+ for (const auto& b : items) {+ auto t = findTrackAuthoring(b.trackId);+ if (!t || !sessionLaunchable(*t)) continue;+ if ((b.kind == 1) != (t->type() == TrackType::Instrument)) continue;+ if (b.kind == 0 && !b.audio.sample) continue;+ byTrack[b.trackId].push_back(&b);+ }+ if (byTrack.empty()) return -1;+ int32_t rows = 0;+ for (auto& [tid, v] : byTrack) {+ std::stable_sort(v.begin(), v.end(), [](const BlockClip* x, const BlockClip* y) { return x->relStart < y->relStart; });+ rows = std::max(rows, static_cast<int32_t>(v.size()));+ }++ int32_t first = startScene;+ if (first < 0) {+ // The first row from which every track's run of slots is empty (rows past the end are).+ auto runFree = [&](int32_t row) {+ for (const auto& [tid, v] : byTrack) {+ auto t = findTrackAuthoring(tid);+ for (int32_t i = 0; i < static_cast<int32_t>(v.size()); ++i)+ if (const SessionSlot* sl = slotAt(*t, row + i); sl && sl->hasClip) return false;+ }+ return true;+ };+ first = 0;+ while (first < authoring_->sceneCount && !runFree(first)) ++first;+ }++ beginUndoGroup();+ while (authoring_->sceneCount < first + rows) insertScene(authoring_->sceneCount);+ for (const auto& [tid, v] : byTrack) {+ auto old = findTrackAuthoring(tid);+ if (!old) continue;+ auto nt = cloneTrack(*old);+ if (static_cast<int32_t>(nt->sessionSlots.size()) < authoring_->sceneCount)+ nt->sessionSlots.resize(authoring_->sceneCount);+ for (int32_t i = 0; i < static_cast<int32_t>(v.size()); ++i)+ nt->sessionSlots[first + i] = v[i]->kind == 1 ? slotFromMidiClip(v[i]->midi) : slotFromAudioClip(v[i]->audio);+ republishWithTrack(tid, nt);+ }+ endUndoGroup();+ return first;+}+namespace {SceneInfo sceneOr(const Graph& g, int32_t scene) {return (scene >= 0 && scene < static_cast<int32_t>(g.scenes.size())) ? g.scenes[scene] : SceneInfo{};diff --git a/src/native/nota.engine/src/Engine_Tracks.cpp b/src/native/nota.engine/src/Engine_Tracks.cppindex 2b2c952f..67f6e4ab 100644--- a/src/native/nota.engine/src/Engine_Tracks.cpp+++ b/src/native/nota.engine/src/Engine_Tracks.cpp@@ -2243,44 +2243,46 @@ bool Engine::cutClipBlock(const std::vector<std::pair<int32_t,int32_t>>& sel) {int32_t Engine::pasteClipBlock(double atBeat, int32_t sourceTrackId) {if (clipboardBlock_.empty() || !authoring_) return 0;- std::vector<BlockClip> items = clipboardBlock_;- // sourceTrackId >= 0 remaps the whole block by the track-index delta from its top track to- // the destination (so a single clip lands on that track; a multi-track block shifts- // together). Clips that fall off the track list or hit a type-mismatched track are- // skipped; a remapped clip's device/plugin automation is dropped (indices are positional).- if (sourceTrackId >= 0) {- auto idxOf = [&](int32_t tid) -> int {- for (size_t i = 0; i < authoring_->tracks.size(); ++i)- if (authoring_->tracks[i]->id() == tid) return static_cast<int>(i);- return -1;- };- const int destIdx = idxOf(sourceTrackId);- int topIdx = std::numeric_limits<int>::max();- for (const auto& b : items) { int ix = idxOf(b.trackId); if (ix >= 0) topIdx = std::min(topIdx, ix); }- if (destIdx < 0 || topIdx == std::numeric_limits<int>::max()) return 0;- const int delta = destIdx - topIdx;- std::vector<BlockClip> remapped;- for (const auto& b : items) {- const int ix = idxOf(b.trackId);- if (ix < 0) continue;- const int ti = ix + delta;- if (ti < 0 || ti >= static_cast<int>(authoring_->tracks.size())) continue;- const auto& tt = authoring_->tracks[ti];- const bool typeOk = (b.kind == 1) ? (tt->type() == TrackType::Instrument)- : (tt->type() == TrackType::Audio);- if (!typeOk) continue;- BlockClip nb = b;- nb.sameTrack = tt->id() == b.trackId;- nb.trackId = tt->id();- remapped.push_back(std::move(nb));- }- items = std::move(remapped);- if (items.empty()) return 0;- }+ // sourceTrackId >= 0 remaps the whole block onto that track (see remapBlock).+ std::vector<BlockClip> items = sourceTrackId >= 0 ? remapBlock(clipboardBlock_, sourceTrackId) : clipboardBlock_;+ if (items.empty()) return 0;placeBlock(items, atBeat);return static_cast<int32_t>(lastPlaced_.size());}+// Remap a block by the track-index delta from its top track to the destination (so a single+// clip lands on that track; a multi-track block shifts together). Clips that fall off the+// track list or hit a type-mismatched track are skipped; a remapped clip's device/plugin+// automation is dropped (indices are positional).+std::vector<Engine::BlockClip> Engine::remapBlock(const std::vector<BlockClip>& items, int32_t destTrackId) const {+ auto idxOf = [&](int32_t tid) -> int {+ for (size_t i = 0; i < authoring_->tracks.size(); ++i)+ if (authoring_->tracks[i]->id() == tid) return static_cast<int>(i);+ return -1;+ };+ const int destIdx = idxOf(destTrackId);+ int topIdx = std::numeric_limits<int>::max();+ for (const auto& b : items) { int ix = idxOf(b.trackId); if (ix >= 0) topIdx = std::min(topIdx, ix); }+ if (destIdx < 0 || topIdx == std::numeric_limits<int>::max()) return {};+ const int delta = destIdx - topIdx;+ std::vector<BlockClip> remapped;+ for (const auto& b : items) {+ const int ix = idxOf(b.trackId);+ if (ix < 0) continue;+ const int ti = ix + delta;+ if (ti < 0 || ti >= static_cast<int>(authoring_->tracks.size())) continue;+ const auto& tt = authoring_->tracks[ti];+ const bool typeOk = (b.kind == 1) ? (tt->type() == TrackType::Instrument)+ : (tt->type() == TrackType::Audio);+ if (!typeOk) continue;+ BlockClip nb = b;+ nb.sameTrack = tt->id() == b.trackId;+ nb.trackId = tt->id();+ remapped.push_back(std::move(nb));+ }+ return remapped;+}+double Engine::duplicateClipBlock(const std::vector<std::pair<int32_t,int32_t>>& sel) {double len = 0.0;auto items = captureBlock(sel, len);diff --git a/src/native/nota.engine/src/nota_engine_track.cpp b/src/native/nota.engine/src/nota_engine_track.cppindex 60a545e0..d1d79574 100644--- a/src/native/nota.engine/src/nota_engine_track.cpp+++ b/src/native/nota.engine/src/nota_engine_track.cpp@@ -449,6 +449,15 @@ double nota_clips_block_duplicate(NotaEngine* e, const int32_t* track_ids, constint32_t nota_clips_block_count(NotaEngine* e) {return e ? CENG(e)->clipboardBlockCount() : 0;}+int32_t nota_clips_to_session(NotaEngine* e, const int32_t* track_ids, const int32_t* clip_indices, int32_t n, int32_t start_scene) {+ return e ? ENG(e)->arrangementClipsToSession(makeSel(track_ids, clip_indices, n), start_scene) : -1;+}+int32_t nota_clips_block_paste_to_session(NotaEngine* e, int32_t dest_track_id, int32_t start_scene) {+ return e ? ENG(e)->pasteClipBlockToSession(dest_track_id, start_scene) : -1;+}+int32_t nota_session_slots_to_arrangement(NotaEngine* e, const int32_t* track_ids, const int32_t* scenes, int32_t n, double at_beat, int32_t dest_track_id) {+ return e ? ENG(e)->sessionSlotsToArrangement(makeSel(track_ids, scenes, n), at_beat, dest_track_id) : 0;+}// Writes the last block paste/duplicate's placed clips into out_track_ids/out_clip_indices// (up to cap pairs) and returns the total count produced.int32_t nota_clips_last_placed(NotaEngine* e, int32_t* out_track_ids, int32_t* out_clip_indices, int32_t cap) {diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex 0ccf2ed5..82c49068 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -8080,6 +8080,56 @@ engine.StopTransport();e.StopAllSession(); e.StopTransport();}+// -- Arrangement <-> Session: whole selections and the cross-view clipboard --+{+ Console.WriteLine("-- arrangement <-> session: selections --");+ using var e = new NotaEngine();+ e.SetBpm(120);+ int ma = e.AddInstrumentTrack(), mb = e.AddInstrumentTrack(), au = e.AddAudioTrack();+ int a0 = e.AddMidiClip(ma, 0.0, 4.0), a1 = e.AddMidiClip(ma, 8.0, 2.0), b0 = e.AddMidiClip(mb, 4.0, 4.0);+ e.SetClipNotes(ma, a1, new[] { new NotaNote(62, 0.5, 1.0, 0.8f) });+ e.SetClipName(ma, a1, "Hook");+ int ac = e.AddAudioClip(au, wav, 0.0);+ int scenes = e.SceneCount;+ var sel = new[] { (ma, a1), (ma, a0), (mb, b0), (au, ac) };++ int row = e.ArrangementClipsToSession(sel);+ Check(row == 0 && e.SessionSlotState(ma, 0) == 1 && e.SessionSlotState(ma, 1) == 1+ && e.SessionSlotState(mb, 0) == 1 && e.SessionSlotState(au, 0) == 1 && e.SessionSlotState(mb, 1) == 0,+ "a selection lands in one scene row, each track's clips down its column");+ Check(e.GetSessionNotes(ma, 1).Length == 1 && e.GetSessionClipName(ma, 1) == "Hook"+ && Math.Abs(e.SessionSlotLength(ma, 1) - 2.0) < 1e-9, "clips fill slots in time order with notes, name and length");++ int row2 = e.ArrangementClipsToSession(sel);+ Check(row2 == 2, $"the next copy takes the first row where it all fits (row={row2})");+ e.Undo();+ Check(e.SessionSlotState(ma, 2) == 0 && e.SessionSlotState(au, 2) == 0 && e.SessionSlotState(ma, 0) == 1,+ "a selection copy is one undo step");++ int far = e.ArrangementClipsToSession(new[] { (ma, a0), (ma, a1) }, scenes - 1);+ Check(far == scenes - 1 && e.SceneCount == scenes + 1 && e.SessionSlotState(ma, scenes) == 1,+ "copying past the last scene appends rows");++ Check(e.CutClipBlock(new[] { (mb, b0) }), "cut an arrangement clip");+ Check(e.PasteClipBlockToSession(ma, 3) == 3 && e.SessionSlotState(ma, 3) == 1,+ "a cut arrangement clip pastes into a session slot (remapped onto the chosen track)");+ Check(e.PasteClipBlockToSession(au, 3) == -1 && e.SessionSlotState(au, 3) == 0,+ "MIDI does not paste onto an audio track");++ int placed = e.SessionSlotsToArrangement(new[] { (ma, 0), (mb, 0), (au, 0) }, 0.0);+ var pl = e.LastPlacedClips();+ var starts = pl.Select(p => e.TryGetClipInfo(p.trackId, p.clipIndex, out var ci) ? ci.StartBeat : -1).ToArray();+ Check(placed == 3 && starts.All(x => Math.Abs(x - starts[0]) < 1e-9) && starts[0] >= 4.0 - 1e-9,+ $"a scene lands on the timeline together, after the clips it would cover (at {starts.FirstOrDefault()})");+ var maPlaced = pl.First(p => p.trackId == ma);+ Check(e.GetClipNotes(ma, maPlaced.clipIndex).Length == e.GetSessionNotes(ma, 0).Length, "slot -> arrangement carries the notes");++ Check(e.SessionSlotsToArrangement(new[] { (ma, 1), (ma, 0) }, 100.0) == 2, "two slots of one track copied");+ var seq = e.LastPlacedClips().Select(p => e.TryGetClipInfo(p.trackId, p.clipIndex, out var ci) ? ci.StartBeat : -1).ToArray();+ Check(seq.Length == 2 && Math.Abs(seq[0] - 100) < 1e-9 && Math.Abs(seq[1] - 104) < 1e-9,+ $"one track's slots land back to back in scene order ({string.Join(", ", seq)})");+}+// -- Session audio slot gain (slot editor) --{using var e = new NotaEngine();