1
0
mirror of synced 2025-01-24 23:13:40 +01:00

converters.py: Change func sig of process_commands

Now, instead of passing an entire TJACourse object, we pass the branch dict. This makes the function signature _much_ clearer, since it's easier to compare the before and after.
This commit is contained in:
Viv 2023-07-31 08:49:44 -04:00
parent 1358fbbca1
commit 098fb51a04

View File

@ -4,20 +4,19 @@ Functions for converting TJA song data to Fumen song data.
import re import re
from tja2fumen.classes import (TJACourse, TJAMeasureProcessed, from tja2fumen.classes import (TJACourse, TJAMeasure, TJAMeasureProcessed,
FumenCourse, FumenHeader, FumenMeasure, FumenCourse, FumenHeader, FumenMeasure,
FumenNote) FumenNote)
def process_tja_commands(tja: TJACourse) \ def process_commands(tja_branches: dict[str, list[TJAMeasure]], bpm: float) \
-> dict[str, list[TJAMeasureProcessed]]: -> dict[str, list[TJAMeasureProcessed]]:
""" """
Process each #COMMAND present in a TJASong's measures, and assign their Process all commands in each measure.
values as attributes to each measure.
This function takes care of two main tasks: This function takes care of two main tasks:
1. Keeping track of what the current values are for BPM, scroll, 1. Keeping track of what the current values are for BPM, scroll,
gogotime, barline, and time signature (#MEASURE). gogotime, barline, and time signature (i.e. #MEASURE).
2. Detecting when a command is placed in the middle of a measure, 2. Detecting when a command is placed in the middle of a measure,
and splitting that measure into sub-measures. and splitting that measure into sub-measures.
@ -29,10 +28,10 @@ def process_tja_commands(tja: TJACourse) \
measure will have attributes (e.g. measure.bpm, measure.scroll) instead. measure will have attributes (e.g. measure.bpm, measure.scroll) instead.
""" """
tja_branches_processed: dict[str, list[TJAMeasureProcessed]] = { tja_branches_processed: dict[str, list[TJAMeasureProcessed]] = {
branch_name: [] for branch_name in tja.branches.keys() branch_name: [] for branch_name in tja_branches.keys()
} }
for branch_name, branch_measures_tja in tja.branches.items(): for branch_name, branch_measures_tja in tja_branches.items():
current_bpm = tja.bpm current_bpm = bpm
current_scroll = 1.0 current_scroll = 1.0
current_gogo = False current_gogo = False
current_barline = True current_barline = True
@ -171,7 +170,7 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse:
being stored within the branch object.)) being stored within the branch object.))
""" """
# Preprocess commands # Preprocess commands
tja_branches_processed = process_tja_commands(tja) tja_branches_processed = process_commands(tja.branches, tja.bpm)
# Pre-allocate the measures for the converted TJA # Pre-allocate the measures for the converted TJA
n_measures = len(tja_branches_processed['normal']) n_measures = len(tja_branches_processed['normal'])