2022-04-11 18:35:28 +01:00
|
|
|
import tkinter as tk
|
2022-06-16 23:53:28 +01:00
|
|
|
from tkinter import ttk
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
from . import builders
|
2022-05-14 14:05:48 +01:00
|
|
|
from .data import _base_values, _configuration
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GainLayer(ttk.LabelFrame):
|
|
|
|
"""Concrete class representing a single gainlayer"""
|
|
|
|
|
|
|
|
def __init__(self, parent, index, j):
|
|
|
|
super().__init__(parent)
|
2022-05-10 20:34:29 +01:00
|
|
|
self.parent = parent
|
2022-04-11 18:35:28 +01:00
|
|
|
self.index = index
|
|
|
|
self.j = j
|
2022-05-10 20:34:29 +01:00
|
|
|
self.styletable = self.parent.parent.styletable
|
2022-04-14 17:25:26 +01:00
|
|
|
if index <= parent.phys_in:
|
|
|
|
self.level_offset = index * 2
|
|
|
|
else:
|
|
|
|
self.level_offset = parent.phys_in * 2 + (index - parent.phys_in) * 8
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
self.builder = builders.ChannelLabelFrameBuilder(self, index, id="gainlayer")
|
|
|
|
self.builder.setup()
|
|
|
|
self.builder.add_progressbar()
|
|
|
|
self.builder.add_scale()
|
2022-05-14 16:00:58 +01:00
|
|
|
self.builder.add_gain_label()
|
2022-05-10 20:34:29 +01:00
|
|
|
self.builder.add_on_button()
|
2022-07-07 01:22:57 +01:00
|
|
|
self.sync_params()
|
|
|
|
self.sync_labels()
|
2022-05-10 20:34:29 +01:00
|
|
|
self.grid_configure()
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def target(self):
|
2022-05-10 20:34:29 +01:00
|
|
|
"""returns the strip[i].gainlayer class in the current interface"""
|
|
|
|
|
|
|
|
_target = self.parent.target
|
2022-04-11 18:35:28 +01:00
|
|
|
return _target.strip[self.index].gainlayer[self.j]
|
|
|
|
|
2022-05-14 14:05:48 +01:00
|
|
|
@property
|
|
|
|
def identifier(self):
|
|
|
|
return "gainlayer"
|
|
|
|
|
2022-04-11 18:35:28 +01:00
|
|
|
def getter(self, param):
|
2023-06-26 13:51:21 +01:00
|
|
|
try:
|
2022-04-11 18:35:28 +01:00
|
|
|
return getattr(self.target, param)
|
2023-06-26 13:51:21 +01:00
|
|
|
except AttributeError as e:
|
|
|
|
self.logger(f"{type(e).__name__}: {e}")
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
def setter(self, param, value):
|
2023-06-26 13:51:21 +01:00
|
|
|
if param in dir(self.target): # avoid calling getattr (with hasattr)
|
2022-04-11 18:35:28 +01:00
|
|
|
setattr(self.target, param, value)
|
|
|
|
|
|
|
|
def reset_gain(self, *args):
|
|
|
|
self.setter("gain", 0)
|
|
|
|
self.gain.set(0)
|
2022-09-16 09:44:47 +01:00
|
|
|
self.gainlabel.set(self.gain.get())
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def scale_callback(self, *args):
|
|
|
|
"""callback function for scale widget"""
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2023-06-26 13:51:21 +01:00
|
|
|
val = round(self.gain.get(), 1)
|
|
|
|
self.setter("gain", val)
|
|
|
|
self.gainlabel.set(val)
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
def scale_press(self, *args):
|
2022-09-16 09:44:47 +01:00
|
|
|
self.after(1, self.remove_events)
|
|
|
|
|
|
|
|
def remove_events(self):
|
|
|
|
self.parent.target.event.remove("pdirty")
|
|
|
|
self.parent.target.event.remove("ldirty")
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
def scale_release(self, *args):
|
2022-09-16 09:44:47 +01:00
|
|
|
_base_values.run_update = False
|
|
|
|
self.after(1, self.add_events)
|
|
|
|
|
|
|
|
def add_events(self):
|
|
|
|
self.parent.target.event.add("pdirty")
|
|
|
|
self.parent.target.event.add("ldirty")
|
|
|
|
self.after(500, self.resume_updates)
|
|
|
|
|
|
|
|
def resume_updates(self):
|
|
|
|
_base_values.run_update = True
|
2022-05-10 20:34:29 +01:00
|
|
|
|
2022-04-14 20:49:06 +01:00
|
|
|
def _on_mousewheel(self, event):
|
2022-09-16 09:44:47 +01:00
|
|
|
_base_values.run_update = False
|
2022-04-17 11:50:44 +01:00
|
|
|
self.gain.set(
|
|
|
|
self.gain.get()
|
|
|
|
+ (
|
2022-05-14 17:24:33 +01:00
|
|
|
_configuration.mwscroll_step
|
2022-04-17 11:50:44 +01:00
|
|
|
if event.delta > 0
|
2022-05-14 17:24:33 +01:00
|
|
|
else -_configuration.mwscroll_step
|
2022-04-17 11:50:44 +01:00
|
|
|
)
|
|
|
|
)
|
2022-04-14 20:49:06 +01:00
|
|
|
if self.gain.get() > 12:
|
|
|
|
self.gain.set(12)
|
|
|
|
elif self.gain.get() < -60:
|
|
|
|
self.gain.set(-60)
|
|
|
|
self.setter("gain", self.gain.get())
|
2022-09-16 09:44:47 +01:00
|
|
|
self.after(1, self.resume_updates)
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
def set_on(self):
|
|
|
|
"""enables a gainlayer. sets its button colour"""
|
2022-05-10 20:34:29 +01:00
|
|
|
|
2022-04-11 18:35:28 +01:00
|
|
|
setattr(
|
2022-05-10 20:34:29 +01:00
|
|
|
self.parent.target.strip[self.index],
|
|
|
|
self.parent.buses[self.j],
|
2022-04-11 18:35:28 +01:00
|
|
|
self.on.get(),
|
|
|
|
)
|
2022-05-10 20:34:29 +01:00
|
|
|
if not _configuration.themes_enabled:
|
|
|
|
self.styletable.configure(
|
2022-05-14 14:05:48 +01:00
|
|
|
f"{self.identifier}On{self.index}.TButton",
|
2022-04-11 18:35:28 +01:00
|
|
|
background=f'{"green" if self.on.get() else "white"}',
|
|
|
|
)
|
|
|
|
|
2022-07-07 01:22:57 +01:00
|
|
|
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)
|
2022-05-14 14:05:48 +01:00
|
|
|
|
|
|
|
def sync_params(self):
|
|
|
|
self.gain.set(self.getter("gain"))
|
2022-05-14 16:00:58 +01:00
|
|
|
self.gainlabel.set(round(self.gain.get(), 1))
|
2022-05-14 14:05:48 +01:00
|
|
|
self.on.set(
|
|
|
|
getattr(
|
|
|
|
self.parent.target.strip[self.index],
|
|
|
|
self.parent.buses[self.j],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if not _configuration.themes_enabled:
|
|
|
|
self.styletable.configure(
|
|
|
|
f"{self.identifier}On{self.index}.TButton",
|
|
|
|
background=f'{"green" if self.on.get() else "white"}',
|
|
|
|
)
|
|
|
|
|
|
|
|
def sync_labels(self):
|
2022-04-11 18:35:28 +01:00
|
|
|
"""sync params with voicemeeter"""
|
2022-05-10 20:34:29 +01:00
|
|
|
retval = self.parent.target.strip[self.index].label
|
2022-04-11 18:35:28 +01:00
|
|
|
if len(retval) > 10:
|
|
|
|
retval = f"{retval[:8]}.."
|
2022-05-10 20:34:29 +01:00
|
|
|
if not retval:
|
|
|
|
self.parent.columnconfigure(self.index, minsize=0)
|
2022-06-20 00:09:27 +01:00
|
|
|
self.parent.parent.subject.remove(self)
|
2022-05-10 20:34:29 +01:00
|
|
|
self.grid_remove()
|
|
|
|
else:
|
2022-06-20 00:09:27 +01:00
|
|
|
self.parent.parent.subject.add(self)
|
2022-05-10 20:34:29 +01:00
|
|
|
self.grid()
|
2022-04-11 18:35:28 +01:00
|
|
|
self.configure(text=retval)
|
|
|
|
|
2022-05-14 14:05:48 +01:00
|
|
|
def upd_levels(self):
|
|
|
|
"""
|
|
|
|
Updates level values.
|
|
|
|
"""
|
2022-07-06 13:57:52 +01:00
|
|
|
|
|
|
|
if self.parent.target.strip[self.index].levels.is_updated:
|
|
|
|
val = max(self.parent.target.strip[self.index].levels.prefader)
|
2022-10-05 23:39:51 +01:00
|
|
|
self.level.set(
|
|
|
|
(
|
|
|
|
0
|
2023-06-26 13:51:21 +01:00
|
|
|
if self.parent.parent.strip_frame.strips[self.index].mute.get()
|
|
|
|
or not self.on.get()
|
2022-10-05 23:39:51 +01:00
|
|
|
else 72 + val - 12 + self.gain.get()
|
2022-05-14 14:05:48 +01:00
|
|
|
)
|
2022-10-05 23:39:51 +01:00
|
|
|
)
|
2022-05-14 14:05:48 +01:00
|
|
|
|
|
|
|
def grid_configure(self):
|
2023-06-29 15:50:39 +01:00
|
|
|
self.grid(padx=_configuration.channel_xpadding, sticky=(tk.N, tk.S))
|
2022-05-14 14:05:48 +01:00
|
|
|
[
|
|
|
|
child.grid_configure(padx=1, pady=1, sticky=(tk.N, tk.S, tk.W, tk.E))
|
|
|
|
for child in self.winfo_children()
|
|
|
|
if isinstance(child, ttk.Checkbutton)
|
|
|
|
]
|
|
|
|
[
|
|
|
|
child.grid_configure(padx=1, pady=1, sticky=(tk.N, tk.S))
|
|
|
|
for child in self.winfo_children()
|
|
|
|
if isinstance(child, ttk.Progressbar) or isinstance(child, ttk.Scale)
|
|
|
|
]
|
|
|
|
# pb and scale
|
|
|
|
self.columnconfigure(0, minsize=36)
|
|
|
|
self.columnconfigure(1, minsize=36)
|
|
|
|
# on button
|
|
|
|
if _configuration.themes_enabled:
|
2022-05-14 16:00:58 +01:00
|
|
|
self.rowconfigure(2, minsize=70)
|
2022-05-14 14:05:48 +01:00
|
|
|
else:
|
2022-05-14 16:00:58 +01:00
|
|
|
self.rowconfigure(2, minsize=55)
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
class SubMixFrame(ttk.Frame):
|
|
|
|
def __init__(self, parent):
|
|
|
|
super().__init__(parent)
|
2022-05-10 20:34:29 +01:00
|
|
|
self.parent = parent
|
2022-04-13 06:50:49 +01:00
|
|
|
self.phys_in, self.virt_in = parent.kind.ins
|
2022-04-11 18:35:28 +01:00
|
|
|
self.phys_out, self.virt_out = parent.kind.outs
|
|
|
|
self.buses = tuple(f"A{i+1}" for i in range(self.phys_out)) + tuple(
|
|
|
|
f"B{i+1}" for i in range(self.virt_out)
|
|
|
|
)
|
|
|
|
|
|
|
|
self.gainlayers = [
|
2022-05-16 22:20:05 +01:00
|
|
|
GainLayer(self, index, _configuration.submixes) for index in range(8)
|
2022-04-11 18:35:28 +01:00
|
|
|
]
|
2022-05-10 20:34:29 +01:00
|
|
|
for i, labelframe in enumerate(self.labelframes):
|
|
|
|
labelframe.grid(row=0, column=i)
|
|
|
|
if not self.target.strip[i].label:
|
2022-04-11 18:35:28 +01:00
|
|
|
self.columnconfigure(i, minsize=0)
|
2022-05-10 20:34:29 +01:00
|
|
|
labelframe.grid_remove()
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
if _configuration.extends_horizontal:
|
|
|
|
self.grid(row=0, column=2)
|
|
|
|
if parent.bus_frame:
|
|
|
|
parent.bus_frame.grid_remove()
|
|
|
|
else:
|
2022-07-16 22:14:02 +01:00
|
|
|
if parent.bus_frame and parent.bus_frame.grid_info():
|
2022-05-14 14:05:48 +01:00
|
|
|
self.grid(
|
|
|
|
row=parent.bus_frame.grid_info()["row"], column=0, sticky=(tk.W)
|
|
|
|
)
|
2022-05-10 20:34:29 +01:00
|
|
|
parent.bus_frame.grid_remove()
|
2022-05-14 14:05:48 +01:00
|
|
|
else:
|
|
|
|
self.grid(row=2, column=0, sticky=(tk.W))
|
2022-05-10 20:34:29 +01:00
|
|
|
|
2022-05-14 14:05:48 +01:00
|
|
|
self.grid_configure()
|
|
|
|
"""
|
|
|
|
Grids each labelframe, grid_removes any without a label
|
|
|
|
"""
|
|
|
|
for i, labelframe in enumerate(self.labelframes):
|
|
|
|
labelframe.grid(row=0, column=i)
|
|
|
|
if not self.target.strip[i].label:
|
|
|
|
self.columnconfigure(i, minsize=0)
|
|
|
|
labelframe.grid_remove()
|
|
|
|
|
2022-07-07 01:22:57 +01:00
|
|
|
self.parent.subject.add(self)
|
|
|
|
|
2022-04-11 18:35:28 +01:00
|
|
|
@property
|
|
|
|
def target(self):
|
|
|
|
"""returns the current interface"""
|
2022-05-10 20:34:29 +01:00
|
|
|
|
|
|
|
return self.parent.target
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
@property
|
2022-05-10 20:34:29 +01:00
|
|
|
def labelframes(self):
|
|
|
|
"""returns a tuple of current gainlayer labelframe addresses"""
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
return tuple(
|
|
|
|
frame
|
|
|
|
for frame in self.winfo_children()
|
|
|
|
if isinstance(frame, ttk.LabelFrame)
|
|
|
|
)
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-07-07 01:22:57 +01:00
|
|
|
def on_update(self, subject):
|
|
|
|
if subject == "pdirty":
|
|
|
|
for labelframe in self.labelframes:
|
|
|
|
labelframe.on_update("labelframe")
|
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def grid_configure(self):
|
2022-04-11 18:35:28 +01:00
|
|
|
[
|
2023-06-29 15:50:39 +01:00
|
|
|
self.columnconfigure(i, minsize=_configuration.channel_width)
|
2022-05-10 20:34:29 +01:00
|
|
|
for i, _ in enumerate(self.labelframes)
|
|
|
|
]
|
|
|
|
[
|
2023-06-29 15:50:39 +01:00
|
|
|
self.rowconfigure(0, minsize=_configuration.channel_height)
|
2022-05-10 20:34:29 +01:00
|
|
|
for i, _ in enumerate(self.labelframes)
|
2022-04-11 18:35:28 +01:00
|
|
|
]
|
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def teardown(self):
|
|
|
|
# deregisters submixframe as pdirty observer
|
2022-07-07 01:22:57 +01:00
|
|
|
[self.parent.subject.remove(frame) for frame in self.gainlayers]
|
2022-06-20 00:09:27 +01:00
|
|
|
self.parent.subject.remove(self)
|
2022-05-10 20:34:29 +01:00
|
|
|
self.destroy()
|