From 38bd284ba6e51aa4e6eabd2d1bacefeb33de9ed2 Mon Sep 17 00:00:00 2001 From: Onyx and Iris Date: Thu, 16 Jan 2025 14:51:20 +0000 Subject: [PATCH] upd examples --- examples/{events => callbacks}/README.md | 0 examples/{events => callbacks}/__main__.py | 14 +++++----- examples/gui/__main__.py | 14 +++++----- examples/midi/__main__.py | 16 ++++++------ examples/obs/__main__.py | 29 ++++++++++++--------- examples/observer/__main__.py | 30 +++++++++++----------- pyproject.toml | 2 +- scripts.py | 28 ++++++++++---------- 8 files changed, 69 insertions(+), 64 deletions(-) rename examples/{events => callbacks}/README.md (100%) rename examples/{events => callbacks}/__main__.py (78%) diff --git a/examples/events/README.md b/examples/callbacks/README.md similarity index 100% rename from examples/events/README.md rename to examples/callbacks/README.md diff --git a/examples/events/__main__.py b/examples/callbacks/__main__.py similarity index 78% rename from examples/events/__main__.py rename to examples/callbacks/__main__.py index fa6ea4c..3413b58 100644 --- a/examples/events/__main__.py +++ b/examples/callbacks/__main__.py @@ -8,18 +8,18 @@ logging.basicConfig(level=logging.INFO) class App: def __init__(self, vm): - self.vm = vm + self._vm = vm # register the callbacks for each event - self.vm.observer.add( + self._vm.observer.add( [self.on_pdirty, self.on_mdirty, self.on_ldirty, self.on_midi] ) def __enter__(self): - self.vm.init_thread() + self._vm.init_thread() return self def __exit__(self, exc_type, exc_value, traceback): - self.vm.end_thread() + self._vm.end_thread() def on_pdirty(self): print('pdirty!') @@ -28,13 +28,13 @@ class App: print('mdirty!') def on_ldirty(self): - for bus in self.vm.bus: + for bus in self._vm.bus: if bus.levels.isdirty: print(bus, bus.levels.all) def on_midi(self): - current = self.vm.midi.current - print(f'Value of midi button {current} is {self.vm.midi.get(current)}') + current = self._vm.midi.current + print(f'Value of midi button {current} is {self._vm.midi.get(current)}') def main(): diff --git a/examples/gui/__main__.py b/examples/gui/__main__.py index 5ae56dc..c9dd23a 100644 --- a/examples/gui/__main__.py +++ b/examples/gui/__main__.py @@ -12,9 +12,9 @@ class App(tk.Tk): def __init__(self, vm): super().__init__() - self.vm = vm + self._vm = vm self.title(f'{vm} - version {vm.version}') - self.vm.observer.add(self.on_ldirty) + self._vm.observer.add(self.on_ldirty) # create widget variables self.button_var = tk.BooleanVar(value=vm.strip[self.INDEX].mute) @@ -31,7 +31,7 @@ class App(tk.Tk): ) # create labelframe and grid it onto the mainframe - self.labelframe = tk.LabelFrame(self, text=self.vm.strip[self.INDEX].label) + self.labelframe = tk.LabelFrame(self, text=self._vm.strip[self.INDEX].label) self.labelframe.grid(padx=1) # create slider and grid it onto the labelframe @@ -76,12 +76,12 @@ class App(tk.Tk): def on_slider_move(self, *args): val = round(self.slider_var.get(), 1) - self.vm.strip[self.INDEX].gain = val + self._vm.strip[self.INDEX].gain = val self.gainlabel_var.set(val) def on_button_press(self): self.button_var.set(not self.button_var.get()) - self.vm.strip[self.INDEX].mute = self.button_var.get() + self._vm.strip[self.INDEX].mute = self.button_var.get() self.style.configure( 'Mute.TButton', foreground='#cd5c5c' if self.button_var.get() else '#5a5a5a' ) @@ -89,10 +89,10 @@ class App(tk.Tk): def on_button_double_click(self, e): self.slider_var.set(0) self.gainlabel_var.set(0) - self.vm.strip[self.INDEX].gain = 0 + self._vm.strip[self.INDEX].gain = 0 def _get_level(self): - val = max(self.vm.strip[self.INDEX].levels.postfader) + val = max(self._vm.strip[self.INDEX].levels.postfader) return 0 if self.button_var.get() else 72 + val - 12 def on_ldirty(self): diff --git a/examples/midi/__main__.py b/examples/midi/__main__.py index 423da40..29bf80a 100644 --- a/examples/midi/__main__.py +++ b/examples/midi/__main__.py @@ -10,31 +10,31 @@ class App: MACROBUTTON = 0 def __init__(self, vm): - self.vm = vm - self.vm.observer.add(self.on_midi) + self._vm = vm + self._vm.observer.add(self.on_midi) def on_midi(self): if self.get_info() == self.MIDI_BUTTON: self.on_midi_press() def get_info(self): - current = self.vm.midi.current - print(f'Value of midi button {current} is {self.vm.midi.get(current)}') + current = self._vm.midi.current + print(f'Value of midi button {current} is {self._vm.midi.get(current)}') return current def on_midi_press(self): """if midi button 48 is pressed and strip 3 level max > -40, then set trigger for macrobutton 0""" if ( - self.vm.midi.get(self.MIDI_BUTTON) == 127 - and max(self.vm.strip[3].levels.postfader) > -40 + self._vm.midi.get(self.MIDI_BUTTON) == 127 + and max(self._vm.strip[3].levels.postfader) > -40 ): print( f'Strip 3 level max 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].trigger = False def main(): diff --git a/examples/obs/__main__.py b/examples/obs/__main__.py index c4a84f6..ee3b889 100644 --- a/examples/obs/__main__.py +++ b/examples/obs/__main__.py @@ -21,15 +21,20 @@ config.dictConfig( } }, 'loggers': { - 'voicemeeterlib.iremote': {'handlers': ['stream'], 'level': 'DEBUG'} + 'voicemeeterlib.iremote': { + 'handlers': ['stream'], + 'level': 'DEBUG', + 'propagate': False, + } }, + 'root': {'handlers': ['stream'], 'level': 'WARNING'}, } ) class MyClient: def __init__(self, vm, stop_event): - self.vm = vm + self._vm = vm self._stop_event = stop_event self._client = obsws.EventClient() self._client.callback.register( @@ -46,16 +51,16 @@ class MyClient: self._client.disconnect() def on_start(self): - self.vm.strip[0].mute = True - self.vm.strip[1].B1 = True - self.vm.strip[2].B2 = True + 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 + self._vm.strip[7].fadeto(0, 500) + self._vm.bus[0].mute = True def on_end(self): - self.vm.apply( + self._vm.apply( { 'strip-0': {'mute': True, 'comp': {'ratio': 4.3}}, 'strip-1': {'mute': True, 'B1': False, 'gate': {'attack': 2.3}}, @@ -65,10 +70,10 @@ class MyClient: ) 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 + 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): scene = data.scene_name diff --git a/examples/observer/__main__.py b/examples/observer/__main__.py index f8e8584..075def7 100644 --- a/examples/observer/__main__.py +++ b/examples/observer/__main__.py @@ -7,39 +7,39 @@ logging.basicConfig(level=logging.INFO) class App: def __init__(self, vm): - self.vm = vm + self._vm = vm # register your app as event observer - self.vm.observer.add(self) + self._vm.observer.add(self) def __str__(self): return type(self).__name__ # define an 'on_update' callback function to receive event updates def on_update(self, event): - if event == "pdirty": - print("pdirty!") - elif event == "mdirty": - print("mdirty!") - elif event == "ldirty": - for bus in self.vm.bus: + if event == 'pdirty': + print('pdirty!') + elif event == 'mdirty': + print('mdirty!') + elif event == 'ldirty': + for bus in self._vm.bus: if bus.levels.isdirty: print(bus, bus.levels.all) - elif event == "midi": - current = self.vm.midi.current - print(f"Value of midi button {current} is {self.vm.midi.get(current)}") + elif event == 'midi': + current = self._vm.midi.current + print(f'Value of midi button {current} is {self._vm.midi.get(current)}') def main(): - KIND_ID = "banana" + KIND_ID = 'banana' with voicemeeterlib.api( - KIND_ID, **{k: True for k in ("pdirty", "mdirty", "ldirty", "midi")} + KIND_ID, **{k: True for k in ('pdirty', 'mdirty', 'ldirty', 'midi')} ) as vm: App(vm) - while _ := input("Press to exit\n"): + while _ := input('Press to exit\n'): pass -if __name__ == "__main__": +if __name__ == '__main__': main() diff --git a/pyproject.toml b/pyproject.toml index 085fc28..63c2edd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ build-backend = "poetry.core.masonry.api" [tool.poe.tasks] dsl.script = "scripts:ex_dsl" -events.script = "scripts:ex_events" +callbacks.script = "scripts:ex_callbacks" gui.script = "scripts:ex_gui" levels.script = "scripts:ex_levels" midi.script = "scripts:ex_midi" diff --git a/scripts.py b/scripts.py index 66ca60f..334bd5f 100644 --- a/scripts.py +++ b/scripts.py @@ -5,51 +5,51 @@ from pathlib import Path def ex_dsl(): - subprocess.run(["tox", "r", "-e", "dsl"]) + subprocess.run(['tox', 'r', '-e', 'dsl']) -def ex_events(): - scriptpath = Path.cwd() / "examples" / "events" / "." +def ex_callbacks(): + scriptpath = Path.cwd() / 'examples' / 'callbacks' / '.' subprocess.run([sys.executable, str(scriptpath)]) def ex_gui(): - scriptpath = Path.cwd() / "examples" / "gui" / "." + scriptpath = Path.cwd() / 'examples' / 'gui' / '.' subprocess.run([sys.executable, str(scriptpath)]) def ex_levels(): - scriptpath = Path.cwd() / "examples" / "levels" / "." + scriptpath = Path.cwd() / 'examples' / 'levels' / '.' subprocess.run([sys.executable, str(scriptpath)]) def ex_midi(): - scriptpath = Path.cwd() / "examples" / "midi" / "." + scriptpath = Path.cwd() / 'examples' / 'midi' / '.' subprocess.run([sys.executable, str(scriptpath)]) def ex_obs(): - subprocess.run(["tox", "r", "-e", "obs"]) + subprocess.run(['tox', 'r', '-e', 'obs']) def ex_observer(): - scriptpath = Path.cwd() / "examples" / "observer" / "." + scriptpath = Path.cwd() / 'examples' / 'observer' / '.' subprocess.run([sys.executable, str(scriptpath)]) def test_basic(): - os.environ["KIND"] = "basic" - subprocess.run(["tox"]) + os.environ['KIND'] = 'basic' + subprocess.run(['tox']) def test_banana(): - os.environ["KIND"] = "banana" - subprocess.run(["tox"]) + os.environ['KIND'] = 'banana' + subprocess.run(['tox']) def test_potato(): - os.environ["KIND"] = "potato" - subprocess.run(["tox"]) + os.environ['KIND'] = 'potato' + subprocess.run(['tox']) def test_all():