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.

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