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.

2056 lines
64KB

  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->maxPluginNumber > 0);
  484. CARLA_ASSERT(fData->plugins != nullptr);
  485. CARLA_ASSERT(name != nullptr);
  486. static CarlaString sname;
  487. sname = name;
  488. if (sname.isEmpty() || fData->plugins == nullptr)
  489. return strdup("(No name)");
  490. sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  491. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  492. for (unsigned short i=0; i < fData->curPluginCount; i++)
  493. {
  494. CARLA_ASSERT(fData->plugins[i].plugin);
  495. // Check if unique name doesn't exist
  496. if (const char* const pluginName = fData->plugins[i].plugin->name())
  497. {
  498. if (sname != pluginName)
  499. continue;
  500. }
  501. // Check if string has already been modified
  502. {
  503. const size_t len = sname.length();
  504. // 1 digit, ex: " (2)"
  505. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  506. {
  507. int number = sname[len-2] - '0';
  508. if (number == 9)
  509. {
  510. // next number is 10, 2 digits
  511. sname.truncate(len-4);
  512. sname += " (10)";
  513. //sname.replace(" (9)", " (10)");
  514. }
  515. else
  516. sname[len-2] = char('0' + number + 1);
  517. continue;
  518. }
  519. // 2 digits, ex: " (11)"
  520. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  521. {
  522. char n2 = sname[len-2];
  523. char n3 = sname[len-3];
  524. if (n2 == '9')
  525. {
  526. n2 = '0';
  527. n3 = char(n3 + 1);
  528. }
  529. else
  530. n2 = char(n2 + 1);
  531. sname[len-2] = n2;
  532. sname[len-3] = n3;
  533. continue;
  534. }
  535. }
  536. // Modify string if not
  537. sname += " (2)";
  538. }
  539. return (const char*)sname;
  540. }
  541. 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)
  542. {
  543. qDebug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra);
  544. CARLA_ASSERT(btype != BINARY_NONE);
  545. CARLA_ASSERT(ptype != PLUGIN_NONE);
  546. CARLA_ASSERT(filename);
  547. CARLA_ASSERT(label);
  548. if (fData->curPluginCount == fData->maxPluginNumber)
  549. {
  550. setLastError("Maximum number of plugins reached");
  551. return false;
  552. }
  553. const unsigned int id = fData->curPluginCount;
  554. CarlaPlugin::Initializer init = {
  555. this,
  556. id,
  557. filename,
  558. name,
  559. label
  560. };
  561. CarlaPlugin* plugin = nullptr;
  562. #ifndef BUILD_BRIDGE
  563. const char* bridgeBinary;
  564. switch (btype)
  565. {
  566. case BINARY_POSIX32:
  567. bridgeBinary = fOptions.bridge_posix32.isNotEmpty() ? (const char*)fOptions.bridge_posix32 : nullptr;
  568. break;
  569. case BINARY_POSIX64:
  570. bridgeBinary = fOptions.bridge_posix64.isNotEmpty() ? (const char*)fOptions.bridge_posix64 : nullptr;
  571. break;
  572. case BINARY_WIN32:
  573. bridgeBinary = fOptions.bridge_win32.isNotEmpty() ? (const char*)fOptions.bridge_win32 : nullptr;
  574. break;
  575. case BINARY_WIN64:
  576. bridgeBinary = fOptions.bridge_win64.isNotEmpty() ? (const char*)fOptions.bridge_win64 : nullptr;
  577. break;
  578. default:
  579. bridgeBinary = nullptr;
  580. break;
  581. }
  582. #ifndef Q_OS_WIN
  583. if (btype == BINARY_NATIVE && fOptions.bridge_native.isNotEmpty())
  584. bridgeBinary = (const char*)fOptions.bridge_native;
  585. #endif
  586. if (fOptions.preferPluginBridges && bridgeBinary != nullptr)
  587. {
  588. // TODO
  589. if (fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  590. {
  591. setLastError("Can only use bridged plugins in JACK Multi-Client mode");
  592. return -1;
  593. }
  594. // TODO
  595. if (type() != kEngineTypeJack)
  596. {
  597. setLastError("Can only use bridged plugins with JACK backend");
  598. return -1;
  599. }
  600. #if 0
  601. plugin = CarlaPlugin::newBridge(init, btype, ptype, bridgeBinary);
  602. #endif
  603. }
  604. else
  605. #endif // BUILD_BRIDGE
  606. {
  607. switch (ptype)
  608. {
  609. case PLUGIN_NONE:
  610. break;
  611. #ifndef BUILD_BRIDGE
  612. case PLUGIN_INTERNAL:
  613. plugin = CarlaPlugin::newNative(init);
  614. break;
  615. #endif
  616. case PLUGIN_LADSPA:
  617. #ifdef WANT_LADSPA
  618. plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra);
  619. #endif
  620. break;
  621. #if 0
  622. case PLUGIN_DSSI:
  623. #ifdef WANT_DSSI
  624. plugin = CarlaPlugin::newDSSI(init, extra);
  625. #endif
  626. break;
  627. case PLUGIN_LV2:
  628. #ifdef WANT_LV2
  629. plugin = CarlaPlugin::newLV2(init);
  630. #endif
  631. break;
  632. case PLUGIN_VST:
  633. #ifdef WANT_VST
  634. plugin = CarlaPlugin::newVST(init);
  635. #endif
  636. break;
  637. case PLUGIN_GIG:
  638. #ifdef WANT_LINUXSAMPLER
  639. plugin = CarlaPlugin::newGIG(init);
  640. #endif
  641. break;
  642. case PLUGIN_SF2:
  643. #ifdef WANT_FLUIDSYNTH
  644. plugin = CarlaPlugin::newSF2(init);
  645. #endif
  646. break;
  647. case PLUGIN_SFZ:
  648. #ifdef WANT_LINUXSAMPLER
  649. plugin = CarlaPlugin::newSFZ(init);
  650. #endif
  651. break;
  652. #else
  653. default:
  654. break;
  655. #endif
  656. }
  657. }
  658. if (plugin == nullptr)
  659. return false;
  660. fData->plugins[id].plugin = plugin;
  661. fData->plugins[id].insPeak[0] = 0.0f;
  662. fData->plugins[id].insPeak[1] = 0.0f;
  663. fData->plugins[id].outsPeak[0] = 0.0f;
  664. fData->plugins[id].outsPeak[1] = 0.0f;
  665. fData->curPluginCount++;
  666. // FIXME
  667. //callback(CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, nullptr);
  668. return true;
  669. }
  670. bool CarlaEngine::removePlugin(const unsigned int id)
  671. {
  672. qDebug("CarlaEngine::removePlugin(%i)", id);
  673. CARLA_ASSERT(fData->curPluginCount > 0);
  674. CARLA_ASSERT(id < fData->curPluginCount);
  675. CARLA_ASSERT(fData->plugins != nullptr);
  676. if (fData->plugins == nullptr)
  677. {
  678. setLastError("Critical error: no plugins are currently loaded!");
  679. return false;
  680. }
  681. CarlaPlugin* const plugin = fData->plugins[id].plugin;
  682. CARLA_ASSERT(plugin);
  683. if (plugin)
  684. {
  685. CARLA_ASSERT(plugin->id() == id);
  686. fData->thread.stopNow();
  687. fData->nextAction.pluginId = id;
  688. fData->nextAction.opcode = EnginePostActionRemovePlugin;
  689. fData->nextAction.mutex.lock();
  690. if (isRunning())
  691. {
  692. // block wait for unlock on proccessing side
  693. fData->nextAction.mutex.lock();
  694. }
  695. else
  696. {
  697. doPluginRemove(fData, false);
  698. }
  699. #ifndef BUILD_BRIDGE
  700. if (isOscControlRegistered())
  701. osc_send_control_remove_plugin(id);
  702. #endif
  703. delete plugin;
  704. fData->nextAction.mutex.unlock();
  705. if (isRunning() && ! fData->aboutToClose)
  706. fData->thread.startNow();
  707. return true;
  708. }
  709. qCritical("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  710. setLastError("Could not find plugin to remove");
  711. return false;
  712. }
  713. void CarlaEngine::removeAllPlugins()
  714. {
  715. qDebug("CarlaEngine::removeAllPlugins()");
  716. fData->thread.stopNow();
  717. const unsigned int oldCount = fData->curPluginCount;
  718. // wait for processing
  719. // TODO
  720. fData->curPluginCount = 0;
  721. fData->maxPluginNumber = 0;
  722. for (unsigned short i=0; i < oldCount; i++)
  723. {
  724. CarlaPlugin* const plugin = fData->plugins[i].plugin;
  725. CARLA_ASSERT(plugin);
  726. if (plugin)
  727. delete plugin;
  728. // clear this plugin
  729. fData->plugins[i].plugin = nullptr;
  730. fData->plugins[i].insPeak[0] = 0.0;
  731. fData->plugins[i].insPeak[1] = 0.0;
  732. fData->plugins[i].outsPeak[0] = 0.0;
  733. fData->plugins[i].outsPeak[1] = 0.0;
  734. }
  735. if (isRunning() && ! fData->aboutToClose)
  736. fData->thread.startNow();
  737. }
  738. #if 0
  739. void CarlaEngine::idlePluginGuis()
  740. {
  741. CARLA_ASSERT(data->maxPluginNumber > 0);
  742. for (unsigned short i=0; i < data->maxPluginNumber; i++)
  743. {
  744. CarlaPlugin* const plugin = data->carlaPlugins[i];
  745. if (plugin && plugin->enabled())
  746. plugin->idleGui();
  747. }
  748. }
  749. void CarlaEngine::__bridgePluginRegister(const unsigned short id, CarlaPlugin* const plugin)
  750. {
  751. data->carlaPlugins[id] = plugin;
  752. }
  753. #endif
  754. // -----------------------------------------------------------------------
  755. // Information (base)
  756. void CarlaEngine::setAboutToClose()
  757. {
  758. qDebug("CarlaEngine::setAboutToClose()");
  759. fData->aboutToClose = true;
  760. }
  761. #if 0
  762. // -----------------------------------------------------------------------
  763. // Information (audio peaks)
  764. double CarlaEngine::getInputPeak(const unsigned short pluginId, const unsigned short id) const
  765. {
  766. CARLA_ASSERT(pluginId < data->maxPluginNumber);
  767. CARLA_ASSERT(id < MAX_PEAKS);
  768. return data->insPeak[pluginId*MAX_PEAKS + id];
  769. }
  770. double CarlaEngine::getOutputPeak(const unsigned short pluginId, const unsigned short id) const
  771. {
  772. CARLA_ASSERT(pluginId < data->maxPluginNumber);
  773. CARLA_ASSERT(id < MAX_PEAKS);
  774. return data->outsPeak[pluginId*MAX_PEAKS + id];
  775. }
  776. void CarlaEngine::setInputPeak(const unsigned short pluginId, const unsigned short id, double value)
  777. {
  778. CARLA_ASSERT(pluginId < data->maxPluginNumber);
  779. CARLA_ASSERT(id < MAX_PEAKS);
  780. data->insPeak[pluginId*MAX_PEAKS + id] = value;
  781. }
  782. void CarlaEngine::setOutputPeak(const unsigned short pluginId, const unsigned short id, double value)
  783. {
  784. CARLA_ASSERT(pluginId < data->maxPluginNumber);
  785. CARLA_ASSERT(id < MAX_PEAKS);
  786. data->outsPeak[pluginId*MAX_PEAKS + id] = value;
  787. }
  788. #endif
  789. // -----------------------------------------------------------------------
  790. // Callback
  791. void CarlaEngine::callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  792. {
  793. qDebug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  794. if (fData->callback)
  795. fData->callback(fData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  796. }
  797. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  798. {
  799. qDebug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  800. CARLA_ASSERT(func);
  801. fData->callback = func;
  802. fData->callbackPtr = ptr;
  803. }
  804. // -----------------------------------------------------------------------
  805. // Error handling
  806. const char* CarlaEngine::getLastError() const
  807. {
  808. return (const char*)fData->lastError;
  809. }
  810. void CarlaEngine::setLastError(const char* const error)
  811. {
  812. fData->lastError = error;
  813. }
  814. // -----------------------------------------------------------------------
  815. // Global options
  816. #ifndef BUILD_BRIDGE
  817. const QProcessEnvironment& CarlaEngine::getOptionsAsProcessEnvironment() const
  818. {
  819. return fData->procEnv;
  820. }
  821. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  822. if (isRunning()) \
  823. return qCritical("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  824. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  825. {
  826. qDebug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  827. switch (option)
  828. {
  829. case OPTION_PROCESS_NAME:
  830. carla_setprocname(valueStr);
  831. break;
  832. case OPTION_PROCESS_MODE:
  833. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  834. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_PATCHBAY)
  835. return qCritical("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  836. fOptions.processMode = static_cast<ProcessMode>(value);
  837. break;
  838. case OPTION_MAX_PARAMETERS:
  839. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  840. if (value < 0)
  841. return; // TODO error here
  842. fOptions.maxParameters = static_cast<uint>(value);
  843. break;
  844. case OPTION_PREFERRED_BUFFER_SIZE:
  845. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  846. fOptions.preferredBufferSize = static_cast<uint>(value);
  847. break;
  848. case OPTION_PREFERRED_SAMPLE_RATE:
  849. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  850. fOptions.preferredSampleRate = static_cast<uint>(value);
  851. break;
  852. case OPTION_FORCE_STEREO:
  853. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  854. fOptions.forceStereo = (value != 0);
  855. break;
  856. #ifdef WANT_DSSI
  857. case OPTION_USE_DSSI_VST_CHUNKS:
  858. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  859. fOptions.useDssiVstChunks = (value != 0);
  860. break;
  861. #endif
  862. case OPTION_PREFER_PLUGIN_BRIDGES:
  863. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  864. fOptions.preferPluginBridges = (value != 0);
  865. break;
  866. case OPTION_PREFER_UI_BRIDGES:
  867. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  868. fOptions.preferUiBridges = (value != 0);
  869. break;
  870. case OPTION_OSC_UI_TIMEOUT:
  871. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  872. fOptions.oscUiTimeout = static_cast<uint>(value);
  873. break;
  874. case OPTION_PATH_BRIDGE_NATIVE:
  875. fOptions.bridge_native = valueStr;
  876. break;
  877. case OPTION_PATH_BRIDGE_POSIX32:
  878. fOptions.bridge_posix32 = valueStr;
  879. break;
  880. case OPTION_PATH_BRIDGE_POSIX64:
  881. fOptions.bridge_posix64 = valueStr;
  882. break;
  883. case OPTION_PATH_BRIDGE_WIN32:
  884. fOptions.bridge_win32 = valueStr;
  885. break;
  886. case OPTION_PATH_BRIDGE_WIN64:
  887. fOptions.bridge_win64 = valueStr;
  888. break;
  889. #ifdef WANT_LV2
  890. case OPTION_PATH_BRIDGE_LV2_GTK2:
  891. fOptions.bridge_lv2gtk2 = valueStr;
  892. break;
  893. case OPTION_PATH_BRIDGE_LV2_GTK3:
  894. fOptions.bridge_lv2gtk3 = valueStr;
  895. break;
  896. case OPTION_PATH_BRIDGE_LV2_QT4:
  897. fOptions.bridge_lv2qt4 = valueStr;
  898. break;
  899. case OPTION_PATH_BRIDGE_LV2_QT5:
  900. fOptions.bridge_lv2qt5 = valueStr;
  901. break;
  902. case OPTION_PATH_BRIDGE_LV2_COCOA:
  903. fOptions.bridge_lv2cocoa = valueStr;
  904. break;
  905. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  906. fOptions.bridge_lv2win = valueStr;
  907. break;
  908. case OPTION_PATH_BRIDGE_LV2_X11:
  909. fOptions.bridge_lv2x11 = valueStr;
  910. break;
  911. #endif
  912. #ifdef WANT_VST
  913. case OPTION_PATH_BRIDGE_VST_COCOA:
  914. fOptions.bridge_vstcocoa = valueStr;
  915. break;
  916. case OPTION_PATH_BRIDGE_VST_HWND:
  917. fOptions.bridge_vsthwnd = valueStr;
  918. break;
  919. case OPTION_PATH_BRIDGE_VST_X11:
  920. fOptions.bridge_vstx11 = valueStr;
  921. break;
  922. #endif
  923. }
  924. }
  925. #endif
  926. // -----------------------------------------------------------------------
  927. // OSC Stuff
  928. #ifdef BUILD_BRIDGE
  929. bool CarlaEngine::isOscBridgeRegistered() const
  930. {
  931. return (fData->oscData != nullptr);
  932. }
  933. #else
  934. bool CarlaEngine::isOscControlRegistered() const
  935. {
  936. return fData->osc.isControlRegistered();
  937. }
  938. #endif
  939. void CarlaEngine::idleOsc()
  940. {
  941. fData->osc.idle();
  942. }
  943. const char* CarlaEngine::getOscServerPathTCP() const
  944. {
  945. return fData->osc.getServerPathTCP();
  946. }
  947. const char* CarlaEngine::getOscServerPathUDP() const
  948. {
  949. return fData->osc.getServerPathUDP();
  950. }
  951. #ifdef BUILD_BRIDGE
  952. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  953. {
  954. fData->oscData = oscData;
  955. }
  956. #endif
  957. // -----------------------------------------------------------------------
  958. // protected calls
  959. #ifndef BUILD_BRIDGE
  960. EngineEvent* CarlaEngine::getRackEventBuffer(const bool isInput)
  961. {
  962. // TODO
  963. return nullptr;
  964. }
  965. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  966. {
  967. // initialize outputs (zero)
  968. carla_zeroFloat(outBuf[0], frames);
  969. carla_zeroFloat(outBuf[1], frames);
  970. #if 0
  971. std::memset(rackEventsOut, 0, sizeof(EngineEvent)*MAX_EVENTS);
  972. bool processed = false;
  973. // process plugins
  974. for (unsigned short i=0, max=maxPluginNumber(); i < max; i++)
  975. {
  976. CarlaPlugin* const plugin = getPluginUnchecked(i);
  977. if (! (plugin && plugin->enabled()))
  978. continue;
  979. if (processed)
  980. {
  981. // initialize inputs (from previous outputs)
  982. memcpy(inBuf[0], outBuf[0], sizeof(float)*frames);
  983. memcpy(inBuf[1], outBuf[1], sizeof(float)*frames);
  984. memcpy(rackMidiEventsIn, rackMidiEventsOut, sizeof(CarlaEngineMidiEvent)*MAX_MIDI_EVENTS);
  985. // initialize outputs (zero)
  986. carla_zeroFloat(outBuf[0], frames);
  987. carla_zeroFloat(outBuf[1], frames);
  988. memset(rackMidiEventsOut, 0, sizeof(CarlaEngineMidiEvent)*MAX_MIDI_EVENTS);
  989. }
  990. // process
  991. processLock();
  992. plugin->initBuffers();
  993. if (false /*plugin->data->processHighPrecision*/)
  994. {
  995. float* inBuf2[2];
  996. float* outBuf2[2];
  997. for (uint32_t j=0; j < frames; j += 8)
  998. {
  999. inBuf2[0] = inBuf[0] + j;
  1000. inBuf2[1] = inBuf[1] + j;
  1001. outBuf2[0] = outBuf[0] + j;
  1002. outBuf2[1] = outBuf[1] + j;
  1003. plugin->process(inBuf2, outBuf2, 8, j);
  1004. }
  1005. }
  1006. else
  1007. plugin->process(inBuf, outBuf, frames);
  1008. processUnlock();
  1009. // if plugin has no audio inputs, add previous buffers
  1010. if (plugin->audioInCount() == 0)
  1011. {
  1012. for (uint32_t j=0; j < frames; j++)
  1013. {
  1014. outBuf[0][j] += inBuf[0][j];
  1015. outBuf[1][j] += inBuf[1][j];
  1016. }
  1017. }
  1018. // if plugin has no midi output, add previous midi input
  1019. if (plugin->midiOutCount() == 0)
  1020. {
  1021. memcpy(rackMidiEventsOut, rackMidiEventsIn, sizeof(CarlaEngineMidiEvent)*MAX_MIDI_EVENTS);
  1022. }
  1023. // set peaks
  1024. {
  1025. double inPeak1 = 0.0;
  1026. double inPeak2 = 0.0;
  1027. double outPeak1 = 0.0;
  1028. double outPeak2 = 0.0;
  1029. for (uint32_t k=0; k < frames; k++)
  1030. {
  1031. // TODO - optimize this
  1032. if (std::abs(inBuf[0][k]) > inPeak1)
  1033. inPeak1 = std::abs(inBuf[0][k]);
  1034. if (std::abs(inBuf[1][k]) > inPeak2)
  1035. inPeak2 = std::abs(inBuf[1][k]);
  1036. if (std::abs(outBuf[0][k]) > outPeak1)
  1037. outPeak1 = std::abs(outBuf[0][k]);
  1038. if (std::abs(outBuf[1][k]) > outPeak2)
  1039. outPeak2 = std::abs(outBuf[1][k]);
  1040. }
  1041. data->insPeak[i*MAX_PEAKS + 0] = inPeak1;
  1042. data->insPeak[i*MAX_PEAKS + 1] = inPeak2;
  1043. data->outsPeak[i*MAX_PEAKS + 0] = outPeak1;
  1044. data->outsPeak[i*MAX_PEAKS + 1] = outPeak2;
  1045. }
  1046. processed = true;
  1047. }
  1048. // if no plugins in the rack, copy inputs over outputs
  1049. if (! processed)
  1050. {
  1051. std::memcpy(outBuf[0], inBuf[0], sizeof(float)*frames);
  1052. std::memcpy(outBuf[1], inBuf[1], sizeof(float)*frames);
  1053. std::memcpy(rackEventsOut, rackEventsIn, sizeof(EngineEvent)*MAX_EVENTS);
  1054. }
  1055. #endif
  1056. }
  1057. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1058. {
  1059. // TODO
  1060. Q_UNUSED(inBuf);
  1061. Q_UNUSED(outBuf);
  1062. Q_UNUSED(bufCount);
  1063. Q_UNUSED(frames);
  1064. }
  1065. #endif
  1066. void CarlaEngine::proccessPendingEvents()
  1067. {
  1068. switch (fData->nextAction.opcode)
  1069. {
  1070. case EnginePostActionNull:
  1071. break;
  1072. case EnginePostActionRemovePlugin:
  1073. doPluginRemove(fData, true);
  1074. break;
  1075. }
  1076. // TODO - peak values
  1077. }
  1078. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1079. {
  1080. qDebug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1081. #if 0
  1082. for (unsigned short i=0; i < data->maxPluginNumber; i++)
  1083. {
  1084. if (data->carlaPlugins[i] && data->carlaPlugins[i]->enabled() /*&& ! data->carlaPlugins[i]->data->processHighPrecision*/)
  1085. data->carlaPlugins[i]->bufferSizeChanged(newBufferSize);
  1086. }
  1087. #endif
  1088. }
  1089. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1090. {
  1091. qDebug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1092. // TODO
  1093. }
  1094. // -------------------------------------------------------------------------------------------------------------------
  1095. // Carla Engine OSC stuff
  1096. #ifdef BUILD_BRIDGE
  1097. void CarlaEngine::osc_send_peaks(CarlaPlugin* const /*plugin*/)
  1098. #else
  1099. void CarlaEngine::osc_send_peaks(CarlaPlugin* const plugin, const unsigned short& id)
  1100. #endif
  1101. {
  1102. #if 0
  1103. // Peak values
  1104. if (plugin->audioInCount() > 0)
  1105. {
  1106. #ifdef BUILD_BRIDGE
  1107. osc_send_bridge_set_inpeak(1);
  1108. osc_send_bridge_set_inpeak(2);
  1109. #else
  1110. osc_send_control_set_input_peak_value(id, 1);
  1111. osc_send_control_set_input_peak_value(id, 2);
  1112. #endif
  1113. }
  1114. if (plugin->audioOutCount() > 0)
  1115. {
  1116. #ifdef BUILD_BRIDGE
  1117. osc_send_bridge_set_outpeak(1);
  1118. osc_send_bridge_set_outpeak(2);
  1119. #else
  1120. osc_send_control_set_output_peak_value(id, 1);
  1121. osc_send_control_set_output_peak_value(id, 2);
  1122. #endif
  1123. }
  1124. #endif
  1125. }
  1126. #ifndef BUILD_BRIDGE
  1127. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1128. {
  1129. qDebug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1130. CARLA_ASSERT(fData->oscData != nullptr);
  1131. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1132. CARLA_ASSERT(pluginName);
  1133. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1134. {
  1135. char target_path[strlen(fData->oscData->path)+18];
  1136. strcpy(target_path, fData->oscData->path);
  1137. strcat(target_path, "/add_plugin_start");
  1138. lo_send(fData->oscData->target, target_path, "is", pluginId, pluginName);
  1139. }
  1140. }
  1141. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1142. {
  1143. qDebug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1144. CARLA_ASSERT(fData->oscData != nullptr);
  1145. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1146. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1147. {
  1148. char target_path[strlen(fData->oscData->path)+16];
  1149. strcpy(target_path, fData->oscData->path);
  1150. strcat(target_path, "/add_plugin_end");
  1151. lo_send(fData->oscData->target, target_path, "i", pluginId);
  1152. }
  1153. }
  1154. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1155. {
  1156. qDebug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1157. CARLA_ASSERT(fData->oscData != nullptr);
  1158. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1159. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1160. {
  1161. char target_path[strlen(fData->oscData->path)+15];
  1162. strcpy(target_path, fData->oscData->path);
  1163. strcat(target_path, "/remove_plugin");
  1164. lo_send(fData->oscData->target, target_path, "i", pluginId);
  1165. }
  1166. }
  1167. 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)
  1168. {
  1169. 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);
  1170. CARLA_ASSERT(fData->oscData != nullptr);
  1171. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1172. CARLA_ASSERT(type != PLUGIN_NONE);
  1173. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1174. {
  1175. char target_path[strlen(fData->oscData->path)+17];
  1176. strcpy(target_path, fData->oscData->path);
  1177. strcat(target_path, "/set_plugin_data");
  1178. lo_send(fData->oscData->target, target_path, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1179. }
  1180. }
  1181. 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)
  1182. {
  1183. qDebug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1184. CARLA_ASSERT(fData->oscData != nullptr);
  1185. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1186. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1187. {
  1188. char target_path[strlen(fData->oscData->path)+18];
  1189. strcpy(target_path, fData->oscData->path);
  1190. strcat(target_path, "/set_plugin_ports");
  1191. lo_send(fData->oscData->target, target_path, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1192. }
  1193. }
  1194. 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)
  1195. {
  1196. qDebug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1197. CARLA_ASSERT(fData->oscData != nullptr);
  1198. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1199. CARLA_ASSERT(index >= 0);
  1200. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1201. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1202. {
  1203. char target_path[strlen(fData->oscData->path)+20];
  1204. strcpy(target_path, fData->oscData->path);
  1205. strcat(target_path, "/set_parameter_data");
  1206. lo_send(fData->oscData->target, target_path, "iiiissd", pluginId, index, type, hints, name, label, current);
  1207. }
  1208. }
  1209. 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)
  1210. {
  1211. qDebug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1212. CARLA_ASSERT(fData->oscData != nullptr);
  1213. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1214. CARLA_ASSERT(index >= 0);
  1215. CARLA_ASSERT(min < max);
  1216. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1217. {
  1218. char target_path[strlen(fData->oscData->path)+22];
  1219. strcpy(target_path, fData->oscData->path);
  1220. strcat(target_path, "/set_parameter_ranges");
  1221. lo_send(fData->oscData->target, target_path, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1222. }
  1223. }
  1224. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1225. {
  1226. qDebug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1227. CARLA_ASSERT(fData->oscData != nullptr);
  1228. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1229. CARLA_ASSERT(index >= 0);
  1230. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1231. {
  1232. char target_path[strlen(fData->oscData->path)+23];
  1233. strcpy(target_path, fData->oscData->path);
  1234. strcat(target_path, "/set_parameter_midi_cc");
  1235. lo_send(fData->oscData->target, target_path, "iii", pluginId, index, cc);
  1236. }
  1237. }
  1238. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1239. {
  1240. qDebug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1241. CARLA_ASSERT(fData->oscData != nullptr);
  1242. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1243. CARLA_ASSERT(index >= 0);
  1244. CARLA_ASSERT(channel >= 0 && channel < 16);
  1245. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1246. {
  1247. char target_path[strlen(fData->oscData->path)+28];
  1248. strcpy(target_path, fData->oscData->path);
  1249. strcat(target_path, "/set_parameter_midi_channel");
  1250. lo_send(fData->oscData->target, target_path, "iii", pluginId, index, channel);
  1251. }
  1252. }
  1253. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const double value)
  1254. {
  1255. #if DEBUG
  1256. if (index < 0)
  1257. qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1258. else
  1259. qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1260. #endif
  1261. CARLA_ASSERT(fData->oscData != nullptr);
  1262. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->curPluginCount);
  1263. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1264. {
  1265. char target_path[strlen(fData->oscData->path)+21];
  1266. strcpy(target_path, fData->oscData->path);
  1267. strcat(target_path, "/set_parameter_value");
  1268. lo_send(fData->oscData->target, target_path, "iid", pluginId, index, value);
  1269. }
  1270. }
  1271. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value)
  1272. {
  1273. qDebug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1274. CARLA_ASSERT(fData->oscData != nullptr);
  1275. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1276. CARLA_ASSERT(index >= 0);
  1277. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1278. {
  1279. char target_path[strlen(fData->oscData->path)+19];
  1280. strcpy(target_path, fData->oscData->path);
  1281. strcat(target_path, "/set_default_value");
  1282. lo_send(fData->oscData->target, target_path, "iid", pluginId, index, value);
  1283. }
  1284. }
  1285. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1286. {
  1287. qDebug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1288. CARLA_ASSERT(fData->oscData != nullptr);
  1289. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1290. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1291. {
  1292. char target_path[strlen(fData->oscData->path)+13];
  1293. strcpy(target_path, fData->oscData->path);
  1294. strcat(target_path, "/set_program");
  1295. lo_send(fData->oscData->target, target_path, "ii", pluginId, index);
  1296. }
  1297. }
  1298. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1299. {
  1300. qDebug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1301. CARLA_ASSERT(fData->oscData != nullptr);
  1302. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1303. CARLA_ASSERT(count >= 0);
  1304. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1305. {
  1306. char target_path[strlen(fData->oscData->path)+19];
  1307. strcpy(target_path, fData->oscData->path);
  1308. strcat(target_path, "/set_program_count");
  1309. lo_send(fData->oscData->target, target_path, "ii", pluginId, count);
  1310. }
  1311. }
  1312. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1313. {
  1314. qDebug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1315. CARLA_ASSERT(fData->oscData != nullptr);
  1316. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1317. CARLA_ASSERT(index >= 0);
  1318. CARLA_ASSERT(name);
  1319. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1320. {
  1321. char target_path[strlen(fData->oscData->path)+18];
  1322. strcpy(target_path, fData->oscData->path);
  1323. strcat(target_path, "/set_program_name");
  1324. lo_send(fData->oscData->target, target_path, "iis", pluginId, index, name);
  1325. }
  1326. }
  1327. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1328. {
  1329. qDebug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1330. CARLA_ASSERT(fData->oscData != nullptr);
  1331. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1332. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1333. {
  1334. char target_path[strlen(fData->oscData->path)+18];
  1335. strcpy(target_path, fData->oscData->path);
  1336. strcat(target_path, "/set_midi_program");
  1337. lo_send(fData->oscData->target, target_path, "ii", pluginId, index);
  1338. }
  1339. }
  1340. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1341. {
  1342. qDebug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1343. CARLA_ASSERT(fData->oscData != nullptr);
  1344. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1345. CARLA_ASSERT(count >= 0);
  1346. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1347. {
  1348. char target_path[strlen(fData->oscData->path)+24];
  1349. strcpy(target_path, fData->oscData->path);
  1350. strcat(target_path, "/set_midi_program_count");
  1351. lo_send(fData->oscData->target, target_path, "ii", pluginId, count);
  1352. }
  1353. }
  1354. 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)
  1355. {
  1356. qDebug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1357. CARLA_ASSERT(fData->oscData != nullptr);
  1358. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1359. CARLA_ASSERT(index >= 0);
  1360. CARLA_ASSERT(bank >= 0);
  1361. CARLA_ASSERT(program >= 0);
  1362. CARLA_ASSERT(name);
  1363. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1364. {
  1365. char target_path[strlen(fData->oscData->path)+23];
  1366. strcpy(target_path, fData->oscData->path);
  1367. strcat(target_path, "/set_midi_program_data");
  1368. lo_send(fData->oscData->target, target_path, "iiiis", pluginId, index, bank, program, name);
  1369. }
  1370. }
  1371. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1372. {
  1373. qDebug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1374. CARLA_ASSERT(fData->oscData != nullptr);
  1375. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1376. CARLA_ASSERT(channel >= 0 && channel < 16);
  1377. CARLA_ASSERT(note >= 0 && note < 128);
  1378. CARLA_ASSERT(velo > 0 && velo < 128);
  1379. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1380. {
  1381. char target_path[strlen(fData->oscData->path)+9];
  1382. strcpy(target_path, fData->oscData->path);
  1383. strcat(target_path, "/note_on");
  1384. lo_send(fData->oscData->target, target_path, "iiii", pluginId, channel, note, velo);
  1385. }
  1386. }
  1387. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1388. {
  1389. qDebug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1390. CARLA_ASSERT(fData->oscData != nullptr);
  1391. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1392. CARLA_ASSERT(channel >= 0 && channel < 16);
  1393. CARLA_ASSERT(note >= 0 && note < 128);
  1394. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1395. {
  1396. char target_path[strlen(fData->oscData->path)+10];
  1397. strcpy(target_path, fData->oscData->path);
  1398. strcat(target_path, "/note_off");
  1399. lo_send(fData->oscData->target, target_path, "iii", pluginId, channel, note);
  1400. }
  1401. }
  1402. #if 0
  1403. void CarlaEngine::osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId)
  1404. {
  1405. //qDebug("CarlaEngine::osc_send_control_set_input_peak_value(%i, %i)", pluginId, portId);
  1406. CARLA_ASSERT(fData->oscData != nullptr);
  1407. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1408. CARLA_ASSERT(portId == 1 || portId == 2);
  1409. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1410. {
  1411. char target_path[strlen(fData->oscData->path)+22];
  1412. strcpy(target_path, fData->oscData->path);
  1413. strcat(target_path, "/set_input_peak_value");
  1414. lo_send(fData->oscData->target, target_path, "iid", pluginId, portId, data->insPeak[pluginId*MAX_PEAKS + portId-1]);
  1415. }
  1416. }
  1417. void CarlaEngine::osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId)
  1418. {
  1419. //qDebug("CarlaEngine::osc_send_control_set_output_peak_value(%i, %i)", pluginId, portId);
  1420. CARLA_ASSERT(fData->oscData != nullptr);
  1421. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)fData->maxPluginNumber);
  1422. CARLA_ASSERT(portId == 1 || portId == 2);
  1423. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1424. {
  1425. char target_path[strlen(fData->oscData->path)+23];
  1426. strcpy(target_path, fData->oscData->path);
  1427. strcat(target_path, "/set_output_peak_value");
  1428. lo_send(fData->oscData->target, target_path, "iid", pluginId, portId, data->outsPeak[pluginId*MAX_PEAKS + portId-1]);
  1429. }
  1430. }
  1431. #endif
  1432. void CarlaEngine::osc_send_control_exit()
  1433. {
  1434. qDebug("CarlaEngine::osc_send_control_exit()");
  1435. CARLA_ASSERT(fData->oscData);
  1436. if (fData->oscData && fData->oscData->target)
  1437. {
  1438. char target_path[strlen(fData->oscData->path)+6];
  1439. strcpy(target_path, fData->oscData->path);
  1440. strcat(target_path, "/exit");
  1441. lo_send(fData->oscData->target, target_path, "");
  1442. }
  1443. }
  1444. #else
  1445. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1446. {
  1447. qDebug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1448. CARLA_ASSERT(fData->oscData != nullptr);
  1449. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1450. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1451. {
  1452. char target_path[strlen(fData->oscData->path)+20];
  1453. strcpy(target_path, fData->oscData->path);
  1454. strcat(target_path, "/bridge_audio_count");
  1455. lo_send(fData->oscData->target, target_path, "iii", ins, outs, total);
  1456. }
  1457. }
  1458. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1459. {
  1460. qDebug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1461. CARLA_ASSERT(fData->oscData != nullptr);
  1462. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1463. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1464. {
  1465. char target_path[strlen(fData->oscData->path)+19];
  1466. strcpy(target_path, fData->oscData->path);
  1467. strcat(target_path, "/bridge_midi_count");
  1468. lo_send(fData->oscData->target, target_path, "iii", ins, outs, total);
  1469. }
  1470. }
  1471. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1472. {
  1473. qDebug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1474. CARLA_ASSERT(fData->oscData != nullptr);
  1475. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1476. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1477. {
  1478. char target_path[strlen(fData->oscData->path)+24];
  1479. strcpy(target_path, fData->oscData->path);
  1480. strcat(target_path, "/bridge_parameter_count");
  1481. lo_send(fData->oscData->target, target_path, "iii", ins, outs, total);
  1482. }
  1483. }
  1484. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1485. {
  1486. qDebug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1487. CARLA_ASSERT(fData->oscData != nullptr);
  1488. CARLA_ASSERT(count >= 0);
  1489. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1490. {
  1491. char target_path[strlen(fData->oscData->path)+22];
  1492. strcpy(target_path, fData->oscData->path);
  1493. strcat(target_path, "/bridge_program_count");
  1494. lo_send(fData->oscData->target, target_path, "i", count);
  1495. }
  1496. }
  1497. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1498. {
  1499. qDebug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1500. CARLA_ASSERT(fData->oscData != nullptr);
  1501. CARLA_ASSERT(count >= 0);
  1502. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1503. {
  1504. char target_path[strlen(fData->oscData->path)+27];
  1505. strcpy(target_path, fData->oscData->path);
  1506. strcat(target_path, "/bridge_midi_program_count");
  1507. lo_send(fData->oscData->target, target_path, "i", count);
  1508. }
  1509. }
  1510. 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)
  1511. {
  1512. qDebug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1513. CARLA_ASSERT(fData->oscData != nullptr);
  1514. CARLA_ASSERT(name);
  1515. CARLA_ASSERT(label);
  1516. CARLA_ASSERT(maker);
  1517. CARLA_ASSERT(copyright);
  1518. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1519. {
  1520. char target_path[strlen(fData->oscData->path)+20];
  1521. strcpy(target_path, fData->oscData->path);
  1522. strcat(target_path, "/bridge_plugin_info");
  1523. lo_send(fData->oscData->target, target_path, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1524. }
  1525. }
  1526. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1527. {
  1528. qDebug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1529. CARLA_ASSERT(fData->oscData != nullptr);
  1530. CARLA_ASSERT(name);
  1531. CARLA_ASSERT(unit);
  1532. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1533. {
  1534. char target_path[strlen(fData->oscData->path)+23];
  1535. strcpy(target_path, fData->oscData->path);
  1536. strcat(target_path, "/bridge_parameter_info");
  1537. lo_send(fData->oscData->target, target_path, "iss", index, name, unit);
  1538. }
  1539. }
  1540. 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)
  1541. {
  1542. qDebug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1543. CARLA_ASSERT(fData->oscData != nullptr);
  1544. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1545. {
  1546. char target_path[strlen(fData->oscData->path)+23];
  1547. strcpy(target_path, fData->oscData->path);
  1548. strcat(target_path, "/bridge_parameter_data");
  1549. lo_send(fData->oscData->target, target_path, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1550. }
  1551. }
  1552. 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)
  1553. {
  1554. qDebug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1555. CARLA_ASSERT(fData->oscData != nullptr);
  1556. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1557. {
  1558. char target_path[strlen(fData->oscData->path)+25];
  1559. strcpy(target_path, fData->oscData->path);
  1560. strcat(target_path, "/bridge_parameter_ranges");
  1561. lo_send(fData->oscData->target, target_path, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1562. }
  1563. }
  1564. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1565. {
  1566. qDebug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1567. CARLA_ASSERT(fData->oscData != nullptr);
  1568. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1569. {
  1570. char target_path[strlen(fData->oscData->path)+21];
  1571. strcpy(target_path, fData->oscData->path);
  1572. strcat(target_path, "/bridge_program_info");
  1573. lo_send(fData->oscData->target, target_path, "is", index, name);
  1574. }
  1575. }
  1576. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1577. {
  1578. qDebug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1579. CARLA_ASSERT(fData->oscData != nullptr);
  1580. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1581. {
  1582. char target_path[strlen(fData->oscData->path)+26];
  1583. strcpy(target_path, fData->oscData->path);
  1584. strcat(target_path, "/bridge_midi_program_info");
  1585. lo_send(fData->oscData->target, target_path, "iiis", index, bank, program, label);
  1586. }
  1587. }
  1588. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1589. {
  1590. qDebug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1591. CARLA_ASSERT(fData->oscData != nullptr);
  1592. CARLA_ASSERT(key);
  1593. CARLA_ASSERT(value);
  1594. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1595. {
  1596. char target_path[strlen(fData->oscData->path)+18];
  1597. strcpy(target_path, fData->oscData->path);
  1598. strcat(target_path, "/bridge_configure");
  1599. lo_send(fData->oscData->target, target_path, "ss", key, value);
  1600. }
  1601. }
  1602. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const double value)
  1603. {
  1604. qDebug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1605. CARLA_ASSERT(fData->oscData != nullptr);
  1606. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1607. {
  1608. char target_path[strlen(fData->oscData->path)+28];
  1609. strcpy(target_path, fData->oscData->path);
  1610. strcat(target_path, "/bridge_set_parameter_value");
  1611. lo_send(fData->oscData->target, target_path, "id", index, value);
  1612. }
  1613. }
  1614. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const double value)
  1615. {
  1616. qDebug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1617. CARLA_ASSERT(fData->oscData != nullptr);
  1618. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1619. {
  1620. char target_path[strlen(fData->oscData->path)+26];
  1621. strcpy(target_path, fData->oscData->path);
  1622. strcat(target_path, "/bridge_set_default_value");
  1623. lo_send(fData->oscData->target, target_path, "id", index, value);
  1624. }
  1625. }
  1626. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1627. {
  1628. qDebug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1629. CARLA_ASSERT(fData->oscData != nullptr);
  1630. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1631. {
  1632. char target_path[strlen(fData->oscData->path)+20];
  1633. strcpy(target_path, fData->oscData->path);
  1634. strcat(target_path, "/bridge_set_program");
  1635. lo_send(fData->oscData->target, target_path, "i", index);
  1636. }
  1637. }
  1638. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1639. {
  1640. qDebug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1641. CARLA_ASSERT(fData->oscData != nullptr);
  1642. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1643. {
  1644. char target_path[strlen(fData->oscData->path)+25];
  1645. strcpy(target_path, fData->oscData->path);
  1646. strcat(target_path, "/bridge_set_midi_program");
  1647. lo_send(fData->oscData->target, target_path, "i", index);
  1648. }
  1649. }
  1650. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1651. {
  1652. qDebug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1653. CARLA_ASSERT(fData->oscData);
  1654. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1655. {
  1656. char target_path[strlen(fData->oscData->path)+24];
  1657. strcpy(target_path, fData->oscData->path);
  1658. strcat(target_path, "/bridge_set_custom_data");
  1659. lo_send(fData->oscData->target, target_path, "sss", type, key, value);
  1660. }
  1661. }
  1662. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1663. {
  1664. qDebug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1665. CARLA_ASSERT(fData->oscData != nullptr);
  1666. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1667. {
  1668. char target_path[strlen(fData->oscData->path)+23];
  1669. strcpy(target_path, fData->oscData->path);
  1670. strcat(target_path, "/bridge_set_chunk_data");
  1671. lo_send(fData->oscData->target, target_path, "s", chunkFile);
  1672. }
  1673. }
  1674. #if 0
  1675. void CarlaEngine::osc_send_bridge_set_inpeak(const int32_t portId)
  1676. {
  1677. CARLA_ASSERT(fData->oscData != nullptr);
  1678. CARLA_ASSERT(portId == 1 || portId == 2);
  1679. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1680. {
  1681. char target_path[strlen(fData->oscData->path)+28];
  1682. strcpy(target_path, fData->oscData->path);
  1683. strcat(target_path, "/bridge_set_inpeak");
  1684. lo_send(fData->oscData->target, target_path, "id", portId, data->insPeak[portId-1]);
  1685. }
  1686. }
  1687. void CarlaEngine::osc_send_bridge_set_outpeak(const int32_t portId)
  1688. {
  1689. CARLA_ASSERT(fData->oscData != nullptr);
  1690. CARLA_ASSERT(portId == 1 || portId == 2);
  1691. if (fData->oscData != nullptr && fData->oscData->target != nullptr)
  1692. {
  1693. char target_path[strlen(fData->oscData->path)+29];
  1694. strcpy(target_path, fData->oscData->path);
  1695. strcat(target_path, "/bridge_set_outpeak");
  1696. lo_send(fData->oscData->target, target_path, "id", portId, data->insPeak[portId-1]);
  1697. }
  1698. }
  1699. #endif
  1700. #endif
  1701. CARLA_BACKEND_END_NAMESPACE