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,94 @@
1
+ /**
2
+ * Headless checks for moving parts up and down: a 2-staff part moves as a unit.
3
+ *
4
+ * Run with: npm run test:move-part
5
+ */
6
+ import { SmoScore } from '../src/smo/data/score';
7
+ import { SmoSystemStaff } from '../src/smo/data/systemStaff';
8
+ import { SmoInstrument, staffModifierDynamicCtorInit } from '../src/smo/data/staffModifiers';
9
+ import { scoreModifierDynamicCtorInit } from '../src/smo/data/scoreModifiers';
10
+ import { noteModifierDynamicCtorInit } from '../src/smo/data/noteModifiers';
11
+ import { measureModifierDynamicCtorInit } from '../src/smo/data/measureModifiers';
12
+ import { SmoSelector, SmoSelection } from '../src/smo/xform/selections';
13
+ import { SmoOperation } from '../src/smo/xform/operations';
14
+
15
+ noteModifierDynamicCtorInit();
16
+ measureModifierDynamicCtorInit();
17
+ staffModifierDynamicCtorInit();
18
+ scoreModifierDynamicCtorInit();
19
+
20
+ let failures = 0;
21
+ const check = (name: string, condition: boolean, detail?: string) => {
22
+ if (condition) {
23
+ console.log(`PASS ${name}`);
24
+ } else {
25
+ failures += 1;
26
+ console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
27
+ }
28
+ };
29
+
30
+ /** A score with a staff for each name; a name ending in '1' is the first staff of a 2-staff part, '2' the second */
31
+ const buildScore = (names: string[]): SmoScore => {
32
+ const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
33
+ for (let ii = 1; ii < names.length; ++ii) {
34
+ const params = SmoSystemStaff.defaults;
35
+ params.staffId = ii;
36
+ params.measureInstrumentMap[0] = new SmoInstrument(SmoInstrument.defaults);
37
+ score.addStaff(params);
38
+ }
39
+ names.forEach((name, ix) => {
40
+ const info = score.staves[ix].partInfo;
41
+ info.partName = name;
42
+ if (name.endsWith('1')) {
43
+ info.stavesAfter = 1;
44
+ } else if (name.endsWith('2')) {
45
+ info.stavesBefore = 1;
46
+ }
47
+ });
48
+ return score;
49
+ };
50
+ const order = (score: SmoScore): string => score.staves.map((staff) => staff.partInfo.partName).join(',');
51
+ const move = (score: SmoScore, staff: number, dir: number) => {
52
+ const selector = SmoSelector.default;
53
+ selector.staff = staff;
54
+ SmoOperation.moveStaffUpDown(score, { selector } as SmoSelection, dir);
55
+ };
56
+
57
+ let score = buildScore(['A', 'B1', 'B2']);
58
+ move(score, 1, -1);
59
+ check('2-staff part up passes single staff', order(score) === 'B1,B2,A', order(score));
60
+ move(score, 0, 1);
61
+ check('2-staff part down passes single staff', order(score) === 'A,B1,B2', order(score));
62
+
63
+ score = buildScore(['A', 'B1', 'B2']);
64
+ move(score, 0, 1);
65
+ check('single staff down passes whole 2-staff part', order(score) === 'B1,B2,A', order(score));
66
+ move(score, 2, -1);
67
+ check('single staff up passes whole 2-staff part', order(score) === 'A,B1,B2', order(score));
68
+
69
+ score = buildScore(['A', 'B1', 'B2']);
70
+ move(score, 2, -1);
71
+ check('selecting second staff of a part moves the part', order(score) === 'B1,B2,A', order(score));
72
+
73
+ score = buildScore(['A', 'B1', 'B2', 'C1', 'C2']);
74
+ move(score, 3, -1);
75
+ check('2-staff part up passes 2-staff part', order(score) === 'A,C1,C2,B1,B2', order(score));
76
+
77
+ score = buildScore(['A', 'B', 'C1', 'C2']);
78
+ move(score, 2, 1);
79
+ check('last part down wraps to first', order(score) === 'C1,C2,A,B', order(score));
80
+ move(score, 0, -1);
81
+ check('first part up wraps to last', order(score) === 'A,B,C1,C2', order(score));
82
+
83
+ score = buildScore(['A1', 'A2', 'B', 'C']);
84
+ move(score, 0, -1);
85
+ check('first 2-staff part up wraps to last', order(score) === 'B,C,A1,A2', order(score));
86
+ check('part links are kept', score.staves[2].partInfo.stavesAfter === 1 && score.staves[3].partInfo.stavesBefore === 1);
87
+ check('staves are numbered', score.staves.every((staff, ix) => staff.staffId === ix));
88
+
89
+ if (failures > 0) {
90
+ console.log(`${failures} check(s) failed`);
91
+ process.exitCode = 1;
92
+ } else {
93
+ console.log('all checks passed');
94
+ }
@@ -0,0 +1,338 @@
1
+ /**
2
+ * Headless checks for how SmoOperation.computeMultipartRest groups empty measures into multimeasure
3
+ * rests around landmarks. Cases G1-G24 are listed in
4
+ * specs/032-split-multimeasure-rests/contracts/grouping-contract.md. Drawing is checked by hand.
5
+ *
6
+ * Run with: npm run test:multimeasure-rest
7
+ */
8
+ import { SmoScore } from '../src/smo/data/score';
9
+ import { SmoSystemStaff } from '../src/smo/data/systemStaff';
10
+ import { SmoInstrument } from '../src/smo/data/staffModifiers';
11
+ import { SmoOperation } from '../src/smo/xform/operations';
12
+ import { SmoBarline, SmoRehearsalMark, SmoRepeatSymbol, SmoTempo, SmoTimeSignature,
13
+ SmoVolta } from '../src/smo/data/measureModifiers';
14
+ import { noteModifierDynamicCtorInit } from '../src/smo/data/noteModifiers';
15
+ import { measureModifierDynamicCtorInit } from '../src/smo/data/measureModifiers';
16
+ import { staffModifierDynamicCtorInit } from '../src/smo/data/staffModifiers';
17
+ import { scoreModifierDynamicCtorInit } from '../src/smo/data/scoreModifiers';
18
+
19
+ // The smo layer registers its deserialization factories at app start; do the same here
20
+ // without pulling in any UI.
21
+ noteModifierDynamicCtorInit();
22
+ measureModifierDynamicCtorInit();
23
+ staffModifierDynamicCtorInit();
24
+ scoreModifierDynamicCtorInit();
25
+
26
+ let failures = 0;
27
+ const check = (name: string, condition: boolean, detail?: string) => {
28
+ if (condition) {
29
+ console.log(`PASS ${name}`);
30
+ } else {
31
+ failures += 1;
32
+ console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
33
+ }
34
+ };
35
+
36
+ const COUNT = 12;
37
+ /** A part of 12 empty 4/4 measures, with multimeasure rests turned on. Measures are 1-based in the helpers. */
38
+ const buildScore = (staffCount: number = 1): SmoScore => {
39
+ const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
40
+ while (score.staves[0].measures.length < COUNT) {
41
+ score.addMeasure(score.staves[0].measures.length - 1);
42
+ }
43
+ for (let s = 1; s < staffCount; ++s) {
44
+ const instrument = SmoInstrument.defaults;
45
+ instrument.startSelector.staff = instrument.endSelector.staff = s;
46
+ const params = SmoSystemStaff.defaults;
47
+ params.staffId = s;
48
+ params.measureInstrumentMap[0] = new SmoInstrument(instrument);
49
+ score.addStaff(params);
50
+ }
51
+ score.staves[0].partInfo.expandMultimeasureRests = false;
52
+ return score;
53
+ };
54
+ const measureAt = (score: SmoScore, m: number, staff: number = 0) => score.staves[staff].measures[m - 1];
55
+
56
+ // --- landmark helpers ---
57
+ const addRehearsal = (score: SmoScore, m: number, staff: number = 0) =>
58
+ measureAt(score, m, staff).addRehearsalMark(SmoRehearsalMark.defaults);
59
+ const setSymbol = (score: SmoScore, m: number, name: string) => {
60
+ const params = SmoRepeatSymbol.defaults;
61
+ params.symbol = SmoRepeatSymbol.symbols[name];
62
+ score.staves.forEach((staff) => staff.measures[m - 1].setRepeatSymbol(new SmoRepeatSymbol(params)));
63
+ };
64
+ const setBarline = (score: SmoScore, m: number, position: 'start' | 'end', barline: string) => {
65
+ const params = SmoBarline.defaults;
66
+ params.position = SmoBarline.positions[position];
67
+ params.barline = SmoBarline.barlines[barline];
68
+ score.staves.forEach((staff) => staff.measures[m - 1].setBarline(new SmoBarline(params)));
69
+ };
70
+ /** A change carries forward, so apply it from measure m to the end */
71
+ const setKey = (score: SmoScore, m: number, key: string) =>
72
+ score.staves.forEach((staff) => staff.measures.forEach((mm, ix) => { if (ix >= m - 1) { mm.keySignature = key; } }));
73
+ const setTime = (score: SmoScore, m: number, beats: number, duration: number) =>
74
+ score.staves.forEach((staff) => staff.measures.forEach((mm, ix) => {
75
+ if (ix >= m - 1) {
76
+ mm.timeSignature = new SmoTimeSignature({ ...SmoTimeSignature.defaults, times: [{ actualBeats: beats, beatDuration: duration }] });
77
+ }
78
+ }));
79
+ const setTempo = (score: SmoScore, m: number, display: boolean) =>
80
+ score.staves.forEach((staff) => staff.measures.forEach((mm, ix) => {
81
+ if (ix >= m - 1) {
82
+ mm.tempo = new SmoTempo({ ...SmoTempo.defaults, bpm: 90, display });
83
+ }
84
+ }));
85
+ const setInstrument = (score: SmoScore, m: number) => {
86
+ const instrument = SmoInstrument.defaults;
87
+ instrument.startSelector.measure = m - 1;
88
+ score.staves[0].measureInstrumentMap[m - 1] = new SmoInstrument(instrument);
89
+ };
90
+
91
+ // --- readers ---
92
+ /** Blocks of two or more measures, as 'start:length' (1-based) */
93
+ const blocks = (score: SmoScore, staff: number = 0): string[] => {
94
+ const rv: string[] = [];
95
+ score.staves[staff].measures.forEach((mm, ix) => {
96
+ if (mm.svg.multimeasureLength > 0) {
97
+ rv.push(`${ix + 1}:${mm.svg.multimeasureLength}`);
98
+ }
99
+ });
100
+ return rv;
101
+ };
102
+ const hidden = (score: SmoScore, staff: number = 0): number[] => {
103
+ const rv: number[] = [];
104
+ score.staves[staff].measures.forEach((mm, ix) => { if (mm.svg.hideMultimeasure) { rv.push(ix + 1); } });
105
+ return rv;
106
+ };
107
+ /** every measure is in a block or an ordinary bar, and the lengths add up */
108
+ const accounted = (score: SmoScore): boolean => {
109
+ let total = 0;
110
+ score.staves[0].measures.forEach((mm) => {
111
+ if (mm.svg.multimeasureLength > 0) {
112
+ total += mm.svg.multimeasureLength;
113
+ } else if (!mm.svg.hideMultimeasure) {
114
+ total += 1;
115
+ }
116
+ });
117
+ return total === COUNT;
118
+ };
119
+ const ordinary = (score: SmoScore, m: number) =>
120
+ measureAt(score, m).svg.multimeasureLength === 0 && !measureAt(score, m).svg.hideMultimeasure;
121
+ const run = (score: SmoScore) => SmoOperation.computeMultipartRest(score);
122
+ const same = (a: string[], b: string[]) => JSON.stringify(a) === JSON.stringify(b);
123
+ const range = (from: number, to: number): number[] => {
124
+ const rv: number[] = [];
125
+ for (let i = from; i <= to; ++i) { rv.push(i); }
126
+ return rv;
127
+ };
128
+
129
+ // --- G1: no landmarks ---
130
+ {
131
+ const score = buildScore();
132
+ run(score);
133
+ check('G1 one block of 12', same(blocks(score), ['1:12']), JSON.stringify(blocks(score)));
134
+ check('G1 measures 2 to 12 are hidden', JSON.stringify(hidden(score)) === JSON.stringify(range(2, 12)));
135
+ check('G1 every measure accounted for', accounted(score));
136
+ }
137
+ // --- G2: rehearsal mark in the middle ---
138
+ {
139
+ const score = buildScore();
140
+ addRehearsal(score, 6);
141
+ run(score);
142
+ check('G2 two blocks, 5 and 7', same(blocks(score), ['1:5', '6:7']), JSON.stringify(blocks(score)));
143
+ check('G2 no lone bar: measure 6 starts a block and is not hidden', !hidden(score).includes(6) && measureAt(score, 6).svg.multimeasureLength === 7);
144
+ check('G2 hidden are 2-5 and 7-12', JSON.stringify(hidden(score)) === JSON.stringify(range(2, 5).concat(range(7, 12))));
145
+ check('G2 every measure accounted for', accounted(score));
146
+ }
147
+ // --- G3: rehearsal mark on the first measure ---
148
+ {
149
+ const score = buildScore();
150
+ addRehearsal(score, 1);
151
+ run(score);
152
+ check('G3 one block of 12', same(blocks(score), ['1:12']), JSON.stringify(blocks(score)));
153
+ }
154
+ // --- G4: rehearsal mark on the last measure ---
155
+ {
156
+ const score = buildScore();
157
+ addRehearsal(score, 12);
158
+ run(score);
159
+ check('G4 block of 11, last measure an ordinary bar', same(blocks(score), ['1:11']) && ordinary(score, 12), JSON.stringify(blocks(score)));
160
+ check('G4 every measure accounted for', accounted(score));
161
+ }
162
+ // --- G5: two marks ---
163
+ {
164
+ const score = buildScore();
165
+ addRehearsal(score, 4);
166
+ addRehearsal(score, 8);
167
+ run(score);
168
+ check('G5 blocks 3, 4, 5', same(blocks(score), ['1:3', '4:4', '8:5']), JSON.stringify(blocks(score)));
169
+ check('G5 every measure accounted for', accounted(score));
170
+ }
171
+ // --- G6-G10: key, time, tempo ---
172
+ {
173
+ const score = buildScore();
174
+ setKey(score, 5, 'D');
175
+ run(score);
176
+ check('G6 key change at 5', same(blocks(score), ['1:4', '5:8']), JSON.stringify(blocks(score)));
177
+ }
178
+ {
179
+ const score = buildScore();
180
+ setTime(score, 5, 3, 4);
181
+ run(score);
182
+ check('G7 time signature change at 5', same(blocks(score), ['1:4', '5:8']), JSON.stringify(blocks(score)));
183
+ }
184
+ {
185
+ const score = buildScore();
186
+ setTempo(score, 5, true);
187
+ run(score);
188
+ check('G8 displayed tempo change at 5', same(blocks(score), ['1:4', '5:8']), JSON.stringify(blocks(score)));
189
+ }
190
+ {
191
+ const score = buildScore();
192
+ setTempo(score, 5, false);
193
+ run(score);
194
+ check('G9 tempo change that is not displayed does not split', same(blocks(score), ['1:12']), JSON.stringify(blocks(score)));
195
+ }
196
+ {
197
+ const score = buildScore();
198
+ setKey(score, 5, 'D');
199
+ addRehearsal(score, 5);
200
+ run(score);
201
+ check('G10 key change and rehearsal mark together split once', same(blocks(score), ['1:4', '5:8']), JSON.stringify(blocks(score)));
202
+ }
203
+ // --- G11-G12: Segno and Coda start the next block ---
204
+ {
205
+ const score = buildScore();
206
+ setSymbol(score, 5, 'Segno');
207
+ run(score);
208
+ check('G11 Segno at 5', same(blocks(score), ['1:4', '5:8']), JSON.stringify(blocks(score)));
209
+ check('G11 a start symbol is not recorded as an end symbol', measureAt(score, 1).svg.multimeasureEndSymbol === null);
210
+ }
211
+ {
212
+ const score = buildScore();
213
+ setSymbol(score, 9, 'Coda');
214
+ run(score);
215
+ check('G12 Coda at 9', same(blocks(score), ['1:8', '9:4']), JSON.stringify(blocks(score)));
216
+ }
217
+ // --- G13-G15: end symbols close the block and are recorded on it ---
218
+ {
219
+ const score = buildScore();
220
+ setSymbol(score, 4, 'DsAlCoda');
221
+ run(score);
222
+ check('G13 D.S. al Coda on 4 ends the first block', same(blocks(score), ['1:4', '5:8']), JSON.stringify(blocks(score)));
223
+ const sym = measureAt(score, 1).svg.multimeasureEndSymbol;
224
+ check('G13 the symbol is recorded on the first measure of the block', !!sym && sym.symbol === SmoRepeatSymbol.symbols.DsAlCoda);
225
+ check('G13 the next block has no end symbol', measureAt(score, 5).svg.multimeasureEndSymbol === null);
226
+ check('G13 every measure accounted for', accounted(score));
227
+ }
228
+ {
229
+ const score = buildScore();
230
+ setSymbol(score, 6, 'ToCoda');
231
+ run(score);
232
+ check('G14 To Coda on 6', same(blocks(score), ['1:6', '7:6']), JSON.stringify(blocks(score)));
233
+ const sym = measureAt(score, 1).svg.multimeasureEndSymbol;
234
+ check('G14 the symbol is recorded on the first measure', !!sym && sym.symbol === SmoRepeatSymbol.symbols.ToCoda);
235
+ }
236
+ {
237
+ const score = buildScore();
238
+ setSymbol(score, 1, 'DcAlFine');
239
+ run(score);
240
+ check('G15 D.C. al Fine on the first measure: it is an ordinary bar, the rest follows', ordinary(score, 1) && same(blocks(score), ['2:11']), JSON.stringify(blocks(score)));
241
+ check('G15 the lone bar keeps its own symbol (none recorded)', measureAt(score, 1).svg.multimeasureEndSymbol === null);
242
+ }
243
+ // --- G16-G18: barlines ---
244
+ {
245
+ const score = buildScore();
246
+ setBarline(score, 4, 'end', 'endRepeat');
247
+ run(score);
248
+ check('G16 end repeat after measure 4', same(blocks(score), ['1:4', '5:8']), JSON.stringify(blocks(score)));
249
+ check('G16 the first block ends with the repeat barline', measureAt(score, 1).svg.multimeasureEndBarline === SmoBarline.barlines.endRepeat);
250
+ check('G16 the second block ends with a plain barline', measureAt(score, 5).svg.multimeasureEndBarline === SmoBarline.barlines.singleBar);
251
+ }
252
+ {
253
+ const score = buildScore();
254
+ setBarline(score, 5, 'start', 'startRepeat');
255
+ run(score);
256
+ check('G17 start repeat on measure 5', same(blocks(score), ['1:4', '5:8']), JSON.stringify(blocks(score)));
257
+ }
258
+ {
259
+ const a = buildScore();
260
+ setBarline(a, 4, 'end', 'doubleBar');
261
+ run(a);
262
+ const b = buildScore();
263
+ setBarline(b, 5, 'start', 'doubleBar');
264
+ run(b);
265
+ check('G18 double bar as the end of 4', same(blocks(a), ['1:4', '5:8']), JSON.stringify(blocks(a)));
266
+ check('G18 double bar as the start of 5', same(blocks(b), ['1:4', '5:8']), JSON.stringify(blocks(b)));
267
+ }
268
+ // --- G19: instrument change ---
269
+ {
270
+ const score = buildScore();
271
+ setInstrument(score, 7);
272
+ run(score);
273
+ check('G19 instrument change at 7', same(blocks(score), ['1:6', '7:6']), JSON.stringify(blocks(score)));
274
+ }
275
+ // --- G20: a measure with both kinds of landmark is a block of its own ---
276
+ {
277
+ const score = buildScore();
278
+ addRehearsal(score, 5);
279
+ setSymbol(score, 5, 'DsAlFine');
280
+ run(score);
281
+ check('G20 rehearsal mark and D.S. on 5: blocks 1-4 and 6-12', same(blocks(score), ['1:4', '6:7']), JSON.stringify(blocks(score)));
282
+ check('G20 measure 5 is an ordinary bar', ordinary(score, 5));
283
+ check('G20 every measure accounted for', accounted(score));
284
+ }
285
+ // --- G21: expanded rests ---
286
+ {
287
+ const score = buildScore();
288
+ score.staves[0].partInfo.expandMultimeasureRests = true;
289
+ addRehearsal(score, 6);
290
+ setSymbol(score, 4, 'DsAlCoda');
291
+ run(score);
292
+ check('G21 no blocks and nothing hidden when rests are expanded', blocks(score).length === 0 && hidden(score).length === 0);
293
+ }
294
+ // --- G22: a volta ending is never grouped ---
295
+ {
296
+ const score = buildScore();
297
+ const volta = new SmoVolta({ ...SmoVolta.defaults,
298
+ startSelector: { staff: 0, measure: 4, voice: 0, tick: 0, pitches: [] },
299
+ endSelector: { staff: 0, measure: 5, voice: 0, tick: 0, pitches: [] } } as any);
300
+ measureAt(score, 5).addNthEnding(volta);
301
+ run(score);
302
+ check('G22 measures 5 and 6 under the ending are ordinary bars', ordinary(score, 5) && ordinary(score, 6), JSON.stringify(blocks(score)));
303
+ check('G22 the rests before and after still group', same(blocks(score), ['1:4', '7:6']), JSON.stringify(blocks(score)));
304
+ check('G22 every measure accounted for', accounted(score));
305
+ }
306
+ // --- G23: two staves, a mark on only one ---
307
+ {
308
+ const score = buildScore(2);
309
+ addRehearsal(score, 6, 1);
310
+ run(score);
311
+ // measure 1 of a part with more than one staff is never the start of a block (unchanged behavior)
312
+ check('G23 staff 0 blocks', same(blocks(score, 0), ['2:4', '6:7']), JSON.stringify(blocks(score, 0)));
313
+ check('G23 staff 1 has the same blocks', same(blocks(score, 1), blocks(score, 0)), JSON.stringify(blocks(score, 1)));
314
+ check('G23 and the same hidden measures', JSON.stringify(hidden(score, 1)) === JSON.stringify(hidden(score, 0)));
315
+ }
316
+ // --- G24: regrouping leaves nothing stale ---
317
+ {
318
+ const score = buildScore();
319
+ addRehearsal(score, 6);
320
+ setSymbol(score, 4, 'DsAlCoda');
321
+ run(score);
322
+ measureAt(score, 6).removeRehearsalMark();
323
+ setSymbol(score, 4, 'None');
324
+ run(score);
325
+ check('G24 back to one block of 12', same(blocks(score), ['1:12']), JSON.stringify(blocks(score)));
326
+ check('G24 measures 2 to 12 hidden, none else', JSON.stringify(hidden(score)) === JSON.stringify(range(2, 12)));
327
+ const lengths = score.staves[0].measures.map((mm) => mm.svg.multimeasureLength).join();
328
+ check('G24 no stale length on other measures', lengths === '12,0,0,0,0,0,0,0,0,0,0,0', lengths);
329
+ check('G24 no stale end symbol', score.staves[0].measures.every((mm) => mm.svg.multimeasureEndSymbol === null));
330
+ check('G24 every measure accounted for', accounted(score));
331
+ }
332
+
333
+ if (failures > 0) {
334
+ console.log(`${failures} check(s) failed`);
335
+ process.exitCode = 1;
336
+ } else {
337
+ console.log('all checks passed');
338
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Headless checks for pasting a partial measure over the start of a measure whose notes are longer.
3
+ * When the paste ends in the middle of an existing note, the rest of that note is filled in and the
4
+ * notes after it must be kept (they used to be dropped, leaving the measure short).
5
+ *
6
+ * Run with: npm run test:paste-into-measure
7
+ */
8
+ import { SmoScore } from '../src/smo/data/score';
9
+ import { SmoNote } from '../src/smo/data/note';
10
+ import { SmoTimeSignature } from '../src/smo/data/measureModifiers';
11
+ import { SmoSelection } from '../src/smo/xform/selections';
12
+ import { SmoOperation } from '../src/smo/xform/operations';
13
+ import { PasteBuffer } from '../src/smo/xform/copypaste';
14
+ import { noteModifierDynamicCtorInit } from '../src/smo/data/noteModifiers';
15
+ import { measureModifierDynamicCtorInit } from '../src/smo/data/measureModifiers';
16
+ import { staffModifierDynamicCtorInit } from '../src/smo/data/staffModifiers';
17
+ import { scoreModifierDynamicCtorInit } from '../src/smo/data/scoreModifiers';
18
+
19
+ noteModifierDynamicCtorInit();
20
+ measureModifierDynamicCtorInit();
21
+ staffModifierDynamicCtorInit();
22
+ scoreModifierDynamicCtorInit();
23
+
24
+ let failures = 0;
25
+ const check = (name: string, condition: boolean, detail?: string) => {
26
+ if (condition) {
27
+ console.log(`PASS ${name}`);
28
+ } else {
29
+ failures += 1;
30
+ console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
31
+ }
32
+ };
33
+
34
+ const dur = (n: number) => ({ numerator: n, denominator: 1, remainder: 0 });
35
+
36
+ /**
37
+ * Copy the first notes (durations `copyDurs`, pitch c) of a 4/4 measure and paste them at the start of
38
+ * a following measure in `beats/beatDuration` time whose notes (pitch b) have durations `existing`.
39
+ * Returns the pasted-into measure as 'pitch:ticks' strings.
40
+ */
41
+ const paste = (beats: number, beatDuration: number, existing: number[], copyDurs: number[]): string[] => {
42
+ const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
43
+ score.addMeasure(0);
44
+ const src = score.staves[0].measures[0];
45
+ const dst = score.staves[0].measures[1];
46
+ const ts = new SmoTimeSignature({ ...SmoTimeSignature.defaults, times: [{ actualBeats: beats, beatDuration }] } as any);
47
+ SmoOperation.setTimeSignature(score, [SmoSelection.measureSelection(score, 0, 1)!], ts);
48
+ const proto = dst.voices[0].notes[0];
49
+ const makeNotes = (list: number[], pitch: string) => list.map((d) => {
50
+ const note = SmoNote.cloneWithDuration(proto, dur(d));
51
+ note.noteType = 'n';
52
+ note.pitches = [{ letter: pitch as any, accidental: 'n', octave: 4 }];
53
+ return note;
54
+ });
55
+ dst.voices[0].notes = makeNotes(existing, 'b');
56
+ const rest = 16384 - copyDurs.reduce((a, b) => a + b, 0);
57
+ src.voices[0].notes = makeNotes(copyDurs, 'c').concat(rest > 0 ? makeNotes([rest], 'g') : []);
58
+ const buffer = new PasteBuffer();
59
+ const selections: SmoSelection[] = [];
60
+ for (let i = 0; i < copyDurs.length; ++i) {
61
+ selections.push(SmoSelection.noteSelection(score, 0, 0, 0, i)!);
62
+ }
63
+ buffer.setSelections(score, selections);
64
+ buffer.pasteSelections({ staff: 0, measure: 1, voice: 0, tick: 0, pitches: [] });
65
+ return score.staves[0].measures[1].voices[0].notes.map((n) => `${n.pitches[0].letter}:${n.tickCount}`);
66
+ };
67
+ const total = (notes: string[]) => notes.reduce((a, n) => a + parseInt(n.split(':')[1], 10), 0);
68
+ const same = (a: string[], b: string[]) => JSON.stringify(a) === JSON.stringify(b);
69
+
70
+ {
71
+ const out = paste(6, 8, [4096, 4096, 4096], [2048, 2048, 2048]);
72
+ check('6/8: 3 eighths over 3 quarters keeps the third quarter',
73
+ same(out, ['c:2048', 'c:2048', 'c:2048', 'b:2048', 'b:4096']), out.join(' '));
74
+ check('6/8: measure is full', total(out) === 12288, `${total(out)}`);
75
+ }
76
+ {
77
+ const out = paste(4, 4, [4096, 4096, 4096, 4096], [2048, 2048, 2048]);
78
+ check('4/4: 3 eighths over 4 quarters keeps the last 2 quarters',
79
+ same(out, ['c:2048', 'c:2048', 'c:2048', 'b:2048', 'b:4096', 'b:4096']), out.join(' '));
80
+ }
81
+ {
82
+ const out = paste(4, 4, [4096, 4096, 4096, 4096], [2048]);
83
+ check('4/4: 1 eighth over 4 quarters keeps the other 3 quarters',
84
+ same(out, ['c:2048', 'b:2048', 'b:4096', 'b:4096', 'b:4096']), out.join(' '));
85
+ }
86
+ {
87
+ const out = paste(4, 4, [4096, 4096, 4096, 4096], [2048, 2048]);
88
+ check('4/4: 2 eighths over 4 quarters (ends on a note boundary) keeps the other 3 quarters',
89
+ same(out, ['c:2048', 'c:2048', 'b:4096', 'b:4096', 'b:4096']), out.join(' '));
90
+ }
91
+ {
92
+ const out = paste(4, 4, [8192, 4096, 4096], [4096, 2048]);
93
+ check('4/4: 1.5 beats over a half note keeps the rest of the measure',
94
+ same(out, ['c:4096', 'c:2048', 'b:2048', 'b:4096', 'b:4096']) || total(out) === 16384, out.join(' '));
95
+ check('4/4: the notes after the split note are kept', out.slice(-2).join(' ') === 'b:4096 b:4096', out.join(' '));
96
+ }
97
+
98
+ if (failures > 0) {
99
+ console.log(`${failures} check(s) failed`);
100
+ process.exitCode = 1;
101
+ } else {
102
+ console.log('all checks passed');
103
+ }