2022-09-29 10:01:18 +01:00
|
|
|
import logging
|
|
|
|
|
2022-07-24 14:38:16 +01:00
|
|
|
import voicemeeterlib
|
|
|
|
|
2023-06-23 17:50:16 +01:00
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
2022-10-28 02:14:08 +01:00
|
|
|
|
2022-07-24 14:38:16 +01:00
|
|
|
|
2023-06-23 17:50:16 +01:00
|
|
|
class App:
|
|
|
|
MIDI_BUTTON = 48 # leftmost M on korg nanokontrol2 in CC mode
|
2022-10-28 02:14:08 +01:00
|
|
|
MACROBUTTON = 0
|
2022-07-24 14:38:16 +01:00
|
|
|
|
2022-10-28 02:14:08 +01:00
|
|
|
def __init__(self, vm):
|
|
|
|
self.vm = vm
|
2023-06-23 17:50:16 +01:00
|
|
|
self.vm.observer.add(self.on_midi)
|
2022-07-24 14:38:16 +01:00
|
|
|
|
2023-06-23 17:50:16 +01:00
|
|
|
def on_midi(self):
|
2023-08-05 13:00:45 +01:00
|
|
|
if self.get_info() == self.MIDI_BUTTON:
|
|
|
|
self.on_midi_press()
|
2022-07-24 14:38:16 +01:00
|
|
|
|
|
|
|
def get_info(self):
|
|
|
|
current = self.vm.midi.current
|
|
|
|
print(f"Value of midi button {current} is {self.vm.midi.get(current)}")
|
2023-08-05 13:00:45 +01:00
|
|
|
return current
|
2022-07-24 14:38:16 +01:00
|
|
|
|
|
|
|
def on_midi_press(self):
|
2023-06-23 17:50:16 +01:00
|
|
|
"""if strip 3 level max > -40 and midi button 48 is pressed, then set trigger for macrobutton 0"""
|
2022-08-04 13:21:21 +01:00
|
|
|
|
2022-07-24 14:38:16 +01:00
|
|
|
if (
|
2023-08-05 13:00:45 +01:00
|
|
|
self.vm.midi.get(self.MIDI_BUTTON) == 127
|
|
|
|
and max(self.vm.strip[3].levels.postfader) > -40
|
2022-07-24 14:38:16 +01:00
|
|
|
):
|
|
|
|
print(
|
2023-06-23 17:50:16 +01:00
|
|
|
f"Strip 3 level max is greater than -40 and midi button {self.MIDI_BUTTON} is pressed"
|
2022-07-24 14:38:16 +01:00
|
|
|
)
|
2022-10-28 02:14:08 +01:00
|
|
|
self.vm.button[self.MACROBUTTON].trigger = True
|
2022-07-24 14:38:16 +01:00
|
|
|
else:
|
2022-10-28 02:14:08 +01:00
|
|
|
self.vm.button[self.MACROBUTTON].trigger = False
|
2022-07-24 14:38:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2023-06-23 17:50:16 +01:00
|
|
|
KIND_ID = "banana"
|
2022-10-28 02:14:08 +01:00
|
|
|
|
2023-06-23 17:50:16 +01:00
|
|
|
with voicemeeterlib.api(KIND_ID, midi=True) as vm:
|
|
|
|
App(vm)
|
2022-07-24 14:38:16 +01:00
|
|
|
|
|
|
|
while cmd := input("Press <Enter> to exit\n"):
|
2023-06-23 17:50:16 +01:00
|
|
|
pass
|
2022-07-24 14:38:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|