2023-09-04 05:11:45 +01:00
|
|
|
import json
|
2023-08-22 02:52:03 +01:00
|
|
|
import logging
|
2023-09-01 03:04:39 +01:00
|
|
|
from pathlib import Path
|
2023-08-22 02:52:03 +01:00
|
|
|
|
2023-08-22 02:04:00 +01:00
|
|
|
import PySimpleGUI as psg
|
|
|
|
|
2023-08-22 16:11:24 +01:00
|
|
|
from .builder import Builder
|
2023-09-05 05:30:46 +01:00
|
|
|
from .models import (
|
|
|
|
_make_bus_mode_cache,
|
|
|
|
_make_hardware_outs_cache,
|
|
|
|
_make_label_cache,
|
|
|
|
_make_output_cache,
|
|
|
|
_make_patch_asio_cache,
|
|
|
|
_make_patch_insert_cache,
|
|
|
|
)
|
2023-08-22 02:04:00 +01:00
|
|
|
from .nvda import Nvda
|
|
|
|
from .parser import Parser
|
2023-08-25 20:23:21 +01:00
|
|
|
from .util import (
|
2023-08-26 21:55:39 +01:00
|
|
|
_patch_insert_channels,
|
2023-08-25 20:23:21 +01:00
|
|
|
get_asio_checkbox_index,
|
2023-09-05 05:30:46 +01:00
|
|
|
get_channel_identifier_list,
|
2023-08-25 20:23:21 +01:00
|
|
|
get_insert_checkbox_index,
|
|
|
|
get_patch_composite_list,
|
2023-08-28 20:27:06 +01:00
|
|
|
open_context_menu_for_buttonmenu,
|
2023-08-25 20:23:21 +01:00
|
|
|
)
|
2023-08-22 02:04:00 +01:00
|
|
|
|
2023-08-22 02:52:03 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2023-08-25 02:19:01 +01:00
|
|
|
psg.theme("Dark Blue 3")
|
2023-08-24 18:02:53 +01:00
|
|
|
|
2023-08-22 02:04:00 +01:00
|
|
|
|
2023-08-25 20:23:21 +01:00
|
|
|
class NVDAVMWindow(psg.Window):
|
|
|
|
"""Represents the main window of the Voicemeeter NVDA application"""
|
2023-08-22 16:11:24 +01:00
|
|
|
|
2023-09-04 05:11:45 +01:00
|
|
|
SETTINGS = "settings.json"
|
2023-09-01 03:04:39 +01:00
|
|
|
|
2023-08-22 02:04:00 +01:00
|
|
|
def __init__(self, title, vm):
|
|
|
|
self.vm = vm
|
|
|
|
self.kind = self.vm.kind
|
2023-08-22 02:52:03 +01:00
|
|
|
self.logger = logger.getChild(type(self).__name__)
|
2023-09-02 04:23:15 +01:00
|
|
|
self.cache = {
|
|
|
|
"outputs": _make_output_cache(self.vm),
|
|
|
|
"busmode": _make_bus_mode_cache(self.vm),
|
|
|
|
"labels": _make_label_cache(self.vm),
|
2023-09-05 05:30:46 +01:00
|
|
|
"asio": _make_patch_asio_cache(self.vm),
|
|
|
|
"insert": _make_patch_insert_cache(self.vm),
|
2023-09-02 04:23:15 +01:00
|
|
|
}
|
2023-08-22 02:04:00 +01:00
|
|
|
self.nvda = Nvda()
|
|
|
|
self.parser = Parser()
|
2023-08-26 00:11:05 +01:00
|
|
|
self.builder = Builder(self)
|
2023-08-22 16:11:24 +01:00
|
|
|
layout = self.builder.run()
|
2023-08-26 19:46:39 +01:00
|
|
|
super().__init__(title, layout, return_keyboard_events=True, finalize=True)
|
2023-08-28 12:11:34 +01:00
|
|
|
buttonmenu_opts = {"takefocus": 1, "highlightthickness": 1}
|
2023-08-28 20:27:06 +01:00
|
|
|
for i in range(self.kind.phys_out):
|
|
|
|
self[f"HARDWARE OUT||A{i + 1}"].Widget.config(**buttonmenu_opts)
|
2023-08-26 10:42:18 +01:00
|
|
|
if self.kind.name != "basic":
|
2023-08-28 12:11:34 +01:00
|
|
|
[self[f"PATCH COMPOSITE||PC{i + 1}"].Widget.config(**buttonmenu_opts) for i in range(self.kind.phys_out)]
|
2023-08-28 21:21:26 +01:00
|
|
|
self["ASIO BUFFER"].Widget.config(**buttonmenu_opts)
|
2023-08-22 02:52:03 +01:00
|
|
|
self.register_events()
|
2023-08-22 02:04:00 +01:00
|
|
|
|
|
|
|
def __enter__(self):
|
2023-09-05 05:30:46 +01:00
|
|
|
settings_path = Path.cwd() / self.SETTINGS
|
|
|
|
if settings_path.exists():
|
2023-09-01 03:04:39 +01:00
|
|
|
try:
|
2023-09-05 05:30:46 +01:00
|
|
|
with open(settings_path, "r") as f:
|
2023-09-04 05:11:45 +01:00
|
|
|
data = json.load(f)
|
2023-09-05 05:30:46 +01:00
|
|
|
defaultconfig = Path(data["default_config"])
|
|
|
|
if defaultconfig.exists():
|
|
|
|
self.vm.set("command.load", str(defaultconfig))
|
|
|
|
self.logger.debug(f"config {defaultconfig} loaded")
|
2023-09-01 10:43:37 +01:00
|
|
|
self.TKroot.after(
|
|
|
|
200,
|
|
|
|
self.nvda.speak,
|
2023-09-05 05:30:46 +01:00
|
|
|
f"config {defaultconfig.stem} has been loaded",
|
2023-09-01 10:43:37 +01:00
|
|
|
)
|
2023-09-04 05:11:45 +01:00
|
|
|
except json.JSONDecodeError:
|
|
|
|
self.logger.debug("no data in settings.json. silently continuing...")
|
2023-09-01 03:04:39 +01:00
|
|
|
|
2023-09-05 05:30:46 +01:00
|
|
|
self.vm.init_thread()
|
|
|
|
self.vm.observer.add(self.on_pdirty)
|
|
|
|
self.TKroot.after(1000, self.enable_parameter_updates)
|
|
|
|
|
2023-08-22 02:04:00 +01:00
|
|
|
return self
|
|
|
|
|
2023-09-05 05:30:46 +01:00
|
|
|
def enable_parameter_updates(self):
|
|
|
|
self.vm.event.pdirty = True
|
|
|
|
|
2023-08-22 02:04:00 +01:00
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
2023-09-05 05:30:46 +01:00
|
|
|
self.vm.end_thread()
|
2023-08-22 02:04:00 +01:00
|
|
|
self.close()
|
|
|
|
|
2023-09-05 05:30:46 +01:00
|
|
|
def on_pdirty(self):
|
|
|
|
self.cache = {
|
|
|
|
"outputs": _make_output_cache(self.vm),
|
|
|
|
"busmode": _make_bus_mode_cache(self.vm),
|
|
|
|
"labels": _make_label_cache(self.vm),
|
|
|
|
"asio": _make_patch_asio_cache(self.vm),
|
|
|
|
"insert": _make_patch_insert_cache(self.vm),
|
|
|
|
}
|
|
|
|
for key, value in self.cache["labels"].items():
|
|
|
|
self[key].update(value=value)
|
|
|
|
for key, value in self.cache["asio"].items():
|
|
|
|
identifier, i = key.split("||")
|
2023-09-05 05:35:38 +01:00
|
|
|
partial = get_channel_identifier_list(self.vm)[int(i)]
|
|
|
|
self[f"{identifier}||{partial}"].update(value=value)
|
2023-09-05 05:30:46 +01:00
|
|
|
for key, value in self.cache["insert"].items():
|
|
|
|
identifier, i = key.split("||")
|
|
|
|
partial = get_channel_identifier_list(self.vm)[int(i)]
|
|
|
|
self[f"{identifier}||{partial}"].update(value=value)
|
|
|
|
|
2023-08-22 02:52:03 +01:00
|
|
|
def register_events(self):
|
2023-08-25 20:23:21 +01:00
|
|
|
"""Registers events for widgets"""
|
|
|
|
|
2023-08-25 22:53:48 +01:00
|
|
|
# TABS
|
|
|
|
self["tabs"].bind("<FocusIn>", "||FOCUS IN")
|
2023-08-28 20:27:06 +01:00
|
|
|
self.bind("<Control-KeyPress-Tab>", "CTRL-TAB")
|
|
|
|
self.bind("<Control-Shift-KeyPress-Tab>", "CTRL-SHIFT-TAB")
|
2023-08-25 22:53:48 +01:00
|
|
|
|
2023-08-25 20:23:21 +01:00
|
|
|
# Hardware Out
|
2023-08-25 20:41:48 +01:00
|
|
|
for i in range(self.vm.kind.phys_out):
|
|
|
|
self[f"HARDWARE OUT||A{i + 1}"].bind("<FocusIn>", "||FOCUS IN")
|
2023-08-28 20:27:06 +01:00
|
|
|
self[f"HARDWARE OUT||A{i + 1}"].bind("<space>", "||KEY SPACE", propagate=False)
|
|
|
|
self[f"HARDWARE OUT||A{i + 1}"].bind("<Return>", "||KEY ENTER", propagate=False)
|
2023-08-25 18:29:43 +01:00
|
|
|
|
2023-08-25 20:23:21 +01:00
|
|
|
# Patch ASIO
|
2023-08-23 02:31:15 +01:00
|
|
|
if self.kind.name != "basic":
|
2023-08-25 20:41:48 +01:00
|
|
|
for i in range(self.kind.phys_out):
|
|
|
|
self[f"ASIO CHECKBOX||IN{i + 1} 0"].bind("<FocusIn>", "||FOCUS IN")
|
|
|
|
self[f"ASIO CHECKBOX||IN{i + 1} 1"].bind("<FocusIn>", "||FOCUS IN")
|
2023-08-25 18:29:43 +01:00
|
|
|
|
2023-08-25 20:23:21 +01:00
|
|
|
# Patch Composite
|
2023-08-26 10:42:18 +01:00
|
|
|
if self.kind.name != "basic":
|
|
|
|
for i in range(self.vm.kind.phys_out):
|
|
|
|
self[f"PATCH COMPOSITE||PC{i + 1}"].bind("<FocusIn>", "||FOCUS IN")
|
2023-08-28 20:27:06 +01:00
|
|
|
self[f"PATCH COMPOSITE||PC{i + 1}"].bind("<space>", "||KEY SPACE", propagate=False)
|
|
|
|
self[f"PATCH COMPOSITE||PC{i + 1}"].bind("<Return>", "||KEY ENTER", propagate=False)
|
2023-08-25 18:29:43 +01:00
|
|
|
|
2023-08-25 20:23:21 +01:00
|
|
|
# Patch Insert
|
2023-08-23 02:31:15 +01:00
|
|
|
if self.kind.name != "basic":
|
2023-08-25 20:41:48 +01:00
|
|
|
for i in range(self.kind.num_strip):
|
2023-08-26 17:29:24 +01:00
|
|
|
if i < self.kind.phys_in:
|
2023-08-25 20:41:48 +01:00
|
|
|
self[f"INSERT CHECKBOX||IN{i + 1} 0"].bind("<FocusIn>", "||FOCUS IN")
|
|
|
|
self[f"INSERT CHECKBOX||IN{i + 1} 1"].bind("<FocusIn>", "||FOCUS IN")
|
2023-08-23 02:31:15 +01:00
|
|
|
else:
|
2023-08-25 20:41:48 +01:00
|
|
|
[self[f"INSERT CHECKBOX||IN{i + 1} {j}"].bind("<FocusIn>", "||FOCUS IN") for j in range(8)]
|
2023-08-22 02:52:03 +01:00
|
|
|
|
2023-08-25 22:25:30 +01:00
|
|
|
# Strip Outputs
|
|
|
|
for i in range(self.kind.num_strip):
|
|
|
|
for j in range(self.kind.phys_out):
|
|
|
|
self[f"STRIP {i}||A{j + 1}"].bind("<FocusIn>", "||FOCUS IN")
|
2023-08-28 20:27:06 +01:00
|
|
|
self[f"STRIP {i}||A{j + 1}"].bind("<Return>", "||KEY ENTER")
|
2023-08-25 22:25:30 +01:00
|
|
|
for j in range(self.kind.virt_out):
|
|
|
|
self[f"STRIP {i}||B{j + 1}"].bind("<FocusIn>", "||FOCUS IN")
|
2023-08-28 20:27:06 +01:00
|
|
|
self[f"STRIP {i}||B{j + 1}"].bind("<Return>", "||KEY ENTER")
|
2023-08-25 22:25:30 +01:00
|
|
|
|
2023-08-28 21:21:26 +01:00
|
|
|
# Bus Modes
|
2023-08-28 20:27:06 +01:00
|
|
|
for i in range(self.kind.num_bus):
|
2023-08-28 21:21:26 +01:00
|
|
|
self[f"BUS {i}||MODE"].bind("<FocusIn>", "||FOCUS IN")
|
2023-09-04 07:40:14 +01:00
|
|
|
self[f"BUS {i}||MODE"].bind("<Return>", "||KEY ENTER")
|
2023-08-26 20:22:46 +01:00
|
|
|
|
2023-08-26 21:55:39 +01:00
|
|
|
# ASIO Buffer
|
2023-08-28 21:21:26 +01:00
|
|
|
if self.kind.name != "basic":
|
|
|
|
self["ASIO BUFFER"].bind("<FocusIn>", "||FOCUS IN")
|
|
|
|
self["ASIO BUFFER"].bind("<space>", "||KEY SPACE", propagate=False)
|
|
|
|
self["ASIO BUFFER"].bind("<Return>", "||KEY ENTER", propagate=False)
|
2023-08-26 21:55:39 +01:00
|
|
|
|
2023-09-01 10:43:37 +01:00
|
|
|
def popup_save_as(self, message, title=None, initial_folder=None):
|
|
|
|
layout = [
|
|
|
|
[psg.Text(message)],
|
|
|
|
[
|
|
|
|
psg.FileSaveAs("Browse", initial_folder=str(initial_folder), file_types=(("XML", ".xml"),)),
|
2023-09-01 23:20:36 +01:00
|
|
|
psg.Button("Cancel"),
|
2023-09-01 10:43:37 +01:00
|
|
|
],
|
|
|
|
]
|
|
|
|
window = psg.Window(title, layout, finalize=True)
|
|
|
|
window["Browse"].bind("<FocusIn>", "||FOCUS IN")
|
2023-09-01 23:20:36 +01:00
|
|
|
window["Browse"].bind("<Return>", "||KEY ENTER")
|
2023-09-01 10:43:37 +01:00
|
|
|
window["Cancel"].bind("<FocusIn>", "||FOCUS IN")
|
2023-09-01 23:20:36 +01:00
|
|
|
window["Cancel"].bind("<Return>", "||KEY ENTER")
|
2023-09-01 10:43:37 +01:00
|
|
|
filepath = None
|
|
|
|
while True:
|
|
|
|
event, values = window.read()
|
2023-09-02 04:49:36 +01:00
|
|
|
self.logger.debug(f"event::{event}")
|
|
|
|
self.logger.debug(f"values::{values}")
|
2023-09-01 10:43:37 +01:00
|
|
|
if event in (psg.WIN_CLOSED, "Cancel"):
|
|
|
|
break
|
2023-09-02 04:23:15 +01:00
|
|
|
elif event.endswith("||FOCUS IN"):
|
2023-09-01 23:20:36 +01:00
|
|
|
if values["Browse"]:
|
|
|
|
filepath = values["Browse"]
|
|
|
|
break
|
2023-09-01 10:43:37 +01:00
|
|
|
label = event.split("||")[0]
|
|
|
|
self.TKroot.after(
|
2023-09-01 23:20:36 +01:00
|
|
|
200 if label == "Edit" else 1,
|
2023-09-01 10:43:37 +01:00
|
|
|
self.nvda.speak,
|
|
|
|
label,
|
|
|
|
)
|
2023-09-01 23:20:36 +01:00
|
|
|
elif event.endswith("||KEY ENTER"):
|
|
|
|
window.find_element_with_focus().click()
|
2023-09-01 10:43:37 +01:00
|
|
|
window.close()
|
|
|
|
if filepath:
|
|
|
|
return Path(filepath)
|
|
|
|
|
2023-09-02 04:23:15 +01:00
|
|
|
def popup_rename(self, message, title=None, tab=None):
|
|
|
|
if tab == "Physical Strip":
|
|
|
|
upper = self.kind.phys_out + 1
|
|
|
|
elif tab == "Virtual Strip":
|
|
|
|
upper = self.kind.virt_out + 1
|
|
|
|
elif tab == "Buses":
|
|
|
|
upper = self.kind.num_bus + 1
|
|
|
|
|
|
|
|
layout = [
|
|
|
|
[psg.Text(message)],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
psg.Spin(
|
|
|
|
list(range(1, upper)), initial_value=1, size=2, enable_events=True, key=f"Index", readonly=True
|
|
|
|
),
|
|
|
|
psg.Input(key="Edit"),
|
|
|
|
],
|
|
|
|
[psg.Button("Ok"), psg.Button("Cancel")],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
window = psg.Window(title, layout, finalize=True)
|
|
|
|
window["Index"].bind("<FocusIn>", "||FOCUS IN")
|
|
|
|
window["Edit"].bind("<FocusIn>", "||FOCUS IN")
|
|
|
|
window["Ok"].bind("<FocusIn>", "||FOCUS IN")
|
|
|
|
window["Ok"].bind("<Return>", "||KEY ENTER")
|
|
|
|
window["Cancel"].bind("<FocusIn>", "||FOCUS IN")
|
|
|
|
window["Cancel"].bind("<Return>", "||KEY ENTER")
|
|
|
|
data = {}
|
|
|
|
while True:
|
|
|
|
event, values = window.read()
|
2023-09-02 04:49:36 +01:00
|
|
|
self.logger.debug(f"event::{event}")
|
|
|
|
self.logger.debug(f"values::{values}")
|
2023-09-02 04:23:15 +01:00
|
|
|
if event in (psg.WIN_CLOSED, "Cancel"):
|
|
|
|
break
|
|
|
|
elif event.endswith("||KEY ENTER"):
|
|
|
|
window.find_element_with_focus().click()
|
|
|
|
elif event == "Index":
|
|
|
|
val = values["Index"]
|
|
|
|
self.nvda.speak(f"Index {val}")
|
|
|
|
elif event.startswith("Index") and event.endswith("||FOCUS IN"):
|
|
|
|
val = values["Index"]
|
|
|
|
self.nvda.speak(f"Index {val}")
|
|
|
|
elif event.startswith("Edit") and event.endswith("||FOCUS IN"):
|
|
|
|
self.nvda.speak("Edit")
|
|
|
|
elif event == "Ok":
|
|
|
|
data = values
|
|
|
|
break
|
|
|
|
elif event.startswith("Ok") and event.endswith("||FOCUS IN"):
|
|
|
|
self.nvda.speak("Ok")
|
|
|
|
elif event.startswith("Cancel") and event.endswith("||FOCUS IN"):
|
|
|
|
self.nvda.speak("Cancel")
|
|
|
|
|
|
|
|
window.close()
|
|
|
|
return data
|
|
|
|
|
2023-08-22 02:04:00 +01:00
|
|
|
def run(self):
|
2023-08-22 05:16:43 +01:00
|
|
|
"""
|
|
|
|
Parses the event string and matches it to events
|
|
|
|
|
|
|
|
Main thread will shutdown once a close or exit event occurs
|
|
|
|
"""
|
2023-08-25 20:23:21 +01:00
|
|
|
|
2023-08-22 02:04:00 +01:00
|
|
|
while True:
|
|
|
|
event, values = self.read()
|
2023-08-26 09:39:51 +01:00
|
|
|
self.logger.debug(f"event::{event}")
|
|
|
|
self.logger.debug(f"values::{values}")
|
2023-08-22 02:04:00 +01:00
|
|
|
if event in (psg.WIN_CLOSED, "Exit"):
|
|
|
|
break
|
2023-08-25 22:33:28 +01:00
|
|
|
elif event == "tabs":
|
2023-08-25 22:53:48 +01:00
|
|
|
self.nvda.speak(f"tab {values['tabs']}")
|
2023-08-25 22:33:28 +01:00
|
|
|
|
2023-08-23 02:04:18 +01:00
|
|
|
match parsed_cmd := self.parser.match.parseString(event):
|
2023-08-29 02:58:13 +01:00
|
|
|
# Focus tabgroup
|
2023-08-28 12:11:34 +01:00
|
|
|
case ["CTRL-TAB"] | ["CTRL-SHIFT-TAB"]:
|
|
|
|
self["tabs"].set_focus()
|
|
|
|
|
2023-09-02 04:23:15 +01:00
|
|
|
# Rename popups
|
|
|
|
case ["F2:113"]:
|
|
|
|
tab = values["tabs"]
|
|
|
|
if tab in ("Physical Strip", "Virtual Strip", "Buses"):
|
|
|
|
data = self.popup_rename("Label", title=f"Rename {tab}", tab=tab)
|
2023-09-05 05:30:46 +01:00
|
|
|
if not data: # cancel was pressed
|
2023-09-02 05:00:38 +01:00
|
|
|
continue
|
|
|
|
index = int(data["Index"]) - 1
|
|
|
|
match tab:
|
2023-09-05 05:30:46 +01:00
|
|
|
case "Physical Strip":
|
|
|
|
label = data.get("Edit") or f"Hardware Input {index + 1}"
|
|
|
|
self.vm.strip[index].label = label
|
|
|
|
self[f"STRIP {index}||LABEL"].update(value=label)
|
|
|
|
self.cache["labels"][f"STRIP {index}||LABEL"] = label
|
|
|
|
case "Virtual Strip":
|
|
|
|
label = data.get("Edit") or f"Virtual Input {index + 1}"
|
2023-09-02 05:00:38 +01:00
|
|
|
self.vm.strip[index].label = label
|
|
|
|
self[f"STRIP {index}||LABEL"].update(value=label)
|
2023-09-05 05:30:46 +01:00
|
|
|
self.cache["labels"][f"STRIP {index}||LABEL"] = label
|
2023-09-02 05:00:38 +01:00
|
|
|
case "Buses":
|
2023-09-05 05:30:46 +01:00
|
|
|
if index < self.kind.phys_out:
|
|
|
|
label = data.get("Edit") or f"Physical Bus {index + 1}"
|
|
|
|
else:
|
|
|
|
label = data.get("Edit") or f"Virtual Bus {index - self.kind.phys_out + 1}"
|
2023-09-02 05:00:38 +01:00
|
|
|
self.vm.bus[index].label = label
|
|
|
|
self[f"BUS {index}||LABEL"].update(value=label)
|
2023-09-05 05:30:46 +01:00
|
|
|
self.cache["labels"][f"BUS {index}||LABEL"] = label
|
2023-09-02 04:23:15 +01:00
|
|
|
|
2023-08-26 19:46:39 +01:00
|
|
|
# Menus
|
|
|
|
case [["Restart", "Audio", "Engine"], ["MENU"]]:
|
|
|
|
self.perform_long_operation(self.vm.command.restart, "ENGINE RESTART||END")
|
|
|
|
case [["ENGINE", "RESTART"], ["END"]]:
|
|
|
|
self.TKroot.after(
|
|
|
|
200,
|
|
|
|
self.nvda.speak,
|
2023-09-01 03:04:39 +01:00
|
|
|
"Audio Engine restarted",
|
2023-08-26 19:46:39 +01:00
|
|
|
)
|
2023-09-01 03:04:39 +01:00
|
|
|
case [["Save", "Settings"], ["MENU"]]:
|
2023-09-01 10:43:37 +01:00
|
|
|
initial_folder = Path.home() / "Documents" / "Voicemeeter"
|
2023-09-01 23:20:36 +01:00
|
|
|
if filepath := self.popup_save_as(
|
|
|
|
"Open the file browser", title="Save As", initial_folder=initial_folder
|
|
|
|
):
|
2023-09-01 10:43:37 +01:00
|
|
|
self.vm.set("command.save", str(filepath))
|
|
|
|
self.logger.debug(f"saving config file to {filepath}")
|
2023-09-01 03:04:39 +01:00
|
|
|
self.TKroot.after(
|
|
|
|
200,
|
|
|
|
self.nvda.speak,
|
2023-09-01 10:43:37 +01:00
|
|
|
f"config file {filepath.stem} has been saved",
|
2023-09-01 03:04:39 +01:00
|
|
|
)
|
|
|
|
case [["Load", "Settings"], ["MENU"]]:
|
2023-09-01 10:43:37 +01:00
|
|
|
initial_folder = Path.home() / "Documents" / "Voicemeeter"
|
2023-09-01 23:20:36 +01:00
|
|
|
if filepath := psg.popup_get_file(
|
|
|
|
"Filename",
|
|
|
|
title="Load Settings",
|
|
|
|
initial_folder=initial_folder,
|
|
|
|
no_window=True,
|
|
|
|
file_types=(("XML", ".xml"),),
|
2023-09-01 10:43:37 +01:00
|
|
|
):
|
2023-09-01 23:20:36 +01:00
|
|
|
filepath = Path(filepath)
|
2023-09-01 10:43:37 +01:00
|
|
|
self.vm.set("command.load", str(filepath))
|
|
|
|
self.logger.debug(f"loading config file from {filepath}")
|
2023-09-01 03:04:39 +01:00
|
|
|
self.TKroot.after(
|
|
|
|
200,
|
|
|
|
self.nvda.speak,
|
2023-09-01 10:43:37 +01:00
|
|
|
f"config file {filepath.stem} has been loaded",
|
2023-09-01 03:04:39 +01:00
|
|
|
)
|
|
|
|
case [["Load", "Settings", "on", "Startup"], ["MENU"]]:
|
2023-09-01 10:43:37 +01:00
|
|
|
initial_folder = Path.home() / "Documents" / "Voicemeeter"
|
2023-09-01 23:20:36 +01:00
|
|
|
if filepath := psg.popup_get_file(
|
|
|
|
"Filename",
|
|
|
|
title="Load Settings",
|
|
|
|
initial_folder=initial_folder,
|
|
|
|
no_window=True,
|
|
|
|
file_types=(("XML", ".xml"),),
|
2023-09-01 10:43:37 +01:00
|
|
|
):
|
2023-09-01 23:20:36 +01:00
|
|
|
filepath = Path(filepath)
|
2023-09-04 05:11:45 +01:00
|
|
|
with open(self.SETTINGS, "w") as f:
|
|
|
|
json.dump({"default_config": str(filepath)}, f)
|
2023-09-01 03:04:39 +01:00
|
|
|
self.TKroot.after(
|
|
|
|
200,
|
|
|
|
self.nvda.speak,
|
2023-09-01 23:20:36 +01:00
|
|
|
f"config {filepath.stem} set as default on startup",
|
2023-09-01 03:04:39 +01:00
|
|
|
)
|
|
|
|
else:
|
2023-09-04 05:11:45 +01:00
|
|
|
with open(self.SETTINGS, "wb") as f:
|
2023-09-01 03:04:39 +01:00
|
|
|
f.truncate()
|
|
|
|
self.logger.debug("default bin was truncated")
|
2023-08-26 19:46:39 +01:00
|
|
|
|
2023-08-25 22:53:48 +01:00
|
|
|
# Tabs
|
|
|
|
case [["tabs"], ["FOCUS", "IN"]]:
|
|
|
|
self.nvda.speak(f"tab {values['tabs']}")
|
|
|
|
|
2023-08-25 20:23:21 +01:00
|
|
|
# Hardware out
|
2023-08-22 02:52:03 +01:00
|
|
|
case [["HARDWARE", "OUT"], [key]]:
|
|
|
|
selection = values[f"HARDWARE OUT||{key}"]
|
2023-08-23 02:04:18 +01:00
|
|
|
index = int(key[1]) - 1
|
2023-08-22 05:37:06 +01:00
|
|
|
match selection.split(":"):
|
|
|
|
case [device_name]:
|
2023-08-23 02:04:18 +01:00
|
|
|
setattr(self.vm.bus[index].device, "wdm", "")
|
2023-08-24 16:07:28 +01:00
|
|
|
self.TKroot.after(200, self.nvda.speak, f"HARDWARE OUT {key} device selection removed")
|
2023-08-22 05:37:06 +01:00
|
|
|
case [driver, device_name]:
|
|
|
|
setattr(self.vm.bus[index].device, driver, device_name.strip())
|
2023-08-24 16:07:28 +01:00
|
|
|
phonetic = {"mme": "em em e"}
|
|
|
|
self.TKroot.after(
|
|
|
|
200,
|
|
|
|
self.nvda.speak,
|
|
|
|
f"HARDWARE OUT {key} set {phonetic.get(driver, driver)} {device_name}",
|
|
|
|
)
|
2023-08-22 02:52:03 +01:00
|
|
|
case [["HARDWARE", "OUT"], [key], ["FOCUS", "IN"]]:
|
2023-08-24 16:07:28 +01:00
|
|
|
self.nvda.speak(f"HARDWARE OUT {key} {self.vm.bus[int(key[-1]) - 1].device.name}")
|
2023-08-28 20:27:06 +01:00
|
|
|
case [["HARDWARE", "OUT"], [key], ["KEY", "SPACE" | "ENTER"]]:
|
|
|
|
open_context_menu_for_buttonmenu(self, f"HARDWARE OUT||{key}")
|
2023-08-25 20:23:21 +01:00
|
|
|
|
|
|
|
# Patch ASIO
|
2023-08-22 20:41:44 +01:00
|
|
|
case [["ASIO", "CHECKBOX"], [in_num, channel]]:
|
2023-08-23 00:27:12 +01:00
|
|
|
index = get_asio_checkbox_index(int(channel), int(in_num[-1]))
|
2023-08-22 20:41:44 +01:00
|
|
|
val = values[f"ASIO CHECKBOX||{in_num} {channel}"]
|
2023-08-22 05:16:43 +01:00
|
|
|
self.vm.patch.asio[index].set(val)
|
2023-08-22 20:41:44 +01:00
|
|
|
channel = ("left", "right")[int(channel)]
|
|
|
|
self.nvda.speak(f"Patch ASIO {in_num} {channel} set to {val}")
|
|
|
|
case [["ASIO", "CHECKBOX"], [in_num, channel], ["FOCUS", "IN"]]:
|
2023-08-25 18:52:26 +01:00
|
|
|
val = values[f"ASIO CHECKBOX||{in_num} {channel}"]
|
2023-08-22 20:41:44 +01:00
|
|
|
channel = ("left", "right")[int(channel)]
|
2023-08-22 05:16:43 +01:00
|
|
|
num = int(in_num[-1])
|
2023-08-25 18:52:26 +01:00
|
|
|
self.nvda.speak(f"Patch ASIO inputs to strips IN#{num} {channel} {val}")
|
2023-08-25 20:23:21 +01:00
|
|
|
|
|
|
|
# Patch COMPOSITE
|
|
|
|
case [["PATCH", "COMPOSITE"], [key]]:
|
|
|
|
val = values[f"PATCH COMPOSITE||{key}"]
|
|
|
|
index = int(key[-1]) - 1
|
|
|
|
self.vm.patch.composite[index].set(get_patch_composite_list(self.kind).index(val) + 1)
|
|
|
|
self.TKroot.after(200, self.nvda.speak, f"PATCH COMPOSITE {key[-1]} set {val}")
|
|
|
|
case [["PATCH", "COMPOSITE"], [key], ["FOCUS", "IN"]]:
|
|
|
|
if values[f"PATCH COMPOSITE||{key}"]:
|
|
|
|
val = values[f"PATCH COMPOSITE||{key}"]
|
|
|
|
else:
|
|
|
|
index = int(key[-1]) - 1
|
|
|
|
val = get_patch_composite_list(self.kind)[self.vm.patch.composite[index].get() - 1]
|
|
|
|
self.nvda.speak(f"Patch COMPOSITE {key[-1]} {val}")
|
2023-08-28 20:27:06 +01:00
|
|
|
case [["PATCH", "COMPOSITE"], [key], ["KEY", "SPACE" | "ENTER"]]:
|
|
|
|
open_context_menu_for_buttonmenu(self, f"PATCH COMPOSITE||{key}")
|
2023-08-25 20:23:21 +01:00
|
|
|
|
|
|
|
# Patch INSERT
|
2023-08-22 20:41:44 +01:00
|
|
|
case [["INSERT", "CHECKBOX"], [in_num, channel]]:
|
2023-08-23 00:27:12 +01:00
|
|
|
index = get_insert_checkbox_index(
|
|
|
|
self.kind,
|
|
|
|
int(channel),
|
|
|
|
int(in_num[-1]),
|
|
|
|
)
|
2023-08-22 20:41:44 +01:00
|
|
|
val = values[f"INSERT CHECKBOX||{in_num} {channel}"]
|
|
|
|
self.vm.patch.insert[index].on = val
|
|
|
|
self.nvda.speak(
|
|
|
|
f"PATCH INSERT {in_num} {_patch_insert_channels[int(channel)]} set to {'on' if val else 'off'}"
|
|
|
|
)
|
|
|
|
case [["INSERT", "CHECKBOX"], [in_num, channel], ["FOCUS", "IN"]]:
|
2023-08-24 16:07:28 +01:00
|
|
|
index = get_insert_checkbox_index(
|
|
|
|
self.kind,
|
|
|
|
int(channel),
|
|
|
|
int(in_num[-1]),
|
|
|
|
)
|
2023-08-25 18:52:26 +01:00
|
|
|
val = values[f"INSERT CHECKBOX||{in_num} {channel}"]
|
2023-08-22 20:41:44 +01:00
|
|
|
channel = _patch_insert_channels[int(channel)]
|
|
|
|
num = int(in_num[-1])
|
2023-08-25 18:52:26 +01:00
|
|
|
self.nvda.speak(f"Patch INSERT IN#{num} {channel} {'on' if val else 'off'}")
|
2023-08-26 00:11:05 +01:00
|
|
|
|
2023-08-26 21:55:39 +01:00
|
|
|
# ASIO Buffer
|
|
|
|
case ["ASIO BUFFER"]:
|
|
|
|
if values[event] == "Default":
|
|
|
|
val = 0
|
|
|
|
else:
|
|
|
|
val = values[event]
|
|
|
|
self.vm.option.buffer("asio", val)
|
2023-08-26 21:59:48 +01:00
|
|
|
self.TKroot.after(200, self.nvda.speak, f"ASIO BUFFER {val if val else 'default'}")
|
2023-08-28 20:27:06 +01:00
|
|
|
case [["ASIO", "BUFFER"], ["FOCUS", "IN"]]:
|
|
|
|
val = int(self.vm.get("option.buffer.asio"))
|
|
|
|
self.nvda.speak(f"ASIO BUFFER {val if val else 'default'}")
|
|
|
|
case [["ASIO", "BUFFER"], ["KEY", "SPACE" | "ENTER"]]:
|
|
|
|
open_context_menu_for_buttonmenu(self, "ASIO BUFFER")
|
2023-08-26 21:55:39 +01:00
|
|
|
|
2023-08-26 00:11:05 +01:00
|
|
|
# Strip outputs
|
2023-08-26 09:07:02 +01:00
|
|
|
case [["STRIP", index], [output]]:
|
2023-08-26 00:11:05 +01:00
|
|
|
val = not self.cache["outputs"][f"STRIP {index}||{output}"]
|
|
|
|
setattr(self.vm.strip[int(index)], output, val)
|
|
|
|
self.cache["outputs"][f"STRIP {index}||{output}"] = val
|
2023-08-26 17:29:24 +01:00
|
|
|
self.nvda.speak(f"STRIP {index} {output} {label if label else ''} {'on' if val else 'off'}")
|
2023-08-26 00:11:05 +01:00
|
|
|
case [["STRIP", index], [output], ["FOCUS", "IN"]]:
|
|
|
|
val = self.cache["outputs"][f"STRIP {index}||{output}"]
|
2023-09-05 05:30:46 +01:00
|
|
|
label = self.cache["labels"][f"STRIP {index}||LABEL"]
|
2023-09-02 04:23:15 +01:00
|
|
|
self.nvda.speak(f"{label} {output} {'on' if val else 'off'}")
|
2023-08-28 20:27:06 +01:00
|
|
|
case [["STRIP", index], [output], ["KEY", "ENTER"]]:
|
|
|
|
self.find_element_with_focus().click()
|
2023-08-26 20:22:46 +01:00
|
|
|
|
2023-08-28 21:21:26 +01:00
|
|
|
# Bus modes
|
|
|
|
case [["BUS", index], ["MODE"]]:
|
2023-08-26 20:22:46 +01:00
|
|
|
val = self.cache["busmode"][event]
|
|
|
|
if val != "normal":
|
|
|
|
self.vm.bus[int(index)].mode.normal = True
|
|
|
|
self.cache["busmode"][event] = "normal"
|
|
|
|
else:
|
|
|
|
self.vm.bus[int(index)].mode.composite = True
|
|
|
|
self.cache["busmode"][event] = "composite"
|
2023-09-05 05:30:46 +01:00
|
|
|
label = self.cache["labels"][f"BUS {index}||LABEL"]
|
2023-08-26 20:22:46 +01:00
|
|
|
self.TKroot.after(
|
|
|
|
200,
|
|
|
|
self.nvda.speak,
|
2023-09-02 04:23:15 +01:00
|
|
|
f"{label} bus mode {self.cache['busmode'][event]}",
|
2023-08-26 20:22:46 +01:00
|
|
|
)
|
2023-08-28 21:21:26 +01:00
|
|
|
case [["BUS", index], ["MODE"], ["FOCUS", "IN"]]:
|
2023-09-05 05:30:46 +01:00
|
|
|
label = self.cache["labels"][f"BUS {index}||LABEL"]
|
2023-09-02 04:23:15 +01:00
|
|
|
self.nvda.speak(f"{label} bus mode {self.cache['busmode'][f'BUS {index}||MODE']}")
|
2023-09-04 07:40:14 +01:00
|
|
|
case [["BUS", index], ["MODE"], ["KEY", "ENTER"]]:
|
|
|
|
self.find_element_with_focus().click()
|
2023-08-26 20:22:46 +01:00
|
|
|
|
|
|
|
# Unknown
|
2023-08-22 02:04:00 +01:00
|
|
|
case _:
|
2023-08-22 05:16:43 +01:00
|
|
|
self.logger.error(f"Unknown event {event}")
|
2023-08-26 19:46:39 +01:00
|
|
|
self.logger.debug(f"parsed::{parsed_cmd}")
|
2023-08-22 02:04:00 +01:00
|
|
|
|
|
|
|
|
2023-08-28 03:25:39 +01:00
|
|
|
def request_window_object(kind_id, vm):
|
2023-08-25 20:23:21 +01:00
|
|
|
NVDAVMWindow_cls = NVDAVMWindow
|
2023-08-28 03:25:39 +01:00
|
|
|
return NVDAVMWindow_cls(f"Voicemeeter {kind_id.capitalize()} NVDA", vm)
|