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.

3039 lines
111KB

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