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.

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