218 lines
6.9 KiB
Python
Executable File
218 lines
6.9 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
# LADITools - Linux Audio Desktop Integration Tools
|
|
# wmladi - Window maker dockapp for jackdbus
|
|
# Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
|
|
# Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import sys
|
|
import os
|
|
from wmdocklib import wmoo, pywmhelpers
|
|
import time
|
|
|
|
try:
|
|
import imp
|
|
imp.find_module('laditools')
|
|
except ImportError:
|
|
# Running from the build tree?
|
|
sys.path.insert(0, os.path.join(sys.path[0], os.pardir))
|
|
|
|
import laditools
|
|
|
|
import pygtk
|
|
pygtk.require('2.0')
|
|
import gtk
|
|
import gobject
|
|
|
|
# Default configuration
|
|
autostart_default = 0
|
|
debug = False
|
|
|
|
class wmladi (wmoo.Application, laditools.manager):
|
|
def __init__ (self):
|
|
# Handle the configuration
|
|
self.global_config = laditools.config ()
|
|
self.param_dict = self.global_config.get_config_section ('wmladi')
|
|
if self.param_dict != None:
|
|
if 'autostart' not in self.param_dict:
|
|
self.param_dict['autostart'] = str (autostart_default)
|
|
else:
|
|
self.param_dict = {}
|
|
self.param_dict['autostart'] = str (autostart_default)
|
|
autostart = self.param_dict['autostart']
|
|
wmoo.Application.__init__ (
|
|
self,
|
|
#background = os.path.dirname(sys.argv[0]) + os.sep + "wmjackctl.xpm",
|
|
margin = 2,
|
|
debug = False)
|
|
|
|
laditools.manager.__init__(self, self.global_config.get_config_section ('ladimenu'), int(autostart))
|
|
|
|
self.addCallback (self.on_button_release, 'buttonrelease', area=(0,0,64,64))
|
|
|
|
self.lines = []
|
|
for i in range (6):
|
|
self.lines.append ("")
|
|
self.clear ()
|
|
self.started = False
|
|
|
|
def set_starting_status (self):
|
|
self.set_line (0, "JACK")
|
|
self.set_line (1, "Starting")
|
|
self.clear_line (2)
|
|
self.clear_line (3)
|
|
self.clear_line (4)
|
|
self.clear_line (5)
|
|
|
|
def on_button_release (self, event):
|
|
if event['button'] == 3:
|
|
self.menu_activate ()
|
|
|
|
def set_line (self, line, text):
|
|
self.lines[line] = text
|
|
while len (self.lines[line]) < 9:
|
|
self.lines[line] += ' '
|
|
|
|
def clear_line (self, line):
|
|
self.set_line (line, "")
|
|
|
|
def clear (self):
|
|
for i in range (6):
|
|
self.clear_line (i)
|
|
|
|
def update (self):
|
|
try:
|
|
if self.jack_is_started():
|
|
self.started = True
|
|
|
|
line0 = "JACK"
|
|
if self.jack_is_realtime():
|
|
line0 += " RT"
|
|
else:
|
|
line0 += " "
|
|
|
|
if self.a2j_is_available():
|
|
try:
|
|
if self.a2j_is_started():
|
|
line0 += ' A'
|
|
else:
|
|
line0 += ' a'
|
|
except:
|
|
pass
|
|
|
|
self.set_line(0, line0)
|
|
self.set_line(1, "started")
|
|
self.set_line(2, "%.3f %%" % self.jack_get_load())
|
|
|
|
xruns = self.jack_get_xruns()
|
|
if xruns == 0:
|
|
self.set_line(3, "no xruns")
|
|
elif xruns == 1:
|
|
self.set_line(3, "1 xrun")
|
|
elif xruns > 999:
|
|
self.set_line(3, "lot xruns")
|
|
else:
|
|
self.set_line(3, "%s xruns" % xruns)
|
|
|
|
rate = self.jack_get_sample_rate()
|
|
if rate % 1000.0 == 0:
|
|
self.set_line(4, "%.0f Khz" % (rate / 1000.0))
|
|
else:
|
|
self.set_line(4, "%.1f Khz" % (rate / 1000.0))
|
|
|
|
self.set_line(5, "%.1f ms" % self.jack_get_latency())
|
|
else:
|
|
self.set_line(0, "JACK")
|
|
self.set_line(1, "stopped")
|
|
if self.started:
|
|
self.clear_line(2)
|
|
self.clear_line(3)
|
|
self.clear_line(4)
|
|
self.clear_line(5)
|
|
self.started = False
|
|
self.clear_diagnose_text()
|
|
except Exception as e:
|
|
self.set_diagnose_text(repr(e))
|
|
if debug:
|
|
print(repr (e))
|
|
self.set_line(0, "JACK")
|
|
self.set_line(1, "is sick")
|
|
self.clear_line(2)
|
|
self.clear_line(3)
|
|
self.clear_line(4)
|
|
self.clear_line(5)
|
|
self.clear_jack_proxies()
|
|
|
|
self.put_lines (self.lines)
|
|
wmoo.Application.update (self)
|
|
# Take a look at the processes we've started so we don't get any zombies
|
|
for i in self.proc_list:
|
|
i.poll ()
|
|
|
|
def put_lines (self, lines):
|
|
x = 3
|
|
y = 2
|
|
for line in lines:
|
|
self.putString (x, y, line)
|
|
y += 9
|
|
|
|
def do_dockapp (self):
|
|
"""this is called from event loop. events are examined and if a
|
|
callback has been registered, it is called, passing it the event as
|
|
argument.
|
|
"""
|
|
event = pywmhelpers.getEvent ()
|
|
while not event is None:
|
|
if event['type'] == 'destroynotify':
|
|
sys.exit (0)
|
|
|
|
for evtype, key, area, callback in self._events:
|
|
if evtype is not None and evtype != event['type']: continue
|
|
if key is not None and key != event['button']: continue
|
|
if area is not None:
|
|
if not area[0] <= event['x'] <= area[2]: continue
|
|
if not area[1] <= event['y'] <= area[3]: continue
|
|
|
|
callback (event)
|
|
|
|
event = pywmhelpers.getEvent ()
|
|
self.redraw ()
|
|
#print "tick"
|
|
return True
|
|
|
|
def run_sleep (self):
|
|
self.go = True
|
|
while self.go:
|
|
while gtk.events_pending ():
|
|
gtk.main_iteration ()
|
|
self.do_dockapp ()
|
|
while gtk.events_pending ():
|
|
gtk.main_iteration ()
|
|
time.sleep (self._sleep)
|
|
|
|
def run_gtk (self):
|
|
#print self._sleep
|
|
gobject.timeout_add (int(self._sleep * 1000), self.do_dockapp)
|
|
gtk.main ()
|
|
|
|
def run (self):
|
|
self.run_gtk ()
|
|
self.global_config.set_config_section ('wmladi', self.param_dict)
|
|
self.global_config.set_config_section ('ladimenu', self.menu_array)
|
|
self.global_config.save ()
|
|
|
|
wmladi ().run ()
|