annotate transform/TransformFactory.h @ 418:d35d4e79c95b

* Wait for input to be ready before running real-time effect -- even if it's a wave file model, because they are now progressively decoded
author Chris Cannam
date Wed, 11 Jun 2008 12:53:20 +0000
parents 370aa9714ef5
children 381ec750eeee
rev   line source
Chris@330 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@330 2
Chris@330 3 /*
Chris@330 4 Sonic Visualiser
Chris@330 5 An audio file viewer and annotation editor.
Chris@330 6 Centre for Digital Music, Queen Mary, University of London.
Chris@330 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@330 8
Chris@330 9 This program is free software; you can redistribute it and/or
Chris@330 10 modify it under the terms of the GNU General Public License as
Chris@330 11 published by the Free Software Foundation; either version 2 of the
Chris@330 12 License, or (at your option) any later version. See the file
Chris@330 13 COPYING included with this distribution for more information.
Chris@330 14 */
Chris@330 15
Chris@330 16 #ifndef _TRANSFORM_FACTORY_H_
Chris@330 17 #define _TRANSFORM_FACTORY_H_
Chris@330 18
Chris@330 19 #include "TransformDescription.h"
Chris@330 20
Chris@350 21 #include <vamp-sdk/Plugin.h>
Chris@350 22
Chris@387 23 #include <QObject>
Chris@387 24
Chris@330 25 #include <map>
Chris@330 26 #include <set>
Chris@330 27
Chris@330 28 class TransformFactory : public QObject
Chris@330 29 {
Chris@330 30 Q_OBJECT
Chris@330 31
Chris@330 32 public:
Chris@330 33 virtual ~TransformFactory();
Chris@330 34
Chris@330 35 static TransformFactory *getInstance();
Chris@330 36
Chris@350 37 TransformList getAllTransformDescriptions();
Chris@350 38 TransformDescription getTransformDescription(TransformId id);
Chris@330 39
Chris@330 40 std::vector<QString> getAllTransformTypes();
Chris@330 41 std::vector<QString> getTransformCategories(QString transformType);
Chris@330 42 std::vector<QString> getTransformMakers(QString transformType);
Chris@330 43
Chris@330 44 /**
Chris@330 45 * Return true if the given transform is known.
Chris@330 46 */
Chris@330 47 bool haveTransform(TransformId identifier);
Chris@330 48
Chris@330 49 /**
Chris@350 50 * A single transform ID can lead to many possible Transforms,
Chris@350 51 * with different parameters and execution context settings.
Chris@350 52 * Return the default one for the given transform.
Chris@350 53 */
Chris@350 54 Transform getDefaultTransformFor(TransformId identifier, size_t rate = 0);
Chris@350 55
Chris@350 56 /**
Chris@330 57 * Full name of a transform, suitable for putting on a menu.
Chris@330 58 */
Chris@330 59 QString getTransformName(TransformId identifier);
Chris@330 60
Chris@330 61 /**
Chris@330 62 * Brief but friendly name of a transform, suitable for use
Chris@330 63 * as the name of the output layer.
Chris@330 64 */
Chris@330 65 QString getTransformFriendlyName(TransformId identifier);
Chris@330 66
Chris@330 67 QString getTransformUnits(TransformId identifier);
Chris@330 68
Chris@350 69 Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier);
Chris@350 70
Chris@330 71 /**
Chris@330 72 * Return true if the transform has any configurable parameters,
Chris@330 73 * i.e. if getConfigurationForTransform can ever return a non-trivial
Chris@330 74 * (not equivalent to empty) configuration string.
Chris@330 75 */
Chris@330 76 bool isTransformConfigurable(TransformId identifier);
Chris@330 77
Chris@330 78 /**
Chris@330 79 * If the transform has a prescribed number or range of channel
Chris@330 80 * inputs, return true and set minChannels and maxChannels to the
Chris@330 81 * minimum and maximum number of channel inputs the transform can
Chris@330 82 * accept. Return false if it doesn't care.
Chris@330 83 */
Chris@330 84 bool getTransformChannelRange(TransformId identifier,
Chris@330 85 int &minChannels, int &maxChannels);
Chris@332 86
Chris@332 87 /**
Chris@351 88 * Load an appropriate plugin for the given transform and set the
Chris@351 89 * parameters, program and configuration strings on that plugin
Chris@351 90 * from the Transform object.
Chris@351 91 *
Chris@351 92 * Note that this requires that the transform has a meaningful
Chris@351 93 * sample rate set, as that is used as the rate for the plugin. A
Chris@351 94 * Transform can legitimately have rate set at zero (= "use the
Chris@351 95 * rate of the input source"), so the caller will need to test for
Chris@351 96 * this case.
Chris@351 97 *
Chris@351 98 * Returns the plugin thus loaded. This will be a
Chris@351 99 * Vamp::PluginBase, but not necessarily a Vamp::Plugin (only if
Chris@351 100 * the transform was a feature-extraction type -- call
Chris@351 101 * downcastVampPlugin if you only want Vamp::Plugins). Returns
Chris@351 102 * NULL if no suitable plugin was available.
Chris@352 103 *
Chris@352 104 * The returned plugin is owned by the caller, and should be
Chris@352 105 * deleted (using "delete") when no longer needed.
Chris@351 106 */
Chris@351 107 Vamp::PluginBase *instantiatePluginFor(const Transform &transform);
Chris@351 108
Chris@351 109 /**
Chris@351 110 * Convert a Vamp::PluginBase to a Vamp::Plugin, if it is one.
Chris@351 111 * Return NULL otherwise. This ill-fitting convenience function
Chris@351 112 * is really just a dynamic_cast wrapper.
Chris@351 113 */
Chris@351 114 Vamp::Plugin *downcastVampPlugin(Vamp::PluginBase *);
Chris@351 115
Chris@351 116 /**
Chris@332 117 * Set the plugin parameters, program and configuration strings on
Chris@332 118 * the given Transform object from the given plugin instance.
Chris@332 119 * Note that no check is made whether the plugin is actually the
Chris@332 120 * "correct" one for the transform.
Chris@332 121 */
Chris@332 122 void setParametersFromPlugin(Transform &transform, Vamp::PluginBase *plugin);
Chris@332 123
Chris@332 124 /**
Chris@350 125 * Set the parameters, program and configuration strings on the
Chris@350 126 * given plugin from the given Transform object.
Chris@350 127 */
Chris@350 128 void setPluginParameters(const Transform &transform, Vamp::PluginBase *plugin);
Chris@350 129
Chris@350 130 /**
Chris@332 131 * If the given Transform object has no processing step and block
Chris@332 132 * sizes set, set them to appropriate defaults for the given
Chris@332 133 * plugin.
Chris@332 134 */
Chris@332 135 void makeContextConsistentWithPlugin(Transform &transform, Vamp::PluginBase *plugin);
Chris@332 136
Chris@332 137 /**
Chris@350 138 * Retrieve a <plugin ... /> XML fragment that describes the
Chris@350 139 * plugin parameters, program and configuration data for the given
Chris@350 140 * transform.
Chris@350 141 *
Chris@350 142 * This function is provided for backward compatibility only. Use
Chris@350 143 * Transform::toXml where compatibility with PluginXml
Chris@350 144 * descriptions of transforms is not required.
Chris@332 145 */
Chris@350 146 QString getPluginConfigurationXml(const Transform &transform);
Chris@350 147
Chris@350 148 /**
Chris@350 149 * Set the plugin parameters, program and configuration strings on
Chris@350 150 * the given Transform object from the given <plugin ... /> XML
Chris@350 151 * fragment.
Chris@350 152 *
Chris@350 153 * This function is provided for backward compatibility only. Use
Chris@350 154 * Transform(QString) where compatibility with PluginXml
Chris@350 155 * descriptions of transforms is not required.
Chris@350 156 */
Chris@350 157 void setParametersFromPluginConfigurationXml(Transform &transform,
Chris@350 158 QString xml);
Chris@332 159
Chris@330 160 protected:
Chris@330 161 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;
Chris@330 162 TransformDescriptionMap m_transforms;
Chris@330 163
Chris@330 164 void populateTransforms();
Chris@330 165 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
Chris@330 166 void populateRealTimePlugins(TransformDescriptionMap &);
Chris@330 167
Chris@351 168 Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, size_t rate);
Chris@350 169
Chris@330 170 static TransformFactory *m_instance;
Chris@330 171 };
Chris@330 172
Chris@330 173
Chris@330 174 #endif