svcore  1.9
ModelTransformerFactory.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam and QMUL.
00008    
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _MODEL_TRANSFORMER_FACTORY_H_
00017 #define _MODEL_TRANSFORMER_FACTORY_H_
00018 
00019 #include "Transform.h"
00020 #include "TransformDescription.h"
00021 #include "FeatureExtractionModelTransformer.h"
00022 
00023 #include "ModelTransformer.h"
00024 
00025 #include <vamp-hostsdk/PluginBase.h>
00026 
00027 #include <QMap>
00028 #include <map>
00029 #include <set>
00030 #include <vector>
00031 
00032 class AudioPlaySource;
00033 
00034 class ModelTransformerFactory : public QObject
00035 {
00036     Q_OBJECT
00037 
00038 public:
00039     virtual ~ModelTransformerFactory();
00040 
00041     static ModelTransformerFactory *getInstance();
00042 
00043     class UserConfigurator {
00044     public:
00045         virtual bool configure(ModelTransformer::Input &input,
00046                                Transform &transform,
00047                                Vamp::PluginBase *plugin,
00048                                Model *&inputModel,
00049                                AudioPlaySource *source,
00050                                int startFrame,
00051                                int duration,
00052                                const QMap<QString, Model *> &modelMap,
00053                                QStringList candidateModelNames,
00054                                QString defaultModelName) = 0;
00055     };
00056 
00065     ModelTransformer::Input
00066     getConfigurationForTransform(Transform &transform,
00067                                  const std::vector<Model *> &candidateInputModels,
00068                                  Model *defaultInputModel,
00069                                  AudioPlaySource *source = 0,
00070                                  int startFrame = 0,
00071                                  int duration = 0,
00072                                  UserConfigurator *configurator = 0);
00073 
00074     class AdditionalModelHandler {
00075     public:
00076         virtual ~AdditionalModelHandler() { }
00077 
00078         // Exactly one of these functions will be called
00079         virtual void moreModelsAvailable(std::vector<Model *> models) = 0;
00080         virtual void noMoreModelsAvailable() = 0;
00081     };
00082     
00106     Model *transform(const Transform &transform,
00107                      const ModelTransformer::Input &input,
00108                      QString &message,
00109                      AdditionalModelHandler *handler = 0);
00110 
00143     std::vector<Model *> transformMultiple(const Transforms &transform,
00144                                            const ModelTransformer::Input &input,
00145                                            QString &message,
00146                                            AdditionalModelHandler *handler = 0);
00147 
00148 protected slots:
00149     void transformerFinished();
00150 
00151     void modelAboutToBeDeleted(Model *);
00152 
00153 protected:
00154     ModelTransformer *createTransformer(const Transforms &transforms,
00155                                         const ModelTransformer::Input &input);
00156 
00157     typedef std::map<TransformId, QString> TransformerConfigurationMap;
00158     TransformerConfigurationMap m_lastConfigurations;
00159 
00160     typedef std::set<ModelTransformer *> TransformerSet;
00161     TransformerSet m_runningTransformers;
00162 
00163     typedef std::map<ModelTransformer *, AdditionalModelHandler *> HandlerMap;
00164     HandlerMap m_handlers;
00165 
00166     static ModelTransformerFactory *m_instance;
00167 };
00168 
00169 
00170 #endif