From e1fb16c32bf632809848de98f92c330c607b6228 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 26 Aug 2023 20:22:46 +0100 Subject: [PATCH] implements: buses tab composite buttons bus composite events --- src/nvda_voicemeeter/builder.py | 22 ++++++++++++++++++++-- src/nvda_voicemeeter/models.py | 4 ++++ src/nvda_voicemeeter/window.py | 31 +++++++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/nvda_voicemeeter/builder.py b/src/nvda_voicemeeter/builder.py index ad8544e..b337283 100644 --- a/src/nvda_voicemeeter/builder.py +++ b/src/nvda_voicemeeter/builder.py @@ -37,10 +37,16 @@ class Builder: for step in steps: layout2.append([step()]) + layout3 = [] + steps = (self.make_tab3_rows,) + for step in steps: + layout3.append([step()]) + tab1 = psg.Tab("Settings", layout0, key="settings") tab2 = psg.Tab("Physical Strips", layout1, key="physical strip") tab3 = psg.Tab("Virtual Strips", layout2, key="virtual strip") - tab_group = psg.TabGroup([[tab1, tab2, tab3]], change_submits=True, key="tabs") + tab4 = psg.Tab("Buses", layout3, key="buses") + tab_group = psg.TabGroup([[tab1, tab2, tab3, tab4]], change_submits=True, key="tabs") return [[menu], [tab_group]] @@ -227,5 +233,17 @@ class Builder: return psg.Frame(self.vm.strip[i].label, outputs) def make_tab2_rows(self) -> psg.Frame: - layout = [[self.make_tab1_row(i)] for i in range(self.kind.phys_in, self.kind.phys_in + self.kind.virt_in)] + layout = [[self.make_tab2_row(i)] for i in range(self.kind.phys_in, self.kind.phys_in + self.kind.virt_in)] + return psg.Frame(None, layout, border_width=0) + + def make_tab3_row(self, i): + def add_strip_outputs(layout): + layout.append([psg.Button(f"COMPOSITE", size=(16, 2), key=f"BUS {i}||COMPOSITE")]) + + buses = list() + [step(buses) for step in (add_strip_outputs,)] + return psg.Frame(self.vm.bus[i].label, buses) + + def make_tab3_rows(self): + layout = [[self.make_tab3_row(i)] for i in range(self.kind.num_bus)] return psg.Frame(None, layout, border_width=0) diff --git a/src/nvda_voicemeeter/models.py b/src/nvda_voicemeeter/models.py index 233bd19..eec5969 100644 --- a/src/nvda_voicemeeter/models.py +++ b/src/nvda_voicemeeter/models.py @@ -26,6 +26,10 @@ def _make_output_cache(vm) -> dict: } +def _make_bus_mode_cache(vm) -> dict: + return {**{f"BUS {i}||COMPOSITE": vm.bus[i].mode.get() for i in range(vm.kind.num_bus)}} + + _patch_insert_channels = ( "left", "right", diff --git a/src/nvda_voicemeeter/window.py b/src/nvda_voicemeeter/window.py index 30a324c..583ed10 100644 --- a/src/nvda_voicemeeter/window.py +++ b/src/nvda_voicemeeter/window.py @@ -3,7 +3,7 @@ import logging import PySimpleGUI as psg from .builder import Builder -from .models import _make_output_cache, _patch_insert_channels +from .models import _make_bus_mode_cache, _make_output_cache, _patch_insert_channels from .nvda import Nvda from .parser import Parser from .util import ( @@ -24,7 +24,7 @@ class NVDAVMWindow(psg.Window): self.vm = vm self.kind = self.vm.kind self.logger = logger.getChild(type(self).__name__) - self.cache = {"outputs": _make_output_cache(self.vm)} + self.cache = {"outputs": _make_output_cache(self.vm), "busmode": _make_bus_mode_cache(self.vm)} self.nvda = Nvda() self.parser = Parser() self.builder = Builder(self) @@ -79,6 +79,10 @@ class NVDAVMWindow(psg.Window): for j in range(self.kind.virt_out): self[f"STRIP {i}||B{j + 1}"].bind("", "||FOCUS IN") + # Bus Composites + for j in range(self.kind.num_bus): + self[f"BUS {i}||COMPOSITE"].bind("", "||FOCUS IN") + def run(self): """ Parses the event string and matches it to events @@ -200,6 +204,29 @@ class NVDAVMWindow(psg.Window): val = self.cache["outputs"][f"STRIP {index}||{output}"] label = self.vm.strip[int(index)].label self.nvda.speak(f"STRIP {index} {output} {label if label else ''} {'on' if val else 'off'}") + + # Bus composite + case [["BUS", index], ["COMPOSITE"]]: + 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" + label = self.vm.bus[int(index)].label + self.TKroot.after( + 200, + self.nvda.speak, + f"BUS {index} {label if label else ''} bus mode {self.cache['busmode'][event]}", + ) + case [["BUS", index], ["COMPOSITE"], ["FOCUS", "IN"]]: + label = self.vm.bus[int(index)].label + self.nvda.speak( + f"BUS {index} {label if label else ''} bus mode {self.cache['busmode'][f'BUS {index}||COMPOSITE']}" + ) + + # Unknown case _: self.logger.error(f"Unknown event {event}") self.logger.debug(f"parsed::{parsed_cmd}")