3 # vi:si:et:sw=4:sts=4:ts=4
6 # Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Library General Public
10 # License as published by the Free Software Foundation; either
11 # version 2 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Library General Public License for more details.
18 # You should have received a copy of the GNU Library General Public
19 # License along with this library; if not, write to the
20 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 # Boston, MA 02110-1301, USA.
24 # A test more of gst-plugins than of gst-python.
39 def clamp(x, min, max):
47 class Window(gtk.Dialog):
49 gtk.Dialog.__init__(self, 'Volume Level')
53 self.set_default_size(200,60)
54 self.set_title('Volume Level')
55 self.connect('delete-event', lambda *x: gtk.main_quit())
57 self.vus.append(fvumeter.FVUMeter())
58 self.vus.append(fvumeter.FVUMeter())
59 self.vbox.add(self.vus[0])
60 self.vbox.add(self.vus[1])
64 def error(self, message, secondary=None):
65 m = gtk.MessageDialog(self,
66 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
71 m.format_secondary_text(secondary)
74 def on_message(self, bus, message):
75 if message.structure.get_name() == 'level':
77 for i in range(0, len(s['peak'])):
78 self.vus[i].freeze_notify()
79 decay = clamp(s['decay'][i], -90.0, 0.0)
80 peak = clamp(s['peak'][i], -90.0, 0.0)
82 print "ERROR: peak bigger than decay!"
84 self.vus[i].set_property('decay', decay)
85 self.vus[i].set_property('peak', peak)
90 self.set_sensitive(False)
91 s = 'alsasrc ! level message=true ! fakesink'
92 pipeline = gst.parse_launch(s)
93 self.set_sensitive(True)
94 pipeline.get_bus().add_signal_watch()
95 i = pipeline.get_bus().connect('message::element', self.on_message)
96 pipeline.set_state(gst.STATE_PLAYING)
98 pipeline.get_bus().disconnect(i)
99 pipeline.get_bus().remove_signal_watch()
100 pipeline.set_state(gst.STATE_NULL)
101 except gobject.GError, e:
102 self.set_sensitive(True)
103 self.error('Could not create pipeline', e.__str__)
105 if __name__ == '__main__':