Skip to content

Commit

Permalink
[WORKING] Play/Pause button
Browse files Browse the repository at this point in the history
  • Loading branch information
16pierre committed Apr 5, 2020
1 parent ece1377 commit 56069d7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
midi_binding
)

midi_play_pause_controller = MidiPlayPauseController(
timing,
generic_midi_input,
midi_binding
)

timing.start_ticking()

while(True):
Expand Down
8 changes: 5 additions & 3 deletions midi/midi_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class MidiBindings:

BUTTON_FORCE_ON = "FORCE_ON"
BUTTON_BPM = "BPM"
BUTTON_PLAY_PAUSE = "PLAY_PAUSE"


def __init__(self, notes_for_time, midi_port_name, generic_midi):
"""
Expand Down Expand Up @@ -34,12 +36,12 @@ def __init__(self, notes_for_time, midi_port_name, generic_midi):
[i + 32 for i in range(8)] +
[i + 24 for i in range(8)] +
[i + 16 for i in range(8)] +
[i + 8 for i in range(8)] +
[i + 0 for i in range(8)],
[i + 8 for i in range(8)],
"APC Key 25",
{
MidiBindings.BUTTON_FORCE_ON: 83, # SOLO button
MidiBindings.BUTTON_BPM: 71 # DEVICE button
MidiBindings.BUTTON_BPM: 71, # DEVICE button
MidiBindings.BUTTON_PLAY_PAUSE: 1
}

)
25 changes: 25 additions & 0 deletions midi/midi_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,28 @@ def notify(self, source, event_type, value = None):
self.generic_output.green(
self.bindings.generic_midi[MidiBindings.BUTTON_FORCE_ON],
blink=False)


class MidiPlayPauseController(Observer):
def __init__(self, timing, generic_listener, bindings):
super().__init__()
self.timing = timing
self.generic_output = MidiOutputGeneric(bindings)
self.bindings = bindings
generic_listener.register_observer(self, MidiGenericInputListener.EVENT_NOTE_ON)

self.generic_output.red(
bindings.generic_midi[MidiBindings.BUTTON_PLAY_PAUSE],
blink=True)

def notify(self, source, event_type, value = None):
if self.timing.is_paused():
self.timing.play()
self.generic_output.red(
self.bindings.generic_midi[MidiBindings.BUTTON_PLAY_PAUSE],
blink=True)
else:
self.timing.pause()
self.generic_output.red(
self.bindings.generic_midi[MidiBindings.BUTTON_PLAY_PAUSE],
blink=False)

0 comments on commit 56069d7

Please sign in to comment.