Mercurial > hg > easaier-soundaccess
comparison plugin/DSSIPluginInstance.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 _DSSIPLUGININSTANCE_H_ | |
22 #define _DSSIPLUGININSTANCE_H_ | |
23 | |
24 #define DSSI_API_LEVEL 2 | |
25 | |
26 #include <vector> | |
27 #include <set> | |
28 #include <map> | |
29 #include <QString> | |
30 #include <QMutex> | |
31 | |
32 #include "api/dssi.h" | |
33 | |
34 #include "base/RingBuffer.h" | |
35 #include "base/Thread.h" | |
36 #include "RealTimePluginInstance.h" | |
37 #include "base/Scavenger.h" | |
38 | |
39 class DSSIPluginInstance : public RealTimePluginInstance | |
40 { | |
41 public: | |
42 virtual ~DSSIPluginInstance(); | |
43 | |
44 virtual bool isOK() const { return m_instanceHandle != 0; } | |
45 | |
46 int getClientId() const { return m_client; } | |
47 virtual QString getPluginIdentifier() const { return m_identifier; } | |
48 int getPosition() const { return m_position; } | |
49 | |
50 virtual std::string getIdentifier() const; | |
51 virtual std::string getName() const; | |
52 virtual std::string getDescription() const; | |
53 virtual std::string getMaker() const; | |
54 virtual int getPluginVersion() const; | |
55 virtual std::string getCopyright() const; | |
56 | |
57 virtual void run(const Vamp::RealTime &); | |
58 | |
59 virtual unsigned int getParameterCount() const; | |
60 virtual void setParameterValue(unsigned int parameter, float value); | |
61 virtual float getParameterValue(unsigned int parameter) const; | |
62 virtual float getParameterDefault(unsigned int parameter) const; | |
63 | |
64 virtual ParameterList getParameterDescriptors() const; | |
65 virtual float getParameter(std::string) const; | |
66 virtual void setParameter(std::string, float); | |
67 | |
68 virtual std::string configure(std::string key, std::string value); | |
69 virtual void sendEvent(const Vamp::RealTime &eventTime, | |
70 const void *event); | |
71 virtual void clearEvents(); | |
72 | |
73 virtual size_t getBufferSize() const { return m_blockSize; } | |
74 virtual size_t getAudioInputCount() const { return m_audioPortsIn.size(); } | |
75 virtual size_t getAudioOutputCount() const { return m_idealChannelCount; } | |
76 virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; } | |
77 virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; } | |
78 | |
79 virtual size_t getControlOutputCount() const { return m_controlPortsOut.size(); } | |
80 virtual float getControlOutputValue(size_t n) const; | |
81 | |
82 virtual ProgramList getPrograms() const; | |
83 virtual std::string getCurrentProgram() const; | |
84 virtual std::string getProgram(int bank, int program) const; | |
85 virtual unsigned long getProgram(std::string name) const; | |
86 virtual void selectProgram(std::string program); | |
87 | |
88 virtual bool isBypassed() const { return m_bypassed; } | |
89 virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; } | |
90 | |
91 virtual size_t getLatency(); | |
92 | |
93 virtual void silence(); | |
94 virtual void discardEvents(); | |
95 virtual void setIdealChannelCount(size_t channels); // may re-instantiate | |
96 | |
97 virtual bool isInGroup() const { return m_grouped; } | |
98 virtual void detachFromGroup(); | |
99 | |
100 virtual std::string getType() const { return "DSSI Real-Time Plugin"; } | |
101 | |
102 protected: | |
103 // To be constructed only by DSSIPluginFactory | |
104 friend class DSSIPluginFactory; | |
105 | |
106 // Constructor that creates the buffers internally | |
107 // | |
108 DSSIPluginInstance(RealTimePluginFactory *factory, | |
109 int client, | |
110 QString identifier, | |
111 int position, | |
112 unsigned long sampleRate, | |
113 size_t blockSize, | |
114 int idealChannelCount, | |
115 const DSSI_Descriptor* descriptor); | |
116 | |
117 void init(); | |
118 void instantiate(unsigned long sampleRate); | |
119 void cleanup(); | |
120 void activate(); | |
121 void deactivate(); | |
122 void connectPorts(); | |
123 | |
124 bool handleController(snd_seq_event_t *ev); | |
125 void setPortValueFromController(unsigned int portNumber, int controlValue); | |
126 void selectProgramAux(std::string program, bool backupPortValues); | |
127 void checkProgramCache() const; | |
128 | |
129 void initialiseGroupMembership(); | |
130 void runGrouped(const Vamp::RealTime &); | |
131 | |
132 // For use in DSSIPluginFactory (set in the DSSI_Host_Descriptor): | |
133 static int requestMidiSend(LADSPA_Handle instance, | |
134 unsigned char ports, | |
135 unsigned char channels); | |
136 static void midiSend(LADSPA_Handle instance, | |
137 snd_seq_event_t *events, | |
138 unsigned long eventCount); | |
139 static int requestNonRTThread(LADSPA_Handle instance, | |
140 void (*runFunction)(LADSPA_Handle)); | |
141 | |
142 int m_client; | |
143 int m_position; | |
144 LADSPA_Handle m_instanceHandle; | |
145 const DSSI_Descriptor *m_descriptor; | |
146 | |
147 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsIn; | |
148 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsOut; | |
149 | |
150 std::vector<LADSPA_Data> m_backupControlPortsIn; | |
151 | |
152 std::map<int, int> m_controllerMap; | |
153 | |
154 std::vector<int> m_audioPortsIn; | |
155 std::vector<int> m_audioPortsOut; | |
156 | |
157 struct ProgramControl { | |
158 int msb; | |
159 int lsb; | |
160 int program; | |
161 }; | |
162 ProgramControl m_pending; | |
163 | |
164 struct ProgramDescriptor { | |
165 int bank; | |
166 int program; | |
167 std::string name; | |
168 }; | |
169 mutable std::vector<ProgramDescriptor> m_cachedPrograms; | |
170 mutable bool m_programCacheValid; | |
171 | |
172 RingBuffer<snd_seq_event_t> m_eventBuffer; | |
173 | |
174 size_t m_blockSize; | |
175 sample_t **m_inputBuffers; | |
176 sample_t **m_outputBuffers; | |
177 bool m_ownBuffers; | |
178 size_t m_idealChannelCount; | |
179 size_t m_outputBufferCount; | |
180 size_t m_sampleRate; | |
181 float *m_latencyPort; | |
182 bool m_run; | |
183 | |
184 bool m_bypassed; | |
185 std::string m_program; | |
186 bool m_grouped; | |
187 Vamp::RealTime m_lastRunTime; | |
188 | |
189 Vamp::RealTime m_lastEventSendTime; | |
190 bool m_haveLastEventSendTime; | |
191 | |
192 QMutex m_processLock; | |
193 | |
194 typedef std::set<DSSIPluginInstance *> PluginSet; | |
195 typedef std::map<QString, PluginSet> GroupMap; | |
196 static GroupMap m_groupMap; | |
197 static snd_seq_event_t **m_groupLocalEventBuffers; | |
198 static size_t m_groupLocalEventBufferCount; | |
199 | |
200 static Scavenger<ScavengerArrayWrapper<snd_seq_event_t *> > m_bufferScavenger; | |
201 | |
202 class NonRTPluginThread : public Thread | |
203 { | |
204 public: | |
205 NonRTPluginThread(LADSPA_Handle handle, | |
206 void (*runFunction)(LADSPA_Handle)) : | |
207 m_handle(handle), | |
208 m_runFunction(runFunction), | |
209 m_exiting(false) { } | |
210 | |
211 virtual void run(); | |
212 void setExiting() { m_exiting = true; } | |
213 | |
214 protected: | |
215 LADSPA_Handle m_handle; | |
216 void (*m_runFunction)(LADSPA_Handle); | |
217 bool m_exiting; | |
218 }; | |
219 static std::map<LADSPA_Handle, std::set<NonRTPluginThread *> > m_threads; | |
220 }; | |
221 | |
222 #endif // _DSSIPLUGININSTANCE_H_ | |
223 |