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.

2905 lines
107KB

  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", index2);
  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", index2);
  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", index2, 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_debug("CarlaEngine::init(\"%s\")", clientName);
  654. if (! pData->init(clientName))
  655. return false;
  656. callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, pData->options.processMode, pData->options.transportMode, 0.0f, getCurrentDriverName());
  657. return true;
  658. }
  659. bool CarlaEngine::close()
  660. {
  661. carla_debug("CarlaEngine::close()");
  662. if (pData->curPluginCount != 0)
  663. {
  664. pData->aboutToClose = true;
  665. removeAllPlugins();
  666. }
  667. #ifndef BUILD_BRIDGE
  668. if (pData->osc.isControlRegistered())
  669. oscSend_control_exit();
  670. #endif
  671. pData->close();
  672. callback(ENGINE_CALLBACK_ENGINE_STOPPED, 0, 0, 0, 0.0f, nullptr);
  673. return true;
  674. }
  675. void CarlaEngine::idle() noexcept
  676. {
  677. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull,); // TESTING, remove later
  678. CARLA_SAFE_ASSERT_RETURN(pData->nextPluginId == pData->maxPluginNumber,); // TESTING, remove later
  679. CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr,); // this one too maybe
  680. for (uint i=0; i < pData->curPluginCount; ++i)
  681. {
  682. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  683. if (plugin != nullptr && plugin->isEnabled())
  684. {
  685. try {
  686. plugin->idle();
  687. } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin idle");
  688. }
  689. }
  690. pData->osc.idle();
  691. }
  692. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  693. {
  694. return new CarlaEngineClient(*this);
  695. }
  696. // -----------------------------------------------------------------------
  697. // Plugin management
  698. 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)
  699. {
  700. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #10)");
  701. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId <= pData->maxPluginNumber, "Invalid engine internal data (err #11)");
  702. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #12)");
  703. CARLA_SAFE_ASSERT_RETURN_ERR(btype != BINARY_NONE, "Invalid plugin params (err #1)");
  704. CARLA_SAFE_ASSERT_RETURN_ERR(ptype != PLUGIN_NONE, "Invalid plugin params (err #2)");
  705. CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin params (err #3)");
  706. 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);
  707. uint id;
  708. #ifndef BUILD_BRIDGE
  709. CarlaPlugin* oldPlugin = nullptr;
  710. if (pData->nextPluginId < pData->curPluginCount)
  711. {
  712. id = pData->nextPluginId;
  713. pData->nextPluginId = pData->maxPluginNumber;
  714. oldPlugin = pData->plugins[id].plugin;
  715. CARLA_SAFE_ASSERT_RETURN_ERR(oldPlugin != nullptr, "Invalid replace plugin Id");
  716. }
  717. else
  718. #endif
  719. {
  720. id = pData->curPluginCount;
  721. if (id == pData->maxPluginNumber)
  722. {
  723. setLastError("Maximum number of plugins reached");
  724. return false;
  725. }
  726. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins[id].plugin == nullptr, "Invalid engine internal data (err #13)");
  727. }
  728. CarlaPlugin::Initializer initializer = {
  729. this,
  730. id,
  731. filename,
  732. name,
  733. label,
  734. uniqueId
  735. };
  736. CarlaPlugin* plugin = nullptr;
  737. #ifndef BUILD_BRIDGE
  738. CarlaString bridgeBinary(pData->options.binaryDir);
  739. if (bridgeBinary.isNotEmpty())
  740. {
  741. # ifndef CARLA_OS_WIN
  742. if (btype == BINARY_NATIVE)
  743. {
  744. bridgeBinary += OS_SEP_STR "carla-bridge-native";
  745. }
  746. else
  747. # endif
  748. {
  749. switch (btype)
  750. {
  751. case BINARY_POSIX32:
  752. bridgeBinary += OS_SEP_STR "carla-bridge-posix32";
  753. break;
  754. case BINARY_POSIX64:
  755. bridgeBinary += OS_SEP_STR "carla-bridge-posix64";
  756. break;
  757. case BINARY_WIN32:
  758. bridgeBinary += OS_SEP_STR "carla-bridge-win32.exe";
  759. break;
  760. case BINARY_WIN64:
  761. bridgeBinary += OS_SEP_STR "carla-bridge-win64.exe";
  762. break;
  763. default:
  764. bridgeBinary.clear();
  765. break;
  766. }
  767. }
  768. File file(bridgeBinary.buffer());
  769. if (! file.existsAsFile())
  770. bridgeBinary.clear();
  771. }
  772. if (ptype != PLUGIN_INTERNAL && ptype != PLUGIN_JACK && (btype != BINARY_NATIVE || (pData->options.preferPluginBridges && bridgeBinary.isNotEmpty())))
  773. {
  774. if (bridgeBinary.isNotEmpty())
  775. {
  776. plugin = CarlaPlugin::newBridge(initializer, btype, ptype, bridgeBinary);
  777. }
  778. # ifdef CARLA_OS_LINUX
  779. else if (btype == BINARY_WIN32)
  780. {
  781. // fallback to dssi-vst
  782. File file(filename);
  783. CarlaString label2(file.getFullPathName().toRawUTF8());
  784. label2.replace(' ', '*');
  785. CarlaPlugin::Initializer init2 = {
  786. this,
  787. id,
  788. "/usr/lib/dssi/dssi-vst.so",
  789. name,
  790. label2,
  791. uniqueId
  792. };
  793. char* const oldVstPath(getenv("VST_PATH"));
  794. carla_setenv("VST_PATH", file.getParentDirectory().getFullPathName().toRawUTF8());
  795. plugin = CarlaPlugin::newDSSI(init2);
  796. if (oldVstPath != nullptr)
  797. carla_setenv("VST_PATH", oldVstPath);
  798. }
  799. # endif
  800. else
  801. {
  802. setLastError("This Carla build cannot handle this binary");
  803. return false;
  804. }
  805. }
  806. else
  807. #endif // ! BUILD_BRIDGE
  808. {
  809. bool use16Outs;
  810. setLastError("Invalid or unsupported plugin type");
  811. switch (ptype)
  812. {
  813. case PLUGIN_NONE:
  814. break;
  815. case PLUGIN_INTERNAL:
  816. if (std::strcmp(label, "Csound") == 0)
  817. {
  818. plugin = CarlaPlugin::newCsound(initializer);
  819. }
  820. else if (std::strcmp(label, "FluidSynth") == 0)
  821. {
  822. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  823. plugin = CarlaPlugin::newFluidSynth(initializer, use16Outs);
  824. }
  825. else if (std::strcmp(label, "LinuxSampler (GIG)") == 0)
  826. {
  827. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  828. plugin = CarlaPlugin::newLinuxSampler(initializer, "GIG", use16Outs);
  829. }
  830. else if (std::strcmp(label, "LinuxSampler (SF2)") == 0)
  831. {
  832. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  833. plugin = CarlaPlugin::newLinuxSampler(initializer, "SF2", use16Outs);
  834. }
  835. else if (std::strcmp(label, "LinuxSampler (SFZ)") == 0)
  836. {
  837. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  838. plugin = CarlaPlugin::newLinuxSampler(initializer, "SFZ", use16Outs);
  839. }
  840. else
  841. {
  842. plugin = CarlaPlugin::newNative(initializer);
  843. }
  844. break;
  845. case PLUGIN_LADSPA:
  846. plugin = CarlaPlugin::newLADSPA(initializer, (const LADSPA_RDF_Descriptor*)extra);
  847. break;
  848. case PLUGIN_DSSI:
  849. plugin = CarlaPlugin::newDSSI(initializer);
  850. break;
  851. case PLUGIN_LV2:
  852. plugin = CarlaPlugin::newLV2(initializer);
  853. break;
  854. case PLUGIN_VST:
  855. plugin = CarlaPlugin::newVST(initializer);
  856. break;
  857. case PLUGIN_VST3:
  858. plugin = CarlaPlugin::newVST3(initializer);
  859. break;
  860. case PLUGIN_AU:
  861. plugin = CarlaPlugin::newAU(initializer);
  862. break;
  863. case PLUGIN_JACK:
  864. plugin = CarlaPlugin::newJACK(initializer);
  865. break;
  866. case PLUGIN_REWIRE:
  867. plugin = CarlaPlugin::newReWire(initializer);
  868. break;
  869. case PLUGIN_FILE_CSD:
  870. plugin = CarlaPlugin::newFileCSD(initializer);
  871. break;
  872. case PLUGIN_FILE_GIG:
  873. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  874. plugin = CarlaPlugin::newFileGIG(initializer, use16Outs);
  875. break;
  876. case PLUGIN_FILE_SF2:
  877. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  878. plugin = CarlaPlugin::newFileSF2(initializer, use16Outs);
  879. break;
  880. case PLUGIN_FILE_SFZ:
  881. plugin = CarlaPlugin::newFileSFZ(initializer);
  882. break;
  883. }
  884. }
  885. if (plugin == nullptr)
  886. {
  887. #ifndef BUILD_BRIDGE
  888. pData->plugins[id].plugin = oldPlugin;
  889. #endif
  890. return false;
  891. }
  892. plugin->registerToOscClient();
  893. EnginePluginData& pluginData(pData->plugins[id]);
  894. pluginData.plugin = plugin;
  895. pluginData.insPeak[0] = 0.0f;
  896. pluginData.insPeak[1] = 0.0f;
  897. pluginData.outsPeak[0] = 0.0f;
  898. pluginData.outsPeak[1] = 0.0f;
  899. #ifndef BUILD_BRIDGE
  900. if (oldPlugin != nullptr)
  901. {
  902. bool wasActive = (oldPlugin->getInternalParameterValue(PARAMETER_ACTIVE) >= 0.5f);
  903. float oldDryWet = oldPlugin->getInternalParameterValue(PARAMETER_DRYWET);
  904. float oldVolume = oldPlugin->getInternalParameterValue(PARAMETER_VOLUME);
  905. delete oldPlugin;
  906. callback(ENGINE_CALLBACK_RELOAD_ALL, id, 0, 0, 0.0f, plugin->getName());
  907. if (wasActive)
  908. plugin->setActive(true, true, true);
  909. if (plugin->getHints() & PLUGIN_CAN_DRYWET)
  910. plugin->setDryWet(oldDryWet, true, true);
  911. if (plugin->getHints() & PLUGIN_CAN_VOLUME)
  912. plugin->setVolume(oldVolume, true, true);
  913. }
  914. else
  915. #endif
  916. {
  917. ++pData->curPluginCount;
  918. callback(ENGINE_CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
  919. //if (pData->curPluginCount == 1 && pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
  920. // callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED, 0, PATCHBAY_ICON_CARLA, 0, 0.0f, nullptr);
  921. }
  922. return true;
  923. }
  924. 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)
  925. {
  926. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, uniqueId, extra);
  927. }
  928. bool CarlaEngine::removePlugin(const uint id)
  929. {
  930. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #14)");
  931. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #15)");
  932. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #16)");
  933. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #1)");
  934. carla_debug("CarlaEngine::removePlugin(%i)", id);
  935. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  936. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove");
  937. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #17)");
  938. pData->thread.stopThread(500);
  939. const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
  940. const ScopedActionLock sal(pData, kEnginePostActionRemovePlugin, id, 0, lockWait);
  941. #ifndef BUILD_BRIDGE
  942. if (isOscControlRegistered())
  943. oscSend_control_remove_plugin(id);
  944. #endif
  945. delete plugin;
  946. if (isRunning() && ! pData->aboutToClose)
  947. pData->thread.startThread();
  948. callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  949. return true;
  950. }
  951. bool CarlaEngine::removeAllPlugins()
  952. {
  953. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #18)");
  954. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #19)");
  955. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #20)");
  956. carla_debug("CarlaEngine::removeAllPlugins()");
  957. if (pData->curPluginCount == 0)
  958. return true;
  959. pData->thread.stopThread(500);
  960. const bool lockWait(isRunning());
  961. const ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait);
  962. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  963. for (uint i=0; i < pData->maxPluginNumber; ++i)
  964. {
  965. EnginePluginData& pluginData(pData->plugins[i]);
  966. if (pluginData.plugin != nullptr)
  967. {
  968. delete pluginData.plugin;
  969. pluginData.plugin = nullptr;
  970. }
  971. pluginData.insPeak[0] = 0.0f;
  972. pluginData.insPeak[1] = 0.0f;
  973. pluginData.outsPeak[0] = 0.0f;
  974. pluginData.outsPeak[1] = 0.0f;
  975. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  976. }
  977. if (isRunning() && ! pData->aboutToClose)
  978. pData->thread.startThread();
  979. return true;
  980. }
  981. const char* CarlaEngine::renamePlugin(const uint id, const char* const newName)
  982. {
  983. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #21)");
  984. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #22)");
  985. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #23)");
  986. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #2)");
  987. CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name");
  988. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  989. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  990. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin != nullptr, "Could not find plugin to rename");
  991. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin->getId() == id, "Invalid engine internal data (err #24)");
  992. if (const char* const name = getUniquePluginName(newName))
  993. {
  994. plugin->setName(name);
  995. return name;
  996. }
  997. setLastError("Unable to get new unique plugin name");
  998. return nullptr;
  999. }
  1000. bool CarlaEngine::clonePlugin(const uint id)
  1001. {
  1002. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #25)");
  1003. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #26)");
  1004. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #27)");
  1005. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #3)");
  1006. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  1007. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  1008. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to clone");
  1009. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #28)");
  1010. char label[STR_MAX+1];
  1011. carla_zeroChar(label, STR_MAX+1);
  1012. plugin->getLabel(label);
  1013. const uint pluginCountBefore(pData->curPluginCount);
  1014. if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getUniqueId(), plugin->getExtraStuff()))
  1015. return false;
  1016. CARLA_SAFE_ASSERT_RETURN_ERR(pluginCountBefore+1 == pData->curPluginCount, "No new plugin found");
  1017. if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
  1018. newPlugin->loadStateSave(plugin->getStateSave());
  1019. return true;
  1020. }
  1021. bool CarlaEngine::replacePlugin(const uint id)
  1022. {
  1023. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #29)");
  1024. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)");
  1025. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)");
  1026. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  1027. // might use this to reset
  1028. if (id == pData->curPluginCount || id == pData->maxPluginNumber)
  1029. {
  1030. pData->nextPluginId = pData->maxPluginNumber;
  1031. return true;
  1032. }
  1033. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #4)");
  1034. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  1035. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to replace");
  1036. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #32)");
  1037. pData->nextPluginId = id;
  1038. return true;
  1039. }
  1040. bool CarlaEngine::switchPlugins(const uint idA, const uint idB)
  1041. {
  1042. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #33)");
  1043. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount >= 2, "Invalid engine internal data (err #34)");
  1044. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #35)");
  1045. CARLA_SAFE_ASSERT_RETURN_ERR(idA != idB, "Invalid operation, cannot switch plugin with itself");
  1046. CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id (err #5)");
  1047. CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id (err #6)");
  1048. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  1049. CarlaPlugin* const pluginA(pData->plugins[idA].plugin);
  1050. CarlaPlugin* const pluginB(pData->plugins[idB].plugin);
  1051. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #1)");
  1052. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #2)");
  1053. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data (err #36)");
  1054. CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data (err #37)");
  1055. pData->thread.stopThread(500);
  1056. const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
  1057. const ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  1058. #ifndef BUILD_BRIDGE // TODO
  1059. //if (isOscControlRegistered())
  1060. // oscSend_control_switch_plugins(idA, idB);
  1061. #endif
  1062. if (isRunning() && ! pData->aboutToClose)
  1063. pData->thread.startThread();
  1064. return true;
  1065. }
  1066. CarlaPlugin* CarlaEngine::getPlugin(const uint id) const
  1067. {
  1068. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #38)");
  1069. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #39)");
  1070. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #40)");
  1071. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #7)");
  1072. return pData->plugins[id].plugin;
  1073. }
  1074. CarlaPlugin* CarlaEngine::getPluginUnchecked(const uint id) const noexcept
  1075. {
  1076. return pData->plugins[id].plugin;
  1077. }
  1078. const char* CarlaEngine::getUniquePluginName(const char* const name) const
  1079. {
  1080. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr);
  1081. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  1082. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  1083. CarlaString sname;
  1084. sname = name;
  1085. if (sname.isEmpty())
  1086. {
  1087. sname = "(No name)";
  1088. return sname.dup();
  1089. }
  1090. const size_t maxNameSize(carla_min<uint>(getMaxClientNameSize(), 0xff, 6) - 6); // 6 = strlen(" (10)") + 1
  1091. if (maxNameSize == 0 || ! isRunning())
  1092. return sname.dup();
  1093. sname.truncate(maxNameSize);
  1094. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  1095. for (uint i=0; i < pData->curPluginCount; ++i)
  1096. {
  1097. CARLA_SAFE_ASSERT_BREAK(pData->plugins[i].plugin != nullptr);
  1098. // Check if unique name doesn't exist
  1099. if (const char* const pluginName = pData->plugins[i].plugin->getName())
  1100. {
  1101. if (sname != pluginName)
  1102. continue;
  1103. }
  1104. // Check if string has already been modified
  1105. {
  1106. const size_t len(sname.length());
  1107. // 1 digit, ex: " (2)"
  1108. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  1109. {
  1110. int number = sname[len-2] - '0';
  1111. if (number == 9)
  1112. {
  1113. // next number is 10, 2 digits
  1114. sname.truncate(len-4);
  1115. sname += " (10)";
  1116. //sname.replace(" (9)", " (10)");
  1117. }
  1118. else
  1119. sname[len-2] = char('0' + number + 1);
  1120. continue;
  1121. }
  1122. // 2 digits, ex: " (11)"
  1123. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  1124. {
  1125. char n2 = sname[len-2];
  1126. char n3 = sname[len-3];
  1127. if (n2 == '9')
  1128. {
  1129. n2 = '0';
  1130. n3 = static_cast<char>(n3 + 1);
  1131. }
  1132. else
  1133. n2 = static_cast<char>(n2 + 1);
  1134. sname[len-2] = n2;
  1135. sname[len-3] = n3;
  1136. continue;
  1137. }
  1138. }
  1139. // Modify string if not
  1140. sname += " (2)";
  1141. }
  1142. return sname.dup();
  1143. }
  1144. // -----------------------------------------------------------------------
  1145. // Project management
  1146. bool CarlaEngine::loadFile(const char* const filename)
  1147. {
  1148. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #1)");
  1149. carla_debug("CarlaEngine::loadFile(\"%s\")", filename);
  1150. File file(filename);
  1151. CARLA_SAFE_ASSERT_RETURN_ERR(file.existsAsFile(), "Requested file does not exist or is not a readable file");
  1152. CarlaString baseName(file.getFileName().toRawUTF8());
  1153. CarlaString extension(file.getFileExtension().toRawUTF8());
  1154. extension.toLower();
  1155. // -------------------------------------------------------------------
  1156. if (extension == "carxp" || extension == "carxs")
  1157. return loadProject(filename);
  1158. // -------------------------------------------------------------------
  1159. if (extension == "csd")
  1160. return addPlugin(PLUGIN_FILE_CSD, filename, baseName, baseName, 0, nullptr);
  1161. if (extension == "gig")
  1162. return addPlugin(PLUGIN_FILE_GIG, filename, baseName, baseName, 0, nullptr);
  1163. if (extension == "sf2")
  1164. return addPlugin(PLUGIN_FILE_SF2, filename, baseName, baseName, 0, nullptr);
  1165. if (extension == "sfz")
  1166. return addPlugin(PLUGIN_FILE_SFZ, filename, baseName, baseName, 0, nullptr);
  1167. // -------------------------------------------------------------------
  1168. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  1169. {
  1170. #ifdef WANT_AUDIOFILE
  1171. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile", 0, nullptr))
  1172. {
  1173. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1174. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1175. return true;
  1176. }
  1177. return false;
  1178. #else
  1179. setLastError("This Carla build does not have Audio file support");
  1180. return false;
  1181. #endif
  1182. }
  1183. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  1184. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  1185. {
  1186. #ifdef WANT_AUDIOFILE
  1187. # ifdef HAVE_FFMPEG
  1188. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile", 0, nullptr))
  1189. {
  1190. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1191. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1192. return true;
  1193. }
  1194. return false;
  1195. # else
  1196. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  1197. return false;
  1198. # endif
  1199. #else
  1200. setLastError("This Carla build does not have Audio file support");
  1201. return false;
  1202. #endif
  1203. }
  1204. // -------------------------------------------------------------------
  1205. if (extension == "mid" || extension == "midi")
  1206. {
  1207. #ifdef WANT_MIDIFILE
  1208. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile", 0, nullptr))
  1209. {
  1210. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1211. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1212. return true;
  1213. }
  1214. return false;
  1215. #else
  1216. setLastError("This Carla build does not have MIDI file support");
  1217. return false;
  1218. #endif
  1219. }
  1220. // -------------------------------------------------------------------
  1221. // ZynAddSubFX
  1222. if (extension == "xmz" || extension == "xiz")
  1223. {
  1224. #ifdef WANT_ZYNADDSUBFX
  1225. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx", 0, nullptr))
  1226. {
  1227. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1228. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  1229. return true;
  1230. }
  1231. return false;
  1232. #else
  1233. setLastError("This Carla build does not have ZynAddSubFX support");
  1234. return false;
  1235. #endif
  1236. }
  1237. // -------------------------------------------------------------------
  1238. setLastError("Unknown file extension");
  1239. return false;
  1240. }
  1241. bool CarlaEngine::loadProject(const char* const filename)
  1242. {
  1243. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #2)");
  1244. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1245. File file(filename);
  1246. CARLA_SAFE_ASSERT_RETURN_ERR(file.existsAsFile(), "Requested file does not exist or is not a readable file");
  1247. XmlDocument xml(file);
  1248. ScopedPointer<XmlElement> xmlElement(xml.getDocumentElement(true));
  1249. CARLA_SAFE_ASSERT_RETURN_ERR(xmlElement != nullptr, "Failed to parse project file");
  1250. const String& xmlType(xmlElement->getTagName());
  1251. const bool isPreset(xmlType.equalsIgnoreCase("carla-preset"));
  1252. if (! (xmlType.equalsIgnoreCase("carla-project") || isPreset))
  1253. {
  1254. setLastError("Not a valid Carla project or preset file");
  1255. return false;
  1256. }
  1257. // completely load file
  1258. xmlElement = xml.getDocumentElement(false);
  1259. CARLA_SAFE_ASSERT_RETURN_ERR(xmlElement != nullptr, "Failed to completely parse project file");
  1260. // handle plugins first
  1261. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1262. {
  1263. const String& tagName(elem->getTagName());
  1264. if (isPreset || tagName.equalsIgnoreCase("plugin"))
  1265. {
  1266. StateSave stateSave;
  1267. stateSave.fillFromXmlElement(isPreset ? xmlElement.get() : elem);
  1268. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1269. CARLA_SAFE_ASSERT_CONTINUE(stateSave.type != nullptr);
  1270. const void* extraStuff = nullptr;
  1271. // check if using GIG, SF2 or SFZ 16outs
  1272. static const char kUse16OutsSuffix[] = " (16 outs)";
  1273. const PluginType ptype(getPluginTypeFromString(stateSave.type));
  1274. if (CarlaString(stateSave.label).endsWith(kUse16OutsSuffix))
  1275. {
  1276. if (ptype == PLUGIN_FILE_GIG || ptype == PLUGIN_FILE_SF2)
  1277. extraStuff = "true";
  1278. }
  1279. // TODO - proper find&load plugins
  1280. if (addPlugin(ptype, stateSave.binary, stateSave.name, stateSave.label, stateSave.uniqueId, extraStuff))
  1281. {
  1282. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1283. plugin->loadStateSave(stateSave);
  1284. }
  1285. else
  1286. carla_stderr2("Failed to load a plugin, error was:%s\n", getLastError());
  1287. }
  1288. if (isPreset)
  1289. return true;
  1290. }
  1291. #ifndef BUILD_BRIDGE
  1292. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1293. // if we're running inside some session-manager, let them handle the connections
  1294. if (pData->options.processMode != ENGINE_PROCESS_MODE_PATCHBAY)
  1295. {
  1296. if (std::getenv("CARLA_DONT_MANAGE_CONNECTIONS") != nullptr || std::getenv("LADISH_APP_NAME") != nullptr || std::getenv("NSM_URL") != nullptr)
  1297. return true;
  1298. }
  1299. // now handle connections
  1300. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1301. {
  1302. const String& tagName(elem->getTagName());
  1303. if (tagName.equalsIgnoreCase("patchbay"))
  1304. {
  1305. CarlaString sourcePort, targetPort;
  1306. for (XmlElement* patchElem = elem->getFirstChildElement(); patchElem != nullptr; patchElem = patchElem->getNextElement())
  1307. {
  1308. const String& patchTag(patchElem->getTagName());
  1309. sourcePort.clear();
  1310. targetPort.clear();
  1311. if (! patchTag.equalsIgnoreCase("connection"))
  1312. continue;
  1313. for (XmlElement* connElem = patchElem->getFirstChildElement(); connElem != nullptr; connElem = connElem->getNextElement())
  1314. {
  1315. const String& tag(connElem->getTagName());
  1316. const String text(connElem->getAllSubText().trim());
  1317. if (tag.equalsIgnoreCase("source"))
  1318. sourcePort = text.toRawUTF8();
  1319. else if (tag.equalsIgnoreCase("target"))
  1320. targetPort = text.toRawUTF8();
  1321. }
  1322. if (sourcePort.isNotEmpty() && targetPort.isNotEmpty())
  1323. restorePatchbayConnection(sourcePort, targetPort);
  1324. }
  1325. break;
  1326. }
  1327. }
  1328. #endif
  1329. return true;
  1330. }
  1331. bool CarlaEngine::saveProject(const char* const filename)
  1332. {
  1333. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #3)");
  1334. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1335. MemoryOutputStream out;
  1336. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1337. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1338. out << "<CARLA-PROJECT VERSION='2.0'>\n";
  1339. bool firstPlugin = true;
  1340. char strBuf[STR_MAX+1];
  1341. for (uint i=0; i < pData->curPluginCount; ++i)
  1342. {
  1343. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1344. if (plugin != nullptr && plugin->isEnabled())
  1345. {
  1346. if (! firstPlugin)
  1347. out << "\n";
  1348. strBuf[0] = '\0';
  1349. plugin->getRealName(strBuf);
  1350. //if (strBuf[0] != '\0')
  1351. // out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1352. out << " <Plugin>\n";
  1353. out << plugin->getStateSave().toString();
  1354. out << " </Plugin>\n";
  1355. firstPlugin = false;
  1356. }
  1357. }
  1358. #ifndef BUILD_BRIDGE
  1359. // if we're running inside some session-manager, let them handle the connections
  1360. if (pData->options.processMode != ENGINE_PROCESS_MODE_PATCHBAY)
  1361. {
  1362. if (std::getenv("CARLA_DONT_MANAGE_CONNECTIONS") != nullptr || std::getenv("LADISH_APP_NAME") != nullptr || std::getenv("NSM_URL") != nullptr)
  1363. return true;
  1364. }
  1365. if (const char* const* patchbayConns = getPatchbayConnections())
  1366. {
  1367. if (! firstPlugin)
  1368. out << "\n";
  1369. out << " <Patchbay>\n";
  1370. for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i )
  1371. {
  1372. const char* const connSource(patchbayConns[i]);
  1373. const char* const connTarget(patchbayConns[i+1]);
  1374. CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0');
  1375. CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0');
  1376. out << " <Connection>\n";
  1377. out << " <Source>" << connSource << "</Source>\n";
  1378. out << " <Target>" << connTarget << "</Target>\n";
  1379. out << " </Connection>\n";
  1380. delete[] connSource;
  1381. delete[] connTarget;
  1382. }
  1383. out << " </Patchbay>\n";
  1384. }
  1385. #endif
  1386. out << "</CARLA-PROJECT>\n";
  1387. File file(filename);
  1388. if (file.replaceWithData(out.getData(), out.getDataSize()))
  1389. return true;
  1390. setLastError("Failed to write file");
  1391. return false;
  1392. }
  1393. // -----------------------------------------------------------------------
  1394. // Information (base)
  1395. uint CarlaEngine::getHints() const noexcept
  1396. {
  1397. return pData->hints;
  1398. }
  1399. uint32_t CarlaEngine::getBufferSize() const noexcept
  1400. {
  1401. return pData->bufferSize;
  1402. }
  1403. double CarlaEngine::getSampleRate() const noexcept
  1404. {
  1405. return pData->sampleRate;
  1406. }
  1407. const char* CarlaEngine::getName() const noexcept
  1408. {
  1409. return pData->name;
  1410. }
  1411. EngineProcessMode CarlaEngine::getProccessMode() const noexcept
  1412. {
  1413. return pData->options.processMode;
  1414. }
  1415. const EngineOptions& CarlaEngine::getOptions() const noexcept
  1416. {
  1417. return pData->options;
  1418. }
  1419. const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept
  1420. {
  1421. return pData->timeInfo;
  1422. }
  1423. // -----------------------------------------------------------------------
  1424. // Information (peaks)
  1425. float CarlaEngine::getInputPeak(const uint pluginId, const bool isLeft) const noexcept
  1426. {
  1427. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1428. return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1];
  1429. }
  1430. float CarlaEngine::getOutputPeak(const uint pluginId, const bool isLeft) const noexcept
  1431. {
  1432. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1433. return pData->plugins[pluginId].outsPeak[isLeft ? 0 : 1];
  1434. }
  1435. // -----------------------------------------------------------------------
  1436. // Callback
  1437. void CarlaEngine::callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept
  1438. {
  1439. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  1440. if (pData->callback != nullptr)
  1441. {
  1442. try {
  1443. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1444. } catch(...) {}
  1445. }
  1446. }
  1447. void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept
  1448. {
  1449. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1450. pData->callback = func;
  1451. pData->callbackPtr = ptr;
  1452. }
  1453. // -----------------------------------------------------------------------
  1454. // File Callback
  1455. const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept
  1456. {
  1457. CARLA_SAFE_ASSERT_RETURN(title != nullptr && title[0] != '\0', nullptr);
  1458. CARLA_SAFE_ASSERT_RETURN(filter != nullptr, nullptr);
  1459. carla_debug("CarlaEngine::runFileCallback(%i:%s, %s, \"%s\", \"%s\")", action, FileCallbackOpcode2Str(action), bool2str(isDir), title, filter);
  1460. const char* ret = nullptr;
  1461. if (pData->fileCallback != nullptr)
  1462. {
  1463. try {
  1464. ret = pData->fileCallback(pData->fileCallbackPtr, action, isDir, title, filter);
  1465. } catch(...) {}
  1466. }
  1467. return ret;
  1468. }
  1469. void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept
  1470. {
  1471. carla_debug("CarlaEngine::setFileCallback(%p, %p)", func, ptr);
  1472. pData->fileCallback = func;
  1473. pData->fileCallbackPtr = ptr;
  1474. }
  1475. #ifndef BUILD_BRIDGE
  1476. // -----------------------------------------------------------------------
  1477. // Patchbay
  1478. bool CarlaEngine::patchbayConnect(const uint groupA, const uint portA, const uint groupB, const uint portB)
  1479. {
  1480. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1481. CARLA_SAFE_ASSERT_RETURN(pData->audio.isReady, false);
  1482. carla_debug("CarlaEngine::patchbayConnect(%u, %u, %u, %u)", groupA, portA, groupB, portB);
  1483. if (pData->graph.isRack)
  1484. {
  1485. CARLA_SAFE_ASSERT_RETURN(pData->graph.rack != nullptr, nullptr);
  1486. return pData->graph.rack->connect(this, groupA, portA, groupB, portB);
  1487. }
  1488. else
  1489. {
  1490. CARLA_SAFE_ASSERT_RETURN(pData->graph.patchbay != nullptr, nullptr);
  1491. return pData->graph.patchbay->connect(this, groupA, portA, groupB, portB);
  1492. }
  1493. }
  1494. bool CarlaEngine::patchbayDisconnect(const uint connectionId)
  1495. {
  1496. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1497. CARLA_SAFE_ASSERT_RETURN(pData->audio.isReady, false);
  1498. carla_debug("CarlaEngine::patchbayDisconnect(%u)", connectionId);
  1499. if (pData->graph.isRack)
  1500. {
  1501. CARLA_SAFE_ASSERT_RETURN(pData->graph.rack != nullptr, nullptr);
  1502. return pData->graph.rack->disconnect(this, connectionId);
  1503. }
  1504. else
  1505. {
  1506. CARLA_SAFE_ASSERT_RETURN(pData->graph.patchbay != nullptr, nullptr);
  1507. return pData->graph.patchbay->disconnect(this, connectionId);
  1508. }
  1509. }
  1510. bool CarlaEngine::patchbayRefresh()
  1511. {
  1512. setLastError("Unsupported operation");
  1513. return false;
  1514. }
  1515. #endif
  1516. // -----------------------------------------------------------------------
  1517. // Transport
  1518. void CarlaEngine::transportPlay() noexcept
  1519. {
  1520. pData->time.playing = true;
  1521. }
  1522. void CarlaEngine::transportPause() noexcept
  1523. {
  1524. pData->time.playing = false;
  1525. }
  1526. void CarlaEngine::transportRelocate(const uint64_t frame) noexcept
  1527. {
  1528. pData->time.frame = frame;
  1529. }
  1530. // -----------------------------------------------------------------------
  1531. // Error handling
  1532. const char* CarlaEngine::getLastError() const noexcept
  1533. {
  1534. return pData->lastError;
  1535. }
  1536. void CarlaEngine::setLastError(const char* const error) const noexcept
  1537. {
  1538. pData->lastError = error;
  1539. }
  1540. void CarlaEngine::setAboutToClose() noexcept
  1541. {
  1542. carla_debug("CarlaEngine::setAboutToClose()");
  1543. pData->aboutToClose = true;
  1544. }
  1545. // -----------------------------------------------------------------------
  1546. // Global options
  1547. void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr)
  1548. {
  1549. carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
  1550. if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
  1551. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
  1552. switch (option)
  1553. {
  1554. case ENGINE_OPTION_DEBUG:
  1555. case ENGINE_OPTION_NSM_INIT:
  1556. break;
  1557. case ENGINE_OPTION_PROCESS_MODE:
  1558. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
  1559. pData->options.processMode = static_cast<EngineProcessMode>(value);
  1560. break;
  1561. case ENGINE_OPTION_TRANSPORT_MODE:
  1562. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
  1563. pData->options.transportMode = static_cast<EngineTransportMode>(value);
  1564. break;
  1565. case ENGINE_OPTION_FORCE_STEREO:
  1566. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1567. pData->options.forceStereo = (value != 0);
  1568. break;
  1569. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  1570. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1571. pData->options.preferPluginBridges = (value != 0);
  1572. break;
  1573. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  1574. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1575. pData->options.preferUiBridges = (value != 0);
  1576. break;
  1577. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  1578. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1579. pData->options.uisAlwaysOnTop = (value != 0);
  1580. break;
  1581. case ENGINE_OPTION_MAX_PARAMETERS:
  1582. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1583. pData->options.maxParameters = static_cast<uint>(value);
  1584. break;
  1585. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  1586. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1587. pData->options.uiBridgesTimeout = static_cast<uint>(value);
  1588. break;
  1589. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  1590. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  1591. pData->options.audioNumPeriods = static_cast<uint>(value);
  1592. break;
  1593. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  1594. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  1595. pData->options.audioBufferSize = static_cast<uint>(value);
  1596. break;
  1597. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  1598. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  1599. pData->options.audioSampleRate = static_cast<uint>(value);
  1600. break;
  1601. case ENGINE_OPTION_AUDIO_DEVICE:
  1602. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  1603. if (pData->options.audioDevice != nullptr)
  1604. delete[] pData->options.audioDevice;
  1605. pData->options.audioDevice = carla_strdup(valueStr);
  1606. break;
  1607. case ENGINE_OPTION_PATH_BINARIES:
  1608. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1609. if (pData->options.binaryDir != nullptr)
  1610. delete[] pData->options.binaryDir;
  1611. pData->options.binaryDir = carla_strdup(valueStr);
  1612. break;
  1613. case ENGINE_OPTION_PATH_RESOURCES:
  1614. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1615. if (pData->options.resourceDir != nullptr)
  1616. delete[] pData->options.resourceDir;
  1617. pData->options.resourceDir = carla_strdup(valueStr);
  1618. break;
  1619. case ENGINE_OPTION_FRONTEND_WIN_ID:
  1620. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1621. const long long winId(std::strtoll(valueStr, nullptr, 16));
  1622. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  1623. pData->options.frontendWinId = static_cast<uintptr_t>(winId);
  1624. break;
  1625. }
  1626. }
  1627. // -----------------------------------------------------------------------
  1628. // OSC Stuff
  1629. #ifdef BUILD_BRIDGE
  1630. bool CarlaEngine::isOscBridgeRegistered() const noexcept
  1631. {
  1632. return (pData->oscData != nullptr);
  1633. }
  1634. #else
  1635. bool CarlaEngine::isOscControlRegistered() const noexcept
  1636. {
  1637. return pData->osc.isControlRegistered();
  1638. }
  1639. #endif
  1640. void CarlaEngine::idleOsc() const noexcept
  1641. {
  1642. pData->osc.idle();
  1643. }
  1644. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1645. {
  1646. return pData->osc.getServerPathTCP();
  1647. }
  1648. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1649. {
  1650. return pData->osc.getServerPathUDP();
  1651. }
  1652. #ifdef BUILD_BRIDGE
  1653. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept
  1654. {
  1655. pData->oscData = oscData;
  1656. }
  1657. #endif
  1658. // -----------------------------------------------------------------------
  1659. // Helper functions
  1660. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1661. {
  1662. return isInput ? pData->events.in : pData->events.out;
  1663. }
  1664. void CarlaEngine::registerEnginePlugin(const uint id, CarlaPlugin* const plugin) noexcept
  1665. {
  1666. CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,);
  1667. carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin);
  1668. pData->plugins[id].plugin = plugin;
  1669. }
  1670. // -----------------------------------------------------------------------
  1671. // Internal stuff
  1672. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1673. {
  1674. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1675. for (uint i=0; i < pData->curPluginCount; ++i)
  1676. {
  1677. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1678. if (plugin != nullptr && plugin->isEnabled())
  1679. plugin->bufferSizeChanged(newBufferSize);
  1680. }
  1681. callback(ENGINE_CALLBACK_BUFFER_SIZE_CHANGED, 0, static_cast<int>(newBufferSize), 0, 0.0f, nullptr);
  1682. }
  1683. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1684. {
  1685. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1686. for (uint i=0; i < pData->curPluginCount; ++i)
  1687. {
  1688. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1689. if (plugin != nullptr && plugin->isEnabled())
  1690. plugin->sampleRateChanged(newSampleRate);
  1691. }
  1692. callback(ENGINE_CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, static_cast<float>(newSampleRate), nullptr);
  1693. }
  1694. void CarlaEngine::offlineModeChanged(const bool isOfflineNow)
  1695. {
  1696. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOfflineNow));
  1697. for (uint i=0; i < pData->curPluginCount; ++i)
  1698. {
  1699. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1700. if (plugin != nullptr && plugin->isEnabled())
  1701. plugin->offlineModeChanged(isOfflineNow);
  1702. }
  1703. }
  1704. void CarlaEngine::runPendingRtEvents() noexcept
  1705. {
  1706. pData->doNextPluginAction(true);
  1707. if (pData->time.playing)
  1708. pData->time.frame += pData->bufferSize;
  1709. if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL)
  1710. {
  1711. pData->timeInfo.playing = pData->time.playing;
  1712. pData->timeInfo.frame = pData->time.frame;
  1713. }
  1714. }
  1715. void CarlaEngine::setPluginPeaks(const uint pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1716. {
  1717. EnginePluginData& pluginData(pData->plugins[pluginId]);
  1718. pluginData.insPeak[0] = inPeaks[0];
  1719. pluginData.insPeak[1] = inPeaks[1];
  1720. pluginData.outsPeak[0] = outPeaks[0];
  1721. pluginData.outsPeak[1] = outPeaks[1];
  1722. }
  1723. #ifndef BUILD_BRIDGE
  1724. // -----------------------------------------------------------------------
  1725. // Patchbay stuff
  1726. const char* const* CarlaEngine::getPatchbayConnections() const
  1727. {
  1728. carla_debug("CarlaEngine::getPatchbayConnections()");
  1729. if (pData->graph.isRack)
  1730. {
  1731. CARLA_SAFE_ASSERT_RETURN(pData->graph.rack != nullptr, nullptr);
  1732. return pData->graph.rack->getConnections();
  1733. }
  1734. else
  1735. {
  1736. CARLA_SAFE_ASSERT_RETURN(pData->graph.patchbay != nullptr, nullptr);
  1737. return pData->graph.patchbay->getConnections();
  1738. }
  1739. }
  1740. void CarlaEngine::restorePatchbayConnection(const char* const connSource, const char* const connTarget)
  1741. {
  1742. CARLA_SAFE_ASSERT_RETURN(connSource != nullptr && connSource[0] != '\0',);
  1743. CARLA_SAFE_ASSERT_RETURN(connTarget != nullptr && connTarget[0] != '\0',);
  1744. carla_debug("CarlaEngine::restorePatchbayConnection(\"%s\", \"%s\")", connSource, connTarget);
  1745. uint groupA, portA;
  1746. uint groupB, portB;
  1747. if (pData->graph.isRack)
  1748. {
  1749. CARLA_SAFE_ASSERT_RETURN(pData->graph.rack != nullptr,);
  1750. if (! pData->graph.rack->getPortIdFromFullName(connSource, groupA, portA))
  1751. return;
  1752. if (! pData->graph.rack->getPortIdFromFullName(connTarget, groupB, portB))
  1753. return;
  1754. }
  1755. else
  1756. {
  1757. CARLA_SAFE_ASSERT_RETURN(pData->graph.patchbay != nullptr,);
  1758. if (! pData->graph.patchbay->getPortIdFromFullName(connSource, groupA, portA))
  1759. return;
  1760. if (! pData->graph.patchbay->getPortIdFromFullName(connTarget, groupB, portB))
  1761. return;
  1762. }
  1763. patchbayConnect(groupA, portA, groupB, portB);
  1764. }
  1765. #endif
  1766. // -----------------------------------------------------------------------
  1767. // Bridge/Controller OSC stuff
  1768. #ifdef BUILD_BRIDGE
  1769. void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept
  1770. {
  1771. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1772. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1773. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1774. carla_debug("CarlaEngine::oscSend_bridge_plugin_info1(%i:%s, %X, " P_INT64 ")", category, PluginCategory2Str(category), hints, uniqueId);
  1775. char targetPath[std::strlen(pData->oscData->path)+21];
  1776. std::strcpy(targetPath, pData->oscData->path);
  1777. std::strcat(targetPath, "/bridge_plugin_info1");
  1778. try_lo_send(pData->oscData->target, targetPath, "iih", static_cast<int32_t>(category), static_cast<int32_t>(hints), uniqueId);
  1779. }
  1780. void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  1781. {
  1782. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1783. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1784. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1785. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  1786. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  1787. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  1788. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  1789. carla_debug("CarlaEngine::oscSend_bridge_plugin_info2(\"%s\", \"%s\", \"%s\", \"%s\")", realName, label, maker, copyright);
  1790. char targetPath[std::strlen(pData->oscData->path)+21];
  1791. std::strcpy(targetPath, pData->oscData->path);
  1792. std::strcat(targetPath, "/bridge_plugin_info2");
  1793. try_lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright);
  1794. }
  1795. void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept
  1796. {
  1797. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1798. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1799. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1800. carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i)", ins, outs);
  1801. char targetPath[std::strlen(pData->oscData->path)+20];
  1802. std::strcpy(targetPath, pData->oscData->path);
  1803. std::strcat(targetPath, "/bridge_audio_count");
  1804. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1805. }
  1806. void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept
  1807. {
  1808. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1809. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1810. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1811. carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i)", ins, outs);
  1812. char targetPath[std::strlen(pData->oscData->path)+19];
  1813. std::strcpy(targetPath, pData->oscData->path);
  1814. std::strcat(targetPath, "/bridge_midi_count");
  1815. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1816. }
  1817. void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept
  1818. {
  1819. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1820. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1821. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1822. carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i)", ins, outs);
  1823. char targetPath[std::strlen(pData->oscData->path)+24];
  1824. std::strcpy(targetPath, pData->oscData->path);
  1825. std::strcat(targetPath, "/bridge_parameter_count");
  1826. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1827. }
  1828. void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const noexcept
  1829. {
  1830. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1831. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1832. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1833. carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
  1834. char targetPath[std::strlen(pData->oscData->path)+23];
  1835. std::strcpy(targetPath, pData->oscData->path);
  1836. std::strcat(targetPath, "/bridge_program_count");
  1837. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1838. }
  1839. void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const noexcept
  1840. {
  1841. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1842. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1843. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1844. carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
  1845. char targetPath[std::strlen(pData->oscData->path)+27];
  1846. std::strcpy(targetPath, pData->oscData->path);
  1847. std::strcat(targetPath, "/bridge_midi_program_count");
  1848. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1849. }
  1850. 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
  1851. {
  1852. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1853. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1854. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1855. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1856. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  1857. carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", index, rindex, type, ParameterType2Str(type), hints, name, unit);
  1858. char targetPath[std::strlen(pData->oscData->path)+24];
  1859. std::strcpy(targetPath, pData->oscData->path);
  1860. std::strcat(targetPath, "/bridge_parameter_data");
  1861. 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);
  1862. }
  1863. void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept
  1864. {
  1865. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1866. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1867. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1868. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, def, min, max);
  1869. char targetPath[std::strlen(pData->oscData->path)+26];
  1870. std::strcpy(targetPath, pData->oscData->path);
  1871. std::strcat(targetPath, "/bridge_parameter_ranges1");
  1872. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), def, min, max);
  1873. }
  1874. void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  1875. {
  1876. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1877. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1878. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1879. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, step, stepSmall, stepLarge);
  1880. char targetPath[std::strlen(pData->oscData->path)+26];
  1881. std::strcpy(targetPath, pData->oscData->path);
  1882. std::strcat(targetPath, "/bridge_parameter_ranges2");
  1883. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), step, stepSmall, stepLarge);
  1884. }
  1885. void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept
  1886. {
  1887. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1888. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1889. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1890. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_cc(%i, %i)", index, cc);
  1891. char targetPath[std::strlen(pData->oscData->path)+26];
  1892. std::strcpy(targetPath, pData->oscData->path);
  1893. std::strcat(targetPath, "/bridge_parameter_midi_cc");
  1894. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(cc));
  1895. }
  1896. void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept
  1897. {
  1898. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1899. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1900. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1901. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_channel(%i, %i)", index, channel);
  1902. char targetPath[std::strlen(pData->oscData->path)+31];
  1903. std::strcpy(targetPath, pData->oscData->path);
  1904. std::strcat(targetPath, "/bridge_parameter_midi_channel");
  1905. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(channel));
  1906. }
  1907. void CarlaEngine::oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept
  1908. {
  1909. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1910. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1911. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1912. carla_debug("CarlaEngine::oscSend_bridge_parameter_value(%i, %f)", index, value);
  1913. char targetPath[std::strlen(pData->oscData->path)+24];
  1914. std::strcpy(targetPath, pData->oscData->path);
  1915. std::strcat(targetPath, "/bridge_parameter_value");
  1916. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1917. }
  1918. void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept
  1919. {
  1920. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1921. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1922. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1923. carla_debug("CarlaEngine::oscSend_bridge_default_value(%i, %f)", index, value);
  1924. char targetPath[std::strlen(pData->oscData->path)+22];
  1925. std::strcpy(targetPath, pData->oscData->path);
  1926. std::strcat(targetPath, "/bridge_default_value");
  1927. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1928. }
  1929. void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const noexcept
  1930. {
  1931. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1932. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1933. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1934. carla_debug("CarlaEngine::oscSend_bridge_current_program(%i)", index);
  1935. char targetPath[std::strlen(pData->oscData->path)+24];
  1936. std::strcpy(targetPath, pData->oscData->path);
  1937. std::strcat(targetPath, "/bridge_current_program");
  1938. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1939. }
  1940. void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const noexcept
  1941. {
  1942. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1943. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1944. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1945. carla_debug("CarlaEngine::oscSend_bridge_current_midi_program(%i)", index);
  1946. char targetPath[std::strlen(pData->oscData->path)+30];
  1947. std::strcpy(targetPath, pData->oscData->path);
  1948. std::strcat(targetPath, "/bridge_current_midi_program");
  1949. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1950. }
  1951. void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept
  1952. {
  1953. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1954. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1955. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1956. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1957. carla_debug("CarlaEngine::oscSend_bridge_program_name(%i, \"%s\")", index, name);
  1958. char targetPath[std::strlen(pData->oscData->path)+21];
  1959. std::strcpy(targetPath, pData->oscData->path);
  1960. std::strcat(targetPath, "/bridge_program_name");
  1961. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(index), name);
  1962. }
  1963. 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
  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_SAFE_ASSERT_RETURN(name != nullptr,);
  1969. carla_debug("CarlaEngine::oscSend_bridge_midi_program_data(%i, %i, %i, \"%s\")", index, bank, program, name);
  1970. char targetPath[std::strlen(pData->oscData->path)+26];
  1971. std::strcpy(targetPath, pData->oscData->path);
  1972. std::strcat(targetPath, "/bridge_midi_program_data");
  1973. try_lo_send(pData->oscData->target, targetPath, "iiis", static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  1974. }
  1975. void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const noexcept
  1976. {
  1977. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1978. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1979. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1980. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1981. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1982. carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
  1983. char targetPath[std::strlen(pData->oscData->path)+18];
  1984. std::strcpy(targetPath, pData->oscData->path);
  1985. std::strcat(targetPath, "/bridge_configure");
  1986. try_lo_send(pData->oscData->target, targetPath, "ss", key, value);
  1987. }
  1988. void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept
  1989. {
  1990. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1991. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1992. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1993. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1994. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1995. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1996. carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1997. char targetPath[std::strlen(pData->oscData->path)+24];
  1998. std::strcpy(targetPath, pData->oscData->path);
  1999. std::strcat(targetPath, "/bridge_set_custom_data");
  2000. try_lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
  2001. }
  2002. void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept
  2003. {
  2004. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2005. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2006. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2007. CARLA_SAFE_ASSERT_RETURN(chunkFile != nullptr && chunkFile[0] != '\0',);
  2008. carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
  2009. char targetPath[std::strlen(pData->oscData->path)+23];
  2010. std::strcpy(targetPath, pData->oscData->path);
  2011. std::strcat(targetPath, "/bridge_set_chunk_data");
  2012. try_lo_send(pData->oscData->target, targetPath, "s", chunkFile);
  2013. }
  2014. void CarlaEngine::oscSend_bridge_pong() const noexcept
  2015. {
  2016. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2017. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2018. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2019. //carla_debug("CarlaEngine::oscSend_pong()");
  2020. char targetPath[std::strlen(pData->oscData->path)+13];
  2021. std::strcpy(targetPath, pData->oscData->path);
  2022. std::strcat(targetPath, "/bridge_pong");
  2023. try_lo_send(pData->oscData->target, targetPath, "");
  2024. }
  2025. #else
  2026. void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept
  2027. {
  2028. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2029. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2030. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2031. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2032. CARLA_SAFE_ASSERT_RETURN(pluginName != nullptr && pluginName[0] != '\0',);
  2033. carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  2034. char targetPath[std::strlen(pData->oscData->path)+18];
  2035. std::strcpy(targetPath, pData->oscData->path);
  2036. std::strcat(targetPath, "/add_plugin_start");
  2037. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(pluginId), pluginName);
  2038. }
  2039. void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const noexcept
  2040. {
  2041. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2042. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2043. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2044. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2045. carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
  2046. char targetPath[std::strlen(pData->oscData->path)+16];
  2047. std::strcpy(targetPath, pData->oscData->path);
  2048. std::strcat(targetPath, "/add_plugin_end");
  2049. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2050. }
  2051. void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const noexcept
  2052. {
  2053. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2054. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2055. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2056. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2057. carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
  2058. char targetPath[std::strlen(pData->oscData->path)+15];
  2059. std::strcpy(targetPath, pData->oscData->path);
  2060. std::strcat(targetPath, "/remove_plugin");
  2061. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2062. }
  2063. 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
  2064. {
  2065. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2066. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2067. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2068. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2069. CARLA_SAFE_ASSERT_RETURN(type != PLUGIN_NONE,);
  2070. 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);
  2071. char targetPath[std::strlen(pData->oscData->path)+18];
  2072. std::strcpy(targetPath, pData->oscData->path);
  2073. std::strcat(targetPath, "/set_plugin_info1");
  2074. 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));
  2075. }
  2076. 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
  2077. {
  2078. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2079. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2080. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2081. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2082. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  2083. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  2084. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  2085. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  2086. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, \"%s\", \"%s\", \"%s\", \"%s\")", pluginId, realName, label, maker, copyright);
  2087. char targetPath[std::strlen(pData->oscData->path)+18];
  2088. std::strcpy(targetPath, pData->oscData->path);
  2089. std::strcat(targetPath, "/set_plugin_info2");
  2090. try_lo_send(pData->oscData->target, targetPath, "issss", static_cast<int32_t>(pluginId), realName, label, maker, copyright);
  2091. }
  2092. void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2093. {
  2094. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2095. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2096. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2097. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2098. carla_debug("CarlaEngine::oscSend_control_set_audio_count(%i, %i, %i)", pluginId, ins, outs);
  2099. char targetPath[std::strlen(pData->oscData->path)+18];
  2100. std::strcpy(targetPath, pData->oscData->path);
  2101. std::strcat(targetPath, "/set_audio_count");
  2102. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2103. }
  2104. void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2105. {
  2106. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2107. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2108. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2109. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2110. carla_debug("CarlaEngine::oscSend_control_set_midi_count(%i, %i, %i)", pluginId, ins, outs);
  2111. char targetPath[std::strlen(pData->oscData->path)+18];
  2112. std::strcpy(targetPath, pData->oscData->path);
  2113. std::strcat(targetPath, "/set_midi_count");
  2114. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2115. }
  2116. void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2117. {
  2118. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2119. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2120. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2121. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2122. carla_debug("CarlaEngine::oscSend_control_set_parameter_count(%i, %i, %i)", pluginId, ins, outs);
  2123. char targetPath[std::strlen(pData->oscData->path)+18];
  2124. std::strcpy(targetPath, pData->oscData->path);
  2125. std::strcat(targetPath, "/set_parameter_count");
  2126. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2127. }
  2128. void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept
  2129. {
  2130. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2131. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2132. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2133. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2134. carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
  2135. char targetPath[std::strlen(pData->oscData->path)+19];
  2136. std::strcpy(targetPath, pData->oscData->path);
  2137. std::strcat(targetPath, "/set_program_count");
  2138. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2139. }
  2140. void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept
  2141. {
  2142. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2143. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2144. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2145. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2146. carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
  2147. char targetPath[std::strlen(pData->oscData->path)+24];
  2148. std::strcpy(targetPath, pData->oscData->path);
  2149. std::strcat(targetPath, "/set_midi_program_count");
  2150. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2151. }
  2152. 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
  2153. {
  2154. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2155. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2156. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2157. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2158. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  2159. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  2160. carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", pluginId, index, type, ParameterType2Str(type), hints, name, unit);
  2161. char targetPath[std::strlen(pData->oscData->path)+20];
  2162. std::strcpy(targetPath, pData->oscData->path);
  2163. std::strcat(targetPath, "/set_parameter_data");
  2164. 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);
  2165. }
  2166. 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
  2167. {
  2168. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2169. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2170. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2171. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2172. CARLA_SAFE_ASSERT_RETURN(def <= min && def >= max,);
  2173. CARLA_SAFE_ASSERT_RETURN(min < max,);
  2174. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges1(%i, %i, %f, %f, %f)", pluginId, index, def, min, max, def);
  2175. char targetPath[std::strlen(pData->oscData->path)+23];
  2176. std::strcpy(targetPath, pData->oscData->path);
  2177. std::strcat(targetPath, "/set_parameter_ranges1");
  2178. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), def, min, max);
  2179. }
  2180. 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
  2181. {
  2182. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2183. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2184. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2185. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2186. CARLA_SAFE_ASSERT_RETURN(step <= stepSmall && step >= stepLarge,);
  2187. CARLA_SAFE_ASSERT_RETURN(stepSmall <= stepLarge,);
  2188. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges2(%i, %i, %f, %f, %f)", pluginId, index, step, stepSmall, stepLarge);
  2189. char targetPath[std::strlen(pData->oscData->path)+23];
  2190. std::strcpy(targetPath, pData->oscData->path);
  2191. std::strcat(targetPath, "/set_parameter_ranges");
  2192. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), step, stepSmall, stepLarge);
  2193. }
  2194. void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept
  2195. {
  2196. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2197. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2198. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2199. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2200. CARLA_SAFE_ASSERT_RETURN(cc <= 0x5F,);
  2201. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  2202. char targetPath[std::strlen(pData->oscData->path)+23];
  2203. std::strcpy(targetPath, pData->oscData->path);
  2204. std::strcat(targetPath, "/set_parameter_midi_cc");
  2205. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(cc));
  2206. }
  2207. void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) 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_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2214. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  2215. char targetPath[std::strlen(pData->oscData->path)+28];
  2216. std::strcpy(targetPath, pData->oscData->path);
  2217. std::strcat(targetPath, "/set_parameter_midi_channel");
  2218. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(channel));
  2219. }
  2220. void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept
  2221. {
  2222. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2223. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2224. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2225. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2226. CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
  2227. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i:%s, %f)", pluginId, index, (index < 0) ? InternalParameterIndex2Str(static_cast<InternalParameterIndex>(index)) : "(none)", value);
  2228. char targetPath[std::strlen(pData->oscData->path)+21];
  2229. std::strcpy(targetPath, pData->oscData->path);
  2230. std::strcat(targetPath, "/set_parameter_value");
  2231. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), index, value);
  2232. }
  2233. void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) 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_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  2240. char targetPath[std::strlen(pData->oscData->path)+19];
  2241. std::strcpy(targetPath, pData->oscData->path);
  2242. std::strcat(targetPath, "/set_default_value");
  2243. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), value);
  2244. }
  2245. void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept
  2246. {
  2247. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2248. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2249. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2250. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2251. carla_debug("CarlaEngine::oscSend_control_set_current_program(%i, %i)", pluginId, index);
  2252. char targetPath[std::strlen(pData->oscData->path)+21];
  2253. std::strcpy(targetPath, pData->oscData->path);
  2254. std::strcat(targetPath, "/set_current_program");
  2255. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2256. }
  2257. void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept
  2258. {
  2259. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2260. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2261. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2262. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2263. carla_debug("CarlaEngine::oscSend_control_set_current_midi_program(%i, %i)", pluginId, index);
  2264. char targetPath[std::strlen(pData->oscData->path)+26];
  2265. std::strcpy(targetPath, pData->oscData->path);
  2266. std::strcat(targetPath, "/set_current_midi_program");
  2267. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2268. }
  2269. void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept
  2270. {
  2271. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2272. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2273. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2274. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2275. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2276. carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  2277. char targetPath[std::strlen(pData->oscData->path)+18];
  2278. std::strcpy(targetPath, pData->oscData->path);
  2279. std::strcat(targetPath, "/set_program_name");
  2280. try_lo_send(pData->oscData->target, targetPath, "iis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), name);
  2281. }
  2282. 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
  2283. {
  2284. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2285. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2286. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2287. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2288. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2289. carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  2290. char targetPath[std::strlen(pData->oscData->path)+23];
  2291. std::strcpy(targetPath, pData->oscData->path);
  2292. std::strcat(targetPath, "/set_midi_program_data");
  2293. 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);
  2294. }
  2295. void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept
  2296. {
  2297. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2298. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2299. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2300. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2301. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2302. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2303. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  2304. carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  2305. char targetPath[std::strlen(pData->oscData->path)+9];
  2306. std::strcpy(targetPath, pData->oscData->path);
  2307. std::strcat(targetPath, "/note_on");
  2308. 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));
  2309. }
  2310. void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept
  2311. {
  2312. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2313. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2314. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2315. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2316. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2317. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2318. carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
  2319. char targetPath[std::strlen(pData->oscData->path)+10];
  2320. std::strcpy(targetPath, pData->oscData->path);
  2321. std::strcat(targetPath, "/note_off");
  2322. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note));
  2323. }
  2324. void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) 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. // TODO - try and see if we can get peaks[4] ref
  2331. const EnginePluginData& epData(pData->plugins[pluginId]);
  2332. char targetPath[std::strlen(pData->oscData->path)+11];
  2333. std::strcpy(targetPath, pData->oscData->path);
  2334. std::strcat(targetPath, "/set_peaks");
  2335. 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]);
  2336. }
  2337. void CarlaEngine::oscSend_control_exit() const noexcept
  2338. {
  2339. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2340. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2341. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2342. carla_debug("CarlaEngine::oscSend_control_exit()");
  2343. char targetPath[std::strlen(pData->oscData->path)+6];
  2344. std::strcpy(targetPath, pData->oscData->path);
  2345. std::strcat(targetPath, "/exit");
  2346. try_lo_send(pData->oscData->target, targetPath, "");
  2347. }
  2348. #endif
  2349. // -----------------------------------------------------------------------
  2350. CARLA_BACKEND_END_NAMESPACE