Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 Sonic Visualiser
|
Chris@0
|
5 An audio file viewer and annotation editor.
|
Chris@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@0
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@0
|
9 This program is free software; you can redistribute it and/or
|
Chris@0
|
10 modify it under the terms of the GNU General Public License as
|
Chris@0
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@0
|
12 License, or (at your option) any later version. See the file
|
Chris@0
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #ifndef _TRANSFORM_FACTORY_H_
|
Chris@0
|
17 #define _TRANSFORM_FACTORY_H_
|
Chris@0
|
18
|
Chris@0
|
19 #include "Transform.h"
|
Chris@27
|
20 #include "PluginTransform.h"
|
Chris@0
|
21
|
Chris@0
|
22 #include <map>
|
Chris@0
|
23
|
Chris@0
|
24 namespace Vamp { class PluginBase; }
|
Chris@0
|
25
|
Chris@41
|
26 class AudioCallbackPlaySource;
|
Chris@41
|
27
|
Chris@0
|
28 class TransformFactory : public QObject
|
Chris@0
|
29 {
|
Chris@0
|
30 Q_OBJECT
|
Chris@0
|
31
|
Chris@0
|
32 public:
|
Chris@0
|
33 virtual ~TransformFactory();
|
Chris@0
|
34
|
Chris@0
|
35 static TransformFactory *getInstance();
|
Chris@0
|
36
|
Chris@0
|
37 // The name is intended to be computer-referenceable, and unique
|
Chris@0
|
38 // within the application. The description is intended to be
|
Chris@0
|
39 // human readable. In principle it doesn't have to be unique, but
|
Chris@0
|
40 // the factory will add suffixes to ensure that it is, all the
|
Chris@0
|
41 // same (just to avoid user confusion). The friendly name is a
|
Chris@0
|
42 // shorter version of the description. The type is also intended
|
Chris@0
|
43 // to be user-readable, for use in menus.
|
Chris@0
|
44
|
Chris@0
|
45 struct TransformDesc {
|
Chris@34
|
46
|
Chris@0
|
47 TransformDesc() { }
|
Chris@33
|
48 TransformDesc(QString _type, QString _category,
|
Chris@33
|
49 TransformName _name, QString _description,
|
Chris@0
|
50 QString _friendlyName, QString _maker,
|
Chris@0
|
51 QString _units, bool _configurable) :
|
Chris@33
|
52 type(_type), category(_category),
|
Chris@33
|
53 name(_name), description(_description),
|
Chris@0
|
54 friendlyName(_friendlyName),
|
Chris@0
|
55 maker(_maker), units(_units), configurable(_configurable) { }
|
Chris@34
|
56
|
Chris@0
|
57 QString type;
|
Chris@33
|
58 QString category;
|
Chris@0
|
59 TransformName name;
|
Chris@0
|
60 QString description;
|
Chris@0
|
61 QString friendlyName;
|
Chris@0
|
62 QString maker;
|
Chris@0
|
63 QString units;
|
Chris@0
|
64 bool configurable;
|
Chris@34
|
65
|
Chris@34
|
66 bool operator<(const TransformDesc &od) const {
|
Chris@34
|
67 return (description < od.description);
|
Chris@34
|
68 };
|
Chris@0
|
69 };
|
Chris@0
|
70 typedef std::vector<TransformDesc> TransformList;
|
Chris@0
|
71
|
Chris@0
|
72 TransformList getAllTransforms();
|
Chris@0
|
73
|
Chris@0
|
74 std::vector<QString> getAllTransformTypes();
|
Chris@0
|
75
|
Chris@33
|
76 std::vector<QString> getTransformCategories(QString transformType);
|
Chris@33
|
77 std::vector<QString> getTransformMakers(QString transformType);
|
Chris@33
|
78
|
Chris@0
|
79 /**
|
Chris@0
|
80 * Get a configuration XML string for the given transform (by
|
Chris@53
|
81 * asking the user, most likely). Returns the selected input
|
Chris@53
|
82 * model if the transform is acceptable, 0 if the operation should
|
Chris@53
|
83 * be cancelled. Audio callback play source may be used to
|
Chris@53
|
84 * audition effects plugins, if provided.
|
Chris@0
|
85 */
|
Chris@53
|
86 Model *getConfigurationForTransform(TransformName name,
|
Chris@53
|
87 const std::vector<Model *> &candidateInputModels,
|
Chris@53
|
88 PluginTransform::ExecutionContext &context,
|
Chris@53
|
89 QString &configurationXml,
|
Chris@53
|
90 AudioCallbackPlaySource *source = 0);
|
Chris@0
|
91
|
Chris@0
|
92 /**
|
Chris@73
|
93 * Get the default execution context for the given transform
|
Chris@73
|
94 * and input model (if known).
|
Chris@73
|
95 */
|
Chris@73
|
96 PluginTransform::ExecutionContext getDefaultContextForTransform(TransformName name,
|
Chris@73
|
97 Model *inputModel = 0);
|
Chris@73
|
98
|
Chris@73
|
99 /**
|
Chris@0
|
100 * Return the output model resulting from applying the named
|
Chris@0
|
101 * transform to the given input model. The transform may still be
|
Chris@0
|
102 * working in the background when the model is returned; check the
|
Chris@0
|
103 * output model's isReady completion status for more details.
|
Chris@0
|
104 *
|
Chris@0
|
105 * If the transform is unknown or the input model is not an
|
Chris@0
|
106 * appropriate type for the given transform, or if some other
|
Chris@0
|
107 * problem occurs, return 0.
|
Chris@0
|
108 *
|
Chris@0
|
109 * The returned model is owned by the caller and must be deleted
|
Chris@0
|
110 * when no longer needed.
|
Chris@0
|
111 */
|
Chris@0
|
112 Model *transform(TransformName name, Model *inputModel,
|
Chris@27
|
113 const PluginTransform::ExecutionContext &context,
|
Chris@27
|
114 QString configurationXml = "");
|
Chris@0
|
115
|
Chris@0
|
116 /**
|
Chris@0
|
117 * Full description of a transform, suitable for putting on a menu.
|
Chris@0
|
118 */
|
Chris@0
|
119 QString getTransformDescription(TransformName name);
|
Chris@0
|
120
|
Chris@0
|
121 /**
|
Chris@0
|
122 * Brief but friendly description of a transform, suitable for use
|
Chris@0
|
123 * as the name of the output layer.
|
Chris@0
|
124 */
|
Chris@0
|
125 QString getTransformFriendlyName(TransformName name);
|
Chris@0
|
126
|
Chris@0
|
127 QString getTransformUnits(TransformName name);
|
Chris@0
|
128
|
Chris@0
|
129 /**
|
Chris@0
|
130 * Return true if the transform has any configurable parameters,
|
Chris@0
|
131 * i.e. if getConfigurationForTransform can ever return a non-trivial
|
Chris@0
|
132 * (not equivalent to empty) configuration string.
|
Chris@0
|
133 */
|
Chris@0
|
134 bool isTransformConfigurable(TransformName name);
|
Chris@0
|
135
|
Chris@0
|
136 /**
|
Chris@0
|
137 * If the transform has a prescribed number or range of channel
|
Chris@0
|
138 * inputs, return true and set minChannels and maxChannels to the
|
Chris@0
|
139 * minimum and maximum number of channel inputs the transform can
|
Chris@34
|
140 * accept. Return false if it doesn't care.
|
Chris@0
|
141 */
|
Chris@0
|
142 bool getTransformChannelRange(TransformName name,
|
Chris@0
|
143 int &minChannels, int &maxChannels);
|
Chris@0
|
144
|
Chris@0
|
145 //!!! Need some way to indicate that the input model has changed /
|
Chris@0
|
146 //been deleted so as not to blow up backgrounded transform! -- Or
|
Chris@0
|
147 //indeed, if the output model has been deleted -- could equally
|
Chris@0
|
148 //well happen!
|
Chris@0
|
149
|
Chris@0
|
150 //!!! Need transform category!
|
Chris@0
|
151
|
Chris@0
|
152 protected slots:
|
Chris@0
|
153 void transformFinished();
|
Chris@0
|
154
|
Chris@0
|
155 protected:
|
Chris@0
|
156 Transform *createTransform(TransformName name, Model *inputModel,
|
Chris@27
|
157 const PluginTransform::ExecutionContext &context,
|
Chris@27
|
158 QString configurationXml, bool start);
|
Chris@0
|
159
|
Chris@0
|
160 struct TransformIdent
|
Chris@0
|
161 {
|
Chris@0
|
162 TransformName name;
|
Chris@0
|
163 QString configurationXml;
|
Chris@0
|
164 };
|
Chris@0
|
165
|
Chris@0
|
166 typedef std::map<TransformName, QString> TransformConfigurationMap;
|
Chris@0
|
167 TransformConfigurationMap m_lastConfigurations;
|
Chris@0
|
168
|
Chris@0
|
169 typedef std::map<TransformName, TransformDesc> TransformDescriptionMap;
|
Chris@0
|
170 TransformDescriptionMap m_transforms;
|
Chris@0
|
171
|
Chris@0
|
172 void populateTransforms();
|
Chris@0
|
173 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
|
Chris@0
|
174 void populateRealTimePlugins(TransformDescriptionMap &);
|
Chris@0
|
175
|
Chris@0
|
176 bool getChannelRange(TransformName name,
|
Chris@0
|
177 Vamp::PluginBase *plugin, int &min, int &max);
|
Chris@0
|
178
|
Chris@0
|
179 static TransformFactory *m_instance;
|
Chris@0
|
180 };
|
Chris@0
|
181
|
Chris@0
|
182
|
Chris@0
|
183 #endif
|