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.

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