Move channel buffers from stack to structs so theyt can be reused when mixing with...
[jack_mixer.git] / abspeak.py
blob1b65c9550d639bc448ea33eb2f89f43d424623fd
1 #!/usr/bin/env python
3 # This file is part of jack_mixer
5 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License
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, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 import gtk
21 import fpconst
22 import pango
23 import gobject
25 class widget(gtk.EventBox):
26 def __init__(self):
27 gtk.EventBox.__init__(self)
28 self.label = gtk.Label()
29 attrs = pango.AttrList()
30 font_attr = pango.AttrFamily("monospace")
31 attrs.insert(font_attr)
32 self.label.set_attributes(attrs)
33 self.add(self.label)
34 self.connect("button-press-event", self.on_mouse)
35 self.peak = fpconst.NegInf
37 def on_mouse(self, widget, event):
38 if event.type == gtk.gdk.BUTTON_PRESS:
39 if event.button == 1:
40 self.emit("reset")
41 elif event.button == 2:
42 adjust = -self.peak
43 if abs(adjust) < 30: # we better don't adjust more than +- 30 dB
44 self.emit("volume-adjust", adjust)
46 def set_peak(self, peak):
47 self.peak = peak
48 if fpconst.isNaN(peak):
49 self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(int(65535 * 0.7), 0, 0))
50 self.label.set_text("NaN")
51 else:
52 text = "%+.1f" % peak
54 if peak > 0:
55 self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(int(65535 * 0.8), int(65535 * 0.3), 0))
56 else:
57 self.modify_bg(gtk.STATE_NORMAL, self.label.style.bg[gtk.STATE_NORMAL])
59 self.label.set_text(text)
61 gobject.signal_new("reset", widget, gobject.SIGNAL_RUN_FIRST | gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [])
62 gobject.signal_new("volume-adjust", widget, gobject.SIGNAL_RUN_FIRST | gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [gobject.TYPE_FLOAT])