annotate plugin/LADSPAPluginInstance.cpp @ 1376:d9511f9e04d7 dev/refactor-piper-related

Introduce some POD structs for describing an external server application and the desired libraries to load from it, and disambiguating between empty list request and invalid list request. This allows for overriding PiperVampPluginFactory behaviour for using a PluginScan to populate the list request.
author Lucas Thompson <lucas.thompson@qmul.ac.uk>
date Fri, 10 Feb 2017 11:15:19 +0000
parents a1cd5abcb38b
children 48e9f538e6e9
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7
Chris@52 8 This program is free software; you can redistribute it and/or
Chris@52 9 modify it under the terms of the GNU General Public License as
Chris@52 10 published by the Free Software Foundation; either version 2 of the
Chris@52 11 License, or (at your option) any later version. See the file
Chris@52 12 COPYING included with this distribution for more information.
Chris@0 13 */
Chris@0 14
Chris@0 15 /*
Chris@0 16 This is a modified version of a source file from the
Chris@0 17 Rosegarden MIDI and audio sequencer and notation editor.
Chris@202 18 This file copyright 2000-2006 Chris Cannam, Richard Bown, and QMUL.
Chris@0 19 */
Chris@0 20
Chris@0 21 #include <iostream>
Chris@0 22 #include <cassert>
Chris@0 23
Chris@0 24 #include "LADSPAPluginInstance.h"
Chris@0 25 #include "LADSPAPluginFactory.h"
Chris@0 26
Chris@166 27 #ifdef HAVE_LRDF
Chris@166 28 #include "lrdf.h"
Chris@166 29 #endif // HAVE_LRDF
Chris@166 30
Chris@117 31 //#define DEBUG_LADSPA 1
Chris@0 32
Chris@259 33 #include <cmath>
Chris@259 34
Chris@0 35
Chris@0 36 LADSPAPluginInstance::LADSPAPluginInstance(RealTimePluginFactory *factory,
Chris@0 37 int clientId,
Chris@0 38 QString identifier,
Chris@0 39 int position,
Chris@1040 40 sv_samplerate_t sampleRate,
Chris@1040 41 int blockSize,
Chris@0 42 int idealChannelCount,
Chris@0 43 const LADSPA_Descriptor* descriptor) :
Chris@0 44 RealTimePluginInstance(factory, identifier),
Chris@0 45 m_client(clientId),
Chris@0 46 m_position(position),
Chris@0 47 m_instanceCount(0),
Chris@0 48 m_descriptor(descriptor),
Chris@0 49 m_blockSize(blockSize),
Chris@0 50 m_sampleRate(sampleRate),
Chris@0 51 m_latencyPort(0),
Chris@0 52 m_run(false),
Chris@0 53 m_bypassed(false)
Chris@0 54 {
Chris@0 55 init(idealChannelCount);
Chris@0 56
Chris@176 57 if (m_audioPortsIn.size() == 0) {
Chris@176 58 m_inputBuffers = 0;
Chris@176 59 } else {
Chris@176 60 m_inputBuffers = new sample_t*[m_instanceCount * m_audioPortsIn.size()];
Chris@176 61 }
Chris@176 62
Chris@176 63 if (m_audioPortsOut.size() == 0) {
Chris@176 64 m_outputBuffers = 0;
Chris@176 65 } else {
Chris@176 66 m_outputBuffers = new sample_t*[m_instanceCount * m_audioPortsOut.size()];
Chris@176 67 }
Chris@0 68
Chris@0 69 for (size_t i = 0; i < m_instanceCount * m_audioPortsIn.size(); ++i) {
Chris@0 70 m_inputBuffers[i] = new sample_t[blockSize];
Chris@0 71 }
Chris@0 72 for (size_t i = 0; i < m_instanceCount * m_audioPortsOut.size(); ++i) {
Chris@0 73 m_outputBuffers[i] = new sample_t[blockSize];
Chris@0 74 }
Chris@0 75
Chris@0 76 m_ownBuffers = true;
Chris@0 77
Chris@0 78 instantiate(sampleRate);
Chris@0 79 if (isOK()) {
Chris@0 80 connectPorts();
Chris@0 81 activate();
Chris@0 82 }
Chris@0 83 }
Chris@0 84
Chris@51 85 std::string
Chris@239 86 LADSPAPluginInstance::getIdentifier() const
Chris@239 87 {
Chris@239 88 return m_descriptor->Label;
Chris@239 89 }
Chris@239 90
Chris@239 91 std::string
Chris@51 92 LADSPAPluginInstance::getName() const
Chris@0 93 {
Chris@239 94 return m_descriptor->Name;
Chris@0 95 }
Chris@0 96
Chris@51 97 std::string
Chris@51 98 LADSPAPluginInstance::getDescription() const
Chris@51 99 {
Chris@239 100 return "";
Chris@51 101 }
Chris@51 102
Chris@51 103 std::string
Chris@51 104 LADSPAPluginInstance::getMaker() const
Chris@51 105 {
Chris@51 106 return m_descriptor->Maker;
Chris@51 107 }
Chris@51 108
Chris@51 109 int
Chris@51 110 LADSPAPluginInstance::getPluginVersion() const
Chris@51 111 {
Chris@473 112 return -1;
Chris@51 113 }
Chris@51 114
Chris@51 115 std::string
Chris@51 116 LADSPAPluginInstance::getCopyright() const
Chris@51 117 {
Chris@51 118 return m_descriptor->Copyright;
Chris@51 119 }
Chris@51 120
Chris@51 121 LADSPAPluginInstance::ParameterList
Chris@51 122 LADSPAPluginInstance::getParameterDescriptors() const
Chris@51 123 {
Chris@51 124 ParameterList list;
Chris@51 125 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
Chris@973 126 if (!f) return list;
Chris@51 127
Chris@51 128 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
Chris@51 129
Chris@51 130 ParameterDescriptor pd;
Chris@51 131 unsigned int pn = m_controlPortsIn[i].first;
Chris@51 132
Chris@239 133 pd.identifier = m_descriptor->PortNames[pn];
Chris@239 134 pd.name = pd.identifier;
Chris@239 135 pd.description = "";
Chris@51 136 pd.minValue = f->getPortMinimum(m_descriptor, pn);
Chris@51 137 pd.maxValue = f->getPortMaximum(m_descriptor, pn);
Chris@51 138 pd.defaultValue = f->getPortDefault(m_descriptor, pn);
Chris@57 139
Chris@57 140 float q = f->getPortQuantization(m_descriptor, pn);
Chris@57 141 if (q == 0.0) {
Chris@57 142 pd.isQuantized = false;
Chris@57 143 } else {
Chris@57 144 pd.isQuantized = true;
Chris@57 145 pd.quantizeStep = q;
Chris@57 146 }
Chris@51 147
Chris@166 148 bool haveLabels = false;
Chris@166 149
Chris@166 150 #ifdef HAVE_LRDF
Chris@166 151 if (pd.isQuantized && pd.quantizeStep == 1.0) {
Chris@166 152
Chris@166 153 lrdf_defaults *defaults =
Chris@166 154 lrdf_get_scale_values(m_descriptor->UniqueID, pn);
Chris@166 155
Chris@166 156 if (defaults) {
Chris@166 157 if (defaults->count > 0) {
Chris@166 158 std::map<int, std::string> values;
Chris@1039 159 int v = 0;
Chris@166 160 for (size_t i = 0; i < defaults->count; ++i) {
Chris@1039 161 v = int(lrintf(fabsf(defaults->items[i].value)));
Chris@166 162 values[v] = defaults->items[i].label;
Chris@166 163 }
Chris@1039 164 for (int i = 0; i <= v; ++i) {
Chris@166 165 pd.valueNames.push_back(values[i]);
Chris@166 166 }
Chris@166 167 haveLabels = true;
Chris@166 168 }
Chris@166 169 lrdf_free_setting_values(defaults);
Chris@166 170 }
Chris@166 171 }
Chris@166 172 #endif
Chris@166 173
Chris@166 174 if (haveLabels) {
Chris@239 175 pd.name = QString(pd.name.c_str())
Chris@166 176 .replace(QRegExp("\\([^\\(\\)]+=[^\\(\\)]+\\)$"), "")
Chris@166 177 .toStdString();
Chris@166 178 } else {
Chris@166 179 static QRegExp unitRE("[\\[\\(]([A-Za-z0-9/]+)[\\)\\]]$");
Chris@166 180 if (unitRE.indexIn(pd.name.c_str()) >= 0) {
Chris@166 181 pd.unit = unitRE.cap(1).toStdString();
Chris@239 182 pd.name = QString(pd.name.c_str())
Chris@166 183 .replace(unitRE, "").toStdString();
Chris@166 184 }
Chris@166 185 }
Chris@166 186
Chris@51 187 list.push_back(pd);
Chris@51 188 }
Chris@51 189
Chris@51 190 return list;
Chris@51 191 }
Chris@51 192
Chris@51 193 float
Chris@239 194 LADSPAPluginInstance::getParameter(std::string id) const
Chris@51 195 {
Chris@51 196 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
Chris@239 197 if (id == m_descriptor->PortNames[m_controlPortsIn[i].first]) {
Chris@51 198 return getParameterValue(i);
Chris@51 199 }
Chris@51 200 }
Chris@51 201
Chris@51 202 return 0.0;
Chris@51 203 }
Chris@51 204
Chris@51 205 void
Chris@239 206 LADSPAPluginInstance::setParameter(std::string id, float value)
Chris@51 207 {
Chris@51 208 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
Chris@239 209 if (id == m_descriptor->PortNames[m_controlPortsIn[i].first]) {
Chris@242 210 #ifdef DEBUG_LADSPA
Chris@690 211 SVDEBUG << "LADSPAPluginInstance::setParameter: Found id "
Chris@687 212 << id << " at control port " << i << endl;
Chris@242 213 #endif
Chris@51 214 setParameterValue(i, value);
Chris@51 215 break;
Chris@51 216 }
Chris@51 217 }
Chris@51 218 }
Chris@0 219
Chris@0 220 void
Chris@0 221 LADSPAPluginInstance::init(int idealChannelCount)
Chris@0 222 {
Chris@0 223 #ifdef DEBUG_LADSPA
Chris@690 224 SVDEBUG << "LADSPAPluginInstance::init(" << idealChannelCount << "): plugin has "
Chris@687 225 << m_descriptor->PortCount << " ports" << endl;
Chris@0 226 #endif
Chris@0 227
Chris@0 228 // Discover ports numbers and identities
Chris@0 229 //
Chris@1039 230 for (int i = 0; i < (int)m_descriptor->PortCount; ++i) {
Chris@242 231
Chris@242 232 if (LADSPA_IS_PORT_AUDIO(m_descriptor->PortDescriptors[i])) {
Chris@242 233
Chris@0 234 if (LADSPA_IS_PORT_INPUT(m_descriptor->PortDescriptors[i])) {
Chris@0 235 #ifdef DEBUG_LADSPA
Chris@690 236 SVDEBUG << "LADSPAPluginInstance::init: port " << i << " is audio in" << endl;
Chris@0 237 #endif
Chris@0 238 m_audioPortsIn.push_back(i);
Chris@0 239 } else {
Chris@0 240 #ifdef DEBUG_LADSPA
Chris@690 241 SVDEBUG << "LADSPAPluginInstance::init: port " << i << " is audio out" << endl;
Chris@0 242 #endif
Chris@0 243 m_audioPortsOut.push_back(i);
Chris@0 244 }
Chris@242 245
Chris@242 246 } else if (LADSPA_IS_PORT_CONTROL(m_descriptor->PortDescriptors[i])) {
Chris@242 247
Chris@0 248 if (LADSPA_IS_PORT_INPUT(m_descriptor->PortDescriptors[i])) {
Chris@242 249
Chris@0 250 #ifdef DEBUG_LADSPA
Chris@690 251 SVDEBUG << "LADSPAPluginInstance::init: port " << i << " is control in" << endl;
Chris@0 252 #endif
Chris@0 253 LADSPA_Data *data = new LADSPA_Data(0.0);
Chris@0 254 m_controlPortsIn.push_back(
Chris@0 255 std::pair<unsigned long, LADSPA_Data*>(i, data));
Chris@242 256
Chris@0 257 } else {
Chris@242 258
Chris@0 259 #ifdef DEBUG_LADSPA
Chris@690 260 SVDEBUG << "LADSPAPluginInstance::init: port " << i << " is control out" << endl;
Chris@0 261 #endif
Chris@0 262 LADSPA_Data *data = new LADSPA_Data(0.0);
Chris@0 263 m_controlPortsOut.push_back(
Chris@0 264 std::pair<unsigned long, LADSPA_Data*>(i, data));
Chris@0 265 if (!strcmp(m_descriptor->PortNames[i], "latency") ||
Chris@0 266 !strcmp(m_descriptor->PortNames[i], "_latency")) {
Chris@0 267 #ifdef DEBUG_LADSPA
Chris@843 268 cerr << "Wooo! We have a latency port!" << endl;
Chris@0 269 #endif
Chris@0 270 m_latencyPort = data;
Chris@0 271 }
Chris@242 272
Chris@0 273 }
Chris@0 274 }
Chris@0 275 #ifdef DEBUG_LADSPA
Chris@0 276 else
Chris@690 277 SVDEBUG << "LADSPAPluginInstance::init - "
Chris@687 278 << "unrecognised port type" << endl;
Chris@0 279 #endif
Chris@0 280 }
Chris@0 281
Chris@0 282 m_instanceCount = 1;
Chris@0 283
Chris@0 284 if (idealChannelCount > 0) {
Chris@0 285 if (m_audioPortsIn.size() == 1) {
Chris@0 286 // mono plugin: duplicate it if need be
Chris@0 287 m_instanceCount = idealChannelCount;
Chris@0 288 }
Chris@0 289 }
Chris@0 290 }
Chris@0 291
Chris@1040 292 sv_frame_t
Chris@0 293 LADSPAPluginInstance::getLatency()
Chris@0 294 {
Chris@0 295 if (m_latencyPort) {
Chris@242 296 if (!m_run) {
Chris@1040 297 for (int i = 0; i < getAudioInputCount(); ++i) {
Chris@1040 298 for (int j = 0; j < m_blockSize; ++j) {
Chris@242 299 m_inputBuffers[i][j] = 0.f;
Chris@242 300 }
Chris@242 301 }
Chris@242 302 run(Vamp::RealTime::zeroTime);
Chris@242 303 }
Chris@1040 304 if (*m_latencyPort > 0) return (sv_frame_t)*m_latencyPort;
Chris@0 305 }
Chris@0 306 return 0;
Chris@0 307 }
Chris@0 308
Chris@0 309 void
Chris@0 310 LADSPAPluginInstance::silence()
Chris@0 311 {
Chris@0 312 if (isOK()) {
Chris@0 313 deactivate();
Chris@0 314 activate();
Chris@0 315 }
Chris@0 316 }
Chris@0 317
Chris@0 318 void
Chris@1040 319 LADSPAPluginInstance::setIdealChannelCount(int channels)
Chris@0 320 {
Chris@0 321 if (m_audioPortsIn.size() != 1 || channels == m_instanceCount) {
Chris@0 322 silence();
Chris@0 323 return;
Chris@0 324 }
Chris@0 325
Chris@0 326 if (isOK()) {
Chris@0 327 deactivate();
Chris@0 328 }
Chris@0 329
Chris@0 330 //!!! don't we need to reallocate inputBuffers and outputBuffers?
Chris@0 331
Chris@0 332 cleanup();
Chris@0 333 m_instanceCount = channels;
Chris@0 334 instantiate(m_sampleRate);
Chris@0 335 if (isOK()) {
Chris@0 336 connectPorts();
Chris@0 337 activate();
Chris@0 338 }
Chris@0 339 }
Chris@0 340
Chris@0 341
Chris@0 342 LADSPAPluginInstance::~LADSPAPluginInstance()
Chris@0 343 {
Chris@0 344 #ifdef DEBUG_LADSPA
Chris@690 345 SVDEBUG << "LADSPAPluginInstance::~LADSPAPluginInstance" << endl;
Chris@0 346 #endif
Chris@0 347
Chris@0 348 if (m_instanceHandles.size() != 0) { // "isOK()"
Chris@0 349 deactivate();
Chris@0 350 }
Chris@0 351
Chris@0 352 cleanup();
Chris@0 353
Chris@0 354 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i)
Chris@0 355 delete m_controlPortsIn[i].second;
Chris@0 356
Chris@0 357 for (unsigned int i = 0; i < m_controlPortsOut.size(); ++i)
Chris@0 358 delete m_controlPortsOut[i].second;
Chris@0 359
Chris@0 360 m_controlPortsIn.clear();
Chris@0 361 m_controlPortsOut.clear();
Chris@0 362
Chris@0 363 if (m_ownBuffers) {
Chris@184 364 for (size_t i = 0; i < m_instanceCount * m_audioPortsIn.size(); ++i) {
Chris@0 365 delete[] m_inputBuffers[i];
Chris@0 366 }
Chris@184 367 for (size_t i = 0; i < m_instanceCount * m_audioPortsOut.size(); ++i) {
Chris@0 368 delete[] m_outputBuffers[i];
Chris@0 369 }
Chris@0 370
Chris@0 371 delete[] m_inputBuffers;
Chris@0 372 delete[] m_outputBuffers;
Chris@0 373 }
Chris@0 374
Chris@0 375 m_audioPortsIn.clear();
Chris@0 376 m_audioPortsOut.clear();
Chris@0 377 }
Chris@0 378
Chris@0 379
Chris@0 380 void
Chris@1040 381 LADSPAPluginInstance::instantiate(sv_samplerate_t sampleRate)
Chris@0 382 {
Chris@724 383 if (!m_descriptor) return;
Chris@724 384
Chris@0 385 #ifdef DEBUG_LADSPA
Chris@843 386 cout << "LADSPAPluginInstance::instantiate - plugin unique id = "
Chris@843 387 << m_descriptor->UniqueID << endl;
Chris@0 388 #endif
Chris@0 389
Chris@0 390 if (!m_descriptor->instantiate) {
Chris@843 391 cerr << "Bad plugin: plugin id " << m_descriptor->UniqueID
Chris@0 392 << ":" << m_descriptor->Label
Chris@843 393 << " has no instantiate method!" << endl;
Chris@0 394 return;
Chris@0 395 }
Chris@0 396
Chris@1040 397 unsigned long pluginRate = (unsigned long)(sampleRate);
Chris@1040 398 if (sampleRate != sv_samplerate_t(pluginRate)) {
Chris@1040 399 cerr << "LADSPAPluginInstance: WARNING: Non-integer sample rate "
Chris@1040 400 << sampleRate << " presented, rounding to " << pluginRate
Chris@1040 401 << endl;
Chris@1040 402 }
Chris@1040 403
Chris@1040 404 for (int i = 0; i < m_instanceCount; ++i) {
Chris@0 405 m_instanceHandles.push_back
Chris@1040 406 (m_descriptor->instantiate(m_descriptor, pluginRate));
Chris@0 407 }
Chris@0 408 }
Chris@0 409
Chris@0 410 void
Chris@0 411 LADSPAPluginInstance::activate()
Chris@0 412 {
Chris@0 413 if (!m_descriptor || !m_descriptor->activate) return;
Chris@0 414
Chris@0 415 for (std::vector<LADSPA_Handle>::iterator hi = m_instanceHandles.begin();
Chris@0 416 hi != m_instanceHandles.end(); ++hi) {
Chris@0 417 m_descriptor->activate(*hi);
Chris@0 418 }
Chris@0 419 }
Chris@0 420
Chris@0 421 void
Chris@0 422 LADSPAPluginInstance::connectPorts()
Chris@0 423 {
Chris@0 424 if (!m_descriptor || !m_descriptor->connect_port) return;
Chris@0 425
Chris@0 426 assert(sizeof(LADSPA_Data) == sizeof(float));
Chris@0 427 assert(sizeof(sample_t) == sizeof(float));
Chris@0 428
Chris@57 429 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
Chris@0 430 int inbuf = 0, outbuf = 0;
Chris@0 431
Chris@0 432 for (std::vector<LADSPA_Handle>::iterator hi = m_instanceHandles.begin();
Chris@0 433 hi != m_instanceHandles.end(); ++hi) {
Chris@0 434
Chris@0 435 for (unsigned int i = 0; i < m_audioPortsIn.size(); ++i) {
Chris@0 436 m_descriptor->connect_port(*hi,
Chris@0 437 m_audioPortsIn[i],
Chris@0 438 (LADSPA_Data *)m_inputBuffers[inbuf]);
Chris@0 439 ++inbuf;
Chris@0 440 }
Chris@0 441
Chris@0 442 for (unsigned int i = 0; i < m_audioPortsOut.size(); ++i) {
Chris@0 443 m_descriptor->connect_port(*hi,
Chris@0 444 m_audioPortsOut[i],
Chris@0 445 (LADSPA_Data *)m_outputBuffers[outbuf]);
Chris@0 446 ++outbuf;
Chris@0 447 }
Chris@0 448
Chris@0 449 // If there is more than one instance, they all share the same
Chris@0 450 // control port ins (and outs, for the moment, because we
Chris@0 451 // don't actually do anything with the outs anyway -- but they
Chris@0 452 // do have to be connected as the plugin can't know if they're
Chris@0 453 // not and will write to them anyway).
Chris@0 454
Chris@0 455 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
Chris@0 456 m_descriptor->connect_port(*hi,
Chris@0 457 m_controlPortsIn[i].first,
Chris@0 458 m_controlPortsIn[i].second);
Chris@57 459 if (f) {
Chris@57 460 float defaultValue = f->getPortDefault
Chris@57 461 (m_descriptor, m_controlPortsIn[i].first);
Chris@57 462 *m_controlPortsIn[i].second = defaultValue;
Chris@57 463 }
Chris@0 464 }
Chris@0 465
Chris@0 466 for (unsigned int i = 0; i < m_controlPortsOut.size(); ++i) {
Chris@0 467 m_descriptor->connect_port(*hi,
Chris@0 468 m_controlPortsOut[i].first,
Chris@0 469 m_controlPortsOut[i].second);
Chris@0 470 }
Chris@0 471 }
Chris@0 472 }
Chris@0 473
Chris@1039 474 int
Chris@0 475 LADSPAPluginInstance::getParameterCount() const
Chris@0 476 {
Chris@1039 477 return (int)m_controlPortsIn.size();
Chris@0 478 }
Chris@0 479
Chris@0 480 void
Chris@1039 481 LADSPAPluginInstance::setParameterValue(int parameter, float value)
Chris@0 482 {
Chris@1039 483 if (!in_range_for(m_controlPortsIn, parameter)) return;
Chris@0 484
Chris@0 485 unsigned int portNumber = m_controlPortsIn[parameter].first;
Chris@0 486
Chris@0 487 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
Chris@0 488 if (f) {
Chris@0 489 if (value < f->getPortMinimum(m_descriptor, portNumber)) {
Chris@0 490 value = f->getPortMinimum(m_descriptor, portNumber);
Chris@0 491 }
Chris@0 492 if (value > f->getPortMaximum(m_descriptor, portNumber)) {
Chris@0 493 value = f->getPortMaximum(m_descriptor, portNumber);
Chris@0 494 }
Chris@0 495 }
Chris@0 496
Chris@0 497 (*m_controlPortsIn[parameter].second) = value;
Chris@0 498 }
Chris@0 499
Chris@0 500 float
Chris@1040 501 LADSPAPluginInstance::getControlOutputValue(int output) const
Chris@60 502 {
Chris@1039 503 if (!in_range_for(m_controlPortsOut, output)) return 0.0;
Chris@60 504 return (*m_controlPortsOut[output].second);
Chris@60 505 }
Chris@60 506
Chris@60 507 float
Chris@1039 508 LADSPAPluginInstance::getParameterValue(int parameter) const
Chris@0 509 {
Chris@1039 510 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
Chris@0 511 return (*m_controlPortsIn[parameter].second);
Chris@0 512 }
Chris@0 513
Chris@0 514 float
Chris@1039 515 LADSPAPluginInstance::getParameterDefault(int parameter) const
Chris@0 516 {
Chris@1039 517 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
Chris@0 518
Chris@0 519 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
Chris@0 520 if (f) {
Chris@0 521 return f->getPortDefault(m_descriptor, m_controlPortsIn[parameter].first);
Chris@0 522 } else {
Chris@0 523 return 0.0f;
Chris@0 524 }
Chris@0 525 }
Chris@0 526
Chris@356 527 int
Chris@1039 528 LADSPAPluginInstance::getParameterDisplayHint(int parameter) const
Chris@356 529 {
Chris@1039 530 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
Chris@356 531
Chris@356 532 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
Chris@356 533 if (f) {
Chris@356 534 return f->getPortDisplayHint(m_descriptor, m_controlPortsIn[parameter].first);
Chris@356 535 } else {
Chris@356 536 return PortHint::NoHint;
Chris@356 537 }
Chris@356 538 }
Chris@356 539
Chris@0 540 void
Chris@1040 541 LADSPAPluginInstance::run(const RealTime &, int count)
Chris@0 542 {
Chris@0 543 if (!m_descriptor || !m_descriptor->run) return;
Chris@0 544
Chris@385 545 if (count == 0) count = m_blockSize;
Chris@385 546
Chris@0 547 for (std::vector<LADSPA_Handle>::iterator hi = m_instanceHandles.begin();
Chris@0 548 hi != m_instanceHandles.end(); ++hi) {
Chris@242 549
Chris@385 550 m_descriptor->run(*hi, count);
Chris@0 551 }
Chris@0 552
Chris@0 553 m_run = true;
Chris@0 554 }
Chris@0 555
Chris@0 556 void
Chris@0 557 LADSPAPluginInstance::deactivate()
Chris@0 558 {
Chris@0 559 if (!m_descriptor || !m_descriptor->deactivate) return;
Chris@0 560
Chris@0 561 for (std::vector<LADSPA_Handle>::iterator hi = m_instanceHandles.begin();
Chris@0 562 hi != m_instanceHandles.end(); ++hi) {
Chris@0 563 m_descriptor->deactivate(*hi);
Chris@0 564 }
Chris@0 565 }
Chris@0 566
Chris@0 567 void
Chris@0 568 LADSPAPluginInstance::cleanup()
Chris@0 569 {
Chris@0 570 if (!m_descriptor) return;
Chris@0 571
Chris@0 572 if (!m_descriptor->cleanup) {
Chris@843 573 cerr << "Bad plugin: plugin id " << m_descriptor->UniqueID
Chris@0 574 << ":" << m_descriptor->Label
Chris@843 575 << " has no cleanup method!" << endl;
Chris@0 576 return;
Chris@0 577 }
Chris@0 578
Chris@0 579 for (std::vector<LADSPA_Handle>::iterator hi = m_instanceHandles.begin();
Chris@0 580 hi != m_instanceHandles.end(); ++hi) {
Chris@0 581 m_descriptor->cleanup(*hi);
Chris@0 582 }
Chris@0 583
Chris@0 584 m_instanceHandles.clear();
Chris@0 585 }
Chris@0 586
Chris@0 587