comparison plugin/RealTimePluginInstance.h @ 0:da6937383da8

initial import
author Chris Cannam
date Tue, 10 Jan 2006 16:33:16 +0000
parents
children d86891498eef
comparison
equal deleted inserted replaced
-1:000000000000 0:da6937383da8
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 A waveform viewer and audio annotation editor.
5 Chris Cannam, Queen Mary University of London, 2005
6
7 This is experimental software. Not for distribution.
8 */
9
10 /*
11 This is a modified version of a source file from the
12 Rosegarden MIDI and audio sequencer and notation editor.
13 This file copyright 2000-2005 Chris Cannam.
14 */
15
16 #ifndef _REALTIME_PLUGIN_INSTANCE_H_
17 #define _REALTIME_PLUGIN_INSTANCE_H_
18
19 #include <QString>
20 #include <QStringList>
21 #include <vector>
22
23 #include "base/RealTime.h"
24
25 class RealTimePluginFactory;
26
27 /**
28 * RealTimePluginInstance is a very trivial interface that an audio
29 * process can use to refer to an instance of a plugin without needing
30 * to know what type of plugin it is.
31 *
32 * The audio code calls run() on an instance that has been passed to
33 * it, and assumes that the passing code has already initialised the
34 * plugin, connected its inputs and outputs and so on, and that there
35 * is an understanding in place about the sizes of the buffers in use
36 * by the plugin. All of this depends on the subclass implementation.
37 */
38
39 // These names are taken from LADSPA, but the values are not
40 // guaranteed to match
41
42 namespace PortType { // ORable
43 static const int Input = 1;
44 static const int Output = 2;
45 static const int Control = 4;
46 static const int Audio = 8;
47 }
48
49 namespace PortHint { // ORable
50 static const int NoHint = 0;
51 static const int Toggled = 1;
52 static const int Integer = 2;
53 static const int Logarithmic = 4;
54 static const int SampleRate = 8;
55 }
56
57 class RealTimePluginInstance
58 {
59 public:
60 typedef float sample_t;
61
62 virtual ~RealTimePluginInstance();
63
64 virtual bool isOK() const = 0;
65
66 virtual QString getIdentifier() const = 0;
67
68 /**
69 * Run for one block, starting at the given time. The start time
70 * may be of interest to synths etc that may have queued events
71 * waiting. Other plugins can ignore it.
72 */
73 virtual void run(const RealTime &blockStartTime) = 0;
74
75 virtual size_t getBufferSize() const = 0;
76
77 virtual size_t getAudioInputCount() const = 0;
78 virtual size_t getAudioOutputCount() const = 0;
79
80 virtual sample_t **getAudioInputBuffers() = 0;
81 virtual sample_t **getAudioOutputBuffers() = 0;
82
83 virtual QStringList getPrograms() const { return QStringList(); }
84 virtual QString getCurrentProgram() const { return QString(); }
85 virtual QString getProgram(int /* bank */, int /* program */) const { return QString(); }
86 virtual unsigned long getProgram(QString /* name */) const { return 0; } // bank << 16 + program
87 virtual void selectProgram(QString) { }
88
89 virtual unsigned int getParameterCount() const = 0;
90 virtual void setParameterValue(unsigned int parameter, float value) = 0;
91 virtual float getParameterValue(unsigned int parameter) const = 0;
92 virtual float getParameterDefault(unsigned int parameter) const = 0;
93
94 virtual QString configure(QString /* key */, QString /* value */) { return QString(); }
95
96 virtual void sendEvent(const RealTime & /* eventTime */,
97 const void * /* event */) { }
98
99 virtual bool isBypassed() const = 0;
100 virtual void setBypassed(bool value) = 0;
101
102 // This should be called after setup, but while not actually playing.
103 virtual size_t getLatency() = 0;
104
105 virtual void silence() = 0;
106 virtual void discardEvents() { }
107 virtual void setIdealChannelCount(size_t channels) = 0; // must also silence(); may also re-instantiate
108
109 void setFactory(RealTimePluginFactory *f) { m_factory = f; } // ew
110
111 protected:
112 RealTimePluginInstance(RealTimePluginFactory *factory, QString identifier) :
113 m_factory(factory), m_identifier(identifier) { }
114
115 RealTimePluginFactory *m_factory;
116 QString m_identifier;
117
118 friend class PluginFactory;
119 };
120
121
122 #endif