Chris@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: Sonic Visualiser Chris@0: An audio file viewer and annotation editor. Chris@0: Centre for Digital Music, Queen Mary, University of London. Chris@0: This file copyright 2006 Chris Cannam. Chris@0: Chris@0: This program is free software; you can redistribute it and/or Chris@0: modify it under the terms of the GNU General Public License as Chris@0: published by the Free Software Foundation; either version 2 of the Chris@0: License, or (at your option) any later version. See the file Chris@0: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@0: #ifndef _TRANSFORM_FACTORY_H_ Chris@0: #define _TRANSFORM_FACTORY_H_ Chris@0: Chris@0: #include "Transform.h" Chris@27: #include "PluginTransform.h" Chris@0: Chris@0: #include Chris@0: Chris@0: namespace Vamp { class PluginBase; } Chris@0: Chris@0: class TransformFactory : public QObject Chris@0: { Chris@0: Q_OBJECT Chris@0: Chris@0: public: Chris@0: virtual ~TransformFactory(); Chris@0: Chris@0: static TransformFactory *getInstance(); Chris@0: Chris@0: // The name is intended to be computer-referenceable, and unique Chris@0: // within the application. The description is intended to be Chris@0: // human readable. In principle it doesn't have to be unique, but Chris@0: // the factory will add suffixes to ensure that it is, all the Chris@0: // same (just to avoid user confusion). The friendly name is a Chris@0: // shorter version of the description. The type is also intended Chris@0: // to be user-readable, for use in menus. Chris@0: Chris@0: struct TransformDesc { Chris@34: Chris@0: TransformDesc() { } Chris@33: TransformDesc(QString _type, QString _category, Chris@33: TransformName _name, QString _description, Chris@0: QString _friendlyName, QString _maker, Chris@0: QString _units, bool _configurable) : Chris@33: type(_type), category(_category), Chris@33: name(_name), description(_description), Chris@0: friendlyName(_friendlyName), Chris@0: maker(_maker), units(_units), configurable(_configurable) { } Chris@34: Chris@0: QString type; Chris@33: QString category; Chris@0: TransformName name; Chris@0: QString description; Chris@0: QString friendlyName; Chris@0: QString maker; Chris@0: QString units; Chris@0: bool configurable; Chris@34: Chris@34: bool operator<(const TransformDesc &od) const { Chris@34: return (description < od.description); Chris@34: }; Chris@0: }; Chris@0: typedef std::vector TransformList; Chris@0: Chris@0: TransformList getAllTransforms(); Chris@0: Chris@0: std::vector getAllTransformTypes(); Chris@0: Chris@33: std::vector getTransformCategories(QString transformType); Chris@33: std::vector getTransformMakers(QString transformType); Chris@33: Chris@0: /** Chris@0: * Get a configuration XML string for the given transform (by Chris@0: * asking the user, most likely). Returns true if the transform Chris@0: * is acceptable, false if the operation should be cancelled. Chris@0: */ Chris@26: bool getConfigurationForTransform(TransformName name, Chris@26: Model *inputModel, Chris@27: PluginTransform::ExecutionContext &context, Chris@0: QString &configurationXml); Chris@0: Chris@0: /** Chris@0: * Return the output model resulting from applying the named Chris@0: * transform to the given input model. The transform may still be Chris@0: * working in the background when the model is returned; check the Chris@0: * output model's isReady completion status for more details. Chris@0: * Chris@0: * If the transform is unknown or the input model is not an Chris@0: * appropriate type for the given transform, or if some other Chris@0: * problem occurs, return 0. Chris@0: * Chris@0: * The returned model is owned by the caller and must be deleted Chris@0: * when no longer needed. Chris@0: */ Chris@0: Model *transform(TransformName name, Model *inputModel, Chris@27: const PluginTransform::ExecutionContext &context, Chris@27: QString configurationXml = ""); Chris@0: Chris@0: /** Chris@0: * Full description of a transform, suitable for putting on a menu. Chris@0: */ Chris@0: QString getTransformDescription(TransformName name); Chris@0: Chris@0: /** Chris@0: * Brief but friendly description of a transform, suitable for use Chris@0: * as the name of the output layer. Chris@0: */ Chris@0: QString getTransformFriendlyName(TransformName name); Chris@0: Chris@0: QString getTransformUnits(TransformName name); Chris@0: Chris@0: /** Chris@0: * Return true if the transform has any configurable parameters, Chris@0: * i.e. if getConfigurationForTransform can ever return a non-trivial Chris@0: * (not equivalent to empty) configuration string. Chris@0: */ Chris@0: bool isTransformConfigurable(TransformName name); Chris@0: Chris@0: /** Chris@0: * If the transform has a prescribed number or range of channel Chris@0: * inputs, return true and set minChannels and maxChannels to the Chris@0: * minimum and maximum number of channel inputs the transform can Chris@34: * accept. Return false if it doesn't care. Chris@0: */ Chris@0: bool getTransformChannelRange(TransformName name, Chris@0: int &minChannels, int &maxChannels); Chris@0: Chris@0: //!!! Need some way to indicate that the input model has changed / Chris@0: //been deleted so as not to blow up backgrounded transform! -- Or Chris@0: //indeed, if the output model has been deleted -- could equally Chris@0: //well happen! Chris@0: Chris@0: //!!! Need transform category! Chris@0: Chris@0: protected slots: Chris@0: void transformFinished(); Chris@0: Chris@0: protected: Chris@0: Transform *createTransform(TransformName name, Model *inputModel, Chris@27: const PluginTransform::ExecutionContext &context, Chris@27: QString configurationXml, bool start); Chris@0: Chris@0: struct TransformIdent Chris@0: { Chris@0: TransformName name; Chris@0: QString configurationXml; Chris@0: }; Chris@0: Chris@0: typedef std::map TransformConfigurationMap; Chris@0: TransformConfigurationMap m_lastConfigurations; Chris@0: Chris@0: typedef std::map TransformDescriptionMap; Chris@0: TransformDescriptionMap m_transforms; Chris@0: Chris@0: void populateTransforms(); Chris@0: void populateFeatureExtractionPlugins(TransformDescriptionMap &); Chris@0: void populateRealTimePlugins(TransformDescriptionMap &); Chris@0: Chris@0: bool getChannelRange(TransformName name, Chris@0: Vamp::PluginBase *plugin, int &min, int &max); Chris@0: Chris@0: static TransformFactory *m_instance; Chris@0: }; Chris@0: Chris@0: Chris@0: #endif