mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2025-01-18 00:50:48 +00:00
upd examples
This commit is contained in:
parent
da1d5132a8
commit
38bd284ba6
@ -8,18 +8,18 @@ logging.basicConfig(level=logging.INFO)
|
|||||||
|
|
||||||
class App:
|
class App:
|
||||||
def __init__(self, vm):
|
def __init__(self, vm):
|
||||||
self.vm = vm
|
self._vm = vm
|
||||||
# register the callbacks for each event
|
# 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]
|
[self.on_pdirty, self.on_mdirty, self.on_ldirty, self.on_midi]
|
||||||
)
|
)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.vm.init_thread()
|
self._vm.init_thread()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
self.vm.end_thread()
|
self._vm.end_thread()
|
||||||
|
|
||||||
def on_pdirty(self):
|
def on_pdirty(self):
|
||||||
print('pdirty!')
|
print('pdirty!')
|
||||||
@ -28,13 +28,13 @@ class App:
|
|||||||
print('mdirty!')
|
print('mdirty!')
|
||||||
|
|
||||||
def on_ldirty(self):
|
def on_ldirty(self):
|
||||||
for bus in self.vm.bus:
|
for bus in self._vm.bus:
|
||||||
if bus.levels.isdirty:
|
if bus.levels.isdirty:
|
||||||
print(bus, bus.levels.all)
|
print(bus, bus.levels.all)
|
||||||
|
|
||||||
def on_midi(self):
|
def on_midi(self):
|
||||||
current = self.vm.midi.current
|
current = self._vm.midi.current
|
||||||
print(f'Value of midi button {current} is {self.vm.midi.get(current)}')
|
print(f'Value of midi button {current} is {self._vm.midi.get(current)}')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
@ -12,9 +12,9 @@ class App(tk.Tk):
|
|||||||
|
|
||||||
def __init__(self, vm):
|
def __init__(self, vm):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.vm = vm
|
self._vm = vm
|
||||||
self.title(f'{vm} - version {vm.version}')
|
self.title(f'{vm} - version {vm.version}')
|
||||||
self.vm.observer.add(self.on_ldirty)
|
self._vm.observer.add(self.on_ldirty)
|
||||||
|
|
||||||
# create widget variables
|
# create widget variables
|
||||||
self.button_var = tk.BooleanVar(value=vm.strip[self.INDEX].mute)
|
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
|
# 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)
|
self.labelframe.grid(padx=1)
|
||||||
|
|
||||||
# create slider and grid it onto the labelframe
|
# create slider and grid it onto the labelframe
|
||||||
@ -76,12 +76,12 @@ class App(tk.Tk):
|
|||||||
|
|
||||||
def on_slider_move(self, *args):
|
def on_slider_move(self, *args):
|
||||||
val = round(self.slider_var.get(), 1)
|
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)
|
self.gainlabel_var.set(val)
|
||||||
|
|
||||||
def on_button_press(self):
|
def on_button_press(self):
|
||||||
self.button_var.set(not self.button_var.get())
|
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(
|
self.style.configure(
|
||||||
'Mute.TButton', foreground='#cd5c5c' if self.button_var.get() else '#5a5a5a'
|
'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):
|
def on_button_double_click(self, e):
|
||||||
self.slider_var.set(0)
|
self.slider_var.set(0)
|
||||||
self.gainlabel_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):
|
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
|
return 0 if self.button_var.get() else 72 + val - 12
|
||||||
|
|
||||||
def on_ldirty(self):
|
def on_ldirty(self):
|
||||||
|
@ -10,31 +10,31 @@ class App:
|
|||||||
MACROBUTTON = 0
|
MACROBUTTON = 0
|
||||||
|
|
||||||
def __init__(self, vm):
|
def __init__(self, vm):
|
||||||
self.vm = vm
|
self._vm = vm
|
||||||
self.vm.observer.add(self.on_midi)
|
self._vm.observer.add(self.on_midi)
|
||||||
|
|
||||||
def on_midi(self):
|
def on_midi(self):
|
||||||
if self.get_info() == self.MIDI_BUTTON:
|
if self.get_info() == self.MIDI_BUTTON:
|
||||||
self.on_midi_press()
|
self.on_midi_press()
|
||||||
|
|
||||||
def get_info(self):
|
def get_info(self):
|
||||||
current = self.vm.midi.current
|
current = self._vm.midi.current
|
||||||
print(f'Value of midi button {current} is {self.vm.midi.get(current)}')
|
print(f'Value of midi button {current} is {self._vm.midi.get(current)}')
|
||||||
return current
|
return current
|
||||||
|
|
||||||
def on_midi_press(self):
|
def on_midi_press(self):
|
||||||
"""if midi button 48 is pressed and strip 3 level max > -40, then set trigger for macrobutton 0"""
|
"""if midi button 48 is pressed and strip 3 level max > -40, then set trigger for macrobutton 0"""
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self.vm.midi.get(self.MIDI_BUTTON) == 127
|
self._vm.midi.get(self.MIDI_BUTTON) == 127
|
||||||
and max(self.vm.strip[3].levels.postfader) > -40
|
and max(self._vm.strip[3].levels.postfader) > -40
|
||||||
):
|
):
|
||||||
print(
|
print(
|
||||||
f'Strip 3 level max is greater than -40 and midi button {self.MIDI_BUTTON} is pressed'
|
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:
|
else:
|
||||||
self.vm.button[self.MACROBUTTON].trigger = False
|
self._vm.button[self.MACROBUTTON].trigger = False
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -21,15 +21,20 @@ config.dictConfig(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
'voicemeeterlib.iremote': {'handlers': ['stream'], 'level': 'DEBUG'}
|
'voicemeeterlib.iremote': {
|
||||||
|
'handlers': ['stream'],
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'propagate': False,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
'root': {'handlers': ['stream'], 'level': 'WARNING'},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MyClient:
|
class MyClient:
|
||||||
def __init__(self, vm, stop_event):
|
def __init__(self, vm, stop_event):
|
||||||
self.vm = vm
|
self._vm = vm
|
||||||
self._stop_event = stop_event
|
self._stop_event = stop_event
|
||||||
self._client = obsws.EventClient()
|
self._client = obsws.EventClient()
|
||||||
self._client.callback.register(
|
self._client.callback.register(
|
||||||
@ -46,16 +51,16 @@ class MyClient:
|
|||||||
self._client.disconnect()
|
self._client.disconnect()
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
self.vm.strip[0].mute = True
|
self._vm.strip[0].mute = True
|
||||||
self.vm.strip[1].B1 = True
|
self._vm.strip[1].B1 = True
|
||||||
self.vm.strip[2].B2 = True
|
self._vm.strip[2].B2 = True
|
||||||
|
|
||||||
def on_brb(self):
|
def on_brb(self):
|
||||||
self.vm.strip[7].fadeto(0, 500)
|
self._vm.strip[7].fadeto(0, 500)
|
||||||
self.vm.bus[0].mute = True
|
self._vm.bus[0].mute = True
|
||||||
|
|
||||||
def on_end(self):
|
def on_end(self):
|
||||||
self.vm.apply(
|
self._vm.apply(
|
||||||
{
|
{
|
||||||
'strip-0': {'mute': True, 'comp': {'ratio': 4.3}},
|
'strip-0': {'mute': True, 'comp': {'ratio': 4.3}},
|
||||||
'strip-1': {'mute': True, 'B1': False, 'gate': {'attack': 2.3}},
|
'strip-1': {'mute': True, 'B1': False, 'gate': {'attack': 2.3}},
|
||||||
@ -65,10 +70,10 @@ class MyClient:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def on_live(self):
|
def on_live(self):
|
||||||
self.vm.strip[0].mute = False
|
self._vm.strip[0].mute = False
|
||||||
self.vm.strip[7].fadeto(-6, 500)
|
self._vm.strip[7].fadeto(-6, 500)
|
||||||
self.vm.strip[7].A3 = True
|
self._vm.strip[7].A3 = True
|
||||||
self.vm.vban.instream[0].on = True
|
self._vm.vban.instream[0].on = True
|
||||||
|
|
||||||
def on_current_program_scene_changed(self, data):
|
def on_current_program_scene_changed(self, data):
|
||||||
scene = data.scene_name
|
scene = data.scene_name
|
||||||
|
@ -7,39 +7,39 @@ logging.basicConfig(level=logging.INFO)
|
|||||||
|
|
||||||
class App:
|
class App:
|
||||||
def __init__(self, vm):
|
def __init__(self, vm):
|
||||||
self.vm = vm
|
self._vm = vm
|
||||||
# register your app as event observer
|
# register your app as event observer
|
||||||
self.vm.observer.add(self)
|
self._vm.observer.add(self)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return type(self).__name__
|
return type(self).__name__
|
||||||
|
|
||||||
# define an 'on_update' callback function to receive event updates
|
# define an 'on_update' callback function to receive event updates
|
||||||
def on_update(self, event):
|
def on_update(self, event):
|
||||||
if event == "pdirty":
|
if event == 'pdirty':
|
||||||
print("pdirty!")
|
print('pdirty!')
|
||||||
elif event == "mdirty":
|
elif event == 'mdirty':
|
||||||
print("mdirty!")
|
print('mdirty!')
|
||||||
elif event == "ldirty":
|
elif event == 'ldirty':
|
||||||
for bus in self.vm.bus:
|
for bus in self._vm.bus:
|
||||||
if bus.levels.isdirty:
|
if bus.levels.isdirty:
|
||||||
print(bus, bus.levels.all)
|
print(bus, bus.levels.all)
|
||||||
elif event == "midi":
|
elif event == 'midi':
|
||||||
current = self.vm.midi.current
|
current = self._vm.midi.current
|
||||||
print(f"Value of midi button {current} is {self.vm.midi.get(current)}")
|
print(f'Value of midi button {current} is {self._vm.midi.get(current)}')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
KIND_ID = "banana"
|
KIND_ID = 'banana'
|
||||||
|
|
||||||
with voicemeeterlib.api(
|
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:
|
) as vm:
|
||||||
App(vm)
|
App(vm)
|
||||||
|
|
||||||
while _ := input("Press <Enter> to exit\n"):
|
while _ := input('Press <Enter> to exit\n'):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -31,7 +31,7 @@ build-backend = "poetry.core.masonry.api"
|
|||||||
|
|
||||||
[tool.poe.tasks]
|
[tool.poe.tasks]
|
||||||
dsl.script = "scripts:ex_dsl"
|
dsl.script = "scripts:ex_dsl"
|
||||||
events.script = "scripts:ex_events"
|
callbacks.script = "scripts:ex_callbacks"
|
||||||
gui.script = "scripts:ex_gui"
|
gui.script = "scripts:ex_gui"
|
||||||
levels.script = "scripts:ex_levels"
|
levels.script = "scripts:ex_levels"
|
||||||
midi.script = "scripts:ex_midi"
|
midi.script = "scripts:ex_midi"
|
||||||
|
28
scripts.py
28
scripts.py
@ -5,51 +5,51 @@ from pathlib import Path
|
|||||||
|
|
||||||
|
|
||||||
def ex_dsl():
|
def ex_dsl():
|
||||||
subprocess.run(["tox", "r", "-e", "dsl"])
|
subprocess.run(['tox', 'r', '-e', 'dsl'])
|
||||||
|
|
||||||
|
|
||||||
def ex_events():
|
def ex_callbacks():
|
||||||
scriptpath = Path.cwd() / "examples" / "events" / "."
|
scriptpath = Path.cwd() / 'examples' / 'callbacks' / '.'
|
||||||
subprocess.run([sys.executable, str(scriptpath)])
|
subprocess.run([sys.executable, str(scriptpath)])
|
||||||
|
|
||||||
|
|
||||||
def ex_gui():
|
def ex_gui():
|
||||||
scriptpath = Path.cwd() / "examples" / "gui" / "."
|
scriptpath = Path.cwd() / 'examples' / 'gui' / '.'
|
||||||
subprocess.run([sys.executable, str(scriptpath)])
|
subprocess.run([sys.executable, str(scriptpath)])
|
||||||
|
|
||||||
|
|
||||||
def ex_levels():
|
def ex_levels():
|
||||||
scriptpath = Path.cwd() / "examples" / "levels" / "."
|
scriptpath = Path.cwd() / 'examples' / 'levels' / '.'
|
||||||
subprocess.run([sys.executable, str(scriptpath)])
|
subprocess.run([sys.executable, str(scriptpath)])
|
||||||
|
|
||||||
|
|
||||||
def ex_midi():
|
def ex_midi():
|
||||||
scriptpath = Path.cwd() / "examples" / "midi" / "."
|
scriptpath = Path.cwd() / 'examples' / 'midi' / '.'
|
||||||
subprocess.run([sys.executable, str(scriptpath)])
|
subprocess.run([sys.executable, str(scriptpath)])
|
||||||
|
|
||||||
|
|
||||||
def ex_obs():
|
def ex_obs():
|
||||||
subprocess.run(["tox", "r", "-e", "obs"])
|
subprocess.run(['tox', 'r', '-e', 'obs'])
|
||||||
|
|
||||||
|
|
||||||
def ex_observer():
|
def ex_observer():
|
||||||
scriptpath = Path.cwd() / "examples" / "observer" / "."
|
scriptpath = Path.cwd() / 'examples' / 'observer' / '.'
|
||||||
subprocess.run([sys.executable, str(scriptpath)])
|
subprocess.run([sys.executable, str(scriptpath)])
|
||||||
|
|
||||||
|
|
||||||
def test_basic():
|
def test_basic():
|
||||||
os.environ["KIND"] = "basic"
|
os.environ['KIND'] = 'basic'
|
||||||
subprocess.run(["tox"])
|
subprocess.run(['tox'])
|
||||||
|
|
||||||
|
|
||||||
def test_banana():
|
def test_banana():
|
||||||
os.environ["KIND"] = "banana"
|
os.environ['KIND'] = 'banana'
|
||||||
subprocess.run(["tox"])
|
subprocess.run(['tox'])
|
||||||
|
|
||||||
|
|
||||||
def test_potato():
|
def test_potato():
|
||||||
os.environ["KIND"] = "potato"
|
os.environ['KIND'] = 'potato'
|
||||||
subprocess.run(["tox"])
|
subprocess.run(['tox'])
|
||||||
|
|
||||||
|
|
||||||
def test_all():
|
def test_all():
|
||||||
|
Loading…
Reference in New Issue
Block a user