examples refactored

poetry scripts added
This commit is contained in:
onyx-and-iris 2022-10-28 02:14:08 +01:00
parent 6fa6d70f9b
commit a4cc7058b6
5 changed files with 113 additions and 107 deletions

View File

@ -1,3 +1,4 @@
import argparse
import logging
import time
@ -14,6 +15,11 @@ from pyparsing import (
nums,
)
logging.basicConfig(level=logging.INFO)
argparser = argparse.ArgumentParser(description="creates a basic dsl")
argparser.add_argument("-i", action="store_true")
args = argparser.parse_args()
class Parser:
def __init__(self, vm):
@ -54,48 +60,41 @@ class Parser:
return res
def main(cmds=None):
def interactive_mode(parser):
while cmd := input("Please enter command (Press <Enter> to exit)\n"):
if not cmd:
break
res = parser.parse((cmd,))
if res:
print(res)
def main():
# fmt: off
cmds = (
"strip 0 -> mute -> on", "strip 0 -> mute", "bus 0 -> mute -> on",
"strip 0 -> mute -> off", "bus 0 -> mute -> on", "strip 3 -> solo -> on",
"strip 3 -> solo -> off", "strip 1 -> A1 -> on", "strip 1 -> A1",
"strip 1 -> A1 -> off", "strip 1 -> A1", "bus 3 -> eq -> on",
"bus 3 -> eq -> off", "strip 4 -> gain -> 1.2", "strip 0 -> gain -> -8.2",
"strip 0 -> gain", "strip 1 -> label -> rode podmic", "strip 2 -> limit -> -28",
"strip 2 -> limit",
)
# fmt: on
kind_id = "banana"
subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]}
with voicemeeterlib.api(kind_id, subs=subs) as vm:
parser = Parser(vm)
if cmds:
res = parser.parse(cmds)
if res:
print(res)
else:
while cmd := input("Please enter command (Press <Enter> to exit)\n"):
if not cmd:
break
res = parser.parse((cmd,))
if res:
print(res)
if args.i:
interactive_mode(parser)
return
res = parser.parse(cmds)
if res:
print(res)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
cmds = (
"strip 0 -> mute -> on",
"strip 0 -> mute",
"bus 0 -> mute -> on",
"strip 0 -> mute -> off",
"bus 0 -> mute -> on",
"strip 3 -> solo -> on",
"strip 3 -> solo -> off",
"strip 1 -> A1 -> on",
"strip 1 -> A1",
"strip 1 -> A1 -> off",
"strip 1 -> A1",
"bus 3 -> eq -> on",
"bus 3 -> eq -> off",
"strip 4 -> gain -> 1.2",
"strip 0 -> gain -> -8.2",
"strip 0 -> gain",
"strip 1 -> label -> rode podmic",
"strip 2 -> limit -> -28",
"strip 2 -> limit",
)
# pass cmds to parse cmds, otherwise simply run main() to test stdin parsing
main(cmds)
main()

View File

@ -2,14 +2,16 @@ import logging
import voicemeeterlib
logging.basicConfig(level=logging.INFO)
class Observer:
def __init__(self, vm, midi_btn, macrobutton):
self.vm = vm
self.midi_btn = midi_btn
self.macrobutton = macrobutton
# leftmost M on korg nanokontrol2 in CC mode
MIDI_BUTTON = 48
MACROBUTTON = 0
def register(self):
def __init__(self, vm):
self.vm = vm
self.vm.subject.add(self)
def on_update(self, subject):
@ -34,23 +36,24 @@ class Observer:
"""
if (
max(self.vm.strip[3].levels.postfader) > -40
and self.vm.midi.get(self.midi_btn) == 127
and self.vm.midi.get(self.MIDI_BUTTON) == 127
):
print(
f"Strip 3 level is greater than -40 and midi button {self.midi_btn} is pressed"
f"Strip 3 level is greater than -40 and midi button {self.MIDI_BUTTON} is pressed"
)
self.vm.button[self.macrobutton].trigger = True
self.vm.button[self.MACROBUTTON].trigger = True
else:
self.vm.button[self.macrobutton].trigger = False
self.vm.button[self.macrobutton].state = False
self.vm.button[self.MACROBUTTON].trigger = False
self.vm.button[self.MACROBUTTON].state = False
def main():
kind_id = "banana"
# we only care about midi events here.
subs = {ev: False for ev in ["pdirty", "mdirty"]}
with voicemeeterlib.api(kind_id, subs=subs) as vm:
obs = Observer(vm, midi_btn, macrobutton)
obs.register()
obs = Observer(vm)
while cmd := input("Press <Enter> to exit\n"):
if not cmd:
@ -58,10 +61,4 @@ def main():
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
kind_id = "banana"
# leftmost M on korg nanokontrol2 in CC mode
midi_btn = 48
macrobutton = 0
main()

View File

@ -3,61 +3,64 @@ import logging
import obsws_python as obs
import voicemeeterlib
def on_start():
vm.strip[0].mute = True
vm.strip[1].B1 = True
vm.strip[2].B2 = True
logging.basicConfig(level=logging.INFO)
def on_brb():
vm.strip[7].fadeto(0, 500)
vm.bus[0].mute = True
class Observer:
def __init__(self, vm):
self.vm = vm
self.client = obs.EventClient()
self.client.callback.register(self.on_current_program_scene_changed)
def on_start(self):
self.vm.strip[0].mute = True
self.vm.strip[1].B1 = True
self.vm.strip[2].B2 = True
def on_brb(self):
self.vm.strip[7].fadeto(0, 500)
self.vm.bus[0].mute = True
def on_end(self):
self.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(self):
self.vm.strip[0].mute = False
self.vm.strip[7].fadeto(-6, 500)
self.vm.strip[7].A3 = True
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()
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
def on_current_program_scene_changed(data):
scene = data.scene_name
print(f"Switched to scene {scene}")
match scene:
case "START":
on_start()
case "BRB":
on_brb()
case "END":
on_end()
case "LIVE":
on_live()
case _:
pass
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
def main():
subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]}
with voicemeeterlib.api("potato", subs=subs) as vm:
cl = obs.EventClient()
cl.callback.register(on_current_program_scene_changed)
obs = Observer(vm)
while cmd := input("<Enter> to exit\n"):
if not cmd:
break
if __name__ == "__main__":
main()

View File

@ -2,6 +2,8 @@ import logging
import voicemeeterlib
logging.basicConfig(level=logging.INFO)
class Observer:
def __init__(self, vm):
@ -27,6 +29,8 @@ class Observer:
def main():
kind_id = "banana"
with voicemeeterlib.api(kind_id) as vm:
Observer(vm)
@ -36,7 +40,4 @@ def main():
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
kind_id = "banana"
main()

View File

@ -25,3 +25,9 @@ isort = "^5.10.1"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
dsl = "examples.dsl.__main__:main"
midi = "examples.midi.__main__:main"
obs = "examples.obs.__main__:main"
observer = "examples.observer.__main__:main"