Mercurial > hg > svcore
comparison plugin/DSSIPluginInstance.cpp @ 51:c2913298cf94
* Make RealTimePluginInstances also provide the PluginInstance interface
author | Chris Cannam |
---|---|
date | Mon, 20 Mar 2006 13:48:58 +0000 |
parents | 39ae3dee27b9 |
children | d397ea0a79f5 |
comparison
equal
deleted
inserted
replaced
50:080ad875395a | 51:c2913298cf94 |
---|---|
90 activate(); | 90 activate(); |
91 initialiseGroupMembership(); | 91 initialiseGroupMembership(); |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 DSSIPluginInstance::DSSIPluginInstance(RealTimePluginFactory *factory, | 95 std::string |
96 int clientId, | 96 DSSIPluginInstance::getName() const |
97 QString identifier, | 97 { |
98 int position, | 98 return m_descriptor->LADSPA_Plugin->Label; |
99 unsigned long sampleRate, | 99 } |
100 size_t blockSize, | 100 |
101 sample_t **inputBuffers, | 101 std::string |
102 sample_t **outputBuffers, | 102 DSSIPluginInstance::getDescription() const |
103 const DSSI_Descriptor* descriptor) : | 103 { |
104 RealTimePluginInstance(factory, identifier), | 104 return m_descriptor->LADSPA_Plugin->Name; |
105 m_client(clientId), | 105 } |
106 m_position(position), | 106 |
107 m_descriptor(descriptor), | 107 std::string |
108 m_eventBuffer(EVENT_BUFFER_SIZE), | 108 DSSIPluginInstance::getMaker() const |
109 m_blockSize(blockSize), | 109 { |
110 m_inputBuffers(inputBuffers), | 110 return m_descriptor->LADSPA_Plugin->Maker; |
111 m_outputBuffers(outputBuffers), | 111 } |
112 m_ownBuffers(false), | 112 |
113 m_idealChannelCount(0), | 113 int |
114 m_sampleRate(sampleRate), | 114 DSSIPluginInstance::getPluginVersion() const |
115 m_latencyPort(0), | 115 { |
116 m_run(false), | 116 return 1; |
117 m_bypassed(false), | 117 } |
118 m_grouped(false) | 118 |
119 { | 119 std::string |
120 #ifdef DEBUG_DSSI | 120 DSSIPluginInstance::getCopyright() const |
121 std::cerr << "DSSIPluginInstance::DSSIPluginInstance[buffers supplied](" << identifier << ")" | 121 { |
122 << std::endl; | 122 return m_descriptor->LADSPA_Plugin->Copyright; |
123 #endif | 123 } |
124 | 124 |
125 init(); | 125 DSSIPluginInstance::ParameterList |
126 | 126 DSSIPluginInstance::getParameterDescriptors() const |
127 m_pending.lsb = m_pending.msb = m_pending.program = -1; | 127 { |
128 | 128 ParameterList list; |
129 instantiate(sampleRate); | 129 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); |
130 if (isOK()) { | 130 |
131 connectPorts(); | 131 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { |
132 activate(); | 132 |
133 if (m_descriptor->run_multiple_synths) { | 133 ParameterDescriptor pd; |
134 m_grouped = true; | 134 unsigned int pn = m_controlPortsIn[i].first; |
135 initialiseGroupMembership(); | 135 |
136 } | 136 pd.name = m_descriptor->LADSPA_Plugin->PortNames[pn]; |
137 } | 137 pd.description = pd.name; |
138 } | 138 pd.minValue = f->getPortMinimum(m_descriptor->LADSPA_Plugin, pn); |
139 | 139 pd.maxValue = f->getPortMaximum(m_descriptor->LADSPA_Plugin, pn); |
140 pd.defaultValue = f->getPortDefault(m_descriptor->LADSPA_Plugin, pn); | |
141 pd.isQuantized = false; | |
142 | |
143 list.push_back(pd); | |
144 } | |
145 | |
146 return list; | |
147 } | |
148 | |
149 float | |
150 DSSIPluginInstance::getParameter(std::string name) const | |
151 { | |
152 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { | |
153 if (name == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) { | |
154 return getParameterValue(i); | |
155 } | |
156 } | |
157 | |
158 return 0.0; | |
159 } | |
160 | |
161 void | |
162 DSSIPluginInstance::setParameter(std::string name, float value) | |
163 { | |
164 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { | |
165 if (name == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) { | |
166 setParameterValue(i, value); | |
167 break; | |
168 } | |
169 } | |
170 } | |
140 | 171 |
141 void | 172 void |
142 DSSIPluginInstance::init() | 173 DSSIPluginInstance::init() |
143 { | 174 { |
144 #ifdef DEBUG_DSSI | 175 #ifdef DEBUG_DSSI |
434 while ((programDescriptor = m_descriptor->get_program(m_instanceHandle, index))) { | 465 while ((programDescriptor = m_descriptor->get_program(m_instanceHandle, index))) { |
435 ++index; | 466 ++index; |
436 ProgramDescriptor d; | 467 ProgramDescriptor d; |
437 d.bank = programDescriptor->Bank; | 468 d.bank = programDescriptor->Bank; |
438 d.program = programDescriptor->Program; | 469 d.program = programDescriptor->Program; |
439 //!!! d.name = QString("%1. %2").arg(index).arg(programDescriptor->Name); | |
440 d.name = programDescriptor->Name; | 470 d.name = programDescriptor->Name; |
441 m_cachedPrograms.push_back(d); | 471 m_cachedPrograms.push_back(d); |
442 } | 472 } |
443 | 473 |
444 #ifdef DEBUG_DSSI | 474 #ifdef DEBUG_DSSI |
446 #endif | 476 #endif |
447 | 477 |
448 m_programCacheValid = true; | 478 m_programCacheValid = true; |
449 } | 479 } |
450 | 480 |
451 QStringList | 481 DSSIPluginInstance::ProgramList |
452 DSSIPluginInstance::getPrograms() const | 482 DSSIPluginInstance::getPrograms() const |
453 { | 483 { |
454 #ifdef DEBUG_DSSI | 484 #ifdef DEBUG_DSSI |
455 std::cerr << "DSSIPluginInstance::getPrograms" << std::endl; | 485 std::cerr << "DSSIPluginInstance::getPrograms" << std::endl; |
456 #endif | 486 #endif |
457 | 487 |
458 if (!m_descriptor) return QStringList(); | 488 if (!m_descriptor) return ProgramList(); |
459 | 489 |
460 checkProgramCache(); | 490 checkProgramCache(); |
461 | 491 |
462 QStringList programs; | 492 ProgramList programs; |
463 | 493 |
464 for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin(); | 494 for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin(); |
465 i != m_cachedPrograms.end(); ++i) { | 495 i != m_cachedPrograms.end(); ++i) { |
466 programs.push_back(i->name); | 496 programs.push_back(i->name); |
467 } | 497 } |
468 | 498 |
469 return programs; | 499 return programs; |
470 } | 500 } |
471 | 501 |
472 QString | 502 std::string |
473 DSSIPluginInstance::getProgram(int bank, int program) const | 503 DSSIPluginInstance::getProgram(int bank, int program) const |
474 { | 504 { |
475 #ifdef DEBUG_DSSI | 505 #ifdef DEBUG_DSSI |
476 std::cerr << "DSSIPluginInstance::getProgram(" << bank << "," << program << ")" << std::endl; | 506 std::cerr << "DSSIPluginInstance::getProgram(" << bank << "," << program << ")" << std::endl; |
477 #endif | 507 #endif |
478 | 508 |
479 if (!m_descriptor) return QString(); | 509 if (!m_descriptor) return std::string(); |
480 | 510 |
481 checkProgramCache(); | 511 checkProgramCache(); |
482 | 512 |
483 for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin(); | 513 for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin(); |
484 i != m_cachedPrograms.end(); ++i) { | 514 i != m_cachedPrograms.end(); ++i) { |
485 if (i->bank == bank && i->program == program) return i->name; | 515 if (i->bank == bank && i->program == program) return i->name; |
486 } | 516 } |
487 | 517 |
488 return QString(); | 518 return std::string(); |
489 } | 519 } |
490 | 520 |
491 unsigned long | 521 unsigned long |
492 DSSIPluginInstance::getProgram(QString name) const | 522 DSSIPluginInstance::getProgram(std::string name) const |
493 { | 523 { |
494 #ifdef DEBUG_DSSI | 524 #ifdef DEBUG_DSSI |
495 std::cerr << "DSSIPluginInstance::getProgram(" << name << ")" << std::endl; | 525 std::cerr << "DSSIPluginInstance::getProgram(" << name << ")" << std::endl; |
496 #endif | 526 #endif |
497 | 527 |
511 } | 541 } |
512 | 542 |
513 return 0; | 543 return 0; |
514 } | 544 } |
515 | 545 |
516 QString | 546 std::string |
517 DSSIPluginInstance::getCurrentProgram() const | 547 DSSIPluginInstance::getCurrentProgram() const |
518 { | 548 { |
519 return m_program; | 549 return m_program; |
520 } | 550 } |
521 | 551 |
522 void | 552 void |
523 DSSIPluginInstance::selectProgram(QString program) | 553 DSSIPluginInstance::selectProgram(std::string program) |
524 { | 554 { |
525 selectProgramAux(program, true); | 555 selectProgramAux(program, true); |
526 } | 556 } |
527 | 557 |
528 void | 558 void |
529 DSSIPluginInstance::selectProgramAux(QString program, bool backupPortValues) | 559 DSSIPluginInstance::selectProgramAux(std::string program, bool backupPortValues) |
530 { | 560 { |
531 #ifdef DEBUG_DSSI | 561 #ifdef DEBUG_DSSI |
532 std::cerr << "DSSIPluginInstance::selectProgram(" << program << ")" << std::endl; | 562 std::cerr << "DSSIPluginInstance::selectProgram(" << program << ")" << std::endl; |
533 #endif | 563 #endif |
534 | 564 |
585 #endif | 615 #endif |
586 | 616 |
587 if (!m_descriptor || !m_descriptor->LADSPA_Plugin->activate) return; | 617 if (!m_descriptor || !m_descriptor->LADSPA_Plugin->activate) return; |
588 m_descriptor->LADSPA_Plugin->activate(m_instanceHandle); | 618 m_descriptor->LADSPA_Plugin->activate(m_instanceHandle); |
589 | 619 |
590 if (!m_program.isEmpty()) { | 620 if (m_program != "") { |
591 #ifdef DEBUG_DSSI | 621 #ifdef DEBUG_DSSI |
592 std::cerr << "DSSIPluginInstance::activate: restoring program " << m_program << std::endl; | 622 std::cerr << "DSSIPluginInstance::activate: restoring program " << m_program << std::endl; |
593 #endif | 623 #endif |
594 selectProgramAux(m_program, false); | 624 selectProgramAux(m_program, false); |
595 } | 625 } |
737 } else { | 767 } else { |
738 return 0.0f; | 768 return 0.0f; |
739 } | 769 } |
740 } | 770 } |
741 | 771 |
742 QString | 772 std::string |
743 DSSIPluginInstance::configure(QString key, | 773 DSSIPluginInstance::configure(std::string key, |
744 QString value) | 774 std::string value) |
745 { | 775 { |
746 if (!m_descriptor || !m_descriptor->configure) return QString(); | 776 if (!m_descriptor || !m_descriptor->configure) return std::string(); |
747 | 777 |
748 if (key == PluginIdentifier::RESERVED_PROJECT_DIRECTORY_KEY) { | 778 if (key == PluginIdentifier::RESERVED_PROJECT_DIRECTORY_KEY.toStdString()) { |
749 #ifdef DSSI_PROJECT_DIRECTORY_KEY | 779 #ifdef DSSI_PROJECT_DIRECTORY_KEY |
750 key = DSSI_PROJECT_DIRECTORY_KEY; | 780 key = DSSI_PROJECT_DIRECTORY_KEY; |
751 #else | 781 #else |
752 return QString(); | 782 return std::string(); |
753 #endif | 783 #endif |
754 } | 784 } |
755 | 785 |
756 | 786 |
757 #ifdef DEBUG_DSSI | 787 #ifdef DEBUG_DSSI |
758 std::cerr << "DSSIPluginInstance::configure(" << key << "," << value << ")" << std::endl; | 788 std::cerr << "DSSIPluginInstance::configure(" << key << "," << value << ")" << std::endl; |
759 #endif | 789 #endif |
760 | 790 |
761 char *message = m_descriptor->configure(m_instanceHandle, | 791 char *message = m_descriptor->configure(m_instanceHandle, |
762 key.toStdString().c_str(), | 792 key.c_str(), |
763 value.toStdString().c_str()); | 793 value.c_str()); |
764 | 794 |
765 m_programCacheValid = false; | 795 m_programCacheValid = false; |
766 | 796 |
767 QString qm; | 797 std::string qm; |
768 | 798 |
769 // Ignore return values from reserved key configuration calls such | 799 // Ignore return values from reserved key configuration calls such |
770 // as project directory | 800 // as project directory |
771 #ifdef DSSI_RESERVED_CONFIGURE_PREFIX | 801 #ifdef DSSI_RESERVED_CONFIGURE_PREFIX |
772 if (key.startsWith(DSSI_RESERVED_CONFIGURE_PREFIX)) { | 802 if (QString(key.c_str()).startsWith(DSSI_RESERVED_CONFIGURE_PREFIX)) { |
773 return qm; | 803 return qm; |
774 } | 804 } |
775 #endif | 805 #endif |
776 | 806 |
777 if (message) { | 807 if (message) { |
778 if (m_descriptor->LADSPA_Plugin && m_descriptor->LADSPA_Plugin->Label) { | 808 if (m_descriptor->LADSPA_Plugin && m_descriptor->LADSPA_Plugin->Label) { |
779 qm = QString(m_descriptor->LADSPA_Plugin->Label) + ": "; | 809 qm = std::string(m_descriptor->LADSPA_Plugin->Label) + ": "; |
780 } | 810 } |
781 qm = qm + message; | 811 qm = qm + message; |
782 free(message); | 812 free(message); |
783 } | 813 } |
784 | 814 |