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