From 103064675ee639f3083bde42d233c29fcecdb183 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Tue, 6 Oct 2015 21:25:44 +0200 Subject: fix audio-level meter --- voctogui/lib/audioleveldisplay.py | 40 ++++++++++++++++++++++++++++++++------- voctogui/ui/voctogui.ui | 3 +++ 2 files changed, 36 insertions(+), 7 deletions(-) (limited to 'voctogui') 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() diff --git a/voctogui/ui/voctogui.ui b/voctogui/ui/voctogui.ui index 5e668e9..f6aa897 100644 --- a/voctogui/ui/voctogui.ui +++ b/voctogui/ui/voctogui.ui @@ -276,6 +276,9 @@ 30 True False + 5 + 5 + 5 False -- cgit v1.2.3