Skip to content

Commit

Permalink
Fix #62 invalid ending
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Jan 28, 2024
1 parent 78fce38 commit 78ccee6
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 107 deletions.
4 changes: 2 additions & 2 deletions doc/irealpro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# iReal Pro format and model

## Sources
- iReal Pro [app](https://irealpro.com/), [forum](https://irealb.com/forums/) and [support docs](https://irealpro.com/support/)
- [iReal Pro File Format](https://www.irealpro.com/ireal-pro-file-format)
- [`ireal-renderer`](https://github.com/daumling/ireal-renderer)

## Application model and playback algorithm
Expand Down Expand Up @@ -115,7 +115,7 @@ _I Got Rhythm_, _Like Someone in Love_, _On the Sunny Side of the Street_, _Mist
"Kcl" or "XyQKcl" - also repeat previous bar (see _Besame Mucho_, _Butterfly_, _Solar_)
"r" - repeat previous 2 bars (see _Mas Que Nada_)
"()" - alternative chord written in small (above actual chord)
" " - represents a chord seperator
" " - represents a chord separator
"," - equivalent to space, especially for whole notes in 44
"<stuff here>" - Comments and repeat directives (can start with "*yy" to denote a vertical offset of yy units, see _La Fiesta_)
"*A" - section A (could be *B, *C, *i, *v, etc.)
Expand Down
2 changes: 1 addition & 1 deletion lib/ireal-musicxml.js

Large diffs are not rendered by default.

196 changes: 98 additions & 98 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.12.1",
"version": "1.12.2",
"description": "iReal Pro to MusicXML converter",
"author": "Karim Ratib <[email protected]> (https://github.com/infojunkie)",
"license": "GPL-3.0-only",
Expand Down
10 changes: 8 additions & 2 deletions src/musicxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class MusicXML {
this.attributes = [];
this.chords = [];
this.barlines = [];
this.barEnding = 0;
this.barEnding = null;
}

number() {
Expand Down Expand Up @@ -450,7 +450,13 @@ export class MusicXML {
}
case 'N': { // ending
// TODO This assumes a single ending at a time.
const ending = parseInt(annot.slice(1));
let ending = parseInt(annot.slice(1));
if (ending < 1) {
// 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;
}
this.measure.barlines[0]['_content'].push(this.convertEnding(ending, 'start'));
// End the previous ending at the previous measure's right barline.
// Also, remove the 'discontinue' ending from its starting measure since we found an end to it.
Expand Down
24 changes: 21 additions & 3 deletions test/bugs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ before(() => {
})

describe('Bug Fixes', function() {
it('Checks #18 Cannot read property \'spaces\' of undefined', async () => {
it('checks #18 cannot read property \'spaces\' of undefined', async () => {
for (const title of [
"All Or Nothing At All",
"Brazilian Suite",
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('Bug Fixes', function() {
}
}).timeout(0);

it('Checks #20 Missing measures', async () => {
it('checks #20 missing measures', async () => {
for (const test of [
{ title: "A Ballad", measures: 41 },
{ title: "After You", measures: 32 },
Expand All @@ -67,5 +67,23 @@ describe('Bug Fixes', function() {

it('doesn\'t crash on empty songs', async () => {
const brendan = new Playlist(fs.readFileSync('test/data/brendan.html', 'utf-8'));
})
});

it('checks #54 messy chord timings', async () => {
const song = jazz.songs.find(song => song.title === 'Afro Blue');
assert.notStrictEqual(song, undefined);
const musicXml = MusicXML.convert(song);
await validateXMLWithXSD(musicXml, 'test/data/musicxml.xsd');
fs.writeFileSync(`test/output/${song.title}.musicxml`, musicXml);
const doc = new DOMParser().parseFromString(musicXml);
});

it('checks #62 invalid file', async () => {
const country = new Playlist(fs.readFileSync('test/data/country.txt', 'utf-8'));
const song = country.songs.find(song => song.title === 'Jackson');
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/country.txt

Large diffs are not rendered by default.

0 comments on commit 78ccee6

Please sign in to comment.