implements up/down slider mode binds

adjustments to pdirty event toggling.

press/release events defined for slider binds

note:
the main window no longer returns keyboard events

minor bump
This commit is contained in:
onyx-and-iris 2023-09-23 16:36:48 +01:00
parent 893f9f59ff
commit 0dd6c89f96
2 changed files with 274 additions and 233 deletions

View File

@ -1,6 +1,6 @@
[project] [project]
name = "nvda_voicemeeter" name = "nvda_voicemeeter"
version = "0.3.1" version = "0.4.0"
description = "A Voicemeeter app compatible with NVDA" description = "A Voicemeeter app compatible with NVDA"
authors = [ authors = [
{ name = "onyx-and-iris", email = "code@onyxandiris.online" }, { name = "onyx-and-iris", email = "code@onyxandiris.online" },

View File

@ -38,7 +38,7 @@ class NVDAVMWindow(psg.Window):
self.popup = Popup(self) self.popup = Popup(self)
self.builder = Builder(self) self.builder = Builder(self)
layout = self.builder.run() layout = self.builder.run()
super().__init__(title, layout, return_keyboard_events=True, finalize=True) super().__init__(title, layout, return_keyboard_events=False, finalize=True)
buttonmenu_opts = {"takefocus": 1, "highlightthickness": 1} buttonmenu_opts = {"takefocus": 1, "highlightthickness": 1}
for i in range(self.kind.phys_in): for i in range(self.kind.phys_in):
self[f"HARDWARE IN||{i + 1}"].Widget.config(**buttonmenu_opts) self[f"HARDWARE IN||{i + 1}"].Widget.config(**buttonmenu_opts)
@ -142,6 +142,7 @@ class NVDAVMWindow(psg.Window):
self[f"tabgroup||{tabname}"].bind("<Shift-KeyPress-Tab>", "||KEY SHIFT TAB") self[f"tabgroup||{tabname}"].bind("<Shift-KeyPress-Tab>", "||KEY SHIFT TAB")
self.bind("<Control-KeyPress-Tab>", "CTRL-TAB") self.bind("<Control-KeyPress-Tab>", "CTRL-TAB")
self.bind("<Control-Shift-KeyPress-Tab>", "CTRL-SHIFT-TAB") self.bind("<Control-Shift-KeyPress-Tab>", "CTRL-SHIFT-TAB")
self.bind("<F2>", "F2")
# NAV # NAV
self.bind("<Control-a>", "CTRL-A") self.bind("<Control-a>", "CTRL-A")
@ -168,13 +169,14 @@ class NVDAVMWindow(psg.Window):
self.bind("<Control-t>", "GATE MODE") self.bind("<Control-t>", "GATE MODE")
self.bind("<Control-d>", "DENOISER MODE") self.bind("<Control-d>", "DENOISER MODE")
self.bind("<Control-l>", "LIMIT MODE") self.bind("<Control-l>", "LIMIT MODE")
self.bind("<Escape>", "ESCAPE")
self.bind("<Alt-Left>", "LEFT") for event in ("KeyPress", "KeyRelease"):
self.bind("<Alt-Right>", "RIGHT") event_id = event.removeprefix("Key").upper()
self.bind("<Alt-Shift-KeyPress-Left>", "SHIFT-LEFT") for direction in ("Left", "Right", "Up", "Down"):
self.bind("<Alt-Shift-KeyPress-Right>", "SHIFT-RIGHT") self.bind(f"<Alt-{event}-{direction}>", f"ALT {direction.upper()}||{event_id}")
self.bind("<Alt-Control-KeyPress-Left>", "CTRL-LEFT") self.bind(f"<Alt-Shift-{event}-{direction}>", f"ALT SHIFT {direction.upper()}||{event_id}")
self.bind("<Alt-Control-KeyPress-Right>", "CTRL-RIGHT") self.bind(f"<Alt-Control-{event}-{direction}>", f"ALT CTRL {direction.upper()}||{event_id}")
# Hardware In # Hardware In
for i in range(self.vm.kind.phys_in): for i in range(self.vm.kind.phys_in):
@ -243,18 +245,18 @@ class NVDAVMWindow(psg.Window):
for param in util.get_full_slider_params(i, self.kind): for param in util.get_full_slider_params(i, self.kind):
self[f"STRIP {i}||SLIDER {param}"].bind("<FocusIn>", "||FOCUS IN") self[f"STRIP {i}||SLIDER {param}"].bind("<FocusIn>", "||FOCUS IN")
self[f"STRIP {i}||SLIDER {param}"].bind("<FocusOut>", "||FOCUS OUT") self[f"STRIP {i}||SLIDER {param}"].bind("<FocusOut>", "||FOCUS OUT")
self[f"STRIP {i}||SLIDER {param}"].bind("<Left>", "||KEY LEFT") for event in ("KeyPress", "KeyRelease"):
self[f"STRIP {i}||SLIDER {param}"].bind("<Right>", "||KEY RIGHT") event_id = event.removeprefix("Key").upper()
self[f"STRIP {i}||SLIDER {param}"].bind("<Shift-KeyPress-Left>", "||KEY SHIFT LEFT") for direction in ("Left", "Right", "Up", "Down"):
self[f"STRIP {i}||SLIDER {param}"].bind("<Shift-KeyPress-Right>", "||KEY SHIFT RIGHT") self[f"STRIP {i}||SLIDER {param}"].bind(
self[f"STRIP {i}||SLIDER {param}"].bind("<Control-KeyPress-Left>", "||KEY CTRL LEFT") f"<{event}-{direction}>", f"||KEY {direction.upper()} {event_id}"
self[f"STRIP {i}||SLIDER {param}"].bind("<Control-KeyPress-Right>", "||KEY CTRL RIGHT") )
self[f"STRIP {i}||SLIDER {param}"].bind("<Up>", "||KEY UP") self[f"STRIP {i}||SLIDER {param}"].bind(
self[f"STRIP {i}||SLIDER {param}"].bind("<Down>", "||KEY DOWN") f"<Shift-{event}-{direction}>", f"||KEY SHIFT {direction.upper()} {event_id}"
self[f"STRIP {i}||SLIDER {param}"].bind("<Shift-KeyPress-Up>", "||KEY SHIFT UP") )
self[f"STRIP {i}||SLIDER {param}"].bind("<Shift-KeyPress-Down>", "||KEY SHIFT DOWN") self[f"STRIP {i}||SLIDER {param}"].bind(
self[f"STRIP {i}||SLIDER {param}"].bind("<Control-KeyPress-Up>", "||KEY CTRL UP") f"<Control-{event}-{direction}>", f"||KEY CTRL {direction.upper()} {event_id}"
self[f"STRIP {i}||SLIDER {param}"].bind("<Control-KeyPress-Down>", "||KEY CTRL DOWN") )
self[f"STRIP {i}||SLIDER {param}"].bind("<Control-Shift-KeyPress-R>", "||KEY CTRL SHIFT R") self[f"STRIP {i}||SLIDER {param}"].bind("<Control-Shift-KeyPress-R>", "||KEY CTRL SHIFT R")
# Bus Params # Bus Params
@ -268,20 +270,18 @@ class NVDAVMWindow(psg.Window):
# Bus Sliders # Bus Sliders
for i in range(self.kind.num_bus): for i in range(self.kind.num_bus):
self[f"BUS {i}||SLIDER GAIN"].bind("<FocusIn>", "||FOCUS IN") for event in ("KeyPress", "KeyRelease"):
self[f"BUS {i}||SLIDER GAIN"].bind("<FocusOut>", "||FOCUS OUT") event_id = event.removeprefix("Key").upper()
self[f"BUS {i}||SLIDER GAIN"].bind("<Left>", "||KEY LEFT") for direction in ("Left", "Right", "Up", "Down"):
self[f"BUS {i}||SLIDER GAIN"].bind("<Right>", "||KEY RIGHT") self[f"BUS {i}||SLIDER GAIN"].bind(
self[f"BUS {i}||SLIDER GAIN"].bind("<Shift-KeyPress-Left>", "||KEY SHIFT LEFT") f"<{event}-{direction}>", f"||KEY {direction.upper()} {event_id}"
self[f"BUS {i}||SLIDER GAIN"].bind("<Shift-KeyPress-Right>", "||KEY SHIFT RIGHT") )
self[f"BUS {i}||SLIDER GAIN"].bind("<Control-KeyPress-Left>", "||KEY CTRL LEFT") self[f"BUS {i}||SLIDER GAIN"].bind(
self[f"BUS {i}||SLIDER GAIN"].bind("<Control-KeyPress-Right>", "||KEY CTRL RIGHT") f"<Shift-{event}-{direction}>", f"||KEY SHIFT {direction.upper()} {event_id}"
self[f"BUS {i}||SLIDER GAIN"].bind("<Up>", "||KEY UP") )
self[f"BUS {i}||SLIDER GAIN"].bind("<Down>", "||KEY DOWN") self[f"BUS {i}||SLIDER GAIN"].bind(
self[f"BUS {i}||SLIDER GAIN"].bind("<Shift-KeyPress-Up>", "||KEY SHIFT UP") f"<Control-{event}-{direction}>", f"||KEY CTRL {direction.upper()} {event_id}"
self[f"BUS {i}||SLIDER GAIN"].bind("<Shift-KeyPress-Down>", "||KEY SHIFT DOWN") )
self[f"BUS {i}||SLIDER GAIN"].bind("<Control-KeyPress-Up>", "||KEY CTRL UP")
self[f"BUS {i}||SLIDER GAIN"].bind("<Control-KeyPress-Down>", "||KEY CTRL DOWN")
self[f"BUS {i}||SLIDER GAIN"].bind("<Control-Shift-KeyPress-R>", "||KEY CTRL SHIFT R") self[f"BUS {i}||SLIDER GAIN"].bind("<Control-Shift-KeyPress-R>", "||KEY CTRL SHIFT R")
def run(self): def run(self):
@ -301,17 +301,25 @@ class NVDAVMWindow(psg.Window):
elif event.endswith("MODE"): elif event.endswith("MODE"):
mode = event mode = event
self.nvda.speak(f"{mode} enabled") self.nvda.speak(f"{mode} enabled")
elif event == "Escape:27": continue
elif event == "ESCAPE":
if mode: if mode:
self.nvda.speak(f"{mode} disabled") self.nvda.speak(f"{mode} disabled")
mode = None mode = None
if mode:
if event in ("LEFT", "RIGHT", "SHIFT-LEFT", "SHIFT-RIGHT", "CTRL-LEFT", "CTRL-RIGHT"):
self.write_event_value(f"SLIDER-MODE-{event}", mode.split()[0])
continue continue
match parsed_cmd := self.parser.match.parseString(event): match parsed_cmd := self.parser.match.parseString(event):
# Slide mode
case [["ALT", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction], ["PRESS" | "RELEASE" as e]]:
if mode:
self.write_event_value(f"SLIDER MODE {direction}||{e}", mode.split()[0])
case [
["ALT", "SHIFT" | "CTRL" as modifier, "LEFT" | "RIGHT" | "UP" | "DOWN" as direction],
["PRESS" | "RELEASE" as e],
]:
if mode:
self.write_event_value(f"SLIDER MODE {modifier} {direction}||{e}", mode.split()[0])
# Focus tabgroup # Focus tabgroup
case ["CTRL-TAB"] | ["CTRL-SHIFT-TAB"]: case ["CTRL-TAB"] | ["CTRL-SHIFT-TAB"]:
self["tabgroup"].set_focus() self["tabgroup"].set_focus()
@ -379,13 +387,19 @@ class NVDAVMWindow(psg.Window):
if focus := self.find_element_with_focus(): if focus := self.find_element_with_focus():
identifier, param = focus.Key.split("||") identifier, param = focus.Key.split("||")
self.write_event_value(f"{identifier}||MUTE", None) self.write_event_value(f"{identifier}||MUTE", None)
case [["SLIDER", "MODE", direction], ["PRESS" | "RELEASE" as e]]:
if values["tabgroup"] not in ("tab||Physical Strip", "tab||Virtual Strip", "tab||Buses"):
continue
param = values[event]
if focus := self.find_element_with_focus():
identifier, partial = focus.Key.split("||")
_, index = identifier.split()
if param in util.get_full_slider_params(int(index), self.kind):
if "SLIDER" not in partial:
self.write_event_value(f"{identifier}||SLIDER {param}||KEY {direction} {e}", None)
case [ case [
"SLIDER-MODE-LEFT" ["SLIDER", "MODE", "SHIFT" | "CTRL" as modifier, direction],
| "SLIDER-MODE-RIGHT" ["PRESS" | "RELEASE" as e],
| "SLIDER-MODE-SHIFT-LEFT"
| "SLIDER-MODE-SHIFT-RIGHT"
| "SLIDER-MODE-CTRL-LEFT"
| "SLIDER-MODE-CTRL-RIGHT" as op
]: ]:
if values["tabgroup"] not in ("tab||Physical Strip", "tab||Virtual Strip", "tab||Buses"): if values["tabgroup"] not in ("tab||Physical Strip", "tab||Virtual Strip", "tab||Buses"):
continue continue
@ -395,11 +409,12 @@ class NVDAVMWindow(psg.Window):
_, index = identifier.split() _, index = identifier.split()
if param in util.get_full_slider_params(int(index), self.kind): if param in util.get_full_slider_params(int(index), self.kind):
if "SLIDER" not in partial: if "SLIDER" not in partial:
op = op.removeprefix("SLIDER-MODE-").split("-") self.write_event_value(
self.write_event_value(f"{identifier}||SLIDER {param}||KEY {' '.join(op)}", None) f"{identifier}||SLIDER {param}||KEY {modifier} {direction} {e}", None
)
# Rename popups # Rename popups
case ["F2:113"]: case ["F2"]:
tab = values["tabgroup"].split("||")[1] tab = values["tabgroup"].split("||")[1]
if tab in ("Physical Strip", "Virtual Strip", "Buses"): if tab in ("Physical Strip", "Virtual Strip", "Buses"):
if focus := self.find_element_with_focus(): if focus := self.find_element_with_focus():
@ -711,7 +726,6 @@ class NVDAVMWindow(psg.Window):
["FOCUS", "IN"], ["FOCUS", "IN"],
]: ]:
if self.find_element_with_focus() is not None: if self.find_element_with_focus() is not None:
self.vm.event.pdirty = False
val = values[f"STRIP {index}||SLIDER {param}"] val = values[f"STRIP {index}||SLIDER {param}"]
label = self.cache["labels"][f"STRIP {index}||LABEL"] label = self.cache["labels"][f"STRIP {index}||LABEL"]
self.nvda.speak(f"{label} {param} {int(val) if param == 'LIMIT' else val}") self.nvda.speak(f"{label} {param} {int(val) if param == 'LIMIT' else val}")
@ -723,7 +737,7 @@ class NVDAVMWindow(psg.Window):
], ],
["FOCUS", "OUT"], ["FOCUS", "OUT"],
]: ]:
self.vm.event.pdirty = True pass
case [ case [
["STRIP", index], ["STRIP", index],
[ [
@ -738,8 +752,10 @@ class NVDAVMWindow(psg.Window):
| "MID" | "MID"
| "TREBLE" as param, | "TREBLE" as param,
], ],
["KEY", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction], ["KEY", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction, "PRESS" | "RELEASE" as e],
]: ]:
if e == "PRESS":
self.vm.event.pdirty = False
match param: match param:
case "GAIN": case "GAIN":
val = self.vm.strip[int(index)].gain val = self.vm.strip[int(index)].gain
@ -781,6 +797,8 @@ class NVDAVMWindow(psg.Window):
self.vm.strip[int(index)].limit = val self.vm.strip[int(index)].limit = val
self[f"STRIP {index}||SLIDER {param}"].update(value=val) self[f"STRIP {index}||SLIDER {param}"].update(value=val)
self.nvda.speak(str(val)) self.nvda.speak(str(val))
else:
self.vm.event.pdirty = True
case [ case [
["STRIP", index], ["STRIP", index],
[ [
@ -795,8 +813,10 @@ class NVDAVMWindow(psg.Window):
| "MID" | "MID"
| "TREBLE" as param, | "TREBLE" as param,
], ],
["KEY", "CTRL", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction], ["KEY", "CTRL", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction, "PRESS" | "RELEASE" as e],
]: ]:
if e == "PRESS":
self.vm.event.pdirty = False
match param: match param:
case "GAIN": case "GAIN":
val = self.vm.strip[int(index)].gain val = self.vm.strip[int(index)].gain
@ -844,6 +864,8 @@ class NVDAVMWindow(psg.Window):
self.vm.strip[int(index)].limit = val self.vm.strip[int(index)].limit = val
self[f"STRIP {index}||SLIDER {param}"].update(value=val) self[f"STRIP {index}||SLIDER {param}"].update(value=val)
self.nvda.speak(f"{param} {val}") self.nvda.speak(f"{param} {val}")
else:
self.vm.event.pdirty = True
case [ case [
["STRIP", index], ["STRIP", index],
[ [
@ -858,8 +880,10 @@ class NVDAVMWindow(psg.Window):
| "MID" | "MID"
| "TREBLE" as param, | "TREBLE" as param,
], ],
["KEY", "SHIFT", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction], ["KEY", "SHIFT", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction, "PRESS" | "RELEASE" as e],
]: ]:
if e == "PRESS":
self.vm.event.pdirty = False
match param: match param:
case "GAIN": case "GAIN":
val = self.vm.strip[int(index)].gain val = self.vm.strip[int(index)].gain
@ -907,6 +931,8 @@ class NVDAVMWindow(psg.Window):
self.vm.strip[int(index)].limit = val self.vm.strip[int(index)].limit = val
self[f"STRIP {index}||SLIDER {param}"].update(value=val) self[f"STRIP {index}||SLIDER {param}"].update(value=val)
self.nvda.speak(f"{param} {val}") self.nvda.speak(f"{param} {val}")
else:
self.vm.event.pdirty = True
case [["STRIP", index], ["SLIDER", param], ["KEY", "CTRL", "SHIFT", "R"]]: case [["STRIP", index], ["SLIDER", param], ["KEY", "CTRL", "SHIFT", "R"]]:
match param: match param:
case "GAIN": case "GAIN":
@ -992,13 +1018,18 @@ class NVDAVMWindow(psg.Window):
self.vm.bus[int(index)].gain = val self.vm.bus[int(index)].gain = val
case [["BUS", index], ["SLIDER", "GAIN"], ["FOCUS", "IN"]]: case [["BUS", index], ["SLIDER", "GAIN"], ["FOCUS", "IN"]]:
if self.find_element_with_focus() is not None: if self.find_element_with_focus() is not None:
self.vm.event.pdirty = False
label = self.cache["labels"][f"BUS {index}||LABEL"] label = self.cache["labels"][f"BUS {index}||LABEL"]
val = values[f"BUS {index}||SLIDER GAIN"] val = values[f"BUS {index}||SLIDER GAIN"]
self.nvda.speak(f"{label} gain {val}") self.nvda.speak(f"{label} gain {val}")
case [["BUS", index], ["SLIDER", "GAIN"], ["FOCUS", "OUT"]]: case [["BUS", index], ["SLIDER", "GAIN"], ["FOCUS", "OUT"]]:
self.vm.event.pdirty = True pass
case [["BUS", index], ["SLIDER", "GAIN"], ["KEY", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction]]: case [
["BUS", index],
["SLIDER", "GAIN"],
["KEY", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction, "PRESS" | "RELEASE" as e],
]:
if e == "PRESS":
self.vm.event.pdirty = False
val = self.vm.bus[int(index)].gain val = self.vm.bus[int(index)].gain
match direction: match direction:
case "RIGHT" | "UP": case "RIGHT" | "UP":
@ -1009,11 +1040,15 @@ class NVDAVMWindow(psg.Window):
self.vm.bus[int(index)].gain = val self.vm.bus[int(index)].gain = val
self[f"BUS {index}||SLIDER GAIN"].update(value=val) self[f"BUS {index}||SLIDER GAIN"].update(value=val)
self.nvda.speak(str(val)) self.nvda.speak(str(val))
else:
self.vm.event.pdirty = True
case [ case [
["BUS", index], ["BUS", index],
["SLIDER", "GAIN"], ["SLIDER", "GAIN"],
["KEY", "CTRL", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction], ["KEY", "CTRL", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction, "PRESS" | "RELEASE" as e],
]: ]:
if e == "PRESS":
self.vm.event.pdirty = False
val = self.vm.bus[int(index)].gain val = self.vm.bus[int(index)].gain
match direction: match direction:
case "RIGHT" | "UP": case "RIGHT" | "UP":
@ -1024,11 +1059,15 @@ class NVDAVMWindow(psg.Window):
self.vm.bus[int(index)].gain = val self.vm.bus[int(index)].gain = val
self[f"BUS {index}||SLIDER GAIN"].update(value=val) self[f"BUS {index}||SLIDER GAIN"].update(value=val)
self.nvda.speak(str(val)) self.nvda.speak(str(val))
else:
self.vm.event.pdirty = True
case [ case [
["BUS", index], ["BUS", index],
["SLIDER", "GAIN"], ["SLIDER", "GAIN"],
["KEY", "SHIFT", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction], ["KEY", "SHIFT", "LEFT" | "RIGHT" | "UP" | "DOWN" as direction, "PRESS" | "RELEASE" as e],
]: ]:
if e == "PRESS":
self.vm.event.pdirty = False
val = self.vm.bus[int(index)].gain val = self.vm.bus[int(index)].gain
match direction: match direction:
case "RIGHT" | "UP": case "RIGHT" | "UP":
@ -1039,6 +1078,8 @@ class NVDAVMWindow(psg.Window):
self.vm.bus[int(index)].gain = val self.vm.bus[int(index)].gain = val
self[f"BUS {index}||SLIDER GAIN"].update(value=val) self[f"BUS {index}||SLIDER GAIN"].update(value=val)
self.nvda.speak(str(val)) self.nvda.speak(str(val))
else:
self.vm.event.pdirty = True
case [["BUS", index], ["SLIDER", "GAIN"], ["KEY", "CTRL", "SHIFT", "R"]]: case [["BUS", index], ["SLIDER", "GAIN"], ["KEY", "CTRL", "SHIFT", "R"]]:
self.vm.bus[int(index)].gain = 0 self.vm.bus[int(index)].gain = 0
self[f"BUS {index}||SLIDER GAIN"].update(value=0) self[f"BUS {index}||SLIDER GAIN"].update(value=0)