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@47: // same (just to avoid user confusion). Chris@0: Chris@0: struct TransformDesc { Chris@56: TransformDesc() { } Chris@56: TransformDesc(TransformName _name, QString _description, bool _configurable) : Chris@56: name(_name), description(_description), configurable(_configurable) { } Chris@0: TransformName name; Chris@0: QString description; 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@16: Chris@0: static TransformFactory *m_instance; Chris@0: }; Chris@0: Chris@0: Chris@0: #endif