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.

2140 lines
67KB

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