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
@@ -815,6 +815,46 @@ export class SuiTracker extends SuiMapper implements TrackerKeyHandler {
815
815
  const c2 = 'v' + (selector.voice + 1).toString() + '-active';
816
816
  $('body').addClass(c2);
817
817
  }
818
+ /**
819
+ * Replace the selection with all the notes of one voice in every measure that has a selection.
820
+ * The whole of each measure is used, not just the selected notes. Only notes that have been
821
+ * rendered can be selected. This changes only the selection: it makes no change to the score,
822
+ * creates no voice, and records no undo. If there are no notes to select, nothing changes.
823
+ * @param voice the voice to select (0-3)
824
+ * @returns true if the selection was replaced
825
+ */
826
+ selectVoice(voice: number): boolean {
827
+ if (!this.score) {
828
+ return false;
829
+ }
830
+ const selectors = SmoSelection.getVoiceSelectors(this.score, this.selections, voice);
831
+ const mapped: SmoSelection[] = [];
832
+ selectors.forEach((selector) => {
833
+ const artifact = this.measureNoteMap[SmoSelector.getNoteKey(selector)];
834
+ if (artifact) {
835
+ mapped.push(artifact);
836
+ }
837
+ });
838
+ if (mapped.length < 1) {
839
+ return false;
840
+ }
841
+ this.selections = mapped;
842
+ this.pitchIndex = -1;
843
+ // Keep the active voice (used for entering notes) in step with the selection, as selecting a
844
+ // single note does.
845
+ const measuresDone: Record<string, boolean> = {};
846
+ mapped.forEach((selection) => {
847
+ const key = SmoSelector.getMeasureKey(selection.selector);
848
+ if (!measuresDone[key]) {
849
+ measuresDone[key] = true;
850
+ selection.measure.setActiveVoice(voice);
851
+ }
852
+ });
853
+ this.score.setActiveStaff(mapped[0].selector.staff);
854
+ this._createLocalModifiersList();
855
+ this.deferHighlight();
856
+ return true;
857
+ }
818
858
  // The user has just switched voices, select the active voice
819
859
  selectActiveVoice() {
820
860
  const selection = this.selections[0];
@@ -189,7 +189,9 @@ export class VxNote {
189
189
  }
190
190
  const vexL: Annotation = new VF.Annotation(text);
191
191
  vexL.setAttribute('id', annotation.attrs.id);
192
- vexL.setFont(annotation.fontInfo.family, annotation.fontInfo.size, annotation.fontInfo.weight);
192
+ vexL.setFont(annotation.fontInfo.family, annotation.fontInfo.size, annotation.fontInfo.weight,
193
+ annotation.fontInfo.style
194
+ );
193
195
  vexL.setVerticalJustification(annotation.verticalJustify);
194
196
  vexL.setReportWidth(false); // ignore width for formatting
195
197
  vexNote.addModifier(vexL);
@@ -35,6 +35,31 @@ export interface ModifierPlacement {
35
35
  modifier: StaffModifierBase,
36
36
  ticksToStart: number
37
37
  }
38
+ /**
39
+ * Voices copied with {@link PasteBuffer.setVoiceSelections}. Whole measures of one voice,
40
+ * or of all the voices, on one or more consecutive staves.
41
+ * @category SmoTransform
42
+ */
43
+ export interface VoiceCopy {
44
+ /** the voice numbers (0-3) that were copied, ascending. More than one means 'all' */
45
+ voices: number[],
46
+ firstStaff: number,
47
+ staffCount: number,
48
+ firstMeasure: number,
49
+ measureCount: number,
50
+ /** for each voice and staff, every note of every copied measure, in order */
51
+ notes: Record<number, Record<number, PasteNote[]>>,
52
+ /** staff modifiers that start on the copied notes, used when the voice number is kept */
53
+ modifiers: Record<number, StaffModifierBase[]>
54
+ }
55
+ /** the most voices a measure can have */
56
+ const MAX_VOICES = 4;
57
+
58
+ /** Set the voice of a tuplet and its nested tuplets, for a tuplet pasted into a different voice */
59
+ const setTupletVoice = (tuplet: SmoTupletTree['tuplet'], voice: number) => {
60
+ tuplet.voice = voice;
61
+ tuplet.childrenTuplets.forEach((child) => setTupletVoice(child, voice));
62
+ }
38
63
  /**
39
64
  * PasteBuffer holds copied music, and handles the action of pasting the music to
40
65
  * a different point in the score. It does this by serializing the measure(s) from the source
@@ -54,6 +79,8 @@ export class PasteBuffer {
54
79
  modifiersToPlace: ModifierPlacement[] = [];
55
80
  destination: SmoSelector = SmoSelector.default;
56
81
  staffSelectors: SmoSelector[] = [];
82
+ /** voices copied by setVoiceSelections, or null. Separate from the notes copied by setSelections */
83
+ voiceCopy: VoiceCopy | null = null;
57
84
  constructor() {
58
85
  this.notes = {};
59
86
  this.noteIndex = 0;
@@ -81,7 +108,267 @@ export class PasteBuffer {
81
108
  });
82
109
  return maxRv;
83
110
  }
111
+ /**
112
+ * Which choices the Copy Voices menu offers.
113
+ * @param voicesInSelection the most voices any selected measure has
114
+ * @returns each voice number to offer, then 'all' if there is more than one voice
115
+ */
116
+ static copyVoiceChoices(voicesInSelection: number): Array<number | 'all'> {
117
+ const count = Math.min(Math.max(voicesInSelection, 0), MAX_VOICES);
118
+ const rv: Array<number | 'all'> = [];
119
+ for (let i = 0; i < count; ++i) {
120
+ rv.push(i);
121
+ }
122
+ if (count > 1) {
123
+ rv.push('all');
124
+ }
125
+ return rv;
126
+ }
127
+ /**
128
+ * Which choices the Paste Voice menu offers.
129
+ * @param copiedVoices the voices in the current voice copy, empty if there is none
130
+ * @param destVoiceCount how many voices the destination has (the most in any destination measure)
131
+ * @returns for one copied voice, each existing destination voice (to replace it) and 'new', a new
132
+ * voice after the existing ones, unless the destination already has the maximum number of voices;
133
+ * for several copied voices, only 'all'; nothing if there is no voice copy or no destination
134
+ */
135
+ static pasteVoiceChoices(copiedVoices: number[], destVoiceCount: number): Array<number | 'all' | 'new'> {
136
+ if (copiedVoices.length < 1) {
137
+ return [];
138
+ }
139
+ if (copiedVoices.length > 1) {
140
+ return ['all'];
141
+ }
142
+ const count = Math.min(destVoiceCount, MAX_VOICES);
143
+ if (count < 1) {
144
+ return [];
145
+ }
146
+ const rv: Array<number | 'all' | 'new'> = [];
147
+ for (let i = 0; i < count; ++i) {
148
+ rv.push(i);
149
+ }
150
+ if (count < MAX_VOICES) {
151
+ rv.push('new');
152
+ }
153
+ return rv;
154
+ }
155
+ hasVoiceCopy(): boolean {
156
+ return this.voiceCopy !== null && this.voiceCopy.voices.length > 0;
157
+ }
158
+ clearVoiceCopy() {
159
+ this.voiceCopy = null;
160
+ }
161
+ copiedVoiceNumbers(): number[] {
162
+ return this.voiceCopy ? this.voiceCopy.voices.slice() : [];
163
+ }
164
+ /**
165
+ * The length of one copied voice in ticks, for working out how many measures a paste covers.
166
+ */
167
+ getVoiceCopyTickCount(): number {
168
+ if (!this.voiceCopy || this.voiceCopy.voices.length < 1) {
169
+ return 0;
170
+ }
171
+ const byStaff = this.voiceCopy.notes[this.voiceCopy.voices[0]];
172
+ let rv = 0;
173
+ Object.keys(byStaff).forEach((staffStr) => {
174
+ let ticks = 0;
175
+ byStaff[parseInt(staffStr, 10)].forEach((pn) => {
176
+ ticks += pn.note.tickCount;
177
+ });
178
+ rv = Math.max(rv, ticks);
179
+ });
180
+ return rv;
181
+ }
182
+ /**
183
+ * Copy whole measures of one voice, or all the voices. If the selection starts or ends in the
184
+ * middle of a measure, it is extended to the start of the first measure and the end of the last.
185
+ * The selection is treated as a rectangle: from the first to the last selected staff and measure.
186
+ * A voice that is missing from a copied measure is copied as that measure's default rests.
187
+ * @param score the score to copy from
188
+ * @param selections the selected notes or measures
189
+ * @param voice the voice to copy (0-3), or 'all'
190
+ * @returns false if nothing was copied
191
+ */
192
+ setVoiceSelections(score: SmoScore, selections: SmoSelection[], voice: number | 'all'): boolean {
193
+ this.voiceCopy = null;
194
+ this.score = score;
195
+ if (selections.length < 1) {
196
+ return false;
197
+ }
198
+ let firstStaff = selections[0].selector.staff;
199
+ let lastStaff = firstStaff;
200
+ let firstMeasure = selections[0].selector.measure;
201
+ let lastMeasure = firstMeasure;
202
+ selections.forEach((sel) => {
203
+ firstStaff = Math.min(firstStaff, sel.selector.staff);
204
+ lastStaff = Math.max(lastStaff, sel.selector.staff);
205
+ firstMeasure = Math.min(firstMeasure, sel.selector.measure);
206
+ lastMeasure = Math.max(lastMeasure, sel.selector.measure);
207
+ });
208
+ lastStaff = Math.min(lastStaff, score.staves.length - 1);
209
+ // Which voices exist in the copied measures
210
+ let voiceCount = 0;
211
+ for (let s = firstStaff; s <= lastStaff; ++s) {
212
+ for (let m = firstMeasure; m <= lastMeasure; ++m) {
213
+ const measure = score.staves[s].measures[m];
214
+ if (measure) {
215
+ voiceCount = Math.max(voiceCount, measure.voices.length);
216
+ }
217
+ }
218
+ }
219
+ voiceCount = Math.min(voiceCount, MAX_VOICES);
220
+ const voices: number[] = [];
221
+ if (voice === 'all') {
222
+ for (let v = 0; v < voiceCount; ++v) {
223
+ voices.push(v);
224
+ }
225
+ } else if (voice >= 0 && voice < voiceCount) {
226
+ voices.push(voice);
227
+ }
228
+ if (voices.length < 1) {
229
+ return false;
230
+ }
231
+ const voiceCopy: VoiceCopy = {
232
+ voices,
233
+ firstStaff,
234
+ staffCount: lastStaff - firstStaff + 1,
235
+ firstMeasure,
236
+ measureCount: lastMeasure - firstMeasure + 1,
237
+ notes: {},
238
+ modifiers: {}
239
+ };
240
+ voices.forEach((v) => {
241
+ // Gather every note in the voice, measure by measure. _populateSelectArray does the
242
+ // work of making concert-pitch copies, and fills this.notes and this.modifiers.
243
+ const noteSelections: SmoSelection[] = [];
244
+ const restNotes: PasteNote[] = [];
245
+ for (let s = firstStaff; s <= lastStaff; ++s) {
246
+ for (let m = firstMeasure; m <= lastMeasure; ++m) {
247
+ const measure = score.staves[s].measures[m];
248
+ if (!measure) {
249
+ continue;
250
+ }
251
+ if (v < measure.voices.length) {
252
+ for (let t = 0; t < measure.voices[v].notes.length; ++t) {
253
+ const sel = SmoSelection.noteSelection(score, s, m, v, t);
254
+ if (sel) {
255
+ noteSelections.push(sel);
256
+ }
257
+ }
258
+ } else {
259
+ // This voice doesn't exist in this measure: copy the measure's rests instead.
260
+ const key = measure.keySignature.toLocaleLowerCase();
261
+ SmoMeasure.getDefaultNotes(measure).forEach((note, t) => {
262
+ restNotes.push({
263
+ note,
264
+ selector: { staff: s, measure: m, voice: v, tick: t, pitches: [] },
265
+ originalKey: key,
266
+ tupletStart: null
267
+ });
268
+ });
269
+ }
270
+ }
271
+ }
272
+ this.notes = {};
273
+ this.modifiers = [];
274
+ if (noteSelections.length > 0) {
275
+ this._populateSelectArray(noteSelections);
276
+ }
277
+ const byStaff: Record<number, PasteNote[]> = this.notes;
278
+ restNotes.forEach((rest) => {
279
+ if (!byStaff[rest.selector.staff]) {
280
+ byStaff[rest.selector.staff] = [];
281
+ }
282
+ byStaff[rest.selector.staff].push(rest);
283
+ });
284
+ Object.keys(byStaff).forEach((staffStr) => {
285
+ const staff = parseInt(staffStr, 10);
286
+ byStaff[staff].sort((a, b) => SmoSelector.gt(a.selector, b.selector) ? 1 : -1);
287
+ });
288
+ voiceCopy.notes[v] = byStaff;
289
+ voiceCopy.modifiers[v] = this.modifiers;
290
+ });
291
+ this.notes = {};
292
+ this.modifiers = [];
293
+ this.voiceCopy = voiceCopy;
294
+ return true;
295
+ }
296
+ /**
297
+ * Paste a single copied voice into a voice of the destination measures, starting at the
298
+ * beginning of the destination measure. The destination voice may be any existing voice,
299
+ * or the next empty one, which is created in each measure it is pasted into.
300
+ * @param destination staff and measure to paste at (the voice and tick are ignored)
301
+ * @param voice the destination voice (0-3)
302
+ * @returns the measures that were replaced
303
+ */
304
+ pasteVoice(destination: SmoSelector, voice: number): SmoSelection[] {
305
+ if (!this.score || !this.voiceCopy || this.voiceCopy.voices.length !== 1) {
306
+ return [];
307
+ }
308
+ if (voice < 0 || voice >= MAX_VOICES) {
309
+ return [];
310
+ }
311
+ return this._pasteCopiedVoice(destination, this.voiceCopy.voices[0], voice);
312
+ }
313
+ /**
314
+ * Paste all the copied voices, each into the voice of the same number, starting at the
315
+ * beginning of the destination measure. Voices the destination doesn't have are created.
316
+ * @param destination staff and measure to paste at (the voice and tick are ignored)
317
+ * @returns the measures that were replaced
318
+ */
319
+ pasteAllVoices(destination: SmoSelector): SmoSelection[] {
320
+ if (!this.score || !this.voiceCopy) {
321
+ return [];
322
+ }
323
+ let rv: SmoSelection[] = [];
324
+ // ascending, so each voice can be created after the one before it
325
+ this.voiceCopy.voices.forEach((v) => {
326
+ rv = rv.concat(this._pasteCopiedVoice(destination, v, v));
327
+ });
328
+ return rv;
329
+ }
330
+ /**
331
+ * Paste voice `srcVoice` of the voice copy into voice `destVoice`, on each copied staff.
332
+ */
333
+ private _pasteCopiedVoice(destination: SmoSelector, srcVoice: number, destVoice: number): SmoSelection[] {
334
+ const copy = this.voiceCopy!;
335
+ let rv: SmoSelection[] = [];
336
+ // Slurs and the like are located by voice, so they are only carried if the voice is unchanged.
337
+ this.modifiers = [];
338
+ if (srcVoice === destVoice) {
339
+ copy.modifiers[srcVoice].forEach((mod) => {
340
+ this.modifiers.push(StaffModifierBase.deserialize(mod.serialize()));
341
+ });
342
+ }
343
+ for (let k = 0; k < copy.staffCount; ++k) {
344
+ const destStaff = destination.staff + k;
345
+ const srcNotes = copy.notes[srcVoice][copy.firstStaff + k];
346
+ if (destStaff >= this.score!.staves.length) {
347
+ break;
348
+ }
349
+ if (!srcNotes || srcNotes.length < 1) {
350
+ continue;
351
+ }
352
+ // pasteNoteSelections changes the notes it is given, so give it copies
353
+ const notes: PasteNote[] = srcNotes.map((pn) => {
354
+ const note = SmoNote.deserialize(pn.note.serialize());
355
+ const selector: SmoSelector = JSON.parse(JSON.stringify(pn.selector));
356
+ selector.voice = destVoice;
357
+ let tupletStart: SmoTupletTree | null = null;
358
+ if (pn.tupletStart) {
359
+ tupletStart = SmoTupletTree.deserialize(pn.tupletStart.serialize());
360
+ setTupletVoice(tupletStart.tuplet, destVoice);
361
+ }
362
+ return { note, selector, originalKey: pn.originalKey, tupletStart };
363
+ });
364
+ this.pasteNoteSelections({ staff: destStaff, measure: destination.measure, voice: destVoice, tick: 0, pitches: [] }, notes);
365
+ rv = rv.concat(this.replacementMeasures);
366
+ }
367
+ return rv;
368
+ }
84
369
  setSelections(score: SmoScore, selections: SmoSelection[]) {
370
+ // A normal copy replaces whatever was copied before, including voices
371
+ this.voiceCopy = null;
85
372
  this.notes = [];
86
373
  this.noteIndex = 0;
87
374
  this.score = score;
@@ -179,6 +466,7 @@ export class PasteBuffer {
179
466
 
180
467
  clearSelections() {
181
468
  this.notes = {};
469
+ this.voiceCopy = null;
182
470
  }
183
471
 
184
472
  _findModifier(selector: SmoSelector) {
@@ -252,6 +540,9 @@ export class PasteBuffer {
252
540
  if (measureSelection != null) {
253
541
  const clonedMeasure = SmoMeasure.cloneForPasteOrUndo(measureSelection.measure);
254
542
  clonedMeasure.svg = measureSelection.measure.svg;
543
+ // The destination voice may not exist in this measure yet (the first measure was
544
+ // aligned above); create it so later steps can look it up.
545
+ this._alignVoices(clonedMeasure, selector.voice);
255
546
  this.measures.push(clonedMeasure);
256
547
  // firstMeasureTickmap = measureSelection.measure.tickmapForVoice(selector.voice);
257
548
  }
@@ -284,10 +575,13 @@ export class PasteBuffer {
284
575
  selector.tick, lastMeasure.getClosestIndexFromTickCount(selector.voice, currentDuration), selector.voice);
285
576
  }
286
577
 
287
- //if there are more than 2 measures remove tuplets from all but first and last measure.
578
+ // if there are more than 2 measures remove tuplets from all but first and last measure.
579
+ // Only the tuplets of the voice being pasted into are removed; the trees of other voices
580
+ // are kept, since those voices are not being replaced.
288
581
  if (this.measures.length > 2) {
289
- for(let i = 1; i < this.measures.length - 2; i++) {
290
- this.measures[i].tupletTrees = [];
582
+ for (let i = 1; i < this.measures.length - 1; i++) {
583
+ this.measures[i].tupletTrees = this.measures[i].tupletTrees.filter(
584
+ (tree) => tree.voice !== this.destination.voice);
291
585
  }
292
586
  }
293
587
  }
@@ -439,7 +733,10 @@ export class PasteBuffer {
439
733
  return;
440
734
  }
441
735
  const selection: PasteNote = notes[this.noteIndex];
442
- const note: SmoNote = selection.note;
736
+ // The paste buffer holds the note in concert pitch. Work on a copy for this measure, since a
737
+ // note that doesn't fit is split and its remainder is pasted in the next measure by coming
738
+ // back through here: transposing the buffer's note in place would transpose that remainder twice.
739
+ const note: SmoNote = SmoNote.clone(selection.note);
443
740
  if (note.noteType === 'n') {
444
741
  const pitchAr: number[] = [];
445
742
  note.pitches.forEach((pitch, ix) => {
@@ -488,6 +785,9 @@ export class PasteBuffer {
488
785
  voice.notes.push(nnote);
489
786
  currentDuration += this.remainder;
490
787
  this.remainder = 0;
788
+ // The whole note has now been pasted, part in the previous measure and the rest here.
789
+ // Move on, or the loop would paste it again.
790
+ this.noteIndex += 1;
491
791
  } else {
492
792
  // The note won't fit, so we split it in 2 and paste the remainder in the next measure.
493
793
  // TODO: tie the last note to this one.
@@ -588,6 +588,74 @@ export class SmoSelection {
588
588
  }
589
589
  return rv;
590
590
  }
591
+ /**
592
+ * The (staff, measure) pairs that have at least one selection, in staff then measure order.
593
+ */
594
+ private static _selectedMeasurePairs(selections: SmoSelection[]): { staff: number, measure: number }[] {
595
+ const seen: Record<string, boolean> = {};
596
+ const rv: { staff: number, measure: number }[] = [];
597
+ selections.forEach((sel) => {
598
+ const key = SmoSelector.getMeasureKey(sel.selector);
599
+ if (!seen[key]) {
600
+ seen[key] = true;
601
+ rv.push({ staff: sel.selector.staff, measure: sel.selector.measure });
602
+ }
603
+ });
604
+ rv.sort((a, b) => a.staff !== b.staff ? a.staff - b.staff : a.measure - b.measure);
605
+ return rv;
606
+ }
607
+ /**
608
+ * Which voices the user can choose to select, given the current selection. Only the voices
609
+ * that exist in at least one measure that has a selection are offered; if every such measure has
610
+ * a single voice there is nothing to choose between, so the result is empty.
611
+ * @param score the score the selections are in
612
+ * @param selections the current selection
613
+ * @returns the voice numbers (0-3) to offer
614
+ */
615
+ static voiceChoices(score: SmoScore, selections: SmoSelection[]): number[] {
616
+ let maxVoices = 0;
617
+ SmoSelection._selectedMeasurePairs(selections).forEach((pair) => {
618
+ const measure = score.staves[pair.staff]?.measures[pair.measure];
619
+ if (measure) {
620
+ maxVoices = Math.max(maxVoices, measure.voices.length);
621
+ }
622
+ });
623
+ maxVoices = Math.min(maxVoices, 4);
624
+ const rv: number[] = [];
625
+ if (maxVoices < 2) {
626
+ return rv;
627
+ }
628
+ for (let i = 0; i < maxVoices; ++i) {
629
+ rv.push(i);
630
+ }
631
+ return rv;
632
+ }
633
+ /**
634
+ * All the notes (including rests) of one voice, in every measure that currently has a selection,
635
+ * on every staff that has a selection. The whole of each measure is used, not just the selected
636
+ * notes, since different voices can have different numbers of notes that overlap in different ways.
637
+ * A measure that does not have the voice contributes nothing, and the voice is never created.
638
+ * @param score the score the selections are in
639
+ * @param selections the current selection
640
+ * @param voice the voice to select (0-3)
641
+ * @returns a selector for each note of the voice, in staff, measure and tick order
642
+ */
643
+ static getVoiceSelectors(score: SmoScore, selections: SmoSelection[], voice: number): SmoSelector[] {
644
+ const rv: SmoSelector[] = [];
645
+ if (voice < 0 || voice > 3) {
646
+ return rv;
647
+ }
648
+ SmoSelection._selectedMeasurePairs(selections).forEach((pair) => {
649
+ const measure = score.staves[pair.staff]?.measures[pair.measure];
650
+ if (!measure || voice >= measure.voices.length) {
651
+ return;
652
+ }
653
+ for (let tick = 0; tick < measure.voices[voice].notes.length; ++tick) {
654
+ rv.push({ staff: pair.staff, measure: pair.measure, voice, tick, pitches: [] });
655
+ }
656
+ });
657
+ return rv;
658
+ }
591
659
  static getMeasuresBetween(score: SmoScore, fromSelector: SmoSelector, toSelector: SmoSelector): SmoSelection[] {
592
660
  let i = 0;
593
661
  const rv: SmoSelection[] = [];
@@ -112,6 +112,12 @@ export class UndoBuffer {
112
112
  reconcile: number = -1;
113
113
  opCount: number;
114
114
  _grouping: boolean;
115
+ /**
116
+ * Optional listener, called every time an undo step is recorded. Recording an undo step
117
+ * means the score is about to be modified, so a view can use this to track unsaved changes.
118
+ * It is not cleared by {@link reset}.
119
+ */
120
+ onAddBuffer?: () => void;
115
121
  constructor() {
116
122
  this.buffer.push(new UndoSet());
117
123
  this.opCount = 0;
@@ -214,6 +220,9 @@ export class UndoBuffer {
214
220
  if (!this._grouping) {
215
221
  this.buffer.push(new UndoSet());
216
222
  }
223
+ if (this.onAddBuffer) {
224
+ this.onAddBuffer();
225
+ }
217
226
  }
218
227
 
219
228
  /**
@@ -167,6 +167,7 @@ body.showAttributeDialog.textEditor .overlay {
167
167
  font-size: 0.9rem;
168
168
  }
169
169
  .side-brand {
170
+ position: relative;
170
171
  display: flex;
171
172
  align-items: center;
172
173
  gap: 8px;
@@ -175,6 +176,31 @@ body.showAttributeDialog.textEditor .overlay {
175
176
  letter-spacing: .12em;
176
177
  text-transform: uppercase;
177
178
  }
179
+ /* The open score's name after the app name; long names are truncated, the full name is in the tooltip.
180
+ The right padding keeps the name clear of the unsaved-changes asterisk. */
181
+ .side-brand .side-score {
182
+ flex: 1 1 auto;
183
+ min-width: 0;
184
+ padding-right: 14px;
185
+ overflow: hidden;
186
+ text-overflow: ellipsis;
187
+ white-space: nowrap;
188
+ text-transform: none;
189
+ letter-spacing: normal;
190
+ font-weight: 400;
191
+ }
192
+ /* Unsaved-changes asterisk: pinned to the right edge of the brand area so it is visible
193
+ even when the score name is truncated. */
194
+ .side-brand .side-changed {
195
+ position: absolute;
196
+ top: 4px;
197
+ bottom: 10px;
198
+ right: 6px;
199
+ display: flex;
200
+ align-items: center;
201
+ letter-spacing: normal;
202
+ font-weight: 700;
203
+ }
178
204
  .side-group {
179
205
  margin-top: var(--space-3);
180
206
  padding: 0 6px 4px;
@@ -285,7 +285,9 @@ export class RibbonButtons {
285
285
  buttonList.push(buttonData);
286
286
  }
287
287
  });
288
- createApp(ribbonSidebarApp as any, { buttonProps: buttonList, domId: selector instanceof HTMLElement ? selector.id : selector }).mount(selector);
288
+ createApp(ribbonSidebarApp as any, { buttonProps: buttonList,
289
+ domId: selector instanceof HTMLElement ? selector.id : selector,
290
+ scoreName: this.view.scoreName, scoreChanged: this.view.scoreChanged }).mount(selector);
289
291
  }
290
292
  createRibbon(buttonDataArray: string[], parentElement: string | HTMLElement) {
291
293
  this.createRibbonHtml(buttonDataArray, parentElement);
@@ -1,23 +1,32 @@
1
1
  <script setup lang="ts">
2
- import { ref } from 'vue';
2
+ import { ref, Ref, computed } from 'vue';
3
3
  import { ButtonDefinition } from '../../buttons/button';
4
4
  import buttonComp from './sidebarButtons.vue';
5
+ import { formatScoreTitle } from '../../../render/sui/scoreChangeState';
5
6
  interface Props {
6
7
  domId: string,
7
- buttonProps: ButtonDefinition[]
8
+ buttonProps: ButtonDefinition[],
9
+ scoreName: Ref<string>,
10
+ scoreChanged: Ref<boolean>
8
11
  }
9
12
  const props = defineProps < Props > ();
10
13
  const buttonProps = props.buttonProps;
11
14
  const domId = props.domId;
15
+ // Name of the open score. The unsaved-changes asterisk is a separate element, so it stays
16
+ // visible when a long name is truncated.
17
+ const scoreTitle = computed(() => formatScoreTitle(props.scoreName.value, false));
18
+ const scoreChanged = computed(() => props.scoreChanged.value);
12
19
  const getId = (str: string) => `${domId}-${str}`;
13
20
  const getClasses = (btnProps: ButtonDefinition) => `${btnProps.icon} ${btnProps.classes}`;
14
-
21
+ const imageLoc = '../../../styles/images/logo.png';
15
22
  </script>
16
23
  <template>
17
24
  <div class="side-brand">
18
- <span class="bv bv-gclef"></span>
19
- <span data-dc-tpl="158">Smoosic</span>
20
- </div>
25
+ <img :src="imageLoc" width="24" height="24">
26
+ <span>Smoosic</span>
27
+ <span class="side-score" :title="scoreTitle">{{ scoreTitle }}</span>
28
+ <span v-if="scoreChanged" class="side-changed" title="Unsaved changes" aria-label="Unsaved changes">*</span>
29
+ </div>
21
30
  <div class="side-group" role="group" :id="domId">
22
31
  <buttonComp v-for="props in buttonProps" :buttonProps="props" :domId="getId(props.id)" :key="props.id">
23
32
  </buttonComp>
@@ -10,6 +10,8 @@ interface Props {
10
10
  label: string,
11
11
  view: SuiScoreViewOperations,
12
12
  topLib: SmoLibrary,
13
+ /** called with the chosen score's url when the user presses OK; the caller loads it after this dialog closes */
14
+ selectedCb: (url: string) => void,
13
15
  commitCb: () => Promise<void>,
14
16
  cancelCb: () => Promise<void>
15
17
  }
@@ -92,7 +94,7 @@ const toggleExpand = (node: SmoLibrary) => {
92
94
 
93
95
  const confirmLoad = async () => {
94
96
  if (canLoad.value && selectedNode.value && selectedNode.value.url) {
95
- await props.view.loadRemoteScore(selectedNode.value.url);
97
+ props.selectedCb(selectedNode.value.url);
96
98
  }
97
99
  };
98
100
  // Matches SuiLibraryAdapter.cancel(): no-op.
@@ -0,0 +1,44 @@
1
+ <script setup lang="ts">
2
+ import { UnsavedChoice } from '../../../render/sui/scoreChangeState';
3
+ interface Props {
4
+ domId: string,
5
+ headline: string,
6
+ message: string,
7
+ choose: (choice: UnsavedChoice) => void,
8
+ commitCb: () => Promise<void>,
9
+ cancelCb: () => Promise<void>
10
+ }
11
+ const props = defineProps<Props>();
12
+ const { domId, headline, message, choose, commitCb, cancelCb } = { ...props };
13
+ const getDomId = () => {
14
+ return `attr-modal-dialog-${domId}`;
15
+ }
16
+ const getId = (str: string) => {
17
+ return `${domId}-${str}`;
18
+ }
19
+ // Record the choice, then close the dialog. Cancel closes through cancelCb.
20
+ const pick = async (choice: UnsavedChoice) => {
21
+ choose(choice);
22
+ await commitCb();
23
+ }
24
+ </script>
25
+ <template>
26
+ <div class="dlg spec attributeModal" :id="getDomId()">
27
+ <div class="container text-center" :id="getId('modal-content')">
28
+ <div class="row mb-2 dlg-bar">
29
+ <h2 class="dlg-title">{{ headline }}</h2>
30
+ </div>
31
+ <div class="text-input">
32
+ <p>{{ message }}</p>
33
+ </div>
34
+ <div class="buttonContainer">
35
+ <button :id="getId('save')" class="ok-button button-left btn btn-primary"
36
+ @click.prevent="pick('save')">Save</button>
37
+ <button :id="getId('discard')" class="button-center btn btn-secondary"
38
+ @click.prevent="pick('discard')">Don't save</button>
39
+ <button :id="getId('cancel')" class="cancel-button button-center btn btn-secondary"
40
+ @click.prevent="cancelCb">Cancel</button>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </template>