smoosic 2.0.3 → 2.0.4
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 +395 -67
- package/changes.md +85 -0
- package/package.json +98 -82
- package/release/smoosic.js +395 -67
- 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/src/application/application.ts +13 -2
- package/src/application/exports.ts +401 -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/scoreChangeState.ts +8 -3
- package/src/render/sui/scoreView.ts +47 -2
- package/src/render/sui/scoreViewOperations.ts +2706 -2555
- package/src/render/sui/staffLineGeometry.ts +82 -0
- 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 +167 -2
- 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 +403 -61
- package/src/smo/xform/selections.ts +7 -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 +5 -0
- 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/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/scoreArchive.ts +218 -0
- package/tests/scoreChangeState.ts +2 -0
- package/tests/staffLineGeometry.ts +179 -0
- package/tests/timeSignatureDisplay.ts +58 -0
- package/tools/smoosic-schema.json +37 -0
- package/typedoc.ts +1 -1
- package/types/src/application/exports.d.ts +453 -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 +759 -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 +476 -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 +245 -129
- package/types/src/smo/xform/selections.d.ts +154 -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 +147 -147
- package/src/ui/dialogs/dynamics.ts +0 -141
- package/types/src/ui/dialogs/dynamics.d.ts +0 -37
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
description: "Task list for Split Multimeasure Rests at Landmarks"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tasks: Split Multimeasure Rests at Landmarks
|
|
7
|
+
|
|
8
|
+
**Input**: Design documents from `/specs/032-split-multimeasure-rests/`
|
|
9
|
+
|
|
10
|
+
**Prerequisites**: [plan.md](./plan.md), [spec.md](./spec.md), [research.md](./research.md), [data-model.md](./data-model.md), [contracts/grouping-contract.md](./contracts/grouping-contract.md), [quickstart.md](./quickstart.md)
|
|
11
|
+
|
|
12
|
+
**Tests**: Included. The plan commits to a headless `tests/multimeasureRest.ts` (cases G1 to G24) for the grouping logic. Drawing is checked manually (M1 to M10).
|
|
13
|
+
|
|
14
|
+
**Organization**: Tasks are grouped by user story. The landmark classification and the rewritten grouping loop are shared by all three stories, so they are the foundation; each story then adds its tests and the drawing or layout work it needs.
|
|
15
|
+
|
|
16
|
+
## Format: `[ID] [P?] [Story] Description`
|
|
17
|
+
|
|
18
|
+
- **[P]**: Can run in parallel (different files, no dependencies on incomplete tasks)
|
|
19
|
+
- **[Story]**: Which user story this task belongs to (US1, US2, US3)
|
|
20
|
+
|
|
21
|
+
## Path Conventions
|
|
22
|
+
|
|
23
|
+
Single project: `src/`, `tests/`, repo-root `package.json`.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Phase 1: Setup
|
|
28
|
+
|
|
29
|
+
- [X] T001 Add the script `"test:multimeasure-rest": "ts-node -P tests/tsconfig.json tests/multimeasureRest.ts"` to `package.json`, next to the existing `test:select-voice` entry.
|
|
30
|
+
- [X] T002 Create `tests/multimeasureRest.ts` with the scaffold and builders: header comment pointing at `specs/032-split-multimeasure-rests/contracts/grouping-contract.md`; the dynamic-ctor-init calls and imports used by `tests/selectVoice.ts`; the `failures` counter and `check()` helper; the final summary block; `buildScore(staffCount = 1)` returning a score of 12 measures in 4/4 where every measure contains only rests (the default measures are rests), exposed as a part by leaving `partInfo.expandMultimeasureRests` false on `staves[0]`; and helpers `blocks(score)` returning the list of `start:length` strings for measures with `svg.multimeasureLength > 0` (1-based start), `hidden(score)` returning the 1-based indexes with `svg.hideMultimeasure`, and `accounted(score)` returning true when the block lengths plus the measures that are neither a block start nor hidden add up to the measure count. Add landmark helpers: `addRehearsal(score, m)` (via `measure.addRehearsalMark`), `setRepeatSymbol(score, m, symbolName)` (set `measure.repeatSymbol = true` and the symbol on `getRepeatSymbol()`), `setStartBarline(score, m, barline)`, `setEndBarline(score, m, barline)`, `setKey(score, m, key)` and `setTime(score, m, beats, duration)` (applied to the measure and all later measures, as a real change carries forward), `setTempo(score, m, display)` (a tempo with a different `bpm`, applied to measure m and later), and `setInstrument(score, m)` (an entry in `staves[0].measureInstrumentMap`).
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Phase 2: Foundational (Blocking Prerequisites)
|
|
35
|
+
|
|
36
|
+
**Purpose**: The classification and grouping that every story relies on.
|
|
37
|
+
|
|
38
|
+
**CRITICAL**: No user story work can begin until this phase is complete.
|
|
39
|
+
|
|
40
|
+
- [X] T003 [P] In `src/smo/data/measure.ts`, add `multimeasureEndSymbol: SmoRepeatSymbol | null` to the `svg` runtime interface (next to `multimeasureEndBarline`) and to its default (`null`), importing `SmoRepeatSymbol` if needed. It is not serialized.
|
|
41
|
+
- [X] T004 In `src/smo/data/score.ts`, add the three helpers from [data-model.md](./data-model.md): `isMultimeasureBlocked(measureIndex)`, `isMultimeasureStartLandmark(measureIndex)` and `isMultimeasureEndLandmark(measureIndex)`, implemented exactly as specified there (volta on any staff, plus the legacy measure-0-of-a-multi-staff-part block; start landmarks: rehearsal mark, repeat symbol Segno or Coda, instrument map entry at measure above 0, non-plain start barline, and for staff 0 a key signature, time signature or displayed-tempo difference from the previous measure; end landmarks: repeat symbol ToCoda, DcAlCoda, DcAlFine, DsAlCoda, DsAlFine or Fine, and a non-plain end barline). Use `SmoBarline.barlines.singleBar` and `.noBar`, `SmoRepeatSymbol.symbols`, `SmoTimeSignature.equal` and `SmoTempo.eq`. Leave `isMultimeasureRest` unchanged and add a doc comment that it is superseded by the new helpers but kept for outside users.
|
|
42
|
+
- [X] T005 In `src/smo/xform/operations.ts`, rewrite `computeMultipartRest` as specified in [data-model.md](./data-model.md): keep the early return for `expandMultimeasureRests`; walk the measures with the new block rule (start measure may carry start landmarks; an end landmark on a measure closes the block after it; join only rest, unblocked measures with no `restBreak` and no start landmark; `forceRest` as before); for every block set length, end barline from the last measure, `multimeasureEndSymbol` from the last measure's end-type symbol (null if none) and `hideMultimeasure` on every staff; and for every measure that is not a block start or a hidden block member, reset `multimeasureLength` to 0, `multimeasureEndBarline` to the single bar, `multimeasureEndSymbol` to null and `hideMultimeasure` to false, on every staff.
|
|
43
|
+
- [X] T006 Run `npx tsc --noEmit -p tsconfig.json` and fix any errors.
|
|
44
|
+
|
|
45
|
+
**Checkpoint**: The grouping follows the new rules; nothing yet exercises them.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Phase 3: User Story 1 - A rehearsal mark inside a long rest starts the next multimeasure rest (Priority: P1) MVP
|
|
50
|
+
|
|
51
|
+
**Goal**: A rehearsal mark splits a run of rests without a lone bar between the blocks, and edits take effect on the next layout.
|
|
52
|
+
|
|
53
|
+
**Independent Test**: quickstart.md section 3, steps 1 to 4.
|
|
54
|
+
|
|
55
|
+
### Tests for User Story 1
|
|
56
|
+
|
|
57
|
+
- [X] T007 [P] [US1] In `tests/multimeasureRest.ts`, add cases G1 to G5 (no landmarks, rehearsal mark in the middle, on the first measure, on the last measure, two marks) and G21 and G22 (expand multimeasure rests on, and a volta ending), each also checking `accounted(score)`.
|
|
58
|
+
- [X] T008 [US1] Run `npm run test:multimeasure-rest` and fix `score.ts` / `operations.ts` until G1 to G5, G21 and G22 pass.
|
|
59
|
+
|
|
60
|
+
### Implementation for User Story 1
|
|
61
|
+
|
|
62
|
+
- [X] T009 [US1] In `src/render/sui/formatter.ts` `SuiLayoutFormatter.layout()`, call `SmoOperation.computeMultipartRest(this.score)` at the start when `this.score.isPartExposed()` is true, importing `SmoOperation`; first confirm there is no circular import problem with `operations.ts` (if there is, call it from the code that invokes `layout()` instead, for example in `scoreRender.ts`).
|
|
63
|
+
- [X] T010 [US1] Run `npx tsc --noEmit -p tsconfig.json` and `npm run build`; fix any errors.
|
|
64
|
+
- [ ] T011 [US1] Manual validation: quickstart.md section 3, steps 1 to 4 and 12 (M1, M7).
|
|
65
|
+
|
|
66
|
+
**Checkpoint**: Rehearsal marks split a long rest correctly.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Phase 4: User Story 2 - Key, time signature and tempo changes inside a long rest (Priority: P1)
|
|
71
|
+
|
|
72
|
+
**Goal**: Key, time and tempo changes split the rest and the change is shown at the start of the second block.
|
|
73
|
+
|
|
74
|
+
**Independent Test**: quickstart.md section 3, step 5.
|
|
75
|
+
|
|
76
|
+
### Tests for User Story 2
|
|
77
|
+
|
|
78
|
+
- [X] T012 [P] [US2] In `tests/multimeasureRest.ts`, add cases G6 to G10 (key change, time change, displayed tempo change, undisplayed tempo change, key change together with a rehearsal mark).
|
|
79
|
+
- [X] T013 [US2] Run `npm run test:multimeasure-rest` and fix until G6 to G10 pass.
|
|
80
|
+
|
|
81
|
+
### Implementation for User Story 2
|
|
82
|
+
|
|
83
|
+
- [ ] T014 [US2] Manual validation: quickstart.md section 3, step 5 (M2, M3, M4): confirm the new key signature, time signature and tempo are drawn at the start of the second rest. If one is not drawn, read `calculateBeginningSymbols` and the hidden-measure carry-over in `src/render/sui/formatter.ts` (around lines 780 to 795 and 833 to 866) and `createMeasureModifiers` in `src/render/vex/vxMeasure.ts`, and fix the cause in the drawing code (the force flags are computed against the measure to the left, which may be a hidden measure); record what was found.
|
|
84
|
+
|
|
85
|
+
**Checkpoint**: Signature and tempo changes split the rest and are visible.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Phase 5: User Story 3 - Landmarks that end a section break the rest after their measure (Priority: P1)
|
|
90
|
+
|
|
91
|
+
**Goal**: D.S., D.C., To Coda, Fine and end barlines end a block and are shown on it; Segno, Coda and start barlines begin the next block.
|
|
92
|
+
|
|
93
|
+
**Independent Test**: quickstart.md section 3, steps 6 to 9.
|
|
94
|
+
|
|
95
|
+
### Tests for User Story 3
|
|
96
|
+
|
|
97
|
+
- [X] T015 [P] [US3] In `tests/multimeasureRest.ts`, add cases G11 to G20 and G23 (Segno and Coda, D.S. al Coda, To Coda, D.C. al Fine on the first measure, end-repeat and start-repeat barlines, double bar both ways, instrument change, a rehearsal mark together with a D.S., two staves). Include in G13, G14 and G15 checks that `svg.multimeasureEndSymbol` is set on the block's first measure with the right symbol (and null elsewhere), and in G16 that `svg.multimeasureEndBarline` of the first block's first measure equals the end-repeat barline.
|
|
98
|
+
- [X] T016 [US3] Run `npm run test:multimeasure-rest` and fix until G11 to G20 and G23 pass.
|
|
99
|
+
|
|
100
|
+
### Implementation for User Story 3
|
|
101
|
+
|
|
102
|
+
- [X] T017 [US3] In `src/render/vex/vxMeasure.ts` `createMeasureModifiers`, after the existing own-symbol block, add: if `this.smoMeasure.svg.multimeasureEndSymbol` is set and `this.smoMeasure.svg.multimeasureLength > 0` and `this.firstInColumn`, create a `VF.Repetition` from that symbol (using `toVexSymbol`, `symbol.xOffset + this.smoMeasure.staffX`, and `symbol.yOffset`, moved up 30 as the existing code does when the measure has a rehearsal mark) and push it onto the stave modifiers, so the symbol shows over the multimeasure rest.
|
|
103
|
+
- [X] T018 [US3] Check `src/render/vex/toVex.ts` (around lines 128 to 142 and where it handles repeat symbols): if the Vex export draws repeat symbols for measures, mirror T017 for `multimeasureEndSymbol`; if it does not draw them at all, record that and make no change.
|
|
104
|
+
- [X] T019 [US3] Run `npx tsc --noEmit -p tsconfig.json` and `npm run build`; fix any errors.
|
|
105
|
+
- [ ] T020 [US3] Manual validation: quickstart.md section 3, steps 6 to 9 (M5, M6, M8): the D.S. over the first rest, the Coda sign at the start of the last rest after the barline, repeat barlines drawn once.
|
|
106
|
+
|
|
107
|
+
**Checkpoint**: All landmark kinds split rests as specified.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Phase 6: Polish & Cross-Cutting Concerns
|
|
112
|
+
|
|
113
|
+
- [X] T021 [P] In `tests/multimeasureRest.ts`, add case G24 (group with a rehearsal mark, remove it, regroup; assert one block `1:12` and that no measure keeps a stale `multimeasureLength`, `hideMultimeasure` or `multimeasureEndSymbol`; repeat with a D.S. added then removed).
|
|
114
|
+
- [X] T022 Run `npm run test:multimeasure-rest` and all nine existing test scripts; confirm all pass.
|
|
115
|
+
- [X] T023 Run `npx tsc --noEmit -p tsconfig.json` and `npm run build`; confirm both succeed with no new warnings.
|
|
116
|
+
- [ ] T024 Run through all of quickstart.md (sections 1 to 3), including steps 9 to 11, and note the result, including which edits regroup immediately.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Dependencies & Execution Order
|
|
121
|
+
|
|
122
|
+
### Phase Dependencies
|
|
123
|
+
|
|
124
|
+
- **Setup (Phase 1)**: none.
|
|
125
|
+
- **Foundational (Phase 2)**: depends on Setup. T003 (measure.ts) is independent; T004 (score.ts) must precede T005 (operations.ts), which uses its helpers and T003's field.
|
|
126
|
+
- **US1, US2, US3 (Phases 3 to 5)**: depend on Phase 2; their test blocks are in one file, so add them in order. US3's drawing task T017 depends on T003 and T005.
|
|
127
|
+
- **Polish (Phase 6)**: depends on all stories.
|
|
128
|
+
|
|
129
|
+
### Within Each Story
|
|
130
|
+
|
|
131
|
+
- `tests/multimeasureRest.ts` is edited by T002, T007, T012, T015 and T021: add cases in separate blocks, in order.
|
|
132
|
+
- `vxMeasure.ts` is edited by T017 (and possibly T014).
|
|
133
|
+
- `formatter.ts` is edited by T009 (and possibly T014).
|
|
134
|
+
|
|
135
|
+
### Parallel Opportunities
|
|
136
|
+
|
|
137
|
+
- T003 can be done while T001 and T002 are written.
|
|
138
|
+
- T007, T012 and T015 are separate blocks of the same file; write them while the code tasks proceed.
|
|
139
|
+
- T017 (drawing) can be written in parallel with T015/T016 once T003 and T005 exist.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Parallel Example: Foundational phase
|
|
144
|
+
|
|
145
|
+
```text
|
|
146
|
+
Task: "Add multimeasureEndSymbol to the svg record in src/smo/data/measure.ts" (T003)
|
|
147
|
+
Task: "Landmark helpers in src/smo/data/score.ts" (T004)
|
|
148
|
+
Task: "Rewrite computeMultipartRest in src/smo/xform/operations.ts" (T005, after T003, T004)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Implementation Strategy
|
|
154
|
+
|
|
155
|
+
### MVP First (User Story 1)
|
|
156
|
+
|
|
157
|
+
1. Phases 1 and 2 (classification and algorithm in place and compiling).
|
|
158
|
+
2. Phase 3: tests prove rehearsal-mark splitting and regression behavior; the layout hook makes it take effect.
|
|
159
|
+
3. Stop and validate in the app: a rehearsal mark in the middle of a part's long rest.
|
|
160
|
+
|
|
161
|
+
### Incremental Delivery
|
|
162
|
+
|
|
163
|
+
1. US1 fixes the most common case.
|
|
164
|
+
2. US2 locks in key, time and tempo changes and verifies their drawing.
|
|
165
|
+
3. US3 adds end landmarks and the drawing of end symbols.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Notes
|
|
170
|
+
|
|
171
|
+
- The legacy rule that blocks measure 0 from starting a block in a multi-staff part is kept on purpose (research.md section 4) so that existing parts look the same; raise it separately if it should change.
|
|
172
|
+
- `SmoScore.isMultimeasureRest` is left unchanged for outside users.
|
|
173
|
+
- Edits that only re-render single columns without a full layout are an existing limitation and out of scope (research.md section 7).
|
|
174
|
+
- Commit after each phase.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Specification Quality Checklist: Key-Distance Enharmonic Spelling for Transposition
|
|
2
|
+
|
|
3
|
+
**Purpose**: Validate specification completeness and quality before proceeding to planning
|
|
4
|
+
**Created**: 2026-10-27
|
|
5
|
+
**Feature**: [spec.md](../spec.md)
|
|
6
|
+
|
|
7
|
+
## Content Quality
|
|
8
|
+
|
|
9
|
+
- [x] No implementation details (languages, frameworks, APIs)
|
|
10
|
+
- [x] Focused on user value and business needs
|
|
11
|
+
- [x] Written for non-technical stakeholders
|
|
12
|
+
- [x] All mandatory sections completed
|
|
13
|
+
|
|
14
|
+
## Requirement Completeness
|
|
15
|
+
|
|
16
|
+
- [x] No [NEEDS CLARIFICATION] markers remain
|
|
17
|
+
- [x] Requirements are testable and unambiguous
|
|
18
|
+
- [x] Success criteria are measurable
|
|
19
|
+
- [x] Success criteria are technology-agnostic (no implementation details)
|
|
20
|
+
- [x] All acceptance scenarios are defined
|
|
21
|
+
- [x] Edge cases are identified
|
|
22
|
+
- [x] Scope is clearly bounded
|
|
23
|
+
- [x] Dependencies and assumptions identified
|
|
24
|
+
|
|
25
|
+
## Feature Readiness
|
|
26
|
+
|
|
27
|
+
- [x] All functional requirements have clear acceptance criteria
|
|
28
|
+
- [x] User scenarios cover primary flows
|
|
29
|
+
- [x] Feature meets measurable outcomes defined in Success Criteria
|
|
30
|
+
- [x] No implementation details leak into specification
|
|
31
|
+
|
|
32
|
+
## Notes
|
|
33
|
+
|
|
34
|
+
- FR-011 names the existing table being removed, because the request explicitly asks for its replacement; this is scope, not design.
|
|
35
|
+
- Distance is defined as steps around the circle of fifths to the nearest key containing the pitch (Bb = 1 flat from C, A# = 5 sharps from C), confirmed by the user on 2026-10-27.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Contract: Spelling API (`SmoMusic`, `SmoOperation`)
|
|
2
|
+
|
|
3
|
+
Internal library contract; `SmoMusic` is part of the exported library surface (see `types/`), so names below are public. All keys are lowercase VexFlow strings as stored on `SmoMeasure.keySignature`.
|
|
4
|
+
|
|
5
|
+
## Added (SmoMusic)
|
|
6
|
+
|
|
7
|
+
| Method | Signature | Behavior |
|
|
8
|
+
|--------|-----------|----------|
|
|
9
|
+
| `keyFifths` | `(keySignature: string) => number` | Sharps (+) / flats (-) of the major key, -7..+7. Throws or returns 0 for an unknown key (match `getSharpsInKeySignature` behavior: unknown returns 0). |
|
|
10
|
+
| `pitchFifths` | `(pitch: Pitch) => number` | Line-of-fifths position. |
|
|
11
|
+
| `fifthsToPitch` | `(f: number, octave: number) => Pitch` | Inverse of `pitchFifths`; octave is taken as given. |
|
|
12
|
+
| `distanceFromKey` | `(pitch: Pitch, keySignature: string) => number` | Signed distance; 0 in key, positive sharp side, negative flat side. |
|
|
13
|
+
| `keyForOffset` | `(keySignature: string, offset: number) => string` | Destination key for a half-step offset; fewest accidentals, tie to flats; offset 0 returns the input key. |
|
|
14
|
+
|
|
15
|
+
## Changed (SmoMusic)
|
|
16
|
+
|
|
17
|
+
| Method | New behavior | Unchanged |
|
|
18
|
+
|--------|--------------|-----------|
|
|
19
|
+
| `getScaleTonesForKey(key)` | Computed from `keyFifths`. | Return shape `{ [letter]: 'f#' / 'bb' / 'cn' }`. |
|
|
20
|
+
| `getEnharmonicInKey(pitch, key)` | Smallest distance spelling, ties to flat. | Signature; octave adjusted so sounding pitch is identical; mutates `pitch.octave = 1` default when undefined, as today. |
|
|
21
|
+
| `transposePitchForKey(pitch, originalKey, destinationKey, offset)` | Position shift `s` (research R4). | Signature; returns a new `Pitch`. |
|
|
22
|
+
|
|
23
|
+
## Removed
|
|
24
|
+
|
|
25
|
+
`enharmonicRoles`, `findRoleOfPitch`, `findPitchForRole`, interface `KeySignatureRole`. No in-repo callers outside `music.ts`.
|
|
26
|
+
|
|
27
|
+
## Changed (SmoOperation)
|
|
28
|
+
|
|
29
|
+
`transposeScore(score, offset)`: for each measure, `kd = keyForOffset(measure.keySignature, offset)`; notes (including grace notes) are transposed with `transposePitchForKey(pitch, ks, kd, offset)`; then `measure.keySignature = kd`. Zero offset is a no-op.
|
|
30
|
+
|
|
31
|
+
## Invariants (asserted by tests)
|
|
32
|
+
|
|
33
|
+
1. `smoPitchToInt(result) === smoPitchToInt(input) + offset` for every transposition.
|
|
34
|
+
2. `abs(distanceFromKey(result, kd)) === abs(distanceFromKey(input, ks))` and the sign is equal, for all non-extreme cases.
|
|
35
|
+
3. `transpose(n)` then `transpose(-n)` restores letter, accidental, octave and key (non-extreme cases).
|
|
36
|
+
4. Tie between sharp and flat spelling resolves to flat.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Data Model: Key-Distance Enharmonic Spelling
|
|
2
|
+
|
|
3
|
+
No persisted data changes. These are the in-memory concepts the logic computes with; none is serialized.
|
|
4
|
+
|
|
5
|
+
## Pitch (existing)
|
|
6
|
+
|
|
7
|
+
`{ letter: 'a'..'g', accidental: 'n' | '#' | 'b' | '##' | 'bb' (empty string tolerated), octave: number }`
|
|
8
|
+
|
|
9
|
+
## Fifths position (derived, integer)
|
|
10
|
+
|
|
11
|
+
| Field | Meaning |
|
|
12
|
+
|-------|---------|
|
|
13
|
+
| `f` | `base(letter) + 7 * acc`, with base F=-1, C=0, G=1, D=2, A=3, E=4, B=5 and `acc` = +1 per sharp / -1 per flat |
|
|
14
|
+
|
|
15
|
+
Rules:
|
|
16
|
+
- Valid range with at most double accidentals: -15 (Fbb) .. 19 (B##).
|
|
17
|
+
- Pitch class is `(7 * f) mod 12`. Two positions are enharmonic iff they differ by a multiple of 12.
|
|
18
|
+
- Converting back: `letter` from `((f + 1) mod 7)` indexed over F,C,G,D,A,E,B; `acc` is `floor((f + 1) / 7)`.
|
|
19
|
+
|
|
20
|
+
## Key index (derived, integer)
|
|
21
|
+
|
|
22
|
+
| Field | Meaning |
|
|
23
|
+
|-------|---------|
|
|
24
|
+
| `k` | Sharps (positive) or flats (negative) in the major key signature, -7 .. +7 |
|
|
25
|
+
|
|
26
|
+
Rules:
|
|
27
|
+
- Source of truth is the key signature string on the measure (`'c'`, `'g'`, `'db'`, ...). `k` is read from it via the existing sharp/flat counts.
|
|
28
|
+
- Scale tones of key `k` are positions `k-1 .. k+5`.
|
|
29
|
+
- Accidental for letter with base `b` in key `k` is `floor((k + 5 - b) / 7)`.
|
|
30
|
+
|
|
31
|
+
## Distance (derived, signed integer)
|
|
32
|
+
|
|
33
|
+
`distance(f, k) = 0` if `k-1 <= f <= k+5`; `f - (k+5)` if above (sharp side, positive); `f - (k-1)` if below (flat side, negative).
|
|
34
|
+
|
|
35
|
+
| Example | f | k | Distance |
|
|
36
|
+
|---------|---|---|----------|
|
|
37
|
+
| A# in C | 10 | 0 | +5 |
|
|
38
|
+
| Bb in C | -2 | 0 | -1 |
|
|
39
|
+
| C# in C | 7 | 0 | +2 |
|
|
40
|
+
| E natural in Eb | 4 | -3 | +2 |
|
|
41
|
+
| G# in G | 8 | 1 | +2 |
|
|
42
|
+
|
|
43
|
+
Note on the Eb row: the window for Eb is positions -4..2 (Ab, Eb, Bb, F, C, G, D); E natural (4) is 2 above the top, so +2; G# in G (window 0..6) is 8, also +2. Equal distance, same direction, which is the preservation the spec requires.
|
|
44
|
+
|
|
45
|
+
## Key shift (derived, integer)
|
|
46
|
+
|
|
47
|
+
`s = kd - ks`, adjusted by a multiple of 12 only if needed so that `7 * s ≡ offset (mod 12)`.
|
|
48
|
+
|
|
49
|
+
State transitions: none. All values are recomputed per operation; transposing by `+n` then `-n` returns each original `f` and `k` exactly, except for pitches that needed a ±12 respell to stay within double accidentals.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Implementation Plan: Key-Distance Enharmonic Spelling for Transposition
|
|
2
|
+
|
|
3
|
+
**Branch**: `033-key-distance-transposition` (work is on `main`; no feature branch was created) | **Date**: 2026-10-27 | **Spec**: [spec.md](spec.md)
|
|
4
|
+
|
|
5
|
+
**Input**: Feature specification from `/specs/033-key-distance-transposition/spec.md`
|
|
6
|
+
|
|
7
|
+
## Summary
|
|
8
|
+
|
|
9
|
+
Replace the `SmoMusic.enharmonicRoles` table in [music.ts](../../src/smo/data/music.ts) and the role lookups built on it with arithmetic on the circle of fifths. Every spelling gets a single integer position on the "line of fifths" (F=-1, C=0, G=1 ... B=5, plus 7 per sharp, minus 7 per flat) and every major key signature gets an index in -7..+7. From those two numbers:
|
|
10
|
+
|
|
11
|
+
- a key's seven scale tones are the positions `k-1 .. k+5`;
|
|
12
|
+
- a spelling's signed *distance* from a key is how far it lies outside that window (A# in C: 5 sharps; Bb in C: 1 flat);
|
|
13
|
+
- the default spelling of a pitch class is the candidate with the smallest distance, ties going to the flat side;
|
|
14
|
+
- transposing from key `ks` to key `kd` shifts every position by `kd - ks`, which preserves scale degree, alteration and therefore distance exactly.
|
|
15
|
+
|
|
16
|
+
The whole-score transpose operation computes the destination key from the interval and applies that shift. No serialization changes.
|
|
17
|
+
|
|
18
|
+
## Technical Context
|
|
19
|
+
|
|
20
|
+
**Language/Version**: TypeScript (see `tsconfig.json`), run in tests with `ts-node`
|
|
21
|
+
|
|
22
|
+
**Primary Dependencies**: None new. VexFlow is not involved in the spelling logic; `SmoMusic` helpers (`smoPitchToInt`, `smoIntToPitch`, `noteValues`) are reused.
|
|
23
|
+
|
|
24
|
+
**Storage**: N/A. Pitches serialize as `{letter, accidental, octave}` and key signatures as lowercase VexFlow strings (`'c'`, `'db'`, `'f#'`); both are unchanged.
|
|
25
|
+
|
|
26
|
+
**Testing**: Headless `ts-node` scripts under `tests/`, one npm script each (see `test:voice-copy-paste`). New: `tests/keyDistanceTransposition.ts` with script `test:key-distance-transposition`.
|
|
27
|
+
|
|
28
|
+
**Target Platform**: Browser application and library (`src/smo` has no UI dependencies).
|
|
29
|
+
|
|
30
|
+
**Project Type**: Single project (TypeScript library plus Vue UI).
|
|
31
|
+
|
|
32
|
+
**Performance Goals**: Spelling is O(1) per pitch (a few integer operations); the table lookup it replaces was a linear scan. No rendering impact.
|
|
33
|
+
|
|
34
|
+
**Constraints**: Sounding pitch must never change when respelling (FR-010). Output must stay within double sharps/flats, which the existing `noteValues` table supports.
|
|
35
|
+
|
|
36
|
+
**Scale/Scope**: One module (`music.ts`), three callers' behavior (`SmoNote.transpose`, chord-symbol transposition, `SmoOperation.transpose`/`transposeScore`), one new test file.
|
|
37
|
+
|
|
38
|
+
## Constitution Check
|
|
39
|
+
|
|
40
|
+
*GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
|
|
41
|
+
|
|
42
|
+
| Principle | Assessment |
|
|
43
|
+
|-----------|------------|
|
|
44
|
+
| #1 Serialization | Pass. No new persisted fields. Existing scores keep their stored spellings; only operations that choose a spelling are affected. |
|
|
45
|
+
| #2 Editing/transformation logic is regression tested | Pass, and driving the design: `tests/keyDistanceTransposition.ts` covers every worked example and edge case from the spec. |
|
|
46
|
+
| #3 Rendering performance | Pass. No render-path change. |
|
|
47
|
+
| #4 Logical dependencies | Pass. All new code is in `src/smo/data/music.ts` and `src/smo/xform/operations.ts`; no UI or renderer imports. |
|
|
48
|
+
|
|
49
|
+
Re-check after Phase 1 design: still passes. No complexity violations.
|
|
50
|
+
|
|
51
|
+
## Project Structure
|
|
52
|
+
|
|
53
|
+
### Documentation (this feature)
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
specs/033-key-distance-transposition/
|
|
57
|
+
├── plan.md # This file
|
|
58
|
+
├── research.md # Phase 0 output
|
|
59
|
+
├── data-model.md # Phase 1 output
|
|
60
|
+
├── quickstart.md # Phase 1 output
|
|
61
|
+
├── contracts/
|
|
62
|
+
│ └── spelling-api.md # Phase 1 output (internal API contract)
|
|
63
|
+
├── checklists/
|
|
64
|
+
│ └── requirements.md
|
|
65
|
+
└── tasks.md # Phase 2 output (/speckit-tasks - NOT created by /speckit-plan)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Source Code (repository root)
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
src/smo/data/music.ts # remove enharmonicRoles, KeySignatureRole, findRoleOfPitch, findPitchForRole;
|
|
72
|
+
# add line-of-fifths helpers; rewrite getScaleTonesForKey, getEnharmonicInKey,
|
|
73
|
+
# transposePitchForKey; fix 'Gg' typo in keySignatureLength
|
|
74
|
+
src/smo/xform/operations.ts # transposeScore: compute destination key, update measure key signatures,
|
|
75
|
+
# transpose with distance preserved
|
|
76
|
+
src/smo/data/note.ts # no change expected (SmoNote.transpose already calls transposePitchForKey)
|
|
77
|
+
src/smo/data/noteModifiers.ts # no change expected (chord-symbol transposition already calls it)
|
|
78
|
+
types/src/smo/data/music.d.ts # regenerated by `npm run types`
|
|
79
|
+
tests/keyDistanceTransposition.ts # new
|
|
80
|
+
package.json # add test:key-distance-transposition script
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Structure Decision**: Single-project layout as it exists. The logic stays in `SmoMusic` as static methods, matching the surrounding code. A separate module would be unwarranted for roughly 80 lines.
|
|
84
|
+
|
|
85
|
+
## Complexity Tracking
|
|
86
|
+
|
|
87
|
+
No constitution violations to justify.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Quickstart: Validating Key-Distance Spelling
|
|
2
|
+
|
|
3
|
+
## Prerequisites
|
|
4
|
+
|
|
5
|
+
- `npm install` done at the repository root.
|
|
6
|
+
- Types regenerated if you changed `music.ts` public signatures: `npm run types`.
|
|
7
|
+
|
|
8
|
+
## Automated check
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm run test:key-distance-transposition
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Expected: every line prints `PASS`, exit code 0. The script covers the cases below (see [contracts/spelling-api.md](contracts/spelling-api.md) for the invariants and [data-model.md](data-model.md) for the arithmetic).
|
|
15
|
+
|
|
16
|
+
| # | Scenario | Expected |
|
|
17
|
+
|---|----------|----------|
|
|
18
|
+
| 1 | C# in C → D, +2 | D# |
|
|
19
|
+
| 2 | A# in C → D, +2 | B# |
|
|
20
|
+
| 3 | E natural in Eb → G, +4 | G# |
|
|
21
|
+
| 4 | Default spelling, pitch class 10 in C | Bb |
|
|
22
|
+
| 5 | Default spelling with sharp/flat tie (pitch class 8 in C) | Ab |
|
|
23
|
+
| 6 | In-key note in destination key (F in C → G, +7) | C (4th degree maps to 4th degree) |
|
|
24
|
+
| 7 | Same key, offset 0 | Spelling unchanged |
|
|
25
|
+
| 8 | Octave handling across B/C (Cb4 in Gb → G, +1) | C4; sounding pitch rises exactly one half step |
|
|
26
|
+
| 9 | Round trip for all 12 chromatic notes, all 15 major keys, offsets -12..12 | Original spelling restored |
|
|
27
|
+
| 10 | Extreme destination (offset giving more than 7 accidentals) | Equivalent key with fewer accidentals |
|
|
28
|
+
| 11 | Chord symbol `C#` in C → D | `D#` |
|
|
29
|
+
| 12 | `SmoOperation.transposeScore` on a 2-measure Eb score with E natural, +4 | Measures in `g`, E natural is G# |
|
|
30
|
+
|
|
31
|
+
## Manual check in the application
|
|
32
|
+
|
|
33
|
+
1. Start the app, enter a measure in C major containing C#.
|
|
34
|
+
2. Select **Transpose Score** and enter +2. The key signature becomes D major (2 sharps) and the C# shows as D#, not Eb.
|
|
35
|
+
3. Press Cancel in the dialog. The score returns to C major with C#.
|
|
36
|
+
4. Copy an A# from C major, paste into a D major measure: B#.
|
|
37
|
+
|
|
38
|
+
## Regression
|
|
39
|
+
|
|
40
|
+
Run the other test scripts in `package.json` (`test:voice-copy-paste`, `test:multimeasure-rest`, ...) to confirm nothing else changed.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Research: Key-Distance Enharmonic Spelling
|
|
2
|
+
|
|
3
|
+
All Technical Context items were resolvable from the code; no NEEDS CLARIFICATION remained.
|
|
4
|
+
|
|
5
|
+
## R1. Representing spellings and keys as one integer each
|
|
6
|
+
|
|
7
|
+
**Decision**: Use the "line of fifths". A spelling's position is `base(letter) + 7 * accidentalCount`, where `base` is F=-1, C=0, G=1, D=2, A=3, E=4, B=5, and `accidentalCount` is +1 per sharp, -1 per flat (double accidentals ±2). A major key's index `k` is its sharps (positive) or flats (negative): C=0, G=1, F=-1, Bb=-2.
|
|
8
|
+
|
|
9
|
+
**Rationale**: Adjacent positions are a fifth apart, so "number of fifths/fourths" from the user's definition is plain subtraction. The seven tones of key `k` are positions `k-1 .. k+5` (check: C gives F..B; G gives C..F#; Eb gives Ab..D). Everything in the spec reduces to comparisons against that window.
|
|
10
|
+
|
|
11
|
+
**Alternatives considered**: Keep a table but generate it (still bulky, still needs lookups); keep `circleOfFifths` array search (`circleOfFifthsIndex` already exists but only covers 12 entries and handles enharmonics by search, which is what we are trying to avoid).
|
|
12
|
+
|
|
13
|
+
## R2. Distance
|
|
14
|
+
|
|
15
|
+
**Decision**: Signed distance of position `f` from key `k` is `0` if `k-1 <= f <= k+5`, `f - (k+5)` (positive, sharps) if above, `f - (k-1)` (negative, flats) if below. Magnitude is the rank used to choose spellings.
|
|
16
|
+
|
|
17
|
+
**Rationale**: This is the user's definition: the number of sharps/flats added to the signature until a key contains the note. Verified against the stated examples: A# (f=10) in C: 10-5 = 5 sharps; Bb (f=-2) in C: -2-(-1) = -1, one flat. Note that `f` can lie outside the 15 real keys; the distance is computed against a theoretical key, which is fine because only the magnitude matters.
|
|
18
|
+
|
|
19
|
+
**Alternatives considered**: Counting accidentals in the spelling itself (Bb has 1, A# has 1, so no preference); rejected since it ignores the key.
|
|
20
|
+
|
|
21
|
+
## R3. Default spelling of a pitch class (replaces the bias block in `getEnharmonicInKey`)
|
|
22
|
+
|
|
23
|
+
**Decision**: For a sounding pitch class, enumerate its spellings that use at most a double accidental (positions `f0 + 12m`, in the range -15..19). Choose the one with the smallest absolute distance from the key. On equal absolute distance, choose the lower position (the flat side).
|
|
24
|
+
|
|
25
|
+
**Rationale**: Directly implements FR-003/FR-004. In-key pitches have distance 0 and always win, so a key's own spelling is used (FR-006-style behavior for defaults, US3 scenario 3).
|
|
26
|
+
|
|
27
|
+
**Behavior change to be aware of**: the old code hard-coded a flat bias (`a#`->`bb`, `g#`->`ab`, `c#`->`db`, `d#`->`eb`) for non-sharp keys. The new rule gives, in C major: Bb, Eb, Ab (tie, flat wins), but **C# and F#** (C# is 2 sharps from C vs 4 flats for Db; F# is 1 sharp vs 5 flats). In C major, C# was previously defaulted to Db. This follows from the requested rule and agrees with the requested example (C# in C stays C# when transposed to D as D#).
|
|
28
|
+
|
|
29
|
+
**Alternatives considered**: Keep the old bias block as an override; rejected because it contradicts the stated rule.
|
|
30
|
+
|
|
31
|
+
## R4. Transposing between keys while preserving distance
|
|
32
|
+
|
|
33
|
+
**Decision**: Compute `s = kd - ks` and set the new position to `f + s`. The sounding pitch is checked: `7 * s` must be congruent to the half-step offset modulo 12. If the caller's destination key and offset disagree, pick the `s` congruent to `7 * offset` (mod 12) that is closest to `kd - ks`, so the sounding pitch is always right. Then fix the octave by solving against `smoPitchToInt`.
|
|
34
|
+
|
|
35
|
+
**Rationale**: Shifting every position by the same amount keeps each note's offset from the key window unchanged, so scale degree, direction and distance are all preserved, and the operation is exactly invertible. Verified by hand against the spec examples:
|
|
36
|
+
|
|
37
|
+
| Case | ks → kd | s | Source f | Result f | Spelling |
|
|
38
|
+
|------|---------|---|----------|----------|----------|
|
|
39
|
+
| C# in C → D | 0 → 2 | 2 | 7 | 9 | D# |
|
|
40
|
+
| A# in C → D | 0 → 2 | 2 | 10 | 12 | B# |
|
|
41
|
+
| E natural in Eb → G | -3 → 1 | 4 | 4 | 8 | G# |
|
|
42
|
+
|
|
43
|
+
**Edge handling**: If `f + s` needs more than a double accidental (positions outside -15..19), respell by ±12 toward the nearest in-range position (the default-spelling rule in R3 picks it). Round trips are therefore exact except for these extremes; the spec's success criterion for round trips is qualified accordingly.
|
|
44
|
+
|
|
45
|
+
**Alternatives considered**: Map to a "role" per scale degree (what the table did; the source of the bulk). Compute from the transposition interval's letter distance (needs interval spelling, not available from half-step offsets alone).
|
|
46
|
+
|
|
47
|
+
## R5. Destination key for whole-score transposition
|
|
48
|
+
|
|
49
|
+
**Decision**: `kd` is the unique residue of `ks + 7 * offset (mod 12)` in -7..+7, preferring fewer accidentals. The one tie (6 vs -6) goes to flats (Gb), matching R3's tie rule. A zero offset keeps the existing key unchanged, so scores written in C# or Cb are not rewritten. Minor-key signatures are not special-cased; the app's key list is major keys only (the old table has only major keys).
|
|
50
|
+
|
|
51
|
+
**Rationale**: Only a residue modulo 12 is determined by the sounding pitch; choosing the representative with the fewest accidentals is what spec edge case "extreme destination key" requires. The existing `vexKeySigWithOffset` does the same job by pitch lookup with a patch table (`a#`->`bb` etc.); the new helper replaces that table-driven patching for this feature's callers but leaves the function in place for other callers.
|
|
52
|
+
|
|
53
|
+
**Alternatives considered**: Reuse `vexKeySigWithOffset`; it can produce `c#` or `cb` and relies on hard-coded patches, which would make the round-trip property harder to guarantee.
|
|
54
|
+
|
|
55
|
+
## R6. Current whole-score behavior
|
|
56
|
+
|
|
57
|
+
**Finding**: `SmoOperation.transposeScore` calls `transpose` for each note using the *measure's existing* key signature and never changes any key signature. The dialog ([transposeScore.ts](../../src/ui/dialogs/transposeScore.ts)) calls it in steps of the entered semitone count, and cancel undoes by transposing the negated total.
|
|
58
|
+
|
|
59
|
+
**Decision**: `transposeScore` computes `kd` per measure from that measure's current key and the offset, updates `measure.keySignature` to `kd`, and transposes pitches with `s = kd - ks`. Because the dialog applies each increment separately and cancel applies the negated total, both stay consistent: the inverse offset yields `s' = -s` and returns the original key and spelling. This matches spec US2 scenario 2 (destination key of each measure follows the interval). `storeScore` is transposed with the same function, so it stays in sync.
|
|
60
|
+
|
|
61
|
+
**Risk**: Users who relied on transposing notes while keeping the key signature will see the signature change. This is the behavior described in the request ("calculate the destination key"). Note in the changelog.
|
|
62
|
+
|
|
63
|
+
## R7. Callers that also use the table
|
|
64
|
+
|
|
65
|
+
| Caller | Use | Replacement |
|
|
66
|
+
|--------|-----|-------------|
|
|
67
|
+
| `getScaleTonesForKey` (also used by `tickMap.ts`, `getKeySignatureKey`, `isPitchInKeySignature`, `getKeyFriendlyEnharmonic`) | Per-letter accidental in the key | Computed from `k`: for letter base `b`, accidental count is `floor((k + 5 - b) / 7)`; return the same `letter + accidental` strings (`'f#'`, `'bb'`, `'cn'`) as before |
|
|
68
|
+
| `getEnharmonicInKey` (also `operations.ts` x2, `midiToSmo.ts`, `getIntervalInKey`) | Default spelling | R3 |
|
|
69
|
+
| `transposePitchForKey` (`note.ts`, chord symbols in `noteModifiers.ts`) | Cross-key spelling | R4 |
|
|
70
|
+
| `findRoleOfPitch`, `findPitchForRole`, `KeySignatureRole` | Table roles | Deleted. Grep shows no callers outside `music.ts` |
|
|
71
|
+
|
|
72
|
+
## R8. Pre-existing defect found
|
|
73
|
+
|
|
74
|
+
`keySignatureLength` contains the key `'Gg'` (should be `'Gb'`), so `getFlatsInKeySignature('gb')` returns `undefined`. Fixed as part of the new key-index helper since the helper depends on correct sharp/flat counts.
|
|
75
|
+
|
|
76
|
+
## R9. Existing tests
|
|
77
|
+
|
|
78
|
+
`package.json` has `"test": "exit 0"` and per-feature scripts. Adopt the same pattern (`ts-node -P tests/tsconfig.json`, `check()` helper, exit non-zero on failure).
|
|
79
|
+
|
|
80
|
+
## R10. Octave rule for B#, B##, Cb, Cbb
|
|
81
|
+
|
|
82
|
+
`smoPitchToInt` only special-cases `cb` (octave minus one). `b#3` evaluates to `3*12+0 = 36` although it sounds as C4 (48), and `b##`/`cbb` have the same problem. The new code therefore computes the sounding value with a letter-based rule that needs no special cases: `octave * 12 + naturalValue(letter) + accidentalCount`, where `naturalValue` is C=0, D=2, E=4, F=5, G=7, A=9, B=11 (so `cb4` = 47, `b#3` = 48). Respelling solves for the octave that makes this value equal the target. `smoPitchToInt` is left unchanged because other code depends on it.
|