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) Atomic move operations for arangement

Egor Khindikaynen74196e85dc40
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0920b297..9bfe4b4e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -108,6 +108,9 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
don't change it.
### Fixed
+- Moving several selected clips at once no longer deletes or shortens some of them. Before,
+ a second move of the same clips could make clips disappear or get cut. A group move is
+ now also a single undo step.
- Nota Scale no longer leaves notes hanging when you change the scale, root or fold while a
key is held, or when two held keys land on the same note.
- Nota Length's Gate % below 100 % now shortens notes from a clip. Before, a note always
diff --git a/src/managed/Nota.App/ArrangementView.LaneControl.cs b/src/managed/Nota.App/ArrangementView.LaneControl.cs
index 811887b9..d332d1da 100644
--- a/src/managed/Nota.App/ArrangementView.LaneControl.cs
+++ b/src/managed/Nota.App/ArrangementView.LaneControl.cs
@@ -447,31 +447,34 @@ public sealed partial class ArrangementView
// Nothing actually moved (snap kept every start, no row change) → don't touch
// the model, so a jiggle-and-release doesn't create a no-op undo step.
bool moved = rowDelta != 0 || _groupMove.Any(m => Math.Abs(m.vm.StartBeat - m.origStart) > 1e-9);
- bool keptDeviceAuto = false;
+ bool committed = false;
if (eng is not null && moved)
- // Descending clip index: cross-track moves erase from the source and
- // would otherwise invalidate lower indices on the same track.
- foreach (var m in _groupMove.OrderByDescending(m => m.clip))
+ {
+ // One atomic group move: moving the clips one by one let an early clip
+ // carve a not-yet-moved member of the group (clips vanished / got cut).
+ var moves = _groupMove.Select(m =>
{
int destRow = m.origRow + rowDelta;
int destTrack = (rowDelta != 0 && destRow >= 0 && destRow < _o._tracks.Count)
? _o._tracks[destRow].Id : m.track;
- if (destTrack != m.track)
- {
- eng.MoveClipToTrack(m.track, m.clip, destTrack, m.vm.StartBeat);
- keptDeviceAuto |= eng.LastMoveKeptDeviceAutomation();
- }
- else eng.MoveClip(m.track, m.clip, m.vm.StartBeat);
- // Same-track moves keep their clip index, so an open editor on one of
- // them stays valid — but its START read-out is now off.
- if (rowDelta == 0) _o.RaiseClipGeometryChanged(m.track, m.clip);
- }
- if (keptDeviceAuto) // explicit hint: only Volume/Pan followed across tracks (req 8.3.4)
- _o.StatusMessage?.Invoke("Moved across tracks — device automation stayed on the source");
+ return (m.track, m.clip, destTrack, m.vm.StartBeat);
+ }).ToArray();
+ committed = eng.MoveClipBlock(moves);
+ // Same-track moves keep their clip index, so an open editor on one of
+ // them stays valid — but its START read-out is now off.
+ if (committed && rowDelta == 0)
+ foreach (var m in _groupMove) _o.RaiseClipGeometryChanged(m.track, m.clip);
+ if (committed && eng.LastMoveKeptDeviceAutomation()) // explicit hint: only Volume/Pan followed across tracks (req 8.3.4)
+ _o.StatusMessage?.Invoke("Moved across tracks — device automation stayed on the source");
+ }
_groupMove = null; _drag = Drag.None; _moveRowDelta = 0;
e.Pointer.Capture(null);
- if (moved && rowDelta != 0) _o.Select(-1, -1); // indices changed → drop stale selection
- if (moved) _o.Refresh(); else InvalidateVisual();
+ if (moved)
+ {
+ _o.Refresh(); // also restores the preview if the engine rejected the move
+ if (committed) _o.ReselectPlaced(); // cross-track moves change indices
+ }
+ else InvalidateVisual();
return;
}
diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.cs
index 0fb7977c..630d1064 100644
--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs
+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs
@@ -112,6 +112,10 @@ public interface IAudioEngine : IDisposable
/// <summary>Moves a clip to another same-type track — instrument→instrument or
/// audio→audio (atomic). Same-track == MoveClip.</summary>
void MoveClipToTrack(int srcTrackId, int clipIndex, int destTrackId, double newStartBeat);
+ /// <summary>Moves a group of clips at once (multi-selection drag): they carve only the
+ /// clips that stay put, never each other; same-track clips keep their index. One undo
+ /// step; <see cref="LastPlacedClips"/> reports each new position in request order.</summary>
+ bool MoveClipBlock((int trackId, int clipIndex, int destTrackId, double newStartBeat)[] moves);
void TrimClip(int trackId, int clipIndex, double newStartBeat, double newLengthBeats);
/// <summary>Grid resize for an audio clip (grid-relative): warped clips (or unwarped
/// clips dragged past their source length) stretch; unwarped clips within source
diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
index 95b5d299..93ded44c 100644
--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
@@ -78,6 +78,9 @@ internal static partial class NativeMethods
[LibraryImport(Lib, EntryPoint = "nota_clip_move_to_track")]
internal static partial NotaResult ClipMoveToTrack(IntPtr engine, int srcTrackId, int clipIndex, int destTrackId, double newStartBeat);
+ [LibraryImport(Lib, EntryPoint = "nota_clips_block_move")]
+ internal static partial NotaResult ClipsBlockMove(IntPtr engine, int[] trackIds, int[] clipIndices, int[] destTrackIds, double[] newStarts, int n);
+
[LibraryImport(Lib, EntryPoint = "nota_clip_trim")]
internal static partial NotaResult ClipTrim(IntPtr engine, int trackId, int clipIndex, double newStartBeat, double newLengthBeats);
diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
index b7622b4f..636c3d52 100644
--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
@@ -82,6 +82,18 @@ public sealed partial class NotaEngine
public void MoveClipToTrack(int srcTrackId, int clipIndex, int destTrackId, double newStartBeat)
{ ThrowIfDisposed(); Check(NativeMethods.ClipMoveToTrack(_handle, srcTrackId, clipIndex, destTrackId, newStartBeat)); }
+ /// <summary>Moves a group of clips at once (multi-selection drag): they carve only the clips
+ /// that stay put, never each other; same-track clips keep their index. One undo step;
+ /// <see cref="LastPlacedClips"/> reports each clip's new position in request order.</summary>
+ public bool MoveClipBlock((int trackId, int clipIndex, int destTrackId, double newStartBeat)[] moves)
+ {
+ ThrowIfDisposed();
+ if (moves.Length == 0) return false;
+ var t = new int[moves.Length]; var c = new int[moves.Length]; var d = new int[moves.Length]; var s = new double[moves.Length];
+ for (int i = 0; i < moves.Length; i++) (t[i], c[i], d[i], s[i]) = moves[i];
+ return NativeMethods.ClipsBlockMove(_handle, t, c, d, s, moves.Length) == NativeMethods.NotaResult.Ok;
+ }
+
/// <summary>Trims/resizes a clip to a new start + length in beats.</summary>
public void TrimClip(int trackId, int clipIndex, double newStartBeat, double newLengthBeats)
{ ThrowIfDisposed(); Check(NativeMethods.ClipTrim(_handle, trackId, clipIndex, newStartBeat, newLengthBeats)); }
diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.h
index 45f294c8..f84fd484 100644
--- a/src/native/nota.engine/include/nota/nota_engine.h
+++ b/src/native/nota.engine/include/nota/nota_engine.h
@@ -678,6 +678,12 @@ NOTA_API NotaResult nota_clip_move(NotaEngine* engine, int32_t track_id, int32_t
/* Move a clip to another same-type track (instrument→instrument or audio→audio,
* atomic). Same-track == nota_clip_move. */
NOTA_API NotaResult nota_clip_move_to_track(NotaEngine* engine, int32_t src_track_id, int32_t clip_index, int32_t source_track_id, double new_start_beat);
+/* Group move (multi-selection drag): moves n clips at once — clip i of track_ids[i] at
+ * clip_indices[i] lands on dest_track_ids[i] at new_starts[i]. Moved clips carve only the
+ * clips that stay put (never each other); same-track clips keep their index. One undo step;
+ * nota_clips_last_placed then reports each clip's new (track, index) in request order. */
+NOTA_API NotaResult nota_clips_block_move(NotaEngine* engine, const int32_t* track_ids, const int32_t* clip_indices,
+ const int32_t* dest_track_ids, const double* new_starts, int32_t n);
NOTA_API NotaResult nota_clip_trim(NotaEngine* engine, int32_t track_id, int32_t clip_index, double new_start_beat, double new_length_beats);
/* Grid resize for an audio clip (grid-relative): warped clips (or unwarped clips
* dragged past their source length) stretch; unwarped clips within source bounds
diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.h
index 1b60d974..8b66bca0 100644
--- a/src/native/nota.engine/src/Engine.h
+++ b/src/native/nota.engine/src/Engine.h
@@ -378,6 +378,13 @@ public:
// or audio→audio; atomic — both tracks change in one publish). Same-track falls
// back to moveClip.
bool moveClipToTrack(int32_t srcTrackId, int32_t clipIndex, int32_t sourceTrackId, double newStartBeat);
+ // Group move (multi-selection drag): every clip moves at once, so a moved clip only
+ // carves the clips that stay put — never another member of the group. Clips that stay
+ // on their track keep their index; cross-track ones are appended to the destination.
+ // All-or-nothing validation, one undo step; lastPlaced() reports each clip's new
+ // (trackId, clipIndex) in request order.
+ struct ClipMoveReq { int32_t srcTrackId; int32_t clipIndex; int32_t dstTrackId; double newStartBeat; };
+ bool moveClipBlock(const std::vector<ClipMoveReq>& moves);
bool trimClip(int32_t trackId, int32_t clipIndex, double newStartBeat, double newLengthBeats);
// Grid resize for an audio clip (grid-relative): warped clips (or unwarped
// clips dragged past their source length) stretch to newLengthBeats; unwarped
diff --git a/src/native/nota.engine/src/Engine_Tracks.cpp b/src/native/nota.engine/src/Engine_Tracks.cpp
index 5a3256ad..d66db9bc 100644
--- a/src/native/nota.engine/src/Engine_Tracks.cpp
+++ b/src/native/nota.engine/src/Engine_Tracks.cpp
@@ -26,6 +26,8 @@
#include <cmath>
#include <limits>
#include <map>
+#include <set>
+#include <type_traits>
namespace nota {
@@ -1196,6 +1198,124 @@ bool Engine::moveClipToTrack(int32_t srcTrackId, int32_t clipIndex, int32_t sour
return true;
}
+bool Engine::moveClipBlock(const std::vector<ClipMoveReq>& moves) {
+ lastPlaced_.clear();
+ lastMoveKeptDeviceAuto_ = false;
+ if (moves.empty() || !authoring_) return false;
+ const double spb = transport_.samplesPerBeat(), devSR = transport_.sampleRate();
+
+ // Validate everything up front (all-or-nothing) and clone each touched track once.
+ std::map<int32_t, std::shared_ptr<Track>> clones;
+ std::set<std::pair<int32_t,int32_t>> seen;
+ for (const auto& m : moves) {
+ auto src = findTrackAuthoring(m.srcTrackId);
+ auto dst = findTrackAuthoring(m.dstTrackId);
+ if (!src || !dst || src->type() != dst->type() || src->type() == TrackType::Return) return false;
+ if (m.srcTrackId == kMasterTrackId || m.dstTrackId == kMasterTrackId) return false;
+ const size_t n = src->type() == TrackType::Instrument ? src->midiClips.size() : src->clips.size();
+ if (m.clipIndex < 0 || m.clipIndex >= static_cast<int32_t>(n)) return false;
+ if (!seen.emplace(m.srcTrackId, m.clipIndex).second) return false; // same clip twice
+ if (!clones.count(m.srcTrackId)) clones[m.srcTrackId] = cloneTrack(*src);
+ if (!clones.count(m.dstTrackId)) clones[m.dstTrackId] = cloneTrack(*dst);
+ }
+
+ // Snapshot each moving clip (+ the automation in its span) from the pre-move tracks.
+ struct Item { const ClipMoveReq* req; bool midi; MidiClip mc; AudioClip ac; double oldStart, len, newStart;
+ bool sameTrack, layoutMatch; std::vector<AutomationLane> snips; };
+ std::vector<Item> items; items.reserve(moves.size());
+ for (const auto& m : moves) {
+ const Track& src = *clones[m.srcTrackId];
+ Item it{ &m, src.type() == TrackType::Instrument, {}, {}, 0, 0, std::max(0.0, m.newStartBeat),
+ m.srcTrackId == m.dstTrackId, true, {} };
+ if (it.midi) { it.mc = src.midiClips[m.clipIndex]; it.oldStart = it.mc.startBeat; it.len = it.mc.lengthBeats; it.mc.startBeat = it.newStart; }
+ else { it.ac = src.clips[m.clipIndex]; it.oldStart = it.ac.startBeat; it.len = audioDisplayLenBeats(it.ac, spb, devSR); it.ac.startBeat = it.newStart; }
+ it.layoutMatch = it.sameTrack || tracksDeviceLayoutMatch(src, *clones[m.dstTrackId]);
+ const bool follow = !automationLock_ && it.len > 1e-6 && (!it.sameTrack || std::abs(it.newStart - it.oldStart) > 1e-9);
+ if (follow) it.snips = captureClipAutomation(src, it.oldStart, it.oldStart + it.len);
+ items.push_back(std::move(it));
+ }
+
+ // Rebuild each touched track's clip list: clips staying on the track keep their slot (new
+ // start), clips leaving are dropped, and every stationary clip is carved by all incoming
+ // ranges. Cross-track arrivals are appended afterwards.
+ std::map<int32_t, std::vector<std::pair<double,double>>> incoming; // dst track → landing ranges
+ for (const auto& it : items) incoming[it.req->dstTrackId].emplace_back(it.newStart, it.newStart + it.len);
+ std::map<std::pair<int32_t,int32_t>, size_t> itemOf; // (src track, index) → item
+ for (size_t i = 0; i < items.size(); ++i) itemOf[{ items[i].req->srcTrackId, items[i].req->clipIndex }] = i;
+ std::vector<int32_t> newIndex(items.size(), -1);
+
+ for (auto& [tid, nt] : clones) {
+ const auto& ranges = incoming[tid];
+ auto rebuild = [&](auto& clips, auto carve) {
+ std::remove_reference_t<decltype(clips)> out; out.reserve(clips.size() + 2 * ranges.size());
+ for (int32_t ci = 0; ci < static_cast<int32_t>(clips.size()); ++ci) {
+ auto f = itemOf.find({ tid, ci });
+ if (f != itemOf.end()) {
+ auto& it = items[f->second];
+ if (!it.sameTrack) continue; // leaves this track
+ newIndex[f->second] = static_cast<int32_t>(out.size());
+ if constexpr (std::is_same_v<std::decay_t<decltype(clips[0])>, MidiClip>) out.push_back(it.mc);
+ else out.push_back(it.ac);
+ continue;
+ }
+ std::remove_reference_t<decltype(clips)> pieces{ clips[ci] };
+ for (const auto& [s, e] : ranges) carve(pieces, s, e);
+ for (auto& p : pieces) out.push_back(std::move(p));
+ }
+ clips.swap(out);
+ };
+ if (nt->type() == TrackType::Instrument)
+ rebuild(nt->midiClips, [](std::vector<MidiClip>& v, double s, double e){ midiOverwriteRange(v, s, e); });
+ else
+ rebuild(nt->clips, [&](std::vector<AudioClip>& v, double s, double e){ audioOverwriteRange(v, s, e, spb, devSR); });
+ }
+ for (size_t i = 0; i < items.size(); ++i) {
+ auto& it = items[i];
+ if (it.sameTrack) continue;
+ Track& dst = *clones[it.req->dstTrackId];
+ if (it.midi) { dst.midiClips.push_back(it.mc); newIndex[i] = static_cast<int32_t>(dst.midiClips.size()) - 1; }
+ else { dst.clips.push_back(it.ac); newIndex[i] = static_cast<int32_t>(dst.clips.size()) - 1; }
+ }
+
+ // Automation follows (req 8.3.1/8.3.4): lift every source span first, then re-land, so
+ // one clip's landing never gets erased by another's lift. Cross-track moves between
+ // differing device layouts carry only Volume/Pan; device/plugin points stay behind.
+ constexpr double eps = 1e-6;
+ for (auto& it : items) {
+ if (it.snips.empty()) continue;
+ Track& src = *clones[it.req->srcTrackId];
+ if (it.layoutMatch) { removeAutomationInRange(src, it.oldStart, it.oldStart + it.len); continue; }
+ for (const auto& s : it.snips)
+ if (s.target != AutomationTarget::Volume && s.target != AutomationTarget::Pan) { lastMoveKeptDeviceAuto_ = true; break; }
+ for (auto& lane : src.automation) {
+ if (lane.target != AutomationTarget::Volume && lane.target != AutomationTarget::Pan) continue;
+ auto& pts = lane.points;
+ pts.erase(std::remove_if(pts.begin(), pts.end(),
+ [&](const AutomationPoint& p){ return p.beat >= it.oldStart - eps && p.beat <= it.oldStart + it.len + eps; }),
+ pts.end());
+ }
+ }
+ for (auto& it : items)
+ if (!it.snips.empty())
+ applyClipAutomation(*clones[it.req->dstTrackId], it.req->dstTrackId, it.snips, it.newStart, it.len, it.layoutMatch);
+
+ for (size_t i = 0; i < items.size(); ++i) lastPlaced_.emplace_back(items[i].req->dstTrackId, newIndex[i]);
+
+ // Publish every touched track at once — a single undo checkpoint for the whole group.
+ pushUndo();
+ 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) {
+ auto it = clones.find(t->id());
+ g->tracks.push_back(it != clones.end() ? it->second : t);
+ }
+ publishRaw(std::move(g));
+ return true;
+}
+
// --- time-range clip ops (arrangement time-selection) -----------------------
namespace {
bool rangeTouchesTrack(const Track& t, double s, double e, double spb, double devSR) {
diff --git a/src/native/nota.engine/src/nota_engine_track.cpp b/src/native/nota.engine/src/nota_engine_track.cpp
index ce24f404..35f14601 100644
--- a/src/native/nota.engine/src/nota_engine_track.cpp
+++ b/src/native/nota.engine/src/nota_engine_track.cpp
@@ -288,6 +288,13 @@ NotaResult nota_clip_move_to_track(NotaEngine* e, int32_t src_track_id, int32_t
if (!e) return NOTA_ERR_INVALID_ARG;
return ENG(e)->moveClipToTrack(src_track_id, clip_index, source_track_id, new_start_beat) ? NOTA_OK : NOTA_ERR_INVALID_ARG;
}
+NotaResult nota_clips_block_move(NotaEngine* e, const int32_t* track_ids, const int32_t* clip_indices,
+ const int32_t* dest_track_ids, const double* new_starts, int32_t n) {
+ if (!e || !track_ids || !clip_indices || !dest_track_ids || !new_starts || n <= 0) return NOTA_ERR_INVALID_ARG;
+ std::vector<Engine::ClipMoveReq> moves; moves.reserve(n);
+ for (int32_t i = 0; i < n; ++i) moves.push_back({ track_ids[i], clip_indices[i], dest_track_ids[i], new_starts[i] });
+ return ENG(e)->moveClipBlock(moves) ? NOTA_OK : NOTA_ERR_INVALID_ARG;
+}
NotaResult nota_clip_trim(NotaEngine* e, int32_t track_id, int32_t clip_index, double new_start_beat, double new_length_beats) {
if (!e) return NOTA_ERR_INVALID_ARG;
return ENG(e)->trimClip(track_id, clip_index, new_start_beat, new_length_beats) ? NOTA_OK : NOTA_ERR_INVALID_ARG;
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index 64db4215..06eb3118 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -11688,6 +11688,77 @@ Console.WriteLine("-- overwrite on drag (carve) --");
}
}
+// ============ group move: the group never carves itself ======================
+// bug02: select all clips, move 1.1→2.1, then 2.1→3.1 (or →5.1). Moving the clips one by
+// one let an early clip land on a not-yet-moved group member and carve it (clips vanished
+// or got cut). The atomic group move only carves clips that stay put.
+Console.WriteLine("-- group move (no self-carve) --");
+{
+ using var ge = new NotaEngine();
+ ge.SetBpm(120); ge.SetTimeSignature(4, 4);
+ int g1 = ge.AddInstrumentTrack(), g2 = ge.AddInstrumentTrack();
+ foreach (var s in new[] { 0.0, 8, 16, 28 }) ge.AddMidiClip(g1, s, 4);
+ foreach (var s in new[] { 4.0, 12, 20, 24, 32 }) ge.AddMidiClip(g2, s, 4);
+ double[] Starts(int tid)
+ {
+ int idx = tid == g1 ? 0 : 1;
+ ge.TryGetTrackInfo(idx, out var ti);
+ var r = new double[ti.ClipCount];
+ bool lenOk = true;
+ for (int k = 0; k < ti.ClipCount; k++) { ge.TryGetClipInfo(tid, k, out var ci); r[k] = ci.StartBeat; lenOk &= Math.Abs(ci.LengthBeats - 4) < 1e-6; }
+ Check(lenOk, "group move keeps every clip's length (no trimming)");
+ Array.Sort(r); return r;
+ }
+ // Shift every clip (as the UI does: current engine indices) by delta on its own track.
+ bool ShiftAll(double delta)
+ {
+ var mv = new System.Collections.Generic.List<(int, int, int, double)>();
+ foreach (var (tid, row) in new[] { (g1, 0), (g2, 1) })
+ {
+ ge.TryGetTrackInfo(row, out var ti);
+ for (int k = 0; k < ti.ClipCount; k++) { ge.TryGetClipInfo(tid, k, out var ci); mv.Add((tid, k, tid, ci.StartBeat + delta)); }
+ }
+ return ge.MoveClipBlock(mv.ToArray());
+ }
+ string Fmt(double[] a) => string.Join(",", a);
+ Check(ShiftAll(4) && ShiftAll(4), "group move accepted");
+ Check(Fmt(Starts(g1)) == "8,16,24,36", $"track 1 after 1.1→2.1→3.1 ({Fmt(Starts(g1))})");
+ Check(Fmt(Starts(g2)) == "12,20,28,32,40", $"track 2 after 1.1→2.1→3.1 ({Fmt(Starts(g2))})");
+ Check(ShiftAll(12), "group move (+3 bars) accepted");
+ Check(Fmt(Starts(g1)) == "20,28,36,48" && Fmt(Starts(g2)) == "24,32,40,44,52",
+ $"group move +3 bars keeps every clip ({Fmt(Starts(g1))} | {Fmt(Starts(g2))})");
+ // One undo step per group move.
+ ge.Undo();
+ Check(Fmt(Starts(g1)) == "8,16,24,36" && Fmt(Starts(g2)) == "12,20,28,32,40", "group move undoes in one step");
+ // Same-track moves keep their clip index; LastPlacedClips reports them in request order.
+ ge.TryGetClipInfo(g1, 0, out var before0);
+ Check(ge.MoveClipBlock(new[] { (g1, 0, g1, before0.StartBeat + 1.0) }), "single group move accepted");
+ ge.TryGetClipInfo(g1, 0, out var after0);
+ var placed = ge.LastPlacedClips();
+ Check(Math.Abs(after0.StartBeat - before0.StartBeat - 1.0) < 1e-6 && placed.Length == 1 && placed[0] == (g1, 0),
+ "same-track group move keeps the clip index");
+ // A stationary clip in the landing range still gets carved (overwrite semantics).
+ ge.Undo();
+ Check(ge.MoveClipBlock(new[] { (g1, 0, g1, 18.0) }), "carving group move accepted"); // [8,12] → [18,22] over [16,20]
+ var spans = new System.Collections.Generic.List<string>();
+ ge.TryGetTrackInfo(0, out var cti);
+ for (int k = 0; k < cti.ClipCount; k++) { ge.TryGetClipInfo(g1, k, out var ci); spans.Add($"{ci.StartBeat}+{ci.LengthBeats}"); }
+ spans.Sort(string.CompareOrdinal);
+ bool carved = string.Join(" ", spans) == "16+2 18+4 24+4 36+4";
+ Check(carved, $"stationary clip under the landing range is carved to [16,18] ({string.Join(" ", spans)})");
+ // Cross-track: a clip moving down onto the next track while that track's clip at the same
+ // spot moves down too must not carve it.
+ using var xe = new NotaEngine();
+ xe.SetBpm(120); xe.SetTimeSignature(4, 4);
+ int x1 = xe.AddInstrumentTrack(), x2 = xe.AddInstrumentTrack(), x3 = xe.AddInstrumentTrack();
+ xe.AddMidiClip(x1, 0, 4); xe.AddMidiClip(x2, 0, 4);
+ Check(xe.MoveClipBlock(new[] { (x1, 0, x2, 0.0), (x2, 0, x3, 0.0) }), "cross-track group move accepted");
+ xe.TryGetTrackInfo(0, out var xi1); xe.TryGetTrackInfo(1, out var xi2); xe.TryGetTrackInfo(2, out var xi3);
+ Check(xi1.ClipCount == 0 && xi2.ClipCount == 1 && xi3.ClipCount == 1,
+ $"cross-track group move keeps both clips ({xi1.ClipCount}/{xi2.ClipCount}/{xi3.ClipCount})");
+ Check(!xe.MoveClipBlock(new[] { (x2, 5, x2, 0.0) }), "group move rejects a bad clip index");
+}
+
// ============ disarming a track stops its recording ========================
Console.WriteLine("-- disarm stops recording --");
{