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.

1848 lines
54KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.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. unsigned short CarlaEngine::m_maxPluginNumber = 0;
  22. CarlaEngine::CarlaEngine()
  23. : m_checkThread(this),
  24. #ifndef BUILD_BRIDGE
  25. m_osc(this),
  26. #endif
  27. m_oscData(nullptr),
  28. m_callback(nullptr),
  29. #ifdef Q_COMPILER_INITIALIZER_LISTS
  30. m_callbackPtr(nullptr),
  31. m_carlaPlugins{nullptr},
  32. m_uniqueNames{nullptr},
  33. m_insPeak{0.0},
  34. m_outsPeak{0.0}
  35. #else
  36. m_callbackPtr(nullptr)
  37. #endif
  38. {
  39. qDebug("CarlaEngine::CarlaEngine()");
  40. type = CarlaEngineTypeNull;
  41. name = nullptr;
  42. bufferSize = 0;
  43. sampleRate = 0.0;
  44. m_maxPluginNumber = 0;
  45. #ifndef Q_COMPILER_INITIALIZER_LISTS
  46. for (unsigned short i=0; i < MAX_PLUGINS; i++)
  47. {
  48. m_carlaPlugins[i] = nullptr;
  49. m_uniqueNames[i] = nullptr;
  50. }
  51. for (unsigned short i=0; i < MAX_PLUGINS * MAX_PEAKS; i++)
  52. {
  53. m_insPeak[i] = 0.0;
  54. m_outsPeak[i] = 0.0;
  55. }
  56. #endif
  57. }
  58. CarlaEngine::~CarlaEngine()
  59. {
  60. qDebug("CarlaEngine::~CarlaEngine()");
  61. if (name)
  62. free((void*)name);
  63. }
  64. // -----------------------------------------------------------------------
  65. // Static values
  66. int CarlaEngine::maxClientNameSize()
  67. {
  68. #ifdef CARLA_ENGINE_JACK
  69. # ifndef BUILD_BRIDGE
  70. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  71. # endif
  72. return jackbridge_client_name_size();
  73. #endif
  74. return STR_MAX/2;
  75. }
  76. int CarlaEngine::maxPortNameSize()
  77. {
  78. #ifdef CARLA_ENGINE_JACK
  79. # ifndef BUILD_BRIDGE
  80. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  81. # endif
  82. return jackbridge_port_name_size();
  83. #endif
  84. return STR_MAX;
  85. }
  86. unsigned short CarlaEngine::maxPluginNumber()
  87. {
  88. return m_maxPluginNumber;
  89. }
  90. bool CarlaEngine::init(const char* const clientName)
  91. {
  92. qDebug("CarlaEngine::init(\"%s\")", clientName);
  93. #ifndef BUILD_BRIDGE
  94. m_osc.init(clientName);
  95. m_oscData = m_osc.getControllerData();
  96. carla_setprocname(clientName);
  97. #endif
  98. return true;
  99. }
  100. bool CarlaEngine::close()
  101. {
  102. qDebug("CarlaEngine::close()");
  103. m_checkThread.stopNow();
  104. #ifndef BUILD_BRIDGE
  105. osc_send_control_exit();
  106. m_osc.close();
  107. #endif
  108. m_oscData = nullptr;
  109. m_maxPluginNumber = 0;
  110. return true;
  111. }
  112. // -----------------------------------------------------------------------
  113. // plugin management
  114. short CarlaEngine::getNewPluginId() const
  115. {
  116. qDebug("CarlaEngine::getNewPluginId()");
  117. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  118. {
  119. if (! m_carlaPlugins[i])
  120. return i;
  121. }
  122. return -1;
  123. }
  124. CarlaPlugin* CarlaEngine::getPlugin(const unsigned short id) const
  125. {
  126. qDebug("CarlaEngine::getPlugin(%i/%i)", id, m_maxPluginNumber);
  127. Q_ASSERT(m_maxPluginNumber != 0);
  128. Q_ASSERT(id < m_maxPluginNumber);
  129. if (id < m_maxPluginNumber)
  130. return m_carlaPlugins[id];
  131. return nullptr;
  132. }
  133. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned short id) const
  134. {
  135. Q_ASSERT(m_maxPluginNumber != 0);
  136. Q_ASSERT(id < m_maxPluginNumber);
  137. return m_carlaPlugins[id];
  138. }
  139. const char* CarlaEngine::getUniqueName(const char* const name)
  140. {
  141. qDebug("CarlaEngine::getUniqueName(\"%s\")", name);
  142. QString qname(name);
  143. if (qname.isEmpty())
  144. qname = "(No name)";
  145. qname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  146. qname.replace(":", "."); // ":" is used in JACK1 to split client/port names
  147. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  148. {
  149. // Check if unique name already exists
  150. if (m_uniqueNames[i] && qname == m_uniqueNames[i])
  151. {
  152. // Check if string has already been modified
  153. uint len = qname.size();
  154. // 1 digit, ex: " (2)"
  155. if (qname.at(len-4) == QChar(' ') && qname.at(len-3) == QChar('(') && qname.at(len-2).isDigit() && qname.at(len-1) == QChar(')'))
  156. {
  157. int number = qname.at(len-2).toAscii()-'0';
  158. if (number == 9)
  159. // next number is 10, 2 digits
  160. qname.replace(" (9)", " (10)");
  161. else
  162. qname[len-2] = QChar('0'+number+1);
  163. continue;
  164. }
  165. // 2 digits, ex: " (11)"
  166. 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(')'))
  167. {
  168. QChar n2 = qname.at(len-2);
  169. QChar n3 = qname.at(len-3);
  170. if (n2 == QChar('9'))
  171. {
  172. n2 = QChar('0');
  173. n3 = QChar(n3.toAscii()+1);
  174. }
  175. else
  176. n2 = QChar(n2.toAscii()+1);
  177. qname[len-2] = n2;
  178. qname[len-3] = n3;
  179. continue;
  180. }
  181. // Modify string if not
  182. qname += " (2)";
  183. }
  184. }
  185. return strdup(qname.toUtf8().constData());
  186. }
  187. short CarlaEngine::addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  188. {
  189. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  190. }
  191. short CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  192. {
  193. qDebug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2str(btype), PluginType2str(ptype), filename, name, label, extra);
  194. Q_ASSERT(btype != BINARY_NONE);
  195. Q_ASSERT(ptype != PLUGIN_NONE);
  196. Q_ASSERT(filename);
  197. Q_ASSERT(label);
  198. if (m_maxPluginNumber == 0)
  199. #ifdef BUILD_BRIDGE
  200. m_maxPluginNumber = MAX_PLUGINS;
  201. #else
  202. m_maxPluginNumber = (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK) ? 16 : MAX_PLUGINS;
  203. #endif
  204. CarlaPlugin::initializer init = {
  205. this,
  206. filename,
  207. name,
  208. label
  209. };
  210. CarlaPlugin* plugin = nullptr;
  211. #ifndef BUILD_BRIDGE
  212. if (btype != BINARY_NATIVE /*|| true*/)
  213. {
  214. # ifdef CARLA_ENGINE_JACK
  215. if (carlaOptions.processMode != CarlaBackend::PROCESS_MODE_MULTIPLE_CLIENTS)
  216. {
  217. setLastError("Can only use bridged plugins in JACK Multi-Client mode");
  218. return -1;
  219. }
  220. # endif
  221. if (type != CarlaEngineTypeJack)
  222. {
  223. setLastError("Can only use bridged plugins with JACK backend");
  224. return -1;
  225. }
  226. plugin = CarlaPlugin::newBridge(init, btype, ptype);
  227. }
  228. else
  229. #endif
  230. {
  231. switch (ptype)
  232. {
  233. case PLUGIN_NONE:
  234. break;
  235. case PLUGIN_INTERNAL:
  236. #ifndef BUILD_BRIDGE
  237. plugin = CarlaPlugin::newNative(init);
  238. #endif
  239. break;
  240. case PLUGIN_LADSPA:
  241. plugin = CarlaPlugin::newLADSPA(init, extra);
  242. break;
  243. case PLUGIN_DSSI:
  244. plugin = CarlaPlugin::newDSSI(init, extra);
  245. break;
  246. case PLUGIN_LV2:
  247. plugin = CarlaPlugin::newLV2(init);
  248. break;
  249. case PLUGIN_VST:
  250. plugin = CarlaPlugin::newVST(init);
  251. break;
  252. #ifdef BUILD_BRIDGE
  253. case PLUGIN_GIG:
  254. case PLUGIN_SF2:
  255. case PLUGIN_SFZ:
  256. break;
  257. #else
  258. case PLUGIN_GIG:
  259. plugin = CarlaPlugin::newGIG(init);
  260. break;
  261. case PLUGIN_SF2:
  262. plugin = CarlaPlugin::newSF2(init);
  263. break;
  264. case PLUGIN_SFZ:
  265. plugin = CarlaPlugin::newSFZ(init);
  266. break;
  267. #endif
  268. }
  269. }
  270. if (! plugin)
  271. return -1;
  272. const short id = plugin->id();
  273. m_carlaPlugins[id] = plugin;
  274. m_uniqueNames[id] = plugin->name();
  275. if (! m_checkThread.isRunning())
  276. m_checkThread.startNow();
  277. return id;
  278. }
  279. bool CarlaEngine::removePlugin(const unsigned short id)
  280. {
  281. qDebug("CarlaEngine::removePlugin(%i)", id);
  282. Q_ASSERT(m_maxPluginNumber != 0);
  283. Q_ASSERT(id < m_maxPluginNumber);
  284. CarlaPlugin* const plugin = m_carlaPlugins[id];
  285. if (plugin /*&& plugin->id() == id*/)
  286. {
  287. Q_ASSERT(plugin->id() == id);
  288. m_checkThread.stopNow();
  289. processLock();
  290. plugin->setEnabled(false);
  291. processUnlock();
  292. delete plugin;
  293. m_carlaPlugins[id] = nullptr;
  294. m_uniqueNames[id] = nullptr;
  295. #ifndef BUILD_BRIDGE
  296. osc_send_control_remove_plugin(id);
  297. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  298. {
  299. // TODO - handle OSC server comm
  300. for (unsigned short i=id; i < m_maxPluginNumber-1; i++)
  301. {
  302. m_carlaPlugins[i] = m_carlaPlugins[i+1];
  303. m_uniqueNames[i] = m_uniqueNames[i+1];
  304. if (m_carlaPlugins[i])
  305. m_carlaPlugins[i]->setId(i);
  306. }
  307. }
  308. #endif
  309. if (isRunning())
  310. m_checkThread.startNow();
  311. return true;
  312. }
  313. qCritical("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  314. setLastError("Could not find plugin to remove");
  315. return false;
  316. }
  317. void CarlaEngine::removeAllPlugins()
  318. {
  319. qDebug("CarlaEngine::removeAllPlugins()");
  320. m_checkThread.stopNow();
  321. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  322. {
  323. CarlaPlugin* const plugin = m_carlaPlugins[i];
  324. if (plugin)
  325. {
  326. processLock();
  327. plugin->setEnabled(false);
  328. processUnlock();
  329. delete plugin;
  330. m_carlaPlugins[i] = nullptr;
  331. m_uniqueNames[i] = nullptr;
  332. }
  333. }
  334. m_maxPluginNumber = 0;
  335. }
  336. void CarlaEngine::idlePluginGuis()
  337. {
  338. Q_ASSERT(m_maxPluginNumber != 0);
  339. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  340. {
  341. CarlaPlugin* const plugin = m_carlaPlugins[i];
  342. if (plugin && plugin->enabled())
  343. plugin->idleGui();
  344. }
  345. }
  346. // -----------------------------------------------------------------------
  347. // Information (base)
  348. CarlaEngineType CarlaEngine::getType() const
  349. {
  350. return type;
  351. }
  352. const char* CarlaEngine::getName() const
  353. {
  354. Q_ASSERT(name);
  355. return name;
  356. }
  357. double CarlaEngine::getSampleRate() const
  358. {
  359. //Q_ASSERT(sampleRate != 0.0);
  360. return sampleRate;
  361. }
  362. uint32_t CarlaEngine::getBufferSize() const
  363. {
  364. //Q_ASSERT(bufferSize != 0);
  365. return bufferSize;
  366. }
  367. const CarlaTimeInfo* CarlaEngine::getTimeInfo() const
  368. {
  369. return &timeInfo;
  370. }
  371. // -----------------------------------------------------------------------
  372. // Information (audio peaks)
  373. double CarlaEngine::getInputPeak(const unsigned short pluginId, const unsigned short id) const
  374. {
  375. Q_ASSERT(pluginId < m_maxPluginNumber);
  376. Q_ASSERT(id < MAX_PEAKS);
  377. return m_insPeak[pluginId*MAX_PEAKS + id];
  378. }
  379. double CarlaEngine::getOutputPeak(const unsigned short pluginId, const unsigned short id) const
  380. {
  381. Q_ASSERT(pluginId < m_maxPluginNumber);
  382. Q_ASSERT(id < MAX_PEAKS);
  383. return m_outsPeak[pluginId*MAX_PEAKS + id];
  384. }
  385. void CarlaEngine::setInputPeak(const unsigned short pluginId, const unsigned short id, double value)
  386. {
  387. Q_ASSERT(pluginId < m_maxPluginNumber);
  388. Q_ASSERT(id < MAX_PEAKS);
  389. m_insPeak[pluginId*MAX_PEAKS + id] = value;
  390. }
  391. void CarlaEngine::setOutputPeak(const unsigned short pluginId, const unsigned short id, double value)
  392. {
  393. Q_ASSERT(pluginId < m_maxPluginNumber);
  394. Q_ASSERT(id < MAX_PEAKS);
  395. m_outsPeak[pluginId*MAX_PEAKS + id] = value;
  396. }
  397. // -----------------------------------------------------------------------
  398. // Callback
  399. void CarlaEngine::callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3)
  400. {
  401. qDebug("CarlaEngine::callback(%s, %i, %i, %i, %f)", CallbackType2str(action), pluginId, value1, value2, value3);
  402. if (m_callback)
  403. m_callback(m_callbackPtr, action, pluginId, value1, value2, value3);
  404. }
  405. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  406. {
  407. qDebug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  408. m_callback = func;
  409. m_callbackPtr = ptr;
  410. }
  411. // -----------------------------------------------------------------------
  412. // Mutex locks
  413. void CarlaEngine::processLock()
  414. {
  415. m_procLock.lock();
  416. }
  417. void CarlaEngine::processUnlock()
  418. {
  419. m_procLock.unlock();
  420. }
  421. void CarlaEngine::midiLock()
  422. {
  423. m_midiLock.lock();
  424. }
  425. void CarlaEngine::midiUnlock()
  426. {
  427. m_midiLock.unlock();
  428. }
  429. // -----------------------------------------------------------------------
  430. // OSC Stuff
  431. bool CarlaEngine::isOscControllerRegisted() const
  432. {
  433. #ifndef BUILD_BRIDGE
  434. return m_osc.isControllerRegistered();
  435. #else
  436. return bool(m_oscData);
  437. #endif
  438. }
  439. #ifndef BUILD_BRIDGE
  440. const char* CarlaEngine::getOscServerPath() const
  441. {
  442. return m_osc.getServerPath();
  443. }
  444. #else
  445. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  446. {
  447. m_oscData = oscData;
  448. }
  449. #endif
  450. // -----------------------------------------------------------------------
  451. // protected calls
  452. void CarlaEngine::bufferSizeChanged(uint32_t newBufferSize)
  453. {
  454. qDebug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  455. bufferSize = newBufferSize;
  456. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  457. {
  458. if (m_carlaPlugins[i] && m_carlaPlugins[i]->enabled())
  459. m_carlaPlugins[i]->bufferSizeChanged(newBufferSize);
  460. }
  461. }
  462. // -------------------------------------------------------------------------------------------------------------------
  463. // Carla Engine Client
  464. CarlaEngineClient::CarlaEngineClient(const CarlaEngineType& type_, const CarlaEngineClientNativeHandle& handle_)
  465. : type(type_),
  466. handle(handle_)
  467. {
  468. qDebug("CarlaEngineClient::CarlaEngineClient()");
  469. Q_ASSERT(type != CarlaEngineTypeNull);
  470. m_active = false;
  471. }
  472. CarlaEngineClient::~CarlaEngineClient()
  473. {
  474. qDebug("CarlaEngineClient::~CarlaEngineClient()");
  475. Q_ASSERT(! m_active);
  476. #ifndef BUILD_BRIDGE
  477. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  478. #endif
  479. {
  480. #ifdef CARLA_ENGINE_JACK
  481. if (handle.jackClient)
  482. jackbridge_client_close(handle.jackClient);
  483. #endif
  484. #ifdef CARLA_ENGINE_RTAUDIO
  485. if (handle.rtAudioPtr)
  486. delete handle.rtAudioPtr;
  487. #endif
  488. }
  489. }
  490. void CarlaEngineClient::activate()
  491. {
  492. qDebug("CarlaEngineClient::activate()");
  493. Q_ASSERT(! m_active);
  494. #ifndef BUILD_BRIDGE
  495. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  496. #endif
  497. {
  498. if (! m_active)
  499. {
  500. #ifdef CARLA_ENGINE_JACK
  501. if (handle.jackClient)
  502. jackbridge_activate(handle.jackClient);
  503. #endif
  504. #ifdef CARLA_ENGINE_RTAUDIO
  505. if (handle.rtAudioPtr)
  506. handle.rtAudioPtr->startStream();
  507. #endif
  508. }
  509. }
  510. m_active = true;
  511. }
  512. void CarlaEngineClient::deactivate()
  513. {
  514. qDebug("CarlaEngineClient::deactivate()");
  515. Q_ASSERT(m_active);
  516. #ifndef BUILD_BRIDGE
  517. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  518. #endif
  519. {
  520. if (m_active)
  521. {
  522. #ifdef CARLA_ENGINE_JACK
  523. if (handle.jackClient)
  524. jackbridge_deactivate(handle.jackClient);
  525. #endif
  526. #ifdef CARLA_ENGINE_RTAUDIO
  527. if (handle.rtAudioPtr)
  528. handle.rtAudioPtr->stopStream();
  529. #endif
  530. }
  531. }
  532. m_active = false;
  533. }
  534. bool CarlaEngineClient::isActive() const
  535. {
  536. qDebug("CarlaEngineClient::isActive()");
  537. return m_active;
  538. }
  539. bool CarlaEngineClient::isOk() const
  540. {
  541. qDebug("CarlaEngineClient::isOk()");
  542. #ifndef BUILD_BRIDGE
  543. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  544. #endif
  545. {
  546. #ifdef CARLA_ENGINE_JACK
  547. if (type == CarlaEngineTypeJack)
  548. return bool(handle.jackClient);
  549. #endif
  550. #ifdef CARLA_ENGINE_RTAUDIO
  551. if (type == CarlaEngineTypeRtAudio)
  552. return bool(handle.rtAudioPtr);
  553. #endif
  554. }
  555. return true;
  556. }
  557. const CarlaEngineBasePort* CarlaEngineClient::addPort(const CarlaEnginePortType portType, const char* const name, const bool isInput)
  558. {
  559. qDebug("CarlaEngineClient::addPort(%i, \"%s\", %s)", type, name, bool2str(isInput));
  560. CarlaEnginePortNativeHandle portHandle;
  561. #ifdef CARLA_ENGINE_JACK
  562. portHandle.jackClient = handle.jackClient;
  563. #endif
  564. #ifndef BUILD_BRIDGE
  565. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  566. #endif
  567. {
  568. #ifdef CARLA_ENGINE_JACK
  569. if (type == CarlaEngineTypeJack)
  570. {
  571. switch (portType)
  572. {
  573. case CarlaEnginePortTypeAudio:
  574. portHandle.jackPort = jackbridge_port_register(handle.jackClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  575. break;
  576. case CarlaEnginePortTypeControl:
  577. case CarlaEnginePortTypeMIDI:
  578. portHandle.jackPort = jackbridge_port_register(handle.jackClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  579. break;
  580. }
  581. }
  582. #endif
  583. #ifdef CARLA_ENGINE_RTAUDIO
  584. if (type == CarlaEngineTypeRtAudio)
  585. {
  586. // TODO
  587. }
  588. #endif
  589. }
  590. switch (portType)
  591. {
  592. case CarlaEnginePortTypeAudio:
  593. return new CarlaEngineAudioPort(portHandle, isInput);
  594. case CarlaEnginePortTypeControl:
  595. return new CarlaEngineControlPort(portHandle, isInput);
  596. case CarlaEnginePortTypeMIDI:
  597. return new CarlaEngineMidiPort(portHandle, isInput);
  598. }
  599. qCritical("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", type, name, bool2str(isInput));
  600. return nullptr;
  601. }
  602. // -------------------------------------------------------------------------------------------------------------------
  603. // Carla Engine Port (Base class)
  604. CarlaEngineBasePort::CarlaEngineBasePort(const CarlaEnginePortNativeHandle& handle_, const bool isInput_)
  605. : isInput(isInput_),
  606. handle(handle_)
  607. {
  608. qDebug("CarlaEngineBasePort::CarlaEngineBasePort(%s)", bool2str(isInput_));
  609. buffer = nullptr;
  610. }
  611. CarlaEngineBasePort::~CarlaEngineBasePort()
  612. {
  613. qDebug("CarlaEngineBasePort::~CarlaEngineBasePort()");
  614. #ifndef BUILD_BRIDGE
  615. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  616. return;
  617. #endif
  618. #ifdef CARLA_ENGINE_JACK
  619. if (handle.jackClient && handle.jackPort)
  620. jackbridge_port_unregister(handle.jackClient, handle.jackPort);
  621. #endif
  622. #ifdef CARLA_ENGINE_RTAUDIO
  623. // TODO
  624. #endif
  625. }
  626. // -------------------------------------------------------------------------------------------------------------------
  627. // Carla Engine Port (Audio)
  628. CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  629. : CarlaEngineBasePort(handle, isInput)
  630. {
  631. qDebug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInput));
  632. }
  633. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const /*engine*/)
  634. {
  635. }
  636. #ifdef CARLA_ENGINE_JACK
  637. float* CarlaEngineAudioPort::getJackAudioBuffer(uint32_t nframes)
  638. {
  639. # ifndef BUILD_BRIDGE
  640. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  641. return nullptr;
  642. # endif
  643. Q_ASSERT(handle.jackPort);
  644. return (float*)jackbridge_port_get_buffer(handle.jackPort, nframes);
  645. }
  646. #endif
  647. // -------------------------------------------------------------------------------------------------------------------
  648. // Carla Engine Port (Control)
  649. CarlaEngineControlPort::CarlaEngineControlPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  650. : CarlaEngineBasePort(handle, isInput)
  651. {
  652. qDebug("CarlaEngineControlPort::CarlaEngineControlPort(%s)", bool2str(isInput));
  653. }
  654. void CarlaEngineControlPort::initBuffer(CarlaEngine* const engine)
  655. {
  656. Q_ASSERT(engine);
  657. #ifndef BUILD_BRIDGE
  658. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  659. {
  660. buffer = isInput ? engine->rackControlEventsIn : engine->rackControlEventsOut;
  661. return;
  662. }
  663. #endif
  664. #ifdef CARLA_ENGINE_JACK
  665. if (handle.jackPort)
  666. {
  667. buffer = jackbridge_port_get_buffer(handle.jackPort, engine->getBufferSize());
  668. if (! isInput)
  669. jackbridge_midi_clear_buffer(buffer);
  670. }
  671. #endif
  672. #ifdef CARLA_ENGINE_RTAUDIO
  673. // TODO
  674. #endif
  675. }
  676. uint32_t CarlaEngineControlPort::getEventCount()
  677. {
  678. if (! isInput)
  679. return 0;
  680. Q_ASSERT(buffer);
  681. #ifndef BUILD_BRIDGE
  682. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  683. {
  684. uint32_t count = 0;
  685. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  686. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  687. {
  688. if (events[i].type != CarlaEngineEventNull)
  689. count++;
  690. else
  691. break;
  692. }
  693. return count;
  694. }
  695. #endif
  696. #ifdef CARLA_ENGINE_JACK
  697. if (handle.jackPort)
  698. return jackbridge_midi_get_event_count(buffer);
  699. #endif
  700. #ifdef CARLA_ENGINE_RTAUDIO
  701. // TODO
  702. #endif
  703. return 0;
  704. }
  705. const CarlaEngineControlEvent* CarlaEngineControlPort::getEvent(uint32_t index)
  706. {
  707. if (! isInput)
  708. return nullptr;
  709. Q_ASSERT(buffer);
  710. #ifndef BUILD_BRIDGE
  711. Q_ASSERT(index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS);
  712. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  713. {
  714. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  715. if (index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS)
  716. return &events[index];
  717. return nullptr;
  718. }
  719. #endif
  720. #ifdef CARLA_ENGINE_JACK
  721. if (handle.jackPort)
  722. {
  723. static jackbridge_midi_event_t jackEvent;
  724. static CarlaEngineControlEvent carlaEvent;
  725. if (jackbridge_midi_event_get(&jackEvent, buffer, index) != 0)
  726. return nullptr;
  727. memset(&carlaEvent, 0, sizeof(CarlaEngineControlEvent));
  728. uint8_t midiStatus = jackEvent.buffer[0];
  729. uint8_t midiChannel = midiStatus & 0x0F;
  730. carlaEvent.time = jackEvent.time;
  731. carlaEvent.channel = midiChannel;
  732. if (MIDI_IS_STATUS_CONTROL_CHANGE(midiStatus))
  733. {
  734. uint8_t midiControl = jackEvent.buffer[1];
  735. if (MIDI_IS_CONTROL_BANK_SELECT(midiControl))
  736. {
  737. uint8_t midiBank = jackEvent.buffer[2];
  738. carlaEvent.type = CarlaEngineEventMidiBankChange;
  739. carlaEvent.value = midiBank;
  740. }
  741. else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF)
  742. {
  743. carlaEvent.type = CarlaEngineEventAllSoundOff;
  744. }
  745. else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF)
  746. {
  747. carlaEvent.type = CarlaEngineEventAllNotesOff;
  748. }
  749. else
  750. {
  751. uint8_t midiValue = jackEvent.buffer[2];
  752. carlaEvent.type = CarlaEngineEventControlChange;
  753. carlaEvent.controller = midiControl;
  754. carlaEvent.value = double(midiValue)/127;
  755. }
  756. return &carlaEvent;
  757. }
  758. else if (MIDI_IS_STATUS_PROGRAM_CHANGE(midiStatus))
  759. {
  760. uint8_t midiProgram = jackEvent.buffer[1];
  761. carlaEvent.type = CarlaEngineEventMidiProgramChange;
  762. carlaEvent.value = midiProgram;
  763. return &carlaEvent;
  764. }
  765. }
  766. #endif
  767. #ifdef CARLA_ENGINE_RTAUDIO
  768. // TODO
  769. #endif
  770. return nullptr;
  771. }
  772. void CarlaEngineControlPort::writeEvent(CarlaEngineControlEventType type, uint32_t time, uint8_t channel, uint8_t controller, double value)
  773. {
  774. if (isInput)
  775. return;
  776. Q_ASSERT(buffer);
  777. Q_ASSERT(type != CarlaEngineEventNull);
  778. #ifndef BUILD_BRIDGE
  779. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  780. {
  781. CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  782. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  783. {
  784. if (events[i].type == CarlaEngineEventNull)
  785. {
  786. events[i].type = type;
  787. events[i].time = time;
  788. events[i].value = value;
  789. events[i].channel = channel;
  790. events[i].controller = controller;
  791. break;
  792. }
  793. }
  794. return;
  795. }
  796. #endif
  797. #ifdef CARLA_ENGINE_JACK
  798. if (handle.jackPort)
  799. {
  800. if (type == CarlaEngineEventControlChange && MIDI_IS_CONTROL_BANK_SELECT(controller))
  801. type = CarlaEngineEventMidiBankChange;
  802. uint8_t data[4] = { 0 };
  803. switch (type)
  804. {
  805. case CarlaEngineEventNull:
  806. break;
  807. case CarlaEngineEventControlChange:
  808. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  809. data[1] = controller;
  810. data[2] = value * 127;
  811. jackbridge_midi_event_write(buffer, time, data, 3);
  812. break;
  813. case CarlaEngineEventMidiBankChange:
  814. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  815. data[1] = MIDI_CONTROL_BANK_SELECT;
  816. data[2] = value;
  817. jackbridge_midi_event_write(buffer, time, data, 3);
  818. break;
  819. case CarlaEngineEventMidiProgramChange:
  820. data[0] = MIDI_STATUS_PROGRAM_CHANGE + channel;
  821. data[1] = value;
  822. jackbridge_midi_event_write(buffer, time, data, 2);
  823. break;
  824. case CarlaEngineEventAllSoundOff:
  825. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  826. data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  827. jackbridge_midi_event_write(buffer, time, data, 2);
  828. break;
  829. case CarlaEngineEventAllNotesOff:
  830. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  831. data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  832. jackbridge_midi_event_write(buffer, time, data, 2);
  833. break;
  834. }
  835. }
  836. #endif
  837. #ifdef CARLA_ENGINE_RTAUDIO
  838. // TODO
  839. #endif
  840. }
  841. // -------------------------------------------------------------------------------------------------------------------
  842. // Carla Engine Port (MIDI)
  843. CarlaEngineMidiPort::CarlaEngineMidiPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  844. : CarlaEngineBasePort(handle, isInput)
  845. {
  846. qDebug("CarlaEngineMidiPort::CarlaEngineMidiPort(%s)", bool2str(isInput));
  847. }
  848. void CarlaEngineMidiPort::initBuffer(CarlaEngine* const engine)
  849. {
  850. Q_ASSERT(engine);
  851. #ifndef BUILD_BRIDGE
  852. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  853. {
  854. buffer = isInput ? engine->rackMidiEventsIn : engine->rackMidiEventsOut;
  855. return;
  856. }
  857. #endif
  858. #ifdef CARLA_ENGINE_JACK
  859. if (handle.jackPort)
  860. {
  861. buffer = jackbridge_port_get_buffer(handle.jackPort, engine->getBufferSize());
  862. if (! isInput)
  863. jackbridge_midi_clear_buffer(buffer);
  864. }
  865. #endif
  866. #ifdef CARLA_ENGINE_RTAUDIO
  867. // TODO
  868. #endif
  869. }
  870. uint32_t CarlaEngineMidiPort::getEventCount()
  871. {
  872. if (! isInput)
  873. return 0;
  874. Q_ASSERT(buffer);
  875. #ifndef BUILD_BRIDGE
  876. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  877. {
  878. uint32_t count = 0;
  879. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  880. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  881. {
  882. if (events[i].size > 0)
  883. count++;
  884. else
  885. break;
  886. }
  887. return count;
  888. }
  889. #endif
  890. #ifdef CARLA_ENGINE_JACK
  891. if (handle.jackPort)
  892. return jackbridge_midi_get_event_count(buffer);
  893. #endif
  894. #ifdef CARLA_ENGINE_RTAUDIO
  895. // TODO
  896. #endif
  897. return 0;
  898. }
  899. const CarlaEngineMidiEvent* CarlaEngineMidiPort::getEvent(uint32_t index)
  900. {
  901. if (! isInput)
  902. return nullptr;
  903. Q_ASSERT(buffer);
  904. #ifndef BUILD_BRIDGE
  905. Q_ASSERT(index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS);
  906. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  907. {
  908. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  909. if (index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS)
  910. return &events[index];
  911. return nullptr;
  912. }
  913. #endif
  914. #ifdef CARLA_ENGINE_JACK
  915. if (handle.jackPort)
  916. {
  917. static jackbridge_midi_event_t jackEvent;
  918. static CarlaEngineMidiEvent carlaEvent;
  919. if (jackbridge_midi_event_get(&jackEvent, buffer, index) == 0 && jackEvent.size <= 4)
  920. {
  921. carlaEvent.time = jackEvent.time;
  922. carlaEvent.size = jackEvent.size;
  923. memcpy(carlaEvent.data, jackEvent.buffer, jackEvent.size);
  924. return &carlaEvent;
  925. }
  926. }
  927. #endif
  928. #ifdef CARLA_ENGINE_RTAUDIO
  929. // TODO
  930. #endif
  931. return nullptr;
  932. }
  933. void CarlaEngineMidiPort::writeEvent(uint32_t time, const uint8_t* data, uint8_t size)
  934. {
  935. if (isInput)
  936. return;
  937. Q_ASSERT(buffer);
  938. Q_ASSERT(data);
  939. Q_ASSERT(size > 0);
  940. #ifndef BUILD_BRIDGE
  941. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  942. {
  943. if (size > 4)
  944. return;
  945. CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  946. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  947. {
  948. if (events[i].size == 0)
  949. {
  950. events[i].time = time;
  951. events[i].size = size;
  952. memcpy(events[i].data, data, size);
  953. break;
  954. }
  955. }
  956. return;
  957. }
  958. #endif
  959. #ifdef CARLA_ENGINE_JACK
  960. if (handle.jackPort)
  961. jackbridge_midi_event_write(buffer, time, data, size);
  962. #endif
  963. #ifdef CARLA_ENGINE_RTAUDIO
  964. // TODO
  965. #endif
  966. }
  967. // -------------------------------------------------------------------------------------------------------------------
  968. // Carla Engine OSC stuff
  969. #ifndef BUILD_BRIDGE
  970. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  971. {
  972. qDebug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  973. Q_ASSERT(m_oscData);
  974. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  975. Q_ASSERT(pluginName);
  976. if (m_oscData && m_oscData->target)
  977. {
  978. char target_path[strlen(m_oscData->path)+18];
  979. strcpy(target_path, m_oscData->path);
  980. strcat(target_path, "/add_plugin_start");
  981. lo_send(m_oscData->target, target_path, "is", pluginId, pluginName);
  982. }
  983. }
  984. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  985. {
  986. qDebug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  987. Q_ASSERT(m_oscData);
  988. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  989. if (m_oscData && m_oscData->target)
  990. {
  991. char target_path[strlen(m_oscData->path)+16];
  992. strcpy(target_path, m_oscData->path);
  993. strcat(target_path, "/add_plugin_end");
  994. lo_send(m_oscData->target, target_path, "i", pluginId);
  995. }
  996. }
  997. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  998. {
  999. qDebug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1000. Q_ASSERT(m_oscData);
  1001. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1002. if (m_oscData && m_oscData->target)
  1003. {
  1004. char target_path[strlen(m_oscData->path)+15];
  1005. strcpy(target_path, m_oscData->path);
  1006. strcat(target_path, "/remove_plugin");
  1007. lo_send(m_oscData->target, target_path, "i", pluginId);
  1008. }
  1009. }
  1010. void CarlaEngine::osc_send_control_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)
  1011. {
  1012. qDebug("CarlaEngine::osc_send_control_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1013. Q_ASSERT(m_oscData);
  1014. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1015. Q_ASSERT(type != PLUGIN_NONE);
  1016. if (m_oscData && m_oscData->target)
  1017. {
  1018. char target_path[strlen(m_oscData->path)+17];
  1019. strcpy(target_path, m_oscData->path);
  1020. strcat(target_path, "/set_plugin_data");
  1021. lo_send(m_oscData->target, target_path, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1022. }
  1023. }
  1024. void CarlaEngine::osc_send_control_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)
  1025. {
  1026. qDebug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1027. Q_ASSERT(m_oscData);
  1028. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1029. if (m_oscData && m_oscData->target)
  1030. {
  1031. char target_path[strlen(m_oscData->path)+18];
  1032. strcpy(target_path, m_oscData->path);
  1033. strcat(target_path, "/set_plugin_ports");
  1034. lo_send(m_oscData->target, target_path, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1035. }
  1036. }
  1037. void CarlaEngine::osc_send_control_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)
  1038. {
  1039. qDebug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1040. Q_ASSERT(m_oscData);
  1041. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1042. Q_ASSERT(index >= 0);
  1043. Q_ASSERT(type != PARAMETER_UNKNOWN);
  1044. if (m_oscData && m_oscData->target)
  1045. {
  1046. char target_path[strlen(m_oscData->path)+20];
  1047. strcpy(target_path, m_oscData->path);
  1048. strcat(target_path, "/set_parameter_data");
  1049. lo_send(m_oscData->target, target_path, "iiiissd", pluginId, index, type, hints, name, label, current);
  1050. }
  1051. }
  1052. void CarlaEngine::osc_send_control_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)
  1053. {
  1054. qDebug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1055. Q_ASSERT(m_oscData);
  1056. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1057. Q_ASSERT(index >= 0);
  1058. Q_ASSERT(min < max);
  1059. if (m_oscData && m_oscData->target)
  1060. {
  1061. char target_path[strlen(m_oscData->path)+22];
  1062. strcpy(target_path, m_oscData->path);
  1063. strcat(target_path, "/set_parameter_ranges");
  1064. lo_send(m_oscData->target, target_path, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1065. }
  1066. }
  1067. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1068. {
  1069. qDebug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1070. Q_ASSERT(m_oscData);
  1071. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1072. Q_ASSERT(index >= 0);
  1073. if (m_oscData && m_oscData->target)
  1074. {
  1075. char target_path[strlen(m_oscData->path)+23];
  1076. strcpy(target_path, m_oscData->path);
  1077. strcat(target_path, "/set_parameter_midi_cc");
  1078. lo_send(m_oscData->target, target_path, "iii", pluginId, index, cc);
  1079. }
  1080. }
  1081. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1082. {
  1083. qDebug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1084. Q_ASSERT(m_oscData);
  1085. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1086. Q_ASSERT(index >= 0);
  1087. Q_ASSERT(channel >= 0 && channel < 16);
  1088. if (m_oscData && m_oscData->target)
  1089. {
  1090. char target_path[strlen(m_oscData->path)+28];
  1091. strcpy(target_path, m_oscData->path);
  1092. strcat(target_path, "/set_parameter_midi_channel");
  1093. lo_send(m_oscData->target, target_path, "iii", pluginId, index, channel);
  1094. }
  1095. }
  1096. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const double value)
  1097. {
  1098. #if DEBUG
  1099. if (index < -1)
  1100. qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2str((InternalParametersIndex)index), value);
  1101. else
  1102. qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1103. #endif
  1104. Q_ASSERT(m_oscData);
  1105. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1106. if (m_oscData && m_oscData->target)
  1107. {
  1108. char target_path[strlen(m_oscData->path)+21];
  1109. strcpy(target_path, m_oscData->path);
  1110. strcat(target_path, "/set_parameter_value");
  1111. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1112. }
  1113. }
  1114. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value)
  1115. {
  1116. qDebug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1117. Q_ASSERT(m_oscData);
  1118. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1119. Q_ASSERT(index >= 0);
  1120. if (m_oscData && m_oscData->target)
  1121. {
  1122. char target_path[strlen(m_oscData->path)+19];
  1123. strcpy(target_path, m_oscData->path);
  1124. strcat(target_path, "/set_default_value");
  1125. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1126. }
  1127. }
  1128. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1129. {
  1130. qDebug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1131. Q_ASSERT(m_oscData);
  1132. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1133. if (m_oscData && m_oscData->target)
  1134. {
  1135. char target_path[strlen(m_oscData->path)+13];
  1136. strcpy(target_path, m_oscData->path);
  1137. strcat(target_path, "/set_program");
  1138. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1139. }
  1140. }
  1141. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1142. {
  1143. qDebug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1144. Q_ASSERT(m_oscData);
  1145. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1146. Q_ASSERT(count >= 0);
  1147. if (m_oscData && m_oscData->target)
  1148. {
  1149. char target_path[strlen(m_oscData->path)+19];
  1150. strcpy(target_path, m_oscData->path);
  1151. strcat(target_path, "/set_program_count");
  1152. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1153. }
  1154. }
  1155. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1156. {
  1157. qDebug("CarlaEngine::osc_send_control_set_program_name(%i, %i, %s)", pluginId, index, name);
  1158. Q_ASSERT(m_oscData);
  1159. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1160. Q_ASSERT(index >= 0);
  1161. Q_ASSERT(name);
  1162. if (m_oscData && m_oscData->target)
  1163. {
  1164. char target_path[strlen(m_oscData->path)+18];
  1165. strcpy(target_path, m_oscData->path);
  1166. strcat(target_path, "/set_program_name");
  1167. lo_send(m_oscData->target, target_path, "iis", pluginId, index, name);
  1168. }
  1169. }
  1170. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1171. {
  1172. qDebug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1173. Q_ASSERT(m_oscData);
  1174. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1175. if (m_oscData && m_oscData->target)
  1176. {
  1177. char target_path[strlen(m_oscData->path)+18];
  1178. strcpy(target_path, m_oscData->path);
  1179. strcat(target_path, "/set_midi_program");
  1180. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1181. }
  1182. }
  1183. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1184. {
  1185. qDebug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1186. Q_ASSERT(m_oscData);
  1187. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1188. Q_ASSERT(count >= 0);
  1189. if (m_oscData && m_oscData->target)
  1190. {
  1191. char target_path[strlen(m_oscData->path)+24];
  1192. strcpy(target_path, m_oscData->path);
  1193. strcat(target_path, "/set_midi_program_count");
  1194. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1195. }
  1196. }
  1197. void CarlaEngine::osc_send_control_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name)
  1198. {
  1199. qDebug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, %s)", pluginId, index, bank, program, name);
  1200. Q_ASSERT(m_oscData);
  1201. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1202. Q_ASSERT(index >= 0);
  1203. Q_ASSERT(bank >= 0);
  1204. Q_ASSERT(program >= 0);
  1205. Q_ASSERT(name);
  1206. if (m_oscData && m_oscData->target)
  1207. {
  1208. char target_path[strlen(m_oscData->path)+23];
  1209. strcpy(target_path, m_oscData->path);
  1210. strcat(target_path, "/set_midi_program_data");
  1211. lo_send(m_oscData->target, target_path, "iiiis", pluginId, index, bank, program, name);
  1212. }
  1213. }
  1214. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1215. {
  1216. qDebug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1217. Q_ASSERT(m_oscData);
  1218. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1219. Q_ASSERT(channel >= 0 && channel < 16);
  1220. Q_ASSERT(note >= 0 && note < 128);
  1221. Q_ASSERT(velo > 0 && velo < 128);
  1222. if (m_oscData && m_oscData->target)
  1223. {
  1224. char target_path[strlen(m_oscData->path)+9];
  1225. strcpy(target_path, m_oscData->path);
  1226. strcat(target_path, "/note_on");
  1227. lo_send(m_oscData->target, target_path, "iiii", pluginId, channel, note, velo);
  1228. }
  1229. }
  1230. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1231. {
  1232. qDebug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1233. Q_ASSERT(m_oscData);
  1234. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1235. Q_ASSERT(channel >= 0 && channel < 16);
  1236. Q_ASSERT(note >= 0 && note < 128);
  1237. if (m_oscData && m_oscData->target)
  1238. {
  1239. char target_path[strlen(m_oscData->path)+10];
  1240. strcpy(target_path, m_oscData->path);
  1241. strcat(target_path, "/note_off");
  1242. lo_send(m_oscData->target, target_path, "iii", pluginId, channel, note);
  1243. }
  1244. }
  1245. void CarlaEngine::osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1246. {
  1247. //qDebug("CarlaEngine::osc_send_control_set_input_peak_value(%i, %i, %g)", pluginId, portId, value);
  1248. Q_ASSERT(m_oscData);
  1249. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1250. Q_ASSERT(portId == 1 || portId == 2);
  1251. if (m_oscData && m_oscData->target)
  1252. {
  1253. char target_path[strlen(m_oscData->path)+22];
  1254. strcpy(target_path, m_oscData->path);
  1255. strcat(target_path, "/set_input_peak_value");
  1256. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1257. }
  1258. }
  1259. void CarlaEngine::osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1260. {
  1261. //qDebug("CarlaEngine::osc_send_control_set_output_peak_value(%i, %i, %g)", pluginId, portId, value);
  1262. Q_ASSERT(m_oscData);
  1263. Q_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1264. Q_ASSERT(portId == 1 || portId == 2);
  1265. if (m_oscData && m_oscData->target)
  1266. {
  1267. char target_path[strlen(m_oscData->path)+23];
  1268. strcpy(target_path, m_oscData->path);
  1269. strcat(target_path, "/set_output_peak_value");
  1270. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1271. }
  1272. }
  1273. void CarlaEngine::osc_send_control_exit()
  1274. {
  1275. qDebug("CarlaEngine::osc_send_control_exit()");
  1276. Q_ASSERT(m_oscData);
  1277. if (m_oscData && m_oscData->target)
  1278. {
  1279. char target_path[strlen(m_oscData->path)+6];
  1280. strcpy(target_path, m_oscData->path);
  1281. strcat(target_path, "/exit");
  1282. lo_send(m_oscData->target, target_path, "");
  1283. }
  1284. }
  1285. #else
  1286. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1287. {
  1288. qDebug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1289. Q_ASSERT(m_oscData);
  1290. Q_ASSERT(total >= 0 && total >= ins + outs);
  1291. if (m_oscData && m_oscData->target)
  1292. {
  1293. char target_path[strlen(m_oscData->path)+20];
  1294. strcpy(target_path, m_oscData->path);
  1295. strcat(target_path, "/bridge_audio_count");
  1296. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1297. }
  1298. }
  1299. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1300. {
  1301. qDebug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1302. Q_ASSERT(m_oscData);
  1303. Q_ASSERT(total >= 0 && total >= ins + outs);
  1304. if (m_oscData && m_oscData->target)
  1305. {
  1306. char target_path[strlen(m_oscData->path)+19];
  1307. strcpy(target_path, m_oscData->path);
  1308. strcat(target_path, "/bridge_midi_count");
  1309. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1310. }
  1311. }
  1312. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1313. {
  1314. qDebug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1315. Q_ASSERT(m_oscData);
  1316. Q_ASSERT(total >= 0 && total >= ins + outs);
  1317. if (m_oscData && m_oscData->target)
  1318. {
  1319. char target_path[strlen(m_oscData->path)+24];
  1320. strcpy(target_path, m_oscData->path);
  1321. strcat(target_path, "/bridge_parameter_count");
  1322. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1323. }
  1324. }
  1325. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1326. {
  1327. qDebug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1328. Q_ASSERT(m_oscData);
  1329. Q_ASSERT(count >= 0);
  1330. if (m_oscData && m_oscData->target)
  1331. {
  1332. char target_path[strlen(m_oscData->path)+22];
  1333. strcpy(target_path, m_oscData->path);
  1334. strcat(target_path, "/bridge_program_count");
  1335. lo_send(m_oscData->target, target_path, "i", count);
  1336. }
  1337. }
  1338. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1339. {
  1340. qDebug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1341. Q_ASSERT(m_oscData);
  1342. Q_ASSERT(count >= 0);
  1343. if (m_oscData && m_oscData->target)
  1344. {
  1345. char target_path[strlen(m_oscData->path)+27];
  1346. strcpy(target_path, m_oscData->path);
  1347. strcat(target_path, "/bridge_midi_program_count");
  1348. lo_send(m_oscData->target, target_path, "i", count);
  1349. }
  1350. }
  1351. void CarlaEngine::osc_send_bridge_plugin_info(const int32_t category, const int32_t hints, const char* const name, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1352. {
  1353. qDebug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1354. Q_ASSERT(m_oscData);
  1355. Q_ASSERT(name);
  1356. Q_ASSERT(label);
  1357. Q_ASSERT(maker);
  1358. Q_ASSERT(copyright);
  1359. if (m_oscData && m_oscData->target)
  1360. {
  1361. char target_path[strlen(m_oscData->path)+20];
  1362. strcpy(target_path, m_oscData->path);
  1363. strcat(target_path, "/bridge_plugin_info");
  1364. lo_send(m_oscData->target, target_path, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1365. }
  1366. }
  1367. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1368. {
  1369. qDebug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1370. Q_ASSERT(m_oscData);
  1371. Q_ASSERT(name);
  1372. Q_ASSERT(unit);
  1373. if (m_oscData && m_oscData->target)
  1374. {
  1375. char target_path[strlen(m_oscData->path)+23];
  1376. strcpy(target_path, m_oscData->path);
  1377. strcat(target_path, "/bridge_parameter_info");
  1378. lo_send(m_oscData->target, target_path, "iss", index, name, unit);
  1379. }
  1380. }
  1381. void CarlaEngine::osc_send_bridge_parameter_data(const int32_t index, const int32_t type, const int32_t rindex, const int32_t hints, const int32_t midiChannel, const int32_t midiCC)
  1382. {
  1383. qDebug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1384. Q_ASSERT(m_oscData);
  1385. if (m_oscData && m_oscData->target)
  1386. {
  1387. char target_path[strlen(m_oscData->path)+23];
  1388. strcpy(target_path, m_oscData->path);
  1389. strcat(target_path, "/bridge_parameter_data");
  1390. lo_send(m_oscData->target, target_path, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1391. }
  1392. }
  1393. void CarlaEngine::osc_send_bridge_parameter_ranges(const int32_t index, const double def, const double min, const double max, const double step, const double stepSmall, const double stepLarge)
  1394. {
  1395. qDebug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1396. Q_ASSERT(m_oscData);
  1397. if (m_oscData && m_oscData->target)
  1398. {
  1399. char target_path[strlen(m_oscData->path)+25];
  1400. strcpy(target_path, m_oscData->path);
  1401. strcat(target_path, "/bridge_parameter_ranges");
  1402. lo_send(m_oscData->target, target_path, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1403. }
  1404. }
  1405. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1406. {
  1407. qDebug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1408. Q_ASSERT(m_oscData);
  1409. if (m_oscData && m_oscData->target)
  1410. {
  1411. char target_path[strlen(m_oscData->path)+21];
  1412. strcpy(target_path, m_oscData->path);
  1413. strcat(target_path, "/bridge_program_info");
  1414. lo_send(m_oscData->target, target_path, "is", index, name);
  1415. }
  1416. }
  1417. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1418. {
  1419. qDebug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1420. Q_ASSERT(m_oscData);
  1421. if (m_oscData && m_oscData->target)
  1422. {
  1423. char target_path[strlen(m_oscData->path)+26];
  1424. strcpy(target_path, m_oscData->path);
  1425. strcat(target_path, "/bridge_midi_program_info");
  1426. lo_send(m_oscData->target, target_path, "iiis", index, bank, program, label);
  1427. }
  1428. }
  1429. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1430. {
  1431. qDebug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1432. Q_ASSERT(m_oscData);
  1433. Q_ASSERT(key);
  1434. Q_ASSERT(value);
  1435. if (m_oscData && m_oscData->target)
  1436. {
  1437. char target_path[strlen(m_oscData->path)+18];
  1438. strcpy(target_path, m_oscData->path);
  1439. strcat(target_path, "/bridge_configure");
  1440. lo_send(m_oscData->target, target_path, "ss", key, value);
  1441. }
  1442. }
  1443. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const double value)
  1444. {
  1445. qDebug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1446. Q_ASSERT(m_oscData);
  1447. if (m_oscData && m_oscData->target)
  1448. {
  1449. char target_path[strlen(m_oscData->path)+28];
  1450. strcpy(target_path, m_oscData->path);
  1451. strcat(target_path, "/bridge_set_parameter_value");
  1452. lo_send(m_oscData->target, target_path, "id", index, value);
  1453. }
  1454. }
  1455. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const double value)
  1456. {
  1457. qDebug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1458. Q_ASSERT(m_oscData);
  1459. if (m_oscData && m_oscData->target)
  1460. {
  1461. char target_path[strlen(m_oscData->path)+26];
  1462. strcpy(target_path, m_oscData->path);
  1463. strcat(target_path, "/bridge_set_default_value");
  1464. lo_send(m_oscData->target, target_path, "id", index, value);
  1465. }
  1466. }
  1467. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1468. {
  1469. qDebug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1470. Q_ASSERT(m_oscData);
  1471. if (m_oscData && m_oscData->target)
  1472. {
  1473. char target_path[strlen(m_oscData->path)+20];
  1474. strcpy(target_path, m_oscData->path);
  1475. strcat(target_path, "/bridge_set_program");
  1476. lo_send(m_oscData->target, target_path, "i", index);
  1477. }
  1478. }
  1479. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1480. {
  1481. qDebug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1482. Q_ASSERT(m_oscData);
  1483. if (m_oscData && m_oscData->target)
  1484. {
  1485. char target_path[strlen(m_oscData->path)+25];
  1486. strcpy(target_path, m_oscData->path);
  1487. strcat(target_path, "/bridge_set_midi_program");
  1488. lo_send(m_oscData->target, target_path, "i", index);
  1489. }
  1490. }
  1491. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const stype, const char* const key, const char* const value)
  1492. {
  1493. qDebug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", stype, key, value);
  1494. Q_ASSERT(m_oscData);
  1495. if (m_oscData && m_oscData->target)
  1496. {
  1497. char target_path[strlen(m_oscData->path)+24];
  1498. strcpy(target_path, m_oscData->path);
  1499. strcat(target_path, "/bridge_set_custom_data");
  1500. lo_send(m_oscData->target, target_path, "sss", stype, key, value);
  1501. }
  1502. }
  1503. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1504. {
  1505. qDebug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1506. Q_ASSERT(m_oscData);
  1507. if (m_oscData && m_oscData->target)
  1508. {
  1509. char target_path[strlen(m_oscData->path)+23];
  1510. strcpy(target_path, m_oscData->path);
  1511. strcat(target_path, "/bridge_set_chunk_data");
  1512. lo_send(m_oscData->target, target_path, "s", chunkFile);
  1513. }
  1514. }
  1515. void CarlaEngine::osc_send_bridge_set_input_peak_value(const int32_t portId, const double value)
  1516. {
  1517. Q_ASSERT(m_oscData);
  1518. Q_ASSERT(portId == 1 || portId == 2);
  1519. if (m_oscData && m_oscData->target)
  1520. {
  1521. char target_path[strlen(m_oscData->path)+28];
  1522. strcpy(target_path, m_oscData->path);
  1523. strcat(target_path, "/bridge_set_input_peak_value");
  1524. lo_send(m_oscData->target, target_path, "id", portId, value);
  1525. }
  1526. }
  1527. void CarlaEngine::osc_send_bridge_set_output_peak_value(const int32_t portId, const double value)
  1528. {
  1529. Q_ASSERT(m_oscData);
  1530. Q_ASSERT(portId == 1 || portId == 2);
  1531. if (m_oscData && m_oscData->target)
  1532. {
  1533. char target_path[strlen(m_oscData->path)+29];
  1534. strcpy(target_path, m_oscData->path);
  1535. strcat(target_path, "/bridge_set_output_peak_value");
  1536. lo_send(m_oscData->target, target_path, "id", portId, value);
  1537. }
  1538. }
  1539. #endif
  1540. CARLA_BACKEND_END_NAMESPACE