annotate plugin/transform/Transform.h @ 383:94fc0591ea43 1.2-stable

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