Skip to content

Commit

Permalink
Fix name error + added try except clause for __add__
Browse files Browse the repository at this point in the history
fixes #6
  • Loading branch information
jamesa08 committed Aug 26, 2022
1 parent 1381c40 commit 6a05651
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions MIDIAnimator/data_structures/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MIDIEvent:
time: float

def __lt__(self, other):
return self.timeOn < other.timeOn
return self.time < other.time

class MIDITrack:
name: str
Expand Down Expand Up @@ -187,19 +187,21 @@ def __str__(self) -> str:

def __add__(self, other) -> MIDITrack:
print(f"INFO: Attempting to merge tracks '{self.name}' & '{other.name}' ...")
addedTrack = MIDITrack(f"{self.name} & {other.name}")

addedTrack.notes = sorted(self.notes + other.notes)

controlChangeCloned = self.controlChange.copy()
controlChangeCloned.update(other.controlChange)

addedTrack.controlChange = controlChangeCloned

addedTrack.pitchweel = sorted(self.pitchwheel + other.pitchwheel)
addedTrack.aftertouch = sorted(self.aftertouch + other.aftertouch)

return addedTrack
try:
addedTrack = MIDITrack(f"{self.name} & {other.name}")

addedTrack.notes = sorted(self.notes + other.notes)

controlChangeCloned = self.controlChange.copy()
controlChangeCloned.update(other.controlChange)

addedTrack.controlChange = controlChangeCloned

addedTrack.pitchweel = sorted(self.pitchwheel + other.pitchwheel)
addedTrack.aftertouch = sorted(self.aftertouch + other.aftertouch)
return addedTrack
except Exception as e:
raise RuntimeError(f"Failed to merge tracks '{self.name}' & '{other.name}'! \nException: {e}")

def __repr__(self) -> str:
type_ = type(self)
Expand Down

0 comments on commit 6a05651

Please sign in to comment.