musicxml-io 0.2.0 → 0.2.7

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.
@@ -1,4 +1,4 @@
1
- import { S as Score, M as Measure, f as MeasureAttributes, P as Pitch, N as NoteEntry, e as Part } from '../types-Dp9zcgIg.mjs';
1
+ import { S as Score, M as Measure, f as MeasureAttributes, P as Pitch, N as NoteEntry, e as Part } from '../types-CSI8kV28.mjs';
2
2
 
3
3
  /**
4
4
  * Get a specific measure from the score
@@ -1,4 +1,4 @@
1
- import { S as Score, M as Measure, f as MeasureAttributes, P as Pitch, N as NoteEntry, e as Part } from '../types-Dp9zcgIg.js';
1
+ import { S as Score, M as Measure, f as MeasureAttributes, P as Pitch, N as NoteEntry, e as Part } from '../types-CSI8kV28.js';
2
2
 
3
3
  /**
4
4
  * Get a specific measure from the score
@@ -1,4 +1,5 @@
1
1
  interface Score {
2
+ _id: string;
2
3
  metadata: ScoreMetadata;
3
4
  partList: PartListEntry[];
4
5
  parts: Part[];
@@ -90,6 +91,7 @@ interface FontInfo {
90
91
  fontWeight?: string;
91
92
  }
92
93
  interface Credit {
94
+ _id: string;
93
95
  page?: number;
94
96
  creditType?: string[];
95
97
  creditWords?: CreditWords[];
@@ -116,6 +118,7 @@ interface CreditWords {
116
118
  }
117
119
  type PartListEntry = PartInfo | PartGroup;
118
120
  interface PartInfo {
121
+ _id: string;
119
122
  type: 'score-part';
120
123
  id: string;
121
124
  name?: string;
@@ -161,6 +164,7 @@ interface MidiInstrument {
161
164
  elevation?: number;
162
165
  }
163
166
  interface PartGroup {
167
+ _id: string;
164
168
  type: 'part-group';
165
169
  groupType: 'start' | 'stop';
166
170
  number?: number;
@@ -173,10 +177,12 @@ interface PartGroup {
173
177
  groupBarline?: 'yes' | 'no' | 'Mensurstrich';
174
178
  }
175
179
  interface Part {
180
+ _id: string;
176
181
  id: string;
177
182
  measures: Measure[];
178
183
  }
179
184
  interface Measure {
185
+ _id: string;
180
186
  number: string;
181
187
  width?: number;
182
188
  implicit?: boolean;
@@ -294,6 +300,7 @@ interface Transpose {
294
300
  octaveChange?: number;
295
301
  }
296
302
  interface Barline {
303
+ _id: string;
297
304
  location: 'left' | 'right' | 'middle';
298
305
  barStyle?: 'regular' | 'dotted' | 'dashed' | 'heavy' | 'light-light' | 'light-heavy' | 'heavy-light' | 'heavy-heavy' | 'tick' | 'short' | 'none';
299
306
  repeat?: {
@@ -307,10 +314,12 @@ interface Barline {
307
314
  }
308
315
  type MeasureEntry = NoteEntry | BackupEntry | ForwardEntry | DirectionEntry | HarmonyEntry | FiguredBassEntry | SoundEntry | AttributesEntry;
309
316
  interface AttributesEntry {
317
+ _id: string;
310
318
  type: 'attributes';
311
319
  attributes: MeasureAttributes;
312
320
  }
313
321
  interface NoteEntry {
322
+ _id: string;
314
323
  type: 'note';
315
324
  pitch?: Pitch;
316
325
  rest?: RestInfo;
@@ -356,10 +365,12 @@ interface NoteEntry {
356
365
  };
357
366
  }
358
367
  interface BackupEntry {
368
+ _id: string;
359
369
  type: 'backup';
360
370
  duration: number;
361
371
  }
362
372
  interface ForwardEntry {
373
+ _id: string;
363
374
  type: 'forward';
364
375
  duration: number;
365
376
  voice?: number;
@@ -380,6 +391,7 @@ interface DirectionSound {
380
391
  sostenutoPedal?: 'yes' | 'no';
381
392
  }
382
393
  interface DirectionEntry {
394
+ _id: string;
383
395
  type: 'direction';
384
396
  directionTypes: DirectionType[];
385
397
  placement?: 'above' | 'below';
@@ -398,6 +410,7 @@ interface Swing {
398
410
  swingType?: string;
399
411
  }
400
412
  interface SoundEntry {
413
+ _id: string;
401
414
  type: 'sound';
402
415
  tempo?: number;
403
416
  dynamics?: number;
@@ -414,6 +427,7 @@ interface SoundEntry {
414
427
  sostenutoPedal?: boolean | 'yes' | 'no';
415
428
  }
416
429
  interface HarmonyEntry {
430
+ _id: string;
417
431
  type: 'harmony';
418
432
  root: {
419
433
  rootStep: string;
@@ -455,6 +469,7 @@ interface FrameNote {
455
469
  barre?: 'start' | 'stop';
456
470
  }
457
471
  interface FiguredBassEntry {
472
+ _id: string;
458
473
  type: 'figured-bass';
459
474
  figures: Figure[];
460
475
  duration?: number;
@@ -540,7 +555,7 @@ interface OrnamentNotation extends BaseNotation {
540
555
  defaultX?: number;
541
556
  defaultY?: number;
542
557
  }
543
- type OrnamentType = 'trill-mark' | 'mordent' | 'inverted-mordent' | 'turn' | 'inverted-turn' | 'delayed-turn' | 'delayed-inverted-turn' | 'vertical-turn' | 'shake' | 'wavy-line' | 'schleifer' | 'tremolo' | 'haydn';
558
+ type OrnamentType = 'trill-mark' | 'mordent' | 'inverted-mordent' | 'turn' | 'inverted-turn' | 'delayed-turn' | 'delayed-inverted-turn' | 'vertical-turn' | 'inverted-vertical-turn' | 'shake' | 'wavy-line' | 'schleifer' | 'tremolo' | 'haydn' | 'other-ornament';
544
559
  interface TechnicalNotation extends BaseNotation {
545
560
  type: 'technical';
546
561
  technical: TechnicalType;
@@ -1089,4 +1104,4 @@ interface StructuralChanges {
1089
1104
  clefChanges: ClefChangeInfo[];
1090
1105
  }
1091
1106
 
1092
- export type { TupletGroup as $, Accidental as A, BackupEntry as B, Clef as C, DirectionEntry as D, EntryWithContext as E, ForwardEntry as F, StaffRange as G, PositionQueryOptions as H, VerticalSlice as I, VoiceLine as J, KeySignature as K, Lyric as L, Measure as M, NoteEntry as N, AdjacentNotes as O, Pitch as P, DirectionKind as Q, DynamicWithContext as R, Score as S, TieInfo as T, TempoWithContext as U, VoiceGroup as V, PedalWithContext as W, WedgeWithContext as X, OctaveShiftWithContext as Y, TiedNoteGroup as Z, SlurSpan as _, ScoreMetadata as a, BeamGroup as a0, NotationType as a1, HarmonyWithContext as a2, LyricWithContext as a3, AssembledLyrics as a4, BarlineWithContext as a5, RepeatInfo as a6, EndingInfo as a7, KeyChangeInfo as a8, TimeChangeInfo as a9, ClefChangeInfo as aa, StructuralChanges as ab, HarmonyEntry as ac, PartInfo as b, PartGroup as c, PartListEntry as d, Part as e, MeasureAttributes as f, MeasureEntry as g, NoteType as h, AccidentalInfo as i, BeamInfo as j, Notation as k, DirectionType as l, DynamicsValue as m, TimeSignature as n, Transpose as o, Barline as p, StaffGroup as q, NoteWithPosition as r, Chord as s, NoteIteratorItem as t, Print as u, Defaults as v, Credit as w, VoiceToStaffMap as x, NoteWithContext as y, DirectionWithContext as z };
1107
+ export type { TupletGroup as $, Accidental as A, BackupEntry as B, Clef as C, DirectionEntry as D, EntryWithContext as E, ForwardEntry as F, StaffRange as G, PositionQueryOptions as H, VerticalSlice as I, VoiceLine as J, KeySignature as K, Lyric as L, Measure as M, NoteEntry as N, AdjacentNotes as O, Pitch as P, DirectionKind as Q, DynamicWithContext as R, Score as S, TieInfo as T, TempoWithContext as U, VoiceGroup as V, PedalWithContext as W, WedgeWithContext as X, OctaveShiftWithContext as Y, TiedNoteGroup as Z, SlurSpan as _, ScoreMetadata as a, BeamGroup as a0, NotationType as a1, HarmonyWithContext as a2, LyricWithContext as a3, AssembledLyrics as a4, BarlineWithContext as a5, RepeatInfo as a6, EndingInfo as a7, KeyChangeInfo as a8, TimeChangeInfo as a9, ClefChangeInfo as aa, StructuralChanges as ab, HarmonyEntry as ac, ArticulationType as ad, OrnamentType as ae, PartInfo as b, PartGroup as c, PartListEntry as d, Part as e, MeasureAttributes as f, MeasureEntry as g, NoteType as h, AccidentalInfo as i, BeamInfo as j, Notation as k, DirectionType as l, DynamicsValue as m, TimeSignature as n, Transpose as o, Barline as p, StaffGroup as q, NoteWithPosition as r, Chord as s, NoteIteratorItem as t, Print as u, Defaults as v, Credit as w, VoiceToStaffMap as x, NoteWithContext as y, DirectionWithContext as z };
@@ -1,4 +1,5 @@
1
1
  interface Score {
2
+ _id: string;
2
3
  metadata: ScoreMetadata;
3
4
  partList: PartListEntry[];
4
5
  parts: Part[];
@@ -90,6 +91,7 @@ interface FontInfo {
90
91
  fontWeight?: string;
91
92
  }
92
93
  interface Credit {
94
+ _id: string;
93
95
  page?: number;
94
96
  creditType?: string[];
95
97
  creditWords?: CreditWords[];
@@ -116,6 +118,7 @@ interface CreditWords {
116
118
  }
117
119
  type PartListEntry = PartInfo | PartGroup;
118
120
  interface PartInfo {
121
+ _id: string;
119
122
  type: 'score-part';
120
123
  id: string;
121
124
  name?: string;
@@ -161,6 +164,7 @@ interface MidiInstrument {
161
164
  elevation?: number;
162
165
  }
163
166
  interface PartGroup {
167
+ _id: string;
164
168
  type: 'part-group';
165
169
  groupType: 'start' | 'stop';
166
170
  number?: number;
@@ -173,10 +177,12 @@ interface PartGroup {
173
177
  groupBarline?: 'yes' | 'no' | 'Mensurstrich';
174
178
  }
175
179
  interface Part {
180
+ _id: string;
176
181
  id: string;
177
182
  measures: Measure[];
178
183
  }
179
184
  interface Measure {
185
+ _id: string;
180
186
  number: string;
181
187
  width?: number;
182
188
  implicit?: boolean;
@@ -294,6 +300,7 @@ interface Transpose {
294
300
  octaveChange?: number;
295
301
  }
296
302
  interface Barline {
303
+ _id: string;
297
304
  location: 'left' | 'right' | 'middle';
298
305
  barStyle?: 'regular' | 'dotted' | 'dashed' | 'heavy' | 'light-light' | 'light-heavy' | 'heavy-light' | 'heavy-heavy' | 'tick' | 'short' | 'none';
299
306
  repeat?: {
@@ -307,10 +314,12 @@ interface Barline {
307
314
  }
308
315
  type MeasureEntry = NoteEntry | BackupEntry | ForwardEntry | DirectionEntry | HarmonyEntry | FiguredBassEntry | SoundEntry | AttributesEntry;
309
316
  interface AttributesEntry {
317
+ _id: string;
310
318
  type: 'attributes';
311
319
  attributes: MeasureAttributes;
312
320
  }
313
321
  interface NoteEntry {
322
+ _id: string;
314
323
  type: 'note';
315
324
  pitch?: Pitch;
316
325
  rest?: RestInfo;
@@ -356,10 +365,12 @@ interface NoteEntry {
356
365
  };
357
366
  }
358
367
  interface BackupEntry {
368
+ _id: string;
359
369
  type: 'backup';
360
370
  duration: number;
361
371
  }
362
372
  interface ForwardEntry {
373
+ _id: string;
363
374
  type: 'forward';
364
375
  duration: number;
365
376
  voice?: number;
@@ -380,6 +391,7 @@ interface DirectionSound {
380
391
  sostenutoPedal?: 'yes' | 'no';
381
392
  }
382
393
  interface DirectionEntry {
394
+ _id: string;
383
395
  type: 'direction';
384
396
  directionTypes: DirectionType[];
385
397
  placement?: 'above' | 'below';
@@ -398,6 +410,7 @@ interface Swing {
398
410
  swingType?: string;
399
411
  }
400
412
  interface SoundEntry {
413
+ _id: string;
401
414
  type: 'sound';
402
415
  tempo?: number;
403
416
  dynamics?: number;
@@ -414,6 +427,7 @@ interface SoundEntry {
414
427
  sostenutoPedal?: boolean | 'yes' | 'no';
415
428
  }
416
429
  interface HarmonyEntry {
430
+ _id: string;
417
431
  type: 'harmony';
418
432
  root: {
419
433
  rootStep: string;
@@ -455,6 +469,7 @@ interface FrameNote {
455
469
  barre?: 'start' | 'stop';
456
470
  }
457
471
  interface FiguredBassEntry {
472
+ _id: string;
458
473
  type: 'figured-bass';
459
474
  figures: Figure[];
460
475
  duration?: number;
@@ -540,7 +555,7 @@ interface OrnamentNotation extends BaseNotation {
540
555
  defaultX?: number;
541
556
  defaultY?: number;
542
557
  }
543
- type OrnamentType = 'trill-mark' | 'mordent' | 'inverted-mordent' | 'turn' | 'inverted-turn' | 'delayed-turn' | 'delayed-inverted-turn' | 'vertical-turn' | 'shake' | 'wavy-line' | 'schleifer' | 'tremolo' | 'haydn';
558
+ type OrnamentType = 'trill-mark' | 'mordent' | 'inverted-mordent' | 'turn' | 'inverted-turn' | 'delayed-turn' | 'delayed-inverted-turn' | 'vertical-turn' | 'inverted-vertical-turn' | 'shake' | 'wavy-line' | 'schleifer' | 'tremolo' | 'haydn' | 'other-ornament';
544
559
  interface TechnicalNotation extends BaseNotation {
545
560
  type: 'technical';
546
561
  technical: TechnicalType;
@@ -1089,4 +1104,4 @@ interface StructuralChanges {
1089
1104
  clefChanges: ClefChangeInfo[];
1090
1105
  }
1091
1106
 
1092
- export type { TupletGroup as $, Accidental as A, BackupEntry as B, Clef as C, DirectionEntry as D, EntryWithContext as E, ForwardEntry as F, StaffRange as G, PositionQueryOptions as H, VerticalSlice as I, VoiceLine as J, KeySignature as K, Lyric as L, Measure as M, NoteEntry as N, AdjacentNotes as O, Pitch as P, DirectionKind as Q, DynamicWithContext as R, Score as S, TieInfo as T, TempoWithContext as U, VoiceGroup as V, PedalWithContext as W, WedgeWithContext as X, OctaveShiftWithContext as Y, TiedNoteGroup as Z, SlurSpan as _, ScoreMetadata as a, BeamGroup as a0, NotationType as a1, HarmonyWithContext as a2, LyricWithContext as a3, AssembledLyrics as a4, BarlineWithContext as a5, RepeatInfo as a6, EndingInfo as a7, KeyChangeInfo as a8, TimeChangeInfo as a9, ClefChangeInfo as aa, StructuralChanges as ab, HarmonyEntry as ac, PartInfo as b, PartGroup as c, PartListEntry as d, Part as e, MeasureAttributes as f, MeasureEntry as g, NoteType as h, AccidentalInfo as i, BeamInfo as j, Notation as k, DirectionType as l, DynamicsValue as m, TimeSignature as n, Transpose as o, Barline as p, StaffGroup as q, NoteWithPosition as r, Chord as s, NoteIteratorItem as t, Print as u, Defaults as v, Credit as w, VoiceToStaffMap as x, NoteWithContext as y, DirectionWithContext as z };
1107
+ export type { TupletGroup as $, Accidental as A, BackupEntry as B, Clef as C, DirectionEntry as D, EntryWithContext as E, ForwardEntry as F, StaffRange as G, PositionQueryOptions as H, VerticalSlice as I, VoiceLine as J, KeySignature as K, Lyric as L, Measure as M, NoteEntry as N, AdjacentNotes as O, Pitch as P, DirectionKind as Q, DynamicWithContext as R, Score as S, TieInfo as T, TempoWithContext as U, VoiceGroup as V, PedalWithContext as W, WedgeWithContext as X, OctaveShiftWithContext as Y, TiedNoteGroup as Z, SlurSpan as _, ScoreMetadata as a, BeamGroup as a0, NotationType as a1, HarmonyWithContext as a2, LyricWithContext as a3, AssembledLyrics as a4, BarlineWithContext as a5, RepeatInfo as a6, EndingInfo as a7, KeyChangeInfo as a8, TimeChangeInfo as a9, ClefChangeInfo as aa, StructuralChanges as ab, HarmonyEntry as ac, ArticulationType as ad, OrnamentType as ae, PartInfo as b, PartGroup as c, PartListEntry as d, Part as e, MeasureAttributes as f, MeasureEntry as g, NoteType as h, AccidentalInfo as i, BeamInfo as j, Notation as k, DirectionType as l, DynamicsValue as m, TimeSignature as n, Transpose as o, Barline as p, StaffGroup as q, NoteWithPosition as r, Chord as s, NoteIteratorItem as t, Print as u, Defaults as v, Credit as w, VoiceToStaffMap as x, NoteWithContext as y, DirectionWithContext as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musicxml-io",
3
- "version": "0.2.0",
3
+ "version": "0.2.7",
4
4
  "description": "Parse and serialize MusicXML (.xml/.mxl) with high round-trip fidelity",
5
5
  "author": "tan-z-tan",
6
6
  "license": "MIT",
@@ -76,7 +76,8 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "fast-xml-parser": "^4.3.2",
79
- "fflate": "^0.8.2"
79
+ "fflate": "^0.8.2",
80
+ "nanoid": "^5.1.6"
80
81
  },
81
82
  "files": [
82
83
  "dist"
@@ -1,377 +0,0 @@
1
- import { S as Score, M as Measure, n as TimeSignature, e as Part, N as NoteEntry, K as KeySignature, P as Pitch, C as Clef } from './types-Dp9zcgIg.js';
2
-
3
- type ValidationErrorCode = 'MISSING_DIVISIONS' | 'INVALID_DIVISIONS' | 'MEASURE_DURATION_MISMATCH' | 'MEASURE_DURATION_OVERFLOW' | 'MEASURE_DURATION_UNDERFLOW' | 'VOICE_INCOMPLETE' | 'VOICE_GAP' | 'NEGATIVE_POSITION' | 'BACKUP_EXCEEDS_POSITION' | 'TIE_START_WITHOUT_STOP' | 'TIE_STOP_WITHOUT_START' | 'TIE_PITCH_MISMATCH' | 'BEAM_BEGIN_WITHOUT_END' | 'BEAM_END_WITHOUT_BEGIN' | 'SLUR_START_WITHOUT_STOP' | 'SLUR_STOP_WITHOUT_START' | 'TUPLET_START_WITHOUT_STOP' | 'TUPLET_STOP_WITHOUT_START' | 'PART_ID_NOT_IN_PART_LIST' | 'PART_LIST_ID_NOT_IN_PARTS' | 'PART_MEASURE_COUNT_MISMATCH' | 'PART_MEASURE_NUMBER_MISMATCH' | 'PART_GROUP_START_WITHOUT_STOP' | 'PART_GROUP_STOP_WITHOUT_START' | 'DUPLICATE_PART_ID' | 'INVALID_VOICE_NUMBER' | 'INVALID_STAFF_NUMBER' | 'STAFF_EXCEEDS_STAVES' | 'MISSING_STAVES_DECLARATION' | 'STAVES_DECLARATION_MISMATCH' | 'MISSING_CLEF_FOR_STAFF' | 'CLEF_STAFF_EXCEEDS_STAVES' | 'INVALID_DURATION' | 'EMPTY_MEASURE';
4
- type ValidationLevel = 'error' | 'warning' | 'info';
5
- interface ValidationLocation {
6
- partIndex?: number;
7
- partId?: string;
8
- measureIndex?: number;
9
- measureNumber?: string;
10
- entryIndex?: number;
11
- voice?: number;
12
- staff?: number;
13
- }
14
- interface ValidationError {
15
- code: ValidationErrorCode;
16
- level: ValidationLevel;
17
- message: string;
18
- location: ValidationLocation;
19
- details?: Record<string, unknown>;
20
- }
21
- interface ValidationResult {
22
- valid: boolean;
23
- errors: ValidationError[];
24
- warnings: ValidationError[];
25
- infos: ValidationError[];
26
- }
27
- interface ValidateOptions {
28
- /** Check divisions consistency (default: true) */
29
- checkDivisions?: boolean;
30
- /** Check measure durations match time signature (default: true) */
31
- checkMeasureDuration?: boolean;
32
- /** Check that each voice fills the entire measure (Piano Roll semantics) (default: false) */
33
- checkMeasureFullness?: boolean;
34
- /** Check backup/forward position consistency (default: true) */
35
- checkPosition?: boolean;
36
- /** Check tie start/stop pairing (default: true) */
37
- checkTies?: boolean;
38
- /** Check beam begin/end pairing (default: true) */
39
- checkBeams?: boolean;
40
- /** Check slur start/stop pairing (default: true) */
41
- checkSlurs?: boolean;
42
- /** Check tuplet start/stop pairing (default: true) */
43
- checkTuplets?: boolean;
44
- /** Check part ID references (default: true) */
45
- checkPartReferences?: boolean;
46
- /** Check part structure (measure count, numbers) (default: true) */
47
- checkPartStructure?: boolean;
48
- /** Check voice/staff numbers (default: true) */
49
- checkVoiceStaff?: boolean;
50
- /** Check staff structure (staves declaration, clefs) (default: true) */
51
- checkStaffStructure?: boolean;
52
- /** Tolerance for measure duration (in divisions, default: 0) */
53
- durationTolerance?: number;
54
- }
55
- /**
56
- * Validate a Score for internal consistency
57
- */
58
- declare function validate(score: Score, options?: ValidateOptions): ValidationResult;
59
- /**
60
- * Validate that divisions are defined and consistent
61
- */
62
- declare function validateDivisions(score: Score): ValidationError[];
63
- /**
64
- * Validate measure duration matches time signature
65
- */
66
- declare function validateMeasureDuration(measure: Measure, divisions: number, time: TimeSignature, location: ValidationLocation, tolerance?: number): ValidationError[];
67
- /**
68
- * Validate backup/forward position consistency
69
- */
70
- declare function validateBackupForward(measure: Measure, location: ValidationLocation): ValidationError[];
71
- /**
72
- * Validate tie start/stop pairing
73
- */
74
- declare function validateTies(measure: Measure, location: ValidationLocation): ValidationError[];
75
- /**
76
- * Validate beam begin/end pairing
77
- */
78
- declare function validateBeams(measure: Measure, location: ValidationLocation): ValidationError[];
79
- /**
80
- * Validate slur start/stop pairing
81
- */
82
- declare function validateSlurs(measure: Measure, _location: ValidationLocation): ValidationError[];
83
- /**
84
- * Validate tuplet start/stop pairing
85
- */
86
- declare function validateTuplets(measure: Measure, location: ValidationLocation): ValidationError[];
87
- /**
88
- * Validate part ID references between partList and parts
89
- */
90
- declare function validatePartReferences(score: Score): ValidationError[];
91
- /**
92
- * Validate voice and staff numbers
93
- */
94
- declare function validateVoiceStaff(measure: Measure, staves: number, location: ValidationLocation): ValidationError[];
95
- /**
96
- * Validate part structure (measure counts and numbers match across parts)
97
- */
98
- declare function validatePartStructure(score: Score): ValidationError[];
99
- /**
100
- * Validate staff structure within a part
101
- */
102
- declare function validateStaffStructure(part: Part, partIndex: number): ValidationError[];
103
- /**
104
- * Context needed to validate a single measure
105
- */
106
- interface MeasureValidationContext {
107
- /** Current divisions value (from previous attributes) */
108
- divisions: number;
109
- /** Current time signature */
110
- time?: TimeSignature;
111
- /** Current staves count */
112
- staves: number;
113
- /** Part index (for error location) */
114
- partIndex: number;
115
- /** Part ID (for error location) */
116
- partId: string;
117
- /** Measure index (for error location) */
118
- measureIndex: number;
119
- }
120
- /**
121
- * Options for local measure validation
122
- */
123
- interface LocalValidateOptions {
124
- checkMeasureDuration?: boolean;
125
- checkMeasureFullness?: boolean;
126
- checkPosition?: boolean;
127
- checkBeams?: boolean;
128
- checkTuplets?: boolean;
129
- checkVoiceStaff?: boolean;
130
- durationTolerance?: number;
131
- }
132
- /**
133
- * Validate a single measure with provided context.
134
- * This is useful for validating after local operations like addNote, deleteNote.
135
- *
136
- * @example
137
- * ```typescript
138
- * const context = getMeasureContext(score, partIndex, measureIndex);
139
- * const errors = validateMeasureLocal(measure, context);
140
- * if (errors.length > 0) {
141
- * throw new Error('Operation created invalid state');
142
- * }
143
- * ```
144
- */
145
- declare function validateMeasureLocal(measure: Measure, context: MeasureValidationContext, options?: LocalValidateOptions): ValidationError[];
146
- /**
147
- * Get the validation context for a measure by traversing previous attributes.
148
- * This collects divisions, time, and staves from measure 0 to the target measure.
149
- */
150
- declare function getMeasureContext(score: Score, partIndex: number, measureIndex: number): MeasureValidationContext;
151
- /**
152
- * Validate a measure after an operation, throwing if invalid.
153
- * Convenience wrapper around validateMeasureLocal.
154
- */
155
- declare function assertMeasureValid(score: Score, partIndex: number, measureIndex: number, options?: LocalValidateOptions): void;
156
- /**
157
- * Check if a score is valid (no errors)
158
- */
159
- declare function isValid(score: Score, options?: ValidateOptions): boolean;
160
- /**
161
- * Validate and throw if invalid
162
- */
163
- declare function assertValid(score: Score, options?: ValidateOptions): void;
164
- /**
165
- * Format a validation location for display
166
- */
167
- declare function formatLocation(location: ValidationLocation): string;
168
- /**
169
- * Validation exception with structured error information
170
- */
171
- declare class ValidationException extends Error {
172
- readonly errors: ValidationError[];
173
- constructor(errors: ValidationError[], message: string);
174
- }
175
- /**
176
- * Validate ties across measures
177
- * This is more complex as ties can span multiple measures
178
- */
179
- declare function validateTiesAcrossMeasures(part: Part): ValidationError[];
180
- /**
181
- * Validate slurs across measures
182
- */
183
- declare function validateSlursAcrossMeasures(part: Part): ValidationError[];
184
-
185
- /**
186
- * Operation result type - success with data or failure with errors
187
- */
188
- type OperationResult<T> = {
189
- success: true;
190
- data: T;
191
- warnings?: ValidationError[];
192
- } | {
193
- success: false;
194
- errors: ValidationError[];
195
- };
196
- type OperationErrorCode = 'NOTE_CONFLICT' | 'EXCEEDS_MEASURE' | 'INVALID_POSITION' | 'NOTE_NOT_FOUND' | 'PART_NOT_FOUND' | 'MEASURE_NOT_FOUND' | 'INVALID_DURATION' | 'INVALID_STAFF' | 'DUPLICATE_PART_ID';
197
- interface InsertNoteOptions {
198
- partIndex: number;
199
- measureIndex: number;
200
- voice: number;
201
- staff?: number;
202
- position: number;
203
- pitch: Pitch;
204
- duration: number;
205
- noteType?: NoteEntry['noteType'];
206
- dots?: number;
207
- }
208
- /**
209
- * Insert a note at the specified position in a voice.
210
- * - If the position has a rest, replaces it with the note
211
- * - If there's a conflicting note, returns NOTE_CONFLICT error
212
- * - If the note exceeds measure duration, returns EXCEEDS_MEASURE error
213
- */
214
- declare function insertNote(score: Score, options: InsertNoteOptions): OperationResult<Score>;
215
- /**
216
- * Remove a note and replace with rest
217
- */
218
- declare function removeNote(score: Score, options: {
219
- partIndex: number;
220
- measureIndex: number;
221
- noteIndex: number;
222
- }): OperationResult<Score>;
223
- /**
224
- * Add a chord note to an existing note
225
- */
226
- declare function addChord(score: Score, options: {
227
- partIndex: number;
228
- measureIndex: number;
229
- noteIndex: number;
230
- pitch: Pitch;
231
- }): OperationResult<Score>;
232
- /**
233
- * Change note duration with proper handling of following notes
234
- * - If longer: consumes following rests/notes, returns error if would overwrite notes
235
- * - If shorter: fills remainder with rest
236
- */
237
- declare function changeNoteDuration(score: Score, options: {
238
- partIndex: number;
239
- measureIndex: number;
240
- noteIndex: number;
241
- newDuration: number;
242
- noteType?: NoteEntry['noteType'];
243
- dots?: number;
244
- }): OperationResult<Score>;
245
- /**
246
- * Set note pitch (simple pitch change, no validation needed)
247
- */
248
- declare function setNotePitch(score: Score, options: {
249
- partIndex: number;
250
- measureIndex: number;
251
- noteIndex: number;
252
- pitch: Pitch;
253
- }): OperationResult<Score>;
254
- /**
255
- * Add a new voice to a measure, filled with a whole-measure rest
256
- */
257
- declare function addVoice(score: Score, options: {
258
- partIndex: number;
259
- measureIndex: number;
260
- voice: number;
261
- staff?: number;
262
- }): OperationResult<Score>;
263
- /**
264
- * Transpose all notes in the score
265
- */
266
- declare function transpose(score: Score, semitones: number): OperationResult<Score>;
267
- interface AddPartOptions {
268
- id: string;
269
- name?: string;
270
- abbreviation?: string;
271
- insertIndex?: number;
272
- time?: TimeSignature;
273
- key?: KeySignature;
274
- clef?: Clef;
275
- divisions?: number;
276
- }
277
- declare function addPart(score: Score, options: AddPartOptions): OperationResult<Score>;
278
- declare function removePart(score: Score, partId: string): OperationResult<Score>;
279
- declare function duplicatePart(score: Score, options: {
280
- sourcePartId: string;
281
- newPartId: string;
282
- newPartName?: string;
283
- }): OperationResult<Score>;
284
- declare function setStaves(score: Score, options: {
285
- partIndex: number;
286
- staves: number;
287
- clefs?: Clef[];
288
- fromMeasure?: number;
289
- }): OperationResult<Score>;
290
- declare function moveNoteToStaff(score: Score, options: {
291
- partIndex: number;
292
- measureIndex: number;
293
- noteIndex: number;
294
- targetStaff: number;
295
- }): OperationResult<Score>;
296
- declare function changeKey(score: Score, key: KeySignature, options: {
297
- fromMeasure: string | number;
298
- }): Score;
299
- declare function changeTime(score: Score, time: TimeSignature, options: {
300
- fromMeasure: string | number;
301
- }): Score;
302
- declare function insertMeasure(score: Score, options: {
303
- afterMeasure: string | number;
304
- copyAttributes?: boolean;
305
- }): Score;
306
- declare function deleteMeasure(score: Score, measureNumber: string | number): Score;
307
- /** @deprecated Use insertNote instead */
308
- declare const addNote: (score: Score, options: {
309
- partIndex: number;
310
- measureIndex: number;
311
- staff?: number;
312
- voice: number;
313
- position: number;
314
- note: Omit<NoteEntry, "type" | "voice" | "staff">;
315
- }) => Score;
316
- /** @deprecated Use removeNote instead */
317
- declare const deleteNote: (score: Score, options: {
318
- partIndex: number;
319
- measureIndex: number;
320
- noteIndex: number;
321
- }) => Score;
322
- /** @deprecated Use addChord instead */
323
- declare const addChordNote: (score: Score, options: {
324
- partIndex: number;
325
- measureIndex: number;
326
- afterNoteIndex: number;
327
- pitch: Pitch;
328
- }) => Score;
329
- /** @deprecated Use setNotePitch instead */
330
- declare const modifyNotePitch: (score: Score, options: {
331
- partIndex: number;
332
- measureIndex: number;
333
- noteIndex: number;
334
- pitch: Pitch;
335
- }) => Score;
336
- /** @deprecated Use changeNoteDuration instead */
337
- declare const modifyNoteDuration: (score: Score, options: {
338
- partIndex: number;
339
- measureIndex: number;
340
- noteIndex: number;
341
- duration: number;
342
- noteType?: NoteEntry["noteType"];
343
- dots?: number;
344
- }) => Score;
345
- /** @deprecated Use insertNote instead */
346
- declare const addNoteChecked: (score: Score, options: {
347
- partIndex: number;
348
- measureIndex: number;
349
- staff?: number;
350
- voice: number;
351
- position: number;
352
- note: Omit<NoteEntry, "type" | "voice" | "staff">;
353
- }) => OperationResult<Score>;
354
- /** @deprecated Use removeNote instead */
355
- declare const deleteNoteChecked: typeof removeNote;
356
- /** @deprecated Use addChord instead */
357
- declare const addChordNoteChecked: (score: Score, options: {
358
- partIndex: number;
359
- measureIndex: number;
360
- afterNoteIndex: number;
361
- pitch: Pitch;
362
- }) => OperationResult<Score>;
363
- /** @deprecated Use setNotePitch instead */
364
- declare const modifyNotePitchChecked: typeof setNotePitch;
365
- /** @deprecated Use changeNoteDuration instead */
366
- declare const modifyNoteDurationChecked: (score: Score, options: {
367
- partIndex: number;
368
- measureIndex: number;
369
- noteIndex: number;
370
- duration: number;
371
- noteType?: NoteEntry["noteType"];
372
- dots?: number;
373
- }) => OperationResult<Score>;
374
- /** @deprecated Use transpose instead */
375
- declare const transposeChecked: typeof transpose;
376
-
377
- export { moveNoteToStaff as $, validateSlursAcrossMeasures as A, formatLocation as B, ValidationException as C, validateMeasureLocal as D, getMeasureContext as E, assertMeasureValid as F, type ValidationError as G, type ValidationLocation as H, type ValidationErrorCode as I, type ValidationLevel as J, type OperationErrorCode as K, type LocalValidateOptions as L, type MeasureValidationContext as M, type InsertNoteOptions as N, type OperationResult as O, insertNote as P, removeNote as Q, addChord as R, changeNoteDuration as S, setNotePitch as T, addVoice as U, type ValidateOptions as V, type AddPartOptions as W, addPart as X, removePart as Y, duplicatePart as Z, setStaves as _, type ValidationResult as a, addNoteChecked as a0, deleteNoteChecked as a1, addChordNoteChecked as a2, modifyNotePitchChecked as a3, modifyNoteDurationChecked as a4, transposeChecked as a5, addNote as b, changeKey as c, deleteNote as d, changeTime as e, deleteMeasure as f, addChordNote as g, modifyNoteDuration as h, insertMeasure as i, isValid as j, assertValid as k, validateDivisions as l, modifyNotePitch as m, validateMeasureDuration as n, validateBackupForward as o, validateTies as p, validateBeams as q, validateSlurs as r, validateTuplets as s, transpose as t, validatePartReferences as u, validate as v, validatePartStructure as w, validateStaffStructure as x, validateVoiceStaff as y, validateTiesAcrossMeasures as z };