smoosic 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/smoosic.js +408 -69
- package/changes.md +95 -0
- package/package.json +19 -1
- package/release/smoosic.js +408 -69
- package/specs/032-split-multimeasure-rests/checklists/requirements.md +40 -0
- package/specs/032-split-multimeasure-rests/contracts/grouping-contract.md +53 -0
- package/specs/032-split-multimeasure-rests/data-model.md +70 -0
- package/specs/032-split-multimeasure-rests/plan.md +81 -0
- package/specs/032-split-multimeasure-rests/quickstart.md +46 -0
- package/specs/032-split-multimeasure-rests/research.md +63 -0
- package/specs/032-split-multimeasure-rests/spec.md +127 -0
- package/specs/032-split-multimeasure-rests/tasks.md +174 -0
- package/specs/033-key-distance-transposition/checklists/requirements.md +35 -0
- package/specs/033-key-distance-transposition/contracts/spelling-api.md +36 -0
- package/specs/033-key-distance-transposition/data-model.md +49 -0
- package/specs/033-key-distance-transposition/plan.md +87 -0
- package/specs/033-key-distance-transposition/quickstart.md +40 -0
- package/specs/033-key-distance-transposition/research.md +82 -0
- package/specs/033-key-distance-transposition/spec.md +132 -0
- package/specs/033-key-distance-transposition/tasks.md +139 -0
- package/specs/034-smz-compressed-scores/checklists/requirements.md +35 -0
- package/specs/034-smz-compressed-scores/contracts/archive-api.md +30 -0
- package/specs/034-smz-compressed-scores/data-model.md +48 -0
- package/specs/034-smz-compressed-scores/plan.md +89 -0
- package/specs/034-smz-compressed-scores/quickstart.md +44 -0
- package/specs/034-smz-compressed-scores/research.md +86 -0
- package/specs/034-smz-compressed-scores/spec.md +137 -0
- package/specs/034-smz-compressed-scores/tasks.md +148 -0
- package/specs/035-paste-special/checklists/requirements.md +35 -0
- package/specs/035-paste-special/contracts/paste-special-api.md +50 -0
- package/specs/035-paste-special/data-model.md +47 -0
- package/specs/035-paste-special/plan.md +83 -0
- package/specs/035-paste-special/quickstart.md +51 -0
- package/specs/035-paste-special/research.md +97 -0
- package/specs/035-paste-special/spec.md +170 -0
- package/specs/035-paste-special/tasks.md +149 -0
- package/specs/036-autosave-recovery/checklists/requirements.md +36 -0
- package/specs/036-autosave-recovery/contracts/autosave-api.md +111 -0
- package/specs/036-autosave-recovery/data-model.md +70 -0
- package/specs/036-autosave-recovery/plan.md +87 -0
- package/specs/036-autosave-recovery/quickstart.md +65 -0
- package/specs/036-autosave-recovery/research.md +105 -0
- package/specs/036-autosave-recovery/spec.md +143 -0
- package/specs/036-autosave-recovery/tasks.md +165 -0
- package/specs/037-fix-new-part-dialog/checklists/requirements.md +38 -0
- package/specs/037-fix-new-part-dialog/contracts/create-part-api.md +84 -0
- package/specs/037-fix-new-part-dialog/data-model.md +68 -0
- package/specs/037-fix-new-part-dialog/plan.md +83 -0
- package/specs/037-fix-new-part-dialog/quickstart.md +58 -0
- package/specs/037-fix-new-part-dialog/research.md +86 -0
- package/specs/037-fix-new-part-dialog/spec.md +144 -0
- package/specs/037-fix-new-part-dialog/tasks.md +174 -0
- package/specs/038-per-measure-beam-groups/checklists/requirements.md +36 -0
- package/specs/038-per-measure-beam-groups/contracts/beam-groups-api.md +74 -0
- package/specs/038-per-measure-beam-groups/data-model.md +75 -0
- package/specs/038-per-measure-beam-groups/plan.md +84 -0
- package/specs/038-per-measure-beam-groups/quickstart.md +53 -0
- package/specs/038-per-measure-beam-groups/research.md +72 -0
- package/specs/038-per-measure-beam-groups/spec.md +146 -0
- package/specs/038-per-measure-beam-groups/tasks.md +132 -0
- package/specs/039-measure-fill-submenu/checklists/requirements.md +35 -0
- package/specs/039-measure-fill-submenu/contracts/measure-fill-api.md +56 -0
- package/specs/039-measure-fill-submenu/data-model.md +79 -0
- package/specs/039-measure-fill-submenu/plan.md +81 -0
- package/specs/039-measure-fill-submenu/quickstart.md +62 -0
- package/specs/039-measure-fill-submenu/research.md +68 -0
- package/specs/039-measure-fill-submenu/spec.md +153 -0
- package/specs/039-measure-fill-submenu/tasks.md +121 -0
- package/specs/040-dynamics-dialog-cleanup/checklists/requirements.md +36 -0
- package/specs/040-dynamics-dialog-cleanup/contracts/dynamics-dialog.md +52 -0
- package/specs/040-dynamics-dialog-cleanup/data-model.md +48 -0
- package/specs/040-dynamics-dialog-cleanup/plan.md +89 -0
- package/specs/040-dynamics-dialog-cleanup/quickstart.md +69 -0
- package/specs/040-dynamics-dialog-cleanup/research.md +80 -0
- package/specs/040-dynamics-dialog-cleanup/spec.md +120 -0
- package/specs/040-dynamics-dialog-cleanup/tasks.md +114 -0
- package/specs/041-delete-special/checklists/requirements.md +35 -0
- package/specs/041-delete-special/contracts/delete-special-api.md +41 -0
- package/specs/041-delete-special/data-model.md +40 -0
- package/specs/041-delete-special/plan.md +93 -0
- package/specs/041-delete-special/quickstart.md +41 -0
- package/specs/041-delete-special/research.md +75 -0
- package/specs/041-delete-special/spec.md +136 -0
- package/specs/041-delete-special/tasks.md +106 -0
- package/specs/042-preserve-music-time-signature/checklists/requirements.md +35 -0
- package/specs/042-preserve-music-time-signature/contracts/rebar-api.md +66 -0
- package/specs/042-preserve-music-time-signature/data-model.md +73 -0
- package/specs/042-preserve-music-time-signature/plan.md +93 -0
- package/specs/042-preserve-music-time-signature/quickstart.md +37 -0
- package/specs/042-preserve-music-time-signature/research.md +102 -0
- package/specs/042-preserve-music-time-signature/spec.md +153 -0
- package/specs/042-preserve-music-time-signature/tasks.md +104 -0
- package/src/application/application.ts +13 -2
- package/src/application/exports.ts +402 -395
- package/src/application/generateVexTests.ts +2 -2
- package/src/render/sui/NoteEntryCaret.ts +117 -16
- package/src/render/sui/autosave.ts +265 -0
- package/src/render/sui/formatter.ts +12 -2
- package/src/render/sui/renderState.ts +4 -4
- package/src/render/sui/scoreChangeState.ts +8 -3
- package/src/render/sui/scoreView.ts +47 -2
- package/src/render/sui/scoreViewOperations.ts +2761 -2555
- package/src/render/sui/staffLineGeometry.ts +82 -0
- package/src/render/sui/tracker.ts +18 -23
- package/src/render/vex/vxMeasure.ts +22 -8
- package/src/render/vex/vxNote.ts +2 -4
- package/src/smo/data/measure.ts +58 -1
- package/src/smo/data/measureModifiers.ts +81 -1
- package/src/smo/data/music.ts +169 -359
- package/src/smo/data/note.ts +1 -1
- package/src/smo/data/noteModifiers.ts +12 -0
- package/src/smo/data/score.ts +179 -7
- package/src/smo/data/scoreModifiers.ts +46 -1
- package/src/smo/data/systemStaff.ts +43 -0
- package/src/smo/xform/beamers.ts +80 -6
- package/src/smo/xform/copypaste.ts +207 -47
- package/src/smo/xform/measureFill.ts +89 -0
- package/src/smo/xform/operations.ts +452 -61
- package/src/smo/xform/rebar.ts +490 -0
- package/src/smo/xform/selections.ts +73 -0
- package/src/ui/components/dialogs/beamGroups.vue +106 -0
- package/src/ui/components/dialogs/deleteSpecial.vue +38 -0
- package/src/ui/components/dialogs/dynamics.vue +16 -3
- package/src/ui/components/dialogs/fileUpload.vue +2 -2
- package/src/ui/components/dialogs/hairpin.vue +3 -3
- package/src/ui/components/dialogs/newPart.vue +148 -184
- package/src/ui/components/dialogs/pasteSpecial.vue +49 -0
- package/src/ui/components/dialogs/recovery.vue +66 -0
- package/src/ui/components/dialogs/save.vue +11 -4
- package/src/ui/components/dialogs/scorePreferences.vue +23 -1
- package/src/ui/components/dialogs/slur.vue +6 -6
- package/src/ui/components/dialogs/tempo.vue +11 -3
- package/src/ui/components/dialogs/timeSignature.vue +18 -3
- package/src/ui/components/dialogs/volta.vue +3 -3
- package/src/ui/dialogs/annotationVue.ts +1 -1
- package/src/ui/dialogs/beamGroupsVue.ts +69 -0
- package/src/ui/dialogs/createPartHelpers.ts +68 -0
- package/src/ui/dialogs/deleteSpecial.ts +57 -0
- package/src/ui/dialogs/dynamicsVue.ts +87 -60
- package/src/ui/dialogs/factory.ts +0 -2
- package/src/ui/dialogs/fileDialogs.ts +63 -22
- package/src/ui/dialogs/instrument.ts +37 -30
- package/src/ui/dialogs/pasteSpecial.ts +59 -0
- package/src/ui/dialogs/preferences.ts +41 -40
- package/src/ui/dialogs/recovery.ts +49 -0
- package/src/ui/dialogs/timeSignature.ts +27 -39
- package/src/ui/fileio/fileInput.ts +12 -3
- package/src/ui/fileio/scoreArchive.ts +151 -0
- package/src/ui/fileio/xhrLoader.ts +26 -0
- package/src/ui/i18n/language.ts +1 -1
- package/src/ui/menus/beams.ts +181 -112
- package/src/ui/menus/edit.ts +44 -6
- package/src/ui/menus/file.ts +21 -1
- package/src/ui/menus/measure.ts +40 -1
- package/tests/autosave.ts +332 -0
- package/tests/beamDotted.ts +56 -0
- package/tests/beamGroups.ts +338 -0
- package/tests/createPart.ts +292 -0
- package/tests/deleteSpecial.ts +350 -0
- package/tests/dynamicsFontSize.ts +132 -0
- package/tests/keyDistanceTransposition.ts +351 -0
- package/tests/measureFill.ts +295 -0
- package/tests/movePart.ts +94 -0
- package/tests/multimeasureRest.ts +338 -0
- package/tests/pasteIntoMeasure.ts +103 -0
- package/tests/pasteSpecial.ts +541 -0
- package/tests/quickBeam.ts +126 -0
- package/tests/rebarMeasures.ts +492 -0
- package/tests/scoreArchive.ts +218 -0
- package/tests/scoreChangeState.ts +2 -0
- package/tests/staffLineGeometry.ts +179 -0
- package/tests/timeRangeSelect.ts +111 -0
- package/tests/timeSignatureDisplay.ts +58 -0
- package/tools/smoosic-schema.json +37 -0
- package/typedoc.ts +2 -1
- package/types/src/application/exports.d.ts +454 -447
- package/types/src/common/promiseHelpers.d.ts +30 -30
- package/types/src/common/vex.d.ts +224 -224
- package/types/src/render/sui/NoteEntryCaret.d.ts +107 -107
- package/types/src/render/sui/autosave.d.ts +99 -0
- package/types/src/render/sui/scoreView.d.ts +23 -0
- package/types/src/render/sui/scoreViewOperations.d.ts +776 -639
- package/types/src/render/sui/svgHelpers.d.ts +88 -88
- package/types/src/render/sui/svgPageMap.d.ts +344 -344
- package/types/src/render/sui/textEdit.d.ts +96 -96
- package/types/src/render/sui/textRender.d.ts +199 -199
- package/types/src/render/vex/smoAdapter.d.ts +47 -47
- package/types/src/render/vex/vxMeasure.d.ts +97 -97
- package/types/src/render/vex/vxNote.d.ts +56 -56
- package/types/src/render/vex/vxSystem.d.ts +71 -71
- package/types/src/smo/data/measure.d.ts +30 -0
- package/types/src/smo/data/measureModifiers.d.ts +568 -513
- package/types/src/smo/data/music.d.ts +74 -32
- package/types/src/smo/data/note.d.ts +498 -498
- package/types/src/smo/data/noteModifiers.d.ts +615 -606
- package/types/src/smo/data/score.d.ts +479 -421
- package/types/src/smo/data/scoreModifiers.d.ts +30 -0
- package/types/src/smo/data/scoreText.d.ts +334 -334
- package/types/src/smo/data/systemStaff.d.ts +14 -0
- package/types/src/smo/xform/beamers.d.ts +23 -1
- package/types/src/smo/xform/copypaste.d.ts +138 -2
- package/types/src/smo/xform/measureFill.d.ts +21 -0
- package/types/src/smo/xform/operations.d.ts +269 -129
- package/types/src/smo/xform/rebar.d.ts +53 -0
- package/types/src/smo/xform/selections.d.ts +168 -154
- package/types/src/smo/xform/undo.d.ts +142 -142
- package/types/src/ui/buttons/button.d.ts +100 -100
- package/types/src/ui/buttons/ribbon.d.ts +70 -70
- package/types/src/ui/common.d.ts +76 -76
- package/types/src/ui/components/dialogs/chordText.d.ts +28 -28
- package/types/src/ui/components/dialogs/textBlockAtomNode.d.ts +20 -20
- package/types/src/ui/components/dialogs/textGroupHtml.d.ts +29 -29
- package/types/src/ui/composable/draggable.d.ts +15 -15
- package/types/src/ui/dialogs/adapter.d.ts +120 -120
- package/types/src/ui/dialogs/annotationVue.d.ts +9 -9
- package/types/src/ui/dialogs/audioSettings.d.ts +32 -32
- package/types/src/ui/dialogs/beamGroupsVue.d.ts +20 -0
- package/types/src/ui/dialogs/chordChangeVue.d.ts +8 -8
- package/types/src/ui/dialogs/createPartHelpers.d.ts +29 -0
- package/types/src/ui/dialogs/customTupletsVue.d.ts +9 -9
- package/types/src/ui/dialogs/deleteSpecial.d.ts +8 -0
- package/types/src/ui/dialogs/dialog.d.ts +203 -203
- package/types/src/ui/dialogs/dynamicsVue.d.ts +10 -10
- package/types/src/ui/dialogs/factory.d.ts +15 -15
- package/types/src/ui/dialogs/fileDialogs.d.ts +4 -4
- package/types/src/ui/dialogs/hairpin.d.ts +35 -35
- package/types/src/ui/dialogs/hairpinVue.d.ts +7 -7
- package/types/src/ui/dialogs/instrument.d.ts +3 -3
- package/types/src/ui/dialogs/keySignatureVue.d.ts +7 -7
- package/types/src/ui/dialogs/libraryVue.d.ts +15 -15
- package/types/src/ui/dialogs/lyricVue.d.ts +8 -8
- package/types/src/ui/dialogs/pasteSpecial.d.ts +8 -0
- package/types/src/ui/dialogs/pedalMarkingVue.d.ts +7 -7
- package/types/src/ui/dialogs/recovery.d.ts +8 -0
- package/types/src/ui/dialogs/rehearsalMark.d.ts +25 -25
- package/types/src/ui/dialogs/rehearsalMarkVue.d.ts +7 -7
- package/types/src/ui/dialogs/slur.d.ts +57 -57
- package/types/src/ui/dialogs/slurVue.d.ts +7 -7
- package/types/src/ui/dialogs/tempo.d.ts +50 -50
- package/types/src/ui/dialogs/tempoVue.d.ts +10 -10
- package/types/src/ui/dialogs/textBlockVue.d.ts +8 -8
- package/types/src/ui/dialogs/textBracket.d.ts +35 -35
- package/types/src/ui/dialogs/textBracketVue.d.ts +7 -7
- package/types/src/ui/dialogs/tie.d.ts +41 -41
- package/types/src/ui/dialogs/volta.d.ts +40 -40
- package/types/src/ui/dialogs/voltaVue.d.ts +7 -7
- package/types/src/ui/fileio/fileInput.d.ts +7 -1
- package/types/src/ui/fileio/library.d.ts +40 -40
- package/types/src/ui/fileio/scoreArchive.d.ts +55 -0
- package/types/src/ui/fileio/xhrLoader.d.ts +7 -0
- package/types/src/ui/menus/file.d.ts +8 -8
- package/types/src/ui/menus/language.d.ts +7 -7
- package/types/src/ui/menus/manager.d.ts +58 -58
- package/types/src/ui/menus/menu.d.ts +159 -159
- package/types/src/ui/menus/partSelection.d.ts +14 -14
- package/types/src/ui/menus/score.d.ts +8 -8
- package/types/src/ui/menus/staffModifier.d.ts +17 -17
- package/types/typedoc.d.ts +148 -147
- package/src/ui/dialogs/dynamics.ts +0 -141
- package/types/src/ui/dialogs/dynamics.d.ts +0 -37
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
description: "Task list for Autosave Buffers and Crash Recovery"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tasks: Autosave Buffers and Crash Recovery
|
|
7
|
+
|
|
8
|
+
**Input**: Design documents from `/specs/036-autosave-recovery/`
|
|
9
|
+
|
|
10
|
+
**Prerequisites**: [plan.md](plan.md), [spec.md](spec.md), [research.md](research.md), [data-model.md](data-model.md), [contracts/autosave-api.md](contracts/autosave-api.md), [quickstart.md](quickstart.md)
|
|
11
|
+
|
|
12
|
+
**Tests**: Included. The constitution asks for regression tests on logic and serialization; the pure settings, store and scheduler logic is tested headless in `tests/autosave.ts`. The dialogs and menu are checked by compilation and [quickstart.md](quickstart.md).
|
|
13
|
+
|
|
14
|
+
**Organization**: Tasks are grouped by user story. The settings, the snapshot store and the scheduler are shared by every story, so they are in the Foundational phase.
|
|
15
|
+
|
|
16
|
+
## Format: `[ID] [P?] [Story] Description`
|
|
17
|
+
|
|
18
|
+
- **[P]**: Can run in parallel (different files, no dependencies on unfinished tasks)
|
|
19
|
+
- **[Story]**: Which user story the task belongs to (US1, US2, US3)
|
|
20
|
+
|
|
21
|
+
## Phase 1: Setup
|
|
22
|
+
|
|
23
|
+
**Purpose**: The test file and its script.
|
|
24
|
+
|
|
25
|
+
- [X] T001 Create `tests/autosave.ts` with the `check()`/failure-count harness used in `tests/scoreChangeState.ts` (print `PASS`/`FAIL`, exit 1 on any failure), a `FakeStorage` class implementing the `AutosaveStorage` interface from [contracts/autosave-api.md](contracts/autosave-api.md) (a `Map`, with a `failWrites` count or flag to make `setItem` throw, and a `quota` byte limit so a write throws when the total would exceed it), and a `FakeTimer` implementing `AutosaveTimer` (records pending timers with their delay, and a `fire()` method that runs the pending callback); register `"test:autosave": "ts-node -P tests/tsconfig.json tests/autosave.ts"` in `package.json`
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Phase 2: Foundational (Blocking Prerequisites)
|
|
30
|
+
|
|
31
|
+
**Purpose**: The settings, snapshot store and scheduler that all three stories use. See [research.md](research.md) R3 to R7 and [data-model.md](data-model.md).
|
|
32
|
+
|
|
33
|
+
**CRITICAL**: No user story work can begin until this phase is complete.
|
|
34
|
+
|
|
35
|
+
- [X] T002 In `src/smo/data/scoreModifiers.ts` add `autosaveInterval` and `autosaveCount` to `SmoScorePreferencesParams` (optional) and to the `SmoScorePreferences` class (defaults 10 and 10); export `autosaveLimits` and the functions `clampAutosaveInterval(value: unknown)` and `clampAutosaveCount(value: unknown)` (round to a whole number, hold to 5-60 and 1-20, use the default when not a finite number); add both fields to `SmoScorePreferences.defaults`; add both to `SmoScorePreferenceNumbers` (extend the `SmoScorePreferenceNumber` type) and apply the clamp functions in the constructor so an absent field gets its default (the existing loop would otherwise set `undefined`); keep `serialize()` writing both
|
|
36
|
+
- [X] T003 [P] Create `src/render/sui/autosave.ts` exporting the `AutosaveStorage`, `AutosaveEntry` and `AutosaveTimer` interfaces and the `AutosaveStore` class per [contracts/autosave-api.md](contracts/autosave-api.md): keys `_smoosicAutosaveIndex` and `_smoosicAutosave.<id>`; `list()` re-reads the index from storage each call and drops entries whose text key is missing (writing the cleaned index back); `add(text, title, time, maxCount)` re-reads the index, uses largest id plus one, writes the text key then the index, trims the oldest entries beyond `maxCount` (removing their text keys), and on a throwing write removes the oldest snapshot and retries until it succeeds or none remain, then returns `null` without throwing; `read(id)` returns `null` if the text is missing or its length differs from the entry's `size`; `trim(maxCount)`. Never touch any other key (Quick Save is `_smoosicScore`). No DOM or browser imports, per [research.md](research.md) R3, R4
|
|
37
|
+
- [X] T004 [P] In `src/render/sui/autosave.ts` add the `AutosaveScheduler` class per [contracts/autosave-api.md](contracts/autosave-api.md): `noteChange(intervalMinutes)` arms a single timer of `intervalMinutes * 60000` ms when idle and does nothing when armed; when the timer fires it goes idle first, then calls `takeSnapshot`, catching a thrown error or rejected promise so the scheduler stays usable; `reset()` clears the timer; `retime(intervalMinutes)` clears and restarts a pending timer from now using the new interval and does nothing when idle; `armed` getter. Add also `createLocalAutosaveStorage(): AutosaveStorage | null`, which returns `window.localStorage` only if a test write and delete of a probe key succeeds and returns `null` otherwise (including when `window` or `localStorage` does not exist), per [research.md](research.md) R5, R11
|
|
38
|
+
- [X] T005 Write the settings tests A1-A5 in `tests/autosave.ts`: legacy params with no autosave fields, clamping and rounding of out-of-range, fractional, `NaN` and non-numeric intervals and counts, serialize-then-construct round trip, and `defaults`. Run `npm run test:autosave` and confirm they pass
|
|
39
|
+
- [X] T006 [P] Write the store tests S1-S11 in `tests/autosave.ts` using `FakeStorage`: empty list, add three, trim on add, `trim`, write failure retry, permanent write failure, entry removed behind the store's back, truncated text, id after removing the newest, the Quick Save key untouched, and two stores sharing one storage. Run `npm run test:autosave` and confirm they pass
|
|
40
|
+
- [X] T007 [P] Write the scheduler tests T1-T9 in `tests/autosave.ts` using `FakeTimer`: arm when idle, one timer for many changes, fire takes one snapshot and goes idle, re-arm after a fire, `reset`, `retime` when armed and when idle, and a rejecting `takeSnapshot`. Run `npm run test:autosave` and confirm they pass
|
|
41
|
+
|
|
42
|
+
**Checkpoint**: Settings, store and scheduler work and are tested. User stories can begin.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Phase 3: User Story 1 - Automatic snapshots while I work (Priority: P1) 🎯 MVP
|
|
47
|
+
|
|
48
|
+
**Goal**: While the user edits, snapshots of the whole score are kept in a rolling set in local storage, without interrupting them.
|
|
49
|
+
|
|
50
|
+
**Independent Test**: Per [quickstart.md](quickstart.md) section 3: with the interval at 5 minutes, edit and wait; one entry appears; wait without editing and none is added; keep editing and the set never exceeds the chosen count. (The settings dialog is User Story 3; until then set `autosaveInterval` and `autosaveCount` through the score preferences in a console, or accept the defaults of 10 and 10.)
|
|
51
|
+
|
|
52
|
+
### Implementation for User Story 1
|
|
53
|
+
|
|
54
|
+
- [X] T008 [US1] In `src/render/sui/scoreView.ts` create the store and scheduler: a private `autosaveStore: AutosaveStore | null` built from `createLocalAutosaveStorage()` (null when storage is unavailable) and an `autosaveScheduler` built with a timer wrapping `window.setTimeout`/`clearTimeout` and a `takeSnapshot` callback that calls the new method `takeAutosave()` (T009). Make `markScoreChanged()` also call `autosaveScheduler.noteChange(this.score.preferences.autosaveInterval)` when the store exists, and make `changeScore()` call `autosaveScheduler.reset()` before it renders the new score. Do not arm the scheduler for the initial `markScoreSaved`/load path, per [research.md](research.md) R5, R6
|
|
55
|
+
- [X] T009 [US1] In `src/render/sui/scoreView.ts` add `async takeAutosave()`: return at once if there is no store; call `SmoScoreArchive.pack(this.storeScore)` right away, before any other `await` (its first statement serializes the score synchronously, so the snapshot is one consistent state even if the user keeps editing while it compresses, per [research.md](research.md) R2), encode the resulting bytes as base64 text (T010), then call `autosaveStore.add(text, this.score.scoreInfo?.name ?? '', Date.now(), this.score.preferences.autosaveCount)`; catch every error and do nothing visible; it must not call `markScoreSaved`/`markScoreChanged` or touch the Quick Save key. See [research.md](research.md) R1 for the encoding
|
|
56
|
+
- [X] T010 [P] [US1] In `src/ui/fileio/scoreArchive.ts` add two small static helpers on `SmoScoreArchive`: `toBase64(bytes: Uint8Array): string` and `fromBase64(text: string): Uint8Array` (chunked `String.fromCharCode` and `btoa`/`atob`, safe for large arrays), used by `takeAutosave` and by recovery; a bad input throws an `Error` with a readable message
|
|
57
|
+
- [X] T011 [US1] In `src/render/sui/scoreView.ts` use `SmoScoreArchive.toBase64` in `takeAutosave()` (T009). Confirm that a snapshot taken from a score with one exposed part still serializes the full `storeScore`
|
|
58
|
+
- [ ] T012 [US1] Run `npx tsc --noEmit -p tsconfig.json` and `npm run test:autosave`; then do the quickstart section 3 manual check with a temporary shortened interval if desired, confirming one snapshot per interval, none without a change, and the set staying at the chosen count *(compile and automated tests done; the manual app check is not done)*
|
|
59
|
+
|
|
60
|
+
**Checkpoint**: User Story 1 is complete: snapshots accumulate and roll. The feature already protects work, though recovery is not yet possible from the UI.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Phase 4: User Story 2 - Recover my work after a crash (Priority: P1)
|
|
65
|
+
|
|
66
|
+
**Goal**: File > Recovery lists the snapshots and loads the chosen one.
|
|
67
|
+
|
|
68
|
+
**Independent Test**: Per [quickstart.md](quickstart.md) sections 4 and 5: with several snapshots stored, open File > Recovery, pick one, confirm, and see that score with the unsaved-changes asterisk; reopen the dialog and every snapshot is still there; empty and damaged cases behave as described.
|
|
69
|
+
|
|
70
|
+
### Implementation for User Story 2
|
|
71
|
+
|
|
72
|
+
- [X] T013 [US2] In `src/render/sui/scoreViewOperations.ts` add `listSnapshots(): (AutosaveEntry & { available: boolean })[]`, newest first, with `available` true when `autosaveStore.read(id) !== null` (empty array when there is no store), and `async recoverSnapshot(id: number): Promise<void>`: read the text (throw `Error('That autosave is no longer available.')` if null), decode it with `SmoScoreArchive.fromBase64` and `SmoScoreArchive.load` (which throws readable errors), then `await this.changeScore(score)` and then `this.markScoreChanged()` so the recovered score is treated as unsaved; on any error the open score is untouched and the error propagates; no snapshot is removed. See [research.md](research.md) R9, R10. `markScoreChanged` also arms the autosave scheduler, which is wanted: the recovered score is not saved to a file
|
|
73
|
+
- [X] T014 [P] [US2] Create `src/ui/components/dialogs/recovery.vue` using `dialogContainer.vue` (label "Recovery"): props `domId`, `entries` (array of `{ id, time, title, available }`, already newest first), `storageAvailable`, `selectCb(id: number)`, `commitCb`, `cancelCb`. Render one selectable row per entry showing a formatted date and time (`toLocaleString`) and the title ("Untitled" if empty); rows with `available` false are shown dimmed with the text "unavailable" and cannot be selected; the selected row is highlighted; when `entries` is empty show "No autosaved scores are available" (and "Browser storage is not available" if `storageAvailable` is false) and no OK; the OK button is disabled until a row is selected. Follow the structure of `library.vue` and `unsavedChanges.vue`
|
|
74
|
+
- [X] T015 [US2] Create `src/ui/dialogs/recovery.ts` exporting `SuiRecoveryDialog(parameters: SuiDialogParams)` using `InstallDialog` and `replaceVueRoot(modalContainerId)` like `libraryVue.ts`: get the rows from `parameters.view.listSnapshots()`, record the chosen id in `selectCb`, and in `afterCloseCb`, if an id was chosen and `await confirmReplaceScore(parameters)` is true, call `parameters.view.recoverSnapshot(id)` and on a thrown error show it with `showLoadError(parameters, error.message)` (both from `./fileDialogs`); cancel does nothing
|
|
75
|
+
- [X] T016 [US2] In `src/ui/menus/file.ts` add a `systemRecoveryOption` (`icon: 'mi history'`, text `Recovery`, value `recovery`, always displayed) whose handler calls `SuiRecoveryDialog` with the same parameter shape as the other file dialogs (`ctor: 'SuiRecoveryDialog'`, `id: 'recovery'`, `modifier: null`, `completeNotifier`, `tracker`, `eventSource`, `view`, `startPromise: menu.closePromise`); add it to `SuiFileMenuOptions` after `systemQuickSave`. Register `'SuiRecoveryDialog'` in the dialog constructor list in `src/ui/i18n/language.ts` next to `'SuiPrintFileDialog'`
|
|
76
|
+
- [ ] T017 [US2] Run `npx tsc --noEmit -p tsconfig.json`; then do the quickstart sections 4 and 5 manual checks (newest-first list, recover, asterisk shown, snapshots remain, empty message, missing and truncated entries marked unavailable, unsaved-changes prompt before replacing) *(compile and automated tests done; the manual app check is not done)*
|
|
77
|
+
|
|
78
|
+
**Checkpoint**: User Stories 1 and 2 work: work is protected and recoverable with the default settings.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Phase 5: User Story 3 - Adjust autosave to my needs (Priority: P2)
|
|
83
|
+
|
|
84
|
+
**Goal**: The Score Preferences dialog has an Autosave section for the interval and count, saved with the score and applied immediately.
|
|
85
|
+
|
|
86
|
+
**Independent Test**: Per [quickstart.md](quickstart.md) section 6: defaults show 10 and 10; values outside the limits are held to them; the values survive saving and reloading the score; lowering the count trims the stored set.
|
|
87
|
+
|
|
88
|
+
### Implementation for User Story 3
|
|
89
|
+
|
|
90
|
+
- [X] T018 [US3] In `src/ui/components/dialogs/scorePreferences.vue` add an "Autosave" section after the default-duration row: a heading row, then two `numberInput.vue` fields with precision 0: "Minutes between autosaves" (`minValue` 5, `maxValue` 60, `initialValue` `preferences.autosaveInterval`) and "Autosaves to keep" (`minValue` 1, `maxValue` 20, `initialValue` `preferences.autosaveCount`). Each `changeCb` writes the clamped value (`clampAutosaveInterval` / `clampAutosaveCount` from `scoreModifiers.ts`) to the reactive `preferences` object, so the existing watcher in `src/ui/dialogs/preferences.ts` sends it to `updateScorePreferences`. Check the `numberInput.vue` props before use and match its callback signature
|
|
91
|
+
- [X] T019 [US3] In `src/render/sui/scoreViewOperations.ts` `updateScorePreferences`, compare the incoming `autosaveInterval` and `autosaveCount` to the current ones before they are replaced; if the count changed call `autosaveStore.trim(count)`, and if the interval changed call `autosaveScheduler.retime(interval)`. Both are no-ops when there is no store. Per [research.md](research.md) R5, R7
|
|
92
|
+
- [X] T020 [US3] In `src/ui/dialogs/preferences.ts` check that the cancel path (`updateScorePreferences(backup)`) restores the previous interval and count and that a snapshot trimmed by a cancelled change is not an issue worth handling: trimming applies as the value is edited, so document in a code comment in `cancelCb` that a trim made while the dialog was open is not undone
|
|
93
|
+
- [X] T021 [P] [US3] In `tools/smoosic-schema.json` add `autosaveInterval` (`integer`, `default` 10, `minimum` 5, `maximum` 60) and `autosaveCount` (`integer`, `default` 10, `minimum` 1, `maximum` 20) to `SmoScorePreferences` under `scoreModifierSchema`
|
|
94
|
+
- [X] T022 [US3] Add a score round-trip test to `tests/autosave.ts` (case A6): build a default score, set `score.preferences.autosaveInterval = 25` and `autosaveCount = 4`, serialize with `SmoScore.serialize` and read back with `SmoScore.deserialize`, and check both values; then deserialize a serialized score whose preferences object has the two fields deleted and check the defaults of 10 and 10. Run `npm run test:autosave`
|
|
95
|
+
- [ ] T023 [US3] Run `npx tsc --noEmit -p tsconfig.json`; then do the quickstart section 6 manual checks *(compile and automated tests done; the manual app check is not done)*
|
|
96
|
+
|
|
97
|
+
**Checkpoint**: All three user stories work.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Phase 6: Polish & Cross-Cutting Concerns
|
|
102
|
+
|
|
103
|
+
- [X] T024 [P] In `src/application/exports.ts` export `SuiRecoveryDialog` (`export * from '../ui/dialogs/recovery'` next to the other dialog exports) and the autosave module (`export * from '../render/sui/autosave'`), and add them to the explicit export list if the file keeps one
|
|
104
|
+
- [X] T025 [P] Add a changelog entry to `changes.md`: autosave snapshots in local storage; File > Recovery; Autosave settings in Score Preferences (`autosaveInterval` 5-60 minutes, `autosaveCount` 1-20, defaults 10 and 10, saved with the score); the separate SmoSchema repository needs the two new `SmoScorePreferences` properties
|
|
105
|
+
- [X] T026 [P] Regenerate declarations with `npm run types`; keep only the files for sources changed here (`autosave.d.ts`, `scoreModifiers.d.ts`, `scoreView.d.ts`, `scoreViewOperations.d.ts`, `scoreArchive.d.ts`, `recovery.d.ts`, `exports.d.ts`) and restore every other changed or untracked file under `types/`
|
|
106
|
+
- [ ] T027 Run the full quickstart sections 1 and 2 and the section 7 manual check (storage unavailable: no errors, empty Recovery dialog)
|
|
107
|
+
- [X] T028 Run `tsc --noEmit -p tsconfig.json` and every `test:*` script in `package.json`; fix regressions
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Dependencies & Execution Order
|
|
112
|
+
|
|
113
|
+
### Phase dependencies
|
|
114
|
+
|
|
115
|
+
- **Setup (Phase 1)**: none.
|
|
116
|
+
- **Foundational (Phase 2)**: depends on T001. Blocks all stories. T002 first (the others read its fields); T003 and T004 are in the same file, so do T003 then T004; T005 depends on T002; T006 on T003; T007 on T004.
|
|
117
|
+
- **User Story 1 (Phase 3)**: depends on Phase 2. T010 can be done at any time after Phase 2; T008, T009, T011 are in the same file and in order.
|
|
118
|
+
- **User Story 2 (Phase 4)**: depends on Phase 2 and on T010 (base64 helpers) and T008 (the store on the view). Can be tested with snapshots made by User Story 1.
|
|
119
|
+
- **User Story 3 (Phase 5)**: depends on Phase 2 and T008 (the store and scheduler it trims and retimes). Independent of User Story 2.
|
|
120
|
+
- **Polish (Phase 6)**: depends on all stories.
|
|
121
|
+
|
|
122
|
+
### Within each story
|
|
123
|
+
|
|
124
|
+
- The view method before the dialog that calls it; the Vue component before the TypeScript dialog that mounts it; the dialog before the menu entry that opens it.
|
|
125
|
+
|
|
126
|
+
### Parallel opportunities
|
|
127
|
+
|
|
128
|
+
- T003/T004 (store and scheduler) are one file, but their tests T006 and T007 are independent of each other once those exist.
|
|
129
|
+
- T010 (`scoreArchive.ts`) is independent of T008 and T009.
|
|
130
|
+
- T014 (`recovery.vue`) can be written while T013 is in progress.
|
|
131
|
+
- T021 (schema) can be done at any time after T002.
|
|
132
|
+
- T024, T025 and T026 touch different files.
|
|
133
|
+
- User Story 2 and User Story 3 can proceed in parallel after User Story 1.
|
|
134
|
+
|
|
135
|
+
```text
|
|
136
|
+
# Example: after Phase 2
|
|
137
|
+
Developer A: T008 -> T009 -> T011 (US1, view) then T013 -> T015 -> T016 (US2)
|
|
138
|
+
Developer B: T010 (base64 helpers) then T018 -> T019 -> T020 (US3)
|
|
139
|
+
Anyone: T014 (recovery.vue), T021 (schema)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Implementation Strategy
|
|
145
|
+
|
|
146
|
+
### MVP first (User Story 1)
|
|
147
|
+
|
|
148
|
+
1. Phase 1 and Phase 2 (settings, store, scheduler, with tests).
|
|
149
|
+
2. Phase 3: snapshots accumulate with the default settings.
|
|
150
|
+
3. Stop and check. The work is protected, though not yet recoverable from the UI. Phase 4 is also P1 and is needed to ship, because snapshots no one can recover are not useful.
|
|
151
|
+
|
|
152
|
+
### Incremental delivery
|
|
153
|
+
|
|
154
|
+
1. Foundational, then User Story 1, then User Story 2: shippable (protected and recoverable with defaults).
|
|
155
|
+
2. User Story 3: adds user control. Can ship separately.
|
|
156
|
+
3. Polish.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Notes
|
|
161
|
+
|
|
162
|
+
- Do not read, write or remove the Quick Save key (`_smoosicScore`) from any autosave code.
|
|
163
|
+
- Snapshots are taken from `storeScore` (the full score), never `score` (which may be one exposed part).
|
|
164
|
+
- Keep `src/render/sui/autosave.ts` free of DOM and browser imports other than inside `createLocalAutosaveStorage`; the store and scheduler take their storage and timer as arguments.
|
|
165
|
+
- The 3 manual-test items in [quickstart.md](quickstart.md) that need a real wait can be shortened by setting the interval to 5 minutes (the minimum).
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Specification Quality Checklist: Fix the Create Part Dialog
|
|
2
|
+
|
|
3
|
+
**Purpose**: Validate specification completeness and quality before proceeding to planning
|
|
4
|
+
|
|
5
|
+
**Created**: 2026-11-06
|
|
6
|
+
|
|
7
|
+
**Feature**: [spec.md](../spec.md)
|
|
8
|
+
|
|
9
|
+
## Content Quality
|
|
10
|
+
|
|
11
|
+
- [x] No implementation details (languages, frameworks, APIs)
|
|
12
|
+
- [x] Focused on user value and business needs
|
|
13
|
+
- [x] Written for non-technical stakeholders
|
|
14
|
+
- [x] All mandatory sections completed
|
|
15
|
+
|
|
16
|
+
## Requirement Completeness
|
|
17
|
+
|
|
18
|
+
- [x] No [NEEDS CLARIFICATION] markers remain
|
|
19
|
+
- [x] Requirements are testable and unambiguous
|
|
20
|
+
- [x] Success criteria are measurable
|
|
21
|
+
- [x] Success criteria are technology-agnostic (no implementation details)
|
|
22
|
+
- [x] All acceptance scenarios are defined
|
|
23
|
+
- [x] Edge cases are identified
|
|
24
|
+
- [x] Scope is clearly bounded
|
|
25
|
+
- [x] Dependencies and assumptions identified
|
|
26
|
+
|
|
27
|
+
## Feature Readiness
|
|
28
|
+
|
|
29
|
+
- [x] All functional requirements have clear acceptance criteria
|
|
30
|
+
- [x] User scenarios cover primary flows
|
|
31
|
+
- [x] Feature meets measurable outcomes defined in Success Criteria
|
|
32
|
+
- [x] No implementation details leak into specification
|
|
33
|
+
|
|
34
|
+
## Notes
|
|
35
|
+
|
|
36
|
+
- When the chosen location falls inside a two-stave part, the request allows "either before or after". The spec picks **after** (see Assumptions); confirm in `/speckit-clarify` if **before** is preferred.
|
|
37
|
+
- The request's "SmoPartInfo.defaults" and "score.staves.length + 1" were rewritten in user terms; the "do not change the default" constraint is kept as FR-013.
|
|
38
|
+
- The title mentions "editing part properties", but all four items concern the Create Part dialog; the Part Properties dialog is only the place where the new part's setting can be changed afterward.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Contract: Create Part
|
|
2
|
+
|
|
3
|
+
The testable surface, followed by the headless test list for `tests/createPart.ts`.
|
|
4
|
+
|
|
5
|
+
## Model (`src/smo`)
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
interface AddPartParams {
|
|
9
|
+
location: number; // one-based, 1..N+1
|
|
10
|
+
instrument: SmoInstrument;
|
|
11
|
+
twoStaves: boolean;
|
|
12
|
+
name: string; // blank = use instrumentLabel
|
|
13
|
+
instrumentLabel: string;
|
|
14
|
+
abbreviation: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class SmoScore {
|
|
18
|
+
/** one-based location -> zero-based insertion index (0..N), never inside a multi-staff part */
|
|
19
|
+
resolveNewPartIndex(location: number): number;
|
|
20
|
+
/** add `delta` to every staff number >= fromIndex held by modifiers, system groups, instrument maps, text groups */
|
|
21
|
+
shiftStaffReferences(fromIndex: number, delta: number): void;
|
|
22
|
+
/** existing; after inserting below the end it now calls shiftStaffReferences(newPos, 1) */
|
|
23
|
+
addStaff(parameters: SmoSystemStaffParams): SmoSystemStaff;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class SmoSystemStaff {
|
|
27
|
+
shiftStaffReferences(fromIndex: number, delta: number): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class SmoOperation {
|
|
31
|
+
/** returns the index of the first new staff */
|
|
32
|
+
static addPart(score: SmoScore, params: AddPartParams): number;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## View (`SuiScoreViewOperations`)
|
|
37
|
+
|
|
38
|
+
| Member | Behavior |
|
|
39
|
+
|--------|----------|
|
|
40
|
+
| `createPart(params: AddPartParams): Promise<void>` | `_undoScore('Create part')` once; `SmoOperation.addPart(storeScore, params)`; `updateInstrumentOffsets` on the new staves; `setNoteInstrumentProperties`; `viewAll`; wait for render |
|
|
41
|
+
| `addStaff(params)` | Unchanged for callers |
|
|
42
|
+
|
|
43
|
+
## Dialog helpers (`src/ui/dialogs/createPartHelpers.ts`, no Vue imports)
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const instrumentChoices: SelectOption[]; // value + label, no duplicates
|
|
47
|
+
function clampPartLocation(value: unknown, staffCount: number): number; // integer 1..staffCount+1; staffCount+1 if not a number
|
|
48
|
+
function resolvePartName(typed: string, instrumentLabel: string): string; // typed.trim() or instrumentLabel
|
|
49
|
+
function instrumentLabelFor(value: string): string; // label for a value, or the value
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Dialog (`SuiCreatePartVue`, `newPart.vue`)
|
|
53
|
+
|
|
54
|
+
- Title "Create Part".
|
|
55
|
+
- Name field, placeholder = `instrumentLabelFor(instrument)`; Abbreviation field.
|
|
56
|
+
- Staff Location: number input, min 1, max N+1, initial N+1.
|
|
57
|
+
- OK calls `view.createPart` with the values above. Cancel does nothing.
|
|
58
|
+
|
|
59
|
+
## Test cases (`tests/createPart.ts`)
|
|
60
|
+
|
|
61
|
+
| # | Case | Expected |
|
|
62
|
+
|---|------|----------|
|
|
63
|
+
| C1 | `clampPartLocation` with 0, 1, N+1, N+2, 2.6, NaN, a string | 1, 1, N+1, N+1, 3, N+1, N+1 |
|
|
64
|
+
| C2 | `resolvePartName` with '', ' ', 'Cello I', ' Vc ' and label 'Cello' | Cello, Cello, Cello I, Vc |
|
|
65
|
+
| C3 | `instrumentChoices` | No two entries share a value; `instrumentLabelFor('cello')` is 'Cello' |
|
|
66
|
+
| P1 | `resolveNewPartIndex` on 3 plain staves, locations 1..4, 9 | 0, 1, 2, 3, 3 |
|
|
67
|
+
| P2 | Staves A, P1+P2, C: location 3 (inside the part) | 3 |
|
|
68
|
+
| P3 | Same score: location 2 (part's first staff), location 4 (after C), location 1 | 1, 3, 0 |
|
|
69
|
+
| P4 | Staves A, P1+P2 only: location 3 and 4 | 3, 3 (3 = after the part; nothing is split) |
|
|
70
|
+
| P5 | Two adjacent two-stave parts: location pointing into each | after that part only |
|
|
71
|
+
| A1 | `addPart` at each of 1..N+1 on 3 plain staves | New staff at the resolved index; the others keep their order |
|
|
72
|
+
| A2 | Name blank, label 'Cello' | `partName` 'Cello' |
|
|
73
|
+
| A3 | Typed name and abbreviation | Exactly those on the new staff |
|
|
74
|
+
| A4 | `preserveTextGroups` on the new part; `SmoPartInfo.defaults.preserveTextGroups` after the call | true; false |
|
|
75
|
+
| A5 | Parts created without `addPart` (`SmoSystemStaff.defaults`) | `preserveTextGroups` false |
|
|
76
|
+
| A6 | `twoStaves` | Two adjacent staves; first has stavesAfter 1 and stavesBefore 0, second the reverse; same name, abbreviation, setting; clefs opposite |
|
|
77
|
+
| A7 | `twoStaves` with a location inside an existing two-stave part | Part intact; new part after it |
|
|
78
|
+
| R1 | A slur on the third staff, then insert at location 1 | The slur's staff selectors, `associatedStaff` and its position are now 3 |
|
|
79
|
+
| R2 | A system group over staves 1-2, insert at location 1 | Group now over staves 2-3 |
|
|
80
|
+
| R3 | A system group over staves 0-2, insert at location 2 | Group now over staves 0-3 |
|
|
81
|
+
| R4 | Insert at N+1 | Nothing shifted; existing groups and modifiers unchanged |
|
|
82
|
+
| R5 | A staff instrument map entry's selectors after an insertion above it | Staff number is one higher |
|
|
83
|
+
| S1 | Serialize and deserialize after creating a one- and a two-stave part | Names, abbreviations, setting, before/after links all kept |
|
|
84
|
+
| S2 | Staff numbers after any insertion | `staves[i].staffId === i` for all i |
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Data Model: Fix the Create Part Dialog
|
|
2
|
+
|
|
3
|
+
No stored fields are added. The entities below are existing ones or short-lived request values.
|
|
4
|
+
|
|
5
|
+
## Create Part Request (`AddPartParams`)
|
|
6
|
+
|
|
7
|
+
What the dialog collects and the operation consumes.
|
|
8
|
+
|
|
9
|
+
| Field | Type | Notes |
|
|
10
|
+
|-------|------|-------|
|
|
11
|
+
| `location` | integer, 1..N+1 | One-based position the new part is to take, N = number of staves in the stored score. Held to the range. |
|
|
12
|
+
| `instrument` | `SmoInstrument` | Sound, clef, staff lines, transposition for the first staff |
|
|
13
|
+
| `twoStaves` | boolean | Add a second staff (opposite clef) to the part |
|
|
14
|
+
| `name` | string | As typed; blank means "use the instrument's name" |
|
|
15
|
+
| `instrumentLabel` | string | Display name of the chosen instrument, used when `name` is blank |
|
|
16
|
+
| `abbreviation` | string | As typed; blank means none |
|
|
17
|
+
|
|
18
|
+
**Validation**: `location` is rounded and held to 1..N+1. `name` and `abbreviation` are trimmed.
|
|
19
|
+
|
|
20
|
+
## Part (existing `SmoPartInfo`, one per staff)
|
|
21
|
+
|
|
22
|
+
The values written for a new part:
|
|
23
|
+
|
|
24
|
+
| Field | One-staff part | First staff of a two-stave part | Second staff of a two-stave part |
|
|
25
|
+
|-------|----------------|---------------------------------|----------------------------------|
|
|
26
|
+
| `partName` | resolved name | resolved name | resolved name |
|
|
27
|
+
| `partAbbreviation` | typed or empty | typed or empty | typed or empty |
|
|
28
|
+
| `preserveTextGroups` | `true` | `true` | `true` |
|
|
29
|
+
| `stavesBefore` | 0 | 0 | 1 |
|
|
30
|
+
| `stavesAfter` | 0 | 1 | 0 |
|
|
31
|
+
|
|
32
|
+
Everything else comes from `SmoPartInfo.defaults`, which is unchanged (`preserveTextGroups: false`).
|
|
33
|
+
|
|
34
|
+
## Placement
|
|
35
|
+
|
|
36
|
+
```text
|
|
37
|
+
index = clamp(round(location), 1, N + 1) - 1 # 0..N, N means append
|
|
38
|
+
if index < N and staves[index].partInfo.stavesBefore > 0:
|
|
39
|
+
index = index + staves[index].partInfo.stavesAfter + 1 # past the end of the part
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| Staves before | Location | Result index | Why |
|
|
43
|
+
|---------------|----------|--------------|-----|
|
|
44
|
+
| A, B, C | 1 | 0 | first |
|
|
45
|
+
| A, B, C | 4 | 3 | after the last |
|
|
46
|
+
| A, B, C | 9 | 3 | held to N + 1 |
|
|
47
|
+
| A, P1+P2 (P2 has stavesBefore 1), C | 3 (index 2 = P2) | 3 | inside part P, moved after it |
|
|
48
|
+
| A, P1+P2, C | 2 (index 1 = P1) | 1 | before the part, not inside it |
|
|
49
|
+
| A, P1+P2 | 4 | 3 | after the last staff, nothing to split |
|
|
50
|
+
|
|
51
|
+
## References shifted by an insertion at index `p`
|
|
52
|
+
|
|
53
|
+
Each staff number `>= p` becomes one higher in:
|
|
54
|
+
|
|
55
|
+
- every staff's modifiers and text brackets: `startSelector.staff`, `endSelector.staff`, `associatedStaff`
|
|
56
|
+
- every system group: `startSelector.staff`, `endSelector.staff`
|
|
57
|
+
- every staff's instrument map entries: `startSelector.staff`, `endSelector.staff`
|
|
58
|
+
- every score text group that has a selector
|
|
59
|
+
|
|
60
|
+
For `p = N` (append) nothing is shifted.
|
|
61
|
+
|
|
62
|
+
## State transitions
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
score with N staves --addPart(location)--> score with N+1 or N+2 staves
|
|
66
|
+
new staff/staves at the resolved index; later staves renumbered; references shifted
|
|
67
|
+
one undo step: score state before addPart
|
|
68
|
+
```
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Implementation Plan: Fix the Create Part Dialog
|
|
2
|
+
|
|
3
|
+
**Branch**: `037-fix-new-part-dialog` (work is on `main`; no feature branch was created) | **Date**: 2026-11-06 | **Spec**: [spec.md](spec.md)
|
|
4
|
+
|
|
5
|
+
**Input**: Feature specification from `/specs/037-fix-new-part-dialog/spec.md`
|
|
6
|
+
|
|
7
|
+
## Summary
|
|
8
|
+
|
|
9
|
+
Move the "where does the new part go, and what is it called" logic out of the dialog and into one tested model operation, `SmoOperation.addPart`, and make the dialog a thin form over it.
|
|
10
|
+
|
|
11
|
+
The operation turns the requested location (1 to N+1) into a staff index, moves it past a two-stave part if it would land inside one, inserts the new staff or staves with their part information (name, abbreviation, Preserve Text Groups on, and the two-stave before/after links), and shifts every reference that points at a staff below the insertion point (staff modifiers, system groups, instrument selectors). The view gets one method, `createPart`, that wraps the operation in a single undo step. The dialog gains the Name and Abbreviation fields, the "Create Part" title, and a Staff Location input that accepts 1 to N+1 and starts at N+1.
|
|
12
|
+
|
|
13
|
+
## Technical Context
|
|
14
|
+
|
|
15
|
+
**Language/Version**: TypeScript; Vue 3 single-file component for the dialog. Tests run with `ts-node`.
|
|
16
|
+
|
|
17
|
+
**Primary Dependencies**: None new. Reuses `SmoScore.addStaff`, `SmoSystemStaff`, `SmoPartInfo`, `SmoSystemGroup`, `numberInput.vue`, `InstallDialog`.
|
|
18
|
+
|
|
19
|
+
**Storage**: N/A. The new part serializes like any part: name, abbreviation, `preserveTextGroups`, `stavesBefore` and `stavesAfter` are existing part fields. `SmoPartInfo.defaults` is not changed.
|
|
20
|
+
|
|
21
|
+
**Testing**: Headless `ts-node` script `tests/createPart.ts` (npm script `test:create-part`), following `tests/voiceCopyPaste.ts`. The model operation and the small pure helpers are tested; the dialog and view method are checked by compilation and the manual steps in [quickstart.md](quickstart.md).
|
|
22
|
+
|
|
23
|
+
**Target Platform**: Browser application and library.
|
|
24
|
+
|
|
25
|
+
**Project Type**: Single project.
|
|
26
|
+
|
|
27
|
+
**Performance Goals**: No new work beyond one extra staff; the score re-renders once, as now.
|
|
28
|
+
|
|
29
|
+
**Constraints**: Inserting a staff above existing staves must not corrupt anything that refers to a staff by number. A two-stave part must never be split. Creating a part is one undo step.
|
|
30
|
+
|
|
31
|
+
**Scale/Scope**: One new model operation, one new score method for shifting staff references, one view method, one dialog change (TypeScript and Vue), one small helper module, one new test file.
|
|
32
|
+
|
|
33
|
+
## Constitution Check
|
|
34
|
+
|
|
35
|
+
*GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
|
|
36
|
+
|
|
37
|
+
| Principle | Assessment |
|
|
38
|
+
|-----------|------------|
|
|
39
|
+
| #1 Serialization | Pass. No new persisted fields. A test serializes and reloads a score after creating a one- and a two-stave part, and checks names, abbreviations, the text-group setting and the before/after links survive. |
|
|
40
|
+
| #2 Editing and transformation logic regression tested | Pass. Placement at every position, the two-stave rule, reference shifting and the part values are headless tests. |
|
|
41
|
+
| #3 Rendering performance | Pass. No rendering change. The view still calls `viewAll` once. |
|
|
42
|
+
| #4 Logical dependencies | Pass. The placement and insertion logic is in `src/smo` with no UI imports. The dialog only collects values and calls the view. |
|
|
43
|
+
|
|
44
|
+
Re-check after Phase 1 design: still passes. No complexity violations.
|
|
45
|
+
|
|
46
|
+
## Project Structure
|
|
47
|
+
|
|
48
|
+
### Documentation (this feature)
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
specs/037-fix-new-part-dialog/
|
|
52
|
+
├── plan.md # This file
|
|
53
|
+
├── research.md # Phase 0 output
|
|
54
|
+
├── data-model.md # Phase 1 output
|
|
55
|
+
├── quickstart.md # Phase 1 output
|
|
56
|
+
├── contracts/
|
|
57
|
+
│ └── create-part-api.md # Phase 1 output
|
|
58
|
+
├── checklists/
|
|
59
|
+
│ └── requirements.md
|
|
60
|
+
└── tasks.md # Phase 2 output (/speckit-tasks - NOT created by /speckit-plan)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Source Code (repository root)
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
src/smo/data/score.ts # resolveNewPartIndex(); shiftStaffReferences(); addStaff() shifts references after an insertion
|
|
67
|
+
src/smo/data/systemStaff.ts # shiftStaffReferences() for a staff's own modifiers, text brackets and instrument selectors
|
|
68
|
+
src/smo/xform/operations.ts # NEW SmoOperation.addPart() and its AddPartParams type
|
|
69
|
+
src/render/sui/scoreViewOperations.ts # createPart(): one undo step around addPart
|
|
70
|
+
src/ui/dialogs/createPartHelpers.ts # NEW pure helpers: clampPartLocation, resolvePartName, instrumentChoices
|
|
71
|
+
src/ui/dialogs/instrument.ts # SuiCreatePartVue: location, name, abbreviation, title, calls createPart
|
|
72
|
+
src/ui/components/dialogs/newPart.vue # Name/Abbreviation fields, Staff Location N+1, shared instrument list
|
|
73
|
+
types/src/... # regenerated declarations for the files above only
|
|
74
|
+
tests/createPart.ts # NEW
|
|
75
|
+
package.json # test:create-part script
|
|
76
|
+
changes.md # changelog entry
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Structure Decision**: Single-project layout as it exists. The new operation sits with the other score operations in `operations.ts`, which is where the existing `addStaff` wrapper is, and which the tests can import without a DOM.
|
|
80
|
+
|
|
81
|
+
## Complexity Tracking
|
|
82
|
+
|
|
83
|
+
No constitution violations to justify.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Quickstart: Validating the Create Part Fixes
|
|
2
|
+
|
|
3
|
+
## 1. Headless checks
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
npm run test:create-part
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Expected: every case in [contracts/create-part-api.md](contracts/create-part-api.md) prints `PASS` and the script exits 0.
|
|
10
|
+
|
|
11
|
+
Also run the suites that touch staves and parts, to check nothing regressed:
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
npm run test:select-voice
|
|
15
|
+
npm run test:paste-special
|
|
16
|
+
npm run test:score-archive
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 2. Compile
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
npx tsc --noEmit -p tsconfig.json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Expected: no errors.
|
|
26
|
+
|
|
27
|
+
## 3. Manual: location
|
|
28
|
+
|
|
29
|
+
Start from a score with three staves, A, B and C.
|
|
30
|
+
|
|
31
|
+
1. Open the part menu > **Create New Part/Stave**. The title is **Create Part**.
|
|
32
|
+
2. Staff Location shows 4. Press OK. The new part is below C.
|
|
33
|
+
3. Undo (one step). Open the dialog, set Staff Location to 1, press OK. The new part is above A.
|
|
34
|
+
4. Undo. Set Staff Location to 2. The new part is between A and B, and A, B and C kept their music and any slurs or hairpins.
|
|
35
|
+
5. Try 0 and 9 in Staff Location: they become 1 and 4.
|
|
36
|
+
|
|
37
|
+
## 4. Manual: two-stave parts
|
|
38
|
+
|
|
39
|
+
1. Create a 2-stave part (use the **2-stave part** toggle) at location 2, so you have A, P1, P2, B, C.
|
|
40
|
+
2. Open the dialog again and set Staff Location to 3 (between P1 and P2). Press OK. The new part is below P2, and P1 and P2 are still together, with their brace.
|
|
41
|
+
3. Set Staff Location to 2 (before P1). The new part is above P1.
|
|
42
|
+
4. With the 2-stave toggle on in the new dialog and a location inside the existing 2-stave part, both new staves land together, after the existing part.
|
|
43
|
+
|
|
44
|
+
## 5. Manual: name and abbreviation
|
|
45
|
+
|
|
46
|
+
1. Open the dialog, choose **Cello**. Name shows "Cello" as placeholder text. Press OK. Open Part Properties: the part is named Cello, abbreviation empty.
|
|
47
|
+
2. Create another, type Name "Cello I" and Abbreviation "Vc. I", press OK. Part Properties shows both.
|
|
48
|
+
3. Create a third and change the instrument after leaving Name empty. The placeholder follows the instrument.
|
|
49
|
+
|
|
50
|
+
## 6. Manual: Preserve Text Groups
|
|
51
|
+
|
|
52
|
+
1. Create a part with the dialog. Part Properties shows **Preserve Text Groups** on. Switch it off, press OK, reopen: it stays off.
|
|
53
|
+
2. Add a staff another way (or open an older score). Its **Preserve Text Groups** is off, as before.
|
|
54
|
+
|
|
55
|
+
## 7. Manual: undo and cancel
|
|
56
|
+
|
|
57
|
+
1. Create a 2-stave part and press Undo once. Both staves are gone.
|
|
58
|
+
2. Open the dialog, change things, press Cancel. The score is unchanged.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Research: Fix the Create Part Dialog
|
|
2
|
+
|
|
3
|
+
No NEEDS CLARIFICATION items remained after the specification. The decisions below come from reading the current code.
|
|
4
|
+
|
|
5
|
+
## R1. Why Staff Location cannot reach the ends today
|
|
6
|
+
|
|
7
|
+
**Finding**: In `newPart.vue` the Staff Location input starts at `staffLength - 1` with limits 1 and `staffLength`. In `SuiCreatePartVue` (`instrument.ts`) the value is a zero-based staff id, initialized to `staves.length - 1`, and `setStaffId` ignores any value `>= staves.length`. So the input mixes one-based limits with a zero-based id, the largest accepted value is the last existing staff rather than the end, the user's value 1 means staff 1 (second), and "after the last staff" is unreachable.
|
|
8
|
+
|
|
9
|
+
**Decision**: The dialog holds a one-based location from 1 to N+1, starting at N+1. The model converts it to a staff index with `index = location - 1` before placement.
|
|
10
|
+
|
|
11
|
+
## R2. Where the placement and insertion logic lives
|
|
12
|
+
|
|
13
|
+
**Decision**: A new `SmoOperation.addPart(score, params)` in `src/smo/xform/operations.ts`. It resolves the index, builds the part information, inserts one or two staves, and returns the index of the first new staff. The view method wraps it with the undo step and the follow-up calls that `addStaff` already makes (`updateInstrumentOffsets`, `setNoteInstrumentProperties`, `viewAll`).
|
|
14
|
+
|
|
15
|
+
**Rationale**: The constitution wants editing logic in `src/smo` and regression-tested. Today the logic is split between the dialog (index and the 2-stave link) and the view (`addStaff`, which also creates system groups), and neither can be tested without a DOM.
|
|
16
|
+
|
|
17
|
+
**Alternatives considered**: Keep the logic in the dialog (untestable). Add the logic to `SmoScore.addStaff` only (it also serves library callers who add one staff at a time and would change their behavior).
|
|
18
|
+
|
|
19
|
+
## R3. Not splitting a two-stave part
|
|
20
|
+
|
|
21
|
+
**Decision**: `SmoScore.resolveNewPartIndex(location)` clamps the one-based location into 1..N+1, converts it to an index, and then, if the staff currently at that index has `partInfo.stavesBefore > 0` (it is not the first staff of its part), moves the index past the end of that part: `index + staff.partInfo.stavesAfter + 1`. The new part therefore goes **after** the existing part, as the spec assumes.
|
|
22
|
+
|
|
23
|
+
**Rationale**: The part links are the data the rest of the program already uses to know a part's extent (`stavesBefore` and `stavesAfter`, see `isPartExposed`, `exposePart`, the part menu). Testing `stavesBefore > 0` on the staff at the insertion index covers a part of any length, not only two staves, at no extra cost. It also leaves insertion at a part's first staff, or just after its last, unchanged.
|
|
24
|
+
|
|
25
|
+
**Alternatives considered**: Moving the new part before the part (equally valid; the spec chose after). Refusing the location with a message (the spec says the user is not shown an error).
|
|
26
|
+
|
|
27
|
+
## R4. Inserting above existing staves: references that must be shifted
|
|
28
|
+
|
|
29
|
+
**Finding**: `SmoScore.addStaff` appends the staff and then bubbles it down to `parameters.staffId`, and calls `numberStaves()`, which renumbers `staffId` on each staff and its measures. Nothing else is updated. Things that refer to a staff by number are therefore left pointing at the wrong staff after an insertion above them:
|
|
30
|
+
|
|
31
|
+
- Staff modifiers (slurs, hairpins, ties, text brackets) on later staves: `startSelector.staff`, `endSelector.staff` and `associatedStaff`.
|
|
32
|
+
- System groups (brackets and braces): `startSelector.staff` and `endSelector.staff`.
|
|
33
|
+
- Each staff's instrument map: `startSelector.staff` and `endSelector.staff`.
|
|
34
|
+
- Score text groups attached to a note by selector.
|
|
35
|
+
|
|
36
|
+
The existing code rarely hit this because the dialog could only add at or near the end. Adding anywhere makes it a real risk, and the same fault would produce slurs drawn on the wrong staff and brackets around the wrong staves.
|
|
37
|
+
|
|
38
|
+
**Decision**: Add `SmoScore.shiftStaffReferences(fromIndex, delta)` which adds `delta` to every staff number that is `>= fromIndex` in the four places above, and call it from `addStaff` after the insertion with `(newPos, 1)`; for an append it changes nothing. Each staff does its own part through a new `SmoSystemStaff.shiftStaffReferences`.
|
|
39
|
+
|
|
40
|
+
**Rationale**: `swapStaves` already uses a per-staff remapping (`mapStaffFromTo`) for the same reason, so there is precedent. A shift is not a swap, so a new routine is needed, but it is a few lines per place.
|
|
41
|
+
|
|
42
|
+
**Alternatives considered**: Re-deriving every selector from the staff's `staffId` at render time (a much larger change). Doing the shift in the view (it would be skipped by library callers of `SmoScore.addStaff`).
|
|
43
|
+
|
|
44
|
+
## R5. System groups for the new staff
|
|
45
|
+
|
|
46
|
+
**Finding**: `SuiScoreViewOperations.addStaff` joins a new staff, when its id is above 0, to the system group of the staff above it, or creates a two-staff group. That sets `grp.endSelector.staff = staffId`, which assumes the group ends at the staff above.
|
|
47
|
+
|
|
48
|
+
**Decision**: Keep the existing behavior (the new part is grouped with the staff above it), but do it after the references are shifted, and widen the group instead of assigning: `end = max(end, newIndex)`. A group that spans the insertion point has already grown by the shift; a group that ended just above is extended to include the new staff, as today. A part at index 0 has no staff above and gets no group, as today.
|
|
49
|
+
|
|
50
|
+
**Rationale**: The spec does not ask to change grouping, so appending behaves exactly as it does now, and the change only keeps a group from shrinking when the insertion is in the middle of one.
|
|
51
|
+
|
|
52
|
+
**Alternatives considered**: Never grouping a new part (changes today's behavior for appends and was not requested). Dropping the join in the middle of a score (surprising, since the same dialog then behaves differently by position).
|
|
53
|
+
|
|
54
|
+
## R6. The part information for the new staves
|
|
55
|
+
|
|
56
|
+
**Decision**: Build a `SmoPartInfo` from `SmoPartInfo.defaults` and set `partName`, `partAbbreviation` and `preserveTextGroups = true`, and pass it in the staff parameters. A one-staff part leaves `stavesBefore` and `stavesAfter` at 0. A two-stave part gives the first staff `stavesAfter = 1, stavesBefore = 0` and the second `stavesAfter = 0, stavesBefore = 1`, with the same name, abbreviation and settings on both (`updatePartInfo` keeps the two staves' information in step the same way).
|
|
57
|
+
|
|
58
|
+
**Finding**: The existing dialog sets only `stavesAfter = 1` on the first staff, through `view.score` (the displayed score, not the stored one), and never sets `stavesBefore` on the second. That cannot be relied on, and the second staff would not be recognized as part of the part, which is also what makes R3 work for parts made by the dialog.
|
|
59
|
+
|
|
60
|
+
**Rationale**: This matches how parts are made when a MusicXML file is read (`xmlToSmo.ts` sets exactly these four values) and what `exposePart` and `isPartExposed` expect.
|
|
61
|
+
|
|
62
|
+
**Alternatives considered**: Setting the values after insertion on the stored score (an extra step that could be skipped). Leaving the second staff unlinked (the bug above).
|
|
63
|
+
|
|
64
|
+
## R7. One undo step
|
|
65
|
+
|
|
66
|
+
**Decision**: `createPart` calls `_undoScore` once before the operation. The old dialog called `view.addStaff` twice for a two-stave part, which recorded two undo steps.
|
|
67
|
+
|
|
68
|
+
**Rationale**: The spec requires creation to undo in one step (FR-014). The score undo buffer stores the whole score, so one snapshot before the change restores everything.
|
|
69
|
+
|
|
70
|
+
## R8. Name and abbreviation
|
|
71
|
+
|
|
72
|
+
**Decision**: The Name placeholder is the label of the instrument chosen in the dialog (for example "Cello"), kept up to date as the choice changes. On confirm, the part name is the typed name if it has non-space text, otherwise that label. The abbreviation is the typed text (trimmed), or empty. A pure helper `resolvePartName(typed, instrumentLabel)` does this and is tested. The instrument list now lives in `createPartHelpers.ts` and is shared by the component and the helper, so the placeholder can never disagree with the list. The list had "Grand Piano" twice; the duplicate is dropped.
|
|
73
|
+
|
|
74
|
+
**Rationale**: One source for the labels avoids the name and the dropdown drifting apart. A helper without Vue imports can be tested headless.
|
|
75
|
+
|
|
76
|
+
**Alternatives considered**: Reading the label back from the select component (couples the model to the UI). Naming the part "Staff N" as the default does (the spec asks for the instrument name).
|
|
77
|
+
|
|
78
|
+
## R9. Preserve Text Groups default
|
|
79
|
+
|
|
80
|
+
**Decision**: `SmoPartInfo.defaults` stays `false`. `addPart` sets `preserveTextGroups = true` on the part information it creates. Loading a score and every other way of creating a staff is unaffected.
|
|
81
|
+
|
|
82
|
+
**Rationale**: The spec requires the global default not to change, only the Create Part dialog's result.
|
|
83
|
+
|
|
84
|
+
## R10. The dialog title and menu text
|
|
85
|
+
|
|
86
|
+
**Decision**: The dialog's label becomes "Create Part". The menu entry text ("Create New Part/Stave") is unchanged.
|