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@350: #include Chris@350: Chris@387: #include Chris@443: #include Chris@387: 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@350: TransformList getAllTransformDescriptions(); Chris@350: 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@443: struct Match Chris@443: { Chris@443: TransformId transform; Chris@443: int score; Chris@444: typedef std::map FragmentMap; Chris@444: FragmentMap fragments; Chris@443: Chris@443: Match() : score(0) { } Chris@444: Match(const Match &m) : Chris@444: transform(m.transform), score(m.score), fragments(m.fragments) { } Chris@443: Chris@444: bool operator<(const Match &m) const; Chris@443: }; Chris@443: Chris@443: typedef std::map SearchResults; Chris@443: SearchResults search(QString keyword); Chris@443: SearchResults search(QStringList keywords); Chris@443: 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@350: * A single transform ID can lead to many possible Transforms, Chris@350: * with different parameters and execution context settings. Chris@350: * Return the default one for the given transform. Chris@350: */ Chris@350: Transform getDefaultTransformFor(TransformId identifier, size_t rate = 0); Chris@350: Chris@350: /** 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@350: Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier); Chris@350: 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@351: * Load an appropriate plugin for the given transform and set the Chris@351: * parameters, program and configuration strings on that plugin Chris@351: * from the Transform object. Chris@351: * Chris@351: * Note that this requires that the transform has a meaningful Chris@351: * sample rate set, as that is used as the rate for the plugin. A Chris@351: * Transform can legitimately have rate set at zero (= "use the Chris@351: * rate of the input source"), so the caller will need to test for Chris@351: * this case. Chris@351: * Chris@351: * Returns the plugin thus loaded. This will be a Chris@351: * Vamp::PluginBase, but not necessarily a Vamp::Plugin (only if Chris@351: * the transform was a feature-extraction type -- call Chris@351: * downcastVampPlugin if you only want Vamp::Plugins). Returns Chris@351: * NULL if no suitable plugin was available. Chris@352: * Chris@352: * The returned plugin is owned by the caller, and should be Chris@352: * deleted (using "delete") when no longer needed. Chris@351: */ Chris@351: Vamp::PluginBase *instantiatePluginFor(const Transform &transform); Chris@351: Chris@351: /** Chris@351: * Convert a Vamp::PluginBase to a Vamp::Plugin, if it is one. Chris@351: * Return NULL otherwise. This ill-fitting convenience function Chris@351: * is really just a dynamic_cast wrapper. Chris@351: */ Chris@351: Vamp::Plugin *downcastVampPlugin(Vamp::PluginBase *); Chris@351: Chris@351: /** 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@350: * Set the parameters, program and configuration strings on the Chris@350: * given plugin from the given Transform object. Chris@350: */ Chris@350: void setPluginParameters(const Transform &transform, Vamp::PluginBase *plugin); Chris@350: Chris@350: /** 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@350: * Retrieve a XML fragment that describes the Chris@350: * plugin parameters, program and configuration data for the given Chris@350: * transform. Chris@350: * Chris@350: * This function is provided for backward compatibility only. Use Chris@350: * Transform::toXml where compatibility with PluginXml Chris@350: * descriptions of transforms is not required. Chris@332: */ Chris@350: QString getPluginConfigurationXml(const Transform &transform); Chris@350: Chris@350: /** Chris@350: * Set the plugin parameters, program and configuration strings on Chris@350: * the given Transform object from the given XML Chris@350: * fragment. Chris@350: * Chris@350: * This function is provided for backward compatibility only. Use Chris@350: * Transform(QString) where compatibility with PluginXml Chris@350: * descriptions of transforms is not required. Chris@350: */ Chris@350: void setParametersFromPluginConfigurationXml(Transform &transform, Chris@350: 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@443: void searchTest(Match &match, QStringList keywords, QString text, Chris@443: QString textType, int score); Chris@443: Chris@351: Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, size_t rate); Chris@350: Chris@330: static TransformFactory *m_instance; Chris@330: }; Chris@330: Chris@330: Chris@330: #endif