Skip to content

Commit

Permalink
revert accidentially commits on master branch
Browse files Browse the repository at this point in the history
Damn, I accidentially committed my last eight changes into the master
branch instead of my feature branch.

List of the reverted commits:
4b175d1
9bf67db
d6d1bbb
49be9fa
246b69d
f2939df
014c460
fd1a6ee
  • Loading branch information
fightling committed Apr 17, 2018
1 parent 4b175d1 commit 24f11df
Showing 1 changed file with 46 additions and 49 deletions.
95 changes: 46 additions & 49 deletions voctogui/lib/audioleveldisplay.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import math
import cairo


class AudioLevelDisplay(object):
Expand All @@ -22,19 +21,6 @@ def __init__(self, drawing_area):
# register on_draw handler
self.drawing_area.connect('draw', self.on_draw)

# generate gradient from green to yellow to red in logarithmic scale
def gradient(self, brightness, darkness, height):
# prepare gradient
lg = cairo.LinearGradient(0, 0, 0, height)
# set gradient stops
lg.add_color_stop_rgb(0.0, brightness, darkness, darkness)
lg.add_color_stop_rgb(0.22, brightness, brightness, darkness)
lg.add_color_stop_rgb(0.25, brightness, brightness, darkness)
lg.add_color_stop_rgb(0.35, darkness, brightness, darkness)
lg.add_color_stop_rgb(1.0, darkness, brightness, darkness)
# return result
return lg

def on_draw(self, widget, cr):
# number of audio-channels
channels = len(self.levelrms)
Expand Down Expand Up @@ -62,41 +48,52 @@ def on_draw(self, widget, cr):
peak_px = [self.normalize_db(db) * height for db in self.levelpeak]
decay_px = [self.normalize_db(db) * height for db in self.leveldecay]

if self.height != height:
self.height = height
# setup gradients for all level bars
self.bg_lg = self.gradient(0.25, 0.0, height)
self.rms_lg = self.gradient(1.0, 0.0, height)
self.peak_lg = self.gradient(0.75, 0.0, height)
self.decay_lg = self.gradient(1.0, 0.5, height)

# draw all level bars for all channels
for channel in range(0, channels):
# start-coordinate for this channel
x = (channel * channel_width) + (channel * margin)

# draw background
cr.rectangle(x, 0, channel_width, height - peak_px[channel])
cr.set_source(self.bg_lg)
cr.fill()

# draw peak bar
cr.rectangle(
x, height - peak_px[channel], channel_width, peak_px[channel])
cr.set_source(self.peak_lg)
cr.fill()

# draw rms bar below
cr.rectangle(
x, height - rms_px[channel], channel_width,
rms_px[channel] - peak_px[channel])
cr.set_source(self.rms_lg)
cr.fill()

# draw decay bar
cr.rectangle(x, height - decay_px[channel], channel_width, 2)
cr.set_source(self.decay_lg)
cr.fill()
# set the line-width >1, to get a nice overlap
cr.set_line_width(2)

# iterate over all pixels
for y in range(0, height):

# calculate our place in the color-gradient, clamp to 0…1
# 0 -> green, 0.5 -> yellow, 1 -> red
color = self.clamp(((y / height) - 0.6) / 0.42)

for channel in range(0, channels):
# start-coordinate for this channel
x = (channel * channel_width) + (channel * margin)

# calculate the brightness based on whether this line is in the
# active region

# default to 0.25, dark
bright = 0.25
if int(y - decay_px[channel]) in range(0, 2):
# decay marker, 2px wide, extra bright
bright = 1.5
elif y < rms_px[channel]:
# rms bar, full bright
bright = 1
elif y < peak_px[channel]:
# peak bar, a little darker
bright = 0.75

# set the color with a little reduced green
cr.set_source_rgb(
color * bright,
(1 - color) * bright * 0.75,
0
)

# draw the marker
cr.move_to(x, height - y)
cr.line_to(x + channel_width, height - y)
cr.stroke()

# draw a black line for the margin
cr.set_source_rgb(0, 0, 0)
cr.move_to(x + channel_width, height - y)
cr.line_to(x + channel_width + margin, height - y)
cr.stroke()

# draw medium grey margin bar
if margin > 0:
Expand Down

0 comments on commit 24f11df

Please sign in to comment.