]> git.parisson.com Git - timeside.git/commitdiff
simplify the grapher api, add a waveform grapher example
authoryomguy <yomguy@parisson.com>
Thu, 28 Jan 2010 12:15:53 +0000 (12:15 +0000)
committeryomguy <yomguy@parisson.com>
Thu, 28 Jan 2010 12:15:53 +0000 (12:15 +0000)
api.py
graph/__init__.py
tests/api/examples.py

diff --git a/api.py b/api.py
index e7db2bbe7f38208e3e260e7ef2ac382380609b9a..a4a5601a4b07d9f2230a3e1634db02f8b86c9997 100644 (file)
--- a/api.py
+++ b/api.py
@@ -154,7 +154,6 @@ class IGrapher(IProcessor):
     def set_colors(self, background=None, scheme=None):
         """Set the colors used for image generation. background is a RGB tuple,
         and scheme a a predefined color theme name"""
-        pass
 
     def render(self):
         """Return a PIL Image object visually representing all of the data passed
index ae5da9daa610fede104373ce116e017f8a40e6d8..378f4f5c8b3a3d2cafbe240ad36f1e30bae0665f 100644 (file)
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
 
+from timeside.graph.core import *
 from timeside.graph.waveform_audiolab import *
 from timeside.graph.spectrogram_audiolab import *
index 15afed2db11a3137b075a7f45c7471f7eddb09d4..d5fb922b231c92e6ca44cf5199084536472511d4 100644 (file)
@@ -1,5 +1,6 @@
 from timeside.core import Processor, implements, interfacedoc
 from timeside.api import *
+from timeside.graph import *
 from timeside import Metadata
 from scikits import audiolab
 import numpy
@@ -56,7 +57,6 @@ class FileDecoder(Processor):
     @interfacedoc
     def encoding(self):
         return self.file.get_encoding()
-
     @interfacedoc
     def resolution(self):
         resolution = None
@@ -64,6 +64,7 @@ class FileDecoder(Processor):
 
         if encoding == "pcm8":
             resolution = 8
+
         elif encoding == "pcm16":
             resolution = 16
         elif encoding == "pcm32":
@@ -163,7 +164,7 @@ class WavEncoder(Processor):
     def setup(self, channels=None, samplerate=None):
         Processor.setup(self, channels, samplerate)
         if self.file:
-            self.file.close();
+            self.file.close()
 
         info = audiolab.formatinfo("wav", "pcm16")
         self.file = audiolab.sndfile(self.filename, "write", format=info, channels=channels,
@@ -203,3 +204,53 @@ class WavEncoder(Processor):
 
         return frames, eod
 
+
+class Waveform(Processor):
+    implements(IGrapher)
+
+    @interfacedoc
+    def __init__(self, width, height, output=None):
+        self.image = None
+        if width:
+            self.width = width
+        else:
+            self.width = 1500
+        if height:
+            self.height = height
+        else:
+            self.height = 200
+        if isinstance(output, basestring):
+            self.filename = output
+        else:
+            raise Exception("Streaming not supported")
+
+    @staticmethod
+    @interfacedoc
+    def id():
+        return "test_waveform"
+
+    @staticmethod
+    @interfacedoc
+    def name():
+        return "Waveform test"
+
+    @interfacedoc
+    def set_colors(self, background=None, scheme=None):
+        self.bg_color = background
+        self.color_scheme = scheme
+
+    @interfacedoc
+    def setup(self, channels=None, samplerate=None):
+        Processor.setup(self, channels, samplerate)
+        if self.image:
+            self.image.close()
+        self.image = WaveformImage(self.width, self.height, self.bg_color, self.color_scheme, self.filename)
+    
+    @interfacedoc
+    def render(self):
+        self.image.process()
+        if self.filename:
+            self.image.save()
+        return self.image
+        
+