musicxml-io 0.2.7 → 0.2.8

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.
@@ -20,20 +20,83 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/query/index.ts
21
21
  var query_exports = {};
22
22
  __export(query_exports, {
23
+ buildVoiceToStaffMap: () => buildVoiceToStaffMap,
24
+ buildVoiceToStaffMapForPart: () => buildVoiceToStaffMapForPart,
23
25
  countNotes: () => countNotes,
26
+ findBarlines: () => findBarlines,
27
+ findDirectionsByType: () => findDirectionsByType,
24
28
  findNotes: () => findNotes,
29
+ findNotesWithNotation: () => findNotesWithNotation,
30
+ getAbsolutePosition: () => getAbsolutePosition,
31
+ getAdjacentNotes: () => getAdjacentNotes,
32
+ getAllNotes: () => getAllNotes,
25
33
  getAttributesAtMeasure: () => getAttributesAtMeasure,
34
+ getBeamGroups: () => getBeamGroups,
35
+ getChordProgression: () => getChordProgression,
36
+ getChords: () => getChords,
37
+ getClefChanges: () => getClefChanges,
38
+ getClefForStaff: () => getClefForStaff,
39
+ getDirections: () => getDirections,
40
+ getDirectionsAtPosition: () => getDirectionsAtPosition,
26
41
  getDivisions: () => getDivisions,
27
42
  getDuration: () => getDuration,
43
+ getDynamics: () => getDynamics,
44
+ getEffectiveStaff: () => getEffectiveStaff,
45
+ getEndings: () => getEndings,
46
+ getEntriesAtPosition: () => getEntriesAtPosition,
47
+ getEntriesForStaff: () => getEntriesForStaff,
48
+ getEntriesInRange: () => getEntriesInRange,
49
+ getHarmonies: () => getHarmonies,
50
+ getHarmonyAtPosition: () => getHarmonyAtPosition,
51
+ getKeyChanges: () => getKeyChanges,
52
+ getLyricText: () => getLyricText,
53
+ getLyrics: () => getLyrics,
28
54
  getMeasure: () => getMeasure,
29
55
  getMeasureByIndex: () => getMeasureByIndex,
30
56
  getMeasureCount: () => getMeasureCount,
57
+ getNextNote: () => getNextNote,
58
+ getNormalizedDuration: () => getNormalizedDuration,
59
+ getNormalizedPosition: () => getNormalizedPosition,
60
+ getNotesAtPosition: () => getNotesAtPosition,
61
+ getNotesForStaff: () => getNotesForStaff,
62
+ getNotesForVoice: () => getNotesForVoice,
63
+ getNotesInRange: () => getNotesInRange,
64
+ getOctaveShifts: () => getOctaveShifts,
31
65
  getPartById: () => getPartById,
66
+ getPartByIndex: () => getPartByIndex,
67
+ getPartCount: () => getPartCount,
68
+ getPartIds: () => getPartIds,
32
69
  getPartIndex: () => getPartIndex,
70
+ getPedalMarkings: () => getPedalMarkings,
71
+ getPrevNote: () => getPrevNote,
72
+ getRepeatStructure: () => getRepeatStructure,
73
+ getSlurSpans: () => getSlurSpans,
74
+ getStaffRange: () => getStaffRange,
33
75
  getStaveCount: () => getStaveCount,
76
+ getStaves: () => getStaves,
77
+ getStructuralChanges: () => getStructuralChanges,
78
+ getTempoMarkings: () => getTempoMarkings,
79
+ getTiedNoteGroups: () => getTiedNoteGroups,
80
+ getTimeChanges: () => getTimeChanges,
81
+ getTupletGroups: () => getTupletGroups,
82
+ getVerseCount: () => getVerseCount,
83
+ getVerticalSlice: () => getVerticalSlice,
84
+ getVoiceLine: () => getVoiceLine,
85
+ getVoiceLineInRange: () => getVoiceLineInRange,
86
+ getVoices: () => getVoices,
87
+ getVoicesForStaff: () => getVoicesForStaff,
88
+ getWedges: () => getWedges,
89
+ groupByStaff: () => groupByStaff,
90
+ groupByVoice: () => groupByVoice,
34
91
  hasMultipleStaves: () => hasMultipleStaves,
92
+ hasNotes: () => hasNotes,
93
+ inferStaff: () => inferStaff,
94
+ isRestMeasure: () => isRestMeasure,
95
+ iterateEntries: () => iterateEntries,
96
+ iterateNotes: () => iterateNotes,
35
97
  measureRoundtrip: () => measureRoundtrip,
36
- scoresEqual: () => scoresEqual
98
+ scoresEqual: () => scoresEqual,
99
+ withAbsolutePositions: () => withAbsolutePositions
37
100
  });
38
101
  module.exports = __toCommonJS(query_exports);
39
102
 
@@ -50,8 +113,1388 @@ var STEP_SEMITONES = {
50
113
  function pitchToSemitone(pitch) {
51
114
  return pitch.octave * 12 + STEP_SEMITONES[pitch.step] + (pitch.alter ?? 0);
52
115
  }
116
+ function createPositionState() {
117
+ return { position: 0, lastNonChordPosition: 0 };
118
+ }
119
+ function updatePositionForEntry(state, entry) {
120
+ const pos = state.position;
121
+ switch (entry.type) {
122
+ case "note": {
123
+ const note = entry;
124
+ if (!note.chord) {
125
+ state.lastNonChordPosition = state.position;
126
+ state.position += note.duration;
127
+ }
128
+ return note.chord ? state.lastNonChordPosition : pos;
129
+ }
130
+ case "backup":
131
+ state.position -= entry.duration;
132
+ state.lastNonChordPosition = state.position;
133
+ return pos;
134
+ case "forward":
135
+ state.position += entry.duration;
136
+ state.lastNonChordPosition = state.position;
137
+ return pos;
138
+ default:
139
+ return pos;
140
+ }
141
+ }
142
+ function getAbsolutePositionForNote(note, measure) {
143
+ const state = createPositionState();
144
+ for (const entry of measure.entries) {
145
+ if (entry === note) return entry.chord ? state.lastNonChordPosition : state.position;
146
+ updatePositionForEntry(state, entry);
147
+ }
148
+ return state.position;
149
+ }
53
150
 
54
151
  // src/query/index.ts
152
+ function getNotesForVoice(measure, filter) {
153
+ return measure.entries.filter((entry) => {
154
+ if (entry.type !== "note") return false;
155
+ if (filter.voice !== void 0 && entry.voice !== filter.voice) return false;
156
+ if (filter.staff !== void 0 && (entry.staff ?? 1) !== filter.staff) return false;
157
+ return true;
158
+ });
159
+ }
160
+ function getNotesForStaff(measure, filter) {
161
+ return measure.entries.filter((entry) => {
162
+ if (entry.type !== "note") return false;
163
+ return (entry.staff ?? 1) === filter.staff;
164
+ });
165
+ }
166
+ function groupByVoice(measure) {
167
+ const groups = /* @__PURE__ */ new Map();
168
+ for (const entry of measure.entries) {
169
+ if (entry.type !== "note") continue;
170
+ const staff = entry.staff ?? 1;
171
+ const voice = entry.voice;
172
+ const key = `${staff}-${voice}`;
173
+ if (!groups.has(key)) {
174
+ groups.set(key, { staff, voice, notes: [] });
175
+ }
176
+ groups.get(key).notes.push(entry);
177
+ }
178
+ return Array.from(groups.values()).sort((a, b) => {
179
+ if (a.staff !== b.staff) return a.staff - b.staff;
180
+ return a.voice - b.voice;
181
+ });
182
+ }
183
+ function groupByStaff(measure) {
184
+ const groups = /* @__PURE__ */ new Map();
185
+ for (const entry of measure.entries) {
186
+ if (entry.type !== "note") continue;
187
+ const staff = entry.staff ?? 1;
188
+ if (!groups.has(staff)) {
189
+ groups.set(staff, { staff, notes: [] });
190
+ }
191
+ groups.get(staff).notes.push(entry);
192
+ }
193
+ return Array.from(groups.values()).sort((a, b) => a.staff - b.staff);
194
+ }
195
+ function getAbsolutePosition(note, measure) {
196
+ return getAbsolutePositionForNote(note, measure);
197
+ }
198
+ function withAbsolutePositions(measure) {
199
+ const result = [];
200
+ const state = createPositionState();
201
+ for (const entry of measure.entries) {
202
+ if (entry.type === "note") {
203
+ const notePosition = entry.chord ? state.lastNonChordPosition : state.position;
204
+ result.push({
205
+ ...entry,
206
+ absolutePosition: notePosition
207
+ });
208
+ }
209
+ updatePositionForEntry(state, entry);
210
+ }
211
+ return result;
212
+ }
213
+ function getChords(measure, filter) {
214
+ const notesWithPos = withAbsolutePositions(measure);
215
+ const filteredNotes = filter ? notesWithPos.filter((note) => {
216
+ if (filter.voice !== void 0 && note.voice !== filter.voice) return false;
217
+ if (filter.staff !== void 0 && (note.staff ?? 1) !== filter.staff) return false;
218
+ return true;
219
+ }) : notesWithPos;
220
+ const chordMap = /* @__PURE__ */ new Map();
221
+ for (const note of filteredNotes) {
222
+ const pos = note.absolutePosition;
223
+ if (!chordMap.has(pos)) {
224
+ chordMap.set(pos, []);
225
+ }
226
+ chordMap.get(pos).push(note);
227
+ }
228
+ const chords = [];
229
+ for (const [position, notes] of chordMap.entries()) {
230
+ const duration = notes[0].duration;
231
+ chords.push({
232
+ position,
233
+ duration,
234
+ notes: notes.map(({ absolutePosition, ...note }) => note)
235
+ });
236
+ }
237
+ return chords.sort((a, b) => a.position - b.position);
238
+ }
239
+ function* iterateNotes(score) {
240
+ for (const part of score.parts) {
241
+ for (const measure of part.measures) {
242
+ const state = createPositionState();
243
+ for (const entry of measure.entries) {
244
+ if (entry.type === "note") {
245
+ const notePosition = entry.chord ? state.lastNonChordPosition : state.position;
246
+ yield {
247
+ part,
248
+ measure,
249
+ note: entry,
250
+ position: notePosition
251
+ };
252
+ }
253
+ updatePositionForEntry(state, entry);
254
+ }
255
+ }
256
+ }
257
+ }
258
+ function getAllNotes(score) {
259
+ return Array.from(iterateNotes(score));
260
+ }
261
+ function getVoices(measure) {
262
+ const voices = /* @__PURE__ */ new Set();
263
+ for (const entry of measure.entries) {
264
+ if (entry.type === "note") {
265
+ voices.add(entry.voice);
266
+ }
267
+ }
268
+ return Array.from(voices).sort((a, b) => a - b);
269
+ }
270
+ function getStaves(measure) {
271
+ const staves = /* @__PURE__ */ new Set();
272
+ for (const entry of measure.entries) {
273
+ if (entry.type === "note") {
274
+ staves.add(entry.staff ?? 1);
275
+ }
276
+ }
277
+ return Array.from(staves).sort((a, b) => a - b);
278
+ }
279
+ function hasNotes(measure) {
280
+ return measure.entries.some((entry) => entry.type === "note");
281
+ }
282
+ function isRestMeasure(measure) {
283
+ const notes = measure.entries.filter((entry) => entry.type === "note");
284
+ return notes.length === 0 || notes.every((note) => !note.pitch);
285
+ }
286
+ function getNormalizedPosition(note, measure, options) {
287
+ const absolutePosition = getAbsolutePosition(note, measure);
288
+ const currentDivisions = options.currentDivisions ?? measure.attributes?.divisions ?? 1;
289
+ return absolutePosition * options.baseDivisions / currentDivisions;
290
+ }
291
+ function getNormalizedDuration(note, options) {
292
+ const currentDivisions = options.currentDivisions ?? 1;
293
+ return note.duration * options.baseDivisions / currentDivisions;
294
+ }
295
+ function getEntriesForStaff(measure, staff) {
296
+ return measure.entries.filter((entry) => {
297
+ if (entry.type === "note") {
298
+ return (entry.staff ?? 1) === staff;
299
+ }
300
+ if (entry.type === "forward") {
301
+ return (entry.staff ?? 1) === staff;
302
+ }
303
+ if (entry.type === "direction") {
304
+ return (entry.staff ?? 1) === staff;
305
+ }
306
+ if (entry.type === "backup") {
307
+ return false;
308
+ }
309
+ return false;
310
+ });
311
+ }
312
+ function buildVoiceToStaffMap(measure) {
313
+ const map = /* @__PURE__ */ new Map();
314
+ for (const entry of measure.entries) {
315
+ if (entry.type === "note" && entry.staff !== void 0) {
316
+ const voice = entry.voice;
317
+ const staff = entry.staff;
318
+ if (!map.has(voice)) {
319
+ map.set(voice, staff);
320
+ }
321
+ }
322
+ }
323
+ return {
324
+ get: (voice) => map.get(voice),
325
+ has: (voice) => map.has(voice),
326
+ entries: () => map.entries(),
327
+ size: map.size
328
+ };
329
+ }
330
+ function buildVoiceToStaffMapForPart(part) {
331
+ const map = /* @__PURE__ */ new Map();
332
+ for (const measure of part.measures) {
333
+ for (const entry of measure.entries) {
334
+ if (entry.type === "note" && entry.staff !== void 0) {
335
+ const voice = entry.voice;
336
+ const staff = entry.staff;
337
+ if (!map.has(voice)) {
338
+ map.set(voice, staff);
339
+ }
340
+ }
341
+ }
342
+ }
343
+ return {
344
+ get: (voice) => map.get(voice),
345
+ has: (voice) => map.has(voice),
346
+ entries: () => map.entries(),
347
+ size: map.size
348
+ };
349
+ }
350
+ function inferStaff(entry, voiceToStaffMap) {
351
+ if (entry.staff !== void 0) {
352
+ return entry.staff;
353
+ }
354
+ const inferredStaff = voiceToStaffMap.get(entry.voice);
355
+ if (inferredStaff !== void 0) {
356
+ return inferredStaff;
357
+ }
358
+ return 1;
359
+ }
360
+ function getEffectiveStaff(entry, measure) {
361
+ if (entry.staff !== void 0) {
362
+ return entry.staff;
363
+ }
364
+ const map = buildVoiceToStaffMap(measure);
365
+ return inferStaff(entry, map);
366
+ }
367
+ function getClefForStaff(score, options) {
368
+ const part = score.parts[options.partIndex];
369
+ if (!part) return void 0;
370
+ for (let i = options.measureIndex; i >= 0; i--) {
371
+ const measure = part.measures[i];
372
+ for (const entry of measure.entries) {
373
+ if (entry.type === "attributes" && entry.attributes.clef) {
374
+ for (const clef of entry.attributes.clef) {
375
+ if ((clef.staff ?? 1) === options.staff) {
376
+ return clef;
377
+ }
378
+ }
379
+ }
380
+ }
381
+ if (measure.attributes?.clef) {
382
+ for (const clef of measure.attributes.clef) {
383
+ if ((clef.staff ?? 1) === options.staff) {
384
+ return clef;
385
+ }
386
+ }
387
+ }
388
+ }
389
+ return void 0;
390
+ }
391
+ function getVoicesForStaff(measure, staff) {
392
+ const voices = /* @__PURE__ */ new Set();
393
+ for (const entry of measure.entries) {
394
+ if (entry.type === "note") {
395
+ const entryStaff = entry.staff ?? 1;
396
+ if (entryStaff === staff) {
397
+ voices.add(entry.voice);
398
+ }
399
+ }
400
+ }
401
+ return Array.from(voices).sort((a, b) => a - b);
402
+ }
403
+ function getStaffRange(score, partIndex) {
404
+ const part = score.parts[partIndex];
405
+ if (!part) return { min: 1, max: 1 };
406
+ let min = 1;
407
+ let max = 1;
408
+ for (const measure of part.measures) {
409
+ if (measure.attributes?.staves !== void 0) {
410
+ max = Math.max(max, measure.attributes.staves);
411
+ }
412
+ for (const entry of measure.entries) {
413
+ if (entry.type === "note" && entry.staff !== void 0) {
414
+ max = Math.max(max, entry.staff);
415
+ }
416
+ }
417
+ }
418
+ return { min, max };
419
+ }
420
+ function getEntriesAtPosition(measure, position, options) {
421
+ const result = [];
422
+ const state = createPositionState();
423
+ for (const entry of measure.entries) {
424
+ const currentPosition = entry.type === "note" && entry.chord ? state.lastNonChordPosition : state.position;
425
+ if (currentPosition === position) {
426
+ if (entry.type === "note") {
427
+ if (options?.staff !== void 0 && (entry.staff ?? 1) !== options.staff) {
428
+ updatePositionForEntry(state, entry);
429
+ continue;
430
+ }
431
+ if (options?.voice !== void 0 && entry.voice !== options.voice) {
432
+ updatePositionForEntry(state, entry);
433
+ continue;
434
+ }
435
+ if (options?.includeChordNotes === false && entry.chord) {
436
+ updatePositionForEntry(state, entry);
437
+ continue;
438
+ }
439
+ }
440
+ result.push(entry);
441
+ }
442
+ updatePositionForEntry(state, entry);
443
+ }
444
+ return result;
445
+ }
446
+ function getNotesAtPosition(measure, position, options) {
447
+ return getEntriesAtPosition(measure, position, options).filter(
448
+ (entry) => entry.type === "note"
449
+ );
450
+ }
451
+ function getEntriesInRange(measure, range, options) {
452
+ const result = [];
453
+ const state = createPositionState();
454
+ for (const entry of measure.entries) {
455
+ const currentPosition = entry.type === "note" && entry.chord ? state.lastNonChordPosition : state.position;
456
+ if (currentPosition >= range.start && currentPosition < range.end) {
457
+ if (entry.type === "note") {
458
+ if (options?.staff !== void 0 && (entry.staff ?? 1) !== options.staff) {
459
+ updatePositionForEntry(state, entry);
460
+ continue;
461
+ }
462
+ if (options?.voice !== void 0 && entry.voice !== options.voice) {
463
+ updatePositionForEntry(state, entry);
464
+ continue;
465
+ }
466
+ if (options?.includeChordNotes === false && entry.chord) {
467
+ updatePositionForEntry(state, entry);
468
+ continue;
469
+ }
470
+ }
471
+ result.push(entry);
472
+ }
473
+ updatePositionForEntry(state, entry);
474
+ }
475
+ return result;
476
+ }
477
+ function getNotesInRange(measure, range, options) {
478
+ return getEntriesInRange(measure, range, options).filter(
479
+ (entry) => entry.type === "note"
480
+ );
481
+ }
482
+ function getVerticalSlice(score, options) {
483
+ const parts = /* @__PURE__ */ new Map();
484
+ for (let partIndex = 0; partIndex < score.parts.length; partIndex++) {
485
+ const part = score.parts[partIndex];
486
+ const measure = part.measures[options.measureIndex];
487
+ if (!measure) continue;
488
+ const notes = getNotesAtPosition(measure, options.position);
489
+ if (notes.length > 0) {
490
+ parts.set(partIndex, notes);
491
+ }
492
+ }
493
+ return {
494
+ measureIndex: options.measureIndex,
495
+ position: options.position,
496
+ parts
497
+ };
498
+ }
499
+ function getVoiceLine(score, options) {
500
+ const part = score.parts[options.partIndex];
501
+ if (!part) {
502
+ return { partIndex: options.partIndex, voice: options.voice, staff: options.staff, notes: [] };
503
+ }
504
+ const notes = [];
505
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
506
+ const measure = part.measures[measureIndex];
507
+ const state = createPositionState();
508
+ for (const entry of measure.entries) {
509
+ if (entry.type === "note") {
510
+ const entryStaff = entry.staff ?? 1;
511
+ const matchesVoice = entry.voice === options.voice;
512
+ const matchesStaff = options.staff === void 0 || entryStaff === options.staff;
513
+ if (matchesVoice && matchesStaff) {
514
+ const position = entry.chord ? state.lastNonChordPosition : state.position;
515
+ notes.push({
516
+ note: entry,
517
+ part,
518
+ partIndex: options.partIndex,
519
+ measure,
520
+ measureIndex,
521
+ position
522
+ });
523
+ }
524
+ }
525
+ updatePositionForEntry(state, entry);
526
+ }
527
+ }
528
+ return {
529
+ partIndex: options.partIndex,
530
+ voice: options.voice,
531
+ staff: options.staff,
532
+ notes
533
+ };
534
+ }
535
+ function getVoiceLineInRange(score, options) {
536
+ const part = score.parts[options.partIndex];
537
+ if (!part) {
538
+ return { partIndex: options.partIndex, voice: options.voice, staff: options.staff, notes: [] };
539
+ }
540
+ const notes = [];
541
+ for (let measureIndex = options.startMeasure; measureIndex <= options.endMeasure && measureIndex < part.measures.length; measureIndex++) {
542
+ const measure = part.measures[measureIndex];
543
+ const state = createPositionState();
544
+ for (const entry of measure.entries) {
545
+ if (entry.type === "note") {
546
+ const entryStaff = entry.staff ?? 1;
547
+ const matchesVoice = entry.voice === options.voice;
548
+ const matchesStaff = options.staff === void 0 || entryStaff === options.staff;
549
+ if (matchesVoice && matchesStaff) {
550
+ const position = entry.chord ? state.lastNonChordPosition : state.position;
551
+ notes.push({
552
+ note: entry,
553
+ part,
554
+ partIndex: options.partIndex,
555
+ measure,
556
+ measureIndex,
557
+ position
558
+ });
559
+ }
560
+ }
561
+ updatePositionForEntry(state, entry);
562
+ }
563
+ }
564
+ return {
565
+ partIndex: options.partIndex,
566
+ voice: options.voice,
567
+ staff: options.staff,
568
+ notes
569
+ };
570
+ }
571
+ function* iterateEntries(score) {
572
+ for (let partIndex = 0; partIndex < score.parts.length; partIndex++) {
573
+ const part = score.parts[partIndex];
574
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
575
+ const measure = part.measures[measureIndex];
576
+ const state = createPositionState();
577
+ for (const entry of measure.entries) {
578
+ const position = entry.type === "note" && entry.chord ? state.lastNonChordPosition : state.position;
579
+ yield {
580
+ entry,
581
+ part,
582
+ partIndex,
583
+ measure,
584
+ measureIndex,
585
+ position
586
+ };
587
+ updatePositionForEntry(state, entry);
588
+ }
589
+ }
590
+ }
591
+ }
592
+ function getNextNote(score, context) {
593
+ const part = score.parts[context.partIndex];
594
+ if (!part) return null;
595
+ let foundCurrent = false;
596
+ for (let measureIndex = context.measureIndex; measureIndex < part.measures.length; measureIndex++) {
597
+ const measure = part.measures[measureIndex];
598
+ const state = createPositionState();
599
+ for (const entry of measure.entries) {
600
+ if (entry.type === "note") {
601
+ const entryPosition = entry.chord ? state.lastNonChordPosition : state.position;
602
+ if (measureIndex === context.measureIndex && entry === context.note) {
603
+ foundCurrent = true;
604
+ updatePositionForEntry(state, entry);
605
+ continue;
606
+ }
607
+ if (foundCurrent && entry.voice === context.note.voice && !entry.chord) {
608
+ if (context.note.staff !== void 0) {
609
+ if ((entry.staff ?? 1) !== context.note.staff) {
610
+ updatePositionForEntry(state, entry);
611
+ continue;
612
+ }
613
+ }
614
+ return {
615
+ note: entry,
616
+ part,
617
+ partIndex: context.partIndex,
618
+ measure,
619
+ measureIndex,
620
+ position: entryPosition
621
+ };
622
+ }
623
+ }
624
+ updatePositionForEntry(state, entry);
625
+ }
626
+ }
627
+ return null;
628
+ }
629
+ function getPrevNote(score, context) {
630
+ const part = score.parts[context.partIndex];
631
+ if (!part) return null;
632
+ let lastCandidate = null;
633
+ for (let measureIndex = 0; measureIndex <= context.measureIndex; measureIndex++) {
634
+ const measure = part.measures[measureIndex];
635
+ const state = createPositionState();
636
+ for (const entry of measure.entries) {
637
+ if (entry.type === "note") {
638
+ const entryPosition = entry.chord ? state.lastNonChordPosition : state.position;
639
+ if (measureIndex === context.measureIndex && entry === context.note) {
640
+ return lastCandidate;
641
+ }
642
+ if (entry.voice === context.note.voice && !entry.chord) {
643
+ if (context.note.staff !== void 0) {
644
+ if ((entry.staff ?? 1) !== context.note.staff) {
645
+ updatePositionForEntry(state, entry);
646
+ continue;
647
+ }
648
+ }
649
+ lastCandidate = {
650
+ note: entry,
651
+ part,
652
+ partIndex: context.partIndex,
653
+ measure,
654
+ measureIndex,
655
+ position: entryPosition
656
+ };
657
+ }
658
+ }
659
+ updatePositionForEntry(state, entry);
660
+ }
661
+ }
662
+ return null;
663
+ }
664
+ function getAdjacentNotes(score, context) {
665
+ return {
666
+ prev: getPrevNote(score, context),
667
+ next: getNextNote(score, context)
668
+ };
669
+ }
670
+ function getDirections(score, options) {
671
+ const results = [];
672
+ const startPart = options?.partIndex ?? 0;
673
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
674
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
675
+ const part = score.parts[partIndex];
676
+ if (!part) continue;
677
+ const startMeasure = options?.measureIndex ?? 0;
678
+ const endMeasure = options?.measureIndex !== void 0 ? options.measureIndex + 1 : part.measures.length;
679
+ for (let measureIndex = startMeasure; measureIndex < endMeasure; measureIndex++) {
680
+ const measure = part.measures[measureIndex];
681
+ if (!measure) continue;
682
+ const state = createPositionState();
683
+ for (const entry of measure.entries) {
684
+ if (entry.type === "direction") {
685
+ results.push({
686
+ direction: entry,
687
+ part,
688
+ partIndex,
689
+ measure,
690
+ measureIndex,
691
+ position: state.position
692
+ });
693
+ }
694
+ updatePositionForEntry(state, entry);
695
+ }
696
+ }
697
+ }
698
+ return results;
699
+ }
700
+ function getDirectionsAtPosition(measure, position) {
701
+ const results = [];
702
+ const state = createPositionState();
703
+ for (const entry of measure.entries) {
704
+ if (entry.type === "direction" && state.position === position) {
705
+ results.push(entry);
706
+ }
707
+ updatePositionForEntry(state, entry);
708
+ }
709
+ return results;
710
+ }
711
+ function findDirectionsByType(score, kind) {
712
+ const allDirections = getDirections(score);
713
+ return allDirections.filter(
714
+ (d) => d.direction.directionTypes.some((dt) => dt.kind === kind)
715
+ );
716
+ }
717
+ function getDynamics(score, options) {
718
+ const results = [];
719
+ const startPart = options?.partIndex ?? 0;
720
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
721
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
722
+ const part = score.parts[partIndex];
723
+ if (!part) continue;
724
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
725
+ const measure = part.measures[measureIndex];
726
+ const state = createPositionState();
727
+ for (const entry of measure.entries) {
728
+ if (entry.type === "direction") {
729
+ for (const dirType of entry.directionTypes) {
730
+ if (dirType.kind === "dynamics") {
731
+ results.push({
732
+ dynamic: dirType.value,
733
+ direction: entry,
734
+ part,
735
+ partIndex,
736
+ measure,
737
+ measureIndex,
738
+ position: state.position
739
+ });
740
+ }
741
+ }
742
+ }
743
+ updatePositionForEntry(state, entry);
744
+ }
745
+ }
746
+ }
747
+ return results;
748
+ }
749
+ function getTempoMarkings(score) {
750
+ const results = [];
751
+ for (let partIndex = 0; partIndex < score.parts.length; partIndex++) {
752
+ const part = score.parts[partIndex];
753
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
754
+ const measure = part.measures[measureIndex];
755
+ const state = createPositionState();
756
+ for (const entry of measure.entries) {
757
+ if (entry.type === "direction") {
758
+ for (const dirType of entry.directionTypes) {
759
+ if (dirType.kind === "metronome") {
760
+ results.push({
761
+ beatUnit: dirType.beatUnit,
762
+ perMinute: dirType.perMinute,
763
+ beatUnitDot: dirType.beatUnitDot,
764
+ direction: entry,
765
+ partIndex,
766
+ measureIndex,
767
+ position: state.position
768
+ });
769
+ }
770
+ }
771
+ }
772
+ updatePositionForEntry(state, entry);
773
+ }
774
+ }
775
+ }
776
+ return results;
777
+ }
778
+ function getPedalMarkings(score, options) {
779
+ const results = [];
780
+ const startPart = options?.partIndex ?? 0;
781
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
782
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
783
+ const part = score.parts[partIndex];
784
+ if (!part) continue;
785
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
786
+ const measure = part.measures[measureIndex];
787
+ const state = createPositionState();
788
+ for (const entry of measure.entries) {
789
+ if (entry.type === "direction") {
790
+ for (const dirType of entry.directionTypes) {
791
+ if (dirType.kind === "pedal") {
792
+ results.push({
793
+ pedalType: dirType.type,
794
+ direction: entry,
795
+ partIndex,
796
+ measureIndex,
797
+ position: state.position
798
+ });
799
+ }
800
+ }
801
+ }
802
+ updatePositionForEntry(state, entry);
803
+ }
804
+ }
805
+ }
806
+ return results;
807
+ }
808
+ function getWedges(score, options) {
809
+ const results = [];
810
+ const startPart = options?.partIndex ?? 0;
811
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
812
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
813
+ const part = score.parts[partIndex];
814
+ if (!part) continue;
815
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
816
+ const measure = part.measures[measureIndex];
817
+ const state = createPositionState();
818
+ for (const entry of measure.entries) {
819
+ if (entry.type === "direction") {
820
+ for (const dirType of entry.directionTypes) {
821
+ if (dirType.kind === "wedge") {
822
+ results.push({
823
+ wedgeType: dirType.type,
824
+ direction: entry,
825
+ partIndex,
826
+ measureIndex,
827
+ position: state.position
828
+ });
829
+ }
830
+ }
831
+ }
832
+ updatePositionForEntry(state, entry);
833
+ }
834
+ }
835
+ }
836
+ return results;
837
+ }
838
+ function getOctaveShifts(score, options) {
839
+ const results = [];
840
+ const startPart = options?.partIndex ?? 0;
841
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
842
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
843
+ const part = score.parts[partIndex];
844
+ if (!part) continue;
845
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
846
+ const measure = part.measures[measureIndex];
847
+ const state = createPositionState();
848
+ for (const entry of measure.entries) {
849
+ if (entry.type === "direction") {
850
+ for (const dirType of entry.directionTypes) {
851
+ if (dirType.kind === "octave-shift") {
852
+ results.push({
853
+ shiftType: dirType.type,
854
+ size: dirType.size,
855
+ direction: entry,
856
+ partIndex,
857
+ measureIndex,
858
+ position: state.position
859
+ });
860
+ }
861
+ }
862
+ }
863
+ updatePositionForEntry(state, entry);
864
+ }
865
+ }
866
+ }
867
+ return results;
868
+ }
869
+ function getTiedNoteGroups(score, options) {
870
+ const results = [];
871
+ const startPart = options?.partIndex ?? 0;
872
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
873
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
874
+ const part = score.parts[partIndex];
875
+ if (!part) continue;
876
+ const pendingTies = /* @__PURE__ */ new Map();
877
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
878
+ const measure = part.measures[measureIndex];
879
+ const state = createPositionState();
880
+ for (const entry of measure.entries) {
881
+ if (entry.type === "note" && entry.pitch) {
882
+ const position = entry.chord ? state.lastNonChordPosition : state.position;
883
+ const pitchKey = `${entry.pitch.step}${entry.pitch.octave}-${entry.voice}`;
884
+ const context = {
885
+ note: entry,
886
+ part,
887
+ partIndex,
888
+ measure,
889
+ measureIndex,
890
+ position
891
+ };
892
+ const hasTieStart = entry.tie?.type === "start" || entry.ties?.some((t) => t.type === "start") || entry.notations?.some((n) => n.type === "tied" && n.tiedType === "start");
893
+ const hasTieStop = entry.tie?.type === "stop" || entry.ties?.some((t) => t.type === "stop") || entry.notations?.some((n) => n.type === "tied" && n.tiedType === "stop");
894
+ if (hasTieStop && pendingTies.has(pitchKey)) {
895
+ const group = pendingTies.get(pitchKey);
896
+ group.push(context);
897
+ if (!hasTieStart) {
898
+ const totalDuration = group.reduce((sum, nc) => sum + nc.note.duration, 0);
899
+ results.push({ notes: group, totalDuration });
900
+ pendingTies.delete(pitchKey);
901
+ }
902
+ } else if (hasTieStart) {
903
+ pendingTies.set(pitchKey, [context]);
904
+ }
905
+ }
906
+ updatePositionForEntry(state, entry);
907
+ }
908
+ }
909
+ }
910
+ return results;
911
+ }
912
+ function getSlurSpans(score, options) {
913
+ const results = [];
914
+ const startPart = options?.partIndex ?? 0;
915
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
916
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
917
+ const part = score.parts[partIndex];
918
+ if (!part) continue;
919
+ const pendingSlurs = /* @__PURE__ */ new Map();
920
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
921
+ const measure = part.measures[measureIndex];
922
+ const state = createPositionState();
923
+ for (const entry of measure.entries) {
924
+ if (entry.type === "note") {
925
+ const position = entry.chord ? state.lastNonChordPosition : state.position;
926
+ const context = {
927
+ note: entry,
928
+ part,
929
+ partIndex,
930
+ measure,
931
+ measureIndex,
932
+ position
933
+ };
934
+ if (entry.notations) {
935
+ for (const notation of entry.notations) {
936
+ if (notation.type === "slur") {
937
+ const slurNumber = notation.number ?? 1;
938
+ if (notation.slurType === "start") {
939
+ pendingSlurs.set(slurNumber, { startNote: context, notes: [context] });
940
+ } else if (notation.slurType === "stop" && pendingSlurs.has(slurNumber)) {
941
+ const pending = pendingSlurs.get(slurNumber);
942
+ pending.notes.push(context);
943
+ results.push({
944
+ number: slurNumber,
945
+ startNote: pending.startNote,
946
+ endNote: context,
947
+ notes: pending.notes
948
+ });
949
+ pendingSlurs.delete(slurNumber);
950
+ } else if (notation.slurType === "continue" && pendingSlurs.has(slurNumber)) {
951
+ pendingSlurs.get(slurNumber).notes.push(context);
952
+ }
953
+ }
954
+ }
955
+ }
956
+ for (const [, pending] of pendingSlurs) {
957
+ const lastNote = pending.notes[pending.notes.length - 1];
958
+ if (lastNote !== context) {
959
+ pending.notes.push(context);
960
+ }
961
+ }
962
+ }
963
+ updatePositionForEntry(state, entry);
964
+ }
965
+ }
966
+ }
967
+ return results;
968
+ }
969
+ function getTupletGroups(score, options) {
970
+ const results = [];
971
+ const startPart = options?.partIndex ?? 0;
972
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
973
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
974
+ const part = score.parts[partIndex];
975
+ if (!part) continue;
976
+ const pendingTuplets = /* @__PURE__ */ new Map();
977
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
978
+ const measure = part.measures[measureIndex];
979
+ const state = createPositionState();
980
+ for (const entry of measure.entries) {
981
+ if (entry.type === "note") {
982
+ const position = entry.chord ? state.lastNonChordPosition : state.position;
983
+ const context = {
984
+ note: entry,
985
+ part,
986
+ partIndex,
987
+ measure,
988
+ measureIndex,
989
+ position
990
+ };
991
+ if (entry.notations) {
992
+ for (const notation of entry.notations) {
993
+ if (notation.type === "tuplet") {
994
+ const tupletNumber = notation.number ?? 1;
995
+ if (notation.tupletType === "start") {
996
+ const actualNotes = entry.timeModification?.actualNotes ?? 3;
997
+ const normalNotes = entry.timeModification?.normalNotes ?? 2;
998
+ pendingTuplets.set(tupletNumber, {
999
+ notes: [context],
1000
+ actualNotes,
1001
+ normalNotes
1002
+ });
1003
+ } else if (notation.tupletType === "stop" && pendingTuplets.has(tupletNumber)) {
1004
+ const pending = pendingTuplets.get(tupletNumber);
1005
+ pending.notes.push(context);
1006
+ results.push({
1007
+ number: tupletNumber,
1008
+ notes: pending.notes,
1009
+ actualNotes: pending.actualNotes,
1010
+ normalNotes: pending.normalNotes
1011
+ });
1012
+ pendingTuplets.delete(tupletNumber);
1013
+ }
1014
+ }
1015
+ }
1016
+ }
1017
+ if (entry.timeModification && !entry.notations?.some((n) => n.type === "tuplet")) {
1018
+ for (const [, pending] of pendingTuplets) {
1019
+ if (entry.timeModification.actualNotes === pending.actualNotes && entry.timeModification.normalNotes === pending.normalNotes) {
1020
+ pending.notes.push(context);
1021
+ }
1022
+ }
1023
+ }
1024
+ }
1025
+ updatePositionForEntry(state, entry);
1026
+ }
1027
+ }
1028
+ }
1029
+ return results;
1030
+ }
1031
+ function getBeamGroups(measure) {
1032
+ const results = [];
1033
+ const state = createPositionState();
1034
+ const pendingBeams = /* @__PURE__ */ new Map();
1035
+ for (const entry of measure.entries) {
1036
+ if (entry.type === "note" && entry.beam) {
1037
+ const position = entry.chord ? state.lastNonChordPosition : state.position;
1038
+ const context = {
1039
+ note: entry,
1040
+ part: {},
1041
+ // Will be set by caller if needed
1042
+ partIndex: 0,
1043
+ measure,
1044
+ measureIndex: 0,
1045
+ position
1046
+ };
1047
+ for (const beam of entry.beam) {
1048
+ const beamNumber = beam.number;
1049
+ if (beam.type === "begin") {
1050
+ pendingBeams.set(beamNumber, [context]);
1051
+ } else if (beam.type === "continue" && pendingBeams.has(beamNumber)) {
1052
+ pendingBeams.get(beamNumber).push(context);
1053
+ } else if (beam.type === "end" && pendingBeams.has(beamNumber)) {
1054
+ const group = pendingBeams.get(beamNumber);
1055
+ group.push(context);
1056
+ results.push({
1057
+ notes: group,
1058
+ beamLevel: beamNumber
1059
+ });
1060
+ pendingBeams.delete(beamNumber);
1061
+ }
1062
+ }
1063
+ }
1064
+ updatePositionForEntry(state, entry);
1065
+ }
1066
+ return results;
1067
+ }
1068
+ function findNotesWithNotation(score, notationType, options) {
1069
+ const results = [];
1070
+ const startPart = options?.partIndex ?? 0;
1071
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1072
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1073
+ const part = score.parts[partIndex];
1074
+ if (!part) continue;
1075
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1076
+ const measure = part.measures[measureIndex];
1077
+ const state = createPositionState();
1078
+ for (const entry of measure.entries) {
1079
+ if (entry.type === "note") {
1080
+ const position = entry.chord ? state.lastNonChordPosition : state.position;
1081
+ if (entry.notations?.some((n) => n.type === notationType)) {
1082
+ results.push({
1083
+ note: entry,
1084
+ part,
1085
+ partIndex,
1086
+ measure,
1087
+ measureIndex,
1088
+ position
1089
+ });
1090
+ }
1091
+ }
1092
+ updatePositionForEntry(state, entry);
1093
+ }
1094
+ }
1095
+ }
1096
+ return results;
1097
+ }
1098
+ function getHarmonies(score, options) {
1099
+ const results = [];
1100
+ const startPart = options?.partIndex ?? 0;
1101
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1102
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1103
+ const part = score.parts[partIndex];
1104
+ if (!part) continue;
1105
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1106
+ const measure = part.measures[measureIndex];
1107
+ const state = createPositionState();
1108
+ for (const entry of measure.entries) {
1109
+ if (entry.type === "harmony") {
1110
+ results.push({
1111
+ harmony: entry,
1112
+ part,
1113
+ partIndex,
1114
+ measure,
1115
+ measureIndex,
1116
+ position: state.position
1117
+ });
1118
+ }
1119
+ updatePositionForEntry(state, entry);
1120
+ }
1121
+ }
1122
+ }
1123
+ return results;
1124
+ }
1125
+ function getHarmonyAtPosition(measure, position) {
1126
+ const state = createPositionState();
1127
+ let lastHarmony;
1128
+ for (const entry of measure.entries) {
1129
+ if (entry.type === "harmony") {
1130
+ if (state.position <= position) {
1131
+ lastHarmony = entry;
1132
+ }
1133
+ }
1134
+ updatePositionForEntry(state, entry);
1135
+ if (state.position > position && lastHarmony) {
1136
+ break;
1137
+ }
1138
+ }
1139
+ return lastHarmony;
1140
+ }
1141
+ function getChordProgression(score, options) {
1142
+ const harmonies = getHarmonies(score, options);
1143
+ return harmonies.map((h) => {
1144
+ const rootAlter = h.harmony.root.rootAlter ?? 0;
1145
+ const rootAccidental = rootAlter > 0 ? "#".repeat(rootAlter) : "b".repeat(-rootAlter);
1146
+ const root = h.harmony.root.rootStep + rootAccidental;
1147
+ let bass;
1148
+ if (h.harmony.bass) {
1149
+ const bassAlter = h.harmony.bass.bassAlter ?? 0;
1150
+ const bassAccidental = bassAlter > 0 ? "#".repeat(bassAlter) : "b".repeat(-bassAlter);
1151
+ bass = h.harmony.bass.bassStep + bassAccidental;
1152
+ }
1153
+ return {
1154
+ root,
1155
+ kind: h.harmony.kind,
1156
+ bass,
1157
+ measureIndex: h.measureIndex,
1158
+ position: h.position
1159
+ };
1160
+ });
1161
+ }
1162
+ function getLyrics(score, options) {
1163
+ const results = [];
1164
+ const startPart = options?.partIndex ?? 0;
1165
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1166
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1167
+ const part = score.parts[partIndex];
1168
+ if (!part) continue;
1169
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1170
+ const measure = part.measures[measureIndex];
1171
+ const state = createPositionState();
1172
+ for (const entry of measure.entries) {
1173
+ if (entry.type === "note" && entry.lyrics) {
1174
+ const position = entry.chord ? state.lastNonChordPosition : state.position;
1175
+ for (const lyric of entry.lyrics) {
1176
+ const verse = lyric.number ?? 1;
1177
+ if (options?.verse !== void 0 && verse !== options.verse) {
1178
+ continue;
1179
+ }
1180
+ results.push({
1181
+ lyric,
1182
+ note: entry,
1183
+ part,
1184
+ partIndex,
1185
+ measure,
1186
+ measureIndex,
1187
+ position,
1188
+ verse
1189
+ });
1190
+ }
1191
+ }
1192
+ updatePositionForEntry(state, entry);
1193
+ }
1194
+ }
1195
+ }
1196
+ return results;
1197
+ }
1198
+ function getLyricText(score, options) {
1199
+ const lyrics = getLyrics(score, options);
1200
+ const verseMap = /* @__PURE__ */ new Map();
1201
+ for (const lyric of lyrics) {
1202
+ if (!verseMap.has(lyric.verse)) {
1203
+ verseMap.set(lyric.verse, []);
1204
+ }
1205
+ verseMap.get(lyric.verse).push(lyric);
1206
+ }
1207
+ const results = [];
1208
+ for (const [verse, verseLyrics] of verseMap) {
1209
+ const syllables = [];
1210
+ const textParts = [];
1211
+ for (const lyric of verseLyrics) {
1212
+ const text = lyric.lyric.text;
1213
+ syllables.push({
1214
+ text,
1215
+ position: lyric.position,
1216
+ measureIndex: lyric.measureIndex
1217
+ });
1218
+ const syllabic = lyric.lyric.syllabic;
1219
+ if (syllabic === "begin" || syllabic === "middle") {
1220
+ textParts.push(text + "-");
1221
+ } else if (syllabic === "end") {
1222
+ textParts.push(text + " ");
1223
+ } else {
1224
+ textParts.push(text + " ");
1225
+ }
1226
+ }
1227
+ results.push({
1228
+ verse,
1229
+ text: textParts.join("").trim(),
1230
+ syllables
1231
+ });
1232
+ }
1233
+ return results.sort((a, b) => a.verse - b.verse);
1234
+ }
1235
+ function getVerseCount(score, options) {
1236
+ const verses = /* @__PURE__ */ new Set();
1237
+ const startPart = options?.partIndex ?? 0;
1238
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1239
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1240
+ const part = score.parts[partIndex];
1241
+ if (!part) continue;
1242
+ for (const measure of part.measures) {
1243
+ for (const entry of measure.entries) {
1244
+ if (entry.type === "note" && entry.lyrics) {
1245
+ for (const lyric of entry.lyrics) {
1246
+ verses.add(lyric.number ?? 1);
1247
+ }
1248
+ }
1249
+ }
1250
+ }
1251
+ }
1252
+ return verses.size;
1253
+ }
1254
+ function getRepeatStructure(score, options) {
1255
+ const results = [];
1256
+ const partIndex = options?.partIndex ?? 0;
1257
+ const part = score.parts[partIndex];
1258
+ if (!part) return results;
1259
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1260
+ const measure = part.measures[measureIndex];
1261
+ const measureNumber = measure.number ?? String(measureIndex + 1);
1262
+ if (measure.barlines) {
1263
+ for (const barline of measure.barlines) {
1264
+ if (barline.repeat) {
1265
+ results.push({
1266
+ type: barline.repeat.direction,
1267
+ times: barline.repeat.times,
1268
+ measureIndex,
1269
+ measureNumber
1270
+ });
1271
+ }
1272
+ }
1273
+ }
1274
+ }
1275
+ return results;
1276
+ }
1277
+ function findBarlines(score, options) {
1278
+ const results = [];
1279
+ const startPart = options?.partIndex ?? 0;
1280
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1281
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1282
+ const part = score.parts[partIndex];
1283
+ if (!part) continue;
1284
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1285
+ const measure = part.measures[measureIndex];
1286
+ const measureNumber = measure.number ?? String(measureIndex + 1);
1287
+ if (measure.barlines) {
1288
+ for (const barline of measure.barlines) {
1289
+ if (options?.style !== void 0 && barline.barStyle !== options.style) {
1290
+ continue;
1291
+ }
1292
+ if (options?.repeat !== void 0) {
1293
+ const hasRepeat = barline.repeat !== void 0;
1294
+ if (hasRepeat !== options.repeat) {
1295
+ continue;
1296
+ }
1297
+ }
1298
+ results.push({
1299
+ barline,
1300
+ partIndex,
1301
+ measureIndex,
1302
+ measureNumber
1303
+ });
1304
+ }
1305
+ }
1306
+ }
1307
+ }
1308
+ return results;
1309
+ }
1310
+ function getEndings(score, options) {
1311
+ const results = [];
1312
+ const startPart = options?.partIndex ?? 0;
1313
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1314
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1315
+ const part = score.parts[partIndex];
1316
+ if (!part) continue;
1317
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1318
+ const measure = part.measures[measureIndex];
1319
+ const measureNumber = measure.number ?? String(measureIndex + 1);
1320
+ if (measure.barlines) {
1321
+ for (const barline of measure.barlines) {
1322
+ if (barline.ending) {
1323
+ results.push({
1324
+ number: barline.ending.number,
1325
+ type: barline.ending.type,
1326
+ partIndex,
1327
+ measureIndex,
1328
+ measureNumber
1329
+ });
1330
+ }
1331
+ }
1332
+ }
1333
+ }
1334
+ }
1335
+ return results;
1336
+ }
1337
+ function getKeyChanges(score, options) {
1338
+ const results = [];
1339
+ const startPart = options?.partIndex ?? 0;
1340
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1341
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1342
+ const part = score.parts[partIndex];
1343
+ if (!part) continue;
1344
+ let lastKey;
1345
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1346
+ const measure = part.measures[measureIndex];
1347
+ const measureNumber = measure.number ?? String(measureIndex + 1);
1348
+ const state = createPositionState();
1349
+ if (measure.attributes?.key) {
1350
+ const key = measure.attributes.key;
1351
+ if (!lastKey || lastKey.fifths !== key.fifths || lastKey.mode !== key.mode) {
1352
+ results.push({
1353
+ key,
1354
+ partIndex,
1355
+ measureIndex,
1356
+ measureNumber,
1357
+ position: 0
1358
+ });
1359
+ lastKey = key;
1360
+ }
1361
+ }
1362
+ for (const entry of measure.entries) {
1363
+ if (entry.type === "attributes" && entry.attributes.key) {
1364
+ const key = entry.attributes.key;
1365
+ if (!lastKey || lastKey.fifths !== key.fifths || lastKey.mode !== key.mode) {
1366
+ results.push({
1367
+ key,
1368
+ partIndex,
1369
+ measureIndex,
1370
+ measureNumber,
1371
+ position: state.position
1372
+ });
1373
+ lastKey = key;
1374
+ }
1375
+ }
1376
+ updatePositionForEntry(state, entry);
1377
+ }
1378
+ }
1379
+ }
1380
+ return results;
1381
+ }
1382
+ function getTimeChanges(score, options) {
1383
+ const results = [];
1384
+ const startPart = options?.partIndex ?? 0;
1385
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1386
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1387
+ const part = score.parts[partIndex];
1388
+ if (!part) continue;
1389
+ let lastTime;
1390
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1391
+ const measure = part.measures[measureIndex];
1392
+ const measureNumber = measure.number ?? String(measureIndex + 1);
1393
+ if (measure.attributes?.time) {
1394
+ const time = measure.attributes.time;
1395
+ if (!lastTime || lastTime.beats !== time.beats || lastTime.beatType !== time.beatType) {
1396
+ results.push({
1397
+ time,
1398
+ partIndex,
1399
+ measureIndex,
1400
+ measureNumber
1401
+ });
1402
+ lastTime = time;
1403
+ }
1404
+ }
1405
+ for (const entry of measure.entries) {
1406
+ if (entry.type === "attributes" && entry.attributes.time) {
1407
+ const time = entry.attributes.time;
1408
+ if (!lastTime || lastTime.beats !== time.beats || lastTime.beatType !== time.beatType) {
1409
+ results.push({
1410
+ time,
1411
+ partIndex,
1412
+ measureIndex,
1413
+ measureNumber
1414
+ });
1415
+ lastTime = time;
1416
+ }
1417
+ }
1418
+ }
1419
+ }
1420
+ }
1421
+ return results;
1422
+ }
1423
+ function getClefChanges(score, options) {
1424
+ const results = [];
1425
+ const startPart = options?.partIndex ?? 0;
1426
+ const endPart = options?.partIndex !== void 0 ? options.partIndex + 1 : score.parts.length;
1427
+ for (let partIndex = startPart; partIndex < endPart; partIndex++) {
1428
+ const part = score.parts[partIndex];
1429
+ if (!part) continue;
1430
+ const lastClefs = /* @__PURE__ */ new Map();
1431
+ for (let measureIndex = 0; measureIndex < part.measures.length; measureIndex++) {
1432
+ const measure = part.measures[measureIndex];
1433
+ const measureNumber = measure.number ?? String(measureIndex + 1);
1434
+ const state = createPositionState();
1435
+ if (measure.attributes?.clef) {
1436
+ for (const clef of measure.attributes.clef) {
1437
+ const staff = clef.staff ?? 1;
1438
+ if (options?.staff !== void 0 && staff !== options.staff) {
1439
+ continue;
1440
+ }
1441
+ const lastClef = lastClefs.get(staff);
1442
+ if (!lastClef || lastClef.sign !== clef.sign || lastClef.line !== clef.line || lastClef.clefOctaveChange !== clef.clefOctaveChange) {
1443
+ results.push({
1444
+ clef,
1445
+ staff,
1446
+ partIndex,
1447
+ measureIndex,
1448
+ measureNumber,
1449
+ position: 0
1450
+ });
1451
+ lastClefs.set(staff, clef);
1452
+ }
1453
+ }
1454
+ }
1455
+ for (const entry of measure.entries) {
1456
+ if (entry.type === "attributes" && entry.attributes.clef) {
1457
+ for (const clef of entry.attributes.clef) {
1458
+ const staff = clef.staff ?? 1;
1459
+ if (options?.staff !== void 0 && staff !== options.staff) {
1460
+ continue;
1461
+ }
1462
+ const lastClef = lastClefs.get(staff);
1463
+ if (!lastClef || lastClef.sign !== clef.sign || lastClef.line !== clef.line || lastClef.clefOctaveChange !== clef.clefOctaveChange) {
1464
+ results.push({
1465
+ clef,
1466
+ staff,
1467
+ partIndex,
1468
+ measureIndex,
1469
+ measureNumber,
1470
+ position: state.position
1471
+ });
1472
+ lastClefs.set(staff, clef);
1473
+ }
1474
+ }
1475
+ }
1476
+ updatePositionForEntry(state, entry);
1477
+ }
1478
+ }
1479
+ }
1480
+ return results;
1481
+ }
1482
+ function getStructuralChanges(score, options) {
1483
+ return {
1484
+ keyChanges: getKeyChanges(score, options),
1485
+ timeChanges: getTimeChanges(score, options),
1486
+ clefChanges: getClefChanges(score, options)
1487
+ };
1488
+ }
1489
+ function getPartByIndex(score, index) {
1490
+ return score.parts[index];
1491
+ }
1492
+ function getPartCount(score) {
1493
+ return score.parts.length;
1494
+ }
1495
+ function getPartIds(score) {
1496
+ return score.parts.map((part) => part.id);
1497
+ }
55
1498
  function getMeasure(score, options) {
56
1499
  const part = score.parts[options.part];
57
1500
  if (!part) return void 0;
@@ -254,18 +1697,81 @@ function pitchesEqual(a, b) {
254
1697
  }
255
1698
  // Annotate the CommonJS export names for ESM import in node:
256
1699
  0 && (module.exports = {
1700
+ buildVoiceToStaffMap,
1701
+ buildVoiceToStaffMapForPart,
257
1702
  countNotes,
1703
+ findBarlines,
1704
+ findDirectionsByType,
258
1705
  findNotes,
1706
+ findNotesWithNotation,
1707
+ getAbsolutePosition,
1708
+ getAdjacentNotes,
1709
+ getAllNotes,
259
1710
  getAttributesAtMeasure,
1711
+ getBeamGroups,
1712
+ getChordProgression,
1713
+ getChords,
1714
+ getClefChanges,
1715
+ getClefForStaff,
1716
+ getDirections,
1717
+ getDirectionsAtPosition,
260
1718
  getDivisions,
261
1719
  getDuration,
1720
+ getDynamics,
1721
+ getEffectiveStaff,
1722
+ getEndings,
1723
+ getEntriesAtPosition,
1724
+ getEntriesForStaff,
1725
+ getEntriesInRange,
1726
+ getHarmonies,
1727
+ getHarmonyAtPosition,
1728
+ getKeyChanges,
1729
+ getLyricText,
1730
+ getLyrics,
262
1731
  getMeasure,
263
1732
  getMeasureByIndex,
264
1733
  getMeasureCount,
1734
+ getNextNote,
1735
+ getNormalizedDuration,
1736
+ getNormalizedPosition,
1737
+ getNotesAtPosition,
1738
+ getNotesForStaff,
1739
+ getNotesForVoice,
1740
+ getNotesInRange,
1741
+ getOctaveShifts,
265
1742
  getPartById,
1743
+ getPartByIndex,
1744
+ getPartCount,
1745
+ getPartIds,
266
1746
  getPartIndex,
1747
+ getPedalMarkings,
1748
+ getPrevNote,
1749
+ getRepeatStructure,
1750
+ getSlurSpans,
1751
+ getStaffRange,
267
1752
  getStaveCount,
1753
+ getStaves,
1754
+ getStructuralChanges,
1755
+ getTempoMarkings,
1756
+ getTiedNoteGroups,
1757
+ getTimeChanges,
1758
+ getTupletGroups,
1759
+ getVerseCount,
1760
+ getVerticalSlice,
1761
+ getVoiceLine,
1762
+ getVoiceLineInRange,
1763
+ getVoices,
1764
+ getVoicesForStaff,
1765
+ getWedges,
1766
+ groupByStaff,
1767
+ groupByVoice,
268
1768
  hasMultipleStaves,
1769
+ hasNotes,
1770
+ inferStaff,
1771
+ isRestMeasure,
1772
+ iterateEntries,
1773
+ iterateNotes,
269
1774
  measureRoundtrip,
270
- scoresEqual
1775
+ scoresEqual,
1776
+ withAbsolutePositions
271
1777
  });