2 # -*- coding: utf-8 -*-
4 # This file is part of jack_mixer
6 # Copyright (C) 2006-2009 Nedko Arnaudov <nedko@arnaudov.name>
7 # Copyright (C) 2009 Frederic Peters <fpeters@0d.be>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; version 2 of the License
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 from argparse import ArgumentParser
30 gi.require_version('Gtk', '3.0')
31 from gi.repository import Gtk
32 from gi.repository import GObject
33 from gi.repository import GLib
35 # temporary change Python modules lookup path to look into installation
36 # directory ($prefix/share/jack_mixer/)
38 sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '..', 'share', 'jack_mixer'))
45 from nsmclient import NSMClient
46 from serialization_xml import XmlSerialization
47 from serialization import SerializedObject, Serializator
48 from preferences import PreferencesDialog
49 from version import __version__
52 # restore Python modules lookup path
54 log = logging.getLogger("jack_mixer")
57 def add_number_suffix(s):
59 return str(int(match.group(0)) + 1)
61 new_s = re.sub('(\d+)\s*$', inc, s)
68 class JackMixer(SerializedObject):
70 # scales suitable as meter scales
76 scale.IEC268Minimalistic()
79 # scales suitable as volume slider scales
85 # name of settings file that is currently open
86 current_filename = None
88 _init_solo_channels = None
90 def __init__(self, client_name='jack_mixer'):
92 self.nsm_client = None
94 if os.environ.get('NSM_URL'):
95 self.nsm_client = NSMClient(
96 prettyName="jack_mixer",
97 saveCallback=self.nsm_save_cb,
98 openOrNewCallback=self.nsm_open_cb,
99 supportsSaveStatus=False,
100 hideGUICallback=self.nsm_hide_cb,
101 showGUICallback=self.nsm_show_cb,
102 exitProgramCallback=self.nsm_exit_cb,
103 loggingLevel="error",
105 self.nsm_client.announceGuiVisibility(self.visible)
108 self.create_mixer(client_name, with_nsm=False)
110 def create_mixer(self, client_name, with_nsm=True):
111 self.mixer = jack_mixer_c.Mixer(client_name)
113 raise RuntimeError("Failed to create Mixer instance.")
115 self.create_ui(with_nsm)
116 self.window.set_title(client_name)
118 self.monitor_channel = self.mixer.add_output_channel("Monitor", True, True)
121 GLib.timeout_add(33, self.read_meters)
122 GLib.timeout_add(50, self.midi_events_check)
125 GLib.timeout_add(200, self.nsm_react)
127 def new_menu_item(self, title, callback=None, accel=None, enabled=True):
128 menuitem = Gtk.MenuItem.new_with_mnemonic(title)
129 menuitem.set_sensitive(enabled)
131 menuitem.connect("activate", callback)
133 key, mod = Gtk.accelerator_parse(accel)
134 menuitem.add_accelerator("activate", self.menu_accelgroup, key, mod,
135 Gtk.AccelFlags.VISIBLE)
138 def create_ui(self, with_nsm):
140 self.output_channels = []
141 self.window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
142 self.window.set_icon_name('jack_mixer')
143 self.gui_factory = gui.Factory(self.window, self.meter_scales, self.slider_scales)
144 self.gui_factory.connect('midi-behavior-mode-changed', self.on_midi_behavior_mode_changed)
145 self.gui_factory.emit_midi_behavior_mode()
147 self.vbox_top = Gtk.VBox()
148 self.window.add(self.vbox_top)
150 self.menu_accelgroup = Gtk.AccelGroup()
151 self.window.add_accel_group(self.menu_accelgroup)
153 self.menubar = Gtk.MenuBar()
154 self.vbox_top.pack_start(self.menubar, False, True, 0)
156 mixer_menu_item = Gtk.MenuItem.new_with_mnemonic("_Mixer")
157 self.menubar.append(mixer_menu_item)
158 edit_menu_item = Gtk.MenuItem.new_with_mnemonic('_Edit')
159 self.menubar.append(edit_menu_item)
160 help_menu_item = Gtk.MenuItem.new_with_mnemonic('_Help')
161 self.menubar.append(help_menu_item)
165 self.paned_position = 210
166 self.window.set_default_size(self.width, self.height)
168 self.mixer_menu = Gtk.Menu()
169 mixer_menu_item.set_submenu(self.mixer_menu)
171 self.mixer_menu.append(self.new_menu_item('New _Input Channel',
172 self.on_add_input_channel, "<Control>N"))
173 self.mixer_menu.append(self.new_menu_item('New Output _Channel',
174 self.on_add_output_channel, "<Shift><Control>N"))
176 self.mixer_menu.append(Gtk.SeparatorMenuItem())
178 self.mixer_menu.append(self.new_menu_item('_Open...', self.on_open_cb, "<Control>O"))
180 self.mixer_menu.append(self.new_menu_item('_Save', self.on_save_cb, "<Control>S"))
183 self.mixer_menu.append(self.new_menu_item('Save _As...', self.on_save_as_cb,
184 "<Shift><Control>S"))
186 self.mixer_menu.append(Gtk.SeparatorMenuItem())
188 self.mixer_menu.append(self.new_menu_item('_Hide', self.nsm_hide_cb, "<Control>W"))
190 self.mixer_menu.append(self.new_menu_item('_Quit', self.on_quit_cb, "<Control>Q"))
192 edit_menu = Gtk.Menu()
193 edit_menu_item.set_submenu(edit_menu)
195 self.channel_edit_input_menu_item = self.new_menu_item('_Edit Input Channel',
197 edit_menu.append(self.channel_edit_input_menu_item)
198 self.channel_edit_input_menu = Gtk.Menu()
199 self.channel_edit_input_menu_item.set_submenu(self.channel_edit_input_menu)
201 self.channel_edit_output_menu_item = self.new_menu_item('E_dit Output Channel',
203 edit_menu.append(self.channel_edit_output_menu_item)
204 self.channel_edit_output_menu = Gtk.Menu()
205 self.channel_edit_output_menu_item.set_submenu(self.channel_edit_output_menu)
207 self.channel_remove_input_menu_item = self.new_menu_item('_Remove Input Channel',
209 edit_menu.append(self.channel_remove_input_menu_item)
210 self.channel_remove_input_menu = Gtk.Menu()
211 self.channel_remove_input_menu_item.set_submenu(self.channel_remove_input_menu)
213 self.channel_remove_output_menu_item = self.new_menu_item('Re_move Output Channel',
215 edit_menu.append(self.channel_remove_output_menu_item)
216 self.channel_remove_output_menu = Gtk.Menu()
217 self.channel_remove_output_menu_item.set_submenu(self.channel_remove_output_menu)
219 edit_menu.append(Gtk.SeparatorMenuItem())
220 edit_menu.append(self.new_menu_item('Shrink Channels', self.on_shrink_channels_cb, "<Control>minus"))
221 edit_menu.append(self.new_menu_item('Expand Channels', self.on_expand_channels_cb, "<Control>plus"))
222 edit_menu.append(Gtk.SeparatorMenuItem())
224 edit_menu.append(self.new_menu_item('_Clear', self.on_channels_clear, "<Control>X"))
225 edit_menu.append(Gtk.SeparatorMenuItem())
226 edit_menu.append(self.new_menu_item('_Preferences', self.on_preferences_cb, "<Control>P"))
228 help_menu = Gtk.Menu()
229 help_menu_item.set_submenu(help_menu)
231 help_menu.append(self.new_menu_item('_About', self.on_about, "F1"))
233 self.hbox_top = Gtk.HBox()
234 self.vbox_top.pack_start(self.hbox_top, True, True, 0)
236 self.scrolled_window = Gtk.ScrolledWindow()
237 self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
239 self.hbox_inputs = Gtk.Box()
240 self.hbox_inputs.set_spacing(0)
241 self.hbox_inputs.set_border_width(0)
242 self.hbox_top.set_spacing(0)
243 self.hbox_top.set_border_width(0)
244 self.scrolled_window.add(self.hbox_inputs)
245 self.hbox_outputs = Gtk.Box()
246 self.hbox_outputs.set_spacing(0)
247 self.hbox_outputs.set_border_width(0)
248 self.scrolled_output = Gtk.ScrolledWindow()
249 self.scrolled_output.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
250 self.scrolled_output.add(self.hbox_outputs)
251 self.paned = Gtk.HPaned()
252 self.paned.set_wide_handle(True)
253 self.hbox_top.pack_start(self.paned, True, True, 0)
254 self.paned.pack1(self.scrolled_window, True, False)
255 self.paned.pack2(self.scrolled_output, True, False)
256 self.window.connect("destroy", Gtk.main_quit)
257 self.window.connect('delete-event', self.on_delete_event)
260 self.nsm_client.reactToMessage()
263 def nsm_hide_cb(self, *args):
266 self.nsm_client.announceGuiVisibility(False)
268 def nsm_show_cb(self):
269 width, height = self.window.get_size()
270 self.window.show_all()
271 self.paned.set_position(self.paned_position/self.width*width)
274 self.nsm_client.announceGuiVisibility(True)
276 def nsm_open_cb(self, path, session_name, client_name):
277 self.create_mixer(client_name, with_nsm=True)
278 self.current_filename = path + '.xml'
279 if os.path.isfile(self.current_filename):
281 with open(self.current_filename, 'r') as fp:
282 self.load_from_xml(fp, from_nsm=True)
283 except Exception as exc:
284 # Re-raise with more meaningful error message
285 raise IOError("Error loading settings file '{}': {}".format(
286 self.current_filename, exc))
288 def nsm_save_cb(self, path, session_name, client_name):
289 self.current_filename = path + '.xml'
290 f = open(self.current_filename, 'w')
294 def nsm_exit_cb(self, path, session_name, client_name):
297 def on_midi_behavior_mode_changed(self, gui_factory, value):
298 self.mixer.midi_behavior_mode = value
300 def on_delete_event(self, widget, event):
305 return self.on_quit_cb()
307 def sighandler(self, signum, frame):
308 log.debug("Signal %d received.", signum)
309 if signum == signal.SIGUSR1:
311 elif signum == signal.SIGTERM:
313 elif signum == signal.SIGINT:
316 log.warning("Unknown signal %d received.", signum)
319 log.debug("Cleaning jack_mixer.")
323 for channel in self.channels:
328 def on_open_cb(self, *args):
329 dlg = Gtk.FileChooserDialog(title='Open', parent=self.window,
330 action=Gtk.FileChooserAction.OPEN)
331 dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
332 Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
333 dlg.set_default_response(Gtk.ResponseType.OK)
334 if dlg.run() == Gtk.ResponseType.OK:
335 filename = dlg.get_filename()
337 with open(filename, 'r') as fp:
338 self.load_from_xml(fp)
339 except Exception as exc:
340 error_dialog(self.window, "Error loading settings file '%s': %s", filename, exc)
342 self.current_filename = filename
345 def on_save_cb(self, *args):
346 if not self.current_filename:
347 return self.on_save_as_cb()
348 f = open(self.current_filename, 'w')
352 def on_save_as_cb(self, *args):
353 dlg = Gtk.FileChooserDialog(title='Save', parent=self.window,
354 action=Gtk.FileChooserAction.SAVE)
355 dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
356 Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
357 dlg.set_default_response(Gtk.ResponseType.OK)
358 if dlg.run() == Gtk.ResponseType.OK:
359 self.current_filename = dlg.get_filename()
363 def on_quit_cb(self, *args):
364 if not self.nsm_client and self.gui_factory.get_confirm_quit():
365 dlg = Gtk.MessageDialog(parent=self.window,
366 message_type=Gtk.MessageType.QUESTION,
367 buttons=Gtk.ButtonsType.NONE)
368 dlg.set_markup("<b>Quit application?</b>")
369 dlg.format_secondary_markup("All jack_mixer ports will be closed and connections lost,"
370 "\nstopping all sound going through jack_mixer.\n\n"
373 Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
374 Gtk.STOCK_QUIT, Gtk.ResponseType.OK
378 if response != Gtk.ResponseType.OK:
383 def on_shrink_channels_cb(self, widget):
384 for channel in self.channels + self.output_channels:
387 def on_expand_channels_cb(self, widget):
388 for channel in self.channels + self.output_channels:
391 preferences_dialog = None
392 def on_preferences_cb(self, widget):
393 if not self.preferences_dialog:
394 self.preferences_dialog = PreferencesDialog(self)
395 self.preferences_dialog.show()
396 self.preferences_dialog.present()
398 def on_add_channel(self, inout="input", default_name="Input"):
399 dialog = getattr(self, '_add_{}_dialog'.format(inout), None)
400 values = getattr(self, '_add_{}_values'.format(inout), {})
403 cls = NewInputChannelDialog if inout == 'input' else NewOutputChannelDialog
404 dialog = cls(app=self)
405 setattr(self, '_add_{}_dialog'.format(inout), dialog)
407 names = {ch.channel_name
408 for ch in (self.channels if inout == 'input' else self.output_channels)}
409 values.setdefault('name', default_name)
411 if values['name'] in names:
412 values['name'] = add_number_suffix(values['name'])
416 dialog.fill_ui(**values)
417 dialog.set_transient_for(self.window)
422 if ret == Gtk.ResponseType.OK:
423 result = dialog.get_result()
424 setattr(self, '_add_{}_values'.format(inout), result)
425 method = getattr(self, 'add_channel' if inout == 'input' else 'add_output_channel')
426 channel = method(**result)
427 if self.visible or self.nsm_client == None:
428 self.window.show_all()
430 def on_add_input_channel(self, widget):
431 return self.on_add_channel("input", "Input")
433 def on_add_output_channel(self, widget):
434 return self.on_add_channel("output", "Output")
436 def on_edit_input_channel(self, widget, channel):
437 log.debug('Editing input channel "%s".', channel.channel_name)
438 channel.on_channel_properties()
440 def remove_channel_edit_input_menuitem_by_label(self, widget, label):
441 if (widget.get_label() == label):
442 self.channel_edit_input_menu.remove(widget)
444 def on_remove_input_channel(self, widget, channel):
445 log.debug('Removing input channel "%s".', channel.channel_name)
446 self.channel_remove_input_menu.remove(widget)
447 self.channel_edit_input_menu.foreach(
448 self.remove_channel_edit_input_menuitem_by_label,
449 channel.channel_name);
450 if self.monitored_channel is channel:
451 channel.monitor_button.set_active(False)
452 for i in range(len(self.channels)):
453 if self.channels[i] is channel:
456 self.hbox_inputs.remove(channel.get_parent())
458 if not self.channels:
459 self.channel_edit_input_menu_item.set_sensitive(False)
460 self.channel_remove_input_menu_item.set_sensitive(False)
462 def on_edit_output_channel(self, widget, channel):
463 log.debug('Editing output channel "%s".', channel.channel_name)
464 channel.on_channel_properties()
466 def remove_channel_edit_output_menuitem_by_label(self, widget, label):
467 if (widget.get_label() == label):
468 self.channel_edit_output_menu.remove(widget)
470 def on_remove_output_channel(self, widget, channel):
471 log.debug('Removing output channel "%s".', channel.channel_name)
472 self.channel_remove_output_menu.remove(widget)
473 self.channel_edit_output_menu.foreach(
474 self.remove_channel_edit_output_menuitem_by_label,
475 channel.channel_name);
476 if self.monitored_channel is channel:
477 channel.monitor_button.set_active(False)
478 for i in range(len(self.channels)):
479 if self.output_channels[i] is channel:
481 del self.output_channels[i]
482 self.hbox_outputs.remove(channel.get_parent())
484 if not self.output_channels:
485 self.channel_edit_output_menu_item.set_sensitive(False)
486 self.channel_remove_output_menu_item.set_sensitive(False)
488 def rename_channels(self, container, parameters):
489 if (container.get_label() == parameters['oldname']):
490 container.set_label(parameters['newname'])
492 def on_channel_rename(self, oldname, newname):
493 rename_parameters = { 'oldname' : oldname, 'newname' : newname }
494 self.channel_edit_input_menu.foreach(self.rename_channels,
496 self.channel_edit_output_menu.foreach(self.rename_channels,
498 self.channel_remove_input_menu.foreach(self.rename_channels,
500 self.channel_remove_output_menu.foreach(self.rename_channels,
502 log.debug('Renaming channel from "%s" to "%s".', oldname, newname)
504 def on_channels_clear(self, widget):
505 dlg = Gtk.MessageDialog(parent = self.window,
507 message_type = Gtk.MessageType.WARNING,
508 text = "Are you sure you want to clear all channels?",
509 buttons = Gtk.ButtonsType.OK_CANCEL)
510 if not widget or dlg.run() == Gtk.ResponseType.OK:
511 for channel in self.output_channels:
513 self.hbox_outputs.remove(channel.get_parent())
514 for channel in self.channels:
516 self.hbox_inputs.remove(channel.get_parent())
518 self.output_channels = []
519 self.channel_edit_input_menu = Gtk.Menu()
520 self.channel_edit_input_menu_item.set_submenu(self.channel_edit_input_menu)
521 self.channel_edit_input_menu_item.set_sensitive(False)
522 self.channel_remove_input_menu = Gtk.Menu()
523 self.channel_remove_input_menu_item.set_submenu(self.channel_remove_input_menu)
524 self.channel_remove_input_menu_item.set_sensitive(False)
525 self.channel_edit_output_menu = Gtk.Menu()
526 self.channel_edit_output_menu_item.set_submenu(self.channel_edit_output_menu)
527 self.channel_edit_output_menu_item.set_sensitive(False)
528 self.channel_remove_output_menu = Gtk.Menu()
529 self.channel_remove_output_menu_item.set_submenu(self.channel_remove_output_menu)
530 self.channel_remove_output_menu_item.set_sensitive(False)
533 def add_channel(self, name, stereo, volume_cc, balance_cc, mute_cc, solo_cc, value):
535 channel = InputChannel(self, name, stereo, value)
536 self.add_channel_precreated(channel)
538 error_dialog(self.window, "Channel creation failed.")
541 channel.channel.volume_midi_cc = volume_cc
543 channel.channel.autoset_volume_midi_cc()
545 channel.channel.balance_midi_cc = balance_cc
547 channel.channel.autoset_balance_midi_cc()
549 channel.channel.mute_midi_cc = mute_cc
551 channel.channel.autoset_mute_midi_cc()
553 channel.channel.solo_midi_cc = solo_cc
555 channel.channel.autoset_solo_midi_cc()
559 def add_channel_precreated(self, channel):
562 self.hbox_inputs.pack_start(frame, False, True, 0)
565 channel_edit_menu_item = Gtk.MenuItem(label=channel.channel_name)
566 self.channel_edit_input_menu.append(channel_edit_menu_item)
567 channel_edit_menu_item.connect("activate", self.on_edit_input_channel, channel)
568 self.channel_edit_input_menu_item.set_sensitive(True)
570 channel_remove_menu_item = Gtk.MenuItem(label=channel.channel_name)
571 self.channel_remove_input_menu.append(channel_remove_menu_item)
572 channel_remove_menu_item.connect("activate", self.on_remove_input_channel, channel)
573 self.channel_remove_input_menu_item.set_sensitive(True)
575 self.channels.append(channel)
577 for outputchannel in self.output_channels:
578 channel.add_control_group(outputchannel)
580 # create post fader output channel matching the input channel
581 channel.post_fader_output_channel = self.mixer.add_output_channel(
582 channel.channel.name + ' Out', channel.channel.is_stereo, True)
583 channel.post_fader_output_channel.volume = 0
584 channel.post_fader_output_channel.set_solo(channel.channel, True)
586 channel.connect('input-channel-order-changed', self.on_input_channel_order_changed)
588 def on_input_channel_order_changed(self, widget, source_name, dest_name):
589 self.channels.clear()
591 channel_box = self.hbox_inputs
592 frames = channel_box.get_children()
596 if source_name == c._channel_name:
602 if (dest_name == c._channel_name):
603 pos = frames.index(f)
604 channel_box.reorder_child(source_frame, pos)
607 for frame in self.hbox_inputs.get_children():
608 c = frame.get_child()
609 self.channels.append(c)
611 def read_meters(self):
612 for channel in self.channels:
614 for channel in self.output_channels:
618 def midi_events_check(self):
619 for channel in self.channels + self.output_channels:
620 channel.midi_events_check()
623 def add_output_channel(self, name, stereo, volume_cc, balance_cc, mute_cc,
624 display_solo_buttons, color, value):
626 channel = OutputChannel(self, name, stereo, value)
627 channel.display_solo_buttons = display_solo_buttons
628 channel.color = color
629 self.add_output_channel_precreated(channel)
631 error_dialog(self.window, "Channel creation failed")
635 channel.channel.volume_midi_cc = volume_cc
637 channel.channel.autoset_volume_midi_cc()
639 channel.channel.balance_midi_cc = balance_cc
641 channel.channel.autoset_balance_midi_cc()
643 channel.channel.mute_midi_cc = mute_cc
645 channel.channel.autoset_mute_midi_cc()
649 def add_output_channel_precreated(self, channel):
652 self.hbox_outputs.pack_end(frame, False, True, 0)
653 self.hbox_outputs.reorder_child(frame, 0)
656 channel_edit_menu_item = Gtk.MenuItem(label=channel.channel_name)
657 self.channel_edit_output_menu.append(channel_edit_menu_item)
658 channel_edit_menu_item.connect("activate", self.on_edit_output_channel, channel)
659 self.channel_edit_output_menu_item.set_sensitive(True)
661 channel_remove_menu_item = Gtk.MenuItem(label=channel.channel_name)
662 self.channel_remove_output_menu.append(channel_remove_menu_item)
663 channel_remove_menu_item.connect("activate", self.on_remove_output_channel, channel)
664 self.channel_remove_output_menu_item.set_sensitive(True)
666 self.output_channels.append(channel)
667 channel.connect('output-channel-order-changed', self.on_output_channel_order_changed)
669 def on_output_channel_order_changed(self, widget, source_name, dest_name):
670 self.output_channels.clear()
671 channel_box = self.hbox_outputs
673 frames = channel_box.get_children()
677 if source_name == c._channel_name:
683 if (dest_name == c._channel_name):
684 pos = len(frames) - 1 - frames.index(f)
685 channel_box.reorder_child(source_frame, pos)
688 for frame in self.hbox_outputs.get_children():
689 c = frame.get_child()
690 self.output_channels.append(c)
692 _monitored_channel = None
693 def get_monitored_channel(self):
694 return self._monitored_channel
696 def set_monitored_channel(self, channel):
697 if self._monitored_channel:
698 if channel.channel.name == self._monitored_channel.channel.name:
700 self._monitored_channel = channel
701 if type(channel) is InputChannel:
702 # reset all solo/mute settings
703 for in_channel in self.channels:
704 self.monitor_channel.set_solo(in_channel.channel, False)
705 self.monitor_channel.set_muted(in_channel.channel, False)
706 self.monitor_channel.set_solo(channel.channel, True)
707 self.monitor_channel.prefader = True
709 self.monitor_channel.prefader = False
710 self.update_monitor(channel)
711 monitored_channel = property(get_monitored_channel, set_monitored_channel)
713 def update_monitor(self, channel):
714 if self._monitored_channel is not channel:
716 self.monitor_channel.volume = channel.channel.volume
717 self.monitor_channel.balance = channel.channel.balance
718 if type(self.monitored_channel) is OutputChannel:
719 # sync solo/muted channels
720 for input_channel in self.channels:
721 self.monitor_channel.set_solo(input_channel.channel,
722 channel.channel.is_solo(input_channel.channel))
723 self.monitor_channel.set_muted(input_channel.channel,
724 channel.channel.is_muted(input_channel.channel))
726 def get_input_channel_by_name(self, name):
727 for input_channel in self.channels:
728 if input_channel.channel.name == name:
732 def on_about(self, *args):
733 about = Gtk.AboutDialog()
734 about.set_name('jack_mixer')
735 about.set_program_name('jack_mixer')
736 about.set_copyright('Copyright © 2006-2020\nNedko Arnaudov, Frédéric Péters, Arnout Engelen, Daniel Sheeler')
737 about.set_license("""\
738 jack_mixer is free software; you can redistribute it and/or modify it
739 under the terms of the GNU General Public License as published by the
740 Free Software Foundation; either version 2 of the License, or (at your
741 option) any later version.
743 jack_mixer is distributed in the hope that it will be useful, but
744 WITHOUT ANY WARRANTY; without even the implied warranty of
745 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
746 General Public License for more details.
748 You should have received a copy of the GNU General Public License along
749 with jack_mixer; if not, write to the Free Software Foundation, Inc., 51
750 Franklin Street, Fifth Floor, Boston, MA 02110-130159 USA""")
752 'Nedko Arnaudov <nedko@arnaudov.name>',
753 'Christopher Arndt <chris@chrisarndt.de>',
754 'Arnout Engelen <arnouten@bzzt.net>',
755 'John Hedges <john@drystone.co.uk>',
756 'Olivier Humbert <trebmuh@tuxfamily.org>',
757 'Sarah Mischke <sarah@spooky-online.de>',
758 'Frédéric Péters <fpeters@0d.be>',
759 'Daniel Sheeler <dsheeler@pobox.com>',
760 'Athanasios Silis <athanasios.silis@gmail.com>',
762 about.set_logo_icon_name('jack_mixer')
763 about.set_version(__version__)
764 about.set_website('https://rdio.space/jackmixer/')
769 def save_to_xml(self, file):
770 log.debug("Saving to XML...")
771 b = XmlSerialization()
776 def load_from_xml(self, file, silence_errors=False, from_nsm=False):
777 log.debug("Loading from XML...")
778 self.unserialized_channels = []
779 b = XmlSerialization()
786 self.on_channels_clear(None)
788 s.unserialize(self, b)
789 for channel in self.unserialized_channels:
790 if isinstance(channel, InputChannel):
791 if self._init_solo_channels and channel.channel_name in self._init_solo_channels:
793 self.add_channel_precreated(channel)
794 self._init_solo_channels = None
795 for channel in self.unserialized_channels:
796 if isinstance(channel, OutputChannel):
797 self.add_output_channel_precreated(channel)
798 del self.unserialized_channels
799 width, height = self.window.get_size()
800 if self.visible or not from_nsm:
801 self.window.show_all()
803 if self.output_channels:
804 self.output_channels[-1].volume_digits.select_region(0,0)
805 self.output_channels[-1].slider.grab_focus()
807 self.channels[-1].volume_digits.select_region(0,0)
808 self.channels[-1].volume_digits.grab_focus()
810 self.paned.set_position(self.paned_position/self.width*width)
811 self.window.resize(self.width, self.height)
813 def serialize(self, object_backend):
814 width, height = self.window.get_size()
815 object_backend.add_property('geometry',
816 '%sx%s' % (width, height))
817 pos = self.paned.get_position()
818 object_backend.add_property('paned_position', '%s' % pos)
820 for input_channel in self.channels:
821 if input_channel.channel.solo:
822 solo_channels.append(input_channel)
824 object_backend.add_property('solo_channels', '|'.join([x.channel.name for x in solo_channels]))
825 object_backend.add_property('visible', '%s' % str(self.visible))
827 def unserialize_property(self, name, value):
828 if name == 'geometry':
829 width, height = value.split('x')
830 self.width = int(width)
831 self.height = int(height)
833 if name == 'solo_channels':
834 self._init_solo_channels = value.split('|')
836 if name == 'visible':
837 self.visible = value == 'True'
839 if name == 'paned_position':
840 self.paned_position = int(value)
844 def unserialize_child(self, name):
845 if name == InputChannel.serialization_name():
846 channel = InputChannel(self, "", True)
847 self.unserialized_channels.append(channel)
850 if name == OutputChannel.serialization_name():
851 channel = OutputChannel(self, "", True)
852 self.unserialized_channels.append(channel)
855 if name == gui.Factory.serialization_name():
856 return self.gui_factory
858 def serialization_get_childs(self):
859 '''Get child objects that required and support serialization'''
860 childs = self.channels[:] + self.output_channels[:] + [self.gui_factory]
863 def serialization_name(self):
870 if self.visible or self.nsm_client == None:
871 width, height = self.window.get_size()
872 self.window.show_all()
873 if hasattr(self, 'paned_position'):
874 self.paned.set_position(self.paned_position/self.width*width)
876 signal.signal(signal.SIGUSR1, self.sighandler)
877 signal.signal(signal.SIGTERM, self.sighandler)
878 signal.signal(signal.SIGINT, self.sighandler)
879 signal.signal(signal.SIGHUP, signal.SIG_IGN)
883 def error_dialog(parent, msg, *args):
884 log.exception(msg, *args)
885 err = Gtk.MessageDialog(parent=parent, modal=True, destroy_with_parent=True,
886 message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text=msg % args)
891 parser = ArgumentParser()
892 parser.add_argument('-c', '--config', metavar="FILE", help='load mixer project configuration from FILE')
893 parser.add_argument('-d', '--debug', action="store_true", help='enable debug logging messages')
894 parser.add_argument('client_name', metavar='NAME', nargs='?', default='jack_mixer',
895 help='set JACK client name')
896 args = parser.parse_args()
898 logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO,
899 format="%(levelname)s: %(message)s")
902 mixer = JackMixer(args.client_name)
903 except Exception as e:
904 error_dialog(None, "Mixer creation failed:\n\n%s", e)
907 if not mixer.nsm_client and args.config:
909 with open(args.config) as fp:
910 mixer.load_from_xml(fp)
911 except Exception as exc:
912 error_dialog(mixer.window, "Error loading settings file '%s': %s", args.config, exc)
914 mixer.current_filename = args.config
916 mixer.window.set_default_size(60*(1+len(mixer.channels)+len(mixer.output_channels)), 300)
922 if __name__ == "__main__":