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,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.mjs';
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 };