Chris@0
|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 A waveform viewer and audio annotation editor.
|
Chris@2
|
5 Chris Cannam, Queen Mary University of London, 2005-2006
|
Chris@0
|
6
|
Chris@0
|
7 This is experimental software. Not for distribution.
|
Chris@0
|
8 */
|
Chris@0
|
9
|
Chris@0
|
10 /*
|
Chris@0
|
11 This is a modified version of a source file from the
|
Chris@0
|
12 Rosegarden MIDI and audio sequencer and notation editor.
|
Chris@17
|
13 This file copyright 2000-2006 Chris Cannam.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #ifndef _DSSIPLUGININSTANCE_H_
|
Chris@0
|
17 #define _DSSIPLUGININSTANCE_H_
|
Chris@0
|
18
|
Chris@0
|
19 #define DSSI_API_LEVEL 2
|
Chris@0
|
20
|
Chris@0
|
21 #include <vector>
|
Chris@0
|
22 #include <set>
|
Chris@0
|
23 #include <map>
|
Chris@0
|
24 #include <QString>
|
Chris@0
|
25 #include <QMutex>
|
Chris@0
|
26 #include <QThread>
|
Chris@0
|
27
|
Chris@0
|
28 #include "api/dssi.h"
|
Chris@0
|
29
|
Chris@0
|
30 #include "base/RingBuffer.h"
|
Chris@0
|
31 #include "RealTimePluginInstance.h"
|
Chris@0
|
32 #include "base/Scavenger.h"
|
Chris@0
|
33
|
Chris@0
|
34 class DSSIPluginInstance : public RealTimePluginInstance
|
Chris@0
|
35 {
|
Chris@0
|
36 public:
|
Chris@0
|
37 virtual ~DSSIPluginInstance();
|
Chris@0
|
38
|
Chris@0
|
39 virtual bool isOK() const { return m_instanceHandle != 0; }
|
Chris@0
|
40
|
Chris@0
|
41 int getClientId() const { return m_client; }
|
Chris@0
|
42 virtual QString getIdentifier() const { return m_identifier; }
|
Chris@0
|
43 int getPosition() const { return m_position; }
|
Chris@0
|
44
|
Chris@0
|
45 virtual void run(const RealTime &);
|
Chris@0
|
46
|
Chris@0
|
47 virtual unsigned int getParameterCount() const;
|
Chris@0
|
48 virtual void setParameterValue(unsigned int parameter, float value);
|
Chris@0
|
49 virtual float getParameterValue(unsigned int parameter) const;
|
Chris@0
|
50 virtual float getParameterDefault(unsigned int parameter) const;
|
Chris@0
|
51 virtual QString configure(QString key, QString value);
|
Chris@0
|
52 virtual void sendEvent(const RealTime &eventTime,
|
Chris@0
|
53 const void *event);
|
Chris@10
|
54 virtual void clearEvents();
|
Chris@0
|
55
|
Chris@0
|
56 virtual size_t getBufferSize() const { return m_blockSize; }
|
Chris@0
|
57 virtual size_t getAudioInputCount() const { return m_audioPortsIn.size(); }
|
Chris@0
|
58 virtual size_t getAudioOutputCount() const { return m_idealChannelCount; }
|
Chris@0
|
59 virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; }
|
Chris@0
|
60 virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; }
|
Chris@0
|
61
|
Chris@0
|
62 virtual QStringList getPrograms() const;
|
Chris@0
|
63 virtual QString getCurrentProgram() const;
|
Chris@0
|
64 virtual QString getProgram(int bank, int program) const;
|
Chris@0
|
65 virtual unsigned long getProgram(QString name) const;
|
Chris@0
|
66 virtual void selectProgram(QString program);
|
Chris@0
|
67
|
Chris@0
|
68 virtual bool isBypassed() const { return m_bypassed; }
|
Chris@0
|
69 virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; }
|
Chris@0
|
70
|
Chris@0
|
71 virtual size_t getLatency();
|
Chris@0
|
72
|
Chris@0
|
73 virtual void silence();
|
Chris@0
|
74 virtual void discardEvents();
|
Chris@0
|
75 virtual void setIdealChannelCount(size_t channels); // may re-instantiate
|
Chris@0
|
76
|
Chris@0
|
77 virtual bool isInGroup() const { return m_grouped; }
|
Chris@0
|
78 virtual void detachFromGroup();
|
Chris@0
|
79
|
Chris@0
|
80 protected:
|
Chris@0
|
81 // To be constructed only by DSSIPluginFactory
|
Chris@0
|
82 friend class DSSIPluginFactory;
|
Chris@0
|
83
|
Chris@0
|
84 // Constructor that creates the buffers internally
|
Chris@0
|
85 //
|
Chris@0
|
86 DSSIPluginInstance(RealTimePluginFactory *factory,
|
Chris@0
|
87 int client,
|
Chris@0
|
88 QString identifier,
|
Chris@0
|
89 int position,
|
Chris@0
|
90 unsigned long sampleRate,
|
Chris@0
|
91 size_t blockSize,
|
Chris@0
|
92 int idealChannelCount,
|
Chris@0
|
93 const DSSI_Descriptor* descriptor);
|
Chris@0
|
94
|
Chris@0
|
95 // Constructor that uses shared buffers
|
Chris@0
|
96 //
|
Chris@0
|
97 DSSIPluginInstance(RealTimePluginFactory *factory,
|
Chris@0
|
98 int client,
|
Chris@0
|
99 QString identifier,
|
Chris@0
|
100 int position,
|
Chris@0
|
101 unsigned long sampleRate,
|
Chris@0
|
102 size_t blockSize,
|
Chris@0
|
103 sample_t **inputBuffers,
|
Chris@0
|
104 sample_t **outputBuffers,
|
Chris@0
|
105 const DSSI_Descriptor* descriptor);
|
Chris@0
|
106
|
Chris@0
|
107 void init();
|
Chris@0
|
108 void instantiate(unsigned long sampleRate);
|
Chris@0
|
109 void cleanup();
|
Chris@0
|
110 void activate();
|
Chris@0
|
111 void deactivate();
|
Chris@0
|
112 void connectPorts();
|
Chris@0
|
113
|
Chris@0
|
114 bool handleController(snd_seq_event_t *ev);
|
Chris@0
|
115 void setPortValueFromController(unsigned int portNumber, int controlValue);
|
Chris@0
|
116 void selectProgramAux(QString program, bool backupPortValues);
|
Chris@0
|
117 void checkProgramCache() const;
|
Chris@0
|
118
|
Chris@0
|
119 void initialiseGroupMembership();
|
Chris@0
|
120 void runGrouped(const RealTime &);
|
Chris@0
|
121
|
Chris@0
|
122 // For use in DSSIPluginFactory (set in the DSSI_Host_Descriptor):
|
Chris@0
|
123 static int requestMidiSend(LADSPA_Handle instance,
|
Chris@0
|
124 unsigned char ports,
|
Chris@0
|
125 unsigned char channels);
|
Chris@0
|
126 static void midiSend(LADSPA_Handle instance,
|
Chris@0
|
127 snd_seq_event_t *events,
|
Chris@0
|
128 unsigned long eventCount);
|
Chris@0
|
129 static int requestNonRTThread(LADSPA_Handle instance,
|
Chris@0
|
130 void (*runFunction)(LADSPA_Handle));
|
Chris@0
|
131
|
Chris@0
|
132 int m_client;
|
Chris@0
|
133 int m_position;
|
Chris@0
|
134 LADSPA_Handle m_instanceHandle;
|
Chris@0
|
135 const DSSI_Descriptor *m_descriptor;
|
Chris@0
|
136
|
Chris@0
|
137 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsIn;
|
Chris@0
|
138 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsOut;
|
Chris@0
|
139
|
Chris@0
|
140 std::vector<LADSPA_Data> m_backupControlPortsIn;
|
Chris@0
|
141
|
Chris@0
|
142 std::map<int, int> m_controllerMap;
|
Chris@0
|
143
|
Chris@0
|
144 std::vector<int> m_audioPortsIn;
|
Chris@0
|
145 std::vector<int> m_audioPortsOut;
|
Chris@0
|
146
|
Chris@0
|
147 struct ProgramControl {
|
Chris@0
|
148 int msb;
|
Chris@0
|
149 int lsb;
|
Chris@0
|
150 int program;
|
Chris@0
|
151 };
|
Chris@0
|
152 ProgramControl m_pending;
|
Chris@0
|
153
|
Chris@0
|
154 struct ProgramDescriptor {
|
Chris@0
|
155 int bank;
|
Chris@0
|
156 int program;
|
Chris@0
|
157 QString name;
|
Chris@0
|
158 };
|
Chris@0
|
159 mutable std::vector<ProgramDescriptor> m_cachedPrograms;
|
Chris@0
|
160 mutable bool m_programCacheValid;
|
Chris@0
|
161
|
Chris@0
|
162 RingBuffer<snd_seq_event_t> m_eventBuffer;
|
Chris@0
|
163
|
Chris@0
|
164 size_t m_blockSize;
|
Chris@0
|
165 sample_t **m_inputBuffers;
|
Chris@0
|
166 sample_t **m_outputBuffers;
|
Chris@0
|
167 bool m_ownBuffers;
|
Chris@0
|
168 size_t m_idealChannelCount;
|
Chris@0
|
169 size_t m_outputBufferCount;
|
Chris@0
|
170 size_t m_sampleRate;
|
Chris@0
|
171 float *m_latencyPort;
|
Chris@0
|
172 bool m_run;
|
Chris@0
|
173
|
Chris@0
|
174 bool m_bypassed;
|
Chris@0
|
175 QString m_program;
|
Chris@0
|
176 bool m_grouped;
|
Chris@0
|
177 RealTime m_lastRunTime;
|
Chris@0
|
178
|
Chris@10
|
179 RealTime m_lastEventSendTime;
|
Chris@10
|
180 bool m_haveLastEventSendTime;
|
Chris@10
|
181
|
Chris@0
|
182 QMutex m_processLock;
|
Chris@0
|
183
|
Chris@0
|
184 typedef std::set<DSSIPluginInstance *> PluginSet;
|
Chris@0
|
185 typedef std::map<QString, PluginSet> GroupMap;
|
Chris@0
|
186 static GroupMap m_groupMap;
|
Chris@0
|
187 static snd_seq_event_t **m_groupLocalEventBuffers;
|
Chris@0
|
188 static size_t m_groupLocalEventBufferCount;
|
Chris@0
|
189
|
Chris@0
|
190 static Scavenger<ScavengerArrayWrapper<snd_seq_event_t *> > m_bufferScavenger;
|
Chris@0
|
191
|
Chris@0
|
192 class NonRTPluginThread : public QThread
|
Chris@0
|
193 {
|
Chris@0
|
194 public:
|
Chris@0
|
195 NonRTPluginThread(LADSPA_Handle handle,
|
Chris@0
|
196 void (*runFunction)(LADSPA_Handle)) :
|
Chris@0
|
197 m_handle(handle),
|
Chris@0
|
198 m_runFunction(runFunction),
|
Chris@0
|
199 m_exiting(false) { }
|
Chris@0
|
200
|
Chris@0
|
201 virtual void run();
|
Chris@0
|
202 void setExiting() { m_exiting = true; }
|
Chris@0
|
203
|
Chris@0
|
204 protected:
|
Chris@0
|
205 LADSPA_Handle m_handle;
|
Chris@0
|
206 void (*m_runFunction)(LADSPA_Handle);
|
Chris@0
|
207 bool m_exiting;
|
Chris@0
|
208 };
|
Chris@0
|
209 static std::map<LADSPA_Handle, std::set<NonRTPluginThread *> > m_threads;
|
Chris@0
|
210 };
|
Chris@0
|
211
|
Chris@0
|
212 #endif // _DSSIPLUGININSTANCE_H_
|
Chris@0
|
213
|