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.

2128 lines
66KB

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