Chris@320: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@320: Chris@320: /* Chris@320: Sonic Visualiser Chris@320: An audio file viewer and annotation editor. Chris@320: Centre for Digital Music, Queen Mary, University of London. Chris@328: This file copyright 2006-2007 Chris Cannam and QMUL. Chris@320: Chris@320: This program is free software; you can redistribute it and/or Chris@320: modify it under the terms of the GNU General Public License as Chris@320: published by the Free Software Foundation; either version 2 of the Chris@320: License, or (at your option) any later version. See the file Chris@320: COPYING included with this distribution for more information. Chris@320: */ Chris@320: Chris@320: #ifndef _TRANSFORM_H_ Chris@320: #define _TRANSFORM_H_ Chris@320: Chris@328: #include "base/XmlExportable.h" Chris@328: #include "base/Window.h" Chris@383: #include "base/RealTime.h" Chris@328: Chris@328: #include Chris@320: Chris@320: typedef QString TransformId; Chris@320: Chris@383: class QXmlAttributes; Chris@383: Chris@328: namespace Vamp { Chris@328: class PluginBase; Chris@328: } Chris@320: Chris@328: class Transform : public XmlExportable Chris@320: { Chris@320: public: Chris@383: /** Chris@383: * Construct a new Transform with default data and no identifier. Chris@383: * The Transform object will be meaningless until some data and an Chris@383: * identifier have been set on it. Chris@383: * Chris@383: * To construct a Transform for use with a particular transform Chris@383: * identifier, use TransformFactory::getDefaultTransformFor. Chris@383: */ Chris@328: Transform(); Chris@383: Chris@383: /** Chris@383: * Construct a Transform by parsing the given XML data string. Chris@383: * This is the inverse of toXml. Chris@383: */ Chris@383: Transform(QString xml); Chris@383: Chris@320: virtual ~Transform(); Chris@320: Chris@383: /** Chris@383: * Compare two Transforms. They only compare equal if every data Chris@383: * element matches. Chris@383: */ Chris@383: bool operator==(const Transform &); Chris@383: Chris@383: void setIdentifier(TransformId id); Chris@383: TransformId getIdentifier() const; Chris@320: Chris@328: enum Type { FeatureExtraction, RealTimeEffect }; Chris@328: Chris@328: Type getType() const; Chris@328: QString getPluginIdentifier() const; Chris@328: QString getOutput() const; Chris@383: Chris@383: void setPluginIdentifier(QString pluginIdentifier); Chris@383: void setOutput(QString output); Chris@383: Chris@383: // Turn a plugin ID and output name into a transform ID. Note Chris@383: // that our pluginIdentifier is the same thing as the Vamp SDK's Chris@383: // PluginLoader::PluginKey. Chris@383: static TransformId getIdentifierForPluginOutput(QString pluginIdentifier, Chris@383: QString output = ""); Chris@328: Chris@328: typedef std::map ParameterMap; Chris@328: Chris@383: const ParameterMap &getParameters() const; Chris@383: void setParameters(const ParameterMap &pm); Chris@383: void setParameter(QString name, float value); Chris@328: Chris@328: typedef std::map ConfigurationMap; Chris@328: Chris@383: const ConfigurationMap &getConfiguration() const; Chris@383: void setConfiguration(const ConfigurationMap &cm); Chris@383: void setConfigurationValue(QString name, QString value); Chris@328: Chris@383: QString getPluginVersion() const; Chris@383: void setPluginVersion(QString version); Chris@383: Chris@383: QString getProgram() const; Chris@383: void setProgram(QString program); Chris@328: Chris@383: size_t getStepSize() const; Chris@383: void setStepSize(size_t s); Chris@328: Chris@383: size_t getBlockSize() const; Chris@383: void setBlockSize(size_t s); Chris@328: Chris@383: WindowType getWindowType() const; Chris@383: void setWindowType(WindowType type); Chris@383: Chris@383: RealTime getStartTime() const; Chris@383: void setStartTime(RealTime t); Chris@383: Chris@383: RealTime getDuration() const; // 0 -> all Chris@383: void setDuration(RealTime d); Chris@383: Chris@383: float getSampleRate() const; // 0 -> as input Chris@383: void setSampleRate(float rate); Chris@328: Chris@328: void toXml(QTextStream &stream, QString indent = "", Chris@328: QString extraAttributes = "") const; Chris@328: Chris@383: /** Chris@383: * Set the main transform data from the given XML attributes. Chris@383: * This does not set the parameters or configuration, which are Chris@383: * exported to separate XML elements rather than attributes of the Chris@383: * transform element. Chris@383: * Chris@383: * Note that this only sets those attributes which are actually Chris@383: * present in the argument. Any attributes not defined in the Chris@383: * attribute will remain unchanged in the Transform. If your aim Chris@383: * is to create a transform exactly matching the given attributes, Chris@383: * ensure you start from an empty transform rather than one that Chris@383: * has already been configured. Chris@383: */ Chris@383: void setFromXmlAttributes(const QXmlAttributes &); Chris@320: Chris@320: protected: Chris@328: TransformId m_id; // pluginid:output, that is type:soname:label:output Chris@328: Chris@328: static QString createIdentifier Chris@328: (QString type, QString soName, QString label, QString output); Chris@320: Chris@328: static void parseIdentifier Chris@328: (QString identifier, Chris@328: QString &type, QString &soName, QString &label, QString &output); Chris@328: Chris@328: ParameterMap m_parameters; Chris@328: ConfigurationMap m_configuration; Chris@383: QString m_pluginVersion; Chris@328: QString m_program; Chris@328: size_t m_stepSize; Chris@328: size_t m_blockSize; Chris@328: WindowType m_windowType; Chris@383: RealTime m_startTime; Chris@383: RealTime m_duration; Chris@328: float m_sampleRate; Chris@320: }; Chris@320: Chris@320: #endif Chris@328: