svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006-2007 Chris Cannam and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _TRANSFORM_H_ 00017 #define _TRANSFORM_H_ 00018 00019 #include "base/XmlExportable.h" 00020 #include "base/Window.h" 00021 #include "base/RealTime.h" 00022 00023 #include <vamp-hostsdk/PluginBase.h> 00024 00025 #include <QString> 00026 00027 #include <map> 00028 #include <vector> 00029 00030 typedef QString TransformId; 00031 00032 class QXmlAttributes; 00033 00034 class Transform : public XmlExportable 00035 { 00036 public: 00045 Transform(); 00046 00051 Transform(QString xml); 00052 00053 virtual ~Transform(); 00054 00059 bool operator==(const Transform &) const; 00060 00065 bool operator<(const Transform &) const; 00066 00067 void setIdentifier(TransformId id); 00068 TransformId getIdentifier() const; 00069 00070 enum Type { FeatureExtraction, RealTimeEffect }; 00071 00072 Type getType() const; 00073 QString getPluginIdentifier() const; 00074 QString getOutput() const; 00075 00076 void setPluginIdentifier(QString pluginIdentifier); 00077 void setOutput(QString output); 00078 00079 // Turn a plugin ID and output name into a transform ID. Note 00080 // that our pluginIdentifier is the same thing as the Vamp SDK's 00081 // PluginLoader::PluginKey. 00082 static TransformId getIdentifierForPluginOutput(QString pluginIdentifier, 00083 QString output = ""); 00084 00085 typedef std::map<QString, float> ParameterMap; 00086 00087 const ParameterMap &getParameters() const; 00088 void setParameters(const ParameterMap &pm); 00089 void setParameter(QString name, float value); 00090 00091 typedef std::map<QString, QString> ConfigurationMap; 00092 00093 const ConfigurationMap &getConfiguration() const; 00094 void setConfiguration(const ConfigurationMap &cm); 00095 void setConfigurationValue(QString name, QString value); 00096 00097 enum SummaryType { 00098 00099 // This is the same as Vamp::PluginSummarisingAdapter::SummaryType 00100 // except with NoSummary instead of UnknownSummaryType 00101 00102 Minimum = 0, 00103 Maximum = 1, 00104 Mean = 2, 00105 Median = 3, 00106 Mode = 4, 00107 Sum = 5, 00108 Variance = 6, 00109 StandardDeviation = 7, 00110 Count = 8, 00111 00112 NoSummary = 999 00113 }; 00114 SummaryType getSummaryType() const; 00115 void setSummaryType(SummaryType type); 00116 00117 QString getPluginVersion() const; 00118 void setPluginVersion(QString version); 00119 00120 QString getProgram() const; 00121 void setProgram(QString program); 00122 00123 int getStepSize() const; 00124 void setStepSize(int s); 00125 00126 int getBlockSize() const; 00127 void setBlockSize(int s); 00128 00129 WindowType getWindowType() const; 00130 void setWindowType(WindowType type); 00131 00132 RealTime getStartTime() const; 00133 void setStartTime(RealTime t); 00134 00135 RealTime getDuration() const; // 0 -> all 00136 void setDuration(RealTime d); 00137 00138 float getSampleRate() const; // 0 -> as input 00139 void setSampleRate(float rate); 00140 00141 void toXml(QTextStream &stream, QString indent = "", 00142 QString extraAttributes = "") const; 00143 00157 void setFromXmlAttributes(const QXmlAttributes &); 00158 00159 static SummaryType stringToSummaryType(QString); 00160 static QString summaryTypeToString(SummaryType); 00161 00162 protected: 00163 TransformId m_id; // pluginid:output, that is type:soname:label:output 00164 00165 static QString createIdentifier 00166 (QString type, QString soName, QString label, QString output); 00167 00168 static void parseIdentifier 00169 (QString identifier, 00170 QString &type, QString &soName, QString &label, QString &output); 00171 00172 template <typename A, typename B> 00173 bool mapLessThan(const std::map<A, B> &a, const std::map<A, B> &b) const { 00174 // Return true if a is "less than" b. Ordering doesn't have 00175 // to be meaningful, just consistent. 00176 typename std::map<A, B>::const_iterator i; 00177 typename std::map<A, B>::const_iterator j; 00178 for (i = a.begin(), j = b.begin(); i != a.end(); ++i) { 00179 if (j == b.end()) return false; // a is longer than b 00180 if (i->first != j->first) return i->first < j->first; 00181 if (i->second != j->second) return i->second < j->second; 00182 } 00183 if (j != b.end()) return true; // a is shorter than b 00184 return false; // equal 00185 } 00186 00187 ParameterMap m_parameters; 00188 ConfigurationMap m_configuration; 00189 SummaryType m_summaryType; 00190 QString m_pluginVersion; 00191 QString m_program; 00192 int m_stepSize; 00193 int m_blockSize; 00194 WindowType m_windowType; 00195 RealTime m_startTime; 00196 RealTime m_duration; 00197 float m_sampleRate; 00198 }; 00199 00200 typedef std::vector<Transform> Transforms; 00201 00202 #endif 00203