comparison transform/Transform.h @ 388:370aa9714ef5

* Move plugin/transform to plain transform. This way transform can depend on model and GUI classes, but plugin doesn't have to.
author Chris Cannam
date Wed, 12 Mar 2008 18:02:17 +0000
parents plugin/transform/Transform.h@4bb19132da23
children 78dd9b35559b
comparison
equal deleted inserted replaced
387:7aa1de571880 388:370aa9714ef5
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-2007 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_H_
17 #define _TRANSFORM_H_
18
19 #include "base/XmlExportable.h"
20 #include "base/Window.h"
21 #include "base/RealTime.h"
22
23 #include <QString>
24
25 typedef QString TransformId;
26
27 class QXmlAttributes;
28
29 namespace Vamp {
30 class PluginBase;
31 }
32
33 class Transform : public XmlExportable
34 {
35 public:
36 /**
37 * Construct a new Transform with default data and no identifier.
38 * The Transform object will be meaningless until some data and an
39 * identifier have been set on it.
40 *
41 * To construct a Transform for use with a particular transform
42 * identifier, use TransformFactory::getDefaultTransformFor.
43 */
44 Transform();
45
46 /**
47 * Construct a Transform by parsing the given XML data string.
48 * This is the inverse of toXml.
49 */
50 Transform(QString xml);
51
52 virtual ~Transform();
53
54 /**
55 * Compare two Transforms. They only compare equal if every data
56 * element matches.
57 */
58 bool operator==(const Transform &);
59
60 void setIdentifier(TransformId id);
61 TransformId getIdentifier() const;
62
63 enum Type { FeatureExtraction, RealTimeEffect };
64
65 Type getType() const;
66 QString getPluginIdentifier() const;
67 QString getOutput() const;
68
69 void setPluginIdentifier(QString pluginIdentifier);
70 void setOutput(QString output);
71
72 // Turn a plugin ID and output name into a transform ID. Note
73 // that our pluginIdentifier is the same thing as the Vamp SDK's
74 // PluginLoader::PluginKey.
75 static TransformId getIdentifierForPluginOutput(QString pluginIdentifier,
76 QString output = "");
77
78 typedef std::map<QString, float> ParameterMap;
79
80 const ParameterMap &getParameters() const;
81 void setParameters(const ParameterMap &pm);
82 void setParameter(QString name, float value);
83
84 typedef std::map<QString, QString> ConfigurationMap;
85
86 const ConfigurationMap &getConfiguration() const;
87 void setConfiguration(const ConfigurationMap &cm);
88 void setConfigurationValue(QString name, QString value);
89
90 QString getPluginVersion() const;
91 void setPluginVersion(QString version);
92
93 QString getProgram() const;
94 void setProgram(QString program);
95
96 size_t getStepSize() const;
97 void setStepSize(size_t s);
98
99 size_t getBlockSize() const;
100 void setBlockSize(size_t s);
101
102 WindowType getWindowType() const;
103 void setWindowType(WindowType type);
104
105 RealTime getStartTime() const;
106 void setStartTime(RealTime t);
107
108 RealTime getDuration() const; // 0 -> all
109 void setDuration(RealTime d);
110
111 float getSampleRate() const; // 0 -> as input
112 void setSampleRate(float rate);
113
114 void toXml(QTextStream &stream, QString indent = "",
115 QString extraAttributes = "") const;
116
117 /**
118 * Set the main transform data from the given XML attributes.
119 * This does not set the parameters or configuration, which are
120 * exported to separate XML elements rather than attributes of the
121 * transform element.
122 *
123 * Note that this only sets those attributes which are actually
124 * present in the argument. Any attributes not defined in the
125 * attribute will remain unchanged in the Transform. If your aim
126 * is to create a transform exactly matching the given attributes,
127 * ensure you start from an empty transform rather than one that
128 * has already been configured.
129 */
130 void setFromXmlAttributes(const QXmlAttributes &);
131
132 protected:
133 TransformId m_id; // pluginid:output, that is type:soname:label:output
134
135 static QString createIdentifier
136 (QString type, QString soName, QString label, QString output);
137
138 static void parseIdentifier
139 (QString identifier,
140 QString &type, QString &soName, QString &label, QString &output);
141
142 ParameterMap m_parameters;
143 ConfigurationMap m_configuration;
144 QString m_pluginVersion;
145 QString m_program;
146 size_t m_stepSize;
147 size_t m_blockSize;
148 WindowType m_windowType;
149 RealTime m_startTime;
150 RealTime m_duration;
151 float m_sampleRate;
152 };
153
154 #endif
155