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.
- package/build/smoosic.js +546 -125
- package/changes.md +85 -0
- package/package.json +23 -2
- package/release/smoosic.js +549 -128
- package/release/styles/menus.css +26 -0
- package/specs/022-text-reposition-on-resize/spec.md +1 -0
- package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
- package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
- package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
- package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
- package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
- package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
- package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
- package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
- package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
- package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
- package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
- package/specs/028-unsaved-changes-indicator/plan.md +96 -0
- package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
- package/specs/028-unsaved-changes-indicator/research.md +68 -0
- package/specs/028-unsaved-changes-indicator/spec.md +135 -0
- package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
- package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
- package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
- package/specs/029-remove-promise-helpers/data-model.md +45 -0
- package/specs/029-remove-promise-helpers/plan.md +86 -0
- package/specs/029-remove-promise-helpers/quickstart.md +53 -0
- package/specs/029-remove-promise-helpers/research.md +71 -0
- package/specs/029-remove-promise-helpers/spec.md +107 -0
- package/specs/029-remove-promise-helpers/tasks.md +164 -0
- package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
- package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
- package/specs/030-copy-paste-voices/data-model.md +63 -0
- package/specs/030-copy-paste-voices/plan.md +80 -0
- package/specs/030-copy-paste-voices/quickstart.md +50 -0
- package/specs/030-copy-paste-voices/research.md +80 -0
- package/specs/030-copy-paste-voices/spec.md +124 -0
- package/specs/030-copy-paste-voices/tasks.md +183 -0
- package/specs/031-select-voice/checklists/requirements.md +39 -0
- package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
- package/specs/031-select-voice/data-model.md +47 -0
- package/specs/031-select-voice/plan.md +79 -0
- package/specs/031-select-voice/quickstart.md +43 -0
- package/specs/031-select-voice/research.md +55 -0
- package/specs/031-select-voice/spec.md +113 -0
- package/specs/031-select-voice/tasks.md +171 -0
- package/specs/032-split-multimeasure-rests/checklists/requirements.md +40 -0
- package/specs/032-split-multimeasure-rests/contracts/grouping-contract.md +53 -0
- package/specs/032-split-multimeasure-rests/data-model.md +70 -0
- package/specs/032-split-multimeasure-rests/plan.md +81 -0
- package/specs/032-split-multimeasure-rests/quickstart.md +46 -0
- package/specs/032-split-multimeasure-rests/research.md +63 -0
- package/specs/032-split-multimeasure-rests/spec.md +127 -0
- package/specs/032-split-multimeasure-rests/tasks.md +174 -0
- package/specs/033-key-distance-transposition/checklists/requirements.md +35 -0
- package/specs/033-key-distance-transposition/contracts/spelling-api.md +36 -0
- package/specs/033-key-distance-transposition/data-model.md +49 -0
- package/specs/033-key-distance-transposition/plan.md +87 -0
- package/specs/033-key-distance-transposition/quickstart.md +40 -0
- package/specs/033-key-distance-transposition/research.md +82 -0
- package/specs/033-key-distance-transposition/spec.md +132 -0
- package/specs/033-key-distance-transposition/tasks.md +139 -0
- package/specs/034-smz-compressed-scores/checklists/requirements.md +35 -0
- package/specs/034-smz-compressed-scores/contracts/archive-api.md +30 -0
- package/specs/034-smz-compressed-scores/data-model.md +48 -0
- package/specs/034-smz-compressed-scores/plan.md +89 -0
- package/specs/034-smz-compressed-scores/quickstart.md +44 -0
- package/specs/034-smz-compressed-scores/research.md +86 -0
- package/specs/034-smz-compressed-scores/spec.md +137 -0
- package/specs/034-smz-compressed-scores/tasks.md +148 -0
- package/specs/035-paste-special/checklists/requirements.md +35 -0
- package/specs/035-paste-special/contracts/paste-special-api.md +50 -0
- package/specs/035-paste-special/data-model.md +47 -0
- package/specs/035-paste-special/plan.md +83 -0
- package/specs/035-paste-special/quickstart.md +51 -0
- package/specs/035-paste-special/research.md +97 -0
- package/specs/035-paste-special/spec.md +170 -0
- package/specs/035-paste-special/tasks.md +149 -0
- package/specs/036-autosave-recovery/checklists/requirements.md +36 -0
- package/specs/036-autosave-recovery/contracts/autosave-api.md +111 -0
- package/specs/036-autosave-recovery/data-model.md +70 -0
- package/specs/036-autosave-recovery/plan.md +87 -0
- package/specs/036-autosave-recovery/quickstart.md +65 -0
- package/specs/036-autosave-recovery/research.md +105 -0
- package/specs/036-autosave-recovery/spec.md +143 -0
- package/specs/036-autosave-recovery/tasks.md +165 -0
- package/specs/037-fix-new-part-dialog/checklists/requirements.md +38 -0
- package/specs/037-fix-new-part-dialog/contracts/create-part-api.md +84 -0
- package/specs/037-fix-new-part-dialog/data-model.md +68 -0
- package/specs/037-fix-new-part-dialog/plan.md +83 -0
- package/specs/037-fix-new-part-dialog/quickstart.md +58 -0
- package/specs/037-fix-new-part-dialog/research.md +86 -0
- package/specs/037-fix-new-part-dialog/spec.md +144 -0
- package/specs/037-fix-new-part-dialog/tasks.md +174 -0
- package/specs/038-per-measure-beam-groups/checklists/requirements.md +36 -0
- package/specs/038-per-measure-beam-groups/contracts/beam-groups-api.md +74 -0
- package/specs/038-per-measure-beam-groups/data-model.md +75 -0
- package/specs/038-per-measure-beam-groups/plan.md +84 -0
- package/specs/038-per-measure-beam-groups/quickstart.md +53 -0
- package/specs/038-per-measure-beam-groups/research.md +72 -0
- package/specs/038-per-measure-beam-groups/spec.md +146 -0
- package/specs/038-per-measure-beam-groups/tasks.md +132 -0
- package/specs/039-measure-fill-submenu/checklists/requirements.md +35 -0
- package/specs/039-measure-fill-submenu/contracts/measure-fill-api.md +56 -0
- package/specs/039-measure-fill-submenu/data-model.md +79 -0
- package/specs/039-measure-fill-submenu/plan.md +81 -0
- package/specs/039-measure-fill-submenu/quickstart.md +62 -0
- package/specs/039-measure-fill-submenu/research.md +68 -0
- package/specs/039-measure-fill-submenu/spec.md +153 -0
- package/specs/039-measure-fill-submenu/tasks.md +121 -0
- package/specs/040-dynamics-dialog-cleanup/checklists/requirements.md +36 -0
- package/specs/040-dynamics-dialog-cleanup/contracts/dynamics-dialog.md +52 -0
- package/specs/040-dynamics-dialog-cleanup/data-model.md +48 -0
- package/specs/040-dynamics-dialog-cleanup/plan.md +89 -0
- package/specs/040-dynamics-dialog-cleanup/quickstart.md +69 -0
- package/specs/040-dynamics-dialog-cleanup/research.md +80 -0
- package/specs/040-dynamics-dialog-cleanup/spec.md +120 -0
- package/specs/040-dynamics-dialog-cleanup/tasks.md +114 -0
- package/specs/041-delete-special/checklists/requirements.md +35 -0
- package/specs/041-delete-special/contracts/delete-special-api.md +41 -0
- package/specs/041-delete-special/data-model.md +40 -0
- package/specs/041-delete-special/plan.md +93 -0
- package/specs/041-delete-special/quickstart.md +41 -0
- package/specs/041-delete-special/research.md +75 -0
- package/specs/041-delete-special/spec.md +136 -0
- package/specs/041-delete-special/tasks.md +106 -0
- package/src/application/application.ts +475 -459
- package/src/application/exports.ts +401 -395
- package/src/application/generateVexTests.ts +2 -2
- package/src/common/promiseHelpers.ts +2 -2
- package/src/render/audio/samples.ts +117 -118
- package/src/render/sui/NoteEntryCaret.ts +117 -16
- package/src/render/sui/autosave.ts +265 -0
- package/src/render/sui/formatter.ts +12 -2
- package/src/render/sui/pageDivisions.ts +58 -0
- package/src/render/sui/renderState.ts +469 -464
- package/src/render/sui/scoreChangeState.ts +67 -0
- package/src/render/sui/scoreView.ts +77 -2
- package/src/render/sui/scoreViewOperations.ts +363 -37
- package/src/render/sui/staffLineGeometry.ts +82 -0
- package/src/render/sui/svgPageMap.ts +16 -17
- package/src/render/sui/textEdit.ts +310 -311
- package/src/render/sui/tracker.ts +40 -0
- package/src/render/vex/vxMeasure.ts +22 -8
- package/src/render/vex/vxNote.ts +5 -5
- package/src/smo/data/measure.ts +58 -1
- package/src/smo/data/measureModifiers.ts +81 -1
- package/src/smo/data/music.ts +169 -359
- package/src/smo/data/note.ts +1 -1
- package/src/smo/data/noteModifiers.ts +12 -0
- package/src/smo/data/score.ts +167 -2
- package/src/smo/data/scoreModifiers.ts +46 -1
- package/src/smo/data/systemStaff.ts +43 -0
- package/src/smo/xform/beamers.ts +80 -6
- package/src/smo/xform/copypaste.ts +511 -51
- package/src/smo/xform/measureFill.ts +89 -0
- package/src/smo/xform/operations.ts +403 -61
- package/src/smo/xform/selections.ts +75 -0
- package/src/smo/xform/undo.ts +9 -0
- package/src/styles/menus.css +26 -0
- package/src/ui/buttons/ribbon.ts +3 -1
- package/src/ui/components/buttons/sidebar.vue +15 -6
- package/src/ui/components/dialogs/beamGroups.vue +106 -0
- package/src/ui/components/dialogs/deleteSpecial.vue +38 -0
- package/src/ui/components/dialogs/dynamics.vue +16 -3
- package/src/ui/components/dialogs/fileUpload.vue +2 -2
- package/src/ui/components/dialogs/hairpin.vue +3 -3
- package/src/ui/components/dialogs/library.vue +3 -1
- package/src/ui/components/dialogs/newPart.vue +148 -184
- package/src/ui/components/dialogs/pasteSpecial.vue +49 -0
- package/src/ui/components/dialogs/recovery.vue +66 -0
- package/src/ui/components/dialogs/save.vue +11 -4
- package/src/ui/components/dialogs/scorePreferences.vue +23 -1
- package/src/ui/components/dialogs/slur.vue +6 -6
- package/src/ui/components/dialogs/tempo.vue +11 -3
- package/src/ui/components/dialogs/timeSignature.vue +5 -0
- package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
- package/src/ui/components/dialogs/volta.vue +3 -3
- package/src/ui/dialogs/adapter.ts +181 -183
- package/src/ui/dialogs/addMeasure.ts +97 -97
- package/src/ui/dialogs/annotationVue.ts +56 -56
- package/src/ui/dialogs/audioSettings.ts +121 -123
- package/src/ui/dialogs/beamGroupsVue.ts +69 -0
- package/src/ui/dialogs/chordChangeVue.ts +46 -46
- package/src/ui/dialogs/clefChange.ts +53 -53
- package/src/ui/dialogs/createPartHelpers.ts +68 -0
- package/src/ui/dialogs/customTuplets.ts +95 -96
- package/src/ui/dialogs/customTupletsVue.ts +47 -47
- package/src/ui/dialogs/deleteSpecial.ts +57 -0
- package/src/ui/dialogs/dialog.ts +627 -620
- package/src/ui/dialogs/durations.ts +34 -34
- package/src/ui/dialogs/dynamicsVue.ts +87 -60
- package/src/ui/dialogs/factory.ts +196 -198
- package/src/ui/dialogs/fileDialogs.ts +286 -179
- package/src/ui/dialogs/fonts.ts +93 -93
- package/src/ui/dialogs/globalLayout.ts +40 -40
- package/src/ui/dialogs/gracenote.ts +31 -31
- package/src/ui/dialogs/hairpin.ts +108 -110
- package/src/ui/dialogs/hairpinVue.ts +51 -51
- package/src/ui/dialogs/instrument.ts +119 -112
- package/src/ui/dialogs/keySignature.ts +175 -176
- package/src/ui/dialogs/keySignatureVue.ts +47 -47
- package/src/ui/dialogs/library.ts +207 -207
- package/src/ui/dialogs/libraryVue.ts +62 -48
- package/src/ui/dialogs/lyricVue.ts +46 -46
- package/src/ui/dialogs/measureFormat.ts +78 -78
- package/src/ui/dialogs/microtones.ts +147 -147
- package/src/ui/dialogs/noteHead.ts +319 -319
- package/src/ui/dialogs/pageLayout.ts +61 -61
- package/src/ui/dialogs/partInfo.ts +60 -60
- package/src/ui/dialogs/pasteSpecial.ts +59 -0
- package/src/ui/dialogs/pedalMarking.ts +117 -117
- package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
- package/src/ui/dialogs/pitch.ts +352 -352
- package/src/ui/dialogs/preferences.ts +1 -0
- package/src/ui/dialogs/recovery.ts +49 -0
- package/src/ui/dialogs/rehearsalMark.ts +64 -64
- package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
- package/src/ui/dialogs/scoreId.ts +35 -36
- package/src/ui/dialogs/scoreView.ts +42 -42
- package/src/ui/dialogs/slur.ts +308 -310
- package/src/ui/dialogs/slurVue.ts +91 -91
- package/src/ui/dialogs/staffGroup.ts +112 -112
- package/src/ui/dialogs/tabNote.ts +84 -84
- package/src/ui/dialogs/tabStave.ts +182 -182
- package/src/ui/dialogs/tempo.ts +261 -263
- package/src/ui/dialogs/tempoVue.ts +73 -73
- package/src/ui/dialogs/textBlockVue.ts +127 -127
- package/src/ui/dialogs/textBracket.ts +114 -116
- package/src/ui/dialogs/textBracketVue.ts +56 -56
- package/src/ui/dialogs/tie.ts +140 -142
- package/src/ui/dialogs/timeSignature.ts +65 -66
- package/src/ui/dialogs/transposeScore.ts +39 -39
- package/src/ui/dialogs/unsavedChanges.ts +43 -0
- package/src/ui/dialogs/volta.ts +120 -122
- package/src/ui/dialogs/voltaVue.ts +51 -51
- package/src/ui/fileio/fileInput.ts +12 -3
- package/src/ui/fileio/library.ts +110 -111
- package/src/ui/fileio/scoreArchive.ts +151 -0
- package/src/ui/fileio/xhrLoader.ts +26 -0
- package/src/ui/i18n/language.ts +1 -1
- package/src/ui/menus/beams.ts +181 -112
- package/src/ui/menus/edit.ts +143 -6
- package/src/ui/menus/file.ts +40 -4
- package/src/ui/menus/measure.ts +40 -1
- package/tests/autosave.ts +332 -0
- package/tests/beamDotted.ts +56 -0
- package/tests/beamGroups.ts +338 -0
- package/tests/createPart.ts +292 -0
- package/tests/deleteSpecial.ts +350 -0
- package/tests/dynamicsFontSize.ts +132 -0
- package/tests/keyDistanceTransposition.ts +351 -0
- package/tests/measureFill.ts +295 -0
- package/tests/movePart.ts +94 -0
- package/tests/multimeasureRest.ts +338 -0
- package/tests/pageDivisions.ts +156 -0
- package/tests/pasteIntoMeasure.ts +103 -0
- package/tests/pasteSpecial.ts +541 -0
- package/tests/promiseHelpersUsage.ts +142 -0
- package/tests/quickBeam.ts +126 -0
- package/tests/scoreArchive.ts +218 -0
- package/tests/scoreChangeState.ts +104 -0
- package/tests/selectVoice.ts +189 -0
- package/tests/staffLineGeometry.ts +179 -0
- package/tests/timeSignatureDisplay.ts +58 -0
- package/tests/voiceCopyPaste.ts +417 -0
- package/tools/smoosic-schema.json +37 -0
- package/typedoc.ts +1 -1
- package/types/src/application/exports.d.ts +453 -447
- package/types/src/common/promiseHelpers.d.ts +30 -30
- package/types/src/common/vex.d.ts +224 -224
- package/types/src/render/sui/NoteEntryCaret.d.ts +107 -107
- package/types/src/render/sui/autosave.d.ts +99 -0
- package/types/src/render/sui/scoreView.d.ts +23 -0
- package/types/src/render/sui/scoreViewOperations.d.ts +759 -639
- package/types/src/render/sui/svgHelpers.d.ts +88 -88
- package/types/src/render/sui/svgPageMap.d.ts +344 -344
- package/types/src/render/sui/textEdit.d.ts +96 -96
- package/types/src/render/sui/textRender.d.ts +199 -199
- package/types/src/render/vex/smoAdapter.d.ts +47 -47
- package/types/src/render/vex/vxMeasure.d.ts +97 -97
- package/types/src/render/vex/vxNote.d.ts +56 -56
- package/types/src/render/vex/vxSystem.d.ts +71 -71
- package/types/src/smo/data/measure.d.ts +30 -0
- package/types/src/smo/data/measureModifiers.d.ts +568 -513
- package/types/src/smo/data/music.d.ts +74 -32
- package/types/src/smo/data/note.d.ts +498 -498
- package/types/src/smo/data/noteModifiers.d.ts +615 -606
- package/types/src/smo/data/score.d.ts +476 -421
- package/types/src/smo/data/scoreModifiers.d.ts +30 -0
- package/types/src/smo/data/scoreText.d.ts +334 -334
- package/types/src/smo/data/systemStaff.d.ts +14 -0
- package/types/src/smo/xform/beamers.d.ts +23 -1
- package/types/src/smo/xform/copypaste.d.ts +138 -2
- package/types/src/smo/xform/measureFill.d.ts +21 -0
- package/types/src/smo/xform/operations.d.ts +245 -129
- package/types/src/smo/xform/selections.d.ts +154 -154
- package/types/src/smo/xform/undo.d.ts +142 -142
- package/types/src/ui/buttons/button.d.ts +100 -100
- package/types/src/ui/buttons/ribbon.d.ts +70 -70
- package/types/src/ui/common.d.ts +76 -76
- package/types/src/ui/components/dialogs/chordText.d.ts +28 -28
- package/types/src/ui/components/dialogs/textBlockAtomNode.d.ts +20 -20
- package/types/src/ui/components/dialogs/textGroupHtml.d.ts +29 -29
- package/types/src/ui/composable/draggable.d.ts +15 -15
- package/types/src/ui/dialogs/adapter.d.ts +120 -120
- package/types/src/ui/dialogs/annotationVue.d.ts +9 -9
- package/types/src/ui/dialogs/audioSettings.d.ts +32 -32
- package/types/src/ui/dialogs/beamGroupsVue.d.ts +20 -0
- package/types/src/ui/dialogs/chordChangeVue.d.ts +8 -8
- package/types/src/ui/dialogs/createPartHelpers.d.ts +29 -0
- package/types/src/ui/dialogs/customTupletsVue.d.ts +9 -9
- package/types/src/ui/dialogs/deleteSpecial.d.ts +8 -0
- package/types/src/ui/dialogs/dialog.d.ts +203 -203
- package/types/src/ui/dialogs/dynamicsVue.d.ts +10 -10
- package/types/src/ui/dialogs/factory.d.ts +15 -15
- package/types/src/ui/dialogs/fileDialogs.d.ts +4 -4
- package/types/src/ui/dialogs/hairpin.d.ts +35 -35
- package/types/src/ui/dialogs/hairpinVue.d.ts +7 -7
- package/types/src/ui/dialogs/instrument.d.ts +3 -3
- package/types/src/ui/dialogs/keySignatureVue.d.ts +7 -7
- package/types/src/ui/dialogs/libraryVue.d.ts +15 -15
- package/types/src/ui/dialogs/lyricVue.d.ts +8 -8
- package/types/src/ui/dialogs/pasteSpecial.d.ts +8 -0
- package/types/src/ui/dialogs/pedalMarkingVue.d.ts +7 -7
- package/types/src/ui/dialogs/recovery.d.ts +8 -0
- package/types/src/ui/dialogs/rehearsalMark.d.ts +25 -25
- package/types/src/ui/dialogs/rehearsalMarkVue.d.ts +7 -7
- package/types/src/ui/dialogs/slur.d.ts +57 -57
- package/types/src/ui/dialogs/slurVue.d.ts +7 -7
- package/types/src/ui/dialogs/tempo.d.ts +50 -50
- package/types/src/ui/dialogs/tempoVue.d.ts +10 -10
- package/types/src/ui/dialogs/textBlockVue.d.ts +8 -8
- package/types/src/ui/dialogs/textBracket.d.ts +35 -35
- package/types/src/ui/dialogs/textBracketVue.d.ts +7 -7
- package/types/src/ui/dialogs/tie.d.ts +41 -41
- package/types/src/ui/dialogs/volta.d.ts +40 -40
- package/types/src/ui/dialogs/voltaVue.d.ts +7 -7
- package/types/src/ui/fileio/fileInput.d.ts +7 -1
- package/types/src/ui/fileio/library.d.ts +40 -40
- package/types/src/ui/fileio/scoreArchive.d.ts +55 -0
- package/types/src/ui/fileio/xhrLoader.d.ts +7 -0
- package/types/src/ui/menus/file.d.ts +8 -8
- package/types/src/ui/menus/language.d.ts +7 -7
- package/types/src/ui/menus/manager.d.ts +58 -58
- package/types/src/ui/menus/menu.d.ts +159 -159
- package/types/src/ui/menus/partSelection.d.ts +14 -14
- package/types/src/ui/menus/score.d.ts +8 -8
- package/types/src/ui/menus/staffModifier.d.ts +17 -17
- package/types/typedoc.d.ts +147 -147
- package/src/ui/dialogs/dynamics.ts +0 -143
- package/types/src/ui/dialogs/dynamics.d.ts +0 -37
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless checks for per-measure beam groups: the SmoBeamPreferences modifier, the group boundaries,
|
|
3
|
+
* the beams that come out, the operations that set a grouping, and serialization. Cases are listed
|
|
4
|
+
* in specs/038-per-measure-beam-groups/contracts/beam-groups-api.md.
|
|
5
|
+
*
|
|
6
|
+
* Run with: npm run test:beam-groups
|
|
7
|
+
*/
|
|
8
|
+
import { SmoScore } from '../src/smo/data/score';
|
|
9
|
+
import { SmoMeasure } from '../src/smo/data/measure';
|
|
10
|
+
import { SmoNote } from '../src/smo/data/note';
|
|
11
|
+
import { SmoTimeSignature, SmoBeamPreferences } from '../src/smo/data/measureModifiers';
|
|
12
|
+
import { SmoBeamer } from '../src/smo/xform/beamers';
|
|
13
|
+
import { SmoOperation } from '../src/smo/xform/operations';
|
|
14
|
+
import { SmoSelection } from '../src/smo/xform/selections';
|
|
15
|
+
import { SmoSystemStaff } from '../src/smo/data/systemStaff';
|
|
16
|
+
import { SmoInstrument } from '../src/smo/data/staffModifiers';
|
|
17
|
+
import { SmoScoreArchive } from '../src/ui/fileio/scoreArchive';
|
|
18
|
+
import { noteModifierDynamicCtorInit } from '../src/smo/data/noteModifiers';
|
|
19
|
+
import { measureModifierDynamicCtorInit } from '../src/smo/data/measureModifiers';
|
|
20
|
+
import { staffModifierDynamicCtorInit } from '../src/smo/data/staffModifiers';
|
|
21
|
+
import { scoreModifierDynamicCtorInit } from '../src/smo/data/scoreModifiers';
|
|
22
|
+
|
|
23
|
+
// In the application JSZip is a global from a script tag.
|
|
24
|
+
(global as any).JSZip = require('../src/common/jszip.js');
|
|
25
|
+
|
|
26
|
+
// The smo layer registers its deserialization factories at app start; do the same here
|
|
27
|
+
// without pulling in any UI.
|
|
28
|
+
noteModifierDynamicCtorInit();
|
|
29
|
+
measureModifierDynamicCtorInit();
|
|
30
|
+
staffModifierDynamicCtorInit();
|
|
31
|
+
scoreModifierDynamicCtorInit();
|
|
32
|
+
|
|
33
|
+
let failures = 0;
|
|
34
|
+
const check = (name: string, condition: boolean, detail?: string) => {
|
|
35
|
+
if (condition) {
|
|
36
|
+
console.log(`PASS ${name}`);
|
|
37
|
+
} else {
|
|
38
|
+
failures += 1;
|
|
39
|
+
console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const E = 2048, S = 1024, Q = 4096, DE = 3072;
|
|
44
|
+
/** n values of an eighth note */
|
|
45
|
+
const eighths = (n: number): number[] => new Array(n).fill(E);
|
|
46
|
+
/**
|
|
47
|
+
* A measure with the given time signature, filled with notes of the given tick counts.
|
|
48
|
+
* The notes are notes, not rests, so they can beam.
|
|
49
|
+
*/
|
|
50
|
+
const buildMeasure = (actualBeats: number, beatDuration: number, ticks: number[]): SmoMeasure => {
|
|
51
|
+
const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
|
|
52
|
+
const measure = score.staves[0].measures[0];
|
|
53
|
+
const tsParams = SmoTimeSignature.defaults;
|
|
54
|
+
tsParams.times = [{ actualBeats, beatDuration }];
|
|
55
|
+
measure.timeSignature = new SmoTimeSignature(tsParams);
|
|
56
|
+
const proto = measure.voices[0].notes[0];
|
|
57
|
+
measure.voices[0].notes = ticks.map((tt) => {
|
|
58
|
+
const note = SmoNote.cloneWithDuration(proto, tt);
|
|
59
|
+
note.noteType = 'n';
|
|
60
|
+
return note;
|
|
61
|
+
});
|
|
62
|
+
return measure;
|
|
63
|
+
};
|
|
64
|
+
/** The number of notes in each beam group, in order */
|
|
65
|
+
const beamSizes = (measure: SmoMeasure): string => {
|
|
66
|
+
SmoBeamer.applyBeams(measure);
|
|
67
|
+
return measure.beamGroups.map((bg) => bg.notes.length).join(',');
|
|
68
|
+
};
|
|
69
|
+
/** The boundaries, in units (eighths, or sixteenths for x/16) */
|
|
70
|
+
const boundaries = (measure: SmoMeasure): string => {
|
|
71
|
+
const unit = SmoBeamPreferences.unitTicks(measure.timeSignature);
|
|
72
|
+
return SmoBeamer.groupBoundaries(measure).map((bb) => bb / unit).join(',');
|
|
73
|
+
};
|
|
74
|
+
/** Set a grouping on a new measure and return the beam sizes */
|
|
75
|
+
const grouped = (actualBeats: number, beatDuration: number, ticks: number[], groups: number[]): string => {
|
|
76
|
+
const measure = buildMeasure(actualBeats, beatDuration, ticks);
|
|
77
|
+
measure.setBeamGroups(groups);
|
|
78
|
+
return beamSizes(measure);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// --- SmoBeamPreferences and the measure accessors ---
|
|
82
|
+
{
|
|
83
|
+
const prefs = new SmoBeamPreferences({ groups: [3, 2] });
|
|
84
|
+
const ser = prefs.serialize();
|
|
85
|
+
check('P1 serialize', ser.ctor === 'SmoBeamPreferences' && JSON.stringify(ser.groups) === '[3,2]');
|
|
86
|
+
check('P2 valid values', SmoBeamPreferences.isValidGroups([1, 4]) && SmoBeamPreferences.isValidGroups([]));
|
|
87
|
+
check('P3 invalid values', !SmoBeamPreferences.isValidGroups([0]) && !SmoBeamPreferences.isValidGroups([5])
|
|
88
|
+
&& !SmoBeamPreferences.isValidGroups([1.5]) && !SmoBeamPreferences.isValidGroups([NaN]));
|
|
89
|
+
let threw = false;
|
|
90
|
+
try {
|
|
91
|
+
new SmoBeamPreferences({ groups: [5] });
|
|
92
|
+
} catch (e) {
|
|
93
|
+
threw = true;
|
|
94
|
+
}
|
|
95
|
+
check('P4 the constructor rejects invalid values', threw);
|
|
96
|
+
check('P5 unit ticks', SmoBeamPreferences.unitTicks(new SmoTimeSignature({ ...SmoTimeSignature.defaults,
|
|
97
|
+
times: [{ actualBeats: 6, beatDuration: 16 }] })) === 1024
|
|
98
|
+
&& SmoBeamPreferences.unitTicks(new SmoTimeSignature({ ...SmoTimeSignature.defaults,
|
|
99
|
+
times: [{ actualBeats: 6, beatDuration: 8 }] })) === 2048);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// --- boundaries ---
|
|
103
|
+
check('B1 5/8 [3,2]', boundaries(buildMeasure(5, 8, eighths(5))) === '' &&
|
|
104
|
+
(() => { const m = buildMeasure(5, 8, eighths(5)); m.setBeamGroups([3, 2]); return boundaries(m); })() === '3,5');
|
|
105
|
+
const bnd = (beats: number, den: number, groups: number[]): string => {
|
|
106
|
+
const m = buildMeasure(beats, den, [Q]);
|
|
107
|
+
m.setBeamGroups(groups);
|
|
108
|
+
return boundaries(m);
|
|
109
|
+
};
|
|
110
|
+
check('B2 5/8 [2,3]', bnd(5, 8, [2, 3]) === '2,5', bnd(5, 8, [2, 3]));
|
|
111
|
+
check('B3 12/8 [3]', bnd(12, 8, [3]) === '3,6,9,12', bnd(12, 8, [3]));
|
|
112
|
+
check('B4 8/8 [3,3,2]', bnd(8, 8, [3, 3, 2]) === '3,6,8', bnd(8, 8, [3, 3, 2]));
|
|
113
|
+
check('B5 10/8 [3,2]', bnd(10, 8, [3, 2]) === '3,5,8,10', bnd(10, 8, [3, 2]));
|
|
114
|
+
check('B6 7/8 [3,2]', bnd(7, 8, [3, 2]) === '3,5,7', bnd(7, 8, [3, 2]));
|
|
115
|
+
check('B7 6/16 [3]', bnd(6, 16, [3]) === '3,6', bnd(6, 16, [3]));
|
|
116
|
+
check('B8 4/4 no grouping', SmoBeamer.groupBoundaries(buildMeasure(4, 4, [Q, Q, Q, Q])).length === 0);
|
|
117
|
+
check('B9 3/4 [2,1]', bnd(3, 4, [2, 1]) === '2,3,5,6', bnd(3, 4, [2, 1]));
|
|
118
|
+
|
|
119
|
+
// --- measure accessors ---
|
|
120
|
+
{
|
|
121
|
+
const measure = buildMeasure(5, 8, eighths(5));
|
|
122
|
+
check('A1 no grouping by default', measure.getBeamGroups().length === 0);
|
|
123
|
+
measure.setBeamGroups([3, 2]);
|
|
124
|
+
check('A2 set', JSON.stringify(measure.getBeamGroups()) === '[3,2]');
|
|
125
|
+
measure.setBeamGroups([2, 3]);
|
|
126
|
+
const count = measure.modifiers.filter((mm) => mm.attrs.type === 'SmoBeamPreferences').length;
|
|
127
|
+
check('A3 replaced, not duplicated', count === 1 && JSON.stringify(measure.getBeamGroups()) === '[2,3]');
|
|
128
|
+
const copy = measure.getBeamGroups();
|
|
129
|
+
copy.push(1);
|
|
130
|
+
check('A4 get returns a copy', measure.getBeamGroups().length === 2);
|
|
131
|
+
measure.setBeamGroups([]);
|
|
132
|
+
check('A5 empty removes it', measure.getBeamGroups().length === 0
|
|
133
|
+
&& measure.modifiers.filter((mm) => mm.attrs.type === 'SmoBeamPreferences').length === 0);
|
|
134
|
+
const rejected = [[5], [0], [1.5]].every((bad) => {
|
|
135
|
+
try {
|
|
136
|
+
measure.setBeamGroups(bad);
|
|
137
|
+
return false;
|
|
138
|
+
} catch (e) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
check('A6 invalid values rejected', rejected);
|
|
143
|
+
measure.voices[0].notes[1].beamState = SmoNote.beamStates.end;
|
|
144
|
+
measure.setBeamGroups([3, 2]);
|
|
145
|
+
check('A7 notes reset to automatic', measure.voices[0].notes.every((nn) => nn.beamState === SmoNote.beamStates.auto));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// --- beaming ---
|
|
149
|
+
check('M1 5/8 [3,2]', grouped(5, 8, eighths(5), [3, 2]) === '3,2', grouped(5, 8, eighths(5), [3, 2]));
|
|
150
|
+
check('M2 5/8 [2,3]', grouped(5, 8, eighths(5), [2, 3]) === '2,3', grouped(5, 8, eighths(5), [2, 3]));
|
|
151
|
+
check('M4 12/8 [3]', grouped(12, 8, eighths(12), [3]) === '3,3,3,3', grouped(12, 8, eighths(12), [3]));
|
|
152
|
+
check('M5 8/8 [3,3,2]', grouped(8, 8, eighths(8), [3, 3, 2]) === '3,3,2', grouped(8, 8, eighths(8), [3, 3, 2]));
|
|
153
|
+
check('M6 10/8 [3,2]', grouped(10, 8, eighths(10), [3, 2]) === '3,2,3,2', grouped(10, 8, eighths(10), [3, 2]));
|
|
154
|
+
check('M7 6/16 [3]', grouped(6, 16, new Array(6).fill(S), [3]) === '3,3', grouped(6, 16, new Array(6).fill(S), [3]));
|
|
155
|
+
check('M8 5/8 quarter then three eighths [3,2]', grouped(5, 8, [Q, E, E, E], [3, 2]) === '2',
|
|
156
|
+
grouped(5, 8, [Q, E, E, E], [3, 2]));
|
|
157
|
+
check('M9 4/4 dotted figures [4]', grouped(4, 4, [DE, S, DE, S, Q, Q], [4]) === '4',
|
|
158
|
+
grouped(4, 4, [DE, S, DE, S, Q, Q], [4]));
|
|
159
|
+
{
|
|
160
|
+
// 7/8 with the partial repeat: 3 + 2 + 2
|
|
161
|
+
check('M13 7/8 [3,2] cut-off repeat', grouped(7, 8, eighths(7), [3, 2]) === '3,2,2', grouped(7, 8, eighths(7), [3, 2]));
|
|
162
|
+
// [1] never beams: every note is its own group
|
|
163
|
+
check('M14 5/8 [1] beams nothing', grouped(5, 8, eighths(5), [1]) === '', grouped(5, 8, eighths(5), [1]));
|
|
164
|
+
}
|
|
165
|
+
// A hand `end` state still closes a group, and a hand beam with `continue` is not split at a boundary
|
|
166
|
+
{
|
|
167
|
+
const m = buildMeasure(5, 8, eighths(5));
|
|
168
|
+
m.setBeamGroups([3, 2]);
|
|
169
|
+
m.voices[0].notes[1].beamState = SmoNote.beamStates.end;
|
|
170
|
+
check('M10 hand end state closes a group', beamSizes(m) === '2,2', beamSizes(m));
|
|
171
|
+
const h = buildMeasure(5, 8, eighths(5));
|
|
172
|
+
h.setBeamGroups([3, 2]);
|
|
173
|
+
const notes = h.voices[0].notes;
|
|
174
|
+
notes[0].beamState = SmoNote.beamStates.end;
|
|
175
|
+
notes[2].beamState = SmoNote.beamStates.continue;
|
|
176
|
+
notes[3].beamState = SmoNote.beamStates.end;
|
|
177
|
+
check('M11 hand beam is not split at a boundary', beamSizes(h) === '3', beamSizes(h));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// --- hand beams and tuplets in a grouped measure ---
|
|
181
|
+
{
|
|
182
|
+
/** a score whose first measure is the given meter, filled with notes of the given ticks */
|
|
183
|
+
const scoreWith = (actualBeats: number, beatDuration: number, ticks: number[]): SmoScore => {
|
|
184
|
+
const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
|
|
185
|
+
const measure = score.staves[0].measures[0];
|
|
186
|
+
const tsParams = SmoTimeSignature.defaults;
|
|
187
|
+
tsParams.times = [{ actualBeats, beatDuration }];
|
|
188
|
+
measure.timeSignature = new SmoTimeSignature(tsParams);
|
|
189
|
+
const proto = measure.voices[0].notes[0];
|
|
190
|
+
measure.voices[0].notes = ticks.map((tt) => {
|
|
191
|
+
const note = SmoNote.cloneWithDuration(proto, tt);
|
|
192
|
+
note.noteType = 'n';
|
|
193
|
+
return note;
|
|
194
|
+
});
|
|
195
|
+
return score;
|
|
196
|
+
};
|
|
197
|
+
const handBeam = (score: SmoScore, from: number, to: number) => {
|
|
198
|
+
const selections: SmoSelection[] = [];
|
|
199
|
+
for (let i = from; i <= to; ++i) {
|
|
200
|
+
selections.push(SmoSelection.noteSelection(score, 0, 0, 0, i)!);
|
|
201
|
+
}
|
|
202
|
+
SmoOperation.beamSelections(score, selections);
|
|
203
|
+
return score.staves[0].measures[0].voices[0].notes.map((nn) => nn.beamState).join('');
|
|
204
|
+
};
|
|
205
|
+
const { auto, continue: cont, end } = SmoNote.beamStates;
|
|
206
|
+
const grouped5 = scoreWith(5, 8, eighths(5));
|
|
207
|
+
grouped5.staves[0].measures[0].setBeamGroups([3, 2]);
|
|
208
|
+
check('O6 hand beam in a grouped measure marks every note but the last continue',
|
|
209
|
+
handBeam(grouped5, 1, 3) === [end, cont, cont, end, auto].join(''), handBeam(grouped5, 1, 3));
|
|
210
|
+
check('M11b the hand beam from beamSelections is not split at the boundary',
|
|
211
|
+
beamSizes(grouped5.staves[0].measures[0]) === '3', beamSizes(grouped5.staves[0].measures[0]));
|
|
212
|
+
// Re-beam a 3 + 2 measure as 2 + 3 by hand, the way a user would: select the last three notes
|
|
213
|
+
const regroup = scoreWith(5, 8, eighths(5));
|
|
214
|
+
regroup.staves[0].measures[0].setBeamGroups([3, 2]);
|
|
215
|
+
handBeam(regroup, 2, 4);
|
|
216
|
+
check('M15 the last three notes of a 3 + 2 measure beam as 2 + 3 by hand',
|
|
217
|
+
beamSizes(regroup.staves[0].measures[0]) === '2,3', beamSizes(regroup.staves[0].measures[0]));
|
|
218
|
+
// and the first two, in a measure grouped 2 + 3, beam as 3 + 2
|
|
219
|
+
const regroup2 = scoreWith(5, 8, eighths(5));
|
|
220
|
+
regroup2.staves[0].measures[0].setBeamGroups([2, 3]);
|
|
221
|
+
handBeam(regroup2, 0, 2);
|
|
222
|
+
check('M16 the first three notes of a 2 + 3 measure beam as 3 + 2 by hand',
|
|
223
|
+
beamSizes(regroup2.staves[0].measures[0]) === '3,2', beamSizes(regroup2.staves[0].measures[0]));
|
|
224
|
+
const plain5 = scoreWith(5, 8, eighths(5));
|
|
225
|
+
check('O7 hand beam in an ungrouped measure is as before (no continue)',
|
|
226
|
+
handBeam(plain5, 1, 3) === [end, auto, auto, end, auto].join(''), handBeam(plain5, 1, 3));
|
|
227
|
+
// A tuplet is beamed by the tuplet code, whatever the measure grouping is
|
|
228
|
+
const tupletSizes = (groups: number[]): string => {
|
|
229
|
+
const score = scoreWith(4, 4, [Q, Q, Q, Q]);
|
|
230
|
+
SmoOperation.makeTuplet(SmoSelection.noteSelection(score, 0, 0, 0, 0)!,
|
|
231
|
+
{ numNotes: 3, notesOccupied: 2, bracketed: true, ratioed: false });
|
|
232
|
+
const measure = score.staves[0].measures[0];
|
|
233
|
+
measure.voices[0].notes.forEach((nn) => { nn.noteType = 'n'; });
|
|
234
|
+
measure.setBeamGroups(groups);
|
|
235
|
+
return beamSizes(measure);
|
|
236
|
+
};
|
|
237
|
+
check('M12 a tuplet beams the same with or without a grouping', tupletSizes([]).length > 0 && tupletSizes([]) === tupletSizes([4]) && tupletSizes([]) === tupletSizes([1]),
|
|
238
|
+
`${tupletSizes([])} ${tupletSizes([4])} ${tupletSizes([1])}`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// --- measures with no grouping beam as they did before this feature (M3) ---
|
|
242
|
+
{
|
|
243
|
+
const same = (beats: number, den: number, ticks: number[], expected: string) => {
|
|
244
|
+
const measure = buildMeasure(beats, den, ticks);
|
|
245
|
+
if (beats === 6 && den === 8) {
|
|
246
|
+
// notes in a real 6/8 measure get a dotted quarter beam length (see SmoMeasure.timeSignatureNotes)
|
|
247
|
+
measure.voices[0].notes.forEach((nn) => { nn.beamBeats = 6144; });
|
|
248
|
+
}
|
|
249
|
+
const before = beamSizes(measure);
|
|
250
|
+
measure.setBeamGroups([3, 2]);
|
|
251
|
+
measure.setBeamGroups([]);
|
|
252
|
+
check(`M3 ${beats}/${den} ungrouped is unchanged by a set and clear`, beamSizes(measure) === before && before === expected,
|
|
253
|
+
`${before} vs ${expected}`);
|
|
254
|
+
};
|
|
255
|
+
same(4, 4, eighths(8), '4,4');
|
|
256
|
+
same(4, 4, new Array(8).fill(S), '4,4');
|
|
257
|
+
same(3, 4, eighths(6), '2,2,2');
|
|
258
|
+
same(6, 8, eighths(6), '3,3');
|
|
259
|
+
same(4, 4, [DE, S, DE, S, Q, Q], '4');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// --- a score with two staves and four measures ---
|
|
263
|
+
const buildScore = (): SmoScore => {
|
|
264
|
+
const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
|
|
265
|
+
while (score.staves[0].measures.length < 4) {
|
|
266
|
+
score.addMeasure(score.staves[0].measures.length - 1);
|
|
267
|
+
}
|
|
268
|
+
const params = SmoSystemStaff.defaults;
|
|
269
|
+
params.staffId = 1;
|
|
270
|
+
params.measureInstrumentMap[0] = new SmoInstrument(SmoInstrument.defaults);
|
|
271
|
+
score.addStaff(params);
|
|
272
|
+
return score;
|
|
273
|
+
};
|
|
274
|
+
const groupsOf = (score: SmoScore, staff: number): string =>
|
|
275
|
+
score.staves[staff].measures.map((mm) => `[${mm.getBeamGroups().join(',')}]`).join('');
|
|
276
|
+
|
|
277
|
+
// --- operations ---
|
|
278
|
+
{
|
|
279
|
+
const score = buildScore();
|
|
280
|
+
const selections = [SmoSelection.measureSelection(score, 1, 1)!, SmoSelection.measureSelection(score, 1, 2)!];
|
|
281
|
+
SmoOperation.setBeamGroups(score, selections, [3, 2]);
|
|
282
|
+
check('O1 only the selected measures in the selected staff change',
|
|
283
|
+
groupsOf(score, 1) === '[][3,2][3,2][]' && groupsOf(score, 0) === '[][][][]',
|
|
284
|
+
`${groupsOf(score, 1)} ${groupsOf(score, 0)}`);
|
|
285
|
+
SmoOperation.setBeamGroups(score, [selections[0]], []);
|
|
286
|
+
check('O2 an empty list clears the selected measures', groupsOf(score, 1) === '[][][3,2][]', groupsOf(score, 1));
|
|
287
|
+
SmoOperation.setAllBeamGroups(score, [3]);
|
|
288
|
+
check('O3 set every measure of every staff', groupsOf(score, 0) === '[3][3][3][3]' && groupsOf(score, 1) === '[3][3][3][3]');
|
|
289
|
+
SmoOperation.setAllBeamGroups(score, []);
|
|
290
|
+
check('O4 clear every measure of every staff', groupsOf(score, 0) === '[][][][]' && groupsOf(score, 1) === '[][][][]');
|
|
291
|
+
const text = JSON.stringify(score.serialize());
|
|
292
|
+
check('O5 a cleared score has no beam preferences in its serialization', text.indexOf('SmoBeamPreferences') < 0
|
|
293
|
+
&& text.indexOf('beamPreferences') < 0);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// --- serialization ---
|
|
297
|
+
{
|
|
298
|
+
const score = buildScore();
|
|
299
|
+
score.staves[0].measures[1].setBeamGroups([3, 2]);
|
|
300
|
+
score.staves[0].measures[3].setBeamGroups([2]);
|
|
301
|
+
score.staves[1].measures[1].setBeamGroups([1, 4]);
|
|
302
|
+
const back = SmoScore.deserialize(JSON.stringify(score.serialize()));
|
|
303
|
+
check('S1 groupings survive a save and load; others stay empty', groupsOf(back, 0) === '[][3,2][][2]' && groupsOf(back, 1) === '[][1,4][][]',
|
|
304
|
+
`${groupsOf(back, 0)} ${groupsOf(back, 1)}`);
|
|
305
|
+
const full = SmoScore.deserialize(JSON.stringify(score.serialize({ skipStaves: false, useDictionary: false, preserveStaffIds: false })));
|
|
306
|
+
check('S1b the full (unabbreviated) form keeps them too', groupsOf(full, 0) === '[][3,2][][2]');
|
|
307
|
+
// A score written by a version without the feature: no beam preferences anywhere
|
|
308
|
+
const legacy = buildScore();
|
|
309
|
+
const legacyBack = SmoScore.deserialize(JSON.stringify(legacy.serialize()));
|
|
310
|
+
check('S2 a score with no grouping loads with every measure ungrouped', groupsOf(legacyBack, 0) === '[][][][]' && groupsOf(legacyBack, 1) === '[][][][]');
|
|
311
|
+
const measure = score.staves[0].measures[1];
|
|
312
|
+
const copy = SmoMeasure.deserialize(JSON.parse(JSON.stringify(measure.serialize())));
|
|
313
|
+
check('S4 a copied measure keeps its grouping', JSON.stringify(copy.getBeamGroups()) === '[3,2]');
|
|
314
|
+
// The score-wide default still applies to ungrouped measures and does not touch grouped ones
|
|
315
|
+
score.preferences.defaultDupleDuration = 2048;
|
|
316
|
+
SmoOperation.clearAllBeamGroups(score);
|
|
317
|
+
check('S5 the score default does not change a grouped measure', JSON.stringify(score.staves[0].measures[1].getBeamGroups()) === '[3,2]');
|
|
318
|
+
check('S5b the score default applies to an ungrouped measure',
|
|
319
|
+
score.staves[0].measures[0].voices[0].notes.every((nn) => nn.beamBeats === 2048));
|
|
320
|
+
}
|
|
321
|
+
const smzCheck = async () => {
|
|
322
|
+
const score = buildScore();
|
|
323
|
+
score.staves[0].measures[1].setBeamGroups([3, 2]);
|
|
324
|
+
score.staves[1].measures[2].setBeamGroups([3]);
|
|
325
|
+
const packed = await SmoScoreArchive.pack(score);
|
|
326
|
+
const back = await SmoScoreArchive.load(packed);
|
|
327
|
+
check('S3 groupings survive the .smz round trip', groupsOf(back, 0) === '[][3,2][][]' && groupsOf(back, 1) === '[][][3][]',
|
|
328
|
+
`${groupsOf(back, 0)} ${groupsOf(back, 1)}`);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
smzCheck().then(() => {
|
|
332
|
+
if (failures > 0) {
|
|
333
|
+
console.log(`${failures} check(s) failed`);
|
|
334
|
+
process.exitCode = 1;
|
|
335
|
+
} else {
|
|
336
|
+
console.log('all checks passed');
|
|
337
|
+
}
|
|
338
|
+
});
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless checks for creating parts: where a new part goes, not splitting a two-stave part, the
|
|
3
|
+
* name and settings it gets, and keeping the references to staves right when a staff is inserted
|
|
4
|
+
* above others. Cases are listed in specs/037-fix-new-part-dialog/contracts/create-part-api.md.
|
|
5
|
+
*
|
|
6
|
+
* Run with: npm run test:create-part
|
|
7
|
+
*/
|
|
8
|
+
import { SmoScore } from '../src/smo/data/score';
|
|
9
|
+
import { SmoSystemStaff } from '../src/smo/data/systemStaff';
|
|
10
|
+
import { SmoSlur, SmoInstrument } from '../src/smo/data/staffModifiers';
|
|
11
|
+
import { SmoSystemGroup, scoreModifierDynamicCtorInit } from '../src/smo/data/scoreModifiers';
|
|
12
|
+
import { noteModifierDynamicCtorInit } from '../src/smo/data/noteModifiers';
|
|
13
|
+
import { measureModifierDynamicCtorInit } from '../src/smo/data/measureModifiers';
|
|
14
|
+
import { staffModifierDynamicCtorInit } from '../src/smo/data/staffModifiers';
|
|
15
|
+
import { SmoSelector } from '../src/smo/xform/selections';
|
|
16
|
+
import { SmoOperation, AddPartParams } from '../src/smo/xform/operations';
|
|
17
|
+
import { SmoPartInfo } from '../src/smo/data/partInfo';
|
|
18
|
+
import { clampPartLocation, resolvePartName, instrumentChoices, instrumentLabelFor } from '../src/ui/dialogs/createPartHelpers';
|
|
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
|
+
/** Parameters for a new staff at `index`, with the default instrument */
|
|
38
|
+
const staffParams = (index: number) => {
|
|
39
|
+
const params = SmoSystemStaff.defaults;
|
|
40
|
+
params.staffId = index;
|
|
41
|
+
params.measureInstrumentMap[0] = new SmoInstrument(SmoInstrument.defaults);
|
|
42
|
+
return params;
|
|
43
|
+
};
|
|
44
|
+
/** A score with one staff for each name, each with the same four measures */
|
|
45
|
+
const buildScore = (names: string[]): SmoScore => {
|
|
46
|
+
const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
|
|
47
|
+
for (let ii = 1; ii < names.length; ++ii) {
|
|
48
|
+
score.addStaff(staffParams(ii));
|
|
49
|
+
}
|
|
50
|
+
names.forEach((name, ix) => {
|
|
51
|
+
score.staves[ix].partInfo.partName = name;
|
|
52
|
+
});
|
|
53
|
+
return score;
|
|
54
|
+
};
|
|
55
|
+
/** The part names, in staff order */
|
|
56
|
+
const order = (score: SmoScore): string => {
|
|
57
|
+
return score.staves.map((staff) => staff.partInfo.partName).join(',');
|
|
58
|
+
};
|
|
59
|
+
/** Insert a staff named `name` at staff index `index` */
|
|
60
|
+
const insert = (score: SmoScore, index: number, name: string) => {
|
|
61
|
+
const staff = score.addStaff(staffParams(index));
|
|
62
|
+
staff.partInfo.partName = name;
|
|
63
|
+
return staff;
|
|
64
|
+
};
|
|
65
|
+
const selector = (staff: number): SmoSelector => {
|
|
66
|
+
const rv = SmoSelector.default;
|
|
67
|
+
rv.staff = staff;
|
|
68
|
+
return rv;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// --- R1-R5, S2: references are kept right when a staff is inserted above others ---
|
|
72
|
+
{
|
|
73
|
+
const score = buildScore(['A', 'B', 'C']);
|
|
74
|
+
const slur = new SmoSlur(SmoSlur.defaults);
|
|
75
|
+
slur.startSelector = selector(2);
|
|
76
|
+
slur.endSelector = selector(2);
|
|
77
|
+
slur.endSelector.measure = 1;
|
|
78
|
+
slur.associatedStaff = 2;
|
|
79
|
+
score.staves[2].addStaffModifier(slur);
|
|
80
|
+
insert(score, 0, 'N');
|
|
81
|
+
check('R1 insert first: staves are in order', order(score) === 'N,A,B,C', order(score));
|
|
82
|
+
const moved = score.staves[3].modifiers[0];
|
|
83
|
+
check('R1 the slur is still on its staff', moved === slur);
|
|
84
|
+
check('R1 its selectors follow the staff', slur.startSelector.staff === 3 && slur.endSelector.staff === 3);
|
|
85
|
+
check('R1 its associated staff follows', slur.associatedStaff === 3);
|
|
86
|
+
check('R1 its measure is untouched', slur.endSelector.measure === 1);
|
|
87
|
+
}
|
|
88
|
+
{
|
|
89
|
+
const score = buildScore(['A', 'B', 'C']);
|
|
90
|
+
const group = new SmoSystemGroup(SmoSystemGroup.defaults);
|
|
91
|
+
group.startSelector.staff = 1;
|
|
92
|
+
group.endSelector.staff = 2;
|
|
93
|
+
score.systemGroups.push(group);
|
|
94
|
+
insert(score, 0, 'N');
|
|
95
|
+
check('R2 a group below the insertion moves down', group.startSelector.staff === 2 && group.endSelector.staff === 3);
|
|
96
|
+
}
|
|
97
|
+
{
|
|
98
|
+
const score = buildScore(['A', 'B', 'C']);
|
|
99
|
+
const group = new SmoSystemGroup(SmoSystemGroup.defaults);
|
|
100
|
+
group.startSelector.staff = 0;
|
|
101
|
+
group.endSelector.staff = 2;
|
|
102
|
+
score.systemGroups.push(group);
|
|
103
|
+
insert(score, 1, 'N');
|
|
104
|
+
check('R3 a group spanning the insertion grows', group.startSelector.staff === 0 && group.endSelector.staff === 3);
|
|
105
|
+
}
|
|
106
|
+
{
|
|
107
|
+
const score = buildScore(['A', 'B', 'C']);
|
|
108
|
+
const group = new SmoSystemGroup(SmoSystemGroup.defaults);
|
|
109
|
+
group.startSelector.staff = 0;
|
|
110
|
+
group.endSelector.staff = 1;
|
|
111
|
+
score.systemGroups.push(group);
|
|
112
|
+
const slur = new SmoSlur(SmoSlur.defaults);
|
|
113
|
+
slur.startSelector = selector(2);
|
|
114
|
+
slur.endSelector = selector(2);
|
|
115
|
+
slur.associatedStaff = 2;
|
|
116
|
+
score.staves[2].addStaffModifier(slur);
|
|
117
|
+
insert(score, 3, 'N');
|
|
118
|
+
check('R4 an append leaves groups alone', group.startSelector.staff === 0 && group.endSelector.staff === 1);
|
|
119
|
+
check('R4 an append leaves modifiers alone', slur.startSelector.staff === 2 && slur.associatedStaff === 2);
|
|
120
|
+
check('R4 an append puts the staff last', order(score) === 'A,B,C,N', order(score));
|
|
121
|
+
}
|
|
122
|
+
{
|
|
123
|
+
const score = buildScore(['A', 'B', 'C']);
|
|
124
|
+
insert(score, 1, 'N');
|
|
125
|
+
const instrumentStaves = score.staves.map((staff) => {
|
|
126
|
+
const keys = Object.keys(staff.measureInstrumentMap);
|
|
127
|
+
return keys.every((key) => staff.measureInstrumentMap[parseInt(key, 10)].startSelector.staff === staff.staffId
|
|
128
|
+
&& staff.measureInstrumentMap[parseInt(key, 10)].endSelector.staff === staff.staffId);
|
|
129
|
+
});
|
|
130
|
+
check('R5 every instrument selector names its own staff', instrumentStaves.every((ok) => ok), JSON.stringify(instrumentStaves));
|
|
131
|
+
check('S2 staves are numbered in order', score.staves.every((staff, ix) => staff.staffId === ix));
|
|
132
|
+
check('S2 and so are their measures', score.staves.every((staff, ix) =>
|
|
133
|
+
staff.measures.every((measure) => measure.measureNumber.staffId === ix)));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Create a part with the given overrides */
|
|
137
|
+
const addPart = (score: SmoScore, location: number, overrides: Partial<AddPartParams> = {}): number => {
|
|
138
|
+
const params: AddPartParams = {
|
|
139
|
+
location,
|
|
140
|
+
instrument: new SmoInstrument(SmoInstrument.defaults),
|
|
141
|
+
twoStaves: false,
|
|
142
|
+
name: '',
|
|
143
|
+
instrumentLabel: 'Piano',
|
|
144
|
+
abbreviation: '',
|
|
145
|
+
...overrides
|
|
146
|
+
};
|
|
147
|
+
return SmoOperation.addPart(score, params);
|
|
148
|
+
};
|
|
149
|
+
/** A score with the staves A, then a two-stave part P (P1, P2), then C */
|
|
150
|
+
const buildScoreWithPart = (): SmoScore => {
|
|
151
|
+
const score = buildScore(['A', 'C']);
|
|
152
|
+
addPart(score, 2, { twoStaves: true, name: 'P' });
|
|
153
|
+
score.staves[1].partInfo.partName = 'P1';
|
|
154
|
+
score.staves[2].partInfo.partName = 'P2';
|
|
155
|
+
return score;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// --- P1: placement on plain staves ---
|
|
159
|
+
{
|
|
160
|
+
const score = buildScore(['A', 'B', 'C']);
|
|
161
|
+
const results = [1, 2, 3, 4, 9, 0, -3, 2.6, NaN].map((loc) => score.resolveNewPartIndex(loc));
|
|
162
|
+
check('P1 locations resolve to indexes', results.join(',') === '0,1,2,3,3,0,0,2,3', results.join(','));
|
|
163
|
+
}
|
|
164
|
+
// --- A1: addPart at every position ---
|
|
165
|
+
{
|
|
166
|
+
const expected = ['N,A,B,C', 'A,N,B,C', 'A,B,N,C', 'A,B,C,N'];
|
|
167
|
+
for (let loc = 1; loc <= 4; ++loc) {
|
|
168
|
+
const score = buildScore(['A', 'B', 'C']);
|
|
169
|
+
const index = addPart(score, loc, { name: 'N' });
|
|
170
|
+
check(`A1 location ${loc} puts the part at index ${loc - 1}`, index === loc - 1 && order(score) === expected[loc - 1], order(score));
|
|
171
|
+
check(`A1 location ${loc} numbers the staves`, score.staves.every((staff, ix) => staff.staffId === ix));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// --- P2-P5: not splitting a two-stave part ---
|
|
175
|
+
{
|
|
176
|
+
const score = buildScoreWithPart();
|
|
177
|
+
check('P2 the setup has A,P1,P2,C', order(score) === 'A,P1,P2,C', order(score));
|
|
178
|
+
check('P2 inside the part resolves to after it', score.resolveNewPartIndex(3) === 3);
|
|
179
|
+
check('P3 at the first staff of the part is before it', score.resolveNewPartIndex(2) === 1);
|
|
180
|
+
check('P3 after the last staff', score.resolveNewPartIndex(5) === 4);
|
|
181
|
+
check('P3 first', score.resolveNewPartIndex(1) === 0);
|
|
182
|
+
check('P3 just after the part is unchanged', score.resolveNewPartIndex(4) === 3);
|
|
183
|
+
}
|
|
184
|
+
{
|
|
185
|
+
const score = buildScore(['A']);
|
|
186
|
+
addPart(score, 2, { twoStaves: true, name: 'P' });
|
|
187
|
+
check('P4 a two-stave part at the end: inside resolves to the end', score.resolveNewPartIndex(3) === 3);
|
|
188
|
+
check('P4 and so does the end', score.resolveNewPartIndex(4) === 3);
|
|
189
|
+
}
|
|
190
|
+
{
|
|
191
|
+
const score = buildScore(['A']);
|
|
192
|
+
addPart(score, 2, { twoStaves: true, name: 'P' });
|
|
193
|
+
addPart(score, 4, { twoStaves: true, name: 'Q' });
|
|
194
|
+
check('P5 two parts: the staves are A,P,P,Q,Q', order(score) === 'A,P,P,Q,Q', order(score));
|
|
195
|
+
check('P5 inside the first part goes after it', score.resolveNewPartIndex(3) === 3);
|
|
196
|
+
check('P5 inside the second part goes after it', score.resolveNewPartIndex(5) === 5);
|
|
197
|
+
}
|
|
198
|
+
// --- A6, A7: a two-stave part ---
|
|
199
|
+
{
|
|
200
|
+
const score = buildScore(['A', 'B']);
|
|
201
|
+
const index = addPart(score, 2, { twoStaves: true, name: 'Pn', abbreviation: 'Pn.' });
|
|
202
|
+
const first = score.staves[index].partInfo;
|
|
203
|
+
const second = score.staves[index + 1].partInfo;
|
|
204
|
+
check('A6 two adjacent staves are added', order(score) === 'A,Pn,Pn,B', order(score));
|
|
205
|
+
check('A6 the first staff has a stave after it', first.stavesAfter === 1 && first.stavesBefore === 0);
|
|
206
|
+
check('A6 the second staff has a stave before it', second.stavesAfter === 0 && second.stavesBefore === 1);
|
|
207
|
+
check('A6 both have the abbreviation', first.partAbbreviation === 'Pn.' && second.partAbbreviation === 'Pn.');
|
|
208
|
+
check('A6 the second staff has the opposite clef',
|
|
209
|
+
score.staves[index].measures[0].clef === 'treble' && score.staves[index + 1].measures[0].clef === 'bass');
|
|
210
|
+
check('A6 the part infos are not shared', first !== second);
|
|
211
|
+
const i1 = score.staves[index].measureInstrumentMap[0];
|
|
212
|
+
const i2 = score.staves[index + 1].measureInstrumentMap[0];
|
|
213
|
+
check('A6 each instrument names its own staff', i1.startSelector.staff === index && i2.startSelector.staff === index + 1,
|
|
214
|
+
`${i1.startSelector.staff} ${i2.startSelector.staff}`);
|
|
215
|
+
}
|
|
216
|
+
{
|
|
217
|
+
const score = buildScoreWithPart();
|
|
218
|
+
const index = addPart(score, 3, { twoStaves: true, name: 'Q' });
|
|
219
|
+
check('A7 a two-stave part inside a two-stave part goes after it', order(score) === 'A,P1,P2,Q,Q,C' && index === 3, order(score));
|
|
220
|
+
check('A7 the existing part is intact', score.staves[1].partInfo.stavesAfter === 1 && score.staves[2].partInfo.stavesBefore === 1);
|
|
221
|
+
}
|
|
222
|
+
// --- A2, A3: names ---
|
|
223
|
+
{
|
|
224
|
+
const score = buildScore(['A']);
|
|
225
|
+
addPart(score, 2, { name: '', instrumentLabel: 'Cello' });
|
|
226
|
+
addPart(score, 3, { name: ' ', instrumentLabel: 'Flute' });
|
|
227
|
+
addPart(score, 4, { name: ' Cello I ', abbreviation: ' Vc. I ', instrumentLabel: 'Cello' });
|
|
228
|
+
check('A2 a blank name becomes the instrument name', score.staves[1].partInfo.partName === 'Cello');
|
|
229
|
+
check('A2 a name of spaces becomes the instrument name', score.staves[2].partInfo.partName === 'Flute');
|
|
230
|
+
check('A3 a typed name and abbreviation are kept, trimmed',
|
|
231
|
+
score.staves[3].partInfo.partName === 'Cello I' && score.staves[3].partInfo.partAbbreviation === 'Vc. I');
|
|
232
|
+
check('A3 no abbreviation is empty', score.staves[1].partInfo.partAbbreviation === '');
|
|
233
|
+
}
|
|
234
|
+
// --- A4, A5: the text group setting ---
|
|
235
|
+
{
|
|
236
|
+
const score = buildScore(['A']);
|
|
237
|
+
const one = addPart(score, 2, { name: 'One' });
|
|
238
|
+
const two = addPart(score, 3, { twoStaves: true, name: 'Two' });
|
|
239
|
+
check('A4 a part from addPart keeps its text groups', score.staves[one].partInfo.preserveTextGroups === true);
|
|
240
|
+
check('A4 so do both staves of a two-stave part',
|
|
241
|
+
score.staves[two].partInfo.preserveTextGroups === true && score.staves[two + 1].partInfo.preserveTextGroups === true);
|
|
242
|
+
check('A4 the default is unchanged', SmoPartInfo.defaults.preserveTextGroups === false);
|
|
243
|
+
check('A5 a staff added another way has the default', score.staves[0].partInfo.preserveTextGroups === false);
|
|
244
|
+
const other = score.addStaff(staffParams(score.staves.length));
|
|
245
|
+
check('A5 so does one added with addStaff', other.partInfo.preserveTextGroups === false);
|
|
246
|
+
}
|
|
247
|
+
// --- groups for the new staves ---
|
|
248
|
+
{
|
|
249
|
+
const score = buildScore(['A', 'B']);
|
|
250
|
+
addPart(score, 3, { twoStaves: true, name: 'P' });
|
|
251
|
+
const grp = score.getSystemGroupForStaffId(2);
|
|
252
|
+
check('G1 a new two-stave part is grouped with the staff above', !!grp && grp.startSelector.staff <= 1 && grp.endSelector.staff === 3);
|
|
253
|
+
const first = buildScore(['A', 'B']);
|
|
254
|
+
addPart(first, 1, { name: 'N' });
|
|
255
|
+
check('G2 a part at the top leaves every group inside the score',
|
|
256
|
+
first.systemGroups.every((g) => g.startSelector.staff >= 0 && g.endSelector.staff < first.staves.length));
|
|
257
|
+
}
|
|
258
|
+
// --- C1-C3: the dialog helpers ---
|
|
259
|
+
{
|
|
260
|
+
const clamped = [0, 1, 4, 5, 2.6, NaN, '3', undefined].map((value) => clampPartLocation(value, 3));
|
|
261
|
+
check('C1 locations are held to 1..N+1', clamped.join(',') === '1,1,4,4,3,4,4,4', clamped.join(','));
|
|
262
|
+
check('C2 a blank name is the instrument name', resolvePartName('', 'Cello') === 'Cello' && resolvePartName(' ', 'Cello') === 'Cello');
|
|
263
|
+
check('C2 a typed name is trimmed', resolvePartName('Cello I', 'Cello') === 'Cello I' && resolvePartName(' Vc ', 'Cello') === 'Vc');
|
|
264
|
+
check('C2 an undefined name is the instrument name', resolvePartName(undefined as any, 'Cello') === 'Cello');
|
|
265
|
+
const values = instrumentChoices.map((choice) => choice.value);
|
|
266
|
+
check('C3 no instrument is listed twice', new Set(values).size === values.length);
|
|
267
|
+
check('C3 an instrument has its label', instrumentLabelFor('cello') === 'Cello' && instrumentLabelFor('trumpet') === 'Bb Trumpet');
|
|
268
|
+
check('C3 an unknown instrument is its own label', instrumentLabelFor('theremin') === 'theremin');
|
|
269
|
+
check('C3 every instrument has a label', instrumentChoices.every((choice) => choice.label.length > 0));
|
|
270
|
+
}
|
|
271
|
+
// --- S1: serialization ---
|
|
272
|
+
{
|
|
273
|
+
const score = buildScore(['A']);
|
|
274
|
+
addPart(score, 1, { name: 'One', abbreviation: '1.' });
|
|
275
|
+
addPart(score, 3, { twoStaves: true, name: 'Two', abbreviation: '2.' });
|
|
276
|
+
const json = JSON.stringify(score.serialize({ skipStaves: false, useDictionary: false, preserveStaffIds: true }));
|
|
277
|
+
const back = SmoScore.deserialize(json);
|
|
278
|
+
const infos = back.staves.map((staff) => staff.partInfo);
|
|
279
|
+
check('S1 names survive', back.staves.length === 4 && infos[0].partName === 'One' && infos[2].partName === 'Two' && infos[3].partName === 'Two',
|
|
280
|
+
infos.map((i) => i.partName).join(','));
|
|
281
|
+
check('S1 abbreviations survive', infos[0].partAbbreviation === '1.' && infos[3].partAbbreviation === '2.');
|
|
282
|
+
check('S1 the setting survives', infos[0].preserveTextGroups && infos[2].preserveTextGroups && infos[3].preserveTextGroups);
|
|
283
|
+
check('S1 the links survive', infos[2].stavesAfter === 1 && infos[3].stavesBefore === 1 && infos[3].stavesAfter === 0);
|
|
284
|
+
check('S1 staves are numbered', back.staves.every((staff, ix) => staff.staffId === ix));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (failures > 0) {
|
|
288
|
+
console.log(`${failures} check(s) failed`);
|
|
289
|
+
process.exitCode = 1;
|
|
290
|
+
} else {
|
|
291
|
+
console.log('all checks passed');
|
|
292
|
+
}
|