mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2026-04-18 20:43:33 +00:00
move callbacks/observer examples into examples/events/
This commit is contained in:
53
examples/events/callbacks/__main__.py
Normal file
53
examples/events/callbacks/__main__.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
import voicemeeterlib
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
class App:
|
||||
def __init__(self, vm):
|
||||
self._vm = vm
|
||||
# register the callbacks for each event
|
||||
self._vm.observer.add(
|
||||
[self.on_pdirty, self.on_mdirty, self.on_ldirty, self.on_midi]
|
||||
)
|
||||
|
||||
def __enter__(self):
|
||||
self._vm.init_thread()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self._vm.end_thread()
|
||||
|
||||
def on_pdirty(self):
|
||||
print('pdirty!')
|
||||
|
||||
def on_mdirty(self):
|
||||
print('mdirty!')
|
||||
|
||||
def on_ldirty(self):
|
||||
for bus in self._vm.bus:
|
||||
if bus.levels.isdirty:
|
||||
print(bus, bus.levels.all)
|
||||
|
||||
def on_midi(self):
|
||||
current = self._vm.midi.current
|
||||
print(f'Value of midi button {current} is {self._vm.midi.get(current)}')
|
||||
|
||||
|
||||
def main():
|
||||
KIND_ID = 'banana'
|
||||
|
||||
with voicemeeterlib.api(KIND_ID) as vm:
|
||||
with App(vm):
|
||||
for i in range(5, 0, -1):
|
||||
print(f'events start in {i} seconds')
|
||||
time.sleep(1)
|
||||
vm.event.add(['pdirty', 'ldirty', 'midi', 'mdirty'])
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user