Skip to content

Commit

Permalink
svp: update notes validator
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulMelody committed Jan 17, 2025
1 parent 4d84ca5 commit 14867ce
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions libresvip/plugins/svp/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@ class SVGroup(BaseModel):
@field_validator("notes", mode="before")
@classmethod
def validate_notes(cls, v: list[dict[str, Any]], _info: ValidationInfo) -> list[dict[str, Any]]:
return [note for note in v if note["onset"] >= 0]
if _info.mode == "json":
return [note for note in v if note["onset"] >= 0]
return v

def overlapped_with(self, other: SVGroup) -> bool:
for note in self.notes:
Expand All @@ -564,18 +566,20 @@ def overlapped_with(self, other: SVGroup) -> bool:
return False

def __add__(self, blick_offset: int) -> SVGroup:
new_group = self.model_copy(deep=True)
new_group.notes = [
note + blick_offset for note in self.notes if note.onset + blick_offset >= 0
]
new_group.parameters += blick_offset
return new_group
return self.model_copy(
deep=True,
update={
"notes": [
note + blick_offset for note in self.notes if note.onset + blick_offset >= 0
],
"parameters": self.parameters + blick_offset,
},
)

def __xor__(self, pitch_offset: int) -> SVGroup:
new_group = self.model_copy(deep=True)
for note in new_group.notes:
note ^= pitch_offset
return new_group
return self.model_copy(
deep=True, update={"notes": [note ^ pitch_offset for note in self.notes]}
)


class SVMixer(BaseModel):
Expand Down

0 comments on commit 14867ce

Please sign in to comment.