mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2026-04-06 23:53:31 +00:00
make changes to sockets.
replace black+isort with ruff upd examples
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import time
|
||||
import threading
|
||||
from logging import config
|
||||
|
||||
import obsws_python as obsws
|
||||
@@ -7,85 +7,98 @@ import vban_cmd
|
||||
|
||||
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": {"vban_cmd.iremote": {"handlers": ["stream"], "level": "DEBUG"}},
|
||||
'loggers': {
|
||||
'vban_cmd.iremote': {
|
||||
'handlers': ['stream'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': False,
|
||||
}
|
||||
},
|
||||
'root': {'handlers': ['stream'], 'level': 'WARNING'},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class Observer:
|
||||
def __init__(self, vban):
|
||||
self.vban = vban
|
||||
self.client = obsws.EventClient()
|
||||
self.client.callback.register(
|
||||
def __init__(self, vban, stop_event):
|
||||
self._vban = vban
|
||||
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.vban.strip[0].mute = True
|
||||
self.vban.strip[1].B1 = True
|
||||
self.vban.strip[2].B2 = True
|
||||
self._vban.strip[0].mute = True
|
||||
self._vban.strip[1].B1 = True
|
||||
self._vban.strip[2].B2 = True
|
||||
|
||||
def on_brb(self):
|
||||
self.vban.strip[7].fadeto(0, 500)
|
||||
self.vban.bus[0].mute = True
|
||||
self._vban.strip[7].fadeto(0, 500)
|
||||
self._vban.bus[0].mute = True
|
||||
|
||||
def on_end(self):
|
||||
self.vban.apply(
|
||||
self._vban.apply(
|
||||
{
|
||||
"strip-0": {"mute": True},
|
||||
"strip-1": {"mute": True, "B1": False},
|
||||
"strip-2": {"mute": True, "B1": False},
|
||||
'strip-0': {'mute': True},
|
||||
'strip-1': {'mute': True, 'B1': False},
|
||||
'strip-2': {'mute': True, 'B1': False},
|
||||
}
|
||||
)
|
||||
|
||||
def on_live(self):
|
||||
self.vban.strip[0].mute = False
|
||||
self.vban.strip[7].fadeto(-6, 500)
|
||||
self.vban.strip[7].A3 = True
|
||||
self._vban.strip[0].mute = False
|
||||
self._vban.strip[7].fadeto(-6, 500)
|
||||
self._vban.strip[7].A3 = 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():
|
||||
with vban_cmd.api("potato") as vban:
|
||||
observer = Observer(vban)
|
||||
while observer.is_running:
|
||||
time.sleep(0.1)
|
||||
KIND_ID = 'potato'
|
||||
|
||||
with vban_cmd.api(KIND_ID) as vban:
|
||||
stop_event = threading.Event()
|
||||
|
||||
with Observer(vban, stop_event):
|
||||
stop_event.wait()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name="obs",
|
||||
description="OBS Example",
|
||||
install_requires=["obsws-python"],
|
||||
name='obs',
|
||||
description='OBS Example',
|
||||
install_requires=['obsws-python'],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user