Last active
September 16, 2022 11:57
-
-
Save onyx-and-iris/c864f07126eeae389b011dc49520a19b to your computer and use it in GitHub Desktop.
sync voicemeeter states with streamlabs desktop scene switches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Creates some dummy test scenes and rotates through them. | |
For each scene switch some Voicemeeter parameters are changed. | |
Requires voicemeeter-api package at https://github.com/onyx-and-iris/voicemeeter-api-python | |
""" | |
import asyncio | |
import logging | |
import voicemeeterlib | |
from pyslobs import ScenesService, config_from_ini_else_stdin, connection | |
def on_start(): | |
vm.strip[0].mute = True | |
vm.strip[1].B1 = True | |
vm.strip[2].B2 = True | |
def on_brb(): | |
vm.strip[7].fadeto(0, 500) | |
vm.bus[0].mute = True | |
def on_end(): | |
vm.apply( | |
{ | |
"strip-0": {"mute": True}, | |
"strip-1": {"mute": True, "B1": False}, | |
"strip-2": {"mute": True, "B1": False}, | |
"vban-in-0": {"on": False}, | |
} | |
) | |
def on_live(): | |
vm.strip[0].mute = False | |
vm.strip[7].fadeto(-6, 500) | |
vm.strip[7].A3 = True | |
vm.vban.instream[0].on = True | |
async def subscribe(conn): | |
async def on_switch_scene(_k, message): | |
scene = message.get("name") | |
print(f"Switching to {scene}") | |
match scene: | |
case "START_TEST": | |
on_start() | |
case "BRB_TEST": | |
on_brb() | |
case "END_TEST": | |
on_end() | |
case "LIVE_TEST": | |
on_live() | |
case _: | |
pass | |
await ScenesService(conn).scene_switched.subscribe(on_switch_scene) | |
async def rotate(conn): | |
ss = ScenesService(conn) | |
tests = ["START_TEST", "BRB_TEST", "END_TEST", "LIVE_TEST"] | |
[await ss.create_scene(scene) for scene in tests] | |
scenes = await ss.get_scenes() | |
ids = {s.name: s.id for s in scenes} | |
for scene in scenes: | |
if scene.name in tests: | |
await ss.make_scene_active(ids.get(scene.name)) | |
await asyncio.sleep(1) | |
[await ss.remove_scene(ids.get(scene)) for scene in tests] | |
conn.close() | |
async def main(): | |
conn = connection.SlobsConnection(config_from_ini_else_stdin()) | |
await asyncio.gather(conn.background_processing(), rotate(conn), subscribe(conn)) | |
if __name__ == "__main__": | |
logging.basicConfig(level=logging.INFO) | |
with voicemeeterlib.api("potato") as vm: | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
voicemeeter-api: https://github.com/onyx-and-iris/voicemeeter-api-python
pyslobs: https://github.com/Julian-O/PySLOBS