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.

2076 lines
62KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #include "carla_engine.h"
  18. #include "carla_plugin.h"
  19. CARLA_BACKEND_START_NAMESPACE
  20. double abs_d(const double& value)
  21. {
  22. return (value < 0.0) ? -value : value;
  23. }
  24. // -----------------------------------------------------------------------
  25. unsigned short CarlaEngine::m_maxPluginNumber = 0;
  26. CarlaEngine::CarlaEngine()
  27. : m_checkThread(this),
  28. #ifndef BUILD_BRIDGE
  29. m_osc(this),
  30. #endif
  31. m_oscData(nullptr),
  32. m_callback(nullptr),
  33. #ifdef Q_COMPILER_INITIALIZER_LISTS
  34. m_callbackPtr(nullptr),
  35. m_carlaPlugins{nullptr},
  36. m_uniqueNames{nullptr},
  37. m_insPeak{0.0},
  38. m_outsPeak{0.0}
  39. #else
  40. m_callbackPtr(nullptr)
  41. #endif
  42. {
  43. qDebug("CarlaEngine::CarlaEngine()");
  44. type = CarlaEngineTypeNull;
  45. name = nullptr;
  46. bufferSize = 0;
  47. sampleRate = 0.0;
  48. m_maxPluginNumber = 0;
  49. #ifndef Q_COMPILER_INITIALIZER_LISTS
  50. for (unsigned short i=0; i < MAX_PLUGINS; i++)
  51. {
  52. m_carlaPlugins[i] = nullptr;
  53. m_uniqueNames[i] = nullptr;
  54. }
  55. for (unsigned short i=0; i < MAX_PLUGINS * MAX_PEAKS; i++)
  56. {
  57. m_insPeak[i] = 0.0;
  58. m_outsPeak[i] = 0.0;
  59. }
  60. #endif
  61. }
  62. CarlaEngine::~CarlaEngine()
  63. {
  64. qDebug("CarlaEngine::~CarlaEngine()");
  65. if (name)
  66. free((void*)name);
  67. }
  68. // -----------------------------------------------------------------------
  69. // Static values
  70. int CarlaEngine::maxClientNameSize()
  71. {
  72. #ifdef CARLA_ENGINE_JACK
  73. # ifndef BUILD_BRIDGE
  74. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  75. # endif
  76. return jackbridge_client_name_size();
  77. #endif
  78. return STR_MAX/2;
  79. }
  80. int CarlaEngine::maxPortNameSize()
  81. {
  82. #ifdef CARLA_ENGINE_JACK
  83. # ifndef BUILD_BRIDGE
  84. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  85. # endif
  86. return jackbridge_port_name_size();
  87. #endif
  88. return STR_MAX;
  89. }
  90. unsigned short CarlaEngine::maxPluginNumber()
  91. {
  92. return m_maxPluginNumber;
  93. }
  94. const char* CarlaEngine::getFixedClientName(const char* const clientName)
  95. {
  96. char* fixedName = strdup(clientName);
  97. for (size_t i=0; i < strlen(fixedName); i++)
  98. {
  99. if (! (std::isalpha(fixedName[i]) || std::isdigit(fixedName[i])))
  100. fixedName[i] = '_';
  101. }
  102. return fixedName;
  103. }
  104. unsigned int CarlaEngine::getDriverCount()
  105. {
  106. unsigned int count = 0;
  107. #ifdef CARLA_ENGINE_JACK
  108. count += 1;
  109. #endif
  110. #ifdef CARLA_ENGINE_RTAUDIO
  111. std::vector<RtAudio::Api> apis;
  112. RtAudio::getCompiledApi(apis);
  113. count += apis.size();
  114. #endif
  115. return count;
  116. }
  117. const char* CarlaEngine::getDriverName(unsigned int index)
  118. {
  119. #ifdef CARLA_ENGINE_JACK
  120. if (index == 0)
  121. return "JACK";
  122. else
  123. index -= 1;
  124. #endif
  125. #ifdef CARLA_ENGINE_RTAUDIO
  126. std::vector<RtAudio::Api> apis;
  127. RtAudio::getCompiledApi(apis);
  128. if (index < apis.size())
  129. {
  130. RtAudio::Api api = apis[index];
  131. switch (api)
  132. {
  133. case RtAudio::UNSPECIFIED:
  134. return "Unspecified";
  135. case RtAudio::LINUX_ALSA:
  136. return "ALSA";
  137. case RtAudio::LINUX_PULSE:
  138. return "PulseAudio";
  139. case RtAudio::LINUX_OSS:
  140. return "OSS";
  141. case RtAudio::UNIX_JACK:
  142. return "JACK (RtAudio)";
  143. case RtAudio::MACOSX_CORE:
  144. return "CoreAudio";
  145. case RtAudio::WINDOWS_ASIO:
  146. return "ASIO";
  147. case RtAudio::WINDOWS_DS:
  148. return "DirectSound";
  149. case RtAudio::RTAUDIO_DUMMY:
  150. return "Dummy";
  151. }
  152. }
  153. #endif
  154. qWarning("CarlaEngine::getDriverName(%i) - invalid index", index);
  155. return nullptr;
  156. }
  157. CarlaEngine* CarlaEngine::newDriverByName(const char* driverName)
  158. {
  159. #ifdef CARLA_ENGINE_JACK
  160. if (strcmp(driverName, "JACK") == 0)
  161. return newJack();
  162. #else
  163. if (false)
  164. pass();
  165. #endif
  166. #ifdef CARLA_ENGINE_RTAUDIO
  167. #ifdef __LINUX_ALSA__
  168. else if (strcmp(driverName, "ALSA") == 0)
  169. return newRtAudio(RtAudio::LINUX_ALSA);
  170. #endif
  171. #ifdef __LINUX_PULSE__
  172. else if (strcmp(driverName, "PulseAudio") == 0)
  173. return newRtAudio(RtAudio::LINUX_PULSE);
  174. #endif
  175. #ifdef __LINUX_OSS__
  176. else if (strcmp(driverName, "OSS") == 0)
  177. return newRtAudio(RtAudio::LINUX_OSS);
  178. #endif
  179. #ifdef __UNIX_JACK__
  180. else if (strcmp(driverName, "JACK (RtAudio)") == 0)
  181. return newRtAudio(RtAudio::UNIX_JACK);
  182. #endif
  183. #ifdef __MACOSX_CORE__
  184. else if (strcmp(driverName, "CoreAudio") == 0)
  185. return newRtAudio(RtAudio::MACOSX_CORE);
  186. #endif
  187. #ifdef __WINDOWS_ASIO__
  188. else if (strcmp(driverName, "ASIO") == 0)
  189. return newRtAudio(RtAudio::WINDOWS_ASIO);
  190. #endif
  191. #ifdef __WINDOWS_DS__
  192. else if (strcmp(driverName, "DirectSound") == 0)
  193. return newRtAudio(RtAudio::WINDOWS_DS);
  194. #endif
  195. #ifdef __RTAUDIO_DUMMY__
  196. else if (strcmp(driverName, "Dummy") == 0)
  197. return newRtAudio(RtAudio::RTAUDIO_DUMMY);
  198. #endif
  199. #endif
  200. return nullptr;
  201. }
  202. // -----------------------------------------------------------------------
  203. // Virtual, per-engine type calls
  204. bool CarlaEngine::init(const char* const clientName)
  205. {
  206. qDebug("CarlaEngine::init(\"%s\")", clientName);
  207. #ifndef BUILD_BRIDGE
  208. m_osc.init(clientName);
  209. m_oscData = m_osc.getControlData();
  210. if (strcmp(clientName, "Carla"))
  211. carla_setprocname(clientName);
  212. #endif
  213. return true;
  214. }
  215. bool CarlaEngine::close()
  216. {
  217. qDebug("CarlaEngine::close()");
  218. m_checkThread.stopNow();
  219. #ifndef BUILD_BRIDGE
  220. osc_send_control_exit();
  221. m_osc.close();
  222. #endif
  223. m_oscData = nullptr;
  224. m_maxPluginNumber = 0;
  225. return true;
  226. }
  227. // -----------------------------------------------------------------------
  228. // plugin management
  229. short CarlaEngine::getNewPluginId() const
  230. {
  231. qDebug("CarlaEngine::getNewPluginId()");
  232. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  233. {
  234. if (! m_carlaPlugins[i])
  235. return i;
  236. }
  237. return -1;
  238. }
  239. CarlaPlugin* CarlaEngine::getPlugin(const unsigned short id) const
  240. {
  241. qDebug("CarlaEngine::getPlugin(%i/%i)", id, m_maxPluginNumber);
  242. CARLA_ASSERT(m_maxPluginNumber != 0);
  243. CARLA_ASSERT(id < m_maxPluginNumber);
  244. if (id < m_maxPluginNumber)
  245. return m_carlaPlugins[id];
  246. return nullptr;
  247. }
  248. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned short id) const
  249. {
  250. CARLA_ASSERT(m_maxPluginNumber != 0);
  251. CARLA_ASSERT(id < m_maxPluginNumber);
  252. return m_carlaPlugins[id];
  253. }
  254. const char* CarlaEngine::getUniquePluginName(const char* const name)
  255. {
  256. qDebug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  257. CARLA_ASSERT(name);
  258. QString qname(name);
  259. if (qname.isEmpty())
  260. qname = "(No name)";
  261. qname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  262. qname.replace(":", "."); // ":" is used in JACK1 to split client/port names
  263. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  264. {
  265. // Check if unique name already exists
  266. if (m_uniqueNames[i] && qname == m_uniqueNames[i])
  267. {
  268. // Check if string has already been modified
  269. uint len = qname.size();
  270. // 1 digit, ex: " (2)"
  271. if (qname.at(len-4) == QChar(' ') && qname.at(len-3) == QChar('(') && qname.at(len-2).isDigit() && qname.at(len-1) == QChar(')'))
  272. {
  273. int number = qname.at(len-2).toAscii()-'0';
  274. if (number == 9)
  275. // next number is 10, 2 digits
  276. qname.replace(" (9)", " (10)");
  277. else
  278. qname[len-2] = QChar('0'+number+1);
  279. continue;
  280. }
  281. // 2 digits, ex: " (11)"
  282. 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(')'))
  283. {
  284. QChar n2 = qname.at(len-2);
  285. QChar n3 = qname.at(len-3);
  286. if (n2 == QChar('9'))
  287. {
  288. n2 = QChar('0');
  289. n3 = QChar(n3.toAscii()+1);
  290. }
  291. else
  292. n2 = QChar(n2.toAscii()+1);
  293. qname[len-2] = n2;
  294. qname[len-3] = n3;
  295. continue;
  296. }
  297. // Modify string if not
  298. qname += " (2)";
  299. }
  300. }
  301. return strdup(qname.toUtf8().constData());
  302. }
  303. short CarlaEngine::addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  304. {
  305. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  306. }
  307. short CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  308. {
  309. qDebug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2str(btype), PluginType2str(ptype), filename, name, label, extra);
  310. CARLA_ASSERT(btype != BINARY_NONE);
  311. CARLA_ASSERT(ptype != PLUGIN_NONE);
  312. CARLA_ASSERT(filename);
  313. CARLA_ASSERT(label);
  314. if (m_maxPluginNumber == 0)
  315. {
  316. #ifdef BUILD_BRIDGE
  317. m_maxPluginNumber = MAX_PLUGINS;
  318. #else
  319. m_maxPluginNumber = (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK) ? 16 : MAX_PLUGINS;
  320. #endif
  321. }
  322. CarlaPlugin::initializer init = {
  323. this,
  324. filename,
  325. name,
  326. label
  327. };
  328. CarlaPlugin* plugin = nullptr;
  329. #ifndef BUILD_BRIDGE
  330. if (btype != BINARY_NATIVE || (carlaOptions.preferPluginBridges && getBinaryBidgePath(btype) && type == CarlaEngineTypeJack))
  331. {
  332. # ifdef CARLA_ENGINE_JACK
  333. if (carlaOptions.processMode != CarlaBackend::PROCESS_MODE_MULTIPLE_CLIENTS)
  334. {
  335. setLastError("Can only use bridged plugins in JACK Multi-Client mode");
  336. return -1;
  337. }
  338. # endif
  339. if (type != CarlaEngineTypeJack)
  340. {
  341. setLastError("Can only use bridged plugins with JACK backend");
  342. return -1;
  343. }
  344. plugin = CarlaPlugin::newBridge(init, btype, ptype);
  345. }
  346. else
  347. #endif
  348. {
  349. switch (ptype)
  350. {
  351. case PLUGIN_NONE:
  352. break;
  353. #ifndef BUILD_BRIDGE
  354. case PLUGIN_INTERNAL:
  355. plugin = CarlaPlugin::newNative(init);
  356. break;
  357. #endif
  358. case PLUGIN_LADSPA:
  359. plugin = CarlaPlugin::newLADSPA(init, extra);
  360. break;
  361. case PLUGIN_DSSI:
  362. plugin = CarlaPlugin::newDSSI(init, extra);
  363. break;
  364. case PLUGIN_LV2:
  365. plugin = CarlaPlugin::newLV2(init);
  366. break;
  367. case PLUGIN_VST:
  368. plugin = CarlaPlugin::newVST(init);
  369. break;
  370. #ifndef BUILD_BRIDGE
  371. case PLUGIN_GIG:
  372. plugin = CarlaPlugin::newGIG(init);
  373. break;
  374. case PLUGIN_SF2:
  375. plugin = CarlaPlugin::newSF2(init);
  376. break;
  377. case PLUGIN_SFZ:
  378. plugin = CarlaPlugin::newSFZ(init);
  379. break;
  380. #else
  381. default:
  382. break;
  383. #endif
  384. }
  385. }
  386. if (! plugin)
  387. return -1;
  388. const short id = plugin->id();
  389. m_carlaPlugins[id] = plugin;
  390. m_uniqueNames[id] = plugin->name();
  391. if (! m_checkThread.isRunning())
  392. m_checkThread.startNow();
  393. return id;
  394. }
  395. bool CarlaEngine::removePlugin(const unsigned short id)
  396. {
  397. qDebug("CarlaEngine::removePlugin(%i)", id);
  398. CARLA_ASSERT(m_maxPluginNumber != 0);
  399. CARLA_ASSERT(id < m_maxPluginNumber);
  400. CarlaPlugin* const plugin = m_carlaPlugins[id];
  401. if (plugin /*&& plugin->id() == id*/)
  402. {
  403. CARLA_ASSERT(plugin->id() == id);
  404. m_checkThread.stopNow();
  405. processLock();
  406. plugin->setEnabled(false);
  407. m_carlaPlugins[id] = nullptr;
  408. m_uniqueNames[id] = nullptr;
  409. processUnlock();
  410. delete plugin;
  411. #ifndef BUILD_BRIDGE
  412. osc_send_control_remove_plugin(id);
  413. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  414. {
  415. // TODO - handle OSC server comm
  416. for (unsigned short i=id; i < m_maxPluginNumber-1; i++)
  417. {
  418. m_carlaPlugins[i] = m_carlaPlugins[i+1];
  419. m_uniqueNames[i] = m_uniqueNames[i+1];
  420. if (m_carlaPlugins[i])
  421. m_carlaPlugins[i]->setId(i);
  422. }
  423. }
  424. #endif
  425. if (isRunning())
  426. {
  427. // only re-start check thread if there are still plugins left
  428. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  429. {
  430. if (m_carlaPlugins[i])
  431. {
  432. m_checkThread.startNow();
  433. break;
  434. }
  435. }
  436. }
  437. return true;
  438. }
  439. qCritical("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  440. setLastError("Could not find plugin to remove");
  441. return false;
  442. }
  443. void CarlaEngine::removeAllPlugins()
  444. {
  445. qDebug("CarlaEngine::removeAllPlugins()");
  446. m_checkThread.stopNow();
  447. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  448. {
  449. CarlaPlugin* const plugin = m_carlaPlugins[i];
  450. if (plugin)
  451. {
  452. processLock();
  453. plugin->setEnabled(false);
  454. processUnlock();
  455. delete plugin;
  456. m_carlaPlugins[i] = nullptr;
  457. m_uniqueNames[i] = nullptr;
  458. }
  459. }
  460. m_maxPluginNumber = 0;
  461. }
  462. void CarlaEngine::idlePluginGuis()
  463. {
  464. CARLA_ASSERT(m_maxPluginNumber != 0);
  465. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  466. {
  467. CarlaPlugin* const plugin = m_carlaPlugins[i];
  468. if (plugin && plugin->enabled())
  469. plugin->idleGui();
  470. }
  471. }
  472. #ifndef BUILD_BRIDGE
  473. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], uint32_t frames)
  474. {
  475. // initialize outputs (zero)
  476. zeroF(outBuf[0], frames);
  477. zeroF(outBuf[1], frames);
  478. memset(rackControlEventsOut, 0, sizeof(CarlaEngineControlEvent)*MAX_ENGINE_CONTROL_EVENTS);
  479. memset(rackMidiEventsOut, 0, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  480. bool processed = false;
  481. // process plugins
  482. for (unsigned short i=0, max=maxPluginNumber(); i < max; i++)
  483. {
  484. CarlaPlugin* const plugin = getPluginUnchecked(i);
  485. if (plugin && plugin->enabled())
  486. {
  487. if (processed)
  488. {
  489. // initialize inputs (from previous outputs)
  490. memcpy(inBuf[0], outBuf[0], sizeof(float)*frames);
  491. memcpy(inBuf[1], outBuf[1], sizeof(float)*frames);
  492. memcpy(rackMidiEventsIn, rackMidiEventsOut, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  493. // initialize outputs (zero)
  494. zeroF(outBuf[0], frames);
  495. zeroF(outBuf[1], frames);
  496. memset(rackMidiEventsOut, 0, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  497. }
  498. // process
  499. plugin->engineProcessLock();
  500. plugin->initBuffers();
  501. if (carlaOptions.processHighPrecision)
  502. {
  503. float* inBuf2[2];
  504. float* outBuf2[2];
  505. for (uint32_t j=0; j < frames; j += 8)
  506. {
  507. inBuf2[0] = inBuf[0] + j;
  508. inBuf2[1] = inBuf[1] + j;
  509. outBuf2[0] = outBuf[0] + j;
  510. outBuf2[1] = outBuf[1] + j;
  511. plugin->process(inBuf2, outBuf2, 8, j);
  512. }
  513. }
  514. else
  515. plugin->process(inBuf, outBuf, frames);
  516. plugin->engineProcessUnlock();
  517. // if plugin has no audio inputs, add previous buffers
  518. if (plugin->audioInCount() == 0)
  519. {
  520. for (uint32_t j=0; j < frames; j++)
  521. {
  522. outBuf[0][j] += inBuf[0][j];
  523. outBuf[1][j] += inBuf[1][j];
  524. }
  525. }
  526. // if plugin has no midi output, add previous midi input
  527. if (plugin->midiOutCount() == 0)
  528. {
  529. memcpy(rackMidiEventsOut, rackMidiEventsIn, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  530. }
  531. // set peaks
  532. {
  533. double inPeak1 = 0.0;
  534. double inPeak2 = 0.0;
  535. double outPeak1 = 0.0;
  536. double outPeak2 = 0.0;
  537. for (uint32_t k=0; k < frames; k++)
  538. {
  539. if (abs_d(inBuf[0][k]) > inPeak1)
  540. inPeak1 = abs_d(inBuf[0][k]);
  541. if (abs_d(inBuf[1][k]) > inPeak2)
  542. inPeak2 = abs_d(inBuf[1][k]);
  543. if (abs_d(outBuf[0][k]) > outPeak1)
  544. outPeak1 = abs_d(outBuf[0][k]);
  545. if (abs_d(outBuf[1][k]) > outPeak2)
  546. outPeak2 = abs_d(outBuf[1][k]);
  547. }
  548. m_insPeak[i*MAX_PEAKS + 0] = inPeak1;
  549. m_insPeak[i*MAX_PEAKS + 1] = inPeak2;
  550. m_outsPeak[i*MAX_PEAKS + 0] = outPeak1;
  551. m_outsPeak[i*MAX_PEAKS + 1] = outPeak2;
  552. }
  553. processed = true;
  554. }
  555. }
  556. // if no plugins in the rack, copy inputs over outputs
  557. if (! processed)
  558. {
  559. memcpy(outBuf[0], inBuf[0], sizeof(float)*frames);
  560. memcpy(outBuf[1], inBuf[1], sizeof(float)*frames);
  561. memcpy(rackMidiEventsOut, rackMidiEventsIn, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  562. }
  563. }
  564. #endif
  565. // -----------------------------------------------------------------------
  566. // Information (base)
  567. CarlaEngineType CarlaEngine::getType() const
  568. {
  569. return type;
  570. }
  571. const char* CarlaEngine::getName() const
  572. {
  573. CARLA_ASSERT(name);
  574. return name;
  575. }
  576. double CarlaEngine::getSampleRate() const
  577. {
  578. //CARLA_ASSERT(sampleRate != 0.0);
  579. return sampleRate;
  580. }
  581. uint32_t CarlaEngine::getBufferSize() const
  582. {
  583. //CARLA_ASSERT(bufferSize != 0);
  584. return bufferSize;
  585. }
  586. const CarlaTimeInfo* CarlaEngine::getTimeInfo() const
  587. {
  588. return &timeInfo;
  589. }
  590. // -----------------------------------------------------------------------
  591. // Information (audio peaks)
  592. double CarlaEngine::getInputPeak(const unsigned short pluginId, const unsigned short id) const
  593. {
  594. CARLA_ASSERT(pluginId < m_maxPluginNumber);
  595. CARLA_ASSERT(id < MAX_PEAKS);
  596. return m_insPeak[pluginId*MAX_PEAKS + id];
  597. }
  598. double CarlaEngine::getOutputPeak(const unsigned short pluginId, const unsigned short id) const
  599. {
  600. CARLA_ASSERT(pluginId < m_maxPluginNumber);
  601. CARLA_ASSERT(id < MAX_PEAKS);
  602. return m_outsPeak[pluginId*MAX_PEAKS + id];
  603. }
  604. void CarlaEngine::setInputPeak(const unsigned short pluginId, const unsigned short id, double value)
  605. {
  606. CARLA_ASSERT(pluginId < m_maxPluginNumber);
  607. CARLA_ASSERT(id < MAX_PEAKS);
  608. m_insPeak[pluginId*MAX_PEAKS + id] = value;
  609. }
  610. void CarlaEngine::setOutputPeak(const unsigned short pluginId, const unsigned short id, double value)
  611. {
  612. CARLA_ASSERT(pluginId < m_maxPluginNumber);
  613. CARLA_ASSERT(id < MAX_PEAKS);
  614. m_outsPeak[pluginId*MAX_PEAKS + id] = value;
  615. }
  616. // -----------------------------------------------------------------------
  617. // Callback
  618. void CarlaEngine::callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3)
  619. {
  620. qDebug("CarlaEngine::callback(%s, %i, %i, %i, %f)", CallbackType2str(action), pluginId, value1, value2, value3);
  621. if (m_callback)
  622. m_callback(m_callbackPtr, action, pluginId, value1, value2, value3);
  623. }
  624. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  625. {
  626. qDebug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  627. CARLA_ASSERT(func);
  628. m_callback = func;
  629. m_callbackPtr = ptr;
  630. }
  631. // -----------------------------------------------------------------------
  632. // Mutex locks
  633. void CarlaEngine::processLock()
  634. {
  635. m_procLock.lock();
  636. }
  637. void CarlaEngine::processUnlock()
  638. {
  639. m_procLock.unlock();
  640. }
  641. void CarlaEngine::midiLock()
  642. {
  643. m_midiLock.lock();
  644. }
  645. void CarlaEngine::midiUnlock()
  646. {
  647. m_midiLock.unlock();
  648. }
  649. // -----------------------------------------------------------------------
  650. // OSC Stuff
  651. bool CarlaEngine::isOscControlRegisted() const
  652. {
  653. #ifndef BUILD_BRIDGE
  654. return m_osc.isControlRegistered();
  655. #else
  656. return bool(m_oscData);
  657. #endif
  658. }
  659. #ifndef BUILD_BRIDGE
  660. void CarlaEngine::oscWaitEvents()
  661. {
  662. m_osc.waitForEvents();
  663. }
  664. const char* CarlaEngine::getOscServerPathTCP() const
  665. {
  666. return m_osc.getServerPathTCP();
  667. }
  668. const char* CarlaEngine::getOscServerPathUDP() const
  669. {
  670. return m_osc.getServerPathUDP();
  671. }
  672. #else
  673. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  674. {
  675. m_oscData = oscData;
  676. }
  677. #endif
  678. // -----------------------------------------------------------------------
  679. // protected calls
  680. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  681. {
  682. qDebug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  683. bufferSize = newBufferSize;
  684. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  685. {
  686. if (m_carlaPlugins[i] && m_carlaPlugins[i]->enabled())
  687. m_carlaPlugins[i]->bufferSizeChanged(newBufferSize);
  688. }
  689. }
  690. void CarlaEngine::startCheckThread()
  691. {
  692. if (! m_checkThread.isRunning())
  693. m_checkThread.startNow();
  694. }
  695. // -------------------------------------------------------------------------------------------------------------------
  696. // Carla Engine Client
  697. CarlaEngineClient::CarlaEngineClient(const CarlaEngineClientNativeHandle& handle_)
  698. : handle(handle_)
  699. {
  700. qDebug("CarlaEngineClient::CarlaEngineClient()");
  701. CARLA_ASSERT(handle.type != CarlaEngineTypeNull);
  702. m_active = false;
  703. m_latency = 0;
  704. }
  705. CarlaEngineClient::~CarlaEngineClient()
  706. {
  707. qDebug("CarlaEngineClient::~CarlaEngineClient()");
  708. CARLA_ASSERT(! m_active);
  709. #ifndef BUILD_BRIDGE
  710. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  711. #endif
  712. {
  713. #ifdef CARLA_ENGINE_JACK
  714. if (handle.jackClient)
  715. jackbridge_client_close(handle.jackClient);
  716. #endif
  717. }
  718. }
  719. void CarlaEngineClient::activate()
  720. {
  721. qDebug("CarlaEngineClient::activate()");
  722. CARLA_ASSERT(! m_active);
  723. #ifndef BUILD_BRIDGE
  724. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  725. #endif
  726. {
  727. if (! m_active)
  728. {
  729. #ifdef CARLA_ENGINE_JACK
  730. if (handle.jackClient)
  731. jackbridge_activate(handle.jackClient);
  732. #endif
  733. }
  734. }
  735. m_active = true;
  736. }
  737. void CarlaEngineClient::deactivate()
  738. {
  739. qDebug("CarlaEngineClient::deactivate()");
  740. CARLA_ASSERT(m_active);
  741. #ifndef BUILD_BRIDGE
  742. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  743. #endif
  744. {
  745. if (m_active)
  746. {
  747. #ifdef CARLA_ENGINE_JACK
  748. if (handle.jackClient)
  749. jackbridge_deactivate(handle.jackClient);
  750. #endif
  751. }
  752. }
  753. m_active = false;
  754. }
  755. bool CarlaEngineClient::isActive() const
  756. {
  757. qDebug("CarlaEngineClient::isActive()");
  758. return m_active;
  759. }
  760. bool CarlaEngineClient::isOk() const
  761. {
  762. qDebug("CarlaEngineClient::isOk()");
  763. #ifndef BUILD_BRIDGE
  764. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  765. #endif
  766. {
  767. #ifdef CARLA_ENGINE_JACK
  768. if (handle.type == CarlaEngineTypeJack)
  769. return bool(handle.jackClient);
  770. #endif
  771. }
  772. return true;
  773. }
  774. uint32_t CarlaEngineClient::getLatency() const
  775. {
  776. return m_latency;
  777. }
  778. void CarlaEngineClient::setLatency(const uint32_t samples)
  779. {
  780. m_latency = samples;
  781. #ifndef BUILD_BRIDGE
  782. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  783. #endif
  784. {
  785. #ifdef CARLA_ENGINE_JACK
  786. if (handle.type == CarlaEngineTypeJack)
  787. jackbridge_recompute_total_latencies(handle.jackClient);
  788. #endif
  789. }
  790. }
  791. const CarlaEngineBasePort* CarlaEngineClient::addPort(const CarlaEnginePortType portType, const char* const name, const bool isInput)
  792. {
  793. qDebug("CarlaEngineClient::addPort(%i, \"%s\", %s)", portType, name, bool2str(isInput));
  794. CarlaEnginePortNativeHandle portHandle;
  795. #ifdef CARLA_ENGINE_JACK
  796. portHandle.jackClient = handle.jackClient;
  797. #endif
  798. #ifndef BUILD_BRIDGE
  799. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  800. #endif
  801. {
  802. #ifdef CARLA_ENGINE_JACK
  803. if (handle.type == CarlaEngineTypeJack)
  804. {
  805. switch (portType)
  806. {
  807. case CarlaEnginePortTypeAudio:
  808. portHandle.jackPort = jackbridge_port_register(handle.jackClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  809. break;
  810. case CarlaEnginePortTypeControl:
  811. case CarlaEnginePortTypeMIDI:
  812. portHandle.jackPort = jackbridge_port_register(handle.jackClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  813. break;
  814. }
  815. }
  816. #endif
  817. }
  818. switch (portType)
  819. {
  820. case CarlaEnginePortTypeAudio:
  821. return new CarlaEngineAudioPort(portHandle, isInput);
  822. case CarlaEnginePortTypeControl:
  823. return new CarlaEngineControlPort(portHandle, isInput);
  824. case CarlaEnginePortTypeMIDI:
  825. return new CarlaEngineMidiPort(portHandle, isInput);
  826. }
  827. qCritical("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  828. return nullptr;
  829. }
  830. // -------------------------------------------------------------------------------------------------------------------
  831. // Carla Engine Port (Base class)
  832. CarlaEngineBasePort::CarlaEngineBasePort(const CarlaEnginePortNativeHandle& handle_, const bool isInput_)
  833. : isInput(isInput_),
  834. handle(handle_)
  835. {
  836. qDebug("CarlaEngineBasePort::CarlaEngineBasePort(%s)", bool2str(isInput_));
  837. buffer = nullptr;
  838. }
  839. CarlaEngineBasePort::~CarlaEngineBasePort()
  840. {
  841. qDebug("CarlaEngineBasePort::~CarlaEngineBasePort()");
  842. #ifndef BUILD_BRIDGE
  843. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  844. return;
  845. #endif
  846. #ifdef CARLA_ENGINE_JACK
  847. if (handle.jackClient && handle.jackPort)
  848. jackbridge_port_unregister(handle.jackClient, handle.jackPort);
  849. #endif
  850. }
  851. // -------------------------------------------------------------------------------------------------------------------
  852. // Carla Engine Port (Audio)
  853. CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  854. : CarlaEngineBasePort(handle, isInput)
  855. {
  856. qDebug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInput));
  857. }
  858. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const /*engine*/)
  859. {
  860. }
  861. #ifdef CARLA_ENGINE_JACK
  862. float* CarlaEngineAudioPort::getJackAudioBuffer(uint32_t nframes)
  863. {
  864. # ifndef BUILD_BRIDGE
  865. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  866. return nullptr;
  867. # endif
  868. CARLA_ASSERT(handle.jackPort);
  869. return (float*)jackbridge_port_get_buffer(handle.jackPort, nframes);
  870. }
  871. #endif
  872. // -------------------------------------------------------------------------------------------------------------------
  873. // Carla Engine Port (Control)
  874. CarlaEngineControlPort::CarlaEngineControlPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  875. : CarlaEngineBasePort(handle, isInput)
  876. {
  877. qDebug("CarlaEngineControlPort::CarlaEngineControlPort(%s)", bool2str(isInput));
  878. }
  879. void CarlaEngineControlPort::initBuffer(CarlaEngine* const engine)
  880. {
  881. CARLA_ASSERT(engine);
  882. #ifndef BUILD_BRIDGE
  883. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  884. {
  885. buffer = isInput ? engine->rackControlEventsIn : engine->rackControlEventsOut;
  886. return;
  887. }
  888. #endif
  889. #ifdef CARLA_ENGINE_JACK
  890. if (handle.jackPort)
  891. {
  892. buffer = jackbridge_port_get_buffer(handle.jackPort, engine->getBufferSize());
  893. if (! isInput)
  894. jackbridge_midi_clear_buffer(buffer);
  895. }
  896. #endif
  897. }
  898. uint32_t CarlaEngineControlPort::getEventCount()
  899. {
  900. if (! isInput)
  901. return 0;
  902. CARLA_ASSERT(buffer);
  903. #ifndef BUILD_BRIDGE
  904. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  905. {
  906. uint32_t count = 0;
  907. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  908. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  909. {
  910. if (events[i].type != CarlaEngineEventNull)
  911. count++;
  912. else
  913. break;
  914. }
  915. return count;
  916. }
  917. #endif
  918. #ifdef CARLA_ENGINE_JACK
  919. if (handle.jackPort)
  920. return jackbridge_midi_get_event_count(buffer);
  921. #endif
  922. return 0;
  923. }
  924. const CarlaEngineControlEvent* CarlaEngineControlPort::getEvent(uint32_t index)
  925. {
  926. if (! isInput)
  927. return nullptr;
  928. CARLA_ASSERT(buffer);
  929. #ifndef BUILD_BRIDGE
  930. CARLA_ASSERT(index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS);
  931. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  932. {
  933. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  934. if (index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS)
  935. return &events[index];
  936. return nullptr;
  937. }
  938. #endif
  939. #ifdef CARLA_ENGINE_JACK
  940. if (handle.jackPort)
  941. {
  942. static jackbridge_midi_event_t jackEvent;
  943. static CarlaEngineControlEvent carlaEvent;
  944. if (jackbridge_midi_event_get(&jackEvent, buffer, index) != 0)
  945. return nullptr;
  946. memset(&carlaEvent, 0, sizeof(CarlaEngineControlEvent));
  947. uint8_t midiStatus = jackEvent.buffer[0];
  948. uint8_t midiChannel = midiStatus & 0x0F;
  949. carlaEvent.time = jackEvent.time;
  950. carlaEvent.channel = midiChannel;
  951. if (MIDI_IS_STATUS_CONTROL_CHANGE(midiStatus))
  952. {
  953. uint8_t midiControl = jackEvent.buffer[1];
  954. if (MIDI_IS_CONTROL_BANK_SELECT(midiControl))
  955. {
  956. uint8_t midiBank = jackEvent.buffer[2];
  957. carlaEvent.type = CarlaEngineEventMidiBankChange;
  958. carlaEvent.value = midiBank;
  959. }
  960. else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF)
  961. {
  962. carlaEvent.type = CarlaEngineEventAllSoundOff;
  963. }
  964. else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF)
  965. {
  966. carlaEvent.type = CarlaEngineEventAllNotesOff;
  967. }
  968. else
  969. {
  970. uint8_t midiValue = jackEvent.buffer[2];
  971. carlaEvent.type = CarlaEngineEventControlChange;
  972. carlaEvent.controller = midiControl;
  973. carlaEvent.value = double(midiValue)/127;
  974. }
  975. return &carlaEvent;
  976. }
  977. else if (MIDI_IS_STATUS_PROGRAM_CHANGE(midiStatus))
  978. {
  979. uint8_t midiProgram = jackEvent.buffer[1];
  980. carlaEvent.type = CarlaEngineEventMidiProgramChange;
  981. carlaEvent.value = midiProgram;
  982. return &carlaEvent;
  983. }
  984. }
  985. #endif
  986. return nullptr;
  987. }
  988. void CarlaEngineControlPort::writeEvent(CarlaEngineControlEventType type, uint32_t time, uint8_t channel, uint8_t controller, double value)
  989. {
  990. if (isInput)
  991. return;
  992. CARLA_ASSERT(buffer);
  993. CARLA_ASSERT(type != CarlaEngineEventNull);
  994. #ifndef BUILD_BRIDGE
  995. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  996. {
  997. CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  998. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  999. {
  1000. if (events[i].type == CarlaEngineEventNull)
  1001. {
  1002. events[i].type = type;
  1003. events[i].time = time;
  1004. events[i].value = value;
  1005. events[i].channel = channel;
  1006. events[i].controller = controller;
  1007. break;
  1008. }
  1009. }
  1010. return;
  1011. }
  1012. #endif
  1013. #ifdef CARLA_ENGINE_JACK
  1014. if (handle.jackPort)
  1015. {
  1016. if (type == CarlaEngineEventControlChange && MIDI_IS_CONTROL_BANK_SELECT(controller))
  1017. type = CarlaEngineEventMidiBankChange;
  1018. uint8_t data[4] = { 0 };
  1019. switch (type)
  1020. {
  1021. case CarlaEngineEventNull:
  1022. break;
  1023. case CarlaEngineEventControlChange:
  1024. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  1025. data[1] = controller;
  1026. data[2] = value * 127;
  1027. jackbridge_midi_event_write(buffer, time, data, 3);
  1028. break;
  1029. case CarlaEngineEventMidiBankChange:
  1030. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  1031. data[1] = MIDI_CONTROL_BANK_SELECT;
  1032. data[2] = value;
  1033. jackbridge_midi_event_write(buffer, time, data, 3);
  1034. break;
  1035. case CarlaEngineEventMidiProgramChange:
  1036. data[0] = MIDI_STATUS_PROGRAM_CHANGE + channel;
  1037. data[1] = value;
  1038. jackbridge_midi_event_write(buffer, time, data, 2);
  1039. break;
  1040. case CarlaEngineEventAllSoundOff:
  1041. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  1042. data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  1043. jackbridge_midi_event_write(buffer, time, data, 2);
  1044. break;
  1045. case CarlaEngineEventAllNotesOff:
  1046. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  1047. data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  1048. jackbridge_midi_event_write(buffer, time, data, 2);
  1049. break;
  1050. }
  1051. }
  1052. #endif
  1053. }
  1054. // -------------------------------------------------------------------------------------------------------------------
  1055. // Carla Engine Port (MIDI)
  1056. CarlaEngineMidiPort::CarlaEngineMidiPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  1057. : CarlaEngineBasePort(handle, isInput)
  1058. {
  1059. qDebug("CarlaEngineMidiPort::CarlaEngineMidiPort(%s)", bool2str(isInput));
  1060. }
  1061. void CarlaEngineMidiPort::initBuffer(CarlaEngine* const engine)
  1062. {
  1063. CARLA_ASSERT(engine);
  1064. #ifndef BUILD_BRIDGE
  1065. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1066. {
  1067. buffer = isInput ? engine->rackMidiEventsIn : engine->rackMidiEventsOut;
  1068. return;
  1069. }
  1070. #endif
  1071. #ifdef CARLA_ENGINE_JACK
  1072. if (handle.jackPort)
  1073. {
  1074. buffer = jackbridge_port_get_buffer(handle.jackPort, engine->getBufferSize());
  1075. if (! isInput)
  1076. jackbridge_midi_clear_buffer(buffer);
  1077. }
  1078. #endif
  1079. }
  1080. uint32_t CarlaEngineMidiPort::getEventCount()
  1081. {
  1082. if (! isInput)
  1083. return 0;
  1084. CARLA_ASSERT(buffer);
  1085. #ifndef BUILD_BRIDGE
  1086. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1087. {
  1088. uint32_t count = 0;
  1089. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  1090. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  1091. {
  1092. if (events[i].size > 0)
  1093. count++;
  1094. else
  1095. break;
  1096. }
  1097. return count;
  1098. }
  1099. #endif
  1100. #ifdef CARLA_ENGINE_JACK
  1101. if (handle.jackPort)
  1102. return jackbridge_midi_get_event_count(buffer);
  1103. #endif
  1104. return 0;
  1105. }
  1106. const CarlaEngineMidiEvent* CarlaEngineMidiPort::getEvent(uint32_t index)
  1107. {
  1108. if (! isInput)
  1109. return nullptr;
  1110. CARLA_ASSERT(buffer);
  1111. #ifndef BUILD_BRIDGE
  1112. CARLA_ASSERT(index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS);
  1113. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1114. {
  1115. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  1116. if (index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS)
  1117. return &events[index];
  1118. return nullptr;
  1119. }
  1120. #endif
  1121. #ifdef CARLA_ENGINE_JACK
  1122. if (handle.jackPort)
  1123. {
  1124. static jackbridge_midi_event_t jackEvent;
  1125. static CarlaEngineMidiEvent carlaEvent;
  1126. if (jackbridge_midi_event_get(&jackEvent, buffer, index) == 0 && jackEvent.size <= 4)
  1127. {
  1128. carlaEvent.time = jackEvent.time;
  1129. carlaEvent.size = jackEvent.size;
  1130. memcpy(carlaEvent.data, jackEvent.buffer, jackEvent.size);
  1131. return &carlaEvent;
  1132. }
  1133. }
  1134. #endif
  1135. return nullptr;
  1136. }
  1137. void CarlaEngineMidiPort::writeEvent(uint32_t time, const uint8_t* data, uint8_t size)
  1138. {
  1139. if (isInput)
  1140. return;
  1141. CARLA_ASSERT(buffer);
  1142. CARLA_ASSERT(data);
  1143. CARLA_ASSERT(size > 0);
  1144. #ifndef BUILD_BRIDGE
  1145. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1146. {
  1147. if (size > 4)
  1148. return;
  1149. CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  1150. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  1151. {
  1152. if (events[i].size == 0)
  1153. {
  1154. events[i].time = time;
  1155. events[i].size = size;
  1156. memcpy(events[i].data, data, size);
  1157. break;
  1158. }
  1159. }
  1160. return;
  1161. }
  1162. #endif
  1163. #ifdef CARLA_ENGINE_JACK
  1164. if (handle.jackPort)
  1165. jackbridge_midi_event_write(buffer, time, data, size);
  1166. #endif
  1167. }
  1168. // -------------------------------------------------------------------------------------------------------------------
  1169. // Carla Engine OSC stuff
  1170. #ifndef BUILD_BRIDGE
  1171. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1172. {
  1173. qDebug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1174. CARLA_ASSERT(m_oscData);
  1175. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1176. CARLA_ASSERT(pluginName);
  1177. if (m_oscData && m_oscData->target)
  1178. {
  1179. char target_path[strlen(m_oscData->path)+18];
  1180. strcpy(target_path, m_oscData->path);
  1181. strcat(target_path, "/add_plugin_start");
  1182. lo_send(m_oscData->target, target_path, "is", pluginId, pluginName);
  1183. }
  1184. }
  1185. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1186. {
  1187. qDebug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1188. CARLA_ASSERT(m_oscData);
  1189. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1190. if (m_oscData && m_oscData->target)
  1191. {
  1192. char target_path[strlen(m_oscData->path)+16];
  1193. strcpy(target_path, m_oscData->path);
  1194. strcat(target_path, "/add_plugin_end");
  1195. lo_send(m_oscData->target, target_path, "i", pluginId);
  1196. }
  1197. }
  1198. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1199. {
  1200. qDebug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1201. CARLA_ASSERT(m_oscData);
  1202. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1203. if (m_oscData && m_oscData->target)
  1204. {
  1205. char target_path[strlen(m_oscData->path)+15];
  1206. strcpy(target_path, m_oscData->path);
  1207. strcat(target_path, "/remove_plugin");
  1208. lo_send(m_oscData->target, target_path, "i", pluginId);
  1209. }
  1210. }
  1211. 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)
  1212. {
  1213. qDebug("CarlaEngine::osc_send_control_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1214. CARLA_ASSERT(m_oscData);
  1215. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1216. CARLA_ASSERT(type != PLUGIN_NONE);
  1217. if (m_oscData && m_oscData->target)
  1218. {
  1219. char target_path[strlen(m_oscData->path)+17];
  1220. strcpy(target_path, m_oscData->path);
  1221. strcat(target_path, "/set_plugin_data");
  1222. lo_send(m_oscData->target, target_path, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1223. }
  1224. }
  1225. 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)
  1226. {
  1227. qDebug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1228. CARLA_ASSERT(m_oscData);
  1229. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1230. if (m_oscData && m_oscData->target)
  1231. {
  1232. char target_path[strlen(m_oscData->path)+18];
  1233. strcpy(target_path, m_oscData->path);
  1234. strcat(target_path, "/set_plugin_ports");
  1235. lo_send(m_oscData->target, target_path, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1236. }
  1237. }
  1238. 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)
  1239. {
  1240. qDebug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1241. CARLA_ASSERT(m_oscData);
  1242. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1243. CARLA_ASSERT(index >= 0);
  1244. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1245. if (m_oscData && m_oscData->target)
  1246. {
  1247. char target_path[strlen(m_oscData->path)+20];
  1248. strcpy(target_path, m_oscData->path);
  1249. strcat(target_path, "/set_parameter_data");
  1250. lo_send(m_oscData->target, target_path, "iiiissd", pluginId, index, type, hints, name, label, current);
  1251. }
  1252. }
  1253. 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)
  1254. {
  1255. qDebug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1256. CARLA_ASSERT(m_oscData);
  1257. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1258. CARLA_ASSERT(index >= 0);
  1259. CARLA_ASSERT(min < max);
  1260. if (m_oscData && m_oscData->target)
  1261. {
  1262. char target_path[strlen(m_oscData->path)+22];
  1263. strcpy(target_path, m_oscData->path);
  1264. strcat(target_path, "/set_parameter_ranges");
  1265. lo_send(m_oscData->target, target_path, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1266. }
  1267. }
  1268. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1269. {
  1270. qDebug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1271. CARLA_ASSERT(m_oscData);
  1272. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1273. CARLA_ASSERT(index >= 0);
  1274. if (m_oscData && m_oscData->target)
  1275. {
  1276. char target_path[strlen(m_oscData->path)+23];
  1277. strcpy(target_path, m_oscData->path);
  1278. strcat(target_path, "/set_parameter_midi_cc");
  1279. lo_send(m_oscData->target, target_path, "iii", pluginId, index, cc);
  1280. }
  1281. }
  1282. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1283. {
  1284. qDebug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1285. CARLA_ASSERT(m_oscData);
  1286. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1287. CARLA_ASSERT(index >= 0);
  1288. CARLA_ASSERT(channel >= 0 && channel < 16);
  1289. if (m_oscData && m_oscData->target)
  1290. {
  1291. char target_path[strlen(m_oscData->path)+28];
  1292. strcpy(target_path, m_oscData->path);
  1293. strcat(target_path, "/set_parameter_midi_channel");
  1294. lo_send(m_oscData->target, target_path, "iii", pluginId, index, channel);
  1295. }
  1296. }
  1297. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const double value)
  1298. {
  1299. #if DEBUG
  1300. if (index < -1)
  1301. qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2str((InternalParametersIndex)index), value);
  1302. else
  1303. qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1304. #endif
  1305. CARLA_ASSERT(m_oscData);
  1306. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1307. if (m_oscData && m_oscData->target)
  1308. {
  1309. char target_path[strlen(m_oscData->path)+21];
  1310. strcpy(target_path, m_oscData->path);
  1311. strcat(target_path, "/set_parameter_value");
  1312. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1313. }
  1314. }
  1315. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value)
  1316. {
  1317. qDebug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1318. CARLA_ASSERT(m_oscData);
  1319. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1320. CARLA_ASSERT(index >= 0);
  1321. if (m_oscData && m_oscData->target)
  1322. {
  1323. char target_path[strlen(m_oscData->path)+19];
  1324. strcpy(target_path, m_oscData->path);
  1325. strcat(target_path, "/set_default_value");
  1326. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1327. }
  1328. }
  1329. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1330. {
  1331. qDebug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1332. CARLA_ASSERT(m_oscData);
  1333. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1334. if (m_oscData && m_oscData->target)
  1335. {
  1336. char target_path[strlen(m_oscData->path)+13];
  1337. strcpy(target_path, m_oscData->path);
  1338. strcat(target_path, "/set_program");
  1339. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1340. }
  1341. }
  1342. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1343. {
  1344. qDebug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1345. CARLA_ASSERT(m_oscData);
  1346. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1347. CARLA_ASSERT(count >= 0);
  1348. if (m_oscData && m_oscData->target)
  1349. {
  1350. char target_path[strlen(m_oscData->path)+19];
  1351. strcpy(target_path, m_oscData->path);
  1352. strcat(target_path, "/set_program_count");
  1353. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1354. }
  1355. }
  1356. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1357. {
  1358. qDebug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1359. CARLA_ASSERT(m_oscData);
  1360. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1361. CARLA_ASSERT(index >= 0);
  1362. CARLA_ASSERT(name);
  1363. if (m_oscData && m_oscData->target)
  1364. {
  1365. char target_path[strlen(m_oscData->path)+18];
  1366. strcpy(target_path, m_oscData->path);
  1367. strcat(target_path, "/set_program_name");
  1368. lo_send(m_oscData->target, target_path, "iis", pluginId, index, name);
  1369. }
  1370. }
  1371. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1372. {
  1373. qDebug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1374. CARLA_ASSERT(m_oscData);
  1375. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1376. if (m_oscData && m_oscData->target)
  1377. {
  1378. char target_path[strlen(m_oscData->path)+18];
  1379. strcpy(target_path, m_oscData->path);
  1380. strcat(target_path, "/set_midi_program");
  1381. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1382. }
  1383. }
  1384. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1385. {
  1386. qDebug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1387. CARLA_ASSERT(m_oscData);
  1388. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1389. CARLA_ASSERT(count >= 0);
  1390. if (m_oscData && m_oscData->target)
  1391. {
  1392. char target_path[strlen(m_oscData->path)+24];
  1393. strcpy(target_path, m_oscData->path);
  1394. strcat(target_path, "/set_midi_program_count");
  1395. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1396. }
  1397. }
  1398. 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)
  1399. {
  1400. qDebug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1401. CARLA_ASSERT(m_oscData);
  1402. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1403. CARLA_ASSERT(index >= 0);
  1404. CARLA_ASSERT(bank >= 0);
  1405. CARLA_ASSERT(program >= 0);
  1406. CARLA_ASSERT(name);
  1407. if (m_oscData && m_oscData->target)
  1408. {
  1409. char target_path[strlen(m_oscData->path)+23];
  1410. strcpy(target_path, m_oscData->path);
  1411. strcat(target_path, "/set_midi_program_data");
  1412. lo_send(m_oscData->target, target_path, "iiiis", pluginId, index, bank, program, name);
  1413. }
  1414. }
  1415. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1416. {
  1417. qDebug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1418. CARLA_ASSERT(m_oscData);
  1419. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1420. CARLA_ASSERT(channel >= 0 && channel < 16);
  1421. CARLA_ASSERT(note >= 0 && note < 128);
  1422. CARLA_ASSERT(velo > 0 && velo < 128);
  1423. if (m_oscData && m_oscData->target)
  1424. {
  1425. char target_path[strlen(m_oscData->path)+9];
  1426. strcpy(target_path, m_oscData->path);
  1427. strcat(target_path, "/note_on");
  1428. lo_send(m_oscData->target, target_path, "iiii", pluginId, channel, note, velo);
  1429. }
  1430. }
  1431. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1432. {
  1433. qDebug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1434. CARLA_ASSERT(m_oscData);
  1435. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1436. CARLA_ASSERT(channel >= 0 && channel < 16);
  1437. CARLA_ASSERT(note >= 0 && note < 128);
  1438. if (m_oscData && m_oscData->target)
  1439. {
  1440. char target_path[strlen(m_oscData->path)+10];
  1441. strcpy(target_path, m_oscData->path);
  1442. strcat(target_path, "/note_off");
  1443. lo_send(m_oscData->target, target_path, "iii", pluginId, channel, note);
  1444. }
  1445. }
  1446. void CarlaEngine::osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1447. {
  1448. //qDebug("CarlaEngine::osc_send_control_set_input_peak_value(%i, %i, %g)", pluginId, portId, value);
  1449. CARLA_ASSERT(m_oscData);
  1450. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1451. CARLA_ASSERT(portId == 1 || portId == 2);
  1452. if (m_oscData && m_oscData->target)
  1453. {
  1454. char target_path[strlen(m_oscData->path)+22];
  1455. strcpy(target_path, m_oscData->path);
  1456. strcat(target_path, "/set_input_peak_value");
  1457. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1458. }
  1459. }
  1460. void CarlaEngine::osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1461. {
  1462. //qDebug("CarlaEngine::osc_send_control_set_output_peak_value(%i, %i, %g)", pluginId, portId, value);
  1463. CARLA_ASSERT(m_oscData);
  1464. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1465. CARLA_ASSERT(portId == 1 || portId == 2);
  1466. if (m_oscData && m_oscData->target)
  1467. {
  1468. char target_path[strlen(m_oscData->path)+23];
  1469. strcpy(target_path, m_oscData->path);
  1470. strcat(target_path, "/set_output_peak_value");
  1471. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1472. }
  1473. }
  1474. void CarlaEngine::osc_send_control_exit()
  1475. {
  1476. qDebug("CarlaEngine::osc_send_control_exit()");
  1477. CARLA_ASSERT(m_oscData);
  1478. if (m_oscData && m_oscData->target)
  1479. {
  1480. char target_path[strlen(m_oscData->path)+6];
  1481. strcpy(target_path, m_oscData->path);
  1482. strcat(target_path, "/exit");
  1483. lo_send(m_oscData->target, target_path, "");
  1484. }
  1485. }
  1486. #else
  1487. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1488. {
  1489. qDebug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1490. CARLA_ASSERT(m_oscData);
  1491. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1492. if (m_oscData && m_oscData->target)
  1493. {
  1494. char target_path[strlen(m_oscData->path)+20];
  1495. strcpy(target_path, m_oscData->path);
  1496. strcat(target_path, "/bridge_audio_count");
  1497. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1498. }
  1499. }
  1500. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1501. {
  1502. qDebug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1503. CARLA_ASSERT(m_oscData);
  1504. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1505. if (m_oscData && m_oscData->target)
  1506. {
  1507. char target_path[strlen(m_oscData->path)+19];
  1508. strcpy(target_path, m_oscData->path);
  1509. strcat(target_path, "/bridge_midi_count");
  1510. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1511. }
  1512. }
  1513. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1514. {
  1515. qDebug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1516. CARLA_ASSERT(m_oscData);
  1517. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1518. if (m_oscData && m_oscData->target)
  1519. {
  1520. char target_path[strlen(m_oscData->path)+24];
  1521. strcpy(target_path, m_oscData->path);
  1522. strcat(target_path, "/bridge_parameter_count");
  1523. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1524. }
  1525. }
  1526. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1527. {
  1528. qDebug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1529. CARLA_ASSERT(m_oscData);
  1530. CARLA_ASSERT(count >= 0);
  1531. if (m_oscData && m_oscData->target)
  1532. {
  1533. char target_path[strlen(m_oscData->path)+22];
  1534. strcpy(target_path, m_oscData->path);
  1535. strcat(target_path, "/bridge_program_count");
  1536. lo_send(m_oscData->target, target_path, "i", count);
  1537. }
  1538. }
  1539. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1540. {
  1541. qDebug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1542. CARLA_ASSERT(m_oscData);
  1543. CARLA_ASSERT(count >= 0);
  1544. if (m_oscData && m_oscData->target)
  1545. {
  1546. char target_path[strlen(m_oscData->path)+27];
  1547. strcpy(target_path, m_oscData->path);
  1548. strcat(target_path, "/bridge_midi_program_count");
  1549. lo_send(m_oscData->target, target_path, "i", count);
  1550. }
  1551. }
  1552. 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)
  1553. {
  1554. qDebug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1555. CARLA_ASSERT(m_oscData);
  1556. CARLA_ASSERT(name);
  1557. CARLA_ASSERT(label);
  1558. CARLA_ASSERT(maker);
  1559. CARLA_ASSERT(copyright);
  1560. if (m_oscData && m_oscData->target)
  1561. {
  1562. char target_path[strlen(m_oscData->path)+20];
  1563. strcpy(target_path, m_oscData->path);
  1564. strcat(target_path, "/bridge_plugin_info");
  1565. lo_send(m_oscData->target, target_path, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1566. }
  1567. }
  1568. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1569. {
  1570. qDebug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1571. CARLA_ASSERT(m_oscData);
  1572. CARLA_ASSERT(name);
  1573. CARLA_ASSERT(unit);
  1574. if (m_oscData && m_oscData->target)
  1575. {
  1576. char target_path[strlen(m_oscData->path)+23];
  1577. strcpy(target_path, m_oscData->path);
  1578. strcat(target_path, "/bridge_parameter_info");
  1579. lo_send(m_oscData->target, target_path, "iss", index, name, unit);
  1580. }
  1581. }
  1582. 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)
  1583. {
  1584. qDebug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1585. CARLA_ASSERT(m_oscData);
  1586. if (m_oscData && m_oscData->target)
  1587. {
  1588. char target_path[strlen(m_oscData->path)+23];
  1589. strcpy(target_path, m_oscData->path);
  1590. strcat(target_path, "/bridge_parameter_data");
  1591. lo_send(m_oscData->target, target_path, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1592. }
  1593. }
  1594. 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)
  1595. {
  1596. qDebug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1597. CARLA_ASSERT(m_oscData);
  1598. if (m_oscData && m_oscData->target)
  1599. {
  1600. char target_path[strlen(m_oscData->path)+25];
  1601. strcpy(target_path, m_oscData->path);
  1602. strcat(target_path, "/bridge_parameter_ranges");
  1603. lo_send(m_oscData->target, target_path, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1604. }
  1605. }
  1606. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1607. {
  1608. qDebug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1609. CARLA_ASSERT(m_oscData);
  1610. if (m_oscData && m_oscData->target)
  1611. {
  1612. char target_path[strlen(m_oscData->path)+21];
  1613. strcpy(target_path, m_oscData->path);
  1614. strcat(target_path, "/bridge_program_info");
  1615. lo_send(m_oscData->target, target_path, "is", index, name);
  1616. }
  1617. }
  1618. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1619. {
  1620. qDebug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1621. CARLA_ASSERT(m_oscData);
  1622. if (m_oscData && m_oscData->target)
  1623. {
  1624. char target_path[strlen(m_oscData->path)+26];
  1625. strcpy(target_path, m_oscData->path);
  1626. strcat(target_path, "/bridge_midi_program_info");
  1627. lo_send(m_oscData->target, target_path, "iiis", index, bank, program, label);
  1628. }
  1629. }
  1630. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1631. {
  1632. qDebug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1633. CARLA_ASSERT(m_oscData);
  1634. CARLA_ASSERT(key);
  1635. CARLA_ASSERT(value);
  1636. if (m_oscData && m_oscData->target)
  1637. {
  1638. char target_path[strlen(m_oscData->path)+18];
  1639. strcpy(target_path, m_oscData->path);
  1640. strcat(target_path, "/bridge_configure");
  1641. lo_send(m_oscData->target, target_path, "ss", key, value);
  1642. }
  1643. }
  1644. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const double value)
  1645. {
  1646. qDebug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1647. CARLA_ASSERT(m_oscData);
  1648. if (m_oscData && m_oscData->target)
  1649. {
  1650. char target_path[strlen(m_oscData->path)+28];
  1651. strcpy(target_path, m_oscData->path);
  1652. strcat(target_path, "/bridge_set_parameter_value");
  1653. lo_send(m_oscData->target, target_path, "id", index, value);
  1654. }
  1655. }
  1656. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const double value)
  1657. {
  1658. qDebug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1659. CARLA_ASSERT(m_oscData);
  1660. if (m_oscData && m_oscData->target)
  1661. {
  1662. char target_path[strlen(m_oscData->path)+26];
  1663. strcpy(target_path, m_oscData->path);
  1664. strcat(target_path, "/bridge_set_default_value");
  1665. lo_send(m_oscData->target, target_path, "id", index, value);
  1666. }
  1667. }
  1668. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1669. {
  1670. qDebug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1671. CARLA_ASSERT(m_oscData);
  1672. if (m_oscData && m_oscData->target)
  1673. {
  1674. char target_path[strlen(m_oscData->path)+20];
  1675. strcpy(target_path, m_oscData->path);
  1676. strcat(target_path, "/bridge_set_program");
  1677. lo_send(m_oscData->target, target_path, "i", index);
  1678. }
  1679. }
  1680. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1681. {
  1682. qDebug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1683. CARLA_ASSERT(m_oscData);
  1684. if (m_oscData && m_oscData->target)
  1685. {
  1686. char target_path[strlen(m_oscData->path)+25];
  1687. strcpy(target_path, m_oscData->path);
  1688. strcat(target_path, "/bridge_set_midi_program");
  1689. lo_send(m_oscData->target, target_path, "i", index);
  1690. }
  1691. }
  1692. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const stype, const char* const key, const char* const value)
  1693. {
  1694. qDebug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", stype, key, value);
  1695. CARLA_ASSERT(m_oscData);
  1696. if (m_oscData && m_oscData->target)
  1697. {
  1698. char target_path[strlen(m_oscData->path)+24];
  1699. strcpy(target_path, m_oscData->path);
  1700. strcat(target_path, "/bridge_set_custom_data");
  1701. lo_send(m_oscData->target, target_path, "sss", stype, key, value);
  1702. }
  1703. }
  1704. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1705. {
  1706. qDebug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1707. CARLA_ASSERT(m_oscData);
  1708. if (m_oscData && m_oscData->target)
  1709. {
  1710. char target_path[strlen(m_oscData->path)+23];
  1711. strcpy(target_path, m_oscData->path);
  1712. strcat(target_path, "/bridge_set_chunk_data");
  1713. lo_send(m_oscData->target, target_path, "s", chunkFile);
  1714. }
  1715. }
  1716. void CarlaEngine::osc_send_bridge_set_inpeak(const int32_t portId, const double value)
  1717. {
  1718. CARLA_ASSERT(m_oscData);
  1719. CARLA_ASSERT(portId == 1 || portId == 2);
  1720. if (m_oscData && m_oscData->target)
  1721. {
  1722. char target_path[strlen(m_oscData->path)+28];
  1723. strcpy(target_path, m_oscData->path);
  1724. strcat(target_path, "/bridge_set_inpeak");
  1725. lo_send(m_oscData->target, target_path, "id", portId, value);
  1726. }
  1727. }
  1728. void CarlaEngine::osc_send_bridge_set_outpeak(const int32_t portId, const double value)
  1729. {
  1730. CARLA_ASSERT(m_oscData);
  1731. CARLA_ASSERT(portId == 1 || portId == 2);
  1732. if (m_oscData && m_oscData->target)
  1733. {
  1734. char target_path[strlen(m_oscData->path)+29];
  1735. strcpy(target_path, m_oscData->path);
  1736. strcat(target_path, "/bridge_set_outpeak");
  1737. lo_send(m_oscData->target, target_path, "id", portId, value);
  1738. }
  1739. }
  1740. #endif
  1741. CARLA_BACKEND_END_NAMESPACE