@sudobility/music_types 0.11.31 → 0.11.33

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 (42) hide show
  1. package/dist/domain/commands/note-commands.d.ts +8 -155
  2. package/dist/domain/commands/note-commands.d.ts.map +1 -1
  3. package/dist/domain/commands/note-commands.js +1 -423
  4. package/dist/domain/commands/note-commands.js.map +1 -1
  5. package/dist/domain/commands/note-marks.d.ts +171 -0
  6. package/dist/domain/commands/note-marks.d.ts.map +1 -0
  7. package/dist/domain/commands/note-marks.js +427 -0
  8. package/dist/domain/commands/note-marks.js.map +1 -0
  9. package/dist/domain/score/fragment.d.ts +3 -7
  10. package/dist/domain/score/fragment.d.ts.map +1 -1
  11. package/dist/domain/score/fragment.js.map +1 -1
  12. package/dist/domain/selection/types.d.ts +2 -2
  13. package/dist/domain/selection/types.d.ts.map +1 -1
  14. package/dist/index.d.ts +7 -5499
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +12 -461
  17. package/dist/index.js.map +1 -1
  18. package/dist/model/api.d.ts +1696 -0
  19. package/dist/model/api.d.ts.map +1 -0
  20. package/dist/model/api.js +125 -0
  21. package/dist/model/api.js.map +1 -0
  22. package/dist/model/generation.d.ts +2178 -0
  23. package/dist/model/generation.d.ts.map +1 -0
  24. package/dist/model/generation.js +142 -0
  25. package/dist/model/generation.js.map +1 -0
  26. package/dist/model/position.d.ts +82 -0
  27. package/dist/model/position.d.ts.map +1 -0
  28. package/dist/model/position.js +24 -0
  29. package/dist/model/position.js.map +1 -0
  30. package/dist/model/schemas.d.ts +1200 -0
  31. package/dist/model/schemas.d.ts.map +1 -0
  32. package/dist/model/schemas.js +200 -0
  33. package/dist/model/schemas.js.map +1 -0
  34. package/dist/model/score.d.ts +462 -0
  35. package/dist/model/score.d.ts.map +1 -0
  36. package/dist/model/score.js +34 -0
  37. package/dist/model/score.js.map +1 -0
  38. package/dist/model/selection-source.d.ts +53 -0
  39. package/dist/model/selection-source.d.ts.map +1 -0
  40. package/dist/model/selection-source.js +2 -0
  41. package/dist/model/selection-source.js.map +1 -0
  42. package/package.json +1 -1
@@ -1,6 +1,12 @@
1
- import type { Accidental, Articulation, DurationName, Hairpin, Ornament, Ottava, Pitch, UUID } from "../../index.js";
2
- import type { Dynamic, Lyric } from "../../index.js";
1
+ import type { Articulation, DurationName, NoteEvent, Pitch, Score, UUID } from "../../index.js";
3
2
  import type { ScoreCommand } from "./types.js";
3
+ /**
4
+ * Applies `updater` to every note event in `score` whose id is in
5
+ * `eventIds`; other events pass through unchanged. Preserves referential
6
+ * equality at every level (voice/measure/track) that has no matching
7
+ * event, so a call that matches nothing is a true no-op (see `withTracks`).
8
+ */
9
+ export declare function mapNotes(score: Score, eventIds: readonly UUID[], updater: (note: NoteEvent) => NoteEvent): Score;
4
10
  export type AddNoteParams = {
5
11
  trackId: UUID;
6
12
  measureId: UUID;
@@ -59,159 +65,6 @@ export declare function moveNotesCommand(eventIds: UUID[], params: MoveNotesPara
59
65
  export declare function resizeNotesCommand(eventIds: UUID[], durationTicks: number, label: string): ScoreCommand;
60
66
  /** Sets the given notes' duration to a named value (e.g. from the inspector), converted to ticks via the score's ppq. */
61
67
  export declare function changeDurationCommand(eventIds: UUID[], duration: DurationName, label: string): ScoreCommand;
62
- /** Sets the given notes' pitch to an absolute `Pitch`. */
63
- export declare function changePitchCommand(eventIds: UUID[], pitch: Pitch, label: string): ScoreCommand;
64
- /** Sets the given notes' velocity (0-127). */
65
- export declare function changeVelocityCommand(eventIds: UUID[], velocity: number, label: string): ScoreCommand;
66
- /** Sets (or clears, when `articulation` is `undefined`) the given notes' articulation. */
67
- export declare function changeArticulationCommand(eventIds: UUID[], articulation: Articulation | undefined, label: string): ScoreCommand;
68
- /**
69
- * Sets (or clears, when `ornament` is `undefined`) the given notes' ornament.
70
- *
71
- * Shaped like `changeArticulationCommand` rather than like the fermata toggle,
72
- * because an ornament is a choice among several rather than an on/off: a menu
73
- * sets the one it names, and "None" clears. A note carries at most one sign —
74
- * a trill that is also a turn is not a marking anybody writes.
75
- */
76
- export declare function changeOrnamentCommand(eventIds: UUID[], ornament: Ornament | undefined, label: string): ScoreCommand;
77
- /**
78
- * Puts a fermata on the given notes, or takes it off the ones that have one.
79
- *
80
- * Toggles on the *whole selection together* rather than per note: the state is
81
- * read from whether every selected note already carries one, so a mixed
82
- * selection gains fermatas rather than flipping each note independently. A
83
- * control that did the latter would leave a selection half-marked and look
84
- * broken.
85
- *
86
- * Unlike `toggleSlurCommand` this needs no endpoints and refuses nothing — a
87
- * fermata is a property of a single note, so one note is a perfectly good
88
- * selection and each marked note stands alone. Chords are marked note by note
89
- * because that is what the selection contains; the renderer draws one fermata
90
- * per notehead position, which is what a chord with a pause looks like.
91
- */
92
- export declare function toggleFermataCommand(eventIds: UUID[], label: string): ScoreCommand;
93
- /**
94
- * Sets or clears the dynamic marking the given notes start.
95
- *
96
- * A dynamic is stored on the note it applies *from* and governs until the next
97
- * one on that track, so marking one note `f` is how a passage becomes loud —
98
- * there is nothing to apply to the notes in between, and applying it to each
99
- * would print a marking under every notehead.
100
- */
101
- export declare function changeDynamicCommand(eventIds: UUID[], dynamic: Dynamic | undefined, label: string): ScoreCommand;
102
- /** Sets the given notes' pitch accidental, keeping their step/octave. */
103
- export declare function changeAccidentalCommand(eventIds: UUID[], accidental: Accidental, label: string): ScoreCommand;
104
- /** Toggles `tieStart` or `tieStop` on the given notes. */
105
- export declare function toggleTieCommand(eventIds: UUID[], which: "tieStart" | "tieStop", label: string): ScoreCommand;
106
- /**
107
- * Slurs a selection, or removes the slur it already carries.
108
- *
109
- * Takes the whole selection rather than a flag per note, because that is what
110
- * a slur is: one mark over a run of notes. The caller says "slur these" and
111
- * this decides which of them is the start and which the stop — marking them
112
- * individually would let a user create a start with no stop, which draws
113
- * nothing and is invisible to fix.
114
- *
115
- * Endpoints are the earliest and latest note by tick, not the order the ids
116
- * arrived in: a selection built by shift-clicking around a phrase is still
117
- * that phrase.
118
- *
119
- * Fewer than two notes cannot be slurred — a phrase mark over one note means
120
- * nothing — and toggling off is offered when the span is already slurred, so
121
- * the same control removes what it made.
122
- */
123
- export declare function toggleSlurCommand(eventIds: UUID[], label: string): ScoreCommand;
124
- /**
125
- * Writes a hairpin across the selection, or removes the one it already has.
126
- *
127
- * Shaped like `toggleSlurCommand`, because a hairpin is the same kind of thing
128
- * — one mark over a run of notes. The caller says "crescendo these" and this
129
- * decides which of them opens it and which closes it; marking them one at a
130
- * time would let a user create an opening with no close, which draws nothing
131
- * and is invisible to fix.
132
- *
133
- * Endpoints are the earliest and latest note **by tick**, not the order the
134
- * ids arrived in, so a selection built by shift-clicking around a phrase is
135
- * still that phrase.
136
- *
137
- * Fewer than two notes is refused: a wedge over one note has nowhere to open
138
- * to. Re-applying the **same** direction to a span that already carries it
139
- * removes it, so one control undoes what it made; applying the **other**
140
- * direction flips it, which is what reaching for the other button means.
141
- */
142
- export declare function toggleHairpinCommand(eventIds: UUID[], hairpin: Hairpin, label: string): ScoreCommand;
143
- /**
144
- * Rolls the selected chords, or stops rolling them.
145
- *
146
- * Toggles the whole selection together, like the fermata: the state is read
147
- * from whether *every* selected note already carries the flag, so a partly
148
- * marked selection becomes fully marked rather than inverting note by note.
149
- *
150
- * The mark belongs to a chord, but the selection is notes — so this simply
151
- * sets the flag on what was selected and lets the renderer decide. A lone note
152
- * keeps the flag harmlessly and draws nothing, which is better than refusing:
153
- * selecting a bar and rolling its chords should not fail because one beat
154
- * happens to be a single note.
155
- */
156
- export declare function toggleArpeggiateCommand(eventIds: UUID[], label: string): ScoreCommand;
157
- /**
158
- * Brackets the selection at an octave, or removes the bracket it has.
159
- *
160
- * A span like the hairpin: endpoints by tick, two notes minimum, the same
161
- * displacement twice removes it and a different one replaces it.
162
- */
163
- export declare function toggleOttavaCommand(eventIds: UUID[], ottava: Ottava, label: string): ScoreCommand;
164
- /**
165
- * Slides between the selected notes, or removes the slide.
166
- *
167
- * Two notes exactly is the usual case and two is the minimum: a glissando is
168
- * a line *between* noteheads, so one note has nothing to slide to. A wider
169
- * selection slides from its first note to its last, which is what dragging
170
- * across a run and asking for a slide means.
171
- */
172
- export declare function toggleGlissandoCommand(eventIds: UUID[], label: string): ScoreCommand;
173
- /**
174
- * Sets or clears the finger written on the given notes.
175
- *
176
- * Blank clears it rather than storing an empty string, which would reserve
177
- * space beside the notehead and print nothing.
178
- */
179
- export declare function setFingeringCommand(eventIds: UUID[], fingering: string | undefined, label: string): ScoreCommand;
180
- /**
181
- * Sets or clears the syllable sung on one note.
182
- *
183
- * One note at a time, unlike the other note commands: every syllable in a line
184
- * is different, so applying one across a selection could only ever write the
185
- * same word repeatedly.
186
- *
187
- * Blank text clears the lyric rather than storing an empty one — an empty
188
- * syllable would reserve space under the note and print nothing.
189
- */
190
- export declare function setLyricCommand(eventId: UUID, lyric: Lyric | undefined, label: string): ScoreCommand;
191
- /**
192
- * Sets or clears the chord symbol printed from a note.
193
- *
194
- * One note at a time, like a lyric: every chord in a progression is different,
195
- * so applying one across a selection could only write the same symbol
196
- * repeatedly. Blank text clears it rather than storing an empty symbol, which
197
- * would reserve space above the stave and print nothing.
198
- */
199
- export declare function setChordSymbolCommand(eventId: UUID, symbol: string | undefined, label: string): ScoreCommand;
200
- /**
201
- * Turns a written note into a grace note on the note that follows it.
202
- *
203
- * The note leaves the voice and reappears hanging off its neighbour, and the
204
- * gap it leaves is filled with a rest — so the bar still adds up, which is the
205
- * whole reason grace notes are stored on their principal rather than as events
206
- * of their own.
207
- *
208
- * The principal is the next note *in the same voice*, since that is what the
209
- * ornament leads into. A note with nothing after it cannot become one: an
210
- * ornament with nothing to ornament would simply vanish from the page.
211
- */
212
- export declare function toGraceNoteCommand(eventId: UUID, label: string): ScoreCommand;
213
- /** Removes every ornament from the given notes. */
214
- export declare function clearGraceNotesCommand(eventIds: UUID[], label: string): ScoreCommand;
215
68
  /** Moves the given notes to the voice at ordinal position `targetVoiceIndex` within their current measure (created if absent). */
216
69
  export declare function changeVoiceCommand(eventIds: UUID[], targetVoiceIndex: number, label: string): ScoreCommand;
217
70
  //# sourceMappingURL=note-commands.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"note-commands.d.ts","sourceRoot":"","sources":["../../../src/domain/commands/note-commands.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,OAAO,EAEP,QAAQ,EACR,MAAM,EACN,KAAK,EAGL,IAAI,EACL,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAa,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAIhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA+C/C,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAwBF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,MAAM,GACZ,YAAY,CAEd;AAgBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,IAAI,EAAE,EAChB,KAAK,EAAE,MAAM,GACZ,YAAY,CAEd;AAID,MAAM,MAAM,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC;AAiF7E;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,IAAI,EAAE,EAChB,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,MAAM,GACZ,YAAY,CAEd;AA0CD;;;;GAIG;AACH,wBA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E,IAAI,EAAE,EAChB,KAAK,EAAE,MAAM,GACZ,YAAY,CAEd;AAID,MAAM,MAAM,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC;AAiF7E;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,IAAI,EAAE,EAChB,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,MAAM,GACZ,YAAY,CAEd;AA0CD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,IAAI,EAAE,EAChB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,GACZ,YAAY,CAId;AAED,yHAAyH;AACzH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,IAAI,EAAE,EAChB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,GACZ,YAAY,CAId;AA0DD,kIAAkI;AAClI,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,IAAI,EAAE,EAChB,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,MAAM,GACZ,YAAY,CAId"}
@@ -13,7 +13,6 @@
13
13
  import { createId } from "../score/ids.js";
14
14
  import { splitNoteAcrossMeasures } from "../score/ties.js";
15
15
  import { isNoteEvent } from "../../index.js";
16
- import { findEvent } from "../score/queries.js";
17
16
  import { ticksFor } from "../time/ticks.js";
18
17
  import { transposePitch } from "../pitch/transpose.js";
19
18
  import { transformCommand } from "./snapshot.js";
@@ -25,7 +24,7 @@ import { clearDanglingTies, ensureVoiceAtIndex, insertNoteIntoTrack, removeNotes
25
24
  * equality at every level (voice/measure/track) that has no matching
26
25
  * event, so a call that matches nothing is a true no-op (see `withTracks`).
27
26
  */
28
- function mapNotes(score, eventIds, updater) {
27
+ export function mapNotes(score, eventIds, updater) {
29
28
  const idSet = new Set(eventIds);
30
29
  const tracks = score.tracks.map((track) => {
31
30
  const measures = track.measures.map((measure) => {
@@ -209,427 +208,6 @@ export function resizeNotesCommand(eventIds, durationTicks, label) {
209
208
  export function changeDurationCommand(eventIds, duration, label) {
210
209
  return transformCommand(label, (score) => resizeNotes(score, eventIds, ticksFor(duration, score.ppq)));
211
210
  }
212
- // ---- simple per-note field commands ------------------------------------------
213
- /** Sets the given notes' pitch to an absolute `Pitch`. */
214
- export function changePitchCommand(eventIds, pitch, label) {
215
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => ({ ...note, pitch })));
216
- }
217
- /** Sets the given notes' velocity (0-127). */
218
- export function changeVelocityCommand(eventIds, velocity, label) {
219
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => ({ ...note, velocity })));
220
- }
221
- /** Sets (or clears, when `articulation` is `undefined`) the given notes' articulation. */
222
- export function changeArticulationCommand(eventIds, articulation, label) {
223
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => {
224
- if (articulation)
225
- return { ...note, articulation };
226
- const updated = { ...note };
227
- delete updated.articulation;
228
- return updated;
229
- }));
230
- }
231
- /**
232
- * Sets (or clears, when `ornament` is `undefined`) the given notes' ornament.
233
- *
234
- * Shaped like `changeArticulationCommand` rather than like the fermata toggle,
235
- * because an ornament is a choice among several rather than an on/off: a menu
236
- * sets the one it names, and "None" clears. A note carries at most one sign —
237
- * a trill that is also a turn is not a marking anybody writes.
238
- */
239
- export function changeOrnamentCommand(eventIds, ornament, label) {
240
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => {
241
- if (ornament)
242
- return { ...note, ornament };
243
- const updated = { ...note };
244
- delete updated.ornament;
245
- return updated;
246
- }));
247
- }
248
- /**
249
- * Puts a fermata on the given notes, or takes it off the ones that have one.
250
- *
251
- * Toggles on the *whole selection together* rather than per note: the state is
252
- * read from whether every selected note already carries one, so a mixed
253
- * selection gains fermatas rather than flipping each note independently. A
254
- * control that did the latter would leave a selection half-marked and look
255
- * broken.
256
- *
257
- * Unlike `toggleSlurCommand` this needs no endpoints and refuses nothing — a
258
- * fermata is a property of a single note, so one note is a perfectly good
259
- * selection and each marked note stands alone. Chords are marked note by note
260
- * because that is what the selection contains; the renderer draws one fermata
261
- * per notehead position, which is what a chord with a pause looks like.
262
- */
263
- export function toggleFermataCommand(eventIds, label) {
264
- return transformCommand(label, (score) => {
265
- const notes = eventIds
266
- .map((id) => findEvent(score, id))
267
- .filter((event) => event !== null && isNoteEvent(event));
268
- if (notes.length === 0)
269
- return score;
270
- // Only remove when every selected note already has one, so a selection
271
- // that is partly marked becomes fully marked rather than inverting.
272
- const allMarked = notes.every((note) => note.fermata);
273
- return mapNotes(score, eventIds, (note) => {
274
- if (allMarked) {
275
- const updated = { ...note };
276
- delete updated.fermata;
277
- return updated;
278
- }
279
- return { ...note, fermata: true };
280
- });
281
- });
282
- }
283
- /**
284
- * Sets or clears the dynamic marking the given notes start.
285
- *
286
- * A dynamic is stored on the note it applies *from* and governs until the next
287
- * one on that track, so marking one note `f` is how a passage becomes loud —
288
- * there is nothing to apply to the notes in between, and applying it to each
289
- * would print a marking under every notehead.
290
- */
291
- export function changeDynamicCommand(eventIds, dynamic, label) {
292
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => {
293
- if (dynamic)
294
- return { ...note, dynamic };
295
- const updated = { ...note };
296
- delete updated.dynamic;
297
- return updated;
298
- }));
299
- }
300
- /** Sets the given notes' pitch accidental, keeping their step/octave. */
301
- export function changeAccidentalCommand(eventIds, accidental, label) {
302
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => ({
303
- ...note,
304
- pitch: { ...note.pitch, accidental },
305
- })));
306
- }
307
- /** Toggles `tieStart` or `tieStop` on the given notes. */
308
- export function toggleTieCommand(eventIds, which, label) {
309
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => ({ ...note, [which]: !note[which] })));
310
- }
311
- /**
312
- * Slurs a selection, or removes the slur it already carries.
313
- *
314
- * Takes the whole selection rather than a flag per note, because that is what
315
- * a slur is: one mark over a run of notes. The caller says "slur these" and
316
- * this decides which of them is the start and which the stop — marking them
317
- * individually would let a user create a start with no stop, which draws
318
- * nothing and is invisible to fix.
319
- *
320
- * Endpoints are the earliest and latest note by tick, not the order the ids
321
- * arrived in: a selection built by shift-clicking around a phrase is still
322
- * that phrase.
323
- *
324
- * Fewer than two notes cannot be slurred — a phrase mark over one note means
325
- * nothing — and toggling off is offered when the span is already slurred, so
326
- * the same control removes what it made.
327
- */
328
- export function toggleSlurCommand(eventIds, label) {
329
- return transformCommand(label, (score) => {
330
- const notes = eventIds
331
- .map((id) => findEvent(score, id))
332
- .filter((event) => event !== null && isNoteEvent(event))
333
- .sort((a, b) => a.startTick - b.startTick);
334
- if (notes.length < 2)
335
- return score;
336
- const first = notes[0];
337
- const last = notes[notes.length - 1];
338
- const alreadySlurred = Boolean(first.slurStart && last.slurStop);
339
- return mapNotes(score, eventIds, (note) => {
340
- const updated = { ...note };
341
- delete updated.slurStart;
342
- delete updated.slurStop;
343
- if (alreadySlurred)
344
- return updated;
345
- if (note.id === first.id)
346
- updated.slurStart = true;
347
- if (note.id === last.id)
348
- updated.slurStop = true;
349
- return updated;
350
- });
351
- });
352
- }
353
- /**
354
- * Writes a hairpin across the selection, or removes the one it already has.
355
- *
356
- * Shaped like `toggleSlurCommand`, because a hairpin is the same kind of thing
357
- * — one mark over a run of notes. The caller says "crescendo these" and this
358
- * decides which of them opens it and which closes it; marking them one at a
359
- * time would let a user create an opening with no close, which draws nothing
360
- * and is invisible to fix.
361
- *
362
- * Endpoints are the earliest and latest note **by tick**, not the order the
363
- * ids arrived in, so a selection built by shift-clicking around a phrase is
364
- * still that phrase.
365
- *
366
- * Fewer than two notes is refused: a wedge over one note has nowhere to open
367
- * to. Re-applying the **same** direction to a span that already carries it
368
- * removes it, so one control undoes what it made; applying the **other**
369
- * direction flips it, which is what reaching for the other button means.
370
- */
371
- export function toggleHairpinCommand(eventIds, hairpin, label) {
372
- return transformCommand(label, (score) => {
373
- const notes = eventIds
374
- .map((id) => findEvent(score, id))
375
- .filter((event) => event !== null && isNoteEvent(event))
376
- .sort((a, b) => a.startTick - b.startTick);
377
- if (notes.length < 2)
378
- return score;
379
- const first = notes[0];
380
- const last = notes[notes.length - 1];
381
- const sameAlready = first.hairpinStart === hairpin && Boolean(last.hairpinStop);
382
- return mapNotes(score, eventIds, (note) => {
383
- const updated = { ...note };
384
- delete updated.hairpinStart;
385
- delete updated.hairpinStop;
386
- if (sameAlready)
387
- return updated;
388
- if (note.id === first.id)
389
- updated.hairpinStart = hairpin;
390
- if (note.id === last.id)
391
- updated.hairpinStop = true;
392
- return updated;
393
- });
394
- });
395
- }
396
- /**
397
- * Rolls the selected chords, or stops rolling them.
398
- *
399
- * Toggles the whole selection together, like the fermata: the state is read
400
- * from whether *every* selected note already carries the flag, so a partly
401
- * marked selection becomes fully marked rather than inverting note by note.
402
- *
403
- * The mark belongs to a chord, but the selection is notes — so this simply
404
- * sets the flag on what was selected and lets the renderer decide. A lone note
405
- * keeps the flag harmlessly and draws nothing, which is better than refusing:
406
- * selecting a bar and rolling its chords should not fail because one beat
407
- * happens to be a single note.
408
- */
409
- export function toggleArpeggiateCommand(eventIds, label) {
410
- return transformCommand(label, (score) => {
411
- const notes = eventIds
412
- .map((id) => findEvent(score, id))
413
- .filter((event) => event !== null && isNoteEvent(event));
414
- if (notes.length === 0)
415
- return score;
416
- const allMarked = notes.every((note) => note.arpeggiate);
417
- return mapNotes(score, eventIds, (note) => {
418
- if (allMarked) {
419
- const updated = { ...note };
420
- delete updated.arpeggiate;
421
- return updated;
422
- }
423
- return { ...note, arpeggiate: true };
424
- });
425
- });
426
- }
427
- /**
428
- * Brackets the selection at an octave, or removes the bracket it has.
429
- *
430
- * A span like the hairpin: endpoints by tick, two notes minimum, the same
431
- * displacement twice removes it and a different one replaces it.
432
- */
433
- export function toggleOttavaCommand(eventIds, ottava, label) {
434
- return transformCommand(label, (score) => {
435
- const notes = eventIds
436
- .map((id) => findEvent(score, id))
437
- .filter((event) => event !== null && isNoteEvent(event))
438
- .sort((a, b) => a.startTick - b.startTick);
439
- if (notes.length < 2)
440
- return score;
441
- const first = notes[0];
442
- const last = notes[notes.length - 1];
443
- const sameAlready = first.ottavaStart === ottava && Boolean(last.ottavaStop);
444
- return mapNotes(score, eventIds, (note) => {
445
- const updated = { ...note };
446
- delete updated.ottavaStart;
447
- delete updated.ottavaStop;
448
- if (sameAlready)
449
- return updated;
450
- if (note.id === first.id)
451
- updated.ottavaStart = ottava;
452
- if (note.id === last.id)
453
- updated.ottavaStop = true;
454
- return updated;
455
- });
456
- });
457
- }
458
- /**
459
- * Slides between the selected notes, or removes the slide.
460
- *
461
- * Two notes exactly is the usual case and two is the minimum: a glissando is
462
- * a line *between* noteheads, so one note has nothing to slide to. A wider
463
- * selection slides from its first note to its last, which is what dragging
464
- * across a run and asking for a slide means.
465
- */
466
- export function toggleGlissandoCommand(eventIds, label) {
467
- return transformCommand(label, (score) => {
468
- const notes = eventIds
469
- .map((id) => findEvent(score, id))
470
- .filter((event) => event !== null && isNoteEvent(event))
471
- .sort((a, b) => a.startTick - b.startTick);
472
- if (notes.length < 2)
473
- return score;
474
- const first = notes[0];
475
- const last = notes[notes.length - 1];
476
- const already = Boolean(first.glissandoStart && last.glissandoStop);
477
- return mapNotes(score, eventIds, (note) => {
478
- const updated = { ...note };
479
- delete updated.glissandoStart;
480
- delete updated.glissandoStop;
481
- if (already)
482
- return updated;
483
- if (note.id === first.id)
484
- updated.glissandoStart = true;
485
- if (note.id === last.id)
486
- updated.glissandoStop = true;
487
- return updated;
488
- });
489
- });
490
- }
491
- /**
492
- * Sets or clears the finger written on the given notes.
493
- *
494
- * Blank clears it rather than storing an empty string, which would reserve
495
- * space beside the notehead and print nothing.
496
- */
497
- export function setFingeringCommand(eventIds, fingering, label) {
498
- const trimmed = fingering?.trim();
499
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => {
500
- if (trimmed)
501
- return { ...note, fingering: trimmed };
502
- const updated = { ...note };
503
- delete updated.fingering;
504
- return updated;
505
- }));
506
- }
507
- /**
508
- * Sets or clears the syllable sung on one note.
509
- *
510
- * One note at a time, unlike the other note commands: every syllable in a line
511
- * is different, so applying one across a selection could only ever write the
512
- * same word repeatedly.
513
- *
514
- * Blank text clears the lyric rather than storing an empty one — an empty
515
- * syllable would reserve space under the note and print nothing.
516
- */
517
- export function setLyricCommand(eventId, lyric, label) {
518
- return transformCommand(label, (score) => mapNotes(score, [eventId], (note) => {
519
- const updated = { ...note };
520
- if (!lyric || lyric.text.trim() === "") {
521
- delete updated.lyric;
522
- return updated;
523
- }
524
- updated.lyric = {
525
- text: lyric.text.trim(),
526
- // `single` is the default the model states, so storing it would only
527
- // be noise in every saved score.
528
- ...(lyric.syllabic && lyric.syllabic !== "single"
529
- ? { syllabic: lyric.syllabic }
530
- : {}),
531
- };
532
- return updated;
533
- }));
534
- }
535
- /**
536
- * Sets or clears the chord symbol printed from a note.
537
- *
538
- * One note at a time, like a lyric: every chord in a progression is different,
539
- * so applying one across a selection could only write the same symbol
540
- * repeatedly. Blank text clears it rather than storing an empty symbol, which
541
- * would reserve space above the stave and print nothing.
542
- */
543
- export function setChordSymbolCommand(eventId, symbol, label) {
544
- return transformCommand(label, (score) => mapNotes(score, [eventId], (note) => {
545
- const updated = { ...note };
546
- const trimmed = symbol?.trim();
547
- if (!trimmed) {
548
- delete updated.chordSymbol;
549
- return updated;
550
- }
551
- updated.chordSymbol = trimmed;
552
- return updated;
553
- }));
554
- }
555
- /**
556
- * Turns a written note into a grace note on the note that follows it.
557
- *
558
- * The note leaves the voice and reappears hanging off its neighbour, and the
559
- * gap it leaves is filled with a rest — so the bar still adds up, which is the
560
- * whole reason grace notes are stored on their principal rather than as events
561
- * of their own.
562
- *
563
- * The principal is the next note *in the same voice*, since that is what the
564
- * ornament leads into. A note with nothing after it cannot become one: an
565
- * ornament with nothing to ornament would simply vanish from the page.
566
- */
567
- export function toGraceNoteCommand(eventId, label) {
568
- return transformCommand(label, (score) => {
569
- const tracks = score.tracks.map((track) => ({
570
- ...track,
571
- measures: track.measures.map((measure) => ({
572
- ...measure,
573
- voices: measure.voices.map((voice) => {
574
- const index = voice.events.findIndex((e) => e.id === eventId);
575
- if (index === -1)
576
- return voice;
577
- const source = voice.events[index];
578
- if (!isNoteEvent(source))
579
- return voice;
580
- // The principal: the next *note* after it in this voice.
581
- const principalIndex = voice.events.findIndex((e, i) => i > index && isNoteEvent(e));
582
- if (principalIndex === -1)
583
- return voice;
584
- const principal = voice.events[principalIndex];
585
- const grace = {
586
- pitch: source.pitch,
587
- durationTicks: source.durationTicks,
588
- slashed: true,
589
- };
590
- /*
591
- Ornaments the source itself carried travel with it, ahead of the
592
- note it becomes: turning a decorated note into a grace note should
593
- move the whole ornamental run to the new principal, not silently
594
- drop everything in front of it.
595
- */
596
- const carried = [...(source.graceNotes ?? []), grace];
597
- return {
598
- ...voice,
599
- events: voice.events.map((event, i) => {
600
- // The time the note occupied stays occupied, by a rest: an
601
- // ornament borrows from its principal, it does not shorten the
602
- // bar.
603
- if (i === index)
604
- return {
605
- id: source.id,
606
- startTick: source.startTick,
607
- durationTicks: source.durationTicks,
608
- voiceId: source.voiceId,
609
- trackId: source.trackId,
610
- };
611
- if (i === principalIndex)
612
- return {
613
- ...principal,
614
- graceNotes: [...(principal.graceNotes ?? []), ...carried],
615
- };
616
- return event;
617
- }),
618
- };
619
- }),
620
- })),
621
- }));
622
- return withTracks(score, tracks);
623
- });
624
- }
625
- /** Removes every ornament from the given notes. */
626
- export function clearGraceNotesCommand(eventIds, label) {
627
- return transformCommand(label, (score) => mapNotes(score, eventIds, (note) => {
628
- const updated = { ...note };
629
- delete updated.graceNotes;
630
- return updated;
631
- }));
632
- }
633
211
  // ---- changeVoiceCommand -----------------------------------------------------------
634
212
  function changeVoice(score, eventIds, targetVoiceIndex) {
635
213
  const idSet = new Set(eventIds);