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.

2515 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_GIG:
  645. plugin = CarlaPlugin::newGIG(init, (extra != nullptr));
  646. break;
  647. case PLUGIN_SF2:
  648. plugin = CarlaPlugin::newSF2(init, (extra != nullptr));
  649. break;
  650. case PLUGIN_SFZ:
  651. plugin = CarlaPlugin::newSFZ(init, (extra != nullptr));
  652. break;
  653. }
  654. }
  655. if (plugin == nullptr)
  656. return false;
  657. plugin->registerToOscClient();
  658. pData->plugins[id].plugin = plugin;
  659. pData->plugins[id].insPeak[0] = 0.0f;
  660. pData->plugins[id].insPeak[1] = 0.0f;
  661. pData->plugins[id].outsPeak[0] = 0.0f;
  662. pData->plugins[id].outsPeak[1] = 0.0f;
  663. ++pData->curPluginCount;
  664. callback(CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
  665. return true;
  666. }
  667. bool CarlaEngine::removePlugin(const unsigned int id)
  668. {
  669. CARLA_ASSERT(pData->curPluginCount != 0);
  670. CARLA_ASSERT(id < pData->curPluginCount);
  671. CARLA_ASSERT(pData->plugins != nullptr);
  672. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull);
  673. carla_debug("CarlaEngine::removePlugin(%i)", id);
  674. if (pData->plugins == nullptr || pData->curPluginCount == 0)
  675. {
  676. setLastError("Critical error: no plugins are currently loaded!");
  677. return false;
  678. }
  679. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  680. if (plugin == nullptr)
  681. {
  682. setLastError("Could not find plugin to remove");
  683. return false;
  684. }
  685. CARLA_ASSERT(plugin->getId() == id);
  686. pData->thread.stopNow();
  687. const bool lockWait(isRunning() && fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  688. const CarlaEngineProtectedData::ScopedPluginAction spa(pData, kEnginePostActionRemovePlugin, id, 0, lockWait);
  689. #ifndef BUILD_BRIDGE
  690. if (isOscControlRegistered())
  691. oscSend_control_remove_plugin(id);
  692. #endif
  693. delete plugin;
  694. if (isRunning() && ! pData->aboutToClose)
  695. pData->thread.startNow();
  696. callback(CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  697. return true;
  698. }
  699. void CarlaEngine::removeAllPlugins()
  700. {
  701. CARLA_ASSERT(pData->plugins != nullptr);
  702. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull);
  703. carla_debug("CarlaEngine::removeAllPlugins() - START");
  704. if (pData->plugins == nullptr || pData->curPluginCount == 0)
  705. return;
  706. pData->thread.stopNow();
  707. const bool lockWait(isRunning());
  708. const CarlaEngineProtectedData::ScopedPluginAction spa(pData, kEnginePostActionZeroCount, 0, 0, lockWait);
  709. for (unsigned int i=0; i < pData->maxPluginNumber; ++i)
  710. {
  711. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  712. pData->plugins[i].plugin = nullptr;
  713. if (plugin != nullptr)
  714. delete plugin;
  715. // clear this plugin
  716. pData->plugins[i].insPeak[0] = 0.0f;
  717. pData->plugins[i].insPeak[1] = 0.0f;
  718. pData->plugins[i].outsPeak[0] = 0.0f;
  719. pData->plugins[i].outsPeak[1] = 0.0f;
  720. }
  721. if (isRunning() && ! pData->aboutToClose)
  722. pData->thread.startNow();
  723. carla_debug("CarlaEngine::removeAllPlugins() - END");
  724. }
  725. const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
  726. {
  727. CARLA_ASSERT(pData->curPluginCount != 0);
  728. CARLA_ASSERT(id < pData->curPluginCount);
  729. CARLA_ASSERT(pData->plugins != nullptr);
  730. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull);
  731. CARLA_ASSERT(newName != nullptr);
  732. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  733. if (pData->plugins == nullptr || pData->curPluginCount == 0)
  734. {
  735. setLastError("Critical error: no plugins are currently loaded!");
  736. return nullptr;
  737. }
  738. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  739. if (plugin == nullptr)
  740. {
  741. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  742. return nullptr;
  743. }
  744. CARLA_ASSERT(plugin->getId() == id);
  745. if (const char* const name = getUniquePluginName(newName))
  746. {
  747. plugin->setName(name);
  748. return name;
  749. }
  750. return nullptr;
  751. }
  752. bool CarlaEngine::clonePlugin(const unsigned int id)
  753. {
  754. CARLA_ASSERT(pData->curPluginCount > 0);
  755. CARLA_ASSERT(id < pData->curPluginCount);
  756. CARLA_ASSERT(pData->plugins != nullptr);
  757. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull);
  758. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  759. if (pData->plugins == nullptr || pData->curPluginCount == 0)
  760. {
  761. setLastError("Critical error: no plugins are currently loaded!");
  762. return false;
  763. }
  764. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  765. if (plugin == nullptr)
  766. {
  767. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  768. return false;
  769. }
  770. CARLA_ASSERT(plugin->getId() == id);
  771. char label[STR_MAX+1] = { '\0' };
  772. plugin->getLabel(label);
  773. BinaryType binaryType = BINARY_NATIVE;
  774. #ifndef BUILD_BRIDGE
  775. if (plugin->getHints() & PLUGIN_IS_BRIDGE)
  776. binaryType = CarlaPluginGetBridgeBinaryType(plugin);
  777. #endif
  778. const unsigned int pluginCountBefore(pData->curPluginCount);
  779. if (! addPlugin(binaryType, plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getExtraStuff()))
  780. return false;
  781. CARLA_ASSERT(pluginCountBefore+1 == pData->curPluginCount);
  782. if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
  783. newPlugin->loadSaveState(plugin->getSaveState());
  784. return true;
  785. }
  786. bool CarlaEngine::replacePlugin(const unsigned int id)
  787. {
  788. CARLA_ASSERT(pData->curPluginCount > 0);
  789. CARLA_ASSERT(id < pData->curPluginCount);
  790. CARLA_ASSERT(pData->plugins != nullptr);
  791. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull);
  792. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  793. if (id < pData->curPluginCount)
  794. pData->nextPluginId = id;
  795. return false;
  796. }
  797. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  798. {
  799. CARLA_ASSERT(pData->curPluginCount >= 2);
  800. CARLA_ASSERT(pData->plugins != nullptr);
  801. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull);
  802. CARLA_ASSERT(idA != idB);
  803. CARLA_ASSERT(idA < pData->curPluginCount);
  804. CARLA_ASSERT(idB < pData->curPluginCount);
  805. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  806. if (pData->plugins == nullptr || pData->curPluginCount == 0)
  807. {
  808. setLastError("Critical error: no plugins are currently loaded!");
  809. return false;
  810. }
  811. pData->thread.stopNow();
  812. const bool lockWait(isRunning() && fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  813. const CarlaEngineProtectedData::ScopedPluginAction spa(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  814. #ifndef BUILD_BRIDGE // TODO
  815. //if (isOscControlRegistered())
  816. // oscSend_control_switch_plugins(idA, idB);
  817. #endif
  818. if (isRunning() && ! pData->aboutToClose)
  819. pData->thread.startNow();
  820. return true;
  821. }
  822. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  823. {
  824. CARLA_ASSERT(pData->curPluginCount != 0);
  825. CARLA_ASSERT(id < pData->curPluginCount);
  826. CARLA_ASSERT(pData->plugins != nullptr);
  827. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull); // TESTING, remove later
  828. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, pData->curPluginCount);
  829. if (id < pData->curPluginCount && pData->plugins != nullptr)
  830. return pData->plugins[id].plugin;
  831. return nullptr;
  832. }
  833. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const noexcept
  834. {
  835. return pData->plugins[id].plugin;
  836. }
  837. const char* CarlaEngine::getUniquePluginName(const char* const name)
  838. {
  839. CARLA_ASSERT(pData->maxPluginNumber != 0);
  840. CARLA_ASSERT(pData->plugins != nullptr);
  841. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull);
  842. CARLA_ASSERT(name != nullptr);
  843. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  844. static CarlaString sname;
  845. sname = name;
  846. if (sname.isEmpty())
  847. {
  848. sname = "(No name)";
  849. return (const char*)sname;
  850. }
  851. if (pData->plugins == nullptr || pData->maxPluginNumber == 0)
  852. return (const char*)sname;
  853. sname.truncate(getMaxClientNameSize()-5-1); // 5 = strlen(" (10)")
  854. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  855. for (unsigned short i=0; i < pData->curPluginCount; ++i)
  856. {
  857. CARLA_ASSERT(pData->plugins[i].plugin != nullptr);
  858. if (pData->plugins[i].plugin == nullptr)
  859. break;
  860. // Check if unique name doesn't exist
  861. if (const char* const pluginName = pData->plugins[i].plugin->getName())
  862. {
  863. if (sname != pluginName)
  864. continue;
  865. }
  866. // Check if string has already been modified
  867. {
  868. const size_t len(sname.length());
  869. // 1 digit, ex: " (2)"
  870. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  871. {
  872. int number = sname[len-2] - '0';
  873. if (number == 9)
  874. {
  875. // next number is 10, 2 digits
  876. sname.truncate(len-4);
  877. sname += " (10)";
  878. //sname.replace(" (9)", " (10)");
  879. }
  880. else
  881. sname[len-2] = char('0' + number + 1);
  882. continue;
  883. }
  884. // 2 digits, ex: " (11)"
  885. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  886. {
  887. char n2 = sname[len-2];
  888. char n3 = sname[len-3];
  889. if (n2 == '9')
  890. {
  891. n2 = '0';
  892. n3 += 1;
  893. }
  894. else
  895. n2 += 1;
  896. sname[len-2] = n2;
  897. sname[len-3] = n3;
  898. continue;
  899. }
  900. }
  901. // Modify string if not
  902. sname += " (2)";
  903. }
  904. return (const char*)sname;
  905. }
  906. // -----------------------------------------------------------------------
  907. // Project management
  908. bool CarlaEngine::loadFilename(const char* const filename)
  909. {
  910. CARLA_ASSERT(filename != nullptr);
  911. carla_debug("CarlaEngine::loadFilename(\"%s\")", filename);
  912. QFileInfo fileInfo(filename);
  913. if (! fileInfo.exists())
  914. {
  915. setLastError("File does not exist");
  916. return false;
  917. }
  918. if (! fileInfo.isFile())
  919. {
  920. setLastError("Not a file");
  921. return false;
  922. }
  923. if (! fileInfo.isReadable())
  924. {
  925. setLastError("File is not readable");
  926. return false;
  927. }
  928. CarlaString baseName(fileInfo.baseName().toUtf8().constData());
  929. CarlaString extension(fileInfo.suffix().toLower().toUtf8().constData());
  930. // -------------------------------------------------------------------
  931. if (extension == "carxp" || extension == "carxs")
  932. return loadProject(filename);
  933. // -------------------------------------------------------------------
  934. if (extension == "gig")
  935. return addPlugin(PLUGIN_GIG, filename, baseName, baseName);
  936. if (extension == "sf2")
  937. return addPlugin(PLUGIN_SF2, filename, baseName, baseName);
  938. if (extension == "sfz")
  939. return addPlugin(PLUGIN_SFZ, filename, baseName, baseName);
  940. // -------------------------------------------------------------------
  941. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  942. {
  943. #ifdef WANT_AUDIOFILE
  944. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  945. {
  946. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  947. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  948. return true;
  949. }
  950. return false;
  951. #else
  952. setLastError("This Carla build does not have Audio file support");
  953. return false;
  954. #endif
  955. }
  956. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  957. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  958. {
  959. #ifdef WANT_AUDIOFILE
  960. # ifdef HAVE_FFMPEG
  961. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  962. {
  963. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  964. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  965. return true;
  966. }
  967. return false;
  968. # else
  969. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  970. return false;
  971. # endif
  972. #else
  973. setLastError("This Carla build does not have Audio file support");
  974. return false;
  975. #endif
  976. }
  977. // -------------------------------------------------------------------
  978. if (extension == "mid" || extension == "midi")
  979. {
  980. #ifdef WANT_MIDIFILE
  981. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile"))
  982. {
  983. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  984. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  985. return true;
  986. }
  987. return false;
  988. #else
  989. setLastError("This Carla build does not have MIDI file support");
  990. return false;
  991. #endif
  992. }
  993. // -------------------------------------------------------------------
  994. // ZynAddSubFX
  995. if (extension == "xmz" || extension == "xiz")
  996. {
  997. #ifdef WANT_ZYNADDSUBFX
  998. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx"))
  999. {
  1000. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1001. plugin->setCustomData(CUSTOM_DATA_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  1002. return true;
  1003. }
  1004. return false;
  1005. #else
  1006. setLastError("This Carla build does not have ZynAddSubFX support");
  1007. return false;
  1008. #endif
  1009. }
  1010. // -------------------------------------------------------------------
  1011. setLastError("Unknown file extension");
  1012. return false;
  1013. }
  1014. bool charEndsWith(const char* const str, const char* const suffix)
  1015. {
  1016. if (str == nullptr || suffix == nullptr)
  1017. return false;
  1018. const size_t strLen(std::strlen(str));
  1019. const size_t suffixLen(std::strlen(suffix));
  1020. if (strLen < suffixLen)
  1021. return false;
  1022. return (std::strncmp(str + (strLen-suffixLen), suffix, suffixLen) == 0);
  1023. }
  1024. bool CarlaEngine::loadProject(const char* const filename)
  1025. {
  1026. CARLA_ASSERT(filename != nullptr);
  1027. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1028. QFile file(filename);
  1029. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  1030. return false;
  1031. QDomDocument xml;
  1032. xml.setContent(file.readAll());
  1033. file.close();
  1034. QDomNode xmlNode(xml.documentElement());
  1035. if (xmlNode.toElement().tagName() != "CARLA-PROJECT" && xmlNode.toElement().tagName() != "CARLA-PRESET")
  1036. {
  1037. setLastError("Not a valid Carla project or preset file");
  1038. return false;
  1039. }
  1040. const bool isPreset(xmlNode.toElement().tagName() == "CARLA-PRESET");
  1041. QDomNode node(xmlNode.firstChild());
  1042. while (! node.isNull())
  1043. {
  1044. if (isPreset || node.toElement().tagName() == "Plugin")
  1045. {
  1046. SaveState saveState;
  1047. fillSaveStateFromXmlNode(saveState, isPreset ? xmlNode : node);
  1048. CARLA_ASSERT(saveState.type != nullptr);
  1049. if (saveState.type == nullptr)
  1050. continue;
  1051. const void* extraStuff = nullptr;
  1052. if (std::strcmp(saveState.type, "DSSI") == 0)
  1053. {
  1054. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  1055. }
  1056. else if (std::strcmp(saveState.type, "SF2") == 0)
  1057. {
  1058. const char use16OutsSuffix[] = " (16 outs)";
  1059. if (charEndsWith(saveState.label, use16OutsSuffix))
  1060. extraStuff = (void*)0x1; // non-null
  1061. }
  1062. // TODO - proper find&load plugins
  1063. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  1064. {
  1065. if (CarlaPlugin* plugin = getPlugin(pData->curPluginCount-1))
  1066. plugin->loadSaveState(saveState);
  1067. }
  1068. }
  1069. if (isPreset)
  1070. break;
  1071. node = node.nextSibling();
  1072. }
  1073. return true;
  1074. }
  1075. bool CarlaEngine::saveProject(const char* const filename)
  1076. {
  1077. CARLA_ASSERT(filename != nullptr);
  1078. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1079. QFile file(filename);
  1080. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1081. return false;
  1082. QTextStream out(&file);
  1083. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1084. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1085. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  1086. bool firstPlugin = true;
  1087. char strBuf[STR_MAX+1];
  1088. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1089. {
  1090. CarlaPlugin* const plugin = pData->plugins[i].plugin;
  1091. if (plugin != nullptr && plugin->isEnabled())
  1092. {
  1093. if (! firstPlugin)
  1094. out << "\n";
  1095. plugin->getRealName(strBuf);
  1096. if (*strBuf != 0)
  1097. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1098. QString content;
  1099. fillXmlStringFromSaveState(content, plugin->getSaveState());
  1100. out << " <Plugin>\n";
  1101. out << content;
  1102. out << " </Plugin>\n";
  1103. firstPlugin = false;
  1104. }
  1105. }
  1106. out << "</CARLA-PROJECT>\n";
  1107. file.close();
  1108. return true;
  1109. }
  1110. // -----------------------------------------------------------------------
  1111. // Information (peaks)
  1112. // FIXME
  1113. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  1114. {
  1115. CARLA_ASSERT(pluginId < pData->curPluginCount);
  1116. CARLA_ASSERT(id-1 < 2);
  1117. if (id == 0 || id > 2)
  1118. return 0.0f;
  1119. return pData->plugins[pluginId].insPeak[id-1];
  1120. }
  1121. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  1122. {
  1123. CARLA_ASSERT(pluginId < pData->curPluginCount);
  1124. CARLA_ASSERT(id-1 < 2);
  1125. if (id == 0 || id > 2)
  1126. return 0.0f;
  1127. return pData->plugins[pluginId].outsPeak[id-1];
  1128. }
  1129. // -----------------------------------------------------------------------
  1130. // Callback
  1131. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  1132. {
  1133. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  1134. if (pData->callback)
  1135. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1136. }
  1137. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  1138. {
  1139. CARLA_ASSERT(func != nullptr);
  1140. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1141. pData->callback = func;
  1142. pData->callbackPtr = ptr;
  1143. }
  1144. // -----------------------------------------------------------------------
  1145. // Patchbay
  1146. bool CarlaEngine::patchbayConnect(int, int)
  1147. {
  1148. setLastError("Unsupported operation");
  1149. return false;
  1150. }
  1151. bool CarlaEngine::patchbayDisconnect(int)
  1152. {
  1153. setLastError("Unsupported operation");
  1154. return false;
  1155. }
  1156. void CarlaEngine::patchbayRefresh()
  1157. {
  1158. // nothing
  1159. }
  1160. // -----------------------------------------------------------------------
  1161. // Transport
  1162. void CarlaEngine::transportPlay()
  1163. {
  1164. pData->time.playing = true;
  1165. }
  1166. void CarlaEngine::transportPause()
  1167. {
  1168. pData->time.playing = false;
  1169. }
  1170. void CarlaEngine::transportRelocate(const uint32_t frame)
  1171. {
  1172. pData->time.frame = frame;
  1173. }
  1174. // -----------------------------------------------------------------------
  1175. // Error handling
  1176. const char* CarlaEngine::getLastError() const noexcept
  1177. {
  1178. return (const char*)pData->lastError;
  1179. }
  1180. void CarlaEngine::setLastError(const char* const error)
  1181. {
  1182. pData->lastError = error;
  1183. }
  1184. void CarlaEngine::setAboutToClose()
  1185. {
  1186. carla_debug("CarlaEngine::setAboutToClose()");
  1187. pData->aboutToClose = true;
  1188. }
  1189. // -----------------------------------------------------------------------
  1190. // Global options
  1191. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  1192. if (isRunning()) \
  1193. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  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. switch (option)
  1198. {
  1199. case OPTION_PROCESS_NAME:
  1200. carla_setprocname(valueStr);
  1201. break;
  1202. case OPTION_PROCESS_MODE:
  1203. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1204. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_BRIDGE)
  1205. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  1206. fOptions.processMode = static_cast<ProcessMode>(value);
  1207. break;
  1208. case OPTION_TRANSPORT_MODE:
  1209. // FIXME: Always enable JACK transport for now
  1210. #if 0
  1211. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_BRIDGE)
  1212. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1213. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  1214. #endif
  1215. break;
  1216. case OPTION_MAX_PARAMETERS:
  1217. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1218. if (value < 0)
  1219. return; // TODO error here
  1220. fOptions.maxParameters = static_cast<uint>(value);
  1221. break;
  1222. case OPTION_FORCE_STEREO:
  1223. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1224. fOptions.forceStereo = (value != 0);
  1225. break;
  1226. case OPTION_PREFER_PLUGIN_BRIDGES:
  1227. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1228. fOptions.preferPluginBridges = (value != 0);
  1229. break;
  1230. case OPTION_PREFER_UI_BRIDGES:
  1231. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1232. fOptions.preferUiBridges = (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_UI_BRIDGES_TIMEOUT:
  1241. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1242. fOptions.oscUiTimeout = static_cast<uint>(value);
  1243. break;
  1244. case OPTION_JACK_AUTOCONNECT:
  1245. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1246. fOptions.jackAutoConnect = (value != 0);
  1247. break;
  1248. #ifdef WANT_RTAUDIO
  1249. case OPTION_RTAUDIO_NUMBER_PERIODS:
  1250. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1251. fOptions.rtaudioNumberPeriods = static_cast<uint>(value);
  1252. break;
  1253. case OPTION_RTAUDIO_BUFFER_SIZE:
  1254. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1255. fOptions.rtaudioBufferSize = static_cast<uint>(value);
  1256. break;
  1257. case OPTION_RTAUDIO_SAMPLE_RATE:
  1258. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1259. fOptions.rtaudioSampleRate = static_cast<uint>(value);
  1260. break;
  1261. case OPTION_RTAUDIO_DEVICE:
  1262. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1263. fOptions.rtaudioDevice = valueStr;
  1264. break;
  1265. #endif
  1266. case OPTION_PATH_RESOURCES:
  1267. fOptions.resourceDir = valueStr;
  1268. break;
  1269. #ifndef BUILD_BRIDGE
  1270. case OPTION_PATH_BRIDGE_NATIVE:
  1271. fOptions.bridge_native = valueStr;
  1272. break;
  1273. case OPTION_PATH_BRIDGE_POSIX32:
  1274. fOptions.bridge_posix32 = valueStr;
  1275. break;
  1276. case OPTION_PATH_BRIDGE_POSIX64:
  1277. fOptions.bridge_posix64 = valueStr;
  1278. break;
  1279. case OPTION_PATH_BRIDGE_WIN32:
  1280. fOptions.bridge_win32 = valueStr;
  1281. break;
  1282. case OPTION_PATH_BRIDGE_WIN64:
  1283. fOptions.bridge_win64 = valueStr;
  1284. break;
  1285. #endif
  1286. #ifdef WANT_LV2
  1287. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1288. fOptions.bridge_lv2Gtk2 = valueStr;
  1289. break;
  1290. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1291. fOptions.bridge_lv2Gtk3 = valueStr;
  1292. break;
  1293. case OPTION_PATH_BRIDGE_LV2_QT4:
  1294. fOptions.bridge_lv2Qt4 = valueStr;
  1295. break;
  1296. case OPTION_PATH_BRIDGE_LV2_QT5:
  1297. fOptions.bridge_lv2Qt5 = valueStr;
  1298. break;
  1299. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1300. fOptions.bridge_lv2Cocoa = valueStr;
  1301. break;
  1302. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1303. fOptions.bridge_lv2Win = valueStr;
  1304. break;
  1305. case OPTION_PATH_BRIDGE_LV2_X11:
  1306. fOptions.bridge_lv2X11 = valueStr;
  1307. break;
  1308. #endif
  1309. #ifdef WANT_VST
  1310. case OPTION_PATH_BRIDGE_VST_COCOA:
  1311. fOptions.bridge_vstCocoa = valueStr;
  1312. break;
  1313. case OPTION_PATH_BRIDGE_VST_HWND:
  1314. fOptions.bridge_vstHWND = valueStr;
  1315. break;
  1316. case OPTION_PATH_BRIDGE_VST_X11:
  1317. fOptions.bridge_vstX11 = valueStr;
  1318. break;
  1319. #endif
  1320. }
  1321. }
  1322. // -----------------------------------------------------------------------
  1323. // OSC Stuff
  1324. #ifdef BUILD_BRIDGE
  1325. bool CarlaEngine::isOscBridgeRegistered() const noexcept
  1326. {
  1327. return (pData->oscData != nullptr);
  1328. }
  1329. #else
  1330. bool CarlaEngine::isOscControlRegistered() const noexcept
  1331. {
  1332. return pData->osc.isControlRegistered();
  1333. }
  1334. #endif
  1335. void CarlaEngine::idleOsc()
  1336. {
  1337. pData->osc.idle();
  1338. }
  1339. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1340. {
  1341. return pData->osc.getServerPathTCP();
  1342. }
  1343. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1344. {
  1345. return pData->osc.getServerPathUDP();
  1346. }
  1347. #ifdef BUILD_BRIDGE
  1348. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) noexcept
  1349. {
  1350. pData->oscData = oscData;
  1351. }
  1352. #endif
  1353. // -----------------------------------------------------------------------
  1354. // protected calls
  1355. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1356. {
  1357. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1358. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1359. {
  1360. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1361. if (plugin != nullptr && plugin->isEnabled())
  1362. plugin->bufferSizeChanged(newBufferSize);
  1363. }
  1364. callback(CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1365. }
  1366. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1367. {
  1368. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1369. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1370. {
  1371. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1372. if (plugin != nullptr && plugin->isEnabled())
  1373. plugin->sampleRateChanged(newSampleRate);
  1374. }
  1375. callback(CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, newSampleRate, nullptr);
  1376. }
  1377. void CarlaEngine::offlineModeChanged(const bool isOffline)
  1378. {
  1379. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOffline));
  1380. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1381. {
  1382. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1383. if (plugin != nullptr && plugin->isEnabled())
  1384. plugin->offlineModeChanged(isOffline);
  1385. }
  1386. }
  1387. void CarlaEngine::runPendingRtEvents()
  1388. {
  1389. pData->doNextPluginAction(true);
  1390. if (pData->time.playing)
  1391. pData->time.frame += fBufferSize;
  1392. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1393. {
  1394. fTimeInfo.playing = pData->time.playing;
  1395. fTimeInfo.frame = pData->time.frame;
  1396. }
  1397. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1398. {
  1399. // TODO - peak values?
  1400. }
  1401. }
  1402. void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1403. {
  1404. pData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1405. pData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1406. pData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1407. pData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1408. }
  1409. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1410. {
  1411. return isInput ? pData->bufEvents.in : pData->bufEvents.out;
  1412. }
  1413. #ifndef BUILD_BRIDGE
  1414. void setValueIfHigher(float& value, const float& compare)
  1415. {
  1416. if (value < compare)
  1417. value = compare;
  1418. }
  1419. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1420. {
  1421. CARLA_ASSERT(pData->bufEvents.in != nullptr);
  1422. CARLA_ASSERT(pData->bufEvents.out != nullptr);
  1423. // initialize outputs (zero)
  1424. carla_zeroFloat(outBuf[0], frames);
  1425. carla_zeroFloat(outBuf[1], frames);
  1426. carla_zeroMem(pData->bufEvents.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1427. bool processed = false;
  1428. // process plugins
  1429. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1430. {
  1431. CarlaPlugin* const plugin = pData->plugins[i].plugin;
  1432. if (plugin == nullptr || ! plugin->isEnabled() || ! plugin->tryLock())
  1433. continue;
  1434. if (processed)
  1435. {
  1436. // initialize inputs (from previous outputs)
  1437. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1438. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1439. std::memcpy(pData->bufEvents.in, pData->bufEvents.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1440. // initialize outputs (zero)
  1441. carla_zeroFloat(outBuf[0], frames);
  1442. carla_zeroFloat(outBuf[1], frames);
  1443. carla_zeroMem(pData->bufEvents.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1444. }
  1445. // process
  1446. plugin->initBuffers();
  1447. plugin->process(inBuf, outBuf, frames);
  1448. plugin->unlock();
  1449. #if 0
  1450. // if plugin has no audio inputs, add previous buffers
  1451. if (plugin->audioInCount() == 0)
  1452. {
  1453. for (uint32_t j=0; j < frames; ++j)
  1454. {
  1455. outBuf[0][j] += inBuf[0][j];
  1456. outBuf[1][j] += inBuf[1][j];
  1457. }
  1458. }
  1459. // if plugin has no midi output, add previous events
  1460. if (plugin->midiOutCount() == 0)
  1461. {
  1462. for (uint32_t j=0, k=0; j < frames; ++j)
  1463. {
  1464. }
  1465. std::memcpy(pData->rack.out, pData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1466. }
  1467. #endif
  1468. // set peaks
  1469. {
  1470. float inPeak1 = 0.0f;
  1471. float inPeak2 = 0.0f;
  1472. float outPeak1 = 0.0f;
  1473. float outPeak2 = 0.0f;
  1474. for (uint32_t k=0; k < frames; ++k)
  1475. {
  1476. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1477. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1478. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1479. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1480. }
  1481. pData->plugins[i].insPeak[0] = inPeak1;
  1482. pData->plugins[i].insPeak[1] = inPeak2;
  1483. pData->plugins[i].outsPeak[0] = outPeak1;
  1484. pData->plugins[i].outsPeak[1] = outPeak2;
  1485. }
  1486. processed = true;
  1487. }
  1488. }
  1489. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1490. {
  1491. // TODO
  1492. return;
  1493. // unused, for now
  1494. (void)inBuf;
  1495. (void)outBuf;
  1496. (void)bufCount;
  1497. (void)frames;
  1498. }
  1499. #endif
  1500. // -------------------------------------------------------------------------------------------------------------------
  1501. // Carla Engine OSC stuff
  1502. #ifndef BUILD_BRIDGE
  1503. void CarlaEngine::oscSend_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1504. {
  1505. CARLA_ASSERT(pData->oscData != nullptr);
  1506. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1507. CARLA_ASSERT(pluginName != nullptr);
  1508. carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1509. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1510. {
  1511. char targetPath[std::strlen(pData->oscData->path)+18];
  1512. std::strcpy(targetPath, pData->oscData->path);
  1513. std::strcat(targetPath, "/add_plugin_start");
  1514. lo_send(pData->oscData->target, targetPath, "is", pluginId, pluginName);
  1515. }
  1516. }
  1517. void CarlaEngine::oscSend_control_add_plugin_end(const int32_t pluginId)
  1518. {
  1519. CARLA_ASSERT(pData->oscData != nullptr);
  1520. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1521. carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
  1522. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1523. {
  1524. char targetPath[std::strlen(pData->oscData->path)+16];
  1525. std::strcpy(targetPath, pData->oscData->path);
  1526. std::strcat(targetPath, "/add_plugin_end");
  1527. lo_send(pData->oscData->target, targetPath, "i", pluginId);
  1528. }
  1529. }
  1530. void CarlaEngine::oscSend_control_remove_plugin(const int32_t pluginId)
  1531. {
  1532. CARLA_ASSERT(pData->oscData != nullptr);
  1533. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->curPluginCount));
  1534. carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
  1535. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1536. {
  1537. char targetPath[std::strlen(pData->oscData->path)+15];
  1538. std::strcpy(targetPath, pData->oscData->path);
  1539. std::strcat(targetPath, "/remove_plugin");
  1540. lo_send(pData->oscData->target, targetPath, "i", pluginId);
  1541. }
  1542. }
  1543. 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)
  1544. {
  1545. CARLA_ASSERT(pData->oscData != nullptr);
  1546. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1547. CARLA_ASSERT(type != PLUGIN_NONE);
  1548. CARLA_ASSERT(realName != nullptr);
  1549. CARLA_ASSERT(label != nullptr);
  1550. CARLA_ASSERT(maker != nullptr);
  1551. CARLA_ASSERT(copyright != nullptr);
  1552. 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);
  1553. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1554. {
  1555. char targetPath[std::strlen(pData->oscData->path)+17];
  1556. std::strcpy(targetPath, pData->oscData->path);
  1557. std::strcat(targetPath, "/set_plugin_data");
  1558. lo_send(pData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1559. }
  1560. }
  1561. 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)
  1562. {
  1563. CARLA_ASSERT(pData->oscData != nullptr);
  1564. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1565. carla_debug("CarlaEngine::oscSend_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1566. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1567. {
  1568. char targetPath[std::strlen(pData->oscData->path)+18];
  1569. std::strcpy(targetPath, pData->oscData->path);
  1570. std::strcat(targetPath, "/set_plugin_ports");
  1571. lo_send(pData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1572. }
  1573. }
  1574. 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)
  1575. {
  1576. CARLA_ASSERT(pData->oscData != nullptr);
  1577. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1578. CARLA_ASSERT(index >= 0);
  1579. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1580. CARLA_ASSERT(name != nullptr);
  1581. CARLA_ASSERT(label != nullptr);
  1582. carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %f)", pluginId, index, type, hints, name, label, current);
  1583. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1584. {
  1585. char targetPath[std::strlen(pData->oscData->path)+20];
  1586. std::strcpy(targetPath, pData->oscData->path);
  1587. std::strcat(targetPath, "/set_parameter_data");
  1588. lo_send(pData->oscData->target, targetPath, "iiiissf", pluginId, index, type, hints, name, label, current);
  1589. }
  1590. }
  1591. 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)
  1592. {
  1593. CARLA_ASSERT(pData->oscData != nullptr);
  1594. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1595. CARLA_ASSERT(index >= 0);
  1596. CARLA_ASSERT(min < max);
  1597. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges(%i, %i, %f, %f, %f, %f, %f, %f)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1598. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1599. {
  1600. char targetPath[std::strlen(pData->oscData->path)+22];
  1601. std::strcpy(targetPath, pData->oscData->path);
  1602. std::strcat(targetPath, "/set_parameter_ranges");
  1603. lo_send(pData->oscData->target, targetPath, "iiffffff", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1604. }
  1605. }
  1606. void CarlaEngine::oscSend_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1607. {
  1608. CARLA_ASSERT(pData->oscData != nullptr);
  1609. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1610. CARLA_ASSERT(index >= 0);
  1611. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1612. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1613. {
  1614. char targetPath[std::strlen(pData->oscData->path)+23];
  1615. std::strcpy(targetPath, pData->oscData->path);
  1616. std::strcat(targetPath, "/set_parameter_midi_cc");
  1617. lo_send(pData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1618. }
  1619. }
  1620. void CarlaEngine::oscSend_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1621. {
  1622. CARLA_ASSERT(pData->oscData != nullptr);
  1623. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1624. CARLA_ASSERT(index >= 0);
  1625. CARLA_ASSERT(channel >= 0 && channel < 16);
  1626. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1627. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1628. {
  1629. char targetPath[std::strlen(pData->oscData->path)+28];
  1630. std::strcpy(targetPath, pData->oscData->path);
  1631. std::strcat(targetPath, "/set_parameter_midi_channel");
  1632. lo_send(pData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1633. }
  1634. }
  1635. void CarlaEngine::oscSend_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1636. {
  1637. CARLA_ASSERT(pData->oscData != nullptr);
  1638. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1639. #if DEBUG
  1640. if (index < 0)
  1641. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %s, %f)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1642. else
  1643. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i, %f)", pluginId, index, value);
  1644. #endif
  1645. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1646. {
  1647. char targetPath[std::strlen(pData->oscData->path)+21];
  1648. std::strcpy(targetPath, pData->oscData->path);
  1649. std::strcat(targetPath, "/set_parameter_value");
  1650. lo_send(pData->oscData->target, targetPath, "iif", pluginId, index, value);
  1651. }
  1652. }
  1653. void CarlaEngine::oscSend_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1654. {
  1655. CARLA_ASSERT(pData->oscData != nullptr);
  1656. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1657. CARLA_ASSERT(index >= 0);
  1658. carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  1659. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1660. {
  1661. char targetPath[std::strlen(pData->oscData->path)+19];
  1662. std::strcpy(targetPath, pData->oscData->path);
  1663. std::strcat(targetPath, "/set_default_value");
  1664. lo_send(pData->oscData->target, targetPath, "iif", pluginId, index, value);
  1665. }
  1666. }
  1667. void CarlaEngine::oscSend_control_set_program(const int32_t pluginId, const int32_t index)
  1668. {
  1669. CARLA_ASSERT(pData->oscData != nullptr);
  1670. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1671. carla_debug("CarlaEngine::oscSend_control_set_program(%i, %i)", pluginId, index);
  1672. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1673. {
  1674. char targetPath[std::strlen(pData->oscData->path)+13];
  1675. std::strcpy(targetPath, pData->oscData->path);
  1676. std::strcat(targetPath, "/set_program");
  1677. lo_send(pData->oscData->target, targetPath, "ii", pluginId, index);
  1678. }
  1679. }
  1680. void CarlaEngine::oscSend_control_set_program_count(const int32_t pluginId, const int32_t count)
  1681. {
  1682. CARLA_ASSERT(pData->oscData != nullptr);
  1683. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1684. CARLA_ASSERT(count >= 0);
  1685. carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
  1686. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1687. {
  1688. char targetPath[std::strlen(pData->oscData->path)+19];
  1689. std::strcpy(targetPath, pData->oscData->path);
  1690. std::strcat(targetPath, "/set_program_count");
  1691. lo_send(pData->oscData->target, targetPath, "ii", pluginId, count);
  1692. }
  1693. }
  1694. void CarlaEngine::oscSend_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1695. {
  1696. CARLA_ASSERT(pData->oscData != nullptr);
  1697. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1698. CARLA_ASSERT(index >= 0);
  1699. CARLA_ASSERT(name != nullptr);
  1700. carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1701. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1702. {
  1703. char targetPath[std::strlen(pData->oscData->path)+18];
  1704. std::strcpy(targetPath, pData->oscData->path);
  1705. std::strcat(targetPath, "/set_program_name");
  1706. lo_send(pData->oscData->target, targetPath, "iis", pluginId, index, name);
  1707. }
  1708. }
  1709. void CarlaEngine::oscSend_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1710. {
  1711. CARLA_ASSERT(pData->oscData != nullptr);
  1712. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1713. carla_debug("CarlaEngine::oscSend_control_set_midi_program(%i, %i)", pluginId, index);
  1714. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1715. {
  1716. char targetPath[std::strlen(pData->oscData->path)+18];
  1717. std::strcpy(targetPath, pData->oscData->path);
  1718. std::strcat(targetPath, "/set_midi_program");
  1719. lo_send(pData->oscData->target, targetPath, "ii", pluginId, index);
  1720. }
  1721. }
  1722. void CarlaEngine::oscSend_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1723. {
  1724. CARLA_ASSERT(pData->oscData != nullptr);
  1725. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1726. CARLA_ASSERT(count >= 0);
  1727. carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
  1728. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1729. {
  1730. char targetPath[std::strlen(pData->oscData->path)+24];
  1731. std::strcpy(targetPath, pData->oscData->path);
  1732. std::strcat(targetPath, "/set_midi_program_count");
  1733. lo_send(pData->oscData->target, targetPath, "ii", pluginId, count);
  1734. }
  1735. }
  1736. 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)
  1737. {
  1738. CARLA_ASSERT(pData->oscData != nullptr);
  1739. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1740. CARLA_ASSERT(index >= 0);
  1741. CARLA_ASSERT(bank >= 0);
  1742. CARLA_ASSERT(program >= 0);
  1743. CARLA_ASSERT(name != nullptr);
  1744. carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1745. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1746. {
  1747. char targetPath[std::strlen(pData->oscData->path)+23];
  1748. std::strcpy(targetPath, pData->oscData->path);
  1749. std::strcat(targetPath, "/set_midi_program_data");
  1750. lo_send(pData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1751. }
  1752. }
  1753. void CarlaEngine::oscSend_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1754. {
  1755. CARLA_ASSERT(pData->oscData != nullptr);
  1756. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->curPluginCount));
  1757. CARLA_ASSERT(channel >= 0 && channel < MAX_MIDI_CHANNELS);
  1758. CARLA_ASSERT(note >= 0 && note < MAX_MIDI_NOTE);
  1759. CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE);
  1760. carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1761. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1762. {
  1763. char targetPath[std::strlen(pData->oscData->path)+9];
  1764. std::strcpy(targetPath, pData->oscData->path);
  1765. std::strcat(targetPath, "/note_on");
  1766. lo_send(pData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1767. }
  1768. }
  1769. void CarlaEngine::oscSend_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1770. {
  1771. CARLA_ASSERT(pData->oscData != nullptr);
  1772. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->curPluginCount));
  1773. CARLA_ASSERT(channel >= 0 && channel < MAX_MIDI_CHANNELS);
  1774. CARLA_ASSERT(note >= 0 && note < MAX_MIDI_NOTE);
  1775. carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1776. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1777. {
  1778. char targetPath[std::strlen(pData->oscData->path)+10];
  1779. std::strcpy(targetPath, pData->oscData->path);
  1780. std::strcat(targetPath, "/note_off");
  1781. lo_send(pData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1782. }
  1783. }
  1784. void CarlaEngine::oscSend_control_set_peaks(const int32_t pluginId)
  1785. {
  1786. CARLA_ASSERT(pData->oscData != nullptr);
  1787. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->curPluginCount));
  1788. const EnginePluginData& epData(pData->plugins[pluginId]);
  1789. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1790. {
  1791. char targetPath[std::strlen(pData->oscData->path)+22];
  1792. std::strcpy(targetPath, pData->oscData->path);
  1793. std::strcat(targetPath, "/set_peaks");
  1794. lo_send(pData->oscData->target, targetPath, "iffff", pluginId, epData.insPeak[0], epData.insPeak[1], epData.outsPeak[0], epData.outsPeak[1]);
  1795. }
  1796. }
  1797. void CarlaEngine::oscSend_control_exit()
  1798. {
  1799. CARLA_ASSERT(pData->oscData != nullptr);
  1800. carla_debug("CarlaEngine::oscSend_control_exit()");
  1801. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1802. {
  1803. char targetPath[std::strlen(pData->oscData->path)+6];
  1804. std::strcpy(targetPath, pData->oscData->path);
  1805. std::strcat(targetPath, "/exit");
  1806. lo_send(pData->oscData->target, targetPath, "");
  1807. }
  1808. }
  1809. #else
  1810. void CarlaEngine::oscSend_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1811. {
  1812. CARLA_ASSERT(pData->oscData != nullptr);
  1813. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1814. carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1815. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1816. {
  1817. char targetPath[std::strlen(pData->oscData->path)+20];
  1818. std::strcpy(targetPath, pData->oscData->path);
  1819. std::strcat(targetPath, "/bridge_audio_count");
  1820. lo_send(pData->oscData->target, targetPath, "iii", ins, outs, total);
  1821. }
  1822. }
  1823. void CarlaEngine::oscSend_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1824. {
  1825. CARLA_ASSERT(pData->oscData != nullptr);
  1826. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1827. carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1828. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1829. {
  1830. char targetPath[std::strlen(pData->oscData->path)+19];
  1831. std::strcpy(targetPath, pData->oscData->path);
  1832. std::strcat(targetPath, "/bridge_midi_count");
  1833. lo_send(pData->oscData->target, targetPath, "iii", ins, outs, total);
  1834. }
  1835. }
  1836. void CarlaEngine::oscSend_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1837. {
  1838. CARLA_ASSERT(pData->oscData != nullptr);
  1839. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1840. carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1841. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1842. {
  1843. char targetPath[std::strlen(pData->oscData->path)+24];
  1844. std::strcpy(targetPath, pData->oscData->path);
  1845. std::strcat(targetPath, "/bridge_parameter_count");
  1846. lo_send(pData->oscData->target, targetPath, "iii", ins, outs, total);
  1847. }
  1848. }
  1849. void CarlaEngine::oscSend_bridge_program_count(const int32_t count)
  1850. {
  1851. CARLA_ASSERT(pData->oscData != nullptr);
  1852. CARLA_ASSERT(count >= 0);
  1853. carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
  1854. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1855. {
  1856. char targetPath[std::strlen(pData->oscData->path)+22];
  1857. std::strcpy(targetPath, pData->oscData->path);
  1858. std::strcat(targetPath, "/bridge_program_count");
  1859. lo_send(pData->oscData->target, targetPath, "i", count);
  1860. }
  1861. }
  1862. void CarlaEngine::oscSend_bridge_midi_program_count(const int32_t count)
  1863. {
  1864. CARLA_ASSERT(pData->oscData != nullptr);
  1865. CARLA_ASSERT(count >= 0);
  1866. carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
  1867. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1868. {
  1869. char targetPath[std::strlen(pData->oscData->path)+27];
  1870. std::strcpy(targetPath, pData->oscData->path);
  1871. std::strcat(targetPath, "/bridge_midi_program_count");
  1872. lo_send(pData->oscData->target, targetPath, "i", count);
  1873. }
  1874. }
  1875. 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)
  1876. {
  1877. CARLA_ASSERT(pData->oscData != nullptr);
  1878. CARLA_ASSERT(name != nullptr);
  1879. CARLA_ASSERT(label != nullptr);
  1880. CARLA_ASSERT(maker != nullptr);
  1881. CARLA_ASSERT(copyright != nullptr);
  1882. carla_debug("CarlaEngine::oscSend_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1883. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1884. {
  1885. char targetPath[std::strlen(pData->oscData->path)+20];
  1886. std::strcpy(targetPath, pData->oscData->path);
  1887. std::strcat(targetPath, "/bridge_plugin_info");
  1888. lo_send(pData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1889. }
  1890. }
  1891. void CarlaEngine::oscSend_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1892. {
  1893. CARLA_ASSERT(pData->oscData != nullptr);
  1894. CARLA_ASSERT(name != nullptr);
  1895. CARLA_ASSERT(unit != nullptr);
  1896. carla_debug("CarlaEngine::oscSend_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1897. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1898. {
  1899. char targetPath[std::strlen(pData->oscData->path)+23];
  1900. std::strcpy(targetPath, pData->oscData->path);
  1901. std::strcat(targetPath, "/bridge_parameter_info");
  1902. lo_send(pData->oscData->target, targetPath, "iss", index, name, unit);
  1903. }
  1904. }
  1905. 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)
  1906. {
  1907. CARLA_ASSERT(pData->oscData != nullptr);
  1908. carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1909. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1910. {
  1911. char targetPath[std::strlen(pData->oscData->path)+23];
  1912. std::strcpy(targetPath, pData->oscData->path);
  1913. std::strcat(targetPath, "/bridge_parameter_data");
  1914. lo_send(pData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1915. }
  1916. }
  1917. 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)
  1918. {
  1919. CARLA_ASSERT(pData->oscData != nullptr);
  1920. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f, %f, %f, %f)", index, def, min, max, step, stepSmall, stepLarge);
  1921. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1922. {
  1923. char targetPath[std::strlen(pData->oscData->path)+25];
  1924. std::strcpy(targetPath, pData->oscData->path);
  1925. std::strcat(targetPath, "/bridge_parameter_ranges");
  1926. lo_send(pData->oscData->target, targetPath, "iffffff", index, def, min, max, step, stepSmall, stepLarge);
  1927. }
  1928. }
  1929. void CarlaEngine::oscSend_bridge_program_info(const int32_t index, const char* const name)
  1930. {
  1931. CARLA_ASSERT(pData->oscData != nullptr);
  1932. carla_debug("CarlaEngine::oscSend_bridge_program_info(%i, \"%s\")", index, name);
  1933. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1934. {
  1935. char targetPath[std::strlen(pData->oscData->path)+21];
  1936. std::strcpy(targetPath, pData->oscData->path);
  1937. std::strcat(targetPath, "/bridge_program_info");
  1938. lo_send(pData->oscData->target, targetPath, "is", index, name);
  1939. }
  1940. }
  1941. void CarlaEngine::oscSend_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1942. {
  1943. CARLA_ASSERT(pData->oscData != nullptr);
  1944. carla_debug("CarlaEngine::oscSend_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1945. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1946. {
  1947. char targetPath[std::strlen(pData->oscData->path)+26];
  1948. std::strcpy(targetPath, pData->oscData->path);
  1949. std::strcat(targetPath, "/bridge_midi_program_info");
  1950. lo_send(pData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1951. }
  1952. }
  1953. void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value)
  1954. {
  1955. CARLA_ASSERT(pData->oscData != nullptr);
  1956. CARLA_ASSERT(key != nullptr);
  1957. CARLA_ASSERT(value != nullptr);
  1958. carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
  1959. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1960. {
  1961. char targetPath[std::strlen(pData->oscData->path)+18];
  1962. std::strcpy(targetPath, pData->oscData->path);
  1963. std::strcat(targetPath, "/bridge_configure");
  1964. lo_send(pData->oscData->target, targetPath, "ss", key, value);
  1965. }
  1966. }
  1967. void CarlaEngine::oscSend_bridge_set_parameter_value(const int32_t index, const float value)
  1968. {
  1969. CARLA_ASSERT(pData->oscData != nullptr);
  1970. carla_debug("CarlaEngine::oscSend_bridge_set_parameter_value(%i, %f)", index, value);
  1971. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1972. {
  1973. char targetPath[std::strlen(pData->oscData->path)+28];
  1974. std::strcpy(targetPath, pData->oscData->path);
  1975. std::strcat(targetPath, "/bridge_set_parameter_value");
  1976. lo_send(pData->oscData->target, targetPath, "if", index, value);
  1977. }
  1978. }
  1979. void CarlaEngine::oscSend_bridge_set_default_value(const int32_t index, const float value)
  1980. {
  1981. CARLA_ASSERT(pData->oscData != nullptr);
  1982. carla_debug("CarlaEngine::oscSend_bridge_set_default_value(%i, %f)", index, value);
  1983. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1984. {
  1985. char targetPath[std::strlen(pData->oscData->path)+26];
  1986. std::strcpy(targetPath, pData->oscData->path);
  1987. std::strcat(targetPath, "/bridge_set_default_value");
  1988. lo_send(pData->oscData->target, targetPath, "if", index, value);
  1989. }
  1990. }
  1991. void CarlaEngine::oscSend_bridge_set_program(const int32_t index)
  1992. {
  1993. CARLA_ASSERT(pData->oscData != nullptr);
  1994. carla_debug("CarlaEngine::oscSend_bridge_set_program(%i)", index);
  1995. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1996. {
  1997. char targetPath[std::strlen(pData->oscData->path)+20];
  1998. std::strcpy(targetPath, pData->oscData->path);
  1999. std::strcat(targetPath, "/bridge_set_program");
  2000. lo_send(pData->oscData->target, targetPath, "i", index);
  2001. }
  2002. }
  2003. void CarlaEngine::oscSend_bridge_set_midi_program(const int32_t index)
  2004. {
  2005. CARLA_ASSERT(pData->oscData != nullptr);
  2006. carla_debug("CarlaEngine::oscSend_bridge_set_midi_program(%i)", index);
  2007. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  2008. {
  2009. char targetPath[std::strlen(pData->oscData->path)+25];
  2010. std::strcpy(targetPath, pData->oscData->path);
  2011. std::strcat(targetPath, "/bridge_set_midi_program");
  2012. lo_send(pData->oscData->target, targetPath, "i", index);
  2013. }
  2014. }
  2015. void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  2016. {
  2017. CARLA_ASSERT(pData->oscData != nullptr);
  2018. carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  2019. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  2020. {
  2021. char targetPath[std::strlen(pData->oscData->path)+24];
  2022. std::strcpy(targetPath, pData->oscData->path);
  2023. std::strcat(targetPath, "/bridge_set_custom_data");
  2024. lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
  2025. }
  2026. }
  2027. void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile)
  2028. {
  2029. CARLA_ASSERT(pData->oscData != nullptr);
  2030. carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
  2031. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  2032. {
  2033. char targetPath[std::strlen(pData->oscData->path)+23];
  2034. std::strcpy(targetPath, pData->oscData->path);
  2035. std::strcat(targetPath, "/bridge_set_chunk_data");
  2036. lo_send(pData->oscData->target, targetPath, "s", chunkFile);
  2037. }
  2038. }
  2039. #endif
  2040. CARLA_BACKEND_END_NAMESPACE