from __future__ import division
from timeside.core import Processor
-from timeside.__init__ import __version__
+import timeside #import __version__
import numpy
from collections import OrderedDict
import h5py
fig = plt.figure(figsize=(xSize, ySize), dpi=dpi)
- ax = plt.Axes(fig, [0, 0, 1, 0.9])
+ ax = plt.Axes(fig, [0, 0, 1, 1])
ax.set_frame_on(False)
-
self._render_plot(ax)
- ax.axis('off')
+# ax.axis('off')
+ # ax.axis('tight')
+ ax.autoscale(axis='x', tight=True)
fig.add_axes(ax)
return fig
# Automatically write known metadata
result.id_metadata.date = datetime.now().replace(
microsecond=0).isoformat(' ')
- result.id_metadata.version = __version__
+ result.id_metadata.version = timeside.__version__
result.id_metadata.author = 'TimeSide'
result.id_metadata.id = self.id()
result.id_metadata.name = self.name()
# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division
-from timeside.core import implements, interfacedoc
+from timeside.core import implements, interfacedoc, abstract
from timeside.api import IGrapher
-from timeside.grapher.core import *
+from core import Grapher, Image
+from timeside import analyzer
-class DisplayAnalyzers(Grapher):
- """ Builds a PIL image ..."""
+class DisplayAnalyzer(Grapher):
+ """
+ Builds a PIL image from analyzer result
+ This is an Abstract base class
+ """
dpi = 72 # Web default value for Telemeta
implements(IGrapher)
@interfacedoc
def __init__(self, width=1024, height=256, bg_color=(0, 0, 0),
color_scheme='default'):
- super(DisplayAnalyzers, self).__init__(width, height, bg_color,
+ super(DisplayAnalyzer, self).__init__(width, height, bg_color,
color_scheme)
- self.dpi = 72
+ #self.dpi = 72
+
+ self._result_id = None
+ self._id = NotImplemented
+ self._name = NotImplemented
@interfacedoc
def process(self, frames, eod=False):
@interfacedoc
def post_process(self):
- parent_result = self.process_pipe.results[self.analyzer_id]
+ parent_result = self.process_pipe.results[self._result_id]
fig = parent_result.render((self.image_width,
self.image_height), self.dpi)
imgdata.seek(0) # rewind the data
self.image = Image.open(imgdata)
+ @classmethod
+ def create(cls, analyzer, result_id, grapher_id, grapher_name):
-class DisplayAubioPitch(DisplayAnalyzers):
+ class NewGrapher(cls):
- implements(IGrapher)
- @interfacedoc
- def __init__(self, width=1024, height=256, bg_color=(0, 0, 0),
- color_scheme='default'):
- super(DisplayAubioPitch, self).__init__(width, height, bg_color,
- color_scheme)
+ _id = grapher_id
- # Analyzer definition --> change this to implement a new analyzer
- from timeside.analyzer import AubioPitch
- self.parents.append(AubioPitch())
- self.analyzer_id = 'aubio_pitch.pitch' # TODO : make it generic when analyzer will be "atomize"
+ implements(IGrapher)
- @staticmethod
- @interfacedoc
- def id():
- return "grapher_aubio_pitch"
+ @interfacedoc
+ def __init__(self, width=1024, height=256, bg_color=(0, 0, 0),
+ color_scheme='default'):
+ super(NewGrapher, self).__init__(width, height, bg_color,
+ color_scheme)
- @staticmethod
- @interfacedoc
- def name():
- return "Aubio Pitch"
+ self.parents.append(analyzer)
+ self._result_id = result_id # TODO : make it generic when analyzer will be "atomize"
+
+ @staticmethod
+ @interfacedoc
+ def id():
+ return grapher_id
+
+ @staticmethod
+ @interfacedoc
+ def name():
+ return grapher_name
+
+ NewGrapher.__name__ = 'Display'+result_id
+
+ return NewGrapher
+
+
+
+# From here define new Grapher based on Analyzers
+
+aubiopitch = analyzer.AubioPitch()
+DisplayAubioPitch = DisplayAnalyzer.create(analyzer=aubiopitch,
+ result_id='aubio_pitch.pitch',
+ grapher_id='grapher_aubio_pitch',
+ grapher_name='Aubio Pitch')
+
+
+odf = analyzer.OnsetDetectionFunction()
+DisplayOnsetDetectionFunction = DisplayAnalyzer.create(analyzer=odf,
+ result_id='odf',
+ grapher_id='grapher_odf',
+ grapher_name='Onset detection function')
+wav = analyzer.Waveform()
+DisplayWaveform = DisplayAnalyzer.create(analyzer=wav,
+ result_id='waveform_analyzer',
+ grapher_id='grapher_waveform',
+ grapher_name='Waveform from Analyzer')