Audio plugin host https://kx.studio/carla
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.

2044 lines
63KB

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