voicemeeter-api-python/examples/callbacks/__main__.py

54 lines
1.2 KiB
Python
Raw Permalink Normal View History

2023-06-23 18:13:45 +01:00
import logging
import time
import voicemeeterlib
logging.basicConfig(level=logging.INFO)
class App:
def __init__(self, vm):
2025-01-16 14:51:20 +00:00
self._vm = vm
2023-06-23 18:13:45 +01:00
# register the callbacks for each event
2025-01-16 14:51:20 +00:00
self._vm.observer.add(
2023-06-23 18:13:45 +01:00
[self.on_pdirty, self.on_mdirty, self.on_ldirty, self.on_midi]
)
def __enter__(self):
2025-01-16 14:51:20 +00:00
self._vm.init_thread()
return self
2023-06-23 18:13:45 +01:00
def __exit__(self, exc_type, exc_value, traceback):
2025-01-16 14:51:20 +00:00
self._vm.end_thread()
2023-06-23 18:13:45 +01:00
def on_pdirty(self):
2025-01-15 12:40:31 +00:00
print('pdirty!')
2023-06-23 18:13:45 +01:00
def on_mdirty(self):
2025-01-15 12:40:31 +00:00
print('mdirty!')
2023-06-23 18:13:45 +01:00
def on_ldirty(self):
2025-01-16 14:51:20 +00:00
for bus in self._vm.bus:
2023-06-23 18:13:45 +01:00
if bus.levels.isdirty:
print(bus, bus.levels.all)
def on_midi(self):
2025-01-16 14:51:20 +00:00
current = self._vm.midi.current
print(f'Value of midi button {current} is {self._vm.midi.get(current)}')
2023-06-23 18:13:45 +01:00
def main():
2025-01-15 12:40:31 +00:00
KIND_ID = 'banana'
2023-06-23 18:13:45 +01:00
with voicemeeterlib.api(KIND_ID) as vm:
2025-01-15 12:34:31 +00:00
with App(vm):
2023-06-23 18:13:45 +01:00
for i in range(5, 0, -1):
2025-01-15 12:40:31 +00:00
print(f'events start in {i} seconds')
2023-06-23 18:13:45 +01:00
time.sleep(1)
2025-01-15 12:40:31 +00:00
vm.event.add(['pdirty', 'ldirty', 'midi', 'mdirty'])
2023-06-23 18:13:45 +01:00
time.sleep(30)
2025-01-15 12:40:31 +00:00
if __name__ == '__main__':
2023-06-23 18:13:45 +01:00
main()