comparison plugin/LADSPAPluginInstance.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 and Richard Bown.
14 */
15
16 #ifndef _LADSPAPLUGININSTANCE_H_
17 #define _LADSPAPLUGININSTANCE_H_
18
19 #include <vector>
20 #include <set>
21 #include <QString>
22
23 #include "api/ladspa.h"
24 #include "RealTimePluginInstance.h"
25
26 // LADSPA plugin instance. LADSPA is a variable block size API, but
27 // for one reason and another it's more convenient to use a fixed
28 // block size in this wrapper.
29 //
30 class LADSPAPluginInstance : public RealTimePluginInstance
31 {
32 public:
33 virtual ~LADSPAPluginInstance();
34
35 virtual bool isOK() const { return m_instanceHandles.size() != 0; }
36
37 int getClientId() const { return m_client; }
38 virtual QString getIdentifier() const { return m_identifier; }
39 int getPosition() const { return m_position; }
40
41 virtual void run(const RealTime &rt);
42
43 virtual unsigned int getParameterCount() const;
44 virtual void setParameterValue(unsigned int parameter, float value);
45 virtual float getParameterValue(unsigned int parameter) const;
46 virtual float getParameterDefault(unsigned int parameter) const;
47
48 virtual size_t getBufferSize() const { return m_blockSize; }
49 virtual size_t getAudioInputCount() const { return m_instanceCount * m_audioPortsIn.size(); }
50 virtual size_t getAudioOutputCount() const { return m_instanceCount * m_audioPortsOut.size(); }
51 virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; }
52 virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; }
53
54 virtual bool isBypassed() const { return m_bypassed; }
55 virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; }
56
57 virtual size_t getLatency();
58
59 virtual void silence();
60 virtual void setIdealChannelCount(size_t channels); // may re-instantiate
61
62 protected:
63 // To be constructed only by LADSPAPluginFactory
64 friend class LADSPAPluginFactory;
65
66 // Constructor that creates the buffers internally
67 //
68 LADSPAPluginInstance(RealTimePluginFactory *factory,
69 int client,
70 QString identifier,
71 int position,
72 unsigned long sampleRate,
73 size_t blockSize,
74 int idealChannelCount,
75 const LADSPA_Descriptor* descriptor);
76
77 // Constructor that uses shared buffers
78 //
79 LADSPAPluginInstance(RealTimePluginFactory *factory,
80 int client,
81 QString identifier,
82 int position,
83 unsigned long sampleRate,
84 size_t blockSize,
85 sample_t **inputBuffers,
86 sample_t **outputBuffers,
87 const LADSPA_Descriptor* descriptor);
88
89 void init(int idealChannelCount = 0);
90 void instantiate(unsigned long sampleRate);
91 void cleanup();
92 void activate();
93 void deactivate();
94
95 // Connection of data (and behind the scenes control) ports
96 //
97 void connectPorts();
98
99 int m_client;
100 int m_position;
101 std::vector<LADSPA_Handle> m_instanceHandles;
102 size_t m_instanceCount;
103 const LADSPA_Descriptor *m_descriptor;
104
105 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsIn;
106 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsOut;
107
108 std::vector<int> m_audioPortsIn;
109 std::vector<int> m_audioPortsOut;
110
111 size_t m_blockSize;
112 sample_t **m_inputBuffers;
113 sample_t **m_outputBuffers;
114 bool m_ownBuffers;
115 size_t m_sampleRate;
116 float *m_latencyPort;
117 bool m_run;
118
119 bool m_bypassed;
120 };
121
122 #endif // _LADSPAPLUGININSTANCE_H_
123