From d85e0c81c61709ebbb395a8cea6889527ac845e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20Thom=C3=A9?= Date: Wed, 5 Oct 2016 01:37:22 +0200 Subject: [PATCH] Minor Python 3 compatibility fixes (#98) * Make sure range is actually a list * cmp_to_key py3 compatibility * Import functools with namespace visible --- pretty_midi/pretty_midi.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pretty_midi/pretty_midi.py b/pretty_midi/pretty_midi.py index 355ace5..6443af1 100644 --- a/pretty_midi/pretty_midi.py +++ b/pretty_midi/pretty_midi.py @@ -9,6 +9,7 @@ import warnings import collections import copy +import functools from .instrument import Instrument from .containers import (KeySignature, TimeSignature, Lyric, Note, @@ -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): @@ -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