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.

2527 lines
81KB

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