diff --git a/vmcompact/app.py b/vmcompact/app.py index 7c9b68d..d798b0a 100644 --- a/vmcompact/app.py +++ b/vmcompact/app.py @@ -67,10 +67,8 @@ class App(tk.Tk): # start pdirty watcher self.upd_pdirty() - self.strip_levels = None - self.bus_levels = None - self._strip_levels = None - self._bus_levels = None + self.strip_levels = self.target.strip_levels + self.bus_levels = self.target.bus_levels self.watch_levels() self.resizable(False, False) @@ -180,20 +178,16 @@ class App(tk.Tk): self.after(1, self.watch_levels_step) def watch_levels_step(self): - """ - Continuously fetch level arrays, only update - if ldirty - """ - self._strip_levels = self.target.strip_levels - self._bus_levels = self.target.bus_levels + """Continuously fetch level arrays, only update if ldirty""" + _strip_levels = self.target.strip_levels + _bus_levels = self.target.bus_levels + self.comp_strip = [not a == b for a, b in zip(self.strip_levels, _strip_levels)] + self.comp_bus = [not a == b for a, b in zip(self.bus_levels, _bus_levels)] - self.ldirty = not ( - self.strip_levels == self._strip_levels - and self.bus_levels == self._bus_levels - ) + self.ldirty = any(self.comp_strip) or any(self.comp_bus) if self.ldirty: - self.strip_levels = self._strip_levels - self.bus_levels = self._bus_levels + self.strip_levels = _strip_levels + self.bus_levels = _bus_levels self.after(_base_vals.ldelay, self.watch_levels_step) def dragging(self, event, *args): diff --git a/vmcompact/channels.py b/vmcompact/channels.py index 743f1a2..39569a4 100644 --- a/vmcompact/channels.py +++ b/vmcompact/channels.py @@ -175,6 +175,10 @@ class Strip(Channel): def __init__(self, parent, index, id): super().__init__(parent, index, id) + if index <= parent.phys_in: + self.level_offset = index * 2 + else: + self.level_offset = parent.phys_in * 2 + (index - parent.phys_in) * 8 @property def target(self): @@ -207,36 +211,45 @@ class Strip(Channel): def watch_levels_step(self): if not _base_vals.dragging: - if self._parent._parent.ldirty: - if self.index <= self._parent.phys_in: + if ( + self._parent._parent.ldirty + and _base_vals.strip_level_array_size + == len(self._parent._parent.comp_strip) + ): + if self.index <= self._parent.phys_in and any( + self._parent._parent.comp_strip[ + self.level_offset : self.level_offset + 1 + ] + ): vals = ( self.convert_level( - self._parent._parent.strip_levels[self.index * 2] + self._parent._parent.strip_levels[self.level_offset] ), self.convert_level( - self._parent._parent.strip_levels[self.index * 2 + 1] + self._parent._parent.strip_levels[self.level_offset + 1] ), ) - else: + peak = vals[0] if vals[0] > vals[1] else vals[1] + self.level.set( + (0 if self.mute.get() else 100 + (peak - 18) + self.gain.get()) + ) + elif any( + self._parent._parent.comp_strip[ + self.level_offset : self.level_offset + 1 + ] + ): vals = ( self.convert_level( - self._parent._parent.strip_levels[ - self._parent.phys_in * 2 - + (self.index - self._parent.phys_in) * 8 - ] + self._parent._parent.strip_levels[self.level_offset] ), self.convert_level( - self._parent._parent.strip_levels[ - self._parent.phys_in * 2 - + (self.index - self._parent.phys_in) * 8 - + 1 - ] + self._parent._parent.strip_levels[self.level_offset + 1] ), ) - peak = vals[0] if vals[0] > vals[1] else vals[1] - self.level.set( - (0 if self.mute.get() else 100 + (peak - 18) + self.gain.get()) - ) + peak = vals[0] if vals[0] > vals[1] else vals[1] + self.level.set( + (0 if self.mute.get() else 100 + (peak - 18) + self.gain.get()) + ) self.after( _base_vals.ldelay if not _base_vals.in_scale_button_1 else 100, self.watch_levels_step, @@ -248,6 +261,7 @@ class Bus(Channel): def __init__(self, parent, index, id): super().__init__(parent, index, id) + self.level_offset = self.index * 8 @property def target(self): @@ -282,15 +296,24 @@ class Bus(Channel): def watch_levels_step(self): if not _base_vals.dragging: - if self._parent._parent.ldirty: - vals = ( - self.convert_level(self._parent._parent.bus_levels[self.index * 8]), - self.convert_level( - self._parent._parent.bus_levels[self.index * 8 + 1] - ), - ) - peak = vals[0] if vals[0] > vals[1] else vals[1] - self.level.set((0 if self.mute.get() else 100 + (peak - 18))) + if self._parent._parent.ldirty and _base_vals.bus_level_array_size == len( + self._parent._parent.comp_bus + ): + if any( + self._parent._parent.comp_bus[ + self.level_offset : self.level_offset + 1 + ] + ): + vals = ( + self.convert_level( + self._parent._parent.bus_levels[self.level_offset] + ), + self.convert_level( + self._parent._parent.bus_levels[self.level_offset + 1] + ), + ) + peak = vals[0] if vals[0] > vals[1] else vals[1] + self.level.set((0 if self.mute.get() else 100 + (peak - 18))) self.after( _base_vals.ldelay if not _base_vals.in_scale_button_1 else 100, self.watch_levels_step, @@ -312,6 +335,8 @@ class ChannelFrame(ttk.Frame): self._is_strip = is_strip self.phys_in, self.virt_in = parent.kind.ins self.phys_out, self.virt_out = parent.kind.outs + _base_vals.strip_level_array_size = 2 * self.phys_in + 8 * self.virt_in + _base_vals.bus_level_array_size = 8 * (self.phys_out + self.virt_out) defaults = { "width": 80, diff --git a/vmcompact/data.py b/vmcompact/data.py index b601c03..d68044b 100644 --- a/vmcompact/data.py +++ b/vmcompact/data.py @@ -25,6 +25,10 @@ class BaseValues: pdelay: int = 5 # ldirty delay ldelay: int = 50 + # size of strip level array for a kind + strip_level_array_size: int = None + # size of bus level array for a kind + bus_level_array_size: int = None _base_vals = BaseValues() diff --git a/vmcompact/gainlayer.py b/vmcompact/gainlayer.py index c14ffcc..b6c8c0e 100644 --- a/vmcompact/gainlayer.py +++ b/vmcompact/gainlayer.py @@ -18,6 +18,10 @@ class GainLayer(ttk.LabelFrame): self.level = tk.DoubleVar() self.on = tk.BooleanVar() self.s = self._parent._parent.styletable + if index <= parent.phys_in: + self.level_offset = index * 2 + else: + self.level_offset = parent.phys_in * 2 + (index - parent.phys_in) * 8 self.sync() self._make_widgets() @@ -162,42 +166,59 @@ class GainLayer(ttk.LabelFrame): def watch_levels_step(self): if not _base_vals.dragging: - if self._parent._parent.ldirty: - if self.index <= self._parent.phys_in: + if ( + self._parent._parent.ldirty + and _base_vals.strip_level_array_size + == len(self._parent._parent.comp_strip) + ): + if self.index <= self._parent.phys_in and any( + self._parent._parent.comp_strip[ + self.level_offset : self.level_offset + 1 + ] + ): vals = ( self.convert_level( - self._parent._parent.strip_levels[self.index * 2] + self._parent._parent.strip_levels[self.level_offset] ), self.convert_level( - self._parent._parent.strip_levels[self.index * 2 + 1] + self._parent._parent.strip_levels[self.level_offset + 1] ), ) - else: + peak = vals[0] if vals[0] > vals[1] else vals[1] + self.level.set( + ( + 0 + if self._parent._parent.channel_frame.strips[ + self.index + ].mute.get() + or not self.on.get() + else 100 + (peak - 18) + self.gain.get() + ) + ) + elif any( + self._parent._parent.comp_strip[ + self.level_offset : self.level_offset + 1 + ] + ): vals = ( self.convert_level( - self._parent._parent.strip_levels[ - self._parent.phys_in * 2 - + (self.index - self._parent.phys_in) * 8 - ] + self._parent._parent.strip_levels[self.level_offset] ), self.convert_level( - self._parent._parent.strip_levels[ - self._parent.phys_in * 2 - + (self.index - self._parent.phys_in) * 8 - + 1 - ] + self._parent._parent.strip_levels[self.level_offset + 1] ), ) - peak = vals[0] if vals[0] > vals[1] else vals[1] - self.level.set( - ( - 0 - if self._parent._parent.channel_frame.strips[ - self.index - ].mute.get() - else 100 + (peak - 18) + self.gain.get() + peak = vals[0] if vals[0] > vals[1] else vals[1] + self.level.set( + ( + 0 + if self._parent._parent.channel_frame.strips[ + self.index + ].mute.get() + or not self.on.get() + else 100 + (peak - 18) + self.gain.get() + ) ) - ) self.after( _base_vals.ldelay if not _base_vals.in_scale_button_1 else 100, self.watch_levels_step,