comparison transform/TransformFactory.h @ 107:dd11619b73ba

* Update along with latest Vamp API change. This has not yet been tested.
author Chris Cannam
date Mon, 26 Feb 2007 18:13:07 +0000
parents f4f52566e451
children 58f21cf235c7
comparison
equal deleted inserted replaced
106:f8e362511b2f 107:dd11619b73ba
32 public: 32 public:
33 virtual ~TransformFactory(); 33 virtual ~TransformFactory();
34 34
35 static TransformFactory *getInstance(); 35 static TransformFactory *getInstance();
36 36
37 // The name is intended to be computer-referenceable, and unique 37 // The identifier is intended to be computer-referenceable, and
38 // within the application. The description is intended to be 38 // unique within the application. The name is intended to be
39 // human readable. In principle it doesn't have to be unique, but 39 // human readable. In principle it doesn't have to be unique, but
40 // the factory will add suffixes to ensure that it is, all the 40 // the factory will add suffixes to ensure that it is, all the
41 // same (just to avoid user confusion). The friendly name is a 41 // same (just to avoid user confusion). The friendly name is a
42 // shorter version of the description. The type is also intended 42 // shorter version of the name. The type is also intended to be
43 // to be user-readable, for use in menus. 43 // user-readable, for use in menus.
44 44
45 struct TransformDesc { 45 struct TransformDesc {
46 46
47 TransformDesc() { } 47 TransformDesc() { }
48 TransformDesc(QString _type, QString _category, 48 TransformDesc(QString _type, QString _category,
49 TransformName _name, QString _description, 49 TransformId _identifier, QString _name,
50 QString _friendlyName, QString _maker, 50 QString _friendlyName, QString _maker,
51 QString _units, bool _configurable) : 51 QString _units, bool _configurable) :
52 type(_type), category(_category), 52 type(_type), category(_category),
53 name(_name), description(_description), 53 identifier(_identifier), name(_name),
54 friendlyName(_friendlyName), 54 friendlyName(_friendlyName),
55 maker(_maker), units(_units), configurable(_configurable) { } 55 maker(_maker), units(_units), configurable(_configurable) { }
56 56
57 QString type; // e.g. feature extraction plugin 57 QString type; // e.g. feature extraction plugin
58 QString category; // e.g. time > onsets 58 QString category; // e.g. time > onsets
59 TransformName name; // e.g. vamp:vamp-aubio:aubioonset 59 TransformId identifier; // e.g. vamp:vamp-aubio:aubioonset
60 QString description; // plugin's desc if 1 output, else "desc: output" 60 QString name; // plugin's name if 1 output, else "name: output"
61 QString friendlyName; // short text for layer name 61 QString friendlyName; // short text for layer name
62 QString maker; 62 QString maker;
63 QString units; 63 QString units;
64 bool configurable; 64 bool configurable;
65 65
66 bool operator<(const TransformDesc &od) const { 66 bool operator<(const TransformDesc &od) const {
67 return (description < od.description); 67 return (name < od.name);
68 }; 68 };
69 }; 69 };
70 typedef std::vector<TransformDesc> TransformList; 70 typedef std::vector<TransformDesc> TransformList;
71 71
72 TransformList getAllTransforms(); 72 TransformList getAllTransforms();
81 * asking the user, most likely). Returns the selected input 81 * asking the user, most likely). Returns the selected input
82 * model if the transform is acceptable, 0 if the operation should 82 * model if the transform is acceptable, 0 if the operation should
83 * be cancelled. Audio callback play source may be used to 83 * be cancelled. Audio callback play source may be used to
84 * audition effects plugins, if provided. 84 * audition effects plugins, if provided.
85 */ 85 */
86 Model *getConfigurationForTransform(TransformName name, 86 Model *getConfigurationForTransform(TransformId identifier,
87 const std::vector<Model *> &candidateInputModels, 87 const std::vector<Model *> &candidateInputModels,
88 PluginTransform::ExecutionContext &context, 88 PluginTransform::ExecutionContext &context,
89 QString &configurationXml, 89 QString &configurationXml,
90 AudioCallbackPlaySource *source = 0); 90 AudioCallbackPlaySource *source = 0);
91 91
92 /** 92 /**
93 * Get the default execution context for the given transform 93 * Get the default execution context for the given transform
94 * and input model (if known). 94 * and input model (if known).
95 */ 95 */
96 PluginTransform::ExecutionContext getDefaultContextForTransform(TransformName name, 96 PluginTransform::ExecutionContext getDefaultContextForTransform(TransformId identifier,
97 Model *inputModel = 0); 97 Model *inputModel = 0);
98 98
99 /** 99 /**
100 * Return the output model resulting from applying the named 100 * Return the output model resulting from applying the named
101 * transform to the given input model. The transform may still be 101 * transform to the given input model. The transform may still be
107 * problem occurs, return 0. 107 * problem occurs, return 0.
108 * 108 *
109 * The returned model is owned by the caller and must be deleted 109 * The returned model is owned by the caller and must be deleted
110 * when no longer needed. 110 * when no longer needed.
111 */ 111 */
112 Model *transform(TransformName name, Model *inputModel, 112 Model *transform(TransformId identifier, Model *inputModel,
113 const PluginTransform::ExecutionContext &context, 113 const PluginTransform::ExecutionContext &context,
114 QString configurationXml = ""); 114 QString configurationXml = "");
115 115
116 /** 116 /**
117 * Full description of a transform, suitable for putting on a menu. 117 * Full name of a transform, suitable for putting on a menu.
118 */ 118 */
119 QString getTransformDescription(TransformName name); 119 QString getTransformName(TransformId identifier);
120 120
121 /** 121 /**
122 * Brief but friendly description of a transform, suitable for use 122 * Brief but friendly name of a transform, suitable for use
123 * as the name of the output layer. 123 * as the name of the output layer.
124 */ 124 */
125 QString getTransformFriendlyName(TransformName name); 125 QString getTransformFriendlyName(TransformId identifier);
126 126
127 QString getTransformUnits(TransformName name); 127 QString getTransformUnits(TransformId identifier);
128 128
129 /** 129 /**
130 * Return true if the transform has any configurable parameters, 130 * Return true if the transform has any configurable parameters,
131 * i.e. if getConfigurationForTransform can ever return a non-trivial 131 * i.e. if getConfigurationForTransform can ever return a non-trivial
132 * (not equivalent to empty) configuration string. 132 * (not equivalent to empty) configuration string.
133 */ 133 */
134 bool isTransformConfigurable(TransformName name); 134 bool isTransformConfigurable(TransformId identifier);
135 135
136 /** 136 /**
137 * If the transform has a prescribed number or range of channel 137 * If the transform has a prescribed number or range of channel
138 * inputs, return true and set minChannels and maxChannels to the 138 * inputs, return true and set minChannels and maxChannels to the
139 * minimum and maximum number of channel inputs the transform can 139 * minimum and maximum number of channel inputs the transform can
140 * accept. Return false if it doesn't care. 140 * accept. Return false if it doesn't care.
141 */ 141 */
142 bool getTransformChannelRange(TransformName name, 142 bool getTransformChannelRange(TransformId identifier,
143 int &minChannels, int &maxChannels); 143 int &minChannels, int &maxChannels);
144 144
145 //!!! Need some way to indicate that the input model has changed / 145 //!!! Need some way to indicate that the input model has changed /
146 //been deleted so as not to blow up backgrounded transform! -- Or 146 //been deleted so as not to blow up backgrounded transform! -- Or
147 //indeed, if the output model has been deleted -- could equally 147 //indeed, if the output model has been deleted -- could equally
151 151
152 protected slots: 152 protected slots:
153 void transformFinished(); 153 void transformFinished();
154 154
155 protected: 155 protected:
156 Transform *createTransform(TransformName name, Model *inputModel, 156 Transform *createTransform(TransformId identifier, Model *inputModel,
157 const PluginTransform::ExecutionContext &context, 157 const PluginTransform::ExecutionContext &context,
158 QString configurationXml, bool start); 158 QString configurationXml, bool start);
159 159
160 struct TransformIdent 160 struct TransformIdent
161 { 161 {
162 TransformName name; 162 TransformId identifier;
163 QString configurationXml; 163 QString configurationXml;
164 }; 164 };
165 165
166 typedef std::map<TransformName, QString> TransformConfigurationMap; 166 typedef std::map<TransformId, QString> TransformConfigurationMap;
167 TransformConfigurationMap m_lastConfigurations; 167 TransformConfigurationMap m_lastConfigurations;
168 168
169 typedef std::map<TransformName, TransformDesc> TransformDescriptionMap; 169 typedef std::map<TransformId, TransformDesc> TransformDescriptionMap;
170 TransformDescriptionMap m_transforms; 170 TransformDescriptionMap m_transforms;
171 171
172 void populateTransforms(); 172 void populateTransforms();
173 void populateFeatureExtractionPlugins(TransformDescriptionMap &); 173 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
174 void populateRealTimePlugins(TransformDescriptionMap &); 174 void populateRealTimePlugins(TransformDescriptionMap &);
175 175
176 bool getChannelRange(TransformName name, 176 bool getChannelRange(TransformId identifier,
177 Vamp::PluginBase *plugin, int &min, int &max); 177 Vamp::PluginBase *plugin, int &min, int &max);
178 178
179 static TransformFactory *m_instance; 179 static TransformFactory *m_instance;
180 }; 180 };
181 181