Skip to content

Commit e36033e

Browse files
committed
Metronome: Allow configurable midi_channel
1 parent e79a99e commit e36033e

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

isobar/timelines/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
from .clock_link import AbletonLinkClock
77
from .midi_note import MidiNoteInstance
88

9-
__all__ = ["Timeline", "Track", "LFO", "Automation", "Clock", "DummyClock", "AbletonLinkClock", "MidiNoteInstance"]
9+
__all__ = ["Timeline", "Track", "LFO", "Automation", "Clock", "DummyClock", "AbletonLinkClock", "MidiNoteInstance", "Metronome", "MetronomeConfig"]

isobar/timelines/metronome.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class MetronomeConfig:
99
type: str = "midi"
1010

1111
midi_output_device: Any = None
12+
midi_channel: int = 0
1213
midi_note_major: int = 72
1314
midi_note_minor: int = 60
1415
midi_velocity_major: int = 64
@@ -45,9 +46,12 @@ def tick(self):
4546
velocity = self.config.midi_velocity_minor
4647

4748
if note is not None:
48-
self.output_device.note_on(note=note, velocity=velocity)
49+
self.output_device.note_on(note=note,
50+
velocity=velocity,
51+
channel=self.config.midi_channel)
4952
def note_off_callback():
50-
self.output_device.note_off(note=note)
53+
self.output_device.note_off(note=note,
54+
channel=self.config.midi_channel)
5155
self.timeline._schedule_action(note_off_callback, delay=self.config.midi_note_duration)
5256

5357
self.current_tick += 1

isobar/timelines/timeline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ def configure_metronome(self,
891891
interval: float = None,
892892
type: str = None,
893893
midi_output_device: Any = None,
894+
midi_channel: int = None,
894895
midi_note_major: int = None,
895896
midi_note_minor: int = None,
896897
midi_velocity_major: int = None,
@@ -906,6 +907,7 @@ def configure_metronome(self,
906907
type (str): specifies the type of metronome event to generate. Currently only "midi" is supported.
907908
midi_output_device (Any): specifies the MIDI output device to send metronome events to.
908909
If not specified, uses the timeline's default output device.
910+
midi_channel (int): specifies the MIDI channel to send metronome events on.
909911
midi_note_major (int): specifies the MIDI note number to use for the major beat.
910912
midi_note_minor (int): specifies the MIDI note number to use for the minor beat.
911913
midi_velocity_major (int): specifies the MIDI velocity to use for the major beat.
@@ -920,6 +922,8 @@ def configure_metronome(self,
920922
self.metronome_config.type = type
921923
if midi_output_device is not None:
922924
self.metronome_config.midi_output_device = midi_output_device
925+
if midi_channel is not None:
926+
self.metronome_config.midi_channel = midi_channel
923927
if midi_note_major is not None:
924928
self.metronome_config.midi_note_major = midi_note_major
925929
if midi_note_minor is not None:

0 commit comments

Comments
 (0)