From e053e1ad7a4bb0e230a8b387f1394bc037ef0466 Mon Sep 17 00:00:00 2001 From: Viv Date: Sat, 3 Jun 2023 20:32:50 -0400 Subject: [PATCH] `converters.py`: Rework the logic for measure offsets To compute the first measure's offset, I currently subtract the first measure's duration from the TJA's OFFSET value. However, I realized that you actually have to subtract the *second* measure's duration from the TJA offset value. (For 99% of songs, the first two measures will have the same duration, so that's why the bug slipped by.) Fixes #4. --- tja2fumen/converters.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tja2fumen/converters.py b/tja2fumen/converters.py index ddf32d1..edb1e51 100644 --- a/tja2fumen/converters.py +++ b/tja2fumen/converters.py @@ -122,16 +122,15 @@ def convertTJAToFumen(fumen, tja): if measureTJA['bpm'] != measureTJANext['bpm']: measureDuration -= (4 * 60_000 * ((1 / measureTJANext['bpm']) - (1 / measureTJA['bpm']))) - # Apply the change in offset to the overall offset to get the measure offset - # This is a bodge I'm using just for Rokuchounen to Ichiya Monogatari - # Its first measure happens _before_ the first barline - # So, we actually need to shift the offsets by 1 to get everything to line up + # Compute the millisecond offset for each measure if idx_m == 0: - # Compute fumen offset for the first measure that has a barline - fumenOffset = float(tja['metadata']['offset']) * -1000 - measureFumen['fumenOffset'] = fumenOffset - measureDuration + pass # NB: Pass for now, since we need the 2nd measure's duration to compute the 1st measure's offset else: - # Just refer back to the previous offset + # Compute the 1st measure's offset by subtracting the 2nd measure's duration from the tjaOffset + if idx_m == 1: + fumenOffset = float(tja['metadata']['offset']) * 1000 * -1 + tjaConverted['measures'][-1]['fumenOffset'] = fumenOffset - measureDuration + # Use the previous measure's offset plus the previous duration to compute the current measure's offset measureOffsetPrev = tjaConverted['measures'][-1]['fumenOffset'] measureFumen['fumenOffset'] = measureOffsetPrev + measureDurationNext measureDurationNext = measureDuration