smoosic 2.0.3 → 2.0.5
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 +408 -69
- package/changes.md +95 -0
- package/package.json +19 -1
- package/release/smoosic.js +408 -69
- 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/specs/042-preserve-music-time-signature/checklists/requirements.md +35 -0
- package/specs/042-preserve-music-time-signature/contracts/rebar-api.md +66 -0
- package/specs/042-preserve-music-time-signature/data-model.md +73 -0
- package/specs/042-preserve-music-time-signature/plan.md +93 -0
- package/specs/042-preserve-music-time-signature/quickstart.md +37 -0
- package/specs/042-preserve-music-time-signature/research.md +102 -0
- package/specs/042-preserve-music-time-signature/spec.md +153 -0
- package/specs/042-preserve-music-time-signature/tasks.md +104 -0
- package/src/application/application.ts +13 -2
- package/src/application/exports.ts +402 -395
- package/src/application/generateVexTests.ts +2 -2
- package/src/render/sui/NoteEntryCaret.ts +117 -16
- package/src/render/sui/autosave.ts +265 -0
- package/src/render/sui/formatter.ts +12 -2
- package/src/render/sui/renderState.ts +4 -4
- package/src/render/sui/scoreChangeState.ts +8 -3
- package/src/render/sui/scoreView.ts +47 -2
- package/src/render/sui/scoreViewOperations.ts +2761 -2555
- package/src/render/sui/staffLineGeometry.ts +82 -0
- package/src/render/sui/tracker.ts +18 -23
- package/src/render/vex/vxMeasure.ts +22 -8
- package/src/render/vex/vxNote.ts +2 -4
- package/src/smo/data/measure.ts +58 -1
- package/src/smo/data/measureModifiers.ts +81 -1
- package/src/smo/data/music.ts +169 -359
- package/src/smo/data/note.ts +1 -1
- package/src/smo/data/noteModifiers.ts +12 -0
- package/src/smo/data/score.ts +179 -7
- package/src/smo/data/scoreModifiers.ts +46 -1
- package/src/smo/data/systemStaff.ts +43 -0
- package/src/smo/xform/beamers.ts +80 -6
- package/src/smo/xform/copypaste.ts +207 -47
- package/src/smo/xform/measureFill.ts +89 -0
- package/src/smo/xform/operations.ts +452 -61
- package/src/smo/xform/rebar.ts +490 -0
- package/src/smo/xform/selections.ts +73 -0
- package/src/ui/components/dialogs/beamGroups.vue +106 -0
- package/src/ui/components/dialogs/deleteSpecial.vue +38 -0
- package/src/ui/components/dialogs/dynamics.vue +16 -3
- package/src/ui/components/dialogs/fileUpload.vue +2 -2
- package/src/ui/components/dialogs/hairpin.vue +3 -3
- package/src/ui/components/dialogs/newPart.vue +148 -184
- package/src/ui/components/dialogs/pasteSpecial.vue +49 -0
- package/src/ui/components/dialogs/recovery.vue +66 -0
- package/src/ui/components/dialogs/save.vue +11 -4
- package/src/ui/components/dialogs/scorePreferences.vue +23 -1
- package/src/ui/components/dialogs/slur.vue +6 -6
- package/src/ui/components/dialogs/tempo.vue +11 -3
- package/src/ui/components/dialogs/timeSignature.vue +18 -3
- package/src/ui/components/dialogs/volta.vue +3 -3
- package/src/ui/dialogs/annotationVue.ts +1 -1
- package/src/ui/dialogs/beamGroupsVue.ts +69 -0
- package/src/ui/dialogs/createPartHelpers.ts +68 -0
- package/src/ui/dialogs/deleteSpecial.ts +57 -0
- package/src/ui/dialogs/dynamicsVue.ts +87 -60
- package/src/ui/dialogs/factory.ts +0 -2
- package/src/ui/dialogs/fileDialogs.ts +63 -22
- package/src/ui/dialogs/instrument.ts +37 -30
- package/src/ui/dialogs/pasteSpecial.ts +59 -0
- package/src/ui/dialogs/preferences.ts +41 -40
- package/src/ui/dialogs/recovery.ts +49 -0
- package/src/ui/dialogs/timeSignature.ts +27 -39
- package/src/ui/fileio/fileInput.ts +12 -3
- package/src/ui/fileio/scoreArchive.ts +151 -0
- package/src/ui/fileio/xhrLoader.ts +26 -0
- package/src/ui/i18n/language.ts +1 -1
- package/src/ui/menus/beams.ts +181 -112
- package/src/ui/menus/edit.ts +44 -6
- package/src/ui/menus/file.ts +21 -1
- package/src/ui/menus/measure.ts +40 -1
- package/tests/autosave.ts +332 -0
- package/tests/beamDotted.ts +56 -0
- package/tests/beamGroups.ts +338 -0
- package/tests/createPart.ts +292 -0
- package/tests/deleteSpecial.ts +350 -0
- package/tests/dynamicsFontSize.ts +132 -0
- package/tests/keyDistanceTransposition.ts +351 -0
- package/tests/measureFill.ts +295 -0
- package/tests/movePart.ts +94 -0
- package/tests/multimeasureRest.ts +338 -0
- package/tests/pasteIntoMeasure.ts +103 -0
- package/tests/pasteSpecial.ts +541 -0
- package/tests/quickBeam.ts +126 -0
- package/tests/rebarMeasures.ts +492 -0
- package/tests/scoreArchive.ts +218 -0
- package/tests/scoreChangeState.ts +2 -0
- package/tests/staffLineGeometry.ts +179 -0
- package/tests/timeRangeSelect.ts +111 -0
- package/tests/timeSignatureDisplay.ts +58 -0
- package/tools/smoosic-schema.json +37 -0
- package/typedoc.ts +2 -1
- package/types/src/application/exports.d.ts +454 -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 +776 -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 +479 -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 +269 -129
- package/types/src/smo/xform/rebar.d.ts +53 -0
- package/types/src/smo/xform/selections.d.ts +168 -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 +148 -147
- package/src/ui/dialogs/dynamics.ts +0 -141
- package/types/src/ui/dialogs/dynamics.d.ts +0 -37
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless checks for re-barring music into a new time signature (Preserve music): the transform
|
|
3
|
+
* (SmoOperation.rebarMeasures / rebarMeasures), the helpers the view uses to decide what to do
|
|
4
|
+
* (timeSignatureChanges, timeSignatureKeepsLength, timeSignatureRange) and the old keep-what-fits
|
|
5
|
+
* behavior. Cases are listed in specs/042-preserve-music-time-signature/contracts/rebar-api.md.
|
|
6
|
+
*
|
|
7
|
+
* Run with: npm run test:rebar-measures
|
|
8
|
+
*/
|
|
9
|
+
import { SmoScore } from '../src/smo/data/score';
|
|
10
|
+
import { SmoMeasure } from '../src/smo/data/measure';
|
|
11
|
+
import { SmoNote } from '../src/smo/data/note';
|
|
12
|
+
import { SmoSystemStaff } from '../src/smo/data/systemStaff';
|
|
13
|
+
import { SmoTimeSignature, SmoBarline } from '../src/smo/data/measureModifiers';
|
|
14
|
+
import { SmoSlur, SmoTie, SmoStaffHairpin, SmoInstrument } from '../src/smo/data/staffModifiers';
|
|
15
|
+
import { SmoLyric, SmoDynamicText, SmoArticulation, 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
|
+
import { SmoSelector, SmoSelection } from '../src/smo/xform/selections';
|
|
20
|
+
import { SmoOperation } from '../src/smo/xform/operations';
|
|
21
|
+
import { PasteBuffer } from '../src/smo/xform/copypaste';
|
|
22
|
+
import { timeSignatureRange } from '../src/smo/xform/rebar';
|
|
23
|
+
|
|
24
|
+
// The smo layer registers its deserialization factories at app start; do the same here
|
|
25
|
+
// without pulling in any UI.
|
|
26
|
+
noteModifierDynamicCtorInit();
|
|
27
|
+
measureModifierDynamicCtorInit();
|
|
28
|
+
staffModifierDynamicCtorInit();
|
|
29
|
+
scoreModifierDynamicCtorInit();
|
|
30
|
+
|
|
31
|
+
let failures = 0;
|
|
32
|
+
const check = (name: string, condition: boolean, detail?: string) => {
|
|
33
|
+
if (condition) {
|
|
34
|
+
console.log(`PASS ${name}`);
|
|
35
|
+
} else {
|
|
36
|
+
failures += 1;
|
|
37
|
+
console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const Q = 4096;
|
|
42
|
+
const H = 8192;
|
|
43
|
+
const W = 16384;
|
|
44
|
+
const E = 2048;
|
|
45
|
+
const LETTERS = ['c', 'd', 'e', 'f', 'g', 'a', 'b'];
|
|
46
|
+
|
|
47
|
+
const ts = (...parts: [number, number][]): SmoTimeSignature => {
|
|
48
|
+
const params = SmoTimeSignature.defaults;
|
|
49
|
+
params.times = parts.map(([actualBeats, beatDuration]) => ({ actualBeats, beatDuration }));
|
|
50
|
+
return new SmoTimeSignature(params);
|
|
51
|
+
};
|
|
52
|
+
const sel = (staff: number, measure: number, tick: number, voice: number = 0): SmoSelector =>
|
|
53
|
+
({ staff, measure, voice, tick, pitches: [] });
|
|
54
|
+
|
|
55
|
+
type NoteSpec = [number, number | 'r'];
|
|
56
|
+
/** Replace a voice with notes of the given lengths. A number names a pitch (0 is c4, 1 is d4...); 'r' is a rest. */
|
|
57
|
+
const setVoice = (measure: SmoMeasure, voice: number, specs: NoteSpec[]) => {
|
|
58
|
+
while (measure.voices.length <= voice) {
|
|
59
|
+
measure.populateVoice(measure.voices.length);
|
|
60
|
+
}
|
|
61
|
+
const template = measure.voices[0].notes[0];
|
|
62
|
+
measure.voices[voice].notes = specs.map(([ticks, id]) => {
|
|
63
|
+
const note = SmoNote.cloneWithDuration(template, ticks);
|
|
64
|
+
note.textModifiers = [];
|
|
65
|
+
if (id === 'r') {
|
|
66
|
+
note.noteType = 'r';
|
|
67
|
+
} else {
|
|
68
|
+
note.noteType = 'n';
|
|
69
|
+
note.pitches = [{ letter: LETTERS[id % 7] as any, accidental: 'n', octave: 4 + Math.floor(id / 7) }];
|
|
70
|
+
}
|
|
71
|
+
return note;
|
|
72
|
+
});
|
|
73
|
+
measure.tupletTrees = measure.tupletTrees.filter((tree) => tree.voice !== voice);
|
|
74
|
+
};
|
|
75
|
+
/** Notes of the given length with pitches 0, 1, 2... starting at `first` */
|
|
76
|
+
const run = (ticks: number, count: number, first: number = 0): NoteSpec[] =>
|
|
77
|
+
Array.from({ length: count }, (_, i) => [ticks, first + i] as NoteSpec);
|
|
78
|
+
|
|
79
|
+
/** A score with the given meters, one measure each, and the given number of staves. Measures are filled with rests. */
|
|
80
|
+
const buildScore = (meters: [number, number][], staves: number = 1): SmoScore => {
|
|
81
|
+
const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
|
|
82
|
+
while (score.staves[0].measures.length < meters.length) {
|
|
83
|
+
score.addMeasure(score.staves[0].measures.length - 1);
|
|
84
|
+
}
|
|
85
|
+
for (let s = 1; s < staves; ++s) {
|
|
86
|
+
const params = SmoSystemStaff.defaults;
|
|
87
|
+
params.staffId = s;
|
|
88
|
+
params.measureInstrumentMap[0] = new SmoInstrument(SmoInstrument.defaults);
|
|
89
|
+
score.addStaff(params);
|
|
90
|
+
}
|
|
91
|
+
score.staves.forEach((staff) => {
|
|
92
|
+
staff.measures.forEach((measure, ix) => {
|
|
93
|
+
measure.timeSignature = ts(meters[ix]);
|
|
94
|
+
setVoice(measure, 0, [[SmoMusicTicks(meters[ix]), 'r']]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return score;
|
|
98
|
+
};
|
|
99
|
+
const SmoMusicTicks = ([beats, duration]: [number, number]) => 2048 * (8 / duration) * beats;
|
|
100
|
+
/** A score of 4/4 measures, the first staff holding `notes` split into measures of four quarters */
|
|
101
|
+
const quarterScore = (quarters: number, staves: number = 1): SmoScore => {
|
|
102
|
+
const measures = Math.ceil(quarters / 4);
|
|
103
|
+
const score = buildScore(Array.from({ length: measures }, () => [4, 4] as [number, number]), staves);
|
|
104
|
+
score.staves.forEach((staff) => {
|
|
105
|
+
staff.measures.forEach((measure, m) => {
|
|
106
|
+
setVoice(measure, 0, run(Q, 4, m * 4));
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return score;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const tag = (note: SmoNote) => note.noteType === 'r' ? 'r' : `${note.pitches[0].letter}${note.pitches[0].octave}`;
|
|
113
|
+
const key = (staff: number, measure: number, voice: number, tick: number) => SmoSelector.getNoteKey(sel(staff, measure, tick, voice));
|
|
114
|
+
const tieKeys = (score: SmoScore, staff: number): string[] =>
|
|
115
|
+
score.staves[staff].modifiers.filter((mod) => mod.ctor === 'SmoTie').map((mod) =>
|
|
116
|
+
`${SmoSelector.getNoteKey(mod.startSelector)}>${SmoSelector.getNoteKey(mod.endSelector)}`);
|
|
117
|
+
/** The notes of a voice in order, with notes joined by ties written as one: "c4:8192 d4:4096 r:4096" */
|
|
118
|
+
const joined = (score: SmoScore, staff: number, voice: number, first: number, last: number): string => {
|
|
119
|
+
const ties = tieKeys(score, staff);
|
|
120
|
+
const out: { tag: string, ticks: number }[] = [];
|
|
121
|
+
let previous: string | null = null;
|
|
122
|
+
for (let m = first; m <= last; ++m) {
|
|
123
|
+
const measure = score.staves[staff].measures[m];
|
|
124
|
+
if (voice >= measure.voices.length) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
measure.voices[voice].notes.forEach((note, t) => {
|
|
128
|
+
const here = key(staff, m, voice, t);
|
|
129
|
+
if (previous !== null && ties.indexOf(`${previous}>${here}`) >= 0) {
|
|
130
|
+
out[out.length - 1].ticks += note.tickCount;
|
|
131
|
+
} else {
|
|
132
|
+
out.push({ tag: tag(note), ticks: note.tickCount });
|
|
133
|
+
}
|
|
134
|
+
previous = here;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return out.map((item) => `${item.tag}:${item.ticks}`).join(' ');
|
|
138
|
+
};
|
|
139
|
+
const expected = (specs: NoteSpec[]): string =>
|
|
140
|
+
specs.map(([ticks, id]) => `${id === 'r' ? 'r' : LETTERS[id % 7] + (4 + Math.floor(id / 7))}:${ticks}`).join(' ');
|
|
141
|
+
/** The number of notes in each measure of a voice, e.g. "3,3,3" */
|
|
142
|
+
const counts = (score: SmoScore, staff: number, voice: number, first: number, last: number): string => {
|
|
143
|
+
const rv: number[] = [];
|
|
144
|
+
for (let m = first; m <= last; ++m) {
|
|
145
|
+
rv.push(score.staves[staff].measures[m].voices[voice]?.notes.length ?? 0);
|
|
146
|
+
}
|
|
147
|
+
return rv.join(',');
|
|
148
|
+
};
|
|
149
|
+
const measureTicks = (measure: SmoMeasure, voice: number = 0): number =>
|
|
150
|
+
measure.voices[voice].notes.reduce((total, note) => total + note.tickCount, 0);
|
|
151
|
+
const allFull = (score: SmoScore, first: number, last: number): boolean =>
|
|
152
|
+
score.staves.every((staff) => {
|
|
153
|
+
for (let m = first; m <= last; ++m) {
|
|
154
|
+
const measure = staff.measures[m];
|
|
155
|
+
const length = SmoMusicTicks([measure.timeSignature.actualBeats, measure.timeSignature.beatDuration]);
|
|
156
|
+
if (measure.voices.some((voice, v) => Math.abs(measureTicks(measure, v) - length) > 0.5)) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// --- B1: the spec's example ---
|
|
164
|
+
{
|
|
165
|
+
const score = quarterScore(8);
|
|
166
|
+
const result = SmoOperation.rebarMeasures(score, 0, 1, ts([3, 4]));
|
|
167
|
+
check('B1 two 4/4 measures become three 3/4 measures', score.staves[0].measures.length === 3 && result.added === 1
|
|
168
|
+
&& result.measureCount === 3, `${score.staves[0].measures.length} ${JSON.stringify(result)}`);
|
|
169
|
+
check('B1 every measure has the 3/4 signature', score.staves[0].measures.every((m) => m.timeSignature.actualBeats === 3 && m.timeSignature.beatDuration === 4));
|
|
170
|
+
check('B1 the notes are in the same order, with a quarter rest to fill', joined(score, 0, 0, 0, 2) === expected([...run(Q, 8), [Q, 'r']]), joined(score, 0, 0, 0, 2));
|
|
171
|
+
check('B1 three notes, three notes, two notes and a rest', counts(score, 0, 0, 0, 2) === '3,3,3', counts(score, 0, 0, 0, 2));
|
|
172
|
+
check('B1 every measure is full', allFull(score, 0, 2));
|
|
173
|
+
check('B1 no ties were needed', tieKeys(score, 0).length === 0);
|
|
174
|
+
check('B1 measures are numbered in order', score.staves[0].measures.every((m, i) => m.measureNumber.measureIndex === i));
|
|
175
|
+
}
|
|
176
|
+
// --- B2: a larger meter ---
|
|
177
|
+
{
|
|
178
|
+
const score = buildScore([[3, 4], [3, 4], [3, 4]]);
|
|
179
|
+
score.staves[0].measures.forEach((measure, m) => setVoice(measure, 0, run(Q, 3, m * 3)));
|
|
180
|
+
const result = SmoOperation.rebarMeasures(score, 0, 2, ts([4, 4]));
|
|
181
|
+
check('B2 3/4 to 4/4: nine quarters need three measures, none added', result.added === 0 && score.staves[0].measures.length === 3);
|
|
182
|
+
check('B2 notes in order, then rests for the last measure', joined(score, 0, 0, 0, 2) === expected([...run(Q, 9), [12288, 'r']]), joined(score, 0, 0, 0, 2));
|
|
183
|
+
check('B2 every measure is full', allFull(score, 0, 2));
|
|
184
|
+
}
|
|
185
|
+
// --- B3: 6/8 and 5/8 ---
|
|
186
|
+
{
|
|
187
|
+
const six = quarterScore(8);
|
|
188
|
+
const r6 = SmoOperation.rebarMeasures(six, 0, 1, ts([6, 8]));
|
|
189
|
+
check('B3 4/4 to 6/8: three measures', r6.added === 1 && six.staves[0].measures.length === 3);
|
|
190
|
+
check('B3 4/4 to 6/8: notes in order, rest of a quarter at the end', joined(six, 0, 0, 0, 2) === expected([...run(Q, 8), [Q, 'r']]), joined(six, 0, 0, 0, 2));
|
|
191
|
+
const five = quarterScore(8);
|
|
192
|
+
const r5 = SmoOperation.rebarMeasures(five, 0, 1, ts([5, 8]));
|
|
193
|
+
check('B3 4/4 to 5/8: four measures, two added', r5.added === 2 && five.staves[0].measures.length === 4, JSON.stringify(r5));
|
|
194
|
+
// four measures of 10240 hold 40960 ticks; the eight quarters are 32768, so 8192 of rest ends the music
|
|
195
|
+
check('B3 4/4 to 5/8: notes in order, tied pieces joined', joined(five, 0, 0, 0, 3) === expected([...run(Q, 8), [H, 'r']]), joined(five, 0, 0, 0, 3));
|
|
196
|
+
// the third quarter starts at 8192 and the eighth starts at 28672: each crosses a bar line (10240 and 30720)
|
|
197
|
+
check('B3 4/4 to 5/8: notes that cross a bar line are tied', tieKeys(five, 0).length === 2, String(tieKeys(five, 0).length));
|
|
198
|
+
check('B3 4/4 to 5/8: every measure is full', allFull(five, 0, 3));
|
|
199
|
+
}
|
|
200
|
+
// --- B4, B5, B6: notes and rests that cross bar lines ---
|
|
201
|
+
{
|
|
202
|
+
const score = buildScore([[4, 4]]);
|
|
203
|
+
setVoice(score.staves[0].measures[0], 0, [[Q, 0], [Q, 1], [H, 2]]);
|
|
204
|
+
SmoOperation.rebarMeasures(score, 0, 0, ts([3, 4]));
|
|
205
|
+
check('B4 a half note on beat 3 of 3/4 is split in two tied notes', joined(score, 0, 0, 0, 1) === expected([[Q, 0], [Q, 1], [H, 2], [H, 'r']]), joined(score, 0, 0, 0, 1));
|
|
206
|
+
check('B4 the two pieces are tied', tieKeys(score, 0).length === 1);
|
|
207
|
+
check('B4 the split note is a quarter and a quarter', score.staves[0].measures[0].voices[0].notes[2].tickCount === Q && score.staves[0].measures[1].voices[0].notes[0].tickCount === Q);
|
|
208
|
+
}
|
|
209
|
+
{
|
|
210
|
+
const score = buildScore([[4, 4]]);
|
|
211
|
+
setVoice(score.staves[0].measures[0], 0, [[W, 0]]);
|
|
212
|
+
const result = SmoOperation.rebarMeasures(score, 0, 0, ts([1, 4]));
|
|
213
|
+
check('B5 a whole note crossing three bar lines: four measures', result.added === 3 && score.staves[0].measures.length === 4);
|
|
214
|
+
check('B5 four quarter pieces, joined by three ties', tieKeys(score, 0).length === 3 && joined(score, 0, 0, 0, 3) === expected([[W, 0]]), joined(score, 0, 0, 0, 3));
|
|
215
|
+
}
|
|
216
|
+
{
|
|
217
|
+
const score = buildScore([[4, 4]]);
|
|
218
|
+
setVoice(score.staves[0].measures[0], 0, [[H, 0], [H, 'r']]);
|
|
219
|
+
SmoOperation.rebarMeasures(score, 0, 0, ts([3, 4]));
|
|
220
|
+
check('B6 a rest that crosses a bar line is split in rests, with no ties', tieKeys(score, 0).length === 0
|
|
221
|
+
&& joined(score, 0, 0, 0, 1) === expected([[H, 0], [Q, 'r'], [Q, 'r'], [H, 'r']]), joined(score, 0, 0, 0, 1));
|
|
222
|
+
}
|
|
223
|
+
// --- B7, B8, B9: tuplets ---
|
|
224
|
+
const tripletOn = (score: SmoScore, m: number, tick: number, voice: number = 0) => {
|
|
225
|
+
SmoOperation.makeTuplet(SmoSelection.noteSelection(score, 0, m, voice, tick)!,
|
|
226
|
+
{ numNotes: 3, notesOccupied: 2, bracketed: true, ratioed: false } as any);
|
|
227
|
+
};
|
|
228
|
+
{
|
|
229
|
+
const score = buildScore([[4, 4]]);
|
|
230
|
+
setVoice(score.staves[0].measures[0], 0, [[Q, 0], [Q, 1], [Q, 2], [Q, 3]]);
|
|
231
|
+
tripletOn(score, 0, 3);
|
|
232
|
+
SmoOperation.rebarMeasures(score, 0, 0, ts([6, 4]));
|
|
233
|
+
const measure = score.staves[0].measures[0];
|
|
234
|
+
check('B7 a triplet that fits is kept whole, with the right indices', measure.tupletTrees.length === 1
|
|
235
|
+
&& measure.tupletTrees[0].startIndex === 3 && measure.tupletTrees[0].endIndex === 5, JSON.stringify(measure.tupletTrees.map((t) => [t.startIndex, t.endIndex])));
|
|
236
|
+
check('B7 its notes are still tuplet notes', [3, 4, 5].every((i) => measure.voices[0].notes[i].isTuplet));
|
|
237
|
+
check('B7 no ties', tieKeys(score, 0).length === 0);
|
|
238
|
+
}
|
|
239
|
+
{
|
|
240
|
+
const score = buildScore([[4, 4], [4, 4]]);
|
|
241
|
+
setVoice(score.staves[0].measures[0], 0, [[Q, 0], [Q, 1], [Q, 2], [Q, 3]]);
|
|
242
|
+
tripletOn(score, 0, 2);
|
|
243
|
+
SmoOperation.rebarMeasures(score, 0, 1, ts([5, 8]));
|
|
244
|
+
// 5/8 is 10240 ticks: two quarters use 8192, so the triplet (4096) starts the next measure
|
|
245
|
+
const m0 = score.staves[0].measures[0];
|
|
246
|
+
const m1 = score.staves[0].measures[1];
|
|
247
|
+
check('B8 a triplet that would cross the bar line starts the next measure', m1.tupletTrees.length === 1 && m1.tupletTrees[0].startIndex === 0
|
|
248
|
+
&& m1.voices[0].notes[0].isTuplet && m0.tupletTrees.length === 0, JSON.stringify(m1.tupletTrees.map((t) => [t.startIndex, t.endIndex])));
|
|
249
|
+
check('B8 the rest of the first measure is a rest', m0.voices[0].notes[m0.voices[0].notes.length - 1].noteType === 'r'
|
|
250
|
+
&& m0.voices[0].notes.length === 3);
|
|
251
|
+
const pitches = score.staves[0].measures.map((m) => m.voices[0].notes.filter((n) => n.noteType !== 'r').map(tag).join('')).join('');
|
|
252
|
+
check('B8 all the notes are kept, in order', pitches === 'c4d4e4e4e4f4', pitches);
|
|
253
|
+
}
|
|
254
|
+
{
|
|
255
|
+
const score = buildScore([[4, 4]]);
|
|
256
|
+
setVoice(score.staves[0].measures[0], 0, [[Q, 0], [Q, 1], [Q, 2], [Q, 3]]);
|
|
257
|
+
tripletOn(score, 0, 1);
|
|
258
|
+
SmoOperation.rebarMeasures(score, 0, 0, ts([1, 8]));
|
|
259
|
+
const trees = score.staves[0].measures.reduce((total, m) => total + m.tupletTrees.length, 0);
|
|
260
|
+
const pitches = Array.from({ length: score.staves[0].measures.length }, (_, m) =>
|
|
261
|
+
score.staves[0].measures[m].voices[0].notes.filter((n) => n.noteType !== 'r').map(tag).join(' ')).join(' ').split(' ');
|
|
262
|
+
check('B9 a tuplet longer than a measure is written out as plain notes, none lost', trees === 0
|
|
263
|
+
&& pitches.filter((p) => p === 'd4').length >= 3 && pitches.indexOf('c4') >= 0 && pitches.indexOf('e4') >= 0 && pitches.indexOf('f4') >= 0, pitches.join(' '));
|
|
264
|
+
}
|
|
265
|
+
// --- B10: voices ---
|
|
266
|
+
{
|
|
267
|
+
const score = buildScore([[4, 4]]);
|
|
268
|
+
setVoice(score.staves[0].measures[0], 0, run(Q, 4));
|
|
269
|
+
setVoice(score.staves[0].measures[0], 1, [[W, 10]]);
|
|
270
|
+
const result = SmoOperation.rebarMeasures(score, 0, 0, ts([3, 4]));
|
|
271
|
+
check('B10 two voices: two measures, both with two voices', result.measureCount === 2
|
|
272
|
+
&& score.staves[0].measures.every((m) => m.voices.length === 2));
|
|
273
|
+
check('B10 voice 0 keeps its notes', joined(score, 0, 0, 0, 1) === expected([...run(Q, 4), [H, 'r']]), joined(score, 0, 0, 0, 1));
|
|
274
|
+
check('B10 voice 1 keeps its note, tied across the bar, then a rest', joined(score, 0, 1, 0, 1) === expected([[W, 10], [H, 'r']]), joined(score, 0, 1, 0, 1));
|
|
275
|
+
}
|
|
276
|
+
{
|
|
277
|
+
// a voice that is only in one measure of a range is not added to the others
|
|
278
|
+
const score = buildScore([[4, 4], [4, 4]]);
|
|
279
|
+
setVoice(score.staves[0].measures[0], 0, run(Q, 4));
|
|
280
|
+
setVoice(score.staves[0].measures[1], 0, run(Q, 4, 4));
|
|
281
|
+
setVoice(score.staves[0].measures[0], 1, [[W, 10]]);
|
|
282
|
+
SmoOperation.rebarMeasures(score, 0, 1, ts([4, 4]));
|
|
283
|
+
check('B10 a voice that was only in the first measure is not added to the second', score.staves[0].measures[0].voices.length === 2
|
|
284
|
+
&& score.staves[0].measures[1].voices.length === 1, score.staves[0].measures.map((m) => m.voices.length).join());
|
|
285
|
+
}
|
|
286
|
+
// --- B11: staves ---
|
|
287
|
+
{
|
|
288
|
+
const score = quarterScore(8, 2);
|
|
289
|
+
score.staves[1].measures.forEach((measure, m) => setVoice(measure, 0, run(E, 8, m * 8)));
|
|
290
|
+
const result = SmoOperation.rebarMeasures(score, 0, 1, ts([3, 4]));
|
|
291
|
+
check('B11 both staves are re-barred and have the same number of measures', score.staves[0].measures.length === 3
|
|
292
|
+
&& score.staves[1].measures.length === 3 && result.added === 1);
|
|
293
|
+
check('B11 each keeps its own music', joined(score, 0, 0, 0, 2) === expected([...run(Q, 8), [Q, 'r']])
|
|
294
|
+
// three measures of 12288 hold 36864 ticks; sixteen eighths are 32768, so a quarter rest ends the music
|
|
295
|
+
&& joined(score, 1, 0, 0, 2) === expected([...run(E, 16), [Q, 'r']]), joined(score, 1, 0, 0, 2));
|
|
296
|
+
check('B11 both staves are full', allFull(score, 0, 2));
|
|
297
|
+
}
|
|
298
|
+
// --- B12: markings stay on the note, the first piece if it is split ---
|
|
299
|
+
{
|
|
300
|
+
const score = buildScore([[4, 4]]);
|
|
301
|
+
setVoice(score.staves[0].measures[0], 0, [[Q, 0], [Q, 1], [H, 2]]);
|
|
302
|
+
const split = score.staves[0].measures[0].voices[0].notes[2];
|
|
303
|
+
split.addLyric(new SmoLyric({ ...SmoLyric.defaults, text: 'la', verse: 0, parser: SmoLyric.parsers.lyric } as any));
|
|
304
|
+
split.addDynamic(new SmoDynamicText({ ...SmoDynamicText.defaults, text: 'mf' } as any));
|
|
305
|
+
split.setArticulation(new SmoArticulation({ ...SmoArticulation.defaults, articulation: 'accent' } as any), true);
|
|
306
|
+
const first = score.staves[0].measures[0].voices[0].notes[0];
|
|
307
|
+
first.addLyric(new SmoLyric({ ...SmoLyric.defaults, text: 'so', verse: 0, parser: SmoLyric.parsers.lyric } as any));
|
|
308
|
+
SmoOperation.rebarMeasures(score, 0, 0, ts([3, 4]));
|
|
309
|
+
const m0 = score.staves[0].measures[0].voices[0].notes;
|
|
310
|
+
const m1 = score.staves[0].measures[1].voices[0].notes;
|
|
311
|
+
check('B12 a note that was not split keeps its lyric', m0[0].getTrueLyrics().length === 1);
|
|
312
|
+
check('B12 the first piece of a split note keeps its markings', m0[2].getTrueLyrics().length === 1
|
|
313
|
+
&& m0[2].getModifiers('SmoDynamicText').length === 1 && m0[2].articulations.length === 1);
|
|
314
|
+
check('B12 the second piece has the pitch and no markings', m1[0].noteType === 'n' && tag(m1[0]) === 'e4' && m1[0].textModifiers.length === 0
|
|
315
|
+
&& m1[0].articulations.length === 0);
|
|
316
|
+
}
|
|
317
|
+
// --- B13: staff modifiers follow their notes ---
|
|
318
|
+
{
|
|
319
|
+
const score = quarterScore(8);
|
|
320
|
+
const staff = score.staves[0];
|
|
321
|
+
const slur = new SmoSlur(SmoSlur.defaults);
|
|
322
|
+
slur.startSelector = sel(0, 0, 3);
|
|
323
|
+
slur.endSelector = sel(0, 1, 1);
|
|
324
|
+
slur.associatedStaff = 0;
|
|
325
|
+
staff.addStaffModifier(slur);
|
|
326
|
+
const hairpin = new SmoStaffHairpin(SmoStaffHairpin.defaults);
|
|
327
|
+
hairpin.startSelector = sel(0, 0, 0);
|
|
328
|
+
hairpin.endSelector = sel(0, 1, 3);
|
|
329
|
+
hairpin.associatedStaff = 0;
|
|
330
|
+
staff.addStaffModifier(hairpin);
|
|
331
|
+
const tie = new SmoTie(SmoTie.defaults);
|
|
332
|
+
tie.startSelector = sel(0, 0, 3);
|
|
333
|
+
tie.endSelector = sel(0, 1, 0);
|
|
334
|
+
tie.lines = SmoTie.createLines(staff.measures[0].voices[0].notes[3], staff.measures[1].voices[0].notes[0]);
|
|
335
|
+
staff.addStaffModifier(tie);
|
|
336
|
+
SmoOperation.rebarMeasures(score, 0, 1, ts([3, 4]));
|
|
337
|
+
// quarter n is note n % 3 of measure floor(n / 3)
|
|
338
|
+
const at = (n: number) => sel(0, Math.floor(n / 3), n % 3);
|
|
339
|
+
const find = (id: string) => staff.modifiers.find((mod) => mod.attrs.id === id)!;
|
|
340
|
+
check('B13 a slur starts and ends on the same notes (quarters 3 and 5)', SmoSelector.eq(find(slur.attrs.id).startSelector, at(3))
|
|
341
|
+
&& SmoSelector.eq(find(slur.attrs.id).endSelector, at(5)), JSON.stringify([find(slur.attrs.id).startSelector, find(slur.attrs.id).endSelector]));
|
|
342
|
+
check('B13 a hairpin starts and ends on the same notes (quarters 0 and 7)', SmoSelector.eq(find(hairpin.attrs.id).startSelector, at(0))
|
|
343
|
+
&& SmoSelector.eq(find(hairpin.attrs.id).endSelector, at(7)));
|
|
344
|
+
check('B13 a tie starts and ends on the same notes (quarters 3 and 4)', SmoSelector.eq(find(tie.attrs.id).startSelector, at(3))
|
|
345
|
+
&& SmoSelector.eq(find(tie.attrs.id).endSelector, at(4)));
|
|
346
|
+
}
|
|
347
|
+
{
|
|
348
|
+
// a modifier on a note that is split: starts on the first piece, ends on the last; a tie starts on the last piece
|
|
349
|
+
const score = buildScore([[4, 4]]);
|
|
350
|
+
const staff = score.staves[0];
|
|
351
|
+
setVoice(staff.measures[0], 0, [[H, 0], [H, 1]]);
|
|
352
|
+
const slur = new SmoSlur(SmoSlur.defaults);
|
|
353
|
+
slur.startSelector = sel(0, 0, 0);
|
|
354
|
+
slur.endSelector = sel(0, 0, 1);
|
|
355
|
+
slur.associatedStaff = 0;
|
|
356
|
+
staff.addStaffModifier(slur);
|
|
357
|
+
SmoOperation.rebarMeasures(score, 0, 0, ts([3, 4]));
|
|
358
|
+
// c4 half note fits (8192 of 12288); d4 half is split (4096 | 4096)
|
|
359
|
+
const mod = staff.modifiers.find((m) => m.attrs.id === slur.attrs.id)!;
|
|
360
|
+
check('B13 a slur to a split note ends on its last piece', SmoSelector.eq(mod.startSelector, sel(0, 0, 0)) && SmoSelector.eq(mod.endSelector, sel(0, 1, 0)),
|
|
361
|
+
JSON.stringify([mod.startSelector, mod.endSelector]));
|
|
362
|
+
}
|
|
363
|
+
// --- B14: alternating meters ---
|
|
364
|
+
{
|
|
365
|
+
const score = quarterScore(8);
|
|
366
|
+
const result = SmoOperation.rebarMeasures(score, 0, 1, ts([3, 4], [2, 4]));
|
|
367
|
+
const lengths = score.staves[0].measures.map((m) => measureTicks(m));
|
|
368
|
+
check('B14 3/4+2/4 alternates 3/4, 2/4, 3/4...', lengths.slice(0, 3).join() === `${3 * Q},${2 * Q},${3 * Q}`, lengths.join());
|
|
369
|
+
check('B14 all the music fits, in order', joined(score, 0, 0, 0, result.measureCount - 1).startsWith(expected(run(Q, 8))), joined(score, 0, 0, 0, result.measureCount - 1));
|
|
370
|
+
check('B14 the measures have the alternating parts', score.staves[0].measures[0].timeSignature.index === 0 && score.staves[0].measures[1].timeSignature.index === 1);
|
|
371
|
+
}
|
|
372
|
+
// --- B15: ranges ---
|
|
373
|
+
{
|
|
374
|
+
const score = buildScore(Array.from({ length: 6 }, () => [4, 4] as [number, number]));
|
|
375
|
+
score.staves[0].measures.forEach((measure, m) => setVoice(measure, 0, run(Q, 4, m * 4)));
|
|
376
|
+
const slur = new SmoSlur(SmoSlur.defaults);
|
|
377
|
+
slur.startSelector = sel(0, 4, 0);
|
|
378
|
+
slur.endSelector = sel(0, 5, 3);
|
|
379
|
+
slur.associatedStaff = 0;
|
|
380
|
+
score.staves[0].addStaffModifier(slur);
|
|
381
|
+
const result = SmoOperation.rebarMeasures(score, 2, 3, ts([3, 4]));
|
|
382
|
+
const measures = score.staves[0].measures;
|
|
383
|
+
check('B15 measures 3 and 4 become three measures; six measures become seven', result.added === 1 && measures.length === 7);
|
|
384
|
+
check('B15 measures before the range are unchanged', measures.slice(0, 2).every((m) => m.timeSignature.actualBeats === 4)
|
|
385
|
+
&& joined(score, 0, 0, 0, 1) === expected(run(Q, 8)));
|
|
386
|
+
check('B15 measures after the range are unchanged, now later', measures.slice(5).every((m) => m.timeSignature.actualBeats === 4)
|
|
387
|
+
&& joined(score, 0, 0, 5, 6) === expected(run(Q, 8, 16)));
|
|
388
|
+
const mod = score.staves[0].modifiers.find((m) => m.attrs.id === slur.attrs.id)!;
|
|
389
|
+
check('B15 a modifier after the range moves later', mod.startSelector.measure === 5 && mod.endSelector.measure === 6,
|
|
390
|
+
JSON.stringify([mod.startSelector, mod.endSelector]));
|
|
391
|
+
check('B15 the range was re-barred', joined(score, 0, 0, 2, 4) === expected([...run(Q, 8, 8), [Q, 'r']]), joined(score, 0, 0, 2, 4));
|
|
392
|
+
check('B15 measure numbers are in order', measures.every((m, i) => m.measureNumber.measureIndex === i));
|
|
393
|
+
}
|
|
394
|
+
{
|
|
395
|
+
const whole = buildScore([[4, 4], [4, 4]]);
|
|
396
|
+
whole.staves[0].measures.forEach((measure, m) => setVoice(measure, 0, run(Q, 4, m * 4)));
|
|
397
|
+
const r = SmoOperation.rebarMeasures(whole, 0, 1, ts([2, 4]));
|
|
398
|
+
check('B15 4/4 to 2/4 over the whole score: the same measures, no loss, and no measure removed', r.added === 2 && whole.staves[0].measures.length === 4
|
|
399
|
+
&& joined(whole, 0, 0, 0, 3) === expected(run(Q, 8)));
|
|
400
|
+
}
|
|
401
|
+
// --- B16: added measures copy the last measure's settings ---
|
|
402
|
+
{
|
|
403
|
+
const score = quarterScore(8);
|
|
404
|
+
score.staves[0].measures[1].keySignature = 'd';
|
|
405
|
+
score.staves[0].measures[0].keySignature = 'd';
|
|
406
|
+
SmoOperation.rebarMeasures(score, 0, 1, ts([3, 4]));
|
|
407
|
+
check('B16 the added measure has the key signature of the last measure', score.staves[0].measures[2].keySignature === 'd');
|
|
408
|
+
}
|
|
409
|
+
{
|
|
410
|
+
const score = quarterScore(8);
|
|
411
|
+
score.staves[0].measures[1].setBarline(new SmoBarline({ position: SmoBarline.positions.end, barline: SmoBarline.barlines.endBar }));
|
|
412
|
+
SmoOperation.rebarMeasures(score, 0, 1, ts([3, 4]));
|
|
413
|
+
check('B16 the end barline goes with the end of the range', score.staves[0].measures[2].getEndBarline().barline === SmoBarline.barlines.endBar
|
|
414
|
+
&& score.staves[0].measures[1].getEndBarline().barline === SmoBarline.barlines.singleBar);
|
|
415
|
+
}
|
|
416
|
+
// --- B17, B18: the checks the view uses ---
|
|
417
|
+
{
|
|
418
|
+
const score = quarterScore(8);
|
|
419
|
+
check('B17 4/4 to 2/2 keeps the length', SmoOperation.timeSignatureKeepsLength(score, 0, 1, ts([2, 2])));
|
|
420
|
+
check('B17 4/4 to 3/4 does not', !SmoOperation.timeSignatureKeepsLength(score, 0, 1, ts([3, 4])));
|
|
421
|
+
check('B17 4/4 to 3/4+2/4 does not', !SmoOperation.timeSignatureKeepsLength(score, 0, 1, ts([3, 4], [2, 4])));
|
|
422
|
+
check('B17 4/4 to 2/2 changes the signature', SmoOperation.timeSignatureChanges(score, 0, 1, ts([2, 2])));
|
|
423
|
+
check('B18 the same signature changes nothing', !SmoOperation.timeSignatureChanges(score, 0, 1, ts([4, 4])));
|
|
424
|
+
const shown = ts([4, 4]);
|
|
425
|
+
shown.display = !score.staves[0].measures[0].timeSignature.display;
|
|
426
|
+
check('B18 a different display option is a change that keeps the length', SmoOperation.timeSignatureChanges(score, 0, 1, shown)
|
|
427
|
+
&& SmoOperation.timeSignatureKeepsLength(score, 0, 1, shown));
|
|
428
|
+
const one = quarterScore(8);
|
|
429
|
+
one.staves[0].measures[1].timeSignature = ts([3, 4]);
|
|
430
|
+
check('B18 one measure that differs is a change', SmoOperation.timeSignatureChanges(one, 0, 1, ts([4, 4])));
|
|
431
|
+
}
|
|
432
|
+
// --- B19: no measure is removed ---
|
|
433
|
+
{
|
|
434
|
+
const score = buildScore([[3, 4], [3, 4], [3, 4]]);
|
|
435
|
+
score.staves[0].measures.forEach((measure, m) => setVoice(measure, 0, run(Q, 3, m * 3)));
|
|
436
|
+
const result = SmoOperation.rebarMeasures(score, 0, 2, ts([6, 4]));
|
|
437
|
+
check('B19 3 measures of 3/4 to 6/4: 9 quarters need 2 measures, 3 stay, none added', result.added === 0 && score.staves[0].measures.length === 3);
|
|
438
|
+
check('B19 the extra measure is rests and the music is in order', joined(score, 0, 0, 0, 2).startsWith(expected(run(Q, 9))) && allFull(score, 0, 2),
|
|
439
|
+
joined(score, 0, 0, 0, 2));
|
|
440
|
+
check('B19 the unneeded measure is a rest', score.staves[0].measures[2].voices[0].notes.every((n) => n.noteType === 'r'));
|
|
441
|
+
}
|
|
442
|
+
// --- B20: serialization ---
|
|
443
|
+
{
|
|
444
|
+
const score = quarterScore(8);
|
|
445
|
+
SmoOperation.rebarMeasures(score, 0, 1, ts([5, 8]));
|
|
446
|
+
const reloaded = SmoScore.deserialize(JSON.stringify(score.serialize()));
|
|
447
|
+
check('B20 a re-barred score reloads with the same measures and music', reloaded.staves[0].measures.length === score.staves[0].measures.length
|
|
448
|
+
&& joined(reloaded, 0, 0, 0, 3) === joined(score, 0, 0, 0, 3), joined(reloaded, 0, 0, 0, 3));
|
|
449
|
+
check('B20 the ties are still there', tieKeys(reloaded, 0).length === tieKeys(score, 0).length);
|
|
450
|
+
}
|
|
451
|
+
// --- B21: bad input ---
|
|
452
|
+
{
|
|
453
|
+
const score = quarterScore(8);
|
|
454
|
+
const before = JSON.stringify(score.serialize());
|
|
455
|
+
const a = SmoOperation.rebarMeasures(score, 0, 9, ts([3, 4]));
|
|
456
|
+
const b = SmoOperation.rebarMeasures(score, 1, 0, ts([3, 4]));
|
|
457
|
+
const c = SmoOperation.rebarMeasures(score, -1, 1, ts([3, 4]));
|
|
458
|
+
check('B21 a range that is not in the score does nothing', a.added === 0 && b.added === 0 && c.added === 0 && JSON.stringify(score.serialize()) === before);
|
|
459
|
+
}
|
|
460
|
+
// --- B22: the old behavior ---
|
|
461
|
+
{
|
|
462
|
+
const score = quarterScore(8);
|
|
463
|
+
const selections = [0, 1].map((m) => SmoSelection.measureSelection(score, 0, m)!);
|
|
464
|
+
SmoOperation.setTimeSignature(score, selections, ts([3, 4]));
|
|
465
|
+
check('B22 keep-what-fits: still two measures of three quarters', score.staves[0].measures.length === 2
|
|
466
|
+
&& counts(score, 0, 0, 0, 1) === '3,3' && joined(score, 0, 0, 0, 1) === expected([...run(Q, 3), ...run(Q, 3, 4)]), joined(score, 0, 0, 0, 1));
|
|
467
|
+
}
|
|
468
|
+
// --- B23: the copy buffer is not used ---
|
|
469
|
+
{
|
|
470
|
+
const score = quarterScore(8);
|
|
471
|
+
const buffer = new PasteBuffer();
|
|
472
|
+
buffer.setSelections(score, [SmoSelection.noteSelection(score, 0, 0, 0, 1)!, SmoSelection.noteSelection(score, 0, 0, 0, 2)!]);
|
|
473
|
+
const before = JSON.stringify(Object.keys(buffer.notes).map((k) => buffer.notes[parseInt(k, 10)].map((n) => tag(n.note))));
|
|
474
|
+
SmoOperation.rebarMeasures(score, 0, 1, ts([3, 4]));
|
|
475
|
+
check('B23 the paste buffer is the same after a re-bar', JSON.stringify(Object.keys(buffer.notes).map((k) => buffer.notes[parseInt(k, 10)].map((n) => tag(n.note)))) === before && buffer.hasNotes());
|
|
476
|
+
}
|
|
477
|
+
// --- the range for each Apply To choice ---
|
|
478
|
+
{
|
|
479
|
+
const r = (applyTo: any, selected: number[], count: number) => JSON.stringify(timeSignatureRange(applyTo, selected, count));
|
|
480
|
+
check('R1 Selected: lowest to highest selected measure', r('Selected', [3, 2, 4], 8) === '{"firstMeasure":2,"lastMeasure":4}', r('Selected', [3, 2, 4], 8));
|
|
481
|
+
check('R2 Remaining: lowest selected measure to the end', r('Remaining', [3, 2], 8) === '{"firstMeasure":2,"lastMeasure":7}');
|
|
482
|
+
check('R3 Score: the whole score, whatever is selected', r('Score', [3], 8) === '{"firstMeasure":0,"lastMeasure":7}' && r('Score', [], 8) === '{"firstMeasure":0,"lastMeasure":7}');
|
|
483
|
+
check('R4 no selection is no range, except for the score', r('Selected', [], 8) === 'null' && r('Remaining', [], 8) === 'null');
|
|
484
|
+
check('R5 no measures is no range', r('Score', [0], 0) === 'null');
|
|
485
|
+
check('R6 a selected measure past the end is clipped', r('Selected', [2, 12], 8) === '{"firstMeasure":2,"lastMeasure":7}');
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (failures > 0) {
|
|
489
|
+
console.log(`${failures} FAILED`);
|
|
490
|
+
process.exit(1);
|
|
491
|
+
}
|
|
492
|
+
console.log('ALL PASS');
|