diff options
author | Thomas Vander Stichele <thomas@apestaart.org> | 2005-09-23 21:10:36 +0000 |
---|---|---|
committer | Thomas Vander Stichele <thomas@apestaart.org> | 2005-09-23 21:10:36 +0000 |
commit | ea0f5ff24b240231e30f79a62c7ce5e7ee94586b (patch) | |
tree | 87b968adb4e7a3b726a7577d5f6c1f330662971f /examples | |
parent | cfdc81b5924f265df5516dd960e8fb07d4abbcc4 (diff) |
examples/fvumeter.py: condense code by using table and loop
Original commit message from CVS:
2005-09-23 Thomas Vander Stichele <thomas at apestaart dot org>
* examples/fvumeter.py:
condense code by using table and loop
* examples/vumeter.py:
fix up example for new API for both bus and level element
Diffstat (limited to 'examples')
-rw-r--r-- | examples/fvumeter.py | 108 | ||||
-rwxr-xr-x | examples/vumeter.py | 37 |
2 files changed, 45 insertions, 100 deletions
diff --git a/examples/fvumeter.py b/examples/fvumeter.py index 3b81c64..ca90309 100644 --- a/examples/fvumeter.py +++ b/examples/fvumeter.py @@ -194,89 +194,31 @@ class FVUMeter(gtk.DrawingArea): self.topborder + vumeter_height) # draw tick marks - # - 90.0 dB - self.window.draw_line(self.style.black_gc, self.leftborder, - h - self.bottomborder, self.leftborder, - h - self.bottomborder + 5) - layout = self.create_pango_layout("-90") - layout_width, layout_height = layout.get_pixel_size() - self.window.draw_layout(self.style.black_gc, - self.leftborder - int(layout_width/2), - h - self.bottomborder + 7, layout) - - # -40.0 dB - self.window.draw_line(self.style.black_gc, - self.leftborder + int(0.15*vumeter_width), - h - self.bottomborder, - self.leftborder + int(0.15*vumeter_width), - h - self.bottomborder + 5) - layout = self.create_pango_layout("-40") - layout_width, layout_height = layout.get_pixel_size() - self.window.draw_layout(self.style.black_gc, - self.leftborder + int(0.15*vumeter_width) - int(layout_width/2), - h - self.bottomborder + 7, layout) - - # -30.0 dB - self.window.draw_line(self.style.black_gc, - self.leftborder + int(0.30*vumeter_width), - h - self.bottomborder, - self.leftborder + int(0.30*vumeter_width), - h - self.bottomborder + 5) - layout = self.create_pango_layout("-30") - layout_width, layout_height = layout.get_pixel_size() - self.window.draw_layout(self.style.black_gc, - self.leftborder + int(0.30*vumeter_width) - int(layout_width/2), - h - self.bottomborder + 7, layout) - - # -20.0 dB - self.window.draw_line(self.style.black_gc, - self.leftborder + int(0.50*vumeter_width), - h - self.bottomborder, - self.leftborder + int(0.50*vumeter_width), - h - self.bottomborder + 5) - layout = self.create_pango_layout("-20") - layout_width, layout_height = layout.get_pixel_size() - self.window.draw_layout(self.style.black_gc, - self.leftborder + int(0.50*vumeter_width) - int(layout_width/2), - h - self.bottomborder + 7, layout) - - # -10.0dB - self.window.draw_line(self.style.black_gc, - self.leftborder + int(0.75*vumeter_width), - h - self.bottomborder, - self.leftborder + int(0.75*vumeter_width), - h - self.bottomborder + 5) - layout = self.create_pango_layout("-10") - layout_width, layout_height = layout.get_pixel_size() - self.window.draw_layout(self.style.black_gc, - self.leftborder + int(0.75*vumeter_width) - int(layout_width/2), - h - self.bottomborder + 7, layout) - - # - 5.0dB - self.window.draw_line(self.style.black_gc, - self.leftborder + int(0.875*vumeter_width), - h - self.bottomborder, - self.leftborder + int(0.875*vumeter_width), - h - self.bottomborder + 5) - layout = self.create_pango_layout("-5") - layout_width, layout_height = layout.get_pixel_size() - self.window.draw_layout(self.style.black_gc, - self.leftborder + int(0.875*vumeter_width) - int(layout_width/2), - h - self.bottomborder + 7, layout) - - # 0.0dB - self.window.draw_line(self.style.black_gc, - self.leftborder + vumeter_width, - h - self.bottomborder, - self.leftborder + vumeter_width, - h - self.bottomborder + 5) - layout = self.create_pango_layout("0") - layout_width, layout_height = layout.get_pixel_size() - self.window.draw_layout(self.style.black_gc, - self.leftborder + vumeter_width - int(layout_width/2), - h - self.bottomborder + 7, layout) - - # draw the value to the right + scalers = [ + ('-90', 0.0), + ('-40', 0.15), + ('-30', 0.30), + ('-20', 0.50), + ('-10', 0.75), + ( '-5', 0.875), + ( '0', 1.0), + ] + for level, scale in scalers: + self.window.draw_line(self.style.black_gc, + self.leftborder + int (scale * vumeter_width), + h - self.bottomborder, + self.leftborder + int(scale * vumeter_width), + h - self.bottomborder + 5) + self.window.draw_line(self.style.black_gc, + self.leftborder, h - self.bottomborder, + self.leftborder, h - self.bottomborder + 5) + layout = self.create_pango_layout(level) + layout_width, layout_height = layout.get_pixel_size() + self.window.draw_layout(self.style.black_gc, + self.leftborder + int(scale * vumeter_width) - int(layout_width / 2), + h - self.bottomborder + 7, layout) + + # draw the peak level to the right layout = self.create_pango_layout("%.2fdB" % self.peaklevel) layout_width, layout_height = layout.get_pixel_size() self.window.draw_layout(self.style.black_gc, diff --git a/examples/vumeter.py b/examples/vumeter.py index 4140153..a543ed2 100755 --- a/examples/vumeter.py +++ b/examples/vumeter.py @@ -51,9 +51,13 @@ class Window(gtk.Dialog): self.set_default_size(200,60) self.set_title('Volume Level') self.connect('delete-event', lambda *x: gtk.main_quit()) - self.vu = fvumeter.FVUMeter() - self.vu.show() - self.vbox.pack_start(self.vu) + 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() def error(self, message, secondary=None): m = gtk.MessageDialog(self, @@ -66,18 +70,13 @@ class Window(gtk.Dialog): m.run() def on_message(self, bus, message): - t = message.type - if t == gst.MESSAGE_STATE_CHANGED: - pass - if (t == gst.MESSAGE_APPLICATION and - message.structure.get_name() == 'level'): + if message.structure.get_name() == 'level': s = message.structure - self.vu.set_property('peak', clamp(s['peak'][0], -90.0, 0.0)) - self.vu.set_property('decay', clamp(s['decay'][0], -90.0, 0.0)) - else: - print '%s: %s:' % (message.src.get_path_string(), - message.type.value_nicks[1]) - print ' %s' % message.structure.to_string() + for i in range(0, len(s['peak'])): + self.vus[i].set_property('peak', + clamp(s['peak'][i], -90.0, 0.0)) + self.vus[i].set_property('decay', + clamp(s['decay'][i], -90.0, 0.0)) return True def run(self): @@ -86,8 +85,12 @@ class Window(gtk.Dialog): s = 'alsasrc ! level message=true ! fakesink' pipeline = gst.parse_launch(s) self.set_sensitive(True) - watch_id = pipeline.get_bus().add_watch(self.on_message) - if pipeline.set_state(gst.STATE_PLAYING) == gst.STATE_SUCCESS: + # FIXME: using gst.MESSAGE_APPLICATION does not give me + # any messages at all + watch_id = pipeline.get_bus().add_watch(gst.MESSAGE_ANY, + self.on_message) + if pipeline.set_state(gst.STATE_PLAYING) == gst.STATE_CHANGE_SUCCESS: + print "going into main" gtk.Dialog.run(self) else: self.error('Could not set state') @@ -99,5 +102,5 @@ class Window(gtk.Dialog): if __name__ == '__main__': w = Window() - w.show() + w.show_all() w.run() |