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.
26 from argparse import ArgumentParser
29 gi.require_version('Gtk', '3.0')
30 from gi.repository import Gtk
31 from gi.repository import GObject
32 from gi.repository import GLib
34 # temporary change Python modules lookup path to look into installation
35 # directory ($prefix/share/jack_mixer/)
37 sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '..', 'share', 'jack_mixer'))
44 from nsmclient import NSMClient
45 from serialization_xml import XmlSerialization
46 from serialization import SerializedObject, Serializator
47 from preferences import PreferencesDialog
49 # restore Python modules lookup path
51 log = logging.getLogger("jack_mixer")
53 class JackMixer(SerializedObject):
55 # scales suitable as meter scales
56 meter_scales = [scale.K20(), scale.K14(), scale.IEC268(), scale.Linear70dB(), scale.IEC268Minimalistic()]
58 # scales suitable as volume slider scales
59 slider_scales = [scale.Linear30dB(), scale.Linear70dB()]
61 # name of settngs file that is currently open
62 current_filename = None
64 _init_solo_channels = None
66 def __init__(self, client_name='jack_mixer'):
68 self.nsm_client = None
70 if os.environ.get('NSM_URL'):
71 self.nsm_client = NSMClient(prettyName = "jack_mixer",
72 saveCallback = self.nsm_save_cb,
73 openOrNewCallback = self.nsm_open_cb,
74 supportsSaveStatus = False,
75 hideGUICallback = self.nsm_hide_cb,
76 showGUICallback = self.nsm_show_cb,
77 exitProgramCallback = self.nsm_exit_cb,
78 loggingLevel = "error",
80 self.nsm_client.announceGuiVisibility(self.visible)
83 self.create_mixer(client_name, with_nsm = False)
85 def create_mixer(self, client_name, with_nsm = True):
86 self.mixer = jack_mixer_c.Mixer(client_name)
87 self.create_ui(with_nsm)
91 self.window.set_title(client_name)
93 self.monitor_channel = self.mixer.add_output_channel("Monitor", True, True)
96 GLib.timeout_add(33, self.read_meters)
98 GLib.timeout_add(200, self.nsm_react)
99 GLib.timeout_add(50, self.midi_events_check)
101 def new_menu_item(self, title, callback=None, accel=None, enabled=True):
102 menuitem = Gtk.MenuItem.new_with_mnemonic(title)
103 menuitem.set_sensitive(enabled)
105 menuitem.connect("activate", callback)
107 key, mod = Gtk.accelerator_parse(accel)
108 menuitem.add_accelerator("activate", self.menu_accelgroup, key, mod,
109 Gtk.AccelFlags.VISIBLE)
112 def create_ui(self, with_nsm):
114 self.output_channels = []
115 self.window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
116 self.window.set_icon_name('jack_mixer')
117 self.gui_factory = gui.Factory(self.window, self.meter_scales, self.slider_scales)
118 self.gui_factory.connect('midi-behavior-mode-changed', self.on_midi_behavior_mode_changed)
119 self.gui_factory.emit_midi_behavior_mode()
121 self.vbox_top = Gtk.VBox()
122 self.window.add(self.vbox_top)
124 self.menu_accelgroup = Gtk.AccelGroup()
125 self.window.add_accel_group(self.menu_accelgroup)
127 self.menubar = Gtk.MenuBar()
128 self.vbox_top.pack_start(self.menubar, False, True, 0)
130 mixer_menu_item = Gtk.MenuItem.new_with_mnemonic("_Mixer")
131 self.menubar.append(mixer_menu_item)
132 edit_menu_item = Gtk.MenuItem.new_with_mnemonic('_Edit')
133 self.menubar.append(edit_menu_item)
134 help_menu_item = Gtk.MenuItem.new_with_mnemonic('_Help')
135 self.menubar.append(help_menu_item)
139 self.paned_position = 210
140 self.window.set_default_size(self.width, self.height)
142 self.mixer_menu = Gtk.Menu()
143 mixer_menu_item.set_submenu(self.mixer_menu)
145 self.mixer_menu.append(self.new_menu_item('New _Input Channel',
146 self.on_add_input_channel, "<Control>N"))
147 self.mixer_menu.append(self.new_menu_item('New Output _Channel',
148 self.on_add_output_channel, "<Shift><Control>N"))
150 self.mixer_menu.append(Gtk.SeparatorMenuItem())
152 self.mixer_menu.append(self.new_menu_item('_Open...', self.on_open_cb, "<Control>O"))
154 self.mixer_menu.append(self.new_menu_item('_Save', self.on_save_cb, "<Control>S"))
157 self.mixer_menu.append(self.new_menu_item('Save _As...', self.on_save_as_cb,
158 "<Shift><Control>S"))
160 self.mixer_menu.append(Gtk.SeparatorMenuItem())
162 self.mixer_menu.append(self.new_menu_item('_Hide', self.nsm_hide_cb, "<Control>W"))
164 self.mixer_menu.append(self.new_menu_item('_Quit', self.on_quit_cb, "<Control>Q"))
166 edit_menu = Gtk.Menu()
167 edit_menu_item.set_submenu(edit_menu)
169 self.channel_edit_input_menu_item = self.new_menu_item('_Edit Input Channel',
171 edit_menu.append(self.channel_edit_input_menu_item)
172 self.channel_edit_input_menu = Gtk.Menu()
173 self.channel_edit_input_menu_item.set_submenu(self.channel_edit_input_menu)
175 self.channel_edit_output_menu_item = self.new_menu_item('E_dit Output Channel',
177 edit_menu.append(self.channel_edit_output_menu_item)
178 self.channel_edit_output_menu = Gtk.Menu()
179 self.channel_edit_output_menu_item.set_submenu(self.channel_edit_output_menu)
181 self.channel_remove_input_menu_item = self.new_menu_item('_Remove Input Channel',
183 edit_menu.append(self.channel_remove_input_menu_item)
184 self.channel_remove_input_menu = Gtk.Menu()
185 self.channel_remove_input_menu_item.set_submenu(self.channel_remove_input_menu)
187 self.channel_remove_output_menu_item = self.new_menu_item('Re_move Output Channel',
189 edit_menu.append(self.channel_remove_output_menu_item)
190 self.channel_remove_output_menu = Gtk.Menu()
191 self.channel_remove_output_menu_item.set_submenu(self.channel_remove_output_menu)
193 edit_menu.append(Gtk.SeparatorMenuItem())
194 edit_menu.append(self.new_menu_item('Shrink Input Channels', self.on_narrow_input_channels_cb, "<Control>minus"))
195 edit_menu.append(self.new_menu_item('Expand Input Channels', self.on_widen_input_channels_cb, "<Control>plus"))
196 edit_menu.append(Gtk.SeparatorMenuItem())
198 edit_menu.append(self.new_menu_item('_Clear', self.on_channels_clear, "<Control>X"))
199 edit_menu.append(Gtk.SeparatorMenuItem())
200 edit_menu.append(self.new_menu_item('_Preferences', self.on_preferences_cb, "<Control>P"))
202 help_menu = Gtk.Menu()
203 help_menu_item.set_submenu(help_menu)
205 help_menu.append(self.new_menu_item('_About', self.on_about, "F1"))
207 self.hbox_top = Gtk.HBox()
208 self.vbox_top.pack_start(self.hbox_top, True, True, 0)
210 self.scrolled_window = Gtk.ScrolledWindow()
211 self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
213 self.hbox_inputs = Gtk.Box()
214 self.hbox_inputs.set_spacing(0)
215 self.hbox_inputs.set_border_width(0)
216 self.hbox_top.set_spacing(0)
217 self.hbox_top.set_border_width(0)
218 self.scrolled_window.add(self.hbox_inputs)
219 self.hbox_outputs = Gtk.Box()
220 self.hbox_outputs.set_spacing(0)
221 self.hbox_outputs.set_border_width(0)
222 self.scrolled_output = Gtk.ScrolledWindow()
223 self.scrolled_output.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
224 self.scrolled_output.add(self.hbox_outputs)
225 self.paned = Gtk.HPaned()
226 self.paned.set_wide_handle(True)
227 self.hbox_top.pack_start(self.paned, True, True, 0)
228 self.paned.pack1(self.scrolled_window, True, False)
229 self.paned.pack2(self.scrolled_output, True, False)
230 self.window.connect("destroy", Gtk.main_quit)
231 self.window.connect('delete-event', self.on_delete_event)
234 self.nsm_client.reactToMessage()
237 def nsm_hide_cb(self, *args):
240 self.nsm_client.announceGuiVisibility(False)
242 def nsm_show_cb(self):
243 width, height = self.window.get_size()
244 self.window.show_all()
245 self.paned.set_position(self.paned_position/self.width*width)
248 self.nsm_client.announceGuiVisibility(True)
250 def nsm_open_cb(self, path, session_name, client_name):
251 self.create_mixer(client_name, with_nsm = True)
252 self.current_filename = path + '.xml'
253 if os.path.isfile(self.current_filename):
254 f = open(self.current_filename, 'r')
255 self.load_from_xml(f, from_nsm=True)
258 f = open(self.current_filename, 'w')
261 def nsm_save_cb(self, path, session_name, client_name):
262 self.current_filename = path + '.xml'
263 f = open(self.current_filename, 'w')
267 def nsm_exit_cb(self, path, session_name, client_name):
270 def on_midi_behavior_mode_changed(self, gui_factory, value):
271 self.mixer.midi_behavior_mode = value
273 def on_delete_event(self, widget, event):
280 def sighandler(self, signum, frame):
281 log.debug("Signal %d received.", signum)
282 if signum == signal.SIGUSR1:
284 elif signum == signal.SIGTERM:
286 elif signum == signal.SIGINT:
289 log.warning("Unknown signal %d received.", signum)
292 log.debug("Cleaning jack_mixer.")
296 for channel in self.channels:
301 def on_open_cb(self, *args):
302 dlg = Gtk.FileChooserDialog(title='Open', parent=self.window,
303 action=Gtk.FileChooserAction.OPEN)
304 dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
305 Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
306 dlg.set_default_response(Gtk.ResponseType.OK)
307 if dlg.run() == Gtk.ResponseType.OK:
308 filename = dlg.get_filename()
310 f = open(filename, 'r')
311 self.load_from_xml(f)
312 except Exception as e:
313 error_dialog(self.window, "Failed loading settings (%s)", e)
315 self.current_filename = filename
320 def on_save_cb(self, *args):
321 if not self.current_filename:
322 return self.on_save_as_cb()
323 f = open(self.current_filename, 'w')
327 def on_save_as_cb(self, *args):
328 dlg = Gtk.FileChooserDialog(title='Save', parent=self.window,
329 action=Gtk.FileChooserAction.SAVE)
330 dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
331 Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
332 dlg.set_default_response(Gtk.ResponseType.OK)
333 if dlg.run() == Gtk.ResponseType.OK:
334 self.current_filename = dlg.get_filename()
338 def on_quit_cb(self, *args):
341 def on_narrow_input_channels_cb(self, widget):
342 for channel in self.channels:
345 def on_widen_input_channels_cb(self, widget):
346 for channel in self.channels:
349 preferences_dialog = None
350 def on_preferences_cb(self, widget):
351 if not self.preferences_dialog:
352 self.preferences_dialog = PreferencesDialog(self)
353 self.preferences_dialog.show()
354 self.preferences_dialog.present()
356 def on_add_input_channel(self, widget):
357 dialog = NewInputChannelDialog(app=self)
358 dialog.set_transient_for(self.window)
363 if ret == Gtk.ResponseType.OK:
364 result = dialog.get_result()
365 channel = self.add_channel(**result)
366 if self.visible or self.nsm_client == None:
367 self.window.show_all()
369 def on_add_output_channel(self, widget):
370 dialog = NewOutputChannelDialog(app=self)
371 dialog.set_transient_for(self.window)
376 if ret == Gtk.ResponseType.OK:
377 result = dialog.get_result()
378 channel = self.add_output_channel(**result)
379 if self.visible or self.nsm_client == None:
380 self.window.show_all()
382 def on_edit_input_channel(self, widget, channel):
383 log.debug('Editing input channel "%s".', channel.channel_name)
384 channel.on_channel_properties()
386 def remove_channel_edit_input_menuitem_by_label(self, widget, label):
387 if (widget.get_label() == label):
388 self.channel_edit_input_menu.remove(widget)
390 def on_remove_input_channel(self, widget, channel):
391 log.debug('Removing input channel "%s".', channel.channel_name)
392 self.channel_remove_input_menu.remove(widget)
393 self.channel_edit_input_menu.foreach(
394 self.remove_channel_edit_input_menuitem_by_label,
395 channel.channel_name);
396 if self.monitored_channel is channel:
397 channel.monitor_button.set_active(False)
398 for i in range(len(self.channels)):
399 if self.channels[i] is channel:
402 self.hbox_inputs.remove(channel.get_parent())
404 if not self.channels:
405 self.channel_edit_input_menu_item.set_sensitive(False)
406 self.channel_remove_input_menu_item.set_sensitive(False)
408 def on_edit_output_channel(self, widget, channel):
409 log.debug('Editing output channel "%s".', channel.channel_name)
410 channel.on_channel_properties()
412 def remove_channel_edit_output_menuitem_by_label(self, widget, label):
413 if (widget.get_label() == label):
414 self.channel_edit_output_menu.remove(widget)
416 def on_remove_output_channel(self, widget, channel):
417 log.debug('Removing output channel "%s".', channel.channel_name)
418 self.channel_remove_output_menu.remove(widget)
419 self.channel_edit_output_menu.foreach(
420 self.remove_channel_edit_output_menuitem_by_label,
421 channel.channel_name);
422 if self.monitored_channel is channel:
423 channel.monitor_button.set_active(False)
424 for i in range(len(self.channels)):
425 if self.output_channels[i] is channel:
427 del self.output_channels[i]
428 self.hbox_outputs.remove(channel.get_parent())
430 if not self.output_channels:
431 self.channel_edit_output_menu_item.set_sensitive(False)
432 self.channel_remove_output_menu_item.set_sensitive(False)
434 def rename_channels(self, container, parameters):
435 if (container.get_label() == parameters['oldname']):
436 container.set_label(parameters['newname'])
438 def on_channel_rename(self, oldname, newname):
439 rename_parameters = { 'oldname' : oldname, 'newname' : newname }
440 self.channel_edit_input_menu.foreach(self.rename_channels,
442 self.channel_edit_output_menu.foreach(self.rename_channels,
444 self.channel_remove_input_menu.foreach(self.rename_channels,
446 self.channel_remove_output_menu.foreach(self.rename_channels,
448 log.debug('Renaming channel from "%s" to "%s".', oldname, newname)
450 def on_channels_clear(self, widget):
451 dlg = Gtk.MessageDialog(parent = self.window,
453 message_type = Gtk.MessageType.WARNING,
454 text = "Are you sure you want to clear all channels?",
455 buttons = Gtk.ButtonsType.OK_CANCEL)
456 if not widget or dlg.run() == Gtk.ResponseType.OK:
457 for channel in self.output_channels:
459 self.hbox_outputs.remove(channel.get_parent())
460 for channel in self.channels:
462 self.hbox_inputs.remove(channel.get_parent())
464 self.output_channels = []
465 self.channel_edit_input_menu = Gtk.Menu()
466 self.channel_edit_input_menu_item.set_submenu(self.channel_edit_input_menu)
467 self.channel_edit_input_menu_item.set_sensitive(False)
468 self.channel_remove_input_menu = Gtk.Menu()
469 self.channel_remove_input_menu_item.set_submenu(self.channel_remove_input_menu)
470 self.channel_remove_input_menu_item.set_sensitive(False)
471 self.channel_edit_output_menu = Gtk.Menu()
472 self.channel_edit_output_menu_item.set_submenu(self.channel_edit_output_menu)
473 self.channel_edit_output_menu_item.set_sensitive(False)
474 self.channel_remove_output_menu = Gtk.Menu()
475 self.channel_remove_output_menu_item.set_submenu(self.channel_remove_output_menu)
476 self.channel_remove_output_menu_item.set_sensitive(False)
479 def add_channel(self, name, stereo, volume_cc, balance_cc, mute_cc, solo_cc, value):
481 channel = InputChannel(self, name, stereo, value)
482 self.add_channel_precreated(channel)
484 error_dialog(self.window, "Channel creation failed.")
487 channel.channel.volume_midi_cc = volume_cc
489 channel.channel.autoset_volume_midi_cc()
491 channel.channel.balance_midi_cc = balance_cc
493 channel.channel.autoset_balance_midi_cc()
495 channel.channel.mute_midi_cc = mute_cc
497 channel.channel.autoset_mute_midi_cc()
499 channel.channel.solo_midi_cc = solo_cc
501 channel.channel.autoset_solo_midi_cc()
505 def add_channel_precreated(self, channel):
508 self.hbox_inputs.pack_start(frame, False, True, 0)
511 channel_edit_menu_item = Gtk.MenuItem(label=channel.channel_name)
512 self.channel_edit_input_menu.append(channel_edit_menu_item)
513 channel_edit_menu_item.connect("activate", self.on_edit_input_channel, channel)
514 self.channel_edit_input_menu_item.set_sensitive(True)
516 channel_remove_menu_item = Gtk.MenuItem(label=channel.channel_name)
517 self.channel_remove_input_menu.append(channel_remove_menu_item)
518 channel_remove_menu_item.connect("activate", self.on_remove_input_channel, channel)
519 self.channel_remove_input_menu_item.set_sensitive(True)
521 self.channels.append(channel)
523 for outputchannel in self.output_channels:
524 channel.add_control_group(outputchannel)
526 # create post fader output channel matching the input channel
527 channel.post_fader_output_channel = self.mixer.add_output_channel(
528 channel.channel.name + ' Out', channel.channel.is_stereo, True)
529 channel.post_fader_output_channel.volume = 0
530 channel.post_fader_output_channel.set_solo(channel.channel, True)
532 channel.connect('input-channel-order-changed', self.on_input_channel_order_changed)
534 def on_input_channel_order_changed(self, widget, source_name, dest_name):
535 self.channels.clear()
537 channel_box = self.hbox_inputs
538 frames = channel_box.get_children()
542 if source_name == c._channel_name:
548 if (dest_name == c._channel_name):
549 pos = frames.index(f)
550 channel_box.reorder_child(source_frame, pos)
553 for frame in self.hbox_inputs.get_children():
554 c = frame.get_child()
555 self.channels.append(c)
557 def read_meters(self):
558 for channel in self.channels:
560 for channel in self.output_channels:
564 def midi_events_check(self):
565 for channel in self.channels + self.output_channels:
566 channel.midi_events_check()
569 def add_output_channel(self, name, stereo, volume_cc, balance_cc, mute_cc,
570 display_solo_buttons, color, value):
572 channel = OutputChannel(self, name, stereo, value)
573 channel.display_solo_buttons = display_solo_buttons
574 channel.color = color
575 self.add_output_channel_precreated(channel)
577 error_dialog(self.window, "Channel creation failed")
581 channel.channel.volume_midi_cc = volume_cc
583 channel.channel.autoset_volume_midi_cc()
585 channel.channel.balance_midi_cc = balance_cc
587 channel.channel.autoset_balance_midi_cc()
589 channel.channel.mute_midi_cc = mute_cc
591 channel.channel.autoset_mute_midi_cc()
595 def add_output_channel_precreated(self, channel):
598 self.hbox_outputs.pack_end(frame, False, True, 0)
599 self.hbox_outputs.reorder_child(frame, 0)
602 channel_edit_menu_item = Gtk.MenuItem(label=channel.channel_name)
603 self.channel_edit_output_menu.append(channel_edit_menu_item)
604 channel_edit_menu_item.connect("activate", self.on_edit_output_channel, channel)
605 self.channel_edit_output_menu_item.set_sensitive(True)
607 channel_remove_menu_item = Gtk.MenuItem(label=channel.channel_name)
608 self.channel_remove_output_menu.append(channel_remove_menu_item)
609 channel_remove_menu_item.connect("activate", self.on_remove_output_channel, channel)
610 self.channel_remove_output_menu_item.set_sensitive(True)
612 self.output_channels.append(channel)
613 channel.connect('output-channel-order-changed', self.on_output_channel_order_changed)
615 def on_output_channel_order_changed(self, widget, source_name, dest_name):
616 self.output_channels.clear()
617 channel_box = self.hbox_outputs
619 frames = channel_box.get_children()
623 if source_name == c._channel_name:
629 if (dest_name == c._channel_name):
630 pos = len(frames) - 1 - frames.index(f)
631 channel_box.reorder_child(source_frame, pos)
634 for frame in self.hbox_outputs.get_children():
635 c = frame.get_child()
636 self.output_channels.append(c)
638 _monitored_channel = None
639 def get_monitored_channel(self):
640 return self._monitored_channel
642 def set_monitored_channel(self, channel):
643 if self._monitored_channel:
644 if channel.channel.name == self._monitored_channel.channel.name:
646 self._monitored_channel = channel
647 if type(channel) is InputChannel:
648 # reset all solo/mute settings
649 for in_channel in self.channels:
650 self.monitor_channel.set_solo(in_channel.channel, False)
651 self.monitor_channel.set_muted(in_channel.channel, False)
652 self.monitor_channel.set_solo(channel.channel, True)
653 self.monitor_channel.prefader = True
655 self.monitor_channel.prefader = False
656 self.update_monitor(channel)
657 monitored_channel = property(get_monitored_channel, set_monitored_channel)
659 def update_monitor(self, channel):
660 if self._monitored_channel is not channel:
662 self.monitor_channel.volume = channel.channel.volume
663 self.monitor_channel.balance = channel.channel.balance
664 if type(self.monitored_channel) is OutputChannel:
665 # sync solo/muted channels
666 for input_channel in self.channels:
667 self.monitor_channel.set_solo(input_channel.channel,
668 channel.channel.is_solo(input_channel.channel))
669 self.monitor_channel.set_muted(input_channel.channel,
670 channel.channel.is_muted(input_channel.channel))
672 def get_input_channel_by_name(self, name):
673 for input_channel in self.channels:
674 if input_channel.channel.name == name:
678 def on_about(self, *args):
679 about = Gtk.AboutDialog()
680 about.set_name('jack_mixer')
681 about.set_copyright('Copyright © 2006-2020\nNedko Arnaudov, Frédéric Péters, Arnout Engelen, Daniel Sheeler')
682 about.set_license('''\
683 jack_mixer is free software; you can redistribute it and/or modify it
684 under the terms of the GNU General Public License as published by the
685 Free Software Foundation; either version 2 of the License, or (at your
686 option) any later version.
688 jack_mixer is distributed in the hope that it will be useful, but
689 WITHOUT ANY WARRANTY; without even the implied warranty of
690 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
691 General Public License for more details.
693 You should have received a copy of the GNU General Public License along
694 with jack_mixer; if not, write to the Free Software Foundation, Inc., 51
695 Franklin Street, Fifth Floor, Boston, MA 02110-130159 USA''')
697 'Nedko Arnaudov <nedko@arnaudov.name>',
698 'Christopher Arndt <chris@chrisarndt.de>',
699 'Arnout Engelen <arnouten@bzzt.net>',
700 'John Hedges <john@drystone.co.uk>',
701 'Olivier Humbert <trebmuh@tuxfamily.org>',
702 'Sarah Mischke <sarah@spooky-online.de>',
703 'Frédéric Péters <fpeters@0d.be>',
704 'Daniel Sheeler <dsheeler@pobox.com>',
705 'Athanasios Silis <athanasios.silis@gmail.com>',
707 about.set_logo_icon_name('jack_mixer')
708 about.set_website('https://rdio.space/jackmixer/')
713 def save_to_xml(self, file):
714 log.debug("Saving to XML...")
715 b = XmlSerialization()
720 def load_from_xml(self, file, silence_errors=False, from_nsm=False):
721 log.debug("Loading from XML...")
722 self.unserialized_channels = []
723 b = XmlSerialization()
730 self.on_channels_clear(None)
732 s.unserialize(self, b)
733 for channel in self.unserialized_channels:
734 if isinstance(channel, InputChannel):
735 if self._init_solo_channels and channel.channel_name in self._init_solo_channels:
737 self.add_channel_precreated(channel)
738 self._init_solo_channels = None
739 for channel in self.unserialized_channels:
740 if isinstance(channel, OutputChannel):
741 self.add_output_channel_precreated(channel)
742 del self.unserialized_channels
743 width, height = self.window.get_size()
744 if self.visible or not from_nsm:
745 self.window.show_all()
746 self.paned.set_position(self.paned_position/self.width*width)
747 self.window.resize(self.width, self.height)
749 def serialize(self, object_backend):
750 width, height = self.window.get_size()
751 object_backend.add_property('geometry',
752 '%sx%s' % (width, height))
753 pos = self.paned.get_position()
754 object_backend.add_property('paned_position', '%s' % pos)
756 for input_channel in self.channels:
757 if input_channel.channel.solo:
758 solo_channels.append(input_channel)
760 object_backend.add_property('solo_channels', '|'.join([x.channel.name for x in solo_channels]))
761 object_backend.add_property('visible', '%s' % str(self.visible))
763 def unserialize_property(self, name, value):
764 if name == 'geometry':
765 width, height = value.split('x')
766 self.width = int(width)
767 self.height = int(height)
769 if name == 'solo_channels':
770 self._init_solo_channels = value.split('|')
772 if name == 'visible':
773 self.visible = value == 'True'
775 if name == 'paned_position':
776 self.paned_position = int(value)
780 def unserialize_child(self, name):
781 if name == InputChannel.serialization_name():
782 channel = InputChannel(self, "", True)
783 self.unserialized_channels.append(channel)
786 if name == OutputChannel.serialization_name():
787 channel = OutputChannel(self, "", True)
788 self.unserialized_channels.append(channel)
791 if name == gui.Factory.serialization_name():
792 return self.gui_factory
794 def serialization_get_childs(self):
795 '''Get child objects that required and support serialization'''
796 childs = self.channels[:] + self.output_channels[:] + [self.gui_factory]
799 def serialization_name(self):
806 if self.visible or self.nsm_client == None:
807 width, height = self.window.get_size()
808 self.window.show_all()
809 if hasattr(self, 'paned_position'):
810 self.paned.set_position(self.paned_position/self.width*width)
812 signal.signal(signal.SIGUSR1, self.sighandler)
813 signal.signal(signal.SIGTERM, self.sighandler)
814 signal.signal(signal.SIGINT, self.sighandler)
815 signal.signal(signal.SIGHUP, signal.SIG_IGN)
819 def error_dialog(parent, msg, *args):
820 log.exception(msg, *args)
821 err = Gtk.MessageDialog(parent=parent, modal=True, destroy_with_parent=True,
822 message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text=msg % args)
827 parser = ArgumentParser()
828 parser.add_argument('-c', '--config', metavar="FILE", help='load mixer project configuration from FILE')
829 parser.add_argument('-d', '--debug', action="store_true", help='enable debug logging messages')
830 parser.add_argument('client_name', metavar='NAME', nargs='?', default='jack_mixer',
831 help='set JACK client name')
832 args = parser.parse_args()
834 logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO,
835 format="%(levelname)s: %(message)s")
838 mixer = JackMixer(args.client_name)
839 except Exception as e:
840 error_dialog(None, "Mixer creation failed (%s).", e)
843 if not mixer.nsm_client and args.config:
844 f = open(args.config)
845 mixer.current_filename = args.config
848 mixer.load_from_xml(f)
849 except Exception as e:
850 error_dialog(mixer.window, "Failed loading settings (%s).", e)
852 mixer.window.set_default_size(60*(1+len(mixer.channels)+len(mixer.output_channels)), 300)
859 if __name__ == "__main__":