2 # LADITools - Linux Audio Desktop Integration Tools
3 # laditray - System tray integration for LADI
4 # Copyright (C) 2012 Alessio Treglia <quadrispro@ubuntu.com>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 sig_handler
= signal
.getsignal(signal
.SIGTERM
)
27 signal
.signal(signal
.SIGINT
, sig_handler
)
29 from laditools
import _gettext_domain
30 gettext
.install(_gettext_domain
)
32 from laditools
import get_version_string
33 from laditools
import LadiConfiguration
34 from laditools
import LadiApp
36 from gi
.repository
import Gtk
37 from gi
.repository
import GObject
38 from laditools
import LadiManager
39 from laditools
.gtk
import LadiManagerGtk
40 from laditools
.gtk
import find_data_file
42 timeout_add
= GObject
.timeout_add
44 class LadiPlayer(LadiManagerGtk
, LadiApp
):
46 _appname
= 'ladi-player'
47 _appname_long
= _("LADI Player")
48 _appid
= 'org.linuxaudio.ladi.player'
50 # Default configuration
55 def on_about(self
, *args
):
56 LadiManagerGtk
.on_about(self
, parent
=self
.window_main
, version
=get_version_string())
58 def on_quit(self
, *args
, **kwargs
):
59 self
.global_config
.set_config_section (self
.appname
, self
.config_dict
)
60 self
.global_config
.save()
63 def _run_select_studio_dialog(self
, title
, *args
):
64 studio_list
= self
.get_ladish_controller().studio_list()
66 dlg
= Gtk
.MessageDialog(None,Gtk
.DialogFlags
.MODAL | Gtk
.DialogFlags
.DESTROY_WITH_PARENT
,
68 Gtk
.ButtonsType
.CLOSE
,
69 _('No studio is available.'))
70 dlg
.set_transient_for(self
.window_main
)
77 treeview
= Gtk
.TreeView()
78 model
= Gtk
.ListStore(GObject
.TYPE_STRING
)
79 renderer
= Gtk
.CellRendererText()
80 column
= Gtk
.TreeViewColumn('Available studios', renderer
, text
=0)
82 treeview
.set_model(model
)
83 treeview
.append_column(column
)
84 treeview
.set_cursor(Gtk
.TreePath(path
=0),
88 for studio
in studio_list
:
89 model
.append((studio
,))
91 dlg
.set_transient_for(self
.window_main
)
93 dlg
.set_destroy_with_parent(True)
95 dlg
.get_content_area().pack_start(child
=treeview
,
99 dlg
.add_button(Gtk
.STOCK_OK
, Gtk
.ResponseType
.OK
)
100 dlg
.add_button(Gtk
.STOCK_CANCEL
, Gtk
.ResponseType
.CANCEL
)
105 if response
== Gtk
.ResponseType
.OK
:
106 path
, column
= treeview
.get_cursor()
111 def _toolbuttons_set_active(self
, group
, **kwargs
):
112 buttons
= getattr(self
, "%s_status_buttons" % group
)
114 status
= kwargs
['all']
115 for button
in buttons
:
116 buttons
[button
].set_sensitive(status
)
118 for button
in kwargs
:
119 buttons
[button
].set_sensitive(kwargs
[button
])
121 def jack_is_started(self
, *args
, **kwargs
):
124 return LadiManagerGtk
.jack_is_started(self
, *args
, **kwargs
)
129 def ladish_toolbuttons_set_active(self
, **kwargs
): self
._toolbuttons
_set
_active
('ladish', **kwargs
)
130 def jack_toolbuttons_set_active(self
, **kwargs
): self
._toolbuttons
_set
_active
('jack', **kwargs
)
131 def a2j_toolbuttons_set_active(self
, **kwargs
): self
._toolbuttons
_set
_active
('a2j', **kwargs
)
133 def ladish_status_buttons_update(self
):
134 buttons
= self
.ladish_status_buttons
136 # Setup ladish controls
137 if self
.ladish_is_available():
138 # Buttons "rename" and "unload"
139 if self
.studio_is_loaded():
140 self
.ladish_toolbuttons_set_active(unload
=True, rename
=True)
141 # Buttons "start" and "stop"
142 if self
.studio_is_started():
143 self
.ladish_toolbuttons_set_active(start
=False, stop
=True, save
=True)
145 self
.ladish_toolbuttons_set_active(start
=True, stop
=False, save
=False)
147 self
.ladish_toolbuttons_set_active(start
=True,
153 self
.ladish_toolbuttons_set_active(all
=False)
155 def jack_status_buttons_update(self
):
156 if not self
.jack_is_available():
159 buttons
= self
.jack_status_buttons
160 ladish_available
= self
.ladish_is_available()
161 jack_started
= self
.jack_is_started()
164 self
.jack_toolbuttons_set_active(jack_start
=False,
165 jack_stop
=(not ladish_available
),
166 jack_reset_xruns
=True,
167 jack_reactivate
=True)
169 self
.jack_toolbuttons_set_active(jack_start
=True,
171 jack_reset_xruns
=False,
172 jack_reactivate
=True)
175 def a2j_status_buttons_update(self
):
176 if not self
.a2j_is_available():
177 self
.a2j_toolbuttons_set_active(all
=False)
180 buttons
= self
.a2j_status_buttons
181 ladish_available
= self
.ladish_is_available()
182 a2j_started
= self
.a2j_is_started()
184 if not ladish_available
:
186 self
.a2j_toolbuttons_set_active(a2j_start
=False,
190 self
.a2j_toolbuttons_set_active(a2j_start
=True,
194 self
.a2j_toolbuttons_set_active(a2j_start
=False,
198 def update_status_buttons(self
):
201 self
.ladish_status_buttons_update()
202 self
.jack_status_buttons_update()
203 self
.a2j_status_buttons_update()
205 # Update status label and window icon
206 if self
.jack_is_started():
207 self
.window_main
.set_icon_name("ladi-started")
208 if self
.jack_is_realtime():
209 status_text
= "RT | "
213 status_text
+= str (round (float (self
.jack_get_load()),1)) + "% | "
215 status_text
+= str (self
.jack_get_xruns())
216 # Set a started status
217 self
.status_label
.set_label (status_text
)
219 self
.window_main
.set_icon_name("ladi-stopped")
220 self
.status_label
.set_label(_('<i>Stopped</i>'))
222 def update(self
, *args
, **kwargs
):
223 self
.update_status_buttons()
224 LadiManagerGtk
.update(self
, *args
, **kwargs
)
227 def _set_starting_status(self
):
228 self
.window_main
.set_icon_name("ladi-starting")
230 def action_ladish_new(self
, action
, *args
):
233 def action_ladish_start(self
, action
, *args
):
234 if self
.studio_is_loaded():
235 if not self
.studio_is_started():
236 self
._set
_starting
_status
()
238 self
.update_status_buttons()
240 self
._set
_starting
_status
()
242 self
.update_status_buttons()
244 def action_ladish_save(self
, action
, *args
):
247 def action_ladish_stop(self
, action
, *args
):
248 if self
.jack_is_started() and self
.studio_is_started():
250 self
.update_status_buttons()
252 def action_ladish_rename(self
, action
, *args
):
254 self
.update_status_buttons()
256 def action_ladish_load(self
, action
, *args
):
257 selection
= self
._run
_select
_studio
_dialog
(_('Load studio'))
259 self
.studio_load(studio
=selection
)
262 def action_ladish_delete(self
, action
, *args
):
263 selection
= self
._run
_select
_studio
_dialog
(_('Delete studio'))
265 LadiManager
.studio_delete(self
, studio
=selection
)
268 def action_ladish_unload(self
, action
, *args
):
271 if self
.studio_is_loaded():
273 self
.update_status_buttons()
279 def action_ladish_reactivate(self
, action
, *args
):
280 self
.ladish_reactivate()
282 def action_jack_start(self
, action
, *args
):
283 self
._set
_starting
_status
()
285 def action_jack_stop(self
, action
, *args
):
287 def action_jack_reset_xruns(self
, action
, *args
):
288 self
.jack_reset_xruns()
289 def action_jack_reactivate(self
, action
, *args
):
290 self
.jack_reactivate()
292 def action_a2j_start(self
, action
, *args
):
294 def action_a2j_stop(self
, action
, *args
):
296 def action_a2j_reactivate(self
, action
, *args
):
297 self
.a2j_reactivate()
299 def action_launcher_launch(self
, action
, *args
):
300 self
.launcher_exec(command
=self
._launcher
_which
(action
.get_name()))
303 # Handle the configuration
304 self
.global_config
= LadiConfiguration(self
.appname
, self
._default
_config
)
305 self
.config_dict
= self
.global_config
.get_config_section (self
.appname
)
306 autostart
= bool(eval(self
.config_dict
['autostart']))
308 LadiManagerGtk
.__init
__(self
, autostart
)
311 builder
= Gtk
.Builder()
312 ui_path
= find_data_file("ladi-player.ui")
313 builder
.add_from_file(ui_path
)
314 sys
.stderr
.write( _("Loading interface from %s\n") % ui_path
)
318 self
.window_main
= builder
.get_object("window_main")
319 actiongroup_ladish
= builder
.get_object("actiongroup_ladish")
320 actiongroup_jack
= builder
.get_object("actiongroup_jack")
321 actiongroup_a2j
= builder
.get_object("actiongroup_a2j")
322 actiongroup_launcher
= builder
.get_object("actiongroup_launcher")
323 self
.status_label
= builder
.get_object('toolbutton_label_status')
325 # Setup status buttons
326 self
.ladish_status_buttons
= ladish_status_buttons
= {}
327 self
.jack_status_buttons
= jack_status_buttons
= {}
328 self
.a2j_status_buttons
= a2j_status_buttons
= {}
329 self
.launcher_status_buttons
= launcher_status_buttons
= {}
331 for action
in actiongroup_ladish
.list_actions():
332 ladish_status_buttons
[action
.get_name()] = action
333 for action
in actiongroup_jack
.list_actions():
334 jack_status_buttons
[action
.get_name()] = action
335 for action
in actiongroup_a2j
.list_actions():
336 a2j_status_buttons
[action
.get_name()] = action
337 for action
in actiongroup_launcher
.list_actions():
338 launcher_status_buttons
[action
.get_name()] = action
340 # Remove launchers for unavailable commands
341 for command
in launcher_status_buttons
:
342 if not self
._launcher
_which
(command
):
343 launcher_status_buttons
[command
].set_active(False)
346 # accelgroup = builder.get_object("accelgroup1")
347 # action = actiongroup_launcher.get_action("gladish")
348 # action.set_accel_group(accelgroup)
349 # action.set_accel_path("menu_studio")
351 # Get the initial status
353 # Add the auto update callback
354 self
.auto_updater
= timeout_add (250, self
.update
, None)
356 builder
.connect_signals(self
)
359 self
.window_main
.show_all()
361 if __name__
== "__main__":
362 parser
= argparse
.ArgumentParser(description
=_('graphical front-end that allows users to start, stop and'
363 'monitor JACK, as well as start some JACK related applications'),
364 epilog
=_('This program is part of the LADITools suite.'))
365 parser
.add_argument('--version', action
='version', version
="%(prog)s " + get_version_string())
368 GObject
.threads_init()