annotate transform/Transform.h @ 494:81963c51b488

* Add ability to export a transform structure as RDF -- for use when exporting data from runner, so as to refer back to the generating transform from the audio features rdf * some improvements to pane & layer management when importing rdf, but it's all still a big hack here
author Chris Cannam
date Tue, 25 Nov 2008 17:46:02 +0000
parents 4c000e196bf1
children 1b8c748fd7ea
rev   line source
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@328 7 This file copyright 2006-2007 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@320 16 #ifndef _TRANSFORM_H_
Chris@320 17 #define _TRANSFORM_H_
Chris@320 18
Chris@328 19 #include "base/XmlExportable.h"
Chris@328 20 #include "base/Window.h"
Chris@350 21 #include "base/RealTime.h"
Chris@328 22
Chris@486 23 #include <vamp-hostsdk/PluginBase.h>
Chris@486 24
Chris@328 25 #include <QString>
Chris@320 26
Chris@400 27 #include <map>
Chris@400 28
Chris@320 29 typedef QString TransformId;
Chris@320 30
Chris@350 31 class QXmlAttributes;
Chris@350 32
Chris@328 33 class Transform : public XmlExportable
Chris@320 34 {
Chris@320 35 public:
Chris@350 36 /**
Chris@350 37 * Construct a new Transform with default data and no identifier.
Chris@350 38 * The Transform object will be meaningless until some data and an
Chris@350 39 * identifier have been set on it.
Chris@350 40 *
Chris@350 41 * To construct a Transform for use with a particular transform
Chris@350 42 * identifier, use TransformFactory::getDefaultTransformFor.
Chris@350 43 */
Chris@328 44 Transform();
Chris@350 45
Chris@350 46 /**
Chris@350 47 * Construct a Transform by parsing the given XML data string.
Chris@350 48 * This is the inverse of toXml.
Chris@350 49 */
Chris@350 50 Transform(QString xml);
Chris@350 51
Chris@320 52 virtual ~Transform();
Chris@320 53
Chris@350 54 /**
Chris@350 55 * Compare two Transforms. They only compare equal if every data
Chris@350 56 * element matches.
Chris@350 57 */
Chris@400 58 bool operator==(const Transform &) const;
Chris@400 59
Chris@400 60 /**
Chris@400 61 * Order two Transforms, so that they can be used as keys in
Chris@400 62 * containers.
Chris@400 63 */
Chris@400 64 bool operator<(const Transform &) const;
Chris@350 65
Chris@350 66 void setIdentifier(TransformId id);
Chris@350 67 TransformId getIdentifier() const;
Chris@320 68
Chris@328 69 enum Type { FeatureExtraction, RealTimeEffect };
Chris@328 70
Chris@328 71 Type getType() const;
Chris@328 72 QString getPluginIdentifier() const;
Chris@328 73 QString getOutput() const;
Chris@353 74
Chris@353 75 void setPluginIdentifier(QString pluginIdentifier);
Chris@353 76 void setOutput(QString output);
Chris@353 77
Chris@353 78 // Turn a plugin ID and output name into a transform ID. Note
Chris@353 79 // that our pluginIdentifier is the same thing as the Vamp SDK's
Chris@353 80 // PluginLoader::PluginKey.
Chris@353 81 static TransformId getIdentifierForPluginOutput(QString pluginIdentifier,
Chris@353 82 QString output = "");
Chris@328 83
Chris@328 84 typedef std::map<QString, float> ParameterMap;
Chris@328 85
Chris@350 86 const ParameterMap &getParameters() const;
Chris@350 87 void setParameters(const ParameterMap &pm);
Chris@350 88 void setParameter(QString name, float value);
Chris@328 89
Chris@328 90 typedef std::map<QString, QString> ConfigurationMap;
Chris@328 91
Chris@350 92 const ConfigurationMap &getConfiguration() const;
Chris@350 93 void setConfiguration(const ConfigurationMap &cm);
Chris@350 94 void setConfigurationValue(QString name, QString value);
Chris@328 95
Chris@366 96 QString getPluginVersion() const;
Chris@366 97 void setPluginVersion(QString version);
Chris@366 98
Chris@350 99 QString getProgram() const;
Chris@350 100 void setProgram(QString program);
Chris@328 101
Chris@350 102 size_t getStepSize() const;
Chris@350 103 void setStepSize(size_t s);
Chris@328 104
Chris@350 105 size_t getBlockSize() const;
Chris@350 106 void setBlockSize(size_t s);
Chris@328 107
Chris@350 108 WindowType getWindowType() const;
Chris@350 109 void setWindowType(WindowType type);
Chris@350 110
Chris@350 111 RealTime getStartTime() const;
Chris@350 112 void setStartTime(RealTime t);
Chris@350 113
Chris@350 114 RealTime getDuration() const; // 0 -> all
Chris@350 115 void setDuration(RealTime d);
Chris@350 116
Chris@350 117 float getSampleRate() const; // 0 -> as input
Chris@350 118 void setSampleRate(float rate);
Chris@328 119
Chris@328 120 void toXml(QTextStream &stream, QString indent = "",
Chris@328 121 QString extraAttributes = "") const;
Chris@328 122
Chris@350 123 /**
Chris@350 124 * Set the main transform data from the given XML attributes.
Chris@350 125 * This does not set the parameters or configuration, which are
Chris@350 126 * exported to separate XML elements rather than attributes of the
Chris@350 127 * transform element.
Chris@366 128 *
Chris@366 129 * Note that this only sets those attributes which are actually
Chris@366 130 * present in the argument. Any attributes not defined in the
Chris@366 131 * attribute will remain unchanged in the Transform. If your aim
Chris@366 132 * is to create a transform exactly matching the given attributes,
Chris@366 133 * ensure you start from an empty transform rather than one that
Chris@366 134 * has already been configured.
Chris@350 135 */
Chris@350 136 void setFromXmlAttributes(const QXmlAttributes &);
Chris@320 137
Chris@320 138 protected:
Chris@328 139 TransformId m_id; // pluginid:output, that is type:soname:label:output
Chris@328 140
Chris@328 141 static QString createIdentifier
Chris@328 142 (QString type, QString soName, QString label, QString output);
Chris@320 143
Chris@328 144 static void parseIdentifier
Chris@328 145 (QString identifier,
Chris@328 146 QString &type, QString &soName, QString &label, QString &output);
Chris@328 147
Chris@400 148 template <typename A, typename B>
Chris@400 149 bool mapLessThan(const std::map<A, B> &a, const std::map<A, B> &b) const {
Chris@400 150 // Return true if a is "less than" b. Ordering doesn't have
Chris@400 151 // to be meaningful, just consistent.
Chris@400 152 typename std::map<A, B>::const_iterator i;
Chris@400 153 typename std::map<A, B>::const_iterator j;
Chris@400 154 for (i = a.begin(), j = b.begin(); i != a.end(); ++i) {
Chris@400 155 if (j == b.end()) return false; // a is longer than b
Chris@400 156 if (i->first != j->first) return i->first < j->first;
Chris@400 157 if (i->second != j->second) return i->second < j->second;
Chris@400 158 }
Chris@400 159 if (j != b.end()) return true; // a is shorter than b
Chris@400 160 return false; // equal
Chris@400 161 }
Chris@400 162
Chris@328 163 ParameterMap m_parameters;
Chris@328 164 ConfigurationMap m_configuration;
Chris@366 165 QString m_pluginVersion;
Chris@328 166 QString m_program;
Chris@328 167 size_t m_stepSize;
Chris@328 168 size_t m_blockSize;
Chris@328 169 WindowType m_windowType;
Chris@350 170 RealTime m_startTime;
Chris@350 171 RealTime m_duration;
Chris@328 172 float m_sampleRate;
Chris@320 173 };
Chris@320 174
Chris@320 175 #endif
Chris@328 176