Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to each channel to enable/disable metering #151

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions jack_mixer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ def create_ui(self, with_nsm):
self.window.connect("destroy", Gtk.main_quit)
self.window.connect("delete-event", self.on_delete_event)

def show_all(self):
self.window.show_all()
for channel in self.output_channels + self.channels:
channel.on_metering_toggled(channel.metering_button)
# ---------------------------------------------------------------------------------------------
# Channel creation

Expand Down Expand Up @@ -486,7 +490,7 @@ def nsm_hide_cb(self, *args):

def nsm_show_cb(self):
width, height = self.window.get_size()
self.window.show_all()
self.show_all()
self.paned.set_position(self.paned_position / self.width * width)

self.visible = True
Expand Down Expand Up @@ -782,7 +786,7 @@ def on_add_channel(self, inout="input", default_name="Input"):
setattr(self, "_add_{}_values".format(inout), result)
(self.add_channel if inout == "input" else self.add_output_channel)(**result)
if self.visible or self.nsm_client is None:
self.window.show_all()
self.show_all()

def on_add_input_channel(self, widget):
return self.on_add_channel("input", _("Input"))
Expand Down Expand Up @@ -1054,7 +1058,7 @@ def load_from_xml(self, file, silence_errors=False, from_nsm=False):
del self.unserialized_channels
width, height = self.window.get_size()
if self.visible or not from_nsm:
self.window.show_all()
self.show_all()

if self.output_channels:
self.output_channels[-1].volume_digits.select_region(0, 0)
Expand Down Expand Up @@ -1128,7 +1132,7 @@ def main(self):

if self.visible or self.nsm_client is None:
width, height = self.window.get_size()
self.window.show_all()
self.show_all()
if hasattr(self, "paned_position"):
self.paned.set_position(self.paned_position / self.width * width)

Expand Down
30 changes: 27 additions & 3 deletions jack_mixer/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(self, app, name, stereo=True, direct_output=True, initial_vol=None)
self.css_name = "css_name_%d" % Channel.num_instances
self.label_name = None
self.wide = True
self.future_metering = None
self.meter_prefader = False
self.prefader_button = None
self.label_chars_wide = 12
Expand Down Expand Up @@ -137,6 +138,11 @@ def create_fader(self):
pre.connect("toggled", self.on_prefader_metering_toggled)
pre.set_active(self.meter_prefader)

self.metering_button = mb = Gtk.ToggleButton(_("METER"))
mb.get_style_context().add_class("metering")
mb.set_tooltip_text(_("Show (on) / Hide (off) metering"))
mb.connect("toggled", self.on_metering_toggled)

self.hbox_readouts = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.hbox_readouts.set_homogeneous(True)
self.hbox_readouts.pack_start(self.volume_digits, False, True, 0)
Expand All @@ -154,9 +160,11 @@ def create_fader(self):
self.event_box_fader.connect("scroll-event", self.on_scroll)
self.event_box_fader.add(self.hbox_fader)
self.vbox_fader.pack_start(self.event_box_fader, True, True, 0)
self.vbox_fader.pack_end(self.metering_button, False, False, 0)
self.vbox_fader.pack_end(self.balance, False, True, 0)

self.pack_start(self.vbox_fader, True, True, 0)
self.metering_button.set_active(self.channel.metering)

def create_slider_widget(self):
parent = None
Expand All @@ -180,6 +188,8 @@ def realize(self):
log.debug('Realizing channel "%s".', self.channel_name)
if self.future_out_mute is not None:
self.channel.out_mute = self.future_out_mute
if self.future_metering is not None:
self.channel.metering = self.future_metering

# Widgets
# Channel strip label
Expand Down Expand Up @@ -320,6 +330,17 @@ def on_custom_widgets_changed(self, gui_factory, value):
self.create_slider_widget()
# balance slider has no custom variant, no need to re-create it.

def on_metering_toggled(self, button):
log.debug(f'on_metering_toggled: {button.get_active()}')
if not button.get_active():
self.channel.metering = False
self.vbox_meter.hide()
self.abspeak.hide()
else:
self.channel.metering = True
self.abspeak.show()
self.vbox_meter.show()

def on_prefader_metering_toggled(self, button):
self.use_prefader_metering(button.get_active())

Expand Down Expand Up @@ -509,7 +530,7 @@ def use_prefader_metering(self, flag=True):
self.channel.kmeter_reset()

def read_meter(self):
if not self.channel:
if not self.channel or self.channel.metering is False:
return

if self.stereo:
Expand Down Expand Up @@ -574,7 +595,8 @@ def serialize(self, object_backend):
object_backend.add_property("balance", "%f" % self.balance_adjustment.get_value())
object_backend.add_property("wide", "%s" % str(self.wide))
object_backend.add_property("meter_prefader", "%s" % str(self.meter_prefader))

if hasattr(self.channel, "metering"):
object_backend.add_property("metering", "%s" % str(self.channel.metering))
if hasattr(self.channel, "out_mute"):
object_backend.add_property("out_mute", str(self.channel.out_mute))
if self.channel.volume_midi_cc != -1:
Expand All @@ -599,8 +621,10 @@ def unserialize_property(self, name, value):
elif name == "meter_prefader":
self.meter_prefader = (value == "True")
return True
elif name == "metering":
self.future_metering = (value == "True")
return True
elif name == "volume_midi_cc":

self.future_volume_midi_cc = int(value)
return True
elif name == "balance_midi_cc":
Expand Down
14 changes: 11 additions & 3 deletions jack_mixer/styling.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
@define-color solo_bgcolor_checked #26A269;
@define-color prefader_bgcolor_hover #A6C2E4;
@define-color prefader_bgcolor_checked #3584E4;

@define-color metering_bgcolor_hover #906090;
@define-color metering_bgcolor_checked #663366;

/* Channel strips */

Expand Down Expand Up @@ -85,7 +86,9 @@
button.mute:checked,
button.solo:checked,
button.prefader:checked,
button.prefader_meter:checked {
button.prefader_meter:checked,
button.metering:hover,
button.metering:checked {
color: white;
text-shadow: unset;
background-image: none;
Expand Down Expand Up @@ -120,7 +123,12 @@
button.prefader_meter:checked {
background-color: @prefader_bgcolor_checked;
}

button.metering:hover {
background-color: @metering_bgcolor_hover;
}
button.metering:checked {
background-color: @metering_bgcolor_checked;
}

/* Control groups */

Expand Down
3 changes: 3 additions & 0 deletions src/_jack_mixer.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ cdef extern from "jack_mixer.h":
cdef const char * channel_get_name(jack_mixer_channel_t channel)
cdef int channel_rename(jack_mixer_channel_t channel, const char * name)

cdef bool channel_get_metering(jack_mixer_channel_t channel)
cdef void channel_set_metering(jack_mixer_channel_t channel, bool flag)

cdef double channel_abspeak_read(jack_mixer_channel_t channel, meter_mode mode)
cdef void channel_abspeak_reset(jack_mixer_channel_t channel, meter_mode mode)

Expand Down
9 changes: 9 additions & 0 deletions src/_jack_mixer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ cdef class Channel:
channel_mono_meter_read(self._channel, &left, MeterMode.POST_FADER)
return (left,)

@property
def metering(self):
"""Using meters."""
return channel_get_metering(self._channel)

@metering.setter
def metering(self, bool flag):
channel_set_metering(self._channel, flag)

@property
def midi_change_callback(self):
"""Function to be called when a channel property is changed via MIDI.
Expand Down
Loading