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.

3021 lines
110KB

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