]> git.parisson.com Git - timeside.git/commitdiff
* add pissing new contour grapher template
authoryomguy <yomguy@parisson.com>
Wed, 25 Jul 2012 17:01:23 +0000 (19:01 +0200)
committeryomguy <yomguy@parisson.com>
Wed, 25 Jul 2012 17:01:23 +0000 (19:01 +0200)
* update tests

tests/testgraphers.py
timeside/grapher/waveform_contour_wh.py [new file with mode: 0644]

index 87be6160bb5d9a2573371b35e4a47eb5d42e3280..314de69fe58a7670c9012c3db7177be31487922c 100644 (file)
@@ -17,7 +17,7 @@ class TestGraphers(TestCase):
 
     def setUp(self):
         pass
-    
+
     # WAVEFORMS
     def testWav2Waveform(self):
         "Test WAV to Waveform"
@@ -30,74 +30,100 @@ class TestGraphers(TestCase):
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.flac")
         self.image = "/tmp/test_waveform_sweep_flac.png"
         self.grapher = Waveform(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-    
+
     def testMp32Waveform(self):
         "Test MP3 to Waveform"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.mp3")
         self.image = "/tmp/test_waveform_sweep_mp3.png"
         self.grapher = Waveform(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-    
+
     def testOgg2Waveform(self):
         "Test OGG to Waveform"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.ogg")
         self.image = "/tmp/test_waveform_sweep_ogg.png"
         self.grapher = Waveform(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-    
-    # WAVEFORMS JOYDIV
-    def testWav2WaveformJoyDiv(self):
-        "Test WAV to WaveformJoyDiv"
+
+    # WAVEFORMS CONTOUR BLACK
+    def testWav2WaveformContourBlack(self):
+        "Test WAV to WaveformContourBlack"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.wav")
-        self.image = "/tmp/test_waveformjoydiv_sweep_wav.png"
-        self.grapher = WaveformJoyDiv(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
+        self.image = "/tmp/test_waveform_contour_bk_sweep_wav.png"
+        self.grapher = WaveformContourBlack(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
 
-    def testFlac2WaveformJoyDiv(self):
-        "Test FLAC to WaveformJoyDiv"
+    def testFlac2WaveformContourBlack(self):
+        "Test FLAC to WaveformContourBlack"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.flac")
-        self.image = "/tmp/test_waveformjoydiv_sweep_flac.png"
-        self.grapher = WaveformJoyDiv(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-    
-    def testMp32WaveformJoyDiv(self):
-        "Test MP3 to WaveformJoyDiv"
+        self.image = "/tmp/test_waveform_contour_bk_sweep_flac.png"
+        self.grapher = WaveformContourBlack(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
+
+    def testMp32WaveformContourBlack(self):
+        "Test MP3 to WaveformContourBlack"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.mp3")
-        self.image = "/tmp/test_waveformjoydiv_sweep_mp3.png"
-        self.grapher = WaveformJoyDiv(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-    
-    def testOgg2WaveformJoyDiv(self):
-        "Test OGG to WaveformJoyDiv"
+        self.image = "/tmp/test_waveform_contour_bk_sweep_mp3.png"
+        self.grapher = WaveformContourBlack(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
+
+    def testOgg2WaveformContourBlack(self):
+        "Test OGG to WaveformContourBlack"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.ogg")
-        self.image = "/tmp/test_waveformjoydiv_sweep_ogg.png"
-        self.grapher = WaveformJoyDiv(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-        
+        self.image = "/tmp/test_waveform_contour_bk_sweep_ogg.png"
+        self.grapher = WaveformContourBlack(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
+
+    # WAVEFORMS CONTOUR WHITE
+    def testWav2WaveformContourWhite(self):
+        "Test WAV to WaveformContourWhite"
+        self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.wav")
+        self.image = "/tmp/test_waveform_contour_wh_sweep_wav.png"
+        self.grapher = WaveformContourWhite(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
+
+    def testFlac2WaveformContourWhite(self):
+        "Test FLAC to WaveformContourWhite"
+        self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.flac")
+        self.image = "/tmp/test_waveform_contour_wh_sweep_flac.png"
+        self.grapher = WaveformContourWhite(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
+
+    def testMp32WaveformContourWhite(self):
+        "Test MP3 to WaveformContourWhite"
+        self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.mp3")
+        self.image = "/tmp/test_waveform_contour_wh_sweep_mp3.png"
+        self.grapher = WaveformContourWhite(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
+
+    def testOggWaveformContourWhite(self):
+        "Test OGG to WaveformContourWhite"
+        self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.ogg")
+        self.image = "/tmp/test_waveform_contour_wh_sweep_ogg.png"
+        self.grapher = WaveformContourWhite(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
+
+
     # SPECTROGRAMS
     def testWav2Spectrogram(self):
         "Test WAV to Spectrogram"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.wav")
         self.image = "/tmp/test_spectrogram_sweep_wav.png"
         self.grapher = Spectrogram(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-    
+
     def testMp32Spectrogram(self):
         "Test MP3 to Spectrogram"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.mp3")
         self.image = "/tmp/test_spectrogram_sweep_mp3.png"
         self.grapher = Spectrogram(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-    
+
     def testFlac2Spectrogram(self):
         "Test FLAC to Spectrogram"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.flac")
         self.image = "/tmp/test_spectrogram_sweep_flac.png"
         self.grapher = Spectrogram(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-    
+
     def testOgg2Spectrogram(self):
         "Test OGG to Spectrogram"
         self.source = os.path.join (os.path.dirname(__file__),  "samples/sweep.ogg")
         self.image = "/tmp/test_spectrogram_sweep_ogg.png"
         self.grapher = Spectrogram(width=1024, height=256, bg_color=(0,0,0), color_scheme='default')
-     
+
     def tearDown(self):
         decoder = FileDecoder(self.source)
         (decoder | self.grapher).run()
         self.grapher.render(self.image)
-        
+
 if __name__ == '__main__':
     unittest.main(testRunner=TestRunner())
 
diff --git a/timeside/grapher/waveform_contour_wh.py b/timeside/grapher/waveform_contour_wh.py
new file mode 100644 (file)
index 0000000..a49ac6c
--- /dev/null
@@ -0,0 +1,82 @@
+# -*- 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 WaveformContourWhite(Processor):
+    implements(IGrapher)
+
+    FFT_SIZE = 0x400
+
+    @interfacedoc
+    def __init__(self, width=1024, height=256, bg_color=(255,255,255), 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_wh"
+
+    @staticmethod
+    @interfacedoc
+    def name():
+        return "Contour white"
+
+    @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(WaveformContourWhite, 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,
+                                            color_offset=60)
+
+    @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=(0, 0, 0), opacity=.6, margin=(5,5)):
+        self.graph.watermark(text, color=color, opacity=opacity, margin=margin)