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.

2860 lines
106KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 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. /* TODO:
  18. * - complete processRack(): carefully add to input, sorted events
  19. * - implement processPatchbay()
  20. * - implement oscSend_control_switch_plugins()
  21. * - proper find&load plugins
  22. * - something about the peaks?
  23. * - patchbayDisconnect should return false sometimes
  24. */
  25. #include "CarlaEngineInternal.hpp"
  26. #include "CarlaPlugin.hpp"
  27. #include "CarlaBackendUtils.hpp"
  28. #include "CarlaEngineUtils.hpp"
  29. #include "CarlaMathUtils.hpp"
  30. #include "CarlaStateUtils.hpp"
  31. #include "CarlaMIDI.h"
  32. #include <QtCore/QDir>
  33. #include <QtCore/QFile>
  34. #include <QtCore/QFileInfo>
  35. #include <QtCore/QTextStream>
  36. #include <QtXml/QDomNode>
  37. // -----------------------------------------------------------------------
  38. CARLA_BACKEND_START_NAMESPACE
  39. #if 0
  40. } // Fix editor indentation
  41. #endif
  42. // -----------------------------------------------------------------------
  43. // EngineControlEvent
  44. void EngineControlEvent::convertToMidiData(const uint8_t channel, uint8_t& size, uint8_t data[3]) const noexcept
  45. {
  46. size = 0;
  47. switch (type)
  48. {
  49. case kEngineControlEventTypeNull:
  50. break;
  51. case kEngineControlEventTypeParameter:
  52. if (param >= MAX_MIDI_VALUE)
  53. {
  54. // out of bounds. do nothing
  55. }
  56. else if (MIDI_IS_CONTROL_BANK_SELECT(param))
  57. {
  58. size = 3;
  59. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE | (channel & MIDI_CHANNEL_BIT));
  60. data[1] = MIDI_CONTROL_BANK_SELECT;
  61. data[2] = uint8_t(carla_fixValue<float>(0.0f, float(MAX_MIDI_VALUE-1), value));
  62. }
  63. else
  64. {
  65. size = 3;
  66. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE | (channel & MIDI_CHANNEL_BIT));
  67. data[1] = static_cast<uint8_t>(param);
  68. data[2] = uint8_t(carla_fixValue<float>(0.0f, 1.0f, value) * float(MAX_MIDI_VALUE-1));
  69. }
  70. break;
  71. case kEngineControlEventTypeMidiBank:
  72. size = 3;
  73. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE | (channel & MIDI_CHANNEL_BIT));
  74. data[1] = MIDI_CONTROL_BANK_SELECT;
  75. data[2] = uint8_t(carla_fixValue<uint16_t>(0, MAX_MIDI_VALUE-1, param));
  76. break;
  77. case kEngineControlEventTypeMidiProgram:
  78. size = 2;
  79. data[0] = static_cast<uint8_t>(MIDI_STATUS_PROGRAM_CHANGE | (channel & MIDI_CHANNEL_BIT));
  80. data[1] = uint8_t(carla_fixValue<uint16_t>(0, MAX_MIDI_VALUE-1, param));
  81. break;
  82. case kEngineControlEventTypeAllSoundOff:
  83. size = 2;
  84. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE | (channel & MIDI_CHANNEL_BIT));
  85. data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  86. break;
  87. case kEngineControlEventTypeAllNotesOff:
  88. size = 2;
  89. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE | (channel & MIDI_CHANNEL_BIT));
  90. data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  91. break;
  92. }
  93. }
  94. // -----------------------------------------------------------------------
  95. // EngineEvent
  96. void EngineEvent::fillFromMidiData(const uint8_t size, const uint8_t* const data) noexcept
  97. {
  98. if (size == 0 || data == nullptr || data[0] < MIDI_STATUS_NOTE_OFF)
  99. {
  100. type = kEngineEventTypeNull;
  101. channel = 0;
  102. return;
  103. }
  104. // get channel
  105. channel = uint8_t(MIDI_GET_CHANNEL_FROM_DATA(data));
  106. // get status
  107. const uint8_t midiStatus(uint8_t(MIDI_GET_STATUS_FROM_DATA(data)));
  108. if (midiStatus == MIDI_STATUS_CONTROL_CHANGE)
  109. {
  110. type = kEngineEventTypeControl;
  111. const uint8_t midiControl(data[1]);
  112. if (MIDI_IS_CONTROL_BANK_SELECT(midiControl))
  113. {
  114. CARLA_SAFE_ASSERT_INT(size == 3, size);
  115. const uint8_t midiBank(data[2]);
  116. ctrl.type = kEngineControlEventTypeMidiBank;
  117. ctrl.param = midiBank;
  118. ctrl.value = 0.0f;
  119. }
  120. else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF)
  121. {
  122. CARLA_SAFE_ASSERT_INT(size == 2, size);
  123. ctrl.type = kEngineControlEventTypeAllSoundOff;
  124. ctrl.param = 0;
  125. ctrl.value = 0.0f;
  126. }
  127. else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF)
  128. {
  129. CARLA_SAFE_ASSERT_INT(size == 2, size);
  130. ctrl.type = kEngineControlEventTypeAllNotesOff;
  131. ctrl.param = 0;
  132. ctrl.value = 0.0f;
  133. }
  134. else
  135. {
  136. CARLA_SAFE_ASSERT_INT2(size == 3, size, midiControl);
  137. const uint8_t midiValue(carla_fixValue<uint8_t>(0, 127, data[2])); // ensures 0.0<->1.0 value range
  138. ctrl.type = kEngineControlEventTypeParameter;
  139. ctrl.param = midiControl;
  140. ctrl.value = float(midiValue)/127.0f;
  141. }
  142. }
  143. else if (midiStatus == MIDI_STATUS_PROGRAM_CHANGE)
  144. {
  145. CARLA_SAFE_ASSERT_INT2(size == 2, size, data[1]);
  146. type = kEngineEventTypeControl;
  147. const uint8_t midiProgram(data[1]);
  148. ctrl.type = kEngineControlEventTypeMidiProgram;
  149. ctrl.param = midiProgram;
  150. ctrl.value = 0.0f;
  151. }
  152. else
  153. {
  154. type = kEngineEventTypeMidi;
  155. midi.port = 0;
  156. midi.size = size;
  157. if (size > EngineMidiEvent::kDataSize)
  158. {
  159. midi.dataExt = data;
  160. std::memset(midi.data, 0, sizeof(uint8_t)*EngineMidiEvent::kDataSize);
  161. }
  162. else
  163. {
  164. midi.data[0] = midiStatus;
  165. uint8_t i=1;
  166. for (; i < midi.size; ++i)
  167. midi.data[i] = data[i];
  168. for (; i < EngineMidiEvent::kDataSize; ++i)
  169. midi.data[i] = 0;
  170. midi.dataExt = nullptr;
  171. }
  172. }
  173. }
  174. // -----------------------------------------------------------------------
  175. // EngineOptions
  176. EngineOptions::EngineOptions() noexcept
  177. #ifdef CARLA_OS_LINUX
  178. : processMode(ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS),
  179. transportMode(ENGINE_TRANSPORT_MODE_JACK),
  180. #else
  181. : processMode(ENGINE_PROCESS_MODE_CONTINUOUS_RACK),
  182. transportMode(ENGINE_TRANSPORT_MODE_INTERNAL),
  183. #endif
  184. forceStereo(false),
  185. preferPluginBridges(false),
  186. preferUiBridges(true),
  187. uisAlwaysOnTop(true),
  188. maxParameters(MAX_DEFAULT_PARAMETERS),
  189. uiBridgesTimeout(4000),
  190. audioNumPeriods(2),
  191. audioBufferSize(512),
  192. audioSampleRate(44100),
  193. audioDevice(nullptr),
  194. binaryDir(nullptr),
  195. resourceDir(nullptr),
  196. frontendWinId(0) {}
  197. EngineOptions::~EngineOptions() noexcept
  198. {
  199. if (audioDevice != nullptr)
  200. {
  201. delete[] audioDevice;
  202. audioDevice = nullptr;
  203. }
  204. if (binaryDir != nullptr)
  205. {
  206. delete[] binaryDir;
  207. binaryDir = nullptr;
  208. }
  209. if (resourceDir != nullptr)
  210. {
  211. delete[] resourceDir;
  212. resourceDir = nullptr;
  213. }
  214. }
  215. // -----------------------------------------------------------------------
  216. // EngineTimeInfoBBT
  217. EngineTimeInfoBBT::EngineTimeInfoBBT() noexcept
  218. : bar(0),
  219. beat(0),
  220. tick(0),
  221. barStartTick(0.0),
  222. beatsPerBar(0.0f),
  223. beatType(0.0f),
  224. ticksPerBeat(0.0),
  225. beatsPerMinute(0.0) {}
  226. // -----------------------------------------------------------------------
  227. // EngineTimeInfo
  228. EngineTimeInfo::EngineTimeInfo() noexcept
  229. : playing(false),
  230. frame(0),
  231. usecs(0),
  232. valid(0x0) {}
  233. void EngineTimeInfo::clear() noexcept
  234. {
  235. playing = false;
  236. frame = 0;
  237. usecs = 0;
  238. valid = 0x0;
  239. }
  240. bool EngineTimeInfo::operator==(const EngineTimeInfo& timeInfo) const noexcept
  241. {
  242. if (timeInfo.playing != playing || timeInfo.frame != frame || timeInfo.valid != valid)
  243. return false;
  244. if ((valid & kValidBBT) == 0)
  245. return true;
  246. if (timeInfo.bbt.beatsPerMinute != bbt.beatsPerMinute)
  247. return false;
  248. return true;
  249. }
  250. bool EngineTimeInfo::operator!=(const EngineTimeInfo& timeInfo) const noexcept
  251. {
  252. return !operator==(timeInfo);
  253. }
  254. // -----------------------------------------------------------------------
  255. // Carla Engine client (Abstract)
  256. CarlaEngineClient::CarlaEngineClient(const CarlaEngine& engine)
  257. : fEngine(engine),
  258. fActive(false),
  259. fLatency(0)
  260. {
  261. carla_debug("CarlaEngineClient::CarlaEngineClient()");
  262. }
  263. CarlaEngineClient::~CarlaEngineClient()
  264. {
  265. CARLA_SAFE_ASSERT(! fActive);
  266. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  267. }
  268. void CarlaEngineClient::activate() noexcept
  269. {
  270. CARLA_SAFE_ASSERT(! fActive);
  271. carla_debug("CarlaEngineClient::activate()");
  272. fActive = true;
  273. }
  274. void CarlaEngineClient::deactivate() noexcept
  275. {
  276. CARLA_SAFE_ASSERT(fActive);
  277. carla_debug("CarlaEngineClient::deactivate()");
  278. fActive = false;
  279. }
  280. bool CarlaEngineClient::isActive() const noexcept
  281. {
  282. return fActive;
  283. }
  284. bool CarlaEngineClient::isOk() const noexcept
  285. {
  286. return true;
  287. }
  288. uint32_t CarlaEngineClient::getLatency() const noexcept
  289. {
  290. return fLatency;
  291. }
  292. void CarlaEngineClient::setLatency(const uint32_t samples) noexcept
  293. {
  294. fLatency = samples;
  295. }
  296. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput) noexcept
  297. {
  298. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  299. carla_debug("CarlaEngineClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput));
  300. CarlaEnginePort* ret = nullptr;
  301. try {
  302. switch (portType)
  303. {
  304. case kEnginePortTypeNull:
  305. break;
  306. case kEnginePortTypeAudio:
  307. ret = new CarlaEngineAudioPort(fEngine, isInput);
  308. case kEnginePortTypeCV:
  309. ret = new CarlaEngineCVPort(fEngine, isInput);
  310. case kEnginePortTypeEvent:
  311. ret = new CarlaEngineEventPort(fEngine, isInput);
  312. }
  313. }
  314. CARLA_SAFE_EXCEPTION_RETURN("new CarlaEnginePort", nullptr);
  315. if (ret != nullptr)
  316. return ret;
  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. : pData(new CarlaEngineProtectedData(this))
  324. {
  325. carla_debug("CarlaEngine::CarlaEngine()");
  326. }
  327. CarlaEngine::~CarlaEngine()
  328. {
  329. carla_debug("CarlaEngine::~CarlaEngine()");
  330. delete pData;
  331. }
  332. // -----------------------------------------------------------------------
  333. // Static calls
  334. unsigned int CarlaEngine::getDriverCount()
  335. {
  336. carla_debug("CarlaEngine::getDriverCount()");
  337. unsigned int count = 1; // JACK
  338. #ifndef BUILD_BRIDGE
  339. count += getRtAudioApiCount();
  340. # ifdef HAVE_JUCE
  341. count += getJuceApiCount();
  342. # endif
  343. #endif
  344. return count;
  345. }
  346. const char* CarlaEngine::getDriverName(const unsigned int index)
  347. {
  348. carla_debug("CarlaEngine::getDriverName(%i)", index);
  349. if (index == 0)
  350. return "JACK";
  351. #ifndef BUILD_BRIDGE
  352. const unsigned int rtAudioIndex(index-1);
  353. if (rtAudioIndex < getRtAudioApiCount())
  354. return getRtAudioApiName(rtAudioIndex);
  355. # ifdef HAVE_JUCE
  356. const unsigned int juceIndex(index-rtAudioIndex-1);
  357. if (juceIndex < getJuceApiCount())
  358. return getJuceApiName(juceIndex);
  359. # endif
  360. #endif
  361. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
  362. return nullptr;
  363. }
  364. const char* const* CarlaEngine::getDriverDeviceNames(const unsigned int index)
  365. {
  366. carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index);
  367. if (index == 0) // JACK
  368. {
  369. static const char* ret[3] = { "Auto-Connect OFF", "Auto-Connect ON", nullptr };
  370. return ret;
  371. }
  372. #ifndef BUILD_BRIDGE
  373. const unsigned int rtAudioIndex(index-1);
  374. if (rtAudioIndex < getRtAudioApiCount())
  375. return getRtAudioApiDeviceNames(rtAudioIndex);
  376. # ifdef HAVE_JUCE
  377. const unsigned int juceIndex(index-rtAudioIndex-1);
  378. if (juceIndex < getJuceApiCount())
  379. return getJuceApiDeviceNames(juceIndex);
  380. # endif
  381. #endif
  382. carla_stderr("CarlaEngine::getDriverDeviceNames(%i) - invalid index", index);
  383. return nullptr;
  384. }
  385. const EngineDriverDeviceInfo* CarlaEngine::getDriverDeviceInfo(const unsigned int index, const char* const deviceName)
  386. {
  387. carla_debug("CarlaEngine::getDriverDeviceInfo(%i, \"%s\")", index, deviceName);
  388. if (index == 0) // JACK
  389. {
  390. static uint32_t bufSizes[11] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 0 };
  391. static EngineDriverDeviceInfo devInfo;
  392. devInfo.hints = ENGINE_DRIVER_DEVICE_VARIABLE_BUFFER_SIZE;
  393. devInfo.bufferSizes = bufSizes;
  394. devInfo.sampleRates = nullptr;
  395. return &devInfo;
  396. }
  397. #ifndef BUILD_BRIDGE
  398. const unsigned int rtAudioIndex(index-1);
  399. if (rtAudioIndex < getRtAudioApiCount())
  400. return getRtAudioDeviceInfo(rtAudioIndex, deviceName);
  401. # ifdef HAVE_JUCE
  402. const unsigned int juceIndex(index-rtAudioIndex-1);
  403. if (juceIndex < getJuceApiCount())
  404. return getJuceDeviceInfo(juceIndex, deviceName);
  405. # endif
  406. #endif
  407. carla_stderr("CarlaEngine::getDriverDeviceNames(%i, \"%s\") - invalid index", index, deviceName);
  408. return nullptr;
  409. }
  410. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  411. {
  412. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', nullptr);
  413. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  414. if (std::strcmp(driverName, "JACK") == 0)
  415. return newJack();
  416. // common
  417. if (std::strncmp(driverName, "JACK ", 5) == 0)
  418. return newRtAudio(AUDIO_API_JACK);
  419. // linux
  420. #if 0//def HAVE_JUCE
  421. if (std::strcmp(driverName, "ALSA") == 0)
  422. return newJuce(AUDIO_API_ALSA);
  423. #else
  424. if (std::strcmp(driverName, "ALSA") == 0)
  425. return newRtAudio(AUDIO_API_ALSA);
  426. #endif
  427. if (std::strcmp(driverName, "OSS") == 0)
  428. return newRtAudio(AUDIO_API_OSS);
  429. if (std::strcmp(driverName, "PulseAudio") == 0)
  430. return newRtAudio(AUDIO_API_PULSE);
  431. // macos
  432. #if 0//def HAVE_JUCE
  433. if (std::strcmp(driverName, "CoreAudio") == 0)
  434. return newJuce(AUDIO_API_CORE);
  435. #else
  436. if (std::strcmp(driverName, "CoreAudio") == 0)
  437. return newRtAudio(AUDIO_API_CORE);
  438. #endif
  439. // windows
  440. #if 0//def HAVE_JUCE
  441. if (std::strcmp(driverName, "ASIO") == 0)
  442. return newJuce(AUDIO_API_ASIO);
  443. if (std::strcmp(driverName, "DirectSound") == 0)
  444. return newJuce(AUDIO_API_DS);
  445. #else
  446. if (std::strcmp(driverName, "ASIO") == 0)
  447. return newRtAudio(AUDIO_API_ASIO);
  448. if (std::strcmp(driverName, "DirectSound") == 0)
  449. return newRtAudio(AUDIO_API_DS);
  450. #endif
  451. carla_stderr("CarlaEngine::newDriverByName(\"%s\") - invalid driver name", driverName);
  452. return nullptr;
  453. }
  454. // -----------------------------------------------------------------------
  455. // Maximum values
  456. unsigned int CarlaEngine::getMaxClientNameSize() const noexcept
  457. {
  458. return STR_MAX/2;
  459. }
  460. unsigned int CarlaEngine::getMaxPortNameSize() const noexcept
  461. {
  462. return STR_MAX;
  463. }
  464. unsigned int CarlaEngine::getCurrentPluginCount() const noexcept
  465. {
  466. return pData->curPluginCount;
  467. }
  468. unsigned int CarlaEngine::getMaxPluginNumber() const noexcept
  469. {
  470. return pData->maxPluginNumber;
  471. }
  472. // -----------------------------------------------------------------------
  473. // Virtual, per-engine type calls
  474. bool CarlaEngine::init(const char* const clientName)
  475. {
  476. CARLA_SAFE_ASSERT_RETURN_ERR(pData->name.isEmpty(), "Invalid engine internal data (err #1)");
  477. CARLA_SAFE_ASSERT_RETURN_ERR(pData->oscData == nullptr, "Invalid engine internal data (err #2)");
  478. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins == nullptr, "Invalid engine internal data (err #3)");
  479. CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.in == nullptr, "Invalid engine internal data (err #4)");
  480. CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.out == nullptr, "Invalid engine internal data (err #5)");
  481. CARLA_SAFE_ASSERT_RETURN_ERR(clientName != nullptr && clientName[0] != '\0', "Invalid client name");
  482. carla_debug("CarlaEngine::init(\"%s\")", clientName);
  483. pData->aboutToClose = false;
  484. pData->curPluginCount = 0;
  485. pData->maxPluginNumber = 0;
  486. pData->nextPluginId = 0;
  487. switch (pData->options.processMode)
  488. {
  489. case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  490. case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  491. pData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
  492. break;
  493. case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  494. pData->maxPluginNumber = MAX_RACK_PLUGINS;
  495. pData->bufEvents.in = new EngineEvent[kMaxEngineEventInternalCount];
  496. pData->bufEvents.out = new EngineEvent[kMaxEngineEventInternalCount];
  497. break;
  498. case ENGINE_PROCESS_MODE_PATCHBAY:
  499. pData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
  500. break;
  501. case ENGINE_PROCESS_MODE_BRIDGE:
  502. pData->maxPluginNumber = 1;
  503. pData->bufEvents.in = new EngineEvent[kMaxEngineEventInternalCount];
  504. pData->bufEvents.out = new EngineEvent[kMaxEngineEventInternalCount];
  505. break;
  506. }
  507. CARLA_SAFE_ASSERT_RETURN_ERR(pData->maxPluginNumber != 0, "Invalid engine process mode");
  508. pData->nextPluginId = pData->maxPluginNumber;
  509. pData->name = clientName;
  510. pData->name.toBasic();
  511. pData->timeInfo.clear();
  512. pData->plugins = new EnginePluginData[pData->maxPluginNumber];
  513. for (uint i=0; i < pData->maxPluginNumber; ++i)
  514. pData->plugins[i].clear();
  515. pData->osc.init(clientName);
  516. #ifndef BUILD_BRIDGE
  517. pData->oscData = pData->osc.getControlData();
  518. #endif
  519. pData->nextAction.ready();
  520. pData->thread.startThread();
  521. callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, 0, 0, 0.0f, getCurrentDriverName());
  522. return true;
  523. }
  524. bool CarlaEngine::close()
  525. {
  526. CARLA_SAFE_ASSERT_RETURN_ERR(pData->name.isNotEmpty(), "Invalid engine internal data (err #6)");
  527. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #7)");
  528. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #8)");
  529. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #9)");
  530. carla_debug("CarlaEngine::close()");
  531. pData->aboutToClose = true;
  532. if (pData->curPluginCount != 0)
  533. removeAllPlugins();
  534. pData->thread.stopThread(500);
  535. pData->nextAction.ready();
  536. #ifndef BUILD_BRIDGE
  537. if (pData->osc.isControlRegistered())
  538. oscSend_control_exit();
  539. #endif
  540. pData->osc.close();
  541. pData->oscData = nullptr;
  542. pData->curPluginCount = 0;
  543. pData->maxPluginNumber = 0;
  544. pData->nextPluginId = 0;
  545. if (pData->plugins != nullptr)
  546. {
  547. delete[] pData->plugins;
  548. pData->plugins = nullptr;
  549. }
  550. if (pData->bufEvents.in != nullptr)
  551. {
  552. delete[] pData->bufEvents.in;
  553. pData->bufEvents.in = nullptr;
  554. }
  555. if (pData->bufEvents.out != nullptr)
  556. {
  557. delete[] pData->bufEvents.out;
  558. pData->bufEvents.out = nullptr;
  559. }
  560. pData->name.clear();
  561. callback(ENGINE_CALLBACK_ENGINE_STOPPED, 0, 0, 0, 0.0f, nullptr);
  562. return true;
  563. }
  564. void CarlaEngine::idle()
  565. {
  566. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull,); // TESTING, remove later
  567. CARLA_SAFE_ASSERT_RETURN(pData->nextPluginId == pData->maxPluginNumber,); // TESTING, remove later
  568. CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr,); // this one too maybe
  569. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  570. {
  571. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  572. if (plugin != nullptr && plugin->isEnabled())
  573. plugin->idle();
  574. }
  575. idleOsc();
  576. }
  577. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  578. {
  579. return new CarlaEngineClient(*this);
  580. }
  581. // -----------------------------------------------------------------------
  582. // Plugin management
  583. bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, const int64_t uniqueId, const void* const extra)
  584. {
  585. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #10)");
  586. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId <= pData->maxPluginNumber, "Invalid engine internal data (err #11)");
  587. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #12)");
  588. CARLA_SAFE_ASSERT_RETURN_ERR(btype != BINARY_NONE, "Invalid plugin params (err #1)");
  589. CARLA_SAFE_ASSERT_RETURN_ERR(ptype != PLUGIN_NONE, "Invalid plugin params (err #2)");
  590. CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin params (err #3)");
  591. carla_debug("CarlaEngine::addPlugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p)", btype, BinaryType2Str(btype), ptype, PluginType2Str(ptype), filename, name, label, uniqueId, extra);
  592. unsigned int id;
  593. CarlaPlugin* oldPlugin = nullptr;
  594. if (pData->nextPluginId < pData->curPluginCount)
  595. {
  596. id = pData->nextPluginId;
  597. pData->nextPluginId = pData->maxPluginNumber;
  598. oldPlugin = pData->plugins[id].plugin;
  599. CARLA_SAFE_ASSERT_RETURN_ERR(oldPlugin != nullptr, "Invalid replace plugin Id");
  600. }
  601. else
  602. {
  603. id = pData->curPluginCount;
  604. if (id == pData->maxPluginNumber)
  605. {
  606. setLastError("Maximum number of plugins reached");
  607. return false;
  608. }
  609. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins[id].plugin == nullptr, "Invalid engine internal data (err #13)");
  610. }
  611. CarlaPlugin::Initializer initializer = {
  612. this,
  613. id,
  614. filename,
  615. name,
  616. label,
  617. uniqueId
  618. };
  619. CarlaPlugin* plugin = nullptr;
  620. #ifndef BUILD_BRIDGE
  621. CarlaString bridgeBinary(pData->options.binaryDir);
  622. if (bridgeBinary.isNotEmpty())
  623. {
  624. # ifdef CARLA_OS_LINUX
  625. // test for local build
  626. if (bridgeBinary.endsWith("/source/backend/"))
  627. bridgeBinary += "../bridges/";
  628. # endif
  629. # ifndef CARLA_OS_WIN
  630. if (btype == BINARY_NATIVE)
  631. {
  632. bridgeBinary += "carla-bridge-native";
  633. }
  634. else
  635. # endif
  636. {
  637. switch (btype)
  638. {
  639. case BINARY_POSIX32:
  640. bridgeBinary += "carla-bridge-posix32";
  641. break;
  642. case BINARY_POSIX64:
  643. bridgeBinary += "carla-bridge-posix64";
  644. break;
  645. case BINARY_WIN32:
  646. bridgeBinary += "carla-bridge-win32.exe";
  647. break;
  648. case BINARY_WIN64:
  649. bridgeBinary += "carla-bridge-win64.exe";
  650. break;
  651. default:
  652. bridgeBinary.clear();
  653. break;
  654. }
  655. }
  656. QFile file(bridgeBinary.buffer());
  657. if (! file.exists())
  658. bridgeBinary.clear();
  659. }
  660. if (ptype != PLUGIN_INTERNAL && ptype != PLUGIN_JACK && (btype != BINARY_NATIVE || (pData->options.preferPluginBridges && bridgeBinary.isNotEmpty())))
  661. {
  662. if (bridgeBinary.isNotEmpty())
  663. {
  664. plugin = CarlaPlugin::newBridge(initializer, btype, ptype, bridgeBinary);
  665. }
  666. # ifdef CARLA_OS_LINUX
  667. else if (btype == BINARY_WIN32)
  668. {
  669. // fallback to dssi-vst
  670. QFileInfo fileInfo(filename);
  671. CarlaString label2(fileInfo.fileName().toUtf8().constData());
  672. label2.replace(' ', '*');
  673. CarlaPlugin::Initializer init2 = {
  674. this,
  675. id,
  676. "/usr/lib/dssi/dssi-vst.so",
  677. name,
  678. label2,
  679. uniqueId
  680. };
  681. char* const oldVstPath(getenv("VST_PATH"));
  682. carla_setenv("VST_PATH", fileInfo.absoluteDir().absolutePath().toUtf8().constData());
  683. plugin = CarlaPlugin::newDSSI(init2);
  684. if (oldVstPath != nullptr)
  685. carla_setenv("VST_PATH", oldVstPath);
  686. }
  687. # endif
  688. else
  689. {
  690. setLastError("This Carla build cannot handle this binary");
  691. return false;
  692. }
  693. }
  694. else
  695. #endif // ! BUILD_BRIDGE
  696. {
  697. bool use16Outs;
  698. setLastError("Invalid or unsupported plugin type");
  699. switch (ptype)
  700. {
  701. case PLUGIN_NONE:
  702. break;
  703. case PLUGIN_INTERNAL:
  704. if (std::strcmp(label, "Csound") == 0)
  705. {
  706. plugin = CarlaPlugin::newCsound(initializer);
  707. }
  708. else if (std::strcmp(label, "FluidSynth") == 0)
  709. {
  710. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  711. plugin = CarlaPlugin::newFluidSynth(initializer, use16Outs);
  712. }
  713. else if (std::strcmp(label, "LinuxSampler (GIG)") == 0)
  714. {
  715. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  716. plugin = CarlaPlugin::newLinuxSampler(initializer, "GIG", use16Outs);
  717. }
  718. else if (std::strcmp(label, "LinuxSampler (SF2)") == 0)
  719. {
  720. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  721. plugin = CarlaPlugin::newLinuxSampler(initializer, "SF2", use16Outs);
  722. }
  723. else if (std::strcmp(label, "LinuxSampler (SFZ)") == 0)
  724. {
  725. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  726. plugin = CarlaPlugin::newLinuxSampler(initializer, "SFZ", use16Outs);
  727. }
  728. else
  729. {
  730. plugin = CarlaPlugin::newNative(initializer);
  731. }
  732. break;
  733. case PLUGIN_LADSPA:
  734. plugin = CarlaPlugin::newLADSPA(initializer, (const LADSPA_RDF_Descriptor*)extra);
  735. break;
  736. case PLUGIN_DSSI:
  737. plugin = CarlaPlugin::newDSSI(initializer);
  738. break;
  739. case PLUGIN_LV2:
  740. plugin = CarlaPlugin::newLV2(initializer);
  741. break;
  742. case PLUGIN_VST:
  743. plugin = CarlaPlugin::newVST(initializer);
  744. break;
  745. case PLUGIN_VST3:
  746. plugin = CarlaPlugin::newVST3(initializer);
  747. break;
  748. case PLUGIN_AU:
  749. plugin = CarlaPlugin::newAU(initializer);
  750. break;
  751. case PLUGIN_JACK:
  752. plugin = CarlaPlugin::newJACK(initializer);
  753. break;
  754. case PLUGIN_REWIRE:
  755. plugin = CarlaPlugin::newReWire(initializer);
  756. break;
  757. case PLUGIN_FILE_CSD:
  758. plugin = CarlaPlugin::newFileCSD(initializer);
  759. break;
  760. case PLUGIN_FILE_GIG:
  761. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  762. plugin = CarlaPlugin::newFileGIG(initializer, use16Outs);
  763. break;
  764. case PLUGIN_FILE_SF2:
  765. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  766. plugin = CarlaPlugin::newFileSF2(initializer, use16Outs);
  767. break;
  768. case PLUGIN_FILE_SFZ:
  769. plugin = CarlaPlugin::newFileSFZ(initializer);
  770. break;
  771. }
  772. }
  773. if (plugin == nullptr)
  774. {
  775. pData->plugins[id].plugin = oldPlugin;
  776. return false;
  777. }
  778. plugin->registerToOscClient();
  779. EnginePluginData& pluginData(pData->plugins[id]);
  780. pluginData.plugin = plugin;
  781. pluginData.insPeak[0] = 0.0f;
  782. pluginData.insPeak[1] = 0.0f;
  783. pluginData.outsPeak[0] = 0.0f;
  784. pluginData.outsPeak[1] = 0.0f;
  785. if (oldPlugin != nullptr)
  786. {
  787. delete oldPlugin;
  788. callback(ENGINE_CALLBACK_RELOAD_ALL, id, 0, 0, 0.0f, plugin->getName());
  789. }
  790. else
  791. {
  792. ++pData->curPluginCount;
  793. callback(ENGINE_CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
  794. if (pData->curPluginCount == 1 && pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
  795. callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED, 0, PATCHBAY_ICON_CARLA, 0, 0.0f, nullptr);
  796. }
  797. return true;
  798. }
  799. bool CarlaEngine::addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const int64_t uniqueId, const void* const extra)
  800. {
  801. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, uniqueId, extra);
  802. }
  803. bool CarlaEngine::removePlugin(const unsigned int id)
  804. {
  805. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #14)");
  806. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #15)");
  807. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #16)");
  808. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #1)");
  809. carla_debug("CarlaEngine::removePlugin(%i)", id);
  810. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  811. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove");
  812. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #17)");
  813. pData->thread.stopThread(500);
  814. const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
  815. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionRemovePlugin, id, 0, lockWait);
  816. #ifndef BUILD_BRIDGE
  817. if (isOscControlRegistered())
  818. oscSend_control_remove_plugin(id);
  819. #endif
  820. delete plugin;
  821. if (isRunning() && ! pData->aboutToClose)
  822. pData->thread.startThread();
  823. callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  824. return true;
  825. }
  826. bool CarlaEngine::removeAllPlugins()
  827. {
  828. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #18)");
  829. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #19)");
  830. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #20)");
  831. carla_debug("CarlaEngine::removeAllPlugins()");
  832. if (pData->curPluginCount == 0)
  833. return true;
  834. pData->thread.stopThread(500);
  835. const bool lockWait(isRunning());
  836. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait);
  837. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  838. for (unsigned int i=0; i < pData->maxPluginNumber; ++i)
  839. {
  840. EnginePluginData& pluginData(pData->plugins[i]);
  841. if (pluginData.plugin != nullptr)
  842. {
  843. delete pluginData.plugin;
  844. pluginData.plugin = nullptr;
  845. }
  846. pluginData.insPeak[0] = 0.0f;
  847. pluginData.insPeak[1] = 0.0f;
  848. pluginData.outsPeak[0] = 0.0f;
  849. pluginData.outsPeak[1] = 0.0f;
  850. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  851. }
  852. if (isRunning() && ! pData->aboutToClose)
  853. pData->thread.startThread();
  854. return true;
  855. }
  856. const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
  857. {
  858. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #21)");
  859. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #22)");
  860. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #23)");
  861. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #2)");
  862. CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name");
  863. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  864. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  865. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin != nullptr, "Could not find plugin to rename");
  866. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin->getId() == id, "Invalid engine internal data (err #24)");
  867. if (const char* const name = getUniquePluginName(newName))
  868. {
  869. plugin->setName(name);
  870. return name;
  871. }
  872. setLastError("Unable to get new unique plugin name");
  873. return nullptr;
  874. }
  875. bool CarlaEngine::clonePlugin(const unsigned int id)
  876. {
  877. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #25)");
  878. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #26)");
  879. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #27)");
  880. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #3)");
  881. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  882. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  883. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to clone");
  884. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #28)");
  885. char label[STR_MAX+1];
  886. carla_zeroChar(label, STR_MAX+1);
  887. plugin->getLabel(label);
  888. const unsigned int pluginCountBefore(pData->curPluginCount);
  889. if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getUniqueId(), plugin->getExtraStuff()))
  890. return false;
  891. CARLA_SAFE_ASSERT_RETURN_ERR(pluginCountBefore+1 == pData->curPluginCount, "No new plugin found");
  892. if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
  893. newPlugin->loadSaveState(plugin->getSaveState());
  894. return true;
  895. }
  896. bool CarlaEngine::replacePlugin(const unsigned int id)
  897. {
  898. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #29)");
  899. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)");
  900. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)");
  901. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  902. // might use this to reset
  903. if (id == pData->curPluginCount || id == pData->maxPluginNumber)
  904. {
  905. pData->nextPluginId = pData->maxPluginNumber;
  906. return true;
  907. }
  908. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #4)");
  909. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  910. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to replace");
  911. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #32)");
  912. pData->nextPluginId = id;
  913. return true;
  914. }
  915. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  916. {
  917. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #33)");
  918. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount >= 2, "Invalid engine internal data (err #34)");
  919. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #35)");
  920. CARLA_SAFE_ASSERT_RETURN_ERR(idA != idB, "Invalid operation, cannot switch plugin with itself");
  921. CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id (err #5)");
  922. CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id (err #6)");
  923. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  924. CarlaPlugin* const pluginA(pData->plugins[idA].plugin);
  925. CarlaPlugin* const pluginB(pData->plugins[idB].plugin);
  926. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #1)");
  927. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #2)");
  928. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data (err #36)");
  929. CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data (err #37)");
  930. pData->thread.stopThread(500);
  931. const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
  932. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  933. #ifndef BUILD_BRIDGE // TODO
  934. //if (isOscControlRegistered())
  935. // oscSend_control_switch_plugins(idA, idB);
  936. #endif
  937. if (isRunning() && ! pData->aboutToClose)
  938. pData->thread.startThread();
  939. return true;
  940. }
  941. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  942. {
  943. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #38)");
  944. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #39)");
  945. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #40)");
  946. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #7)");
  947. return pData->plugins[id].plugin;
  948. }
  949. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const noexcept
  950. {
  951. return pData->plugins[id].plugin;
  952. }
  953. const char* CarlaEngine::getUniquePluginName(const char* const name) const
  954. {
  955. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr);
  956. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  957. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  958. CarlaString sname;
  959. sname = name;
  960. if (sname.isEmpty())
  961. {
  962. sname = "(No name)";
  963. return sname.dup();
  964. }
  965. const size_t maxNameSize(carla_min<uint>(getMaxClientNameSize(), 0xff, 6) - 6); // 6 = strlen(" (10)") + 1
  966. if (maxNameSize == 0 || ! isRunning())
  967. return sname.dup();
  968. sname.truncate(maxNameSize);
  969. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  970. for (unsigned short i=0; i < pData->curPluginCount; ++i)
  971. {
  972. CARLA_SAFE_ASSERT_BREAK(pData->plugins[i].plugin != nullptr);
  973. // Check if unique name doesn't exist
  974. if (const char* const pluginName = pData->plugins[i].plugin->getName())
  975. {
  976. if (sname != pluginName)
  977. continue;
  978. }
  979. // Check if string has already been modified
  980. {
  981. const size_t len(sname.length());
  982. // 1 digit, ex: " (2)"
  983. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  984. {
  985. int number = sname[len-2] - '0';
  986. if (number == 9)
  987. {
  988. // next number is 10, 2 digits
  989. sname.truncate(len-4);
  990. sname += " (10)";
  991. //sname.replace(" (9)", " (10)");
  992. }
  993. else
  994. sname[len-2] = char('0' + number + 1);
  995. continue;
  996. }
  997. // 2 digits, ex: " (11)"
  998. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  999. {
  1000. char n2 = sname[len-2];
  1001. char n3 = sname[len-3];
  1002. if (n2 == '9')
  1003. {
  1004. n2 = '0';
  1005. n3 = static_cast<char>(n3 + 1);
  1006. }
  1007. else
  1008. n2 = static_cast<char>(n2 + 1);
  1009. sname[len-2] = n2;
  1010. sname[len-3] = n3;
  1011. continue;
  1012. }
  1013. }
  1014. // Modify string if not
  1015. sname += " (2)";
  1016. }
  1017. return sname.dup();
  1018. }
  1019. // -----------------------------------------------------------------------
  1020. // Project management
  1021. bool CarlaEngine::loadFile(const char* const filename)
  1022. {
  1023. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #1)");
  1024. carla_debug("CarlaEngine::loadFile(\"%s\")", filename);
  1025. QFileInfo fileInfo(filename);
  1026. if (! fileInfo.exists())
  1027. {
  1028. setLastError("File does not exist");
  1029. return false;
  1030. }
  1031. if (! fileInfo.isFile())
  1032. {
  1033. setLastError("Not a file");
  1034. return false;
  1035. }
  1036. if (! fileInfo.isReadable())
  1037. {
  1038. setLastError("File is not readable");
  1039. return false;
  1040. }
  1041. CarlaString baseName(fileInfo.baseName().toUtf8().constData());
  1042. CarlaString extension(fileInfo.suffix().toLower().toUtf8().constData());
  1043. extension.toLower();
  1044. // -------------------------------------------------------------------
  1045. if (extension == "carxp" || extension == "carxs")
  1046. return loadProject(filename);
  1047. // -------------------------------------------------------------------
  1048. if (extension == "csd")
  1049. return addPlugin(PLUGIN_FILE_CSD, filename, baseName, baseName, 0, nullptr);
  1050. if (extension == "gig")
  1051. return addPlugin(PLUGIN_FILE_GIG, filename, baseName, baseName, 0, nullptr);
  1052. if (extension == "sf2")
  1053. return addPlugin(PLUGIN_FILE_SF2, filename, baseName, baseName, 0, nullptr);
  1054. if (extension == "sfz")
  1055. return addPlugin(PLUGIN_FILE_SFZ, filename, baseName, baseName, 0, nullptr);
  1056. // -------------------------------------------------------------------
  1057. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  1058. {
  1059. #ifdef WANT_AUDIOFILE
  1060. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile", 0, nullptr))
  1061. {
  1062. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1063. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1064. return true;
  1065. }
  1066. return false;
  1067. #else
  1068. setLastError("This Carla build does not have Audio file support");
  1069. return false;
  1070. #endif
  1071. }
  1072. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  1073. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  1074. {
  1075. #ifdef WANT_AUDIOFILE
  1076. # ifdef HAVE_FFMPEG
  1077. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile", 0, nullptr))
  1078. {
  1079. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1080. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1081. return true;
  1082. }
  1083. return false;
  1084. # else
  1085. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  1086. return false;
  1087. # endif
  1088. #else
  1089. setLastError("This Carla build does not have Audio file support");
  1090. return false;
  1091. #endif
  1092. }
  1093. // -------------------------------------------------------------------
  1094. if (extension == "mid" || extension == "midi")
  1095. {
  1096. #ifdef WANT_MIDIFILE
  1097. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile", 0, nullptr))
  1098. {
  1099. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1100. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1101. return true;
  1102. }
  1103. return false;
  1104. #else
  1105. setLastError("This Carla build does not have MIDI file support");
  1106. return false;
  1107. #endif
  1108. }
  1109. // -------------------------------------------------------------------
  1110. // ZynAddSubFX
  1111. if (extension == "xmz" || extension == "xiz")
  1112. {
  1113. #ifdef WANT_ZYNADDSUBFX
  1114. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx", 0, nullptr))
  1115. {
  1116. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1117. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  1118. return true;
  1119. }
  1120. return false;
  1121. #else
  1122. setLastError("This Carla build does not have ZynAddSubFX support");
  1123. return false;
  1124. #endif
  1125. }
  1126. // -------------------------------------------------------------------
  1127. setLastError("Unknown file extension");
  1128. return false;
  1129. }
  1130. bool CarlaEngine::loadProject(const char* const filename)
  1131. {
  1132. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #2)");
  1133. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1134. QFile file(filename);
  1135. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  1136. return false;
  1137. QDomDocument xml;
  1138. xml.setContent(file.readAll());
  1139. file.close();
  1140. QDomNode xmlNode(xml.documentElement());
  1141. const bool isPreset(xmlNode.toElement().tagName().compare("carla-preset", Qt::CaseInsensitive) == 0);
  1142. if (xmlNode.toElement().tagName().compare("carla-project", Qt::CaseInsensitive) != 0 && ! isPreset)
  1143. {
  1144. setLastError("Not a valid Carla project or preset file");
  1145. return false;
  1146. }
  1147. // handle plugins first
  1148. for (QDomNode node = xmlNode.firstChild(); ! node.isNull(); node = node.nextSibling())
  1149. {
  1150. if (isPreset || node.toElement().tagName().compare("plugin", Qt::CaseInsensitive) == 0)
  1151. {
  1152. SaveState saveState;
  1153. fillSaveStateFromXmlNode(saveState, isPreset ? xmlNode : node);
  1154. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1155. CARLA_SAFE_ASSERT_CONTINUE(saveState.type != nullptr);
  1156. const void* extraStuff = nullptr;
  1157. // check if using GIG, SF2 or SFZ 16outs
  1158. static const char kUse16OutsSuffix[] = " (16 outs)";
  1159. const PluginType ptype(getPluginTypeFromString(saveState.type));
  1160. if (CarlaString(saveState.label).endsWith(kUse16OutsSuffix))
  1161. {
  1162. if (ptype == PLUGIN_FILE_GIG || ptype == PLUGIN_FILE_SF2)
  1163. extraStuff = "true";
  1164. }
  1165. // TODO - proper find&load plugins
  1166. if (addPlugin(ptype, saveState.binary, saveState.name, saveState.label, saveState.uniqueId, extraStuff))
  1167. {
  1168. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1169. plugin->loadSaveState(saveState);
  1170. }
  1171. else
  1172. carla_stderr2("Failed to load a plugin, error was:%s\n", getLastError());
  1173. }
  1174. if (isPreset)
  1175. return true;
  1176. }
  1177. #ifndef BUILD_BRIDGE
  1178. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1179. // now connections
  1180. for (QDomNode node = xmlNode.firstChild(); ! node.isNull(); node = node.nextSibling())
  1181. {
  1182. if (node.toElement().tagName().compare("patchbay", Qt::CaseInsensitive) == 0)
  1183. {
  1184. CarlaString sourcePort, targetPort;
  1185. for (QDomNode patchNode = node.firstChild(); ! patchNode.isNull(); patchNode = patchNode.nextSibling())
  1186. {
  1187. sourcePort.clear();
  1188. targetPort.clear();
  1189. if (patchNode.toElement().tagName().compare("connection", Qt::CaseInsensitive) != 0)
  1190. continue;
  1191. for (QDomNode connNode = patchNode.firstChild(); ! connNode.isNull(); connNode = connNode.nextSibling())
  1192. {
  1193. const QString tag(connNode.toElement().tagName());
  1194. const QString text(connNode.toElement().text().trimmed());
  1195. if (tag.compare("source", Qt::CaseInsensitive) == 0)
  1196. sourcePort = text.toUtf8().constData();
  1197. else if (tag.compare("target", Qt::CaseInsensitive) == 0)
  1198. targetPort = text.toUtf8().constData();
  1199. }
  1200. if (sourcePort.isNotEmpty() && targetPort.isNotEmpty())
  1201. restorePatchbayConnection(sourcePort, targetPort);
  1202. }
  1203. break;
  1204. }
  1205. }
  1206. #endif
  1207. return true;
  1208. }
  1209. bool CarlaEngine::saveProject(const char* const filename)
  1210. {
  1211. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #3)");
  1212. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1213. QFile file(filename);
  1214. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1215. return false;
  1216. QTextStream out(&file);
  1217. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1218. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1219. out << "<CARLA-PROJECT VERSION='2.0'>\n";
  1220. bool firstPlugin = true;
  1221. char strBuf[STR_MAX+1];
  1222. for (uint i=0; i < pData->curPluginCount; ++i)
  1223. {
  1224. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1225. if (plugin != nullptr && plugin->isEnabled())
  1226. {
  1227. if (! firstPlugin)
  1228. out << "\n";
  1229. strBuf[0] = '\0';
  1230. plugin->getRealName(strBuf);
  1231. //if (strBuf[0] != '\0')
  1232. // out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1233. QString content;
  1234. fillXmlStringFromSaveState(content, plugin->getSaveState());
  1235. out << " <Plugin>\n";
  1236. out << content;
  1237. out << " </Plugin>\n";
  1238. firstPlugin = false;
  1239. }
  1240. }
  1241. #ifndef BUILD_BRIDGE
  1242. if (const char* const* patchbayConns = getPatchbayConnections())
  1243. {
  1244. if (! firstPlugin)
  1245. out << "\n";
  1246. out << " <Patchbay>\n";
  1247. for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i )
  1248. {
  1249. const char* const connSource(patchbayConns[i]);
  1250. const char* const connTarget(patchbayConns[i+1]);
  1251. CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0');
  1252. CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0');
  1253. out << " <Connection>\n";
  1254. out << " <Source>" << connSource << "</Source>\n";
  1255. out << " <Target>" << connTarget << "</Target>\n";
  1256. out << " </Connection>\n";
  1257. delete[] connSource;
  1258. delete[] connTarget;
  1259. }
  1260. out << " </Patchbay>\n";
  1261. }
  1262. #endif
  1263. out << "</CARLA-PROJECT>\n";
  1264. file.close();
  1265. return true;
  1266. }
  1267. // -----------------------------------------------------------------------
  1268. // Information (base)
  1269. unsigned int CarlaEngine::getHints() const noexcept
  1270. {
  1271. return pData->hints;
  1272. }
  1273. uint32_t CarlaEngine::getBufferSize() const noexcept
  1274. {
  1275. return pData->bufferSize;
  1276. }
  1277. double CarlaEngine::getSampleRate() const noexcept
  1278. {
  1279. return pData->sampleRate;
  1280. }
  1281. const char* CarlaEngine::getName() const noexcept
  1282. {
  1283. return pData->name;
  1284. }
  1285. EngineProcessMode CarlaEngine::getProccessMode() const noexcept
  1286. {
  1287. return pData->options.processMode;
  1288. }
  1289. const EngineOptions& CarlaEngine::getOptions() const noexcept
  1290. {
  1291. return pData->options;
  1292. }
  1293. const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept
  1294. {
  1295. return pData->timeInfo;
  1296. }
  1297. // -----------------------------------------------------------------------
  1298. // Information (peaks)
  1299. float CarlaEngine::getInputPeak(const unsigned int pluginId, const bool isLeft) const noexcept
  1300. {
  1301. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1302. return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1];
  1303. }
  1304. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) const noexcept
  1305. {
  1306. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1307. return pData->plugins[pluginId].outsPeak[isLeft ? 0 : 1];
  1308. }
  1309. // -----------------------------------------------------------------------
  1310. // Callback
  1311. void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept
  1312. {
  1313. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  1314. if (pData->callback != nullptr)
  1315. {
  1316. try {
  1317. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1318. } catch(...) {}
  1319. }
  1320. }
  1321. void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept
  1322. {
  1323. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1324. pData->callback = func;
  1325. pData->callbackPtr = ptr;
  1326. }
  1327. // -----------------------------------------------------------------------
  1328. // File Callback
  1329. const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept
  1330. {
  1331. CARLA_SAFE_ASSERT_RETURN(title != nullptr && title[0] != '\0', nullptr);
  1332. CARLA_SAFE_ASSERT_RETURN(filter != nullptr, nullptr);
  1333. carla_debug("CarlaEngine::runFileCallback(%i:%s, %s, \"%s\", \"%s\")", action, FileCallbackOpcode2Str(action), bool2str(isDir), title, filter);
  1334. const char* ret = nullptr;
  1335. if (pData->fileCallback != nullptr)
  1336. {
  1337. try {
  1338. ret = pData->fileCallback(pData->fileCallbackPtr, action, isDir, title, filter);
  1339. } catch(...) {}
  1340. }
  1341. return ret;
  1342. }
  1343. void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept
  1344. {
  1345. carla_debug("CarlaEngine::setFileCallback(%p, %p)", func, ptr);
  1346. pData->fileCallback = func;
  1347. pData->fileCallbackPtr = ptr;
  1348. }
  1349. #ifndef BUILD_BRIDGE
  1350. // -----------------------------------------------------------------------
  1351. // Patchbay
  1352. bool CarlaEngine::patchbayConnect(const int groupA, const int portA, const int groupB, const int portB)
  1353. {
  1354. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1355. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1356. carla_debug("CarlaEngine::patchbayConnect(%i, %i)", portA, portB);
  1357. if (portA < 0 || portB < 0)
  1358. {
  1359. setLastError("Invalid connection");
  1360. return false;
  1361. }
  1362. return pData->bufAudio.connect(this, groupA, portA, groupB, portB);
  1363. }
  1364. bool CarlaEngine::patchbayDisconnect(const uint connectionId)
  1365. {
  1366. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1367. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1368. carla_debug("CarlaEngineRtAudio::patchbayDisconnect(%i)", connectionId);
  1369. if (pData->bufAudio.usePatchbay)
  1370. {
  1371. // not implemented yet
  1372. return false;
  1373. }
  1374. #if 0
  1375. EngineRackBuffers* const rack(pData->bufAudio.rack);
  1376. CARLA_SAFE_ASSERT_RETURN_ERR(rack->usedConnections.count() > 0, "No connections available");
  1377. for (LinkedList<ConnectionToId>::Itenerator it=rack->usedConnections.begin(); it.valid(); it.next())
  1378. {
  1379. const ConnectionToId& connection(it.getValue());
  1380. if (connection.id == connectionId)
  1381. {
  1382. const int otherPort((connection.portOut >= 0) ? connection.portOut : connection.portIn);
  1383. const int carlaPort((otherPort == connection.portOut) ? connection.portIn : connection.portOut);
  1384. if (otherPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000)
  1385. {
  1386. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_MIDI_IN, false);
  1387. const int portId(otherPort-RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1388. disconnectRackMidiInPort(portId);
  1389. }
  1390. else if (otherPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000)
  1391. {
  1392. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_MIDI_OUT, false);
  1393. const int portId(otherPort-RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1394. disconnectRackMidiOutPort(portId);
  1395. }
  1396. else if (otherPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000)
  1397. {
  1398. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT2, false);
  1399. const int portId(otherPort-RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1400. rack->connectLock.enter();
  1401. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1)
  1402. rack->connectedOut1.removeAll(portId);
  1403. else
  1404. rack->connectedOut2.removeAll(portId);
  1405. rack->connectLock.leave();
  1406. }
  1407. else if (otherPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000)
  1408. {
  1409. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN2, false);
  1410. const int portId(otherPort-RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1411. rack->connectLock.enter();
  1412. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1)
  1413. rack->connectedIn1.removeAll(portId);
  1414. else
  1415. rack->connectedIn2.removeAll(portId);
  1416. rack->connectLock.leave();
  1417. }
  1418. else
  1419. {
  1420. CARLA_SAFE_ASSERT_RETURN(false, false);
  1421. }
  1422. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED, connection.id, 0, 0, 0.0f, nullptr);
  1423. rack->usedConnections.remove(it);
  1424. return true;
  1425. }
  1426. }
  1427. #endif
  1428. setLastError("Failed to find connection");
  1429. return false;
  1430. }
  1431. bool CarlaEngine::patchbayRefresh()
  1432. {
  1433. setLastError("Unsupported operation");
  1434. return false;
  1435. }
  1436. #endif
  1437. // -----------------------------------------------------------------------
  1438. // Transport
  1439. void CarlaEngine::transportPlay() noexcept
  1440. {
  1441. pData->time.playing = true;
  1442. }
  1443. void CarlaEngine::transportPause() noexcept
  1444. {
  1445. pData->time.playing = false;
  1446. }
  1447. void CarlaEngine::transportRelocate(const uint64_t frame) noexcept
  1448. {
  1449. pData->time.frame = frame;
  1450. }
  1451. // -----------------------------------------------------------------------
  1452. // Error handling
  1453. const char* CarlaEngine::getLastError() const noexcept
  1454. {
  1455. return pData->lastError;
  1456. }
  1457. void CarlaEngine::setLastError(const char* const error) const noexcept
  1458. {
  1459. pData->lastError = error;
  1460. }
  1461. void CarlaEngine::setAboutToClose() noexcept
  1462. {
  1463. carla_debug("CarlaEngine::setAboutToClose()");
  1464. pData->aboutToClose = true;
  1465. }
  1466. // -----------------------------------------------------------------------
  1467. // Global options
  1468. void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr)
  1469. {
  1470. carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
  1471. if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
  1472. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
  1473. switch (option)
  1474. {
  1475. case ENGINE_OPTION_DEBUG:
  1476. break;
  1477. case ENGINE_OPTION_PROCESS_MODE:
  1478. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
  1479. pData->options.processMode = static_cast<EngineProcessMode>(value);
  1480. break;
  1481. case ENGINE_OPTION_TRANSPORT_MODE:
  1482. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
  1483. pData->options.transportMode = static_cast<EngineTransportMode>(value);
  1484. break;
  1485. case ENGINE_OPTION_FORCE_STEREO:
  1486. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1487. pData->options.forceStereo = (value != 0);
  1488. break;
  1489. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  1490. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1491. pData->options.preferPluginBridges = (value != 0);
  1492. break;
  1493. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  1494. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1495. pData->options.preferUiBridges = (value != 0);
  1496. break;
  1497. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  1498. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1499. pData->options.uisAlwaysOnTop = (value != 0);
  1500. break;
  1501. case ENGINE_OPTION_MAX_PARAMETERS:
  1502. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1503. pData->options.maxParameters = static_cast<uint>(value);
  1504. break;
  1505. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  1506. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1507. pData->options.uiBridgesTimeout = static_cast<uint>(value);
  1508. break;
  1509. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  1510. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  1511. pData->options.audioNumPeriods = static_cast<uint>(value);
  1512. break;
  1513. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  1514. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  1515. pData->options.audioBufferSize = static_cast<uint>(value);
  1516. break;
  1517. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  1518. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  1519. pData->options.audioSampleRate = static_cast<uint>(value);
  1520. break;
  1521. case ENGINE_OPTION_AUDIO_DEVICE:
  1522. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  1523. if (pData->options.audioDevice != nullptr)
  1524. delete[] pData->options.audioDevice;
  1525. pData->options.audioDevice = carla_strdup(valueStr);
  1526. break;
  1527. case ENGINE_OPTION_PATH_BINARIES:
  1528. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1529. if (pData->options.binaryDir != nullptr)
  1530. delete[] pData->options.binaryDir;
  1531. pData->options.binaryDir = carla_strdup(valueStr);
  1532. break;
  1533. case ENGINE_OPTION_PATH_RESOURCES:
  1534. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1535. if (pData->options.resourceDir != nullptr)
  1536. delete[] pData->options.resourceDir;
  1537. pData->options.resourceDir = carla_strdup(valueStr);
  1538. break;
  1539. case ENGINE_OPTION_FRONTEND_WIN_ID:
  1540. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1541. const long winId(std::atol(valueStr));
  1542. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  1543. pData->options.frontendWinId = static_cast<uintptr_t>(winId);
  1544. break;
  1545. }
  1546. }
  1547. // -----------------------------------------------------------------------
  1548. // OSC Stuff
  1549. #ifdef BUILD_BRIDGE
  1550. bool CarlaEngine::isOscBridgeRegistered() const noexcept
  1551. {
  1552. return (pData->oscData != nullptr);
  1553. }
  1554. #else
  1555. bool CarlaEngine::isOscControlRegistered() const noexcept
  1556. {
  1557. return pData->osc.isControlRegistered();
  1558. }
  1559. #endif
  1560. void CarlaEngine::idleOsc() const noexcept
  1561. {
  1562. try {
  1563. pData->osc.idle();
  1564. } catch(...) {}
  1565. }
  1566. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1567. {
  1568. return pData->osc.getServerPathTCP();
  1569. }
  1570. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1571. {
  1572. return pData->osc.getServerPathUDP();
  1573. }
  1574. #ifdef BUILD_BRIDGE
  1575. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept
  1576. {
  1577. pData->oscData = oscData;
  1578. }
  1579. #endif
  1580. // -----------------------------------------------------------------------
  1581. // Helper functions
  1582. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1583. {
  1584. return isInput ? pData->bufEvents.in : pData->bufEvents.out;
  1585. }
  1586. void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept
  1587. {
  1588. CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,);
  1589. carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin);
  1590. pData->plugins[id].plugin = plugin;
  1591. }
  1592. // -----------------------------------------------------------------------
  1593. // Internal stuff
  1594. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1595. {
  1596. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1597. for (uint i=0; i < pData->curPluginCount; ++i)
  1598. {
  1599. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1600. if (plugin != nullptr && plugin->isEnabled())
  1601. plugin->bufferSizeChanged(newBufferSize);
  1602. }
  1603. callback(ENGINE_CALLBACK_BUFFER_SIZE_CHANGED, 0, static_cast<int>(newBufferSize), 0, 0.0f, nullptr);
  1604. }
  1605. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1606. {
  1607. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1608. for (uint i=0; i < pData->curPluginCount; ++i)
  1609. {
  1610. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1611. if (plugin != nullptr && plugin->isEnabled())
  1612. plugin->sampleRateChanged(newSampleRate);
  1613. }
  1614. callback(ENGINE_CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, static_cast<float>(newSampleRate), nullptr);
  1615. }
  1616. void CarlaEngine::offlineModeChanged(const bool isOfflineNow)
  1617. {
  1618. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOfflineNow));
  1619. for (uint i=0; i < pData->curPluginCount; ++i)
  1620. {
  1621. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1622. if (plugin != nullptr && plugin->isEnabled())
  1623. plugin->offlineModeChanged(isOfflineNow);
  1624. }
  1625. }
  1626. void CarlaEngine::runPendingRtEvents() noexcept
  1627. {
  1628. pData->doNextPluginAction(true);
  1629. if (pData->time.playing)
  1630. pData->time.frame += pData->bufferSize;
  1631. if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL)
  1632. {
  1633. pData->timeInfo.playing = pData->time.playing;
  1634. pData->timeInfo.frame = pData->time.frame;
  1635. }
  1636. }
  1637. void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1638. {
  1639. EnginePluginData& pluginData(pData->plugins[pluginId]);
  1640. pluginData.insPeak[0] = inPeaks[0];
  1641. pluginData.insPeak[1] = inPeaks[1];
  1642. pluginData.outsPeak[0] = outPeaks[0];
  1643. pluginData.outsPeak[1] = outPeaks[1];
  1644. }
  1645. #ifndef BUILD_BRIDGE
  1646. // -----------------------------------------------------------------------
  1647. // Patchbay stuff
  1648. const char* const* CarlaEngine::getPatchbayConnections() const
  1649. {
  1650. carla_debug("CarlaEngine::getPatchbayConnections()");
  1651. return pData->bufAudio.getConnections();
  1652. }
  1653. void CarlaEngine::restorePatchbayConnection(const char* const connSource, const char* const connTarget)
  1654. {
  1655. CARLA_SAFE_ASSERT_RETURN(connSource != nullptr && connSource[0] != '\0',);
  1656. CARLA_SAFE_ASSERT_RETURN(connTarget != nullptr && connTarget[0] != '\0',);
  1657. carla_debug("CarlaEngine::restorePatchbayConnection(\"%s\", \"%s\")", connSource, connTarget);
  1658. #if 0
  1659. if (pData->bufAudio.usePatchbay)
  1660. {
  1661. // TODO
  1662. }
  1663. else
  1664. {
  1665. int sourceGroup, targetGroup;
  1666. int sourcePort, targetPort;
  1667. if (std::strncmp(connSource, "Carla:", 6) == 0)
  1668. {
  1669. sourceGroup = RACK_PATCHBAY_GROUP_CARLA;
  1670. sourcePort = getCarlaPortIdFromName(connSource+6);
  1671. }
  1672. else if (std::strncmp(connSource, "AudioIn:", 8) == 0)
  1673. {
  1674. sourceGroup = RACK_PATCHBAY_GROUP_AUDIO_IN;
  1675. sourcePort = std::atoi(connSource+8) - 1;
  1676. }
  1677. else if (std::strncmp(connSource, "AudioOut:", 9) == 0)
  1678. {
  1679. sourceGroup = RACK_PATCHBAY_GROUP_AUDIO_OUT;
  1680. sourcePort = std::atoi(connSource+9) - 1;
  1681. }
  1682. else if (std::strncmp(connSource, "MidiIn:", 7) == 0)
  1683. {
  1684. sourceGroup = RACK_PATCHBAY_GROUP_MIDI_IN;
  1685. sourcePort = std::atoi(connSource+7) - 1;
  1686. }
  1687. else if (std::strncmp(connSource, "MidiOut:", 8) == 0)
  1688. {
  1689. sourceGroup = RACK_PATCHBAY_GROUP_MIDI_OUT;
  1690. sourcePort = std::atoi(connSource+8) - 1;
  1691. }
  1692. else
  1693. {
  1694. sourceGroup = RACK_PATCHBAY_GROUP_MAX;
  1695. sourcePort = RACK_PATCHBAY_PORT_MAX;
  1696. }
  1697. if (std::strncmp(connTarget, "Carla:", 6) == 0)
  1698. {
  1699. targetGroup = RACK_PATCHBAY_GROUP_CARLA;
  1700. targetPort = getCarlaPortIdFromName(connTarget+6);
  1701. }
  1702. else if (std::strncmp(connTarget, "AudioIn:", 8) == 0)
  1703. {
  1704. targetGroup = RACK_PATCHBAY_GROUP_AUDIO_IN;
  1705. targetPort = std::atoi(connTarget+8) - 1;
  1706. }
  1707. else if (std::strncmp(connTarget, "AudioOut:", 9) == 0)
  1708. {
  1709. targetGroup = RACK_PATCHBAY_GROUP_AUDIO_OUT;
  1710. targetPort = std::atoi(connTarget+9) - 1;
  1711. }
  1712. else if (std::strncmp(connTarget, "MidiIn:", 7) == 0)
  1713. {
  1714. targetGroup = RACK_PATCHBAY_GROUP_MIDI_IN;
  1715. targetPort = std::atoi(connTarget+7) - 1;
  1716. }
  1717. else if (std::strncmp(connTarget, "MidiOut:", 8) == 0)
  1718. {
  1719. targetGroup = RACK_PATCHBAY_GROUP_MIDI_OUT;
  1720. targetPort = std::atoi(connTarget+8) - 1;
  1721. }
  1722. else
  1723. {
  1724. targetGroup = RACK_PATCHBAY_GROUP_MAX;
  1725. targetPort = RACK_PATCHBAY_PORT_MAX;
  1726. }
  1727. CARLA_SAFE_ASSERT_RETURN(sourceGroup == RACK_PATCHBAY_GROUP_MAX || sourcePort == RACK_PATCHBAY_PORT_MAX,);
  1728. CARLA_SAFE_ASSERT_RETURN(targetGroup == RACK_PATCHBAY_GROUP_MAX || targetPort == RACK_PATCHBAY_PORT_MAX,);
  1729. patchbayConnect(targetGroup, targetPort, sourceGroup, sourcePort);
  1730. }
  1731. #endif
  1732. }
  1733. #endif
  1734. // -----------------------------------------------------------------------
  1735. // Bridge/Controller OSC stuff
  1736. #ifdef BUILD_BRIDGE
  1737. void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept
  1738. {
  1739. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1740. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1741. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1742. carla_debug("CarlaEngine::oscSend_bridge_plugin_info1(%i:%s, %X, " P_INT64 ")", category, PluginCategory2Str(category), hints, uniqueId);
  1743. char targetPath[std::strlen(pData->oscData->path)+21];
  1744. std::strcpy(targetPath, pData->oscData->path);
  1745. std::strcat(targetPath, "/bridge_plugin_info1");
  1746. try_lo_send(pData->oscData->target, targetPath, "iih", static_cast<int32_t>(category), static_cast<int32_t>(hints), uniqueId);
  1747. }
  1748. void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  1749. {
  1750. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1751. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1752. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1753. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  1754. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  1755. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  1756. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  1757. carla_debug("CarlaEngine::oscSend_bridge_plugin_info2(\"%s\", \"%s\", \"%s\", \"%s\")", realName, label, maker, copyright);
  1758. char targetPath[std::strlen(pData->oscData->path)+21];
  1759. std::strcpy(targetPath, pData->oscData->path);
  1760. std::strcat(targetPath, "/bridge_plugin_info2");
  1761. try_lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright);
  1762. }
  1763. void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept
  1764. {
  1765. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1766. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1767. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1768. carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i)", ins, outs);
  1769. char targetPath[std::strlen(pData->oscData->path)+20];
  1770. std::strcpy(targetPath, pData->oscData->path);
  1771. std::strcat(targetPath, "/bridge_audio_count");
  1772. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1773. }
  1774. void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept
  1775. {
  1776. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1777. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1778. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1779. carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i)", ins, outs);
  1780. char targetPath[std::strlen(pData->oscData->path)+19];
  1781. std::strcpy(targetPath, pData->oscData->path);
  1782. std::strcat(targetPath, "/bridge_midi_count");
  1783. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1784. }
  1785. void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept
  1786. {
  1787. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1788. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1789. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1790. carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i)", ins, outs);
  1791. char targetPath[std::strlen(pData->oscData->path)+24];
  1792. std::strcpy(targetPath, pData->oscData->path);
  1793. std::strcat(targetPath, "/bridge_parameter_count");
  1794. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1795. }
  1796. void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const noexcept
  1797. {
  1798. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1799. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1800. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1801. carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
  1802. char targetPath[std::strlen(pData->oscData->path)+23];
  1803. std::strcpy(targetPath, pData->oscData->path);
  1804. std::strcat(targetPath, "/bridge_program_count");
  1805. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1806. }
  1807. void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const noexcept
  1808. {
  1809. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1810. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1811. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1812. carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
  1813. char targetPath[std::strlen(pData->oscData->path)+27];
  1814. std::strcpy(targetPath, pData->oscData->path);
  1815. std::strcat(targetPath, "/bridge_midi_program_count");
  1816. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1817. }
  1818. void CarlaEngine::oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept
  1819. {
  1820. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1821. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1822. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1823. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1824. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  1825. carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", index, rindex, type, ParameterType2Str(type), hints, name, unit);
  1826. char targetPath[std::strlen(pData->oscData->path)+23];
  1827. std::strcpy(targetPath, pData->oscData->path);
  1828. std::strcat(targetPath, "/bridge_parameter_data");
  1829. try_lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast<int32_t>(index), static_cast<int32_t>(rindex), static_cast<int32_t>(type), static_cast<int32_t>(hints), name, unit);
  1830. }
  1831. void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept
  1832. {
  1833. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1834. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1835. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1836. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, def, min, max);
  1837. char targetPath[std::strlen(pData->oscData->path)+26];
  1838. std::strcpy(targetPath, pData->oscData->path);
  1839. std::strcat(targetPath, "/bridge_parameter_ranges1");
  1840. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), def, min, max);
  1841. }
  1842. void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  1843. {
  1844. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1845. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1846. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1847. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, step, stepSmall, stepLarge);
  1848. char targetPath[std::strlen(pData->oscData->path)+26];
  1849. std::strcpy(targetPath, pData->oscData->path);
  1850. std::strcat(targetPath, "/bridge_parameter_ranges2");
  1851. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), step, stepSmall, stepLarge);
  1852. }
  1853. void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept
  1854. {
  1855. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1856. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1857. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1858. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_cc(%i, %i)", index, cc);
  1859. char targetPath[std::strlen(pData->oscData->path)+26];
  1860. std::strcpy(targetPath, pData->oscData->path);
  1861. std::strcat(targetPath, "/bridge_parameter_midi_cc");
  1862. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(cc));
  1863. }
  1864. void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept
  1865. {
  1866. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1867. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1868. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1869. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_channel(%i, %i)", index, channel);
  1870. char targetPath[std::strlen(pData->oscData->path)+31];
  1871. std::strcpy(targetPath, pData->oscData->path);
  1872. std::strcat(targetPath, "/bridge_parameter_midi_channel");
  1873. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(channel));
  1874. }
  1875. void CarlaEngine::oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept
  1876. {
  1877. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1878. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1879. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1880. carla_debug("CarlaEngine::oscSend_bridge_parameter_value(%i, %f)", index, value);
  1881. char targetPath[std::strlen(pData->oscData->path)+24];
  1882. std::strcpy(targetPath, pData->oscData->path);
  1883. std::strcat(targetPath, "/bridge_parameter_value");
  1884. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1885. }
  1886. void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept
  1887. {
  1888. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1889. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1890. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1891. carla_debug("CarlaEngine::oscSend_bridge_default_value(%i, %f)", index, value);
  1892. char targetPath[std::strlen(pData->oscData->path)+22];
  1893. std::strcpy(targetPath, pData->oscData->path);
  1894. std::strcat(targetPath, "/bridge_default_value");
  1895. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1896. }
  1897. void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const noexcept
  1898. {
  1899. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1900. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1901. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1902. carla_debug("CarlaEngine::oscSend_bridge_current_program(%i)", index);
  1903. char targetPath[std::strlen(pData->oscData->path)+24];
  1904. std::strcpy(targetPath, pData->oscData->path);
  1905. std::strcat(targetPath, "/bridge_current_program");
  1906. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1907. }
  1908. void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const noexcept
  1909. {
  1910. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1911. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1912. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1913. carla_debug("CarlaEngine::oscSend_bridge_current_midi_program(%i)", index);
  1914. char targetPath[std::strlen(pData->oscData->path)+30];
  1915. std::strcpy(targetPath, pData->oscData->path);
  1916. std::strcat(targetPath, "/bridge_current_midi_program");
  1917. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1918. }
  1919. void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept
  1920. {
  1921. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1922. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1923. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1924. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1925. carla_debug("CarlaEngine::oscSend_bridge_program_name(%i, \"%s\")", index, name);
  1926. char targetPath[std::strlen(pData->oscData->path)+21];
  1927. std::strcpy(targetPath, pData->oscData->path);
  1928. std::strcat(targetPath, "/bridge_program_name");
  1929. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(index), name);
  1930. }
  1931. void CarlaEngine::oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept
  1932. {
  1933. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1934. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1935. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1936. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1937. carla_debug("CarlaEngine::oscSend_bridge_midi_program_data(%i, %i, %i, \"%s\")", index, bank, program, name);
  1938. char targetPath[std::strlen(pData->oscData->path)+26];
  1939. std::strcpy(targetPath, pData->oscData->path);
  1940. std::strcat(targetPath, "/bridge_midi_program_data");
  1941. try_lo_send(pData->oscData->target, targetPath, "iiis", static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  1942. }
  1943. void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const noexcept
  1944. {
  1945. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1946. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1947. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1948. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1949. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1950. carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
  1951. char targetPath[std::strlen(pData->oscData->path)+18];
  1952. std::strcpy(targetPath, pData->oscData->path);
  1953. std::strcat(targetPath, "/bridge_configure");
  1954. try_lo_send(pData->oscData->target, targetPath, "ss", key, value);
  1955. }
  1956. void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept
  1957. {
  1958. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1959. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1960. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1961. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1962. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1963. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1964. carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1965. char targetPath[std::strlen(pData->oscData->path)+24];
  1966. std::strcpy(targetPath, pData->oscData->path);
  1967. std::strcat(targetPath, "/bridge_set_custom_data");
  1968. try_lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
  1969. }
  1970. void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept
  1971. {
  1972. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1973. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1974. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1975. CARLA_SAFE_ASSERT_RETURN(chunkFile != nullptr && chunkFile[0] != '\0',);
  1976. carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
  1977. char targetPath[std::strlen(pData->oscData->path)+23];
  1978. std::strcpy(targetPath, pData->oscData->path);
  1979. std::strcat(targetPath, "/bridge_set_chunk_data");
  1980. try_lo_send(pData->oscData->target, targetPath, "s", chunkFile);
  1981. }
  1982. void CarlaEngine::oscSend_bridge_pong() const noexcept
  1983. {
  1984. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1985. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1986. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1987. //carla_debug("CarlaEngine::oscSend_pong()");
  1988. char targetPath[std::strlen(pData->oscData->path)+13];
  1989. std::strcpy(targetPath, pData->oscData->path);
  1990. std::strcat(targetPath, "/bridge_pong");
  1991. try_lo_send(pData->oscData->target, targetPath, "");
  1992. }
  1993. #else
  1994. void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept
  1995. {
  1996. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1997. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1998. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1999. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2000. CARLA_SAFE_ASSERT_RETURN(pluginName != nullptr && pluginName[0] != '\0',);
  2001. carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  2002. char targetPath[std::strlen(pData->oscData->path)+18];
  2003. std::strcpy(targetPath, pData->oscData->path);
  2004. std::strcat(targetPath, "/add_plugin_start");
  2005. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(pluginId), pluginName);
  2006. }
  2007. void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const noexcept
  2008. {
  2009. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2010. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2011. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2012. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2013. carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
  2014. char targetPath[std::strlen(pData->oscData->path)+16];
  2015. std::strcpy(targetPath, pData->oscData->path);
  2016. std::strcat(targetPath, "/add_plugin_end");
  2017. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2018. }
  2019. void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const noexcept
  2020. {
  2021. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2022. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2023. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2024. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2025. carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
  2026. char targetPath[std::strlen(pData->oscData->path)+15];
  2027. std::strcpy(targetPath, pData->oscData->path);
  2028. std::strcat(targetPath, "/remove_plugin");
  2029. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2030. }
  2031. void CarlaEngine::oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept
  2032. {
  2033. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2034. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2035. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2036. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2037. CARLA_SAFE_ASSERT_RETURN(type != PLUGIN_NONE,);
  2038. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, %i:%s, %i:%s, %X, " P_INT64 ")", pluginId, type, PluginType2Str(type), category, PluginCategory2Str(category), hints, uniqueId);
  2039. char targetPath[std::strlen(pData->oscData->path)+18];
  2040. std::strcpy(targetPath, pData->oscData->path);
  2041. std::strcat(targetPath, "/set_plugin_info1");
  2042. try_lo_send(pData->oscData->target, targetPath, "iiiih", static_cast<int32_t>(pluginId), static_cast<int32_t>(type), static_cast<int32_t>(category), static_cast<int32_t>(hints), static_cast<int64_t>(uniqueId));
  2043. }
  2044. void CarlaEngine::oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  2045. {
  2046. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2047. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2048. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2049. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2050. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  2051. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  2052. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  2053. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  2054. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, \"%s\", \"%s\", \"%s\", \"%s\")", pluginId, realName, label, maker, copyright);
  2055. char targetPath[std::strlen(pData->oscData->path)+18];
  2056. std::strcpy(targetPath, pData->oscData->path);
  2057. std::strcat(targetPath, "/set_plugin_info2");
  2058. try_lo_send(pData->oscData->target, targetPath, "issss", static_cast<int32_t>(pluginId), realName, label, maker, copyright);
  2059. }
  2060. void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2061. {
  2062. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2063. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2064. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2065. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2066. carla_debug("CarlaEngine::oscSend_control_set_audio_count(%i, %i, %i)", pluginId, ins, outs);
  2067. char targetPath[std::strlen(pData->oscData->path)+18];
  2068. std::strcpy(targetPath, pData->oscData->path);
  2069. std::strcat(targetPath, "/set_audio_count");
  2070. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2071. }
  2072. void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2073. {
  2074. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2075. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2076. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2077. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2078. carla_debug("CarlaEngine::oscSend_control_set_midi_count(%i, %i, %i)", pluginId, ins, outs);
  2079. char targetPath[std::strlen(pData->oscData->path)+18];
  2080. std::strcpy(targetPath, pData->oscData->path);
  2081. std::strcat(targetPath, "/set_midi_count");
  2082. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2083. }
  2084. void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2085. {
  2086. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2087. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2088. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2089. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2090. carla_debug("CarlaEngine::oscSend_control_set_parameter_count(%i, %i, %i)", pluginId, ins, outs);
  2091. char targetPath[std::strlen(pData->oscData->path)+18];
  2092. std::strcpy(targetPath, pData->oscData->path);
  2093. std::strcat(targetPath, "/set_parameter_count");
  2094. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2095. }
  2096. void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept
  2097. {
  2098. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2099. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2100. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2101. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2102. carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
  2103. char targetPath[std::strlen(pData->oscData->path)+19];
  2104. std::strcpy(targetPath, pData->oscData->path);
  2105. std::strcat(targetPath, "/set_program_count");
  2106. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2107. }
  2108. void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept
  2109. {
  2110. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2111. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2112. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2113. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2114. carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
  2115. char targetPath[std::strlen(pData->oscData->path)+24];
  2116. std::strcpy(targetPath, pData->oscData->path);
  2117. std::strcat(targetPath, "/set_midi_program_count");
  2118. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2119. }
  2120. void CarlaEngine::oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept
  2121. {
  2122. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2123. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2124. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2125. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2126. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  2127. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  2128. carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", pluginId, index, type, ParameterType2Str(type), hints, name, unit);
  2129. char targetPath[std::strlen(pData->oscData->path)+20];
  2130. std::strcpy(targetPath, pData->oscData->path);
  2131. std::strcat(targetPath, "/set_parameter_data");
  2132. try_lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(type), static_cast<int32_t>(hints), name, unit);
  2133. }
  2134. void CarlaEngine::oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept
  2135. {
  2136. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2137. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2138. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2139. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2140. CARLA_SAFE_ASSERT_RETURN(def <= min && def >= max,);
  2141. CARLA_SAFE_ASSERT_RETURN(min < max,);
  2142. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges1(%i, %i, %f, %f, %f)", pluginId, index, def, min, max, def);
  2143. char targetPath[std::strlen(pData->oscData->path)+23];
  2144. std::strcpy(targetPath, pData->oscData->path);
  2145. std::strcat(targetPath, "/set_parameter_ranges1");
  2146. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), def, min, max);
  2147. }
  2148. void CarlaEngine::oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  2149. {
  2150. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2151. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2152. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2153. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2154. CARLA_SAFE_ASSERT_RETURN(step <= stepSmall && step >= stepLarge,);
  2155. CARLA_SAFE_ASSERT_RETURN(stepSmall <= stepLarge,);
  2156. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges2(%i, %i, %f, %f, %f)", pluginId, index, step, stepSmall, stepLarge);
  2157. char targetPath[std::strlen(pData->oscData->path)+23];
  2158. std::strcpy(targetPath, pData->oscData->path);
  2159. std::strcat(targetPath, "/set_parameter_ranges");
  2160. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), step, stepSmall, stepLarge);
  2161. }
  2162. void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept
  2163. {
  2164. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2165. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2166. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2167. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2168. CARLA_SAFE_ASSERT_RETURN(cc <= 0x5F,);
  2169. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  2170. char targetPath[std::strlen(pData->oscData->path)+23];
  2171. std::strcpy(targetPath, pData->oscData->path);
  2172. std::strcat(targetPath, "/set_parameter_midi_cc");
  2173. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(cc));
  2174. }
  2175. void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept
  2176. {
  2177. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2178. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2179. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2180. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2181. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2182. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  2183. char targetPath[std::strlen(pData->oscData->path)+28];
  2184. std::strcpy(targetPath, pData->oscData->path);
  2185. std::strcat(targetPath, "/set_parameter_midi_channel");
  2186. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(channel));
  2187. }
  2188. void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept
  2189. {
  2190. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2191. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2192. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2193. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2194. CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
  2195. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i:%s, %f)", pluginId, index, (index < 0) ? InternalParameterIndex2Str(static_cast<InternalParameterIndex>(index)) : "(none)", value);
  2196. char targetPath[std::strlen(pData->oscData->path)+21];
  2197. std::strcpy(targetPath, pData->oscData->path);
  2198. std::strcat(targetPath, "/set_parameter_value");
  2199. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), index, value);
  2200. }
  2201. void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept
  2202. {
  2203. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2204. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2205. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2206. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2207. carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  2208. char targetPath[std::strlen(pData->oscData->path)+19];
  2209. std::strcpy(targetPath, pData->oscData->path);
  2210. std::strcat(targetPath, "/set_default_value");
  2211. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), value);
  2212. }
  2213. void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept
  2214. {
  2215. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2216. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2217. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2218. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2219. carla_debug("CarlaEngine::oscSend_control_set_current_program(%i, %i)", pluginId, index);
  2220. char targetPath[std::strlen(pData->oscData->path)+21];
  2221. std::strcpy(targetPath, pData->oscData->path);
  2222. std::strcat(targetPath, "/set_current_program");
  2223. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2224. }
  2225. void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept
  2226. {
  2227. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2228. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2229. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2230. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2231. carla_debug("CarlaEngine::oscSend_control_set_current_midi_program(%i, %i)", pluginId, index);
  2232. char targetPath[std::strlen(pData->oscData->path)+26];
  2233. std::strcpy(targetPath, pData->oscData->path);
  2234. std::strcat(targetPath, "/set_current_midi_program");
  2235. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2236. }
  2237. void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept
  2238. {
  2239. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2240. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2241. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2242. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2243. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2244. carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  2245. char targetPath[std::strlen(pData->oscData->path)+18];
  2246. std::strcpy(targetPath, pData->oscData->path);
  2247. std::strcat(targetPath, "/set_program_name");
  2248. try_lo_send(pData->oscData->target, targetPath, "iis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), name);
  2249. }
  2250. void CarlaEngine::oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept
  2251. {
  2252. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2253. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2254. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2255. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2256. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2257. carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  2258. char targetPath[std::strlen(pData->oscData->path)+23];
  2259. std::strcpy(targetPath, pData->oscData->path);
  2260. std::strcat(targetPath, "/set_midi_program_data");
  2261. try_lo_send(pData->oscData->target, targetPath, "iiiis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  2262. }
  2263. void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept
  2264. {
  2265. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2266. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2267. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2268. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2269. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2270. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2271. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  2272. carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  2273. char targetPath[std::strlen(pData->oscData->path)+9];
  2274. std::strcpy(targetPath, pData->oscData->path);
  2275. std::strcat(targetPath, "/note_on");
  2276. try_lo_send(pData->oscData->target, targetPath, "iiii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note), static_cast<int32_t>(velo));
  2277. }
  2278. void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept
  2279. {
  2280. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2281. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2282. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2283. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2284. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2285. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2286. carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
  2287. char targetPath[std::strlen(pData->oscData->path)+10];
  2288. std::strcpy(targetPath, pData->oscData->path);
  2289. std::strcat(targetPath, "/note_off");
  2290. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note));
  2291. }
  2292. void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) const noexcept
  2293. {
  2294. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2295. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2296. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2297. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2298. // TODO - try and see if we can get peaks[4] ref
  2299. const EnginePluginData& epData(pData->plugins[pluginId]);
  2300. char targetPath[std::strlen(pData->oscData->path)+11];
  2301. std::strcpy(targetPath, pData->oscData->path);
  2302. std::strcat(targetPath, "/set_peaks");
  2303. try_lo_send(pData->oscData->target, targetPath, "iffff", static_cast<int32_t>(pluginId), epData.insPeak[0], epData.insPeak[1], epData.outsPeak[0], epData.outsPeak[1]);
  2304. }
  2305. void CarlaEngine::oscSend_control_exit() const noexcept
  2306. {
  2307. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2308. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2309. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2310. carla_debug("CarlaEngine::oscSend_control_exit()");
  2311. char targetPath[std::strlen(pData->oscData->path)+6];
  2312. std::strcpy(targetPath, pData->oscData->path);
  2313. std::strcat(targetPath, "/exit");
  2314. try_lo_send(pData->oscData->target, targetPath, "");
  2315. }
  2316. #endif
  2317. // -----------------------------------------------------------------------
  2318. CARLA_BACKEND_END_NAMESPACE