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 meter refresh period as user preference #139

Merged
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
14 changes: 13 additions & 1 deletion jack_mixer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def create_mixer(self, client_name, with_nsm=True):
# in which a project is loaded.
self.monitor_channel = self.mixer.add_output_channel("Monitor", True, True)

GLib.timeout_add(33, self.read_meters)
self.meter_refresh_period = \
self.gui_factory.get_meter_refresh_period_milliseconds()
self.meter_refresh_timer_id = GLib.timeout_add(self.meter_refresh_period, self.read_meters)
GLib.timeout_add(50, self.midi_events_check)

if with_nsm:
Expand Down Expand Up @@ -200,6 +202,10 @@ def create_ui(self, with_nsm):
self.gui_factory.connect("language-changed", self.on_language_changed)
self.gui_factory.emit("language-changed", self.gui_factory.get_language())
self.gui_factory.connect("midi-behavior-mode-changed", self.on_midi_behavior_mode_changed)
self.gui_factory.connect(
"meter-refresh-period-milliseconds-changed",
self.on_meter_refresh_period_milliseconds_changed
)
self.gui_factory.emit_midi_behavior_mode()

# Recent files manager
Expand Down Expand Up @@ -918,6 +924,12 @@ def on_channels_clear(self, widget):

dlg.destroy()

def on_meter_refresh_period_milliseconds_changed(self, sender, value):
if self.meter_refresh_timer_id is not None:
GLib.source_remove(self.meter_refresh_timer_id)
self.meter_refresh_period = value
self.meter_refresh_timer_id = GLib.timeout_add(self.meter_refresh_period, self.read_meters)

def read_meters(self):
for channel in self.channels:
channel.read_meter()
Expand Down
28 changes: 28 additions & 0 deletions jack_mixer/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def set_default_preferences(self):
self.vumeter_color_scheme = "default"
self.auto_reset_peak_meters = False
self.auto_reset_peak_meters_time_seconds = 2.0
self.meter_refresh_period_milliseconds = 33

def read_preferences(self):
self.config.read(self.path)
Expand Down Expand Up @@ -127,6 +128,10 @@ def read_preferences(self):
"Preferences", "auto_reset_peak_meters_time_seconds",
fallback=self.auto_reset_peak_meters_time_seconds
)
self.meter_refresh_period_milliseconds = self.config.getint(
"Preferences", "meter_refresh_period_milliseconds",
fallback=self.meter_refresh_period_milliseconds
)

def write_preferences(self):
self.config["Preferences"] = {}
Expand All @@ -142,6 +147,9 @@ def write_preferences(self):
self.config["Preferences"]["auto_reset_peak_meters"] = str(self.auto_reset_peak_meters)
self.config["Preferences"]["auto_reset_peak_meters_time_seconds"] = \
str(self.auto_reset_peak_meters_time_seconds)
self.config["Preferences"]["meter_refresh_period_milliseconds"] = \
str(self.meter_refresh_period_milliseconds)

with open(self.path, "w") as configfile:
self.config.write(configfile)
configfile.close()
Expand Down Expand Up @@ -197,6 +205,9 @@ def set_auto_reset_peak_meters(self, auto_reset):
def set_auto_reset_peak_meters_time_seconds(self, time):
self._update_setting("auto_reset_peak_meters_time_seconds", time)

def set_meter_refresh_period_milliseconds(self, period):
self._update_setting("meter_refresh_period_milliseconds", period)

def get_confirm_quit(self):
return self.confirm_quit

Expand Down Expand Up @@ -233,6 +244,9 @@ def get_auto_reset_peak_meters(self):
def get_auto_reset_peak_meters_time_seconds(self):
return self.auto_reset_peak_meters_time_seconds

def get_meter_refresh_period_milliseconds(self):
return self.meter_refresh_period_milliseconds

def emit_midi_behavior_mode(self):
self.emit("midi-behavior-mode-changed", self.midi_behavior_mode)

Expand Down Expand Up @@ -260,6 +274,11 @@ def serialize(self, object_backend):
self.get_auto_reset_peak_meters_time_seconds()
)
)
object_backend.add_property(
"meter_refresh_period_milliseconds", str(
self.get_meter_refresh_period_milliseconds()
)
)

def unserialize_property(self, name, value):
if name == "confirm_quit":
Expand Down Expand Up @@ -292,6 +311,8 @@ def unserialize_property(self, name, value):
elif name == "auto_reset_peak_meters_time_seconds":
self.set_auto_reset_peak_meters_time_seconds(float(value))
return True
elif name == "meter_refresh_period_milliseconds":
self.set_meter_refresh_period_milliseconds(int(value))
return False


Expand Down Expand Up @@ -372,3 +393,10 @@ def unserialize_property(self, name, value):
None,
[float],
)
GObject.signal_new(
"meter-refresh-period-milliseconds-changed",
Factory,
GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION,
None,
[int],
)
29 changes: 28 additions & 1 deletion jack_mixer/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,20 @@ def create_ui(self):
interface_vbox.pack_start(hbox, True, True, 3)

hbox.set_sensitive(self.auto_reset_peak_meters_checkbutton.get_active())
hbox.pack_start(Gtk.Label(_("Time:")), False, True, 5)
hbox.pack_start(Gtk.Label(_("Time (s):")), False, True, 5)
self.auto_reset_peak_meters_time_seconds_spinbutton = spinbutton = \
self.create_auto_reset_peak_meters_time_seconds_spinbutton()
hbox.pack_start(spinbutton, True, True, 0)

self.meter_refresh_period_milliseconds_box = hbox = Gtk.Box(
orientation=Gtk.Orientation.HORIZONTAL
)
interface_vbox.pack_start(hbox, True, True, 3)
hbox.pack_start(Gtk.Label(_("Meter Refresh Period (ms):")), False, True, 5)
self.meter_refresh_period_milliseconds_spinbutton = spinbutton = \
self.create_meter_refresh_period_milliseconds_spinbutton()
hbox.pack_start(spinbutton, True, True, 0)

vbox.pack_start(self.create_frame(_("Interface"), interface_vbox), True, True, 0)

table = Gtk.Table(2, 2, False)
Expand Down Expand Up @@ -226,6 +235,19 @@ def create_auto_reset_peak_meters_time_seconds_spinbutton(self):
spinbutton.connect("value-changed", self.on_peak_reset_spinbutton_changed)
return spinbutton

def create_meter_refresh_period_milliseconds_spinbutton(self):
adjustment = \
Gtk.Adjustment(value=int(
self.app.gui_factory.get_meter_refresh_period_milliseconds()
),
lower=1,
upper=1000,
step_increment=1,
page_increment=10)
spinbutton = Gtk.SpinButton(adjustment=adjustment)
spinbutton.connect("value-changed", self.on_meter_refresh_spinbutton_changed)
return spinbutton

def on_response_cb(self, dlg, response_id, *args):
self.app.preferences_dialog = None
self.destroy()
Expand Down Expand Up @@ -304,3 +326,8 @@ def on_peak_reset_spinbutton_changed(self, *args):
self.app.gui_factory.set_auto_reset_peak_meters_time_seconds(
self.auto_reset_peak_meters_time_seconds_spinbutton.get_value()
)

def on_meter_refresh_spinbutton_changed(self, *args):
self.app.gui_factory.set_meter_refresh_period_milliseconds(
self.meter_refresh_period_milliseconds_spinbutton.get_value_as_int()
)