diff options
Diffstat (limited to 'voctogui/lib')
-rw-r--r-- | voctogui/lib/audioleveldisplay.py | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/voctogui/lib/audioleveldisplay.py b/voctogui/lib/audioleveldisplay.py index bc2a38f..f74c3f5 100644 --- a/voctogui/lib/audioleveldisplay.py +++ b/voctogui/lib/audioleveldisplay.py @@ -9,17 +9,43 @@ class AudioLevelDisplay(object): self.drawing_area = drawing_area - self.levelrms = [0, 0] # Initialize to [] + self.levelrms = [] self.drawing_area.connect('draw', self.on_draw) - def on_draw(self, widget, cr): - cr.set_source_rgb(1, 1, 1) - cr.set_line_width(10) + channels = len(self.levelrms) + + if channels == 0: + return + + width = self.drawing_area.get_allocated_width() + height = self.drawing_area.get_allocated_height() + + strip_width = int(width / 2) + #self.log.debug('width: %u, strip_width: %u', width, strip_width) + + cr.set_line_width(strip_width) + + maxdb = -75 + + for idx, level in enumerate(self.levelrms): + level = level / maxdb + + x = idx * strip_width + strip_width/2 + #self.log.debug('x: %u', x) + + cr.move_to(x, height) + cr.line_to(x, height * level) + + if idx % 2 == 0: + cr.set_source_rgb(1, 0, 0) + else: + cr.set_source_rgb(0, 1, 0) + + cr.stroke() - cr.move_to(15, 0) - cr.line_to(15, self.levelrms[0]*-20) # Work with 0+ Channels - cr.stroke() + return True def level_callback(self, peaks, rms): self.levelrms = rms + self.drawing_area.queue_draw() |