Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
description: "Tasks: Rearrange the song by moving sections with their content"
Tasks: Rearrange the song by moving sections with their content
Input: Design documents from specs/073-section-rearrange/
Prerequisites: plan.md, spec.md, research.md, data-model.md, contracts/abi.md, quickstart.md
Tests: included — the constitution (IV) requires engine behaviour changes to extend
tests/Nota.SmokeTest. Engine tests live in a new tests/Nota.SmokeTest/SectionRearrangeTests.cs
(internal static class SectionRearrangeTests { public static IEnumerable<(bool ok, string label)> Run() },
registered in tests/Nota.SmokeTest/Program.cs next to ArrangementMovesTests.Run()).
Organization: grouped by user story (spec.md US1–US5).
Format: [ID] [P?] [Story] Description
- [P]: can run in parallel (different files, no dependency on unfinished tasks)
- [Story]: US1 … US5 from spec.md
Phase 1: Setup
- T001 Create branch
feat/section-rearrangeoffdevelop(user commits; do not commit or push) - T002 Create
tests/Nota.SmokeTest/SectionRearrangeTests.cs(SPDX two-line header, emptyRun()yielding nothing) and registerforeach (var (ok, label) in SectionRearrangeTests.Run()) Check(ok, label);intests/Nota.SmokeTest/Program.csbesideArrangementMovesTests
Phase 2: Foundational (engine time-mapping primitives)
Purpose: the shared engine machinery every with-content operation uses (research R2–R5).
⚠️ CRITICAL: no user story work before this phase is done.
- T003 In
src/native/nota.engine/src/engine/Engine_Tracks.cpp(anonymous namespace next tolaneSlice/laneInsertGap) add aTimeMaphelper: given(a, b, d)withL = b − a > 0,d ∉ (a, b), return the offset for a position by region —d <= a:[a,b) → −(a−d),[d,a) → +L;d >= b:[a,b) → +(d−b),[b,d) → −L; else 0 — plus the sorted cut points{a, b, d}and the affected window[min(a,d), max(b,d)) - T004 In
Engine_Tracks.cppaddlaneRemap(AutomationLane&, const TimeMap&): keep points outside the window untouched; rebuild the window fromlaneSlicepieces of each region, re-based to the region's new start, each piece starting with an explicit point at its edge value (FR-005); return false when the lane is empty or unchanged - T005 In
Engine_Tracks.cppaddremapTrack(const Track&, const TimeMap&)→ cloned track or null: MIDI clips and audio clips cut at the cut points withmidiSlice/audioSlice(pieces keep audio and notes in time) and shifted by their region's offset; everyautomationlane throughlaneRemap;takesshifted by the offset of theiroriginBeat(research R6); clips wholly outside the window kept as-is - T006 Add
bool Engine::moveTimeRange(double a, double b, double d)(private, declared insrc/native/nota.engine/src/engine/Engine.h) inEngine_Tracks.cpp: newGraph,inheritGraphLevel,remapTrackover every track andmasterTrack,laneRemapong->masterVolume, every section's start shifted by the same map (sections re-sorted), then onepushUndo()+publishRaw(); false (and no undo step) when nothing changed - T007 Add
bool Engine::removeTimeRange(double a, double b)(private) inEngine_Tracks.cpp: clips cut ata/b, the inside dropped, everything>= bshifted by−L(clips, lanes via slices, takes, master volume); sections inside[a,b)removed, later ones shifted; one undo step - T008 Add
bool Engine::sectionOverlaps(int index) constinEngine_Tracks.cpp/Engine.h: true when sectionindex's span intersects another section's by more than1e-6beats (data-model § Section); plus a privateboundaryBeat(int k)—k < n→sections[k].startBeat,k == n→ end of the last section
Checkpoint: primitives compile; no public surface yet.
Phase 3: User Story 1 — Drag a section to reorder the song (P1) 🎯 MVP
Goal: a plain drag of a section's body moves it with all its content to a section boundary.
Independent Test: four sections with a distinct MIDI clip, audio clip and automation ramp in each; drag the third before the second; playback and positions match; one ⌘Z restores.
Tests for User Story 1
- T009 [P] [US1] In
tests/Nota.SmokeTest/SectionRearrangeTests.csadd the engine block from quickstart § 1: sections A [0,8) · B [8,16) · C [16,24), two instrument tracks (one MIDI clip crossing 8), one audio track, a volume ramp, master volume automation; assertMoveSection(2, 1)→ A · C · B with C's content at 8 and B's at 16, the crossing clip cut at 8, automation values at 0, 8⁻, 8, 16⁻, 16, 24 equal the original values at the mapped positions, nothing ≥ 24 moved;MoveSection(0, 3)→ B · C · A;MoveSection(1, 1)and(1, 2)false with no undo step; Undo restores clips, lanes and sections exactly, Redo repeats; names and automatic mode preserved - T010 [P] [US1] In
SectionRearrangeTests.csadd the render checks (SC-002/003) with a deterministic WAV clip (not synth notes): offline render after move + undo equals the render before; the moved section's span renders the same at its new place - T011 [P] [US1] In
SectionRearrangeTests.csadd: a take (specs/067) whose origin is inside B moves with B; the playhead position is unchanged by a move during playback (FR-011)
Implementation for User Story 1
- T012 [US1] Add public
bool Engine::moveSection(int index, int toBoundary)inEngine_Tracks.cpp/Engine.h: reject out-of-range,toBoundary ∈ {index, index+1}(no-op),sectionOverlaps(index), or a boundary beat strictly inside an overlap; elsemoveTimeRange(start, start+len, boundaryBeat(toBoundary)) - T013 [US1] Declare
nota_section_moveandnota_section_overlapsinsrc/native/nota.engine/include/nota/nota_engine.hafternota_engine_set_sections, with the comment block from contracts/abi.md; implement them insrc/native/nota.engine/src/abi/nota_engine_core.cppbesidenota_engine_set_sections(NOTA_OK/NOTA_ERR_INVALID_ARG) - T014 [US1] Add
[LibraryImport]sSectionMove/SectionOverlapsinsrc/managed/Nota.Infrastructure/Interop/NativeMethods.csbesideSetSections; addbool MoveSection(int index, int toBoundary)andbool SectionOverlaps(int index)tosrc/managed/Nota.Application/Engine/IAudioEngine.cs(with doc comments) and implement them insrc/managed/Nota.Infrastructure/Interop/NotaEngine.csnearSetSections - T015 [US1] In
src/managed/Nota.App/ArrangementView.Sections.csaddMode.Reorder: on press over a body without Option/Alt, and when the section does not overlap (_engine.SectionOverlaps(index)), enter Reorder once past the 3 px threshold (Option/Alt or an overlapping section → existingMode.Move; for an overlap set the status text explaining why, FR-009) - T016 [US1] In
ArrangementView.Sections.cscompute the target boundary while dragging: compare the pointer beat with each other section's midpoint (research R8); keep_reorderFrom(start-sorted index) and_reorderTo(0..n); skip boundaries inside an overlap - T017 [US1] In
ArrangementView.Sections.cson release in Reorder: if_reorderTois not a no-op call_engine.MoveSection(from, to), thenClearTimeSelection(),Refresh(),ReloadSections(), raiseSectionsChanged; a no-op or failed call changes nothing (no seek either once the drag threshold was passed) - T018 [US1] Run the US1 smoke tests (T009–T011) via
scripts/build.shand fix until green
Checkpoint: dragging reorders with content; MVP usable without a preview.
Phase 4: User Story 2 — See where the section will land (P1)
Goal: preview while dragging, auto-scroll, Esc cancels, a no-op drop records nothing.
Independent Test: drag across the lane — the insertion bar jumps at midpoints; Esc mid-drag changes nothing; dropping on the original place adds no undo step.
- T019 [US2] In
ArrangementView.Sections.csRender: while in Reorder draw the other sections at their preview positions (the R2 mapping computed in C# for(from, to)), the dragged section as a ghost under the pointer (section fill at reduced opacity), and a 2 px insertion bar in the accent brush at the target boundary — tokens perDESIGN.md/nota-design, no hard-coded colours - T020 [US2] In
ArrangementView.Sections.csadd edge auto-scroll during Reorder (and Move), reusing theEnsureAutoScroll/AutoScrollTickpattern fromsrc/managed/Nota.App/ArrangementView.LaneControl.cs - T021 [US2] In
ArrangementView.Sections.csaddinternal bool CancelGesture()onSectionsControl(restore the working copy viaReloadSections()after clearing the mode, release capture) and expose it fromArrangementView; route Esc to it insrc/managed/Nota.App/MainWindow.Input.csnext to the existingCancelGesturecalls; lost window focus cancels too, as the lane does - T022 [US2] Headless check (done in the throwaway UI harness /tmp/sections073harness, not in the smoke test — the Sections lane is a private Avalonia control) in
SectionRearrangeTests.cs(or the existing headless UI harness): a Reorder drag dropped on its own boundary makes no engine call and adds no undo step;CancelGesture()mid-drag leaves sections and clips unchanged
Checkpoint: US1 + US2 = the full P1 experience.
Phase 5: User Story 3 — Move the section marker alone (P2)
Goal: Option/Alt-drag keeps today's marker-only move; edge resizing never moves content.
Independent Test: ⌥-drag a section two bars — only the section moved; Undo restores it.
- T023 [US3] In
ArrangementView.Sections.csmake sureMode.Moveis reached only with Option/Alt held at press (or for an overlapping section) and behaves exactly as before (SnapBar,SectionsEdited()→ one undo step);EdgeLeft/EdgeRightunchanged - T024 [P] [US3] In
src/managed/Nota.App/PreferencesWindow.csreplace the "Drag section · its edge" row with "Drag section" → "Reorder the song: the section and everything in it move to the marked boundary", "⌥-drag section" → "Move only the section marker, snapped to bars", "Drag section edge" → "Resize it, snapped to bars" (via thenota-shortcutsskill) - T025 [US3] Headless check (UI harness, as T022; the engine side is covered by the smoke test) in
SectionRearrangeTests.cs: a marker-only move changesSectionsbut no clip or automation position
Phase 6: User Story 5 — Duplicate or delete a section with its content (P2)
Goal: menu + palette commands that ripple the rest of the song.
Independent Test: A · B · C → Duplicate with content on B gives A · B · B′ · C, C later by B's length; Delete with content on B gives A · C; Undo restores each.
Tests for User Story 5
- T026 [P] [US5] In
SectionRearrangeTests.cs:DuplicateSectionWithContent(1)→ B′ at 16 with B's content and name (automatic stays automatic), C at 24, automation continuous at 16 and 24;DeleteSectionWithContent(1)→ A · C, C at 8, B's content gone, a clip crossing 8 or 16 cut there; both one undo step; both false on an overlapping section
Implementation for User Story 5
- T027 [US5] Add
bool Engine::duplicateSectionWithContent(int index)inEngine_Tracks.cpp/Engine.h: reject out-of-range / overlapping; reuse theinsertTime(b, L, duplicate=true)track/lane logic (factor its body into a helper that takes the targetGraph) and in the same graph copy every section inside[a,b)to+Land shift sections>= bby+L; one undo step - T028 [US5] Add
bool Engine::deleteSectionWithContent(int index)inEngine_Tracks.cpp/Engine.h: reject out-of-range / overlapping;removeTimeRange(start, start+len) - T029 [US5] Declare/implement
nota_section_duplicate_with_contentandnota_section_delete_with_contentinnota_engine.h/nota_engine_core.cpp; imports inNativeMethods.cs;DuplicateSectionWithContent/DeleteSectionWithContentinIAudioEngine.csandNotaEngine.cs - T030 [US5] In
ArrangementView.Sections.csShowMenu: add Duplicate with content (GlyphKind.Duplicate) next to Duplicate and Delete with content (MenuKit.Danger, GlyphKind.Trash) next to Delete; disabled whenSectionOverlaps; after successClearTimeSelection(),Refresh(),ReloadSections(),SectionsChanged - T031 [US5] Add
internal string DuplicateSectionWithContentAtPlayhead()/DeleteSectionWithContentAtPlayhead()inArrangementView.Sections.cs(status text likeResetSectionNameAtPlayhead, incl. "No section at the playhead" and the overlap reason); registeredit.duplicateSectionWithContent/edit.deleteSectionWithContentinsrc/managed/Nota.Application/Palette/CommandCatalog.cs(category Edit, view "Arrangement") and bind them insrc/managed/Nota.App/MainWindow.Commands.cs
Phase 7: User Story 4 — Move a section without dragging (P3)
Goal: Move earlier / later from the menu and the palette.
Independent Test: A · B · C → Move later on A gives B · A · C; Move earlier disabled on the first.
- T032 [US4] In
ArrangementView.Sections.csShowMenuadd Move earlier / Move later (a new group above Duplicate) calling_engine.MoveSection(i, i-1)/MoveSection(i, i+2); disabled for the first / last section and for an overlapping one - T033 [US4] Add
MoveSectionAtPlayhead(bool later)returning status text inArrangementView.Sections.cs; registeredit.moveSectionEarlier/edit.moveSectionLaterinCommandCatalog.csand bind them inMainWindow.Commands.cs - T034 [P] [US4] In
SectionRearrangeTests.cs:MoveSection(0, 2)on A · B · C gives B · A · C (the "Move later" call shape); palette catalog contains the four new ids (extendPaletteTestsif it enumerates ids)
Phase 8: MCP (FR-014, serves US1/US4/US5)
- T035 [P] In
src/managed/Nota.Mcp/Tools/ProjectTools.csaddmove_section(index, toBoundary),duplicate_section_with_content(index),delete_section_with_content(index)per contracts/abi.md —Mutate(...)returningListed(), an error message when the engine call returns false (out of range, overlap, no-op); descriptions say indices arelist_sectionsorder and everything in the span moves in one undo step - T036 [P] Extend the MCP tests in
tests/Nota.SmokeTest(wherelist_sections/set_sectionsare covered) for the three tools
Phase 9: Polish & Cross-Cutting Concerns
- T037 [P] Add every new
Loc.Tstring (menu entries, palette titles / keywords, status texts, Shortcuts rows) tosrc/managed/Nota.App/Languages/en.jsonandfr.json; run the localization design-token check in the smoke test - T038 Performance check (SC-004): 50 tracks / 500 clips, move a section and time release → redraw ≤ 200 ms; during playback
DropoutCounterstays 0- Measured headless (/tmp/sections073harness
perf): the engine edit takes 0.2 ms; release → redraw is ~400 ms, almost all of it the existing fullArrangementView.Refresh()— Insert silence on the same project costs the same (210–370 ms). Not met at first; met by T047. Dropout during playback not measured on a device.
- Measured headless (/tmp/sections073harness
- T039 Run quickstart.md §§ 2–3 (MCP and UI); capture before/after headless screenshots of the drag preview for the PR (
nota-prskill) - T040 Post a scope note on issue #192 (Duplicate / Delete with content added in clarification) — ask the user before posting
Nota closing tasks (PR gates)
- T041 Run
scripts/build.shuntil native + managed + smoke test are green - T042 AGPL-3.0-only SPDX two-line header on every new source file (
SectionRearrangeTests.cs) - T043 New dependency: N/A
- T044
CHANGELOG.md[Unreleased]→ Added: reorder sections with content (drag, Move earlier / later), Duplicate / Delete with content, MCP tools; Changed: plain section drag now moves content, ⌥-drag moves the marker only - T045 FEATURES.md via
nota-features(Sections bullet); user docs EN + RU vianota-docs; shortcuts vianota-shortcuts(T024) - T046 Engine behaviour change → smoke test extended (T009–T011, T026, T034, T036) ✔ confirm all run in
scripts/build.sh
Dependencies & Execution Order
- Phase 1 → Phase 2 → all stories.
- US1 (Phase 3) needs Phase 2. US2 builds on US1's Reorder mode (same file). US3
touches the same drag code — do after US1. US5 needs Phase 2 only (engine) plus the menu
in
ArrangementView.Sections.cs. US4 needsMoveSectionfrom US1. - MCP (Phase 8) needs T012/T014 (move) and T027–T029 (duplicate/delete).
- Polish last.
Within the engine, T003 → T004 → T005 → T006/T007 → T012/T027/T028. ABI (T013, T029) before managed wrappers (T014, T029) before UI.
Parallel Opportunities
- T009, T010, T011 (tests, one file but independent blocks — write together before T012).
- T024 (PreferencesWindow), T035/T036 (MCP), T037 (strings) touch separate files and can run alongside UI work once the engine API exists.
- US5 engine work (T027–T029) can proceed in parallel with US1/US2 UI work (T015–T021): different files after Phase 2.
Parallel Example: after Phase 2
Task: "T012–T014 moveSection engine + ABI + managed wrapper"
Task: "T027–T029 duplicate/delete with content engine + ABI + managed wrappers"
Task: "T009–T011 SectionRearrangeTests engine blocks"
Implementation Strategy
- MVP = Phases 1–3 (drag reorders with content, one undo step). Validate with T018.
- Add US2 (preview, Esc, auto-scroll) — together with US1 the full P1 experience.
- US3 (marker-only ⌥-drag + Shortcuts), then US5 (duplicate / delete with content), then US4 (menu / palette moves), then MCP.
- Polish and gates; one PR closing #192.
Notes
- Same-file tasks (
ArrangementView.Sections.cs,Engine_Tracks.cpp) are sequential. - Don't commit or push — the user reviews and commits.
Phase 10: Convergence
- T047 Bring release → redraw after a section move/duplicate/delete within 200 ms on 50 tracks / 500 clips (refresh only what the edit touched instead of the full
ArrangementView.Refresh()insrc/managed/Nota.App/ArrangementView.Sections.csSectionContentEdited), and measure dropouts while moving during playback, per SC-004 / FR-011 (partial)SectionContentEditrefreshes withRefreshMovedClips()(no header rebuild; audio peaks kept by source, not index) unless a take lane came or went. Headless, 50 tracks × 10 clips: move → refresh → frame 6–14 ms (was ~400). Reused peaks match a full refresh, cut clips included (/tmp/sections073harnesspeaks). Dropouts while moving during playback not measured on a device (the edit is one snapshot swap, AR-5).
- T048 Pick the drop boundary by the pointer's position against each other section's midpoint (not the ghost's centre) in
SectionsControl.TargetBoundary(src/managed/Nota.App/ArrangementView.Sections.cs), or record the ghost-centre rule in the artifacts, and keep the docs' "until its middle passes" wording in step, per US2/AC1 and plan R8 (contradicts)- Kept the ghost-centre rule (the grab point doesn't change where it lands); recorded in spec US2/AC1 and research R8. The docs already describe it.
- T049 With only one section, make a plain body drag a marker-only move (
Mode.Move) instead of a Reorder that can never land, inSectionsControl.OnPointerPressed(src/managed/Nota.App/ArrangementView.Sections.cs), per spec Edge Cases "Only one section" (contradicts)_sections.Count < 2→Mode.Move.
- T050 Handle take lanes in the ripple edits: a take whose first played frame is inside a deleted section's span is removed (or documented as kept), and Duplicate with content either copies takes in the span or the spec states it doesn't, in
Engine::deleteSectionWithContent/duplicateSectionWithContent(src/native/nota.engine/src/engine/Engine_Tracks.cpp), per FR-015 / FR-016 (partial)- Duplicate copies a take that starts in the section (new id and number) and points the copied comp clips at it; delete drops such a take unless a comp clip elsewhere still plays from it. Smoke-tested.
- T051 Add a save → reopen check that a moved arrangement (clips, automation, sections) round-trips through the project file in
tests/Nota.SmokeTest/SectionRearrangeTests.cs, per FR-013 (partial)- Save →
ProjectService.Load/Applyinto a fresh engine: sections, notes and automation as moved. Smoke-tested.
- Save →