Mercurial > hg > easaier-soundaccess
comparison sv/transform/TransformFactory.h @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam and QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _TRANSFORM_FACTORY_H_ | |
17 #define _TRANSFORM_FACTORY_H_ | |
18 | |
19 #include "Transform.h" | |
20 #include "PluginTransform.h" | |
21 | |
22 #include <map> | |
23 #include <set> | |
24 | |
25 namespace Vamp { class PluginBase; } | |
26 | |
27 class AudioCallbackPlaySource; | |
28 | |
29 class TransformFactory : public QObject | |
30 { | |
31 Q_OBJECT | |
32 | |
33 public: | |
34 virtual ~TransformFactory(); | |
35 | |
36 static TransformFactory *getInstance(); | |
37 | |
38 // The identifier is intended to be computer-referenceable, and | |
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 TransformDesc { | |
47 | |
48 TransformDesc() { } | |
49 TransformDesc(QString _type, QString _category, | |
50 TransformId _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 TransformId 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 TransformDesc &od) const { | |
69 return (name < od.name); | |
70 }; | |
71 }; | |
72 typedef std::vector<TransformDesc> TransformList; | |
73 | |
74 TransformList getAllTransforms(); | |
75 | |
76 std::vector<QString> getAllTransformTypes(); | |
77 | |
78 std::vector<QString> getTransformCategories(QString transformType); | |
79 std::vector<QString> getTransformMakers(QString transformType); | |
80 | |
81 /** | |
82 * Get a configuration XML string for the given transform (by | |
83 * asking the user, most likely). Returns the selected input | |
84 * model if the transform is acceptable, 0 if the operation should | |
85 * be cancelled. Audio callback play source may be used to | |
86 * audition effects plugins, if provided. | |
87 */ | |
88 Model *getConfigurationForTransform(TransformId identifier, | |
89 const std::vector<Model *> &candidateInputModels, | |
90 PluginTransform::ExecutionContext &context, | |
91 QString &configurationXml, | |
92 AudioCallbackPlaySource *source = 0); | |
93 | |
94 /** | |
95 * Get the default execution context for the given transform | |
96 * and input model (if known). | |
97 */ | |
98 PluginTransform::ExecutionContext getDefaultContextForTransform(TransformId identifier, | |
99 Model *inputModel = 0); | |
100 | |
101 /** | |
102 * Return the output model resulting from applying the named | |
103 * transform to the given input model. The transform may still be | |
104 * working in the background when the model is returned; check the | |
105 * output model's isReady completion status for more details. | |
106 * | |
107 * If the transform is unknown or the input model is not an | |
108 * appropriate type for the given transform, or if some other | |
109 * problem occurs, return 0. | |
110 * | |
111 * The returned model is owned by the caller and must be deleted | |
112 * when no longer needed. | |
113 */ | |
114 Model *transform(TransformId identifier, Model *inputModel, | |
115 const PluginTransform::ExecutionContext &context, | |
116 QString configurationXml = ""); | |
117 | |
118 /** | |
119 * Full name of a transform, suitable for putting on a menu. | |
120 */ | |
121 QString getTransformName(TransformId identifier); | |
122 | |
123 /** | |
124 * Brief but friendly name of a transform, suitable for use | |
125 * as the name of the output layer. | |
126 */ | |
127 QString getTransformFriendlyName(TransformId identifier); | |
128 | |
129 QString getTransformUnits(TransformId identifier); | |
130 | |
131 /** | |
132 * Return true if the transform has any configurable parameters, | |
133 * i.e. if getConfigurationForTransform can ever return a non-trivial | |
134 * (not equivalent to empty) configuration string. | |
135 */ | |
136 bool isTransformConfigurable(TransformId identifier); | |
137 | |
138 /** | |
139 * If the transform has a prescribed number or range of channel | |
140 * inputs, return true and set minChannels and maxChannels to the | |
141 * minimum and maximum number of channel inputs the transform can | |
142 * accept. Return false if it doesn't care. | |
143 */ | |
144 bool getTransformChannelRange(TransformId identifier, | |
145 int &minChannels, int &maxChannels); | |
146 | |
147 protected slots: | |
148 void transformFinished(); | |
149 | |
150 void modelAboutToBeDeleted(Model *); | |
151 | |
152 protected: | |
153 Transform *createTransform(TransformId identifier, Model *inputModel, | |
154 const PluginTransform::ExecutionContext &context, | |
155 QString configurationXml); | |
156 | |
157 struct TransformIdent | |
158 { | |
159 TransformId identifier; | |
160 QString configurationXml; | |
161 }; | |
162 | |
163 typedef std::map<TransformId, QString> TransformConfigurationMap; | |
164 TransformConfigurationMap m_lastConfigurations; | |
165 | |
166 typedef std::map<TransformId, TransformDesc> TransformDescriptionMap; | |
167 TransformDescriptionMap m_transforms; | |
168 | |
169 typedef std::set<Transform *> TransformSet; | |
170 TransformSet m_runningTransforms; | |
171 | |
172 void populateTransforms(); | |
173 void populateFeatureExtractionPlugins(TransformDescriptionMap &); | |
174 void populateRealTimePlugins(TransformDescriptionMap &); | |
175 | |
176 bool getChannelRange(TransformId identifier, | |
177 Vamp::PluginBase *plugin, int &min, int &max); | |
178 | |
179 static TransformFactory *m_instance; | |
180 }; | |
181 | |
182 | |
183 #endif |