Chris@320: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@320: Chris@320: /* Chris@320: Sonic Visualiser Chris@320: An audio file viewer and annotation editor. Chris@320: Centre for Digital Music, Queen Mary, University of London. Chris@320: This file copyright 2006 Chris Cannam and QMUL. Chris@320: Chris@320: This program is free software; you can redistribute it and/or Chris@320: modify it under the terms of the GNU General Public License as Chris@320: published by the Free Software Foundation; either version 2 of the Chris@320: License, or (at your option) any later version. See the file Chris@320: COPYING included with this distribution for more information. Chris@320: */ Chris@320: Chris@331: #ifndef _MODEL_TRANSFORMER_FACTORY_H_ Chris@331: #define _MODEL_TRANSFORMER_FACTORY_H_ Chris@320: Chris@331: #include "Transform.h" Chris@329: #include "TransformDescription.h" Chris@329: Chris@331: #include "ModelTransformer.h" Chris@331: Chris@328: #include "PluginTransformer.h" Chris@320: Chris@320: #include Chris@320: #include Chris@320: Chris@320: namespace Vamp { class PluginBase; } Chris@320: Chris@320: class AudioCallbackPlaySource; Chris@320: Chris@329: //!!! split into TransformFactory (information about available Chris@329: // transforms, create default Transform for each transform ID etc) and Chris@329: // TransformerFactory (create Transformers to apply transforms) Chris@329: Chris@331: class ModelTransformerFactory : public QObject Chris@320: { Chris@320: Q_OBJECT Chris@320: Chris@320: public: Chris@331: virtual ~ModelTransformerFactory(); Chris@320: Chris@331: static ModelTransformerFactory *getInstance(); Chris@320: Chris@329: TransformList getAllTransforms(); Chris@320: Chris@328: std::vector getAllTransformerTypes(); Chris@320: Chris@328: std::vector getTransformerCategories(QString transformType); Chris@328: std::vector getTransformerMakers(QString transformType); Chris@320: Chris@320: /** Chris@320: * Get a configuration XML string for the given transform (by Chris@320: * asking the user, most likely). Returns the selected input Chris@320: * model if the transform is acceptable, 0 if the operation should Chris@320: * be cancelled. Audio callback play source may be used to Chris@320: * audition effects plugins, if provided. Chris@320: */ Chris@329: Model *getConfigurationForTransformer(TransformId identifier, Chris@320: const std::vector &candidateInputModels, Chris@328: PluginTransformer::ExecutionContext &context, Chris@320: QString &configurationXml, Chris@320: AudioCallbackPlaySource *source = 0, Chris@320: size_t startFrame = 0, Chris@320: size_t duration = 0); Chris@320: Chris@320: /** Chris@320: * Get the default execution context for the given transform Chris@320: * and input model (if known). Chris@320: */ Chris@329: PluginTransformer::ExecutionContext getDefaultContextForTransformer(TransformId identifier, Chris@320: Model *inputModel = 0); Chris@320: Chris@320: /** Chris@320: * Return the output model resulting from applying the named Chris@320: * transform to the given input model. The transform may still be Chris@320: * working in the background when the model is returned; check the Chris@320: * output model's isReady completion status for more details. Chris@320: * Chris@320: * If the transform is unknown or the input model is not an Chris@320: * appropriate type for the given transform, or if some other Chris@320: * problem occurs, return 0. Chris@320: * Chris@320: * The returned model is owned by the caller and must be deleted Chris@320: * when no longer needed. Chris@320: */ Chris@329: Model *transform(TransformId identifier, Model *inputModel, Chris@328: const PluginTransformer::ExecutionContext &context, Chris@320: QString configurationXml = ""); Chris@320: Chris@320: /** Chris@326: * Return true if the given transform is known. Chris@326: */ Chris@329: bool haveTransformer(TransformId identifier); Chris@326: Chris@326: /** Chris@320: * Full name of a transform, suitable for putting on a menu. Chris@320: */ Chris@329: QString getTransformerName(TransformId identifier); Chris@320: Chris@320: /** Chris@320: * Brief but friendly name of a transform, suitable for use Chris@320: * as the name of the output layer. Chris@320: */ Chris@329: QString getTransformerFriendlyName(TransformId identifier); Chris@320: Chris@329: QString getTransformerUnits(TransformId identifier); Chris@320: Chris@320: /** Chris@320: * Return true if the transform has any configurable parameters, Chris@328: * i.e. if getConfigurationForTransformer can ever return a non-trivial Chris@320: * (not equivalent to empty) configuration string. Chris@320: */ Chris@329: bool isTransformerConfigurable(TransformId identifier); Chris@320: Chris@320: /** Chris@320: * If the transform has a prescribed number or range of channel Chris@320: * inputs, return true and set minChannels and maxChannels to the Chris@320: * minimum and maximum number of channel inputs the transform can Chris@320: * accept. Return false if it doesn't care. Chris@320: */ Chris@329: bool getTransformerChannelRange(TransformId identifier, Chris@320: int &minChannels, int &maxChannels); Chris@320: Chris@320: protected slots: Chris@331: void transformerFinished(); Chris@320: Chris@320: void modelAboutToBeDeleted(Model *); Chris@320: Chris@320: protected: Chris@331: ModelTransformer *createTransformer(TransformId identifier, Model *inputModel, Chris@331: const PluginTransformer::ExecutionContext &context, Chris@331: QString configurationXml); Chris@320: Chris@329: typedef std::map TransformerConfigurationMap; Chris@328: TransformerConfigurationMap m_lastConfigurations; Chris@320: Chris@329: typedef std::map TransformDescriptionMap; Chris@329: TransformDescriptionMap m_transforms; Chris@320: Chris@331: typedef std::set TransformerSet; Chris@328: TransformerSet m_runningTransformers; Chris@320: Chris@329: void populateTransforms(); Chris@329: void populateFeatureExtractionPlugins(TransformDescriptionMap &); Chris@329: void populateRealTimePlugins(TransformDescriptionMap &); Chris@320: Chris@329: bool getChannelRange(TransformId identifier, Chris@320: Vamp::PluginBase *plugin, int &min, int &max); Chris@320: Chris@331: static ModelTransformerFactory *m_instance; Chris@320: }; Chris@320: Chris@320: Chris@320: #endif