Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@52: This file copyright 2006 Chris Cannam. Chris@0: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: 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@0: Chris@16: #include Chris@16: 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 *instance(); Chris@0: Chris@56: // The name is intended to be computer-referenceable, and unique Chris@47: // within the application. The description is intended to be Chris@47: // human readable. In principle it doesn't have to be unique, but Chris@47: // the factory will add suffixes to ensure that it is, all the Chris@60: // same (just to avoid user confusion). The friendly name is a Chris@60: // shorter version of the description. Chris@0: Chris@0: struct TransformDesc { Chris@56: TransformDesc() { } Chris@60: TransformDesc(TransformName _name, QString _description, Chris@60: QString _friendlyName, QString _maker, Chris@60: bool _configurable) : Chris@60: name(_name), description(_description), friendlyName(_friendlyName), Chris@60: maker(_maker), configurable(_configurable) { } Chris@0: TransformName name; Chris@0: QString description; Chris@60: QString friendlyName; Chris@60: QString maker; Chris@56: bool configurable; Chris@0: }; Chris@0: typedef std::vector TransformList; Chris@0: Chris@0: TransformList getAllTransforms(); Chris@0: Chris@0: /** Chris@56: * Get a configuration XML string for the given transform (by Chris@56: * asking the user, most likely). Returns true if the transform Chris@56: * is acceptable, false if the operation should be cancelled. Chris@56: */ Chris@56: bool getConfigurationForTransform(TransformName name, Model *inputModel, Chris@56: QString &configurationXml); Chris@56: Chris@56: /** 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@56: Model *transform(TransformName name, Model *inputModel, Chris@56: QString configurationXml = ""); Chris@0: Chris@18: /** Chris@18: * Full description of a transform, suitable for putting on a menu. Chris@18: */ Chris@16: QString getTransformDescription(TransformName name); Chris@16: Chris@18: /** Chris@18: * Brief but friendly description of a transform, suitable for use Chris@18: * as the name of the output layer. Chris@18: */ Chris@18: QString getTransformFriendlyName(TransformName name); Chris@18: Chris@57: /** Chris@57: * Return true if the transform has any configurable parameters, Chris@57: * i.e. if getConfigurationForTransform can ever return a non-trivial Chris@57: * (not equivalent to empty) configuration string. Chris@57: */ Chris@57: bool isTransformConfigurable(TransformName name); Chris@57: 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@56: QString configurationXml, bool start); Chris@0: Chris@56: struct TransformIdent Chris@56: { Chris@56: TransformName name; Chris@56: QString configurationXml; Chris@56: }; Chris@56: Chris@56: typedef std::map TransformConfigurationMap; Chris@56: TransformConfigurationMap m_lastConfigurations; Chris@56: Chris@56: typedef std::map TransformDescriptionMap; Chris@56: TransformDescriptionMap m_transforms; Chris@56: Chris@16: void populateTransforms(); Chris@60: void populateFeatureExtractionPlugins(TransformDescriptionMap &); Chris@60: void populateRealTimePlugins(TransformDescriptionMap &); Chris@16: Chris@0: static TransformFactory *m_instance; Chris@0: }; Chris@0: Chris@0: Chris@0: #endif