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.

2518 lines
79KB

  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 "CarlaEngineInternal.hpp"
  18. #include "CarlaBackendUtils.hpp"
  19. #include "CarlaStateUtils.hpp"
  20. #include "CarlaMIDI.h"
  21. #include <cmath>
  22. #include <QtCore/QDir>
  23. #include <QtCore/QFile>
  24. #include <QtCore/QFileInfo>
  25. #include <QtCore/QTextStream>
  26. // -------------------------------------------------------------------------------------------------------------------
  27. // Register native engine plugin
  28. #ifndef BUILD_BRIDGE
  29. # include "CarlaNative.h"
  30. void carla_register_native_plugin_carla()
  31. {
  32. CARLA_BACKEND_USE_NAMESPACE;
  33. CarlaEngine::registerNativePlugin();
  34. }
  35. #endif
  36. // -------------------------------------------------------------------------------------------------------------------
  37. CARLA_BACKEND_START_NAMESPACE
  38. // -------------------------------------------------------------------------------------------------------------------
  39. // Fallback data
  40. static const EngineEvent kFallbackEngineEvent;
  41. #ifndef BUILD_BRIDGE
  42. // -------------------------------------------------------------------------------------------------------------------
  43. // Bridge Helper, defined in CarlaPlugin.cpp
  44. extern BinaryType CarlaPluginGetBridgeBinaryType(CarlaPlugin* const plugin);
  45. // -------------------------------------------------------------------------------------------------------------------
  46. // Engine Helpers
  47. void registerEnginePlugin(CarlaEngine* const engine, const unsigned int id, CarlaPlugin* const plugin)
  48. {
  49. CarlaEngineProtectedData::registerEnginePlugin(engine, id, plugin);
  50. }
  51. #endif
  52. // -------------------------------------------------------------------------------------------------------------------
  53. // Carla Engine port (Abstract)
  54. CarlaEnginePort::CarlaEnginePort(const bool isInput, const ProcessMode processMode)
  55. : kIsInput(isInput),
  56. kProcessMode(processMode)
  57. {
  58. carla_debug("CarlaEnginePort::CarlaEnginePort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  59. }
  60. CarlaEnginePort::~CarlaEnginePort()
  61. {
  62. carla_debug("CarlaEnginePort::~CarlaEnginePort()");
  63. }
  64. // -------------------------------------------------------------------------------------------------------------------
  65. // Carla Engine Audio port
  66. CarlaEngineAudioPort::CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode)
  67. : CarlaEnginePort(isInput, processMode),
  68. fBuffer(nullptr)
  69. {
  70. carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  71. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  72. fBuffer = new float[PATCHBAY_BUFFER_SIZE];
  73. }
  74. CarlaEngineAudioPort::~CarlaEngineAudioPort()
  75. {
  76. carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()");
  77. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  78. {
  79. CARLA_ASSERT(fBuffer != nullptr);
  80. if (fBuffer != nullptr)
  81. delete[] fBuffer;
  82. }
  83. }
  84. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const)
  85. {
  86. if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  87. carla_zeroFloat(fBuffer, PATCHBAY_BUFFER_SIZE);
  88. }
  89. // -------------------------------------------------------------------------------------------------------------------
  90. // Carla Engine Event port
  91. CarlaEngineEventPort::CarlaEngineEventPort(const bool isInput, const ProcessMode processMode)
  92. : CarlaEnginePort(isInput, processMode),
  93. fBuffer(nullptr)
  94. {
  95. carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  96. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  97. fBuffer = new EngineEvent[INTERNAL_EVENT_COUNT];
  98. }
  99. CarlaEngineEventPort::~CarlaEngineEventPort()
  100. {
  101. carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()");
  102. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  103. {
  104. CARLA_ASSERT(fBuffer != nullptr);
  105. if (fBuffer != nullptr)
  106. delete[] fBuffer;
  107. }
  108. }
  109. void CarlaEngineEventPort::initBuffer(CarlaEngine* const engine)
  110. {
  111. CARLA_ASSERT(engine != nullptr);
  112. if (engine == nullptr)
  113. {
  114. fBuffer = nullptr;
  115. return;
  116. }
  117. if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_BRIDGE)
  118. {
  119. fBuffer = engine->getInternalEventBuffer(kIsInput);
  120. return;
  121. }
  122. if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  123. carla_zeroStruct<EngineEvent>(fBuffer, INTERNAL_EVENT_COUNT);
  124. }
  125. uint32_t CarlaEngineEventPort::getEventCount() const
  126. {
  127. CARLA_ASSERT(kIsInput);
  128. CARLA_ASSERT(fBuffer != nullptr);
  129. CARLA_ASSERT(kProcessMode != PROCESS_MODE_SINGLE_CLIENT && kProcessMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  130. if (! kIsInput)
  131. return 0;
  132. if (fBuffer == nullptr)
  133. return 0;
  134. if (kProcessMode == PROCESS_MODE_SINGLE_CLIENT || kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  135. return 0;
  136. for (uint32_t i=0; i < INTERNAL_EVENT_COUNT; ++i)
  137. {
  138. if (fBuffer[i].type == kEngineEventTypeNull)
  139. return i;
  140. }
  141. CARLA_ASSERT(false); // should never happen
  142. return 0;
  143. }
  144. const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index)
  145. {
  146. CARLA_ASSERT(kIsInput);
  147. CARLA_ASSERT(fBuffer != nullptr);
  148. CARLA_ASSERT(kProcessMode != PROCESS_MODE_SINGLE_CLIENT && kProcessMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  149. CARLA_ASSERT(index < INTERNAL_EVENT_COUNT);
  150. if (! kIsInput)
  151. return kFallbackEngineEvent;
  152. if (fBuffer == nullptr)
  153. return kFallbackEngineEvent;
  154. if (kProcessMode == PROCESS_MODE_SINGLE_CLIENT || kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  155. return kFallbackEngineEvent;
  156. if (index >= INTERNAL_EVENT_COUNT)
  157. return kFallbackEngineEvent;
  158. return fBuffer[index];
  159. }
  160. void CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value)
  161. {
  162. CARLA_ASSERT(! kIsInput);
  163. CARLA_ASSERT(fBuffer != nullptr);
  164. CARLA_ASSERT(kProcessMode != PROCESS_MODE_SINGLE_CLIENT && kProcessMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  165. CARLA_ASSERT(type != kEngineControlEventTypeNull);
  166. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  167. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  168. if (kIsInput)
  169. return;
  170. if (fBuffer == nullptr)
  171. return;
  172. if (kProcessMode == PROCESS_MODE_SINGLE_CLIENT || kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  173. return;
  174. if (type == kEngineControlEventTypeNull)
  175. return;
  176. if (channel >= MAX_MIDI_CHANNELS)
  177. return;
  178. if (type == kEngineControlEventTypeParameter)
  179. {
  180. CARLA_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param));
  181. }
  182. for (uint32_t i=0; i < INTERNAL_EVENT_COUNT; ++i)
  183. {
  184. if (fBuffer[i].type != kEngineEventTypeNull)
  185. continue;
  186. fBuffer[i].type = kEngineEventTypeControl;
  187. fBuffer[i].time = time;
  188. fBuffer[i].channel = channel;
  189. fBuffer[i].ctrl.type = type;
  190. fBuffer[i].ctrl.param = param;
  191. fBuffer[i].ctrl.value = carla_fixValue<float>(0.0f, 1.0f, value);
  192. return;
  193. }
  194. carla_stderr2("CarlaEngineEventPort::writeControlEvent() - buffer full");
  195. }
  196. void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t* const data, const uint8_t size)
  197. {
  198. CARLA_ASSERT(! kIsInput);
  199. CARLA_ASSERT(fBuffer != nullptr);
  200. CARLA_ASSERT(kProcessMode != PROCESS_MODE_SINGLE_CLIENT && kProcessMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  201. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  202. CARLA_ASSERT(data != nullptr);
  203. CARLA_ASSERT(size > 0);
  204. if (kIsInput)
  205. return;
  206. if (fBuffer == nullptr)
  207. return;
  208. if (kProcessMode == PROCESS_MODE_SINGLE_CLIENT || kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  209. return;
  210. if (channel >= MAX_MIDI_CHANNELS)
  211. return;
  212. if (data == nullptr)
  213. return;
  214. if (size == 0 || size > 4)
  215. return;
  216. for (uint32_t i=0; i < INTERNAL_EVENT_COUNT; ++i)
  217. {
  218. if (fBuffer[i].type != kEngineEventTypeNull)
  219. continue;
  220. fBuffer[i].type = kEngineEventTypeMidi;
  221. fBuffer[i].time = time;
  222. fBuffer[i].channel = channel;
  223. fBuffer[i].midi.port = port;
  224. fBuffer[i].midi.size = size;
  225. carla_copy<uint8_t>(fBuffer[i].midi.data, data, size);
  226. // strip MIDI channel from 1st byte
  227. fBuffer[i].midi.data[0] = MIDI_GET_STATUS_FROM_DATA(fBuffer[i].midi.data);
  228. return;
  229. }
  230. carla_stderr2("CarlaEngineEventPort::writeMidiEvent() - buffer full");
  231. }
  232. // -------------------------------------------------------------------------------------------------------------------
  233. // Carla Engine client (Abstract)
  234. CarlaEngineClient::CarlaEngineClient(const EngineType engineType, const ProcessMode processMode)
  235. : kEngineType(engineType),
  236. kProcessMode(processMode),
  237. fActive(false),
  238. fLatency(0)
  239. {
  240. CARLA_ASSERT(engineType != kEngineTypeNull);
  241. carla_debug("CarlaEngineClient::CarlaEngineClient(%s, %s)", EngineType2Str(engineType), ProcessMode2Str(processMode));
  242. }
  243. CarlaEngineClient::~CarlaEngineClient()
  244. {
  245. CARLA_ASSERT(! fActive);
  246. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  247. }
  248. void CarlaEngineClient::activate()
  249. {
  250. CARLA_ASSERT(! fActive);
  251. carla_debug("CarlaEngineClient::activate()");
  252. fActive = true;
  253. }
  254. void CarlaEngineClient::deactivate()
  255. {
  256. CARLA_ASSERT(fActive);
  257. carla_debug("CarlaEngineClient::deactivate()");
  258. fActive = false;
  259. }
  260. bool CarlaEngineClient::isActive() const
  261. {
  262. carla_debug("CarlaEngineClient::isActive()");
  263. return fActive;
  264. }
  265. bool CarlaEngineClient::isOk() const
  266. {
  267. carla_debug("CarlaEngineClient::isOk()");
  268. return true;
  269. }
  270. uint32_t CarlaEngineClient::getLatency() const
  271. {
  272. return fLatency;
  273. }
  274. void CarlaEngineClient::setLatency(const uint32_t samples)
  275. {
  276. fLatency = samples;
  277. }
  278. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  279. {
  280. carla_debug("CarlaEngineClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput));
  281. switch (portType)
  282. {
  283. case kEnginePortTypeNull:
  284. break;
  285. case kEnginePortTypeAudio:
  286. return new CarlaEngineAudioPort(isInput, kProcessMode);
  287. case kEnginePortTypeEvent:
  288. return new CarlaEngineEventPort(isInput, kProcessMode);
  289. }
  290. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  291. return nullptr;
  292. }
  293. // -------------------------------------------------------------------------------------------------------------------
  294. // Carla Engine
  295. CarlaEngine::CarlaEngine()
  296. : fBufferSize(0),
  297. fSampleRate(0.0),
  298. kData(new CarlaEngineProtectedData(this))
  299. {
  300. carla_debug("CarlaEngine::CarlaEngine()");
  301. }
  302. CarlaEngine::~CarlaEngine()
  303. {
  304. carla_debug("CarlaEngine::~CarlaEngine()");
  305. delete kData;
  306. }
  307. // -----------------------------------------------------------------------
  308. // Helpers
  309. void doPluginIdle(CarlaEngineProtectedData* const kData, const bool unlock)
  310. {
  311. CARLA_ASSERT(kData->curPluginCount > 0);
  312. kData->nextAction.opcode = kEnginePostActionNull;
  313. if (unlock)
  314. kData->nextAction.mutex.unlock();
  315. }
  316. void doPluginRemove(CarlaEngineProtectedData* const kData, const bool unlock)
  317. {
  318. CARLA_ASSERT(kData->curPluginCount > 0);
  319. kData->curPluginCount--;
  320. const unsigned int id = kData->nextAction.pluginId;
  321. // reset current plugin
  322. kData->plugins[id].plugin = nullptr;
  323. CarlaPlugin* plugin;
  324. // move all plugins 1 spot backwards
  325. for (unsigned int i=id; i < kData->curPluginCount; ++i)
  326. {
  327. plugin = kData->plugins[i+1].plugin;
  328. CARLA_ASSERT(plugin != nullptr);
  329. if (plugin == nullptr)
  330. break;
  331. plugin->setId(i);
  332. kData->plugins[i].plugin = plugin;
  333. kData->plugins[i].insPeak[0] = 0.0f;
  334. kData->plugins[i].insPeak[1] = 0.0f;
  335. kData->plugins[i].outsPeak[0] = 0.0f;
  336. kData->plugins[i].outsPeak[1] = 0.0f;
  337. }
  338. kData->nextAction.opcode = kEnginePostActionNull;
  339. if (unlock)
  340. kData->nextAction.mutex.unlock();
  341. }
  342. void doPluginsSwitch(CarlaEngineProtectedData* const kData, const bool unlock)
  343. {
  344. CARLA_ASSERT(kData->curPluginCount >= 2);
  345. const unsigned int idA = kData->nextAction.pluginId;
  346. const unsigned int idB = kData->nextAction.value;
  347. CarlaPlugin* const tmp = kData->plugins[idA].plugin;
  348. kData->plugins[idA].plugin = kData->plugins[idB].plugin;
  349. kData->plugins[idB].plugin = tmp;
  350. kData->nextAction.opcode = kEnginePostActionNull;
  351. if (unlock)
  352. kData->nextAction.mutex.unlock();
  353. }
  354. const char* findDSSIGUI(const char* const filename, const char* const label)
  355. {
  356. QString guiFilename;
  357. guiFilename.clear();
  358. QString pluginDir(filename);
  359. pluginDir.resize(pluginDir.lastIndexOf("."));
  360. QString shortName = QFileInfo(pluginDir).baseName();
  361. QString checkLabel = QString(label);
  362. QString checkSName = shortName;
  363. if (! checkLabel.endsWith("_")) checkLabel += "_";
  364. if (! checkSName.endsWith("_")) checkSName += "_";
  365. QStringList guiFiles = QDir(pluginDir).entryList();
  366. foreach (const QString& gui, guiFiles)
  367. {
  368. if (gui.startsWith(checkLabel) || gui.startsWith(checkSName))
  369. {
  370. QFileInfo finalname(pluginDir + QDir::separator() + gui);
  371. guiFilename = finalname.absoluteFilePath();
  372. break;
  373. }
  374. }
  375. if (guiFilename.isEmpty())
  376. return nullptr;
  377. return carla_strdup(guiFilename.toUtf8().constData());
  378. }
  379. // -----------------------------------------------------------------------
  380. // Static values and calls
  381. unsigned int CarlaEngine::getDriverCount()
  382. {
  383. carla_debug("CarlaEngine::getDriverCount()");
  384. unsigned int count = 1; // JACK
  385. #ifdef WANT_RTAUDIO
  386. count += getRtAudioApiCount();
  387. #endif
  388. return count;
  389. }
  390. const char* CarlaEngine::getDriverName(unsigned int index)
  391. {
  392. carla_debug("CarlaEngine::getDriverName(%i)", index);
  393. if (index == 0)
  394. return "JACK";
  395. else
  396. index -= 1;
  397. #ifdef WANT_RTAUDIO
  398. if (index < getRtAudioApiCount())
  399. return getRtAudioApiName(index);
  400. #endif
  401. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
  402. return nullptr;
  403. }
  404. const char** CarlaEngine::getDriverDeviceNames(unsigned int index)
  405. {
  406. carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index);
  407. if (index == 0)
  408. return nullptr;
  409. else
  410. index -= 1;
  411. #ifdef WANT_RTAUDIO
  412. if (index < getRtAudioApiCount())
  413. return getRtAudioApiDeviceNames(index);
  414. #endif
  415. carla_stderr("CarlaEngine::getDriverDeviceNames(%i) - invalid index", index);
  416. return nullptr;
  417. }
  418. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  419. {
  420. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  421. if (std::strcmp(driverName, "JACK") == 0)
  422. return newJack();
  423. #ifdef WANT_RTAUDIO
  424. # ifdef __LINUX_ALSA__
  425. if (std::strcmp(driverName, "ALSA") == 0)
  426. return newRtAudio(RTAUDIO_LINUX_ALSA);
  427. # endif
  428. # ifdef __LINUX_PULSE__
  429. if (std::strcmp(driverName, "PulseAudio") == 0)
  430. return newRtAudio(RTAUDIO_LINUX_PULSE);
  431. # endif
  432. # ifdef __LINUX_OSS__
  433. if (std::strcmp(driverName, "OSS") == 0)
  434. return newRtAudio(RTAUDIO_LINUX_OSS);
  435. # endif
  436. # ifdef __UNIX_JACK__
  437. if (std::strncmp(driverName, "JACK ", 5) == 0)
  438. return newRtAudio(RTAUDIO_UNIX_JACK);
  439. # endif
  440. # ifdef __MACOSX_CORE__
  441. if (std::strcmp(driverName, "CoreAudio") == 0)
  442. return newRtAudio(RTAUDIO_MACOSX_CORE);
  443. # endif
  444. # ifdef __WINDOWS_ASIO__
  445. if (std::strcmp(driverName, "ASIO") == 0)
  446. return newRtAudio(RTAUDIO_WINDOWS_ASIO);
  447. # endif
  448. # ifdef __WINDOWS_DS__
  449. if (std::strcmp(driverName, "DirectSound") == 0)
  450. return newRtAudio(RTAUDIO_WINDOWS_DS);
  451. # endif
  452. #endif
  453. return nullptr;
  454. }
  455. // -----------------------------------------------------------------------
  456. // Maximum values
  457. unsigned int CarlaEngine::maxClientNameSize() const
  458. {
  459. return STR_MAX/2;
  460. }
  461. unsigned int CarlaEngine::maxPortNameSize() const
  462. {
  463. return STR_MAX;
  464. }
  465. unsigned int CarlaEngine::currentPluginCount() const
  466. {
  467. return kData->curPluginCount;
  468. }
  469. unsigned int CarlaEngine::maxPluginNumber() const
  470. {
  471. return kData->maxPluginNumber;
  472. }
  473. // -----------------------------------------------------------------------
  474. // Virtual, per-engine type calls
  475. bool CarlaEngine::init(const char* const clientName)
  476. {
  477. CARLA_ASSERT(kData->oscData == nullptr);
  478. CARLA_ASSERT(kData->plugins == nullptr);
  479. carla_debug("CarlaEngine::init(\"%s\")", clientName);
  480. CARLA_ASSERT(kData->bufEvent.in == nullptr);
  481. CARLA_ASSERT(kData->bufEvent.out == nullptr);
  482. fName = clientName;
  483. fName.toBasic();
  484. fTimeInfo.clear();
  485. kData->aboutToClose = false;
  486. kData->curPluginCount = 0;
  487. kData->maxPluginNumber = 0;
  488. switch (fOptions.processMode)
  489. {
  490. case PROCESS_MODE_SINGLE_CLIENT:
  491. case PROCESS_MODE_MULTIPLE_CLIENTS:
  492. kData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
  493. break;
  494. case PROCESS_MODE_CONTINUOUS_RACK:
  495. kData->maxPluginNumber = MAX_RACK_PLUGINS;
  496. kData->bufEvent.in = new EngineEvent[INTERNAL_EVENT_COUNT];
  497. kData->bufEvent.out = new EngineEvent[INTERNAL_EVENT_COUNT];
  498. break;
  499. case PROCESS_MODE_PATCHBAY:
  500. kData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
  501. break;
  502. case PROCESS_MODE_BRIDGE:
  503. kData->maxPluginNumber = 1;
  504. kData->bufEvent.in = new EngineEvent[INTERNAL_EVENT_COUNT];
  505. kData->bufEvent.out = new EngineEvent[INTERNAL_EVENT_COUNT];
  506. break;
  507. }
  508. kData->plugins = new EnginePluginData[kData->maxPluginNumber];
  509. kData->osc.init(clientName);
  510. #ifndef BUILD_BRIDGE
  511. kData->oscData = kData->osc.getControlData();
  512. #endif
  513. if (type() != kEngineTypePlugin)
  514. carla_setprocname(clientName);
  515. kData->nextAction.ready();
  516. kData->thread.startNow();
  517. return true;
  518. }
  519. bool CarlaEngine::close()
  520. {
  521. CARLA_ASSERT(kData->plugins != nullptr);
  522. carla_debug("CarlaEngine::close()");
  523. kData->thread.stopNow();
  524. kData->nextAction.ready();
  525. #ifndef BUILD_BRIDGE
  526. osc_send_control_exit();
  527. #endif
  528. kData->osc.close();
  529. kData->oscData = nullptr;
  530. kData->aboutToClose = true;
  531. kData->curPluginCount = 0;
  532. kData->maxPluginNumber = 0;
  533. if (kData->plugins != nullptr)
  534. {
  535. delete[] kData->plugins;
  536. kData->plugins = nullptr;
  537. }
  538. if (kData->bufEvent.in != nullptr)
  539. {
  540. delete[] kData->bufEvent.in;
  541. kData->bufEvent.in = nullptr;
  542. }
  543. if (kData->bufEvent.out != nullptr)
  544. {
  545. delete[] kData->bufEvent.out;
  546. kData->bufEvent.out = nullptr;
  547. }
  548. fName.clear();
  549. return true;
  550. }
  551. void CarlaEngine::idle()
  552. {
  553. CARLA_ASSERT(kData->plugins != nullptr);
  554. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  555. {
  556. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  557. if (plugin != nullptr && plugin->enabled())
  558. plugin->idleGui();
  559. }
  560. }
  561. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  562. {
  563. return new CarlaEngineClient(type(), fOptions.processMode);
  564. }
  565. // -----------------------------------------------------------------------
  566. // Plugin management
  567. 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)
  568. {
  569. CARLA_ASSERT(btype != BINARY_NONE);
  570. CARLA_ASSERT(ptype != PLUGIN_NONE);
  571. carla_debug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra);
  572. if (kData->curPluginCount == kData->maxPluginNumber)
  573. {
  574. setLastError("Maximum number of plugins reached");
  575. return false;
  576. }
  577. const unsigned int id = kData->curPluginCount;
  578. CarlaPlugin::Initializer init = {
  579. this,
  580. id,
  581. filename,
  582. name,
  583. label
  584. };
  585. CarlaPlugin* plugin = nullptr;
  586. #ifndef BUILD_BRIDGE
  587. const char* bridgeBinary;
  588. switch (btype)
  589. {
  590. case BINARY_POSIX32:
  591. bridgeBinary = fOptions.bridge_posix32.isNotEmpty() ? (const char*)fOptions.bridge_posix32 : nullptr;
  592. break;
  593. case BINARY_POSIX64:
  594. bridgeBinary = fOptions.bridge_posix64.isNotEmpty() ? (const char*)fOptions.bridge_posix64 : nullptr;
  595. break;
  596. case BINARY_WIN32:
  597. bridgeBinary = fOptions.bridge_win32.isNotEmpty() ? (const char*)fOptions.bridge_win32 : nullptr;
  598. break;
  599. case BINARY_WIN64:
  600. bridgeBinary = fOptions.bridge_win64.isNotEmpty() ? (const char*)fOptions.bridge_win64 : nullptr;
  601. break;
  602. default:
  603. bridgeBinary = nullptr;
  604. break;
  605. }
  606. #ifndef Q_OS_WIN
  607. if (btype == BINARY_NATIVE && fOptions.bridge_native.isNotEmpty())
  608. bridgeBinary = (const char*)fOptions.bridge_native;
  609. #endif
  610. if (bridgeBinary != nullptr && (btype != BINARY_NATIVE || fOptions.preferPluginBridges))
  611. {
  612. plugin = CarlaPlugin::newBridge(init, btype, ptype, bridgeBinary);
  613. }
  614. else
  615. #endif // BUILD_BRIDGE
  616. {
  617. switch (ptype)
  618. {
  619. case PLUGIN_NONE:
  620. break;
  621. case PLUGIN_INTERNAL:
  622. plugin = CarlaPlugin::newNative(init);
  623. break;
  624. case PLUGIN_LADSPA:
  625. plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra);
  626. break;
  627. case PLUGIN_DSSI:
  628. plugin = CarlaPlugin::newDSSI(init, (const char*)extra);
  629. break;
  630. case PLUGIN_LV2:
  631. plugin = CarlaPlugin::newLV2(init);
  632. break;
  633. case PLUGIN_VST:
  634. plugin = CarlaPlugin::newVST(init);
  635. break;
  636. case PLUGIN_VST3:
  637. plugin = CarlaPlugin::newVST3(init);
  638. break;
  639. case PLUGIN_GIG:
  640. plugin = CarlaPlugin::newGIG(init, (extra != nullptr));
  641. break;
  642. case PLUGIN_SF2:
  643. plugin = CarlaPlugin::newSF2(init, (extra != nullptr));
  644. break;
  645. case PLUGIN_SFZ:
  646. plugin = CarlaPlugin::newSFZ(init, (extra != nullptr));
  647. break;
  648. }
  649. }
  650. if (plugin == nullptr)
  651. return false;
  652. plugin->registerToOscClient();
  653. kData->plugins[id].plugin = plugin;
  654. kData->plugins[id].insPeak[0] = 0.0f;
  655. kData->plugins[id].insPeak[1] = 0.0f;
  656. kData->plugins[id].outsPeak[0] = 0.0f;
  657. kData->plugins[id].outsPeak[1] = 0.0f;
  658. kData->curPluginCount += 1;
  659. callback(CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->name());
  660. return true;
  661. }
  662. bool CarlaEngine::removePlugin(const unsigned int id)
  663. {
  664. CARLA_ASSERT(kData->curPluginCount > 0);
  665. CARLA_ASSERT(id < kData->curPluginCount);
  666. CARLA_ASSERT(kData->plugins != nullptr);
  667. carla_debug("CarlaEngine::removePlugin(%i)", id);
  668. if (kData->plugins == nullptr)
  669. {
  670. setLastError("Critical error: no plugins are currently loaded!");
  671. return false;
  672. }
  673. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  674. if (plugin == nullptr)
  675. {
  676. setLastError("Could not find plugin to remove");
  677. return false;
  678. }
  679. CARLA_ASSERT(plugin->id() == id);
  680. kData->thread.stopNow();
  681. kData->nextAction.pluginId = id;
  682. kData->nextAction.opcode = kEnginePostActionRemovePlugin;
  683. kData->nextAction.mutex.lock();
  684. if (isRunning())
  685. {
  686. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking START", id);
  687. // block wait for unlock on proccessing side
  688. kData->nextAction.mutex.lock();
  689. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking DONE", id);
  690. }
  691. else
  692. {
  693. doPluginRemove(kData, false);
  694. }
  695. #ifndef BUILD_BRIDGE
  696. if (isOscControlRegistered())
  697. osc_send_control_remove_plugin(id);
  698. #endif
  699. delete plugin;
  700. kData->nextAction.mutex.unlock();
  701. if (isRunning() && ! kData->aboutToClose)
  702. kData->thread.startNow();
  703. callback(CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  704. return true;
  705. }
  706. void CarlaEngine::removeAllPlugins()
  707. {
  708. carla_debug("CarlaEngine::removeAllPlugins() - START");
  709. kData->thread.stopNow();
  710. if (kData->curPluginCount > 0)
  711. {
  712. const unsigned int oldCount = kData->curPluginCount;
  713. kData->curPluginCount = 0;
  714. for (unsigned int i=0; i < oldCount; ++i)
  715. {
  716. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  717. CARLA_ASSERT(plugin != nullptr);
  718. kData->plugins[i].plugin = nullptr;
  719. if (plugin != nullptr)
  720. delete plugin;
  721. // clear this plugin
  722. kData->plugins[i].insPeak[0] = 0.0f;
  723. kData->plugins[i].insPeak[1] = 0.0f;
  724. kData->plugins[i].outsPeak[0] = 0.0f;
  725. kData->plugins[i].outsPeak[1] = 0.0f;
  726. }
  727. }
  728. if (isRunning() && ! kData->aboutToClose)
  729. kData->thread.startNow();
  730. carla_debug("CarlaEngine::removeAllPlugins() - END");
  731. }
  732. const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
  733. {
  734. CARLA_ASSERT(kData->curPluginCount > 0);
  735. CARLA_ASSERT(id < kData->curPluginCount);
  736. CARLA_ASSERT(kData->plugins != nullptr);
  737. CARLA_ASSERT(newName != nullptr);
  738. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  739. if (kData->plugins == nullptr)
  740. {
  741. setLastError("Critical error: no plugins are currently loaded!");
  742. return nullptr;
  743. }
  744. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  745. if (plugin == nullptr)
  746. {
  747. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  748. return nullptr;
  749. }
  750. CARLA_ASSERT(plugin->id() == id);
  751. if (const char* const name = getUniquePluginName(newName))
  752. {
  753. plugin->setName(name);
  754. return name;
  755. }
  756. return nullptr;
  757. }
  758. bool CarlaEngine::clonePlugin(const unsigned int id)
  759. {
  760. CARLA_ASSERT(kData->curPluginCount > 0);
  761. CARLA_ASSERT(id < kData->curPluginCount);
  762. CARLA_ASSERT(kData->plugins != nullptr);
  763. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  764. if (kData->plugins == nullptr)
  765. {
  766. setLastError("Critical error: no plugins are currently loaded!");
  767. return false;
  768. }
  769. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  770. if (plugin == nullptr)
  771. {
  772. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  773. return false;
  774. }
  775. CARLA_ASSERT(plugin->id() == id);
  776. const SaveState& saveState(plugin->getSaveState());
  777. char label[STR_MAX+1] = { '\0' };
  778. plugin->getLabel(label);
  779. BinaryType binaryType = BINARY_NATIVE;
  780. #ifndef BUILD_BRIDGE
  781. if (plugin->hints() & PLUGIN_IS_BRIDGE)
  782. binaryType = CarlaPluginGetBridgeBinaryType(plugin);
  783. #endif
  784. const unsigned int pluginsBefore(kData->curPluginCount);
  785. if (! addPlugin(binaryType, plugin->type(), plugin->filename(), plugin->name(), label, plugin->getExtraStuff()))
  786. return false;
  787. CARLA_ASSERT(pluginsBefore+1 == kData->curPluginCount);
  788. CarlaPlugin* const newPlugin = kData->plugins[kData->curPluginCount-1].plugin;
  789. CARLA_ASSERT(newPlugin != nullptr);
  790. newPlugin->loadSaveState(saveState);
  791. return true;
  792. }
  793. bool CarlaEngine::replacePlugin(const unsigned int id)
  794. {
  795. CARLA_ASSERT(kData->curPluginCount > 0);
  796. CARLA_ASSERT(id < kData->curPluginCount);
  797. CARLA_ASSERT(kData->plugins != nullptr);
  798. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  799. setLastError("Not implemented yet");
  800. return false;
  801. }
  802. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  803. {
  804. CARLA_ASSERT(kData->curPluginCount > 0);
  805. CARLA_ASSERT(idA < kData->curPluginCount);
  806. CARLA_ASSERT(idB < kData->curPluginCount);
  807. CARLA_ASSERT(kData->plugins != nullptr);
  808. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  809. if (kData->plugins == nullptr)
  810. {
  811. setLastError("Critical error: no plugins are currently loaded!");
  812. return false;
  813. }
  814. kData->thread.stopNow();
  815. kData->nextAction.pluginId = idA;
  816. kData->nextAction.value = idB;
  817. kData->nextAction.opcode = kEnginePostActionSwitchPlugins;
  818. kData->nextAction.mutex.lock();
  819. if (isRunning())
  820. {
  821. carla_stderr("CarlaEngine::switchPlugins(%i, %i) - switch blocking START", idA, idB);
  822. // block wait for unlock on proccessing side
  823. kData->nextAction.mutex.lock();
  824. carla_stderr("CarlaEngine::switchPlugins(%i, %i) - switch blocking DONE", idA, idB);
  825. }
  826. else
  827. {
  828. doPluginsSwitch(kData, false);
  829. }
  830. #ifndef BUILD_BRIDGE // TODO
  831. //if (isOscControlRegistered())
  832. // osc_send_control_remove_plugin(id);
  833. #endif
  834. kData->nextAction.mutex.unlock();
  835. if (isRunning() && ! kData->aboutToClose)
  836. kData->thread.startNow();
  837. return true;
  838. }
  839. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  840. {
  841. CARLA_ASSERT(kData->curPluginCount > 0);
  842. CARLA_ASSERT(id < kData->curPluginCount);
  843. CARLA_ASSERT(kData->plugins != nullptr);
  844. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, kData->curPluginCount);
  845. if (id < kData->curPluginCount && kData->plugins != nullptr)
  846. return kData->plugins[id].plugin;
  847. return nullptr;
  848. }
  849. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const
  850. {
  851. return kData->plugins[id].plugin;
  852. }
  853. const char* CarlaEngine::getUniquePluginName(const char* const name)
  854. {
  855. CARLA_ASSERT(kData->maxPluginNumber > 0);
  856. CARLA_ASSERT(kData->plugins != nullptr);
  857. CARLA_ASSERT(name != nullptr);
  858. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  859. static CarlaString sname;
  860. sname = name;
  861. if (sname.isEmpty() || kData->plugins == nullptr)
  862. {
  863. sname = "(No name)";
  864. return (const char*)sname;
  865. }
  866. sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  867. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  868. for (unsigned short i=0; i < kData->curPluginCount; ++i)
  869. {
  870. CARLA_ASSERT(kData->plugins[i].plugin);
  871. if (kData->plugins[i].plugin == nullptr)
  872. continue;
  873. // Check if unique name doesn't exist
  874. if (const char* const pluginName = kData->plugins[i].plugin->name())
  875. {
  876. if (sname != pluginName)
  877. continue;
  878. }
  879. // Check if string has already been modified
  880. {
  881. const size_t len = sname.length();
  882. // 1 digit, ex: " (2)"
  883. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  884. {
  885. int number = sname[len-2] - '0';
  886. if (number == 9)
  887. {
  888. // next number is 10, 2 digits
  889. sname.truncate(len-4);
  890. sname += " (10)";
  891. //sname.replace(" (9)", " (10)");
  892. }
  893. else
  894. sname[len-2] = char('0' + number + 1);
  895. continue;
  896. }
  897. // 2 digits, ex: " (11)"
  898. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  899. {
  900. char n2 = sname[len-2];
  901. char n3 = sname[len-3];
  902. if (n2 == '9')
  903. {
  904. n2 = '0';
  905. n3 += 1;
  906. }
  907. else
  908. n2 += 1;
  909. sname[len-2] = n2;
  910. sname[len-3] = n3;
  911. continue;
  912. }
  913. }
  914. // Modify string if not
  915. sname += " (2)";
  916. }
  917. return (const char*)sname;
  918. }
  919. // -----------------------------------------------------------------------
  920. // Project management
  921. bool CarlaEngine::loadFilename(const char* const filename)
  922. {
  923. CARLA_ASSERT(filename != nullptr);
  924. carla_debug("CarlaEngine::loadFilename(\"%s\")", filename);
  925. QFileInfo fileInfo(filename);
  926. if (! fileInfo.exists())
  927. {
  928. setLastError("File does not exist");
  929. return false;
  930. }
  931. if (! fileInfo.isFile())
  932. {
  933. setLastError("Not a file");
  934. return false;
  935. }
  936. if (! fileInfo.isReadable())
  937. {
  938. setLastError("File is not readable");
  939. return false;
  940. }
  941. CarlaString baseName(fileInfo.baseName().toUtf8().constData());
  942. CarlaString extension(fileInfo.suffix().toLower().toUtf8().constData());
  943. // -------------------------------------------------------------------
  944. if (extension == "carxp" || extension == "carxs")
  945. return loadProject(filename);
  946. // -------------------------------------------------------------------
  947. if (extension == "gig")
  948. return addPlugin(PLUGIN_GIG, filename, baseName, baseName);
  949. if (extension == "sf2")
  950. return addPlugin(PLUGIN_SF2, filename, baseName, baseName);
  951. if (extension == "sfz")
  952. return addPlugin(PLUGIN_SFZ, filename, baseName, baseName);
  953. // -------------------------------------------------------------------
  954. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  955. {
  956. #ifdef WANT_AUDIOFILE
  957. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  958. {
  959. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  960. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  961. return true;
  962. }
  963. return false;
  964. #else
  965. setLastError("This Carla build does not have Audio file support");
  966. return false;
  967. #endif
  968. }
  969. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  970. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  971. {
  972. #ifdef WANT_AUDIOFILE
  973. # ifdef HAVE_FFMPEG
  974. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  975. {
  976. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  977. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  978. return true;
  979. }
  980. return false;
  981. # else
  982. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  983. return false;
  984. # endif
  985. #else
  986. setLastError("This Carla build does not have Audio file support");
  987. return false;
  988. #endif
  989. }
  990. // -------------------------------------------------------------------
  991. if (extension == "mid" || extension == "midi")
  992. {
  993. #ifdef WANT_MIDIFILE
  994. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile"))
  995. {
  996. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  997. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  998. return true;
  999. }
  1000. return false;
  1001. #else
  1002. setLastError("This Carla build does not have MIDI file support");
  1003. return false;
  1004. #endif
  1005. }
  1006. // -------------------------------------------------------------------
  1007. // ZynAddSubFX
  1008. if (extension == "xmz" || extension == "xiz")
  1009. {
  1010. #ifdef WANT_ZYNADDSUBFX
  1011. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx"))
  1012. {
  1013. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  1014. plugin->setCustomData(CUSTOM_DATA_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  1015. return true;
  1016. }
  1017. return false;
  1018. #else
  1019. setLastError("This Carla build does not have ZynAddSubFX support");
  1020. return false;
  1021. #endif
  1022. }
  1023. // -------------------------------------------------------------------
  1024. setLastError("Unknown file extension");
  1025. return false;
  1026. }
  1027. bool CarlaEngine::loadProject(const char* const filename)
  1028. {
  1029. CARLA_ASSERT(filename != nullptr);
  1030. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1031. QFile file(filename);
  1032. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  1033. return false;
  1034. QDomDocument xml;
  1035. xml.setContent(file.readAll());
  1036. file.close();
  1037. QDomNode xmlNode(xml.documentElement());
  1038. if (xmlNode.toElement().tagName() != "CARLA-PROJECT" && xmlNode.toElement().tagName() != "CARLA-PRESET")
  1039. {
  1040. setLastError("Not a valid Carla project or preset file");
  1041. return false;
  1042. }
  1043. const bool isPreset(xmlNode.toElement().tagName() == "CARLA-PRESET");
  1044. QDomNode node(xmlNode.firstChild());
  1045. while (! node.isNull())
  1046. {
  1047. if (isPreset || node.toElement().tagName() == "Plugin")
  1048. {
  1049. const SaveState& saveState(getSaveStateDictFromXML(isPreset ? xmlNode : node));
  1050. CARLA_ASSERT(saveState.type != nullptr);
  1051. if (saveState.type == nullptr)
  1052. continue;
  1053. const void* extraStuff = nullptr;
  1054. if (std::strcmp(saveState.type, "DSSI") == 0)
  1055. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  1056. // TODO - proper find&load plugins
  1057. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  1058. {
  1059. if (CarlaPlugin* plugin = getPlugin(kData->curPluginCount-1))
  1060. plugin->loadSaveState(saveState);
  1061. }
  1062. }
  1063. if (isPreset)
  1064. break;
  1065. node = node.nextSibling();
  1066. }
  1067. return true;
  1068. }
  1069. bool CarlaEngine::saveProject(const char* const filename)
  1070. {
  1071. CARLA_ASSERT(filename != nullptr);
  1072. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1073. QFile file(filename);
  1074. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1075. return false;
  1076. QTextStream out(&file);
  1077. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1078. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1079. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  1080. bool firstPlugin = true;
  1081. char strBuf[STR_MAX+1];
  1082. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1083. {
  1084. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1085. if (plugin != nullptr && plugin->enabled())
  1086. {
  1087. if (! firstPlugin)
  1088. out << "\n";
  1089. plugin->getRealName(strBuf);
  1090. if (*strBuf != 0)
  1091. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1092. out << " <Plugin>\n";
  1093. out << getXMLFromSaveState(plugin->getSaveState());
  1094. out << " </Plugin>\n";
  1095. firstPlugin = false;
  1096. }
  1097. }
  1098. out << "</CARLA-PROJECT>\n";
  1099. file.close();
  1100. return true;
  1101. }
  1102. // -----------------------------------------------------------------------
  1103. // Information (peaks)
  1104. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  1105. {
  1106. CARLA_ASSERT(pluginId < kData->curPluginCount);
  1107. CARLA_ASSERT(id-1 < MAX_PEAKS);
  1108. if (id == 0 || id > MAX_PEAKS)
  1109. return 0.0f;
  1110. return kData->plugins[pluginId].insPeak[id-1];
  1111. }
  1112. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  1113. {
  1114. CARLA_ASSERT(pluginId < kData->curPluginCount);
  1115. CARLA_ASSERT(id-1 < MAX_PEAKS);
  1116. if (id == 0 || id > MAX_PEAKS)
  1117. return 0.0f;
  1118. return kData->plugins[pluginId].outsPeak[id-1];
  1119. }
  1120. // -----------------------------------------------------------------------
  1121. // Callback
  1122. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  1123. {
  1124. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  1125. if (kData->callback)
  1126. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1127. }
  1128. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  1129. {
  1130. CARLA_ASSERT(func != nullptr);
  1131. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1132. kData->callback = func;
  1133. kData->callbackPtr = ptr;
  1134. }
  1135. // -----------------------------------------------------------------------
  1136. // Patchbay
  1137. bool CarlaEngine::patchbayConnect(int, int)
  1138. {
  1139. setLastError("Unsupported operation");
  1140. return false;
  1141. }
  1142. bool CarlaEngine::patchbayDisconnect(int)
  1143. {
  1144. setLastError("Unsupported operation");
  1145. return false;
  1146. }
  1147. void CarlaEngine::patchbayRefresh()
  1148. {
  1149. // nothing
  1150. }
  1151. // -----------------------------------------------------------------------
  1152. // Transport
  1153. void CarlaEngine::transportPlay()
  1154. {
  1155. kData->time.playing = true;
  1156. }
  1157. void CarlaEngine::transportPause()
  1158. {
  1159. kData->time.playing = false;
  1160. }
  1161. void CarlaEngine::transportRelocate(const uint32_t frame)
  1162. {
  1163. kData->time.frame = frame;
  1164. }
  1165. // -----------------------------------------------------------------------
  1166. // Error handling
  1167. const char* CarlaEngine::getLastError() const
  1168. {
  1169. return (const char*)kData->lastError;
  1170. }
  1171. void CarlaEngine::setLastError(const char* const error)
  1172. {
  1173. kData->lastError = error;
  1174. }
  1175. void CarlaEngine::setAboutToClose()
  1176. {
  1177. carla_debug("CarlaEngine::setAboutToClose()");
  1178. kData->aboutToClose = true;
  1179. }
  1180. // -----------------------------------------------------------------------
  1181. // Global options
  1182. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  1183. if (isRunning()) \
  1184. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  1185. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  1186. {
  1187. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  1188. switch (option)
  1189. {
  1190. case OPTION_PROCESS_NAME:
  1191. carla_setprocname(valueStr);
  1192. break;
  1193. case OPTION_PROCESS_MODE:
  1194. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1195. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_BRIDGE)
  1196. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  1197. fOptions.processMode = static_cast<ProcessMode>(value);
  1198. break;
  1199. case OPTION_TRANSPORT_MODE:
  1200. // FIXME: Always enable JACK transport for now
  1201. #if 0
  1202. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_BRIDGE)
  1203. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1204. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  1205. #endif
  1206. break;
  1207. case OPTION_MAX_PARAMETERS:
  1208. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1209. if (value < 0)
  1210. return; // TODO error here
  1211. fOptions.maxParameters = static_cast<uint>(value);
  1212. break;
  1213. case OPTION_FORCE_STEREO:
  1214. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1215. fOptions.forceStereo = (value != 0);
  1216. break;
  1217. #ifdef WANT_DSSI
  1218. case OPTION_USE_DSSI_VST_CHUNKS:
  1219. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1220. fOptions.useDssiVstChunks = (value != 0);
  1221. break;
  1222. #endif
  1223. case OPTION_PREFER_PLUGIN_BRIDGES:
  1224. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1225. fOptions.preferPluginBridges = (value != 0);
  1226. break;
  1227. case OPTION_PREFER_UI_BRIDGES:
  1228. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1229. fOptions.preferUiBridges = (value != 0);
  1230. break;
  1231. case OPTION_OSC_UI_TIMEOUT:
  1232. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1233. fOptions.oscUiTimeout = static_cast<uint>(value);
  1234. break;
  1235. case OPTION_JACK_AUTOCONNECT:
  1236. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1237. fOptions.jackAutoConnect = (value != 0);
  1238. break;
  1239. case OPTION_JACK_TIMEMASTER:
  1240. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1241. fOptions.jackTimeMaster = (value != 0);
  1242. break;
  1243. #ifdef WANT_RTAUDIO
  1244. case OPTION_RTAUDIO_BUFFER_SIZE:
  1245. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1246. fOptions.rtaudioBufferSize = static_cast<uint>(value);
  1247. break;
  1248. case OPTION_RTAUDIO_SAMPLE_RATE:
  1249. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1250. fOptions.rtaudioSampleRate = static_cast<uint>(value);
  1251. break;
  1252. case OPTION_RTAUDIO_DEVICE:
  1253. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1254. fOptions.rtaudioDevice = valueStr;
  1255. break;
  1256. #endif
  1257. case OPTION_PATH_RESOURCES:
  1258. fOptions.resourceDir = valueStr;
  1259. break;
  1260. #ifndef BUILD_BRIDGE
  1261. case OPTION_PATH_BRIDGE_NATIVE:
  1262. fOptions.bridge_native = valueStr;
  1263. break;
  1264. case OPTION_PATH_BRIDGE_POSIX32:
  1265. fOptions.bridge_posix32 = valueStr;
  1266. break;
  1267. case OPTION_PATH_BRIDGE_POSIX64:
  1268. fOptions.bridge_posix64 = valueStr;
  1269. break;
  1270. case OPTION_PATH_BRIDGE_WIN32:
  1271. fOptions.bridge_win32 = valueStr;
  1272. break;
  1273. case OPTION_PATH_BRIDGE_WIN64:
  1274. fOptions.bridge_win64 = valueStr;
  1275. break;
  1276. #endif
  1277. #ifdef WANT_LV2
  1278. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1279. fOptions.bridge_lv2Gtk2 = valueStr;
  1280. break;
  1281. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1282. fOptions.bridge_lv2Gtk3 = valueStr;
  1283. break;
  1284. case OPTION_PATH_BRIDGE_LV2_QT4:
  1285. fOptions.bridge_lv2Qt4 = valueStr;
  1286. break;
  1287. case OPTION_PATH_BRIDGE_LV2_QT5:
  1288. fOptions.bridge_lv2Qt5 = valueStr;
  1289. break;
  1290. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1291. fOptions.bridge_lv2Cocoa = valueStr;
  1292. break;
  1293. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1294. fOptions.bridge_lv2Win = valueStr;
  1295. break;
  1296. case OPTION_PATH_BRIDGE_LV2_X11:
  1297. fOptions.bridge_lv2X11 = valueStr;
  1298. break;
  1299. #endif
  1300. #ifdef WANT_VST
  1301. case OPTION_PATH_BRIDGE_VST_COCOA:
  1302. fOptions.bridge_vstCocoa = valueStr;
  1303. break;
  1304. case OPTION_PATH_BRIDGE_VST_HWND:
  1305. fOptions.bridge_vstHWND = valueStr;
  1306. break;
  1307. case OPTION_PATH_BRIDGE_VST_X11:
  1308. fOptions.bridge_vstX11 = valueStr;
  1309. break;
  1310. #endif
  1311. }
  1312. }
  1313. // -----------------------------------------------------------------------
  1314. // OSC Stuff
  1315. #ifdef BUILD_BRIDGE
  1316. bool CarlaEngine::isOscBridgeRegistered() const
  1317. {
  1318. return (kData->oscData != nullptr);
  1319. }
  1320. #else
  1321. bool CarlaEngine::isOscControlRegistered() const
  1322. {
  1323. return kData->osc.isControlRegistered();
  1324. }
  1325. #endif
  1326. void CarlaEngine::idleOsc()
  1327. {
  1328. kData->osc.idle();
  1329. }
  1330. const char* CarlaEngine::getOscServerPathTCP() const
  1331. {
  1332. return kData->osc.getServerPathTCP();
  1333. }
  1334. const char* CarlaEngine::getOscServerPathUDP() const
  1335. {
  1336. return kData->osc.getServerPathUDP();
  1337. }
  1338. #ifdef BUILD_BRIDGE
  1339. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1340. {
  1341. kData->oscData = oscData;
  1342. }
  1343. #endif
  1344. // -----------------------------------------------------------------------
  1345. // protected calls
  1346. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1347. {
  1348. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1349. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1350. {
  1351. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1352. if (plugin != nullptr && plugin->enabled())
  1353. plugin->bufferSizeChanged(newBufferSize);
  1354. }
  1355. callback(CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1356. }
  1357. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1358. {
  1359. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1360. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1361. {
  1362. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1363. if (plugin != nullptr && plugin->enabled())
  1364. plugin->sampleRateChanged(newSampleRate);
  1365. }
  1366. callback(CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, newSampleRate, nullptr);
  1367. }
  1368. void CarlaEngine::proccessPendingEvents()
  1369. {
  1370. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1371. switch (kData->nextAction.opcode)
  1372. {
  1373. case kEnginePostActionNull:
  1374. break;
  1375. case kEnginePostActionIdle:
  1376. doPluginIdle(kData, true);
  1377. break;
  1378. case kEnginePostActionRemovePlugin:
  1379. doPluginRemove(kData, true);
  1380. break;
  1381. case kEnginePostActionSwitchPlugins:
  1382. doPluginsSwitch(kData, true);
  1383. break;
  1384. }
  1385. if (kData->time.playing)
  1386. kData->time.frame += fBufferSize;
  1387. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1388. {
  1389. fTimeInfo.playing = kData->time.playing;
  1390. fTimeInfo.frame = kData->time.frame;
  1391. }
  1392. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1393. {
  1394. // TODO - peak values?
  1395. }
  1396. }
  1397. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS])
  1398. {
  1399. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1400. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1401. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1402. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1403. }
  1404. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const
  1405. {
  1406. return isInput ? kData->bufEvent.in : kData->bufEvent.out;
  1407. }
  1408. #ifndef BUILD_BRIDGE
  1409. void setValueIfHigher(float& value, const float& compare)
  1410. {
  1411. if (value < compare)
  1412. value = compare;
  1413. }
  1414. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1415. {
  1416. CARLA_ASSERT(kData->bufEvent.in != nullptr);
  1417. CARLA_ASSERT(kData->bufEvent.out != nullptr);
  1418. // initialize outputs (zero)
  1419. carla_zeroFloat(outBuf[0], frames);
  1420. carla_zeroFloat(outBuf[1], frames);
  1421. carla_zeroMem(kData->bufEvent.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1422. bool processed = false;
  1423. // process plugins
  1424. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1425. {
  1426. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1427. if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock())
  1428. continue;
  1429. if (processed)
  1430. {
  1431. // initialize inputs (from previous outputs)
  1432. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1433. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1434. std::memcpy(kData->bufEvent.in, kData->bufEvent.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1435. // initialize outputs (zero)
  1436. carla_zeroFloat(outBuf[0], frames);
  1437. carla_zeroFloat(outBuf[1], frames);
  1438. carla_zeroMem(kData->bufEvent.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1439. }
  1440. // process
  1441. plugin->initBuffers();
  1442. plugin->process(inBuf, outBuf, frames);
  1443. plugin->unlock();
  1444. #if 0
  1445. // if plugin has no audio inputs, add previous buffers
  1446. if (plugin->audioInCount() == 0)
  1447. {
  1448. for (uint32_t j=0; j < frames; ++j)
  1449. {
  1450. outBuf[0][j] += inBuf[0][j];
  1451. outBuf[1][j] += inBuf[1][j];
  1452. }
  1453. }
  1454. // if plugin has no midi output, add previous events
  1455. if (plugin->midiOutCount() == 0)
  1456. {
  1457. for (uint32_t j=0, k=0; j < frames; ++j)
  1458. {
  1459. }
  1460. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1461. }
  1462. #endif
  1463. // set peaks
  1464. {
  1465. float inPeak1 = 0.0f;
  1466. float inPeak2 = 0.0f;
  1467. float outPeak1 = 0.0f;
  1468. float outPeak2 = 0.0f;
  1469. for (uint32_t k=0; k < frames; ++k)
  1470. {
  1471. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1472. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1473. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1474. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1475. }
  1476. kData->plugins[i].insPeak[0] = inPeak1;
  1477. kData->plugins[i].insPeak[1] = inPeak2;
  1478. kData->plugins[i].outsPeak[0] = outPeak1;
  1479. kData->plugins[i].outsPeak[1] = outPeak2;
  1480. }
  1481. processed = true;
  1482. }
  1483. }
  1484. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1485. {
  1486. // TODO
  1487. return;
  1488. // unused, for now
  1489. (void)inBuf;
  1490. (void)outBuf;
  1491. (void)bufCount;
  1492. (void)frames;
  1493. }
  1494. #endif
  1495. // -------------------------------------------------------------------------------------------------------------------
  1496. // Carla Engine OSC stuff
  1497. #ifndef BUILD_BRIDGE
  1498. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1499. {
  1500. CARLA_ASSERT(kData->oscData != nullptr);
  1501. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1502. CARLA_ASSERT(pluginName != nullptr);
  1503. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1504. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1505. {
  1506. char targetPath[std::strlen(kData->oscData->path)+18];
  1507. std::strcpy(targetPath, kData->oscData->path);
  1508. std::strcat(targetPath, "/add_plugin_start");
  1509. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1510. }
  1511. }
  1512. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1513. {
  1514. CARLA_ASSERT(kData->oscData != nullptr);
  1515. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1516. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1517. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1518. {
  1519. char targetPath[std::strlen(kData->oscData->path)+16];
  1520. std::strcpy(targetPath, kData->oscData->path);
  1521. std::strcat(targetPath, "/add_plugin_end");
  1522. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1523. }
  1524. }
  1525. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1526. {
  1527. CARLA_ASSERT(kData->oscData != nullptr);
  1528. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->curPluginCount));
  1529. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1530. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1531. {
  1532. char targetPath[std::strlen(kData->oscData->path)+15];
  1533. std::strcpy(targetPath, kData->oscData->path);
  1534. std::strcat(targetPath, "/remove_plugin");
  1535. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1536. }
  1537. }
  1538. 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)
  1539. {
  1540. CARLA_ASSERT(kData->oscData != nullptr);
  1541. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1542. CARLA_ASSERT(type != PLUGIN_NONE);
  1543. CARLA_ASSERT(realName != nullptr);
  1544. CARLA_ASSERT(label != nullptr);
  1545. CARLA_ASSERT(maker != nullptr);
  1546. CARLA_ASSERT(copyright != nullptr);
  1547. carla_debug("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);
  1548. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1549. {
  1550. char targetPath[std::strlen(kData->oscData->path)+17];
  1551. std::strcpy(targetPath, kData->oscData->path);
  1552. std::strcat(targetPath, "/set_plugin_data");
  1553. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1554. }
  1555. }
  1556. 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)
  1557. {
  1558. CARLA_ASSERT(kData->oscData != nullptr);
  1559. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1560. carla_debug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1561. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1562. {
  1563. char targetPath[std::strlen(kData->oscData->path)+18];
  1564. std::strcpy(targetPath, kData->oscData->path);
  1565. std::strcat(targetPath, "/set_plugin_ports");
  1566. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1567. }
  1568. }
  1569. 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 float current)
  1570. {
  1571. CARLA_ASSERT(kData->oscData != nullptr);
  1572. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1573. CARLA_ASSERT(index >= 0);
  1574. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1575. CARLA_ASSERT(name != nullptr);
  1576. CARLA_ASSERT(label != nullptr);
  1577. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %f)", pluginId, index, type, hints, name, label, current);
  1578. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1579. {
  1580. char targetPath[std::strlen(kData->oscData->path)+20];
  1581. std::strcpy(targetPath, kData->oscData->path);
  1582. std::strcat(targetPath, "/set_parameter_data");
  1583. lo_send(kData->oscData->target, targetPath, "iiiissf", pluginId, index, type, hints, name, label, current);
  1584. }
  1585. }
  1586. void CarlaEngine::osc_send_control_set_parameter_ranges(const int32_t pluginId, const int32_t index, const float min, const float max, const float def, const float step, const float stepSmall, const float stepLarge)
  1587. {
  1588. CARLA_ASSERT(kData->oscData != nullptr);
  1589. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1590. CARLA_ASSERT(index >= 0);
  1591. CARLA_ASSERT(min < max);
  1592. carla_debug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %f, %f, %f, %f, %f, %f)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1593. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1594. {
  1595. char targetPath[std::strlen(kData->oscData->path)+22];
  1596. std::strcpy(targetPath, kData->oscData->path);
  1597. std::strcat(targetPath, "/set_parameter_ranges");
  1598. lo_send(kData->oscData->target, targetPath, "iiffffff", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1599. }
  1600. }
  1601. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1602. {
  1603. CARLA_ASSERT(kData->oscData != nullptr);
  1604. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1605. CARLA_ASSERT(index >= 0);
  1606. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1607. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1608. {
  1609. char targetPath[std::strlen(kData->oscData->path)+23];
  1610. std::strcpy(targetPath, kData->oscData->path);
  1611. std::strcat(targetPath, "/set_parameter_midi_cc");
  1612. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1613. }
  1614. }
  1615. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1616. {
  1617. CARLA_ASSERT(kData->oscData != nullptr);
  1618. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1619. CARLA_ASSERT(index >= 0);
  1620. CARLA_ASSERT(channel >= 0 && channel < 16);
  1621. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1622. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1623. {
  1624. char targetPath[std::strlen(kData->oscData->path)+28];
  1625. std::strcpy(targetPath, kData->oscData->path);
  1626. std::strcat(targetPath, "/set_parameter_midi_channel");
  1627. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1628. }
  1629. }
  1630. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1631. {
  1632. CARLA_ASSERT(kData->oscData != nullptr);
  1633. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1634. #if DEBUG
  1635. if (index < 0)
  1636. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %f)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1637. else
  1638. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %f)", pluginId, index, value);
  1639. #endif
  1640. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1641. {
  1642. char targetPath[std::strlen(kData->oscData->path)+21];
  1643. std::strcpy(targetPath, kData->oscData->path);
  1644. std::strcat(targetPath, "/set_parameter_value");
  1645. lo_send(kData->oscData->target, targetPath, "iif", pluginId, index, value);
  1646. }
  1647. }
  1648. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1649. {
  1650. CARLA_ASSERT(kData->oscData != nullptr);
  1651. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1652. CARLA_ASSERT(index >= 0);
  1653. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  1654. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1655. {
  1656. char targetPath[std::strlen(kData->oscData->path)+19];
  1657. std::strcpy(targetPath, kData->oscData->path);
  1658. std::strcat(targetPath, "/set_default_value");
  1659. lo_send(kData->oscData->target, targetPath, "iif", pluginId, index, value);
  1660. }
  1661. }
  1662. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1663. {
  1664. CARLA_ASSERT(kData->oscData != nullptr);
  1665. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1666. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1667. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1668. {
  1669. char targetPath[std::strlen(kData->oscData->path)+13];
  1670. std::strcpy(targetPath, kData->oscData->path);
  1671. std::strcat(targetPath, "/set_program");
  1672. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1673. }
  1674. }
  1675. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1676. {
  1677. CARLA_ASSERT(kData->oscData != nullptr);
  1678. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1679. CARLA_ASSERT(count >= 0);
  1680. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1681. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1682. {
  1683. char targetPath[std::strlen(kData->oscData->path)+19];
  1684. std::strcpy(targetPath, kData->oscData->path);
  1685. std::strcat(targetPath, "/set_program_count");
  1686. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1687. }
  1688. }
  1689. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1690. {
  1691. CARLA_ASSERT(kData->oscData != nullptr);
  1692. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1693. CARLA_ASSERT(index >= 0);
  1694. CARLA_ASSERT(name != nullptr);
  1695. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1696. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1697. {
  1698. char targetPath[std::strlen(kData->oscData->path)+18];
  1699. std::strcpy(targetPath, kData->oscData->path);
  1700. std::strcat(targetPath, "/set_program_name");
  1701. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1702. }
  1703. }
  1704. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1705. {
  1706. CARLA_ASSERT(kData->oscData != nullptr);
  1707. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1708. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1709. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1710. {
  1711. char targetPath[std::strlen(kData->oscData->path)+18];
  1712. std::strcpy(targetPath, kData->oscData->path);
  1713. std::strcat(targetPath, "/set_midi_program");
  1714. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1715. }
  1716. }
  1717. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1718. {
  1719. CARLA_ASSERT(kData->oscData != nullptr);
  1720. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1721. CARLA_ASSERT(count >= 0);
  1722. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1723. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1724. {
  1725. char targetPath[std::strlen(kData->oscData->path)+24];
  1726. std::strcpy(targetPath, kData->oscData->path);
  1727. std::strcat(targetPath, "/set_midi_program_count");
  1728. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1729. }
  1730. }
  1731. 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)
  1732. {
  1733. CARLA_ASSERT(kData->oscData != nullptr);
  1734. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1735. CARLA_ASSERT(index >= 0);
  1736. CARLA_ASSERT(bank >= 0);
  1737. CARLA_ASSERT(program >= 0);
  1738. CARLA_ASSERT(name != nullptr);
  1739. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1740. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1741. {
  1742. char targetPath[std::strlen(kData->oscData->path)+23];
  1743. std::strcpy(targetPath, kData->oscData->path);
  1744. std::strcat(targetPath, "/set_midi_program_data");
  1745. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1746. }
  1747. }
  1748. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1749. {
  1750. CARLA_ASSERT(kData->oscData != nullptr);
  1751. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->curPluginCount));
  1752. CARLA_ASSERT(channel >= 0 && channel < MAX_MIDI_CHANNELS);
  1753. CARLA_ASSERT(note >= 0 && note < MAX_MIDI_NOTE);
  1754. CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE);
  1755. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1756. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1757. {
  1758. char targetPath[std::strlen(kData->oscData->path)+9];
  1759. std::strcpy(targetPath, kData->oscData->path);
  1760. std::strcat(targetPath, "/note_on");
  1761. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1762. }
  1763. }
  1764. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1765. {
  1766. CARLA_ASSERT(kData->oscData != nullptr);
  1767. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->curPluginCount));
  1768. CARLA_ASSERT(channel >= 0 && channel < MAX_MIDI_CHANNELS);
  1769. CARLA_ASSERT(note >= 0 && note < MAX_MIDI_NOTE);
  1770. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1771. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1772. {
  1773. char targetPath[std::strlen(kData->oscData->path)+10];
  1774. std::strcpy(targetPath, kData->oscData->path);
  1775. std::strcat(targetPath, "/note_off");
  1776. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1777. }
  1778. }
  1779. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1780. {
  1781. CARLA_ASSERT(kData->oscData != nullptr);
  1782. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->curPluginCount));
  1783. const EnginePluginData& pData = kData->plugins[pluginId];
  1784. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1785. {
  1786. char targetPath[std::strlen(kData->oscData->path)+22];
  1787. std::strcpy(targetPath, kData->oscData->path);
  1788. std::strcat(targetPath, "/set_peaks");
  1789. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1790. }
  1791. }
  1792. void CarlaEngine::osc_send_control_exit()
  1793. {
  1794. CARLA_ASSERT(kData->oscData != nullptr);
  1795. carla_debug("CarlaEngine::osc_send_control_exit()");
  1796. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1797. {
  1798. char targetPath[std::strlen(kData->oscData->path)+6];
  1799. std::strcpy(targetPath, kData->oscData->path);
  1800. std::strcat(targetPath, "/exit");
  1801. lo_send(kData->oscData->target, targetPath, "");
  1802. }
  1803. }
  1804. #else
  1805. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1806. {
  1807. CARLA_ASSERT(kData->oscData != nullptr);
  1808. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1809. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1810. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1811. {
  1812. char targetPath[std::strlen(kData->oscData->path)+20];
  1813. std::strcpy(targetPath, kData->oscData->path);
  1814. std::strcat(targetPath, "/bridge_audio_count");
  1815. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1816. }
  1817. }
  1818. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1819. {
  1820. CARLA_ASSERT(kData->oscData != nullptr);
  1821. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1822. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1823. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1824. {
  1825. char targetPath[std::strlen(kData->oscData->path)+19];
  1826. std::strcpy(targetPath, kData->oscData->path);
  1827. std::strcat(targetPath, "/bridge_midi_count");
  1828. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1829. }
  1830. }
  1831. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1832. {
  1833. CARLA_ASSERT(kData->oscData != nullptr);
  1834. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1835. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1836. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1837. {
  1838. char targetPath[std::strlen(kData->oscData->path)+24];
  1839. std::strcpy(targetPath, kData->oscData->path);
  1840. std::strcat(targetPath, "/bridge_parameter_count");
  1841. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1842. }
  1843. }
  1844. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1845. {
  1846. CARLA_ASSERT(kData->oscData != nullptr);
  1847. CARLA_ASSERT(count >= 0);
  1848. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1849. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1850. {
  1851. char targetPath[std::strlen(kData->oscData->path)+22];
  1852. std::strcpy(targetPath, kData->oscData->path);
  1853. std::strcat(targetPath, "/bridge_program_count");
  1854. lo_send(kData->oscData->target, targetPath, "i", count);
  1855. }
  1856. }
  1857. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1858. {
  1859. CARLA_ASSERT(kData->oscData != nullptr);
  1860. CARLA_ASSERT(count >= 0);
  1861. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1862. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1863. {
  1864. char targetPath[std::strlen(kData->oscData->path)+27];
  1865. std::strcpy(targetPath, kData->oscData->path);
  1866. std::strcat(targetPath, "/bridge_midi_program_count");
  1867. lo_send(kData->oscData->target, targetPath, "i", count);
  1868. }
  1869. }
  1870. 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)
  1871. {
  1872. CARLA_ASSERT(kData->oscData != nullptr);
  1873. CARLA_ASSERT(name != nullptr);
  1874. CARLA_ASSERT(label != nullptr);
  1875. CARLA_ASSERT(maker != nullptr);
  1876. CARLA_ASSERT(copyright != nullptr);
  1877. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1878. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1879. {
  1880. char targetPath[std::strlen(kData->oscData->path)+20];
  1881. std::strcpy(targetPath, kData->oscData->path);
  1882. std::strcat(targetPath, "/bridge_plugin_info");
  1883. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1884. }
  1885. }
  1886. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1887. {
  1888. CARLA_ASSERT(kData->oscData != nullptr);
  1889. CARLA_ASSERT(name != nullptr);
  1890. CARLA_ASSERT(unit != nullptr);
  1891. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1892. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1893. {
  1894. char targetPath[std::strlen(kData->oscData->path)+23];
  1895. std::strcpy(targetPath, kData->oscData->path);
  1896. std::strcat(targetPath, "/bridge_parameter_info");
  1897. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1898. }
  1899. }
  1900. 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)
  1901. {
  1902. CARLA_ASSERT(kData->oscData != nullptr);
  1903. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1904. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1905. {
  1906. char targetPath[std::strlen(kData->oscData->path)+23];
  1907. std::strcpy(targetPath, kData->oscData->path);
  1908. std::strcat(targetPath, "/bridge_parameter_data");
  1909. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1910. }
  1911. }
  1912. void CarlaEngine::osc_send_bridge_parameter_ranges(const int32_t index, const float def, const float min, const float max, const float step, const float stepSmall, const float stepLarge)
  1913. {
  1914. CARLA_ASSERT(kData->oscData != nullptr);
  1915. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %f, %f, %f, %f, %f, %f)", index, def, min, max, step, stepSmall, stepLarge);
  1916. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1917. {
  1918. char targetPath[std::strlen(kData->oscData->path)+25];
  1919. std::strcpy(targetPath, kData->oscData->path);
  1920. std::strcat(targetPath, "/bridge_parameter_ranges");
  1921. lo_send(kData->oscData->target, targetPath, "iffffff", index, def, min, max, step, stepSmall, stepLarge);
  1922. }
  1923. }
  1924. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1925. {
  1926. CARLA_ASSERT(kData->oscData != nullptr);
  1927. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1928. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1929. {
  1930. char targetPath[std::strlen(kData->oscData->path)+21];
  1931. std::strcpy(targetPath, kData->oscData->path);
  1932. std::strcat(targetPath, "/bridge_program_info");
  1933. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1934. }
  1935. }
  1936. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1937. {
  1938. CARLA_ASSERT(kData->oscData != nullptr);
  1939. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1940. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1941. {
  1942. char targetPath[std::strlen(kData->oscData->path)+26];
  1943. std::strcpy(targetPath, kData->oscData->path);
  1944. std::strcat(targetPath, "/bridge_midi_program_info");
  1945. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1946. }
  1947. }
  1948. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1949. {
  1950. CARLA_ASSERT(kData->oscData != nullptr);
  1951. CARLA_ASSERT(key != nullptr);
  1952. CARLA_ASSERT(value != nullptr);
  1953. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1954. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1955. {
  1956. char targetPath[std::strlen(kData->oscData->path)+18];
  1957. std::strcpy(targetPath, kData->oscData->path);
  1958. std::strcat(targetPath, "/bridge_configure");
  1959. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1960. }
  1961. }
  1962. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1963. {
  1964. CARLA_ASSERT(kData->oscData != nullptr);
  1965. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %f)", index, value);
  1966. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1967. {
  1968. char targetPath[std::strlen(kData->oscData->path)+28];
  1969. std::strcpy(targetPath, kData->oscData->path);
  1970. std::strcat(targetPath, "/bridge_set_parameter_value");
  1971. lo_send(kData->oscData->target, targetPath, "if", index, value);
  1972. }
  1973. }
  1974. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1975. {
  1976. CARLA_ASSERT(kData->oscData != nullptr);
  1977. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %f)", index, value);
  1978. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1979. {
  1980. char targetPath[std::strlen(kData->oscData->path)+26];
  1981. std::strcpy(targetPath, kData->oscData->path);
  1982. std::strcat(targetPath, "/bridge_set_default_value");
  1983. lo_send(kData->oscData->target, targetPath, "if", index, value);
  1984. }
  1985. }
  1986. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1987. {
  1988. CARLA_ASSERT(kData->oscData != nullptr);
  1989. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1990. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1991. {
  1992. char targetPath[std::strlen(kData->oscData->path)+20];
  1993. std::strcpy(targetPath, kData->oscData->path);
  1994. std::strcat(targetPath, "/bridge_set_program");
  1995. lo_send(kData->oscData->target, targetPath, "i", index);
  1996. }
  1997. }
  1998. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1999. {
  2000. CARLA_ASSERT(kData->oscData != nullptr);
  2001. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  2002. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  2003. {
  2004. char targetPath[std::strlen(kData->oscData->path)+25];
  2005. std::strcpy(targetPath, kData->oscData->path);
  2006. std::strcat(targetPath, "/bridge_set_midi_program");
  2007. lo_send(kData->oscData->target, targetPath, "i", index);
  2008. }
  2009. }
  2010. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  2011. {
  2012. CARLA_ASSERT(kData->oscData != nullptr);
  2013. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  2014. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  2015. {
  2016. char targetPath[std::strlen(kData->oscData->path)+24];
  2017. std::strcpy(targetPath, kData->oscData->path);
  2018. std::strcat(targetPath, "/bridge_set_custom_data");
  2019. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  2020. }
  2021. }
  2022. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  2023. {
  2024. CARLA_ASSERT(kData->oscData != nullptr);
  2025. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  2026. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  2027. {
  2028. char targetPath[std::strlen(kData->oscData->path)+23];
  2029. std::strcpy(targetPath, kData->oscData->path);
  2030. std::strcat(targetPath, "/bridge_set_chunk_data");
  2031. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  2032. }
  2033. }
  2034. #endif
  2035. CARLA_BACKEND_END_NAMESPACE