Skip to content

Commit

Permalink
Minor Python 3 compatibility fixes (#98)
Browse files Browse the repository at this point in the history
* Make sure range is actually a list

* cmp_to_key py3 compatibility

* Import functools with namespace visible
  • Loading branch information
carlthome authored and craffel committed Oct 4, 2016
1 parent 22542e3 commit d85e0c8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pretty_midi/pretty_midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import warnings
import collections
import copy
import functools

from .instrument import Instrument
from .containers import (KeySignature, TimeSignature, Lyric, Note,
Expand Down Expand Up @@ -1271,7 +1272,7 @@ def event_compare(event1, event2):
mid.tracks.append(timing_track)
# Create a list of possible channels to assign - this seems to matter
# for some synths.
channels = range(16)
channels = list(range(16))
# Don't assign the drum channel by mistake!
channels.remove(9)
for n, instrument in enumerate(self.instruments):
Expand Down Expand Up @@ -1314,7 +1315,7 @@ def event_compare(event1, event2):
channel=channel, control=control_change.number,
value=control_change.value))
# Sort all the events using the event_compare comparator.
track = sorted(track, cmp=event_compare)
track = sorted(track, key=functools.cmp_to_key(event_compare))

# If there's a note off event and a note on event with the same
# tick and pitch, put the note off event first
Expand Down

0 comments on commit d85e0c8

Please sign in to comment.