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.

2896 lines
109KB

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