-import core
+from core import *
import decode
import encode
import analyze
# Author: Guillaume Pellerin <yomguy@parisson.com>
-from timeside.core import *
+from timeside.api import IProcessor
-class IAnalyzer(Interface):
+class IAnalyzer(IProcessor):
"""Media item analyzer driver interface"""
@staticmethod
import numpy
import scikits.audiolab as audiolab
-class AudioProcessor(Component):
+# FIXME: AudioProcessor: wrong name, should be Analyzer or AnalyzerCore
+class AudioProcessor(Processor):
def __init__(self):
self.fft_size = 2048
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2009 Olivier Guilyardi <olivier@samalyse.com>
+#
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
+
+from timeside.component import Interface
+
+class IProcessor(Interface):
+ pass
+
# You should have received a copy of the GNU General Public License
# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
+from timeside.component import *
+from timeside.api import IProcessor
-
-# This file defines an object interface mechanism and a way to determine
-# which components implements a given interface
-#
-# For example, the following defines the Music class as implementing the
-# listenable interface.
-#
-# class Listenable(Interface):
-# pass
-#
-# class Music(Component):
-# implements(Listenable)
-#
-# Several class can implements a such interface, and it is possible to
-# discover which class implements it with implementations():
-#
-# list_of_classes = implementations(Listenable)
-#
-# This mechanism support inheritance of interfaces: a class implementing a given
-# interface is also considered to implement all the ascendants of this interface.
-#
-# However, inheritance is not supported for components. The descendants of a class
-# implementing a given interface are not automatically considered to implement this
-# interface too.
-
-__all__ = ['Component', 'implements', 'Interface', 'implementations', 'TimeSideError']
+__all__ = ['Processor', 'Component', 'implements', 'processors', 'TimeSideError']
class TimeSideError(Exception):
"""Exception base class for errors in TimeSide."""
# FIXME: is this redundant with Django's error handling ?
- # FIXME: this class doesn't belong to the core
-
-class Interface(object):
- """Marker base class for interfaces."""
-
-def implements(*interfaces):
- _implements.extend(interfaces)
-
-def implementations(interface):
- result = []
- find_implementations(interface, result)
- return result
-_implementations = []
-_implements = []
-
-class ComponentMeta(type):
+_processors = []
+class MetaProcessor(MetaComponent):
+ """Metaclass of the Processor class, used mainly for ensuring uniqueness of
+ processor id's"""
def __new__(cls, name, bases, d):
- new_class = type.__new__(cls, name, bases, d)
- if _implements:
- for i in _implements:
- _implementations.append((i, new_class))
- del _implements[:]
+ new_class = MetaComponent.__new__(cls, name, bases, d)
+ id = "fixme"
+ _processors.append((id, new_class))
return new_class
-class Component(object):
- __metaclass__ = ComponentMeta
-
-def extend_unique(list1, list2):
- for item in list2:
- if item not in list1:
- list1.append(item)
-
-def find_implementations(interface, result):
- for i, cls in _implementations:
- if (i == interface):
- extend_unique(result, [cls])
-
- subinterfaces = interface.__subclasses__()
- if subinterfaces:
- for i in subinterfaces:
- find_implementations(i, result)
+class Processor(Component):
+ """Base component class of all processors"""
+ __metaclass__ = MetaProcessor
+def processors(interface=IProcessor, recurse=True):
+ """Returns the processors implementing a given interface and, if recurse,
+ any of the descendants of this interface."""
+ return implementations(interface, recurse)
+
# You should have received a copy of the GNU General Public License
# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
-from timeside.core import Interface, TimeSideError
+from timeside.api import IProcessor
+from timeside.core import TimeSideError
-class IDecoder(Interface):
+class IDecoder(IProcessor):
"""Decoder driver interface"""
@staticmethod
# You should have received a copy of the GNU General Public License
# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
-from timeside.core import Interface, TimeSideError
+from timeside.core import TimeSideError
+from timeside.api import IProcessor
-class IEncoder(Interface):
+class IEncoder(IProcessor):
"""Encoder driver interface"""
def __init__(self, output, nchannels, samplerate):
self.input = self.proc.stdin
self.output = self.proc.stdout
-
-class EncoderCore(Component):
+class EncoderCore(Processor):
"""Defines the main parts of the encoding tools :
paths, metadata parsing, data streaming thru system command"""
# Author: Guillaume Pellerin <yomguy@parisson.com>
# Author: Olivier Guilyardi <olivier@samalyse.com>
-from timeside.core import *
+from timeside.api import IProcessor
-class IGrapher(Interface):
+class IGrapher(IProcessor):
"""Media item visualizer driver interface"""
@staticmethod
from tempfile import NamedTemporaryFile
from timeside.graph.wav2png import *
-class SpectrogramGrapherAudiolab(Component):
+class SpectrogramGrapherAudiolab(Processor):
"""Spectrogram graph driver (python style thanks to wav2png.py and scikits.audiolab)"""
implements(IGrapher)
from tempfile import NamedTemporaryFile
from timeside.graph.wav2png import *
-class WaveFormGrapherAudiolab(Component):
+class WaveFormGrapherAudiolab(Processor):
"""WaveForm graph driver (python style thanks to wav2png.py and scikits.audiolab)"""
implements(IGrapher)
--- /dev/null
+import timeside
+
+def list_processors(interface, prefix=""):
+ print prefix + interface.__name__
+ subinterfaces = interface.__subclasses__()
+ for i in subinterfaces:
+ list_processors(i, prefix + " ")
+ processors = timeside.processors(interface, False)
+ for p in processors:
+ print prefix + " " + p.__name__
+
+list_processors(timeside.api.IProcessor)
class TestAnalyzers(Component):
- analyzers = implementations(timeside.analyze.IAnalyzer)
+ analyzers = processors(timeside.analyze.IAnalyzer)
def list(self):
analyzers = []
class TestDecoders(Component):
- decoders = implementations(timeside.decode.IDecoder)
+ decoders = processors(timeside.decode.IDecoder)
def list(self):
decoders_list = []
f.close()
class TestEncoders(Component):
- encoders = implementations(timeside.encode.IEncoder)
+ encoders = processors(timeside.encode.IEncoder)
def list(self):
encoders = []
class TestGraphers(Component):
- graphers = implementations(timeside.graph.IGrapher)
+ graphers = processors(timeside.graph.IGrapher)
def list(self):
graphers = []