3 # LADITools - Linux Audio Desktop Integration Tools
4 # g15ladi - A jack monitor for the g15 keyboard that uses the dbus interface
5 # Copyright (C) 2012 Alessio Treglia <quadrispro@ubuntu.com>
6 # Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
7 # Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
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, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 pipe_filename
= "/dev/shm/g15log.pipe"
32 class g15composer (object):
34 text_justify_center
= 1
35 text_justify_right
= 2
44 def __init__(self
, pipe_filename
, large
):
46 self
.size
= self
.text_size_large
47 self
.max_lines
= 5 # 7 for small, 5 for large
50 self
.size
= self
.text_size_small
54 self
.pipe_filename
= pipe_filename
55 self
.pid
= os
.spawnlp(os
.P_NOWAIT
, 'g15composer', 'g15composer', self
.pipe_filename
)
56 #print "g15composer started"
57 while not os
.access(self
.pipe_filename
, os
.F_OK
):
58 #print "Waiting pipe to appear..."
60 self
.pipe
= file(self
.pipe_filename
, "w")
61 os
.remove(self
.pipe_filename
)
62 #print "pipe unlinked"
66 #print "stopping g15composer..."
67 os
.kill(self
.pid
, signal
.SIGTERM
)
68 os
.waitpid(self
.pid
, 0)
69 #print "g15composer stopped"
71 def send_message(self
, message
):
73 self
.pipe
.write(message
)
76 def draw_lines(self
, lines
, x
, y
, justify
):
77 message
= 'TO %u %u %u %u' % (x
, y
, self
.size
, justify
)
79 message
+= ' "%s "' % line
.replace('"', "'").strip("\n")
81 self
.send_message(message
)
83 def draw_lines(self
, lines
, x
, y
, justify
):
84 message
= 'TO %u %u %u %u' % (x
, y
, self
.size
, justify
)
86 message
+= ' "%s "' % line
.replace('"', "'").strip("\n")
88 self
.send_message(message
)
95 self
.send_message(message
)
97 def draw_bar(self
, x
, y
, width
, height
, ink
, fill
):
99 width
= self
.width
- width
- x
- 1
112 self
.send_message("DB %u %u %u %u %u %u %u 1\n" % (x
, y
, x
+ width
, y
+ height
, ink
, fill
* 1000, 1000))
114 class jackctl_g15(object):
117 self
.g15
= g15composer(pipe_filename
, False)
121 def get_jack_info(self
):
123 self
.jack
= laditools
.JackController()
125 if not self
.jack
.is_started():
126 return False, None, None, None, None, None
128 realtime
= self
.jack
.is_realtime()
129 load
= self
.jack
.get_load()
131 xruns
= self
.jack
.get_xruns()
133 xruns_line
= "no xruns"
135 xruns_line
= "1 xrun"
137 xruns_line
= "%u xruns" % xruns
139 rate
= self
.jack
.get_sample_rate()
140 if rate
% 1000.0 == 0:
141 rate_line
= "Sample rate: %.0f Khz" % (rate
/ 1000.0)
143 rate_line
= "Sample rate: %.1f Khz" % (rate
/ 1000.0)
144 latency_line
= "Latency: %.1f ms" % self
.jack
.get_latency()
146 return True, realtime
, load
, xruns_line
, rate_line
, latency_line
153 self
.ladish
= laditools
.LadishProxy()
157 studio_name
= self
.ladish
.studio_name()
161 started
, realtime
, load
, xruns_line
, rate_line
, latency_line
= self
.get_jack_info()
166 self
.g15
.clear(False)
171 status_line
= '"' + studio_name
+ '"'
173 status_line
+= " started"
175 status_line
+= " (RT)"
177 status_line
+= " stopped"
180 status_line
= "ladish is sick, jack started w/o studio"
182 status_line
= "No studio loaded"
187 status_line
+= " started in realtime mode"
189 status_line
+= " started in non-realtime mode"
191 status_line
+= " stopped"
194 status_line
= "JACK cannot be connected"
196 self
.g15
.clear(False)
200 self
.g15
.draw_lines([status_line
], 0, 0, self
.g15
.text_justify_left
)
202 self
.g15
.draw_lines(["DSP load"], 0, 12, self
.g15
.text_justify_left
)
203 self
.g15
.draw_bar(35, 12, 95, 5, True, load
/ 100.0)
204 self
.g15
.draw_lines(["%.3f%%" % load
], 135, 12, self
.g15
.text_justify_left
)
206 self
.g15
.draw_lines([xruns_line
], 0, 22, self
.g15
.text_justify_left
)
207 self
.g15
.draw_lines([rate_line
, latency_line
], 0, 31, self
.g15
.text_justify_left
)
216 if __name__
== '__main__':
217 parser
= argparse
.ArgumentParser(description
='JACK monitor for g15 keyboards',
218 epilog
='This program is part of the LADITools suite.')
219 parser
.add_argument('--version', action
='version', version
="%(prog)s " + laditools
.get_version_string())