From a1c7f1358edf0069ce41bc12f204361ff7209da9 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 26 Aug 2023 21:55:39 +0100 Subject: [PATCH] implements asio buffer --- src/nvda_voicemeeter/builder.py | 33 ++++++++++++++++++++--- src/nvda_voicemeeter/models.py | 12 --------- src/nvda_voicemeeter/util.py | 48 ++++++++++++++++++++++++++++++--- src/nvda_voicemeeter/window.py | 17 +++++++++++- 4 files changed, 90 insertions(+), 20 deletions(-) diff --git a/src/nvda_voicemeeter/builder.py b/src/nvda_voicemeeter/builder.py index b337283..b339e58 100644 --- a/src/nvda_voicemeeter/builder.py +++ b/src/nvda_voicemeeter/builder.py @@ -2,6 +2,7 @@ import PySimpleGUI as psg from .util import ( get_asio_checkbox_index, + get_asio_samples_list, get_input_device_list, get_insert_checkbox_index, get_patch_composite_list, @@ -17,13 +18,19 @@ class Builder: self.kind = self.vm.kind def run(self) -> list: - menu = self.make_menu() + menu = [[self.make_menu()]] layout0 = [] if self.kind.name == "basic": steps = (self.make_tab0_row0,) else: - steps = (self.make_tab0_row0, self.make_tab0_row1, self.make_tab0_row2, self.make_tab0_row3) + steps = ( + self.make_tab0_row0, + self.make_tab0_row1, + self.make_tab0_row2, + self.make_tab0_row3, + self.make_tab0_row4, + ) for step in steps: layout0.append([step()]) @@ -59,7 +66,7 @@ class Builder: ], ], ] - return [[psg.Menu(menu_def, key="menus")]] + return psg.Menu(menu_def, key="menus") def make_tab0_row0(self) -> psg.Frame: """row0 represents hardware outs""" @@ -190,6 +197,26 @@ class Builder: return psg.Frame("PATCH INSERT", asio_checkboxes) + def make_tab0_row4(self) -> psg.Frame: + """row4 represents asio buffer""" + + samples = get_asio_samples_list() + samples.append("Default") + + return psg.Frame( + "ASIO BUFFER", + [ + [ + psg.ButtonMenu( + "ASIO BUFFER", + size=(12, 2), + menu_def=["", samples], + key="ASIO BUFFER", + ) + ] + ], + ) + def make_tab1_row(self, i) -> psg.Frame: def add_strip_outputs(layout): layout.append( diff --git a/src/nvda_voicemeeter/models.py b/src/nvda_voicemeeter/models.py index eec5969..2427901 100644 --- a/src/nvda_voicemeeter/models.py +++ b/src/nvda_voicemeeter/models.py @@ -28,15 +28,3 @@ 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", - "center", - "low frequency effect", - "surround left", - "surround right", - "back left", - "back right", -) diff --git a/src/nvda_voicemeeter/util.py b/src/nvda_voicemeeter/util.py index e71a14b..d62842f 100644 --- a/src/nvda_voicemeeter/util.py +++ b/src/nvda_voicemeeter/util.py @@ -1,10 +1,10 @@ -def get_asio_checkbox_index(channel, num): +def get_asio_checkbox_index(channel, num) -> int: if channel == 0: return 2 * num - 2 return 2 * num - 1 -def get_insert_checkbox_index(kind, channel, num): +def get_insert_checkbox_index(kind, channel, num) -> int: if num <= kind.phys_in: if channel == 0: return 2 * num - 2 @@ -13,11 +13,11 @@ def get_insert_checkbox_index(kind, channel, num): return (2 * kind.phys_in) + (8 * (num - kind.phys_in - 1)) + channel -def get_input_device_list(vm): +def get_input_device_list(vm) -> list: return ["{type}: {name}".format(**vm.device.output(i)) for i in range(vm.device.outs)] -def get_patch_composite_list(kind): +def get_patch_composite_list(kind) -> list: temp = [] for i in range(kind.phys_out): [temp.append(f"IN#{i + 1} {channel}") for channel in ("Left", "Right")] @@ -25,3 +25,43 @@ def get_patch_composite_list(kind): [temp.append(f"IN#{i + 1} {channel}") for channel in ("Left", "Right", "Center", "LFE", "SL", "SR", "BL", "BR")] temp.append(f"BUS Channel") return temp + + +def get_patch_insert_channels() -> list: + return [ + "left", + "right", + "center", + "low frequency effect", + "surround left", + "surround right", + "back left", + "back right", + ] + + +_patch_insert_channels = get_patch_insert_channels() + + +def get_asio_samples_list() -> list: + return [ + "1024", + "768", + "704", + "640", + "576", + "512", + "480", + "448", + "441", + "416", + "384", + "352", + "320", + "288", + "256", + "224", + "192", + "160", + "128", + ] diff --git a/src/nvda_voicemeeter/window.py b/src/nvda_voicemeeter/window.py index 583ed10..394d50d 100644 --- a/src/nvda_voicemeeter/window.py +++ b/src/nvda_voicemeeter/window.py @@ -3,10 +3,11 @@ import logging import PySimpleGUI as psg from .builder import Builder -from .models import _make_bus_mode_cache, _make_output_cache, _patch_insert_channels +from .models import _make_bus_mode_cache, _make_output_cache from .nvda import Nvda from .parser import Parser from .util import ( + _patch_insert_channels, get_asio_checkbox_index, get_insert_checkbox_index, get_patch_composite_list, @@ -33,6 +34,7 @@ class NVDAVMWindow(psg.Window): [self[f"HARDWARE OUT||A{i + 1}"].Widget.config(takefocus=1) for i in range(self.kind.phys_out)] if self.kind.name != "basic": [self[f"PATCH COMPOSITE||PC{i + 1}"].Widget.config(takefocus=1) for i in range(self.kind.phys_out)] + self["ASIO BUFFER"].Widget.config(takefocus=1) self.register_events() self.current_focus = None @@ -83,6 +85,9 @@ class NVDAVMWindow(psg.Window): for j in range(self.kind.num_bus): self[f"BUS {i}||COMPOSITE"].bind("", "||FOCUS IN") + # ASIO Buffer + self[f"ASIO BUFFER"].bind("", "||FOCUS IN") + def run(self): """ Parses the event string and matches it to events @@ -194,6 +199,16 @@ class NVDAVMWindow(psg.Window): num = int(in_num[-1]) self.nvda.speak(f"Patch INSERT IN#{num} {channel} {'on' if val else 'off'}") + # ASIO Buffer + case [["ASIO", "BUFFER"], ["FOCUS", "IN"]]: + self.nvda.speak(f"ASIO BUFFER") + case ["ASIO BUFFER"]: + if values[event] == "Default": + val = 0 + else: + val = values[event] + self.vm.option.buffer("asio", val) + # Strip outputs case [["STRIP", index], [output]]: val = not self.cache["outputs"][f"STRIP {index}||{output}"]