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.

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