Skip to content

Commit

Permalink
Add dixieland tests and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Aug 25, 2024
1 parent 23055ad commit 8d5d57b
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 105 deletions.
4 changes: 2 additions & 2 deletions demo/cli/ireal-musicxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ try {
fs.writeFileSync(outFile, musicXml);
}
catch (error) {
console.error(`[ireal-musicxml] [${song.title}] ${error.toString()}`);
console.error(`[ireal-musicxml] [${song.title}] ${error}`);
}
}
}
catch (error) {
console.error(`[ireal-musicxml] [${args[0]}] ${error.toString()}`);
console.error(`[ireal-musicxml] [${args[0]}] ${error}`);
process.exit(1);
}
2 changes: 1 addition & 1 deletion lib/ireal-musicxml.js

Large diffs are not rendered by default.

170 changes: 79 additions & 91 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ireal-musicxml",
"version": "1.13.1",
"version": "1.13.2",
"description": "iReal Pro to MusicXML converter",
"author": "Karim Ratib <[email protected]> (https://github.com/infojunkie)",
"license": "GPL-3.0-only",
Expand Down
24 changes: 14 additions & 10 deletions src/musicxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,12 @@ export class MusicXML {
this._log(LogLevel.Error, `Cannot find any measure with chords prior to ${JSON.stringify(cell.chord)}`);
}
}
const chord = target.chords[target.chords.length-1].ireal;
chord.over = cell.chord.over;
chord.alternate = cell.chord.alternate;
this.measure.chords.push(this.convertChord(chord));
if (target) {
const chord = target.chords[target.chords.length-1].ireal;
chord.over = cell.chord.over;
chord.alternate = cell.chord.alternate;
this.measure.chords.push(this.convertChord(chord));
}
break;
}
case ' ': {
Expand Down Expand Up @@ -455,7 +457,7 @@ export class MusicXML {
// It can happen that the ending number comes as 0 from iRP.
// In this case, we do a best effort of finding the previous ending and incrementing it.
const target = measures.slice().reverse().find(m => !!m.barEnding);
ending = target.barEnding + 1;
ending = target?.barEnding ?? 0 + 1;
}
this.measure.barlines[0]['_content'].push(this.convertEnding(ending, 'start'));
// End the previous ending at the previous measure's right barline.
Expand All @@ -466,12 +468,14 @@ export class MusicXML {
if (!target) {
this._log(LogLevel.Error, `Cannot find ending ${ending-1} in right barline of any measure`);
}
// The last result is the good one: remove the 'discontinue' ending.
const index = target.barlines[1]['_content'].findIndex(b => b['_name'] === 'ending');
if (index === -1) {
this._log(LogLevel.Error, `Cannot find ending ${ending-1} in right barline`, target);
else {
// The last result is the good one: remove the 'discontinue' ending.
const index = target.barlines[1]['_content'].findIndex(b => !!b && b['_name'] === 'ending');
if (index === -1) {
this._log(LogLevel.Error, `Cannot find ending ${ending-1} in right barline`, target);
}
delete target.barlines[1]['_content'][index];
}
delete target.barlines[1]['_content'][index];
}
// We will add a 'discontinue' ending at this measure's right barline.
this.measure.barEnding = ending;
Expand Down
15 changes: 15 additions & 0 deletions test/bugs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,19 @@ describe('Bug Fixes', function() {
fs.writeFileSync(`test/output/${song.title}.musicxml`, musicXml);
await validateXMLWithXSD(musicXml, 'test/data/musicxml.xsd');
});

it('succeeds for dixieland1 playlist', async() => {
const dixieland1 = new Playlist(fs.readFileSync('test/data/dixieland1.txt', 'utf-8'));
for (const title of [
'All I Do Is Dream Of You',
'Beautiful Dreamer',
'Bouncin\' Around'
]) {
const song = dixieland1.songs.find(song => song.title === title);
assert.notStrictEqual(song, undefined);
const musicXml = MusicXML.convert(song);
fs.writeFileSync(`test/output/${song.title}.musicxml`, musicXml);
await validateXMLWithXSD(musicXml, 'test/data/musicxml.xsd');
}
})
});
1 change: 1 addition & 0 deletions test/data/dixieland1.txt

Large diffs are not rendered by default.

0 comments on commit 8d5d57b

Please sign in to comment.