From 4118002b0ad8d2e5c242cb38583210af72d2b054 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 7 Jul 2022 01:22:57 +0100 Subject: [PATCH] update timing adjusted deregister as observer moved into teardown functions. check index against num_strip, num_bus in level updates patch bump --- pyproject.toml | 4 +-- vmcompact/channels.py | 62 ++++++++++++++++++----------------------- vmcompact/config.py | 2 +- vmcompact/data.py | 4 --- vmcompact/gainlayer.py | 37 +++++++++++------------- vmcompact/navigation.py | 18 ++++++------ 6 files changed, 56 insertions(+), 71 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 42e50ac..24d19c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] 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} diff --git a/vmcompact/channels.py b/vmcompact/channels.py index 99bd3bd..adb7be3 100644 --- a/vmcompact/channels.py +++ b/vmcompact/channels.py @@ -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.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) + 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()) + ) class Bus(ChannelLabelFrame): @@ -185,14 +188,10 @@ class Bus(ChannelLabelFrame): return getattr(_target, self.identifier)[self.index] def upd_levels(self): - 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) + 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)) class ChannelFrame(ttk.Frame): @@ -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, diff --git a/vmcompact/config.py b/vmcompact/config.py index 9d0d4fd..d3a1bdd 100644 --- a/vmcompact/config.py +++ b/vmcompact/config.py @@ -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): diff --git a/vmcompact/data.py b/vmcompact/data.py index f4120c0..407c167 100644 --- a/vmcompact/data.py +++ b/vmcompact/data.py @@ -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() diff --git a/vmcompact/gainlayer.py b/vmcompact/gainlayer.py index 1d99831..4fbcec8 100644 --- a/vmcompact/gainlayer.py +++ b/vmcompact/gainlayer.py @@ -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() diff --git a/vmcompact/navigation.py b/vmcompact/navigation.py index 55bbc59..66d7893 100644 --- a/vmcompact/navigation.py +++ b/vmcompact/navigation.py @@ -75,13 +75,13 @@ class Navigation(ttk.Frame): self.parent.bus_frame = None self.channel_button["state"] = "normal" - if self.parent.submix_frame: - self.parent.submix_frame.teardown() - self.submix.set(False) - if not _configuration.themes_enabled: - self.styletable.configure( - f"Submix.TButton", - background=f'{"purple" if self.submix.get() else "white"}', - ) + if self.parent.submix_frame: + self.parent.submix_frame.teardown() + self.submix.set(False) + if not _configuration.themes_enabled: + self.styletable.configure( + f"Submix.TButton", + background=f'{"purple" if self.submix.get() else "white"}', + ) - self.extend_text.set("REDUCE" if self.extend.get() else "EXTEND") + self.extend_text.set("REDUCE" if self.extend.get() else "EXTEND")