Mercurial > hg > vamp-plugin-sdk
comparison vamp-sdk/PluginAdapter.cpp @ 22:1eb44d33a371
* Rename simplehost to vamp-simple-host
* Add a temporary test for validity of plugin instances with overlapping
lifespans
author | cannam |
---|---|
date | Mon, 24 Apr 2006 12:58:27 +0000 |
parents | 61887dda7fe0 |
children | db01ce9e7657 |
comparison
equal
deleted
inserted
replaced
21:16eeab18bf72 | 22:1eb44d33a371 |
---|---|
34 authorization. | 34 authorization. |
35 */ | 35 */ |
36 | 36 |
37 #include "PluginAdapter.h" | 37 #include "PluginAdapter.h" |
38 | 38 |
39 #define DEBUG_PLUGIN_ADAPTER 1 | |
40 | |
41 | |
39 namespace Vamp { | 42 namespace Vamp { |
40 | 43 |
41 PluginAdapterBase::PluginAdapterBase() : | 44 PluginAdapterBase::PluginAdapterBase() : |
42 m_populated(false) | 45 m_populated(false) |
43 { | 46 { |
47 #ifdef DEBUG_PLUGIN_ADAPTER | |
48 std::cerr << "PluginAdapterBase[" << this << "]::PluginAdapterBase" << std::endl; | |
49 #endif | |
44 } | 50 } |
45 | 51 |
46 const VampPluginDescriptor * | 52 const VampPluginDescriptor * |
47 PluginAdapterBase::getDescriptor() | 53 PluginAdapterBase::getDescriptor() |
48 { | 54 { |
55 #ifdef DEBUG_PLUGIN_ADAPTER | |
56 std::cerr << "PluginAdapterBase[" << this << "]::getDescriptor" << std::endl; | |
57 #endif | |
58 | |
49 if (m_populated) return &m_descriptor; | 59 if (m_populated) return &m_descriptor; |
50 | 60 |
51 Plugin *plugin = createPlugin(48000); | 61 Plugin *plugin = createPlugin(48000); |
52 | 62 |
53 m_parameters = plugin->getParameterDescriptors(); | 63 m_parameters = plugin->getParameterDescriptors(); |
132 return &m_descriptor; | 142 return &m_descriptor; |
133 } | 143 } |
134 | 144 |
135 PluginAdapterBase::~PluginAdapterBase() | 145 PluginAdapterBase::~PluginAdapterBase() |
136 { | 146 { |
147 #ifdef DEBUG_PLUGIN_ADAPTER | |
148 std::cerr << "PluginAdapterBase[" << this << "]::~PluginAdapterBase" << std::endl; | |
149 #endif | |
150 | |
137 if (!m_populated) return; | 151 if (!m_populated) return; |
138 | 152 |
139 free((void *)m_descriptor.name); | 153 free((void *)m_descriptor.name); |
140 free((void *)m_descriptor.description); | 154 free((void *)m_descriptor.description); |
141 free((void *)m_descriptor.maker); | 155 free((void *)m_descriptor.maker); |
172 } | 186 } |
173 | 187 |
174 PluginAdapterBase * | 188 PluginAdapterBase * |
175 PluginAdapterBase::lookupAdapter(VampPluginHandle handle) | 189 PluginAdapterBase::lookupAdapter(VampPluginHandle handle) |
176 { | 190 { |
191 #ifdef DEBUG_PLUGIN_ADAPTER | |
192 std::cerr << "PluginAdapterBase::lookupAdapter(" << handle << ")" << std::endl; | |
193 #endif | |
194 | |
177 if (!m_adapterMap) return 0; | 195 if (!m_adapterMap) return 0; |
178 AdapterMap::const_iterator i = m_adapterMap->find(handle); | 196 AdapterMap::const_iterator i = m_adapterMap->find(handle); |
179 if (i == m_adapterMap->end()) return 0; | 197 if (i == m_adapterMap->end()) return 0; |
180 return i->second; | 198 return i->second; |
181 } | 199 } |
182 | 200 |
183 VampPluginHandle | 201 VampPluginHandle |
184 PluginAdapterBase::vampInstantiate(const VampPluginDescriptor *desc, | 202 PluginAdapterBase::vampInstantiate(const VampPluginDescriptor *desc, |
185 float inputSampleRate) | 203 float inputSampleRate) |
186 { | 204 { |
205 #ifdef DEBUG_PLUGIN_ADAPTER | |
206 std::cerr << "PluginAdapterBase::vampInstantiate(" << desc << ")" << std::endl; | |
207 #endif | |
208 | |
187 if (!m_adapterMap) { | 209 if (!m_adapterMap) { |
188 m_adapterMap = new AdapterMap(); | 210 m_adapterMap = new AdapterMap(); |
189 } | 211 } |
190 | 212 |
191 if (m_adapterMap->find(desc) == m_adapterMap->end()) { | 213 if (m_adapterMap->find(desc) == m_adapterMap->end()) { |
199 Plugin *plugin = adapter->createPlugin(inputSampleRate); | 221 Plugin *plugin = adapter->createPlugin(inputSampleRate); |
200 if (plugin) { | 222 if (plugin) { |
201 (*m_adapterMap)[plugin] = adapter; | 223 (*m_adapterMap)[plugin] = adapter; |
202 } | 224 } |
203 | 225 |
226 #ifdef DEBUG_PLUGIN_ADAPTER | |
227 std::cerr << "PluginAdapterBase::vampInstantiate(" << desc << "): returning handle " << plugin << std::endl; | |
228 #endif | |
229 | |
204 return plugin; | 230 return plugin; |
205 } | 231 } |
206 | 232 |
207 void | 233 void |
208 PluginAdapterBase::vampCleanup(VampPluginHandle handle) | 234 PluginAdapterBase::vampCleanup(VampPluginHandle handle) |
209 { | 235 { |
236 #ifdef DEBUG_PLUGIN_ADAPTER | |
237 std::cerr << "PluginAdapterBase::vampCleanup(" << handle << ")" << std::endl; | |
238 #endif | |
239 | |
210 PluginAdapterBase *adapter = lookupAdapter(handle); | 240 PluginAdapterBase *adapter = lookupAdapter(handle); |
211 if (!adapter) { | 241 if (!adapter) { |
212 delete ((Plugin *)handle); | 242 delete ((Plugin *)handle); |
213 return; | 243 return; |
214 } | 244 } |
219 PluginAdapterBase::vampInitialise(VampPluginHandle handle, | 249 PluginAdapterBase::vampInitialise(VampPluginHandle handle, |
220 unsigned int channels, | 250 unsigned int channels, |
221 unsigned int stepSize, | 251 unsigned int stepSize, |
222 unsigned int blockSize) | 252 unsigned int blockSize) |
223 { | 253 { |
254 #ifdef DEBUG_PLUGIN_ADAPTER | |
255 std::cerr << "PluginAdapterBase::vampInitialise(" << handle << ", " << channels << ", " << stepSize << ", " << blockSize << ")" << std::endl; | |
256 #endif | |
257 | |
224 bool result = ((Plugin *)handle)->initialise | 258 bool result = ((Plugin *)handle)->initialise |
225 (channels, stepSize, blockSize); | 259 (channels, stepSize, blockSize); |
226 return result ? 1 : 0; | 260 return result ? 1 : 0; |
227 } | 261 } |
228 | 262 |
229 void | 263 void |
230 PluginAdapterBase::vampReset(VampPluginHandle handle) | 264 PluginAdapterBase::vampReset(VampPluginHandle handle) |
231 { | 265 { |
266 #ifdef DEBUG_PLUGIN_ADAPTER | |
267 std::cerr << "PluginAdapterBase::vampReset(" << handle << ")" << std::endl; | |
268 #endif | |
269 | |
232 ((Plugin *)handle)->reset(); | 270 ((Plugin *)handle)->reset(); |
233 } | 271 } |
234 | 272 |
235 float | 273 float |
236 PluginAdapterBase::vampGetParameter(VampPluginHandle handle, | 274 PluginAdapterBase::vampGetParameter(VampPluginHandle handle, |
237 int param) | 275 int param) |
238 { | 276 { |
277 #ifdef DEBUG_PLUGIN_ADAPTER | |
278 std::cerr << "PluginAdapterBase::vampGetParameter(" << handle << ", " << param << ")" << std::endl; | |
279 #endif | |
280 | |
239 PluginAdapterBase *adapter = lookupAdapter(handle); | 281 PluginAdapterBase *adapter = lookupAdapter(handle); |
240 if (!adapter) return 0.0; | 282 if (!adapter) return 0.0; |
241 Plugin::ParameterList &list = adapter->m_parameters; | 283 Plugin::ParameterList &list = adapter->m_parameters; |
242 return ((Plugin *)handle)->getParameter(list[param].name); | 284 return ((Plugin *)handle)->getParameter(list[param].name); |
243 } | 285 } |
244 | 286 |
245 void | 287 void |
246 PluginAdapterBase::vampSetParameter(VampPluginHandle handle, | 288 PluginAdapterBase::vampSetParameter(VampPluginHandle handle, |
247 int param, float value) | 289 int param, float value) |
248 { | 290 { |
291 #ifdef DEBUG_PLUGIN_ADAPTER | |
292 std::cerr << "PluginAdapterBase::vampSetParameter(" << handle << ", " << param << ", " << value << ")" << std::endl; | |
293 #endif | |
294 | |
249 PluginAdapterBase *adapter = lookupAdapter(handle); | 295 PluginAdapterBase *adapter = lookupAdapter(handle); |
250 if (!adapter) return; | 296 if (!adapter) return; |
251 Plugin::ParameterList &list = adapter->m_parameters; | 297 Plugin::ParameterList &list = adapter->m_parameters; |
252 ((Plugin *)handle)->setParameter(list[param].name, value); | 298 ((Plugin *)handle)->setParameter(list[param].name, value); |
253 } | 299 } |
254 | 300 |
255 unsigned int | 301 unsigned int |
256 PluginAdapterBase::vampGetCurrentProgram(VampPluginHandle handle) | 302 PluginAdapterBase::vampGetCurrentProgram(VampPluginHandle handle) |
257 { | 303 { |
304 #ifdef DEBUG_PLUGIN_ADAPTER | |
305 std::cerr << "PluginAdapterBase::vampGetCurrentProgram(" << handle << ")" << std::endl; | |
306 #endif | |
307 | |
258 PluginAdapterBase *adapter = lookupAdapter(handle); | 308 PluginAdapterBase *adapter = lookupAdapter(handle); |
259 if (!adapter) return 0; | 309 if (!adapter) return 0; |
260 Plugin::ProgramList &list = adapter->m_programs; | 310 Plugin::ProgramList &list = adapter->m_programs; |
261 std::string program = ((Plugin *)handle)->getCurrentProgram(); | 311 std::string program = ((Plugin *)handle)->getCurrentProgram(); |
262 for (unsigned int i = 0; i < list.size(); ++i) { | 312 for (unsigned int i = 0; i < list.size(); ++i) { |
267 | 317 |
268 void | 318 void |
269 PluginAdapterBase::vampSelectProgram(VampPluginHandle handle, | 319 PluginAdapterBase::vampSelectProgram(VampPluginHandle handle, |
270 unsigned int program) | 320 unsigned int program) |
271 { | 321 { |
322 #ifdef DEBUG_PLUGIN_ADAPTER | |
323 std::cerr << "PluginAdapterBase::vampSelectProgram(" << handle << ", " << program << ")" << std::endl; | |
324 #endif | |
325 | |
272 PluginAdapterBase *adapter = lookupAdapter(handle); | 326 PluginAdapterBase *adapter = lookupAdapter(handle); |
273 if (!adapter) return; | 327 if (!adapter) return; |
274 Plugin::ProgramList &list = adapter->m_programs; | 328 Plugin::ProgramList &list = adapter->m_programs; |
275 ((Plugin *)handle)->selectProgram(list[program]); | 329 ((Plugin *)handle)->selectProgram(list[program]); |
276 } | 330 } |
277 | 331 |
278 unsigned int | 332 unsigned int |
279 PluginAdapterBase::vampGetPreferredStepSize(VampPluginHandle handle) | 333 PluginAdapterBase::vampGetPreferredStepSize(VampPluginHandle handle) |
280 { | 334 { |
335 #ifdef DEBUG_PLUGIN_ADAPTER | |
336 std::cerr << "PluginAdapterBase::vampGetPreferredStepSize(" << handle << ")" << std::endl; | |
337 #endif | |
338 | |
281 return ((Plugin *)handle)->getPreferredStepSize(); | 339 return ((Plugin *)handle)->getPreferredStepSize(); |
282 } | 340 } |
283 | 341 |
284 unsigned int | 342 unsigned int |
285 PluginAdapterBase::vampGetPreferredBlockSize(VampPluginHandle handle) | 343 PluginAdapterBase::vampGetPreferredBlockSize(VampPluginHandle handle) |
286 { | 344 { |
345 #ifdef DEBUG_PLUGIN_ADAPTER | |
346 std::cerr << "PluginAdapterBase::vampGetPreferredBlockSize(" << handle << ")" << std::endl; | |
347 #endif | |
348 | |
287 return ((Plugin *)handle)->getPreferredBlockSize(); | 349 return ((Plugin *)handle)->getPreferredBlockSize(); |
288 } | 350 } |
289 | 351 |
290 unsigned int | 352 unsigned int |
291 PluginAdapterBase::vampGetMinChannelCount(VampPluginHandle handle) | 353 PluginAdapterBase::vampGetMinChannelCount(VampPluginHandle handle) |
292 { | 354 { |
355 #ifdef DEBUG_PLUGIN_ADAPTER | |
356 std::cerr << "PluginAdapterBase::vampGetMinChannelCount(" << handle << ")" << std::endl; | |
357 #endif | |
358 | |
293 return ((Plugin *)handle)->getMinChannelCount(); | 359 return ((Plugin *)handle)->getMinChannelCount(); |
294 } | 360 } |
295 | 361 |
296 unsigned int | 362 unsigned int |
297 PluginAdapterBase::vampGetMaxChannelCount(VampPluginHandle handle) | 363 PluginAdapterBase::vampGetMaxChannelCount(VampPluginHandle handle) |
298 { | 364 { |
365 #ifdef DEBUG_PLUGIN_ADAPTER | |
366 std::cerr << "PluginAdapterBase::vampGetMaxChannelCount(" << handle << ")" << std::endl; | |
367 #endif | |
368 | |
299 return ((Plugin *)handle)->getMaxChannelCount(); | 369 return ((Plugin *)handle)->getMaxChannelCount(); |
300 } | 370 } |
301 | 371 |
302 unsigned int | 372 unsigned int |
303 PluginAdapterBase::vampGetOutputCount(VampPluginHandle handle) | 373 PluginAdapterBase::vampGetOutputCount(VampPluginHandle handle) |
304 { | 374 { |
375 #ifdef DEBUG_PLUGIN_ADAPTER | |
376 std::cerr << "PluginAdapterBase::vampGetOutputCount(" << handle << ")" << std::endl; | |
377 #endif | |
378 | |
305 PluginAdapterBase *adapter = lookupAdapter(handle); | 379 PluginAdapterBase *adapter = lookupAdapter(handle); |
306 | 380 |
307 // std::cerr << "vampGetOutputCount: handle " << handle << " -> adapter "<< adapter << std::endl; | 381 // std::cerr << "vampGetOutputCount: handle " << handle << " -> adapter "<< adapter << std::endl; |
308 | 382 |
309 if (!adapter) return 0; | 383 if (!adapter) return 0; |
312 | 386 |
313 VampOutputDescriptor * | 387 VampOutputDescriptor * |
314 PluginAdapterBase::vampGetOutputDescriptor(VampPluginHandle handle, | 388 PluginAdapterBase::vampGetOutputDescriptor(VampPluginHandle handle, |
315 unsigned int i) | 389 unsigned int i) |
316 { | 390 { |
391 #ifdef DEBUG_PLUGIN_ADAPTER | |
392 std::cerr << "PluginAdapterBase::vampGetOutputDescriptor(" << handle << ", " << i << ")" << std::endl; | |
393 #endif | |
394 | |
317 PluginAdapterBase *adapter = lookupAdapter(handle); | 395 PluginAdapterBase *adapter = lookupAdapter(handle); |
318 | 396 |
319 // std::cerr << "vampGetOutputDescriptor: handle " << handle << " -> adapter "<< adapter << std::endl; | 397 // std::cerr << "vampGetOutputDescriptor: handle " << handle << " -> adapter "<< adapter << std::endl; |
320 | 398 |
321 if (!adapter) return 0; | 399 if (!adapter) return 0; |
323 } | 401 } |
324 | 402 |
325 void | 403 void |
326 PluginAdapterBase::vampReleaseOutputDescriptor(VampOutputDescriptor *desc) | 404 PluginAdapterBase::vampReleaseOutputDescriptor(VampOutputDescriptor *desc) |
327 { | 405 { |
406 #ifdef DEBUG_PLUGIN_ADAPTER | |
407 std::cerr << "PluginAdapterBase::vampReleaseOutputDescriptor(" << desc << ")" << std::endl; | |
408 #endif | |
409 | |
328 if (desc->name) free((void *)desc->name); | 410 if (desc->name) free((void *)desc->name); |
329 if (desc->description) free((void *)desc->description); | 411 if (desc->description) free((void *)desc->description); |
330 if (desc->unit) free((void *)desc->unit); | 412 if (desc->unit) free((void *)desc->unit); |
331 for (unsigned int i = 0; i < desc->binCount; ++i) { | 413 for (unsigned int i = 0; i < desc->binCount; ++i) { |
332 free((void *)desc->binNames[i]); | 414 free((void *)desc->binNames[i]); |
339 PluginAdapterBase::vampProcess(VampPluginHandle handle, | 421 PluginAdapterBase::vampProcess(VampPluginHandle handle, |
340 float **inputBuffers, | 422 float **inputBuffers, |
341 int sec, | 423 int sec, |
342 int nsec) | 424 int nsec) |
343 { | 425 { |
426 #ifdef DEBUG_PLUGIN_ADAPTER | |
427 std::cerr << "PluginAdapterBase::vampProcess(" << handle << ", " << sec << ", " << nsec << ")" << std::endl; | |
428 #endif | |
429 | |
344 PluginAdapterBase *adapter = lookupAdapter(handle); | 430 PluginAdapterBase *adapter = lookupAdapter(handle); |
345 if (!adapter) return 0; | 431 if (!adapter) return 0; |
346 return adapter->process((Plugin *)handle, | 432 return adapter->process((Plugin *)handle, |
347 inputBuffers, sec, nsec); | 433 inputBuffers, sec, nsec); |
348 } | 434 } |
349 | 435 |
350 VampFeatureList * | 436 VampFeatureList * |
351 PluginAdapterBase::vampGetRemainingFeatures(VampPluginHandle handle) | 437 PluginAdapterBase::vampGetRemainingFeatures(VampPluginHandle handle) |
352 { | 438 { |
439 #ifdef DEBUG_PLUGIN_ADAPTER | |
440 std::cerr << "PluginAdapterBase::vampGetRemainingFeatures(" << handle << ")" << std::endl; | |
441 #endif | |
442 | |
353 PluginAdapterBase *adapter = lookupAdapter(handle); | 443 PluginAdapterBase *adapter = lookupAdapter(handle); |
354 if (!adapter) return 0; | 444 if (!adapter) return 0; |
355 return adapter->getRemainingFeatures((Plugin *)handle); | 445 return adapter->getRemainingFeatures((Plugin *)handle); |
356 } | 446 } |
357 | 447 |
358 void | 448 void |
359 PluginAdapterBase::vampReleaseFeatureSet(VampFeatureList *fs) | 449 PluginAdapterBase::vampReleaseFeatureSet(VampFeatureList *fs) |
360 { | 450 { |
451 #ifdef DEBUG_PLUGIN_ADAPTER | |
452 std::cerr << "PluginAdapterBase::vampReleaseFeatureSet" << std::endl; | |
453 #endif | |
361 } | 454 } |
362 | 455 |
363 void | 456 void |
364 PluginAdapterBase::cleanup(Plugin *plugin) | 457 PluginAdapterBase::cleanup(Plugin *plugin) |
365 { | 458 { |