Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/importer/MusicXmlImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,11 @@ export class MusicXmlImporter extends ScoreImporter {
for (const c of element.childElements()) {
switch (c.localName) {
case 'direction-type':
directionTypes.push(c.firstElement!);
// See https://github.com/CoderLine/alphaTab/issues/2102
const type = c.firstElement;
if(type) {
directionTypes.push(type);
}
break;
case 'offset':
offset = Number.parseFloat(c.innerText);
Expand Down
32 changes: 32 additions & 0 deletions test-data/musicxml4/2102-corrupt-direction.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<score-partwise version="4.0">
<part-list>
<score-part id="P1">
<part-name>Track 1</part-name>
<part-abbreviation>T1</part-abbreviation>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>480</divisions>
</attributes>

<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>480</duration>
<type>quarter</type>
</note>

<direction placement="below">
<!-- Malformed: no direction type -->
<direction-type>
</direction-type>
<staff>1</staff>
</direction>
</measure>
</part>
</score-partwise>
5 changes: 5 additions & 0 deletions test/importer/MusicXmlImporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,9 @@ describe('MusicXmlImporterTests', () => {
const score = await MusicXmlImporterTestHelper.loadFile('test-data/musicxml4/barlines.xml');
expect(score).toMatchSnapshot();
});

it('2102-corrupt-direction', async () => {
const score = await MusicXmlImporterTestHelper.loadFile('test-data/musicxml4/2102-corrupt-direction.xml');
expect(score).toMatchSnapshot();
});
});
67 changes: 67 additions & 0 deletions test/importer/__snapshots__/musicxmlimporter.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,72 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MusicXmlImporterTests 2102-corrupt-direction 1`] = `
Map {
"__kind" => "Score",
"masterbars" => Array [
Map {
"__kind" => "MasterBar",
},
],
"tracks" => Array [
Map {
"__kind" => "Track",
"staves" => Array [
Map {
"__kind" => "Staff",
"bars" => Array [
Map {
"__kind" => "Bar",
"id" => 0,
"voices" => Array [
Map {
"__kind" => "Voice",
"id" => 0,
"beats" => Array [
Map {
"__kind" => "Beat",
"id" => 0,
"notes" => Array [
Map {
"__kind" => "Note",
"id" => 0,
"octave" => 5,
"tone" => 0,
},
],
"automations" => Array [
Map {
"islinear" => false,
"type" => 2,
"value" => 0,
"ratioposition" => 0,
"text" => "",
},
],
"displayduration" => 960,
"playbackduration" => 960,
"overridedisplayduration" => 960,
},
],
},
],
},
],
},
],
"playbackinfo" => Map {
"secondarychannel" => 1,
},
"name" => "Track 1",
"shortname" => "T1",
},
],
"stylesheet" => Map {
"hidedynamics" => true,
},
}
`;

exports[`MusicXmlImporterTests barlines 1`] = `
Map {
"__kind" => "Score",
Expand Down