Chris@320
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@320
|
2
|
Chris@320
|
3 /*
|
Chris@320
|
4 Sonic Visualiser
|
Chris@320
|
5 An audio file viewer and annotation editor.
|
Chris@320
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@320
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@320
|
8
|
Chris@320
|
9 This program is free software; you can redistribute it and/or
|
Chris@320
|
10 modify it under the terms of the GNU General Public License as
|
Chris@320
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@320
|
12 License, or (at your option) any later version. See the file
|
Chris@320
|
13 COPYING included with this distribution for more information.
|
Chris@320
|
14 */
|
Chris@320
|
15
|
Chris@328
|
16 #ifndef _TRANSFORMER_FACTORY_H_
|
Chris@328
|
17 #define _TRANSFORMER_FACTORY_H_
|
Chris@320
|
18
|
Chris@329
|
19 #include "TransformDescription.h"
|
Chris@329
|
20
|
Chris@328
|
21 #include "Transformer.h"
|
Chris@328
|
22 #include "PluginTransformer.h"
|
Chris@320
|
23
|
Chris@320
|
24 #include <map>
|
Chris@320
|
25 #include <set>
|
Chris@320
|
26
|
Chris@320
|
27 namespace Vamp { class PluginBase; }
|
Chris@320
|
28
|
Chris@320
|
29 class AudioCallbackPlaySource;
|
Chris@320
|
30
|
Chris@329
|
31 //!!! split into TransformFactory (information about available
|
Chris@329
|
32 // transforms, create default Transform for each transform ID etc) and
|
Chris@329
|
33 // TransformerFactory (create Transformers to apply transforms)
|
Chris@329
|
34
|
Chris@328
|
35 class TransformerFactory : public QObject
|
Chris@320
|
36 {
|
Chris@320
|
37 Q_OBJECT
|
Chris@320
|
38
|
Chris@320
|
39 public:
|
Chris@328
|
40 virtual ~TransformerFactory();
|
Chris@320
|
41
|
Chris@328
|
42 static TransformerFactory *getInstance();
|
Chris@320
|
43
|
Chris@329
|
44 TransformList getAllTransforms();
|
Chris@320
|
45
|
Chris@328
|
46 std::vector<QString> getAllTransformerTypes();
|
Chris@320
|
47
|
Chris@328
|
48 std::vector<QString> getTransformerCategories(QString transformType);
|
Chris@328
|
49 std::vector<QString> getTransformerMakers(QString transformType);
|
Chris@320
|
50
|
Chris@320
|
51 /**
|
Chris@320
|
52 * Get a configuration XML string for the given transform (by
|
Chris@320
|
53 * asking the user, most likely). Returns the selected input
|
Chris@320
|
54 * model if the transform is acceptable, 0 if the operation should
|
Chris@320
|
55 * be cancelled. Audio callback play source may be used to
|
Chris@320
|
56 * audition effects plugins, if provided.
|
Chris@320
|
57 */
|
Chris@329
|
58 Model *getConfigurationForTransformer(TransformId identifier,
|
Chris@320
|
59 const std::vector<Model *> &candidateInputModels,
|
Chris@328
|
60 PluginTransformer::ExecutionContext &context,
|
Chris@320
|
61 QString &configurationXml,
|
Chris@320
|
62 AudioCallbackPlaySource *source = 0,
|
Chris@320
|
63 size_t startFrame = 0,
|
Chris@320
|
64 size_t duration = 0);
|
Chris@320
|
65
|
Chris@320
|
66 /**
|
Chris@320
|
67 * Get the default execution context for the given transform
|
Chris@320
|
68 * and input model (if known).
|
Chris@320
|
69 */
|
Chris@329
|
70 PluginTransformer::ExecutionContext getDefaultContextForTransformer(TransformId identifier,
|
Chris@320
|
71 Model *inputModel = 0);
|
Chris@320
|
72
|
Chris@320
|
73 /**
|
Chris@320
|
74 * Return the output model resulting from applying the named
|
Chris@320
|
75 * transform to the given input model. The transform may still be
|
Chris@320
|
76 * working in the background when the model is returned; check the
|
Chris@320
|
77 * output model's isReady completion status for more details.
|
Chris@320
|
78 *
|
Chris@320
|
79 * If the transform is unknown or the input model is not an
|
Chris@320
|
80 * appropriate type for the given transform, or if some other
|
Chris@320
|
81 * problem occurs, return 0.
|
Chris@320
|
82 *
|
Chris@320
|
83 * The returned model is owned by the caller and must be deleted
|
Chris@320
|
84 * when no longer needed.
|
Chris@320
|
85 */
|
Chris@329
|
86 Model *transform(TransformId identifier, Model *inputModel,
|
Chris@328
|
87 const PluginTransformer::ExecutionContext &context,
|
Chris@320
|
88 QString configurationXml = "");
|
Chris@320
|
89
|
Chris@320
|
90 /**
|
Chris@326
|
91 * Return true if the given transform is known.
|
Chris@326
|
92 */
|
Chris@329
|
93 bool haveTransformer(TransformId identifier);
|
Chris@326
|
94
|
Chris@326
|
95 /**
|
Chris@320
|
96 * Full name of a transform, suitable for putting on a menu.
|
Chris@320
|
97 */
|
Chris@329
|
98 QString getTransformerName(TransformId identifier);
|
Chris@320
|
99
|
Chris@320
|
100 /**
|
Chris@320
|
101 * Brief but friendly name of a transform, suitable for use
|
Chris@320
|
102 * as the name of the output layer.
|
Chris@320
|
103 */
|
Chris@329
|
104 QString getTransformerFriendlyName(TransformId identifier);
|
Chris@320
|
105
|
Chris@329
|
106 QString getTransformerUnits(TransformId identifier);
|
Chris@320
|
107
|
Chris@320
|
108 /**
|
Chris@320
|
109 * Return true if the transform has any configurable parameters,
|
Chris@328
|
110 * i.e. if getConfigurationForTransformer can ever return a non-trivial
|
Chris@320
|
111 * (not equivalent to empty) configuration string.
|
Chris@320
|
112 */
|
Chris@329
|
113 bool isTransformerConfigurable(TransformId identifier);
|
Chris@320
|
114
|
Chris@320
|
115 /**
|
Chris@320
|
116 * If the transform has a prescribed number or range of channel
|
Chris@320
|
117 * inputs, return true and set minChannels and maxChannels to the
|
Chris@320
|
118 * minimum and maximum number of channel inputs the transform can
|
Chris@320
|
119 * accept. Return false if it doesn't care.
|
Chris@320
|
120 */
|
Chris@329
|
121 bool getTransformerChannelRange(TransformId identifier,
|
Chris@320
|
122 int &minChannels, int &maxChannels);
|
Chris@320
|
123
|
Chris@320
|
124 protected slots:
|
Chris@320
|
125 void transformFinished();
|
Chris@320
|
126
|
Chris@320
|
127 void modelAboutToBeDeleted(Model *);
|
Chris@320
|
128
|
Chris@320
|
129 protected:
|
Chris@329
|
130 Transformer *createTransformer(TransformId identifier, Model *inputModel,
|
Chris@328
|
131 const PluginTransformer::ExecutionContext &context,
|
Chris@320
|
132 QString configurationXml);
|
Chris@320
|
133
|
Chris@329
|
134 struct TransformIdent
|
Chris@320
|
135 {
|
Chris@329
|
136 TransformId identifier;
|
Chris@320
|
137 QString configurationXml;
|
Chris@320
|
138 };
|
Chris@320
|
139
|
Chris@329
|
140 typedef std::map<TransformId, QString> TransformerConfigurationMap;
|
Chris@328
|
141 TransformerConfigurationMap m_lastConfigurations;
|
Chris@320
|
142
|
Chris@329
|
143 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;
|
Chris@329
|
144 TransformDescriptionMap m_transforms;
|
Chris@320
|
145
|
Chris@328
|
146 typedef std::set<Transformer *> TransformerSet;
|
Chris@328
|
147 TransformerSet m_runningTransformers;
|
Chris@320
|
148
|
Chris@329
|
149 void populateTransforms();
|
Chris@329
|
150 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
|
Chris@329
|
151 void populateRealTimePlugins(TransformDescriptionMap &);
|
Chris@320
|
152
|
Chris@329
|
153 bool getChannelRange(TransformId identifier,
|
Chris@320
|
154 Vamp::PluginBase *plugin, int &min, int &max);
|
Chris@320
|
155
|
Chris@328
|
156 static TransformerFactory *m_instance;
|
Chris@320
|
157 };
|
Chris@320
|
158
|
Chris@320
|
159
|
Chris@320
|
160 #endif
|