annotate transform/Transform.h @ 1290:fa574c909c3d 3.0-integration

Add MAD_BUFFER_GUARD padding at end of mp3 buffer, in order to ensure last frame is decoded successfully (otherwise the decoded audio is truncated). Another thing learned from madplay.
author Chris Cannam
date Thu, 24 Nov 2016 17:06:31 +0000
parents d094598f84bd
children c01cbe41aeb5
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@848 28 #include <vector>
Chris@400 29
Chris@320 30 typedef QString TransformId;
Chris@320 31
Chris@350 32 class QXmlAttributes;
Chris@350 33
Chris@328 34 class Transform : public XmlExportable
Chris@320 35 {
Chris@320 36 public:
Chris@350 37 /**
Chris@350 38 * Construct a new Transform with default data and no identifier.
Chris@350 39 * The Transform object will be meaningless until some data and an
Chris@350 40 * identifier have been set on it.
Chris@350 41 *
Chris@350 42 * To construct a Transform for use with a particular transform
Chris@350 43 * identifier, use TransformFactory::getDefaultTransformFor.
Chris@350 44 */
Chris@328 45 Transform();
Chris@350 46
Chris@350 47 /**
Chris@350 48 * Construct a Transform by parsing the given XML data string.
Chris@1163 49 * This is the inverse of toXml. If this fails, getErrorString()
Chris@1163 50 * will return a non-empty string.
Chris@350 51 */
Chris@350 52 Transform(QString xml);
Chris@350 53
Chris@320 54 virtual ~Transform();
Chris@320 55
Chris@350 56 /**
Chris@350 57 * Compare two Transforms. They only compare equal if every data
Chris@350 58 * element matches.
Chris@350 59 */
Chris@400 60 bool operator==(const Transform &) const;
Chris@400 61
Chris@400 62 /**
Chris@400 63 * Order two Transforms, so that they can be used as keys in
Chris@400 64 * containers.
Chris@400 65 */
Chris@400 66 bool operator<(const Transform &) const;
Chris@350 67
Chris@350 68 void setIdentifier(TransformId id);
Chris@350 69 TransformId getIdentifier() const;
Chris@320 70
Chris@1138 71 enum Type { FeatureExtraction, RealTimeEffect, UnknownType };
Chris@328 72
Chris@328 73 Type getType() const;
Chris@328 74 QString getPluginIdentifier() const;
Chris@328 75 QString getOutput() const;
Chris@353 76
Chris@353 77 void setPluginIdentifier(QString pluginIdentifier);
Chris@353 78 void setOutput(QString output);
Chris@353 79
Chris@353 80 // Turn a plugin ID and output name into a transform ID. Note
Chris@353 81 // that our pluginIdentifier is the same thing as the Vamp SDK's
Chris@353 82 // PluginLoader::PluginKey.
Chris@353 83 static TransformId getIdentifierForPluginOutput(QString pluginIdentifier,
Chris@353 84 QString output = "");
Chris@328 85
Chris@328 86 typedef std::map<QString, float> ParameterMap;
Chris@328 87
Chris@350 88 const ParameterMap &getParameters() const;
Chris@350 89 void setParameters(const ParameterMap &pm);
Chris@350 90 void setParameter(QString name, float value);
Chris@328 91
Chris@328 92 typedef std::map<QString, QString> ConfigurationMap;
Chris@328 93
Chris@350 94 const ConfigurationMap &getConfiguration() const;
Chris@350 95 void setConfiguration(const ConfigurationMap &cm);
Chris@350 96 void setConfigurationValue(QString name, QString value);
Chris@328 97
Chris@508 98 enum SummaryType {
Chris@508 99
Chris@508 100 // This is the same as Vamp::PluginSummarisingAdapter::SummaryType
Chris@508 101 // except with NoSummary instead of UnknownSummaryType
Chris@508 102
Chris@508 103 Minimum = 0,
Chris@508 104 Maximum = 1,
Chris@508 105 Mean = 2,
Chris@508 106 Median = 3,
Chris@508 107 Mode = 4,
Chris@508 108 Sum = 5,
Chris@508 109 Variance = 6,
Chris@508 110 StandardDeviation = 7,
Chris@508 111 Count = 8,
Chris@508 112
Chris@508 113 NoSummary = 999
Chris@508 114 };
Chris@508 115 SummaryType getSummaryType() const;
Chris@508 116 void setSummaryType(SummaryType type);
Chris@508 117
Chris@366 118 QString getPluginVersion() const;
Chris@366 119 void setPluginVersion(QString version);
Chris@366 120
Chris@350 121 QString getProgram() const;
Chris@350 122 void setProgram(QString program);
Chris@328 123
Chris@930 124 int getStepSize() const;
Chris@930 125 void setStepSize(int s);
Chris@328 126
Chris@930 127 int getBlockSize() const;
Chris@930 128 void setBlockSize(int s);
Chris@328 129
Chris@350 130 WindowType getWindowType() const;
Chris@350 131 void setWindowType(WindowType type);
Chris@350 132
Chris@350 133 RealTime getStartTime() const;
Chris@350 134 void setStartTime(RealTime t);
Chris@350 135
Chris@350 136 RealTime getDuration() const; // 0 -> all
Chris@350 137 void setDuration(RealTime d);
Chris@350 138
Chris@1047 139 sv_samplerate_t getSampleRate() const; // 0 -> as input
Chris@1047 140 void setSampleRate(sv_samplerate_t rate);
Chris@328 141
Chris@328 142 void toXml(QTextStream &stream, QString indent = "",
Chris@328 143 QString extraAttributes = "") const;
Chris@328 144
Chris@350 145 /**
Chris@350 146 * Set the main transform data from the given XML attributes.
Chris@350 147 * This does not set the parameters or configuration, which are
Chris@350 148 * exported to separate XML elements rather than attributes of the
Chris@350 149 * transform element.
Chris@366 150 *
Chris@366 151 * Note that this only sets those attributes which are actually
Chris@366 152 * present in the argument. Any attributes not defined in the
Chris@366 153 * attribute will remain unchanged in the Transform. If your aim
Chris@366 154 * is to create a transform exactly matching the given attributes,
Chris@366 155 * ensure you start from an empty transform rather than one that
Chris@366 156 * has already been configured.
Chris@350 157 */
Chris@350 158 void setFromXmlAttributes(const QXmlAttributes &);
Chris@320 159
Chris@1163 160 QString getErrorString() const { return m_errorString; }
Chris@1163 161
Chris@508 162 static SummaryType stringToSummaryType(QString);
Chris@508 163 static QString summaryTypeToString(SummaryType);
Chris@508 164
Chris@320 165 protected:
Chris@328 166 TransformId m_id; // pluginid:output, that is type:soname:label:output
Chris@328 167
Chris@328 168 static QString createIdentifier
Chris@328 169 (QString type, QString soName, QString label, QString output);
Chris@320 170
Chris@328 171 static void parseIdentifier
Chris@328 172 (QString identifier,
Chris@328 173 QString &type, QString &soName, QString &label, QString &output);
Chris@328 174
Chris@400 175 template <typename A, typename B>
Chris@400 176 bool mapLessThan(const std::map<A, B> &a, const std::map<A, B> &b) const {
Chris@400 177 // Return true if a is "less than" b. Ordering doesn't have
Chris@400 178 // to be meaningful, just consistent.
Chris@400 179 typename std::map<A, B>::const_iterator i;
Chris@400 180 typename std::map<A, B>::const_iterator j;
Chris@400 181 for (i = a.begin(), j = b.begin(); i != a.end(); ++i) {
Chris@400 182 if (j == b.end()) return false; // a is longer than b
Chris@400 183 if (i->first != j->first) return i->first < j->first;
Chris@400 184 if (i->second != j->second) return i->second < j->second;
Chris@400 185 }
Chris@400 186 if (j != b.end()) return true; // a is shorter than b
Chris@400 187 return false; // equal
Chris@400 188 }
Chris@400 189
Chris@328 190 ParameterMap m_parameters;
Chris@328 191 ConfigurationMap m_configuration;
Chris@508 192 SummaryType m_summaryType;
Chris@366 193 QString m_pluginVersion;
Chris@328 194 QString m_program;
Chris@930 195 int m_stepSize;
Chris@930 196 int m_blockSize;
Chris@328 197 WindowType m_windowType;
Chris@350 198 RealTime m_startTime;
Chris@350 199 RealTime m_duration;
Chris@1047 200 sv_samplerate_t m_sampleRate;
Chris@1163 201 QString m_errorString;
Chris@320 202 };
Chris@320 203
Chris@848 204 typedef std::vector<Transform> Transforms;
Chris@848 205
Chris@320 206 #endif
Chris@328 207