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