From: Thomas Fillon Date: Sat, 25 Jan 2014 21:47:18 +0000 (+0000) Subject: Grapher : Make Analyzer rendering more generic and easy to implement X-Git-Tag: 0.5.3~10 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=d897cf07b043cb20a7723470a06718b84eff3be4;p=timeside.git Grapher : Make Analyzer rendering more generic and easy to implement --- diff --git a/timeside/analyzer/__init__.py b/timeside/analyzer/__init__.py index 4c293f1..29ee3cf 100644 --- a/timeside/analyzer/__init__.py +++ b/timeside/analyzer/__init__.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- -from level import * -from dc import * -from aubio_temporal import * -from aubio_pitch import * +from level import Level +from dc import MeanDCShift +from aubio_temporal import AubioTemporal +from aubio_pitch import AubioPitch from aubio_mfcc import * from aubio_melenergy import * from aubio_specdesc import * -from yaafe import * # TF : add Yaafe analyzer +from yaafe import * from spectrogram import Spectrogram from waveform import Waveform from vamp_plugin import VampSimpleHost diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index 1cbc41a..87a905c 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -24,7 +24,7 @@ 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 @@ -633,12 +633,13 @@ class AnalyzerResult(MetadataObject): 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 @@ -1065,7 +1066,7 @@ class Analyzer(Processor): # 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() diff --git a/timeside/grapher/__init__.py b/timeside/grapher/__init__.py index 4284bd4..fcc7b2c 100644 --- a/timeside/grapher/__init__.py +++ b/timeside/grapher/__init__.py @@ -6,4 +6,4 @@ from waveform_transparent import * from waveform_contour import * from spectrogram_log import * from spectrogram_lin import * -from render_analyzers import DisplayAubioPitch \ No newline at end of file +from render_analyzers import * \ No newline at end of file diff --git a/timeside/grapher/render_analyzers.py b/timeside/grapher/render_analyzers.py index c831e59..a43bee1 100644 --- a/timeside/grapher/render_analyzers.py +++ b/timeside/grapher/render_analyzers.py @@ -20,13 +20,17 @@ # along with TimeSide. If not, see . 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) @@ -35,9 +39,13 @@ class DisplayAnalyzers(Grapher): @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): @@ -45,7 +53,7 @@ class DisplayAnalyzers(Grapher): @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) @@ -57,28 +65,57 @@ class DisplayAnalyzers(Grapher): 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')