converters.py
: Remove redundant submeasures
object
This commit is contained in:
parent
fdeefc2499
commit
1f76b19e69
@ -38,13 +38,12 @@ def preprocessTJAMeasures(tja):
|
|||||||
|
|
||||||
In the future, this logic should probably be moved into the TJA parser itself.
|
In the future, this logic should probably be moved into the TJA parser itself.
|
||||||
"""
|
"""
|
||||||
measuresCorrected = []
|
|
||||||
|
|
||||||
currentBPM = 0
|
currentBPM = 0
|
||||||
currentScroll = 1.0
|
currentScroll = 1.0
|
||||||
currentGogo = False
|
currentGogo = False
|
||||||
currentHidden = False
|
currentHidden = False
|
||||||
|
|
||||||
|
measuresCorrected = []
|
||||||
for measure in tja['measures']:
|
for measure in tja['measures']:
|
||||||
# Step 1: Combine notes and events
|
# Step 1: Combine notes and events
|
||||||
notes = [{'pos': i, 'type': 'note', 'value': TJA_NOTE_TYPES[note]}
|
notes = [{'pos': i, 'type': 'note', 'value': TJA_NOTE_TYPES[note]}
|
||||||
@ -64,8 +63,9 @@ def preprocessTJAMeasures(tja):
|
|||||||
combined.append(notes.pop(0))
|
combined.append(notes.pop(0))
|
||||||
|
|
||||||
# Step 2: Split measure into submeasure
|
# Step 2: Split measure into submeasure
|
||||||
submeasures = []
|
measure_cur = {'bpm': currentBPM, 'scroll': currentScroll, 'subdivisions': len(measure['data']),
|
||||||
measure_cur = {'bpm': currentBPM, 'scroll': currentScroll, 'pos_start': 0, 'data': []}
|
'pos_start': 0, 'pos_end': 0, 'time_sig': measure['length'],
|
||||||
|
'data': [], 'properties': measure['properties']}
|
||||||
for data in combined:
|
for data in combined:
|
||||||
if data['type'] == 'bpm':
|
if data['type'] == 'bpm':
|
||||||
currentBPM = float(data['value'])
|
currentBPM = float(data['value'])
|
||||||
@ -75,8 +75,10 @@ def preprocessTJAMeasures(tja):
|
|||||||
# Case 2: BPM change mid-measure, so start a new sub-measure
|
# Case 2: BPM change mid-measure, so start a new sub-measure
|
||||||
else:
|
else:
|
||||||
measure_cur['pos_end'] = data['pos']
|
measure_cur['pos_end'] = data['pos']
|
||||||
submeasures.append(measure_cur)
|
measuresCorrected.append(measure_cur)
|
||||||
measure_cur = {'bpm': currentBPM, 'scroll': currentScroll, 'pos_start': data['pos'], 'data': []}
|
measure_cur = {'bpm': currentBPM, 'scroll': currentScroll, 'subdivisions': len(measure['data']),
|
||||||
|
'pos_start': data['pos'], 'pos_end': 0, 'time_sig': measure['length'],
|
||||||
|
'data': [], 'properties': measure['properties']}
|
||||||
elif data['type'] == 'scroll':
|
elif data['type'] == 'scroll':
|
||||||
currentScroll = data['value']
|
currentScroll = data['value']
|
||||||
measure_cur['scroll'] = currentScroll
|
measure_cur['scroll'] = currentScroll
|
||||||
@ -84,20 +86,7 @@ def preprocessTJAMeasures(tja):
|
|||||||
else:
|
else:
|
||||||
measure_cur['data'].append(data)
|
measure_cur['data'].append(data)
|
||||||
measure_cur['pos_end'] = len(measure['data'])
|
measure_cur['pos_end'] = len(measure['data'])
|
||||||
submeasures.append(measure_cur)
|
measuresCorrected.append(measure_cur)
|
||||||
|
|
||||||
# Append the newly-created measures
|
|
||||||
for submeasure in submeasures:
|
|
||||||
measuresCorrected.append({
|
|
||||||
'bpm': submeasure['bpm'],
|
|
||||||
'scroll': submeasure['scroll'],
|
|
||||||
'subdivisions': len(measure['data']),
|
|
||||||
'pos_start': submeasure['pos_start'],
|
|
||||||
'pos_end': submeasure['pos_end'],
|
|
||||||
'time_sig': measure['length'],
|
|
||||||
'data': submeasure['data'],
|
|
||||||
'properties': measure['properties'],
|
|
||||||
})
|
|
||||||
|
|
||||||
return measuresCorrected
|
return measuresCorrected
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user