Mercurial > hg > svcore
comparison plugin/transform/TransformFactory.h @ 383:94fc0591ea43 1.2-stable
* merge from trunk (1.2 ended up being tracked from trunk, but we may want
this branch for fixes later)
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 10:32:45 +0000 |
parents | 13e5870040e6 |
children |
comparison
equal
deleted
inserted
replaced
349:f39d33b0b265 | 383:94fc0591ea43 |
---|---|
16 #ifndef _TRANSFORM_FACTORY_H_ | 16 #ifndef _TRANSFORM_FACTORY_H_ |
17 #define _TRANSFORM_FACTORY_H_ | 17 #define _TRANSFORM_FACTORY_H_ |
18 | 18 |
19 #include "TransformDescription.h" | 19 #include "TransformDescription.h" |
20 | 20 |
21 #include <vamp-sdk/Plugin.h> | |
22 | |
21 #include <map> | 23 #include <map> |
22 #include <set> | 24 #include <set> |
23 | |
24 namespace Vamp { class PluginBase; } | |
25 | 25 |
26 class TransformFactory : public QObject | 26 class TransformFactory : public QObject |
27 { | 27 { |
28 Q_OBJECT | 28 Q_OBJECT |
29 | 29 |
30 public: | 30 public: |
31 virtual ~TransformFactory(); | 31 virtual ~TransformFactory(); |
32 | 32 |
33 static TransformFactory *getInstance(); | 33 static TransformFactory *getInstance(); |
34 | 34 |
35 TransformList getAllTransforms(); | 35 TransformList getAllTransformDescriptions(); |
36 TransformDescription getTransformDescription(TransformId id); | |
36 | 37 |
37 std::vector<QString> getAllTransformTypes(); | 38 std::vector<QString> getAllTransformTypes(); |
38 | |
39 std::vector<QString> getTransformCategories(QString transformType); | 39 std::vector<QString> getTransformCategories(QString transformType); |
40 std::vector<QString> getTransformMakers(QString transformType); | 40 std::vector<QString> getTransformMakers(QString transformType); |
41 | 41 |
42 /** | 42 /** |
43 * Return true if the given transform is known. | 43 * Return true if the given transform is known. |
44 */ | 44 */ |
45 bool haveTransform(TransformId identifier); | 45 bool haveTransform(TransformId identifier); |
46 | |
47 /** | |
48 * A single transform ID can lead to many possible Transforms, | |
49 * with different parameters and execution context settings. | |
50 * Return the default one for the given transform. | |
51 */ | |
52 Transform getDefaultTransformFor(TransformId identifier, size_t rate = 0); | |
46 | 53 |
47 /** | 54 /** |
48 * Full name of a transform, suitable for putting on a menu. | 55 * Full name of a transform, suitable for putting on a menu. |
49 */ | 56 */ |
50 QString getTransformName(TransformId identifier); | 57 QString getTransformName(TransformId identifier); |
54 * as the name of the output layer. | 61 * as the name of the output layer. |
55 */ | 62 */ |
56 QString getTransformFriendlyName(TransformId identifier); | 63 QString getTransformFriendlyName(TransformId identifier); |
57 | 64 |
58 QString getTransformUnits(TransformId identifier); | 65 QString getTransformUnits(TransformId identifier); |
66 | |
67 Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier); | |
59 | 68 |
60 /** | 69 /** |
61 * Return true if the transform has any configurable parameters, | 70 * Return true if the transform has any configurable parameters, |
62 * i.e. if getConfigurationForTransform can ever return a non-trivial | 71 * i.e. if getConfigurationForTransform can ever return a non-trivial |
63 * (not equivalent to empty) configuration string. | 72 * (not equivalent to empty) configuration string. |
72 */ | 81 */ |
73 bool getTransformChannelRange(TransformId identifier, | 82 bool getTransformChannelRange(TransformId identifier, |
74 int &minChannels, int &maxChannels); | 83 int &minChannels, int &maxChannels); |
75 | 84 |
76 /** | 85 /** |
86 * Load an appropriate plugin for the given transform and set the | |
87 * parameters, program and configuration strings on that plugin | |
88 * from the Transform object. | |
89 * | |
90 * Note that this requires that the transform has a meaningful | |
91 * sample rate set, as that is used as the rate for the plugin. A | |
92 * Transform can legitimately have rate set at zero (= "use the | |
93 * rate of the input source"), so the caller will need to test for | |
94 * this case. | |
95 * | |
96 * Returns the plugin thus loaded. This will be a | |
97 * Vamp::PluginBase, but not necessarily a Vamp::Plugin (only if | |
98 * the transform was a feature-extraction type -- call | |
99 * downcastVampPlugin if you only want Vamp::Plugins). Returns | |
100 * NULL if no suitable plugin was available. | |
101 * | |
102 * The returned plugin is owned by the caller, and should be | |
103 * deleted (using "delete") when no longer needed. | |
104 */ | |
105 Vamp::PluginBase *instantiatePluginFor(const Transform &transform); | |
106 | |
107 /** | |
108 * Convert a Vamp::PluginBase to a Vamp::Plugin, if it is one. | |
109 * Return NULL otherwise. This ill-fitting convenience function | |
110 * is really just a dynamic_cast wrapper. | |
111 */ | |
112 Vamp::Plugin *downcastVampPlugin(Vamp::PluginBase *); | |
113 | |
114 /** | |
77 * Set the plugin parameters, program and configuration strings on | 115 * Set the plugin parameters, program and configuration strings on |
78 * the given Transform object from the given plugin instance. | 116 * the given Transform object from the given plugin instance. |
79 * Note that no check is made whether the plugin is actually the | 117 * Note that no check is made whether the plugin is actually the |
80 * "correct" one for the transform. | 118 * "correct" one for the transform. |
81 */ | 119 */ |
82 void setParametersFromPlugin(Transform &transform, Vamp::PluginBase *plugin); | 120 void setParametersFromPlugin(Transform &transform, Vamp::PluginBase *plugin); |
83 | 121 |
84 /** | 122 /** |
123 * Set the parameters, program and configuration strings on the | |
124 * given plugin from the given Transform object. | |
125 */ | |
126 void setPluginParameters(const Transform &transform, Vamp::PluginBase *plugin); | |
127 | |
128 /** | |
85 * If the given Transform object has no processing step and block | 129 * If the given Transform object has no processing step and block |
86 * sizes set, set them to appropriate defaults for the given | 130 * sizes set, set them to appropriate defaults for the given |
87 * plugin. | 131 * plugin. |
88 */ | 132 */ |
89 void makeContextConsistentWithPlugin(Transform &transform, Vamp::PluginBase *plugin); | 133 void makeContextConsistentWithPlugin(Transform &transform, Vamp::PluginBase *plugin); |
90 | 134 |
91 /** | 135 /** |
92 * A single transform ID can lead to many possible Transforms, | 136 * Retrieve a <plugin ... /> XML fragment that describes the |
93 * with different parameters and execution context settings. | 137 * plugin parameters, program and configuration data for the given |
94 * Return the default one for the given transform. | 138 * transform. |
139 * | |
140 * This function is provided for backward compatibility only. Use | |
141 * Transform::toXml where compatibility with PluginXml | |
142 * descriptions of transforms is not required. | |
95 */ | 143 */ |
96 Transform getDefaultTransformFor(TransformId identifier, size_t rate = 0); | 144 QString getPluginConfigurationXml(const Transform &transform); |
145 | |
146 /** | |
147 * Set the plugin parameters, program and configuration strings on | |
148 * the given Transform object from the given <plugin ... /> XML | |
149 * fragment. | |
150 * | |
151 * This function is provided for backward compatibility only. Use | |
152 * Transform(QString) where compatibility with PluginXml | |
153 * descriptions of transforms is not required. | |
154 */ | |
155 void setParametersFromPluginConfigurationXml(Transform &transform, | |
156 QString xml); | |
97 | 157 |
98 protected: | 158 protected: |
99 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap; | 159 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap; |
100 TransformDescriptionMap m_transforms; | 160 TransformDescriptionMap m_transforms; |
101 | 161 |
102 void populateTransforms(); | 162 void populateTransforms(); |
103 void populateFeatureExtractionPlugins(TransformDescriptionMap &); | 163 void populateFeatureExtractionPlugins(TransformDescriptionMap &); |
104 void populateRealTimePlugins(TransformDescriptionMap &); | 164 void populateRealTimePlugins(TransformDescriptionMap &); |
105 | 165 |
166 Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, size_t rate); | |
167 | |
106 static TransformFactory *m_instance; | 168 static TransformFactory *m_instance; |
107 }; | 169 }; |
108 | 170 |
109 | 171 |
110 #endif | 172 #endif |