smoosic 2.0.2 → 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 (352) hide show
  1. package/build/smoosic.js +546 -125
  2. package/changes.md +85 -0
  3. package/package.json +23 -2
  4. package/release/smoosic.js +549 -128
  5. package/release/styles/menus.css +26 -0
  6. package/specs/022-text-reposition-on-resize/spec.md +1 -0
  7. package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
  8. package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
  9. package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
  10. package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
  11. package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
  12. package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
  13. package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
  14. package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
  15. package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
  16. package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
  17. package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
  18. package/specs/028-unsaved-changes-indicator/plan.md +96 -0
  19. package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
  20. package/specs/028-unsaved-changes-indicator/research.md +68 -0
  21. package/specs/028-unsaved-changes-indicator/spec.md +135 -0
  22. package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
  23. package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
  24. package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
  25. package/specs/029-remove-promise-helpers/data-model.md +45 -0
  26. package/specs/029-remove-promise-helpers/plan.md +86 -0
  27. package/specs/029-remove-promise-helpers/quickstart.md +53 -0
  28. package/specs/029-remove-promise-helpers/research.md +71 -0
  29. package/specs/029-remove-promise-helpers/spec.md +107 -0
  30. package/specs/029-remove-promise-helpers/tasks.md +164 -0
  31. package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
  32. package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
  33. package/specs/030-copy-paste-voices/data-model.md +63 -0
  34. package/specs/030-copy-paste-voices/plan.md +80 -0
  35. package/specs/030-copy-paste-voices/quickstart.md +50 -0
  36. package/specs/030-copy-paste-voices/research.md +80 -0
  37. package/specs/030-copy-paste-voices/spec.md +124 -0
  38. package/specs/030-copy-paste-voices/tasks.md +183 -0
  39. package/specs/031-select-voice/checklists/requirements.md +39 -0
  40. package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
  41. package/specs/031-select-voice/data-model.md +47 -0
  42. package/specs/031-select-voice/plan.md +79 -0
  43. package/specs/031-select-voice/quickstart.md +43 -0
  44. package/specs/031-select-voice/research.md +55 -0
  45. package/specs/031-select-voice/spec.md +113 -0
  46. package/specs/031-select-voice/tasks.md +171 -0
  47. package/specs/032-split-multimeasure-rests/checklists/requirements.md +40 -0
  48. package/specs/032-split-multimeasure-rests/contracts/grouping-contract.md +53 -0
  49. package/specs/032-split-multimeasure-rests/data-model.md +70 -0
  50. package/specs/032-split-multimeasure-rests/plan.md +81 -0
  51. package/specs/032-split-multimeasure-rests/quickstart.md +46 -0
  52. package/specs/032-split-multimeasure-rests/research.md +63 -0
  53. package/specs/032-split-multimeasure-rests/spec.md +127 -0
  54. package/specs/032-split-multimeasure-rests/tasks.md +174 -0
  55. package/specs/033-key-distance-transposition/checklists/requirements.md +35 -0
  56. package/specs/033-key-distance-transposition/contracts/spelling-api.md +36 -0
  57. package/specs/033-key-distance-transposition/data-model.md +49 -0
  58. package/specs/033-key-distance-transposition/plan.md +87 -0
  59. package/specs/033-key-distance-transposition/quickstart.md +40 -0
  60. package/specs/033-key-distance-transposition/research.md +82 -0
  61. package/specs/033-key-distance-transposition/spec.md +132 -0
  62. package/specs/033-key-distance-transposition/tasks.md +139 -0
  63. package/specs/034-smz-compressed-scores/checklists/requirements.md +35 -0
  64. package/specs/034-smz-compressed-scores/contracts/archive-api.md +30 -0
  65. package/specs/034-smz-compressed-scores/data-model.md +48 -0
  66. package/specs/034-smz-compressed-scores/plan.md +89 -0
  67. package/specs/034-smz-compressed-scores/quickstart.md +44 -0
  68. package/specs/034-smz-compressed-scores/research.md +86 -0
  69. package/specs/034-smz-compressed-scores/spec.md +137 -0
  70. package/specs/034-smz-compressed-scores/tasks.md +148 -0
  71. package/specs/035-paste-special/checklists/requirements.md +35 -0
  72. package/specs/035-paste-special/contracts/paste-special-api.md +50 -0
  73. package/specs/035-paste-special/data-model.md +47 -0
  74. package/specs/035-paste-special/plan.md +83 -0
  75. package/specs/035-paste-special/quickstart.md +51 -0
  76. package/specs/035-paste-special/research.md +97 -0
  77. package/specs/035-paste-special/spec.md +170 -0
  78. package/specs/035-paste-special/tasks.md +149 -0
  79. package/specs/036-autosave-recovery/checklists/requirements.md +36 -0
  80. package/specs/036-autosave-recovery/contracts/autosave-api.md +111 -0
  81. package/specs/036-autosave-recovery/data-model.md +70 -0
  82. package/specs/036-autosave-recovery/plan.md +87 -0
  83. package/specs/036-autosave-recovery/quickstart.md +65 -0
  84. package/specs/036-autosave-recovery/research.md +105 -0
  85. package/specs/036-autosave-recovery/spec.md +143 -0
  86. package/specs/036-autosave-recovery/tasks.md +165 -0
  87. package/specs/037-fix-new-part-dialog/checklists/requirements.md +38 -0
  88. package/specs/037-fix-new-part-dialog/contracts/create-part-api.md +84 -0
  89. package/specs/037-fix-new-part-dialog/data-model.md +68 -0
  90. package/specs/037-fix-new-part-dialog/plan.md +83 -0
  91. package/specs/037-fix-new-part-dialog/quickstart.md +58 -0
  92. package/specs/037-fix-new-part-dialog/research.md +86 -0
  93. package/specs/037-fix-new-part-dialog/spec.md +144 -0
  94. package/specs/037-fix-new-part-dialog/tasks.md +174 -0
  95. package/specs/038-per-measure-beam-groups/checklists/requirements.md +36 -0
  96. package/specs/038-per-measure-beam-groups/contracts/beam-groups-api.md +74 -0
  97. package/specs/038-per-measure-beam-groups/data-model.md +75 -0
  98. package/specs/038-per-measure-beam-groups/plan.md +84 -0
  99. package/specs/038-per-measure-beam-groups/quickstart.md +53 -0
  100. package/specs/038-per-measure-beam-groups/research.md +72 -0
  101. package/specs/038-per-measure-beam-groups/spec.md +146 -0
  102. package/specs/038-per-measure-beam-groups/tasks.md +132 -0
  103. package/specs/039-measure-fill-submenu/checklists/requirements.md +35 -0
  104. package/specs/039-measure-fill-submenu/contracts/measure-fill-api.md +56 -0
  105. package/specs/039-measure-fill-submenu/data-model.md +79 -0
  106. package/specs/039-measure-fill-submenu/plan.md +81 -0
  107. package/specs/039-measure-fill-submenu/quickstart.md +62 -0
  108. package/specs/039-measure-fill-submenu/research.md +68 -0
  109. package/specs/039-measure-fill-submenu/spec.md +153 -0
  110. package/specs/039-measure-fill-submenu/tasks.md +121 -0
  111. package/specs/040-dynamics-dialog-cleanup/checklists/requirements.md +36 -0
  112. package/specs/040-dynamics-dialog-cleanup/contracts/dynamics-dialog.md +52 -0
  113. package/specs/040-dynamics-dialog-cleanup/data-model.md +48 -0
  114. package/specs/040-dynamics-dialog-cleanup/plan.md +89 -0
  115. package/specs/040-dynamics-dialog-cleanup/quickstart.md +69 -0
  116. package/specs/040-dynamics-dialog-cleanup/research.md +80 -0
  117. package/specs/040-dynamics-dialog-cleanup/spec.md +120 -0
  118. package/specs/040-dynamics-dialog-cleanup/tasks.md +114 -0
  119. package/specs/041-delete-special/checklists/requirements.md +35 -0
  120. package/specs/041-delete-special/contracts/delete-special-api.md +41 -0
  121. package/specs/041-delete-special/data-model.md +40 -0
  122. package/specs/041-delete-special/plan.md +93 -0
  123. package/specs/041-delete-special/quickstart.md +41 -0
  124. package/specs/041-delete-special/research.md +75 -0
  125. package/specs/041-delete-special/spec.md +136 -0
  126. package/specs/041-delete-special/tasks.md +106 -0
  127. package/src/application/application.ts +475 -459
  128. package/src/application/exports.ts +401 -395
  129. package/src/application/generateVexTests.ts +2 -2
  130. package/src/common/promiseHelpers.ts +2 -2
  131. package/src/render/audio/samples.ts +117 -118
  132. package/src/render/sui/NoteEntryCaret.ts +117 -16
  133. package/src/render/sui/autosave.ts +265 -0
  134. package/src/render/sui/formatter.ts +12 -2
  135. package/src/render/sui/pageDivisions.ts +58 -0
  136. package/src/render/sui/renderState.ts +469 -464
  137. package/src/render/sui/scoreChangeState.ts +67 -0
  138. package/src/render/sui/scoreView.ts +77 -2
  139. package/src/render/sui/scoreViewOperations.ts +363 -37
  140. package/src/render/sui/staffLineGeometry.ts +82 -0
  141. package/src/render/sui/svgPageMap.ts +16 -17
  142. package/src/render/sui/textEdit.ts +310 -311
  143. package/src/render/sui/tracker.ts +40 -0
  144. package/src/render/vex/vxMeasure.ts +22 -8
  145. package/src/render/vex/vxNote.ts +5 -5
  146. package/src/smo/data/measure.ts +58 -1
  147. package/src/smo/data/measureModifiers.ts +81 -1
  148. package/src/smo/data/music.ts +169 -359
  149. package/src/smo/data/note.ts +1 -1
  150. package/src/smo/data/noteModifiers.ts +12 -0
  151. package/src/smo/data/score.ts +167 -2
  152. package/src/smo/data/scoreModifiers.ts +46 -1
  153. package/src/smo/data/systemStaff.ts +43 -0
  154. package/src/smo/xform/beamers.ts +80 -6
  155. package/src/smo/xform/copypaste.ts +511 -51
  156. package/src/smo/xform/measureFill.ts +89 -0
  157. package/src/smo/xform/operations.ts +403 -61
  158. package/src/smo/xform/selections.ts +75 -0
  159. package/src/smo/xform/undo.ts +9 -0
  160. package/src/styles/menus.css +26 -0
  161. package/src/ui/buttons/ribbon.ts +3 -1
  162. package/src/ui/components/buttons/sidebar.vue +15 -6
  163. package/src/ui/components/dialogs/beamGroups.vue +106 -0
  164. package/src/ui/components/dialogs/deleteSpecial.vue +38 -0
  165. package/src/ui/components/dialogs/dynamics.vue +16 -3
  166. package/src/ui/components/dialogs/fileUpload.vue +2 -2
  167. package/src/ui/components/dialogs/hairpin.vue +3 -3
  168. package/src/ui/components/dialogs/library.vue +3 -1
  169. package/src/ui/components/dialogs/newPart.vue +148 -184
  170. package/src/ui/components/dialogs/pasteSpecial.vue +49 -0
  171. package/src/ui/components/dialogs/recovery.vue +66 -0
  172. package/src/ui/components/dialogs/save.vue +11 -4
  173. package/src/ui/components/dialogs/scorePreferences.vue +23 -1
  174. package/src/ui/components/dialogs/slur.vue +6 -6
  175. package/src/ui/components/dialogs/tempo.vue +11 -3
  176. package/src/ui/components/dialogs/timeSignature.vue +5 -0
  177. package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
  178. package/src/ui/components/dialogs/volta.vue +3 -3
  179. package/src/ui/dialogs/adapter.ts +181 -183
  180. package/src/ui/dialogs/addMeasure.ts +97 -97
  181. package/src/ui/dialogs/annotationVue.ts +56 -56
  182. package/src/ui/dialogs/audioSettings.ts +121 -123
  183. package/src/ui/dialogs/beamGroupsVue.ts +69 -0
  184. package/src/ui/dialogs/chordChangeVue.ts +46 -46
  185. package/src/ui/dialogs/clefChange.ts +53 -53
  186. package/src/ui/dialogs/createPartHelpers.ts +68 -0
  187. package/src/ui/dialogs/customTuplets.ts +95 -96
  188. package/src/ui/dialogs/customTupletsVue.ts +47 -47
  189. package/src/ui/dialogs/deleteSpecial.ts +57 -0
  190. package/src/ui/dialogs/dialog.ts +627 -620
  191. package/src/ui/dialogs/durations.ts +34 -34
  192. package/src/ui/dialogs/dynamicsVue.ts +87 -60
  193. package/src/ui/dialogs/factory.ts +196 -198
  194. package/src/ui/dialogs/fileDialogs.ts +286 -179
  195. package/src/ui/dialogs/fonts.ts +93 -93
  196. package/src/ui/dialogs/globalLayout.ts +40 -40
  197. package/src/ui/dialogs/gracenote.ts +31 -31
  198. package/src/ui/dialogs/hairpin.ts +108 -110
  199. package/src/ui/dialogs/hairpinVue.ts +51 -51
  200. package/src/ui/dialogs/instrument.ts +119 -112
  201. package/src/ui/dialogs/keySignature.ts +175 -176
  202. package/src/ui/dialogs/keySignatureVue.ts +47 -47
  203. package/src/ui/dialogs/library.ts +207 -207
  204. package/src/ui/dialogs/libraryVue.ts +62 -48
  205. package/src/ui/dialogs/lyricVue.ts +46 -46
  206. package/src/ui/dialogs/measureFormat.ts +78 -78
  207. package/src/ui/dialogs/microtones.ts +147 -147
  208. package/src/ui/dialogs/noteHead.ts +319 -319
  209. package/src/ui/dialogs/pageLayout.ts +61 -61
  210. package/src/ui/dialogs/partInfo.ts +60 -60
  211. package/src/ui/dialogs/pasteSpecial.ts +59 -0
  212. package/src/ui/dialogs/pedalMarking.ts +117 -117
  213. package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
  214. package/src/ui/dialogs/pitch.ts +352 -352
  215. package/src/ui/dialogs/preferences.ts +1 -0
  216. package/src/ui/dialogs/recovery.ts +49 -0
  217. package/src/ui/dialogs/rehearsalMark.ts +64 -64
  218. package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
  219. package/src/ui/dialogs/scoreId.ts +35 -36
  220. package/src/ui/dialogs/scoreView.ts +42 -42
  221. package/src/ui/dialogs/slur.ts +308 -310
  222. package/src/ui/dialogs/slurVue.ts +91 -91
  223. package/src/ui/dialogs/staffGroup.ts +112 -112
  224. package/src/ui/dialogs/tabNote.ts +84 -84
  225. package/src/ui/dialogs/tabStave.ts +182 -182
  226. package/src/ui/dialogs/tempo.ts +261 -263
  227. package/src/ui/dialogs/tempoVue.ts +73 -73
  228. package/src/ui/dialogs/textBlockVue.ts +127 -127
  229. package/src/ui/dialogs/textBracket.ts +114 -116
  230. package/src/ui/dialogs/textBracketVue.ts +56 -56
  231. package/src/ui/dialogs/tie.ts +140 -142
  232. package/src/ui/dialogs/timeSignature.ts +65 -66
  233. package/src/ui/dialogs/transposeScore.ts +39 -39
  234. package/src/ui/dialogs/unsavedChanges.ts +43 -0
  235. package/src/ui/dialogs/volta.ts +120 -122
  236. package/src/ui/dialogs/voltaVue.ts +51 -51
  237. package/src/ui/fileio/fileInput.ts +12 -3
  238. package/src/ui/fileio/library.ts +110 -111
  239. package/src/ui/fileio/scoreArchive.ts +151 -0
  240. package/src/ui/fileio/xhrLoader.ts +26 -0
  241. package/src/ui/i18n/language.ts +1 -1
  242. package/src/ui/menus/beams.ts +181 -112
  243. package/src/ui/menus/edit.ts +143 -6
  244. package/src/ui/menus/file.ts +40 -4
  245. package/src/ui/menus/measure.ts +40 -1
  246. package/tests/autosave.ts +332 -0
  247. package/tests/beamDotted.ts +56 -0
  248. package/tests/beamGroups.ts +338 -0
  249. package/tests/createPart.ts +292 -0
  250. package/tests/deleteSpecial.ts +350 -0
  251. package/tests/dynamicsFontSize.ts +132 -0
  252. package/tests/keyDistanceTransposition.ts +351 -0
  253. package/tests/measureFill.ts +295 -0
  254. package/tests/movePart.ts +94 -0
  255. package/tests/multimeasureRest.ts +338 -0
  256. package/tests/pageDivisions.ts +156 -0
  257. package/tests/pasteIntoMeasure.ts +103 -0
  258. package/tests/pasteSpecial.ts +541 -0
  259. package/tests/promiseHelpersUsage.ts +142 -0
  260. package/tests/quickBeam.ts +126 -0
  261. package/tests/scoreArchive.ts +218 -0
  262. package/tests/scoreChangeState.ts +104 -0
  263. package/tests/selectVoice.ts +189 -0
  264. package/tests/staffLineGeometry.ts +179 -0
  265. package/tests/timeSignatureDisplay.ts +58 -0
  266. package/tests/voiceCopyPaste.ts +417 -0
  267. package/tools/smoosic-schema.json +37 -0
  268. package/typedoc.ts +1 -1
  269. package/types/src/application/exports.d.ts +453 -447
  270. package/types/src/common/promiseHelpers.d.ts +30 -30
  271. package/types/src/common/vex.d.ts +224 -224
  272. package/types/src/render/sui/NoteEntryCaret.d.ts +107 -107
  273. package/types/src/render/sui/autosave.d.ts +99 -0
  274. package/types/src/render/sui/scoreView.d.ts +23 -0
  275. package/types/src/render/sui/scoreViewOperations.d.ts +759 -639
  276. package/types/src/render/sui/svgHelpers.d.ts +88 -88
  277. package/types/src/render/sui/svgPageMap.d.ts +344 -344
  278. package/types/src/render/sui/textEdit.d.ts +96 -96
  279. package/types/src/render/sui/textRender.d.ts +199 -199
  280. package/types/src/render/vex/smoAdapter.d.ts +47 -47
  281. package/types/src/render/vex/vxMeasure.d.ts +97 -97
  282. package/types/src/render/vex/vxNote.d.ts +56 -56
  283. package/types/src/render/vex/vxSystem.d.ts +71 -71
  284. package/types/src/smo/data/measure.d.ts +30 -0
  285. package/types/src/smo/data/measureModifiers.d.ts +568 -513
  286. package/types/src/smo/data/music.d.ts +74 -32
  287. package/types/src/smo/data/note.d.ts +498 -498
  288. package/types/src/smo/data/noteModifiers.d.ts +615 -606
  289. package/types/src/smo/data/score.d.ts +476 -421
  290. package/types/src/smo/data/scoreModifiers.d.ts +30 -0
  291. package/types/src/smo/data/scoreText.d.ts +334 -334
  292. package/types/src/smo/data/systemStaff.d.ts +14 -0
  293. package/types/src/smo/xform/beamers.d.ts +23 -1
  294. package/types/src/smo/xform/copypaste.d.ts +138 -2
  295. package/types/src/smo/xform/measureFill.d.ts +21 -0
  296. package/types/src/smo/xform/operations.d.ts +245 -129
  297. package/types/src/smo/xform/selections.d.ts +154 -154
  298. package/types/src/smo/xform/undo.d.ts +142 -142
  299. package/types/src/ui/buttons/button.d.ts +100 -100
  300. package/types/src/ui/buttons/ribbon.d.ts +70 -70
  301. package/types/src/ui/common.d.ts +76 -76
  302. package/types/src/ui/components/dialogs/chordText.d.ts +28 -28
  303. package/types/src/ui/components/dialogs/textBlockAtomNode.d.ts +20 -20
  304. package/types/src/ui/components/dialogs/textGroupHtml.d.ts +29 -29
  305. package/types/src/ui/composable/draggable.d.ts +15 -15
  306. package/types/src/ui/dialogs/adapter.d.ts +120 -120
  307. package/types/src/ui/dialogs/annotationVue.d.ts +9 -9
  308. package/types/src/ui/dialogs/audioSettings.d.ts +32 -32
  309. package/types/src/ui/dialogs/beamGroupsVue.d.ts +20 -0
  310. package/types/src/ui/dialogs/chordChangeVue.d.ts +8 -8
  311. package/types/src/ui/dialogs/createPartHelpers.d.ts +29 -0
  312. package/types/src/ui/dialogs/customTupletsVue.d.ts +9 -9
  313. package/types/src/ui/dialogs/deleteSpecial.d.ts +8 -0
  314. package/types/src/ui/dialogs/dialog.d.ts +203 -203
  315. package/types/src/ui/dialogs/dynamicsVue.d.ts +10 -10
  316. package/types/src/ui/dialogs/factory.d.ts +15 -15
  317. package/types/src/ui/dialogs/fileDialogs.d.ts +4 -4
  318. package/types/src/ui/dialogs/hairpin.d.ts +35 -35
  319. package/types/src/ui/dialogs/hairpinVue.d.ts +7 -7
  320. package/types/src/ui/dialogs/instrument.d.ts +3 -3
  321. package/types/src/ui/dialogs/keySignatureVue.d.ts +7 -7
  322. package/types/src/ui/dialogs/libraryVue.d.ts +15 -15
  323. package/types/src/ui/dialogs/lyricVue.d.ts +8 -8
  324. package/types/src/ui/dialogs/pasteSpecial.d.ts +8 -0
  325. package/types/src/ui/dialogs/pedalMarkingVue.d.ts +7 -7
  326. package/types/src/ui/dialogs/recovery.d.ts +8 -0
  327. package/types/src/ui/dialogs/rehearsalMark.d.ts +25 -25
  328. package/types/src/ui/dialogs/rehearsalMarkVue.d.ts +7 -7
  329. package/types/src/ui/dialogs/slur.d.ts +57 -57
  330. package/types/src/ui/dialogs/slurVue.d.ts +7 -7
  331. package/types/src/ui/dialogs/tempo.d.ts +50 -50
  332. package/types/src/ui/dialogs/tempoVue.d.ts +10 -10
  333. package/types/src/ui/dialogs/textBlockVue.d.ts +8 -8
  334. package/types/src/ui/dialogs/textBracket.d.ts +35 -35
  335. package/types/src/ui/dialogs/textBracketVue.d.ts +7 -7
  336. package/types/src/ui/dialogs/tie.d.ts +41 -41
  337. package/types/src/ui/dialogs/volta.d.ts +40 -40
  338. package/types/src/ui/dialogs/voltaVue.d.ts +7 -7
  339. package/types/src/ui/fileio/fileInput.d.ts +7 -1
  340. package/types/src/ui/fileio/library.d.ts +40 -40
  341. package/types/src/ui/fileio/scoreArchive.d.ts +55 -0
  342. package/types/src/ui/fileio/xhrLoader.d.ts +7 -0
  343. package/types/src/ui/menus/file.d.ts +8 -8
  344. package/types/src/ui/menus/language.d.ts +7 -7
  345. package/types/src/ui/menus/manager.d.ts +58 -58
  346. package/types/src/ui/menus/menu.d.ts +159 -159
  347. package/types/src/ui/menus/partSelection.d.ts +14 -14
  348. package/types/src/ui/menus/score.d.ts +8 -8
  349. package/types/src/ui/menus/staffModifier.d.ts +17 -17
  350. package/types/typedoc.d.ts +147 -147
  351. package/src/ui/dialogs/dynamics.ts +0 -143
  352. package/types/src/ui/dialogs/dynamics.d.ts +0 -37
@@ -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
+ }
@@ -0,0 +1,541 @@
1
+ /**
2
+ * Headless checks for Paste Special (PasteBuffer.pasteAttributes and the alignment it uses). Cases are
3
+ * listed in specs/035-paste-special/quickstart.md.
4
+ *
5
+ * Run with: npm run test:paste-special
6
+ */
7
+ import { SmoScore } from '../src/smo/data/score';
8
+ import { SmoMeasure } from '../src/smo/data/measure';
9
+ import { SmoNote } from '../src/smo/data/note';
10
+ import { SmoSystemStaff } from '../src/smo/data/systemStaff';
11
+ import { SmoInstrument } from '../src/smo/data/staffModifiers';
12
+ import { SmoSelection, SmoSelector } from '../src/smo/xform/selections';
13
+ import { PasteBuffer, PasteAttributeKind, PasteAttributeMode } from '../src/smo/xform/copypaste';
14
+ import { SmoLyric, SmoDynamicText, SmoArticulation, SmoOrnament,
15
+ noteModifierDynamicCtorInit } from '../src/smo/data/noteModifiers';
16
+ import { measureModifierDynamicCtorInit } from '../src/smo/data/measureModifiers';
17
+ import { staffModifierDynamicCtorInit } from '../src/smo/data/staffModifiers';
18
+ import { scoreModifierDynamicCtorInit } from '../src/smo/data/scoreModifiers';
19
+
20
+ // The smo layer registers its deserialization factories at app start; do the same here
21
+ // without pulling in any UI.
22
+ noteModifierDynamicCtorInit();
23
+ measureModifierDynamicCtorInit();
24
+ staffModifierDynamicCtorInit();
25
+ scoreModifierDynamicCtorInit();
26
+
27
+ let failures = 0;
28
+ const check = (name: string, condition: boolean, detail?: string) => {
29
+ if (condition) {
30
+ console.log(`PASS ${name}`);
31
+ } else {
32
+ failures += 1;
33
+ console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
34
+ }
35
+ };
36
+
37
+ const QUARTER = 4096;
38
+ const EIGHTH = 2048;
39
+ const WHOLE = 16384;
40
+ const KINDS = PasteBuffer.attributeKinds;
41
+ const DYNAMICS = ['pp', 'p', 'mp', 'mf', 'f', 'ff', 'sfz'];
42
+ const CHORDS = ['C', 'F', 'G', 'Am', 'Dm', 'Em', 'Bm'];
43
+ const ARTICULATIONS = ['accent', 'staccato', 'marcato', 'tenuto', 'upStroke', 'downStroke', 'pizzicato'];
44
+ const ORNAMENTS = ['mordent', 'turn', 'tr', 'upprall', 'doit', 'scoop', 'flip'];
45
+
46
+ /** The markings of a note as comparable text, by kind */
47
+ type Markings = Record<PasteAttributeKind, string[]>;
48
+ const markings = (note: SmoNote): Markings => ({
49
+ dynamics: note.getModifiers('SmoDynamicText').map((d) => (d as SmoDynamicText).text),
50
+ lyrics: note.getTrueLyrics().map((l) => `${l.verse}:${l.getText()}`),
51
+ annotations: note.getAnnotations().map((l) => `${l.verse}:${l.getText()}`),
52
+ chords: note.getChords().map((l) => l.getText()),
53
+ articulations: note.getArticulations().map((a) => a.articulation),
54
+ ornaments: note.getOrnaments().map((o) => o.ornament)
55
+ });
56
+ const sorted = (list: string[]) => [...list].sort();
57
+ const same = (a: string[], b: string[]) => JSON.stringify(sorted(a)) === JSON.stringify(sorted(b));
58
+
59
+ /** Give a note a full set of markings, all different for different `n`. `prefix` tells the staves apart. */
60
+ const decorate = (note: SmoNote, n: number, prefix: string, skipSome: boolean = false) => {
61
+ note.textModifiers = [];
62
+ note.articulations = [];
63
+ note.ornaments = [];
64
+ note.addLyric(new SmoLyric({ ...SmoLyric.defaults, text: `${prefix}ly${n}`, verse: 0, parser: SmoLyric.parsers.lyric } as any));
65
+ note.addAnnotation(new SmoLyric({ ...SmoLyric.defaults, text: `${prefix}an${n}`, verse: 0, parser: SmoLyric.parsers.annotation } as any));
66
+ note.addLyric(new SmoLyric({ ...SmoLyric.defaults, text: CHORDS[n % CHORDS.length], verse: 0, parser: SmoLyric.parsers.chord } as any));
67
+ note.addDynamic(new SmoDynamicText({ ...SmoDynamicText.defaults, text: DYNAMICS[n % DYNAMICS.length] } as any));
68
+ if (!skipSome) {
69
+ note.setArticulation(new SmoArticulation({ ...SmoArticulation.defaults, articulation: ARTICULATIONS[n % ARTICULATIONS.length] } as any), true);
70
+ note.setOrnament(new SmoOrnament({ ...SmoOrnament.defaults, ornament: ORNAMENTS[n % ORNAMENTS.length] } as any), true);
71
+ }
72
+ };
73
+
74
+ /** Replace the notes of the first voice of a measure with notes of the given durations (they must add up to the measure) */
75
+ const setRhythm = (measure: SmoMeasure, durations: number[], letter: string, octave: number) => {
76
+ const proto = measure.voices[0].notes[0];
77
+ measure.voices[0].notes = durations.map((d) => {
78
+ const note = SmoNote.cloneWithDuration(proto, { numerator: d, denominator: 1, remainder: 0 });
79
+ note.noteType = 'n';
80
+ note.pitches = [{ letter: letter as any, accidental: 'n', octave }];
81
+ return note;
82
+ });
83
+ };
84
+
85
+ /**
86
+ * `staves` staves of 4 measures of 4 quarter notes. Staff 0 notes are c4 with markings tagged 'S'; every
87
+ * other staff has g3 notes with its own markings tagged 'D1', 'D2'... Every 3rd note of staff 0 has no
88
+ * articulation or ornament.
89
+ */
90
+ const buildScore = (staves: number = 2): SmoScore => {
91
+ const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
92
+ while (score.staves[0].measures.length < 4) {
93
+ score.addMeasure(score.staves[0].measures.length - 1);
94
+ }
95
+ for (let s = 1; s < staves; ++s) {
96
+ const params = SmoSystemStaff.defaults;
97
+ params.staffId = s;
98
+ params.measureInstrumentMap = { 0: new SmoInstrument(SmoInstrument.defaults) } as any;
99
+ score.addStaff(params);
100
+ }
101
+ score.staves.forEach((staff, s) => {
102
+ staff.measures.forEach((measure, m) => {
103
+ setRhythm(measure, [QUARTER, QUARTER, QUARTER, QUARTER], s === 0 ? 'c' : 'g', s === 0 ? 4 : 3);
104
+ measure.voices[0].notes.forEach((note, t) => {
105
+ const n = m * 4 + t;
106
+ // the other staves use different markings from staff 0, so a paste is always visible
107
+ decorate(note, s === 0 ? n : n + 3, s === 0 ? 'S' : `D${s}`, s === 0 && n % 3 === 2);
108
+ });
109
+ });
110
+ });
111
+ return score;
112
+ };
113
+
114
+ const noteAt = (score: SmoScore, staff: number, measure: number, tick: number): SmoNote =>
115
+ score.staves[staff].measures[measure].voices[0].notes[tick];
116
+ const markingsAt = (score: SmoScore, staff: number, measure: number, tick: number): Markings =>
117
+ markings(noteAt(score, staff, measure, tick));
118
+ /** Pitches, durations and note types of every note, as text */
119
+ const structure = (score: SmoScore): string => JSON.stringify(score.staves.map((staff) => staff.measures.map((measure) =>
120
+ measure.voices.map((voice) => voice.notes.map((note) =>
121
+ [note.noteType, JSON.stringify(note.pitches), note.tickCount, note.stemTicks])))));
122
+ /** Every note's markings, keyed by position, for before and after comparisons */
123
+ const allMarkings = (score: SmoScore): Record<string, Markings> => {
124
+ const rv: Record<string, Markings> = {};
125
+ score.staves.forEach((staff, s) => staff.measures.forEach((measure, m) =>
126
+ measure.voices[0].notes.forEach((note, t) => {
127
+ rv[`${s}-${m}-${t}`] = markings(note);
128
+ })));
129
+ return rv;
130
+ };
131
+ const copyNotes = (score: SmoScore, staff: number, measure: number, firstTick: number, lastMeasure: number, lastTick: number): PasteBuffer => {
132
+ const buffer = new PasteBuffer();
133
+ const selections: SmoSelection[] = [];
134
+ for (let m = measure; m <= lastMeasure; ++m) {
135
+ const notes = score.staves[staff].measures[m].voices[0].notes;
136
+ const from = m === measure ? firstTick : 0;
137
+ const to = m === lastMeasure ? lastTick : notes.length - 1;
138
+ for (let t = from; t <= to; ++t) {
139
+ selections.push(SmoSelection.noteSelection(score, staff, m, 0, t)!);
140
+ }
141
+ }
142
+ buffer.setSelections(score, selections);
143
+ return buffer;
144
+ };
145
+ const dest = (staff: number, measure: number, tick: number = 0): SmoSelector =>
146
+ ({ staff, measure, voice: 0, tick, pitches: [] });
147
+ /** Which notes of a staff had any of their markings change, as 'measure-tick' text */
148
+ const changedNotes = (before: Record<string, Markings>, score: SmoScore, staff: number): string[] => {
149
+ const after = allMarkings(score);
150
+ return Object.keys(after).filter((key) => key.startsWith(`${staff}-`) &&
151
+ JSON.stringify(before[key]) !== JSON.stringify(after[key])).map((key) => key.substring(2));
152
+ };
153
+
154
+ // ---- Foundation: hasNotes, alignment, extent ----
155
+ {
156
+ const score = buildScore();
157
+ const empty = new PasteBuffer();
158
+ check('hasNotes is false before a copy', empty.hasNotes() === false);
159
+ empty.setScore(score);
160
+ check('alignment of no notes is empty', empty.alignAttributeNotes(dest(1, 0), []).length === 0);
161
+ check('extent is null with nothing copied', empty.getAttributePasteExtent(dest(1, 0)) === null);
162
+
163
+ const buffer = copyNotes(score, 0, 0, 0, 1, 3);
164
+ check('hasNotes is true after a copy', buffer.hasNotes() === true);
165
+ check('hasNotes is false after clearSelections', (() => { const b = copyNotes(score, 0, 0, 0, 0, 3); b.clearSelections(); return !b.hasNotes(); })());
166
+ const before = structure(score);
167
+ const beforeMarkings = JSON.stringify(allMarkings(score));
168
+ const pairs = buffer.alignAttributeNotes(dest(1, 0), buffer.notes[0]);
169
+ check('same rhythm: 8 copied notes pair with 8 destination notes', pairs.length === 8);
170
+ check('same rhythm: note i pairs with note i', pairs.every((pair, i) =>
171
+ pair.destination.selector.measure === Math.floor(i / 4) && pair.destination.selector.tick === i % 4 &&
172
+ pair.destination.selector.staff === 1));
173
+ check('alignment changes nothing', structure(score) === before && JSON.stringify(allMarkings(score)) === beforeMarkings);
174
+ const extent = buffer.getAttributePasteExtent(dest(1, 0));
175
+ check('extent is the measures of the pairs', extent !== null && extent.firstMeasure === 0 && extent.lastMeasure === 1);
176
+ check('extent changes nothing', structure(score) === before && JSON.stringify(allMarkings(score)) === beforeMarkings);
177
+ }
178
+
179
+ // ---- US1: each kind alone, all kinds, nothing else changes ----
180
+ {
181
+ const run = (kinds: PasteAttributeKind[], mode: PasteAttributeMode) => {
182
+ const score = buildScore();
183
+ const buffer = copyNotes(score, 0, 0, 0, 1, 3);
184
+ const before = allMarkings(score);
185
+ const shape = structure(score);
186
+ buffer.pasteAttributes(dest(1, 0), { kinds, mode });
187
+ return { score, before, shape };
188
+ };
189
+ KINDS.forEach((kind) => {
190
+ const { score, before, shape } = run([kind], 'replace');
191
+ let ticked = true;
192
+ let others = true;
193
+ for (let i = 0; i < 8; ++i) {
194
+ const m = Math.floor(i / 4);
195
+ const t = i % 4;
196
+ const got = markingsAt(score, 1, m, t);
197
+ const source = markingsAt(score, 0, m, t);
198
+ const was = before[`1-${m}-${t}`];
199
+ // the ticked kind is what the copied note had, the others are untouched
200
+ if (!same(got[kind], source[kind])) {
201
+ ticked = false;
202
+ }
203
+ KINDS.filter((k) => k !== kind).forEach((k) => {
204
+ if (!same(got[k], was[k])) {
205
+ others = false;
206
+ }
207
+ });
208
+ }
209
+ check(`${kind} alone: the destination gets the copied ${kind}`, ticked);
210
+ check(`${kind} alone: the other kinds are untouched`, others);
211
+ check(`${kind} alone: notes after the paste are untouched`, JSON.stringify(markingsAt(score, 1, 2, 0)) === JSON.stringify(before['1-2-0']));
212
+ check(`${kind} alone: pitches and durations are unchanged`, structure(score) === shape);
213
+ });
214
+ {
215
+ const { score, shape } = run([...KINDS], 'replace');
216
+ let all = true;
217
+ for (let i = 0; i < 8; ++i) {
218
+ const got = markingsAt(score, 1, Math.floor(i / 4), i % 4);
219
+ const source = markingsAt(score, 0, Math.floor(i / 4), i % 4);
220
+ KINDS.forEach((k) => {
221
+ if (!same(got[k], source[k])) {
222
+ all = false;
223
+ }
224
+ });
225
+ }
226
+ check('all six kinds: the destination matches the source', all);
227
+ check('all six kinds: pitches and durations are unchanged', structure(score) === shape);
228
+ }
229
+ {
230
+ const score = buildScore();
231
+ const buffer = copyNotes(score, 0, 0, 0, 1, 3);
232
+ const before = JSON.stringify(allMarkings(score));
233
+ buffer.pasteAttributes(dest(1, 0), { kinds: [], mode: 'replace' });
234
+ check('no kinds ticked: nothing changes', JSON.stringify(allMarkings(score)) === before);
235
+ }
236
+ {
237
+ // the pasted markings are independent copies
238
+ const score = buildScore();
239
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
240
+ buffer.pasteAttributes(dest(1, 0), { kinds: [...KINDS], mode: 'replace' });
241
+ const pasted = noteAt(score, 1, 0, 0);
242
+ const original = noteAt(score, 0, 0, 0);
243
+ const pastedLyric = pasted.getTrueLyrics()[0];
244
+ const originalLyric = original.getTrueLyrics()[0];
245
+ check('a pasted lyric is not the copied object', pastedLyric !== originalLyric && pastedLyric.attrs.id !== originalLyric.attrs.id);
246
+ pastedLyric.text = 'changed';
247
+ pasted.getModifiers('SmoDynamicText').forEach((d) => { (d as SmoDynamicText).text = 'changed'; });
248
+ pasted.articulations.forEach((a) => { a.articulation = 'changed'; });
249
+ pasted.ornaments.forEach((o) => { o.ornament = 'changed'; });
250
+ check('editing pasted markings leaves the source score alone', markings(original).lyrics[0] === '0:Sly0' &&
251
+ markings(original).dynamics[0] === 'pp' && markings(original).articulations[0] === 'accent');
252
+ const copiedAgain = buffer.notes[0][0].note;
253
+ check('editing pasted markings leaves the copy buffer alone', markings(copiedAgain).lyrics[0] === '0:Sly0');
254
+ // paste a second time from the same copy
255
+ buffer.pasteAttributes(dest(1, 2), { kinds: [...KINDS], mode: 'replace' });
256
+ check('the copy can be pasted again', markingsAt(score, 1, 2, 0).lyrics[0] === '0:Sly0' &&
257
+ markingsAt(score, 1, 2, 3).lyrics[0] === '0:Sly3');
258
+ }
259
+ {
260
+ // serialization
261
+ const score = buildScore();
262
+ const buffer = copyNotes(score, 0, 0, 0, 1, 3);
263
+ buffer.pasteAttributes(dest(1, 0), { kinds: [...KINDS], mode: 'replace' });
264
+ const reloaded = SmoScore.deserialize(JSON.stringify(score.serialize({ skipStaves: false, useDictionary: false, preserveStaffIds: false })));
265
+ let equal = true;
266
+ for (let i = 0; i < 8; ++i) {
267
+ if (JSON.stringify(markingsAt(reloaded, 1, Math.floor(i / 4), i % 4)) !== JSON.stringify(markingsAt(score, 1, Math.floor(i / 4), i % 4))) {
268
+ equal = false;
269
+ }
270
+ }
271
+ check('pasted markings survive serialize and deserialize', equal);
272
+ }
273
+ }
274
+
275
+ // ---- US2: replace or add ----
276
+ {
277
+ const score = buildScore();
278
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
279
+ // source note 2 (n % 3 === 2) has no articulations or ornaments
280
+ check('setup: source note 2 has no articulation', markingsAt(score, 0, 0, 2).articulations.length === 0);
281
+ const before = allMarkings(score);
282
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['articulations'], mode: 'replace' });
283
+ check('replace: a destination note whose copied note has none ends with none', markingsAt(score, 1, 0, 2).articulations.length === 0);
284
+ check('replace: others get the copied articulation', markingsAt(score, 1, 0, 0).articulations[0] === 'accent' &&
285
+ markingsAt(score, 1, 0, 1).articulations[0] === 'staccato');
286
+ check('replace: ornaments were not ticked, so they are untouched', JSON.stringify(markingsAt(score, 1, 0, 2).ornaments) ===
287
+ JSON.stringify(before['1-0-2'].ornaments));
288
+ check('replace: only aligned notes are cleared', JSON.stringify(markingsAt(score, 1, 1, 0)) === JSON.stringify(before['1-1-0']));
289
+ }
290
+ {
291
+ const score = buildScore();
292
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
293
+ const before = allMarkings(score);
294
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['articulations', 'ornaments', 'annotations', 'chords'], mode: 'add' });
295
+ const got = markingsAt(score, 1, 0, 0);
296
+ const own = before['1-0-0'];
297
+ const src = markingsAt(score, 0, 0, 0);
298
+ check('add: articulations are the destination\'s and the copied ones', same(got.articulations, [...own.articulations, ...src.articulations]));
299
+ check('add: ornaments are the destination\'s and the copied ones', same(got.ornaments, [...own.ornaments, ...src.ornaments]));
300
+ check('add: annotation and chord of the same verse are superseded, never doubled', got.annotations.length === 1 && got.chords.length === 1 &&
301
+ got.annotations[0] === src.annotations[0] && got.chords[0] === src.chords[0]);
302
+ check('add: a note whose copied note has none keeps its own', same(markingsAt(score, 1, 0, 2).articulations, before['1-0-2'].articulations));
303
+ check('add: unticked kinds untouched', JSON.stringify(got.lyrics) === JSON.stringify(own.lyrics) && JSON.stringify(got.dynamics) === JSON.stringify(own.dynamics));
304
+ }
305
+ {
306
+ // a dynamic over a dynamic, and verses
307
+ const score = buildScore();
308
+ const buffer = copyNotes(score, 0, 0, 0, 0, 0);
309
+ const target = noteAt(score, 1, 0, 0);
310
+ target.addLyric(new SmoLyric({ ...SmoLyric.defaults, text: 'verse two', verse: 1, parser: SmoLyric.parsers.lyric } as any));
311
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['dynamics', 'lyrics'], mode: 'add' });
312
+ const got = markings(target);
313
+ check('add: a dynamic over a dynamic leaves exactly one, the pasted', got.dynamics.length === 1 && got.dynamics[0] === 'pp');
314
+ check('add: a lyric of the same verse is replaced and another verse kept', same(got.lyrics, ['0:Sly0', '1:verse two']), got.lyrics.join('|'));
315
+ }
316
+ {
317
+ // replace with several kinds replaces only the ticked ones
318
+ const score = buildScore();
319
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
320
+ const before = allMarkings(score);
321
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['dynamics', 'chords'], mode: 'replace' });
322
+ const got = markingsAt(score, 1, 0, 1);
323
+ check('replace with two kinds: both replaced', same(got.dynamics, markingsAt(score, 0, 0, 1).dynamics) && same(got.chords, markingsAt(score, 0, 0, 1).chords));
324
+ check('replace with two kinds: the other four untouched', same(got.lyrics, before['1-0-1'].lyrics) && same(got.annotations, before['1-0-1'].annotations) &&
325
+ same(got.articulations, before['1-0-1'].articulations) && same(got.ornaments, before['1-0-1'].ornaments));
326
+ }
327
+
328
+ // ---- US3: alignment by elapsed time ----
329
+ {
330
+ // 4 quarters onto 8 eighths: copied notes go to eighths 1, 3, 5, 7
331
+ const score = buildScore();
332
+ setRhythm(score.staves[1].measures[0], new Array(8).fill(EIGHTH), 'g', 3);
333
+ score.staves[1].measures[0].voices[0].notes.forEach((note, t) => decorate(note, 40 + t, 'D1'));
334
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
335
+ const before = allMarkings(score);
336
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['lyrics'], mode: 'replace' });
337
+ const lyrics = score.staves[1].measures[0].voices[0].notes.map((n) => markings(n).lyrics[0]);
338
+ check('4 quarters onto 8 eighths: copied lyrics land on eighths 1, 3, 5, 7',
339
+ lyrics[0] === '0:Sly0' && lyrics[2] === '0:Sly1' && lyrics[4] === '0:Sly2' && lyrics[6] === '0:Sly3', lyrics.join(' '));
340
+ check('4 quarters onto 8 eighths: eighths 2, 4, 6, 8 keep their own lyrics, even in replace mode',
341
+ [1, 3, 5, 7].every((i) => lyrics[i] === before[`1-0-${i}`].lyrics[0]));
342
+ check('4 quarters onto 8 eighths: the extent is measure 0', (() => {
343
+ const e = buffer.getAttributePasteExtent(dest(1, 0));
344
+ return e !== null && e.firstMeasure === 0 && e.lastMeasure === 0;
345
+ })());
346
+ }
347
+ {
348
+ // 2 quarters onto whole notes in two measures: the second copied note reaches the next measure
349
+ const score = buildScore();
350
+ setRhythm(score.staves[1].measures[0], [WHOLE], 'g', 3);
351
+ setRhythm(score.staves[1].measures[1], [WHOLE], 'g', 3);
352
+ decorate(noteAt(score, 1, 0, 0), 50, 'D1');
353
+ decorate(noteAt(score, 1, 1, 0), 51, 'D1');
354
+ const buffer = copyNotes(score, 0, 0, 0, 0, 1);
355
+ const pairs = buffer.alignAttributeNotes(dest(1, 0), buffer.notes[0]);
356
+ check('2 quarters onto 2 wholes: the second note goes to the next measure', pairs.length === 2 &&
357
+ pairs[0].destination.selector.measure === 0 && pairs[1].destination.selector.measure === 1);
358
+ const e = buffer.getAttributePasteExtent(dest(1, 0));
359
+ check('2 quarters onto 2 wholes: the extent includes the second measure (longer than the copied time)', e !== null && e.lastMeasure === 1);
360
+ const before = allMarkings(score);
361
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['lyrics', 'dynamics'], mode: 'replace' });
362
+ check('2 quarters onto 2 wholes: markings arrive in order', markingsAt(score, 1, 0, 0).lyrics[0] === '0:Sly0' &&
363
+ markingsAt(score, 1, 1, 0).lyrics[0] === '0:Sly1');
364
+ const changed = changedNotes(before, score, 1);
365
+ check('2 quarters onto 2 wholes: the extent is exactly the measures edited', changed.length === 2 &&
366
+ Math.min(...changed.map((c) => parseInt(c, 10))) === e!.firstMeasure && Math.max(...changed.map((c) => parseInt(c, 10))) === e!.lastMeasure, changed.join(','));
367
+ }
368
+ {
369
+ // 4 quarters onto [half, quarter, quarter]: the 2nd and 3rd copied notes both go to the first quarter
370
+ const score = buildScore();
371
+ setRhythm(score.staves[1].measures[0], [2 * QUARTER, QUARTER, QUARTER], 'g', 3);
372
+ score.staves[1].measures[0].voices[0].notes.forEach((note, t) => decorate(note, 60 + t, 'D1'));
373
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
374
+ const pairs = buffer.alignAttributeNotes(dest(1, 0), buffer.notes[0]);
375
+ check('4 quarters onto half, quarter, quarter: pairing is 0, 1, 1, 2',
376
+ JSON.stringify(pairs.map((p) => p.destination.selector.tick)) === '[0,1,1,2]', JSON.stringify(pairs.map((p) => p.destination.selector.tick)));
377
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['articulations', 'dynamics', 'lyrics'], mode: 'replace' });
378
+ const second = markingsAt(score, 1, 0, 1);
379
+ check('a destination note aligned to two copied notes gets both articulations', same(second.articulations, ['staccato']
380
+ .concat(markingsAt(score, 0, 0, 2).articulations)));
381
+ check('a single-valued kind keeps the last copied note\'s (dynamic and lyric)',
382
+ second.dynamics.length === 1 && second.dynamics[0] === markingsAt(score, 0, 0, 2).dynamics[0] &&
383
+ second.lyrics.length === 1 && second.lyrics[0] === '0:Sly2');
384
+ check('the note after gets the last copied note', markingsAt(score, 1, 0, 2).lyrics[0] === '0:Sly3');
385
+ }
386
+ {
387
+ // the copy runs past the end of the destination part
388
+ const score = buildScore();
389
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
390
+ const before = allMarkings(score);
391
+ const shape = structure(score);
392
+ buffer.pasteAttributes(dest(1, 3, 2), { kinds: [...KINDS], mode: 'replace' });
393
+ const changed = changedNotes(before, score, 1);
394
+ check('copy longer than the destination: stops at the end of the part, no error', changed.join(',') === '3-2,3-3', changed.join(','));
395
+ check('copy longer than the destination: no notes added', structure(score) === shape);
396
+ const e = buffer.getAttributePasteExtent(dest(1, 3, 2));
397
+ check('copy longer than the destination: extent is the last measure', e !== null && e.firstMeasure === 3 && e.lastMeasure === 3);
398
+ }
399
+ {
400
+ // rests
401
+ const score = buildScore();
402
+ const rests = score.staves[1].measures[0].voices[0].notes;
403
+ rests[1].noteType = 'r';
404
+ rests[2].noteType = 'r';
405
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
406
+ // a copied rest counts too
407
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['lyrics'], mode: 'replace' });
408
+ check('rests in the destination are aligned like notes and stay rests', rests[1].noteType === 'r' && rests[2].noteType === 'r' &&
409
+ markings(rests[1]).lyrics[0] === '0:Sly1' && markings(rests[2]).lyrics[0] === '0:Sly2');
410
+ const score2 = buildScore();
411
+ noteAt(score2, 0, 0, 1).noteType = 'r';
412
+ const buffer2 = copyNotes(score2, 0, 0, 0, 0, 3);
413
+ buffer2.pasteAttributes(dest(1, 0), { kinds: ['dynamics'], mode: 'replace' });
414
+ check('a copied rest is aligned by its length like a note', buffer2.notes[0].length === 4 &&
415
+ markingsAt(score2, 1, 0, 2).dynamics[0] === markingsAt(score2, 0, 0, 2).dynamics[0]);
416
+ }
417
+ {
418
+ // a copy of two measures keeps lining up across the barline
419
+ const score = buildScore();
420
+ const buffer = copyNotes(score, 0, 0, 0, 1, 3);
421
+ const before = allMarkings(score);
422
+ buffer.pasteAttributes(dest(1, 2), { kinds: ['lyrics'], mode: 'replace' });
423
+ check('two measures onto two measures', markingsAt(score, 1, 2, 0).lyrics[0] === '0:Sly0' && markingsAt(score, 1, 3, 3).lyrics[0] === '0:Sly7');
424
+ const e = buffer.getAttributePasteExtent(dest(1, 2));
425
+ const changed = changedNotes(before, score, 1);
426
+ check('two measures: the extent is exactly the measures edited', e !== null && e.firstMeasure === 2 && e.lastMeasure === 3 &&
427
+ changed.length === 8 && changed.every((c) => c.startsWith('2-') || c.startsWith('3-')));
428
+ // starting in the middle of a measure
429
+ const score2 = buildScore();
430
+ const buffer2 = copyNotes(score2, 0, 0, 0, 1, 3);
431
+ buffer2.pasteAttributes(dest(1, 1, 2), { kinds: ['lyrics'], mode: 'replace' });
432
+ check('starting mid-measure: the first copied note goes to the note under the cursor', markingsAt(score2, 1, 1, 2).lyrics[0] === '0:Sly0' &&
433
+ markingsAt(score2, 1, 2, 1).lyrics[0] === '0:Sly3');
434
+ }
435
+ {
436
+ // two staves, three-staff score
437
+ const score = buildScore(3);
438
+ const buffer = new PasteBuffer();
439
+ const sels: SmoSelection[] = [];
440
+ [0, 1].forEach((staff) => {
441
+ for (let t = 0; t < 4; ++t) {
442
+ sels.push(SmoSelection.noteSelection(score, staff, 0, 0, t)!);
443
+ }
444
+ });
445
+ buffer.setSelections(score, sels);
446
+ const before = allMarkings(score);
447
+ buffer.pasteAttributes(dest(1, 1), { kinds: ['lyrics'], mode: 'replace' });
448
+ check('two staves: the first staff goes to the cursor staff', markingsAt(score, 1, 1, 0).lyrics[0] === '0:Sly0');
449
+ check('two staves: the second staff goes to the staff below', markingsAt(score, 2, 1, 0).lyrics[0] === before['1-0-0'].lyrics[0]);
450
+ check('two staves: the staff above is untouched', JSON.stringify(allMarkings(score)['0-1-0']) === JSON.stringify(before['0-1-0']));
451
+ // no staff below the cursor staff: only the first is pasted
452
+ const score2 = buildScore(3);
453
+ const buffer2 = new PasteBuffer();
454
+ const sels2: SmoSelection[] = [];
455
+ [0, 1].forEach((staff) => {
456
+ for (let t = 0; t < 4; ++t) {
457
+ sels2.push(SmoSelection.noteSelection(score2, staff, 0, 0, t)!);
458
+ }
459
+ });
460
+ buffer2.setSelections(score2, sels2);
461
+ buffer2.pasteAttributes(dest(2, 1), { kinds: ['lyrics'], mode: 'replace' });
462
+ check('two staves with no staff below: the first staff is pasted and nothing fails', markingsAt(score2, 2, 1, 0).lyrics[0] === '0:Sly0');
463
+ }
464
+
465
+ // ---- US4: chords follow the destination's transposition; the rest is as it is ----
466
+ {
467
+ const sourceChords = (score: SmoScore) => [0, 1, 2, 3].map((t) => markingsAt(score, 0, 0, t).chords[0]);
468
+ // a concert-pitch part in another key: chord names are not changed
469
+ const concert = buildScore();
470
+ concert.staves[1].measures.forEach((measure) => measure.setKeySignature('d'));
471
+ copyNotes(concert, 0, 0, 0, 0, 3).pasteAttributes(dest(1, 0), { kinds: ['chords'], mode: 'replace' });
472
+ check('chords onto a concert-pitch part in another key are not changed', JSON.stringify([0, 1, 2, 3].map((t) => markingsAt(concert, 1, 0, t).chords[0])) ===
473
+ JSON.stringify(sourceChords(concert)));
474
+ // a transposing part: chords are spelled for it (written a whole step higher)
475
+ const transposing = buildScore();
476
+ transposing.staves[1].measures.forEach((measure) => {
477
+ measure.transposeIndex = 2;
478
+ measure.setKeySignature('d');
479
+ });
480
+ const buffer = copyNotes(transposing, 0, 0, 0, 0, 3);
481
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['chords'], mode: 'replace' });
482
+ const expected = [0, 1, 2, 3].map((t) => SmoLyric.transposeChordToKey(
483
+ noteAt(transposing, 0, 0, t).getChords()[0], 2, 'c', 'd').getText());
484
+ const got = [0, 1, 2, 3].map((t) => markingsAt(transposing, 1, 0, t).chords[0]);
485
+ check('chords onto a transposing part are spelled for it (C F G Am to D G A Bm)', JSON.stringify(got) === JSON.stringify(expected) &&
486
+ JSON.stringify(got) === JSON.stringify(['D', 'G', 'A', 'Bm']), got.join(' '));
487
+ check('the copied chords are not changed by pasting', JSON.stringify(sourceChords(transposing)) === JSON.stringify(['C', 'F', 'G', 'Am']));
488
+
489
+ // everything else is copied as is, with all its settings
490
+ const other = buildScore();
491
+ other.staves[1].measures.forEach((measure) => {
492
+ measure.transposeIndex = 2;
493
+ measure.setKeySignature('d');
494
+ });
495
+ noteAt(other, 0, 0, 0).getModifiers('SmoDynamicText').forEach((d) => {
496
+ (d as SmoDynamicText).xOffset = -7;
497
+ (d as SmoDynamicText).yOffsetPixels = 5;
498
+ });
499
+ noteAt(other, 0, 0, 0).getTrueLyrics()[0].translateX = 9;
500
+ const buf = copyNotes(other, 0, 0, 0, 0, 3);
501
+ const ownChords = markings(noteAt(other, 1, 0, 0)).chords;
502
+ buf.pasteAttributes(dest(1, 0), { kinds: ['dynamics', 'lyrics', 'annotations', 'articulations', 'ornaments'], mode: 'replace' });
503
+ const text = (mods: any[]) => JSON.stringify(mods.map((m) => m.serialize()));
504
+ const a = noteAt(other, 0, 0, 0);
505
+ const b = noteAt(other, 1, 0, 0);
506
+ check('dynamics keep their offsets on a transposing part', text(b.getModifiers('SmoDynamicText')) === text(a.getModifiers('SmoDynamicText')) &&
507
+ (b.getModifiers('SmoDynamicText')[0] as SmoDynamicText).xOffset === -7);
508
+ check('lyrics and annotations keep their settings on a transposing part', text(b.getTrueLyrics()) === text(a.getTrueLyrics()) &&
509
+ text(b.getAnnotations()) === text(a.getAnnotations()) && b.getTrueLyrics()[0].translateX === 9);
510
+ check('articulations and ornaments are identical on a transposing part', text(b.getArticulations()) === text(a.getArticulations()) &&
511
+ text(b.getOrnaments()) === text(a.getOrnaments()));
512
+ check('chords were not ticked, so the destination keeps its own', ownChords.length === 1 && same(markings(b).chords, ownChords) &&
513
+ !same(markings(b).chords, markings(a).chords));
514
+ }
515
+ {
516
+ // two pastes of different kinds: the second leaves the first alone
517
+ const score = buildScore();
518
+ const buffer = copyNotes(score, 0, 0, 0, 0, 3);
519
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['lyrics'], mode: 'replace' });
520
+ buffer.pasteAttributes(dest(1, 0), { kinds: ['dynamics'], mode: 'replace' });
521
+ check('a second paste of another kind leaves the first alone', markingsAt(score, 1, 0, 1).lyrics[0] === '0:Sly1' &&
522
+ markingsAt(score, 1, 0, 1).dynamics[0] === 'p');
523
+ }
524
+
525
+ // ---- removeAllAnnotations only removes annotations ----
526
+ {
527
+ const note = buildScore().staves[0].measures[0].voices[0].notes[0];
528
+ const before = markings(note);
529
+ note.removeAllAnnotations();
530
+ const after = markings(note);
531
+ check('removeAllAnnotations removes the annotation', before.annotations.length === 1 && after.annotations.length === 0);
532
+ check('removeAllAnnotations keeps lyrics, chords and dynamics', same(after.lyrics, before.lyrics) && same(after.chords, before.chords) &&
533
+ same(after.dynamics, before.dynamics));
534
+ }
535
+
536
+ if (failures > 0) {
537
+ console.log(`${failures} check(s) failed`);
538
+ process.exitCode = 1;
539
+ } else {
540
+ console.log('all checks passed');
541
+ }