Skip to content

Commit

Permalink
Fix all validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Aug 28, 2024
1 parent dc29b76 commit 61baa94
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/js/musicxml-grooves.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ function createPartEntry(groove, partId, part) {
notes.push(note)
if (index === source.length - 1) {
const duration = beats + 1 - note.onset
if (duration <= 0) {
console.warn(`Found note with duration 0. Ignoring.`)
}
notes.filter(note => note.duration === undefined).forEach(note => { note.duration = Math.min(1, duration) })
if (duration > 1) {
notes.push({
Expand All @@ -358,14 +361,15 @@ function createPartEntry(groove, partId, part) {
}
}
return notes
}, []).map((note, index, notes) => {
}, []).filter(note => note.duration > 0).map((note, index, notes) => {
const drum = note.midi ? SaxonJS.XPath.evaluate(`//instrument[@id="${instrumentId}"]/drum[@midi="${note.midi}"]`, instruments) : undefined
const pitch = drum ? `
<unpitched>
<display-step>${drum.getElementsByTagName('display-step')[0].textContent}</display-step>
<display-octave>${drum.getElementsByTagName('display-octave')[0].textContent}</display-octave>
</unpitched>
`.trim() : '<rest/>'
const instrument = drum ? `<instrument id="P${note.partId}-I${note.midi}"/>` : ''
const chord = (index > 0 && notes[index - 1].onset === note.onset) ? '<chord/>' : ''
const stem = drum ? `<stem>${drum.getElementsByTagName('stem')[0].textContent}</stem>` : ''
const notehead = drum ? `<notehead>${drum.getElementsByTagName('notehead')[0].textContent}</notehead>` : ''
Expand All @@ -375,7 +379,7 @@ function createPartEntry(groove, partId, part) {
${chord}
${pitch}
<duration>${duration}</duration>
<instrument id="P${note.partId}-I${note.midi}"/>
${instrument}
${getNoteTiming(note, index, notes, beatType)}
${stem}
${notehead}
Expand Down

0 comments on commit 61baa94

Please sign in to comment.