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.

2986 lines
109KB

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