From 483e6844bab52a9d7bf135beaf6167d256290386 Mon Sep 17 00:00:00 2001 From: yansnow78 Date: Wed, 23 Mar 2022 15:09:21 +0100 Subject: [PATCH 1/4] Update sequencer.py Fixed bug that caused all tracks to play to channel 1 --- mingus/midi/sequencer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mingus/midi/sequencer.py b/mingus/midi/sequencer.py index 7cb4e82..57e9007 100644 --- a/mingus/midi/sequencer.py +++ b/mingus/midi/sequencer.py @@ -139,9 +139,9 @@ def play_Note(self, note, channel=1, velocity=100): you can set the Note.velocity and Note.channel attributes, which will take presedence over the function arguments. """ - if hasattr(note, "velocity"): + if "velocity" in note.__dict__: velocity = note.velocity - if hasattr(note, "channel"): + if "channel" in note.__dict__: channel = note.channel self.play_event(int(note) + 12, int(channel), int(velocity)) self.notify_listeners( From d9feab6f8c9701f779d9184ad535eac86eee5e7c Mon Sep 17 00:00:00 2001 From: yansnow78 Date: Thu, 24 Mar 2022 11:58:20 +0100 Subject: [PATCH 2/4] Fix bug that caused all tracks to play with instrument 1 when track.instrument is not set Add possibilty to pass a string or a MidiInstrument to set_instrument --- mingus/midi/sequencer.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/mingus/midi/sequencer.py b/mingus/midi/sequencer.py index 57e9007..b840627 100644 --- a/mingus/midi/sequencer.py +++ b/mingus/midi/sequencer.py @@ -30,7 +30,7 @@ from mingus.containers.instrument import MidiInstrument from six.moves import range - +import six class Sequencer(object): @@ -110,10 +110,22 @@ def notify_listeners(self, msg_type, params): def set_instrument(self, channel, instr, bank=0): """Set the channel to the instrument _instr_.""" - self.instr_event(channel, instr, bank) + if isinstance(instr, MidiInstrument): + try: + instr_i = instr.names.index(instr.name) + except ValueError: + instr_i = 1 + elif isinstance(instr, six.string_types): + try: + instr_i = MidiInstrument.names.index(instr) + except ValueError: + instr_i = 1 + else: + instr_i = instr + self.instr_event(channel, instr_i, bank) self.notify_listeners( self.MSG_INSTR, - {"channel": int(channel), "instr": int(instr), "bank": int(bank)}, + {"channel": int(channel), "instr": int(instr_i), "bank": int(bank)}, ) def control_change(self, channel, control, value): @@ -306,6 +318,9 @@ def play_Bars(self, bars, channels, bpm=120): def play_Track(self, track, channel=1, bpm=120): """Play a Track object.""" self.notify_listeners(self.MSG_PLAY_TRACK, {"track": track, "channel": channel, "bpm": bpm}) + instr = track.instrument + if instr is not None: + self.set_instrument(channel, instr) for bar in track: res = self.play_Bar(bar, channel, bpm) if res != {}: @@ -327,15 +342,9 @@ def play_Tracks(self, tracks, channels, bpm=120): # Set the right instruments for x in range(len(tracks)): instr = tracks[x].instrument - if isinstance(instr, MidiInstrument): - try: - i = instr.names.index(instr.name) - except: - i = 1 - self.set_instrument(channels[x], i) - else: - self.set_instrument(channels[x], 1) - current_bar = 0 + if instr is not None: + self.set_instrument(channels[x], instr) + current_bar = 0 max_bar = len(tracks[0]) # Play the bars From 47f78512f8a3a6dcec560dce8c45f89cba6a7b36 Mon Sep 17 00:00:00 2001 From: yansnow78 Date: Thu, 7 Apr 2022 11:29:59 +0200 Subject: [PATCH 3/4] correct small mistake in previous commit --- mingus/midi/sequencer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mingus/midi/sequencer.py b/mingus/midi/sequencer.py index b840627..29da815 100644 --- a/mingus/midi/sequencer.py +++ b/mingus/midi/sequencer.py @@ -344,7 +344,7 @@ def play_Tracks(self, tracks, channels, bpm=120): instr = tracks[x].instrument if instr is not None: self.set_instrument(channels[x], instr) - current_bar = 0 + current_bar = 0 max_bar = len(tracks[0]) # Play the bars From 76e1b45e184937b82777706d397ce7cf4dc539b8 Mon Sep 17 00:00:00 2001 From: yansnow78 Date: Thu, 7 Apr 2022 11:39:32 +0200 Subject: [PATCH 4/4] Fix bugs in play_Note, stop_Note Fix bug that caused stop_Note to ignore channel parameter Fix bug that caused int note to not be accepted anymore in play_Note --- mingus/midi/sequencer.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mingus/midi/sequencer.py b/mingus/midi/sequencer.py index 29da815..3767381 100644 --- a/mingus/midi/sequencer.py +++ b/mingus/midi/sequencer.py @@ -151,10 +151,11 @@ def play_Note(self, note, channel=1, velocity=100): you can set the Note.velocity and Note.channel attributes, which will take presedence over the function arguments. """ - if "velocity" in note.__dict__: - velocity = note.velocity - if "channel" in note.__dict__: - channel = note.channel + if hasattr(note, '__dict__'): + if "velocity" in note.__dict__: + velocity = note.velocity + if "channel" in note.__dict__: + channel = note.channel self.play_event(int(note) + 12, int(channel), int(velocity)) self.notify_listeners( self.MSG_PLAY_INT, @@ -176,7 +177,7 @@ def stop_Note(self, note, channel=1): If Note.channel is set, it will take presedence over the channel argument given here. """ - if hasattr(note, "channel"): + if hasattr(note, '__dict__') and "channel" in note.__dict__: channel = note.channel self.stop_event(int(note) + 12, int(channel)) self.notify_listeners(self.MSG_STOP_INT, {"channel": int(channel), "note": int(note) + 12})