From ae96a3be0e60a94e3df598812f5f1acb5dbab666 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 12 Dec 2009 23:12:14 +0100 Subject: [PATCH] Serialize mute/solo status --- channel.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++-- jack_mixer.py | 18 +++++++----- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/channel.py b/channel.py index fb19345..c5291e9 100644 --- a/channel.py +++ b/channel.py @@ -371,6 +371,7 @@ class input_channel(channel): control_group = ControlGroup(channel, self) control_group.show_all() self.vbox.pack_start(control_group, False) + return control_group def update_control_group(self, channel): for control_group in self.vbox.get_children(): @@ -378,6 +379,13 @@ class input_channel(channel): if control_group.output_channel is channel: control_group.update() + def get_control_group(self, channel): + for control_group in self.vbox.get_children(): + if isinstance(control_group, ControlGroup): + if control_group.output_channel is channel: + return control_group + return None + def unrealize(self): channel.unrealize(self) self.channel.remove() @@ -445,6 +453,9 @@ class output_channel(channel): colours = available_colours[:] _display_solo_buttons = False + _init_muted_channels = None + _init_solo_channels = None + def __init__(self, app, name, stereo): channel.__init__(self, app, name, stereo) @@ -515,6 +526,17 @@ class output_channel(channel): self.monitor_button.connect('toggled', self.on_monitor_button_toggled) self.pack_start(self.monitor_button, False, False) + # add control groups to the input channels, and initialize them + # appropriately + for input_channel in self.app.channels: + ctlgroup = input_channel.add_control_group(self) + if self._init_muted_channels and input_channel.channel.name in self._init_muted_channels: + ctlgroup.mute.set_active(True) + if self._init_solo_channels and input_channel.channel.name in self._init_solo_channels: + ctlgroup.solo.set_active(True) + self._init_muted_channels = None + self._init_solo_channels = None + channel_properties_dialog = None def on_channel_properties(self): if not self.channel_properties_dialog: @@ -542,6 +564,17 @@ class output_channel(channel): object_backend.add_property("type", "mono") if self.display_solo_buttons: object_backend.add_property("solo_buttons", "true") + muted_channels = [] + solo_channels = [] + for input_channel in self.app.channels: + if self.channel.is_muted(input_channel.channel): + muted_channels.append(input_channel) + if self.channel.is_solo(input_channel.channel): + solo_channels.append(input_channel) + if muted_channels: + object_backend.add_property('muted_channels', '|'.join([x.channel.name for x in muted_channels])) + if solo_channels: + object_backend.add_property('solo_channels', '|'.join([x.channel.name for x in solo_channels])) channel.serialize(self, object_backend) def unserialize_property(self, name, value): @@ -558,12 +591,22 @@ class output_channel(channel): if name == "solo_buttons": if value == "true": self.display_solo_buttons = True + return True + if name == 'muted_channels': + self._init_muted_channels = value.split('|') + return True + if name == 'solo_channels': + self._init_solo_channels = value.split('|') + return True return channel.unserialize_property(self, name, value) def output_channel_serialization_name(): return "output_channel" class main_mix(channel): + _init_muted_channels = None + _init_solo_channels = None + def __init__(self, app): channel.__init__(self, app, "MAIN", True) @@ -609,6 +652,14 @@ class main_mix(channel): self.monitor_button.connect('toggled', self.on_monitor_button_toggled) self.pack_start(self.monitor_button, False, False) + for input_channel in self.app.channels: + if self._init_muted_channels and input_channel.channel.name in self._init_muted_channels: + input_channel.mute.set_active(True) + if self._init_solo_channels and input_channel.channel.name in self._init_solo_channels: + input_channel.solo.set_active(True) + self._init_muted_channels = None + self._init_solo_channels = None + def unrealize(self): channel.unrealize(self) self.channel = False @@ -616,6 +667,29 @@ class main_mix(channel): def serialization_name(self): return main_mix_serialization_name() + def serialize(self, object_backend): + muted_channels = [] + solo_channels = [] + for input_channel in self.app.channels: + if input_channel.channel.mute: + muted_channels.append(input_channel) + if input_channel.channel.solo: + solo_channels.append(input_channel) + if muted_channels: + object_backend.add_property('muted_channels', '|'.join([x.channel.name for x in muted_channels])) + if solo_channels: + object_backend.add_property('solo_channels', '|'.join([x.channel.name for x in solo_channels])) + channel.serialize(self, object_backend) + + def unserialize_property(self, name, value): + if name == 'muted_channels': + self._init_muted_channels = value.split('|') + return True + if name == 'solo_channels': + self._init_solo_channels = value.split('|') + return True + return channel.unserialize_property(self, name, value) + def main_mix_serialization_name(): return "main_mix_channel" @@ -835,15 +909,14 @@ class ControlGroup(gtk.Alignment): self.add(hbox) mute = gtk.ToggleButton() + self.mute = mute mute.set_label("M") - #mute.set_active(self.channel.mute) mute.connect("toggled", self.on_mute_toggled) hbox.pack_start(mute, False) solo = gtk.ToggleButton() self.solo = solo solo.set_label("S") - #solo.set_active(self.channel.solo) solo.connect("toggled", self.on_solo_toggled) if self.output_channel.display_solo_buttons: hbox.pack_start(solo, True) diff --git a/jack_mixer.py b/jack_mixer.py index 13e8705..58f6c6a 100755 --- a/jack_mixer.py +++ b/jack_mixer.py @@ -168,8 +168,6 @@ class jack_mixer(serialized_object): self.scrolled_window.add_with_viewport(self.hbox_inputs) self.main_mix = main_mix(self) - self.main_mix.realize() - self.main_mix.set_monitored() self.hbox_outputs = gtk.HBox() self.hbox_outputs.set_spacing(0) self.hbox_outputs.set_border_width(0) @@ -365,10 +363,6 @@ class jack_mixer(serialized_object): #self.channel_remove_menu_item.set_sensitive(True) self.output_channels.append(channel) - # add group controls to the input channels - for inputchannel in self.channels: - inputchannel.add_control_group(channel) - _monitored_channel = None def get_monitored_channel(self): return self._monitored_channel @@ -410,6 +404,12 @@ class jack_mixer(serialized_object): self.monitor_channel.set_muted(input_channel.channel, input_channel.channel.mute) + def get_input_channel_by_name(self, name): + for input_channel in self.channels: + if input_channel.channel.name == name: + return input_channel + return None + def on_about(self, *args): about = gtk.AboutDialog() about.set_name('jack_mixer') @@ -489,7 +489,8 @@ Franklin Street, Fifth Floor, Boston, MA 02110-130159 USA''') for channel in self.unserialized_channels: if isinstance(channel, input_channel): self.add_channel_precreated(channel) - else: + for channel in self.unserialized_channels: + if isinstance(channel, output_channel): self.add_output_channel_precreated(channel) del self.unserialized_channels self.window.show_all() @@ -528,6 +529,9 @@ Franklin Street, Fifth Floor, Boston, MA 02110-130159 USA''') return "jack_mixer" def main(self): + self.main_mix.realize() + self.main_mix.set_monitored() + if not self.mixer: return -- 2.39.2