update examples

This commit is contained in:
Onyx and Iris 2025-01-15 12:34:31 +00:00
parent cf7301712c
commit 7b725a51e3
7 changed files with 52 additions and 49 deletions

View File

@ -131,7 +131,8 @@ class Parser:
case [
[kls, index],
[secondary, param],
[val] | val,
[val]
| val,
]:
primary = getattr(self.vm, kls)[int(index)]
target = getattr(primary, secondary)

View File

@ -41,7 +41,7 @@ def main():
KIND_ID = "banana"
with voicemeeterlib.api(KIND_ID) as vm:
with App(vm) as app:
with App(vm):
for i in range(5, 0, -1):
print(f"events start in {i} seconds")
time.sleep(1)

View File

@ -1,10 +1,10 @@
import logging
import tkinter as tk
from tkinter import ttk
import voicemeeterlib
logging.basicConfig(level=logging.DEBUG)
import tkinter as tk
from tkinter import ttk
class App(tk.Tk):

View File

@ -43,7 +43,7 @@ def main():
with voicemeeterlib.api(KIND_ID, midi=True) as vm:
App(vm)
while cmd := input("Press <Enter> to exit\n"):
while _ := input("Press <Enter> to exit\n"):
pass

View File

@ -1,4 +1,4 @@
import time
import threading
from logging import config
import obsws_python as obsws
@ -7,37 +7,43 @@ import voicemeeterlib
config.dictConfig(
{
"version": 1,
"formatters": {
"standard": {
"format": "%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s"
'version': 1,
'formatters': {
'standard': {
'format': '%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s'
}
},
"handlers": {
"stream": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "standard",
'handlers': {
'stream': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'standard',
}
},
"loggers": {
"voicemeeterlib.iremote": {"handlers": ["stream"], "level": "DEBUG"}
'loggers': {
'voicemeeterlib.iremote': {'handlers': ['stream'], 'level': 'DEBUG'}
},
}
)
class MyClient:
def __init__(self, vm):
def __init__(self, vm, stop_event):
self.vm = vm
self.client = obsws.EventClient()
self.client.callback.register(
self._stop_event = stop_event
self._client = obsws.EventClient()
self._client.callback.register(
(
self.on_current_program_scene_changed,
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):
self.vm.strip[0].mute = True
@ -51,10 +57,10 @@ class MyClient:
def on_end(self):
self.vm.apply(
{
"strip-0": {"mute": True, "comp": {"ratio": 4.3}},
"strip-1": {"mute": True, "B1": False, "gate": {"attack": 2.3}},
"strip-2": {"mute": True, "B1": False},
"vban-in-0": {"on": False},
'strip-0': {'mute': True, 'comp': {'ratio': 4.3}},
'strip-1': {'mute': True, 'B1': False, 'gate': {'attack': 2.3}},
'strip-2': {'mute': True, 'B1': False},
'vban-in-0': {'on': False},
}
)
@ -65,33 +71,31 @@ class MyClient:
self.vm.vban.instream[0].on = True
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
print(f"Switched to scene {scene}")
if fn := fget(scene):
fn()
print(f'Switched to scene {scene}')
match scene:
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, _):
self.client.unsubscribe()
self.is_running = False
self._stop_event.set()
def main():
KIND_ID = "potato"
KIND_ID = 'potato'
with voicemeeterlib.api(KIND_ID) as vm:
client = MyClient(vm)
while client.is_running:
time.sleep(0.1)
stop_event = threading.Event()
with MyClient(vm, stop_event):
stop_event.wait()
if __name__ == "__main__":
if __name__ == '__main__':
main()

View File

@ -37,7 +37,7 @@ def main():
) as vm:
App(vm)
while cmd := input("Press <Enter> to exit\n"):
while _ := input("Press <Enter> to exit\n"):
pass

View File

@ -5,8 +5,7 @@ from pathlib import Path
def ex_dsl():
scriptpath = Path.cwd() / "examples" / "dsl" / "."
subprocess.run([sys.executable, str(scriptpath)])
subprocess.run(["tox", "r", "-e", "dsl"])
def ex_events():
@ -30,8 +29,7 @@ def ex_midi():
def ex_obs():
scriptpath = Path.cwd() / "examples" / "obs" / "."
subprocess.run([sys.executable, str(scriptpath)])
subprocess.run(["tox", "r", "-e", "obs"])
def ex_observer():