Chris@330
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@330
|
2
|
Chris@330
|
3 /*
|
Chris@330
|
4 Sonic Visualiser
|
Chris@330
|
5 An audio file viewer and annotation editor.
|
Chris@330
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@330
|
7 This file copyright 2006-2007 Chris Cannam and QMUL.
|
Chris@330
|
8
|
Chris@330
|
9 This program is free software; you can redistribute it and/or
|
Chris@330
|
10 modify it under the terms of the GNU General Public License as
|
Chris@330
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@330
|
12 License, or (at your option) any later version. See the file
|
Chris@330
|
13 COPYING included with this distribution for more information.
|
Chris@330
|
14 */
|
Chris@330
|
15
|
Chris@330
|
16 #ifndef _TRANSFORM_FACTORY_H_
|
Chris@330
|
17 #define _TRANSFORM_FACTORY_H_
|
Chris@330
|
18
|
Chris@330
|
19 #include "TransformDescription.h"
|
Chris@330
|
20
|
Chris@383
|
21 #include <vamp-sdk/Plugin.h>
|
Chris@383
|
22
|
Chris@330
|
23 #include <map>
|
Chris@330
|
24 #include <set>
|
Chris@330
|
25
|
Chris@330
|
26 class TransformFactory : public QObject
|
Chris@330
|
27 {
|
Chris@330
|
28 Q_OBJECT
|
Chris@330
|
29
|
Chris@330
|
30 public:
|
Chris@330
|
31 virtual ~TransformFactory();
|
Chris@330
|
32
|
Chris@330
|
33 static TransformFactory *getInstance();
|
Chris@330
|
34
|
Chris@383
|
35 TransformList getAllTransformDescriptions();
|
Chris@383
|
36 TransformDescription getTransformDescription(TransformId id);
|
Chris@330
|
37
|
Chris@330
|
38 std::vector<QString> getAllTransformTypes();
|
Chris@330
|
39 std::vector<QString> getTransformCategories(QString transformType);
|
Chris@330
|
40 std::vector<QString> getTransformMakers(QString transformType);
|
Chris@330
|
41
|
Chris@330
|
42 /**
|
Chris@330
|
43 * Return true if the given transform is known.
|
Chris@330
|
44 */
|
Chris@330
|
45 bool haveTransform(TransformId identifier);
|
Chris@330
|
46
|
Chris@330
|
47 /**
|
Chris@383
|
48 * A single transform ID can lead to many possible Transforms,
|
Chris@383
|
49 * with different parameters and execution context settings.
|
Chris@383
|
50 * Return the default one for the given transform.
|
Chris@383
|
51 */
|
Chris@383
|
52 Transform getDefaultTransformFor(TransformId identifier, size_t rate = 0);
|
Chris@383
|
53
|
Chris@383
|
54 /**
|
Chris@330
|
55 * Full name of a transform, suitable for putting on a menu.
|
Chris@330
|
56 */
|
Chris@330
|
57 QString getTransformName(TransformId identifier);
|
Chris@330
|
58
|
Chris@330
|
59 /**
|
Chris@330
|
60 * Brief but friendly name of a transform, suitable for use
|
Chris@330
|
61 * as the name of the output layer.
|
Chris@330
|
62 */
|
Chris@330
|
63 QString getTransformFriendlyName(TransformId identifier);
|
Chris@330
|
64
|
Chris@330
|
65 QString getTransformUnits(TransformId identifier);
|
Chris@330
|
66
|
Chris@383
|
67 Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier);
|
Chris@383
|
68
|
Chris@330
|
69 /**
|
Chris@330
|
70 * Return true if the transform has any configurable parameters,
|
Chris@330
|
71 * i.e. if getConfigurationForTransform can ever return a non-trivial
|
Chris@330
|
72 * (not equivalent to empty) configuration string.
|
Chris@330
|
73 */
|
Chris@330
|
74 bool isTransformConfigurable(TransformId identifier);
|
Chris@330
|
75
|
Chris@330
|
76 /**
|
Chris@330
|
77 * If the transform has a prescribed number or range of channel
|
Chris@330
|
78 * inputs, return true and set minChannels and maxChannels to the
|
Chris@330
|
79 * minimum and maximum number of channel inputs the transform can
|
Chris@330
|
80 * accept. Return false if it doesn't care.
|
Chris@330
|
81 */
|
Chris@330
|
82 bool getTransformChannelRange(TransformId identifier,
|
Chris@330
|
83 int &minChannels, int &maxChannels);
|
Chris@332
|
84
|
Chris@332
|
85 /**
|
Chris@383
|
86 * Load an appropriate plugin for the given transform and set the
|
Chris@383
|
87 * parameters, program and configuration strings on that plugin
|
Chris@383
|
88 * from the Transform object.
|
Chris@383
|
89 *
|
Chris@383
|
90 * Note that this requires that the transform has a meaningful
|
Chris@383
|
91 * sample rate set, as that is used as the rate for the plugin. A
|
Chris@383
|
92 * Transform can legitimately have rate set at zero (= "use the
|
Chris@383
|
93 * rate of the input source"), so the caller will need to test for
|
Chris@383
|
94 * this case.
|
Chris@383
|
95 *
|
Chris@383
|
96 * Returns the plugin thus loaded. This will be a
|
Chris@383
|
97 * Vamp::PluginBase, but not necessarily a Vamp::Plugin (only if
|
Chris@383
|
98 * the transform was a feature-extraction type -- call
|
Chris@383
|
99 * downcastVampPlugin if you only want Vamp::Plugins). Returns
|
Chris@383
|
100 * NULL if no suitable plugin was available.
|
Chris@383
|
101 *
|
Chris@383
|
102 * The returned plugin is owned by the caller, and should be
|
Chris@383
|
103 * deleted (using "delete") when no longer needed.
|
Chris@383
|
104 */
|
Chris@383
|
105 Vamp::PluginBase *instantiatePluginFor(const Transform &transform);
|
Chris@383
|
106
|
Chris@383
|
107 /**
|
Chris@383
|
108 * Convert a Vamp::PluginBase to a Vamp::Plugin, if it is one.
|
Chris@383
|
109 * Return NULL otherwise. This ill-fitting convenience function
|
Chris@383
|
110 * is really just a dynamic_cast wrapper.
|
Chris@383
|
111 */
|
Chris@383
|
112 Vamp::Plugin *downcastVampPlugin(Vamp::PluginBase *);
|
Chris@383
|
113
|
Chris@383
|
114 /**
|
Chris@332
|
115 * Set the plugin parameters, program and configuration strings on
|
Chris@332
|
116 * the given Transform object from the given plugin instance.
|
Chris@332
|
117 * Note that no check is made whether the plugin is actually the
|
Chris@332
|
118 * "correct" one for the transform.
|
Chris@332
|
119 */
|
Chris@332
|
120 void setParametersFromPlugin(Transform &transform, Vamp::PluginBase *plugin);
|
Chris@332
|
121
|
Chris@332
|
122 /**
|
Chris@383
|
123 * Set the parameters, program and configuration strings on the
|
Chris@383
|
124 * given plugin from the given Transform object.
|
Chris@383
|
125 */
|
Chris@383
|
126 void setPluginParameters(const Transform &transform, Vamp::PluginBase *plugin);
|
Chris@383
|
127
|
Chris@383
|
128 /**
|
Chris@332
|
129 * If the given Transform object has no processing step and block
|
Chris@332
|
130 * sizes set, set them to appropriate defaults for the given
|
Chris@332
|
131 * plugin.
|
Chris@332
|
132 */
|
Chris@332
|
133 void makeContextConsistentWithPlugin(Transform &transform, Vamp::PluginBase *plugin);
|
Chris@332
|
134
|
Chris@332
|
135 /**
|
Chris@383
|
136 * Retrieve a <plugin ... /> XML fragment that describes the
|
Chris@383
|
137 * plugin parameters, program and configuration data for the given
|
Chris@383
|
138 * transform.
|
Chris@383
|
139 *
|
Chris@383
|
140 * This function is provided for backward compatibility only. Use
|
Chris@383
|
141 * Transform::toXml where compatibility with PluginXml
|
Chris@383
|
142 * descriptions of transforms is not required.
|
Chris@332
|
143 */
|
Chris@383
|
144 QString getPluginConfigurationXml(const Transform &transform);
|
Chris@383
|
145
|
Chris@383
|
146 /**
|
Chris@383
|
147 * Set the plugin parameters, program and configuration strings on
|
Chris@383
|
148 * the given Transform object from the given <plugin ... /> XML
|
Chris@383
|
149 * fragment.
|
Chris@383
|
150 *
|
Chris@383
|
151 * This function is provided for backward compatibility only. Use
|
Chris@383
|
152 * Transform(QString) where compatibility with PluginXml
|
Chris@383
|
153 * descriptions of transforms is not required.
|
Chris@383
|
154 */
|
Chris@383
|
155 void setParametersFromPluginConfigurationXml(Transform &transform,
|
Chris@383
|
156 QString xml);
|
Chris@332
|
157
|
Chris@330
|
158 protected:
|
Chris@330
|
159 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;
|
Chris@330
|
160 TransformDescriptionMap m_transforms;
|
Chris@330
|
161
|
Chris@330
|
162 void populateTransforms();
|
Chris@330
|
163 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
|
Chris@330
|
164 void populateRealTimePlugins(TransformDescriptionMap &);
|
Chris@330
|
165
|
Chris@383
|
166 Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, size_t rate);
|
Chris@383
|
167
|
Chris@330
|
168 static TransformFactory *m_instance;
|
Chris@330
|
169 };
|
Chris@330
|
170
|
Chris@330
|
171
|
Chris@330
|
172 #endif
|