comparison plugin/RealTimePluginInstance.h @ 0:fc9323a41f5a

start base : Sonic Visualiser sv1-1.0rc1
author lbajardsilogic
date Fri, 11 May 2007 09:08:14 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:fc9323a41f5a
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
14
15 /*
16 This is a modified version of a source file from the
17 Rosegarden MIDI and audio sequencer and notation editor.
18 This file copyright 2000-2006 Chris Cannam.
19 */
20
21 #ifndef _REALTIME_PLUGIN_INSTANCE_H_
22 #define _REALTIME_PLUGIN_INSTANCE_H_
23
24 #include "vamp-sdk/PluginBase.h"
25 #include "vamp-sdk/RealTime.h"
26
27 #include <QString>
28 #include <QStringList>
29 #include <vector>
30 #include <string>
31 #include <map>
32
33 class RealTimePluginFactory;
34
35 /**
36 * RealTimePluginInstance is an interface that an audio process can
37 * use to refer to an instance of a plugin without needing to know
38 * what type of plugin it is.
39 *
40 * The audio code calls run() on an instance that has been passed to
41 * it, and assumes that the passing code has already initialised the
42 * plugin, connected its inputs and outputs and so on, and that there
43 * is an understanding in place about the sizes of the buffers in use
44 * by the plugin. All of this depends on the subclass implementation.
45 *
46 * The PluginInstance base class includes additional abstract methods
47 * which the subclass of RealTimePluginInstance must implement.
48 */
49
50 /*
51 * N.B. RealTimePluginInstance, RealTimePluginFactory and their
52 * subclasses are terrible code. They've been reused, cut and pasted
53 * and mangled too many times to fit too many different uses, and
54 * could do with a good tidy.
55 */
56
57 // These names are taken from LADSPA, but the values are not
58 // guaranteed to match
59
60 namespace PortType { // ORable
61 static const int Input = 1;
62 static const int Output = 2;
63 static const int Control = 4;
64 static const int Audio = 8;
65 }
66
67 namespace PortHint { // ORable
68 static const int NoHint = 0;
69 static const int Toggled = 1;
70 static const int Integer = 2;
71 static const int Logarithmic = 4;
72 static const int SampleRate = 8;
73 }
74
75 class RealTimePluginInstance : public Vamp::PluginBase
76 {
77 public:
78 typedef float sample_t;
79
80 virtual ~RealTimePluginInstance();
81
82 virtual bool isOK() const = 0;
83
84 virtual QString getPluginIdentifier() const = 0;
85
86 /**
87 * Run for one block, starting at the given time. The start time
88 * may be of interest to synths etc that may have queued events
89 * waiting. Other plugins can ignore it.
90 */
91 virtual void run(const Vamp::RealTime &blockStartTime) = 0;
92
93 virtual size_t getBufferSize() const = 0;
94
95 virtual size_t getAudioInputCount() const = 0;
96 virtual size_t getAudioOutputCount() const = 0;
97
98 virtual sample_t **getAudioInputBuffers() = 0;
99 virtual sample_t **getAudioOutputBuffers() = 0;
100
101 // Control inputs are known as parameters here
102 virtual size_t getControlOutputCount() const = 0;
103 virtual float getControlOutputValue(size_t n) const = 0;
104
105 // virtual QStringList getPrograms() const { return QStringList(); }
106 // virtual QString getCurrentProgram() const { return QString(); }
107 virtual std::string getProgram(int /* bank */, int /* program */) const { return std::string(); }
108 // virtual unsigned long getProgram(QString /* name */) const { return 0; } // bank << 16 + program
109 // virtual void selectProgram(QString) { }
110
111 virtual unsigned int getParameterCount() const = 0;
112 virtual void setParameterValue(unsigned int parameter, float value) = 0;
113 virtual float getParameterValue(unsigned int parameter) const = 0;
114 virtual float getParameterDefault(unsigned int parameter) const = 0;
115
116 virtual std::string configure(std::string /* key */, std::string /* value */) { return std::string(); }
117
118 virtual void sendEvent(const Vamp::RealTime & /* eventTime */,
119 const void * /* event */) { }
120 virtual void clearEvents() { }
121
122 virtual bool isBypassed() const = 0;
123 virtual void setBypassed(bool value) = 0;
124
125 // This should be called after setup, but while not actually playing.
126 virtual size_t getLatency() = 0;
127
128 virtual void silence() = 0;
129 virtual void discardEvents() { }
130 virtual void setIdealChannelCount(size_t channels) = 0; // must also silence(); may also re-instantiate
131
132 void setFactory(RealTimePluginFactory *f) { m_factory = f; } // ew
133
134 virtual std::string getType() const { return "Real-Time Plugin"; }
135
136 virtual std::map<std::string, std::string> getConfigurePairs() {
137 return m_configurationData;
138 }
139
140 protected:
141 RealTimePluginInstance(RealTimePluginFactory *factory, QString identifier) :
142 m_factory(factory), m_identifier(identifier) { }
143
144 RealTimePluginFactory *m_factory;
145 QString m_identifier;
146
147 std::map<std::string, std::string> m_configurationData;
148
149 friend class PluginFactory;
150 };
151
152
153 #endif