mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2025-01-18 09:00:48 +00:00
update examples
This commit is contained in:
parent
cf7301712c
commit
7b725a51e3
@ -131,7 +131,8 @@ class Parser:
|
|||||||
case [
|
case [
|
||||||
[kls, index],
|
[kls, index],
|
||||||
[secondary, param],
|
[secondary, param],
|
||||||
[val] | val,
|
[val]
|
||||||
|
| val,
|
||||||
]:
|
]:
|
||||||
primary = getattr(self.vm, kls)[int(index)]
|
primary = getattr(self.vm, kls)[int(index)]
|
||||||
target = getattr(primary, secondary)
|
target = getattr(primary, secondary)
|
||||||
|
@ -41,7 +41,7 @@ def main():
|
|||||||
KIND_ID = "banana"
|
KIND_ID = "banana"
|
||||||
|
|
||||||
with voicemeeterlib.api(KIND_ID) as vm:
|
with voicemeeterlib.api(KIND_ID) as vm:
|
||||||
with App(vm) as app:
|
with App(vm):
|
||||||
for i in range(5, 0, -1):
|
for i in range(5, 0, -1):
|
||||||
print(f"events start in {i} seconds")
|
print(f"events start in {i} seconds")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import ttk
|
||||||
|
|
||||||
import voicemeeterlib
|
import voicemeeterlib
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
import tkinter as tk
|
|
||||||
from tkinter import ttk
|
|
||||||
|
|
||||||
|
|
||||||
class App(tk.Tk):
|
class App(tk.Tk):
|
||||||
|
@ -43,7 +43,7 @@ def main():
|
|||||||
with voicemeeterlib.api(KIND_ID, midi=True) as vm:
|
with voicemeeterlib.api(KIND_ID, midi=True) as vm:
|
||||||
App(vm)
|
App(vm)
|
||||||
|
|
||||||
while cmd := input("Press <Enter> to exit\n"):
|
while _ := input("Press <Enter> to exit\n"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import time
|
import threading
|
||||||
from logging import config
|
from logging import config
|
||||||
|
|
||||||
import obsws_python as obsws
|
import obsws_python as obsws
|
||||||
@ -7,37 +7,43 @@ import voicemeeterlib
|
|||||||
|
|
||||||
config.dictConfig(
|
config.dictConfig(
|
||||||
{
|
{
|
||||||
"version": 1,
|
'version': 1,
|
||||||
"formatters": {
|
'formatters': {
|
||||||
"standard": {
|
'standard': {
|
||||||
"format": "%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s"
|
'format': '%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"handlers": {
|
'handlers': {
|
||||||
"stream": {
|
'stream': {
|
||||||
"level": "DEBUG",
|
'level': 'DEBUG',
|
||||||
"class": "logging.StreamHandler",
|
'class': 'logging.StreamHandler',
|
||||||
"formatter": "standard",
|
'formatter': 'standard',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"loggers": {
|
'loggers': {
|
||||||
"voicemeeterlib.iremote": {"handlers": ["stream"], "level": "DEBUG"}
|
'voicemeeterlib.iremote': {'handlers': ['stream'], 'level': 'DEBUG'}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MyClient:
|
class MyClient:
|
||||||
def __init__(self, vm):
|
def __init__(self, vm, stop_event):
|
||||||
self.vm = vm
|
self.vm = vm
|
||||||
self.client = obsws.EventClient()
|
self._stop_event = stop_event
|
||||||
self.client.callback.register(
|
self._client = obsws.EventClient()
|
||||||
|
self._client.callback.register(
|
||||||
(
|
(
|
||||||
self.on_current_program_scene_changed,
|
self.on_current_program_scene_changed,
|
||||||
self.on_exit_started,
|
self.on_exit_started,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.is_running = True
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, exc_traceback):
|
||||||
|
self._client.disconnect()
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
self.vm.strip[0].mute = True
|
self.vm.strip[0].mute = True
|
||||||
@ -51,10 +57,10 @@ class MyClient:
|
|||||||
def on_end(self):
|
def on_end(self):
|
||||||
self.vm.apply(
|
self.vm.apply(
|
||||||
{
|
{
|
||||||
"strip-0": {"mute": True, "comp": {"ratio": 4.3}},
|
'strip-0': {'mute': True, 'comp': {'ratio': 4.3}},
|
||||||
"strip-1": {"mute": True, "B1": False, "gate": {"attack": 2.3}},
|
'strip-1': {'mute': True, 'B1': False, 'gate': {'attack': 2.3}},
|
||||||
"strip-2": {"mute": True, "B1": False},
|
'strip-2': {'mute': True, 'B1': False},
|
||||||
"vban-in-0": {"on": False},
|
'vban-in-0': {'on': False},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,33 +71,31 @@ class MyClient:
|
|||||||
self.vm.vban.instream[0].on = True
|
self.vm.vban.instream[0].on = True
|
||||||
|
|
||||||
def on_current_program_scene_changed(self, data):
|
def on_current_program_scene_changed(self, data):
|
||||||
def fget(scene):
|
|
||||||
run = {
|
|
||||||
"START": self.on_start,
|
|
||||||
"BRB": self.on_brb,
|
|
||||||
"END": self.on_end,
|
|
||||||
"LIVE": self.on_live,
|
|
||||||
}
|
|
||||||
return run.get(scene)
|
|
||||||
|
|
||||||
scene = data.scene_name
|
scene = data.scene_name
|
||||||
print(f"Switched to scene {scene}")
|
print(f'Switched to scene {scene}')
|
||||||
if fn := fget(scene):
|
match scene:
|
||||||
fn()
|
case 'START':
|
||||||
|
self.on_start()
|
||||||
|
case 'BRB':
|
||||||
|
self.on_brb()
|
||||||
|
case 'END':
|
||||||
|
self.on_end()
|
||||||
|
case 'LIVE':
|
||||||
|
self.on_live()
|
||||||
|
|
||||||
def on_exit_started(self, _):
|
def on_exit_started(self, _):
|
||||||
self.client.unsubscribe()
|
self._stop_event.set()
|
||||||
self.is_running = False
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
KIND_ID = "potato"
|
KIND_ID = 'potato'
|
||||||
|
|
||||||
with voicemeeterlib.api(KIND_ID) as vm:
|
with voicemeeterlib.api(KIND_ID) as vm:
|
||||||
client = MyClient(vm)
|
stop_event = threading.Event()
|
||||||
while client.is_running:
|
|
||||||
time.sleep(0.1)
|
with MyClient(vm, stop_event):
|
||||||
|
stop_event.wait()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -37,7 +37,7 @@ def main():
|
|||||||
) as vm:
|
) as vm:
|
||||||
App(vm)
|
App(vm)
|
||||||
|
|
||||||
while cmd := input("Press <Enter> to exit\n"):
|
while _ := input("Press <Enter> to exit\n"):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
def ex_dsl():
|
def ex_dsl():
|
||||||
scriptpath = Path.cwd() / "examples" / "dsl" / "."
|
subprocess.run(["tox", "r", "-e", "dsl"])
|
||||||
subprocess.run([sys.executable, str(scriptpath)])
|
|
||||||
|
|
||||||
|
|
||||||
def ex_events():
|
def ex_events():
|
||||||
@ -30,8 +29,7 @@ def ex_midi():
|
|||||||
|
|
||||||
|
|
||||||
def ex_obs():
|
def ex_obs():
|
||||||
scriptpath = Path.cwd() / "examples" / "obs" / "."
|
subprocess.run(["tox", "r", "-e", "obs"])
|
||||||
subprocess.run([sys.executable, str(scriptpath)])
|
|
||||||
|
|
||||||
|
|
||||||
def ex_observer():
|
def ex_observer():
|
||||||
|
Loading…
Reference in New Issue
Block a user