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) Add hotkeys for tracks
Egor Khindikaynenf10de553cc61
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 59b46ce5..ee385e90 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,8 +22,17 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.outlined). Dropping an instrument there replaces the track's instrument. Either way it isone undo step.- Effects and presets can be dropped on a return track or the master in the arrangement.+- Work with several tracks at once. ⇧-click track headers to select them (⇧-click again to+ deselect), or click the headers and press ⌘A to select every track. With the headers in+ focus, ⌘C / ⌘X / ⌘V / ⌘D and Delete copy, cut, paste, duplicate and delete the selected+ tracks. Right-clicking a selection opens a menu for the whole set: group, colour, freeze,+ copy, cut, paste, duplicate and delete. Each command is one undo step.### Changed+- "Add track" in a track's right-click menu puts the new track right after that track. On a+ group it adds the track inside the group.+- Copying, duplicating or deleting a group now includes its tracks. Pasted tracks go after+ the selected track, in its group.- The first time you switch to automation mode, each track that already has automationshows its first automated parameter instead of Volume.- While dragging from the browser over the arrangement, the target track is outlined in itsdiff --git a/src/managed/Nota.App/ArrangementView.Groups.cs b/src/managed/Nota.App/ArrangementView.Groups.csindex cfeee778..0b8d0bfb 100644--- a/src/managed/Nota.App/ArrangementView.Groups.cs+++ b/src/managed/Nota.App/ArrangementView.Groups.cs@@ -4,7 +4,8 @@// Arrangement · track groups (submix buses). A Group track owns child tracks and its own// device chain; groups may nest. This file holds the view-side glue: the hierarchical row// ordering (DFS over the groupId forest, collapse-filtered), collapse state, the multi-track-// selection used to form a group, and the create/ungroup commands.+// selection (grouping + the track commands in ArrangementView.Tracks.cs), and the+// create/ungroup commands.using System.Collections.Generic;using System.Linq;@@ -15,8 +16,8 @@ public sealed partial class ArrangementView{// Collapsed group ids (subtree hidden in the arrangement). View state; persisted per project.private readonly HashSet<int> _collapsed = new();- // Multi-track selection used for "Group" (Ctrl/Cmd-click headers). The primary SelTrackId- // is treated as part of the set even when this is empty.+ // Multi-track header selection (Shift/Cmd-click, Cmd+A). The primary SelTrackId is treated+ // as part of the set even when this is empty; any other Select() clears it.private readonly HashSet<int> _selTracks = new();internal IReadOnlyCollection<int> CollapsedGroups => _collapsed;@@ -98,15 +99,20 @@ public sealed partial class ArrangementViewRefresh();}- // ---- multi-track selection (for grouping) -----------------------------+ // ---- multi-track selection (Shift/Cmd-click headers, Cmd+A) --------------private bool IsTrackMultiSelected(int trackId) => _selTracks.Contains(trackId) || trackId == SelTrackId;private void ToggleTrackInSelection(int trackId){- // Seed the set with the current primary so Ctrl-click extends rather than replaces.- if (_selTracks.Count == 0 && SelTrackId > 0) _selTracks.Add(SelTrackId);- if (!_selTracks.Remove(trackId)) _selTracks.Add(trackId);- Select(trackId, -1); // make it primary + show its devices+ // Seed the set with the current primary so the click extends rather than replaces.+ if (_selTracks.Count == 0 && _tracks.Any(t => t.Id == SelTrackId)) _selTracks.Add(SelTrackId);+ if (_selTracks.Add(trackId)) { Select(trackId, -1, keepTrackSet: true); return; } // make it primary + show its devices++ // Second click removes it; the primary (device panel) moves to another member, if any.+ _selTracks.Remove(trackId);+ int next = _tracks.FirstOrDefault(t => _selTracks.Contains(t.Id))?.Id ?? -1;+ if (next > 0) Select(next, -1, keepTrackSet: true);+ else Select(-1, -1);}private void ClearTrackMultiSelection() => _selTracks.Clear();diff --git a/src/managed/Nota.App/ArrangementView.Tracks.cs b/src/managed/Nota.App/ArrangementView.Tracks.csnew file mode 100644index 00000000..39b0f49b--- /dev/null+++ b/src/managed/Nota.App/ArrangementView.Tracks.cs@@ -0,0 +1,213 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// Arrangement · track commands on the header selection: select all, copy / cut / paste,+// duplicate, delete (keys while the track headers have focus, and the header menus), the+// multi-track context menu, and where a context-menu "Add track" lands. The engine expands+// a set with every descendant of a group in it, so a group always travels with its children,+// and each command is a single undo step.++using System;+using System.Collections.Generic;+using System.Linq;+using Avalonia;+using Avalonia.Controls;+using Avalonia.Input;+using Avalonia.VisualTree;+using Nota.Application;++namespace Nota.App;++public sealed partial class ArrangementView+{+ /// <summary>The selected tracks (multi-selection + primary) in row order. Returns and the+ /// master live in the footer, not in the rows, so they never take part.</summary>+ internal List<int> SelectedTrackIds()+ => _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>+ internal bool IsInTrackHeaders(PointerEventArgs e)+ {+ if (e.Source is not Visual v || !v.GetSelfAndVisualAncestors().Contains(_scroller)) return false;+ double x = e.GetPosition(_headers).X;+ return x >= 0 && x < HeaderW;+ }++ // Select exactly these tracks; the first becomes the primary (device panel).+ private void SetTrackSelection(IReadOnlyList<int> ids)+ {+ var shown = ids.Where(id => _tracks.Any(t => t.Id == id)).ToList();+ if (shown.Count == 0) { Select(-1, -1); return; }+ Select(shown[0], -1);+ if (shown.Count > 1) foreach (var id in shown) _selTracks.Add(id);+ UpdateHeaderSelection();+ }++ // After a structural edit (and the Refresh): let the session grid + device panel follow.+ private void AfterTrackEdit()+ {+ SessionChanged?.Invoke();+ TrackSelected?.Invoke(SelTrackId);+ }++ // Select the pasted/duplicated set by its top-level members (their children come along).+ private void SelectNewTracks(int[] newIds)+ {+ var set = new HashSet<int>(newIds);+ SetTrackSelection(_tracks.Where(t => set.Contains(t.Id) && !set.Contains(t.GroupId)).Select(t => t.Id).ToList());+ }++ // ---- commands (keys: Cmd+A / C / X / V / D, Delete; header menus) ------+ /// <summary>Cmd+A over the track headers — select every track row.</summary>+ public bool SelectAllTracks()+ {+ if (_tracks.Count == 0) return false;+ var ids = _tracks.Select(t => t.Id).ToList();+ // Keep the current primary (and its device panel) when it's a row.+ int primary = ids.Contains(SelTrackId) ? SelTrackId : ids[0];+ ids.Remove(primary);+ ids.Insert(0, primary);+ SetTrackSelection(ids);+ return true;+ }++ public bool CopySelectedTracks()+ {+ var ids = SelectedTrackIds();+ return ids.Count > 0 && _engine is not null && _engine.CopyTracks(ids.ToArray());+ }++ public bool CutSelectedTracks() => CutTracks(SelectedTrackIds());++ /// <summary>Pastes the copied tracks after the last selected one (in its group), or at+ /// the end when nothing is selected.</summary>+ public bool PasteTracks()+ {+ var ids = SelectedTrackIds();+ return PasteTracksAfter(ids.Count > 0 ? ids[^1] : -1);+ }++ public bool DuplicateSelectedTracks() => DuplicateTracks(SelectedTrackIds());++ public bool DeleteSelectedTracks() => DeleteTracks(SelectedTrackIds());++ private bool CutTracks(IReadOnlyList<int> ids)+ {+ if (_engine is null || ids.Count == 0 || !_engine.CopyTracks(ids.ToArray())) return false;+ return DeleteTracks(ids);+ }++ private bool PasteTracksAfter(int anchorTrackId)+ {+ if (_engine is null || !_engine.HasTrackClipboard()) return false;+ var newIds = _engine.PasteTracks(anchorTrackId);+ if (newIds.Length == 0) return false;+ Refresh();+ SelectNewTracks(newIds);+ AfterTrackEdit();+ return true;+ }++ private bool DuplicateTracks(IReadOnlyList<int> ids)+ {+ if (_engine is null || ids.Count == 0) return false;+ var newIds = _engine.DuplicateTracks(ids.ToArray());+ if (newIds.Length == 0) return false;+ Refresh();+ SelectNewTracks(newIds);+ AfterTrackEdit();+ return true;+ }++ private bool DeleteTracks(IReadOnlyList<int> ids)+ {+ if (_engine is null || ids.Count == 0 || !_engine.RemoveTracks(ids.ToArray())) return false;+ Refresh();+ // Drop what went with them (a group takes its children); a surviving primary stays.+ bool Alive(int id) => _tracks.Any(t => t.Id == id) || _returns.Any(t => t.Id == id);+ if (!Alive(SelTrackId)) Select(-1, -1);+ else { _selTracks.RemoveWhere(id => !Alive(id)); UpdateHeaderSelection(); }+ AfterTrackEdit();+ return true;+ }++ // ---- "Add track" placement ---------------------------------------------+ /// <summary>Moves a freshly added (appended) track next to the row its context menu was+ /// opened on: right after a track, in that track's group; for a group, into it as its+ /// last child. No-op without an anchor row. Call inside the caller's undo group.</summary>+ internal void PlaceNewTrack(int newTrackId, int anchorTrackId)+ {+ if (_engine is null || anchorTrackId <= 0) return;+ var anchor = _tracks.FirstOrDefault(t => t.Id == anchorTrackId);+ if (anchor is null) return; // a return / the master: new tracks stay at the end+ int parent = anchor.IsGroup ? anchor.Id : anchor.GroupId;+ int after = anchor.IsGroup ? LastDescendantOf(anchor.Id) : anchor.Id;+ if (parent >= 0) _engine.SetTrackGroup(newTrackId, parent);+ // The new track is the last regular one, so every other index is unaffected by its+ // removal inside MoveTrack: after's index + 1 is the slot right behind it.+ int idx = RegularIndexOf(after);+ if (idx >= 0) _engine.MoveTrack(newTrackId, idx + 1);+ }++ // The group's last descendant in engine order (collapsed children included), or the+ // group itself when it's empty — the new child goes behind it to become the last one.+ private int LastDescendantOf(int groupId)+ {+ if (_engine is null) return groupId;+ var parents = new Dictionary<int, int>();+ var order = new List<int>();+ for (int i = 0; i < _engine.TrackCount; i++)+ {+ if (!_engine.TryGetTrackInfo(i, out var ti) || ti.IsReturn) continue;+ parents[ti.Id] = ti.GroupId;+ order.Add(ti.Id);+ }+ bool Inside(int id)+ {+ for (int a = parents.GetValueOrDefault(id, -1), hops = 0; a >= 0 && hops < 64; hops++)+ {+ if (a == groupId) return true;+ a = parents.GetValueOrDefault(a, -1);+ }+ return false;+ }+ int last = groupId;+ foreach (var id in order) if (Inside(id)) last = id;+ return last;+ }++ // ---- multi-track context menu ------------------------------------------+ private void ShowTracksMenu(Control anchor, List<int> ids)+ {+ if (_engine is null) return;+ var flyout = new MenuFlyout();+ string n = $"{ids.Count} tracks";++ var group = MenuKit.Item($"Group {n}", GlyphKind.Folder, () => GroupTracks(-1), MenuKit.GroupKey);+ var color = BuildColorSubmenu(ids);+ var freeze = FreezeTracksMenuItems?.Invoke(ids) ?? Array.Empty<Control>();+ var copy = MenuKit.Item($"Copy {n}", GlyphKind.Copy, () => _engine.CopyTracks(ids.ToArray()), MenuKit.CopyKey);+ var cut = MenuKit.Item($"Cut {n}", GlyphKind.Cut, () => CutTracks(ids), MenuKit.CutKey);+ var paste = MenuKit.Item("Paste track", GlyphKind.Paste, () => PasteTracksAfter(ids[^1]), MenuKit.PasteKey,+ enabled: _engine.HasTrackClipboard());+ var dup = MenuKit.Item($"Duplicate {n}", GlyphKind.Duplicate, () => DuplicateTracks(ids), MenuKit.DuplicateKey);+ var del = MenuKit.Item($"Delete {n}", GlyphKind.Trash, () => DeleteTracks(ids), MenuKit.DeleteKey);++ flyout.Items.Add(group);+ flyout.Items.Add(color);+ if (freeze.Count > 0)+ {+ flyout.Items.Add(new Separator());+ foreach (var item in freeze) flyout.Items.Add(item);+ }+ flyout.Items.Add(new Separator());+ flyout.Items.Add(copy);+ flyout.Items.Add(cut);+ flyout.Items.Add(paste);+ flyout.Items.Add(dup);+ flyout.Items.Add(new Separator());+ flyout.Items.Add(del);+ flyout.ShowAt(anchor, showAtPointer: true);+ }+}diff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.csindex 239136a7..fc5668b9 100644--- a/src/managed/Nota.App/ArrangementView.cs+++ b/src/managed/Nota.App/ArrangementView.cs@@ -203,6 +203,8 @@ public sealed partial class ArrangementView : UserControl/// <summary>Freeze / Live Freeze entries for a track's context menu (empty when the track/// can't be frozen). Built by MainWindow, which owns the freeze state and commands.</summary>public Func<int, IReadOnlyList<Control>>? FreezeMenuItems;+ /// <summary>Freeze entries for the multi-track context menu (the selected ids, row order).</summary>+ public Func<IReadOnlyList<int>, IReadOnlyList<Control>>? FreezeTracksMenuItems;/// <summary>Called at the start of a full <see cref="Refresh"/>, before the track model is/// rebuilt — MainWindow drops live-freeze links whose tracks were deleted or undone.</summary>public Action? RefreshStarting;@@ -217,8 +219,10 @@ public sealed partial class ArrangementView : UserControlpublic event Action<int, int, ClipConvertMode>? ConvertClipRequested;/// <summary>A context menu asked for a new track. MainWindow owns creation — the seed/// MIDI clip, the session / modular / device-chain refreshes and the status line — so the- /// menu only asks, and the toolbar's + buttons and these entries stay one behaviour.</summary>- public event Action<NewTrackKind>? AddTrackRequested;+ /// menu only asks, and the toolbar's + buttons and these entries stay one behaviour.+ /// The id is the track the menu was opened on (-1 = none): the new track lands after it,+ /// or inside it for a group (see <see cref="PlaceNewTrack"/>).</summary>+ public event Action<NewTrackKind, int>? AddTrackRequested;/// <summary>Raised after a clip's start/length changed in place (edge-drag trim or/// stretch): track id, clip index. An open clip editor re-reads its geometry from this.</summary>public event Action<int, int>? ClipGeometryChanged;@@ -1082,9 +1086,10 @@ public sealed partial class ArrangementView : UserControlItemDropped?.Invoke(items[i], i == 0 ? trackId : -1, beat);e.Handled = true;}- internal void Select(int trackId, int clipIndex)+ internal void Select(int trackId, int clipIndex, bool keepTrackSet = false){if (HasTimeSelection) ClearTimeSelection(); // clip- and time-selection are exclusive (1.2.5)+ if (!keepTrackSet) _selTracks.Clear(); // any other selection resets the header multi-selectionint prev = SelTrackId;SelTrackId = trackId;SelClipIndex = clipIndex;@@ -1757,9 +1762,9 @@ public sealed partial class ArrangementView : UserControltry { _engine?.OpenPluginEditor(t.Id, -1); } catch { /* builtin/no editor: no-op */ }return;}- // Ctrl/Cmd-click extends the multi-track selection (used to form a group).+ // Shift- (or Ctrl/Cmd-) click adds the track to the multi-selection; again removes it.if (e.GetCurrentPoint(card).Properties.IsLeftButtonPressed- && (e.KeyModifiers & (KeyModifiers.Control | KeyModifiers.Meta)) != 0)+ && (e.KeyModifiers & (KeyModifiers.Shift | KeyModifiers.Control | KeyModifiers.Meta)) != 0){ToggleTrackInSelection(t.Id); e.Handled = true; return;}@@ -1817,10 +1822,10 @@ public sealed partial class ArrangementView : UserControl// "Add …" entries shared by the arrangement's track-level menus. Return is left enabled// when the buses are full, like the toolbar's + Return — MainWindow says so in the status// line rather than the menu going quietly dead.- private IEnumerable<MenuItem> AddTrackItems()+ private IEnumerable<MenuItem> AddTrackItems(int anchorTrackId = -1){MenuItem Item(string header, NewTrackKind kind)- => MenuKit.Item(header, GlyphKind.Plus, () => AddTrackRequested?.Invoke(kind));+ => MenuKit.Item(header, GlyphKind.Plus, () => AddTrackRequested?.Invoke(kind, anchorTrackId));yield return Item("Add instrument track", NewTrackKind.Instrument);yield return Item("Add audio track", NewTrackKind.Audio);yield return Item("Add return track", NewTrackKind.Return);@@ -1834,15 +1839,8 @@ public sealed partial class ArrangementView : UserControlvar flyout = new MenuFlyout();foreach (var mi in AddTrackItems()) flyout.Items.Add(mi);flyout.Items.Add(new Separator());- var paste = new MenuItem { Header = "Paste track", IsEnabled = _engine.HasTrackClipboard(), Icon = MenuKit.Icon(GlyphKind.Paste) };- paste.Click += (_, _) =>- {- int nid = _engine.PasteTrack();- if (nid > 0) Select(nid, -1);- Refresh();- SessionChanged?.Invoke();- TrackSelected?.Invoke(SelTrackId);- };+ var paste = new MenuItem { Header = "Paste track", IsEnabled = _engine.HasTrackClipboard(), Icon = MenuKit.Icon(GlyphKind.Paste), InputGesture = MenuKit.PasteKey };+ paste.Click += (_, _) => PasteTracksAfter(-1);flyout.Items.Add(paste);flyout.ShowAt(anchor, showAtPointer: true);}@@ -1850,15 +1848,18 @@ public sealed partial class ArrangementView : UserControlprivate void ShowTrackMenu(Control anchor, int trackId){if (_engine is null) return;+ // Right-click inside a multi-selection acts on the whole set.+ var selected = SelectedTrackIds();+ if (selected.Count > 1 && selected.Contains(trackId)) { ShowTracksMenu(anchor, selected); return; }var flyout = new MenuFlyout();var rename = new MenuItem { Header = "Rename…", Icon = MenuKit.Icon(GlyphKind.Edit) };rename.Click += (_, _) => PromptRenameTrack(anchor, trackId);- var color = BuildColorSubmenu(trackId);+ var color = BuildColorSubmenu(new[] { trackId });// Record input ▸ (audio tracks only): hardware, master, or another track's output// (internal resampling). The active source is ticked.- bool isAudio = _tracks.Any(v => v.Id == trackId && !v.IsInstrument && !v.IsReturn);+ bool isAudio = _tracks.Any(v => v.Id == trackId && !v.IsInstrument && !v.IsReturn && !v.IsGroup);MenuItem? recInput = null;if (isAudio){@@ -1901,42 +1902,20 @@ public sealed partial class ArrangementView : UserControlmidiFrom.Items.Add(Src(v.Name.Length > 0 ? v.Name : $"Track {v.Id}", v.Id));}- var copy = new MenuItem { Header = "Copy track", Icon = MenuKit.Icon(GlyphKind.Copy) };- copy.Click += (_, _) => _engine.CopyTrack(trackId);- var cut = new MenuItem { Header = "Cut track", Icon = MenuKit.Icon(GlyphKind.Cut) };- cut.Click += (_, _) =>- {- if (!_engine.CopyTrack(trackId)) return;- _engine.RemoveTrack(trackId);- if (SelTrackId == trackId) SelTrackId = -1;- Refresh(); SessionChanged?.Invoke(); TrackSelected?.Invoke(SelTrackId);- };- var paste = new MenuItem { Header = "Paste track", IsEnabled = _engine.HasTrackClipboard(), Icon = MenuKit.Icon(GlyphKind.Paste) };- paste.Click += (_, _) =>- {- int nid = _engine.PasteTrack();- if (nid > 0) Select(nid, -1);- Refresh(); SessionChanged?.Invoke(); TrackSelected?.Invoke(SelTrackId);- };-- var dup = new MenuItem { Header = "Duplicate track", Icon = MenuKit.Icon(GlyphKind.Duplicate) };- dup.Click += (_, _) =>- {- int nid = _engine.DuplicateTrack(trackId);- if (nid > 0) Select(nid, -1);- Refresh();- SessionChanged?.Invoke();- TrackSelected?.Invoke(SelTrackId);- };- var del = new MenuItem { Header = "Delete track", Icon = MenuKit.Icon(GlyphKind.Trash) };- del.Click += (_, _) =>- {- _engine.RemoveTrack(trackId);- if (SelTrackId == trackId) SelTrackId = -1;- Refresh();- SessionChanged?.Invoke();- TrackSelected?.Invoke(SelTrackId);- };+ // Clipboard + lifecycle go through the same set commands as the keys (a group carries+ // its children); paste lands right after this track.+ var one = new[] { trackId };+ var copy = new MenuItem { Header = "Copy track", Icon = MenuKit.Icon(GlyphKind.Copy), InputGesture = MenuKit.CopyKey };+ copy.Click += (_, _) => _engine.CopyTracks(one);+ var cut = new MenuItem { Header = "Cut track", Icon = MenuKit.Icon(GlyphKind.Cut), InputGesture = MenuKit.CutKey };+ cut.Click += (_, _) => CutTracks(one);+ var paste = new MenuItem { Header = "Paste track", IsEnabled = _engine.HasTrackClipboard(), Icon = MenuKit.Icon(GlyphKind.Paste), InputGesture = MenuKit.PasteKey };+ paste.Click += (_, _) => PasteTracksAfter(trackId);++ var dup = new MenuItem { Header = "Duplicate track", Icon = MenuKit.Icon(GlyphKind.Duplicate), InputGesture = MenuKit.DuplicateKey };+ dup.Click += (_, _) => DuplicateTracks(one);+ var del = new MenuItem { Header = "Delete track", Icon = MenuKit.Icon(GlyphKind.Trash), InputGesture = MenuKit.DeleteKey };+ del.Click += (_, _) => DeleteTracks(one);// Group / Ungroup (submix). "Group" folds the multi-selection (or this track) into a// new group; "Ungroup" dissolves the group this track is/belongs to.@@ -1966,7 +1945,7 @@ public sealed partial class ArrangementView : UserControlflyout.Items.Add(group);if (ungroup is not null) flyout.Items.Add(ungroup);var addTrack = new MenuItem { Header = "Add track", Icon = MenuKit.Icon(GlyphKind.Plus) }; // submenu: this menu is long already- foreach (var mi in AddTrackItems()) addTrack.Items.Add(mi);+ foreach (var mi in AddTrackItems(trackId)) addTrack.Items.Add(mi);flyout.Items.Add(new Separator());flyout.Items.Add(addTrack);@@ -2109,9 +2088,17 @@ public sealed partial class ArrangementView : UserControl}// Colour ▸ one submenu per base hue, each with normal / light / dark shades shown as- // swatches, plus Auto. Picking sets the track's stored palette index.- private MenuItem BuildColorSubmenu(int trackId)+ // swatches, plus Auto. Picking sets the stored palette index of every given track.+ private MenuItem BuildColorSubmenu(IReadOnlyList<int> trackIds){+ void SetColor(int ci)+ {+ if (_engine is null) return;+ _engine.BeginUndoGroup();+ try { foreach (var id in trackIds) _engine.SetTrackColorIndex(id, ci); }+ finally { _engine.EndUndoGroup(); }+ Refresh(); SessionChanged?.Invoke();+ }var color = new MenuItem { Header = "Color", Icon = MenuKit.Icon(GlyphKind.Palette) };for (int b = 0; b < PaletteBases; b++){@@ -2120,13 +2107,13 @@ public sealed partial class ArrangementView : UserControl{int ci = b * PaletteShades + s;var shade = new MenuItem { Header = TrackColorNames[b] + ShadeNames[s], Icon = Swatch(ci) };- shade.Click += (_, _) => { _engine?.SetTrackColorIndex(trackId, ci); Refresh(); SessionChanged?.Invoke(); };+ shade.Click += (_, _) => SetColor(ci);baseItem.Items.Add(shade);}color.Items.Add(baseItem);}var autoColor = new MenuItem { Header = "Auto" };- autoColor.Click += (_, _) => { _engine?.SetTrackColorIndex(trackId, -1); Refresh(); SessionChanged?.Invoke(); };+ autoColor.Click += (_, _) => SetColor(-1);color.Items.Add(new Separator());color.Items.Add(autoColor);return color;@@ -2292,7 +2279,7 @@ public sealed partial class ArrangementView : UserControlvar rename = new MenuItem { Header = "Rename…", Icon = MenuKit.Icon(GlyphKind.Edit) };rename.Click += (_, _) => PromptRenameTrack(anchor, trackId);flyout.Items.Add(rename);- flyout.Items.Add(BuildColorSubmenu(trackId));+ flyout.Items.Add(BuildColorSubmenu(new[] { trackId }));flyout.ShowAt(anchor, showAtPointer: true);}diff --git a/src/managed/Nota.App/MainWindow.Freeze.cs b/src/managed/Nota.App/MainWindow.Freeze.csindex 92902ae3..ae8efd5a 100644--- a/src/managed/Nota.App/MainWindow.Freeze.cs+++ b/src/managed/Nota.App/MainWindow.Freeze.cs@@ -11,6 +11,7 @@using System;using System.Collections.Generic;using System.IO;+using System.Linq;using System.Threading.Tasks;using Avalonia.Controls;using Avalonia.Interactivity;@@ -185,6 +186,67 @@ public partial class MainWindowreturn items;}+ // Freeze entries for the multi-track menu: freeze the live tracks / unfreeze the frozen+ // ones among the selection. Live-freeze pairs are per-track, so they're left to each+ // track's own menu, as are returns and groups (never freezable).+ private IReadOnlyList<Control> BuildTracksFreezeMenu(IReadOnlyList<int> trackIds)+ {+ var items = new List<Control>();+ var plain = trackIds.Where(id => IsFreezable(id) && LinkForSource(id) is null && LinkForFrozen(id) is null).ToList();+ var live = plain.Where(id => !Engine.IsTrackFrozen(id)).ToList();+ var frozen = plain.Where(id => Engine.IsTrackFrozen(id)).ToList();+ if (live.Count > 0)+ items.Add(FreezeMenuItem(live.Count == 1 ? "Freeze track" : $"Freeze {live.Count} tracks", SnowflakeIcon(),+ () => FreezeTracksAsync(live)));+ if (frozen.Count > 0)+ items.Add(FreezeMenuItem(frozen.Count == 1 ? "Unfreeze track" : $"Unfreeze {frozen.Count} tracks", SnowflakeIcon(),+ () => UnfreezeTracks(frozen)));+ return items;+ }++ // Freeze several tracks behind one progress dialog (each bounce takes over the engine).+ private async Task FreezeTracksAsync(IReadOnlyList<int> trackIds)+ {+ if (_vm is null || trackIds.Count == 0) return;+ double endBeats = ProjectEndBeats();+ if (endBeats <= 0.0) { _vm.StatusText = "Nothing to freeze — the arrangement is empty."; return; }++ _vm.SuspendEnginePolling = true;+ int done = 0;+ try+ {+ await RunBlockingAsync("Freeze", "Freezing tracks…", async prog =>+ {+ for (int i = 0; i < trackIds.Count; i++)+ {+ int k = i;+ var frac = new Progress<double>(f =>+ {+ double all = (k + f) / trackIds.Count;+ prog.Report(ProgressReport.At(all, $"Freezing track {k + 1} of {trackIds.Count}… {all * 100:0}\u2009%"));+ });+ if (await Task.Run(() => _freezer.Freeze(Engine, trackIds[k], endBeats,+ _vm.Transport.LoopOn, _vm.Transport.MetronomeOn, frac)))+ done++;+ }+ });+ _vm.StatusText = done == trackIds.Count+ ? $"{done} tracks frozen — their devices are idle until you unfreeze."+ : $"Froze {done} of {trackIds.Count} tracks.";+ }+ catch (Exception ex) { _vm.StatusText = $"Freeze failed: {ex.Message}"; }+ finally { _vm.SuspendEnginePolling = false; }++ AfterFreezeChange();+ }++ private void UnfreezeTracks(IReadOnlyList<int> trackIds)+ {+ foreach (var id in trackIds) Engine.UnfreezeTrack(id);+ if (_vm is not null) _vm.StatusText = trackIds.Count == 1 ? "Track unfrozen." : $"{trackIds.Count} tracks unfrozen.";+ AfterFreezeChange();+ }+private static MenuItem FreezeMenuItem(string header, Control? icon, Action run){var mi = new MenuItem { Header = header, Icon = icon };diff --git a/src/managed/Nota.App/MainWindow.Input.cs b/src/managed/Nota.App/MainWindow.Input.csindex 5237e4a7..d5138a69 100644--- a/src/managed/Nota.App/MainWindow.Input.cs+++ b/src/managed/Nota.App/MainWindow.Input.cs@@ -105,6 +105,15 @@ public partial class MainWindowreturn;}+ // Track headers focused (the last click landed in the header column): ⌘A selects every+ // track, ⌘C/X/V/D copy/cut/paste/duplicate the selected tracks, Delete removes them.+ // Anything with nothing to act on falls through to the clip handling below.+ if (_trackHeadersFocused && Timeline.IsVisible && HandleTrackKey(e))+ {+ e.Handled = true;+ return;+ }+// ⌘/⌃ + ⇧ + A: toggle Automation mode. ⌘/⌃ + A: select all arrangement clips —// gated to when the piano-roll grid isn't focused, where ⌘A instead selects all notes.if (mod && e.Key == Key.A && (e.KeyModifiers & KeyModifiers.Alt) == 0)@@ -243,6 +252,35 @@ public partial class MainWindowelse base.OnKeyDown(e);}+ // Track-header keys (see HandleKeyDown). True when the key acted on tracks.+ private bool HandleTrackKey(KeyEventArgs e)+ {+ if (_vm is null) return false;+ bool extra = (e.KeyModifiers & (KeyModifiers.Alt | KeyModifiers.Shift)) != 0;+ if (ArrangementView.IsPrimaryDown(e.KeyModifiers) && !extra)+ {+ switch (e.Key)+ {+ case Key.A: return Timeline.SelectAllTracks();+ case Key.C: return Report(Timeline.CopySelectedTracks(), "Copied track(s)");+ case Key.X: return Report(Timeline.CutSelectedTracks(), "Cut track(s)");+ case Key.V: return Report(Timeline.PasteTracks(), "Pasted track(s)");+ // macOS: the Edit menu's ⌘D accelerator gets there first (OnMenuDuplicate).+ case Key.D when !OperatingSystem.IsMacOS(): return Report(Timeline.DuplicateSelectedTracks(), "Duplicated track(s)");+ }+ return false;+ }+ if (e.KeyModifiers == KeyModifiers.None && (e.Key == Key.Delete || e.Key == Key.Back))+ return Report(Timeline.DeleteSelectedTracks(), "Deleted track(s)");+ return false;++ bool Report(bool done, string status)+ {+ if (done) _vm.StatusText = status;+ return done;+ }+ }+protected override void OnKeyUp(KeyEventArgs e) => HandleKeyUp(e);internal void HandleKeyUp(KeyEventArgs e)diff --git a/src/managed/Nota.App/MainWindow.Menu.cs b/src/managed/Nota.App/MainWindow.Menu.csindex 19f0eb2a..371dafe9 100644--- a/src/managed/Nota.App/MainWindow.Menu.cs+++ b/src/managed/Nota.App/MainWindow.Menu.cs@@ -77,6 +77,8 @@ public partial class MainWindow_vm.StatusText = "Duplicated notes";return;}+ // Track headers focused: duplicate the selected tracks.+ if (_trackHeadersFocused && Timeline.DuplicateSelectedTracks()) { _vm.StatusText = "Duplicated track(s)"; return; }// In automation mode a selected range duplicates the envelope slice (chains on repeat).if (Timeline.AutomationMode && Timeline.DuplicateAutoSelection()) { _vm.StatusText = "Duplicated automation"; return; }// A time-range selection duplicates the covered slice (chains on repeat) before clips.@@ -121,24 +123,28 @@ public partial class MainWindowprivate void OnMenuCopy(object? sender, EventArgs e){if (_vm is null) return;+ if (_trackHeadersFocused && Timeline.CopySelectedTracks()) { _vm.StatusText = "Copied track(s)"; return; }if (ActiveRoll() is { } roll && roll.CopySelection()) { _vm.StatusText = "Copied notes"; return; }if (Timeline.CopySelectedClip()) _vm.StatusText = "Copied clip";}private void OnMenuCut(object? sender, EventArgs e){if (_vm is null) return;+ if (_trackHeadersFocused && Timeline.CutSelectedTracks()) { _vm.StatusText = "Cut track(s)"; return; }if (ActiveRoll() is { } roll && roll.CutSelection()) { _vm.StatusText = "Cut notes"; return; }if (Timeline.CutSelectedClip()) { _session?.Refresh(); _vm.StatusText = "Cut clip"; }}private void OnMenuPaste(object? sender, EventArgs e){if (_vm is null) return;+ if (_trackHeadersFocused && Timeline.PasteTracks()) { _vm.StatusText = "Pasted track(s)"; return; }if (ActiveRoll() is { } roll && roll.PasteClipboard()) { _vm.StatusText = "Pasted notes"; return; }if (Timeline.PasteClipboard()) { _session?.Refresh(); _vm.StatusText = "Pasted clip"; }}private void OnMenuDeleteSel(object? sender, EventArgs e){if (_vm is null) return;+ if (_trackHeadersFocused && Timeline.DeleteSelectedTracks()) { _vm.StatusText = "Deleted track(s)"; return; }if (ActiveRoll() is { } roll && roll.DeleteSelection()) { _vm.StatusText = "Deleted notes"; return; }if (Timeline.DeleteSelectedClips()) { _session?.Refresh(); _vm.StatusText = "Deleted clip(s)"; }}diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.csindex 313dc81a..89e95fed 100644--- a/src/managed/Nota.App/MainWindow.axaml.cs+++ b/src/managed/Nota.App/MainWindow.axaml.cs@@ -76,6 +76,7 @@ public partial class MainWindow : Window// True while the detail panel (Devices/Clip) was the last area the user interacted// with — Tab then toggles between the two tabs.private bool _detailWasLastFocused;+ private bool _trackHeadersFocused;private IAudioEngine Engine => _vm!.Engine;@@ -169,22 +170,19 @@ public partial class MainWindow : WindowTimeline.Engine = vm.Engine;Timeline.FreezeRole = FreezeRoleOf; // live-freeze (v1.1) header badgesTimeline.FreezeMenuItems = BuildTrackFreezeMenu; // track context menu: Freeze / Live Freeze+ Timeline.FreezeTracksMenuItems = BuildTracksFreezeMenu; // multi-track menu: Freeze / Unfreeze allTimeline.RefreshStarting = PruneFreezeLinks; // drop links to deleted / undone tracksTimeline.MidiClipActivated += OpenClipEditor;Timeline.AudioClipActivated += OpenAudioClipEditor;Timeline.ItemDropped += OnArrangementDrop; // browser drag & drop (M7-5)Timeline.PasteBouncedRequested += (track, beat) => _ = PasteBouncedAsync(track, beat);Timeline.ConvertClipRequested += OnConvertClip; // audio clip → MIDI (Convert / Slice)- // Arrangement context menus add tracks through the toolbar's own handlers, so the two- // routes seed, refresh and report identically.- Timeline.AddTrackRequested += kind =>+ // Arrangement context menus add tracks through the toolbar's own path, so the two+ // routes seed, refresh and report identically; the menu's row places the new track.+ Timeline.AddTrackRequested += (kind, anchor) =>{- switch (kind)- {- case NewTrackKind.Instrument: OnAddInstrumentClicked(this, new RoutedEventArgs()); break;- case NewTrackKind.Audio: OnAddAudioClicked(this, new RoutedEventArgs()); break;- case NewTrackKind.Return: OnAddReturnClicked(this, new RoutedEventArgs()); break;- }+ if (kind == NewTrackKind.Return) OnAddReturnClicked(this, new RoutedEventArgs());+ else AddTrack(kind, anchor);};_masterMeter = new MeterBar(horizontal: true);@@ -353,6 +351,8 @@ public partial class MainWindow : Window{if (e.Source is Visual v)_detailWasLastFocused = DetailPanel.IsVisible && v.GetSelfAndVisualAncestors().Contains(DetailPanel);+ // Likewise the track-header column: while it has focus, Cmd+A/C/X/V/D and Delete act on tracks.+ _trackHeadersFocused = Timeline.IsVisible && Timeline.IsInTrackHeaders(e);}, RoutingStrategies.Tunnel, handledEventsToo: true);// Global transport keys (Space = Play/Stop, Return = Stop) must win over whatever@@ -432,25 +432,31 @@ public partial class MainWindow : Window}- private void OnAddInstrumentClicked(object? sender, RoutedEventArgs e)- {- if (_vm is null) return;- int trackId = Engine.AddInstrumentTrack();- Engine.AddMidiClip(trackId, 0.0, 4.0);- Timeline.Refresh();- _session?.Refresh();- if (_modular?.IsVisible == true) _modular.Refresh(); // new track shows in the graph/sidebar- _vm.StatusText = $"Instrument track {trackId} (synth)";- }+ private void OnAddInstrumentClicked(object? sender, RoutedEventArgs e) => AddTrack(NewTrackKind.Instrument);+ private void OnAddAudioClicked(object? sender, RoutedEventArgs e) => AddTrack(NewTrackKind.Audio);- private void OnAddAudioClicked(object? sender, RoutedEventArgs e)+ // Adds an instrument (with a seed MIDI clip) or audio track. From a track's context menu+ // the new track lands after that row — or inside it, for a group; the toolbar appends.+ // Creation + placement are one undo step.+ private void AddTrack(NewTrackKind kind, int anchorTrackId = -1){if (_vm is null) return;- int trackId = Engine.AddAudioTrack();+ int trackId;+ Engine.BeginUndoGroup();+ try+ {+ trackId = kind == NewTrackKind.Instrument ? Engine.AddInstrumentTrack() : Engine.AddAudioTrack();+ if (kind == NewTrackKind.Instrument) Engine.AddMidiClip(trackId, 0.0, 4.0);+ Timeline.PlaceNewTrack(trackId, anchorTrackId);+ }+ finally { Engine.EndUndoGroup(); }Timeline.Refresh();+ if (anchorTrackId > 0) Timeline.Select(trackId, -1); // show where it landed_session?.Refresh();- if (_modular?.IsVisible == true) _modular.Refresh();- _vm.StatusText = $"Audio track {trackId} — arm it and hit Rec to record input";+ if (_modular?.IsVisible == true) _modular.Refresh(); // new track shows in the graph/sidebar+ _vm.StatusText = kind == NewTrackKind.Instrument+ ? $"Instrument track {trackId} (synth)"+ : $"Audio track {trackId} — arm it and hit Rec to record input";}private void OnAddReturnClicked(object? sender, RoutedEventArgs e)diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.csindex a2cf587f..a05928a2 100644--- a/src/managed/Nota.App/PreferencesWindow.cs+++ b/src/managed/Nota.App/PreferencesWindow.cs@@ -669,6 +669,13 @@ public sealed class PreferencesWindow : NotaWindow("0", "Deactivate / activate the selected clip(s)"),("Delete", "Delete the selected clip / range"),}),+ ("TRACKS (AFTER A CLICK IN THE TRACK HEADERS)", new[]+ {+ ("⌘A", "Select all tracks"),+ ("⌘C ⌘X ⌘V", "Copy / cut / paste the selected tracks · paste lands after the last one"),+ ("⌘D", "Duplicate the selected tracks"),+ ("Delete", "Delete the selected tracks · a group goes with its tracks"),+ }),("PIANO ROLL", new[]{("← →", "Move notes by the grid"),@@ -700,6 +707,8 @@ public sealed class PreferencesWindow : NotaWindow("MOUSE", new[]{("Double-click clip", "Open in the clip editor"),+ ("⇧-click track header", "Add the track to the selection · again to remove it"),+ ("Right-click track headers", "A multi-selection gets its own menu: group, colour, freeze, copy, duplicate, delete"),("Drag sections lane", "Mark a new section over the dragged bars"),("Click section", "Jump the playhead to its start"),("Double-click section", "Rename it"),diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.csindex 14ff266f..603d4161 100644--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs@@ -59,6 +59,8 @@ public interface IAudioEngine : IDisposableint CreateGroup(int[] trackIds); // group tracks under a new group; returns group id or -1void Ungroup(int groupId); // dissolve; children reparent up one levelvoid SetTrackGroup(int trackId, int groupId); // move a track into groupId (-1 = top-level)+ int[] DuplicateTracks(int[] trackIds); // set (+ group children) after its last member; new ids+ bool RemoveTracks(int[] trackIds); // set (+ group children), one undo step// --- Send / return buses (M6-1) ----------------------------------------int AddReturnTrack();@@ -221,6 +223,8 @@ public interface IAudioEngine : IDisposable/// <summary>Copies a whole track to the clipboard; pastes it as a new track (-1 on fail).</summary>bool CopyTrack(int trackId);int PasteTrack();+ bool CopyTracks(int[] trackIds); // a group brings its children+ int[] PasteTracks(int afterTrackId); // after the anchor, inside its group (-1 = end); new idsbool HasTrackClipboard();/// <summary>Audio-track record input source: 0 hardware, -1 master, >0 source track id.</summary>void SetTrackRecordInput(int trackId, int source);diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.csindex 93ded44c..287565ea 100644--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs@@ -51,6 +51,12 @@ internal static partial class NativeMethods[LibraryImport(Lib, EntryPoint = "nota_engine_set_track_group")]internal static partial NotaResult SetTrackGroup(IntPtr engine, int trackId, int groupId);+ [LibraryImport(Lib, EntryPoint = "nota_engine_duplicate_tracks")]+ internal static partial int DuplicateTracks(IntPtr engine, [In] int[] trackIds, int n, [Out] int[] outIds, int cap);++ [LibraryImport(Lib, EntryPoint = "nota_engine_remove_tracks")]+ internal static partial NotaResult RemoveTracks(IntPtr engine, [In] int[] trackIds, int n);+[LibraryImport(Lib, EntryPoint = "nota_engine_add_return_track")]internal static partial int AddReturnTrack(IntPtr engine);@@ -234,6 +240,12 @@ internal static partial class NativeMethods[LibraryImport(Lib, EntryPoint = "nota_track_paste")]internal static partial int TrackPaste(IntPtr engine);+ [LibraryImport(Lib, EntryPoint = "nota_track_copy_many")]+ internal static partial NotaResult TrackCopyMany(IntPtr engine, [In] int[] trackIds, int n);++ [LibraryImport(Lib, EntryPoint = "nota_track_paste_after")]+ internal static partial int TrackPasteAfter(IntPtr engine, int afterTrackId, [Out] int[] outIds, int cap);+[LibraryImport(Lib, EntryPoint = "nota_track_has_clipboard")]internal static partial int TrackHasClipboard(IntPtr engine);diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.csindex 636c3d52..aa6e566e 100644--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs@@ -44,6 +44,25 @@ public sealed partial class NotaEngine/// <summary>Move a track into groupId (-1 = top-level). Rejects cycles/returns.</summary>public void SetTrackGroup(int trackId, int groupId) { ThrowIfDisposed(); NativeMethods.SetTrackGroup(_handle, trackId, groupId); }+ /// <summary>Duplicates a set of tracks (a group brings its children) after the set's last+ /// member, as one undo step. Returns the new ids in engine order (empty on failure).</summary>+ public int[] DuplicateTracks(int[] trackIds)+ {+ ThrowIfDisposed();+ if (trackIds is not { Length: > 0 }) return Array.Empty<int>();+ var buf = new int[TrackCount + 1]; // a copy can't outnumber the existing tracks+ int n = NativeMethods.DuplicateTracks(_handle, trackIds, trackIds.Length, buf, buf.Length);+ return n > 0 ? buf[..Math.Min(n, buf.Length)] : Array.Empty<int>();+ }++ /// <summary>Removes a set of tracks (a group takes its children) as one undo step.</summary>+ public bool RemoveTracks(int[] trackIds)+ {+ ThrowIfDisposed();+ return trackIds is { Length: > 0 }+ && NativeMethods.RemoveTracks(_handle, trackIds, trackIds.Length) == NativeMethods.NotaResult.Ok;+ }+// --- Send / return buses (M6-1) ----------------------------------------/// <summary>Adds a return (aux) effect bus. Returns the track id (>0), or 0 if all return slots are used.</summary>@@ -355,6 +374,24 @@ public sealed partial class NotaEnginepublic int PasteTrack(){ ThrowIfDisposed(); return NativeMethods.TrackPaste(_handle); }+ /// <summary>Copies a set of tracks (a group brings its children) to the clipboard.</summary>+ public bool CopyTracks(int[] trackIds)+ {+ ThrowIfDisposed();+ return trackIds is { Length: > 0 }+ && NativeMethods.TrackCopyMany(_handle, trackIds, trackIds.Length) == NativeMethods.NotaResult.Ok;+ }++ /// <summary>Pastes the clipboard tracks after <paramref name="afterTrackId"/>, inside its+ /// group (-1 = top-level at the end), as one undo step. Returns the new ids in engine order.</summary>+ public int[] PasteTracks(int afterTrackId)+ {+ ThrowIfDisposed();+ var buf = new int[4096]; // far above any real clipboard; paste reports the full count+ int n = NativeMethods.TrackPasteAfter(_handle, afterTrackId, buf, buf.Length);+ return n > 0 ? buf[..Math.Min(n, buf.Length)] : Array.Empty<int>();+ }+/// <summary>True when a track has been copied to the clipboard.</summary>public bool HasTrackClipboard(){ ThrowIfDisposed(); return NativeMethods.TrackHasClipboard(_handle) != 0; }diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.hindex 5354b2f2..cbe9923d 100644--- a/src/native/nota.engine/include/nota/nota_engine.h+++ b/src/native/nota.engine/include/nota/nota_engine.h@@ -339,6 +339,13 @@ NOTA_API int32_t nota_engine_add_group_track(NotaEngine* engine);NOTA_API int32_t nota_engine_create_group(NotaEngine* engine, const int32_t* track_ids, int32_t n);NOTA_API NotaResult nota_engine_ungroup(NotaEngine* engine, int32_t group_id);NOTA_API NotaResult nota_engine_set_track_group(NotaEngine* engine, int32_t track_id, int32_t group_id);+/* Multi-track ops (header multi-selection). The set expands to every descendant of a group in+ * it; each call is one undo step. duplicate inserts the copies after the set's last member+ * (memberships kept) and writes up to cap new ids, returning the count (-1 none); remove+ * drops the whole set. */+NOTA_API int32_t nota_engine_duplicate_tracks(NotaEngine* engine, const int32_t* track_ids, int32_t n,+ int32_t* out_ids, int32_t cap);+NOTA_API NotaResult nota_engine_remove_tracks(NotaEngine* engine, const int32_t* track_ids, int32_t n);/* ---- Send / return buses (M6-1) ----------------------------------------- *//* Adds a return (aux) track: an effect bus that other tracks send to, running@@ -801,10 +808,15 @@ NOTA_API NotaResult nota_track_set_name(NotaEngine* engine, int32_t track_id, coNOTA_API int32_t nota_track_get_name(NotaEngine* engine, int32_t track_id, char* out, int32_t cap);NOTA_API NotaResult nota_track_set_color(NotaEngine* engine, int32_t track_id, int32_t color_index);NOTA_API int32_t nota_track_get_color(NotaEngine* engine, int32_t track_id);-/* Track clipboard: copy stores an independent clone, paste appends a fresh copy (new id).- * Cut = copy + nota_engine_remove_track. has_clipboard: 1 when a track is copied. */+/* Track clipboard: copy stores independent clones (a group brings its children), paste+ * appends fresh copies (new ids) top-level. copy_many / paste_after are the multi-track forms:+ * paste_after lands the copies after after_track_id inside its group (-1 = top-level at the+ * end), writes up to cap new ids and returns the count (-1 none). Cut = copy + remove.+ * has_clipboard: 1 when tracks are copied. */NOTA_API NotaResult nota_track_copy(NotaEngine* engine, int32_t track_id);-NOTA_API int32_t nota_track_paste(NotaEngine* engine); /* -> new track id, or -1 */+NOTA_API int32_t nota_track_paste(NotaEngine* engine); /* -> first new track id, or -1 */+NOTA_API NotaResult nota_track_copy_many(NotaEngine* engine, const int32_t* track_ids, int32_t n);+NOTA_API int32_t nota_track_paste_after(NotaEngine* engine, int32_t after_track_id, int32_t* out_ids, int32_t cap);NOTA_API int32_t nota_track_has_clipboard(NotaEngine* engine);/* Record input source for an audio track (internal resampling): 0 = hardware input,* -1 = master bus, >0 = another track's post-fader output (by id). */diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.hindex bf9c1f5b..4d9f2c97 100644--- a/src/native/nota.engine/src/Engine.h+++ b/src/native/nota.engine/src/Engine.h@@ -327,6 +327,13 @@ public:bool ungroup(int32_t groupId); // dissolve; children reparent up one levelbool setTrackGroup(int32_t trackId, int32_t groupId); // move track into groupId (-1 = top-level)+ // Multi-track ops (arrangement header multi-selection). A set expands to every descendant+ // of each group in it and keeps engine order; each op is one snapshot / undo step.+ // duplicateTracks inserts the copies after the set's last member, members keeping their+ // own groups; removeTracks drops the whole set. Unknown ids are ignored.+ int32_t duplicateTracks(const int32_t* ids, int32_t n, int32_t* outIds, int32_t cap); // -> copies made, -1 none+ bool removeTracks(const int32_t* ids, int32_t n);+// --- send/return buses (M6-1) ---int32_t addReturnTrack(); // aux bus: device chain -> mastervoid setTrackSend(int32_t trackId, int32_t bus, float level); // post-fader send (atomic)@@ -461,10 +468,15 @@ public:bool setTrackColorIndex(int32_t trackId, int32_t colorIndex);int32_t trackColorIndex(int32_t trackId) const;- // Track clipboard (copy/cut/paste). copyTrack stores a fully independent clone;- // pasteTrack appends a fresh copy (new id + cloned DSP). Cut = copy + removeTrack.+ // Track clipboard (copy/cut/paste). copyTracks stores fully independent clones of the+ // expanded set (a group brings its children); pasteTracks inserts fresh copies (new ids ++ // cloned DSP) after afterTrackId inside its group — or top-level after the last regular+ // track when afterTrackId is -1 — with group links inside the set following the copies.+ // copyTrack / pasteTrack are the single-track forms. Cut = copy + removeTracks.bool copyTrack(int32_t trackId);- int32_t pasteTrack(); // -> new track id, or -1+ int32_t pasteTrack(); // -> first new track id, or -1+ bool copyTracks(const int32_t* ids, int32_t n);+ int32_t pasteTracks(int32_t afterTrackId, int32_t* outIds, int32_t cap); // -> tracks pasted, -1 nonebool hasTrackClipboard() const;// --- project load (M7-6) ---@@ -1005,8 +1017,9 @@ private:// can re-select exactly what it produced.std::vector<std::pair<int32_t,int32_t>> lastPlaced_;- // Track clipboard: a fully independent clone of the copied track (null = empty).- std::shared_ptr<Track> trackClipboard_;+ // Track clipboard: fully independent clones of the copied set, engine order (empty = none).+ // Each clone keeps its source id so paste can re-link group membership inside the set.+ std::vector<std::shared_ptr<Track>> trackClipboard_;// Automation carried with clips (copy/cut/paste/duplicate). captureClipAutomation// pulls the points in [start,end] out of every lane, offset to clip-relative beats.@@ -1033,6 +1046,13 @@ private:// Build a fully independent copy of a track (fresh id + cloned instrument/devices).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;+ // 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.+ std::vector<int32_t> insertTrackClones(const std::vector<std::shared_ptr<Track>>& src,+ int32_t afterId, int32_t rootParent, bool keepParent);// Carve [ns, ne) out of a track's audio clips (overwrite/comp on record + drag).void overwriteAudioClipsInRange(std::vector<AudioClip>& clips, double ns, double ne);diff --git a/src/native/nota.engine/src/Engine_Tracks.cpp b/src/native/nota.engine/src/Engine_Tracks.cppindex d66db9bc..7ce7a120 100644--- a/src/native/nota.engine/src/Engine_Tracks.cpp+++ b/src/native/nota.engine/src/Engine_Tracks.cpp@@ -2504,34 +2504,129 @@ bool Engine::setTrackGroup(int32_t trackId, int32_t groupId) {return true;}-// --- track clipboard (copy/cut/paste) ---------------------------------------bool Engine::copyTrack(int32_t trackId) {- auto src = findTrackAuthoring(trackId);- if (!src) return false;- trackClipboard_ = deepCloneTrack(*src, 0); // id is a placeholder; paste assigns a real one- return true;+// --- multi-track sets (header multi-selection) -----------------------------+std::vector<std::shared_ptr<Track>> Engine::expandTrackSet(const int32_t* ids, int32_t n) const {+ std::vector<std::shared_ptr<Track>> out;+ if (!ids || n <= 0) return out;+ std::set<int32_t> want(ids, ids + n);+ // A track belongs when it or any ancestor group is in the set.+ auto inSet = [&](const Track& t) {+ if (want.count(t.id())) return true;+ for (int32_t a = t.groupId(), hops = 0; a >= 0 && hops < 64; ++hops) {+ if (want.count(a)) return true;+ auto p = findTrackAuthoring(a);+ a = p ? p->groupId() : -1;+ }+ return false;+ };+ for (auto& t : authoring_->tracks) if (inSet(*t)) out.push_back(t);+ return out;}-bool Engine::hasTrackClipboard() const { return trackClipboard_ != nullptr; }-int32_t Engine::pasteTrack() {- if (!trackClipboard_) return -1;- if (trackClipboard_->type() == TrackType::Return) return -1; // return-bus identity can't be duplicated- const int32_t newId = nextTrackId_++;- auto nt = deepCloneTrack(*trackClipboard_, newId); // re-clone so repeat pastes stay independent- nt->setGroupId(-1); // paste lands top-level (its group may not exist)++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+ for (auto& s : src) if (s->type() != TrackType::Return) remap[s->id()] = nextTrackId_++;+ std::vector<std::shared_ptr<Track>> clones;+ std::vector<int32_t> newIds;+ for (auto& s : src) {+ if (s->type() == TrackType::Return) continue; // return-bus identity can't be duplicated+ auto nt = deepCloneTrack(*s, remap[s->id()]);+ auto it = remap.find(s->groupId());+ nt->setGroupId(it != remap.end() ? it->second : keepParent ? s->groupId() : rootParent);+ clones.push_back(nt);+ newIds.push_back(nt->id());+ }+ if (clones.empty()) return newIds;+auto g = std::make_shared<Graph>();g->sceneCount = authoring_->sceneCount;g->masterVolume = authoring_->masterVolume;g->masterTrack = authoring_->masterTrack;- g->tracks.reserve(authoring_->tracks.size() + 1);+ g->tracks.reserve(authoring_->tracks.size() + clones.size());for (auto& t : authoring_->tracks) g->tracks.push_back(t);- // Append after the last non-return track so it sits with the regular tracks.- int32_t insertAt = static_cast<int32_t>(g->tracks.size());+ int32_t insertAt = -1;for (int32_t i = 0; i < static_cast<int32_t>(g->tracks.size()); ++i)- if (g->tracks[i]->type() == TrackType::Return) { insertAt = i; break; }- g->tracks.insert(g->tracks.begin() + insertAt, nt);+ if (g->tracks[i]->id() == afterId && g->tracks[i]->type() != TrackType::Return) { insertAt = i + 1; break; }+ if (insertAt < 0) {+ // Append after the last non-return track so the copies sit with the regular tracks.+ insertAt = static_cast<int32_t>(g->tracks.size());+ for (int32_t i = 0; i < static_cast<int32_t>(g->tracks.size()); ++i)+ if (g->tracks[i]->type() == TrackType::Return) { insertAt = i; break; }+ }+ g->tracks.insert(g->tracks.begin() + insertAt, clones.begin(), clones.end());publish(std::move(g));recomputePdc();- return newId;+ return newIds;+}++int32_t Engine::duplicateTracks(const int32_t* ids, int32_t n, int32_t* outIds, int32_t cap) {+ auto set = expandTrackSet(ids, n);+ set.erase(std::remove_if(set.begin(), set.end(),+ [](const std::shared_ptr<Track>& t) { return t->type() == TrackType::Return; }),+ set.end());+ if (set.empty()) return -1;+ auto newIds = insertTrackClones(set, set.back()->id(), -1, /*keepParent*/ true);+ const int32_t count = static_cast<int32_t>(newIds.size());+ if (outIds) for (int32_t i = 0; i < count && i < cap; ++i) outIds[i] = newIds[i];+ return count > 0 ? count : -1;+}++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;+ for (auto& t : set) {+ // 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();+ drop.insert(t->id());+ }+ auto g = std::make_shared<Graph>();+ g->sceneCount = authoring_->sceneCount;+ g->masterVolume = authoring_->masterVolume;+ g->masterTrack = authoring_->masterTrack;+ g->tracks.reserve(authoring_->tracks.size());+ for (auto& t : authoring_->tracks)+ if (!drop.count(t->id())) g->tracks.push_back(t);+ publish(std::move(g));+ recomputePdc();+ return true;+}++// --- track clipboard (copy/cut/paste) --------------------------------------+bool Engine::copyTrack(int32_t trackId) { return copyTracks(&trackId, 1); }++bool Engine::copyTracks(const int32_t* ids, int32_t n) {+ auto set = expandTrackSet(ids, n);+ if (set.empty()) return false;+ std::vector<std::shared_ptr<Track>> clip;+ clip.reserve(set.size());+ for (auto& t : set) clip.push_back(deepCloneTrack(*t, t->id())); // source id kept for re-linking+ trackClipboard_ = std::move(clip);+ return true;+}++bool Engine::hasTrackClipboard() const { return !trackClipboard_.empty(); }++int32_t Engine::pasteTrack() {+ std::vector<int32_t> ids(trackClipboard_.size());+ int32_t n = pasteTracks(-1, ids.data(), static_cast<int32_t>(ids.size()));+ return n > 0 ? ids[0] : -1;+}++int32_t Engine::pasteTracks(int32_t afterTrackId, int32_t* outIds, int32_t cap) {+ if (trackClipboard_.empty()) return -1;+ // Land next to the anchor, in its group; without one, top-level (the source groups may be gone).+ int32_t parent = -1;+ auto anchor = findTrackAuthoring(afterTrackId);+ if (anchor && anchor->type() != TrackType::Return && anchor->id() != kMasterTrackId)+ parent = anchor->groupId();+ else afterTrackId = -1;+ auto newIds = insertTrackClones(trackClipboard_, afterTrackId, parent, /*keepParent*/ false);+ const int32_t count = static_cast<int32_t>(newIds.size());+ if (outIds) for (int32_t i = 0; i < count && i < cap; ++i) outIds[i] = newIds[i];+ return count > 0 ? count : -1;}diff --git a/src/native/nota.engine/src/nota_engine_track.cpp b/src/native/nota.engine/src/nota_engine_track.cppindex 35f14601..6f0bac77 100644--- a/src/native/nota.engine/src/nota_engine_track.cpp+++ b/src/native/nota.engine/src/nota_engine_track.cpp@@ -64,6 +64,13 @@ NotaResult nota_engine_set_track_group(NotaEngine* e, int32_t track_id, int32_tif (!e) return NOTA_ERR_INVALID_ARG;return ENG(e)->setTrackGroup(track_id, group_id) ? NOTA_OK : NOTA_ERR_INVALID_ARG;}+int32_t nota_engine_duplicate_tracks(NotaEngine* e, const int32_t* track_ids, int32_t n, int32_t* out_ids, int32_t cap) {+ return e ? ENG(e)->duplicateTracks(track_ids, n, out_ids, cap) : -1;+}+NotaResult nota_engine_remove_tracks(NotaEngine* e, const int32_t* track_ids, int32_t n) {+ if (!e) return NOTA_ERR_INVALID_ARG;+ return ENG(e)->removeTracks(track_ids, n) ? NOTA_OK : NOTA_ERR_INVALID_ARG;+}// ---- Send / return buses (M6-1) -------------------------------------------int32_t nota_engine_add_return_track(NotaEngine* e) {@@ -497,6 +504,13 @@ NotaResult nota_track_copy(NotaEngine* e, int32_t track_id) {int32_t nota_track_paste(NotaEngine* e) {return e ? ENG(e)->pasteTrack() : -1;}+NotaResult nota_track_copy_many(NotaEngine* e, const int32_t* track_ids, int32_t n) {+ if (!e) return NOTA_ERR_INVALID_ARG;+ return ENG(e)->copyTracks(track_ids, n) ? NOTA_OK : NOTA_ERR_INVALID_ARG;+}+int32_t nota_track_paste_after(NotaEngine* e, int32_t after_track_id, int32_t* out_ids, int32_t cap) {+ return e ? ENG(e)->pasteTracks(after_track_id, out_ids, cap) : -1;+}int32_t nota_track_has_clipboard(NotaEngine* e) {return (e && CENG(e)->hasTrackClipboard()) ? 1 : 0;}diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex a077c351..8aa73f2e 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -12531,6 +12531,53 @@ Console.WriteLine("-- track groups --");finally { try { if (System.IO.Directory.Exists(gdir)) System.IO.Directory.Delete(gdir, true); } catch { } }}+// ============ multi-track copy / paste / duplicate / remove ===============+Console.WriteLine("-- multi-track set ops --");+{+ using var me = new NotaEngine();+ int a = me.AddInstrumentTrack(), b = me.AddAudioTrack(), c = me.AddInstrumentTrack();+ int g = me.CreateGroup(new[] { a, b });+ me.SetTrackName(a, "A"); me.SetTrackName(c, "C");+ List<(int id, int group)> Order()+ {+ var l = new List<(int, int)>();+ for (int i = 0; i < me.TrackCount; i++) if (me.TryGetTrackInfo(i, out var ti) && !ti.IsReturn) l.Add((ti.Id, ti.GroupId));+ return l;+ }+ int IndexOf(int id) => Order().FindIndex(t => t.id == id);+ int GroupOf(int id) => Order().First(t => t.id == id).group;++ // Copying a group brings its children; paste after C re-links them to the new group.+ Check(me.CopyTracks(new[] { g }), "copy a group");+ var pasted = me.PasteTracks(c);+ Check(pasted.Length == 3, $"pasting a group pastes it + both children ({pasted.Length})");+ int ng = pasted.FirstOrDefault(id => Order().Any(t => t.group == id));+ Check(ng > 0 && pasted.Count(id => GroupOf(id) == ng) == 2, "pasted children belong to the pasted group");+ Check(GroupOf(ng) == -1 && pasted.All(id => IndexOf(id) > IndexOf(c)), "paste lands top-level after the anchor");++ // Paste after a group member lands in that group, right behind the member.+ Check(me.CopyTracks(new[] { c }), "copy a single track");+ var intoGroup = me.PasteTracks(a);+ Check(intoGroup.Length == 1 && GroupOf(intoGroup[0]) == g && IndexOf(intoGroup[0]) == IndexOf(a) + 1,+ "paste after a group member joins its group, right after it");+ Check(me.GetTrackName(intoGroup[0]) == "C", "pasted track keeps its name");++ // Duplicate keeps each copy's own group and inserts after the set's last member.+ int before = me.TrackCount;+ var dups = me.DuplicateTracks(new[] { a, c });+ Check(dups.Length == 2 && me.TrackCount == before + 2, $"duplicate two tracks ({dups.Length})");+ Check(dups.All(id => IndexOf(id) > IndexOf(c)), "duplicates land after the last selected track");+ Check(GroupOf(dups[0]) == g && GroupOf(dups[1]) == -1, "duplicates keep their own groups");++ // Removing a group takes its children, in one undo step.+ int count = me.TrackCount;+ Check(me.RemoveTracks(new[] { g }), "remove a group");+ Check(Order().All(t => t.id != g && t.group != g), "removing a group removes its children");+ Check(me.TrackCount < count - 3, $"group + children gone ({count} -> {me.TrackCount})");+ me.Undo();+ Check(me.TrackCount == count, $"one undo restores the removed set ({me.TrackCount})");+}+// ============ MCP tools drive the engine ================================Console.WriteLine("-- MCP tools --");{