diff --git a/src/parsing/musicxml/measure.ts b/src/parsing/musicxml/measure.ts index a72ad755b..3df82af2a 100644 --- a/src/parsing/musicxml/measure.ts +++ b/src/parsing/musicxml/measure.ts @@ -134,6 +134,12 @@ export class Measure { fragments.push(Fragment.create(config, log, signature, buffer, partIds)); } + // Ensure every measure has at least one fragment so the Part structure is preserved + // for empty measures (e.g. when and notes are missing). + if (fragments.length === 0) { + fragments.push(Fragment.create(config, log, signature, [], partIds)); + } + return fragments; } diff --git a/tests/__data__/vexml/empty_first_measure.musicxml b/tests/__data__/vexml/empty_first_measure.musicxml new file mode 100644 index 000000000..3a4872f4a --- /dev/null +++ b/tests/__data__/vexml/empty_first_measure.musicxml @@ -0,0 +1,25 @@ + + + + Pitches and accidentals + + + All pitches from G to c'''' in + ascending steps; First without accidentals, then with a sharp and then + with a flat accidental. Double alterations and cautionary accidentals + are tested at the end. + + + + + MusicXML Part + + + + + + + + + diff --git a/tests/integration/__image_snapshots__/empty_first_measure_900px.png b/tests/integration/__image_snapshots__/empty_first_measure_900px.png new file mode 100644 index 000000000..4e85229f2 Binary files /dev/null and b/tests/integration/__image_snapshots__/empty_first_measure_900px.png differ diff --git a/tests/integration/vexml.test.ts b/tests/integration/vexml.test.ts index 99406c370..21debc66a 100644 --- a/tests/integration/vexml.test.ts +++ b/tests/integration/vexml.test.ts @@ -42,6 +42,7 @@ describe('vexml', () => { { filename: 'tabs_vibrato.musicxml', width: 900 }, { filename: 'tabs_bends.musicxml', width: 900 }, { filename: 'chord_symbols.musicxml', width: 900 }, + { filename: 'empty_first_measure.musicxml', width: 900 }, ])(`$filename ($width px)`, async (t) => { const { document, vexmlDiv, screenshotElementSelector } = setup();