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.

2120 lines
65KB

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