1
0
mirror of synced 2024-11-30 23:57:16 +01:00

converters.py: Don't update SCROLL/GOGO/BARLINE right away

Instead, we should only update the values once we encounter more notes.

This prevents an issue where a command is used before a BPMCHANGE event:

#   33
#   #GOGOEND
#   #BPMCHANGE 107
#   33,

If GOGOEND is applied right away, then the first '33' notes will be affected. But, we only want the last '33' notes to be affected.
This commit is contained in:
Viv 2023-06-29 16:23:26 -04:00
parent 3f981236e3
commit 9069f462ce

View File

@ -71,6 +71,20 @@ def preprocessTJAMeasures(tja):
for data in combined: for data in combined:
if data['type'] == 'note': if data['type'] == 'note':
measure_cur['data'].append(data) measure_cur['data'].append(data)
# Update the current measure's SCROLL/GOGO/BARLINE status.
measure_cur['scroll'] = currentScroll
measure_cur['gogo'] = currentGogo
measure_cur['barline'] = currentBarline
# NB: The reason we update the measure's SCROLL/GOGO/BARLINE during the "note" event is because of
# an ordering problem for mid-measure BPMCHANGEs. For example, imagine the following two TJA charts:
# 33 11021020
# #GOGOEND #BPMCHANGE 178
# #BPMCHANGE 107 #SCROLL 1.04
# 33, 1102,
# In both examples, BPMCHANGE + one other command happen mid-measure. But, the ordering differs.
# This is relevant because in fumen files, "BPMCHANGE" signals the start of a new sub-measure.
# Yet, in both cases, we want the 2nd command to apply to the notes _after_ the BPMCHANGE.
# So, we make sure to only apply SCROLL/GOGO/BARLINE changes once we actually encounter new notes.
elif data['type'] == 'bpm': elif data['type'] == 'bpm':
currentBPM = float(data['value']) currentBPM = float(data['value'])
# Case 1: BPM change at the start of a measure; just change BPM # Case 1: BPM change at the start of a measure; just change BPM
@ -85,13 +99,10 @@ def preprocessTJAMeasures(tja):
'time_sig': measure['length'], 'data': []} 'time_sig': measure['length'], 'data': []}
elif data['type'] == 'scroll': elif data['type'] == 'scroll':
currentScroll = data['value'] currentScroll = data['value']
measure_cur['scroll'] = currentScroll
elif data['type'] == 'gogo': elif data['type'] == 'gogo':
currentGogo = bool(int(data['value'])) currentGogo = bool(int(data['value']))
measure_cur['gogo'] = currentGogo
elif data['type'] == 'barline': elif data['type'] == 'barline':
currentBarline = bool(int(data['value'])) currentBarline = bool(int(data['value']))
measure_cur['barline'] = currentBarline
else: else:
print(f"Unexpected event type: {data['type']}") print(f"Unexpected event type: {data['type']}")
measure_cur['pos_end'] = len(measure['data']) measure_cur['pos_end'] = len(measure['data'])