changes to level updates

strip/bus levels compared by index iteratively.

strip/bus level array size added to _base_vals dataclass. Helps to keep track of level array size when switching between kinds.

level_offset class attributes added to strip/bus/gainlayer labelframe classes.

watch_levels adjusted to only updated frames when a level has changed.
This commit is contained in:
onyx-and-iris 2022-04-14 17:25:26 +01:00
parent 4ce288e474
commit 26832b3cb9
4 changed files with 110 additions and 66 deletions

View File

@ -67,10 +67,8 @@ class App(tk.Tk):
# start pdirty watcher # start pdirty watcher
self.upd_pdirty() self.upd_pdirty()
self.strip_levels = None self.strip_levels = self.target.strip_levels
self.bus_levels = None self.bus_levels = self.target.bus_levels
self._strip_levels = None
self._bus_levels = None
self.watch_levels() self.watch_levels()
self.resizable(False, False) self.resizable(False, False)
@ -180,20 +178,16 @@ class App(tk.Tk):
self.after(1, self.watch_levels_step) self.after(1, self.watch_levels_step)
def watch_levels_step(self): def watch_levels_step(self):
""" """Continuously fetch level arrays, only update if ldirty"""
Continuously fetch level arrays, only update _strip_levels = self.target.strip_levels
if ldirty _bus_levels = self.target.bus_levels
""" self.comp_strip = [not a == b for a, b in zip(self.strip_levels, _strip_levels)]
self._strip_levels = self.target.strip_levels self.comp_bus = [not a == b for a, b in zip(self.bus_levels, _bus_levels)]
self._bus_levels = self.target.bus_levels
self.ldirty = not ( self.ldirty = any(self.comp_strip) or any(self.comp_bus)
self.strip_levels == self._strip_levels
and self.bus_levels == self._bus_levels
)
if self.ldirty: if self.ldirty:
self.strip_levels = self._strip_levels self.strip_levels = _strip_levels
self.bus_levels = self._bus_levels self.bus_levels = _bus_levels
self.after(_base_vals.ldelay, self.watch_levels_step) self.after(_base_vals.ldelay, self.watch_levels_step)
def dragging(self, event, *args): def dragging(self, event, *args):

View File

@ -175,6 +175,10 @@ class Strip(Channel):
def __init__(self, parent, index, id): def __init__(self, parent, index, id):
super().__init__(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 @property
def target(self): def target(self):
@ -207,36 +211,45 @@ class Strip(Channel):
def watch_levels_step(self): def watch_levels_step(self):
if not _base_vals.dragging: if not _base_vals.dragging:
if self._parent._parent.ldirty: if (
if self.index <= self._parent.phys_in: 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 = ( vals = (
self.convert_level( self.convert_level(
self._parent._parent.strip_levels[self.index * 2] self._parent._parent.strip_levels[self.level_offset]
), ),
self.convert_level( 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 = ( vals = (
self.convert_level( self.convert_level(
self._parent._parent.strip_levels[ self._parent._parent.strip_levels[self.level_offset]
self._parent.phys_in * 2
+ (self.index - self._parent.phys_in) * 8
]
), ),
self.convert_level( self.convert_level(
self._parent._parent.strip_levels[ self._parent._parent.strip_levels[self.level_offset + 1]
self._parent.phys_in * 2
+ (self.index - self._parent.phys_in) * 8
+ 1
]
), ),
) )
peak = vals[0] if vals[0] > vals[1] else vals[1] peak = vals[0] if vals[0] > vals[1] else vals[1]
self.level.set( self.level.set(
(0 if self.mute.get() else 100 + (peak - 18) + self.gain.get()) (0 if self.mute.get() else 100 + (peak - 18) + self.gain.get())
) )
self.after( self.after(
_base_vals.ldelay if not _base_vals.in_scale_button_1 else 100, _base_vals.ldelay if not _base_vals.in_scale_button_1 else 100,
self.watch_levels_step, self.watch_levels_step,
@ -248,6 +261,7 @@ class Bus(Channel):
def __init__(self, parent, index, id): def __init__(self, parent, index, id):
super().__init__(parent, index, id) super().__init__(parent, index, id)
self.level_offset = self.index * 8
@property @property
def target(self): def target(self):
@ -282,15 +296,24 @@ class Bus(Channel):
def watch_levels_step(self): def watch_levels_step(self):
if not _base_vals.dragging: if not _base_vals.dragging:
if self._parent._parent.ldirty: if self._parent._parent.ldirty and _base_vals.bus_level_array_size == len(
vals = ( self._parent._parent.comp_bus
self.convert_level(self._parent._parent.bus_levels[self.index * 8]), ):
self.convert_level( if any(
self._parent._parent.bus_levels[self.index * 8 + 1] self._parent._parent.comp_bus[
), self.level_offset : 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))) 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( self.after(
_base_vals.ldelay if not _base_vals.in_scale_button_1 else 100, _base_vals.ldelay if not _base_vals.in_scale_button_1 else 100,
self.watch_levels_step, self.watch_levels_step,
@ -312,6 +335,8 @@ class ChannelFrame(ttk.Frame):
self._is_strip = is_strip self._is_strip = is_strip
self.phys_in, self.virt_in = parent.kind.ins self.phys_in, self.virt_in = parent.kind.ins
self.phys_out, self.virt_out = parent.kind.outs 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 = { defaults = {
"width": 80, "width": 80,

View File

@ -25,6 +25,10 @@ class BaseValues:
pdelay: int = 5 pdelay: int = 5
# ldirty delay # ldirty delay
ldelay: int = 50 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() _base_vals = BaseValues()

View File

@ -18,6 +18,10 @@ class GainLayer(ttk.LabelFrame):
self.level = tk.DoubleVar() self.level = tk.DoubleVar()
self.on = tk.BooleanVar() self.on = tk.BooleanVar()
self.s = self._parent._parent.styletable 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.sync()
self._make_widgets() self._make_widgets()
@ -162,42 +166,59 @@ class GainLayer(ttk.LabelFrame):
def watch_levels_step(self): def watch_levels_step(self):
if not _base_vals.dragging: if not _base_vals.dragging:
if self._parent._parent.ldirty: if (
if self.index <= self._parent.phys_in: 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 = ( vals = (
self.convert_level( self.convert_level(
self._parent._parent.strip_levels[self.index * 2] self._parent._parent.strip_levels[self.level_offset]
), ),
self.convert_level( 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 = ( vals = (
self.convert_level( self.convert_level(
self._parent._parent.strip_levels[ self._parent._parent.strip_levels[self.level_offset]
self._parent.phys_in * 2
+ (self.index - self._parent.phys_in) * 8
]
), ),
self.convert_level( self.convert_level(
self._parent._parent.strip_levels[ self._parent._parent.strip_levels[self.level_offset + 1]
self._parent.phys_in * 2
+ (self.index - self._parent.phys_in) * 8
+ 1
]
), ),
) )
peak = vals[0] if vals[0] > vals[1] else vals[1] peak = vals[0] if vals[0] > vals[1] else vals[1]
self.level.set( self.level.set(
( (
0 0
if self._parent._parent.channel_frame.strips[ if self._parent._parent.channel_frame.strips[
self.index self.index
].mute.get() ].mute.get()
else 100 + (peak - 18) + self.gain.get() or not self.on.get()
else 100 + (peak - 18) + self.gain.get()
)
) )
)
self.after( self.after(
_base_vals.ldelay if not _base_vals.in_scale_button_1 else 100, _base_vals.ldelay if not _base_vals.in_scale_button_1 else 100,
self.watch_levels_step, self.watch_levels_step,