comparison plugin/transform/TransformerFactory.h @ 329:3179d8b29336

* Another incremental Transform update
author Chris Cannam
date Tue, 06 Nov 2007 17:08:11 +0000
parents 21bd032ae791
children
comparison
equal deleted inserted replaced
328:21bd032ae791 329:3179d8b29336
14 */ 14 */
15 15
16 #ifndef _TRANSFORMER_FACTORY_H_ 16 #ifndef _TRANSFORMER_FACTORY_H_
17 #define _TRANSFORMER_FACTORY_H_ 17 #define _TRANSFORMER_FACTORY_H_
18 18
19 #include "TransformDescription.h"
20
19 #include "Transformer.h" 21 #include "Transformer.h"
20 #include "PluginTransformer.h" 22 #include "PluginTransformer.h"
21 23
22 #include <map> 24 #include <map>
23 #include <set> 25 #include <set>
24 26
25 namespace Vamp { class PluginBase; } 27 namespace Vamp { class PluginBase; }
26 28
27 class AudioCallbackPlaySource; 29 class AudioCallbackPlaySource;
28 30
31 //!!! split into TransformFactory (information about available
32 // transforms, create default Transform for each transform ID etc) and
33 // TransformerFactory (create Transformers to apply transforms)
34
29 class TransformerFactory : public QObject 35 class TransformerFactory : public QObject
30 { 36 {
31 Q_OBJECT 37 Q_OBJECT
32 38
33 public: 39 public:
34 virtual ~TransformerFactory(); 40 virtual ~TransformerFactory();
35 41
36 static TransformerFactory *getInstance(); 42 static TransformerFactory *getInstance();
37 43
38 // The identifier is intended to be computer-referenceable, and 44 TransformList getAllTransforms();
39 // unique within the application. The name is intended to be
40 // human readable. In principle it doesn't have to be unique, but
41 // the factory will add suffixes to ensure that it is, all the
42 // same (just to avoid user confusion). The friendly name is a
43 // shorter version of the name. The type is also intended to be
44 // user-readable, for use in menus.
45
46 struct TransformerDesc {
47
48 TransformerDesc() { }
49 TransformerDesc(QString _type, QString _category,
50 TransformerId _identifier, QString _name,
51 QString _friendlyName, QString _description,
52 QString _maker, QString _units, bool _configurable) :
53 type(_type), category(_category),
54 identifier(_identifier), name(_name),
55 friendlyName(_friendlyName), description(_description),
56 maker(_maker), units(_units), configurable(_configurable) { }
57
58 QString type; // e.g. feature extraction plugin
59 QString category; // e.g. time > onsets
60 TransformerId identifier; // e.g. vamp:vamp-aubio:aubioonset
61 QString name; // plugin's name if 1 output, else "name: output"
62 QString friendlyName; // short text for layer name
63 QString description; // sentence describing transform
64 QString maker;
65 QString units;
66 bool configurable;
67
68 bool operator<(const TransformerDesc &od) const {
69 return (name < od.name);
70 };
71 };
72 typedef std::vector<TransformerDesc> TransformerList;
73
74 TransformerList getAllTransformers();
75 45
76 std::vector<QString> getAllTransformerTypes(); 46 std::vector<QString> getAllTransformerTypes();
77 47
78 std::vector<QString> getTransformerCategories(QString transformType); 48 std::vector<QString> getTransformerCategories(QString transformType);
79 std::vector<QString> getTransformerMakers(QString transformType); 49 std::vector<QString> getTransformerMakers(QString transformType);
83 * asking the user, most likely). Returns the selected input 53 * asking the user, most likely). Returns the selected input
84 * model if the transform is acceptable, 0 if the operation should 54 * model if the transform is acceptable, 0 if the operation should
85 * be cancelled. Audio callback play source may be used to 55 * be cancelled. Audio callback play source may be used to
86 * audition effects plugins, if provided. 56 * audition effects plugins, if provided.
87 */ 57 */
88 Model *getConfigurationForTransformer(TransformerId identifier, 58 Model *getConfigurationForTransformer(TransformId identifier,
89 const std::vector<Model *> &candidateInputModels, 59 const std::vector<Model *> &candidateInputModels,
90 PluginTransformer::ExecutionContext &context, 60 PluginTransformer::ExecutionContext &context,
91 QString &configurationXml, 61 QString &configurationXml,
92 AudioCallbackPlaySource *source = 0, 62 AudioCallbackPlaySource *source = 0,
93 size_t startFrame = 0, 63 size_t startFrame = 0,
95 65
96 /** 66 /**
97 * Get the default execution context for the given transform 67 * Get the default execution context for the given transform
98 * and input model (if known). 68 * and input model (if known).
99 */ 69 */
100 PluginTransformer::ExecutionContext getDefaultContextForTransformer(TransformerId identifier, 70 PluginTransformer::ExecutionContext getDefaultContextForTransformer(TransformId identifier,
101 Model *inputModel = 0); 71 Model *inputModel = 0);
102 72
103 /** 73 /**
104 * Return the output model resulting from applying the named 74 * Return the output model resulting from applying the named
105 * transform to the given input model. The transform may still be 75 * transform to the given input model. The transform may still be
111 * problem occurs, return 0. 81 * problem occurs, return 0.
112 * 82 *
113 * The returned model is owned by the caller and must be deleted 83 * The returned model is owned by the caller and must be deleted
114 * when no longer needed. 84 * when no longer needed.
115 */ 85 */
116 Model *transform(TransformerId identifier, Model *inputModel, 86 Model *transform(TransformId identifier, Model *inputModel,
117 const PluginTransformer::ExecutionContext &context, 87 const PluginTransformer::ExecutionContext &context,
118 QString configurationXml = ""); 88 QString configurationXml = "");
119 89
120 /** 90 /**
121 * Return true if the given transform is known. 91 * Return true if the given transform is known.
122 */ 92 */
123 bool haveTransformer(TransformerId identifier); 93 bool haveTransformer(TransformId identifier);
124 94
125 /** 95 /**
126 * Full name of a transform, suitable for putting on a menu. 96 * Full name of a transform, suitable for putting on a menu.
127 */ 97 */
128 QString getTransformerName(TransformerId identifier); 98 QString getTransformerName(TransformId identifier);
129 99
130 /** 100 /**
131 * Brief but friendly name of a transform, suitable for use 101 * Brief but friendly name of a transform, suitable for use
132 * as the name of the output layer. 102 * as the name of the output layer.
133 */ 103 */
134 QString getTransformerFriendlyName(TransformerId identifier); 104 QString getTransformerFriendlyName(TransformId identifier);
135 105
136 QString getTransformerUnits(TransformerId identifier); 106 QString getTransformerUnits(TransformId identifier);
137 107
138 /** 108 /**
139 * Return true if the transform has any configurable parameters, 109 * Return true if the transform has any configurable parameters,
140 * i.e. if getConfigurationForTransformer can ever return a non-trivial 110 * i.e. if getConfigurationForTransformer can ever return a non-trivial
141 * (not equivalent to empty) configuration string. 111 * (not equivalent to empty) configuration string.
142 */ 112 */
143 bool isTransformerConfigurable(TransformerId identifier); 113 bool isTransformerConfigurable(TransformId identifier);
144 114
145 /** 115 /**
146 * If the transform has a prescribed number or range of channel 116 * If the transform has a prescribed number or range of channel
147 * inputs, return true and set minChannels and maxChannels to the 117 * inputs, return true and set minChannels and maxChannels to the
148 * minimum and maximum number of channel inputs the transform can 118 * minimum and maximum number of channel inputs the transform can
149 * accept. Return false if it doesn't care. 119 * accept. Return false if it doesn't care.
150 */ 120 */
151 bool getTransformerChannelRange(TransformerId identifier, 121 bool getTransformerChannelRange(TransformId identifier,
152 int &minChannels, int &maxChannels); 122 int &minChannels, int &maxChannels);
153 123
154 protected slots: 124 protected slots:
155 void transformFinished(); 125 void transformFinished();
156 126
157 void modelAboutToBeDeleted(Model *); 127 void modelAboutToBeDeleted(Model *);
158 128
159 protected: 129 protected:
160 Transformer *createTransformer(TransformerId identifier, Model *inputModel, 130 Transformer *createTransformer(TransformId identifier, Model *inputModel,
161 const PluginTransformer::ExecutionContext &context, 131 const PluginTransformer::ExecutionContext &context,
162 QString configurationXml); 132 QString configurationXml);
163 133
164 struct TransformerIdent 134 struct TransformIdent
165 { 135 {
166 TransformerId identifier; 136 TransformId identifier;
167 QString configurationXml; 137 QString configurationXml;
168 }; 138 };
169 139
170 typedef std::map<TransformerId, QString> TransformerConfigurationMap; 140 typedef std::map<TransformId, QString> TransformerConfigurationMap;
171 TransformerConfigurationMap m_lastConfigurations; 141 TransformerConfigurationMap m_lastConfigurations;
172 142
173 typedef std::map<TransformerId, TransformerDesc> TransformerDescriptionMap; 143 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;
174 TransformerDescriptionMap m_transforms; 144 TransformDescriptionMap m_transforms;
175 145
176 typedef std::set<Transformer *> TransformerSet; 146 typedef std::set<Transformer *> TransformerSet;
177 TransformerSet m_runningTransformers; 147 TransformerSet m_runningTransformers;
178 148
179 void populateTransformers(); 149 void populateTransforms();
180 void populateFeatureExtractionPlugins(TransformerDescriptionMap &); 150 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
181 void populateRealTimePlugins(TransformerDescriptionMap &); 151 void populateRealTimePlugins(TransformDescriptionMap &);
182 152
183 bool getChannelRange(TransformerId identifier, 153 bool getChannelRange(TransformId identifier,
184 Vamp::PluginBase *plugin, int &min, int &max); 154 Vamp::PluginBase *plugin, int &min, int &max);
185 155
186 static TransformerFactory *m_instance; 156 static TransformerFactory *m_instance;
187 }; 157 };
188 158