Skip to content

Commit

Permalink
Cache pedal resolve (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
loubbrad authored Mar 13, 2024
1 parent 791b2f0 commit db53a36
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions aria/data/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def __init__(
self.ticks_per_beat = ticks_per_beat
self.metadata = metadata

self.pedal_resolved = False # Default value

# Special case that temo_msg is empty, in this case we spoof the default
if not self.tempo_msgs:
self.tempo_msgs = [
Expand Down Expand Up @@ -248,6 +250,12 @@ def _resolve_overlaps(self):

def resolve_pedal(self):
"""Resolve pedal - extend note offsets and resolve note overlaps"""
# If has been already resolved, we don't recalculate
if self.pedal_resolved == True:
return self

assert self.pedal_resolved == False, "Internal error"

# Organize note messages by channel
note_msgs_c = defaultdict(list)
for msg in self.note_msgs:
Expand All @@ -265,6 +273,8 @@ def resolve_pedal(self):
msg["data"]["end"] = pedal_end
break

self.pedal_resolved = True

return self._resolve_overlaps()

# TODO:
Expand Down

0 comments on commit db53a36

Please sign in to comment.