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,541 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless checks for Paste Special (PasteBuffer.pasteAttributes and the alignment it uses). Cases are
|
|
3
|
+
* listed in specs/035-paste-special/quickstart.md.
|
|
4
|
+
*
|
|
5
|
+
* Run with: npm run test:paste-special
|
|
6
|
+
*/
|
|
7
|
+
import { SmoScore } from '../src/smo/data/score';
|
|
8
|
+
import { SmoMeasure } from '../src/smo/data/measure';
|
|
9
|
+
import { SmoNote } from '../src/smo/data/note';
|
|
10
|
+
import { SmoSystemStaff } from '../src/smo/data/systemStaff';
|
|
11
|
+
import { SmoInstrument } from '../src/smo/data/staffModifiers';
|
|
12
|
+
import { SmoSelection, SmoSelector } from '../src/smo/xform/selections';
|
|
13
|
+
import { PasteBuffer, PasteAttributeKind, PasteAttributeMode } from '../src/smo/xform/copypaste';
|
|
14
|
+
import { SmoLyric, SmoDynamicText, SmoArticulation, SmoOrnament,
|
|
15
|
+
noteModifierDynamicCtorInit } from '../src/smo/data/noteModifiers';
|
|
16
|
+
import { measureModifierDynamicCtorInit } from '../src/smo/data/measureModifiers';
|
|
17
|
+
import { staffModifierDynamicCtorInit } from '../src/smo/data/staffModifiers';
|
|
18
|
+
import { scoreModifierDynamicCtorInit } from '../src/smo/data/scoreModifiers';
|
|
19
|
+
|
|
20
|
+
// The smo layer registers its deserialization factories at app start; do the same here
|
|
21
|
+
// without pulling in any UI.
|
|
22
|
+
noteModifierDynamicCtorInit();
|
|
23
|
+
measureModifierDynamicCtorInit();
|
|
24
|
+
staffModifierDynamicCtorInit();
|
|
25
|
+
scoreModifierDynamicCtorInit();
|
|
26
|
+
|
|
27
|
+
let failures = 0;
|
|
28
|
+
const check = (name: string, condition: boolean, detail?: string) => {
|
|
29
|
+
if (condition) {
|
|
30
|
+
console.log(`PASS ${name}`);
|
|
31
|
+
} else {
|
|
32
|
+
failures += 1;
|
|
33
|
+
console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const QUARTER = 4096;
|
|
38
|
+
const EIGHTH = 2048;
|
|
39
|
+
const WHOLE = 16384;
|
|
40
|
+
const KINDS = PasteBuffer.attributeKinds;
|
|
41
|
+
const DYNAMICS = ['pp', 'p', 'mp', 'mf', 'f', 'ff', 'sfz'];
|
|
42
|
+
const CHORDS = ['C', 'F', 'G', 'Am', 'Dm', 'Em', 'Bm'];
|
|
43
|
+
const ARTICULATIONS = ['accent', 'staccato', 'marcato', 'tenuto', 'upStroke', 'downStroke', 'pizzicato'];
|
|
44
|
+
const ORNAMENTS = ['mordent', 'turn', 'tr', 'upprall', 'doit', 'scoop', 'flip'];
|
|
45
|
+
|
|
46
|
+
/** The markings of a note as comparable text, by kind */
|
|
47
|
+
type Markings = Record<PasteAttributeKind, string[]>;
|
|
48
|
+
const markings = (note: SmoNote): Markings => ({
|
|
49
|
+
dynamics: note.getModifiers('SmoDynamicText').map((d) => (d as SmoDynamicText).text),
|
|
50
|
+
lyrics: note.getTrueLyrics().map((l) => `${l.verse}:${l.getText()}`),
|
|
51
|
+
annotations: note.getAnnotations().map((l) => `${l.verse}:${l.getText()}`),
|
|
52
|
+
chords: note.getChords().map((l) => l.getText()),
|
|
53
|
+
articulations: note.getArticulations().map((a) => a.articulation),
|
|
54
|
+
ornaments: note.getOrnaments().map((o) => o.ornament)
|
|
55
|
+
});
|
|
56
|
+
const sorted = (list: string[]) => [...list].sort();
|
|
57
|
+
const same = (a: string[], b: string[]) => JSON.stringify(sorted(a)) === JSON.stringify(sorted(b));
|
|
58
|
+
|
|
59
|
+
/** Give a note a full set of markings, all different for different `n`. `prefix` tells the staves apart. */
|
|
60
|
+
const decorate = (note: SmoNote, n: number, prefix: string, skipSome: boolean = false) => {
|
|
61
|
+
note.textModifiers = [];
|
|
62
|
+
note.articulations = [];
|
|
63
|
+
note.ornaments = [];
|
|
64
|
+
note.addLyric(new SmoLyric({ ...SmoLyric.defaults, text: `${prefix}ly${n}`, verse: 0, parser: SmoLyric.parsers.lyric } as any));
|
|
65
|
+
note.addAnnotation(new SmoLyric({ ...SmoLyric.defaults, text: `${prefix}an${n}`, verse: 0, parser: SmoLyric.parsers.annotation } as any));
|
|
66
|
+
note.addLyric(new SmoLyric({ ...SmoLyric.defaults, text: CHORDS[n % CHORDS.length], verse: 0, parser: SmoLyric.parsers.chord } as any));
|
|
67
|
+
note.addDynamic(new SmoDynamicText({ ...SmoDynamicText.defaults, text: DYNAMICS[n % DYNAMICS.length] } as any));
|
|
68
|
+
if (!skipSome) {
|
|
69
|
+
note.setArticulation(new SmoArticulation({ ...SmoArticulation.defaults, articulation: ARTICULATIONS[n % ARTICULATIONS.length] } as any), true);
|
|
70
|
+
note.setOrnament(new SmoOrnament({ ...SmoOrnament.defaults, ornament: ORNAMENTS[n % ORNAMENTS.length] } as any), true);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** Replace the notes of the first voice of a measure with notes of the given durations (they must add up to the measure) */
|
|
75
|
+
const setRhythm = (measure: SmoMeasure, durations: number[], letter: string, octave: number) => {
|
|
76
|
+
const proto = measure.voices[0].notes[0];
|
|
77
|
+
measure.voices[0].notes = durations.map((d) => {
|
|
78
|
+
const note = SmoNote.cloneWithDuration(proto, { numerator: d, denominator: 1, remainder: 0 });
|
|
79
|
+
note.noteType = 'n';
|
|
80
|
+
note.pitches = [{ letter: letter as any, accidental: 'n', octave }];
|
|
81
|
+
return note;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* `staves` staves of 4 measures of 4 quarter notes. Staff 0 notes are c4 with markings tagged 'S'; every
|
|
87
|
+
* other staff has g3 notes with its own markings tagged 'D1', 'D2'... Every 3rd note of staff 0 has no
|
|
88
|
+
* articulation or ornament.
|
|
89
|
+
*/
|
|
90
|
+
const buildScore = (staves: number = 2): SmoScore => {
|
|
91
|
+
const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
|
|
92
|
+
while (score.staves[0].measures.length < 4) {
|
|
93
|
+
score.addMeasure(score.staves[0].measures.length - 1);
|
|
94
|
+
}
|
|
95
|
+
for (let s = 1; s < staves; ++s) {
|
|
96
|
+
const params = SmoSystemStaff.defaults;
|
|
97
|
+
params.staffId = s;
|
|
98
|
+
params.measureInstrumentMap = { 0: new SmoInstrument(SmoInstrument.defaults) } as any;
|
|
99
|
+
score.addStaff(params);
|
|
100
|
+
}
|
|
101
|
+
score.staves.forEach((staff, s) => {
|
|
102
|
+
staff.measures.forEach((measure, m) => {
|
|
103
|
+
setRhythm(measure, [QUARTER, QUARTER, QUARTER, QUARTER], s === 0 ? 'c' : 'g', s === 0 ? 4 : 3);
|
|
104
|
+
measure.voices[0].notes.forEach((note, t) => {
|
|
105
|
+
const n = m * 4 + t;
|
|
106
|
+
// the other staves use different markings from staff 0, so a paste is always visible
|
|
107
|
+
decorate(note, s === 0 ? n : n + 3, s === 0 ? 'S' : `D${s}`, s === 0 && n % 3 === 2);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
return score;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const noteAt = (score: SmoScore, staff: number, measure: number, tick: number): SmoNote =>
|
|
115
|
+
score.staves[staff].measures[measure].voices[0].notes[tick];
|
|
116
|
+
const markingsAt = (score: SmoScore, staff: number, measure: number, tick: number): Markings =>
|
|
117
|
+
markings(noteAt(score, staff, measure, tick));
|
|
118
|
+
/** Pitches, durations and note types of every note, as text */
|
|
119
|
+
const structure = (score: SmoScore): string => JSON.stringify(score.staves.map((staff) => staff.measures.map((measure) =>
|
|
120
|
+
measure.voices.map((voice) => voice.notes.map((note) =>
|
|
121
|
+
[note.noteType, JSON.stringify(note.pitches), note.tickCount, note.stemTicks])))));
|
|
122
|
+
/** Every note's markings, keyed by position, for before and after comparisons */
|
|
123
|
+
const allMarkings = (score: SmoScore): Record<string, Markings> => {
|
|
124
|
+
const rv: Record<string, Markings> = {};
|
|
125
|
+
score.staves.forEach((staff, s) => staff.measures.forEach((measure, m) =>
|
|
126
|
+
measure.voices[0].notes.forEach((note, t) => {
|
|
127
|
+
rv[`${s}-${m}-${t}`] = markings(note);
|
|
128
|
+
})));
|
|
129
|
+
return rv;
|
|
130
|
+
};
|
|
131
|
+
const copyNotes = (score: SmoScore, staff: number, measure: number, firstTick: number, lastMeasure: number, lastTick: number): PasteBuffer => {
|
|
132
|
+
const buffer = new PasteBuffer();
|
|
133
|
+
const selections: SmoSelection[] = [];
|
|
134
|
+
for (let m = measure; m <= lastMeasure; ++m) {
|
|
135
|
+
const notes = score.staves[staff].measures[m].voices[0].notes;
|
|
136
|
+
const from = m === measure ? firstTick : 0;
|
|
137
|
+
const to = m === lastMeasure ? lastTick : notes.length - 1;
|
|
138
|
+
for (let t = from; t <= to; ++t) {
|
|
139
|
+
selections.push(SmoSelection.noteSelection(score, staff, m, 0, t)!);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
buffer.setSelections(score, selections);
|
|
143
|
+
return buffer;
|
|
144
|
+
};
|
|
145
|
+
const dest = (staff: number, measure: number, tick: number = 0): SmoSelector =>
|
|
146
|
+
({ staff, measure, voice: 0, tick, pitches: [] });
|
|
147
|
+
/** Which notes of a staff had any of their markings change, as 'measure-tick' text */
|
|
148
|
+
const changedNotes = (before: Record<string, Markings>, score: SmoScore, staff: number): string[] => {
|
|
149
|
+
const after = allMarkings(score);
|
|
150
|
+
return Object.keys(after).filter((key) => key.startsWith(`${staff}-`) &&
|
|
151
|
+
JSON.stringify(before[key]) !== JSON.stringify(after[key])).map((key) => key.substring(2));
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// ---- Foundation: hasNotes, alignment, extent ----
|
|
155
|
+
{
|
|
156
|
+
const score = buildScore();
|
|
157
|
+
const empty = new PasteBuffer();
|
|
158
|
+
check('hasNotes is false before a copy', empty.hasNotes() === false);
|
|
159
|
+
empty.setScore(score);
|
|
160
|
+
check('alignment of no notes is empty', empty.alignAttributeNotes(dest(1, 0), []).length === 0);
|
|
161
|
+
check('extent is null with nothing copied', empty.getAttributePasteExtent(dest(1, 0)) === null);
|
|
162
|
+
|
|
163
|
+
const buffer = copyNotes(score, 0, 0, 0, 1, 3);
|
|
164
|
+
check('hasNotes is true after a copy', buffer.hasNotes() === true);
|
|
165
|
+
check('hasNotes is false after clearSelections', (() => { const b = copyNotes(score, 0, 0, 0, 0, 3); b.clearSelections(); return !b.hasNotes(); })());
|
|
166
|
+
const before = structure(score);
|
|
167
|
+
const beforeMarkings = JSON.stringify(allMarkings(score));
|
|
168
|
+
const pairs = buffer.alignAttributeNotes(dest(1, 0), buffer.notes[0]);
|
|
169
|
+
check('same rhythm: 8 copied notes pair with 8 destination notes', pairs.length === 8);
|
|
170
|
+
check('same rhythm: note i pairs with note i', pairs.every((pair, i) =>
|
|
171
|
+
pair.destination.selector.measure === Math.floor(i / 4) && pair.destination.selector.tick === i % 4 &&
|
|
172
|
+
pair.destination.selector.staff === 1));
|
|
173
|
+
check('alignment changes nothing', structure(score) === before && JSON.stringify(allMarkings(score)) === beforeMarkings);
|
|
174
|
+
const extent = buffer.getAttributePasteExtent(dest(1, 0));
|
|
175
|
+
check('extent is the measures of the pairs', extent !== null && extent.firstMeasure === 0 && extent.lastMeasure === 1);
|
|
176
|
+
check('extent changes nothing', structure(score) === before && JSON.stringify(allMarkings(score)) === beforeMarkings);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ---- US1: each kind alone, all kinds, nothing else changes ----
|
|
180
|
+
{
|
|
181
|
+
const run = (kinds: PasteAttributeKind[], mode: PasteAttributeMode) => {
|
|
182
|
+
const score = buildScore();
|
|
183
|
+
const buffer = copyNotes(score, 0, 0, 0, 1, 3);
|
|
184
|
+
const before = allMarkings(score);
|
|
185
|
+
const shape = structure(score);
|
|
186
|
+
buffer.pasteAttributes(dest(1, 0), { kinds, mode });
|
|
187
|
+
return { score, before, shape };
|
|
188
|
+
};
|
|
189
|
+
KINDS.forEach((kind) => {
|
|
190
|
+
const { score, before, shape } = run([kind], 'replace');
|
|
191
|
+
let ticked = true;
|
|
192
|
+
let others = true;
|
|
193
|
+
for (let i = 0; i < 8; ++i) {
|
|
194
|
+
const m = Math.floor(i / 4);
|
|
195
|
+
const t = i % 4;
|
|
196
|
+
const got = markingsAt(score, 1, m, t);
|
|
197
|
+
const source = markingsAt(score, 0, m, t);
|
|
198
|
+
const was = before[`1-${m}-${t}`];
|
|
199
|
+
// the ticked kind is what the copied note had, the others are untouched
|
|
200
|
+
if (!same(got[kind], source[kind])) {
|
|
201
|
+
ticked = false;
|
|
202
|
+
}
|
|
203
|
+
KINDS.filter((k) => k !== kind).forEach((k) => {
|
|
204
|
+
if (!same(got[k], was[k])) {
|
|
205
|
+
others = false;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
check(`${kind} alone: the destination gets the copied ${kind}`, ticked);
|
|
210
|
+
check(`${kind} alone: the other kinds are untouched`, others);
|
|
211
|
+
check(`${kind} alone: notes after the paste are untouched`, JSON.stringify(markingsAt(score, 1, 2, 0)) === JSON.stringify(before['1-2-0']));
|
|
212
|
+
check(`${kind} alone: pitches and durations are unchanged`, structure(score) === shape);
|
|
213
|
+
});
|
|
214
|
+
{
|
|
215
|
+
const { score, shape } = run([...KINDS], 'replace');
|
|
216
|
+
let all = true;
|
|
217
|
+
for (let i = 0; i < 8; ++i) {
|
|
218
|
+
const got = markingsAt(score, 1, Math.floor(i / 4), i % 4);
|
|
219
|
+
const source = markingsAt(score, 0, Math.floor(i / 4), i % 4);
|
|
220
|
+
KINDS.forEach((k) => {
|
|
221
|
+
if (!same(got[k], source[k])) {
|
|
222
|
+
all = false;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
check('all six kinds: the destination matches the source', all);
|
|
227
|
+
check('all six kinds: pitches and durations are unchanged', structure(score) === shape);
|
|
228
|
+
}
|
|
229
|
+
{
|
|
230
|
+
const score = buildScore();
|
|
231
|
+
const buffer = copyNotes(score, 0, 0, 0, 1, 3);
|
|
232
|
+
const before = JSON.stringify(allMarkings(score));
|
|
233
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: [], mode: 'replace' });
|
|
234
|
+
check('no kinds ticked: nothing changes', JSON.stringify(allMarkings(score)) === before);
|
|
235
|
+
}
|
|
236
|
+
{
|
|
237
|
+
// the pasted markings are independent copies
|
|
238
|
+
const score = buildScore();
|
|
239
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
240
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: [...KINDS], mode: 'replace' });
|
|
241
|
+
const pasted = noteAt(score, 1, 0, 0);
|
|
242
|
+
const original = noteAt(score, 0, 0, 0);
|
|
243
|
+
const pastedLyric = pasted.getTrueLyrics()[0];
|
|
244
|
+
const originalLyric = original.getTrueLyrics()[0];
|
|
245
|
+
check('a pasted lyric is not the copied object', pastedLyric !== originalLyric && pastedLyric.attrs.id !== originalLyric.attrs.id);
|
|
246
|
+
pastedLyric.text = 'changed';
|
|
247
|
+
pasted.getModifiers('SmoDynamicText').forEach((d) => { (d as SmoDynamicText).text = 'changed'; });
|
|
248
|
+
pasted.articulations.forEach((a) => { a.articulation = 'changed'; });
|
|
249
|
+
pasted.ornaments.forEach((o) => { o.ornament = 'changed'; });
|
|
250
|
+
check('editing pasted markings leaves the source score alone', markings(original).lyrics[0] === '0:Sly0' &&
|
|
251
|
+
markings(original).dynamics[0] === 'pp' && markings(original).articulations[0] === 'accent');
|
|
252
|
+
const copiedAgain = buffer.notes[0][0].note;
|
|
253
|
+
check('editing pasted markings leaves the copy buffer alone', markings(copiedAgain).lyrics[0] === '0:Sly0');
|
|
254
|
+
// paste a second time from the same copy
|
|
255
|
+
buffer.pasteAttributes(dest(1, 2), { kinds: [...KINDS], mode: 'replace' });
|
|
256
|
+
check('the copy can be pasted again', markingsAt(score, 1, 2, 0).lyrics[0] === '0:Sly0' &&
|
|
257
|
+
markingsAt(score, 1, 2, 3).lyrics[0] === '0:Sly3');
|
|
258
|
+
}
|
|
259
|
+
{
|
|
260
|
+
// serialization
|
|
261
|
+
const score = buildScore();
|
|
262
|
+
const buffer = copyNotes(score, 0, 0, 0, 1, 3);
|
|
263
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: [...KINDS], mode: 'replace' });
|
|
264
|
+
const reloaded = SmoScore.deserialize(JSON.stringify(score.serialize({ skipStaves: false, useDictionary: false, preserveStaffIds: false })));
|
|
265
|
+
let equal = true;
|
|
266
|
+
for (let i = 0; i < 8; ++i) {
|
|
267
|
+
if (JSON.stringify(markingsAt(reloaded, 1, Math.floor(i / 4), i % 4)) !== JSON.stringify(markingsAt(score, 1, Math.floor(i / 4), i % 4))) {
|
|
268
|
+
equal = false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
check('pasted markings survive serialize and deserialize', equal);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ---- US2: replace or add ----
|
|
276
|
+
{
|
|
277
|
+
const score = buildScore();
|
|
278
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
279
|
+
// source note 2 (n % 3 === 2) has no articulations or ornaments
|
|
280
|
+
check('setup: source note 2 has no articulation', markingsAt(score, 0, 0, 2).articulations.length === 0);
|
|
281
|
+
const before = allMarkings(score);
|
|
282
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['articulations'], mode: 'replace' });
|
|
283
|
+
check('replace: a destination note whose copied note has none ends with none', markingsAt(score, 1, 0, 2).articulations.length === 0);
|
|
284
|
+
check('replace: others get the copied articulation', markingsAt(score, 1, 0, 0).articulations[0] === 'accent' &&
|
|
285
|
+
markingsAt(score, 1, 0, 1).articulations[0] === 'staccato');
|
|
286
|
+
check('replace: ornaments were not ticked, so they are untouched', JSON.stringify(markingsAt(score, 1, 0, 2).ornaments) ===
|
|
287
|
+
JSON.stringify(before['1-0-2'].ornaments));
|
|
288
|
+
check('replace: only aligned notes are cleared', JSON.stringify(markingsAt(score, 1, 1, 0)) === JSON.stringify(before['1-1-0']));
|
|
289
|
+
}
|
|
290
|
+
{
|
|
291
|
+
const score = buildScore();
|
|
292
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
293
|
+
const before = allMarkings(score);
|
|
294
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['articulations', 'ornaments', 'annotations', 'chords'], mode: 'add' });
|
|
295
|
+
const got = markingsAt(score, 1, 0, 0);
|
|
296
|
+
const own = before['1-0-0'];
|
|
297
|
+
const src = markingsAt(score, 0, 0, 0);
|
|
298
|
+
check('add: articulations are the destination\'s and the copied ones', same(got.articulations, [...own.articulations, ...src.articulations]));
|
|
299
|
+
check('add: ornaments are the destination\'s and the copied ones', same(got.ornaments, [...own.ornaments, ...src.ornaments]));
|
|
300
|
+
check('add: annotation and chord of the same verse are superseded, never doubled', got.annotations.length === 1 && got.chords.length === 1 &&
|
|
301
|
+
got.annotations[0] === src.annotations[0] && got.chords[0] === src.chords[0]);
|
|
302
|
+
check('add: a note whose copied note has none keeps its own', same(markingsAt(score, 1, 0, 2).articulations, before['1-0-2'].articulations));
|
|
303
|
+
check('add: unticked kinds untouched', JSON.stringify(got.lyrics) === JSON.stringify(own.lyrics) && JSON.stringify(got.dynamics) === JSON.stringify(own.dynamics));
|
|
304
|
+
}
|
|
305
|
+
{
|
|
306
|
+
// a dynamic over a dynamic, and verses
|
|
307
|
+
const score = buildScore();
|
|
308
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 0);
|
|
309
|
+
const target = noteAt(score, 1, 0, 0);
|
|
310
|
+
target.addLyric(new SmoLyric({ ...SmoLyric.defaults, text: 'verse two', verse: 1, parser: SmoLyric.parsers.lyric } as any));
|
|
311
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['dynamics', 'lyrics'], mode: 'add' });
|
|
312
|
+
const got = markings(target);
|
|
313
|
+
check('add: a dynamic over a dynamic leaves exactly one, the pasted', got.dynamics.length === 1 && got.dynamics[0] === 'pp');
|
|
314
|
+
check('add: a lyric of the same verse is replaced and another verse kept', same(got.lyrics, ['0:Sly0', '1:verse two']), got.lyrics.join('|'));
|
|
315
|
+
}
|
|
316
|
+
{
|
|
317
|
+
// replace with several kinds replaces only the ticked ones
|
|
318
|
+
const score = buildScore();
|
|
319
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
320
|
+
const before = allMarkings(score);
|
|
321
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['dynamics', 'chords'], mode: 'replace' });
|
|
322
|
+
const got = markingsAt(score, 1, 0, 1);
|
|
323
|
+
check('replace with two kinds: both replaced', same(got.dynamics, markingsAt(score, 0, 0, 1).dynamics) && same(got.chords, markingsAt(score, 0, 0, 1).chords));
|
|
324
|
+
check('replace with two kinds: the other four untouched', same(got.lyrics, before['1-0-1'].lyrics) && same(got.annotations, before['1-0-1'].annotations) &&
|
|
325
|
+
same(got.articulations, before['1-0-1'].articulations) && same(got.ornaments, before['1-0-1'].ornaments));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ---- US3: alignment by elapsed time ----
|
|
329
|
+
{
|
|
330
|
+
// 4 quarters onto 8 eighths: copied notes go to eighths 1, 3, 5, 7
|
|
331
|
+
const score = buildScore();
|
|
332
|
+
setRhythm(score.staves[1].measures[0], new Array(8).fill(EIGHTH), 'g', 3);
|
|
333
|
+
score.staves[1].measures[0].voices[0].notes.forEach((note, t) => decorate(note, 40 + t, 'D1'));
|
|
334
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
335
|
+
const before = allMarkings(score);
|
|
336
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['lyrics'], mode: 'replace' });
|
|
337
|
+
const lyrics = score.staves[1].measures[0].voices[0].notes.map((n) => markings(n).lyrics[0]);
|
|
338
|
+
check('4 quarters onto 8 eighths: copied lyrics land on eighths 1, 3, 5, 7',
|
|
339
|
+
lyrics[0] === '0:Sly0' && lyrics[2] === '0:Sly1' && lyrics[4] === '0:Sly2' && lyrics[6] === '0:Sly3', lyrics.join(' '));
|
|
340
|
+
check('4 quarters onto 8 eighths: eighths 2, 4, 6, 8 keep their own lyrics, even in replace mode',
|
|
341
|
+
[1, 3, 5, 7].every((i) => lyrics[i] === before[`1-0-${i}`].lyrics[0]));
|
|
342
|
+
check('4 quarters onto 8 eighths: the extent is measure 0', (() => {
|
|
343
|
+
const e = buffer.getAttributePasteExtent(dest(1, 0));
|
|
344
|
+
return e !== null && e.firstMeasure === 0 && e.lastMeasure === 0;
|
|
345
|
+
})());
|
|
346
|
+
}
|
|
347
|
+
{
|
|
348
|
+
// 2 quarters onto whole notes in two measures: the second copied note reaches the next measure
|
|
349
|
+
const score = buildScore();
|
|
350
|
+
setRhythm(score.staves[1].measures[0], [WHOLE], 'g', 3);
|
|
351
|
+
setRhythm(score.staves[1].measures[1], [WHOLE], 'g', 3);
|
|
352
|
+
decorate(noteAt(score, 1, 0, 0), 50, 'D1');
|
|
353
|
+
decorate(noteAt(score, 1, 1, 0), 51, 'D1');
|
|
354
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 1);
|
|
355
|
+
const pairs = buffer.alignAttributeNotes(dest(1, 0), buffer.notes[0]);
|
|
356
|
+
check('2 quarters onto 2 wholes: the second note goes to the next measure', pairs.length === 2 &&
|
|
357
|
+
pairs[0].destination.selector.measure === 0 && pairs[1].destination.selector.measure === 1);
|
|
358
|
+
const e = buffer.getAttributePasteExtent(dest(1, 0));
|
|
359
|
+
check('2 quarters onto 2 wholes: the extent includes the second measure (longer than the copied time)', e !== null && e.lastMeasure === 1);
|
|
360
|
+
const before = allMarkings(score);
|
|
361
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['lyrics', 'dynamics'], mode: 'replace' });
|
|
362
|
+
check('2 quarters onto 2 wholes: markings arrive in order', markingsAt(score, 1, 0, 0).lyrics[0] === '0:Sly0' &&
|
|
363
|
+
markingsAt(score, 1, 1, 0).lyrics[0] === '0:Sly1');
|
|
364
|
+
const changed = changedNotes(before, score, 1);
|
|
365
|
+
check('2 quarters onto 2 wholes: the extent is exactly the measures edited', changed.length === 2 &&
|
|
366
|
+
Math.min(...changed.map((c) => parseInt(c, 10))) === e!.firstMeasure && Math.max(...changed.map((c) => parseInt(c, 10))) === e!.lastMeasure, changed.join(','));
|
|
367
|
+
}
|
|
368
|
+
{
|
|
369
|
+
// 4 quarters onto [half, quarter, quarter]: the 2nd and 3rd copied notes both go to the first quarter
|
|
370
|
+
const score = buildScore();
|
|
371
|
+
setRhythm(score.staves[1].measures[0], [2 * QUARTER, QUARTER, QUARTER], 'g', 3);
|
|
372
|
+
score.staves[1].measures[0].voices[0].notes.forEach((note, t) => decorate(note, 60 + t, 'D1'));
|
|
373
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
374
|
+
const pairs = buffer.alignAttributeNotes(dest(1, 0), buffer.notes[0]);
|
|
375
|
+
check('4 quarters onto half, quarter, quarter: pairing is 0, 1, 1, 2',
|
|
376
|
+
JSON.stringify(pairs.map((p) => p.destination.selector.tick)) === '[0,1,1,2]', JSON.stringify(pairs.map((p) => p.destination.selector.tick)));
|
|
377
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['articulations', 'dynamics', 'lyrics'], mode: 'replace' });
|
|
378
|
+
const second = markingsAt(score, 1, 0, 1);
|
|
379
|
+
check('a destination note aligned to two copied notes gets both articulations', same(second.articulations, ['staccato']
|
|
380
|
+
.concat(markingsAt(score, 0, 0, 2).articulations)));
|
|
381
|
+
check('a single-valued kind keeps the last copied note\'s (dynamic and lyric)',
|
|
382
|
+
second.dynamics.length === 1 && second.dynamics[0] === markingsAt(score, 0, 0, 2).dynamics[0] &&
|
|
383
|
+
second.lyrics.length === 1 && second.lyrics[0] === '0:Sly2');
|
|
384
|
+
check('the note after gets the last copied note', markingsAt(score, 1, 0, 2).lyrics[0] === '0:Sly3');
|
|
385
|
+
}
|
|
386
|
+
{
|
|
387
|
+
// the copy runs past the end of the destination part
|
|
388
|
+
const score = buildScore();
|
|
389
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
390
|
+
const before = allMarkings(score);
|
|
391
|
+
const shape = structure(score);
|
|
392
|
+
buffer.pasteAttributes(dest(1, 3, 2), { kinds: [...KINDS], mode: 'replace' });
|
|
393
|
+
const changed = changedNotes(before, score, 1);
|
|
394
|
+
check('copy longer than the destination: stops at the end of the part, no error', changed.join(',') === '3-2,3-3', changed.join(','));
|
|
395
|
+
check('copy longer than the destination: no notes added', structure(score) === shape);
|
|
396
|
+
const e = buffer.getAttributePasteExtent(dest(1, 3, 2));
|
|
397
|
+
check('copy longer than the destination: extent is the last measure', e !== null && e.firstMeasure === 3 && e.lastMeasure === 3);
|
|
398
|
+
}
|
|
399
|
+
{
|
|
400
|
+
// rests
|
|
401
|
+
const score = buildScore();
|
|
402
|
+
const rests = score.staves[1].measures[0].voices[0].notes;
|
|
403
|
+
rests[1].noteType = 'r';
|
|
404
|
+
rests[2].noteType = 'r';
|
|
405
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
406
|
+
// a copied rest counts too
|
|
407
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['lyrics'], mode: 'replace' });
|
|
408
|
+
check('rests in the destination are aligned like notes and stay rests', rests[1].noteType === 'r' && rests[2].noteType === 'r' &&
|
|
409
|
+
markings(rests[1]).lyrics[0] === '0:Sly1' && markings(rests[2]).lyrics[0] === '0:Sly2');
|
|
410
|
+
const score2 = buildScore();
|
|
411
|
+
noteAt(score2, 0, 0, 1).noteType = 'r';
|
|
412
|
+
const buffer2 = copyNotes(score2, 0, 0, 0, 0, 3);
|
|
413
|
+
buffer2.pasteAttributes(dest(1, 0), { kinds: ['dynamics'], mode: 'replace' });
|
|
414
|
+
check('a copied rest is aligned by its length like a note', buffer2.notes[0].length === 4 &&
|
|
415
|
+
markingsAt(score2, 1, 0, 2).dynamics[0] === markingsAt(score2, 0, 0, 2).dynamics[0]);
|
|
416
|
+
}
|
|
417
|
+
{
|
|
418
|
+
// a copy of two measures keeps lining up across the barline
|
|
419
|
+
const score = buildScore();
|
|
420
|
+
const buffer = copyNotes(score, 0, 0, 0, 1, 3);
|
|
421
|
+
const before = allMarkings(score);
|
|
422
|
+
buffer.pasteAttributes(dest(1, 2), { kinds: ['lyrics'], mode: 'replace' });
|
|
423
|
+
check('two measures onto two measures', markingsAt(score, 1, 2, 0).lyrics[0] === '0:Sly0' && markingsAt(score, 1, 3, 3).lyrics[0] === '0:Sly7');
|
|
424
|
+
const e = buffer.getAttributePasteExtent(dest(1, 2));
|
|
425
|
+
const changed = changedNotes(before, score, 1);
|
|
426
|
+
check('two measures: the extent is exactly the measures edited', e !== null && e.firstMeasure === 2 && e.lastMeasure === 3 &&
|
|
427
|
+
changed.length === 8 && changed.every((c) => c.startsWith('2-') || c.startsWith('3-')));
|
|
428
|
+
// starting in the middle of a measure
|
|
429
|
+
const score2 = buildScore();
|
|
430
|
+
const buffer2 = copyNotes(score2, 0, 0, 0, 1, 3);
|
|
431
|
+
buffer2.pasteAttributes(dest(1, 1, 2), { kinds: ['lyrics'], mode: 'replace' });
|
|
432
|
+
check('starting mid-measure: the first copied note goes to the note under the cursor', markingsAt(score2, 1, 1, 2).lyrics[0] === '0:Sly0' &&
|
|
433
|
+
markingsAt(score2, 1, 2, 1).lyrics[0] === '0:Sly3');
|
|
434
|
+
}
|
|
435
|
+
{
|
|
436
|
+
// two staves, three-staff score
|
|
437
|
+
const score = buildScore(3);
|
|
438
|
+
const buffer = new PasteBuffer();
|
|
439
|
+
const sels: SmoSelection[] = [];
|
|
440
|
+
[0, 1].forEach((staff) => {
|
|
441
|
+
for (let t = 0; t < 4; ++t) {
|
|
442
|
+
sels.push(SmoSelection.noteSelection(score, staff, 0, 0, t)!);
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
buffer.setSelections(score, sels);
|
|
446
|
+
const before = allMarkings(score);
|
|
447
|
+
buffer.pasteAttributes(dest(1, 1), { kinds: ['lyrics'], mode: 'replace' });
|
|
448
|
+
check('two staves: the first staff goes to the cursor staff', markingsAt(score, 1, 1, 0).lyrics[0] === '0:Sly0');
|
|
449
|
+
check('two staves: the second staff goes to the staff below', markingsAt(score, 2, 1, 0).lyrics[0] === before['1-0-0'].lyrics[0]);
|
|
450
|
+
check('two staves: the staff above is untouched', JSON.stringify(allMarkings(score)['0-1-0']) === JSON.stringify(before['0-1-0']));
|
|
451
|
+
// no staff below the cursor staff: only the first is pasted
|
|
452
|
+
const score2 = buildScore(3);
|
|
453
|
+
const buffer2 = new PasteBuffer();
|
|
454
|
+
const sels2: SmoSelection[] = [];
|
|
455
|
+
[0, 1].forEach((staff) => {
|
|
456
|
+
for (let t = 0; t < 4; ++t) {
|
|
457
|
+
sels2.push(SmoSelection.noteSelection(score2, staff, 0, 0, t)!);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
buffer2.setSelections(score2, sels2);
|
|
461
|
+
buffer2.pasteAttributes(dest(2, 1), { kinds: ['lyrics'], mode: 'replace' });
|
|
462
|
+
check('two staves with no staff below: the first staff is pasted and nothing fails', markingsAt(score2, 2, 1, 0).lyrics[0] === '0:Sly0');
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// ---- US4: chords follow the destination's transposition; the rest is as it is ----
|
|
466
|
+
{
|
|
467
|
+
const sourceChords = (score: SmoScore) => [0, 1, 2, 3].map((t) => markingsAt(score, 0, 0, t).chords[0]);
|
|
468
|
+
// a concert-pitch part in another key: chord names are not changed
|
|
469
|
+
const concert = buildScore();
|
|
470
|
+
concert.staves[1].measures.forEach((measure) => measure.setKeySignature('d'));
|
|
471
|
+
copyNotes(concert, 0, 0, 0, 0, 3).pasteAttributes(dest(1, 0), { kinds: ['chords'], mode: 'replace' });
|
|
472
|
+
check('chords onto a concert-pitch part in another key are not changed', JSON.stringify([0, 1, 2, 3].map((t) => markingsAt(concert, 1, 0, t).chords[0])) ===
|
|
473
|
+
JSON.stringify(sourceChords(concert)));
|
|
474
|
+
// a transposing part: chords are spelled for it (written a whole step higher)
|
|
475
|
+
const transposing = buildScore();
|
|
476
|
+
transposing.staves[1].measures.forEach((measure) => {
|
|
477
|
+
measure.transposeIndex = 2;
|
|
478
|
+
measure.setKeySignature('d');
|
|
479
|
+
});
|
|
480
|
+
const buffer = copyNotes(transposing, 0, 0, 0, 0, 3);
|
|
481
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['chords'], mode: 'replace' });
|
|
482
|
+
const expected = [0, 1, 2, 3].map((t) => SmoLyric.transposeChordToKey(
|
|
483
|
+
noteAt(transposing, 0, 0, t).getChords()[0], 2, 'c', 'd').getText());
|
|
484
|
+
const got = [0, 1, 2, 3].map((t) => markingsAt(transposing, 1, 0, t).chords[0]);
|
|
485
|
+
check('chords onto a transposing part are spelled for it (C F G Am to D G A Bm)', JSON.stringify(got) === JSON.stringify(expected) &&
|
|
486
|
+
JSON.stringify(got) === JSON.stringify(['D', 'G', 'A', 'Bm']), got.join(' '));
|
|
487
|
+
check('the copied chords are not changed by pasting', JSON.stringify(sourceChords(transposing)) === JSON.stringify(['C', 'F', 'G', 'Am']));
|
|
488
|
+
|
|
489
|
+
// everything else is copied as is, with all its settings
|
|
490
|
+
const other = buildScore();
|
|
491
|
+
other.staves[1].measures.forEach((measure) => {
|
|
492
|
+
measure.transposeIndex = 2;
|
|
493
|
+
measure.setKeySignature('d');
|
|
494
|
+
});
|
|
495
|
+
noteAt(other, 0, 0, 0).getModifiers('SmoDynamicText').forEach((d) => {
|
|
496
|
+
(d as SmoDynamicText).xOffset = -7;
|
|
497
|
+
(d as SmoDynamicText).yOffsetPixels = 5;
|
|
498
|
+
});
|
|
499
|
+
noteAt(other, 0, 0, 0).getTrueLyrics()[0].translateX = 9;
|
|
500
|
+
const buf = copyNotes(other, 0, 0, 0, 0, 3);
|
|
501
|
+
const ownChords = markings(noteAt(other, 1, 0, 0)).chords;
|
|
502
|
+
buf.pasteAttributes(dest(1, 0), { kinds: ['dynamics', 'lyrics', 'annotations', 'articulations', 'ornaments'], mode: 'replace' });
|
|
503
|
+
const text = (mods: any[]) => JSON.stringify(mods.map((m) => m.serialize()));
|
|
504
|
+
const a = noteAt(other, 0, 0, 0);
|
|
505
|
+
const b = noteAt(other, 1, 0, 0);
|
|
506
|
+
check('dynamics keep their offsets on a transposing part', text(b.getModifiers('SmoDynamicText')) === text(a.getModifiers('SmoDynamicText')) &&
|
|
507
|
+
(b.getModifiers('SmoDynamicText')[0] as SmoDynamicText).xOffset === -7);
|
|
508
|
+
check('lyrics and annotations keep their settings on a transposing part', text(b.getTrueLyrics()) === text(a.getTrueLyrics()) &&
|
|
509
|
+
text(b.getAnnotations()) === text(a.getAnnotations()) && b.getTrueLyrics()[0].translateX === 9);
|
|
510
|
+
check('articulations and ornaments are identical on a transposing part', text(b.getArticulations()) === text(a.getArticulations()) &&
|
|
511
|
+
text(b.getOrnaments()) === text(a.getOrnaments()));
|
|
512
|
+
check('chords were not ticked, so the destination keeps its own', ownChords.length === 1 && same(markings(b).chords, ownChords) &&
|
|
513
|
+
!same(markings(b).chords, markings(a).chords));
|
|
514
|
+
}
|
|
515
|
+
{
|
|
516
|
+
// two pastes of different kinds: the second leaves the first alone
|
|
517
|
+
const score = buildScore();
|
|
518
|
+
const buffer = copyNotes(score, 0, 0, 0, 0, 3);
|
|
519
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['lyrics'], mode: 'replace' });
|
|
520
|
+
buffer.pasteAttributes(dest(1, 0), { kinds: ['dynamics'], mode: 'replace' });
|
|
521
|
+
check('a second paste of another kind leaves the first alone', markingsAt(score, 1, 0, 1).lyrics[0] === '0:Sly1' &&
|
|
522
|
+
markingsAt(score, 1, 0, 1).dynamics[0] === 'p');
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// ---- removeAllAnnotations only removes annotations ----
|
|
526
|
+
{
|
|
527
|
+
const note = buildScore().staves[0].measures[0].voices[0].notes[0];
|
|
528
|
+
const before = markings(note);
|
|
529
|
+
note.removeAllAnnotations();
|
|
530
|
+
const after = markings(note);
|
|
531
|
+
check('removeAllAnnotations removes the annotation', before.annotations.length === 1 && after.annotations.length === 0);
|
|
532
|
+
check('removeAllAnnotations keeps lyrics, chords and dynamics', same(after.lyrics, before.lyrics) && same(after.chords, before.chords) &&
|
|
533
|
+
same(after.dynamics, before.dynamics));
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (failures > 0) {
|
|
537
|
+
console.log(`${failures} check(s) failed`);
|
|
538
|
+
process.exitCode = 1;
|
|
539
|
+
} else {
|
|
540
|
+
console.log('all checks passed');
|
|
541
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless checks for the Quick Beam and Stem Direction menu choices: autobeaming selected notes, and
|
|
3
|
+
* setting the stem direction of selected notes to up, down or auto.
|
|
4
|
+
*
|
|
5
|
+
* Run with: npm run test:quick-beam
|
|
6
|
+
*/
|
|
7
|
+
import { SmoScore } from '../src/smo/data/score';
|
|
8
|
+
import { SmoNote } from '../src/smo/data/note';
|
|
9
|
+
import { SmoTimeSignature } from '../src/smo/data/measureModifiers';
|
|
10
|
+
import { SmoBeamer } from '../src/smo/xform/beamers';
|
|
11
|
+
import { SmoOperation } from '../src/smo/xform/operations';
|
|
12
|
+
import { SmoSelection } from '../src/smo/xform/selections';
|
|
13
|
+
import { noteModifierDynamicCtorInit } from '../src/smo/data/noteModifiers';
|
|
14
|
+
import { measureModifierDynamicCtorInit } from '../src/smo/data/measureModifiers';
|
|
15
|
+
import { staffModifierDynamicCtorInit } from '../src/smo/data/staffModifiers';
|
|
16
|
+
import { scoreModifierDynamicCtorInit } from '../src/smo/data/scoreModifiers';
|
|
17
|
+
|
|
18
|
+
noteModifierDynamicCtorInit();
|
|
19
|
+
measureModifierDynamicCtorInit();
|
|
20
|
+
staffModifierDynamicCtorInit();
|
|
21
|
+
scoreModifierDynamicCtorInit();
|
|
22
|
+
|
|
23
|
+
let failures = 0;
|
|
24
|
+
const check = (name: string, condition: boolean, detail?: string) => {
|
|
25
|
+
if (condition) {
|
|
26
|
+
console.log(`PASS ${name}`);
|
|
27
|
+
} else {
|
|
28
|
+
failures += 1;
|
|
29
|
+
console.log(`FAIL ${name}${detail ? ' -- ' + detail : ''}`);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const E = 2048;
|
|
34
|
+
/** A score whose first measure has the given meter and n eighth notes */
|
|
35
|
+
const scoreWith = (actualBeats: number, beatDuration: number, count: number): SmoScore => {
|
|
36
|
+
const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
|
|
37
|
+
const measure = score.staves[0].measures[0];
|
|
38
|
+
const tsParams = SmoTimeSignature.defaults;
|
|
39
|
+
tsParams.times = [{ actualBeats, beatDuration }];
|
|
40
|
+
measure.timeSignature = new SmoTimeSignature(tsParams);
|
|
41
|
+
const proto = measure.voices[0].notes[0];
|
|
42
|
+
measure.voices[0].notes = new Array(count).fill(E).map((tt) => {
|
|
43
|
+
const note = SmoNote.cloneWithDuration(proto, tt);
|
|
44
|
+
note.noteType = 'n';
|
|
45
|
+
return note;
|
|
46
|
+
});
|
|
47
|
+
return score;
|
|
48
|
+
};
|
|
49
|
+
const select = (score: SmoScore, from: number, to: number): SmoSelection[] => {
|
|
50
|
+
const rv: SmoSelection[] = [];
|
|
51
|
+
for (let i = from; i <= to; ++i) {
|
|
52
|
+
rv.push(SmoSelection.noteSelection(score, 0, 0, 0, i)!);
|
|
53
|
+
}
|
|
54
|
+
return rv;
|
|
55
|
+
};
|
|
56
|
+
const notesOf = (score: SmoScore) => score.staves[0].measures[0].voices[0].notes;
|
|
57
|
+
const sizes = (score: SmoScore) => {
|
|
58
|
+
const measure = score.staves[0].measures[0];
|
|
59
|
+
SmoBeamer.applyBeams(measure);
|
|
60
|
+
return measure.beamGroups.map((bg) => bg.notes.length).join(',');
|
|
61
|
+
};
|
|
62
|
+
const { auto, continue: cont, end } = SmoNote.beamStates;
|
|
63
|
+
|
|
64
|
+
// --- autobeam ---
|
|
65
|
+
{
|
|
66
|
+
const score = scoreWith(4, 4, 8);
|
|
67
|
+
const notes = notesOf(score);
|
|
68
|
+
notes[1].beamState = end;
|
|
69
|
+
notes[2].beamState = cont;
|
|
70
|
+
notes[3].beamBeats = 2048;
|
|
71
|
+
notes[3].endBeam = true;
|
|
72
|
+
SmoOperation.autoBeamSelections(score, select(score, 1, 3));
|
|
73
|
+
check('Q1 selected notes go back to the auto beam state', notes.slice(1, 4).every((nn) => nn.beamState === auto));
|
|
74
|
+
check('Q2 selected notes get the default beam length for the meter',
|
|
75
|
+
notes.slice(1, 4).every((nn) => nn.beamBeats === score.preferences.defaultDupleDuration));
|
|
76
|
+
check('Q3 the end-beam flag is cleared', (notes[3].endBeam as boolean) === false);
|
|
77
|
+
}
|
|
78
|
+
{
|
|
79
|
+
const score = scoreWith(6, 8, 6);
|
|
80
|
+
const notes = notesOf(score);
|
|
81
|
+
SmoOperation.autoBeamSelections(score, select(score, 0, 5));
|
|
82
|
+
check('Q4 a triple meter gets the triple default', notes.every((nn) => nn.beamBeats === score.preferences.defaultTripleDuration));
|
|
83
|
+
}
|
|
84
|
+
{
|
|
85
|
+
const score = scoreWith(4, 4, 8);
|
|
86
|
+
const notes = notesOf(score);
|
|
87
|
+
notes[1].beamState = end;
|
|
88
|
+
notes[5].beamState = end;
|
|
89
|
+
SmoOperation.autoBeamSelections(score, select(score, 0, 3));
|
|
90
|
+
check('Q5 notes outside the selection are not changed', notes[5].beamState === end && notes[1].beamState === auto);
|
|
91
|
+
}
|
|
92
|
+
{
|
|
93
|
+
// Autobeaming a hand-beamed 5/8 measure with a grouping brings the grouping back
|
|
94
|
+
const score = scoreWith(5, 8, 5);
|
|
95
|
+
score.staves[0].measures[0].setBeamGroups([3, 2]);
|
|
96
|
+
SmoOperation.beamSelections(score, select(score, 2, 4));
|
|
97
|
+
const handBeamed = sizes(score);
|
|
98
|
+
SmoOperation.autoBeamSelections(score, select(score, 0, 4));
|
|
99
|
+
check('Q6 hand beam, then autobeam, in a measure grouped 3 + 2', handBeamed === '2,3' && sizes(score) === '3,2',
|
|
100
|
+
`${handBeamed} then ${sizes(score)}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// --- stem direction ---
|
|
104
|
+
{
|
|
105
|
+
const score = scoreWith(4, 4, 8);
|
|
106
|
+
const notes = notesOf(score);
|
|
107
|
+
const { up, down, auto: autoFlag } = SmoNote.flagStates;
|
|
108
|
+
SmoOperation.setStemDirection(select(score, 0, 2), up);
|
|
109
|
+
check('D1 up sets every selected note', notes.slice(0, 3).every((nn) => nn.flagState === up) && notes[3].flagState === autoFlag);
|
|
110
|
+
SmoOperation.setStemDirection(select(score, 1, 3), down);
|
|
111
|
+
check('D2 down sets every selected note', notes.slice(1, 4).every((nn) => nn.flagState === down) && notes[0].flagState === up);
|
|
112
|
+
SmoOperation.setStemDirection(select(score, 0, 3), autoFlag);
|
|
113
|
+
check('D3 auto sets every selected note', notes.slice(0, 4).every((nn) => nn.flagState === autoFlag));
|
|
114
|
+
// Mixed selection: setting is explicit, so it does not depend on the first note, unlike the toggle
|
|
115
|
+
notes[0].flagState = up;
|
|
116
|
+
notes[1].flagState = down;
|
|
117
|
+
SmoOperation.setStemDirection(select(score, 0, 1), up);
|
|
118
|
+
check('D4 a mixed selection all becomes the chosen direction', notes[0].flagState === up && notes[1].flagState === up);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (failures > 0) {
|
|
122
|
+
console.log(`${failures} check(s) failed`);
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
} else {
|
|
125
|
+
console.log('all checks passed');
|
|
126
|
+
}
|