update timing adjusted

deregister as observer moved into teardown functions.

check index against num_strip, num_bus in level updates

patch bump
This commit is contained in:
onyx-and-iris 2022-07-07 01:22:57 +01:00
parent 8790e24ff3
commit 4118002b0a
6 changed files with 56 additions and 71 deletions

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "voicemeeter-compact"
version = "1.0.7"
version = "1.0.8"
description = "A Compact Voicemeeter Remote App"
authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT"
@ -16,7 +16,7 @@ include = ["vmcompact/img/cat.ico"]
python = "^3.11"
sv-ttk = "^0.1"
voicemeeter-api = { version = "^0.2.1", python = "^3.10" }
vban-cmd = { version = "^1.1.0", python = "^3.10" }
vban-cmd = { version = "^1.1.1", python = "^3.10" }
[tool.poetry.dev-dependencies]
black = {version = "^22.6.0", allow-prereleases = true}

View File

@ -23,7 +23,8 @@ class ChannelLabelFrame(ttk.LabelFrame):
self.builder.add_mute_button()
self.builder.add_conf_button()
self.builder.add_gain_label()
self.sync()
self.sync_params()
self.sync_labels()
self.grid_configure()
self.configbuilder = builders.MainFrameBuilder(self.parent.parent)
@ -96,9 +97,13 @@ class ChannelLabelFrame(ttk.LabelFrame):
background=f'{"yellow" if self.conf.get() else "white"}',
)
def sync(self):
self.after(_base_values.pdelay, self.sync_params)
self.after(100, self.sync_labels)
def on_update(self, subject):
if subject == "ldirty":
self.upd_levels()
elif subject == "pdirty":
self.sync_params()
elif subject == "labelframe":
self.after(5, self.sync_labels)
def sync_params(self):
"""sync parameter states, update button colours"""
@ -160,14 +165,12 @@ class Strip(ChannelLabelFrame):
"""
Updates level values.
"""
if self.index < self.parent.parent.kind.num_strip:
if self.target.levels.is_updated:
val = max(self.target.levels.prefader)
self.level.set((0 if self.mute.get() else 100 + val - 18 + self.gain.get()))
def on_update(self, subject):
"""update levels"""
if subject == "ldirty":
self.after(_base_values.ldelay, self.upd_levels)
self.level.set(
(0 if self.mute.get() else 100 + val - 18 + self.gain.get())
)
class Bus(ChannelLabelFrame):
@ -185,15 +188,11 @@ class Bus(ChannelLabelFrame):
return getattr(_target, self.identifier)[self.index]
def upd_levels(self):
if self.index < self.parent.parent.kind.num_bus:
if self.target.levels.is_updated:
val = max(self.target.levels.all)
self.level.set((0 if self.mute.get() else 100 + val - 18))
def on_update(self, subject):
"""update levels"""
if subject == "ldirty":
self.after(_base_values.ldelay, self.upd_levels)
class ChannelFrame(ttk.Frame):
def init(self, parent, id):
@ -202,8 +201,6 @@ class ChannelFrame(ttk.Frame):
self.id = id
self.phys_in, self.virt_in = parent.kind.ins
self.phys_out, self.virt_out = parent.kind.outs
# registers channelframe as pdirty observer
self.parent.subject.add(self)
@property
@ -226,6 +223,11 @@ class ChannelFrame(ttk.Frame):
if isinstance(frame, ttk.LabelFrame)
)
def on_update(self, subject):
if subject == "pdirty":
for labelframe in self.labelframes:
labelframe.on_update("labelframe")
def grid_configure(self):
[
self.columnconfigure(i, minsize=_configuration.level_width)
@ -233,18 +235,8 @@ class ChannelFrame(ttk.Frame):
]
[self.rowconfigure(0, minsize=100) for i, _ in enumerate(self.labelframes)]
def upd_labelframe(self, labelframe):
labelframe.sync()
def on_update(self, subject):
"""update parameters"""
if subject == "pdirty":
for labelframe in self.labelframes:
self.after(1, self.upd_labelframe, labelframe)
def teardown(self):
# deregisters channelframe as pdirty observer
[self.parent.subject.remove(frame) for frame in self.labelframes]
self.parent.subject.remove(self)
self.destroy()
setattr(self.parent, f"{self.identifier}_frame", None)
@ -293,7 +285,7 @@ def _make_channelframe(parent, id):
if id == "strip":
CHANNELFRAME_cls = type(
f"ChannelFrame{id.capitalize}",
f"ChannelFrame{id.capitalize()}",
(ChannelFrame,),
{
"__init__": init_strip,
@ -301,7 +293,7 @@ def _make_channelframe(parent, id):
)
else:
CHANNELFRAME_cls = type(
f"ChannelFrame{id.capitalize}",
f"ChannelFrame{id.capitalize()}",
(ChannelFrame,),
{
"__init__": init_bus,

View File

@ -71,7 +71,7 @@ class Config(ttk.Frame):
def on_update(self, subject):
"""update parameters"""
if subject == "pdirty":
self.after(_base_values.pdelay, self.sync)
self.sync()
class StripConfig(Config):

View File

@ -51,10 +51,6 @@ class BaseValues(metaclass=SingletonMeta):
dragging: bool = False
# a vban connection established
vban_connected: bool = False
# pdirty delay
pdelay: int = 1
# ldirty delay
ldelay: int = 5
_base_values = BaseValues()

View File

@ -26,7 +26,8 @@ class GainLayer(ttk.LabelFrame):
self.builder.add_scale()
self.builder.add_gain_label()
self.builder.add_on_button()
self.sync()
self.sync_params()
self.sync_labels()
self.grid_configure()
@property
@ -94,9 +95,13 @@ class GainLayer(ttk.LabelFrame):
background=f'{"green" if self.on.get() else "white"}',
)
def sync(self):
self.after(_base_values.pdelay, self.sync_params)
self.after(100, self.sync_labels)
def on_update(self, subject):
if subject == "ldirty":
self.upd_levels()
elif subject == "pdirty":
self.sync_params()
elif subject == "labelframe":
self.after(5, self.sync_labels)
def sync_params(self):
self.gain.set(self.getter("gain"))
@ -142,11 +147,6 @@ class GainLayer(ttk.LabelFrame):
)
)
def on_update(self, subject):
"""update levels"""
if subject == "ldirty":
self.after(_base_values.ldelay, self.upd_levels)
def grid_configure(self):
[
child.grid_configure(padx=1, pady=1, sticky=(tk.N, tk.S, tk.W, tk.E))
@ -200,9 +200,6 @@ class SubMixFrame(ttk.Frame):
else:
self.grid(row=2, column=0, sticky=(tk.W))
# registers submixframe as pdirty observer
self.parent.subject.add(self)
self.grid_configure()
"""
Grids each labelframe, grid_removes any without a label
@ -213,6 +210,8 @@ class SubMixFrame(ttk.Frame):
self.columnconfigure(i, minsize=0)
labelframe.grid_remove()
self.parent.subject.add(self)
@property
def target(self):
"""returns the current interface"""
@ -229,6 +228,11 @@ class SubMixFrame(ttk.Frame):
if isinstance(frame, ttk.LabelFrame)
)
def on_update(self, subject):
if subject == "pdirty":
for labelframe in self.labelframes:
labelframe.on_update("labelframe")
def grid_configure(self):
[
self.columnconfigure(i, minsize=_configuration.level_width)
@ -239,15 +243,8 @@ class SubMixFrame(ttk.Frame):
for i, _ in enumerate(self.labelframes)
]
def upd_labelframe(self, labelframe):
labelframe.sync()
def on_update(self, subject):
if subject == "pdirty":
for labelframe in self.labelframes:
self.after(1, self.upd_labelframe, labelframe)
def teardown(self):
# deregisters submixframe as pdirty observer
[self.parent.subject.remove(frame) for frame in self.gainlayers]
self.parent.subject.remove(self)
self.destroy()