Collection of tools useful for audio production
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1429 lines
41KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 2012 Filipe Coelho <falktx@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #include "carla_engine.h"
  18. #include "carla_plugin.h"
  19. CARLA_BACKEND_START_NAMESPACE
  20. // -----------------------------------------------------------------------
  21. CarlaEngine::CarlaEngine()
  22. : m_checkThread(this),
  23. #ifndef BUILD_BRIDGE
  24. m_osc(this),
  25. m_oscData(nullptr),
  26. #endif
  27. m_callback(nullptr),
  28. #ifdef Q_COMPILER_INITIALIZER_LISTS
  29. m_callbackPtr(nullptr),
  30. m_carlaPlugins{nullptr},
  31. m_uniqueNames{nullptr},
  32. m_insPeak{0.0},
  33. m_outsPeak{0.0}
  34. #else
  35. m_callbackPtr(nullptr)
  36. #endif
  37. {
  38. qDebug("CarlaEngine::CarlaEngine()");
  39. type = CarlaEngineTypeNull;
  40. name = nullptr;
  41. bufferSize = 0;
  42. sampleRate = 0.0;
  43. maxPluginNumber = 0;
  44. #ifndef Q_COMPILER_INITIALIZER_LISTS
  45. for (unsigned short i=0; i < MAX_PLUGINS; i++)
  46. {
  47. m_carlaPlugins[i] = nullptr;
  48. m_uniqueNames[i] = nullptr;
  49. }
  50. for (unsigned short i=0; i < MAX_PLUGINS * MAX_PEAKS; i++)
  51. {
  52. m_insPeak[i] = 0.0;
  53. m_outsPeak[i] = 0.0;
  54. }
  55. #endif
  56. }
  57. CarlaEngine::~CarlaEngine()
  58. {
  59. qDebug("CarlaEngine::~CarlaEngine()");
  60. if (name)
  61. free((void*)name);
  62. }
  63. // -----------------------------------------------------------------------
  64. // Static values
  65. int CarlaEngine::maxClientNameSize()
  66. {
  67. #ifdef CARLA_ENGINE_JACK
  68. # ifndef BUILD_BRIDGE
  69. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  70. # endif
  71. return jack_client_name_size();
  72. #endif
  73. return STR_MAX/2;
  74. }
  75. int CarlaEngine::maxPortNameSize()
  76. {
  77. #ifdef CARLA_ENGINE_JACK
  78. # ifndef BUILD_BRIDGE
  79. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  80. # endif
  81. return jack_port_name_size();
  82. #endif
  83. return STR_MAX;
  84. }
  85. bool CarlaEngine::init(const char* const clientName)
  86. {
  87. qDebug("CarlaEngine::init(\"%s\")", clientName);
  88. m_osc.init(clientName);
  89. m_oscData = m_osc.getControllerData();
  90. return true;
  91. }
  92. bool CarlaEngine::close()
  93. {
  94. qDebug("CarlaEngine::close()");
  95. m_checkThread.stopNow();
  96. m_oscData = nullptr;
  97. m_osc.close();
  98. maxPluginNumber = 0;
  99. return true;
  100. }
  101. // -----------------------------------------------------------------------
  102. // plugin management
  103. short CarlaEngine::getNewPluginId() const
  104. {
  105. qDebug("CarlaEngine::getNewPluginId()");
  106. for (unsigned short i=0; i < maxPluginNumber; i++)
  107. {
  108. if (! m_carlaPlugins[i])
  109. return i;
  110. }
  111. return -1;
  112. }
  113. CarlaPlugin* CarlaEngine::getPlugin(const unsigned short id) const
  114. {
  115. qDebug("CarlaEngine::getPlugin(%i/%i)", id, maxPluginNumber);
  116. Q_ASSERT(maxPluginNumber != 0);
  117. Q_ASSERT(id < maxPluginNumber);
  118. if (id < maxPluginNumber)
  119. return m_carlaPlugins[id];
  120. return nullptr;
  121. }
  122. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned short id) const
  123. {
  124. Q_ASSERT(maxPluginNumber != 0);
  125. Q_ASSERT(id < maxPluginNumber);
  126. return m_carlaPlugins[id];
  127. }
  128. const char* CarlaEngine::getUniqueName(const char* const name)
  129. {
  130. qDebug("CarlaEngine::getUniqueName(\"%s\")", name);
  131. QString qname(name);
  132. if (qname.isEmpty())
  133. qname = "(No name)";
  134. qname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  135. qname.replace(":", "."); // ":" is used in JACK1 to split client/port names
  136. for (unsigned short i=0; i < maxPluginNumber; i++)
  137. {
  138. // Check if unique name already exists
  139. if (m_uniqueNames[i] && qname == m_uniqueNames[i])
  140. {
  141. // Check if string has already been modified
  142. uint len = qname.size();
  143. // 1 digit, ex: " (2)"
  144. if (qname.at(len-4) == QChar(' ') && qname.at(len-3) == QChar('(') && qname.at(len-2).isDigit() && qname.at(len-1) == QChar(')'))
  145. {
  146. int number = qname.at(len-2).toAscii()-'0';
  147. if (number == 9)
  148. // next number is 10, 2 digits
  149. qname.replace(" (9)", " (10)");
  150. else
  151. qname[len-2] = QChar('0'+number+1);
  152. continue;
  153. }
  154. // 2 digits, ex: " (11)"
  155. if (qname.at(len-5) == QChar(' ') && qname.at(len-4) == QChar('(') && qname.at(len-3).isDigit() && qname.at(len-2).isDigit() && qname.at(len-1) == QChar(')'))
  156. {
  157. QChar n2 = qname.at(len-2);
  158. QChar n3 = qname.at(len-3);
  159. if (n2 == QChar('9'))
  160. {
  161. n2 = QChar('0');
  162. n3 = QChar(n3.toAscii()+1);
  163. }
  164. else
  165. n2 = QChar(n2.toAscii()+1);
  166. qname[len-2] = n2;
  167. qname[len-3] = n3;
  168. continue;
  169. }
  170. // Modify string if not
  171. qname += " (2)";
  172. }
  173. }
  174. return strdup(qname.toUtf8().constData());
  175. }
  176. short CarlaEngine::addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  177. {
  178. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  179. }
  180. short CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  181. {
  182. qDebug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2str(btype), PluginType2str(ptype), filename, name, label, extra);
  183. Q_ASSERT(btype != BINARY_NONE);
  184. Q_ASSERT(ptype != PLUGIN_NONE);
  185. Q_ASSERT(filename);
  186. Q_ASSERT(label);
  187. if (maxPluginNumber == 0)
  188. #ifdef BUILD_BRIDGE
  189. maxPluginNumber = MAX_PLUGINS;
  190. #else
  191. maxPluginNumber = (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK) ? 16 : MAX_PLUGINS;
  192. #endif
  193. CarlaPlugin::initializer init = {
  194. this,
  195. filename,
  196. name,
  197. label
  198. };
  199. CarlaPlugin* plugin = nullptr;
  200. #ifndef BUILD_BRIDGE
  201. if (btype != BINARY_NATIVE)
  202. {
  203. # ifdef CARLA_ENGINE_JACK
  204. if (carlaOptions.processMode != CarlaBackend::PROCESS_MODE_MULTIPLE_CLIENTS)
  205. {
  206. setLastError("Can only use bridged plugins in JACK Multi-Client mode");
  207. return -1;
  208. }
  209. # endif
  210. if (type != CarlaEngineTypeJack)
  211. {
  212. setLastError("Can only use bridged plugins with JACK backend");
  213. return -1;
  214. }
  215. plugin = CarlaPlugin::newBridge(init, btype, ptype);
  216. }
  217. else
  218. #endif
  219. {
  220. switch (ptype)
  221. {
  222. case PLUGIN_NONE:
  223. break;
  224. case PLUGIN_LADSPA:
  225. plugin = CarlaPlugin::newLADSPA(init, extra);
  226. break;
  227. case PLUGIN_DSSI:
  228. plugin = CarlaPlugin::newDSSI(init, extra);
  229. break;
  230. case PLUGIN_LV2:
  231. plugin = CarlaPlugin::newLV2(init);
  232. break;
  233. case PLUGIN_VST:
  234. plugin = CarlaPlugin::newVST(init);
  235. break;
  236. case PLUGIN_GIG:
  237. plugin = CarlaPlugin::newGIG(init);
  238. break;
  239. case PLUGIN_SF2:
  240. plugin = CarlaPlugin::newSF2(init);
  241. break;
  242. case PLUGIN_SFZ:
  243. plugin = CarlaPlugin::newSFZ(init);
  244. break;
  245. }
  246. }
  247. if (! plugin)
  248. return -1;
  249. const short id = plugin->id();
  250. m_carlaPlugins[id] = plugin;
  251. m_uniqueNames[id] = plugin->name();
  252. if (! m_checkThread.isRunning())
  253. m_checkThread.startNow(maxPluginNumber);
  254. return id;
  255. }
  256. bool CarlaEngine::removePlugin(const unsigned short id)
  257. {
  258. qDebug("CarlaEngine::removePlugin(%i)", id);
  259. Q_ASSERT(maxPluginNumber != 0);
  260. Q_ASSERT(id < maxPluginNumber);
  261. CarlaPlugin* const plugin = m_carlaPlugins[id];
  262. if (plugin /*&& plugin->id() == id*/)
  263. {
  264. Q_ASSERT(plugin->id() == id);
  265. m_checkThread.stopNow();
  266. processLock();
  267. plugin->setEnabled(false);
  268. processUnlock();
  269. delete plugin;
  270. m_carlaPlugins[id] = nullptr;
  271. m_uniqueNames[id] = nullptr;
  272. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  273. {
  274. for (unsigned short i=id; i < maxPluginNumber-1; i++)
  275. {
  276. m_carlaPlugins[i] = m_carlaPlugins[i+1];
  277. m_uniqueNames[i] = m_uniqueNames[i+1];
  278. if (m_carlaPlugins[i])
  279. m_carlaPlugins[i]->setId(i);
  280. }
  281. }
  282. if (isRunning())
  283. m_checkThread.startNow(maxPluginNumber);
  284. return true;
  285. }
  286. qCritical("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  287. setLastError("Could not find plugin to remove");
  288. return false;
  289. }
  290. void CarlaEngine::removeAllPlugins()
  291. {
  292. qDebug("CarlaEngine::removeAllPlugins()");
  293. m_checkThread.stopNow();
  294. for (unsigned short i=0; i < maxPluginNumber; i++)
  295. {
  296. CarlaPlugin* const plugin = m_carlaPlugins[i];
  297. if (plugin)
  298. {
  299. processLock();
  300. plugin->setEnabled(false);
  301. processUnlock();
  302. delete plugin;
  303. m_carlaPlugins[i] = nullptr;
  304. m_uniqueNames[i] = nullptr;
  305. }
  306. }
  307. maxPluginNumber = 0;
  308. }
  309. void CarlaEngine::idlePluginGuis()
  310. {
  311. Q_ASSERT(maxPluginNumber != 0);
  312. for (unsigned short i=0; i < maxPluginNumber; i++)
  313. {
  314. CarlaPlugin* const plugin = m_carlaPlugins[i];
  315. if (plugin && plugin->enabled())
  316. plugin->idleGui();
  317. }
  318. }
  319. // -----------------------------------------------------------------------
  320. // Information (base)
  321. const char* CarlaEngine::getName() const
  322. {
  323. Q_ASSERT(name);
  324. return name;
  325. }
  326. double CarlaEngine::getSampleRate() const
  327. {
  328. Q_ASSERT(sampleRate != 0.0);
  329. return sampleRate;
  330. }
  331. uint32_t CarlaEngine::getBufferSize() const
  332. {
  333. Q_ASSERT(bufferSize != 0);
  334. return bufferSize;
  335. }
  336. const CarlaTimeInfo* CarlaEngine::getTimeInfo() const
  337. {
  338. return &timeInfo;
  339. }
  340. // -----------------------------------------------------------------------
  341. // Information (audio peaks)
  342. double CarlaEngine::getInputPeak(const unsigned short pluginId, const unsigned short id) const
  343. {
  344. Q_ASSERT(pluginId < maxPluginNumber);
  345. Q_ASSERT(id < MAX_PEAKS);
  346. return m_insPeak[pluginId*MAX_PEAKS + id];
  347. }
  348. double CarlaEngine::getOutputPeak(const unsigned short pluginId, const unsigned short id) const
  349. {
  350. Q_ASSERT(pluginId < maxPluginNumber);
  351. Q_ASSERT(id < MAX_PEAKS);
  352. return m_outsPeak[pluginId*MAX_PEAKS + id];
  353. }
  354. void CarlaEngine::setInputPeak(const unsigned short pluginId, const unsigned short id, double value)
  355. {
  356. Q_ASSERT(pluginId < maxPluginNumber);
  357. Q_ASSERT(id < MAX_PEAKS);
  358. m_insPeak[pluginId*MAX_PEAKS + id] = value;
  359. }
  360. void CarlaEngine::setOutputPeak(const unsigned short pluginId, const unsigned short id, double value)
  361. {
  362. Q_ASSERT(pluginId < maxPluginNumber);
  363. Q_ASSERT(id < MAX_PEAKS);
  364. m_outsPeak[pluginId*MAX_PEAKS + id] = value;
  365. }
  366. // -----------------------------------------------------------------------
  367. // Callback
  368. void CarlaEngine::callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3)
  369. {
  370. qDebug("CarlaEngine::callback(%s, %i, %i, %i, %f)", CallbackType2str(action), pluginId, value1, value2, value3);
  371. if (m_callback)
  372. m_callback(m_callbackPtr, action, pluginId, value1, value2, value3);
  373. }
  374. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  375. {
  376. qDebug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  377. m_callback = func;
  378. m_callbackPtr = ptr;
  379. }
  380. // -----------------------------------------------------------------------
  381. // Mutex locks
  382. void CarlaEngine::processLock()
  383. {
  384. m_procLock.lock();
  385. }
  386. void CarlaEngine::processUnlock()
  387. {
  388. m_procLock.unlock();
  389. }
  390. void CarlaEngine::midiLock()
  391. {
  392. m_midiLock.lock();
  393. }
  394. void CarlaEngine::midiUnlock()
  395. {
  396. m_midiLock.unlock();
  397. }
  398. #ifndef BUILD_BRIDGE
  399. // -----------------------------------------------------------------------
  400. // OSC Stuff
  401. bool CarlaEngine::isOscControllerRegisted() const
  402. {
  403. return m_osc.isControllerRegistered();
  404. }
  405. const char* CarlaEngine::getOscServerPath() const
  406. {
  407. return m_osc.getServerPath();
  408. }
  409. #endif
  410. // -----------------------------------------------------------------------
  411. // protected calls
  412. void CarlaEngine::bufferSizeChanged(uint32_t newBufferSize)
  413. {
  414. qDebug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  415. bufferSize = newBufferSize;
  416. for (unsigned short i=0; i < maxPluginNumber; i++)
  417. {
  418. if (m_carlaPlugins[i] && m_carlaPlugins[i]->enabled())
  419. m_carlaPlugins[i]->bufferSizeChanged(newBufferSize);
  420. }
  421. }
  422. // -------------------------------------------------------------------------------------------------------------------
  423. // Carla Engine Client
  424. CarlaEngineClient::CarlaEngineClient(const CarlaEngineType& type_, const CarlaEngineClientNativeHandle& handle_)
  425. : type(type_),
  426. handle(handle_)
  427. {
  428. qDebug("CarlaEngineClient::CarlaEngineClient()");
  429. Q_ASSERT(type != CarlaEngineTypeNull);
  430. m_active = false;
  431. }
  432. CarlaEngineClient::~CarlaEngineClient()
  433. {
  434. qDebug("CarlaEngineClient::~CarlaEngineClient()");
  435. Q_ASSERT(! m_active);
  436. #ifndef BUILD_BRIDGE
  437. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  438. #endif
  439. {
  440. #ifdef CARLA_ENGINE_JACK
  441. if (handle.jackClient)
  442. jack_client_close(handle.jackClient);
  443. #endif
  444. #ifdef CARLA_ENGINE_RTAUDIO
  445. if (handle.rtAudioPtr)
  446. delete handle.rtAudioPtr;
  447. #endif
  448. }
  449. }
  450. void CarlaEngineClient::activate()
  451. {
  452. qDebug("CarlaEngineClient::activate()");
  453. Q_ASSERT(! m_active);
  454. #ifndef BUILD_BRIDGE
  455. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  456. #endif
  457. {
  458. if (! m_active)
  459. {
  460. #ifdef CARLA_ENGINE_JACK
  461. if (handle.jackClient)
  462. jack_activate(handle.jackClient);
  463. #endif
  464. #ifdef CARLA_ENGINE_RTAUDIO
  465. if (handle.rtAudioPtr)
  466. handle.rtAudioPtr->startStream();
  467. #endif
  468. }
  469. }
  470. m_active = true;
  471. }
  472. void CarlaEngineClient::deactivate()
  473. {
  474. qDebug("CarlaEngineClient::deactivate()");
  475. Q_ASSERT(m_active);
  476. #ifndef BUILD_BRIDGE
  477. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  478. #endif
  479. {
  480. if (m_active)
  481. {
  482. #ifdef CARLA_ENGINE_JACK
  483. if (handle.jackClient)
  484. jack_deactivate(handle.jackClient);
  485. #endif
  486. #ifdef CARLA_ENGINE_RTAUDIO
  487. if (handle.rtAudioPtr)
  488. handle.rtAudioPtr->stopStream();
  489. #endif
  490. }
  491. }
  492. m_active = false;
  493. }
  494. bool CarlaEngineClient::isActive() const
  495. {
  496. qDebug("CarlaEngineClient::isActive()");
  497. return m_active;
  498. }
  499. bool CarlaEngineClient::isOk() const
  500. {
  501. qDebug("CarlaEngineClient::isOk()");
  502. #ifndef BUILD_BRIDGE
  503. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  504. #endif
  505. {
  506. #ifdef CARLA_ENGINE_JACK
  507. return bool(handle.jackClient);
  508. // FIXME
  509. #endif
  510. }
  511. return true;
  512. }
  513. const CarlaEngineBasePort* CarlaEngineClient::addPort(const CarlaEnginePortType type, const char* const name, const bool isInput)
  514. {
  515. qDebug("CarlaEngineClient::addPort(%i, \"%s\", %s)", type, name, bool2str(isInput));
  516. CarlaEnginePortNativeHandle portHandle;
  517. #ifdef CARLA_ENGINE_JACK
  518. portHandle.jackClient = handle.jackClient;
  519. #endif
  520. #ifdef CARLA_ENGINE_JACK
  521. # ifndef BUILD_BRIDGE
  522. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  523. # endif
  524. {
  525. switch (type)
  526. {
  527. case CarlaEnginePortTypeAudio:
  528. portHandle.jackPort = jack_port_register(handle.jackClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  529. break;
  530. case CarlaEnginePortTypeControl:
  531. case CarlaEnginePortTypeMIDI:
  532. portHandle.jackPort = jack_port_register(handle.jackClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  533. break;
  534. }
  535. }
  536. #else
  537. Q_UNUSED(name);
  538. #endif
  539. switch (type)
  540. {
  541. case CarlaEnginePortTypeAudio:
  542. return new CarlaEngineAudioPort(portHandle, isInput);
  543. case CarlaEnginePortTypeControl:
  544. return new CarlaEngineControlPort(portHandle, isInput);
  545. case CarlaEnginePortTypeMIDI:
  546. return new CarlaEngineMidiPort(portHandle, isInput);
  547. }
  548. qCritical("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", type, name, bool2str(isInput));
  549. return nullptr;
  550. }
  551. // -------------------------------------------------------------------------------------------------------------------
  552. // Carla Engine Port (Base class)
  553. CarlaEngineBasePort::CarlaEngineBasePort(const CarlaEnginePortNativeHandle& handle_, const bool isInput_)
  554. : isInput(isInput_),
  555. handle(handle_)
  556. {
  557. qDebug("CarlaEngineBasePort::CarlaEngineBasePort(%s)", bool2str(isInput_));
  558. buffer = nullptr;
  559. }
  560. CarlaEngineBasePort::~CarlaEngineBasePort()
  561. {
  562. qDebug("CarlaEngineBasePort::~CarlaEngineBasePort()");
  563. #ifdef CARLA_ENGINE_JACK
  564. # ifndef BUILD_BRIDGE
  565. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  566. # endif
  567. {
  568. if (handle.jackClient && handle.jackPort)
  569. jack_port_unregister(handle.jackClient, handle.jackPort);
  570. }
  571. #endif
  572. }
  573. // -------------------------------------------------------------------------------------------------------------------
  574. // Carla Engine Port (Audio)
  575. CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  576. : CarlaEngineBasePort(handle, isInput)
  577. {
  578. qDebug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInput));
  579. }
  580. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const /*engine*/)
  581. {
  582. }
  583. #ifdef CARLA_ENGINE_JACK
  584. float* CarlaEngineAudioPort::getJackAudioBuffer(uint32_t nframes)
  585. {
  586. # ifndef BUILD_BRIDGE
  587. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  588. return nullptr;
  589. # endif
  590. Q_ASSERT(handle.jackPort);
  591. return (float*)jack_port_get_buffer(handle.jackPort, nframes);
  592. }
  593. #endif
  594. // -------------------------------------------------------------------------------------------------------------------
  595. // Carla Engine Port (Control)
  596. CarlaEngineControlPort::CarlaEngineControlPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  597. : CarlaEngineBasePort(handle, isInput)
  598. {
  599. qDebug("CarlaEngineControlPort::CarlaEngineControlPort(%s)", bool2str(isInput));
  600. }
  601. void CarlaEngineControlPort::initBuffer(CarlaEngine* const engine)
  602. {
  603. Q_ASSERT(engine);
  604. #ifndef BUILD_BRIDGE
  605. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  606. {
  607. buffer = isInput ? engine->rackControlEventsIn : engine->rackControlEventsOut;
  608. return;
  609. }
  610. #endif
  611. #ifdef CARLA_ENGINE_JACK
  612. if (handle.jackPort)
  613. {
  614. buffer = jack_port_get_buffer(handle.jackPort, engine->getBufferSize());
  615. if (! isInput)
  616. jack_midi_clear_buffer(buffer);
  617. }
  618. #endif
  619. }
  620. uint32_t CarlaEngineControlPort::getEventCount()
  621. {
  622. if (! isInput)
  623. return 0;
  624. Q_ASSERT(buffer);
  625. #ifndef BUILD_BRIDGE
  626. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  627. {
  628. uint32_t count = 0;
  629. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  630. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  631. {
  632. if (events[i].type != CarlaEngineEventNull)
  633. count++;
  634. else
  635. break;
  636. }
  637. return count;
  638. }
  639. #endif
  640. #ifdef CARLA_ENGINE_JACK
  641. return jack_midi_get_event_count(buffer);
  642. #else
  643. return 0;
  644. #endif
  645. }
  646. const CarlaEngineControlEvent* CarlaEngineControlPort::getEvent(uint32_t index)
  647. {
  648. if (! isInput)
  649. return nullptr;
  650. Q_ASSERT(buffer);
  651. Q_ASSERT(index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS);
  652. #ifndef BUILD_BRIDGE
  653. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  654. {
  655. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  656. if (index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS)
  657. return &events[index];
  658. return nullptr;
  659. }
  660. #endif
  661. #ifdef CARLA_ENGINE_JACK
  662. static jack_midi_event_t jackEvent;
  663. static CarlaEngineControlEvent carlaEvent;
  664. if (jack_midi_event_get(&jackEvent, buffer, index) != 0)
  665. return nullptr;
  666. memset(&carlaEvent, 0, sizeof(CarlaEngineControlEvent));
  667. uint8_t midiStatus = jackEvent.buffer[0];
  668. uint8_t midiChannel = midiStatus & 0x0F;
  669. carlaEvent.time = jackEvent.time;
  670. carlaEvent.channel = midiChannel;
  671. if (MIDI_IS_STATUS_CONTROL_CHANGE(midiStatus))
  672. {
  673. uint8_t midiControl = jackEvent.buffer[1];
  674. if (MIDI_IS_CONTROL_BANK_SELECT(midiControl))
  675. {
  676. uint8_t midiBank = jackEvent.buffer[2];
  677. carlaEvent.type = CarlaEngineEventMidiBankChange;
  678. carlaEvent.value = midiBank;
  679. }
  680. else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF)
  681. {
  682. carlaEvent.type = CarlaEngineEventAllSoundOff;
  683. }
  684. else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF)
  685. {
  686. carlaEvent.type = CarlaEngineEventAllNotesOff;
  687. }
  688. else
  689. {
  690. uint8_t midiValue = jackEvent.buffer[2];
  691. carlaEvent.type = CarlaEngineEventControlChange;
  692. carlaEvent.controller = midiControl;
  693. carlaEvent.value = double(midiValue)/127;
  694. }
  695. return &carlaEvent;
  696. }
  697. else if (MIDI_IS_STATUS_PROGRAM_CHANGE(midiStatus))
  698. {
  699. uint8_t midiProgram = jackEvent.buffer[1];
  700. carlaEvent.type = CarlaEngineEventMidiProgramChange;
  701. carlaEvent.value = midiProgram;
  702. return &carlaEvent;
  703. }
  704. #endif
  705. return nullptr;
  706. }
  707. void CarlaEngineControlPort::writeEvent(CarlaEngineControlEventType type, uint32_t time, uint8_t channel, uint8_t controller, double value)
  708. {
  709. if (isInput)
  710. return;
  711. Q_ASSERT(buffer);
  712. Q_ASSERT(type != CarlaEngineEventNull);
  713. #ifndef BUILD_BRIDGE
  714. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  715. {
  716. CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  717. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  718. {
  719. if (events[i].type == CarlaEngineEventNull)
  720. {
  721. events[i].type = type;
  722. events[i].time = time;
  723. events[i].value = value;
  724. events[i].channel = channel;
  725. events[i].controller = controller;
  726. break;
  727. }
  728. }
  729. return;
  730. }
  731. #endif
  732. #ifdef CARLA_ENGINE_JACK
  733. if (type == CarlaEngineEventControlChange && MIDI_IS_CONTROL_BANK_SELECT(controller))
  734. type = CarlaEngineEventMidiBankChange;
  735. uint8_t data[4] = { 0 };
  736. switch (type)
  737. {
  738. case CarlaEngineEventNull:
  739. break;
  740. case CarlaEngineEventControlChange:
  741. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  742. data[1] = controller;
  743. data[2] = value * 127;
  744. jack_midi_event_write(buffer, time, data, 3);
  745. break;
  746. case CarlaEngineEventMidiBankChange:
  747. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  748. data[1] = MIDI_CONTROL_BANK_SELECT;
  749. data[2] = value;
  750. jack_midi_event_write(buffer, time, data, 3);
  751. break;
  752. case CarlaEngineEventMidiProgramChange:
  753. data[0] = MIDI_STATUS_PROGRAM_CHANGE + channel;
  754. data[1] = value;
  755. jack_midi_event_write(buffer, time, data, 2);
  756. break;
  757. case CarlaEngineEventAllSoundOff:
  758. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  759. data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  760. jack_midi_event_write(buffer, time, data, 2);
  761. break;
  762. case CarlaEngineEventAllNotesOff:
  763. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  764. data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  765. jack_midi_event_write(buffer, time, data, 2);
  766. break;
  767. }
  768. #endif
  769. }
  770. // -------------------------------------------------------------------------------------------------------------------
  771. // Carla Engine Port (MIDI)
  772. CarlaEngineMidiPort::CarlaEngineMidiPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  773. : CarlaEngineBasePort(handle, isInput)
  774. {
  775. qDebug("CarlaEngineMidiPort::CarlaEngineMidiPort(%s)", bool2str(isInput));
  776. }
  777. void CarlaEngineMidiPort::initBuffer(CarlaEngine* const engine)
  778. {
  779. Q_ASSERT(engine);
  780. #ifndef BUILD_BRIDGE
  781. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  782. {
  783. buffer = isInput ? engine->rackMidiEventsIn : engine->rackMidiEventsOut;
  784. return;
  785. }
  786. #endif
  787. #ifdef CARLA_ENGINE_JACK
  788. if (handle.jackPort)
  789. {
  790. buffer = jack_port_get_buffer(handle.jackPort, engine->getBufferSize());
  791. if (! isInput)
  792. jack_midi_clear_buffer(buffer);
  793. }
  794. #endif
  795. }
  796. uint32_t CarlaEngineMidiPort::getEventCount()
  797. {
  798. if (! isInput)
  799. return 0;
  800. Q_ASSERT(buffer);
  801. #ifndef BUILD_BRIDGE
  802. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  803. {
  804. uint32_t count = 0;
  805. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  806. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  807. {
  808. if (events[i].size > 0)
  809. count++;
  810. else
  811. break;
  812. }
  813. return count;
  814. }
  815. #endif
  816. #ifdef CARLA_ENGINE_JACK
  817. return jack_midi_get_event_count(buffer);
  818. #else
  819. return 0;
  820. #endif
  821. }
  822. const CarlaEngineMidiEvent* CarlaEngineMidiPort::getEvent(uint32_t index)
  823. {
  824. if (! isInput)
  825. return nullptr;
  826. Q_ASSERT(buffer);
  827. Q_ASSERT(index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS);
  828. #ifndef BUILD_BRIDGE
  829. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  830. {
  831. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  832. if (index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS)
  833. return &events[index];
  834. return nullptr;
  835. }
  836. #endif
  837. #ifdef CARLA_ENGINE_JACK
  838. static jack_midi_event_t jackEvent;
  839. static CarlaEngineMidiEvent carlaEvent;
  840. if (jack_midi_event_get(&jackEvent, buffer, index) == 0 && jackEvent.size <= 4)
  841. {
  842. carlaEvent.time = jackEvent.time;
  843. carlaEvent.size = jackEvent.size;
  844. memcpy(carlaEvent.data, jackEvent.buffer, jackEvent.size);
  845. return &carlaEvent;
  846. }
  847. #endif
  848. return nullptr;
  849. }
  850. void CarlaEngineMidiPort::writeEvent(uint32_t time, const uint8_t* data, uint8_t size)
  851. {
  852. if (isInput)
  853. return;
  854. Q_ASSERT(buffer);
  855. Q_ASSERT(data);
  856. Q_ASSERT(size > 0);
  857. #ifndef BUILD_BRIDGE
  858. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  859. {
  860. if (size > 4)
  861. return;
  862. CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  863. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  864. {
  865. if (events[i].size == 0)
  866. {
  867. events[i].time = time;
  868. events[i].size = size;
  869. memcpy(events[i].data, data, size);
  870. break;
  871. }
  872. }
  873. return;
  874. }
  875. #endif
  876. #ifdef CARLA_ENGINE_JACK
  877. jack_midi_event_write(buffer, time, data, size);
  878. #endif
  879. }
  880. // -------------------------------------------------------------------------------------------------------------------
  881. // Carla Engine OSC stuff
  882. void CarlaEngine::osc_send_add_plugin(const int32_t pluginId, const char* const pluginName)
  883. {
  884. qDebug("CarlaEngine::osc_send_add_plugin(%i, \"%s\")", pluginId, pluginName);
  885. Q_ASSERT(m_oscData);
  886. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  887. Q_ASSERT(pluginName);
  888. if (m_oscData && m_oscData->target)
  889. {
  890. char target_path[strlen(m_oscData->path)+12];
  891. strcpy(target_path, m_oscData->path);
  892. strcat(target_path, "/add_plugin");
  893. lo_send(m_oscData->target, target_path, "is", pluginId, pluginName);
  894. }
  895. }
  896. void CarlaEngine::osc_send_remove_plugin(const int32_t pluginId)
  897. {
  898. qDebug("CarlaEngine::osc_send_remove_plugin(%i)", pluginId);
  899. Q_ASSERT(m_oscData);
  900. if (m_oscData && m_oscData->target)
  901. {
  902. char target_path[strlen(m_oscData->path)+15];
  903. strcpy(target_path, m_oscData->path);
  904. strcat(target_path, "/remove_plugin");
  905. lo_send(m_oscData->target, target_path, "i", pluginId);
  906. }
  907. }
  908. void CarlaEngine::osc_send_set_plugin_data(const int32_t pluginId, const int32_t type, const int32_t category, const int32_t hints, const char* const realName, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  909. {
  910. qDebug("CarlaEngine::osc_send_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", %li)", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  911. Q_ASSERT(m_oscData);
  912. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  913. Q_ASSERT(type != PLUGIN_NONE);
  914. if (m_oscData && m_oscData->target)
  915. {
  916. char target_path[strlen(m_oscData->path)+17];
  917. strcpy(target_path, m_oscData->path);
  918. strcat(target_path, "/set_plugin_data");
  919. lo_send(m_oscData->target, target_path, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  920. }
  921. }
  922. void CarlaEngine::osc_send_set_plugin_ports(const int32_t pluginId, const int32_t audioIns, const int32_t audioOuts, const int32_t midiIns, const int32_t midiOuts, const int32_t cIns, const int32_t cOuts, const int32_t cTotals)
  923. {
  924. qDebug("CarlaEngine::osc_send_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  925. Q_ASSERT(m_oscData);
  926. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  927. if (m_oscData && m_oscData->target)
  928. {
  929. char target_path[strlen(m_oscData->path)+18];
  930. strcpy(target_path, m_oscData->path);
  931. strcat(target_path, "/set_plugin_ports");
  932. lo_send(m_oscData->target, target_path, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  933. }
  934. }
  935. void CarlaEngine::osc_send_set_parameter_data(const int32_t pluginId, const int32_t index, const int32_t type, const int32_t hints, const char* const name, const char* const label, const double current)
  936. {
  937. qDebug("CarlaEngine::osc_send_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  938. Q_ASSERT(m_oscData);
  939. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  940. Q_ASSERT(index >= 0);
  941. Q_ASSERT(type != PARAMETER_UNKNOWN);
  942. if (m_oscData && m_oscData->target)
  943. {
  944. char target_path[strlen(m_oscData->path)+20];
  945. strcpy(target_path, m_oscData->path);
  946. strcat(target_path, "/set_parameter_data");
  947. lo_send(m_oscData->target, target_path, "iiiissd", pluginId, index, type, hints, name, label, current);
  948. }
  949. }
  950. void CarlaEngine::osc_send_set_parameter_ranges(const int32_t pluginId, const int32_t index, const double min, const double max, const double def, const double step, const double stepSmall, const double stepLarge)
  951. {
  952. qDebug("CarlaEngine::osc_send_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  953. Q_ASSERT(m_oscData);
  954. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  955. Q_ASSERT(index >= 0);
  956. Q_ASSERT(min < max);
  957. if (m_oscData && m_oscData->target)
  958. {
  959. char target_path[strlen(m_oscData->path)+22];
  960. strcpy(target_path, m_oscData->path);
  961. strcat(target_path, "/set_parameter_ranges");
  962. lo_send(m_oscData->target, target_path, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  963. }
  964. }
  965. void CarlaEngine::osc_send_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  966. {
  967. qDebug("CarlaEngine::osc_send_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  968. Q_ASSERT(m_oscData);
  969. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  970. Q_ASSERT(index >= 0);
  971. if (m_oscData && m_oscData->target)
  972. {
  973. char target_path[strlen(m_oscData->path)+23];
  974. strcpy(target_path, m_oscData->path);
  975. strcat(target_path, "/set_parameter_midi_cc");
  976. lo_send(m_oscData->target, target_path, "iii", pluginId, index, cc);
  977. }
  978. }
  979. void CarlaEngine::osc_send_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  980. {
  981. qDebug("CarlaEngine::osc_send_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  982. Q_ASSERT(m_oscData);
  983. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  984. Q_ASSERT(index >= 0);
  985. Q_ASSERT(channel >= 0 && channel < 16);
  986. if (m_oscData && m_oscData->target)
  987. {
  988. char target_path[strlen(m_oscData->path)+28];
  989. strcpy(target_path, m_oscData->path);
  990. strcat(target_path, "/set_parameter_midi_channel");
  991. lo_send(m_oscData->target, target_path, "iii", pluginId, index, channel);
  992. }
  993. }
  994. void CarlaEngine::osc_send_set_parameter_value(const int32_t pluginId, const int32_t index, const double value)
  995. {
  996. #if DEBUG
  997. if (index < 0)
  998. qDebug("CarlaEngine::osc_send_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2str((InternalParametersIndex)index), value);
  999. else
  1000. qDebug("CarlaEngine::osc_send_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1001. #endif
  1002. Q_ASSERT(m_oscData);
  1003. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1004. if (m_oscData && m_oscData->target)
  1005. {
  1006. char target_path[strlen(m_oscData->path)+21];
  1007. strcpy(target_path, m_oscData->path);
  1008. strcat(target_path, "/set_parameter_value");
  1009. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1010. }
  1011. }
  1012. void CarlaEngine::osc_send_set_default_value(const int32_t pluginId, const int32_t index, const double value)
  1013. {
  1014. qDebug("CarlaEngine::osc_send_set_default_value(%i, %i, %g)", pluginId, index, value);
  1015. Q_ASSERT(m_oscData);
  1016. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1017. Q_ASSERT(index >= 0);
  1018. if (m_oscData && m_oscData->target)
  1019. {
  1020. char target_path[strlen(m_oscData->path)+19];
  1021. strcpy(target_path, m_oscData->path);
  1022. strcat(target_path, "/set_default_value");
  1023. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1024. }
  1025. }
  1026. void CarlaEngine::osc_send_set_program(const int32_t pluginId, const int32_t index)
  1027. {
  1028. qDebug("CarlaEngine::osc_send_set_program(%i, %i)", pluginId, index);
  1029. Q_ASSERT(m_oscData);
  1030. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1031. if (m_oscData && m_oscData->target)
  1032. {
  1033. char target_path[strlen(m_oscData->path)+13];
  1034. strcpy(target_path, m_oscData->path);
  1035. strcat(target_path, "/set_program");
  1036. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1037. }
  1038. }
  1039. void CarlaEngine::osc_send_set_program_count(const int32_t pluginId, const int32_t count)
  1040. {
  1041. qDebug("CarlaEngine::osc_send_set_program_count(%i, %i)", pluginId, count);
  1042. Q_ASSERT(m_oscData);
  1043. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1044. Q_ASSERT(count >= 0);
  1045. if (m_oscData && m_oscData->target)
  1046. {
  1047. char target_path[strlen(m_oscData->path)+19];
  1048. strcpy(target_path, m_oscData->path);
  1049. strcat(target_path, "/set_program_count");
  1050. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1051. }
  1052. }
  1053. void CarlaEngine::osc_send_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1054. {
  1055. qDebug("CarlaEngine::osc_send_set_program_name(%i, %i, %s)", pluginId, index, name);
  1056. Q_ASSERT(m_oscData);
  1057. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1058. Q_ASSERT(index >= 0);
  1059. Q_ASSERT(name);
  1060. if (m_oscData && m_oscData->target)
  1061. {
  1062. char target_path[strlen(m_oscData->path)+18];
  1063. strcpy(target_path, m_oscData->path);
  1064. strcat(target_path, "/set_program_name");
  1065. lo_send(m_oscData->target, target_path, "iis", pluginId, index, name);
  1066. }
  1067. }
  1068. void CarlaEngine::osc_send_set_midi_program(const int32_t pluginId, const int32_t index)
  1069. {
  1070. qDebug("CarlaEngine::osc_send_set_midi_program(%i, %i)", pluginId, index);
  1071. Q_ASSERT(m_oscData);
  1072. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1073. if (m_oscData && m_oscData->target)
  1074. {
  1075. char target_path[strlen(m_oscData->path)+18];
  1076. strcpy(target_path, m_oscData->path);
  1077. strcat(target_path, "/set_midi_program");
  1078. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1079. }
  1080. }
  1081. void CarlaEngine::osc_send_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1082. {
  1083. qDebug("CarlaEngine::osc_send_set_midi_program_count(%i, %i)", pluginId, count);
  1084. Q_ASSERT(m_oscData);
  1085. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1086. Q_ASSERT(count >= 0);
  1087. if (m_oscData && m_oscData->target)
  1088. {
  1089. char target_path[strlen(m_oscData->path)+24];
  1090. strcpy(target_path, m_oscData->path);
  1091. strcat(target_path, "/set_midi_program_count");
  1092. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1093. }
  1094. }
  1095. void CarlaEngine::osc_send_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name)
  1096. {
  1097. qDebug("CarlaEngine::osc_send_set_midi_program_data(%i, %i, %i, %i, %s)", pluginId, index, bank, program, name);
  1098. Q_ASSERT(m_oscData);
  1099. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1100. Q_ASSERT(index >= 0);
  1101. Q_ASSERT(bank >= 0);
  1102. Q_ASSERT(program >= 0);
  1103. Q_ASSERT(name);
  1104. if (m_oscData && m_oscData->target)
  1105. {
  1106. char target_path[strlen(m_oscData->path)+23];
  1107. strcpy(target_path, m_oscData->path);
  1108. strcat(target_path, "/set_midi_program_data");
  1109. lo_send(m_oscData->target, target_path, "iiiis", pluginId, index, bank, program, name);
  1110. }
  1111. }
  1112. void CarlaEngine::osc_send_set_input_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1113. {
  1114. qDebug("CarlaEngine::osc_send_set_input_peak_value(%i, %i, %g)", pluginId, portId, value);
  1115. Q_ASSERT(m_oscData);
  1116. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1117. Q_ASSERT(portId == 1 || portId == 2);
  1118. if (m_oscData && m_oscData->target)
  1119. {
  1120. char target_path[strlen(m_oscData->path)+22];
  1121. strcpy(target_path, m_oscData->path);
  1122. strcat(target_path, "/set_input_peak_value");
  1123. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1124. }
  1125. }
  1126. void CarlaEngine::osc_send_set_output_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1127. {
  1128. qDebug("CarlaEngine::osc_send_set_output_peak_value(%i, %i, %g)", pluginId, portId, value);
  1129. Q_ASSERT(m_oscData);
  1130. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1131. Q_ASSERT(portId == 1 || portId == 2);
  1132. if (m_oscData && m_oscData->target)
  1133. {
  1134. char target_path[strlen(m_oscData->path)+23];
  1135. strcpy(target_path, m_oscData->path);
  1136. strcat(target_path, "/set_output_peak_value");
  1137. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1138. }
  1139. }
  1140. void CarlaEngine::osc_send_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1141. {
  1142. qDebug("CarlaEngine::osc_send_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1143. Q_ASSERT(m_oscData);
  1144. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1145. Q_ASSERT(channel >= 0 && channel < 16);
  1146. Q_ASSERT(note >= 0 && note < 128);
  1147. Q_ASSERT(velo >= 0 && velo < 128);
  1148. if (m_oscData && m_oscData->target)
  1149. {
  1150. char target_path[strlen(m_oscData->path)+9];
  1151. strcpy(target_path, m_oscData->path);
  1152. strcat(target_path, "/note_on");
  1153. lo_send(m_oscData->target, target_path, "iiii", pluginId, channel, note, velo);
  1154. }
  1155. }
  1156. void CarlaEngine::osc_send_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1157. {
  1158. qDebug("CarlaEngine::osc_send_note_off(%i, %i, %i)", pluginId, channel, note);
  1159. Q_ASSERT(m_oscData);
  1160. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1161. Q_ASSERT(channel >= 0 && channel < 16);
  1162. Q_ASSERT(note >= 0 && note < 128);
  1163. if (m_oscData && m_oscData->target)
  1164. {
  1165. char target_path[strlen(m_oscData->path)+10];
  1166. strcpy(target_path, m_oscData->path);
  1167. strcat(target_path, "/note_off");
  1168. lo_send(m_oscData->target, target_path, "iii", pluginId, channel, note);
  1169. }
  1170. }
  1171. void CarlaEngine::osc_send_exit()
  1172. {
  1173. qDebug("CarlaEngine::osc_send_exit()");
  1174. Q_ASSERT(m_oscData);
  1175. if (m_oscData && m_oscData->target)
  1176. {
  1177. char target_path[strlen(m_oscData->path)+6];
  1178. strcpy(target_path, m_oscData->path);
  1179. strcat(target_path, "/exit");
  1180. lo_send(m_oscData->target, target_path, "");
  1181. }
  1182. }
  1183. CARLA_BACKEND_END_NAMESPACE