Skip to content

armgit / nota

Public Imported from GitHub
0

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

(fix) Take one track out of a group; click a group's lane to select it (#494)

Chris Laupamae31ade6b810b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e0d3e3f0..788afb71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -258,6 +258,15 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
returns, then the master.
### Fixed
+- **Take one track out of a group** (#488, #489): **Remove from group** in a grouped track's
+ menu, and ⌘⇧G (Ctrl+Shift+G) on it, take just that track out — it lands right after the
+ group, which keeps its other tracks and its effects. Before, **Ungroup** there dissolved the
+ whole group and its effects went with it; on a group, **Ungroup** still does that, and undo
+ brings the group back with its effects. Dragging a header above the first row or below the
+ last one now takes it out of its group too, so a track can leave even when every track is
+ grouped.
+- **Click a group's lane to select it** (#490): a click on a group's row in the Arrangement
+ selects the group and a double-click shows its devices, as on its header.
- **Reset velocity in the piano roll**: double-clicking the stem of a note already at the default
velocity, below its cap, no longer adds an empty undo step, and the right-click **Reset
velocity** menu opens at the pointer instead of the middle of the lane.
diff --git a/src/managed/Nota.App/ArrangementView.Groups.cs b/src/managed/Nota.App/ArrangementView.Groups.cs
index 3ec9795c..451ec1c8 100644
--- a/src/managed/Nota.App/ArrangementView.Groups.cs
+++ b/src/managed/Nota.App/ArrangementView.Groups.cs
@@ -227,13 +227,19 @@ public sealed partial class ArrangementView
return gid;
}
- /// <summary>The group to ungroup for a header: the track itself if it is a group, else the
- /// group that contains it, else -1.</summary>
- private int GroupToUngroupFor(int trackId)
+ /// <summary>True when the track sits inside a group (it can be taken out of it).</summary>
+ private bool IsInGroup(int trackId) => _tracks.FirstOrDefault(x => x.Id == trackId) is { GroupId: > 0 };
+
+ private bool IsGroupId(int trackId) => _tracks.FirstOrDefault(x => x.Id == trackId) is { IsGroup: true };
+
+ /// <summary>Takes one track out of its group (#489): the group, its other members and its
+ /// devices stay. One undo step.</summary>
+ private void RemoveFromGroup(int trackId)
{
- var t = _tracks.FirstOrDefault(x => x.Id == trackId);
- if (t is null) return -1;
- return t.IsGroup ? t.Id : t.GroupId;
+ if (_engine is null || !TrackGroups.LeaveGroup(_engine, trackId)) return;
+ Refresh();
+ Select(trackId, -1);
+ SessionChanged?.Invoke();
}
private void UngroupGroup(int groupId)
@@ -249,25 +255,51 @@ public sealed partial class ArrangementView
// ---- header drag drop (reorder + into/out of a group) -----------------
/// <summary>Resolves a header drag-drop at viewport <paramref name="y"/>: joins the target
/// group (drop onto a group or one of its members), leaves the group (drop on a top-level
- /// row), and reorders next to the target. Membership + order are separate engine edits.</summary>
+ /// row), and reorders next to the target. Above the first row or below the last one is the
+ /// top level, first or last — the way out of a group when every track is grouped (#488).
+ /// Membership + order are separate engine edits, made as one undo step.</summary>
private void HandleHeaderDrop(int id, double y)
{
if (_engine is null || _tracks.Count == 0) { Select(id, -1); return; }
- int row = RowAtYClamped(y);
- if (row < 0) { Select(id, -1); return; }
- var target = _tracks[row];
var dragged = _tracks.FirstOrDefault(t => t.Id == id);
- if (dragged is null || target.Id == id) { Select(id, -1); return; }
- // Drop onto a group → join it; onto a member → join that member's group; else top-level.
- int desiredParent = target.IsGroup ? target.Id : target.GroupId;
- if (desiredParent != dragged.GroupId) _engine.SetTrackGroup(id, desiredParent);
- int destIdx = RegularIndexOf(target.Id); // position next to the target in the flat list
- if (destIdx >= 0) _engine.MoveTrack(id, destIdx);
+ if (dragged is null) { Select(id, -1); return; }
+ int desiredParent, destIdx;
+ if (RowGapAtY(y) == 0 || y >= RowsHeight)
+ {
+ desiredParent = -1;
+ destIdx = y >= RowsHeight ? RegularCount() - 1 : 0;
+ }
+ else
+ {
+ var target = _tracks[RowAtYClamped(y)];
+ if (target.Id == id) { Select(id, -1); return; }
+ // Drop onto a group → join it; onto a member → join that member's group; else top-level.
+ desiredParent = target.IsGroup ? target.Id : target.GroupId;
+ destIdx = RegularIndexOf(target.Id); // position next to the target in the flat list
+ }
+ if (desiredParent == dragged.GroupId && destIdx == RegularIndexOf(id)) { Select(id, -1); return; }
+ _engine.BeginUndoGroup();
+ try
+ {
+ if (desiredParent != dragged.GroupId) _engine.SetTrackGroup(id, desiredParent);
+ if (destIdx >= 0) _engine.MoveTrack(id, destIdx);
+ }
+ finally { _engine.EndUndoGroup(); }
Refresh();
Select(id, -1);
SessionChanged?.Invoke();
}
+ /// <summary>How many non-return tracks the engine holds (MoveTrack's index space).</summary>
+ private int RegularCount()
+ {
+ if (_engine is null) return 0;
+ int n = 0;
+ for (int i = 0; i < _engine.TrackCount; i++)
+ if (_engine.TryGetTrackInfo(i, out var ti) && !ti.IsReturn) n++;
+ return n;
+ }
+
/// <summary>Index of a track among the engine's non-return tracks (the space MoveTrack uses).</summary>
private int RegularIndexOf(int trackId)
{
@@ -286,12 +318,13 @@ public sealed partial class ArrangementView
/// <summary>Cmd+G — group the selected tracks. Returns true if a group was formed.</summary>
public bool GroupSelection() => GroupTracks(-1) > 0;
- /// <summary>Cmd+Shift+G — ungroup the selected group (or the group of the selected track).</summary>
+ /// <summary>Cmd+Shift+G — ungroup the selected group, or take the selected track out of its
+ /// group (#489: the group and its devices stay).</summary>
public bool UngroupSelection()
{
- int gid = GroupToUngroupFor(SelTrackId);
- if (gid <= 0) return false;
- UngroupGroup(gid);
+ if (IsGroupId(SelTrackId)) { UngroupGroup(SelTrackId); return true; }
+ if (!IsInGroup(SelTrackId)) return false;
+ RemoveFromGroup(SelTrackId);
return true;
}
}
diff --git a/src/managed/Nota.App/ArrangementView.LaneControl.cs b/src/managed/Nota.App/ArrangementView.LaneControl.cs
index 54ab8d72..43024471 100644
--- a/src/managed/Nota.App/ArrangementView.LaneControl.cs
+++ b/src/managed/Nota.App/ArrangementView.LaneControl.cs
@@ -259,10 +259,18 @@ public sealed partial class ArrangementView
if (hit is not { } hh)
{
- // Double-click empty space on an instrument track's lane → new MIDI clip there.
+ // Double-click empty space on an instrument track's lane → new MIDI clip there;
+ // on a group's lane → the group's devices in the Detail panel, as on its header (#490).
if (e.ClickCount == 2)
{
int ti = _o.RowAtY(pt.Position.Y);
+ if (ti >= 0 && _o._tracks[ti].IsGroup)
+ {
+ int gid = _o._tracks[ti].Id;
+ if (_o.SelTrackId != gid) _o.Select(gid, -1);
+ _o.TrackDevicesRequested?.Invoke(gid);
+ return;
+ }
if (ti >= 0 && _o._tracks[ti].IsInstrument)
{
_o.AddMidiClipAt(_o._tracks[ti].Id, beat);
@@ -651,10 +659,12 @@ public sealed partial class ArrangementView
else
{
// Plain click on empty space: clear everything and move the playhead
- // (except during playback — scrub from the ruler, not the grid).
- _o.Select(-1, -1);
- _o.ClearTimeSelection();
+ // (except during playback — scrub from the ruler, not the grid). A group's
+ // lane holds no clips of its own, so a click there selects the group (#490).
int row = _o.RowAtY(_marqueePress.Y);
+ bool groupLane = row >= 0 && row < _o._tracks.Count && _o._tracks[row].IsGroup;
+ _o.Select(groupLane ? _o._tracks[row].Id : -1, -1);
+ _o.ClearTimeSelection();
if (row >= 0 && row < _o._tracks.Count) _o.FocusTrackId = _o._tracks[row].Id;
if (_o._engine is not { IsPlaying: true })
_o.SeekTo(_o._scrollBeats + _marqueePress.X / _o._pixelsPerBeat);
diff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.cs
index f0e281bf..16e33e55 100644
--- a/src/managed/Nota.App/ArrangementView.cs
+++ b/src/managed/Nota.App/ArrangementView.cs
@@ -2758,16 +2758,18 @@ public sealed partial class ArrangementView : UserControl
}
// Group / Ungroup (submix). "Group" folds the multi-selection (or this track) into a
- // new group; "Ungroup" dissolves the group this track is/belongs to.
+ // new group; on a group "Ungroup" dissolves it, on a member "Remove from group" takes
+ // just this track out (#489).
var create = new List<Control>();
var addTrack = MenuKit.Item(Loc.T("arrangement.add_track"), GlyphKind.Plus);
foreach (var mi in AddTrackItems(trackId, inSubmenu: true)) addTrack.Items.Add(mi);
AddRecentInstruments(addTrack, trackId);
create.Add(addTrack);
create.Add(MenuKit.Item(Loc.T("arrangement.group_tracks"), GlyphKind.Folder, () => GroupTracks(trackId), MenuKit.GroupKey));
- int ungroupId = GroupToUngroupFor(trackId);
- if (ungroupId > 0)
- create.Add(MenuKit.Item(Loc.T("arrangement.ungroup"), GlyphKind.Ungroup, () => UngroupGroup(ungroupId), MenuKit.UngroupKey));
+ if (vm is { IsGroup: true })
+ create.Add(MenuKit.Item(Loc.T("arrangement.ungroup"), GlyphKind.Ungroup, () => UngroupGroup(trackId), MenuKit.UngroupKey));
+ else if (IsInGroup(trackId))
+ create.Add(MenuKit.Item(Loc.T("arrangement.remove_from_group"), GlyphKind.Ungroup, () => RemoveFromGroup(trackId), MenuKit.UngroupKey));
if (vm is { IsGroup: true } gvm) // group Link (specs/076)
create.Add(MenuKit.SwitchItem(Loc.T("arrangement.link_tracks"), GlyphKind.ChainLink, gvm.EditLink, () => SetGroupLink(gvm.Id, !gvm.EditLink)));
diff --git a/src/managed/Nota.Application/Editing/TrackGroups.cs b/src/managed/Nota.Application/Editing/TrackGroups.cs
new file mode 100644
index 00000000..2c8ce92e
--- /dev/null
+++ b/src/managed/Nota.Application/Editing/TrackGroups.cs
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Taking one track out of its group (#488, #489): the track moves up one level — into the
+// group's own parent, or to the top level — and sits right after the group, which keeps its
+// other members and its devices. Membership and order are two engine edits; this makes them
+// one undo step. The header menu, ⌘⇧G on a member and a header drop above or below every row
+// all go through here.
+
+using System.Collections.Generic;
+
+namespace Nota.Application.Editing;
+
+public static class TrackGroups
+{
+ /// <summary>Moves <paramref name="trackId"/> out of the group that holds it, placing it right
+ /// after the group's last track. False when the track isn't in a group.</summary>
+ public static bool LeaveGroup(IAudioEngine eng, int trackId)
+ {
+ var regular = Regular(eng);
+ int gid = -1;
+ foreach (var t in regular) if (t.Id == trackId) gid = t.GroupId;
+ if (gid < 0) return false;
+ int parent = -1;
+ foreach (var t in regular) if (t.Id == gid) parent = t.GroupId;
+
+ // Where the track goes, as an index in engine order once it is out (MoveTrack takes the
+ // track out, then inserts it there). Rows list a parent's children in engine order, and a
+ // group's members need not be adjacent in it: an ungrouped track can sit between them.
+ // So the slot is right after the group's last row, but never past the
+ // group's next sibling, so nothing at the parent's level comes between the group and
+ // the track.
+ var inGroup = new HashSet<int> { gid };
+ for (bool grew = true; grew;)
+ {
+ grew = false;
+ foreach (var t in regular)
+ if (inGroup.Contains(t.GroupId) && inGroup.Add(t.Id)) grew = true;
+ }
+ regular.RemoveAll(t => t.Id == trackId);
+ int groupAt = regular.FindIndex(t => t.Id == gid);
+ int dest = groupAt + 1;
+ for (int i = groupAt + 1; i < regular.Count; i++)
+ {
+ if (regular[i].GroupId == parent && !inGroup.Contains(regular[i].Id)) break; // the next sibling
+ if (inGroup.Contains(regular[i].Id)) dest = i + 1;
+ }
+
+ eng.BeginUndoGroup();
+ try
+ {
+ eng.SetTrackGroup(trackId, parent);
+ eng.MoveTrack(trackId, dest);
+ }
+ finally { eng.EndUndoGroup(); }
+ return true;
+ }
+
+ /// <summary>The non-return tracks in engine order — the index space MoveTrack uses.</summary>
+ private static List<NotaTrackInfo> Regular(IAudioEngine eng)
+ {
+ var list = new List<NotaTrackInfo>();
+ for (int i = 0; i < eng.TrackCount; i++)
+ if (eng.TryGetTrackInfo(i, out var ti) && !ti.IsReturn) list.Add(ti);
+ return list;
+ }
+}
diff --git a/src/managed/Nota.Application/Localization/en.json b/src/managed/Nota.Application/Localization/en.json
index 04fee023..04b0fd34 100644
--- a/src/managed/Nota.Application/Localization/en.json
+++ b/src/managed/Nota.Application/Localization/en.json
@@ -93,6 +93,7 @@
"arrangement.paste_track": "Paste track",
"arrangement.played_from_a_phone": "Played from a phone: {0}",
"arrangement.processing": "Processing…",
+ "arrangement.remove_from_group": "Remove from group",
"arrangement.sections.add_section_here": "Add section here",
"arrangement.sections.already_has_its_automatic_name": "{0} already has its automatic name",
"arrangement.sections.automatic_name": "Automatic name",
diff --git a/tests/Nota.SmokeTest/GroupMembershipTests.cs b/tests/Nota.SmokeTest/GroupMembershipTests.cs
new file mode 100644
index 00000000..60813a9a
--- /dev/null
+++ b/tests/Nota.SmokeTest/GroupMembershipTests.cs
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Taking one track out of its group (#488, #489): the track leaves, the group keeps its other
+// members and its devices, the track lands right after the group, and it is one undo step —
+// also when every track in the project is grouped. Dissolving a whole group can be undone with
+// its devices.
+
+using Nota.Application;
+using Nota.Application.Editing;
+using Nota.Infrastructure;
+
+namespace Nota.SmokeTest;
+
+internal static class GroupMembershipTests
+{
+ private const int Utility = 4;
+
+ public static IEnumerable<(bool, string)> Run()
+ {
+ using var e = new NotaEngine();
+ int a = e.AddAudioTrack(), b = e.AddAudioTrack(), c = e.AddAudioTrack();
+ int g = e.CreateGroup(new[] { a, b, c }); // every track is grouped
+ e.AddBuiltinDevice(g, Utility);
+ int fx = e.TrackDeviceCount(g);
+
+ yield return (!TrackGroups.LeaveGroup(e, g), "groups: a top-level group has no group to leave");
+ yield return (TrackGroups.LeaveGroup(e, a), "groups: a member leaves its group even when every track is grouped");
+ yield return (Info(e, a).GroupId == -1 && Info(e, b).GroupId == g && Info(e, c).GroupId == g,
+ "groups: only that track leaves; the others stay members");
+ yield return (Info(e, g).IsGroup && e.TrackDeviceCount(g) == fx, "groups: the group and its devices stay");
+ yield return (Order(e).SequenceEqual(new[] { g, b, c, a }), "groups: the track lands right after the group");
+ yield return (e.Undo() && Info(e, a).GroupId == g && Order(e).SequenceEqual(new[] { g, a, b, c }),
+ "groups: leaving is one undo step");
+
+ // Nested: a track leaves an inner group into the outer one, not to the top level.
+ int inner = e.CreateGroup(new[] { b, c });
+ yield return (Info(e, inner).GroupId == g, "groups: (an inner group nests in the outer one)");
+ yield return (TrackGroups.LeaveGroup(e, b) && Info(e, b).GroupId == g && Info(e, c).GroupId == inner,
+ "groups: leaving an inner group moves the track up one level");
+
+ // Dissolving the whole group drops the group track; undo brings it back with its devices.
+ e.Ungroup(g);
+ yield return (!Order(e).Contains(g), "groups: Ungroup dissolves the group");
+ yield return (e.Undo() && Order(e).Contains(g) && e.TrackDeviceCount(g) == fx && Info(e, inner).GroupId == g,
+ "groups: undoing an Ungroup brings the group back with its devices");
+
+ // Members need not be adjacent: grouping p and q around an ungrouped x leaves engine
+ // order [h, p, x, q]. p must land right after the group's rows, before x.
+ using var e2 = new NotaEngine();
+ int p = e2.AddAudioTrack(), x = e2.AddAudioTrack(), q = e2.AddAudioTrack();
+ int h = e2.CreateGroup(new[] { p, q });
+ yield return (Order(e2).SequenceEqual(new[] { h, p, x, q }), "groups: (members around an ungrouped track)");
+ yield return (TrackGroups.LeaveGroup(e2, p) && Info(e2, p).GroupId == -1
+ && Order(e2).IndexOf(p) > Order(e2).IndexOf(h) && Order(e2).IndexOf(p) < Order(e2).IndexOf(x),
+ "groups: with non-adjacent members the track still lands right after the group, before the next track");
+ }
+
+ private static NotaTrackInfo Info(NotaEngine e, int id)
+ {
+ for (int i = 0; i < e.TrackCount; i++)
+ if (e.TryGetTrackInfo(i, out var ti) && ti.Id == id) return ti;
+ return default;
+ }
+
+ private static List<int> Order(NotaEngine e)
+ {
+ var l = new List<int>();
+ for (int i = 0; i < e.TrackCount; i++)
+ if (e.TryGetTrackInfo(i, out var ti) && !ti.IsReturn) l.Add(ti.Id);
+ return l;
+ }
+}
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index c54ff667..26fe975f 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -15483,6 +15483,8 @@ Console.WriteLine("-- session launch + record input --");
foreach (var (ok, label) in SessionInputTests.Run()) Check(ok, label);
Console.WriteLine("-- group link --");
foreach (var (ok, label) in GroupLinkTests.Run()) Check(ok, label);
+Console.WriteLine("-- group membership --");
+foreach (var (ok, label) in GroupMembershipTests.Run()) Check(ok, label);
Console.WriteLine("-- tempo follow --");
foreach (var (ok, label) in TempoFollowTests.Run()) Check(ok, label);
Console.WriteLine("-- meter --");