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.
Files changed (245) hide show
  1. package/build/smoosic.js +395 -67
  2. package/changes.md +85 -0
  3. package/package.json +98 -82
  4. package/release/smoosic.js +395 -67
  5. package/specs/032-split-multimeasure-rests/checklists/requirements.md +40 -0
  6. package/specs/032-split-multimeasure-rests/contracts/grouping-contract.md +53 -0
  7. package/specs/032-split-multimeasure-rests/data-model.md +70 -0
  8. package/specs/032-split-multimeasure-rests/plan.md +81 -0
  9. package/specs/032-split-multimeasure-rests/quickstart.md +46 -0
  10. package/specs/032-split-multimeasure-rests/research.md +63 -0
  11. package/specs/032-split-multimeasure-rests/spec.md +127 -0
  12. package/specs/032-split-multimeasure-rests/tasks.md +174 -0
  13. package/specs/033-key-distance-transposition/checklists/requirements.md +35 -0
  14. package/specs/033-key-distance-transposition/contracts/spelling-api.md +36 -0
  15. package/specs/033-key-distance-transposition/data-model.md +49 -0
  16. package/specs/033-key-distance-transposition/plan.md +87 -0
  17. package/specs/033-key-distance-transposition/quickstart.md +40 -0
  18. package/specs/033-key-distance-transposition/research.md +82 -0
  19. package/specs/033-key-distance-transposition/spec.md +132 -0
  20. package/specs/033-key-distance-transposition/tasks.md +139 -0
  21. package/specs/034-smz-compressed-scores/checklists/requirements.md +35 -0
  22. package/specs/034-smz-compressed-scores/contracts/archive-api.md +30 -0
  23. package/specs/034-smz-compressed-scores/data-model.md +48 -0
  24. package/specs/034-smz-compressed-scores/plan.md +89 -0
  25. package/specs/034-smz-compressed-scores/quickstart.md +44 -0
  26. package/specs/034-smz-compressed-scores/research.md +86 -0
  27. package/specs/034-smz-compressed-scores/spec.md +137 -0
  28. package/specs/034-smz-compressed-scores/tasks.md +148 -0
  29. package/specs/035-paste-special/checklists/requirements.md +35 -0
  30. package/specs/035-paste-special/contracts/paste-special-api.md +50 -0
  31. package/specs/035-paste-special/data-model.md +47 -0
  32. package/specs/035-paste-special/plan.md +83 -0
  33. package/specs/035-paste-special/quickstart.md +51 -0
  34. package/specs/035-paste-special/research.md +97 -0
  35. package/specs/035-paste-special/spec.md +170 -0
  36. package/specs/035-paste-special/tasks.md +149 -0
  37. package/specs/036-autosave-recovery/checklists/requirements.md +36 -0
  38. package/specs/036-autosave-recovery/contracts/autosave-api.md +111 -0
  39. package/specs/036-autosave-recovery/data-model.md +70 -0
  40. package/specs/036-autosave-recovery/plan.md +87 -0
  41. package/specs/036-autosave-recovery/quickstart.md +65 -0
  42. package/specs/036-autosave-recovery/research.md +105 -0
  43. package/specs/036-autosave-recovery/spec.md +143 -0
  44. package/specs/036-autosave-recovery/tasks.md +165 -0
  45. package/specs/037-fix-new-part-dialog/checklists/requirements.md +38 -0
  46. package/specs/037-fix-new-part-dialog/contracts/create-part-api.md +84 -0
  47. package/specs/037-fix-new-part-dialog/data-model.md +68 -0
  48. package/specs/037-fix-new-part-dialog/plan.md +83 -0
  49. package/specs/037-fix-new-part-dialog/quickstart.md +58 -0
  50. package/specs/037-fix-new-part-dialog/research.md +86 -0
  51. package/specs/037-fix-new-part-dialog/spec.md +144 -0
  52. package/specs/037-fix-new-part-dialog/tasks.md +174 -0
  53. package/specs/038-per-measure-beam-groups/checklists/requirements.md +36 -0
  54. package/specs/038-per-measure-beam-groups/contracts/beam-groups-api.md +74 -0
  55. package/specs/038-per-measure-beam-groups/data-model.md +75 -0
  56. package/specs/038-per-measure-beam-groups/plan.md +84 -0
  57. package/specs/038-per-measure-beam-groups/quickstart.md +53 -0
  58. package/specs/038-per-measure-beam-groups/research.md +72 -0
  59. package/specs/038-per-measure-beam-groups/spec.md +146 -0
  60. package/specs/038-per-measure-beam-groups/tasks.md +132 -0
  61. package/specs/039-measure-fill-submenu/checklists/requirements.md +35 -0
  62. package/specs/039-measure-fill-submenu/contracts/measure-fill-api.md +56 -0
  63. package/specs/039-measure-fill-submenu/data-model.md +79 -0
  64. package/specs/039-measure-fill-submenu/plan.md +81 -0
  65. package/specs/039-measure-fill-submenu/quickstart.md +62 -0
  66. package/specs/039-measure-fill-submenu/research.md +68 -0
  67. package/specs/039-measure-fill-submenu/spec.md +153 -0
  68. package/specs/039-measure-fill-submenu/tasks.md +121 -0
  69. package/specs/040-dynamics-dialog-cleanup/checklists/requirements.md +36 -0
  70. package/specs/040-dynamics-dialog-cleanup/contracts/dynamics-dialog.md +52 -0
  71. package/specs/040-dynamics-dialog-cleanup/data-model.md +48 -0
  72. package/specs/040-dynamics-dialog-cleanup/plan.md +89 -0
  73. package/specs/040-dynamics-dialog-cleanup/quickstart.md +69 -0
  74. package/specs/040-dynamics-dialog-cleanup/research.md +80 -0
  75. package/specs/040-dynamics-dialog-cleanup/spec.md +120 -0
  76. package/specs/040-dynamics-dialog-cleanup/tasks.md +114 -0
  77. package/specs/041-delete-special/checklists/requirements.md +35 -0
  78. package/specs/041-delete-special/contracts/delete-special-api.md +41 -0
  79. package/specs/041-delete-special/data-model.md +40 -0
  80. package/specs/041-delete-special/plan.md +93 -0
  81. package/specs/041-delete-special/quickstart.md +41 -0
  82. package/specs/041-delete-special/research.md +75 -0
  83. package/specs/041-delete-special/spec.md +136 -0
  84. package/specs/041-delete-special/tasks.md +106 -0
  85. package/src/application/application.ts +13 -2
  86. package/src/application/exports.ts +401 -395
  87. package/src/application/generateVexTests.ts +2 -2
  88. package/src/render/sui/NoteEntryCaret.ts +117 -16
  89. package/src/render/sui/autosave.ts +265 -0
  90. package/src/render/sui/formatter.ts +12 -2
  91. package/src/render/sui/scoreChangeState.ts +8 -3
  92. package/src/render/sui/scoreView.ts +47 -2
  93. package/src/render/sui/scoreViewOperations.ts +2706 -2555
  94. package/src/render/sui/staffLineGeometry.ts +82 -0
  95. package/src/render/vex/vxMeasure.ts +22 -8
  96. package/src/render/vex/vxNote.ts +2 -4
  97. package/src/smo/data/measure.ts +58 -1
  98. package/src/smo/data/measureModifiers.ts +81 -1
  99. package/src/smo/data/music.ts +169 -359
  100. package/src/smo/data/note.ts +1 -1
  101. package/src/smo/data/noteModifiers.ts +12 -0
  102. package/src/smo/data/score.ts +167 -2
  103. package/src/smo/data/scoreModifiers.ts +46 -1
  104. package/src/smo/data/systemStaff.ts +43 -0
  105. package/src/smo/xform/beamers.ts +80 -6
  106. package/src/smo/xform/copypaste.ts +207 -47
  107. package/src/smo/xform/measureFill.ts +89 -0
  108. package/src/smo/xform/operations.ts +403 -61
  109. package/src/smo/xform/selections.ts +7 -0
  110. package/src/ui/components/dialogs/beamGroups.vue +106 -0
  111. package/src/ui/components/dialogs/deleteSpecial.vue +38 -0
  112. package/src/ui/components/dialogs/dynamics.vue +16 -3
  113. package/src/ui/components/dialogs/fileUpload.vue +2 -2
  114. package/src/ui/components/dialogs/hairpin.vue +3 -3
  115. package/src/ui/components/dialogs/newPart.vue +148 -184
  116. package/src/ui/components/dialogs/pasteSpecial.vue +49 -0
  117. package/src/ui/components/dialogs/recovery.vue +66 -0
  118. package/src/ui/components/dialogs/save.vue +11 -4
  119. package/src/ui/components/dialogs/scorePreferences.vue +23 -1
  120. package/src/ui/components/dialogs/slur.vue +6 -6
  121. package/src/ui/components/dialogs/tempo.vue +11 -3
  122. package/src/ui/components/dialogs/timeSignature.vue +5 -0
  123. package/src/ui/components/dialogs/volta.vue +3 -3
  124. package/src/ui/dialogs/annotationVue.ts +1 -1
  125. package/src/ui/dialogs/beamGroupsVue.ts +69 -0
  126. package/src/ui/dialogs/createPartHelpers.ts +68 -0
  127. package/src/ui/dialogs/deleteSpecial.ts +57 -0
  128. package/src/ui/dialogs/dynamicsVue.ts +87 -60
  129. package/src/ui/dialogs/factory.ts +0 -2
  130. package/src/ui/dialogs/fileDialogs.ts +63 -22
  131. package/src/ui/dialogs/instrument.ts +37 -30
  132. package/src/ui/dialogs/pasteSpecial.ts +59 -0
  133. package/src/ui/dialogs/preferences.ts +41 -40
  134. package/src/ui/dialogs/recovery.ts +49 -0
  135. package/src/ui/fileio/fileInput.ts +12 -3
  136. package/src/ui/fileio/scoreArchive.ts +151 -0
  137. package/src/ui/fileio/xhrLoader.ts +26 -0
  138. package/src/ui/i18n/language.ts +1 -1
  139. package/src/ui/menus/beams.ts +181 -112
  140. package/src/ui/menus/edit.ts +44 -6
  141. package/src/ui/menus/file.ts +21 -1
  142. package/src/ui/menus/measure.ts +40 -1
  143. package/tests/autosave.ts +332 -0
  144. package/tests/beamDotted.ts +56 -0
  145. package/tests/beamGroups.ts +338 -0
  146. package/tests/createPart.ts +292 -0
  147. package/tests/deleteSpecial.ts +350 -0
  148. package/tests/dynamicsFontSize.ts +132 -0
  149. package/tests/keyDistanceTransposition.ts +351 -0
  150. package/tests/measureFill.ts +295 -0
  151. package/tests/movePart.ts +94 -0
  152. package/tests/multimeasureRest.ts +338 -0
  153. package/tests/pasteIntoMeasure.ts +103 -0
  154. package/tests/pasteSpecial.ts +541 -0
  155. package/tests/quickBeam.ts +126 -0
  156. package/tests/scoreArchive.ts +218 -0
  157. package/tests/scoreChangeState.ts +2 -0
  158. package/tests/staffLineGeometry.ts +179 -0
  159. package/tests/timeSignatureDisplay.ts +58 -0
  160. package/tools/smoosic-schema.json +37 -0
  161. package/typedoc.ts +1 -1
  162. package/types/src/application/exports.d.ts +453 -447
  163. package/types/src/common/promiseHelpers.d.ts +30 -30
  164. package/types/src/common/vex.d.ts +224 -224
  165. package/types/src/render/sui/NoteEntryCaret.d.ts +107 -107
  166. package/types/src/render/sui/autosave.d.ts +99 -0
  167. package/types/src/render/sui/scoreView.d.ts +23 -0
  168. package/types/src/render/sui/scoreViewOperations.d.ts +759 -639
  169. package/types/src/render/sui/svgHelpers.d.ts +88 -88
  170. package/types/src/render/sui/svgPageMap.d.ts +344 -344
  171. package/types/src/render/sui/textEdit.d.ts +96 -96
  172. package/types/src/render/sui/textRender.d.ts +199 -199
  173. package/types/src/render/vex/smoAdapter.d.ts +47 -47
  174. package/types/src/render/vex/vxMeasure.d.ts +97 -97
  175. package/types/src/render/vex/vxNote.d.ts +56 -56
  176. package/types/src/render/vex/vxSystem.d.ts +71 -71
  177. package/types/src/smo/data/measure.d.ts +30 -0
  178. package/types/src/smo/data/measureModifiers.d.ts +568 -513
  179. package/types/src/smo/data/music.d.ts +74 -32
  180. package/types/src/smo/data/note.d.ts +498 -498
  181. package/types/src/smo/data/noteModifiers.d.ts +615 -606
  182. package/types/src/smo/data/score.d.ts +476 -421
  183. package/types/src/smo/data/scoreModifiers.d.ts +30 -0
  184. package/types/src/smo/data/scoreText.d.ts +334 -334
  185. package/types/src/smo/data/systemStaff.d.ts +14 -0
  186. package/types/src/smo/xform/beamers.d.ts +23 -1
  187. package/types/src/smo/xform/copypaste.d.ts +138 -2
  188. package/types/src/smo/xform/measureFill.d.ts +21 -0
  189. package/types/src/smo/xform/operations.d.ts +245 -129
  190. package/types/src/smo/xform/selections.d.ts +154 -154
  191. package/types/src/smo/xform/undo.d.ts +142 -142
  192. package/types/src/ui/buttons/button.d.ts +100 -100
  193. package/types/src/ui/buttons/ribbon.d.ts +70 -70
  194. package/types/src/ui/common.d.ts +76 -76
  195. package/types/src/ui/components/dialogs/chordText.d.ts +28 -28
  196. package/types/src/ui/components/dialogs/textBlockAtomNode.d.ts +20 -20
  197. package/types/src/ui/components/dialogs/textGroupHtml.d.ts +29 -29
  198. package/types/src/ui/composable/draggable.d.ts +15 -15
  199. package/types/src/ui/dialogs/adapter.d.ts +120 -120
  200. package/types/src/ui/dialogs/annotationVue.d.ts +9 -9
  201. package/types/src/ui/dialogs/audioSettings.d.ts +32 -32
  202. package/types/src/ui/dialogs/beamGroupsVue.d.ts +20 -0
  203. package/types/src/ui/dialogs/chordChangeVue.d.ts +8 -8
  204. package/types/src/ui/dialogs/createPartHelpers.d.ts +29 -0
  205. package/types/src/ui/dialogs/customTupletsVue.d.ts +9 -9
  206. package/types/src/ui/dialogs/deleteSpecial.d.ts +8 -0
  207. package/types/src/ui/dialogs/dialog.d.ts +203 -203
  208. package/types/src/ui/dialogs/dynamicsVue.d.ts +10 -10
  209. package/types/src/ui/dialogs/factory.d.ts +15 -15
  210. package/types/src/ui/dialogs/fileDialogs.d.ts +4 -4
  211. package/types/src/ui/dialogs/hairpin.d.ts +35 -35
  212. package/types/src/ui/dialogs/hairpinVue.d.ts +7 -7
  213. package/types/src/ui/dialogs/instrument.d.ts +3 -3
  214. package/types/src/ui/dialogs/keySignatureVue.d.ts +7 -7
  215. package/types/src/ui/dialogs/libraryVue.d.ts +15 -15
  216. package/types/src/ui/dialogs/lyricVue.d.ts +8 -8
  217. package/types/src/ui/dialogs/pasteSpecial.d.ts +8 -0
  218. package/types/src/ui/dialogs/pedalMarkingVue.d.ts +7 -7
  219. package/types/src/ui/dialogs/recovery.d.ts +8 -0
  220. package/types/src/ui/dialogs/rehearsalMark.d.ts +25 -25
  221. package/types/src/ui/dialogs/rehearsalMarkVue.d.ts +7 -7
  222. package/types/src/ui/dialogs/slur.d.ts +57 -57
  223. package/types/src/ui/dialogs/slurVue.d.ts +7 -7
  224. package/types/src/ui/dialogs/tempo.d.ts +50 -50
  225. package/types/src/ui/dialogs/tempoVue.d.ts +10 -10
  226. package/types/src/ui/dialogs/textBlockVue.d.ts +8 -8
  227. package/types/src/ui/dialogs/textBracket.d.ts +35 -35
  228. package/types/src/ui/dialogs/textBracketVue.d.ts +7 -7
  229. package/types/src/ui/dialogs/tie.d.ts +41 -41
  230. package/types/src/ui/dialogs/volta.d.ts +40 -40
  231. package/types/src/ui/dialogs/voltaVue.d.ts +7 -7
  232. package/types/src/ui/fileio/fileInput.d.ts +7 -1
  233. package/types/src/ui/fileio/library.d.ts +40 -40
  234. package/types/src/ui/fileio/scoreArchive.d.ts +55 -0
  235. package/types/src/ui/fileio/xhrLoader.d.ts +7 -0
  236. package/types/src/ui/menus/file.d.ts +8 -8
  237. package/types/src/ui/menus/language.d.ts +7 -7
  238. package/types/src/ui/menus/manager.d.ts +58 -58
  239. package/types/src/ui/menus/menu.d.ts +159 -159
  240. package/types/src/ui/menus/partSelection.d.ts +14 -14
  241. package/types/src/ui/menus/score.d.ts +8 -8
  242. package/types/src/ui/menus/staffModifier.d.ts +17 -17
  243. package/types/typedoc.d.ts +147 -147
  244. package/src/ui/dialogs/dynamics.ts +0 -141
  245. package/types/src/ui/dialogs/dynamics.d.ts +0 -37
@@ -0,0 +1,53 @@
1
+ # Quickstart: Validating Per-Measure Beam Groups
2
+
3
+ ## 1. Headless checks
4
+
5
+ ```text
6
+ npm run test:beam-groups
7
+ ```
8
+
9
+ Expected: every case in [contracts/beam-groups-api.md](contracts/beam-groups-api.md) prints `PASS` and the script exits 0.
10
+
11
+ Also run the suites that touch beaming and measure data, to check nothing regressed:
12
+
13
+ ```text
14
+ npm run test:beam-dotted
15
+ npm run test:paste-special
16
+ npm run test:score-archive
17
+ npm run test:create-part
18
+ ```
19
+
20
+ ## 2. Compile
21
+
22
+ ```text
23
+ npx tsc --noEmit -p tsconfig.json
24
+ ```
25
+
26
+ Expected: no errors.
27
+
28
+ ## 3. Manual: 3 + 2 in 5/8 (spec user story 1)
29
+
30
+ 1. Start a score, change the time signature to 5/8, and enter ten eighth notes (two measures).
31
+ 2. Select the first measure, open the Beams menu, choose **Beam Groups**.
32
+ 3. Press **Add group** twice, set Group 1 to 3 and Group 2 to 2, leave Apply To as **Selected measures**, press OK.
33
+ 4. Expected: the first measure beams 3 then 2. The second measure beams as it did before.
34
+ 5. Undo. Expected: the first measure returns to its old beaming in one step.
35
+
36
+ ## 4. Manual: compound meter and the whole score (user stories 2 and 3)
37
+
38
+ 1. Change to 12/8, enter twelve eighth notes in a measure, open **Beam Groups**, press **Add group** once, set Group 1 to 3, choose **Whole score**.
39
+ 2. Expected: four groups of three, in every measure of the score.
40
+ 3. Open the dialog again, press **Clear**, choose **Whole score**, OK. Expected: every measure returns to the standard grouping for its meter.
41
+ 4. In a 10/8 measure add two groups, 3 and 2. Expected: 3 + 2 + 3 + 2.
42
+
43
+ ## 5. Manual: adding and removing groups
44
+
45
+ Open the dialog on a measure with no grouping. Expected: no groups are shown, with the note "Default for the meter". Press **Add group** three times: the first group is 3 and the next two copy the last. Remove the middle group: the labels renumber and the other two keep their numbers. Try to type 0 or 9 in a group: it is brought back into 1 to 4. Press **Clear**: no groups remain.
46
+
47
+ ## 6. Manual: saving
48
+
49
+ Set a grouping, save the score as JSON, reload it. Expected: the grouping shows in the dialog and the beams are unchanged. Open a score saved before this feature. Expected: the beams are identical to the previous version.
50
+
51
+ ## 7. Manual: hand beams
52
+
53
+ In a grouped measure, select notes 2 to 4 and use **Beam Selections**. Expected: those notes stay beamed together across the boundary. Note: applying a grouping to a measure replaces any hand-placed beams in it.
@@ -0,0 +1,72 @@
1
+ # Research: Per-Measure Beam Groups
2
+
3
+ All unknowns from the Technical Context are resolved below. No `NEEDS CLARIFICATION` items remain.
4
+
5
+ ## R1: Where does beam length come from today?
6
+
7
+ **Finding**: `SmoBeamer.beamNote` (in `src/smo/xform/beamers.ts`) ends a group when `duration === note.beamBeats`. `beamBeats` is stored on each note. It is set from the score-wide preferences (`defaultDupleDuration` 4096, `defaultTripleDuration` 6144) by `SmoOperation.clearAllBeamGroups`/`clearBeamGroups`, and to 6144 for 8th-note meters in `SmoMeasure.timeSignatureNotes`. Hand-beaming (`SmoOperation.beamSelections`) writes the selected span's ticks into `beamBeats` and sets `beamState` (auto, continue, end).
8
+
9
+ **Decision**: Do not touch `beamBeats` or the preferences. A measure with a grouping bypasses the `beamBeats` logic inside the beamer and uses tick positions instead. A measure without one runs the existing code path unchanged.
10
+
11
+ **Rationale**: Writing the grouping into every note's `beamBeats` would be lost whenever notes are replaced or edited, and would break FR-007 (applied whenever the measure is beamed). Reading it at beam time cannot go stale.
12
+
13
+ **Alternatives considered**: Store the grouping on the notes (stale after edits, much more data); store it in the score preferences (not per measure).
14
+
15
+ ## R2: Position-based boundaries, not group counts
16
+
17
+ **Decision**: The grouping becomes a list of boundary tick positions, the list repeated from its first number until the measure's length: `[3, 2]` in 10/8 gives eighth-note positions 3, 5, 8, 10. A beam group never crosses a boundary. A note that starts before a boundary and ends after it stays in the group it started in, and the group closes after it.
18
+
19
+ **Rationale**: "The second number is used for the second beam group" is exactly this when the measure is all eighth notes. Counting positions also gives the right answer when a quarter note or a rest sits inside the measure (5/8 as quarter, eighth, eighth, eighth with "3, 2": the first eighth is alone before the boundary at 3, the last two beam). Counting groups would beam three eighths together there.
20
+
21
+ **Alternatives considered**: Counting completed groups (wrong beams when a non-beamable note falls inside a group).
22
+
23
+ ## R3: Unit
24
+
25
+ **Decision**: One number counts 2048 ticks (an eighth note), or 1024 ticks (a sixteenth) when the time signature's lower number is 16 or more. This is the spec's rule (FR-003). Meters with a lower number of 4 or 2 count eighths. The unit comes from the time signature of the measure at beam time, so a time signature change is picked up automatically.
26
+
27
+ ## R4: Repeat rule (from the 2026-11-08 clarification)
28
+
29
+ **Decision**: When the list is shorter than the measure, it starts over from its first number. A final repeat that does not fit is cut at the end of the measure, so "3, 2" in 7/8 gives 3 + 2 + 2.
30
+
31
+ ## R5: Interaction with hand-placed beam states
32
+
33
+ **Finding**: Notes carry `beamState`: auto, continue (joins the previous note), end (closes the group), secondary. `SmoMeasure.timeSignatureNotes` also writes `end` on every third rest of a new 8th-note measure, so `end` in old data is sometimes not hand-placed.
34
+
35
+ **Decision**:
36
+ 1. Applying or clearing a grouping on a measure resets that measure's notes to `beamState` auto, so stale or generated `end` marks cannot fight the new grouping. The dialog tells the user this.
37
+ 2. After that, hand edits win: an `end` state still closes a group (existing check, unchanged), and a `continue` note does not close a group at a boundary.
38
+ 3. `SmoOperation.beamSelections` marks every note of a hand-beamed span except the last `continue` when the measure has a grouping (the last note is `end`, as now). A `continue` note is never the end of a group at a boundary, which is how the beamer already treats `continue` at a beat. In ungrouped measures `beamSelections` behaves as before.
39
+
40
+ **Rationale**: Keeps FR-008 meaningful without guessing which `end` marks were hand-placed.
41
+
42
+ **Point to confirm with the user**: rule 1 replaces hand-placed beam states in the measures a grouping is applied to.
43
+
44
+ ## R6: Serialization and the .smz dictionary
45
+
46
+ **Finding**: Measure modifiers are saved as `{ ctor, ...fields }` and revived through `SmoDynamicCtor[ctor]` (`measureModifierDynamicCtorInit`). The `.smz` compression (`serializationHelpers.js`) builds its key dictionary from the data it is given and passes unknown keys through.
47
+
48
+ **Decision**: Register `SmoBeamPreferences` in `measureModifierDynamicCtorInit`. Use the field name `groups`. Do not call it `beamGroups`, which the measure already uses for rendered beam groups. Write the modifier only when the list is non-empty. No compression table change. A test loads a measure written before the feature (no such modifier) and one written with it.
49
+
50
+ **Alternatives considered**: A field on the measure itself (new top-level serialized key, more migration code than one more modifier).
51
+
52
+ ## R7: Copy and paste
53
+
54
+ **Finding**: Measure modifiers travel with `SmoMeasure.serialize`/`deserialize`. Whether paste and "add measure" copy modifiers is existing behaviour that differs by operation.
55
+
56
+ **Decision**: Rely on the existing measure copy mechanism (FR-018 says "in the same way as other measure-level formatting"). Add one test that serializes and deserializes a measure and checks the grouping is kept. No new copy code.
57
+
58
+ ## R8: Scope of the dialog
59
+
60
+ **Finding**: The key signature dialog offers selected measures, future measures, and the whole score, using `getMeasuresBetween` on staff 0 and `modifyColumnsSelectionsNoWait`, which affects whole columns. The spec limits the selection scope to the selected staves.
61
+
62
+ **Decision**: Two scopes: "Selected measures" (the measures in the selected staves, via `SmoSelection.getMeasureList`) and "Whole score" (every measure of every staff). One undo step each: `undoTrackerMeasureSelections` for the selection, `_undoScore` for the score. Changes go to both the displayed score and the stored score so partial-score (part) views stay consistent, as `clearSelectedBeams` does. A "Clear" action sets the empty list over the same scope.
63
+
64
+ ## R9: Dialog input
65
+
66
+ **Decision**: The dialog shows one number field (1 to 4, the existing number spinner) for each group, labeled "Group 1", "Group 2", and so on. An **Add group** (+) button adds a group, copying the last group's number (3 for the first), and each row has a remove button. **Clear** removes every group, which means the default for the meter. At most 16 groups can be added. Because the fields cannot hold anything but 1 to 4, there is no invalid state to report (FR-012 holds by construction).
67
+
68
+ **Alternatives considered**: A single text field of comma-separated numbers (first version; it gave no visible way to add a second group, and needs a parser and error messages); a fixed number of dropdowns (needs a cap on groups, clumsy for 12/8).
69
+
70
+ ## R10: Menu placement
71
+
72
+ **Decision**: Add "Beam Groups" to the existing Beams menu (`SuiBeamMenuOptions`). The handler opens the Vue dialog directly, as `tabStaveMenuOption` does.
@@ -0,0 +1,146 @@
1
+ # Feature Specification: Per-Measure Beam Groups
2
+
3
+ **Feature Branch**: `038-per-measure-beam-groups`
4
+
5
+ **Created**: 2026-11-08
6
+
7
+ **Status**: Draft
8
+
9
+ **Input**: User description: "Make default beaming lengths configurable per-measure and to support compound meter. SmoBeamPreferences will be derived from SmoMeasureModifierBase. SmoScorePreferences currently has defaultDoubleDuration which is supposed to decide beaming lengths for eighth notes in even meter or triple meter. We should have beaming groups that can be specified per-measure. It is an array of integers between 1 and 4. By default the array is empty so we use the default duration for the meter. The numbers specify the longest beam groups of 1/8 notes, or 16th notes if the time denominator is 16. If there are 2 numbers in the array, the second number is used for the second beam group. This supports compound meter or non-standard grouping, for instance, 3 + 2 beams for 5/8 time. The dialog should allow the user to specify measures, selection, or score."
10
+
11
+ ## Clarifications
12
+
13
+ ### Session 2026-11-08
14
+
15
+ - Q: When a measure has more beam groups than numbers in its grouping, what happens to the extra groups? → A: The grouping repeats from its first number.
16
+
17
+ ## User Scenarios & Testing *(mandatory)*
18
+
19
+ ### User Story 1 - Beam an irregular meter as 3 + 2 (Priority: P1)
20
+
21
+ A composer writes a measure of 5/8. Today the notes beam according to the score-wide duple or triple default, which gives the wrong grouping for 5/8. The composer opens the beam groups dialog, chooses the selected measure, and enters the grouping "3, 2". The eighth notes in that measure now beam as three, then two. A 2 + 3 grouping can be entered the same way for measures that are felt that way.
22
+
23
+ **Why this priority**: This is the case the existing defaults cannot handle at all, and it is the reason for the feature. Everything else builds on a measure being able to carry its own grouping.
24
+
25
+ **Independent Test**: Enter ten eighth notes across two 5/8 measures, set the grouping "3, 2" on the first measure only, and confirm the first beams 3 + 2 while the second keeps the standard grouping for the meter.
26
+
27
+ **Acceptance Scenarios**:
28
+
29
+ 1. **Given** a 5/8 measure of five eighth notes with no grouping set, **When** the user sets the grouping to "3, 2" for that measure, **Then** the first three notes beam together and the last two beam together.
30
+ 2. **Given** a 5/8 measure with grouping "3, 2", **When** the user sets it to "2, 3", **Then** the beams change to two then three.
31
+ 3. **Given** a 5/8 measure with grouping "3, 2" and a neighbouring 5/8 measure with none, **When** the score is displayed, **Then** only the first measure uses the custom grouping.
32
+
33
+ ---
34
+
35
+ ### User Story 2 - Compound meter beams by dotted beats (Priority: P1)
36
+
37
+ A user writing in 9/8, 12/8 or 6/8 wants beams that follow the beat: groups of three eighth notes. They select the measures and enter the grouping "3". Every beam group in those measures is three eighths long, however many beats the measure has. A grouping such as "3, 3, 2" is also accepted for measures with an irregular pulse, such as 8/8.
38
+
39
+ **Why this priority**: Compound meter is named in the request. It also exercises the rule for measures that have more beam groups than numbers in the grouping.
40
+
41
+ **Independent Test**: Enter a 12/8 measure of twelve eighth notes, set the grouping to "3", and confirm there are four beams of three. Then set "3, 3, 2" on an 8/8 measure and confirm the groups are 3 + 3 + 2.
42
+
43
+ **Acceptance Scenarios**:
44
+
45
+ 1. **Given** a 12/8 measure of twelve eighth notes, **When** the user sets the grouping to "3", **Then** the notes beam in four groups of three.
46
+ 2. **Given** an 8/8 measure of eight eighth notes, **When** the user sets the grouping to "3, 3, 2", **Then** the notes beam as 3 + 3 + 2.
47
+ 3. **Given** a 6/16 measure of six sixteenth notes, **When** the user sets the grouping to "3", **Then** the notes beam in two groups of three sixteenths.
48
+ 4. **Given** a 10/8 measure of ten eighth notes, **When** the user sets the grouping to "3, 2", **Then** the notes beam as 3 + 2 + 3 + 2.
49
+
50
+ ---
51
+
52
+ ### User Story 3 - Apply a grouping to the selection or the whole score (Priority: P2)
53
+
54
+ The user wants to set the grouping once and apply it to many measures. The beam groups dialog lets the user choose the scope: the measures covered by the current selection, or the whole score. The user can also clear the grouping on the same scope to return to the standard grouping for the meter.
55
+
56
+ **Why this priority**: Without this the user must repeat the dialog for every measure. Per-measure editing (Story 1) is still useful on its own, so this ranks below it.
57
+
58
+ **Independent Test**: Select measures 3 to 6 of a 6/8 piece, apply the grouping "3", and confirm measures 3 to 6 change while the others do not. Apply it to the whole score and confirm all measures change. Clear it on the whole score and confirm every measure reverts.
59
+
60
+ **Acceptance Scenarios**:
61
+
62
+ 1. **Given** measures 3 to 6 are selected, **When** the user applies the grouping "3" to the selected measures, **Then** measures 3 to 6 use it and no other measure changes.
63
+ 2. **Given** a grouping is set on several measures, **When** the user clears the grouping for the score, **Then** every measure returns to the standard grouping for its meter.
64
+ 3. **Given** a multi-staff score, **When** the user applies a grouping to the selected measures, **Then** it applies to the same measures in the staves covered by the selection and no other staves change.
65
+
66
+ ---
67
+
68
+ ### User Story 4 - Existing scores and the score-wide default are unchanged (Priority: P2)
69
+
70
+ A user opens a score saved before this feature. Every measure beams exactly as it did, and the existing score-wide default beam length setting still works for any measure that has no grouping of its own. Saving and reopening a score keeps any groupings that were set.
71
+
72
+ **Why this priority**: This protects existing work and is required for the feature to ship safely, but it adds no new capability.
73
+
74
+ **Independent Test**: Open a score saved before the feature, confirm the beams are identical. Set groupings on some measures, save, reopen, and confirm they are kept.
75
+
76
+ **Acceptance Scenarios**:
77
+
78
+ 1. **Given** a score saved before this feature, **When** it is opened, **Then** all beams are unchanged and no measure has a grouping.
79
+ 2. **Given** a measure with no grouping, **When** the score-wide default beam length is changed, **Then** that measure follows the new default.
80
+ 3. **Given** a measure with a grouping, **When** the score-wide default beam length is changed, **Then** that measure keeps its own grouping.
81
+ 4. **Given** a score with groupings set on some measures, **When** it is saved and reopened, **Then** the groupings are preserved.
82
+
83
+ ---
84
+
85
+ ### Edge Cases
86
+
87
+ - A grouping that adds up to more notes than the measure holds: the last group is cut at the end of the measure.
88
+ - A grouping that adds up to fewer notes than the measure holds: the grouping starts over from its first number for the rest of the measure. For example, "3" in 12/8 gives four groups of three, and "3, 2" in 10/8 gives 3 + 2 + 3 + 2. If the measure ends partway through a repeat, the final group is shorter (for example "3, 2" in 7/8 gives 3 + 2 + 2).
89
+ - A note that cannot sit inside a beam, such as a quarter note, or a rest at the start of a group, still ends the group; the grouping only decides how far beams may extend.
90
+ - Notes longer than an eighth, including dotted-eighth and sixteenth figures, count by their duration in the grouping unit (eighths, or sixteenths when the meter's lower number is 16). A group is closed once its total length reaches the number.
91
+ - Beam breaks or beam joins that the user placed by hand on individual notes take precedence over the measure's grouping.
92
+ - Values outside 1 to 4, non-numbers or empty entries are rejected in the dialog with a clear message, and the measure is left unchanged.
93
+ - A tuplet is beamed as a unit as it is today; a measure grouping does not split a tuplet.
94
+ - A time signature change partway through a selection: each measure uses the unit for its own time signature.
95
+ - A pickup (partial) measure: the grouping applies from the start of the measure.
96
+
97
+ ## Requirements *(mandatory)*
98
+
99
+ ### Functional Requirements
100
+
101
+ - **FR-001**: Each measure MUST be able to hold a beam grouping: an ordered list of whole numbers, each between 1 and 4.
102
+ - **FR-002**: By default a measure's grouping MUST be empty. A measure with an empty grouping MUST beam using the score-wide default beam length for its meter type, exactly as it does today.
103
+ - **FR-003**: Each number in the grouping MUST give the maximum length of one beam group, counted in eighth notes, or in sixteenth notes when the measure's time signature has 16 as its lower number.
104
+ - **FR-004**: The first number MUST govern the first beam group in the measure, the second number the second beam group, and so on.
105
+ - **FR-005**: When a measure has more beam groups than numbers in its grouping, the grouping MUST repeat from its first number until the end of the measure.
106
+ - **FR-006**: A grouping MUST be able to express compound meters (such as 6/8, 9/8 and 12/8) and irregular grouping (such as 3 + 2 and 2 + 3 in 5/8, or 3 + 3 + 2 in 8/8).
107
+ - **FR-007**: A measure's grouping MUST be applied whenever the measure is beamed, including after the user edits notes, changes durations, or changes the time signature.
108
+ - **FR-008**: Beam groups that were placed by hand on individual notes MUST NOT be overridden by the measure grouping.
109
+ - **FR-009**: The user MUST be able to open a beam groups dialog and enter a grouping.
110
+ - **FR-010**: The dialog MUST let the user choose where the grouping is applied: the measures covered by the current selection, or the whole score.
111
+ - **FR-011**: The dialog MUST let the user clear the grouping for the chosen scope, returning those measures to the standard grouping for their meter.
112
+ - **FR-012**: The dialog MUST reject numbers outside 1 to 4 and entries that are not whole numbers, and MUST tell the user why.
113
+ - **FR-013**: When the dialog opens on a measure that already has a grouping, it MUST show that grouping.
114
+ - **FR-014**: Changing a grouping MUST update the displayed score without requiring any other action from the user.
115
+ - **FR-015**: A change to a grouping MUST be undoable as a single step.
116
+ - **FR-016**: A measure's grouping MUST be saved with the score and restored when the score is opened.
117
+ - **FR-017**: Scores saved before this feature MUST open with every measure ungrouped and beamed as before.
118
+ - **FR-018**: The grouping MUST be carried with the measure when the measure is copied, in the same way as other measure-level formatting.
119
+
120
+ ### Key Entities *(include if feature involves data)*
121
+
122
+ - **Beam grouping (per measure)**: An ordered list of whole numbers from 1 to 4 attached to a measure. Empty means "use the default for the meter". It is a measure setting like other per-measure settings, and is saved with the measure.
123
+ - **Score-wide default beam length**: The existing preference that sets beam length for duple and triple meters. It remains the fallback for any measure with no grouping.
124
+ - **Measure**: Gains an optional beam grouping. Its time signature determines whether the numbers count eighth or sixteenth notes.
125
+
126
+ ## Success Criteria *(mandatory)*
127
+
128
+ ### Measurable Outcomes
129
+
130
+ - **SC-001**: A user can change a measure from the standard grouping to 3 + 2 in 5/8 in under 30 seconds, with a single visit to the dialog.
131
+ - **SC-002**: A user can apply one grouping to every measure of a score in a single dialog action.
132
+ - **SC-003**: For a test set covering 5/8, 6/8, 9/8, 12/8, 8/8 and 6/16 time, the beams produced match the entered grouping in 100% of cases.
133
+ - **SC-004**: 100% of scores saved before this feature open with identical beams to the previous version.
134
+ - **SC-005**: 100% of groupings set in a score survive saving and reopening the score.
135
+ - **SC-006**: Invalid entries (outside 1 to 4, non-numeric) are rejected 100% of the time, and the measure is left unchanged.
136
+
137
+ ## Assumptions
138
+
139
+ - The request refers to the score-wide default beam length setting as "defaultDoubleDuration"; in the application this is the duple-meter default beam length. It remains unchanged and is the fallback when a measure has no grouping.
140
+ - The request lists "measures, selection, or score" as scopes. Because the grouping belongs to measures, "measures" and "selection" are treated as the same thing: the measures covered by the current selection. Together with "whole score" this matches the "Apply To" convention of existing dialogs. A "remaining measures" scope is offered by some other dialogs but was not requested, so it is out of scope here.
141
+ - A grouping applies to all voices of the measure, and only to the staves covered by the selection when the scope is the selection.
142
+ - A measure whose lower time number is 4 or 2 counts the grouping in eighth notes.
143
+ - A group may be shorter than its number when it is cut off by a note that cannot be beamed, by a rest, or by the end of the measure.
144
+ - Showing the grouping in the dialog is sufficient; no new on-staff marking of the grouping is required.
145
+ - Changing the beaming of tuplets is out of scope.
146
+ - Localization of the new dialog follows the existing practice for dialogs.
@@ -0,0 +1,132 @@
1
+ ---
2
+
3
+ description: "Task list for Per-Measure Beam Groups"
4
+ ---
5
+
6
+ # Tasks: Per-Measure Beam Groups
7
+
8
+ **Input**: Design documents from `/specs/038-per-measure-beam-groups/`
9
+
10
+ **Prerequisites**: [plan.md](plan.md), [spec.md](spec.md), [research.md](research.md), [data-model.md](data-model.md), [contracts/beam-groups-api.md](contracts/beam-groups-api.md), [quickstart.md](quickstart.md)
11
+
12
+ **Tests**: Included. The constitution asks for regression tests on editing logic and serialization. The modifier, boundary calculation, beaming, operations and parsing helper are tested headless in `tests/beamGroups.ts`; the dialog, menu and view method are checked by compilation and [quickstart.md](quickstart.md).
13
+
14
+ **Organization**: Tasks are grouped by user story. The modifier, the measure accessors and the beamer change are needed 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 to US4)
20
+
21
+ ## Phase 1: Setup
22
+
23
+ - [X] T001 Create `tests/beamGroups.ts` with the `check()`/failure-count harness and the dynamic-ctor registration used in `tests/beamDotted.ts` (`noteModifierDynamicCtorInit`, `measureModifierDynamicCtorInit`, `staffModifierDynamicCtorInit`, `scoreModifierDynamicCtorInit`). Add helpers: `buildMeasure(actualBeats, beatDuration, ticks: number[])` that makes a default score, sets the first measure's time signature with `new SmoTimeSignature({ ...SmoTimeSignature.defaults, times: [{ actualBeats, beatDuration }] })`, replaces `voices[0].notes` with notes cloned from the default note by `SmoNote.cloneWithDuration` with `noteType = 'n'` (as in `tests/beamDotted.ts`), and returns the measure; `beamSizes(measure)` that runs `SmoBeamer.applyBeams(measure)` and returns `measure.beamGroups.map((bg) => bg.notes.length).join(',')`; and `eighths(n)` returning an array of n values of 2048. Register `"test:beam-groups": "ts-node -P tests/tsconfig.json tests/beamGroups.ts"` in `package.json`
24
+
25
+ ---
26
+
27
+ ## Phase 2: Foundational (Blocking Prerequisites)
28
+
29
+ **Purpose**: The modifier, the measure accessors and the beamer's boundary logic. See [data-model.md](data-model.md) and [research.md](research.md) R1 to R6.
30
+
31
+ - [X] T002 Add `SmoBeamPreferences` to `src/smo/data/measureModifiers.ts`, deriving from `SmoMeasureModifierBase` with `super('SmoBeamPreferences')`. Fields and API per [data-model.md](data-model.md): `groups: number[]`; `static readonly minGroup = 1`, `maxGroup = 4`; `static isValidGroups(values: number[]): boolean` (every entry a whole number from 1 to 4; an empty list is valid); `static unitTicks(timeSignature: SmoTimeSignature): number` (1024 when `beatDuration >= 16`, otherwise 2048); a constructor taking `{ groups: number[] }` that copies the list and throws on an invalid list; `serialize()` returning `{ ctor: 'SmoBeamPreferences', groups }`. Export the params and serialized types. Add `SmoDynamicCtor['SmoBeamPreferences'] = (params) => new SmoBeamPreferences(params)` to `measureModifierDynamicCtorInit`
32
+ - [X] T003 In `src/smo/data/measure.ts` add `getBeamGroups(): number[]` (copy of the singleton modifier's `groups`, or `[]`) and `setBeamGroups(groups: number[])`. `setBeamGroups` removes any existing `SmoBeamPreferences` with `_removeSingletonModifier`, validates with `SmoBeamPreferences.isValidGroups` (throw on invalid), pushes a new modifier when the list is non-empty, and sets `beamState = SmoNote.beamStates.auto` on every note of every voice (research R5). Import `SmoBeamPreferences` next to the existing measure modifier imports
33
+ - [X] T004 In `src/smo/xform/beamers.ts` add `static groupBoundaries(measure: SmoMeasure): number[]` to `SmoBeamer`: return `[]` when `measure.getBeamGroups()` is empty; otherwise compute tick positions with unit `SmoBeamPreferences.unitTicks(measure.timeSignature)` and measure length `measure.timeSignature.ticksFromTimeSignature()`, repeating the list from its first number and clamping the last position to the measure length, as in [data-model.md](data-model.md)
34
+ - [X] T005 In `src/smo/xform/beamers.ts` change `SmoBeamer` so that when `groupBoundaries` is non-empty `beamNote` uses boundaries: compute the boundaries once in the constructor (field `boundaries`, plus `boundaryIndex`); for a non-tuplet note, work out `start = this.measureDuration - tickmap.deltaMap[index]` and `end = this.measureDuration`; first advance `boundaryIndex` past every boundary at or before `start`; push the note; keep the existing `beamState === end` and last-note-in-voice handling; after pushing, if `end >= boundaries[boundaryIndex]` and the note's `beamState` is not `continue`, call `_completeGroup`/`_advanceGroup` and advance `boundaryIndex` past every boundary at or before `end`; then return, skipping the half-measure, beat-alignment and `beamBeats` checks. Tuplet notes, rests at the start of a group and notes of 4096 ticks or more keep the existing code. When `boundaries` is empty nothing changes
35
+ - [X] T006 Run `npx tsc --noEmit -p tsconfig.json` and `npm run test:beam-dotted` to confirm the foundation compiles and the existing beaming test still passes (no grouped measures yet)
36
+
37
+ **Checkpoint**: A measure can hold a grouping and the beamer honors it. Nothing yet lets a user set one.
38
+
39
+ ---
40
+
41
+ ## Phase 3: User Story 1 - Beam an irregular meter as 3 + 2 (Priority: P1)
42
+
43
+ **Goal**: A user selects a measure, opens Beam Groups, enters `3, 2`, and the measure beams 3 + 2.
44
+
45
+ **Independent Test**: Run the contract cases B1, B2, B8, M1, M2, M3, M8 and the operation and parser cases in `tests/beamGroups.ts`, then run [quickstart.md](quickstart.md) section 3.
46
+
47
+ - [X] T007 [US1] (dropped) The text-parsing helper `src/ui/dialogs/beamGroupHelpers.ts` was removed when the dialog changed to one number field per group with an Add group button; nothing parses text any more
48
+ - [X] T008 [P] [US1] Add `SmoOperation.setBeamGroups(score: SmoScore, selections: SmoSelection[], groups: number[])` to `src/smo/xform/operations.ts`: for each distinct measure in `selections` (de-duplicate by staff and measure index) call `measure.setBeamGroups(groups)`. It touches only the staves in the selections
49
+ - [X] T009 [US1] Add `setBeamGroups(groups: number[], scope: 'selections' | 'all'): Promise<void>` to `SuiScoreViewOperations` in `src/render/sui/scoreViewOperations.ts`. For `'selections'`: `const measureSelections = this.undoTrackerMeasureSelections('beam groups')`, apply `SmoOperation.setBeamGroups` to `this.score` with the tracker selections and to `this.storeScore` with `this._getEquivalentSelections(selections)` (as `clearSelectedBeams` does), then `this._renderChangedMeasures(measureSelections)` and `await this.renderer.updatePromise()`. Implement only the `'selections'` branch here; T014 adds `'all'`
50
+ - [X] T010 [US1] Create `src/ui/components/dialogs/beamGroups.vue` following `keySignature.vue`: props `domId`, `label`, `initialGroups`, `applyTo`, `setGroupsCb`, `setApplyToCb`, `commitCb`, `cancelCb`. It shows one `numberInput.vue` (1 to 4) for each group, labeled "Group N" with a remove button, an **Add group** (+) button (at most 16 groups; a new group copies the last one's number, or 3 for the first), a Clear button, the explanatory text, an Apply To select (`selections`: 'Selected measures', `all`: 'Whole score') and the note that applying replaces hand-placed beams. Each row has a stable id so removing a row does not shift values. Wrap in `dialogContainer`
51
+ - [X] T011 [US1] Create `src/ui/dialogs/beamGroupsVue.ts` exporting `SuiBeamGroupsDialogVue(parameters: SuiDialogParams)`, modeled on `src/ui/dialogs/keySignatureVue.ts`. It reads the first selected measure's `getBeamGroups()` for the initial groups, keeps `groups` and `applyTo` state, and on commit calls `view.setBeamGroups(groups, applyTo)`. Use `replaceVueRoot(modalContainerId)` and `InstallDialog` as in the key signature dialog; use `ctor: 'SuiBeamGroupsDialog'`
52
+ - [X] T012 [US1] Add a "Beam Groups" option to `src/ui/menus/beams.ts` (`menuChoice: { icon: 'bv tall bv-beamed', text: 'Beam Groups', value: 'beamGroupsMenuOption' }`, `display: () => true`) whose handler calls `SuiBeamGroupsDialogVue({ ctor: 'SuiBeamGroupsDialog', id: 'beamGroupsDialog', tracker: menu.view.tracker, completeNotifier: menu.completeNotifier, startPromise: null, view: menu.view, eventSource: menu.eventSource })`, as `tabStaveMenuOption` does in `src/ui/menus/parts.ts`; add it to `SuiBeamMenuOptions`
53
+ - [X] T013 [US1] In `tests/beamGroups.ts` add the checks: boundaries B1, B2, B8; beaming M1, M2, M3 (compare an ungrouped 5/8 measure's `beamSizes` before and after a set/clear round trip), M8; `SmoOperation.setBeamGroups` sets exactly the selected measures (two staves, select one) and leaves others empty; `SmoMeasure.setBeamGroups` replaces rather than duplicates, rejects `[5]`, `[0]`, `[1.5]`, and resets notes to `beamState` auto. Run `npm run test:beam-groups`
54
+
55
+ **Checkpoint**: User story 1 works end to end for selected measures.
56
+
57
+ ---
58
+
59
+ ## Phase 4: User Story 2 - Compound meter beams by dotted beats (Priority: P1)
60
+
61
+ **Goal**: 6/8, 9/8, 12/8, 8/8, 10/8 and x/16 measures beam by the entered grouping, including the repeat rule.
62
+
63
+ **Independent Test**: Contract cases B3 to B7, B9, M4 to M7, M9 pass, then [quickstart.md](quickstart.md) section 4.
64
+
65
+ - [X] T014 [US2] In `tests/beamGroups.ts` add boundary cases B3, B4, B5, B6, B7, B9 and beaming cases M4, M5, M6 (10/8 with `[3, 2]` gives `3,2,3,2`), M7 (6/16 with six notes of 1024 ticks), M9. Fix `src/smo/xform/beamers.ts` if any fails (the likely places are the unit for /16 and the final partial repeat)
66
+ - [X] T015 [US2] Add a regression check in `tests/beamGroups.ts` that a 4/4 measure and a 6/8 measure with no grouping beam the same as before this feature: record the `beamSizes` for eighths, sixteenths and dotted figures in 4/4, 3/4 and 6/8 using the cases in `tests/beamDotted.ts`, and assert them
67
+
68
+ **Checkpoint**: Compound and irregular meters work for selected measures.
69
+
70
+ ---
71
+
72
+ ## Phase 5: User Story 3 - Apply to the selection or the whole score (Priority: P2)
73
+
74
+ **Goal**: The dialog applies a grouping to the whole score, and Clear returns measures to the default.
75
+
76
+ **Independent Test**: Contract operation cases for `setAllBeamGroups`, then [quickstart.md](quickstart.md) section 4 steps 1 to 3.
77
+
78
+ - [X] T016 [P] [US3] Add `SmoOperation.setAllBeamGroups(score: SmoScore, groups: number[])` to `src/smo/xform/operations.ts`: call `measure.setBeamGroups(groups)` on every measure of every staff
79
+ - [X] T017 [US3] Add the `'all'` branch to `setBeamGroups` in `src/render/sui/scoreViewOperations.ts`: `this._undoScore('beam groups')`, `SmoOperation.setAllBeamGroups(this.score, groups)` and `SmoOperation.setAllBeamGroups(this.storeScore, groups)`, then `await this.awaitRender()` as `clearAllBeams` does
80
+ - [X] T018 [US3] Add a "Clear" button to `src/ui/components/dialogs/beamGroups.vue` that removes every group (an empty list clears the grouping on the chosen scope)
81
+ - [X] T019 [US3] In `tests/beamGroups.ts` add checks: `setAllBeamGroups` sets every measure of a two-staff, three-measure score; `setAllBeamGroups(score, [])` clears every measure and the serialized measures have no `SmoBeamPreferences` entry; `setBeamGroups` on a selection in staff 1 leaves staff 0 unchanged
82
+
83
+ **Checkpoint**: The scope choices and Clear work.
84
+
85
+ ---
86
+
87
+ ## Phase 6: User Story 4 - Existing scores and the default are unchanged (Priority: P2)
88
+
89
+ **Goal**: Old scores load and beam as before, the score-wide default still applies to ungrouped measures, and groupings are saved.
90
+
91
+ **Independent Test**: Contract serialization cases S1 to S3 and the fallback checks pass.
92
+
93
+ - [X] T020 [US4] In `tests/beamGroups.ts` add S1 (a score with groupings on measures 2 and 4, through `score.serialize()` and `SmoScore.deserialize`, keeps them and keeps measures 1 and 3 empty) and S2 (a serialized score containing no `SmoBeamPreferences` entries loads with every measure reporting `[]` and the same `beamSizes` as before). Use `JSON.parse(JSON.stringify(...))` on the serialized score to prove it is plain data
94
+ - [X] T021 [US4] In `tests/beamGroups.ts` add S3: round trip a grouped score through the `.smz` compression in `src/common/serializationHelpers.js` (see how `tests/scoreArchive.ts` or the score-archive code exercises it) and check the groupings survive. Add the fallback check: change `score.preferences.defaultDupleDuration` and confirm an ungrouped measure's notes follow `clearAllBeamGroups` as before while a grouped measure's `getBeamGroups()` is unchanged
95
+ - [X] T022 [US4] Add a check in `tests/beamGroups.ts` that a measure copied through `SmoMeasure.serialize()` then `SmoMeasure.deserialize()` keeps its grouping (FR-018, research R7)
96
+
97
+ **Checkpoint**: Compatibility and persistence are verified.
98
+
99
+ ---
100
+
101
+ ## Phase 7: Polish and Cross-Cutting Concerns
102
+
103
+ - [X] T023 In `src/smo/xform/operations.ts` change `SmoOperation.beamSelections` so that when the measure of the beamed notes has a non-empty `getBeamGroups()`, every note of the hand-beamed span except the last is marked `SmoNote.beamStates.continue` (the last note still gets `end`). Ungrouped measures keep today's behavior exactly (research R5, rule 3)
104
+ - [X] T024 In `tests/beamGroups.ts` add M10, M11 and M12 from the contract (an `end` state still closes a group; a hand beam with `continue` is not split at a boundary; a tuplet is beamed as before) and a check that `beamSelections` in an ungrouped measure leaves note states as it did before
105
+ - [X] T025 [P] Regenerate declarations for the changed source files only. Run `npm run types`, then keep only the `types/src/...` changes for `measureModifiers`, `measure`, `beamers`, `operations`, `scoreViewOperations`, and the new `beamGroupsVue` file (restore any unrelated declaration churn with `git checkout -- <file>`)
106
+ - [X] T026 [P] Add a `changes.md` entry (follow the entries at the top of the file) describing per-measure beam groups, the Beam Groups menu item, and that applying a grouping replaces hand-placed beam states in those measures
107
+ - [X] T027 Run `npx tsc --noEmit -p tsconfig.json`, then `npm run test:beam-groups`, `npm run test:beam-dotted`, `npm run test:paste-special`, `npm run test:score-archive`, `npm run test:create-part`, `npm run test:move-part`. All must pass
108
+ - [ ] T028 Walk through [quickstart.md](quickstart.md) sections 3 to 7 by hand in the running application (`npm run build`, then load the app) and note any difference from the expected results
109
+
110
+ ---
111
+
112
+ ## Dependencies and Execution Order
113
+
114
+ - Phase 1 (T001) first. Phase 2 (T002 to T006) blocks every story. T002 before T003 and T004; T004 before T005.
115
+ - US1 (T007 to T013) depends on Phase 2. T007 and T008 are independent files. T009 needs T008. T010 and T011 need T007 and T009. T012 needs T011. T013 needs T007, T008 and T003 to T005.
116
+ - US2 (T014, T015) depends only on Phase 2 and can run alongside US1's UI work.
117
+ - US3 (T016 to T019) depends on US1 (T009, T010, T011).
118
+ - US4 (T020 to T022) depends on Phase 2 and can run alongside US1 to US3.
119
+ - Polish (T023 to T028) after the stories; T023 and T024 can start after Phase 2.
120
+
121
+ ### Parallel opportunities
122
+
123
+ - T007 and T008 (different files).
124
+ - T014 and T015 once Phase 2 is done.
125
+ - T016 alongside T010 and T011.
126
+ - T025 and T026.
127
+
128
+ ## Implementation Strategy
129
+
130
+ **MVP**: Phase 1, Phase 2, then US1 (T001 to T013): a user can set a grouping on selected measures and see 3 + 2 in 5/8. US2 adds test coverage for compound meters and the repeat rule against the same code, so ship it with US1 if desired. US3 adds the whole-score scope and Clear. US4 locks in compatibility. Polish adds hand-beam handling, declarations, changelog and the manual walkthrough.
131
+
132
+ Run `npm run test:beam-groups` after each phase.
@@ -0,0 +1,35 @@
1
+ # Specification Quality Checklist: Measure Fill Submenu
2
+
3
+ **Purpose**: Validate specification completeness and quality before proceeding to planning
4
+ **Created**: 2026-11-09
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
+ - The examples table was checked against the rest durations the application can represent (dotted and double-dotted values are valid, dotted whole is valid), so 7/8 is one double-dotted half rest and 9/8 is a whole rest plus an eighth rest under the "largest rest" rule.
35
+ - Assumptions record the readings of the request for the user to confirm: the "Beats" rule for meters the request does not name (x/2, x/16, odd x/8), the remainder rule that keeps a measure from being left short, the "largest rest" result for 9/8, and that the submenu goes in the Measure menu.
@@ -0,0 +1,56 @@
1
+ # Contract: Measure Fill
2
+
3
+ This lists the behaviour that `tests/measureFill.ts` checks, and the interfaces the menu depends on. Case ids are used in the test names.
4
+
5
+ ## `fillRestDurations(timeSignature, fill, totalTicks?)`
6
+
7
+ Every row of the table in [data-model.md](../data-model.md) is a case (ids D1 to D39, three fills for each of the 13 meters). In addition:
8
+
9
+ | Id | Case | Expected |
10
+ |----|------|----------|
11
+ | D40 | every result adds up to the target length | for all meters and fills in the table, `sum(durations) === totalTicks` |
12
+ | D41 | every result uses only valid durations | each value is a key of `SmoMusic.validDurations` |
13
+ | D42 | pickup length: 4/4 with `totalTicks` 4096, Whole Rest | `[4096]` |
14
+ | D43 | pickup length: 4/4 with `totalTicks` 4096, Beats | `[4096]` |
15
+ | D44 | pickup length: 4/4 with `totalTicks` 6144, Eighth Rests | `[2048, 2048, 2048]` |
16
+ | D45 | pickup length: 6/8 with `totalTicks` 2048, Beats | `[2048]` (shorter than a beat, filled greedily) |
17
+ | D46 | zero length | `[]` |
18
+
19
+ ## `SmoMeasure.fillWithRests`
20
+
21
+ - F1: after filling a measure that had two voices of notes, `voices.length === 1` and every note has `noteType === 'r'`.
22
+ - F2: the rests' tick counts equal the durations given, in order, and add up to the measure length.
23
+ - F3: `tupletTrees` and `beamGroups` are empty, and `activeVoice` is 0.
24
+ - F4: the time signature, clef, key signature, tempo, format and `modifiers` (barline, rehearsal mark, beam grouping) are the same as before.
25
+ - F5: every rest has the measure's key signature and clef.
26
+
27
+ ## `SmoOperation.fillMeasures`
28
+
29
+ | Id | Case | Expected |
30
+ |----|------|----------|
31
+ | O1 | select measures 2 and 3 of staff 1 in a two-staff, four-measure score, Beats | measures 2 and 3 of staff 1 are rests; every other measure of both staves has the same notes as before |
32
+ | O2 | measures in 4/4 and 6/8 selected together, Beats | four quarter rests and two dotted quarter rests |
33
+ | O3 | a measure with a tuplet, Whole Rest | no tuplet remains, one whole rest |
34
+ | O4 | a measure with notes carrying lyrics, dynamics and articulations | none of these remain (the notes are rests) |
35
+ | O5 | a slur starting in a filled measure and ending in a later measure | the slur is removed |
36
+ | O6 | a slur ending in a filled measure | the slur is removed |
37
+ | O7 | a hairpin starting before and ending after the filled measure | the hairpin is kept |
38
+ | O8 | a slur in a different staff over the same measures | kept |
39
+ | O9 | a text group attached to a note in a filled measure | removed from `score.textGroups` |
40
+ | O10 | a text group attached to a note in another measure | kept |
41
+ | O11 | a pickup measure (one quarter note in 4/4), Whole Rest | one quarter rest, the measure is still a pickup |
42
+ | O12 | the same fill applied twice | the measure is identical after the second application |
43
+ | O13 | a measure that is already one whole rest, Whole Rest | unchanged durations |
44
+ | O14 | a measure with its own beam grouping `[3, 2]` in 5/8, Eighth Rests | the grouping is still `[3, 2]` |
45
+ | O15 | rests get `beamBeats` equal to the score's triple default in 6/8 and duple default in 4/4 | as stated |
46
+
47
+ ## Serialization
48
+
49
+ - S1: a score with filled measures (one per fill type, and a pickup) serializes and deserializes with the same rest durations, and the preserved measure settings.
50
+ - S2: a score with no filled measures serializes to the same text as before the feature.
51
+
52
+ ## View and menu
53
+
54
+ `SuiScoreViewOperations.fillMeasures(fill: MeasureFillType): Promise<void>` applies the operation to the displayed and the stored score as one undo step, redraws, and waits for the render. Undo restores every voice, every removed staff modifier and every removed text group.
55
+
56
+ - The Measure menu has a "Fill Measures" entry that opens a submenu with "Whole Rest", "Beats" and "Eighth Rests". The entry and its choices are shown only when measures are selected.
@@ -0,0 +1,79 @@
1
+ # Data Model: Measure Fill Submenu
2
+
3
+ No new persisted data. A filled measure is an ordinary measure whose only voice holds rest notes.
4
+
5
+ ## MeasureFillType (new, not persisted)
6
+
7
+ `'wholeRest' | 'beats' | 'eighthRests'`: the three menu choices.
8
+
9
+ ## fillRestDurations (new pure function, `src/smo/xform/measureFill.ts`)
10
+
11
+ ```text
12
+ fillRestDurations(timeSignature: SmoTimeSignature, fill: MeasureFillType, totalTicks?: number): number[]
13
+ ```
14
+
15
+ Returns the duration, in ticks, of each rest in order. `totalTicks` defaults to the length of a full measure of the time signature. The result always adds up to `totalTicks` (it is empty only when `totalTicks` is 0).
16
+
17
+ Steps, with `T = totalTicks` (rules and reasons in [research.md](research.md) R1 to R3):
18
+
19
+ ```text
20
+ largest(left): the largest value in SmoMusic.validDurations that is <= left
21
+ greedy(left): repeat largest(left), subtracting, until left is 0
22
+ wholeRest: greedy(T)
23
+ beats: B beats of length B, floor(T / B) times, then greedy(T mod B)
24
+ eighthRests: 2048, floor(T / 2048) times, then greedy(T mod 2048)
25
+
26
+ beat length B:
27
+ lower number 1, 2, 4: 16384, 8192, 4096
28
+ lower number 8 or more: unit = 16384 / lower
29
+ compound (top number is a multiple of 3): 3 * unit
30
+ otherwise: 2 * unit
31
+ ```
32
+
33
+ Expected results (ticks; 2048 is an eighth, 4096 a quarter, 6144 a dotted quarter, 8192 a half, 12288 a dotted half, 16384 a whole):
34
+
35
+ | Meter | Whole Rest | Beats | Eighth Rests |
36
+ |-------|-----------|-------|--------------|
37
+ | 4/4 | 16384 | 4096 x 4 | 2048 x 8 |
38
+ | 2/4 | 8192 | 4096 x 2 | 2048 x 4 |
39
+ | 3/4 | 12288 | 4096 x 3 | 2048 x 6 |
40
+ | 6/8 | 12288 | 6144 x 2 | 2048 x 6 |
41
+ | 9/8 | 16384, 2048 | 6144 x 3 | 2048 x 9 |
42
+ | 12/8 | 24576 | 6144 x 4 | 2048 x 12 |
43
+ | 5/8 | 8192, 2048 | 4096 x 2, 2048 | 2048 x 5 |
44
+ | 7/8 | 14336 | 4096 x 3, 2048 | 2048 x 7 |
45
+ | 3/8 | 6144 | 6144 | 2048 x 3 |
46
+ | 4/8 | 8192 | 4096 x 2 | 2048 x 4 |
47
+ | 2/2 | 16384 | 8192 x 2 | 2048 x 8 |
48
+ | 6/16 | 6144 | 3072 x 2 | 2048 x 3 |
49
+ | 5/16 | 4096, 1024 | 2048 x 2, 1024 | 2048 x 2, 1024 |
50
+
51
+ ## SmoMeasure (changed)
52
+
53
+ | Member | Behaviour |
54
+ |--------|-----------|
55
+ | `fillWithRests(durations: number[], beamBeats: number)` | Replaces `voices` with one voice of rest notes of the given durations (clef pitch, key signature of the measure, `beamBeats` as given), empties `tupletTrees` and `beamGroups`, sets `activeVoice` to 0. Does not change `modifiers`, `timeSignature`, `clef`, `keySignature`, `tempo` or `format`. |
56
+
57
+ ## SmoOperation.fillMeasures (new)
58
+
59
+ ```text
60
+ fillMeasures(score: SmoScore, selections: SmoSelection[], fill: MeasureFillType): void
61
+ ```
62
+
63
+ For each distinct (staff, measure) in `selections`:
64
+
65
+ 1. `target` = ticks voice 0 holds if the measure is a pickup, otherwise the full-measure ticks.
66
+ 2. `durations = fillRestDurations(measure.timeSignature, fill, target)`.
67
+ 3. Remove from that staff every staff modifier whose `startSelector` or `endSelector` is in this measure.
68
+ 4. Remove every text group attached to a note whose selector is in this staff and measure, from `score.textGroups` and from the staff's part information.
69
+ 5. `measure.fillWithRests(durations, beamBeats)` with `beamBeats` the score's triple default if the meter's top number is a multiple of 3, otherwise the duple default (as `clearAllBeamGroups` decides).
70
+
71
+ Idempotent: applying the same fill twice leaves the same measure.
72
+
73
+ ## SuiScoreViewOperations.fillMeasures (new)
74
+
75
+ ```text
76
+ fillMeasures(fill: MeasureFillType): Promise<void>
77
+ ```
78
+
79
+ One whole-score undo step, applies the operation to the displayed score and the stored score, redraws the changed measures.