diff options
author | MaZderMind <git@mazdermind.de> | 2015-10-06 21:25:44 +0200 |
---|---|---|
committer | MaZderMind <git@mazdermind.de> | 2015-10-06 21:25:44 +0200 |
commit | 103064675ee639f3083bde42d233c29fcecdb183 (patch) | |
tree | 7d548b42d2f72b4377ca738e20c648a27f7a7474 /voctogui/lib/audioleveldisplay.py | |
parent | 4f32f46484cb208c9fd3d90bd249b57d649aed06 (diff) |
fix audio-level meter
Diffstat (limited to 'voctogui/lib/audioleveldisplay.py')
-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() |