Skip to content

Commit

Permalink
Restore beat boundaries but after quantization
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Sep 16, 2024
1 parent e131f8b commit 0e267d4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/js/musicxml-grooves.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ for (const groove of JSON.parse(fs.readFileSync('build/grooves.json'))) {
}
catch (error) {
console.error(`Failed to convert ${groove.groove} to MusicXML: ${error}`)
throw error
}
}

Expand Down Expand Up @@ -601,7 +600,7 @@ function quantizeNoteOnset(note, index, notes, beats, grid) {
// Store the note.
note.quantized = {
onset: onset.multiple,
duration: scoreDuration - onset.error_sgn
duration: Math.min(scoreDuration - onset.error_sgn, DIVISIONS_QUARTER - onset.multiple % DIVISIONS_QUARTER)
}
}

Expand Down Expand Up @@ -630,12 +629,13 @@ function quantizeNoteDuration(note, index, notes, beats, grid) {
}, undefined)

if (offset === undefined) {
// TODO Handle this case.
console.warn(`[${note.track}:${note.measure+1}] Failed to quantize note duration at ${note.onset} to avoid zero duration.`)
}

// Adjust the note duration if it crosses the measure boundary.
if (offset.multiple >= beats * DIVISIONS) {
console.warn(`[${note.track}:${note.measure+1}] Quantized note duration at ${note.onset} crosses beat boundary. Reducing the duration.`)
if (offset.multiple > beats * DIVISIONS) {
console.warn(`[${note.track}:${note.measure+1}] Quantized note duration at ${note.onset} crosses measure boundary. Reducing the duration.`)
offset.multiple = beats * DIVISIONS
}

Expand Down

0 comments on commit 0e267d4

Please sign in to comment.