From e5b35717efc348add11335d0e858845571d78054 Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Wed, 21 May 2014 18:17:47 +0200 Subject: [PATCH] Implement Parameters by subclassing Processor --- timeside/analyzer/spectrogram.py | 7 +++++++ timeside/component.py | 5 ++++- timeside/core.py | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/timeside/analyzer/spectrogram.py b/timeside/analyzer/spectrogram.py index d30c2e8..01fa6a8 100644 --- a/timeside/analyzer/spectrogram.py +++ b/timeside/analyzer/spectrogram.py @@ -23,6 +23,9 @@ from timeside.core import implements, interfacedoc from timeside.analyzer.core import Analyzer from timeside.api import IAnalyzer from timeside.analyzer.preprocessors import downmix_to_mono, frames_adapter +from ..tools.parameters import Unicode, Int, HasTraits + + import numpy as np @@ -31,6 +34,10 @@ class Spectrogram(Analyzer): """Spectrogram analyzer""" implements(IAnalyzer) + # Define Parameters + class _Param(HasTraits): + FFT_SIZE = Int() + def __init__(self, blocksize=2048, stepsize=None, fft_size=None): super(Spectrogram, self).__init__() diff --git a/timeside/component.py b/timeside/component.py index a92ae16..dfbb43d 100644 --- a/timeside/component.py +++ b/timeside/component.py @@ -92,7 +92,7 @@ class MetaComponent(type): abstract = False def __new__(cls, name, bases, d): - new_class = type.__new__(cls, name, bases, d) + new_class = super(MetaComponent, cls).__new__(cls, name, bases, d) # Register implementations if MetaComponent.implements: @@ -129,6 +129,9 @@ class Component(object): """Base class of all components""" __metaclass__ = MetaComponent + def __init__(self): + super(Component, self).__init__() + def extend_unique(list1, list2): """Extend list1 with list2 as list.extend(), but doesn't append duplicates diff --git a/timeside/core.py b/timeside/core.py index d821225..2203450 100644 --- a/timeside/core.py +++ b/timeside/core.py @@ -22,6 +22,7 @@ from .component import Component, MetaComponent, abstract from .component import implements, implementations, interfacedoc from .api import IProcessor from .exceptions import Error, PIDError, ApiError +from .tools.parameters import HasParam import re import numpy @@ -44,7 +45,7 @@ class MetaProcessor(MetaComponent): valid_id = re.compile("^[a-z][_a-z0-9]*$") def __new__(cls, name, bases, d): - new_class = MetaComponent.__new__(cls, name, bases, d) + new_class = super(MetaProcessor, cls).__new__(cls, name, bases, d) if new_class in implementations(IProcessor): id = str(new_class.id()) if id in _processors: @@ -67,7 +68,7 @@ class MetaProcessor(MetaComponent): return new_class -class Processor(Component): +class Processor(Component, HasParam): """Base component class of all processors -- 2.39.5