upd examples

This commit is contained in:
Onyx and Iris 2025-01-16 14:51:20 +00:00
parent da1d5132a8
commit 38bd284ba6
8 changed files with 69 additions and 64 deletions

View File

@ -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():

View File

@ -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):

View File

@ -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():

View File

@ -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

View File

@ -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 <Enter> to exit\n"):
while _ := input('Press <Enter> to exit\n'):
pass
if __name__ == "__main__":
if __name__ == '__main__':
main()

View File

@ -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"

View File

@ -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():