2005-07-13 10:55:18 +00:00
|
|
|
#!/usr/bin/env python
|
2005-11-19 10:37:58 +00:00
|
|
|
# -*- Mode: Python -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
|
2005-07-13 10:55:18 +00:00
|
|
|
# gst-python
|
|
|
|
# Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Library General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library 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
|
|
|
|
# Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Library General Public
|
|
|
|
# License along with this library; if not, write to the
|
2013-11-25 17:01:48 +00:00
|
|
|
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2013-12-12 11:20:12 +00:00
|
|
|
# Boston, MA 02110-1301, USA.
|
2005-07-13 10:55:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
# A test more of gst-plugins than of gst-python.
|
|
|
|
|
|
|
|
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
import pygst
|
2005-12-01 19:15:26 +00:00
|
|
|
pygst.require('0.10')
|
2005-07-13 10:55:18 +00:00
|
|
|
import gst
|
|
|
|
|
|
|
|
import fvumeter
|
|
|
|
|
|
|
|
|
|
|
|
def clamp(x, min, max):
|
|
|
|
if x < min:
|
|
|
|
return min
|
|
|
|
elif x > max:
|
|
|
|
return max
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
|
|
|
class Window(gtk.Dialog):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Dialog.__init__(self, 'Volume Level')
|
|
|
|
self.prepare_ui()
|
|
|
|
|
|
|
|
def prepare_ui(self):
|
|
|
|
self.set_default_size(200,60)
|
|
|
|
self.set_title('Volume Level')
|
|
|
|
self.connect('delete-event', lambda *x: gtk.main_quit())
|
2005-09-23 21:10:36 +00:00
|
|
|
self.vus = []
|
|
|
|
self.vus.append(fvumeter.FVUMeter())
|
|
|
|
self.vus.append(fvumeter.FVUMeter())
|
|
|
|
self.vbox.add(self.vus[0])
|
|
|
|
self.vbox.add(self.vus[1])
|
|
|
|
self.vus[0].show()
|
|
|
|
self.vus[1].show()
|
2005-07-13 10:55:18 +00:00
|
|
|
|
|
|
|
def error(self, message, secondary=None):
|
|
|
|
m = gtk.MessageDialog(self,
|
|
|
|
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
gtk.MESSAGE_ERROR,
|
|
|
|
gtk.BUTTONS_OK,
|
|
|
|
message)
|
|
|
|
if secondary:
|
|
|
|
m.format_secondary_text(secondary)
|
|
|
|
m.run()
|
|
|
|
|
|
|
|
def on_message(self, bus, message):
|
2005-09-23 21:10:36 +00:00
|
|
|
if message.structure.get_name() == 'level':
|
2005-07-13 10:55:18 +00:00
|
|
|
s = message.structure
|
2005-09-23 21:10:36 +00:00
|
|
|
for i in range(0, len(s['peak'])):
|
2005-09-24 12:17:59 +00:00
|
|
|
self.vus[i].freeze_notify()
|
|
|
|
decay = clamp(s['decay'][i], -90.0, 0.0)
|
|
|
|
peak = clamp(s['peak'][i], -90.0, 0.0)
|
|
|
|
if peak > decay:
|
|
|
|
print "ERROR: peak bigger than decay!"
|
|
|
|
|
|
|
|
self.vus[i].set_property('decay', decay)
|
|
|
|
self.vus[i].set_property('peak', peak)
|
2005-07-13 10:55:18 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
try:
|
|
|
|
self.set_sensitive(False)
|
2005-09-12 17:06:09 +00:00
|
|
|
s = 'alsasrc ! level message=true ! fakesink'
|
2005-07-13 10:55:18 +00:00
|
|
|
pipeline = gst.parse_launch(s)
|
|
|
|
self.set_sensitive(True)
|
2005-09-29 16:38:06 +00:00
|
|
|
pipeline.get_bus().add_signal_watch()
|
2006-02-20 18:07:59 +00:00
|
|
|
i = pipeline.get_bus().connect('message::element', self.on_message)
|
2006-02-20 16:58:14 +00:00
|
|
|
pipeline.set_state(gst.STATE_PLAYING)
|
|
|
|
gtk.Dialog.run(self)
|
2005-09-29 16:38:06 +00:00
|
|
|
pipeline.get_bus().disconnect(i)
|
|
|
|
pipeline.get_bus().remove_signal_watch()
|
2005-07-13 10:55:18 +00:00
|
|
|
pipeline.set_state(gst.STATE_NULL)
|
|
|
|
except gobject.GError, e:
|
|
|
|
self.set_sensitive(True)
|
|
|
|
self.error('Could not create pipeline', e.__str__)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
w = Window()
|
2005-09-23 21:10:36 +00:00
|
|
|
w.show_all()
|
2005-07-13 10:55:18 +00:00
|
|
|
w.run()
|