comparison plugin/transform/Transform.h @ 328:21bd032ae791

* Introduce new Transform class which contains data necessary to describe the context for a plugin -- the plugin's name and output, the step/block size etc (formerly spread across ExecutionContext and TransformFactory). Other code hasn't been updated to use this yet. * Rename existing Transform stuff to Transformers (because they run Transforms) I'm still not 100% sure about this change, don't rely on it.
author Chris Cannam
date Mon, 05 Nov 2007 15:31:06 +0000
parents 32e50b620a6c
children d7c41483af8f 94fc0591ea43
comparison
equal deleted inserted replaced
327:1d656dcda8ef 328:21bd032ae791
2 2
3 /* 3 /*
4 Sonic Visualiser 4 Sonic Visualiser
5 An audio file viewer and annotation editor. 5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London. 6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam. 7 This file copyright 2006-2007 Chris Cannam and QMUL.
8 8
9 This program is free software; you can redistribute it and/or 9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as 10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
14 */ 14 */
15 15
16 #ifndef _TRANSFORM_H_ 16 #ifndef _TRANSFORM_H_
17 #define _TRANSFORM_H_ 17 #define _TRANSFORM_H_
18 18
19 #include "base/Thread.h" 19 #include "base/XmlExportable.h"
20 #include "base/Window.h"
20 21
21 #include "data/model/Model.h" 22 #include <vamp-sdk/RealTime.h>
23
24 #include <QString>
22 25
23 typedef QString TransformId; 26 typedef QString TransformId;
24 27
25 /** 28 namespace Vamp {
26 * A Transform turns one data model into another. 29 class PluginBase;
27 * 30 }
28 * Typically in this application, a Transform might have a
29 * DenseTimeValueModel as its input (e.g. an audio waveform) and a
30 * SparseOneDimensionalModel (e.g. detected beats) as its output.
31 *
32 * The Transform typically runs in the background, as a separate
33 * thread populating the output model. The model is available to the
34 * user of the Transform immediately, but may be initially empty until
35 * the background thread has populated it.
36 */
37 31
38 class Transform : public Thread 32 class Transform : public XmlExportable
39 { 33 {
40 public: 34 public:
35 Transform();
41 virtual ~Transform(); 36 virtual ~Transform();
42 37
43 // Just a hint to the processing thread that it should give up. 38 void setIdentifier(TransformId id) { m_id = id; }
44 // Caller should still wait() and/or delete the transform before 39 TransformId getIdentifier() const { return m_id; }
45 // assuming its input and output models are no longer required. 40
46 void abandon() { m_abandoned = true; } 41 void setPlugin(QString pluginIdentifier);
42 void setOutput(QString output);
47 43
48 Model *getInputModel() { return m_input; } 44 enum Type { FeatureExtraction, RealTimeEffect };
49 Model *getOutputModel() { return m_output; } 45
50 Model *detachOutputModel() { m_detached = true; return m_output; } 46 Type getType() const;
47 QString getPluginIdentifier() const;
48 QString getOutput() const;
49
50 typedef std::map<QString, float> ParameterMap;
51
52 ParameterMap getParameters() const { return m_parameters; }
53 void setParameters(const ParameterMap &pm) { m_parameters = pm; }
54
55 typedef std::map<QString, QString> ConfigurationMap;
56
57 ConfigurationMap getConfiguration() const { return m_configuration; }
58 void setConfiguration(const ConfigurationMap &cm) { m_configuration = cm; }
59
60 QString getProgram() const { return m_program; }
61 void setProgram(QString program) { m_program = program; }
62
63 size_t getStepSize() const { return m_stepSize; }
64 void setStepSize(size_t s) { m_stepSize = s; }
65
66 size_t getBlockSize() const { return m_blockSize; }
67 void setBlockSize(size_t s) { m_blockSize = s; }
68
69 WindowType getWindowType() const { return m_windowType; }
70 void setWindowType(WindowType type) { m_windowType = type; }
71
72 Vamp::RealTime getStartTime() const { return m_startTime; }
73 void setStartTime(Vamp::RealTime t) { m_startTime = t; }
74
75 Vamp::RealTime getDuration() const { return m_duration; } // 0 -> all
76 void setDuration(Vamp::RealTime d) { m_duration = d; }
77
78 float getSampleRate() const { return m_sampleRate; } // 0 -> as input
79 void setSampleRate(float rate) { m_sampleRate = rate; }
80
81 void toXml(QTextStream &stream, QString indent = "",
82 QString extraAttributes = "") const;
83
84 static Transform fromXmlString(QString xml);
51 85
52 protected: 86 protected:
53 Transform(Model *m); 87 TransformId m_id; // pluginid:output, that is type:soname:label:output
88
89 static QString createIdentifier
90 (QString type, QString soName, QString label, QString output);
54 91
55 Model *m_input; // I don't own this 92 static void parseIdentifier
56 Model *m_output; // I own this, unless... 93 (QString identifier,
57 bool m_detached; // ... this is true. 94 QString &type, QString &soName, QString &label, QString &output);
58 bool m_abandoned; 95
96 ParameterMap m_parameters;
97 ConfigurationMap m_configuration;
98 QString m_program;
99 size_t m_stepSize;
100 size_t m_blockSize;
101 WindowType m_windowType;
102 Vamp::RealTime m_startTime;
103 Vamp::RealTime m_duration;
104 float m_sampleRate;
59 }; 105 };
60 106
61 #endif 107 #endif
108