mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2026-04-07 16:03:30 +00:00
add support for midi devices.
midi example added. minor version bump
This commit is contained in:
24
examples/midi/README.md
Normal file
24
examples/midi/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
## About/Requirements
|
||||
|
||||
A simple demonstration showing how to use a midi controller with this API.
|
||||
|
||||
This script was written for and tested with a Korg NanoKontrol2 configured in CC mode.
|
||||
|
||||
In order to run this example script you will need to have setup Voicemeeter with a midi device in Menu->Midi Mapping.
|
||||
|
||||
## Use
|
||||
|
||||
The script launches Voicemeeter Banana version and assumes that is the version being tested (if it was already launched)
|
||||
|
||||
`get_info()` responds to any midi button press or midi slider movement and prints its' CC number and most recent value.
|
||||
|
||||
`on_midi_press()` should enable trigger mode for macrobutton 0 if peak level value for strip 3 exceeds -40 and midi button 48 is pressed. On the NanoKontrol2 midi button 48 corresponds to the leftmost M button. You may need to disable any Keyboard Shortcut assignment first.
|
||||
|
||||
For a clear illustration of what may be done fill in some commands in `Request for Button ON / Trigger IN` and `Request for Button OFF / Trigger OUT`.
|
||||
|
||||
## Resources
|
||||
|
||||
If you want to know how to setup the NanoKontrol2 for CC mode check the following resources.
|
||||
|
||||
- [Korg NanoKontrol2 Manual](https://www.korg.com/us/support/download/manual/0/159/1912/)
|
||||
- [CC Mode Info](https://i.korg.com/uploads/Support/nanoKONTROL2_PG_E1_634479709631760000.pdf)
|
||||
52
examples/midi/__main__.py
Normal file
52
examples/midi/__main__.py
Normal file
@@ -0,0 +1,52 @@
|
||||
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):
|
||||
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):
|
||||
if (
|
||||
max(self.vm.strip[3].levels.postfader) > -40
|
||||
and self.vm.midi.get(self.midi_btn) != 0
|
||||
):
|
||||
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():
|
||||
with voicemeeterlib.api(kind_id) as vm:
|
||||
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()
|
||||
@@ -19,6 +19,8 @@ class Observer:
|
||||
f"[{self.vm.bus[4]} {self.vm.bus[4].levels.isdirty}]",
|
||||
)
|
||||
print(" ".join(info))
|
||||
if subject == "midi":
|
||||
print(self.vm.midi.cache)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user