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.

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