From 29dd13ec58619d28c8eca1898719f6f0b8a88fb3 Mon Sep 17 00:00:00 2001 From: yomguy Date: Thu, 28 Jan 2010 12:15:53 +0000 Subject: [PATCH] simplify the grapher api, add a waveform grapher example --- api.py | 1 - graph/__init__.py | 1 + tests/api/examples.py | 55 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/api.py b/api.py index e7db2bb..a4a5601 100644 --- 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 diff --git a/graph/__init__.py b/graph/__init__.py index ae5da9d..378f4f5 100644 --- a/graph/__init__.py +++ b/graph/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from timeside.graph.core import * from timeside.graph.waveform_audiolab import * from timeside.graph.spectrogram_audiolab import * diff --git a/tests/api/examples.py b/tests/api/examples.py index 15afed2..d5fb922 100644 --- a/tests/api/examples.py +++ b/tests/api/examples.py @@ -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 + + -- 2.39.5