]> git.0d.be Git - jack_mixer.git/blob - jack_mixer.py
ladish level 1 support
[jack_mixer.git] / jack_mixer.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # This file is part of jack_mixer
5 #
6 # Copyright (C) 2006-2009 Nedko Arnaudov <nedko@arnaudov.name>
7 # Copyright (C) 2009 Frederic Peters <fpeters@0d.be>
8 #
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
12 #
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.
17 #
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.
21
22 from optparse import OptionParser
23
24 import gtk
25 import gobject
26 import sys
27 import os
28 import signal
29
30 try:
31     import lash
32 except:
33     lash = None
34     print >> sys.stderr, "Cannot load LASH python bindings, you want them unless you enjoy manual jack plumbing each time you use this app"
35
36 # temporary change Python modules lookup path to look into installation
37 # directory ($prefix/share/jack_mixer/)
38 old_path = sys.path
39 sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '..', 'share', 'jack_mixer'))
40
41 import jack_mixer_c
42 import scale
43 from channel import *
44
45 import gui
46 from preferences import PreferencesDialog
47
48 from serialization_xml import XmlSerialization
49 from serialization import SerializedObject, Serializator
50
51 # restore Python modules lookup path
52 sys.path = old_path
53
54 class JackMixer(SerializedObject):
55
56     # scales suitable as meter scales
57     meter_scales = [scale.IEC268(), scale.Linear70dB(), scale.IEC268Minimalistic()]
58
59     # scales suitable as volume slider scales
60     slider_scales = [scale.Linear30dB(), scale.Linear70dB()]
61
62     # name of settngs file that is currently open
63     current_filename = None
64
65     def __init__(self, name, lash_client):
66         self.mixer = jack_mixer_c.Mixer(name)
67         if not self.mixer:
68             return
69         self.monitor_channel = self.mixer.add_output_channel("Monitor", True, True)
70
71         self.save = False
72
73         if lash_client:
74             # Send our client name to server
75             lash_event = lash.lash_event_new_with_type(lash.LASH_Client_Name)
76             lash.lash_event_set_string(lash_event, name)
77             lash.lash_send_event(lash_client, lash_event)
78
79             lash.lash_jack_client_name(lash_client, name)
80
81         gtk.window_set_default_icon_name('jack_mixer')
82
83         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
84         self.window.set_title(name)
85
86         self.gui_factory = gui.Factory(self.window, self.meter_scales, self.slider_scales)
87
88         self.vbox_top = gtk.VBox()
89         self.window.add(self.vbox_top)
90
91         self.menubar = gtk.MenuBar()
92         self.vbox_top.pack_start(self.menubar, False)
93
94         mixer_menu_item = gtk.MenuItem("_Mixer")
95         self.menubar.append(mixer_menu_item)
96         edit_menu_item = gtk.MenuItem('_Edit')
97         self.menubar.append(edit_menu_item)
98         help_menu_item = gtk.MenuItem('_Help')
99         self.menubar.append(help_menu_item)
100
101         self.window.set_default_size(120, 300)
102
103         mixer_menu = gtk.Menu()
104         mixer_menu_item.set_submenu(mixer_menu)
105
106         add_input_channel = gtk.ImageMenuItem('New _Input Channel')
107         mixer_menu.append(add_input_channel)
108         add_input_channel.connect("activate", self.on_add_input_channel)
109
110         add_output_channel = gtk.ImageMenuItem('New _Output Channel')
111         mixer_menu.append(add_output_channel)
112         add_output_channel.connect("activate", self.on_add_output_channel)
113
114         mixer_menu.append(gtk.SeparatorMenuItem())
115         open = gtk.ImageMenuItem(gtk.STOCK_OPEN)
116         mixer_menu.append(open)
117         open.connect('activate', self.on_open_cb)
118         save = gtk.ImageMenuItem(gtk.STOCK_SAVE)
119         mixer_menu.append(save)
120         save.connect('activate', self.on_save_cb)
121         save_as = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS)
122         mixer_menu.append(save_as)
123         save_as.connect('activate', self.on_save_as_cb)
124
125         mixer_menu.append(gtk.SeparatorMenuItem())
126
127         quit = gtk.ImageMenuItem(gtk.STOCK_QUIT)
128         mixer_menu.append(quit)
129         quit.connect('activate', self.on_quit_cb)
130
131         edit_menu = gtk.Menu()
132         edit_menu_item.set_submenu(edit_menu)
133
134         self.channel_remove_input_menu_item = gtk.MenuItem('Remove Input Channel')
135         edit_menu.append(self.channel_remove_input_menu_item)
136         self.channel_remove_input_menu = gtk.Menu()
137         self.channel_remove_input_menu_item.set_submenu(self.channel_remove_input_menu)
138
139         self.channel_remove_output_menu_item = gtk.MenuItem('Remove Output Channel')
140         edit_menu.append(self.channel_remove_output_menu_item)
141         self.channel_remove_output_menu = gtk.Menu()
142         self.channel_remove_output_menu_item.set_submenu(self.channel_remove_output_menu)
143
144         channel_remove_all_menu_item = gtk.ImageMenuItem(gtk.STOCK_CLEAR)
145         edit_menu.append(channel_remove_all_menu_item)
146         channel_remove_all_menu_item.connect("activate", self.on_channels_clear)
147
148         edit_menu.append(gtk.SeparatorMenuItem())
149
150         preferences = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
151         preferences.connect('activate', self.on_preferences_cb)
152         edit_menu.append(preferences)
153
154         help_menu = gtk.Menu()
155         help_menu_item.set_submenu(help_menu)
156
157         about = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
158         help_menu.append(about)
159         about.connect("activate", self.on_about)
160
161         self.hbox_top = gtk.HBox()
162         self.vbox_top.pack_start(self.hbox_top, True)
163
164         self.scrolled_window = gtk.ScrolledWindow()
165         self.hbox_top.pack_start(self.scrolled_window, True)
166
167         self.hbox_inputs = gtk.HBox()
168         self.hbox_inputs.set_spacing(0)
169         self.hbox_inputs.set_border_width(0)
170         self.hbox_top.set_spacing(0)
171         self.hbox_top.set_border_width(0)
172         self.channels = []
173         self.output_channels = []
174
175         self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
176         self.scrolled_window.add_with_viewport(self.hbox_inputs)
177
178         self.main_mix = MainMixChannel(self)
179         self.hbox_outputs = gtk.HBox()
180         self.hbox_outputs.set_spacing(0)
181         self.hbox_outputs.set_border_width(0)
182         frame = gtk.Frame()
183         frame.add(self.main_mix)
184         self.hbox_outputs.pack_start(frame, False)
185         self.hbox_top.pack_start(self.hbox_outputs, False)
186
187         self.window.connect("destroy", gtk.main_quit)
188
189         gobject.timeout_add(80, self.read_meters)
190         self.lash_client = lash_client
191
192         gobject.timeout_add(200, self.lash_check_events)
193
194     def sighandler(self, signum, frame):
195         print "Signal %d received" % signum
196         if signum == signal.SIGUSR1:
197             self.save = True
198         elif signum == signal.SIGTERM:
199             gtk.main_quit()
200         elif signum == signal.SIGINT:
201             gtk.main_quit()
202         else:
203             print "Unknown signal %d received" % signum
204
205     def cleanup(self):
206         print "Cleaning jack_mixer"
207         if not self.mixer:
208             return
209
210         for channel in self.channels:
211             channel.unrealize()
212
213     def on_open_cb(self, *args):
214         dlg = gtk.FileChooserDialog(title='Open', parent=self.window,
215                         action=gtk.FILE_CHOOSER_ACTION_OPEN,
216                         buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
217                                  gtk.STOCK_OPEN, gtk.RESPONSE_OK))
218         dlg.set_default_response(gtk.RESPONSE_OK)
219         if dlg.run() == gtk.RESPONSE_OK:
220             filename = dlg.get_filename()
221             try:
222                 f = file(filename, 'r')
223                 self.load_from_xml(f)
224             except:
225                 err = gtk.MessageDialog(self.window,
226                             gtk.DIALOG_MODAL,
227                             gtk.MESSAGE_ERROR,
228                             gtk.BUTTONS_OK,
229                             "Failed loading settings.")
230                 err.run()
231                 err.destroy()
232             else:
233                 self.current_filename = filename
234             finally:
235                 f.close()
236         dlg.destroy()
237
238     def on_save_cb(self, *args):
239         if not self.current_filename:
240             return self.on_save_as_cb()
241         f = file(self.current_filename, 'w')
242         self.save_to_xml(f)
243         f.close()
244
245     def on_save_as_cb(self, *args):
246         dlg = gtk.FileChooserDialog(title='Save', parent=self.window,
247                         action=gtk.FILE_CHOOSER_ACTION_SAVE,
248                         buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
249                                  gtk.STOCK_SAVE, gtk.RESPONSE_OK))
250         dlg.set_default_response(gtk.RESPONSE_OK)
251         if dlg.run() == gtk.RESPONSE_OK:
252             self.current_filename = dlg.get_filename()
253             self.on_save_cb()
254         dlg.destroy()
255
256     def on_quit_cb(self, *args):
257         gtk.main_quit()
258
259     preferences_dialog = None
260     def on_preferences_cb(self, widget):
261         if not self.preferences_dialog:
262             self.preferences_dialog = PreferencesDialog(self)
263         self.preferences_dialog.show()
264         self.preferences_dialog.present()
265
266     def on_add_input_channel(self, widget):
267         dialog = NewChannelDialog(app=self)
268         dialog.set_transient_for(self.window)
269         dialog.show()
270         ret = dialog.run()
271         dialog.hide()
272
273         if ret == gtk.RESPONSE_OK:
274             result = dialog.get_result()
275             channel = self.add_channel(**result)
276             self.window.show_all()
277
278     def on_add_output_channel(self, widget):
279         dialog = NewOutputChannelDialog(app=self)
280         dialog.set_transient_for(self.window)
281         dialog.show()
282         ret = dialog.run()
283         dialog.hide()
284
285         if ret == gtk.RESPONSE_OK:
286             result = dialog.get_result()
287             channel = self.add_output_channel(**result)
288             self.window.show_all()
289
290     def on_remove_input_channel(self, widget, channel):
291         print 'Removing channel "%s"' % channel.channel_name
292         self.channel_remove_input_menu.remove(widget)
293         if self.monitored_channel is channel:
294             channel.monitor_button.set_active(False)
295         for i in range(len(self.channels)):
296             if self.channels[i] is channel:
297                 channel.unrealize()
298                 del self.channels[i]
299                 self.hbox_inputs.remove(channel.parent)
300                 break
301         if len(self.channels) == 0:
302             self.channel_remove_input_menu_item.set_sensitive(False)
303
304     def on_remove_output_channel(self, widget, channel):
305         print 'Removing channel "%s"' % channel.channel_name
306         self.channel_remove_output_menu.remove(widget)
307         if self.monitored_channel is channel:
308             channel.monitor_button.set_active(False)
309         for i in range(len(self.channels)):
310             if self.output_channels[i] is channel:
311                 channel.unrealize()
312                 del self.output_channels[i]
313                 self.hbox_outputs.remove(channel.parent)
314                 break
315         if len(self.output_channels) == 0:
316             self.channel_remove_output_menu_item.set_sensitive(False)
317
318     def on_channels_clear(self, widget):
319         for channel in self.output_channels:
320             channel.unrealize()
321             self.hbox_outputs.remove(channel.parent)
322         for channel in self.channels:
323             channel.unrealize()
324             self.hbox_inputs.remove(channel.parent)
325         self.channels = []
326         self.output_channels = []
327         self.channel_remove_input_menu = gtk.Menu()
328         self.channel_remove_input_menu_item.set_submenu(self.channel_remove_input_menu)
329         self.channel_remove_input_menu_item.set_sensitive(False)
330         self.channel_remove_output_menu = gtk.Menu()
331         self.channel_remove_output_menu_item.set_submenu(self.channel_remove_output_menu)
332         self.channel_remove_output_menu_item.set_sensitive(False)
333
334     def add_channel(self, name, stereo, volume_cc, balance_cc):
335         try:
336             channel = InputChannel(self, name, stereo)
337             self.add_channel_precreated(channel)
338         except Exception:
339             err = gtk.MessageDialog(self.window,
340                             gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
341                             gtk.MESSAGE_ERROR,
342                             gtk.BUTTONS_OK,
343                             "Channel creation failed")
344             err.run()
345             err.destroy()
346             return
347         if volume_cc:
348             channel.channel.volume_midi_cc = int(volume_cc)
349         if balance_cc:
350             channel.channel.balance_midi_cc = int(balance_cc)
351         if not (volume_cc or balance_cc):
352             channel.channel.autoset_midi_cc()
353
354         return channel
355
356     def add_channel_precreated(self, channel):
357         frame = gtk.Frame()
358         frame.add(channel)
359         self.hbox_inputs.pack_start(frame, False)
360         channel.realize()
361         channel_remove_menu_item = gtk.MenuItem(channel.channel_name)
362         self.channel_remove_input_menu.append(channel_remove_menu_item)
363         channel_remove_menu_item.connect("activate", self.on_remove_input_channel, channel)
364         self.channel_remove_input_menu_item.set_sensitive(True)
365         self.channels.append(channel)
366
367         for outputchannel in self.output_channels:
368             channel.add_control_group(outputchannel)
369
370         # create post fader output channel matching the input channel
371         channel.post_fader_output_channel = self.mixer.add_output_channel(
372                         channel.channel.name + ' Out', channel.channel.is_stereo, True)
373         channel.post_fader_output_channel.volume = 0
374         channel.post_fader_output_channel.set_solo(channel.channel, True)
375
376     def read_meters(self):
377         for channel in self.channels:
378             channel.read_meter()
379         self.main_mix.read_meter()
380         for channel in self.output_channels:
381             channel.read_meter()
382         return True
383
384     def add_output_channel(self, name, stereo, volume_cc, balance_cc, display_solo_buttons):
385         try:
386             channel = OutputChannel(self, name, stereo)
387             channel.display_solo_buttons = display_solo_buttons
388             self.add_output_channel_precreated(channel)
389         except Exception:
390             err = gtk.MessageDialog(self.window,
391                             gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
392                             gtk.MESSAGE_ERROR,
393                             gtk.BUTTONS_OK,
394                             "Channel creation failed")
395             err.run()
396             err.destroy()
397             return
398         if volume_cc:
399             channel.channel.volume_midi_cc = int(volume_cc)
400         if balance_cc:
401             channel.channel.balance_midi_cc = int(balance_cc)
402         return channel
403
404     def add_output_channel_precreated(self, channel):
405         frame = gtk.Frame()
406         frame.add(channel)
407         self.hbox_outputs.pack_start(frame, False)
408         channel.realize()
409         channel_remove_menu_item = gtk.MenuItem(channel.channel_name)
410         self.channel_remove_output_menu.append(channel_remove_menu_item)
411         channel_remove_menu_item.connect("activate", self.on_remove_output_channel, channel)
412         self.channel_remove_output_menu_item.set_sensitive(True)
413         self.output_channels.append(channel)
414
415     _monitored_channel = None
416     def get_monitored_channel(self):
417         return self._monitored_channel
418
419     def set_monitored_channel(self, channel):
420         if self._monitored_channel:
421             if channel.channel.name == self._monitored_channel.channel.name:
422                 return
423         self._monitored_channel = channel
424         if type(channel) is InputChannel:
425             # reset all solo/mute settings
426             for in_channel in self.channels:
427                 self.monitor_channel.set_solo(in_channel.channel, False)
428                 self.monitor_channel.set_muted(in_channel.channel, False)
429             self.monitor_channel.set_solo(channel.channel, True)
430             self.monitor_channel.prefader = True
431         else:
432             self.monitor_channel.prefader = False
433         self.update_monitor(channel)
434     monitored_channel = property(get_monitored_channel, set_monitored_channel)
435
436     def update_monitor(self, channel):
437         if self.monitored_channel is not channel:
438             return
439         self.monitor_channel.volume = channel.channel.volume
440         self.monitor_channel.balance = channel.channel.balance
441         if type(self.monitored_channel) is OutputChannel:
442             # sync solo/muted channels
443             for input_channel in self.channels:
444                 self.monitor_channel.set_solo(input_channel.channel,
445                                 channel.channel.is_solo(input_channel.channel))
446                 self.monitor_channel.set_muted(input_channel.channel,
447                                 channel.channel.is_muted(input_channel.channel))
448         elif type(self.monitored_channel) is MainMixChannel:
449             # sync solo/muted channels
450             for input_channel in self.channels:
451                 self.monitor_channel.set_solo(input_channel.channel,
452                                 input_channel.channel.solo)
453                 self.monitor_channel.set_muted(input_channel.channel,
454                                 input_channel.channel.mute)
455
456     def get_input_channel_by_name(self, name):
457         for input_channel in self.channels:
458             if input_channel.channel.name == name:
459                 return input_channel
460         return None
461
462     def on_about(self, *args):
463         about = gtk.AboutDialog()
464         about.set_name('jack_mixer')
465         about.set_copyright('Copyright © 2006-2009\nNedko Arnaudov, Frederic Peters')
466         about.set_license('''\
467 jack_mixer is free software; you can redistribute it and/or modify it
468 under the terms of the GNU General Public License as published by the
469 Free Software Foundation; either version 2 of the License, or (at your
470 option) any later version.
471
472 jack_mixer is distributed in the hope that it will be useful, but
473 WITHOUT ANY WARRANTY; without even the implied warranty of
474 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
475 General Public License for more details.
476
477 You should have received a copy of the GNU General Public License along
478 with jack_mixer; if not, write to the Free Software Foundation, Inc., 51
479 Franklin Street, Fifth Floor, Boston, MA 02110-130159 USA''')
480         about.set_authors(['Nedko Arnaudov <nedko@arnaudov.name>',
481                            'Frederic Peters <fpeters@0d.be>'])
482         about.set_logo_icon_name('jack_mixer')
483         about.set_website('http://home.gna.org/jackmixer/')
484
485         about.run()
486         about.destroy()
487
488     def lash_check_events(self):
489         if self.current_filename and self.save:
490             print "saving on SIGUSR1 request"
491             self.on_save_cb()
492             print "save done"
493             self.save = False
494             return True
495
496         if not self.lash_client:
497             return True
498
499         while lash.lash_get_pending_event_count(self.lash_client):
500             event = lash.lash_get_event(self.lash_client)
501
502             #print repr(event)
503
504             event_type = lash.lash_event_get_type(event)
505             if event_type == lash.LASH_Quit:
506                 print "jack_mixer: LASH ordered quit."
507                 gtk.main_quit()
508                 return False
509             elif event_type == lash.LASH_Save_File:
510                 directory = lash.lash_event_get_string(event)
511                 print "jack_mixer: LASH ordered to save data in directory %s" % directory
512                 filename = directory + os.sep + "jack_mixer.xml"
513                 f = file(filename, "w")
514                 self.save_to_xml(f)
515                 f.close()
516                 lash.lash_send_event(self.lash_client, event) # we crash with double free
517             elif event_type == lash.LASH_Restore_File:
518                 directory = lash.lash_event_get_string(event)
519                 print "jack_mixer: LASH ordered to restore data from directory %s" % directory
520                 filename = directory + os.sep + "jack_mixer.xml"
521                 f = file(filename, "r")
522                 self.load_from_xml(f, silence_errors=True)
523                 f.close()
524                 lash.lash_send_event(self.lash_client, event)
525             else:
526                 print "jack_mixer: Got unhandled LASH event, type " + str(event_type)
527                 return True
528
529             #lash.lash_event_destroy(event)
530
531         return True
532
533     def save_to_xml(self, file):
534         #print "Saving to XML..."
535         b = XmlSerialization()
536         s = Serializator()
537         s.serialize(self, b)
538         b.save(file)
539
540     def load_from_xml(self, file, silence_errors=False):
541         #print "Loading from XML..."
542         self.on_channels_clear(None)
543         self.unserialized_channels = []
544         b = XmlSerialization()
545         try:
546             b.load(file)
547         except:
548             if silence_errors:
549                 return
550             raise
551         s = Serializator()
552         s.unserialize(self, b)
553         for channel in self.unserialized_channels:
554             if isinstance(channel, InputChannel):
555                 self.add_channel_precreated(channel)
556         for channel in self.unserialized_channels:
557             if isinstance(channel, OutputChannel):
558                 self.add_output_channel_precreated(channel)
559         del self.unserialized_channels
560         self.window.show_all()
561
562     def serialize(self, object_backend):
563         object_backend.add_property('geometry',
564                         '%sx%s' % (self.window.allocation.width, self.window.allocation.height))
565
566     def unserialize_property(self, name, value):
567         if name == 'geometry':
568             width, height = value.split('x')
569             self.window.resize(int(width), int(height))
570             return True
571
572     def unserialize_child(self, name):
573         if name == MainMixChannel.serialization_name():
574             return self.main_mix
575
576         if name == InputChannel.serialization_name():
577             channel = InputChannel(self, "", True)
578             self.unserialized_channels.append(channel)
579             return channel
580
581         if name == OutputChannel.serialization_name():
582             channel = OutputChannel(self, "", True)
583             self.unserialized_channels.append(channel)
584             return channel
585
586     def serialization_get_childs(self):
587         '''Get child objects tha required and support serialization'''
588         childs = self.channels[:] + self.output_channels[:]
589         childs.append(self.main_mix)
590         return childs
591
592     def serialization_name(self):
593         return "jack_mixer"
594
595     def main(self):
596         self.main_mix.realize()
597         self.main_mix.set_monitored()
598
599         if not self.mixer:
600             return
601
602         self.window.show_all()
603
604         signal.signal(signal.SIGUSR1, self.sighandler)
605         signal.signal(signal.SIGTERM, self.sighandler)
606         signal.signal(signal.SIGINT, self.sighandler)
607
608         gtk.main()
609
610         #f = file("/dev/stdout", "w")
611         #self.save_to_xml(f)
612         #f.close
613
614 def help():
615     print "Usage: %s [mixer_name]" % sys.argv[0]
616
617 def main():
618     # Connect to LASH if Python bindings are available, and the user did not
619     # pass --no-lash
620     if lash and not '--no-lash' in sys.argv:
621         # sys.argv is modified by this call
622         lash_client = lash.init(sys.argv, "jack_mixer", lash.LASH_Config_File)
623     else:
624         lash_client = None
625
626     parser = OptionParser()
627     parser.add_option('-c', '--config', dest='config',
628                       help='use a non default configuration file')
629     # --no-lash here is not acted upon, it is specified for completeness when
630     # --help is passed.
631     parser.add_option('--no-lash', dest='nolash', action='store_true',
632                       help='do not connect to LASH')
633     options, args = parser.parse_args()
634
635     # Yeah , this sounds stupid, we connected earlier, but we dont want to show this if we got --help option
636     # This issue should be fixed in pylash, there is a reason for having two functions for initialization after all
637     if lash_client:
638         print "Successfully connected to LASH server at " +  lash.lash_get_server_name(lash_client)
639
640     if len(args) == 1:
641         name = args[0]
642     else:
643         name = None
644
645     if not name:
646         name = "jack_mixer-%u" % os.getpid()
647
648     gtk.gdk.threads_init()
649     try:
650         mixer = JackMixer(name, lash_client)
651     except Exception, e:
652         err = gtk.MessageDialog(None,
653                             gtk.DIALOG_MODAL,
654                             gtk.MESSAGE_ERROR,
655                             gtk.BUTTONS_OK,
656                             "Mixer creation failed (%s)" % str(e))
657         err.run()
658         err.destroy()
659         sys.exit(1)
660
661     if options.config:
662         f = file(options.config)
663         mixer.current_filename = options.config
664         try:
665             mixer.load_from_xml(f)
666         except:
667             err = gtk.MessageDialog(mixer.window,
668                             gtk.DIALOG_MODAL,
669                             gtk.MESSAGE_ERROR,
670                             gtk.BUTTONS_OK,
671                             "Failed loading settings.")
672             err.run()
673             err.destroy()
674         mixer.window.set_default_size(60*(1+len(mixer.channels)+len(mixer.output_channels)), 300)
675         f.close()
676
677     mixer.main()
678
679     mixer.cleanup()
680
681 if __name__ == "__main__":
682     main()