comparison transform/TransformFactory.h @ 0:cd5d7ff8ef38

* Reorganising code base. This revision will not compile.
author Chris Cannam
date Mon, 31 Jul 2006 12:03:45 +0000
parents
children d88d117e0c34
comparison
equal deleted inserted replaced
-1:000000000000 0:cd5d7ff8ef38
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.
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
21 #include <map>
22
23 namespace Vamp { class PluginBase; }
24
25 class TransformFactory : public QObject
26 {
27 Q_OBJECT
28
29 public:
30 virtual ~TransformFactory();
31
32 static TransformFactory *getInstance();
33
34 // The name is intended to be computer-referenceable, and unique
35 // within the application. The description is intended to be
36 // human readable. In principle it doesn't have to be unique, but
37 // the factory will add suffixes to ensure that it is, all the
38 // same (just to avoid user confusion). The friendly name is a
39 // shorter version of the description. The type is also intended
40 // to be user-readable, for use in menus.
41
42 struct TransformDesc {
43 TransformDesc() { }
44 TransformDesc(QString _type, TransformName _name, QString _description,
45 QString _friendlyName, QString _maker,
46 QString _units, bool _configurable) :
47 type(_type), name(_name), description(_description),
48 friendlyName(_friendlyName),
49 maker(_maker), units(_units), configurable(_configurable) { }
50 QString type;
51 TransformName name;
52 QString description;
53 QString friendlyName;
54 QString maker;
55 QString units;
56 bool configurable;
57 };
58 typedef std::vector<TransformDesc> TransformList;
59
60 TransformList getAllTransforms();
61
62 std::vector<QString> getAllTransformTypes();
63
64 /**
65 * Get a configuration XML string for the given transform (by
66 * asking the user, most likely). Returns true if the transform
67 * is acceptable, false if the operation should be cancelled.
68 */
69 bool getConfigurationForTransform(TransformName name, Model *inputModel,
70 int &channel,
71 QString &configurationXml);
72
73 /**
74 * Return the output model resulting from applying the named
75 * transform to the given input model. The transform may still be
76 * working in the background when the model is returned; check the
77 * output model's isReady completion status for more details.
78 *
79 * If the transform is unknown or the input model is not an
80 * appropriate type for the given transform, or if some other
81 * problem occurs, return 0.
82 *
83 * The returned model is owned by the caller and must be deleted
84 * when no longer needed.
85 */
86 Model *transform(TransformName name, Model *inputModel,
87 int channel, QString configurationXml = "");
88
89 /**
90 * Full description of a transform, suitable for putting on a menu.
91 */
92 QString getTransformDescription(TransformName name);
93
94 /**
95 * Brief but friendly description of a transform, suitable for use
96 * as the name of the output layer.
97 */
98 QString getTransformFriendlyName(TransformName name);
99
100 QString getTransformUnits(TransformName name);
101
102 /**
103 * Return true if the transform has any configurable parameters,
104 * i.e. if getConfigurationForTransform can ever return a non-trivial
105 * (not equivalent to empty) configuration string.
106 */
107 bool isTransformConfigurable(TransformName name);
108
109 /**
110 * If the transform has a prescribed number or range of channel
111 * inputs, return true and set minChannels and maxChannels to the
112 * minimum and maximum number of channel inputs the transform can
113 * accept.
114 */
115 bool getTransformChannelRange(TransformName name,
116 int &minChannels, int &maxChannels);
117
118 //!!! Need some way to indicate that the input model has changed /
119 //been deleted so as not to blow up backgrounded transform! -- Or
120 //indeed, if the output model has been deleted -- could equally
121 //well happen!
122
123 //!!! Need transform category!
124
125 protected slots:
126 void transformFinished();
127
128 protected:
129 Transform *createTransform(TransformName name, Model *inputModel,
130 int channel, QString configurationXml, bool start);
131
132 struct TransformIdent
133 {
134 TransformName name;
135 QString configurationXml;
136 };
137
138 typedef std::map<TransformName, QString> TransformConfigurationMap;
139 TransformConfigurationMap m_lastConfigurations;
140
141 typedef std::map<TransformName, TransformDesc> TransformDescriptionMap;
142 TransformDescriptionMap m_transforms;
143
144 void populateTransforms();
145 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
146 void populateRealTimePlugins(TransformDescriptionMap &);
147
148 bool getChannelRange(TransformName name,
149 Vamp::PluginBase *plugin, int &min, int &max);
150
151 static TransformFactory *m_instance;
152 };
153
154
155 #endif