Skip to content

Commit

Permalink
Format code with black (bot)
Browse files Browse the repository at this point in the history
  • Loading branch information
neosatrapahereje committed Sep 21, 2023
1 parent 9f231e3 commit 4027a9a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
30 changes: 24 additions & 6 deletions partitura/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class PerformedNote(dict):
If not provided, the default values will be used.
Pitch, note_on, and note_off are required.
"""

def __init__(self, pnote_dict):
super().__init__(pnote_dict)
self["id"] = self.get("id", None)
Expand All @@ -308,7 +309,16 @@ def __init__(self, pnote_dict):
self["channel"] = self.get("channel", 1)
self["velocity"] = self.get("velocity", 60)
self._validate_values()
self._accepted_keys = ["id", "pitch", "note_on", "note_off", "velocity", "track", "channel", "sound_off"]
self._accepted_keys = [
"id",
"pitch",
"note_on",
"note_off",
"velocity",
"track",
"channel",
"sound_off",
]
self.__setitem__ = self._setitem_new

def __str__(self):
Expand All @@ -319,7 +329,9 @@ def __eq__(self, other):
return False
if not self.keys() == other.keys():
return False
return np.all(np.array([self[k] == other[k] for k in self.keys() if k in other.keys()]))
return np.all(
np.array([self[k] == other[k] for k in self.keys() if k in other.keys()])
)

def __hash__(self):
return hash(self["id"])
Expand All @@ -346,7 +358,9 @@ def _setitem_new(self, key, value):
# Verify that the note_off is after the note_on
if value < self["note_on"]:
raise ValueError(f"note_off must be after or equal to note_on")
self["sound_off"] = value if self["sound_off"] < value else self["sound_off"]
self["sound_off"] = (
value if self["sound_off"] < value else self["sound_off"]
)
self["note_off"] = value
elif key == "note_on":
# Verify that the note_on is before the note_off
Expand Down Expand Up @@ -379,10 +393,14 @@ def _validate_values(self):
if self["pitch"] > 127 or self["pitch"] < 0:
raise ValueError(f"pitch must be between 0 and 127")
if self["note_on"] < 0:
raise ValueError(f"Note on value provided is invalid, must be greater than or equal to 0")
raise ValueError(
f"Note on value provided is invalid, must be greater than or equal to 0"
)
if self["note_off"] < 0 or self["note_off"] < self["note_on"]:
raise ValueError(f"Note off value provided is invalid, "
f"must be greater than or equal to 0 and greater or equal to note_on")
raise ValueError(
f"Note off value provided is invalid, "
f"must be greater than or equal to 0 and greater or equal to note_on"
)
if self["velocity"] > 127 or self["velocity"] < 0:
raise ValueError(f"velocity must be between 0 and 127")

Expand Down
5 changes: 3 additions & 2 deletions partitura/utils/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -3283,7 +3283,6 @@ def slice_ppart_by_time(
new_pr["time_tick"] = int(2 * ppq * pr["time"])
programs_slice.append(new_pr)


notes_slice = []
note_id = 0
for note in ppart.notes:
Expand Down Expand Up @@ -3327,7 +3326,9 @@ def slice_ppart_by_time(
break

# Create slice PerformedPart
ppart_slice = PerformedPart(notes=notes_slice, programs=programs_slice, controls=controls_slice, ppq=ppq)
ppart_slice = PerformedPart(
notes=notes_slice, programs=programs_slice, controls=controls_slice, ppq=ppq
)

# set threshold property after creating notes list to update 'sound_offset' values
ppart_slice.sustain_pedal_threshold = ppart.sustain_pedal_threshold
Expand Down

0 comments on commit 4027a9a

Please sign in to comment.