smoosic 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/build/smoosic.js +171 -78
  2. package/package.json +82 -77
  3. package/release/smoosic.js +171 -78
  4. package/release/styles/fonts/MaterialIconsOutlined-Regular.otf +0 -0
  5. package/release/styles/menus.css +26 -0
  6. package/specs/022-text-reposition-on-resize/spec.md +1 -0
  7. package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
  8. package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
  9. package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
  10. package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
  11. package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
  12. package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
  13. package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
  14. package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
  15. package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
  16. package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
  17. package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
  18. package/specs/028-unsaved-changes-indicator/plan.md +96 -0
  19. package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
  20. package/specs/028-unsaved-changes-indicator/research.md +68 -0
  21. package/specs/028-unsaved-changes-indicator/spec.md +135 -0
  22. package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
  23. package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
  24. package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
  25. package/specs/029-remove-promise-helpers/data-model.md +45 -0
  26. package/specs/029-remove-promise-helpers/plan.md +86 -0
  27. package/specs/029-remove-promise-helpers/quickstart.md +53 -0
  28. package/specs/029-remove-promise-helpers/research.md +71 -0
  29. package/specs/029-remove-promise-helpers/spec.md +107 -0
  30. package/specs/029-remove-promise-helpers/tasks.md +164 -0
  31. package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
  32. package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
  33. package/specs/030-copy-paste-voices/data-model.md +63 -0
  34. package/specs/030-copy-paste-voices/plan.md +80 -0
  35. package/specs/030-copy-paste-voices/quickstart.md +50 -0
  36. package/specs/030-copy-paste-voices/research.md +80 -0
  37. package/specs/030-copy-paste-voices/spec.md +124 -0
  38. package/specs/030-copy-paste-voices/tasks.md +183 -0
  39. package/specs/031-select-voice/checklists/requirements.md +39 -0
  40. package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
  41. package/specs/031-select-voice/data-model.md +47 -0
  42. package/specs/031-select-voice/plan.md +79 -0
  43. package/specs/031-select-voice/quickstart.md +43 -0
  44. package/specs/031-select-voice/research.md +55 -0
  45. package/specs/031-select-voice/spec.md +113 -0
  46. package/specs/031-select-voice/tasks.md +171 -0
  47. package/src/application/application.ts +464 -459
  48. package/src/common/promiseHelpers.ts +2 -2
  49. package/src/render/audio/samples.ts +117 -118
  50. package/src/render/sui/pageDivisions.ts +58 -0
  51. package/src/render/sui/renderState.ts +469 -464
  52. package/src/render/sui/scoreChangeState.ts +62 -0
  53. package/src/render/sui/scoreView.ts +30 -0
  54. package/src/render/sui/scoreViewOperations.ts +2555 -2380
  55. package/src/render/sui/svgPageMap.ts +16 -17
  56. package/src/render/sui/textEdit.ts +310 -311
  57. package/src/render/sui/tracker.ts +40 -0
  58. package/src/render/vex/vxNote.ts +3 -1
  59. package/src/smo/xform/copypaste.ts +304 -4
  60. package/src/smo/xform/selections.ts +68 -0
  61. package/src/smo/xform/undo.ts +9 -0
  62. package/src/styles/menus.css +26 -0
  63. package/src/ui/buttons/ribbon.ts +3 -1
  64. package/src/ui/components/buttons/sidebar.vue +15 -6
  65. package/src/ui/components/dialogs/library.vue +3 -1
  66. package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
  67. package/src/ui/dialogs/adapter.ts +181 -183
  68. package/src/ui/dialogs/addMeasure.ts +97 -97
  69. package/src/ui/dialogs/annotationVue.ts +56 -56
  70. package/src/ui/dialogs/audioSettings.ts +121 -123
  71. package/src/ui/dialogs/chordChangeVue.ts +46 -46
  72. package/src/ui/dialogs/clefChange.ts +53 -53
  73. package/src/ui/dialogs/customTuplets.ts +95 -96
  74. package/src/ui/dialogs/customTupletsVue.ts +47 -47
  75. package/src/ui/dialogs/dialog.ts +627 -620
  76. package/src/ui/dialogs/durations.ts +34 -34
  77. package/src/ui/dialogs/dynamics.ts +140 -142
  78. package/src/ui/dialogs/factory.ts +198 -198
  79. package/src/ui/dialogs/fileDialogs.ts +245 -179
  80. package/src/ui/dialogs/fonts.ts +93 -93
  81. package/src/ui/dialogs/globalLayout.ts +40 -40
  82. package/src/ui/dialogs/gracenote.ts +31 -31
  83. package/src/ui/dialogs/hairpin.ts +108 -110
  84. package/src/ui/dialogs/hairpinVue.ts +51 -51
  85. package/src/ui/dialogs/instrument.ts +111 -111
  86. package/src/ui/dialogs/keySignature.ts +175 -176
  87. package/src/ui/dialogs/keySignatureVue.ts +47 -47
  88. package/src/ui/dialogs/library.ts +207 -207
  89. package/src/ui/dialogs/libraryVue.ts +62 -48
  90. package/src/ui/dialogs/lyricVue.ts +46 -46
  91. package/src/ui/dialogs/measureFormat.ts +78 -78
  92. package/src/ui/dialogs/microtones.ts +147 -147
  93. package/src/ui/dialogs/noteHead.ts +319 -319
  94. package/src/ui/dialogs/pageLayout.ts +61 -61
  95. package/src/ui/dialogs/partInfo.ts +60 -60
  96. package/src/ui/dialogs/pedalMarking.ts +117 -117
  97. package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
  98. package/src/ui/dialogs/pitch.ts +352 -352
  99. package/src/ui/dialogs/preferences.ts +40 -40
  100. package/src/ui/dialogs/rehearsalMark.ts +64 -64
  101. package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
  102. package/src/ui/dialogs/scoreId.ts +35 -36
  103. package/src/ui/dialogs/scoreView.ts +42 -42
  104. package/src/ui/dialogs/slur.ts +308 -310
  105. package/src/ui/dialogs/slurVue.ts +91 -91
  106. package/src/ui/dialogs/staffGroup.ts +112 -112
  107. package/src/ui/dialogs/tabNote.ts +84 -84
  108. package/src/ui/dialogs/tabStave.ts +182 -182
  109. package/src/ui/dialogs/tempo.ts +261 -263
  110. package/src/ui/dialogs/tempoVue.ts +73 -73
  111. package/src/ui/dialogs/textBlockVue.ts +127 -127
  112. package/src/ui/dialogs/textBracket.ts +114 -116
  113. package/src/ui/dialogs/textBracketVue.ts +56 -56
  114. package/src/ui/dialogs/tie.ts +140 -142
  115. package/src/ui/dialogs/timeSignature.ts +65 -66
  116. package/src/ui/dialogs/transposeScore.ts +39 -39
  117. package/src/ui/dialogs/unsavedChanges.ts +43 -0
  118. package/src/ui/dialogs/volta.ts +120 -122
  119. package/src/ui/dialogs/voltaVue.ts +51 -51
  120. package/src/ui/fileio/library.ts +110 -111
  121. package/src/ui/menus/edit.ts +100 -1
  122. package/src/ui/menus/file.ts +19 -3
  123. package/tests/pageDivisions.ts +156 -0
  124. package/tests/promiseHelpersUsage.ts +142 -0
  125. package/tests/scoreChangeState.ts +102 -0
  126. package/tests/selectVoice.ts +189 -0
  127. package/tests/voiceCopyPaste.ts +417 -0
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Headless checks for the Select Voice logic (SmoSelection.voiceChoices and
3
+ * SmoSelection.getVoiceSelectors). Cases S1-S16 are listed in
4
+ * specs/031-select-voice/contracts/select-voice-contract.md. The tracker mapping and the menu
5
+ * need the renderer and are checked by hand.
6
+ *
7
+ * Run with: npm run test:select-voice
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 { SmoInstrument } from '../src/smo/data/staffModifiers';
14
+ import { SmoSelection, SmoSelector } from '../src/smo/xform/selections';
15
+ import { 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 WHOLE = 16384;
38
+ /** Replace a voice with notes of the given tick lengths, all pitched so they are real notes */
39
+ const setVoice = (measure: SmoMeasure, voice: number, lengths: number[], rests: boolean = false) => {
40
+ while (measure.voices.length <= voice) {
41
+ measure.populateVoice(measure.voices.length);
42
+ }
43
+ const template = measure.voices[voice].notes[0];
44
+ measure.voices[voice].notes = lengths.map((ticks) => {
45
+ const note = SmoNote.clone(template);
46
+ note.ticks = { numerator: ticks, denominator: 1, remainder: 0 };
47
+ note.noteType = rests ? 'r' : 'n';
48
+ return note;
49
+ });
50
+ };
51
+ const QUARTERS = [4096, 4096, 4096, 4096];
52
+
53
+ /**
54
+ * Two staves of six 4/4 measures. Staff 0: voice 0 is four quarters in each measure (rests in
55
+ * measure 3); voice 1 on measures 0-2 as a whole note, two half notes, four quarters; voice 2 on
56
+ * measure 2 only. Staff 1: voice 0 everywhere, voice 1 on measure 1 only.
57
+ */
58
+ const buildScore = (): SmoScore => {
59
+ const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
60
+ while (score.staves[0].measures.length < 6) {
61
+ score.addMeasure(score.staves[0].measures.length - 1);
62
+ }
63
+ // the second staff copies the measures of the first
64
+ const instrument = SmoInstrument.defaults;
65
+ instrument.startSelector.staff = instrument.endSelector.staff = 1;
66
+ const staffParams = SmoSystemStaff.defaults;
67
+ staffParams.staffId = 1;
68
+ staffParams.measureInstrumentMap[0] = new SmoInstrument(instrument);
69
+ score.addStaff(staffParams);
70
+ const s0 = score.staves[0].measures;
71
+ const s1 = score.staves[1].measures;
72
+ s0.forEach((m, ix) => setVoice(m, 0, QUARTERS, ix === 3));
73
+ s1.forEach((m) => setVoice(m, 0, QUARTERS));
74
+ setVoice(s0[0], 1, [WHOLE]);
75
+ setVoice(s0[1], 1, [WHOLE / 2, WHOLE / 2]);
76
+ setVoice(s0[2], 1, QUARTERS);
77
+ setVoice(s0[2], 2, QUARTERS);
78
+ setVoice(s1[1], 1, [WHOLE / 2, WHOLE / 2]);
79
+ return score;
80
+ };
81
+ /** Selections for ticks first-last of a voice in a measure, as the tracker would hold them */
82
+ const sel = (score: SmoScore, staff: number, measure: number, voice: number, first: number, last: number = first): SmoSelection[] => {
83
+ const rv: SmoSelection[] = [];
84
+ for (let t = first; t <= last; ++t) {
85
+ const s = SmoSelection.noteSelection(score, staff, measure, voice, t);
86
+ if (s) {
87
+ rv.push(s);
88
+ }
89
+ }
90
+ return rv;
91
+ };
92
+ const keys = (selectors: SmoSelector[]) => selectors.map((s) => SmoSelector.getNoteKey(s));
93
+
94
+ const score = buildScore();
95
+ check('builder: score has 2 staves of 6 measures', score.staves.length === 2 && score.staves.every((s) => s.measures.length === 6));
96
+ check('builder: voice counts as designed', score.staves[0].measures.map((m) => m.voices.length).join() === '2,2,3,1,1,1' &&
97
+ score.staves[1].measures.map((m) => m.voices.length).join() === '1,2,1,1,1,1', score.staves[0].measures.map((m) => m.voices.length).join());
98
+
99
+ // --- S1-S5: the choices ---
100
+ check('S1 a single-voice measure offers nothing', JSON.stringify(SmoSelection.voiceChoices(score, sel(score, 0, 4, 0, 0))) === '[]');
101
+ check('S2 no selection offers nothing', JSON.stringify(SmoSelection.voiceChoices(score, [])) === '[]');
102
+ check('S3 a two-voice measure offers voices 0 and 1', JSON.stringify(SmoSelection.voiceChoices(score, sel(score, 0, 0, 0, 0))) === '[0,1]');
103
+ check('S4 measures 0 to 2 offer voices 0, 1 and 2',
104
+ JSON.stringify(SmoSelection.voiceChoices(score, sel(score, 0, 0, 0, 0).concat(sel(score, 0, 2, 0, 0)))) === '[0,1,2]');
105
+ check('S5 two single-voice measures offer nothing',
106
+ JSON.stringify(SmoSelection.voiceChoices(score, sel(score, 0, 3, 0, 0).concat(sel(score, 0, 4, 0, 0)))) === '[]');
107
+
108
+ // --- S6: a single selected note selects the whole voice in the measure ---
109
+ {
110
+ // the third quarter of voice 0 in measure 0; voice 1 there is one whole note
111
+ const got = SmoSelection.getVoiceSelectors(score, sel(score, 0, 0, 0, 2), 1);
112
+ check('S6 the whole note of voice 1 is selected from a single voice 0 note', JSON.stringify(keys(got)) === '["0-0-1-0"]', JSON.stringify(keys(got)));
113
+ }
114
+ // --- S7: uneven voices ---
115
+ {
116
+ const got = SmoSelection.getVoiceSelectors(score, sel(score, 0, 1, 0, 0), 1);
117
+ check('S7 two half notes selected even though voice 0 has four notes', JSON.stringify(keys(got)) === '["0-1-1-0","0-1-1-1"]', JSON.stringify(keys(got)));
118
+ }
119
+ // --- S8: several measures, in order ---
120
+ {
121
+ const picked = sel(score, 0, 0, 0, 0).concat(sel(score, 0, 1, 0, 0), sel(score, 0, 2, 0, 0));
122
+ const got = SmoSelection.getVoiceSelectors(score, picked, 1);
123
+ check('S8 1 + 2 + 4 notes of voice 1', got.length === 7, `n=${got.length}`);
124
+ check('S8 all are voice 1, in measure then tick order',
125
+ got.every((s) => s.voice === 1) && JSON.stringify(keys(got)) ===
126
+ '["0-0-1-0","0-1-1-0","0-1-1-1","0-2-1-0","0-2-1-1","0-2-1-2","0-2-1-3"]', JSON.stringify(keys(got)));
127
+ // --- S9: a voice present in only some of the measures ---
128
+ const v2 = SmoSelection.getVoiceSelectors(score, picked, 2);
129
+ check('S9 voice 2 exists only in measure 2: four notes there, nothing from the others',
130
+ JSON.stringify(keys(v2)) === '["0-2-2-0","0-2-2-1","0-2-2-2","0-2-2-3"]', JSON.stringify(keys(v2)));
131
+ }
132
+ // --- S10: no notes anywhere in the selected measures ---
133
+ {
134
+ const picked = sel(score, 0, 0, 0, 0).concat(sel(score, 0, 1, 0, 0));
135
+ check('S10 voice 2 has no notes in measures 0 and 1: nothing to select',
136
+ SmoSelection.getVoiceSelectors(score, picked, 2).length === 0);
137
+ }
138
+ // --- S11: two staves, each gets its own voice ---
139
+ {
140
+ const picked = sel(score, 0, 1, 0, 0).concat(sel(score, 1, 1, 0, 0));
141
+ const got = SmoSelection.getVoiceSelectors(score, picked, 1);
142
+ check('S11 both staves contribute their voice 1 notes in measure 1',
143
+ JSON.stringify(keys(got)) === '["0-1-1-0","0-1-1-1","1-1-1-0","1-1-1-1"]', JSON.stringify(keys(got)));
144
+ }
145
+ // --- S12: a staff without the voice contributes nothing and gets no voice ---
146
+ {
147
+ const picked = sel(score, 0, 0, 0, 0).concat(sel(score, 1, 0, 0, 0));
148
+ const got = SmoSelection.getVoiceSelectors(score, picked, 1);
149
+ check('S12 only staff 0 contributes (staff 1 measure 0 has one voice)', JSON.stringify(keys(got)) === '["0-0-1-0"]', JSON.stringify(keys(got)));
150
+ check('S12 the voice was not created on staff 1', score.staves[1].measures[0].voices.length === 1);
151
+ }
152
+ // --- S13: rests are notes of the voice ---
153
+ {
154
+ const got = SmoSelection.getVoiceSelectors(score, sel(score, 0, 3, 0, 0), 0);
155
+ const allRests = got.every((s) => score.staves[0].measures[3].voices[0].notes[s.tick].noteType === 'r');
156
+ check('S13 the four rests of measure 3 are selected', got.length === 4 && allRests, `n=${got.length}`);
157
+ }
158
+ // --- S14: nothing in the score changes ---
159
+ {
160
+ const fresh = buildScore();
161
+ const before = JSON.stringify(fresh.serialize({ skipStaves: false, useDictionary: false, preserveStaffIds: false }));
162
+ const everything: SmoSelection[] = [];
163
+ fresh.staves.forEach((staff, si) => staff.measures.forEach((_m, mi) => everything.push(...sel(fresh, si, mi, 0, 0))));
164
+ SmoSelection.voiceChoices(fresh, everything);
165
+ for (let v = -1; v <= 4; ++v) {
166
+ SmoSelection.getVoiceSelectors(fresh, everything, v);
167
+ }
168
+ const after = JSON.stringify(fresh.serialize({ skipStaves: false, useDictionary: false, preserveStaffIds: false }));
169
+ check('S14 the serialized score is unchanged', before === after);
170
+ check('S14 the voice counts are unchanged', fresh.staves[0].measures.map((m) => m.voices.length).join() === '2,2,3,1,1,1' &&
171
+ fresh.staves[1].measures.map((m) => m.voices.length).join() === '1,2,1,1,1,1');
172
+ }
173
+ // --- S15: out-of-range voices ---
174
+ check('S15 voice 4 selects nothing', SmoSelection.getVoiceSelectors(score, sel(score, 0, 0, 0, 0), 4).length === 0);
175
+ check('S15 voice -1 selects nothing', SmoSelection.getVoiceSelectors(score, sel(score, 0, 0, 0, 0), -1).length === 0);
176
+ check('S15 no selection selects nothing', SmoSelection.getVoiceSelectors(score, [], 0).length === 0);
177
+ // --- S16: selector shape ---
178
+ {
179
+ const got = SmoSelection.getVoiceSelectors(score, sel(score, 0, 2, 0, 0), 2);
180
+ check('S16 selectors name the requested voice and select whole notes', got.length === 4 &&
181
+ got.every((s) => s.voice === 2 && Array.isArray(s.pitches) && s.pitches.length === 0));
182
+ }
183
+
184
+ if (failures > 0) {
185
+ console.log(`${failures} check(s) failed`);
186
+ process.exitCode = 1;
187
+ } else {
188
+ console.log('all checks passed');
189
+ }
@@ -0,0 +1,417 @@
1
+ /**
2
+ * Headless checks for copying and pasting voices (PasteBuffer.setVoiceSelections, pasteVoice,
3
+ * pasteAllVoices, and the menu choice functions). Cases V1-V20 are listed in
4
+ * specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md.
5
+ *
6
+ * Run with: npm run test:voice-copy-paste
7
+ */
8
+ import { SmoScore } from '../src/smo/data/score';
9
+ import { SmoMeasure } from '../src/smo/data/measure';
10
+ import { SmoNote } from '../src/smo/data/note';
11
+ import { SmoSelection, SmoSelector } from '../src/smo/xform/selections';
12
+ import { SmoOperation } from '../src/smo/xform/operations';
13
+ import { PasteBuffer } from '../src/smo/xform/copypaste';
14
+ import { SmoSlur } from '../src/smo/data/staffModifiers';
15
+ import { 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 LETTERS = ['c', 'd', 'e', 'f', 'g', 'a', 'b'];
38
+ /** Give a quarter-note slot a pitch that encodes where it is, so a pasted note can be traced */
39
+ const encodePitch = (note: SmoNote, measure: number, voice: number, tick: number) => {
40
+ note.noteType = 'n';
41
+ note.pitches = [{ letter: LETTERS[(measure + tick + voice * 2) % 7] as any, accidental: 'n', octave: 3 + voice }];
42
+ };
43
+ const fillVoice = (measure: SmoMeasure, voice: number, measureIx: number) => {
44
+ while (measure.voices.length <= voice) {
45
+ measure.populateVoice(measure.voices.length);
46
+ }
47
+ measure.voices[voice].notes.forEach((note, tick) => encodePitch(note, measureIx, voice, tick));
48
+ };
49
+
50
+ /** Voice `v` of measure `m` as a list of 'pitch:ticks' strings, or null if the voice doesn't exist */
51
+ const voiceNotes = (score: SmoScore, m: number, v: number, staff: number = 0): string[] | null => {
52
+ const measure = score.staves[staff].measures[m];
53
+ if (!measure || measure.voices.length <= v) {
54
+ return null;
55
+ }
56
+ return measure.voices[v].notes.map((note) => {
57
+ const p = note.pitches[0];
58
+ return `${note.noteType === 'r' ? 'r' : p.letter + p.octave}:${note.tickCount}`;
59
+ });
60
+ };
61
+ const same = (a: string[] | null, b: string[] | null) => JSON.stringify(a) === JSON.stringify(b);
62
+ const voiceCount = (score: SmoScore, m: number, staff: number = 0) => score.staves[staff].measures[m].voices.length;
63
+ const tupletVoices = (score: SmoScore, m: number, staff: number = 0): number[] =>
64
+ score.staves[staff].measures[m].tupletTrees.map((tree) => tree.voice);
65
+
66
+ /**
67
+ * Single staff, 12 measures (indexes 0-11) of 4/4. Voice 0 on every measure; voice 1 on
68
+ * measures 0-3; voice 2 on measure 1 only; a triplet in voice 0 of measure 5 and in voice 1 of
69
+ * measure 6 (voice 1 also exists there); measure 9 has one voice.
70
+ */
71
+ const buildScore = (): SmoScore => {
72
+ const score = SmoScore.getDefaultScore(SmoScore.defaults, null);
73
+ while (score.staves[0].measures.length < 12) {
74
+ score.addMeasure(score.staves[0].measures.length - 1);
75
+ }
76
+ score.staves[0].measures.forEach((measure, m) => {
77
+ fillVoice(measure, 0, m);
78
+ if (m < 4 || m === 6) {
79
+ fillVoice(measure, 1, m);
80
+ }
81
+ if (m === 1) {
82
+ fillVoice(measure, 2, m);
83
+ }
84
+ });
85
+ // triplets: quarter notes 0-2 of voice 0 in measure 5, and of voice 1 in measure 6
86
+ const trip = (m: number, v: number) => {
87
+ const sel = SmoSelection.noteSelection(score, 0, m, v, 0)!;
88
+ SmoOperation.makeTuplet(sel, { numNotes: 3, notesOccupied: 2, bracketed: true, ratioed: false } as any);
89
+ };
90
+ trip(5, 0);
91
+ trip(6, 1);
92
+ return score;
93
+ };
94
+ /** Note selections covering ticks first-last of voice v in measure m, for copy */
95
+ const selectNotes = (score: SmoScore, m: number, first: number, last: number, v: number = 0): SmoSelection[] => {
96
+ const rv: SmoSelection[] = [];
97
+ for (let t = first; t <= last; ++t) {
98
+ const sel = SmoSelection.noteSelection(score, 0, m, v, t);
99
+ if (sel) {
100
+ rv.push(sel);
101
+ }
102
+ }
103
+ return rv;
104
+ };
105
+ const dest = (measure: number, staff: number = 0): SmoSelector => ({ staff, measure, voice: 0, tick: 0, pitches: [] });
106
+
107
+ // --- V1-V4: menu choice functions ---
108
+ check('V1 copy choices, no voices', JSON.stringify(PasteBuffer.copyVoiceChoices(0)) === '[]');
109
+ check('V1 copy choices, one voice', JSON.stringify(PasteBuffer.copyVoiceChoices(1)) === '[0]');
110
+ check('V1 copy choices, two voices', JSON.stringify(PasteBuffer.copyVoiceChoices(2)) === '[0,1,"all"]');
111
+ check('V1 copy choices, three voices', JSON.stringify(PasteBuffer.copyVoiceChoices(3)) === '[0,1,2,"all"]');
112
+ check('V2 paste choices with no voice copy', JSON.stringify(PasteBuffer.pasteVoiceChoices([], 2)) === '[]');
113
+ check('V3 one destination voice: replace it, or add a new voice', JSON.stringify(PasteBuffer.pasteVoiceChoices([1], 1)) === '[0,"new"]');
114
+ check('V3 two destination voices', JSON.stringify(PasteBuffer.pasteVoiceChoices([0], 2)) === '[0,1,"new"]');
115
+ check('V3 three destination voices', JSON.stringify(PasteBuffer.pasteVoiceChoices([0], 3)) === '[0,1,2,"new"]');
116
+ check('V3 four destination voices: existing voices only, no new voice', JSON.stringify(PasteBuffer.pasteVoiceChoices([0], 4)) === '[0,1,2,3]');
117
+ check('V3 no destination offers nothing', JSON.stringify(PasteBuffer.pasteVoiceChoices([0], 0)) === '[]');
118
+ check('V4 paste choices, several copied voices', JSON.stringify(PasteBuffer.pasteVoiceChoices([0, 1], 1)) === '["all"]');
119
+
120
+ // --- V5: copy extends to whole measures ---
121
+ {
122
+ const score = buildScore();
123
+ const buffer = new PasteBuffer();
124
+ // from the 3rd note of measure 1 to the 2nd note of measure 2
125
+ const sels = selectNotes(score, 1, 2, 3).concat(selectNotes(score, 2, 0, 1));
126
+ const ok = buffer.setVoiceSelections(score, sels, 0);
127
+ const vc = buffer.voiceCopy!;
128
+ check('V5 voice copy succeeds', ok && !!vc);
129
+ check('V5 covers measures 1 to 2', vc.firstMeasure === 1 && vc.measureCount === 2, `first=${vc.firstMeasure} count=${vc.measureCount}`);
130
+ check('V5 copies all 8 notes of the two whole measures', vc.notes[0][0].length === 8, `n=${vc.notes[0][0].length}`);
131
+ check('V5 one voice copied', JSON.stringify(vc.voices) === '[0]');
132
+ check('V5 tick count is two measures', buffer.getVoiceCopyTickCount() === 2 * 16384, `${buffer.getVoiceCopyTickCount()}`);
133
+
134
+ // --- V6, V7: paste into the same voice number elsewhere; other voices unchanged ---
135
+ const before7 = voiceNotes(score, 7, 1);
136
+ buffer.pasteVoice(dest(7), 0);
137
+ check('V6 measure 7 voice 0 equals measure 1 voice 0', same(voiceNotes(score, 7, 0), voiceNotes(score, 1, 0)));
138
+ check('V6 measure 8 voice 0 equals measure 2 voice 0', same(voiceNotes(score, 8, 0), voiceNotes(score, 2, 0)));
139
+ check('V7 other voices of the destination unchanged', same(voiceNotes(score, 7, 1), before7) && voiceCount(score, 7) === 1);
140
+ check('V6 the copy is still there after a paste', buffer.hasVoiceCopy());
141
+ buffer.pasteVoice(dest(10), 0);
142
+ check('V6 a second paste from the same copy works', same(voiceNotes(score, 10, 0), voiceNotes(score, 1, 0)) &&
143
+ same(voiceNotes(score, 11, 0), voiceNotes(score, 2, 0)));
144
+ }
145
+
146
+ // --- V8: paste into an existing different voice ---
147
+ {
148
+ const score = buildScore();
149
+ const buffer = new PasteBuffer();
150
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0), 0);
151
+ const v0Before = voiceNotes(score, 3, 0);
152
+ buffer.pasteVoice(dest(3), 1);
153
+ check('V8 voice 1 of measure 3 replaced by the copied voice 0', same(voiceNotes(score, 3, 1), voiceNotes(score, 0, 0)));
154
+ check('V8 voice 0 of measure 3 unchanged', same(voiceNotes(score, 3, 0), v0Before));
155
+ }
156
+
157
+ // --- V9: paste into the next empty voice ---
158
+ {
159
+ const score = buildScore();
160
+ const buffer = new PasteBuffer();
161
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0), 0);
162
+ const v0Before = voiceNotes(score, 9, 0);
163
+ check('V9 measure 9 starts with one voice', voiceCount(score, 9) === 1);
164
+ buffer.pasteVoice(dest(9), 1);
165
+ check('V9 measure 9 now has two voices', voiceCount(score, 9) === 2, `n=${voiceCount(score, 9)}`);
166
+ check('V9 the new voice holds the copied notes', same(voiceNotes(score, 9, 1), voiceNotes(score, 0, 0)));
167
+ check('V9 voice 0 unchanged', same(voiceNotes(score, 9, 0), v0Before));
168
+ }
169
+
170
+ // --- V10: copy voice 1, paste into voice 0 ---
171
+ {
172
+ const score = buildScore();
173
+ const buffer = new PasteBuffer();
174
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0, 1), 1);
175
+ check('V10 voice 1 copied', JSON.stringify(buffer.copiedVoiceNumbers()) === '[1]');
176
+ buffer.pasteVoice(dest(10), 0);
177
+ check('V10 measure 10 voice 0 equals measure 0 voice 1', same(voiceNotes(score, 10, 0), voiceNotes(score, 0, 1)));
178
+ check('V10 measure 10 gets no second voice', voiceCount(score, 10) === 1);
179
+ }
180
+
181
+ // --- V11: copy All, paste All into a one-voice destination ---
182
+ {
183
+ const score = buildScore();
184
+ const buffer = new PasteBuffer();
185
+ const ok = buffer.setVoiceSelections(score, selectNotes(score, 1, 1, 2).concat(selectNotes(score, 2, 0, 0)), 'all');
186
+ check('V11 copy all succeeds', ok);
187
+ check('V11 voices 0 and 1 and 2 copied (measure 1 has three)', JSON.stringify(buffer.copiedVoiceNumbers()) === '[0,1,2]',
188
+ JSON.stringify(buffer.copiedVoiceNumbers()));
189
+ buffer.pasteAllVoices(dest(7));
190
+ check('V11 measure 7 has three voices', voiceCount(score, 7) === 3, `n=${voiceCount(score, 7)}`);
191
+ [0, 1, 2].forEach((v) => {
192
+ check(`V11 measure 7 voice ${v} equals measure 1 voice ${v}`, same(voiceNotes(score, 7, v), voiceNotes(score, 1, v)));
193
+ });
194
+ check('V11 measure 8 voice 0 equals measure 2 voice 0', same(voiceNotes(score, 8, 0), voiceNotes(score, 2, 0)));
195
+ check('V11 measure 8 voice 1 equals measure 2 voice 1', same(voiceNotes(score, 8, 1), voiceNotes(score, 2, 1)));
196
+ // measure 2 has no voice 2: the copy holds rests there, pasted as rests
197
+ const rests = voiceNotes(score, 8, 2);
198
+ check('V11 a copied voice missing from a measure is pasted as rests', rests !== null && rests.every((n) => n.startsWith('r:')),
199
+ JSON.stringify(rests));
200
+ }
201
+
202
+ // --- V12: paste All onto a destination that already has voices ---
203
+ {
204
+ const score = buildScore();
205
+ const buffer = new PasteBuffer();
206
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0), 'all');
207
+ buffer.pasteAllVoices(dest(2));
208
+ check('V12 measure 2 voice 0 replaced', same(voiceNotes(score, 2, 0), voiceNotes(score, 0, 0)));
209
+ check('V12 measure 2 voice 1 replaced', same(voiceNotes(score, 2, 1), voiceNotes(score, 0, 1)));
210
+ check('V12 measure 2 has two voices, no extra voice', voiceCount(score, 2) === 2, `n=${voiceCount(score, 2)}`);
211
+ check('V12 measure 3 (destination for the second copied measure? only one copied) is unchanged',
212
+ same(voiceNotes(score, 3, 1), voiceNotes(buildScore(), 3, 1)));
213
+ }
214
+
215
+ // --- V13: uncopied destination voices are unchanged ---
216
+ {
217
+ const score = buildScore();
218
+ const buffer = new PasteBuffer();
219
+ // copy All from measure 6 (two voices: 0 and 1); the destination (measure 1) has a third voice
220
+ buffer.setVoiceSelections(score, selectNotes(score, 6, 0, 0), 'all');
221
+ check('V13 two voices copied', JSON.stringify(buffer.copiedVoiceNumbers()) === '[0,1]');
222
+ const v2Before = voiceNotes(score, 1, 2);
223
+ buffer.pasteAllVoices(dest(1));
224
+ check('V13 voice 2 of the destination, which was not copied, is unchanged', same(voiceNotes(score, 1, 2), v2Before));
225
+ }
226
+
227
+ // --- V14: a paste past the end of the score is limited ---
228
+ {
229
+ const score = buildScore();
230
+ const buffer = new PasteBuffer();
231
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0).concat(selectNotes(score, 3, 0, 0)), 0);
232
+ check('V14 copies four measures', buffer.voiceCopy!.measureCount === 4);
233
+ let threw = false;
234
+ try {
235
+ buffer.pasteVoice(dest(10), 0);
236
+ } catch (e) {
237
+ threw = true;
238
+ }
239
+ check('V14 pasting past the end does not throw', !threw);
240
+ check('V14 score still has 12 measures', score.staves[0].measures.length === 12);
241
+ check('V14 measure 10 holds the first copied measure', same(voiceNotes(score, 10, 0), voiceNotes(score, 0, 0)));
242
+ check('V14 measure 11 holds the second copied measure', same(voiceNotes(score, 11, 0), voiceNotes(score, 1, 0)));
243
+ }
244
+
245
+ // --- V15: a voice missing on part of the copy is copied as rests ---
246
+ {
247
+ const score = buildScore();
248
+ const buffer = new PasteBuffer();
249
+ // voice 1 exists on measures 2, 3 and 6, not 4 or 5
250
+ buffer.setVoiceSelections(score, selectNotes(score, 2, 0, 0, 0).concat(selectNotes(score, 4, 0, 0, 0)), 1);
251
+ check('V15 voice 1 copied over three measures', buffer.voiceCopy!.measureCount === 3);
252
+ buffer.pasteVoice(dest(8), 1);
253
+ check('V15 measure 8 voice 1 equals measure 2 voice 1', same(voiceNotes(score, 8, 1), voiceNotes(score, 2, 1)));
254
+ check('V15 measure 9 voice 1 equals measure 3 voice 1', same(voiceNotes(score, 9, 1), voiceNotes(score, 3, 1)));
255
+ const rests = voiceNotes(score, 10, 1);
256
+ check('V15 measure 10 voice 1 is rests (the source had no voice 1 in measure 4)', rests !== null && rests.every((n) => n.startsWith('r:')),
257
+ JSON.stringify(rests));
258
+ }
259
+
260
+ // --- V16: tuplets are kept, and registered for the destination voice ---
261
+ {
262
+ const score = buildScore();
263
+ const buffer = new PasteBuffer();
264
+ check('V16 the source has a tuplet in voice 0 of measure 5', tupletVoices(score, 5).join() === '0');
265
+ buffer.setVoiceSelections(score, selectNotes(score, 5, 0, 0), 0);
266
+ buffer.pasteVoice(dest(8), 0);
267
+ check('V16 pasted measure has the same notes, including the tuplet', same(voiceNotes(score, 8, 0), voiceNotes(score, 5, 0)));
268
+ check('V16 the tuplet is registered for voice 0', tupletVoices(score, 8).join() === '0', tupletVoices(score, 8).join());
269
+ buffer.pasteVoice(dest(9), 1);
270
+ check('V16 pasted into voice 1, the tuplet belongs to voice 1', tupletVoices(score, 9).join() === '1', tupletVoices(score, 9).join());
271
+ check('V16 the tuplet notes are tuplets in the new voice', score.staves[0].measures[9].voices[1].notes[0].isTuplet === true);
272
+ }
273
+
274
+ // --- V17: another voice's tuplet survives a multi-measure paste ---
275
+ {
276
+ const score = buildScore();
277
+ const buffer = new PasteBuffer();
278
+ // copy voice 0 of measures 0-2, paste over measures 5-7; voice 1 of measure 6 has a triplet
279
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0).concat(selectNotes(score, 2, 0, 0)), 0);
280
+ check('V17 voice 1 of measure 6 has a tuplet before', tupletVoices(score, 6).indexOf(1) >= 0);
281
+ buffer.pasteVoice(dest(5), 0);
282
+ check('V17 voice 1 tuplet of the middle measure survives', tupletVoices(score, 6).indexOf(1) >= 0, tupletVoices(score, 6).join());
283
+ check('V17 voice 1 notes of the middle measure are still a tuplet', score.staves[0].measures[6].voices[1].notes[0].isTuplet === true);
284
+ check('V17 voice 0 of measure 5 was replaced (its tuplet is gone)', tupletVoices(score, 5).indexOf(0) < 0, tupletVoices(score, 5).join());
285
+ }
286
+
287
+ // --- V18: no stale tuplet trees in the replaced voice ---
288
+ {
289
+ const score = buildScore();
290
+ const buffer = new PasteBuffer();
291
+ // copy 3 measures of plain voice 0 (measures 0-2), paste over measures 3-5; measure 5 voice 0 has a triplet
292
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0).concat(selectNotes(score, 2, 0, 0)), 0);
293
+ buffer.pasteVoice(dest(3), 0);
294
+ check('V18 the triplet in the last pasted measure is gone', tupletVoices(score, 5).indexOf(0) < 0, tupletVoices(score, 5).join());
295
+ check('V18 the pasted notes are plain', score.staves[0].measures[5].voices[0].notes.every((n) => !n.isTuplet));
296
+ }
297
+
298
+ // --- V19: slurs are carried when the voice number is kept ---
299
+ {
300
+ const slurFor = (score: SmoScore) => {
301
+ const a = SmoSelection.noteSelection(score, 0, 0, 0, 0)!;
302
+ const b = SmoSelection.noteSelection(score, 0, 0, 0, 2)!;
303
+ const slur = SmoOperation.createSlur(score, a, b);
304
+ a.staff.addStaffModifier(slur);
305
+ return slur;
306
+ };
307
+ const slursAt = (score: SmoScore, m: number) =>
308
+ score.staves[0].getModifiers().filter((mod: any) => mod.ctor === 'SmoSlur' && mod.startSelector.measure === m);
309
+ // same voice number: carried
310
+ {
311
+ const score = buildScore();
312
+ slurFor(score);
313
+ const buffer = new PasteBuffer();
314
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0), 0);
315
+ buffer.pasteVoice(dest(7), 0);
316
+ check('V19 a slur is carried when pasted into the same voice number', slursAt(score, 7).length === 1, `n=${slursAt(score, 7).length}`);
317
+ }
318
+ // different voice number: not carried
319
+ {
320
+ const score = buildScore();
321
+ slurFor(score);
322
+ const buffer = new PasteBuffer();
323
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0), 0);
324
+ buffer.pasteVoice(dest(8), 1);
325
+ check('V19 a slur is not carried into a different voice number', slursAt(score, 8).length === 0, `n=${slursAt(score, 8).length}`);
326
+ check('V19 the notes are still pasted', same(voiceNotes(score, 8, 1), voiceNotes(score, 0, 0)));
327
+ }
328
+ }
329
+
330
+ // --- V20: the existing copy and paste are unchanged ---
331
+ {
332
+ const score = buildScore();
333
+ const buffer = new PasteBuffer();
334
+ buffer.setVoiceSelections(score, selectNotes(score, 0, 0, 0), 0);
335
+ check('V20 a voice copy exists before a normal copy', buffer.hasVoiceCopy());
336
+ buffer.setSelections(score, selectNotes(score, 1, 0, 3, 0));
337
+ check('V20 a normal copy clears the voice copy', !buffer.hasVoiceCopy());
338
+ buffer.pasteSelections({ staff: 0, measure: 8, voice: 0, tick: 0, pitches: [] });
339
+ check('V20 plain paste of one voice into measure 8', same(voiceNotes(score, 8, 0), voiceNotes(score, 1, 0)));
340
+ check('V20 plain paste leaves measure 8 with one voice', voiceCount(score, 8) === 1);
341
+ // a partial-measure copy and paste still works note by note
342
+ const score2 = buildScore();
343
+ const buffer2 = new PasteBuffer();
344
+ buffer2.setSelections(score2, selectNotes(score2, 0, 1, 2, 0));
345
+ buffer2.pasteSelections({ staff: 0, measure: 8, voice: 0, tick: 0, pitches: [] });
346
+ const src = voiceNotes(score2, 0, 0)!;
347
+ const got = voiceNotes(score2, 8, 0)!;
348
+ check('V20 partial plain paste puts the 2 notes first', got[0] === src[1] && got[1] === src[2], JSON.stringify(got));
349
+ check('V20 partial plain paste keeps the rest of the measure', got.length === 4 && got[2] === voiceNotes(buildScore(), 8, 0)![2]);
350
+ // an unrelated voice's tuplet in middle measures is kept by a plain multi-measure paste
351
+ const score3 = buildScore();
352
+ const buffer3 = new PasteBuffer();
353
+ buffer3.setSelections(score3, selectNotes(score3, 0, 0, 3, 0).concat(selectNotes(score3, 1, 0, 3, 0), selectNotes(score3, 2, 0, 3, 0)));
354
+ buffer3.pasteSelections({ staff: 0, measure: 5, voice: 0, tick: 0, pitches: [] });
355
+ check('V20 plain multi-measure paste works', same(voiceNotes(score3, 6, 0), voiceNotes(score3, 1, 0)));
356
+ }
357
+
358
+ // --- P1: a note split across a measure boundary is transposed once, not once per measure ---
359
+ // (existing paste bug: the remainder in the next measure was transposed a second time)
360
+ {
361
+ const score = buildScore();
362
+ // measure 1 becomes a single whole note
363
+ const src = score.staves[0].measures[1];
364
+ src.voices = [{ notes: [src.voices[0].notes[0]] }];
365
+ src.voices[0].notes[0].ticks = { numerator: 16384, denominator: 1, remainder: 0 };
366
+ // measures 8 and 9 belong to a transposing instrument (written 2 semitones above concert)
367
+ [8, 9].forEach((m) => {
368
+ const measure = score.staves[0].measures[m];
369
+ measure.transposeIndex = 2;
370
+ measure.keySignature = 'd';
371
+ });
372
+ const buffer = new PasteBuffer();
373
+ buffer.setSelections(score, selectNotes(score, 1, 0, 0));
374
+ // start on the third beat, so the whole note has to be split
375
+ buffer.pasteSelections({ staff: 0, measure: 8, voice: 0, tick: 2, pitches: [] });
376
+ const m8 = voiceNotes(score, 8, 0)!;
377
+ const m9 = voiceNotes(score, 9, 0)!;
378
+ check('P1 the first part is in measure 8, on the third beat', m8.length === 3, JSON.stringify(m8));
379
+ const first = m8[2].split(':')[0];
380
+ const rest = m9[0].split(':')[0];
381
+ check('P1 the remainder in measure 9 has the same pitch as the first part', first === rest, `first=${first} remainder=${rest}`);
382
+ // the split note is pasted once: its remainder fills the first half of measure 9 and the
383
+ // existing music follows, not a second copy of the note
384
+ const original9 = voiceNotes(buildScore(), 9, 0)!;
385
+ check('P2 the remainder is a half note', m9[0].endsWith(':8192'), JSON.stringify(m9));
386
+ check('P2 the split note is not pasted a second time', m9.length === 3 && m9[1] === original9[2] && m9[2] === original9[3],
387
+ `measure 9 = ${JSON.stringify(m9)}, existing = ${JSON.stringify(original9)}`);
388
+ }
389
+
390
+ // --- P3: after a split note, the notes copied after it follow, each pasted once ---
391
+ {
392
+ const score = buildScore();
393
+ // measure 1 becomes two half notes
394
+ const src = score.staves[0].measures[1];
395
+ src.voices = [{ notes: [src.voices[0].notes[0], src.voices[0].notes[1]] }];
396
+ src.voices[0].notes.forEach((n) => { n.ticks = { numerator: 8192, denominator: 1, remainder: 0 }; });
397
+ const copied = voiceNotes(score, 1, 0)!;
398
+ const original9 = voiceNotes(buildScore(), 9, 0)!;
399
+ const buffer = new PasteBuffer();
400
+ buffer.setSelections(score, selectNotes(score, 1, 0, 1));
401
+ // start on the fourth beat: the first half note is split, one beat in measure 8 and one in measure 9
402
+ buffer.pasteSelections({ staff: 0, measure: 8, voice: 0, tick: 3, pitches: [] });
403
+ const m8 = voiceNotes(score, 8, 0)!;
404
+ const m9 = voiceNotes(score, 9, 0)!;
405
+ const pitchA = copied[0].split(':')[0];
406
+ const pitchB = copied[1].split(':')[0];
407
+ check('P3 measure 8 ends with one beat of the first note', m8[m8.length - 1] === `${pitchA}:4096`, JSON.stringify(m8));
408
+ check('P3 measure 9 is: rest of the first note, the second note, then the existing last beat',
409
+ JSON.stringify(m9) === JSON.stringify([`${pitchA}:4096`, `${pitchB}:8192`, original9[3]]), JSON.stringify(m9));
410
+ }
411
+
412
+ if (failures > 0) {
413
+ console.log(`${failures} check(s) failed`);
414
+ process.exitCode = 1;
415
+ } else {
416
+ console.log('all checks passed');
417
+ }