From a9f582e266773929e935878b54f2b87a712e3ba7 Mon Sep 17 00:00:00 2001 From: yomguy Date: Wed, 4 Jul 2012 11:36:41 +0200 Subject: [PATCH] rename contour graphers, add a white one --- timeside/grapher/__init__.py | 5 +- timeside/grapher/core.py | 47 ++++++++++--------- ...eform_joydiv.py => waveform_contour_bk.py} | 15 +++--- .../{waveform_awdio.py => waveform_simple.py} | 16 ++++--- 4 files changed, 46 insertions(+), 37 deletions(-) rename timeside/grapher/{waveform_joydiv.py => waveform_contour_bk.py} (81%) rename timeside/grapher/{waveform_awdio.py => waveform_simple.py} (87%) diff --git a/timeside/grapher/__init__.py b/timeside/grapher/__init__.py index 421390c..74981e9 100644 --- a/timeside/grapher/__init__.py +++ b/timeside/grapher/__init__.py @@ -3,5 +3,6 @@ from core import * from waveform import * from spectrogram import * -from waveform_joydiv import * -from waveform_awdio import * +from waveform_contour_bk import * +from waveform_contour_wh import * +from waveform_simple import * diff --git a/timeside/grapher/core.py b/timeside/grapher/core.py index 0c24be9..5fbca93 100644 --- a/timeside/grapher/core.py +++ b/timeside/grapher/core.py @@ -43,12 +43,12 @@ default_color_schemes = { 'waveform': [(173,173,173), (147,149,196), (77,80,138), (108,66,0)], 'spectrogram': [(0, 0, 0), (58/4,68/4,65/4), (80/2,100/2,153/2), (90,180,100), (224,224,44), (255,60,30), (255,255,255)] - }, + }, 'awdio': { 'waveform': [(255,255,255), (255,255,255), (255,255,255), (255,255,255)], 'spectrogram': [(0, 0, 0), (58/4,68/4,65/4), (80/2,100/2,153/2), (90,180,100), (224,224,44), (255,60,30), (255,255,255)] - }, + }, } @@ -207,7 +207,7 @@ class WaveformImage(object): def draw_anti_aliased_pixels(self, x, y1, y2, color): """ vertical anti-aliasing at y1 and y2 """ - + y_max = max(y1, y2) y_max_int = int(y_max) alpha = y_max - y_max_int @@ -247,7 +247,7 @@ class WaveformImage(object): def watermark(self, text, color=None, opacity=.6, margin=(10,10)): self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin) - + def save(self, filename): """ Apply last 2D transforms and write all pixels to the file. """ @@ -262,14 +262,17 @@ class WaveformImage(object): class WaveformImageJoyContour(WaveformImage): - def __init__(self, image_width, image_height, nframes, samplerate, fft_size, bg_color, color_scheme, ndiv=1, symetry=None): - WaveformImage.__init__(self, image_width, image_height, nframes, samplerate, fft_size, bg_color, color_scheme) + def __init__(self, image_width, image_height, nframes, samplerate, + fft_size, bg_color, color_scheme, ndiv=1, symetry=None, color_offset=160): + WaveformImage.__init__(self, image_width, image_height, nframes, samplerate, + fft_size, bg_color, color_scheme) self.contour = numpy.zeros(self.image_width) self.centroids = numpy.zeros(self.image_width) self.ndiv = ndiv self.x = numpy.r_[0:self.image_width-1:1] self.dx1 = self.x[1]-self.x[0] self.symetry = symetry + self.color_offset = color_offset def get_peaks_contour(self, x, peaks, spectral_centroid=None): self.contour[x] = numpy.max(peaks) @@ -304,14 +307,14 @@ class WaveformImageJoyContour(WaveformImage): height = int(self.image_height/2) else: height = self.image_height - + # Multicurve rotating for i in range(0,self.ndiv): self.previous_x, self.previous_y = None, None #bright_color = 255 bright_color = int(255*(1-float(i)/(self.ndiv*2))) - bright_color = 255-bright_color+160 + bright_color = 255-bright_color+self.color_offset #line_color = self.color_lookup[int(self.centroids[j]*255.0)] line_color = (bright_color,bright_color,bright_color) @@ -328,7 +331,7 @@ class WaveformImageJoyContour(WaveformImage): curve = (height-1)*contour #curve = contour*(height-2)/2+height/2 - + for x in self.x: x = int(x) y = curve[x] @@ -363,7 +366,7 @@ class WaveformImageJoyContour(WaveformImage): def watermark(self, text, color=None, opacity=.6, margin=(10,10)): self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin) - + def save(self, filename): """ Apply last 2D transforms and write all pixels to the file. """ # middle line (0 for none) @@ -372,10 +375,10 @@ class WaveformImageJoyContour(WaveformImage): self.pixel[x, self.image_height/2] = tuple(map(lambda p: p+a, self.pixel[x, self.image_height/2])) #self.image = self.image.transpose(Image.FLIP_TOP_BOTTOM) self.image.save(filename) - + def release(self): pass - + class WaveformImageSimple(object): """ Builds a PIL image representing a waveform of the audio stream. Adds pixels iteratively thanks to the adapter providing fixed size frame buffers. @@ -407,11 +410,11 @@ class WaveformImageSimple(object): self.previous_x, self.previous_y = None, None self.frame_cursor = 0 self.pixel_cursor = 0 - + def normalize(self, contour): contour = contour-min(contour) return contour/max(contour) - + def peaks(self, samples): """ Find the minimum and maximum peak of the samples. Returns that pair in the order they were found. @@ -427,13 +430,13 @@ class WaveformImageSimple(object): return (min_value, max_value) else: return (max_value, min_value) - + def draw_peaks(self, x, peaks): """ draw 2 peaks at x using the spectral_centroid for color """ y1 = self.image_height * 0.5 - peaks[0] * (self.image_height - 4) * 0.5 y2 = self.image_height * 0.5 - peaks[1] * (self.image_height - 4) * 0.5 - + if self.previous_y and x < self.image_width-1: if y1 < y2: self.draw.line((x, 0, x, y1), self.line_color) @@ -464,19 +467,19 @@ class WaveformImageSimple(object): def watermark(self, text, color=None, opacity=.6, margin=(10,10)): self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin) - + def save(self, filename): """ Apply last 2D transforms and write all pixels to the file. """ - + # middle line (0 for none) a = 1 for x in range(self.image_width): self.pixel[x, self.image_height/2] = tuple(map(lambda p: p+a, self.pixel[x, self.image_height/2])) self.image.save(filename) - + def release(self): pass - + class SpectrogramImage(object): """ Builds a PIL image representing a spectrogram of the audio stream (level vs. frequency vs. time). Adds pixels iteratively thanks to the adapter providing fixed size frame buffers.""" @@ -545,7 +548,7 @@ class SpectrogramImage(object): (spectral_centroid, db_spectrum) = self.spectrum.process(samples, True) self.draw_spectrum(self.pixel_cursor, db_spectrum) self.pixel_cursor += 1 - + def watermark(self, text, color=None, opacity=.6, margin=(10,10)): #self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin) pass @@ -557,7 +560,7 @@ class SpectrogramImage(object): def release(self): pass - + class Noise(object): """A class that mimics audiolab.sndfile but generates noise instead of reading a wave file. Additionally it can be told to have a "broken" header and thus crashing diff --git a/timeside/grapher/waveform_joydiv.py b/timeside/grapher/waveform_contour_bk.py similarity index 81% rename from timeside/grapher/waveform_joydiv.py rename to timeside/grapher/waveform_contour_bk.py index 9af9828..072511a 100644 --- a/timeside/grapher/waveform_joydiv.py +++ b/timeside/grapher/waveform_contour_bk.py @@ -24,7 +24,7 @@ from timeside.api import IGrapher from timeside.grapher.core import * -class WaveformJoyDiv(Processor): +class WaveformContourBlack(Processor): implements(IGrapher) FFT_SIZE = 0x400 @@ -42,12 +42,12 @@ class WaveformJoyDiv(Processor): @staticmethod @interfacedoc def id(): - return "waveform_joydiv" + return "waveform_contour_bk" @staticmethod @interfacedoc def name(): - return "Waveform JoyDiv" + return "Contour black" @interfacedoc def set_colors(self, background, scheme): @@ -56,9 +56,12 @@ class WaveformJoyDiv(Processor): @interfacedoc def setup(self, channels=None, samplerate=None, nframes=None): - super(WaveformJoyDiv, self).setup(channels, samplerate, nframes) - self.graph = WaveformImageJoyContour(self.width, self.height, self.nframes(), self.samplerate(), self.FFT_SIZE, - bg_color=self.bg_color, color_scheme=self.color_scheme, ndiv=self.ndiv, symetry=self.symetry) + super(WaveformContourBlack, self).setup(channels, samplerate, nframes) + self.graph = WaveformImageJoyContour(self.width, self.height, self.nframes(), + self.samplerate(), self.FFT_SIZE, + bg_color=self.bg_color, + color_scheme=self.color_scheme, + ndiv=self.ndiv, symetry=self.symetry) @interfacedoc def process(self, frames, eod=False): diff --git a/timeside/grapher/waveform_awdio.py b/timeside/grapher/waveform_simple.py similarity index 87% rename from timeside/grapher/waveform_awdio.py rename to timeside/grapher/waveform_simple.py index 26eae20..2dd5e3e 100644 --- a/timeside/grapher/waveform_awdio.py +++ b/timeside/grapher/waveform_simple.py @@ -26,7 +26,7 @@ from timeside.grapher.core import * class WaveformAwdio(Processor): implements(IGrapher) - + FFT_SIZE = 0x400 @interfacedoc @@ -39,12 +39,12 @@ class WaveformAwdio(Processor): @staticmethod @interfacedoc def id(): - return "waveform_awdio" + return "waveform_simple" @staticmethod @interfacedoc def name(): - return "Waveform Awdio" + return "Waveform simple" @interfacedoc def set_colors(self, background, scheme): @@ -54,9 +54,11 @@ class WaveformAwdio(Processor): @interfacedoc def setup(self, channels=None, samplerate=None, nframes=None): super(WaveformAwdio, self).setup(channels, samplerate, nframes) - self.graph = WaveformImageSimple(self.width, self.height, self.nframes(), self.samplerate(), self.FFT_SIZE, - bg_color=self.bg_color, color_scheme=self.color_scheme) - + self.graph = WaveformImageSimple(self.width, self.height, self.nframes(), + self.samplerate(), self.FFT_SIZE, + bg_color=self.bg_color, + color_scheme=self.color_scheme) + @interfacedoc def process(self, frames, eod=False): self.graph.process(frames, eod) @@ -67,6 +69,6 @@ class WaveformAwdio(Processor): if output: self.graph.save(output) return self.graph.image - + def watermark(self, text, font=None, color=(255, 255, 255), opacity=.6, margin=(5,5)): self.graph.watermark(text, color=color, opacity=opacity, margin=margin) -- 2.39.5