From dda7b35eb028a848c38e12a8aec48e818d588a74 Mon Sep 17 00:00:00 2001 From: yardex Date: Mon, 27 Jul 2015 13:28:45 +0100 Subject: [PATCH] Added ability to set instrument_nr and set instrument name based on GM instr no. I didn't seem to be possible to set instrument_nr. It was hardcoded as 1 and setting it as per docs didn't work. Also the list of instrument names didn't seem to be utilized so I propose changing the constructor argument from name to instrument_nr and then the name is being auto-set based on id using the GM list. Not really sure how to handle out of range numbers here (are they allowed by midi standard ect) so just setting 'Unknown Instrument' as name --- mingus/containers/instrument.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mingus/containers/instrument.py b/mingus/containers/instrument.py index 482ba7ad..3e01da7a 100644 --- a/mingus/containers/instrument.py +++ b/mingus/containers/instrument.py @@ -251,8 +251,12 @@ class MidiInstrument(Instrument): 'Gunshot', ] - def __init__(self, name=''): - self.name = name + def __init__(self, instrument_nr=1): + self.instrument_nr = instrument_nr + try: + self.name = self.names[instrument_nr -1] + except IndexError: + self.name = 'Unknown Instrument' class MidiPercussionInstrument(Instrument): def __init__(self):