]> git.parisson.com Git - timeside.git/commitdiff
rename contour graphers, add a white one
authoryomguy <yomguy@parisson.com>
Wed, 4 Jul 2012 09:36:41 +0000 (11:36 +0200)
committeryomguy <yomguy@parisson.com>
Wed, 4 Jul 2012 09:36:41 +0000 (11:36 +0200)
timeside/grapher/__init__.py
timeside/grapher/core.py
timeside/grapher/waveform_awdio.py [deleted file]
timeside/grapher/waveform_contour_bk.py [new file with mode: 0644]
timeside/grapher/waveform_joydiv.py [deleted file]
timeside/grapher/waveform_simple.py [new file with mode: 0644]

index 421390c0a5230598d015dd5189ceb8a280892581..74981e901cae5bbd4cf7778800fd3b454b3c774b 100644 (file)
@@ -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 *
index 0c24be97bb6940a18c2eec0733a4dc6237af04cd..5fbca9351946ee9445885ceee8b7a2b542f527b2 100644 (file)
@@ -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_awdio.py b/timeside/grapher/waveform_awdio.py
deleted file mode 100644 (file)
index 26eae20..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (c) 2007-2010 Guillaume Pellerin <yomguy@parisson.com>
-# Copyright (c) 2010 Olivier Guilyardi <olivier@samalyse.com>
-
-# This file is part of TimeSide.
-
-# TimeSide is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-
-# TimeSide is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
-
-
-from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
-from timeside.api import IGrapher
-from timeside.grapher.core import *
-
-
-class WaveformAwdio(Processor):
-    implements(IGrapher)
-    
-    FFT_SIZE = 0x400
-
-    @interfacedoc
-    def __init__(self, width=572, height=74, bg_color=None, color_scheme='awdio'):
-        self.width = width
-        self.height = height
-        self.bg_color = bg_color
-        self.color_scheme = color_scheme
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "waveform_awdio"
-
-    @staticmethod
-    @interfacedoc
-    def name():
-        return "Waveform Awdio"
-
-    @interfacedoc
-    def set_colors(self, background, scheme):
-        self.bg_color = background
-        self.color_scheme = scheme
-
-    @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)
-    
-    @interfacedoc
-    def process(self, frames, eod=False):
-        self.graph.process(frames, eod)
-        return frames, eod
-
-    @interfacedoc
-    def render(self, output):
-        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)
diff --git a/timeside/grapher/waveform_contour_bk.py b/timeside/grapher/waveform_contour_bk.py
new file mode 100644 (file)
index 0000000..072511a
--- /dev/null
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2007-2010 Guillaume Pellerin <yomguy@parisson.com>
+# Copyright (c) 2010 Olivier Guilyardi <olivier@samalyse.com>
+
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+
+from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
+from timeside.api import IGrapher
+from timeside.grapher.core import *
+
+
+class WaveformContourBlack(Processor):
+    implements(IGrapher)
+
+    FFT_SIZE = 0x400
+
+    @interfacedoc
+    def __init__(self, width=1024, height=256, bg_color=(0,0,0), color_scheme='default'):
+        self.width = width
+        self.height = height
+        self.bg_color = bg_color
+        self.color_scheme = color_scheme
+        self.graph = None
+        self.ndiv = 4
+        self.symetry = True
+
+    @staticmethod
+    @interfacedoc
+    def id():
+        return "waveform_contour_bk"
+
+    @staticmethod
+    @interfacedoc
+    def name():
+        return "Contour black"
+
+    @interfacedoc
+    def set_colors(self, background, scheme):
+        self.bg_color = background
+        self.color_scheme = scheme
+
+    @interfacedoc
+    def setup(self, channels=None, samplerate=None, nframes=None):
+        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):
+        self.graph.process(frames, eod)
+        return frames, eod
+
+    @interfacedoc
+    def render(self, output):
+        if output:
+            self.graph.save(output)
+        return self.graph.image
+
+    def release(self):
+        self.graph.release()
+
+    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)
diff --git a/timeside/grapher/waveform_joydiv.py b/timeside/grapher/waveform_joydiv.py
deleted file mode 100644 (file)
index 9af9828..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (c) 2007-2010 Guillaume Pellerin <yomguy@parisson.com>
-# Copyright (c) 2010 Olivier Guilyardi <olivier@samalyse.com>
-
-# This file is part of TimeSide.
-
-# TimeSide is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# (at your option) any later version.
-
-# TimeSide is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
-
-
-from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
-from timeside.api import IGrapher
-from timeside.grapher.core import *
-
-
-class WaveformJoyDiv(Processor):
-    implements(IGrapher)
-
-    FFT_SIZE = 0x400
-
-    @interfacedoc
-    def __init__(self, width=1024, height=256, bg_color=(0,0,0), color_scheme='default'):
-        self.width = width
-        self.height = height
-        self.bg_color = bg_color
-        self.color_scheme = color_scheme
-        self.graph = None
-        self.ndiv = 4
-        self.symetry = True
-
-    @staticmethod
-    @interfacedoc
-    def id():
-        return "waveform_joydiv"
-
-    @staticmethod
-    @interfacedoc
-    def name():
-        return "Waveform JoyDiv"
-
-    @interfacedoc
-    def set_colors(self, background, scheme):
-        self.bg_color = background
-        self.color_scheme = scheme
-
-    @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)
-
-    @interfacedoc
-    def process(self, frames, eod=False):
-        self.graph.process(frames, eod)
-        return frames, eod
-
-    @interfacedoc
-    def render(self, output):
-        if output:
-            self.graph.save(output)
-        return self.graph.image
-
-    def release(self):
-        self.graph.release()
-
-    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)
diff --git a/timeside/grapher/waveform_simple.py b/timeside/grapher/waveform_simple.py
new file mode 100644 (file)
index 0000000..2dd5e3e
--- /dev/null
@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2007-2010 Guillaume Pellerin <yomguy@parisson.com>
+# Copyright (c) 2010 Olivier Guilyardi <olivier@samalyse.com>
+
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+
+from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
+from timeside.api import IGrapher
+from timeside.grapher.core import *
+
+
+class WaveformAwdio(Processor):
+    implements(IGrapher)
+
+    FFT_SIZE = 0x400
+
+    @interfacedoc
+    def __init__(self, width=572, height=74, bg_color=None, color_scheme='awdio'):
+        self.width = width
+        self.height = height
+        self.bg_color = bg_color
+        self.color_scheme = color_scheme
+
+    @staticmethod
+    @interfacedoc
+    def id():
+        return "waveform_simple"
+
+    @staticmethod
+    @interfacedoc
+    def name():
+        return "Waveform simple"
+
+    @interfacedoc
+    def set_colors(self, background, scheme):
+        self.bg_color = background
+        self.color_scheme = scheme
+
+    @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)
+
+    @interfacedoc
+    def process(self, frames, eod=False):
+        self.graph.process(frames, eod)
+        return frames, eod
+
+    @interfacedoc
+    def render(self, output):
+        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)