aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/audioleveldisplay.py
blob: f74c3f5bcee9c42a17dd07e541aa95223b1005b3 (plain)
  1. import logging
  2. from gi.repository import Gst, Gtk
  3. class AudioLevelDisplay(object):
  4. """ Displays a Level-Meter of another VideoDisplay into a GtkWidget """
  5. def __init__(self, drawing_area):
  6. self.log = logging.getLogger('AudioLevelDisplay[%s]' % drawing_area.get_name())
  7. self.drawing_area = drawing_area
  8. self.levelrms = []
  9. self.drawing_area.connect('draw', self.on_draw)
  10. def on_draw(self, widget, cr):
  11. channels = len(self.levelrms)
  12. if channels == 0:
  13. return
  14. width = self.drawing_area.get_allocated_width()
  15. height = self.drawing_area.get_allocated_height()
  16. strip_width = int(width / 2)
  17. #self.log.debug('width: %u, strip_width: %u', width, strip_width)
  18. cr.set_line_width(strip_width)
  19. maxdb = -75
  20. for idx, level in enumerate(self.levelrms):
  21. level = level / maxdb
  22. x = idx * strip_width + strip_width/2
  23. #self.log.debug('x: %u', x)
  24. cr.move_to(x, height)
  25. cr.line_to(x, height * level)
  26. if idx % 2 == 0:
  27. cr.set_source_rgb(1, 0, 0)
  28. else:
  29. cr.set_source_rgb(0, 1, 0)
  30. cr.stroke()
  31. return True
  32. def level_callback(self, peaks, rms):
  33. self.levelrms = rms
  34. self.drawing_area.queue_draw()