Chris@330: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@330: Chris@330: /* Chris@330: Sonic Visualiser Chris@330: An audio file viewer and annotation editor. Chris@330: Centre for Digital Music, Queen Mary, University of London. Chris@330: This file copyright 2006-2007 Chris Cannam and QMUL. Chris@330: Chris@330: This program is free software; you can redistribute it and/or Chris@330: modify it under the terms of the GNU General Public License as Chris@330: published by the Free Software Foundation; either version 2 of the Chris@330: License, or (at your option) any later version. See the file Chris@330: COPYING included with this distribution for more information. Chris@330: */ Chris@330: Chris@330: #ifndef _TRANSFORM_FACTORY_H_ Chris@330: #define _TRANSFORM_FACTORY_H_ Chris@330: Chris@330: #include "TransformDescription.h" Chris@330: Chris@383: #include Chris@383: Chris@330: #include Chris@330: #include Chris@330: Chris@330: class TransformFactory : public QObject Chris@330: { Chris@330: Q_OBJECT Chris@330: Chris@330: public: Chris@330: virtual ~TransformFactory(); Chris@330: Chris@330: static TransformFactory *getInstance(); Chris@330: Chris@383: TransformList getAllTransformDescriptions(); Chris@383: TransformDescription getTransformDescription(TransformId id); Chris@330: Chris@330: std::vector getAllTransformTypes(); Chris@330: std::vector getTransformCategories(QString transformType); Chris@330: std::vector getTransformMakers(QString transformType); Chris@330: Chris@330: /** Chris@330: * Return true if the given transform is known. Chris@330: */ Chris@330: bool haveTransform(TransformId identifier); Chris@330: Chris@330: /** Chris@383: * A single transform ID can lead to many possible Transforms, Chris@383: * with different parameters and execution context settings. Chris@383: * Return the default one for the given transform. Chris@383: */ Chris@383: Transform getDefaultTransformFor(TransformId identifier, size_t rate = 0); Chris@383: Chris@383: /** Chris@330: * Full name of a transform, suitable for putting on a menu. Chris@330: */ Chris@330: QString getTransformName(TransformId identifier); Chris@330: Chris@330: /** Chris@330: * Brief but friendly name of a transform, suitable for use Chris@330: * as the name of the output layer. Chris@330: */ Chris@330: QString getTransformFriendlyName(TransformId identifier); Chris@330: Chris@330: QString getTransformUnits(TransformId identifier); Chris@330: Chris@383: Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier); Chris@383: Chris@330: /** Chris@330: * Return true if the transform has any configurable parameters, Chris@330: * i.e. if getConfigurationForTransform can ever return a non-trivial Chris@330: * (not equivalent to empty) configuration string. Chris@330: */ Chris@330: bool isTransformConfigurable(TransformId identifier); Chris@330: Chris@330: /** Chris@330: * If the transform has a prescribed number or range of channel Chris@330: * inputs, return true and set minChannels and maxChannels to the Chris@330: * minimum and maximum number of channel inputs the transform can Chris@330: * accept. Return false if it doesn't care. Chris@330: */ Chris@330: bool getTransformChannelRange(TransformId identifier, Chris@330: int &minChannels, int &maxChannels); Chris@332: Chris@332: /** Chris@383: * Load an appropriate plugin for the given transform and set the Chris@383: * parameters, program and configuration strings on that plugin Chris@383: * from the Transform object. Chris@383: * Chris@383: * Note that this requires that the transform has a meaningful Chris@383: * sample rate set, as that is used as the rate for the plugin. A Chris@383: * Transform can legitimately have rate set at zero (= "use the Chris@383: * rate of the input source"), so the caller will need to test for Chris@383: * this case. Chris@383: * Chris@383: * Returns the plugin thus loaded. This will be a Chris@383: * Vamp::PluginBase, but not necessarily a Vamp::Plugin (only if Chris@383: * the transform was a feature-extraction type -- call Chris@383: * downcastVampPlugin if you only want Vamp::Plugins). Returns Chris@383: * NULL if no suitable plugin was available. Chris@383: * Chris@383: * The returned plugin is owned by the caller, and should be Chris@383: * deleted (using "delete") when no longer needed. Chris@383: */ Chris@383: Vamp::PluginBase *instantiatePluginFor(const Transform &transform); Chris@383: Chris@383: /** Chris@383: * Convert a Vamp::PluginBase to a Vamp::Plugin, if it is one. Chris@383: * Return NULL otherwise. This ill-fitting convenience function Chris@383: * is really just a dynamic_cast wrapper. Chris@383: */ Chris@383: Vamp::Plugin *downcastVampPlugin(Vamp::PluginBase *); Chris@383: Chris@383: /** Chris@332: * Set the plugin parameters, program and configuration strings on Chris@332: * the given Transform object from the given plugin instance. Chris@332: * Note that no check is made whether the plugin is actually the Chris@332: * "correct" one for the transform. Chris@332: */ Chris@332: void setParametersFromPlugin(Transform &transform, Vamp::PluginBase *plugin); Chris@332: Chris@332: /** Chris@383: * Set the parameters, program and configuration strings on the Chris@383: * given plugin from the given Transform object. Chris@383: */ Chris@383: void setPluginParameters(const Transform &transform, Vamp::PluginBase *plugin); Chris@383: Chris@383: /** Chris@332: * If the given Transform object has no processing step and block Chris@332: * sizes set, set them to appropriate defaults for the given Chris@332: * plugin. Chris@332: */ Chris@332: void makeContextConsistentWithPlugin(Transform &transform, Vamp::PluginBase *plugin); Chris@332: Chris@332: /** Chris@383: * Retrieve a XML fragment that describes the Chris@383: * plugin parameters, program and configuration data for the given Chris@383: * transform. Chris@383: * Chris@383: * This function is provided for backward compatibility only. Use Chris@383: * Transform::toXml where compatibility with PluginXml Chris@383: * descriptions of transforms is not required. Chris@332: */ Chris@383: QString getPluginConfigurationXml(const Transform &transform); Chris@383: Chris@383: /** Chris@383: * Set the plugin parameters, program and configuration strings on Chris@383: * the given Transform object from the given XML Chris@383: * fragment. Chris@383: * Chris@383: * This function is provided for backward compatibility only. Use Chris@383: * Transform(QString) where compatibility with PluginXml Chris@383: * descriptions of transforms is not required. Chris@383: */ Chris@383: void setParametersFromPluginConfigurationXml(Transform &transform, Chris@383: QString xml); Chris@332: Chris@330: protected: Chris@330: typedef std::map TransformDescriptionMap; Chris@330: TransformDescriptionMap m_transforms; Chris@330: Chris@330: void populateTransforms(); Chris@330: void populateFeatureExtractionPlugins(TransformDescriptionMap &); Chris@330: void populateRealTimePlugins(TransformDescriptionMap &); Chris@330: Chris@383: Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, size_t rate); Chris@383: Chris@330: static TransformFactory *m_instance; Chris@330: }; Chris@330: Chris@330: Chris@330: #endif