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.

1707 lines
51KB

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