mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2024-11-22 02:50:47 +00:00
midi example now registers callback on_midi
This commit is contained in:
parent
b81c4c4b97
commit
9ef89852de
@ -2,25 +2,18 @@ import logging
|
|||||||
|
|
||||||
import voicemeeterlib
|
import voicemeeterlib
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
class Observer:
|
class App:
|
||||||
# leftmost M on korg nanokontrol2 in CC mode
|
MIDI_BUTTON = 48 # leftmost M on korg nanokontrol2 in CC mode
|
||||||
MIDI_BUTTON = 48
|
|
||||||
MACROBUTTON = 0
|
MACROBUTTON = 0
|
||||||
|
|
||||||
def __init__(self, vm):
|
def __init__(self, vm):
|
||||||
self.vm = vm
|
self.vm = vm
|
||||||
self.vm.subject.add(self)
|
self.vm.observer.add(self.on_midi)
|
||||||
|
|
||||||
def on_update(self, subject):
|
def on_midi(self):
|
||||||
"""
|
|
||||||
We expect to only receive midi updates.
|
|
||||||
|
|
||||||
We could skip subject check but check anyway, in case an event is added later.
|
|
||||||
"""
|
|
||||||
if subject == "midi":
|
|
||||||
self.get_info()
|
self.get_info()
|
||||||
self.on_midi_press()
|
self.on_midi_press()
|
||||||
|
|
||||||
@ -29,35 +22,28 @@ class Observer:
|
|||||||
print(f"Value of midi button {current} is {self.vm.midi.get(current)}")
|
print(f"Value of midi button {current} is {self.vm.midi.get(current)}")
|
||||||
|
|
||||||
def on_midi_press(self):
|
def on_midi_press(self):
|
||||||
"""
|
"""if strip 3 level max > -40 and midi button 48 is pressed, then set trigger for macrobutton 0"""
|
||||||
checks if strip 3 level postfader mode is greater than -40
|
|
||||||
|
|
||||||
checks if midi button 48 velocity is 127 (full velocity for button press).
|
|
||||||
"""
|
|
||||||
if (
|
if (
|
||||||
max(self.vm.strip[3].levels.postfader) > -40
|
max(self.vm.strip[3].levels.postfader) > -40
|
||||||
and self.vm.midi.get(self.MIDI_BUTTON) == 127
|
and self.vm.midi.get(self.MIDI_BUTTON) == 127
|
||||||
):
|
):
|
||||||
print(
|
print(
|
||||||
f"Strip 3 level is greater than -40 and midi button {self.MIDI_BUTTON} is pressed"
|
f"Strip 3 level max is greater than -40 and midi button {self.MIDI_BUTTON} is pressed"
|
||||||
)
|
)
|
||||||
self.vm.button[self.MACROBUTTON].trigger = True
|
self.vm.button[self.MACROBUTTON].trigger = True
|
||||||
else:
|
else:
|
||||||
self.vm.button[self.MACROBUTTON].trigger = False
|
self.vm.button[self.MACROBUTTON].trigger = False
|
||||||
self.vm.button[self.MACROBUTTON].state = False
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
kind_id = "banana"
|
KIND_ID = "banana"
|
||||||
|
|
||||||
# we only care about midi events here.
|
with voicemeeterlib.api(KIND_ID, midi=True) as vm:
|
||||||
subs = {ev: False for ev in ["pdirty", "mdirty"]}
|
App(vm)
|
||||||
with voicemeeterlib.api(kind_id, subs=subs) as vm:
|
|
||||||
obs = Observer(vm)
|
|
||||||
|
|
||||||
while cmd := input("Press <Enter> to exit\n"):
|
while cmd := input("Press <Enter> to exit\n"):
|
||||||
if not cmd:
|
pass
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user