Skip to content

Commit

Permalink
acep: move normalization of time signatures to model validator
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulMelody committed Jan 5, 2025
1 parent 7684c80 commit 6346db5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
30 changes: 13 additions & 17 deletions libresvip/plugins/acep/ace_studio_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
AcepParams,
AcepProject,
AcepTempo,
AcepTimeSignature,
AcepTrack,
AcepVocalTrack,
)
Expand All @@ -52,23 +53,7 @@ class AceParser:
def parse_project(self, ace_project: AcepProject) -> Project:
project = Project()
self.content_version = ace_project.version
if ace_project.time_signatures:
project.time_signature_list = [
TimeSignature(
bar_index=ace_time_sig.bar_pos,
numerator=ace_time_sig.numerator,
denominator=ace_time_sig.denominator,
)
for ace_time_sig in ace_project.time_signatures
]
else:
project.time_signature_list.append(
TimeSignature(
bar_index=0,
numerator=ace_project.beats_per_bar,
denominator=4,
)
)
project.time_signature_list = self.parse_time_signatures(ace_project.time_signatures)
self.first_bar_ticks = int(project.time_signature_list[0].bar_length())
project.song_tempo_list = shift_tempo_list(
self.parse_tempos(ace_project.tempos),
Expand All @@ -82,6 +67,17 @@ def parse_project(self, ace_project: AcepProject) -> Project:
project.track_list.append(track)
return project

@staticmethod
def parse_time_signatures(ace_time_sigs: list[AcepTimeSignature]) -> list[TimeSignature]:
return [
TimeSignature(
bar_index=ace_time_sig.bar_pos,
numerator=ace_time_sig.numerator,
denominator=ace_time_sig.denominator,
)
for ace_time_sig in ace_time_sigs
]

@staticmethod
def parse_tempos(ace_tempos: list[AcepTempo]) -> list[SongTempo]:
return [
Expand Down
12 changes: 12 additions & 0 deletions libresvip/plugins/acep/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,15 @@ class AcepProject(BaseModel):
singer_library_id: Optional[str] = "1200593006"
time_signatures: list[AcepTimeSignature] = Field(default_factory=list, alias="timeSignatures")
track_control_panel_w: Optional[int] = Field(0, alias="trackControlPanelW")

@model_validator(mode="after")
def migrate_time_signatures(self) -> Self:
if not self.time_signatures:
self.time_signatures.append(
AcepTimeSignature(
bar_pos=0,
numerator=self.beats_per_bar,
denominator=4,
)
)
return self

0 comments on commit 6346db5

Please sign in to comment.