Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
description: "Tasks: Discard and Retry a Take (#185)"
Tasks: Discard and Retry a Take
Input: Design documents from specs/078-discard-and-retry-take/
Prerequisites: plan.md, spec.md, research.md, data-model.md, contracts/, quickstart.md
Tests: Required — the constitution's verification gate (IV) and SC-002 ask for smoke-test
coverage of engine behaviour. Tests live in tests/Nota.SmokeTest/RetryTakeTests.cs.
Organization: grouped by user story (spec.md priorities).
Format: [ID] [P?] [Story] Description
- [P]: can run in parallel (different files, no dependency on an unfinished task)
- [Story]: US1–US4 from spec.md
Phase 1: Setup
- T001 Add
src/engine/Engine_TakeRetry.cpp(SPDX header, why-comment) to the engine source list insrc/native/nota.engine/CMakeLists.txt
Phase 2: Foundational (blocks every story)
- T002 Declare the take-attempt state in
src/native/nota.engine/src/engine/Engine.hper data-model.md:TakeAttempt { bool active; bool session; std::vector<std::pair<int32_t, std::shared_ptr<Track>>> baseTracks; size_t undoBase; std::vector<UndoEntry> redoSaved; bool countedIn; int32_t sessionTrackId; int32_t sessionScene; },std::atomic<uint32_t> takeEpoch_,double retryStartBeat_ = NaN, and private methodsopenTakeAttempt(bool session),noteTakeTrack(int32_t),closeTakeAttempt(),discardTake(),abortAudioRecording(), publicint32_t retryTake() - T003 Implement
openTakeAttempt/noteTakeTrack(first write wins; master track id included) /closeTakeAttemptinsrc/native/nota.engine/src/engine/Engine_TakeRetry.cpp - T004 In
pushUndo(src/native/nota.engine/src/engine/Engine.cpp) decrementtakeAttempt_.undoBasewhen the oldest entry is trimmed pastkMaxUndoDepth - T005 Add a
uint32_t epochtoRecordedNote,RecordedCtl,RecordedExpr(Engine.h); stamp it on the audio thread from one relaxed load oftakeEpoch_per block insrc/native/nota.engine/src/engine/Engine_Render.cpp(live, routed, loop-wrap split, controller and expression pushes); drop stale entries inpoll()andcollectRecordedExpr() - T006 Implement
abortAudioRecording()insrc/native/nota.engine/src/engine/Engine_Recording.cpp: taps off,releaseAudioInputIfIdle, drain, clearaudioCaptureBuf_,capturePasses_, loop-capture fields,audioRecordTrackId_,recordSessionAudio_— no materialise - T007 Implement
discardTake()inEngine_TakeRetry.cpp:recording_ = false; end automation writes without committing (reusefinishAllWritespaths, then restore lanes via base tracks);abortAudioRecording(); clear MIDI fold state (takeNotes_,takeCtls_,ctlBatch_,pendingExpr_,ctlStopPending_,resetCtlFold()); bumptakeEpoch_; republish base tracks raw (Arrangement: whole tracks still present; Session: only the target slot copied into the current track);recomputePdc()/reapplyRackMacros()/reapplyCcRoutes()after the restore; trimundoStack_toundoBase, restoreredoStack_; close the attempt - T008 Add
nota_engine_retry_taketosrc/native/nota.engine/include/nota/nota_engine.h(doc per contracts/c-abi.md) and its shim insrc/native/nota.engine/src/abi/nota_engine_core.cpp - T009 [P] Managed mirror:
RetryTakeResult { None = 0, Arrangement = 1, Session = 2, Failed = -1 }andRetryTakeResult RetryTake()insrc/managed/Nota.Application/Engine/IAudioEngine.cs/EngineContracts.cs; P/Invoke insrc/managed/Nota.Infrastructure/Interop/NativeMethods.csand wrapper inNotaEngine*.cs; update any otherIAudioEngineimplementations (test doubles)
Checkpoint: the engine can discard a take; nothing calls it yet.
Phase 3: User Story 1 — Throw the take away and go again (P1) 🎯 MVP
Goal: one command discards an Arrangement take and records again from the same place.
Independent Test: quickstart.md automated scenarios 1, 2, 4, 5, 6, 9.
Tests
- T010 [US1] Create
tests/Nota.SmokeTest/RetryTakeTests.cs(SPDX header) and register it intests/Nota.SmokeTest/Program.cs; scenarios: MIDI from stop with count-in (clip removed, playhead at start, count-in running, second take only, one Undo → pre-first-take, no Redo); retry into an existing clip restores its notes; audio via internal resample source (no clip, then one clip at the original start); punch-in from beat 4 at beat 8 → restarts at 4 with no count-in; automation written during the take is gone; a note released after the retry is not in the new take; nothing recording →None, project unchanged
Implementation
- T011 [US1] Call
openTakeAttempt(false)insetRecording(true)before the MIDI clip is created and recordcountedIn; callcloseTakeAttempt()onsetRecording(false)insrc/native/nota.engine/src/engine/Engine_Recording.cpp - T012 [US1] Call
noteTakeTrack(trackId)frombeginAutomationWritewhile an attempt is open, before the lane is created, insrc/native/nota.engine/src/engine/Engine_Automation.cpp - T013 [US1] Implement the Arrangement branch of
retryTake()inEngine_TakeRetry.cpp: remembercountedIn,recordStartedTransport_,recordReturnBeat_;discardTake();transportStop(); seek torecordReturnBeat_when the take started the transport; restart through an internal start that takesallowCountIn(refactorsetRecording(true)body intostartRecordingTake(bool allowCountIn)); return 1, or −1 when nothing could start - T014 [US1]
RetryTakeCommandinsrc/managed/Nota.Presentation/ViewModels/TransportViewModel.cs: callRetryTake();Arrangement→ keepRecordOn,TracksChanged, messagetransport.take_discarded_retrying;None→transport.no_take_to_discard;Failed→ setRecordOnfalse without re-calling the engine and show the record-start failure message - T015 [US1] Localization keys
commands.discard_and_retry_take,transport.take_discarded_retrying,transport.no_take_to_discardinsrc/managed/Nota.Application/Localization/en.jsonand the bundled languages the localization flow requires
Checkpoint: MVP — Arrangement retry works through the view-model.
Phase 4: User Story 2 — Retry a loop-recorded take (P2)
Goal: no pass of a multi-pass loop take survives a retry; Replace-mode removals come back.
Independent Test: quickstart.md scenario 3.
- T016 [US2] Add loop scenarios to
tests/Nota.SmokeTest/RetryTakeTests.cs: audio loop take with ≥2 passes → retry →TakeCountunchanged from before; MIDI Replace pass that removed notes → retry → clip notes equal the pre-take notes - T017 [US2] Verify
abortAudioRecording()/discardTake()cover loop punch state (captureLoop_,captureWrapped_,capturePasses_,replaceUpTo_,appliedReplaceUpTo_) and fix gaps inEngine_TakeRetry.cpp/Engine_Recording.cpp
Phase 5: User Story 3 — Reach it the way that fits the session (P2)
Goal: shortcut, menu, palette, MCP.
Independent Test: quickstart.md scenario 10; manual step 1.
- T018 [P] [US3] Add
C("transport.retryTake", Loc.T("commands.discard_and_retry_take"), Loc.T("common.transport"), Shortcut.Cmd('.'), "undo restart retry discard take again redo record over")aftertransport.recordinsrc/managed/Nota.Application/Palette/CommandCatalog.cs - T019 [US3] Bind
transport.retryTaketo_vm.Transport.RetryTakeCommandinsrc/managed/Nota.App/MainWindow.Commands.cs; add the Transport menu item withapp:Commands.Id="transport.retryTake"insrc/managed/Nota.App/MainWindow.axaml; make sure⌘.reaches it from the keyboard handler inMainWindow.Input.cs(not swallowed by a focused text box only when typing) - T020 [P] [US3] MCP tool
retry_takeinsrc/managed/Nota.Mcp/Tools/TransportTools.csreturning{ result: none|arrangement|session|failed }(contracts/commands.md) - T021 [US3] Smoke check in
RetryTakeTests.cs(orPaletteTests) that the catalog holdstransport.retryTakewith⌘.
Phase 6: User Story 4 — Retry a take recorded into a Session slot (P3)
Goal: only the slot's take is dropped; other clips keep playing; pending until the quantum.
Independent Test: quickstart.md scenarios 7, 8.
- T022 [US4] Session scenarios in
tests/Nota.SmokeTest/RetryTakeTests.cs: MIDI slot with another track's slot playing → retry → other slot still state 3; target state 5 until the quantum, then 4; stop → target slot plays; fresh slot removed then re-created (no undo residue); audio slot retry → materialised take starts on the quantum (trimmed length) - T023 [US4] Call
openTakeAttempt(true)inrecordSessionSlotbeforeaddSessionMidiClip, store track/scene; close it infinalizeSessionRecordandcancelSessionCountIninsrc/native/nota.engine/src/engine/Engine_Session.cpp - T024 [US4] Session branch of
retryTake()inEngine_TakeRetry.cpp: remember track/scene/audio;discardTake()(slot restore only, other players untouched, transport untouched); for audio setretryStartBeat_to the next launch-quantum boundary (now when quantize is 0);recordSessionSlot(track, scene); return 2 - T025 [US4] Trim frames before
retryStartBeat_in the session branch ofstopAudioRecording()(Engine_Recording.cpp) and reset it; also reset it on discard / close - T026 [US4] Slot state 5 "record pending" in
sessionSlotState(Engine_Session.cpp) and the ABI doc innota_engine.h;TryGetSessionRecordTargetunchanged - T027 [US4] Session grid draws state 5 as record-pending (the queued visual in record colour) in
src/managed/Nota.App/SessionView.Grid.cs;TransportViewModel/ MainWindow refresh the Session view after aSessionresult
Phase 7: Polish & Cross-Cutting
- T028 [P]
CHANGELOG.md[Unreleased]→ Added entry (closes #185) - T029 [P] FEATURES.md via the nota-features skill
- T030 [P] Preferences → Shortcuts list via the nota-shortcuts skill
- T031 [P] User docs EN + RU (recording page) via the nota-docs skill in
../nota-docs - T032 Run
scripts/build.sh— native + managed + smoke test green - T033 Re-check the Nota Compliance Checklist in spec.md; run
/speckit-converge
Dependencies & Execution Order
- Phase 1 → Phase 2 → stories. T002 before T003–T007; T008 after T007; T009 after T008.
- US1 (Phase 3) is the MVP and is needed by US2 (same retry path) and US3's command (T014).
- US3 T018/T020 can start once T009 is done; T019 needs T014.
- US4 needs Phase 2 and T013's refactor (shared
retryTake()entry); independent of US2/US3. - Polish after the stories.
Parallel Opportunities
- T009 (managed mirror) alongside T010 (test scaffolding).
- T018 and T020 in parallel (different projects).
- T028–T031 in parallel.
Implementation Strategy
- Phases 1–2, then US1 → run the smoke test → MVP.
- US2 (mostly verification), US3 (surface), US4 (Session).
- Polish,
scripts/build.sh, converge.
Phase 8: Convergence
- T034 Restart a Session take's count-in from its first click when retried during it, in
src/native/nota.engine/src/engine/Engine_TakeRetry.cpp, per Edge Cases: command during the count-in (partial) - T035 Release the Record button when recording ended outside the UI (MCP
retry_takefailed) by following the engine inTransportViewModel.Tick(src/managed/Nota.Presentation/ViewModels/TransportViewModel.cs), per FR-009 / FR-010 (partial)
Phase 9: Review of PR #486
- T036 Remember a track before its first automation write in the take (
beginAutomationWrite), so a retry drops lanes written on tracks the take doesn't record, per FR-002 (T012 had been marked done without it) - T037 Mark the take's own checkpoints (
UndoEntry::take); a discard drops only those and removes the take from the user's checkpoints made meanwhile, so their undo steps survive, per FR-003 / FR-011 - T038 Close the take attempt when disarming ends the take, and return None when nothing records, so a retry never deletes a kept take, per FR-010
- T039 Session MIDI retry: the audio thread adopts the new take epoch only when the slot has relaunched (held keys reseeded there), per FR-012 / FR-013
- T040 Session retry relaunches the slot whatever its launch mode (Toggle), per FR-012
- T041 Capture epoch marker frames in the input ring: a retried audio take drops what an in-flight block wrote for the discarded one, per FR-002
- T042 Session audio retry notes the boundary frame when the capture crosses it (tempo changes after it don't move the trim), per FR-012
- T043 Disarming one of two recording tracks keeps its part and leaves the attempt for the capture still running (
keepTakeTrack), per FR-010 / FR-014 - T044 Every take started without a retry syncs the audio thread's take epoch and cancels a Session retry still waiting for its slot (
syncTakeEpoch), per FR-007 - T045 A retry after a partial keep drops the former take checkpoints that end up changing nothing (no empty Undo), per FR-003