comparison plugin/transform/TransformFactory.h @ 320:32e50b620a6c

* Move some things around to facilitate plundering libraries for other applications without needing to duplicate so much code. sv/osc -> data/osc sv/audioio -> audioio sv/transform -> plugin/transform sv/document -> document (will rename to framework in next commit)
author Chris Cannam
date Wed, 24 Oct 2007 16:34:31 +0000
parents
children bb6e4c46e202
comparison
equal deleted inserted replaced
319:3ff8f571da09 320:32e50b620a6c
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 size_t startFrame = 0,
94 size_t duration = 0);
95
96 /**
97 * Get the default execution context for the given transform
98 * and input model (if known).
99 */
100 PluginTransform::ExecutionContext getDefaultContextForTransform(TransformId identifier,
101 Model *inputModel = 0);
102
103 /**
104 * Return the output model resulting from applying the named
105 * transform to the given input model. The transform may still be
106 * working in the background when the model is returned; check the
107 * output model's isReady completion status for more details.
108 *
109 * If the transform is unknown or the input model is not an
110 * appropriate type for the given transform, or if some other
111 * problem occurs, return 0.
112 *
113 * The returned model is owned by the caller and must be deleted
114 * when no longer needed.
115 */
116 Model *transform(TransformId identifier, Model *inputModel,
117 const PluginTransform::ExecutionContext &context,
118 QString configurationXml = "");
119
120 /**
121 * Full name of a transform, suitable for putting on a menu.
122 */
123 QString getTransformName(TransformId identifier);
124
125 /**
126 * Brief but friendly name of a transform, suitable for use
127 * as the name of the output layer.
128 */
129 QString getTransformFriendlyName(TransformId identifier);
130
131 QString getTransformUnits(TransformId identifier);
132
133 /**
134 * Return true if the transform has any configurable parameters,
135 * i.e. if getConfigurationForTransform can ever return a non-trivial
136 * (not equivalent to empty) configuration string.
137 */
138 bool isTransformConfigurable(TransformId identifier);
139
140 /**
141 * If the transform has a prescribed number or range of channel
142 * inputs, return true and set minChannels and maxChannels to the
143 * minimum and maximum number of channel inputs the transform can
144 * accept. Return false if it doesn't care.
145 */
146 bool getTransformChannelRange(TransformId identifier,
147 int &minChannels, int &maxChannels);
148
149 protected slots:
150 void transformFinished();
151
152 void modelAboutToBeDeleted(Model *);
153
154 protected:
155 Transform *createTransform(TransformId identifier, Model *inputModel,
156 const PluginTransform::ExecutionContext &context,
157 QString configurationXml);
158
159 struct TransformIdent
160 {
161 TransformId identifier;
162 QString configurationXml;
163 };
164
165 typedef std::map<TransformId, QString> TransformConfigurationMap;
166 TransformConfigurationMap m_lastConfigurations;
167
168 typedef std::map<TransformId, TransformDesc> TransformDescriptionMap;
169 TransformDescriptionMap m_transforms;
170
171 typedef std::set<Transform *> TransformSet;
172 TransformSet m_runningTransforms;
173
174 void populateTransforms();
175 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
176 void populateRealTimePlugins(TransformDescriptionMap &);
177
178 bool getChannelRange(TransformId identifier,
179 Vamp::PluginBase *plugin, int &min, int &max);
180
181 static TransformFactory *m_instance;
182 };
183
184
185 #endif