2022-04-11 18:35:28 +01:00
|
|
|
import tkinter as tk
|
2022-04-13 06:50:49 +01:00
|
|
|
from math import log
|
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
|
|
|
|
from .data import _base_values, _configuration
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
class ChannelLabelFrame(ttk.LabelFrame):
|
2022-04-11 18:35:28 +01:00
|
|
|
"""Base class for a single channel"""
|
|
|
|
|
|
|
|
def __init__(self, parent, index, id):
|
|
|
|
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.id = id
|
2022-05-10 20:34:29 +01:00
|
|
|
self.styletable = self.parent.parent.styletable
|
|
|
|
|
|
|
|
self.builder = builders.ChannelLabelFrameBuilder(self, index, id)
|
|
|
|
self.builder.setup()
|
|
|
|
self.builder.add_progressbar()
|
|
|
|
self.builder.add_scale()
|
|
|
|
self.builder.add_mute_button()
|
|
|
|
self.builder.add_conf_button()
|
2022-05-14 14:05:48 +01:00
|
|
|
self.builder.add_gain_label()
|
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
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
self.configbuilder = builders.MainFrameBuilder(self.parent.parent)
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def identifier(self):
|
|
|
|
return self.id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target(self):
|
2022-05-10 20:34:29 +01:00
|
|
|
"""returns the current interface"""
|
|
|
|
|
|
|
|
return self.parent.target
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
def getter(self, param):
|
2022-05-14 17:24:33 +01:00
|
|
|
if hasattr(self.target, param):
|
2022-04-11 18:35:28 +01:00
|
|
|
return getattr(self.target, param)
|
|
|
|
|
|
|
|
def setter(self, param, value):
|
2022-05-14 17:24:33 +01:00
|
|
|
if hasattr(self.target, param):
|
2022-04-11 18:35:28 +01:00
|
|
|
setattr(self.target, param, value)
|
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def scale_callback(self, *args):
|
|
|
|
"""callback function for scale widget"""
|
|
|
|
|
|
|
|
self.setter("gain", self.gain.get())
|
2022-05-14 14:05:48 +01:00
|
|
|
self.gainlabel.set(round(self.gain.get(), 1))
|
2022-05-10 20:34:29 +01:00
|
|
|
|
2022-04-11 18:35:28 +01:00
|
|
|
def toggle_mute(self, *args):
|
|
|
|
self.target.mute = self.mute.get()
|
2022-05-10 20:34:29 +01:00
|
|
|
if not _configuration.themes_enabled:
|
|
|
|
self.styletable.configure(
|
2022-04-11 18:35:28 +01:00
|
|
|
f"{self.identifier}Mute{self.index}.TButton",
|
|
|
|
background=f'{"red" if self.mute.get() else "white"}',
|
|
|
|
)
|
|
|
|
|
|
|
|
def reset_gain(self, *args):
|
|
|
|
self.setter("gain", 0)
|
|
|
|
self.gain.set(0)
|
|
|
|
|
|
|
|
def scale_press(self, *args):
|
2022-05-10 20:34:29 +01:00
|
|
|
_base_values.in_scale_button_1 = True
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
def scale_release(self, *args):
|
2022-05-10 20:34:29 +01:00
|
|
|
_base_values.in_scale_button_1 = False
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-04-14 20:49:06 +01:00
|
|
|
def _on_mousewheel(self, event):
|
2022-07-16 22:12:55 +01:00
|
|
|
_base_values.in_scale_button_1 = True
|
2022-04-17 11:50:44 +01:00
|
|
|
self.gain.set(
|
|
|
|
self.gain.get()
|
|
|
|
+ (
|
2022-05-10 20:34:29 +01:00
|
|
|
_configuration.mwscroll_step
|
2022-04-17 11:50:44 +01:00
|
|
|
if event.delta > 0
|
2022-05-10 20:34:29 +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-07-16 22:12:55 +01:00
|
|
|
_base_values.in_scale_button_1 = False
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def open_config(self):
|
|
|
|
if self.conf.get():
|
|
|
|
self.configbuilder.create_configframe(self.identifier, self.index, self.id)
|
|
|
|
else:
|
|
|
|
self.parent.parent.config_frame.teardown()
|
|
|
|
if not _configuration.themes_enabled:
|
|
|
|
self.styletable.configure(
|
|
|
|
f"{self.identifier}Conf{self.index}.TButton",
|
|
|
|
background=f'{"yellow" if self.conf.get() else "white"}',
|
|
|
|
)
|
2022-04-11 18:35:28 +01:00
|
|
|
|
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):
|
|
|
|
"""sync parameter states, update button colours"""
|
|
|
|
self.gain.set(self.getter("gain"))
|
|
|
|
self.gainlabel.set(round(self.gain.get(), 1))
|
|
|
|
self.mute.set(self.getter("mute"))
|
|
|
|
if not _configuration.themes_enabled:
|
|
|
|
self.styletable.configure(
|
|
|
|
f"{self.identifier}Mute{self.index}.TButton",
|
|
|
|
background=f'{"red" if self.mute.get() else "white"}',
|
|
|
|
)
|
|
|
|
|
|
|
|
def sync_labels(self):
|
|
|
|
"""sync labelframes according to label text"""
|
2022-04-11 18:35:28 +01:00
|
|
|
retval = self.getter("label")
|
2022-07-16 22:12:55 +01:00
|
|
|
self.parent.label_cache[self.id].insert(self.index, retval)
|
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-10 20:34:29 +01:00
|
|
|
def grid_configure(self):
|
2022-04-11 18:35:28 +01:00
|
|
|
self.grid(sticky=(tk.N, tk.S))
|
|
|
|
[
|
|
|
|
child.grid_configure(padx=1, pady=1, sticky=(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)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
class Strip(ChannelLabelFrame):
|
|
|
|
"""Concrete class representing a single strip"""
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
def __init__(self, parent, index, id):
|
|
|
|
super().__init__(parent, index, id)
|
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
|
|
|
|
|
|
|
@property
|
|
|
|
def target(self):
|
2022-05-10 20:34:29 +01:00
|
|
|
"""returns the strip class for this labelframe in the current interface"""
|
|
|
|
|
2022-04-11 18:35:28 +01:00
|
|
|
_target = super(Strip, self).target
|
|
|
|
return getattr(_target, self.identifier)[self.index]
|
|
|
|
|
2022-05-14 14:05:48 +01:00
|
|
|
def upd_levels(self):
|
|
|
|
"""
|
|
|
|
Updates level values.
|
|
|
|
"""
|
2022-07-07 01:22:57 +01:00
|
|
|
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())
|
|
|
|
)
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
class Bus(ChannelLabelFrame):
|
2022-04-11 18:35:28 +01:00
|
|
|
"""Concrete bus class representing a single bus"""
|
|
|
|
|
|
|
|
def __init__(self, parent, index, id):
|
|
|
|
super().__init__(parent, index, id)
|
2022-05-10 20:34:29 +01:00
|
|
|
self.level_offset = index * 8
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def target(self):
|
2022-05-10 20:34:29 +01:00
|
|
|
"""returns the bus class for this labelframe in the current interface"""
|
|
|
|
|
2022-04-11 18:35:28 +01:00
|
|
|
_target = super(Bus, self).target
|
|
|
|
return getattr(_target, self.identifier)[self.index]
|
|
|
|
|
2022-05-14 14:05:48 +01:00
|
|
|
def upd_levels(self):
|
2022-07-07 01:22:57 +01:00
|
|
|
if self.index < self.parent.parent.kind.num_bus:
|
2022-07-14 17:24:05 +01:00
|
|
|
if self.target.levels.is_updated or self.level.get() != -118:
|
2022-07-07 01:22:57 +01:00
|
|
|
val = max(self.target.levels.all)
|
|
|
|
self.level.set((0 if self.mute.get() else 100 + val - 18))
|
2022-04-11 18:35:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ChannelFrame(ttk.Frame):
|
2022-07-16 22:12:55 +01:00
|
|
|
label_cache = {"strip": list(), "bus": list()}
|
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def init(self, parent, id):
|
2022-04-11 18:35:28 +01:00
|
|
|
super().__init__(parent)
|
2022-05-10 20:34:29 +01:00
|
|
|
self.parent = parent
|
|
|
|
self.id = id
|
2022-04-11 18:35:28 +01:00
|
|
|
self.phys_in, self.virt_in = parent.kind.ins
|
|
|
|
self.phys_out, self.virt_out = parent.kind.outs
|
2022-06-20 00:09:27 +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
|
|
|
|
def identifier(self):
|
2022-05-10 20:34:29 +01:00
|
|
|
return self.id
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
@property
|
|
|
|
def labelframes(self):
|
|
|
|
"""returns a tuple of current channel labelframe addresses"""
|
2022-04-26 08:06:08 +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-07-07 01:22:57 +01:00
|
|
|
def on_update(self, subject):
|
|
|
|
if subject == "pdirty":
|
2022-07-16 22:12:55 +01:00
|
|
|
target = getattr(self.target, self.id)
|
|
|
|
num = getattr(self.parent.kind, f"num_{self.id}")
|
|
|
|
if self.label_cache[self.id] != [target[i].label for i in range(num)]:
|
|
|
|
for labelframe in self.labelframes:
|
|
|
|
labelframe.on_update("labelframe")
|
2022-07-07 01:22:57 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def grid_configure(self):
|
2022-04-11 18:35:28 +01:00
|
|
|
[
|
2022-05-10 20:34:29 +01:00
|
|
|
self.columnconfigure(i, minsize=_configuration.level_width)
|
|
|
|
for i, _ in enumerate(self.labelframes)
|
2022-04-11 18:35:28 +01:00
|
|
|
]
|
2022-05-14 14:05:48 +01:00
|
|
|
[self.rowconfigure(0, minsize=100) for i, _ in enumerate(self.labelframes)]
|
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def teardown(self):
|
2022-07-07 01:22:57 +01:00
|
|
|
[self.parent.subject.remove(frame) for frame in self.labelframes]
|
2022-06-20 00:09:27 +01:00
|
|
|
self.parent.subject.remove(self)
|
2022-05-10 20:34:29 +01:00
|
|
|
self.destroy()
|
2022-05-14 14:05:48 +01:00
|
|
|
setattr(self.parent, f"{self.identifier}_frame", None)
|
2022-05-10 20:34:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
def _make_channelframe(parent, id):
|
|
|
|
"""
|
|
|
|
Creates a Channel Frame class of type strip or bus
|
|
|
|
"""
|
|
|
|
|
|
|
|
phys_in, virt_in = parent.kind.ins
|
|
|
|
phys_out, virt_out = parent.kind.outs
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
def init_labels(self, id):
|
|
|
|
"""
|
|
|
|
Grids each labelframe, grid_removes any without a label
|
|
|
|
"""
|
2022-04-11 18:35:28 +01:00
|
|
|
|
2022-05-10 20:34:29 +01:00
|
|
|
for i, labelframe in enumerate(
|
|
|
|
getattr(self, "strips" if id == "strip" else "buses")
|
|
|
|
):
|
|
|
|
labelframe.grid(row=0, column=i)
|
|
|
|
if not labelframe.target.label:
|
2022-04-11 18:35:28 +01:00
|
|
|
self.columnconfigure(i, minsize=0)
|
|
|
|
labelframe.grid_remove()
|
2022-05-10 20:34:29 +01:00
|
|
|
|
|
|
|
def init_strip(self, *args, **kwargs):
|
|
|
|
self.init(parent, id)
|
|
|
|
self.strips = tuple(Strip(self, i, id) for i in range(phys_in + virt_in))
|
|
|
|
self.grid(row=0, column=0, sticky=(tk.W))
|
|
|
|
self.grid_configure()
|
|
|
|
init_labels(self, id)
|
|
|
|
|
|
|
|
def init_bus(self, *args, **kwargs):
|
|
|
|
self.init(parent, id)
|
|
|
|
self.buses = tuple(Bus(self, i, id) for i in range(phys_out + virt_out))
|
|
|
|
if _configuration.extended:
|
|
|
|
if _configuration.extends_horizontal:
|
2022-05-14 14:05:48 +01:00
|
|
|
self.grid(row=0, column=2, sticky=(tk.W))
|
2022-04-11 18:35:28 +01:00
|
|
|
else:
|
2022-05-10 20:34:29 +01:00
|
|
|
self.grid(row=2, column=0, sticky=(tk.W))
|
|
|
|
else:
|
|
|
|
self.grid(row=0, column=0)
|
|
|
|
self.grid_configure()
|
|
|
|
init_labels(self, id)
|
|
|
|
|
|
|
|
if id == "strip":
|
|
|
|
CHANNELFRAME_cls = type(
|
2022-07-07 01:22:57 +01:00
|
|
|
f"ChannelFrame{id.capitalize()}",
|
2022-05-10 20:34:29 +01:00
|
|
|
(ChannelFrame,),
|
|
|
|
{
|
|
|
|
"__init__": init_strip,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
CHANNELFRAME_cls = type(
|
2022-07-07 01:22:57 +01:00
|
|
|
f"ChannelFrame{id.capitalize()}",
|
2022-05-10 20:34:29 +01:00
|
|
|
(ChannelFrame,),
|
|
|
|
{
|
|
|
|
"__init__": init_bus,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return CHANNELFRAME_cls(parent)
|