comparison plugin/DSSIPluginInstance.cpp @ 1057:5c5d4863b428 tonioni

Merge from cxx11 branch
author Chris Cannam
date Mon, 23 Mar 2015 11:26:28 +0000
parents a1cd5abcb38b
children 48e9f538e6e9
comparison
equal deleted inserted replaced
1056:c4898e57eea5 1057:5c5d4863b428
55 55
56 DSSIPluginInstance::DSSIPluginInstance(RealTimePluginFactory *factory, 56 DSSIPluginInstance::DSSIPluginInstance(RealTimePluginFactory *factory,
57 int clientId, 57 int clientId,
58 QString identifier, 58 QString identifier,
59 int position, 59 int position,
60 unsigned long sampleRate, 60 sv_samplerate_t sampleRate,
61 size_t blockSize, 61 int blockSize,
62 int idealChannelCount, 62 int idealChannelCount,
63 const DSSI_Descriptor* descriptor) : 63 const DSSI_Descriptor* descriptor) :
64 RealTimePluginInstance(factory, identifier), 64 RealTimePluginInstance(factory, identifier),
65 m_client(clientId), 65 m_client(clientId),
66 m_position(position), 66 m_position(position),
88 m_outputBuffers = new sample_t*[m_outputBufferCount]; 88 m_outputBuffers = new sample_t*[m_outputBufferCount];
89 89
90 for (size_t i = 0; i < m_audioPortsIn.size(); ++i) { 90 for (size_t i = 0; i < m_audioPortsIn.size(); ++i) {
91 m_inputBuffers[i] = new sample_t[blockSize]; 91 m_inputBuffers[i] = new sample_t[blockSize];
92 } 92 }
93 for (size_t i = 0; i < m_outputBufferCount; ++i) { 93 for (int i = 0; i < m_outputBufferCount; ++i) {
94 m_outputBuffers[i] = new sample_t[blockSize]; 94 m_outputBuffers[i] = new sample_t[blockSize];
95 } 95 }
96 96
97 m_ownBuffers = true; 97 m_ownBuffers = true;
98 98
147 { 147 {
148 ParameterList list; 148 ParameterList list;
149 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); 149 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
150 if (!f) return list; 150 if (!f) return list;
151 151
152 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { 152 for (int i = 0; in_range_for(m_controlPortsIn, i); ++i) {
153 153
154 ParameterDescriptor pd; 154 ParameterDescriptor pd;
155 unsigned int pn = m_controlPortsIn[i].first; 155 int pn = (int)m_controlPortsIn[i].first;
156 156
157 pd.identifier = m_descriptor->LADSPA_Plugin->PortNames[pn]; 157 pd.identifier = m_descriptor->LADSPA_Plugin->PortNames[pn];
158 pd.name = pd.identifier; 158 pd.name = pd.identifier;
159 pd.description = ""; 159 pd.description = "";
160 pd.minValue = f->getPortMinimum(m_descriptor->LADSPA_Plugin, pn); 160 pd.minValue = f->getPortMinimum(m_descriptor->LADSPA_Plugin, pn);
179 DSSIPluginInstance::getParameter(std::string id) const 179 DSSIPluginInstance::getParameter(std::string id) const
180 { 180 {
181 #ifdef DEBUG_DSSI 181 #ifdef DEBUG_DSSI
182 SVDEBUG << "DSSIPluginInstance::getParameter(" << id << ")" << endl; 182 SVDEBUG << "DSSIPluginInstance::getParameter(" << id << ")" << endl;
183 #endif 183 #endif
184 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { 184 for (int i = 0; in_range_for(m_controlPortsIn, i); ++i) {
185 if (id == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) { 185 if (id == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) {
186 #ifdef DEBUG_DSSI 186 #ifdef DEBUG_DSSI
187 cerr << "Matches port " << i << endl; 187 cerr << "Matches port " << i << endl;
188 #endif 188 #endif
189 float v = getParameterValue(i); 189 float v = getParameterValue(i);
202 { 202 {
203 #ifdef DEBUG_DSSI 203 #ifdef DEBUG_DSSI
204 SVDEBUG << "DSSIPluginInstance::setParameter(" << id << ", " << value << ")" << endl; 204 SVDEBUG << "DSSIPluginInstance::setParameter(" << id << ", " << value << ")" << endl;
205 #endif 205 #endif
206 206
207 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { 207 for (int i = 0; in_range_for(m_controlPortsIn, i); ++i) {
208 if (id == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) { 208 if (id == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) {
209 setParameterValue(i, value); 209 setParameterValue(i, value);
210 break; 210 break;
211 } 211 }
212 } 212 }
221 221
222 // Discover ports numbers and identities 222 // Discover ports numbers and identities
223 // 223 //
224 const LADSPA_Descriptor *descriptor = m_descriptor->LADSPA_Plugin; 224 const LADSPA_Descriptor *descriptor = m_descriptor->LADSPA_Plugin;
225 225
226 for (unsigned long i = 0; i < descriptor->PortCount; ++i) 226 for (int i = 0; i < (int)descriptor->PortCount; ++i)
227 { 227 {
228 if (LADSPA_IS_PORT_AUDIO(descriptor->PortDescriptors[i])) 228 if (LADSPA_IS_PORT_AUDIO(descriptor->PortDescriptors[i]))
229 { 229 {
230 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) { 230 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
231 m_audioPortsIn.push_back(i); 231 m_audioPortsIn.push_back(i);
238 { 238 {
239 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) { 239 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
240 240
241 LADSPA_Data *data = new LADSPA_Data(0.0); 241 LADSPA_Data *data = new LADSPA_Data(0.0);
242 242
243 m_controlPortsIn.push_back(std::pair<unsigned long, LADSPA_Data*> 243 m_controlPortsIn.push_back(std::pair<long, LADSPA_Data*>
244 (i, data)); 244 (i, data));
245 245
246 m_backupControlPortsIn.push_back(0.0); 246 m_backupControlPortsIn.push_back(0.0);
247 247
248 } else { 248 } else {
249 LADSPA_Data *data = new LADSPA_Data(0.0); 249 LADSPA_Data *data = new LADSPA_Data(0.0);
250 m_controlPortsOut.push_back( 250 m_controlPortsOut.push_back(
251 std::pair<unsigned long, LADSPA_Data*>(i, data)); 251 std::pair<long, LADSPA_Data*>(i, data));
252 if (!strcmp(descriptor->PortNames[i], "latency") || 252 if (!strcmp(descriptor->PortNames[i], "latency") ||
253 !strcmp(descriptor->PortNames[i], "_latency")) { 253 !strcmp(descriptor->PortNames[i], "_latency")) {
254 #ifdef DEBUG_DSSI 254 #ifdef DEBUG_DSSI
255 cerr << "Wooo! We have a latency port!" << endl; 255 cerr << "Wooo! We have a latency port!" << endl;
256 #endif 256 #endif
263 SVDEBUG << "DSSIPluginInstance::DSSIPluginInstance - " 263 SVDEBUG << "DSSIPluginInstance::DSSIPluginInstance - "
264 << "unrecognised port type" << endl; 264 << "unrecognised port type" << endl;
265 #endif 265 #endif
266 } 266 }
267 267
268 m_outputBufferCount = std::max(m_idealChannelCount, m_audioPortsOut.size()); 268 m_outputBufferCount = std::max(m_idealChannelCount,
269 } 269 (int)m_audioPortsOut.size());
270 270 }
271 size_t 271
272 sv_frame_t
272 DSSIPluginInstance::getLatency() 273 DSSIPluginInstance::getLatency()
273 { 274 {
274 size_t latency = 0; 275 sv_frame_t latency = 0;
275 276
276 #ifdef DEBUG_DSSI_PROCESS 277 #ifdef DEBUG_DSSI_PROCESS
277 SVDEBUG << "DSSIPluginInstance::getLatency(): m_latencyPort " << m_latencyPort << ", m_run " << m_run << endl; 278 SVDEBUG << "DSSIPluginInstance::getLatency(): m_latencyPort " << m_latencyPort << ", m_run " << m_run << endl;
278 #endif 279 #endif
279 280
280 if (m_latencyPort) { 281 if (m_latencyPort) {
281 if (!m_run) { 282 if (!m_run) {
282 for (size_t i = 0; i < getAudioInputCount(); ++i) { 283 for (int i = 0; i < getAudioInputCount(); ++i) {
283 for (size_t j = 0; j < m_blockSize; ++j) { 284 for (int j = 0; j < m_blockSize; ++j) {
284 m_inputBuffers[i][j] = 0.f; 285 m_inputBuffers[i][j] = 0.f;
285 } 286 }
286 } 287 }
287 run(Vamp::RealTime::zeroTime); 288 run(Vamp::RealTime::zeroTime);
288 } 289 }
289 latency = (size_t)(*m_latencyPort + 0.1); 290 latency = (sv_frame_t)(*m_latencyPort + 0.1);
290 } 291 }
291 292
292 #ifdef DEBUG_DSSI_PROCESS 293 #ifdef DEBUG_DSSI_PROCESS
293 SVDEBUG << "DSSIPluginInstance::getLatency(): latency is " << latency << endl; 294 SVDEBUG << "DSSIPluginInstance::getLatency(): latency is " << latency << endl;
294 #endif 295 #endif
310 { 311 {
311 m_eventBuffer.reset(); 312 m_eventBuffer.reset();
312 } 313 }
313 314
314 void 315 void
315 DSSIPluginInstance::setIdealChannelCount(size_t channels) 316 DSSIPluginInstance::setIdealChannelCount(int channels)
316 { 317 {
317 #ifdef DEBUG_DSSI 318 #ifdef DEBUG_DSSI
318 SVDEBUG << "DSSIPluginInstance::setIdealChannelCount: channel count " 319 SVDEBUG << "DSSIPluginInstance::setIdealChannelCount: channel count "
319 << channels << " (was " << m_idealChannelCount << ")" << endl; 320 << channels << " (was " << m_idealChannelCount << ")" << endl;
320 #endif 321 #endif
330 331
331 m_idealChannelCount = channels; 332 m_idealChannelCount = channels;
332 333
333 if (channels > m_outputBufferCount) { 334 if (channels > m_outputBufferCount) {
334 335
335 for (size_t i = 0; i < m_outputBufferCount; ++i) { 336 for (int i = 0; i < m_outputBufferCount; ++i) {
336 delete[] m_outputBuffers[i]; 337 delete[] m_outputBuffers[i];
337 } 338 }
338 339
339 delete[] m_outputBuffers; 340 delete[] m_outputBuffers;
340 341
341 m_outputBufferCount = channels; 342 m_outputBufferCount = channels;
342 343
343 m_outputBuffers = new sample_t*[m_outputBufferCount]; 344 m_outputBuffers = new sample_t*[m_outputBufferCount];
344 345
345 for (size_t i = 0; i < m_outputBufferCount; ++i) { 346 for (int i = 0; i < m_outputBufferCount; ++i) {
346 m_outputBuffers[i] = new sample_t[m_blockSize]; 347 m_outputBuffers[i] = new sample_t[m_blockSize];
347 } 348 }
348 349
349 connectPorts(); 350 connectPorts();
350 } 351 }
426 deactivate(); 427 deactivate();
427 } 428 }
428 429
429 cleanup(); 430 cleanup();
430 431
431 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) 432 for (int i = 0; in_range_for(m_controlPortsIn, i); ++i)
432 delete m_controlPortsIn[i].second; 433 delete m_controlPortsIn[i].second;
433 434
434 for (unsigned int i = 0; i < m_controlPortsOut.size(); ++i) 435 for (int i = 0; in_range_for(m_controlPortsOut, i); ++i)
435 delete m_controlPortsOut[i].second; 436 delete m_controlPortsOut[i].second;
436 437
437 m_controlPortsIn.clear(); 438 m_controlPortsIn.clear();
438 m_controlPortsOut.clear(); 439 m_controlPortsOut.clear();
439 440
440 if (m_ownBuffers) { 441 if (m_ownBuffers) {
441 for (size_t i = 0; i < m_audioPortsIn.size(); ++i) { 442 for (int i = 0; i < getAudioInputCount(); ++i) {
442 delete[] m_inputBuffers[i]; 443 delete[] m_inputBuffers[i];
443 } 444 }
444 for (size_t i = 0; i < m_outputBufferCount; ++i) { 445 for (int i = 0; i < m_outputBufferCount; ++i) {
445 delete[] m_outputBuffers[i]; 446 delete[] m_outputBuffers[i];
446 } 447 }
447 448
448 delete[] m_inputBuffers; 449 delete[] m_inputBuffers;
449 delete[] m_outputBuffers; 450 delete[] m_outputBuffers;
453 m_audioPortsOut.clear(); 454 m_audioPortsOut.clear();
454 } 455 }
455 456
456 457
457 void 458 void
458 DSSIPluginInstance::instantiate(unsigned long sampleRate) 459 DSSIPluginInstance::instantiate(sv_samplerate_t sampleRate)
459 { 460 {
460 if (!m_descriptor) return; 461 if (!m_descriptor) return;
461 462
462 #ifdef DEBUG_DSSI 463 #ifdef DEBUG_DSSI
463 cout << "DSSIPluginInstance::instantiate - plugin \"unique\" id = " 464 cout << "DSSIPluginInstance::instantiate - plugin \"unique\" id = "
470 << ":" << descriptor->Label 471 << ":" << descriptor->Label
471 << " has no instantiate method!" << endl; 472 << " has no instantiate method!" << endl;
472 return; 473 return;
473 } 474 }
474 475
475 m_instanceHandle = descriptor->instantiate(descriptor, sampleRate); 476 unsigned long pluginRate = (unsigned long)(sampleRate);
477 if (sampleRate != sv_samplerate_t(pluginRate)) {
478 cerr << "DSSIPluginInstance: WARNING: Non-integer sample rate "
479 << sampleRate << " presented, rounding to " << pluginRate
480 << endl;
481 }
482 m_instanceHandle = descriptor->instantiate(descriptor, pluginRate);
476 483
477 if (m_instanceHandle) { 484 if (m_instanceHandle) {
478 485
479 if (m_descriptor->get_midi_controller_for_port) { 486 if (m_descriptor->get_midi_controller_for_port) {
480 487
481 for (unsigned long i = 0; i < descriptor->PortCount; ++i) { 488 for (int i = 0; i < (int)descriptor->PortCount; ++i) {
482 489
483 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i]) && 490 if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i]) &&
484 LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) { 491 LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
485 492
486 int controller = m_descriptor->get_midi_controller_for_port 493 int controller = m_descriptor->get_midi_controller_for_port
510 if (!m_descriptor || !m_descriptor->get_program) { 517 if (!m_descriptor || !m_descriptor->get_program) {
511 m_programCacheValid = true; 518 m_programCacheValid = true;
512 return; 519 return;
513 } 520 }
514 521
515 unsigned long index = 0; 522 int index = 0;
516 const DSSI_Program_Descriptor *programDescriptor; 523 const DSSI_Program_Descriptor *programDescriptor;
517 while ((programDescriptor = m_descriptor->get_program(m_instanceHandle, index))) { 524 while ((programDescriptor = m_descriptor->get_program(m_instanceHandle, index))) {
518 ++index; 525 ++index;
519 ProgramDescriptor d; 526 ProgramDescriptor d;
520 d.bank = programDescriptor->Bank; 527 d.bank = (int)programDescriptor->Bank;
521 d.program = programDescriptor->Program; 528 d.program = (int)programDescriptor->Program;
522 d.name = programDescriptor->Name; 529 d.name = programDescriptor->Name;
523 m_cachedPrograms.push_back(d); 530 m_cachedPrograms.push_back(d);
524 } 531 }
525 532
526 #ifdef DEBUG_DSSI 533 #ifdef DEBUG_DSSI
568 } 575 }
569 576
570 return std::string(); 577 return std::string();
571 } 578 }
572 579
573 unsigned long 580 int
574 DSSIPluginInstance::getProgram(std::string name) const 581 DSSIPluginInstance::getProgram(std::string name) const
575 { 582 {
576 #ifdef DEBUG_DSSI 583 #ifdef DEBUG_DSSI
577 SVDEBUG << "DSSIPluginInstance::getProgram(" << name << ")" << endl; 584 SVDEBUG << "DSSIPluginInstance::getProgram(" << name << ")" << endl;
578 #endif 585 #endif
579 586
580 if (!m_descriptor) return 0; 587 if (!m_descriptor) return 0;
581 588
582 checkProgramCache(); 589 checkProgramCache();
583 590
584 unsigned long rv; 591 int rv;
585 592
586 for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin(); 593 for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin();
587 i != m_cachedPrograms.end(); ++i) { 594 i != m_cachedPrograms.end(); ++i) {
588 if (i->name == name) { 595 if (i->name == name) {
589 rv = i->bank; 596 rv = i->bank;
619 checkProgramCache(); 626 checkProgramCache();
620 627
621 if (!m_descriptor->select_program) return; 628 if (!m_descriptor->select_program) return;
622 629
623 bool found = false; 630 bool found = false;
624 unsigned long bankNo = 0, programNo = 0; 631 int bankNo = 0, programNo = 0;
625 632
626 for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin(); 633 for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin();
627 i != m_cachedPrograms.end(); ++i) { 634 i != m_cachedPrograms.end(); ++i) {
628 635
629 if (i->name == program) { 636 if (i->name == program) {
687 void 694 void
688 DSSIPluginInstance::connectPorts() 695 DSSIPluginInstance::connectPorts()
689 { 696 {
690 if (!m_descriptor || !m_descriptor->LADSPA_Plugin->connect_port) return; 697 if (!m_descriptor || !m_descriptor->LADSPA_Plugin->connect_port) return;
691 #ifdef DEBUG_DSSI 698 #ifdef DEBUG_DSSI
692 SVDEBUG << "DSSIPluginInstance::connectPorts: " << m_audioPortsIn.size() 699 SVDEBUG << "DSSIPluginInstance::connectPorts: " << getAudioInputCount()
693 << " audio ports in, " << m_audioPortsOut.size() << " out, " 700 << " audio ports in, " << m_audioPortsOut.size() << " out, "
694 << m_outputBufferCount << " output buffers" << endl; 701 << m_outputBufferCount << " output buffers" << endl;
695 #endif 702 #endif
696 703
697 assert(sizeof(LADSPA_Data) == sizeof(float)); 704 assert(sizeof(LADSPA_Data) == sizeof(float));
698 assert(sizeof(sample_t) == sizeof(float)); 705 assert(sizeof(sample_t) == sizeof(float));
699 706
700 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); 707 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
701 int inbuf = 0, outbuf = 0; 708 int inbuf = 0, outbuf = 0;
702 709
703 for (unsigned int i = 0; i < m_audioPortsIn.size(); ++i) { 710 for (int i = 0; i < getAudioInputCount(); ++i) {
704 m_descriptor->LADSPA_Plugin->connect_port 711 m_descriptor->LADSPA_Plugin->connect_port
705 (m_instanceHandle, 712 (m_instanceHandle,
706 m_audioPortsIn[i], 713 m_audioPortsIn[i],
707 (LADSPA_Data *)m_inputBuffers[inbuf]); 714 (LADSPA_Data *)m_inputBuffers[inbuf]);
708 ++inbuf; 715 ++inbuf;
709 } 716 }
710 717
711 for (unsigned int i = 0; i < m_audioPortsOut.size(); ++i) { 718 for (size_t i = 0; i < m_audioPortsOut.size(); ++i) {
712 m_descriptor->LADSPA_Plugin->connect_port 719 m_descriptor->LADSPA_Plugin->connect_port
713 (m_instanceHandle, 720 (m_instanceHandle,
714 m_audioPortsOut[i], 721 m_audioPortsOut[i],
715 (LADSPA_Data *)m_outputBuffers[outbuf]); 722 (LADSPA_Data *)m_outputBuffers[outbuf]);
716 ++outbuf; 723 ++outbuf;
717 } 724 }
718 725
719 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { 726 for (size_t i = 0; i < m_controlPortsIn.size(); ++i) {
720 m_descriptor->LADSPA_Plugin->connect_port 727 m_descriptor->LADSPA_Plugin->connect_port
721 (m_instanceHandle, 728 (m_instanceHandle,
722 m_controlPortsIn[i].first, 729 m_controlPortsIn[i].first,
723 m_controlPortsIn[i].second); 730 m_controlPortsIn[i].second);
724 731
725 if (f) { 732 if (f) {
726 float defaultValue = f->getPortDefault 733 float defaultValue = f->getPortDefault
727 (m_descriptor->LADSPA_Plugin, m_controlPortsIn[i].first); 734 (m_descriptor->LADSPA_Plugin, (int)m_controlPortsIn[i].first);
728 *m_controlPortsIn[i].second = defaultValue; 735 *m_controlPortsIn[i].second = defaultValue;
729 m_backupControlPortsIn[i] = defaultValue; 736 m_backupControlPortsIn[i] = defaultValue;
730 #ifdef DEBUG_DSSI 737 #ifdef DEBUG_DSSI
731 SVDEBUG << "DSSIPluginInstance::connectPorts: set control port " << i << " to default value " << defaultValue << endl; 738 SVDEBUG << "DSSIPluginInstance::connectPorts: set control port " << i << " to default value " << defaultValue << endl;
732 #endif 739 #endif
733 } 740 }
734 } 741 }
735 742
736 for (unsigned int i = 0; i < m_controlPortsOut.size(); ++i) { 743 for (size_t i = 0; i < m_controlPortsOut.size(); ++i) {
737 m_descriptor->LADSPA_Plugin->connect_port 744 m_descriptor->LADSPA_Plugin->connect_port
738 (m_instanceHandle, 745 (m_instanceHandle,
739 m_controlPortsOut[i].first, 746 m_controlPortsOut[i].first,
740 m_controlPortsOut[i].second); 747 m_controlPortsOut[i].second);
741 } 748 }
742 } 749 }
743 750
744 unsigned int 751 int
745 DSSIPluginInstance::getParameterCount() const 752 DSSIPluginInstance::getParameterCount() const
746 { 753 {
747 return m_controlPortsIn.size(); 754 return (int)m_controlPortsIn.size();
748 } 755 }
749 756
750 void 757 void
751 DSSIPluginInstance::setParameterValue(unsigned int parameter, float value) 758 DSSIPluginInstance::setParameterValue(int parameter, float value)
752 { 759 {
753 #ifdef DEBUG_DSSI 760 #ifdef DEBUG_DSSI
754 SVDEBUG << "DSSIPluginInstance::setParameterValue(" << parameter << ") to " << value << endl; 761 SVDEBUG << "DSSIPluginInstance::setParameterValue(" << parameter << ") to " << value << endl;
755 #endif 762 #endif
756 if (parameter >= m_controlPortsIn.size()) return; 763 if (!in_range_for(m_controlPortsIn, parameter)) return;
757 764
758 unsigned int portNumber = m_controlPortsIn[parameter].first; 765 int portNumber = m_controlPortsIn[parameter].first;
759 766
760 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); 767 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
761 if (f) { 768 if (f) {
762 if (value < f->getPortMinimum(m_descriptor->LADSPA_Plugin, portNumber)) { 769 if (value < f->getPortMinimum(m_descriptor->LADSPA_Plugin, portNumber)) {
763 value = f->getPortMinimum(m_descriptor->LADSPA_Plugin, portNumber); 770 value = f->getPortMinimum(m_descriptor->LADSPA_Plugin, portNumber);
770 (*m_controlPortsIn[parameter].second) = value; 777 (*m_controlPortsIn[parameter].second) = value;
771 m_backupControlPortsIn[parameter] = value; 778 m_backupControlPortsIn[parameter] = value;
772 } 779 }
773 780
774 void 781 void
775 DSSIPluginInstance::setPortValueFromController(unsigned int port, int cv) 782 DSSIPluginInstance::setPortValueFromController(int port, int cv)
776 { 783 {
777 #ifdef DEBUG_DSSI 784 #ifdef DEBUG_DSSI
778 SVDEBUG << "DSSIPluginInstance::setPortValueFromController(" << port << ") to " << cv << endl; 785 SVDEBUG << "DSSIPluginInstance::setPortValueFromController(" << port << ") to " << cv << endl;
779 #endif 786 #endif
780 787
801 /* XXX !!! todo: fill in logarithmic, sample rate &c */ 808 /* XXX !!! todo: fill in logarithmic, sample rate &c */
802 value = lb + ((ub - lb) * value / 127.0f); 809 value = lb + ((ub - lb) * value / 127.0f);
803 } 810 }
804 } 811 }
805 812
806 for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { 813 for (int i = 0; in_range_for(m_controlPortsIn, i); ++i) {
807 if (m_controlPortsIn[i].first == port) { 814 if (m_controlPortsIn[i].first == port) {
808 setParameterValue(i, value); 815 setParameterValue(i, value);
809 } 816 }
810 } 817 }
811 } 818 }
812 819
813 float 820 float
814 DSSIPluginInstance::getControlOutputValue(size_t output) const 821 DSSIPluginInstance::getControlOutputValue(int output) const
815 { 822 {
816 if (output > m_controlPortsOut.size()) return 0.0; 823 if (!in_range_for(m_controlPortsOut, output)) return 0.0;
817 return (*m_controlPortsOut[output].second); 824 return (*m_controlPortsOut[output].second);
818 } 825 }
819 826
820 float 827 float
821 DSSIPluginInstance::getParameterValue(unsigned int parameter) const 828 DSSIPluginInstance::getParameterValue(int parameter) const
822 { 829 {
823 #ifdef DEBUG_DSSI 830 #ifdef DEBUG_DSSI
824 SVDEBUG << "DSSIPluginInstance::getParameterValue(" << parameter << ")" << endl; 831 SVDEBUG << "DSSIPluginInstance::getParameterValue(" << parameter << ")" << endl;
825 #endif 832 #endif
826 if (parameter >= m_controlPortsIn.size()) return 0.0; 833 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
827 return (*m_controlPortsIn[parameter].second); 834 return (*m_controlPortsIn[parameter].second);
828 } 835 }
829 836
830 float 837 float
831 DSSIPluginInstance::getParameterDefault(unsigned int parameter) const 838 DSSIPluginInstance::getParameterDefault(int parameter) const
832 { 839 {
833 if (parameter >= m_controlPortsIn.size()) return 0.0; 840 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
834 841
835 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); 842 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
836 if (f) { 843 if (f) {
837 return f->getPortDefault(m_descriptor->LADSPA_Plugin, 844 return f->getPortDefault(m_descriptor->LADSPA_Plugin,
838 m_controlPortsIn[parameter].first); 845 m_controlPortsIn[parameter].first);
840 return 0.0f; 847 return 0.0f;
841 } 848 }
842 } 849 }
843 850
844 int 851 int
845 DSSIPluginInstance::getParameterDisplayHint(unsigned int parameter) const 852 DSSIPluginInstance::getParameterDisplayHint(int parameter) const
846 { 853 {
847 if (parameter >= m_controlPortsIn.size()) return 0.0; 854 if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
848 855
849 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory); 856 LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
850 if (f) { 857 if (f) {
851 return f->getPortDisplayHint(m_descriptor->LADSPA_Plugin, 858 return f->getPortDisplayHint(m_descriptor->LADSPA_Plugin,
852 m_controlPortsIn[parameter].first); 859 m_controlPortsIn[parameter].first);
904 911
905 return qm; 912 return qm;
906 } 913 }
907 914
908 void 915 void
909 DSSIPluginInstance::sendEvent(const Vamp::RealTime &eventTime, 916 DSSIPluginInstance::sendEvent(const RealTime &eventTime,
910 const void *e) 917 const void *e)
911 { 918 {
912 #ifdef DEBUG_DSSI_PROCESS 919 #ifdef DEBUG_DSSI_PROCESS
913 SVDEBUG << "DSSIPluginInstance::sendEvent: last was " << m_lastEventSendTime << " (valid " << m_haveLastEventSendTime << "), this is " << eventTime << endl; 920 SVDEBUG << "DSSIPluginInstance::sendEvent: last was " << m_lastEventSendTime << " (valid " << m_haveLastEventSendTime << "), this is " << eventTime << endl;
914 #endif 921 #endif
980 987
981 return false; 988 return false;
982 } 989 }
983 990
984 void 991 void
985 DSSIPluginInstance::run(const Vamp::RealTime &blockTime, size_t count) 992 DSSIPluginInstance::run(const RealTime &blockTime, int count)
986 { 993 {
987 static snd_seq_event_t localEventBuffer[EVENT_BUFFER_SIZE]; 994 static snd_seq_event_t localEventBuffer[EVENT_BUFFER_SIZE];
988 int evCount = 0; 995 int evCount = 0;
989 996
990 if (count == 0) count = m_blockSize; 997 if (count == 0) count = m_blockSize;
1036 1043
1037 snd_seq_event_t *ev = localEventBuffer + evCount; 1044 snd_seq_event_t *ev = localEventBuffer + evCount;
1038 *ev = m_eventBuffer.peekOne(); 1045 *ev = m_eventBuffer.peekOne();
1039 bool accept = true; 1046 bool accept = true;
1040 1047
1041 Vamp::RealTime evTime(ev->time.time.tv_sec, ev->time.time.tv_nsec); 1048 RealTime evTime(ev->time.time.tv_sec, ev->time.time.tv_nsec);
1042 1049
1043 int frameOffset = 0; 1050 sv_frame_t frameOffset = 0;
1044 if (evTime > blockTime) { 1051 if (evTime > blockTime) {
1045 frameOffset = Vamp::RealTime::realTime2Frame(evTime - blockTime, m_sampleRate); 1052 frameOffset = RealTime::realTime2Frame(evTime - blockTime, m_sampleRate);
1046 } 1053 }
1047 1054
1048 #ifdef DEBUG_DSSI_PROCESS 1055 #ifdef DEBUG_DSSI_PROCESS
1049 SVDEBUG << "DSSIPluginInstance::run: evTime " << evTime << ", blockTime " << blockTime << ", frameOffset " << frameOffset 1056 SVDEBUG << "DSSIPluginInstance::run: evTime " << evTime << ", blockTime " << blockTime << ", frameOffset " << frameOffset
1050 << ", blockSize " << m_blockSize << endl; 1057 << ", blockSize " << m_blockSize << endl;
1051 cerr << "Type: " << int(ev->type) << ", pitch: " << int(ev->data.note.note) << ", velocity: " << int(ev->data.note.velocity) << endl; 1058 cerr << "Type: " << int(ev->type) << ", pitch: " << int(ev->data.note.note) << ", velocity: " << int(ev->data.note.velocity) << endl;
1052 #endif 1059 #endif
1053 1060
1054 if (frameOffset >= int(count)) break; 1061 if (frameOffset >= (long)count) break;
1055 if (frameOffset < 0) { 1062 if (frameOffset < 0) {
1056 frameOffset = 0; 1063 frameOffset = 0;
1057 if (ev->type == SND_SEQ_EVENT_NOTEON) { 1064 if (ev->type == SND_SEQ_EVENT_NOTEON) {
1058 m_eventBuffer.skip(1); 1065 m_eventBuffer.skip(1);
1059 continue; 1066 continue;
1060 } 1067 }
1061 } 1068 }
1062 1069
1063 ev->time.tick = frameOffset; 1070 ev->time.tick = (snd_seq_tick_time_t)frameOffset;
1064 m_eventBuffer.skip(1); 1071 m_eventBuffer.skip(1);
1065 1072
1066 if (ev->type == SND_SEQ_EVENT_CONTROLLER) { 1073 if (ev->type == SND_SEQ_EVENT_CONTROLLER) {
1067 accept = handleController(ev); 1074 accept = handleController(ev);
1068 } else if (ev->type == SND_SEQ_EVENT_PGMCHANGE) { 1075 } else if (ev->type == SND_SEQ_EVENT_PGMCHANGE) {
1108 #endif 1115 #endif
1109 1116
1110 done: 1117 done:
1111 if (needLock) m_processLock.unlock(); 1118 if (needLock) m_processLock.unlock();
1112 1119
1113 if (m_audioPortsOut.size() == 0) { 1120 int numAudioOuts = int(m_audioPortsOut.size());
1121
1122 if (numAudioOuts == 0) {
1114 // copy inputs to outputs 1123 // copy inputs to outputs
1115 for (size_t ch = 0; ch < m_idealChannelCount; ++ch) { 1124 for (int ch = 0; ch < m_idealChannelCount; ++ch) {
1116 size_t sch = ch % m_audioPortsIn.size(); 1125 int sch = ch % getAudioInputCount();
1117 for (size_t i = 0; i < m_blockSize; ++i) { 1126 for (int i = 0; i < m_blockSize; ++i) {
1118 m_outputBuffers[ch][i] = m_inputBuffers[sch][i]; 1127 m_outputBuffers[ch][i] = m_inputBuffers[sch][i];
1119 } 1128 }
1120 } 1129 }
1121 } else if (m_idealChannelCount < m_audioPortsOut.size()) { 1130 } else if (m_idealChannelCount < numAudioOuts) {
1122 if (m_idealChannelCount == 1) { 1131 if (m_idealChannelCount == 1) {
1123 // mix down to mono 1132 // mix down to mono
1124 for (size_t ch = 1; ch < m_audioPortsOut.size(); ++ch) { 1133 for (int ch = 1; ch < numAudioOuts; ++ch) {
1125 for (size_t i = 0; i < m_blockSize; ++i) { 1134 for (int i = 0; i < m_blockSize; ++i) {
1126 m_outputBuffers[0][i] += m_outputBuffers[ch][i]; 1135 m_outputBuffers[0][i] += m_outputBuffers[ch][i];
1127 } 1136 }
1128 } 1137 }
1129 } 1138 }
1130 } else if (m_idealChannelCount > m_audioPortsOut.size()) { 1139 } else if (m_idealChannelCount > numAudioOuts) {
1131 // duplicate 1140 // duplicate
1132 for (size_t ch = m_audioPortsOut.size(); ch < m_idealChannelCount; ++ch) { 1141 for (int ch = numAudioOuts; ch < m_idealChannelCount; ++ch) {
1133 size_t sch = (ch - m_audioPortsOut.size()) % m_audioPortsOut.size(); 1142 int sch = (ch - numAudioOuts) % numAudioOuts;
1134 for (size_t i = 0; i < m_blockSize; ++i) { 1143 for (int i = 0; i < m_blockSize; ++i) {
1135 m_outputBuffers[ch][i] = m_outputBuffers[sch][i]; 1144 m_outputBuffers[ch][i] = m_outputBuffers[sch][i];
1136 } 1145 }
1137 } 1146 }
1138 } 1147 }
1139 1148
1140 m_lastRunTime = blockTime; 1149 m_lastRunTime = blockTime;
1141 m_run = true; 1150 m_run = true;
1142 } 1151 }
1143 1152
1144 void 1153 void
1145 DSSIPluginInstance::runGrouped(const Vamp::RealTime &blockTime) 1154 DSSIPluginInstance::runGrouped(const RealTime &blockTime)
1146 { 1155 {
1147 // If something else in our group has just been called for this 1156 // If something else in our group has just been called for this
1148 // block time (but we haven't) then we should just write out the 1157 // block time (but we haven't) then we should just write out the
1149 // results and return; if we have just been called for this block 1158 // results and return; if we have just been called for this block
1150 // time or nothing else in the group has been, we should run the 1159 // time or nothing else in the group has been, we should run the
1212 1221
1213 snd_seq_event_t *ev = m_groupLocalEventBuffers[index] + counts[index]; 1222 snd_seq_event_t *ev = m_groupLocalEventBuffers[index] + counts[index];
1214 *ev = instance->m_eventBuffer.peekOne(); 1223 *ev = instance->m_eventBuffer.peekOne();
1215 bool accept = true; 1224 bool accept = true;
1216 1225
1217 Vamp::RealTime evTime(ev->time.time.tv_sec, ev->time.time.tv_nsec); 1226 RealTime evTime(ev->time.time.tv_sec, ev->time.time.tv_nsec);
1218 1227
1219 int frameOffset = 0; 1228 sv_frame_t frameOffset = 0;
1220 if (evTime > blockTime) { 1229 if (evTime > blockTime) {
1221 frameOffset = Vamp::RealTime::realTime2Frame(evTime - blockTime, m_sampleRate); 1230 frameOffset = RealTime::realTime2Frame(evTime - blockTime, m_sampleRate);
1222 } 1231 }
1223 1232
1224 #ifdef DEBUG_DSSI_PROCESS 1233 #ifdef DEBUG_DSSI_PROCESS
1225 SVDEBUG << "DSSIPluginInstance::runGrouped: evTime " << evTime << ", frameOffset " << frameOffset 1234 SVDEBUG << "DSSIPluginInstance::runGrouped: evTime " << evTime << ", frameOffset " << frameOffset
1226 << ", block size " << m_blockSize << endl; 1235 << ", block size " << m_blockSize << endl;
1227 #endif 1236 #endif
1228 1237
1229 if (frameOffset >= int(m_blockSize)) break; 1238 if (frameOffset >= int(m_blockSize)) break;
1230 if (frameOffset < 0) frameOffset = 0; 1239 if (frameOffset < 0) frameOffset = 0;
1231 1240
1232 ev->time.tick = frameOffset; 1241 ev->time.tick = snd_seq_tick_time_t(frameOffset);
1233 instance->m_eventBuffer.skip(1); 1242 instance->m_eventBuffer.skip(1);
1234 1243
1235 if (ev->type == SND_SEQ_EVENT_CONTROLLER) { 1244 if (ev->type == SND_SEQ_EVENT_CONTROLLER) {
1236 accept = instance->handleController(ev); 1245 accept = instance->handleController(ev);
1237 } else if (ev->type == SND_SEQ_EVENT_PGMCHANGE) { 1246 } else if (ev->type == SND_SEQ_EVENT_PGMCHANGE) {