laditools/wmjackctl

201 lines
6.2 KiB
Python
Executable File

#!/usr/bin/env python
# pyjackctl - The python jackdbus controller suite
# wmjackctl - Window maker dockapp for jackdbus
# Copyright (C) 2007-2008, Marc-Olivier Barre and Nedko Arnaudov.
#
# 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 laditools
import time
import pygtk
pygtk.require('2.0')
import gtk
import gobject
# Default configuration
autostart_default = 0
debug = False
class wmjackctl(wmoo.Application, pyjackctl.jack_menu):
def __init__(self):
# Handle the configuration
self.wmjackctl_config = pyjackctl.config()
self.param_dict = self.wmjackctl_config.get_as_dict('wmjackctl')
if 'autostart' not in self.param_dict:
self.param_dict['autostart'] = str(autostart_default), {}
self.autostart, devnull = self.param_dict['autostart']
self.autostart = int(self.autostart)
self.jack = pyjackctl.jack_controller()
if self.autostart:
self.jack.start()
wmoo.Application.__init__(
self,
#background = os.path.dirname(sys.argv[0]) + os.sep + "wmjackctl.xpm",
margin = 2,
debug = False)
pyjackctl.jack_menu.__init__(self)
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 get_controller(self):
return self.jack
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 not self.jack:
self.jack = pyjackctl.jack_controller()
if self.jack.is_started():
self.started = True
if self.jack.is_realtime():
self.set_line(0, "JACK RT")
else:
self.set_line(0, "JACK")
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
except Exception, e:
if debug:
print repr(e)
self.set_line(0, "JACK")
self.set_line(1, "error")
if self.jack:
self.clear_line(2)
self.clear_line(3)
self.clear_line(4)
self.clear_line(5)
self.jack = None
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.wmjackctl_config.set_as_dict('wmjackctl', self.param_dict)
wmjackctl().run()