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

View File

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

View File

@ -3,20 +3,26 @@ import logging
import obsws_python as obs import obsws_python as obs
import voicemeeterlib import voicemeeterlib
logging.basicConfig(level=logging.INFO)
def on_start():
vm.strip[0].mute = True
vm.strip[1].B1 = True
vm.strip[2].B2 = True
def on_brb(): class Observer:
vm.strip[7].fadeto(0, 500) def __init__(self, vm):
vm.bus[0].mute = True 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_end(): def on_brb(self):
vm.apply( 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-0": {"mute": True},
"strip-1": {"mute": True, "B1": False}, "strip-1": {"mute": True, "B1": False},
@ -25,39 +31,36 @@ def on_end():
} }
) )
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_live(): def on_current_program_scene_changed(self, data):
vm.strip[0].mute = False def fget(scene):
vm.strip[7].fadeto(-6, 500) run = {
vm.strip[7].A3 = True "START": self.on_start,
vm.vban.instream[0].on = True "BRB": self.on_brb,
"END": self.on_end,
"LIVE": self.on_live,
}
return run.get(scene)
def on_current_program_scene_changed(data):
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":
on_start()
case "BRB":
on_brb()
case "END":
on_end()
case "LIVE":
on_live()
case _:
pass
if __name__ == "__main__": def main():
logging.basicConfig(level=logging.INFO)
subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]} subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]}
with voicemeeterlib.api("potato", subs=subs) as vm: with voicemeeterlib.api("potato", subs=subs) as vm:
cl = obs.EventClient() obs = Observer(vm)
cl.callback.register(on_current_program_scene_changed)
while cmd := input("<Enter> to exit\n"): while cmd := input("<Enter> to exit\n"):
if not cmd: if not cmd:
break break
if __name__ == "__main__":
main()

View File

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

View File

@ -25,3 +25,9 @@ isort = "^5.10.1"
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" 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"