2022-07-24 14:38:16 +01:00
|
|
|
import voicemeeterlib
|
|
|
|
|
|
|
|
|
|
|
|
class Observer:
|
|
|
|
def __init__(self, vm, midi_btn, macrobutton):
|
|
|
|
self.vm = vm
|
|
|
|
self.midi_btn = midi_btn
|
|
|
|
self.macrobutton = macrobutton
|
|
|
|
|
|
|
|
def register(self):
|
|
|
|
self.vm.subject.add(self)
|
|
|
|
|
|
|
|
def on_update(self, subject):
|
2022-08-04 13:21:21 +01:00
|
|
|
"""
|
|
|
|
We expect to only receive midi updates.
|
|
|
|
|
|
|
|
We could skip subject check but check anyway, in case an event is added later.
|
|
|
|
"""
|
2022-07-24 14:38:16 +01:00
|
|
|
if subject == "midi":
|
|
|
|
self.get_info()
|
|
|
|
self.on_midi_press()
|
|
|
|
|
|
|
|
def get_info(self):
|
|
|
|
current = self.vm.midi.current
|
|
|
|
print(f"Value of midi button {current} is {self.vm.midi.get(current)}")
|
|
|
|
|
|
|
|
def on_midi_press(self):
|
2022-08-04 13:21:21 +01:00
|
|
|
"""
|
2022-08-04 13:22:44 +01:00
|
|
|
checks if strip 3 level postfader mode is greater than -40
|
2022-08-04 13:21:21 +01:00
|
|
|
|
2022-08-04 13:23:38 +01:00
|
|
|
checks if midi button 48 velocity is 127 (full velocity for button press).
|
2022-08-04 13:21:21 +01:00
|
|
|
"""
|
2022-07-24 14:38:16 +01:00
|
|
|
if (
|
|
|
|
max(self.vm.strip[3].levels.postfader) > -40
|
2022-08-04 13:21:21 +01:00
|
|
|
and self.vm.midi.get(self.midi_btn) == 127
|
2022-07-24 14:38:16 +01:00
|
|
|
):
|
|
|
|
print(
|
|
|
|
f"Strip 3 level is greater than -40 and midi button {self.midi_btn} is pressed"
|
|
|
|
)
|
|
|
|
self.vm.button[self.macrobutton].trigger = True
|
|
|
|
else:
|
|
|
|
self.vm.button[self.macrobutton].trigger = False
|
|
|
|
self.vm.button[self.macrobutton].state = False
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2022-08-04 13:21:21 +01:00
|
|
|
# we only care about midi events here.
|
|
|
|
subs = {ev: False for ev in ["pdirty", "mdirty", "ldirty"]}
|
|
|
|
with voicemeeterlib.api(kind_id, subs=subs) as vm:
|
2022-07-24 14:38:16 +01:00
|
|
|
obs = Observer(vm, midi_btn, macrobutton)
|
|
|
|
obs.register()
|
|
|
|
|
|
|
|
while cmd := input("Press <Enter> to exit\n"):
|
|
|
|
if not cmd:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
kind_id = "banana"
|
|
|
|
# leftmost M on korg nanokontrol2 in CC mode
|
|
|
|
midi_btn = 48
|
|
|
|
macrobutton = 0
|
|
|
|
|
|
|
|
main()
|