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.

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