converters.py
: Improve comments in convertTJAToFumen function
This commit is contained in:
parent
fac814f6de
commit
bc21f5a31d
@ -125,8 +125,11 @@ def processTJACommands(tja):
|
|||||||
def convertTJAToFumen(tja):
|
def convertTJAToFumen(tja):
|
||||||
# Preprocess commands
|
# Preprocess commands
|
||||||
tja['branches'] = processTJACommands(tja)
|
tja['branches'] = processTJACommands(tja)
|
||||||
# Parse TJA measures to create converted TJA -> Fumen file
|
|
||||||
|
# Pre-allocate the measures for the converted TJA
|
||||||
tjaConverted = {'measures': [deepcopy(default_measure) for _ in range(len(tja['branches']['normal']))]}
|
tjaConverted = {'measures': [deepcopy(default_measure) for _ in range(len(tja['branches']['normal']))]}
|
||||||
|
|
||||||
|
# Iterate through the different branches in the TJA
|
||||||
for currentBranch, branch in tja['branches'].items():
|
for currentBranch, branch in tja['branches'].items():
|
||||||
if not len(branch):
|
if not len(branch):
|
||||||
continue
|
continue
|
||||||
@ -135,24 +138,31 @@ def convertTJAToFumen(tja):
|
|||||||
note_counter_branch = 0
|
note_counter_branch = 0
|
||||||
currentDrumroll = None
|
currentDrumroll = None
|
||||||
courseBalloons = tja['metadata']['balloon'].copy()
|
courseBalloons = tja['metadata']['balloon'].copy()
|
||||||
|
|
||||||
|
# Iterate through the measures within the branch
|
||||||
for idx_m, measureTJA in enumerate(branch):
|
for idx_m, measureTJA in enumerate(branch):
|
||||||
# Fetch a pair of measures
|
# Fetch a pair of measures
|
||||||
measureFumenPrev = tjaConverted['measures'][idx_m-1] if idx_m != 0 else None
|
measureFumenPrev = tjaConverted['measures'][idx_m-1] if idx_m != 0 else None
|
||||||
measureFumen = tjaConverted['measures'][idx_m]
|
measureFumen = tjaConverted['measures'][idx_m]
|
||||||
|
|
||||||
# Apply basic measure properties (that don't depend on notes or commands)
|
# Copy over basic measure properties from the TJA (that don't depend on notes or commands)
|
||||||
measureFumen[currentBranch]['speed'] = measureTJA['scroll']
|
measureFumen[currentBranch]['speed'] = measureTJA['scroll']
|
||||||
measureFumen['gogo'] = measureTJA['gogo']
|
measureFumen['gogo'] = measureTJA['gogo']
|
||||||
measureFumen['bpm'] = measureTJA['bpm']
|
measureFumen['bpm'] = measureTJA['bpm']
|
||||||
|
|
||||||
# Compute the duration of the measure
|
# Compute the duration of the measure
|
||||||
measureSize = measureTJA['time_sig'][0] / measureTJA['time_sig'][1]
|
# First, we compute the duration for a full 4/4 measure
|
||||||
measureLength = measureTJA['pos_end'] - measureTJA['pos_start']
|
|
||||||
measureRatio = 1.0 if measureTJA['subdivisions'] == 0.0 else (measureLength / measureTJA['subdivisions'])
|
|
||||||
measureDurationFullMeasure = 4 * 60_000 / measureTJA['bpm']
|
measureDurationFullMeasure = 4 * 60_000 / measureTJA['bpm']
|
||||||
# Adjust the duration based on both:
|
# Next, we adjust this duration based on both:
|
||||||
# 1. Measure size (e.g. #MEASURE 1/8, #MEASURE 5/4, etc.)
|
# 1. The *actual* measure size (e.g. #MEASURE 1/8, #MEASURE 5/4, etc.)
|
||||||
# 2. Whether this is a "submeasure" (i.e. it contains mid-measure commands, splitting up the measure)
|
measureSize = measureTJA['time_sig'][0] / measureTJA['time_sig'][1]
|
||||||
|
# 2. Whether this is a "submeasure" (i.e. it contains mid-measure commands, which split up the measure)
|
||||||
|
# - If this is a submeasure, then `measureLength` will be less than the total number of subdivisions.
|
||||||
|
measureLength = measureTJA['pos_end'] - measureTJA['pos_start']
|
||||||
|
# - In other words, `measureRatio` will be less than 1.0:
|
||||||
|
measureRatio = (1.0 if measureTJA['subdivisions'] == 0.0 # Avoid division by 0 for empty measures
|
||||||
|
else (measureLength / measureTJA['subdivisions']))
|
||||||
|
# Apply the 2 adjustments to the measure duration
|
||||||
measureFumen['duration'] = measureDuration = measureDurationFullMeasure * measureSize * measureRatio
|
measureFumen['duration'] = measureDuration = measureDurationFullMeasure * measureSize * measureRatio
|
||||||
|
|
||||||
# Compute the millisecond offsets for the start and end of each measure
|
# Compute the millisecond offsets for the start and end of each measure
|
||||||
@ -162,9 +172,9 @@ def convertTJAToFumen(tja):
|
|||||||
tjaOffset = float(tja['metadata']['offset']) * 1000 * -1
|
tjaOffset = float(tja['metadata']['offset']) * 1000 * -1
|
||||||
measureFumen['fumenOffsetStart'] = tjaOffset - measureDurationFullMeasure
|
measureFumen['fumenOffsetStart'] = tjaOffset - measureDurationFullMeasure
|
||||||
else:
|
else:
|
||||||
# Start the measure using the end timing of the previous measure (plus any #DELAY commands)
|
# First, start the measure using the end timing of the previous measure (plus any #DELAY commands)
|
||||||
measureFumen['fumenOffsetStart'] = measureFumenPrev['fumenOffsetEnd'] + measureTJA['delay']
|
measureFumen['fumenOffsetStart'] = measureFumenPrev['fumenOffsetEnd'] + measureTJA['delay']
|
||||||
# Adjust the start of this measure to account for #BPMCHANGE commands (!!! Discovered by tana :3 !!!)
|
# Next, adjust the start timing to account for #BPMCHANGE commands (!!! Discovered by tana :3 !!!)
|
||||||
# To understand what's going on here, imagine the following simple example:
|
# To understand what's going on here, imagine the following simple example:
|
||||||
# * You have a very slow-moving note (i.e. low BPM), like the big DON in Donkama 2000.
|
# * You have a very slow-moving note (i.e. low BPM), like the big DON in Donkama 2000.
|
||||||
# * All the other notes move fast (i.e. high BPM), moving past the big slow note.
|
# * All the other notes move fast (i.e. high BPM), moving past the big slow note.
|
||||||
@ -190,17 +200,23 @@ def convertTJAToFumen(tja):
|
|||||||
|
|
||||||
# Check to see if the measure contains a branching condition
|
# Check to see if the measure contains a branching condition
|
||||||
if measureTJA['branchStart']:
|
if measureTJA['branchStart']:
|
||||||
|
# Determine which values to assign based on the type of branching condition
|
||||||
if measureTJA['branchStart'][0] == 'p':
|
if measureTJA['branchStart'][0] == 'p':
|
||||||
|
val1 = int(total_notes_branch * measureTJA['branchStart'][1] * 20)
|
||||||
|
val2 = int(total_notes_branch * measureTJA['branchStart'][2] * 20)
|
||||||
|
elif measureTJA['branchStart'][0] == 'r':
|
||||||
|
val1, val2 = measureTJA['branchStart'][1:]
|
||||||
|
# Determine which bytes to assign the values to
|
||||||
if currentBranch == 'normal':
|
if currentBranch == 'normal':
|
||||||
idx_b1, idx_b2 = 0, 1
|
idx_b1, idx_b2 = 0, 1
|
||||||
elif currentBranch == 'advanced':
|
elif currentBranch == 'advanced':
|
||||||
idx_b1, idx_b2 = 2, 3
|
idx_b1, idx_b2 = 2, 3
|
||||||
elif currentBranch == 'master':
|
elif currentBranch == 'master':
|
||||||
idx_b1, idx_b2 = 4, 5
|
idx_b1, idx_b2 = 4, 5
|
||||||
measureFumen['branchInfo'][idx_b1] = int(total_notes_branch * measureTJA['branchStart'][1] * 20)
|
# Assign the values to their intended bytes
|
||||||
measureFumen['branchInfo'][idx_b2] = int(total_notes_branch * measureTJA['branchStart'][2] * 20)
|
measureFumen['branchInfo'][idx_b1] = val1
|
||||||
elif measureTJA['branchStart'][0] == 'r':
|
measureFumen['branchInfo'][idx_b2] = val2
|
||||||
measureFumen['branchInfo'] = measureTJA['branchStart'][1:] * 3
|
# Reset the note counter corresponding to this branch
|
||||||
total_notes_branch = 0
|
total_notes_branch = 0
|
||||||
total_notes_branch += note_counter_branch
|
total_notes_branch += note_counter_branch
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user