2023-08-22 02:52:03 +01:00
|
|
|
import logging
|
|
|
|
|
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-08-22 20:41:44 +01:00
|
|
|
from .models import _make_cache, _patch_insert_channels
|
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 (
|
|
|
|
get_asio_checkbox_index,
|
|
|
|
get_insert_checkbox_index,
|
|
|
|
get_patch_composite_list,
|
|
|
|
)
|
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-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-08-25 02:19:01 +01:00
|
|
|
self.cache = {}
|
2023-08-22 02:04:00 +01:00
|
|
|
self.nvda = Nvda()
|
|
|
|
self.parser = Parser()
|
2023-08-22 16:11:24 +01:00
|
|
|
self.builder = Builder(self, self.vm)
|
|
|
|
layout = self.builder.run()
|
|
|
|
super().__init__(title, layout, finalize=True)
|
2023-08-25 20:41:48 +01:00
|
|
|
[self[f"HARDWARE OUT||A{i + 1}"].Widget.config(takefocus=1) for i in range(self.kind.phys_out)]
|
|
|
|
[self[f"PATCH COMPOSITE||PC{i + 1}"].Widget.config(takefocus=1) for i in range(self.kind.phys_out)]
|
2023-08-22 02:52:03 +01:00
|
|
|
self.register_events()
|
2023-08-22 02:04:00 +01:00
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
|
|
self.close()
|
|
|
|
|
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-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-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-25 20:41:48 +01:00
|
|
|
for i in range(self.vm.kind.phys_out):
|
|
|
|
self[f"PATCH COMPOSITE||PC{i + 1}"].bind("<FocusIn>", "||FOCUS IN")
|
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-23 02:31:15 +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")
|
|
|
|
for j in range(self.kind.virt_out):
|
|
|
|
self[f"STRIP {i}||B{j + 1}"].bind("<FocusIn>", "||FOCUS IN")
|
|
|
|
|
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-25 22:25:30 +01:00
|
|
|
self.logger.debug(f"event::{event}\nvalues::{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
|
|
|
continue
|
|
|
|
|
2023-08-23 02:04:18 +01:00
|
|
|
match parsed_cmd := self.parser.match.parseString(event):
|
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-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}")
|
|
|
|
|
|
|
|
# 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-22 02:04:00 +01:00
|
|
|
case _:
|
2023-08-22 05:16:43 +01:00
|
|
|
self.logger.error(f"Unknown event {event}")
|
2023-08-23 02:04:18 +01:00
|
|
|
self.logger.debug(parsed_cmd)
|
2023-08-22 02:04:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
def request_window_object(title, vm):
|
2023-08-25 20:23:21 +01:00
|
|
|
NVDAVMWindow_cls = NVDAVMWindow
|
|
|
|
return NVDAVMWindow_cls(title, vm)
|