From 0e267d4ccd4bddcfc484ec697b3c272005c11792 Mon Sep 17 00:00:00 2001 From: infojunkie Date: Sun, 15 Sep 2024 22:08:23 -0700 Subject: [PATCH] Restore beat boundaries but after quantization --- src/js/musicxml-grooves.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/musicxml-grooves.js b/src/js/musicxml-grooves.js index 6baa7cd6..12501bbe 100755 --- a/src/js/musicxml-grooves.js +++ b/src/js/musicxml-grooves.js @@ -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 } } @@ -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) } } @@ -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 }