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.

1774 lines
52KB

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