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.

2898 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. else
  1131. carla_stderr2("Failed to load a plugin, error was:%s\n", getLastError());
  1132. }
  1133. if (isPreset)
  1134. return true;
  1135. }
  1136. #ifndef BUILD_BRIDGE
  1137. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1138. // now connections
  1139. for (QDomNode node = xmlNode.firstChild(); ! node.isNull(); node = node.nextSibling())
  1140. {
  1141. if (node.toElement().tagName().compare("patchbay", Qt::CaseInsensitive) == 0)
  1142. {
  1143. CarlaString sourcePort, targetPort;
  1144. for (QDomNode patchNode = node.firstChild(); ! patchNode.isNull(); patchNode = patchNode.nextSibling())
  1145. {
  1146. sourcePort.clear();
  1147. targetPort.clear();
  1148. if (patchNode.toElement().tagName().compare("connection", Qt::CaseInsensitive) != 0)
  1149. continue;
  1150. for (QDomNode connNode = patchNode.firstChild(); ! connNode.isNull(); connNode = connNode.nextSibling())
  1151. {
  1152. const QString tag(connNode.toElement().tagName());
  1153. const QString text(connNode.toElement().text().trimmed());
  1154. if (tag.compare("source", Qt::CaseInsensitive) == 0)
  1155. sourcePort = text.toUtf8().constData();
  1156. else if (tag.compare("target", Qt::CaseInsensitive) == 0)
  1157. targetPort = text.toUtf8().constData();
  1158. }
  1159. if (sourcePort.isNotEmpty() && targetPort.isNotEmpty())
  1160. restorePatchbayConnection(sourcePort, targetPort);
  1161. }
  1162. break;
  1163. }
  1164. }
  1165. #endif
  1166. return true;
  1167. }
  1168. bool CarlaEngine::saveProject(const char* const filename)
  1169. {
  1170. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #3)");
  1171. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1172. QFile file(filename);
  1173. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1174. return false;
  1175. QTextStream out(&file);
  1176. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1177. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1178. out << "<CARLA-PROJECT VERSION='2.0'>\n";
  1179. bool firstPlugin = true;
  1180. char strBuf[STR_MAX+1];
  1181. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1182. {
  1183. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1184. if (plugin != nullptr && plugin->isEnabled())
  1185. {
  1186. if (! firstPlugin)
  1187. out << "\n";
  1188. strBuf[0] = '\0';
  1189. plugin->getRealName(strBuf);
  1190. //if (strBuf[0] != '\0')
  1191. // out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1192. QString content;
  1193. fillXmlStringFromSaveState(content, plugin->getSaveState());
  1194. out << " <Plugin>\n";
  1195. out << content;
  1196. out << " </Plugin>\n";
  1197. firstPlugin = false;
  1198. }
  1199. }
  1200. #ifndef BUILD_BRIDGE
  1201. if (const char* const* patchbayConns = getPatchbayConnections())
  1202. {
  1203. if (! firstPlugin)
  1204. out << "\n";
  1205. out << " <Patchbay>\n";
  1206. for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i )
  1207. {
  1208. const char* const connSource(patchbayConns[i]);
  1209. const char* const connTarget(patchbayConns[i+1]);
  1210. CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0');
  1211. CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0');
  1212. out << " <Connection>\n";
  1213. out << " <Source>" << connSource << "</Source>\n";
  1214. out << " <Target>" << connTarget << "</Target>\n";
  1215. out << " </Connection>\n";
  1216. delete[] connSource;
  1217. delete[] connTarget;
  1218. }
  1219. out << " </Patchbay>\n";
  1220. }
  1221. #endif
  1222. out << "</CARLA-PROJECT>\n";
  1223. file.close();
  1224. return true;
  1225. }
  1226. // -----------------------------------------------------------------------
  1227. // Information (base)
  1228. unsigned int CarlaEngine::getHints() const noexcept
  1229. {
  1230. return pData->hints;
  1231. }
  1232. uint32_t CarlaEngine::getBufferSize() const noexcept
  1233. {
  1234. return pData->bufferSize;
  1235. }
  1236. double CarlaEngine::getSampleRate() const noexcept
  1237. {
  1238. return pData->sampleRate;
  1239. }
  1240. const char* CarlaEngine::getName() const noexcept
  1241. {
  1242. return pData->name;
  1243. }
  1244. EngineProcessMode CarlaEngine::getProccessMode() const noexcept
  1245. {
  1246. return pData->options.processMode;
  1247. }
  1248. const EngineOptions& CarlaEngine::getOptions() const noexcept
  1249. {
  1250. return pData->options;
  1251. }
  1252. const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept
  1253. {
  1254. return pData->timeInfo;
  1255. }
  1256. // -----------------------------------------------------------------------
  1257. // Information (peaks)
  1258. float CarlaEngine::getInputPeak(const unsigned int pluginId, const bool isLeft) const noexcept
  1259. {
  1260. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1261. return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1];
  1262. }
  1263. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) const noexcept
  1264. {
  1265. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1266. return pData->plugins[pluginId].outsPeak[isLeft ? 0 : 1];
  1267. }
  1268. // -----------------------------------------------------------------------
  1269. // Callback
  1270. void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept
  1271. {
  1272. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  1273. if (pData->callback != nullptr)
  1274. {
  1275. try {
  1276. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1277. } catch(...) {}
  1278. }
  1279. }
  1280. void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept
  1281. {
  1282. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1283. pData->callback = func;
  1284. pData->callbackPtr = ptr;
  1285. }
  1286. // -----------------------------------------------------------------------
  1287. // File Callback
  1288. const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept
  1289. {
  1290. CARLA_SAFE_ASSERT_RETURN(title != nullptr && title[0] != '\0', nullptr);
  1291. CARLA_SAFE_ASSERT_RETURN(filter != nullptr, nullptr);
  1292. carla_debug("CarlaEngine::runFileCallback(%i:%s, %s, \"%s\", \"%s\")", action, FileCallbackOpcode2Str(action), bool2str(isDir), title, filter);
  1293. const char* ret = nullptr;
  1294. if (pData->fileCallback != nullptr)
  1295. {
  1296. try {
  1297. ret = pData->fileCallback(pData->fileCallbackPtr, action, isDir, title, filter);
  1298. } catch(...) {}
  1299. }
  1300. return ret;
  1301. }
  1302. void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept
  1303. {
  1304. pData->fileCallback = func;
  1305. pData->fileCallbackPtr = ptr;
  1306. }
  1307. #ifndef BUILD_BRIDGE
  1308. // -----------------------------------------------------------------------
  1309. // Patchbay
  1310. bool CarlaEngine::patchbayConnect(const int portA, const int portB)
  1311. {
  1312. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1313. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1314. carla_debug("CarlaEngineRtAudio::patchbayConnect(%i, %i)", portA, portB);
  1315. if (pData->bufAudio.usePatchbay)
  1316. {
  1317. // not implemented yet
  1318. return false;
  1319. }
  1320. EngineRackBuffers* const rack(pData->bufAudio.rack);
  1321. CARLA_SAFE_ASSERT_RETURN_ERR(portA > RACK_PATCHBAY_PORT_MAX, "Invalid output port");
  1322. CARLA_SAFE_ASSERT_RETURN_ERR(portB > RACK_PATCHBAY_PORT_MAX, "Invalid input port");
  1323. // only allow connections between Carla and other ports
  1324. if (portA < 0 && portB < 0)
  1325. {
  1326. setLastError("Invalid connection (1)");
  1327. return false;
  1328. }
  1329. if (portA >= 0 && portB >= 0)
  1330. {
  1331. setLastError("Invalid connection (2)");
  1332. return false;
  1333. }
  1334. const int carlaPort = (portA < 0) ? portA : portB;
  1335. const int targetPort = (carlaPort == portA) ? portB : portA;
  1336. bool makeConnection = false;
  1337. switch (carlaPort)
  1338. {
  1339. case RACK_PATCHBAY_PORT_AUDIO_IN1:
  1340. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1341. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_IN*1000+999);
  1342. rack->connectLock.enter();
  1343. rack->connectedIn1.append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1344. rack->connectLock.leave();
  1345. makeConnection = true;
  1346. break;
  1347. case RACK_PATCHBAY_PORT_AUDIO_IN2:
  1348. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1349. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_IN*1000+999);
  1350. rack->connectLock.enter();
  1351. rack->connectedIn2.append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1352. rack->connectLock.leave();
  1353. makeConnection = true;
  1354. break;
  1355. case RACK_PATCHBAY_PORT_AUDIO_OUT1:
  1356. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1357. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000+999);
  1358. rack->connectLock.enter();
  1359. rack->connectedOut1.append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1360. rack->connectLock.leave();
  1361. makeConnection = true;
  1362. break;
  1363. case RACK_PATCHBAY_PORT_AUDIO_OUT2:
  1364. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1365. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000+999);
  1366. rack->connectLock.enter();
  1367. rack->connectedOut2.append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1368. rack->connectLock.leave();
  1369. makeConnection = true;
  1370. break;
  1371. case RACK_PATCHBAY_PORT_MIDI_IN:
  1372. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1373. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_MIDI_IN*1000+999);
  1374. makeConnection = connectRackMidiInPort(targetPort - RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1375. break;
  1376. case RACK_PATCHBAY_PORT_MIDI_OUT:
  1377. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1378. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_MIDI_OUT*1000+999);
  1379. makeConnection = connectRackMidiOutPort(targetPort - RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1380. break;
  1381. }
  1382. if (! makeConnection)
  1383. {
  1384. setLastError("Invalid connection (3)");
  1385. return false;
  1386. }
  1387. ConnectionToId connectionToId;
  1388. connectionToId.id = rack->lastConnectionId;
  1389. connectionToId.portOut = portA;
  1390. connectionToId.portIn = portB;
  1391. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, portA, portB, 0.0f, nullptr);
  1392. rack->usedConnections.append(connectionToId);
  1393. rack->lastConnectionId++;
  1394. return true;
  1395. }
  1396. bool CarlaEngine::patchbayDisconnect(const uint connectionId)
  1397. {
  1398. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1399. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1400. carla_debug("CarlaEngineRtAudio::patchbayDisconnect(%i)", connectionId);
  1401. if (pData->bufAudio.usePatchbay)
  1402. {
  1403. // not implemented yet
  1404. return false;
  1405. }
  1406. EngineRackBuffers* const rack(pData->bufAudio.rack);
  1407. CARLA_SAFE_ASSERT_RETURN_ERR(rack->usedConnections.count() > 0, "No connections available");
  1408. for (LinkedList<ConnectionToId>::Itenerator it=rack->usedConnections.begin(); it.valid(); it.next())
  1409. {
  1410. const ConnectionToId& connection(it.getValue());
  1411. if (connection.id == connectionId)
  1412. {
  1413. const int otherPort((connection.portOut >= 0) ? connection.portOut : connection.portIn);
  1414. const int carlaPort((otherPort == connection.portOut) ? connection.portIn : connection.portOut);
  1415. if (otherPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000)
  1416. {
  1417. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_MIDI_IN, false);
  1418. const int portId(otherPort-RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1419. disconnectRackMidiInPort(portId);
  1420. }
  1421. else if (otherPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000)
  1422. {
  1423. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_MIDI_OUT, false);
  1424. const int portId(otherPort-RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1425. disconnectRackMidiOutPort(portId);
  1426. }
  1427. else if (otherPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000)
  1428. {
  1429. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT2, false);
  1430. const int portId(otherPort-RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1431. rack->connectLock.enter();
  1432. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1)
  1433. rack->connectedOut1.removeAll(portId);
  1434. else
  1435. rack->connectedOut2.removeAll(portId);
  1436. rack->connectLock.leave();
  1437. }
  1438. else if (otherPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000)
  1439. {
  1440. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN2, false);
  1441. const int portId(otherPort-RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1442. rack->connectLock.enter();
  1443. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1)
  1444. rack->connectedIn1.removeAll(portId);
  1445. else
  1446. rack->connectedIn2.removeAll(portId);
  1447. rack->connectLock.leave();
  1448. }
  1449. else
  1450. {
  1451. CARLA_SAFE_ASSERT_RETURN(false, false);
  1452. }
  1453. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED, connection.id, connection.portOut, connection.portIn, 0.0f, nullptr);
  1454. rack->usedConnections.remove(it);
  1455. return true;
  1456. }
  1457. }
  1458. setLastError("Failed to find connection");
  1459. return false;
  1460. }
  1461. bool CarlaEngine::patchbayRefresh()
  1462. {
  1463. setLastError("Unsupported operation");
  1464. return false;
  1465. }
  1466. #endif
  1467. // -----------------------------------------------------------------------
  1468. // Transport
  1469. void CarlaEngine::transportPlay() noexcept
  1470. {
  1471. pData->time.playing = true;
  1472. }
  1473. void CarlaEngine::transportPause() noexcept
  1474. {
  1475. pData->time.playing = false;
  1476. }
  1477. void CarlaEngine::transportRelocate(const uint64_t frame) noexcept
  1478. {
  1479. pData->time.frame = frame;
  1480. }
  1481. // -----------------------------------------------------------------------
  1482. // Error handling
  1483. const char* CarlaEngine::getLastError() const noexcept
  1484. {
  1485. return pData->lastError;
  1486. }
  1487. void CarlaEngine::setLastError(const char* const error) const
  1488. {
  1489. pData->lastError = error;
  1490. }
  1491. void CarlaEngine::setAboutToClose() noexcept
  1492. {
  1493. carla_debug("CarlaEngine::setAboutToClose()");
  1494. pData->aboutToClose = true;
  1495. }
  1496. // -----------------------------------------------------------------------
  1497. // Global options
  1498. void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr)
  1499. {
  1500. carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
  1501. if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
  1502. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
  1503. switch (option)
  1504. {
  1505. case ENGINE_OPTION_DEBUG:
  1506. break;
  1507. case ENGINE_OPTION_PROCESS_MODE:
  1508. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
  1509. pData->options.processMode = static_cast<EngineProcessMode>(value);
  1510. break;
  1511. case ENGINE_OPTION_TRANSPORT_MODE:
  1512. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
  1513. pData->options.transportMode = static_cast<EngineTransportMode>(value);
  1514. break;
  1515. case ENGINE_OPTION_FORCE_STEREO:
  1516. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1517. pData->options.forceStereo = (value != 0);
  1518. break;
  1519. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  1520. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1521. pData->options.preferPluginBridges = (value != 0);
  1522. break;
  1523. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  1524. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1525. pData->options.preferUiBridges = (value != 0);
  1526. break;
  1527. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  1528. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1529. pData->options.uisAlwaysOnTop = (value != 0);
  1530. break;
  1531. case ENGINE_OPTION_MAX_PARAMETERS:
  1532. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1533. pData->options.maxParameters = static_cast<uint>(value);
  1534. break;
  1535. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  1536. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1537. pData->options.uiBridgesTimeout = static_cast<uint>(value);
  1538. break;
  1539. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  1540. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  1541. pData->options.audioNumPeriods = static_cast<uint>(value);
  1542. break;
  1543. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  1544. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  1545. pData->options.audioBufferSize = static_cast<uint>(value);
  1546. break;
  1547. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  1548. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  1549. pData->options.audioSampleRate = static_cast<uint>(value);
  1550. break;
  1551. case ENGINE_OPTION_AUDIO_DEVICE:
  1552. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  1553. if (pData->options.audioDevice != nullptr)
  1554. delete[] pData->options.audioDevice;
  1555. pData->options.audioDevice = carla_strdup(valueStr);
  1556. break;
  1557. case ENGINE_OPTION_PATH_BINARIES:
  1558. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1559. if (pData->options.binaryDir != nullptr)
  1560. delete[] pData->options.binaryDir;
  1561. pData->options.binaryDir = carla_strdup(valueStr);
  1562. break;
  1563. case ENGINE_OPTION_PATH_RESOURCES:
  1564. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1565. if (pData->options.resourceDir != nullptr)
  1566. delete[] pData->options.resourceDir;
  1567. pData->options.resourceDir = carla_strdup(valueStr);
  1568. break;
  1569. case ENGINE_OPTION_FRONTEND_WIN_ID:
  1570. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1571. const long winId(std::atol(valueStr));
  1572. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  1573. pData->options.frontendWinId = static_cast<uintptr_t>(winId);
  1574. break;
  1575. }
  1576. }
  1577. // -----------------------------------------------------------------------
  1578. // OSC Stuff
  1579. #ifdef BUILD_BRIDGE
  1580. bool CarlaEngine::isOscBridgeRegistered() const noexcept
  1581. {
  1582. return (pData->oscData != nullptr);
  1583. }
  1584. #else
  1585. bool CarlaEngine::isOscControlRegistered() const noexcept
  1586. {
  1587. return pData->osc.isControlRegistered();
  1588. }
  1589. #endif
  1590. void CarlaEngine::idleOsc() const noexcept
  1591. {
  1592. try {
  1593. pData->osc.idle();
  1594. } catch(...) {}
  1595. }
  1596. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1597. {
  1598. return pData->osc.getServerPathTCP();
  1599. }
  1600. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1601. {
  1602. return pData->osc.getServerPathUDP();
  1603. }
  1604. #ifdef BUILD_BRIDGE
  1605. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept
  1606. {
  1607. pData->oscData = oscData;
  1608. }
  1609. #endif
  1610. // -----------------------------------------------------------------------
  1611. // Helper functions
  1612. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1613. {
  1614. return isInput ? pData->bufEvents.in : pData->bufEvents.out;
  1615. }
  1616. void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept
  1617. {
  1618. CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,);
  1619. carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin);
  1620. pData->plugins[id].plugin = plugin;
  1621. }
  1622. // -----------------------------------------------------------------------
  1623. // Internal stuff
  1624. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1625. {
  1626. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1627. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1628. {
  1629. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1630. if (plugin != nullptr && plugin->isEnabled())
  1631. plugin->bufferSizeChanged(newBufferSize);
  1632. }
  1633. callback(ENGINE_CALLBACK_BUFFER_SIZE_CHANGED, 0, static_cast<int>(newBufferSize), 0, 0.0f, nullptr);
  1634. }
  1635. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1636. {
  1637. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1638. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1639. {
  1640. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1641. if (plugin != nullptr && plugin->isEnabled())
  1642. plugin->sampleRateChanged(newSampleRate);
  1643. }
  1644. callback(ENGINE_CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, static_cast<float>(newSampleRate), nullptr);
  1645. }
  1646. void CarlaEngine::offlineModeChanged(const bool isOfflineNow)
  1647. {
  1648. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOfflineNow));
  1649. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1650. {
  1651. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1652. if (plugin != nullptr && plugin->isEnabled())
  1653. plugin->offlineModeChanged(isOfflineNow);
  1654. }
  1655. }
  1656. void CarlaEngine::runPendingRtEvents() noexcept
  1657. {
  1658. pData->doNextPluginAction(true);
  1659. if (pData->time.playing)
  1660. pData->time.frame += pData->bufferSize;
  1661. if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL)
  1662. {
  1663. pData->timeInfo.playing = pData->time.playing;
  1664. pData->timeInfo.frame = pData->time.frame;
  1665. }
  1666. }
  1667. void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1668. {
  1669. EnginePluginData& pluginData(pData->plugins[pluginId]);
  1670. pluginData.insPeak[0] = inPeaks[0];
  1671. pluginData.insPeak[1] = inPeaks[1];
  1672. pluginData.outsPeak[0] = outPeaks[0];
  1673. pluginData.outsPeak[1] = outPeaks[1];
  1674. }
  1675. #ifndef BUILD_BRIDGE
  1676. // -----------------------------------------------------------------------
  1677. // Patchbay stuff
  1678. const char* const* CarlaEngine::getPatchbayConnections() const
  1679. {
  1680. carla_debug("CarlaEngine::getPatchbayConnections()");
  1681. if (pData->bufAudio.usePatchbay)
  1682. {
  1683. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.patchbay != nullptr, nullptr);
  1684. return pData->bufAudio.patchbay->getConnections();
  1685. }
  1686. else
  1687. {
  1688. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.rack != nullptr, nullptr);
  1689. return pData->bufAudio.rack->getConnections();
  1690. }
  1691. }
  1692. static int getCarlaPortIdFromName(const char* const shortname) noexcept
  1693. {
  1694. if (std::strcmp(shortname, "AudioIn1") == 0)
  1695. return RACK_PATCHBAY_PORT_AUDIO_IN1;
  1696. if (std::strcmp(shortname, "AudioIn2") == 0)
  1697. return RACK_PATCHBAY_PORT_AUDIO_IN2;
  1698. if (std::strcmp(shortname, "AudioOut1") == 0)
  1699. return RACK_PATCHBAY_PORT_AUDIO_OUT1;
  1700. if (std::strcmp(shortname, "AudioOut2") == 0)
  1701. return RACK_PATCHBAY_PORT_AUDIO_OUT2;
  1702. if (std::strcmp(shortname, "MidiIn") == 0)
  1703. return RACK_PATCHBAY_PORT_MIDI_IN;
  1704. if (std::strcmp(shortname, "MidiOut") == 0)
  1705. return RACK_PATCHBAY_PORT_MIDI_OUT;
  1706. return RACK_PATCHBAY_PORT_MAX;
  1707. }
  1708. void CarlaEngine::restorePatchbayConnection(const char* const connSource, const char* const connTarget)
  1709. {
  1710. CARLA_SAFE_ASSERT_RETURN(connSource != nullptr && connSource[0] != '\0',);
  1711. CARLA_SAFE_ASSERT_RETURN(connTarget != nullptr && connTarget[0] != '\0',);
  1712. carla_debug("CarlaEngine::restorePatchbayConnection(\"%s\", \"%s\")", connSource, connTarget);
  1713. if (pData->bufAudio.usePatchbay)
  1714. {
  1715. // TODO
  1716. }
  1717. else
  1718. {
  1719. int sourcePort, targetPort;
  1720. if (std::strncmp(connSource, "Carla:", 6) == 0)
  1721. sourcePort = getCarlaPortIdFromName(connSource+6);
  1722. else if (std::strncmp(connSource, "AudioIn:", 8) == 0)
  1723. sourcePort = std::atoi(connSource+8) + RACK_PATCHBAY_GROUP_AUDIO_IN*1000 - 1;
  1724. else if (std::strncmp(connSource, "AudioOut:", 9) == 0)
  1725. sourcePort = std::atoi(connSource+9) + RACK_PATCHBAY_GROUP_AUDIO_OUT*1000 - 1;
  1726. else if (std::strncmp(connSource, "MidiIn:", 7) == 0)
  1727. sourcePort = std::atoi(connSource+7) + RACK_PATCHBAY_GROUP_MIDI_IN*1000 - 1;
  1728. else if (std::strncmp(connSource, "MidiOut:", 8) == 0)
  1729. sourcePort = std::atoi(connSource+8) + RACK_PATCHBAY_GROUP_MIDI_OUT*1000 - 1;
  1730. else
  1731. sourcePort = RACK_PATCHBAY_PORT_MAX;
  1732. if (std::strncmp(connTarget, "Carla:", 6) == 0)
  1733. targetPort = getCarlaPortIdFromName(connTarget+6);
  1734. else if (std::strncmp(connTarget, "AudioIn:", 8) == 0)
  1735. targetPort = std::atoi(connTarget+8) + RACK_PATCHBAY_GROUP_AUDIO_IN*1000 - 1;
  1736. else if (std::strncmp(connTarget, "AudioOut:", 9) == 0)
  1737. targetPort = std::atoi(connTarget+9) + RACK_PATCHBAY_GROUP_AUDIO_OUT*1000 - 1;
  1738. else if (std::strncmp(connTarget, "MidiIn:", 7) == 0)
  1739. targetPort = std::atoi(connTarget+7) + RACK_PATCHBAY_GROUP_MIDI_IN*1000 - 1;
  1740. else if (std::strncmp(connTarget, "MidiOut:", 8) == 0)
  1741. targetPort = std::atoi(connTarget+8) + RACK_PATCHBAY_GROUP_MIDI_OUT*1000 - 1;
  1742. else
  1743. targetPort = RACK_PATCHBAY_PORT_MAX;
  1744. if (sourcePort != RACK_PATCHBAY_PORT_MAX && targetPort != RACK_PATCHBAY_PORT_MAX)
  1745. patchbayConnect(targetPort, sourcePort);
  1746. }
  1747. }
  1748. #endif
  1749. // -----------------------------------------------------------------------
  1750. // Bridge/Controller OSC stuff
  1751. #ifdef BUILD_BRIDGE
  1752. void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const int64_t uniqueId) const noexcept
  1753. {
  1754. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1755. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1756. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1757. carla_debug("CarlaEngine::oscSend_bridge_plugin_info1(%i:%s, %X, " P_INT64 ")", category, PluginCategory2Str(category), hints, uniqueId);
  1758. char targetPath[std::strlen(pData->oscData->path)+21];
  1759. std::strcpy(targetPath, pData->oscData->path);
  1760. std::strcat(targetPath, "/bridge_plugin_info1");
  1761. try_lo_send(pData->oscData->target, targetPath, "iih", static_cast<int32_t>(category), static_cast<int32_t>(hints), uniqueId);
  1762. }
  1763. void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  1764. {
  1765. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1766. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1767. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1768. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  1769. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  1770. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  1771. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  1772. carla_debug("CarlaEngine::oscSend_bridge_plugin_info2(\"%s\", \"%s\", \"%s\", \"%s\")", realName, label, maker, copyright);
  1773. char targetPath[std::strlen(pData->oscData->path)+21];
  1774. std::strcpy(targetPath, pData->oscData->path);
  1775. std::strcat(targetPath, "/bridge_plugin_info2");
  1776. try_lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright);
  1777. }
  1778. void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept
  1779. {
  1780. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1781. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1782. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1783. carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i)", ins, outs);
  1784. char targetPath[std::strlen(pData->oscData->path)+20];
  1785. std::strcpy(targetPath, pData->oscData->path);
  1786. std::strcat(targetPath, "/bridge_audio_count");
  1787. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1788. }
  1789. void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept
  1790. {
  1791. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1792. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1793. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1794. carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i)", ins, outs);
  1795. char targetPath[std::strlen(pData->oscData->path)+19];
  1796. std::strcpy(targetPath, pData->oscData->path);
  1797. std::strcat(targetPath, "/bridge_midi_count");
  1798. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1799. }
  1800. void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept
  1801. {
  1802. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1803. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1804. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1805. carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i)", ins, outs);
  1806. char targetPath[std::strlen(pData->oscData->path)+24];
  1807. std::strcpy(targetPath, pData->oscData->path);
  1808. std::strcat(targetPath, "/bridge_parameter_count");
  1809. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1810. }
  1811. void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const noexcept
  1812. {
  1813. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1814. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1815. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1816. carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
  1817. char targetPath[std::strlen(pData->oscData->path)+23];
  1818. std::strcpy(targetPath, pData->oscData->path);
  1819. std::strcat(targetPath, "/bridge_program_count");
  1820. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1821. }
  1822. void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const noexcept
  1823. {
  1824. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1825. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1826. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1827. carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
  1828. char targetPath[std::strlen(pData->oscData->path)+27];
  1829. std::strcpy(targetPath, pData->oscData->path);
  1830. std::strcat(targetPath, "/bridge_midi_program_count");
  1831. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1832. }
  1833. 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
  1834. {
  1835. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1836. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1837. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1838. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1839. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  1840. carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", index, rindex, type, ParameterType2Str(type), hints, name, unit);
  1841. char targetPath[std::strlen(pData->oscData->path)+23];
  1842. std::strcpy(targetPath, pData->oscData->path);
  1843. std::strcat(targetPath, "/bridge_parameter_data");
  1844. 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);
  1845. }
  1846. void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept
  1847. {
  1848. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1849. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1850. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1851. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, def, min, max);
  1852. char targetPath[std::strlen(pData->oscData->path)+26];
  1853. std::strcpy(targetPath, pData->oscData->path);
  1854. std::strcat(targetPath, "/bridge_parameter_ranges1");
  1855. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), def, min, max);
  1856. }
  1857. void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  1858. {
  1859. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1860. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1861. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1862. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, step, stepSmall, stepLarge);
  1863. char targetPath[std::strlen(pData->oscData->path)+26];
  1864. std::strcpy(targetPath, pData->oscData->path);
  1865. std::strcat(targetPath, "/bridge_parameter_ranges2");
  1866. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), step, stepSmall, stepLarge);
  1867. }
  1868. void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept
  1869. {
  1870. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1871. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1872. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1873. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_cc(%i, %i)", index, cc);
  1874. char targetPath[std::strlen(pData->oscData->path)+26];
  1875. std::strcpy(targetPath, pData->oscData->path);
  1876. std::strcat(targetPath, "/bridge_parameter_midi_cc");
  1877. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(cc));
  1878. }
  1879. void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept
  1880. {
  1881. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1882. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1883. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1884. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_channel(%i, %i)", index, channel);
  1885. char targetPath[std::strlen(pData->oscData->path)+31];
  1886. std::strcpy(targetPath, pData->oscData->path);
  1887. std::strcat(targetPath, "/bridge_parameter_midi_channel");
  1888. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(channel));
  1889. }
  1890. void CarlaEngine::oscSend_bridge_parameter_value(const uint32_t index, const float value) const noexcept
  1891. {
  1892. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1893. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1894. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1895. carla_debug("CarlaEngine::oscSend_bridge_parameter_value(%i, %f)", index, value);
  1896. char targetPath[std::strlen(pData->oscData->path)+24];
  1897. std::strcpy(targetPath, pData->oscData->path);
  1898. std::strcat(targetPath, "/bridge_parameter_value");
  1899. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1900. }
  1901. void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept
  1902. {
  1903. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1904. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1905. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1906. carla_debug("CarlaEngine::oscSend_bridge_default_value(%i, %f)", index, value);
  1907. char targetPath[std::strlen(pData->oscData->path)+22];
  1908. std::strcpy(targetPath, pData->oscData->path);
  1909. std::strcat(targetPath, "/bridge_default_value");
  1910. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1911. }
  1912. void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const noexcept
  1913. {
  1914. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1915. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1916. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1917. carla_debug("CarlaEngine::oscSend_bridge_current_program(%i)", index);
  1918. char targetPath[std::strlen(pData->oscData->path)+24];
  1919. std::strcpy(targetPath, pData->oscData->path);
  1920. std::strcat(targetPath, "/bridge_current_program");
  1921. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1922. }
  1923. void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const noexcept
  1924. {
  1925. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1926. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1927. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1928. carla_debug("CarlaEngine::oscSend_bridge_current_midi_program(%i)", index);
  1929. char targetPath[std::strlen(pData->oscData->path)+30];
  1930. std::strcpy(targetPath, pData->oscData->path);
  1931. std::strcat(targetPath, "/bridge_current_midi_program");
  1932. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1933. }
  1934. void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept
  1935. {
  1936. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1937. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1938. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1939. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1940. carla_debug("CarlaEngine::oscSend_bridge_program_name(%i, \"%s\")", index, name);
  1941. char targetPath[std::strlen(pData->oscData->path)+21];
  1942. std::strcpy(targetPath, pData->oscData->path);
  1943. std::strcat(targetPath, "/bridge_program_name");
  1944. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(index), name);
  1945. }
  1946. 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
  1947. {
  1948. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1949. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1950. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1951. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1952. carla_debug("CarlaEngine::oscSend_bridge_midi_program_data(%i, %i, %i, \"%s\")", index, bank, program, name);
  1953. char targetPath[std::strlen(pData->oscData->path)+26];
  1954. std::strcpy(targetPath, pData->oscData->path);
  1955. std::strcat(targetPath, "/bridge_midi_program_data");
  1956. try_lo_send(pData->oscData->target, targetPath, "iiis", static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  1957. }
  1958. void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const noexcept
  1959. {
  1960. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1961. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1962. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1963. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1964. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1965. carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
  1966. char targetPath[std::strlen(pData->oscData->path)+18];
  1967. std::strcpy(targetPath, pData->oscData->path);
  1968. std::strcat(targetPath, "/bridge_configure");
  1969. try_lo_send(pData->oscData->target, targetPath, "ss", key, value);
  1970. }
  1971. void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept
  1972. {
  1973. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1974. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1975. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1976. CARLA_SAFE_ASSERT_RETURN(type != nullptr && type[0] != '\0',);
  1977. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1978. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1979. carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1980. char targetPath[std::strlen(pData->oscData->path)+24];
  1981. std::strcpy(targetPath, pData->oscData->path);
  1982. std::strcat(targetPath, "/bridge_set_custom_data");
  1983. try_lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
  1984. }
  1985. void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept
  1986. {
  1987. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1988. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1989. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1990. CARLA_SAFE_ASSERT_RETURN(chunkFile != nullptr && chunkFile[0] != '\0',);
  1991. carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
  1992. char targetPath[std::strlen(pData->oscData->path)+23];
  1993. std::strcpy(targetPath, pData->oscData->path);
  1994. std::strcat(targetPath, "/bridge_set_chunk_data");
  1995. try_lo_send(pData->oscData->target, targetPath, "s", chunkFile);
  1996. }
  1997. void CarlaEngine::oscSend_bridge_pong() const noexcept
  1998. {
  1999. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2000. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2001. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2002. //carla_debug("CarlaEngine::oscSend_pong()");
  2003. char targetPath[std::strlen(pData->oscData->path)+13];
  2004. std::strcpy(targetPath, pData->oscData->path);
  2005. std::strcat(targetPath, "/bridge_pong");
  2006. try_lo_send(pData->oscData->target, targetPath, "");
  2007. }
  2008. #else
  2009. void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept
  2010. {
  2011. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2012. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2013. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2014. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2015. CARLA_SAFE_ASSERT_RETURN(pluginName != nullptr && pluginName[0] != '\0',);
  2016. carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  2017. char targetPath[std::strlen(pData->oscData->path)+18];
  2018. std::strcpy(targetPath, pData->oscData->path);
  2019. std::strcat(targetPath, "/add_plugin_start");
  2020. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(pluginId), pluginName);
  2021. }
  2022. void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const noexcept
  2023. {
  2024. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2025. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2026. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2027. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2028. carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
  2029. char targetPath[std::strlen(pData->oscData->path)+16];
  2030. std::strcpy(targetPath, pData->oscData->path);
  2031. std::strcat(targetPath, "/add_plugin_end");
  2032. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2033. }
  2034. void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const noexcept
  2035. {
  2036. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2037. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2038. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2039. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2040. carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
  2041. char targetPath[std::strlen(pData->oscData->path)+15];
  2042. std::strcpy(targetPath, pData->oscData->path);
  2043. std::strcat(targetPath, "/remove_plugin");
  2044. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2045. }
  2046. 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
  2047. {
  2048. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2049. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2050. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2051. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2052. CARLA_SAFE_ASSERT_RETURN(type != PLUGIN_NONE,);
  2053. 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);
  2054. char targetPath[std::strlen(pData->oscData->path)+18];
  2055. std::strcpy(targetPath, pData->oscData->path);
  2056. std::strcat(targetPath, "/set_plugin_info1");
  2057. 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));
  2058. }
  2059. 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
  2060. {
  2061. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2062. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2063. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2064. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2065. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  2066. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  2067. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  2068. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  2069. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, \"%s\", \"%s\", \"%s\", \"%s\")", pluginId, realName, label, maker, copyright);
  2070. char targetPath[std::strlen(pData->oscData->path)+18];
  2071. std::strcpy(targetPath, pData->oscData->path);
  2072. std::strcat(targetPath, "/set_plugin_info2");
  2073. try_lo_send(pData->oscData->target, targetPath, "issss", static_cast<int32_t>(pluginId), realName, label, maker, copyright);
  2074. }
  2075. void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2076. {
  2077. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2078. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2079. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2080. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2081. carla_debug("CarlaEngine::oscSend_control_set_audio_count(%i, %i, %i)", pluginId, ins, outs);
  2082. char targetPath[std::strlen(pData->oscData->path)+18];
  2083. std::strcpy(targetPath, pData->oscData->path);
  2084. std::strcat(targetPath, "/set_audio_count");
  2085. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2086. }
  2087. void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2088. {
  2089. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2090. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2091. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2092. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2093. carla_debug("CarlaEngine::oscSend_control_set_midi_count(%i, %i, %i)", pluginId, ins, outs);
  2094. char targetPath[std::strlen(pData->oscData->path)+18];
  2095. std::strcpy(targetPath, pData->oscData->path);
  2096. std::strcat(targetPath, "/set_midi_count");
  2097. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2098. }
  2099. void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2100. {
  2101. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2102. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2103. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2104. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2105. carla_debug("CarlaEngine::oscSend_control_set_parameter_count(%i, %i, %i)", pluginId, ins, outs);
  2106. char targetPath[std::strlen(pData->oscData->path)+18];
  2107. std::strcpy(targetPath, pData->oscData->path);
  2108. std::strcat(targetPath, "/set_parameter_count");
  2109. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2110. }
  2111. void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept
  2112. {
  2113. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2114. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2115. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2116. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2117. carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
  2118. char targetPath[std::strlen(pData->oscData->path)+19];
  2119. std::strcpy(targetPath, pData->oscData->path);
  2120. std::strcat(targetPath, "/set_program_count");
  2121. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2122. }
  2123. void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept
  2124. {
  2125. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2126. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2127. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2128. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2129. carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
  2130. char targetPath[std::strlen(pData->oscData->path)+24];
  2131. std::strcpy(targetPath, pData->oscData->path);
  2132. std::strcat(targetPath, "/set_midi_program_count");
  2133. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2134. }
  2135. 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
  2136. {
  2137. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2138. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2139. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2140. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2141. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  2142. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  2143. carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", pluginId, index, type, ParameterType2Str(type), hints, name, unit);
  2144. char targetPath[std::strlen(pData->oscData->path)+20];
  2145. std::strcpy(targetPath, pData->oscData->path);
  2146. std::strcat(targetPath, "/set_parameter_data");
  2147. 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);
  2148. }
  2149. 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
  2150. {
  2151. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2152. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2153. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2154. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2155. CARLA_SAFE_ASSERT_RETURN(def <= min && def >= max,);
  2156. CARLA_SAFE_ASSERT_RETURN(min < max,);
  2157. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges1(%i, %i, %f, %f, %f)", pluginId, index, def, min, max, def);
  2158. char targetPath[std::strlen(pData->oscData->path)+23];
  2159. std::strcpy(targetPath, pData->oscData->path);
  2160. std::strcat(targetPath, "/set_parameter_ranges1");
  2161. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), def, min, max);
  2162. }
  2163. 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
  2164. {
  2165. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2166. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2167. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2168. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2169. CARLA_SAFE_ASSERT_RETURN(step <= stepSmall && step >= stepLarge,);
  2170. CARLA_SAFE_ASSERT_RETURN(stepSmall <= stepLarge,);
  2171. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges2(%i, %i, %f, %f, %f)", pluginId, index, step, stepSmall, stepLarge);
  2172. char targetPath[std::strlen(pData->oscData->path)+23];
  2173. std::strcpy(targetPath, pData->oscData->path);
  2174. std::strcat(targetPath, "/set_parameter_ranges");
  2175. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), step, stepSmall, stepLarge);
  2176. }
  2177. void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept
  2178. {
  2179. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2180. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2181. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2182. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2183. CARLA_SAFE_ASSERT_RETURN(cc <= 0x5F,);
  2184. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  2185. char targetPath[std::strlen(pData->oscData->path)+23];
  2186. std::strcpy(targetPath, pData->oscData->path);
  2187. std::strcat(targetPath, "/set_parameter_midi_cc");
  2188. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(cc));
  2189. }
  2190. void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept
  2191. {
  2192. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2193. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2194. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2195. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2196. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2197. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  2198. char targetPath[std::strlen(pData->oscData->path)+28];
  2199. std::strcpy(targetPath, pData->oscData->path);
  2200. std::strcat(targetPath, "/set_parameter_midi_channel");
  2201. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(channel));
  2202. }
  2203. void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept
  2204. {
  2205. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2206. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2207. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2208. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2209. CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
  2210. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i:%s, %f)", pluginId, index, (index < 0) ? InternalParameterIndex2Str(static_cast<InternalParameterIndex>(index)) : "(none)", value);
  2211. char targetPath[std::strlen(pData->oscData->path)+21];
  2212. std::strcpy(targetPath, pData->oscData->path);
  2213. std::strcat(targetPath, "/set_parameter_value");
  2214. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), index, value);
  2215. }
  2216. void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept
  2217. {
  2218. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2219. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2220. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2221. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2222. carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  2223. char targetPath[std::strlen(pData->oscData->path)+19];
  2224. std::strcpy(targetPath, pData->oscData->path);
  2225. std::strcat(targetPath, "/set_default_value");
  2226. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), value);
  2227. }
  2228. void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept
  2229. {
  2230. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2231. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2232. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2233. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2234. carla_debug("CarlaEngine::oscSend_control_set_current_program(%i, %i)", pluginId, index);
  2235. char targetPath[std::strlen(pData->oscData->path)+21];
  2236. std::strcpy(targetPath, pData->oscData->path);
  2237. std::strcat(targetPath, "/set_current_program");
  2238. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2239. }
  2240. void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept
  2241. {
  2242. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2243. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2244. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2245. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2246. carla_debug("CarlaEngine::oscSend_control_set_current_midi_program(%i, %i)", pluginId, index);
  2247. char targetPath[std::strlen(pData->oscData->path)+26];
  2248. std::strcpy(targetPath, pData->oscData->path);
  2249. std::strcat(targetPath, "/set_current_midi_program");
  2250. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2251. }
  2252. void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept
  2253. {
  2254. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2255. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2256. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2257. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2258. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2259. carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  2260. char targetPath[std::strlen(pData->oscData->path)+18];
  2261. std::strcpy(targetPath, pData->oscData->path);
  2262. std::strcat(targetPath, "/set_program_name");
  2263. try_lo_send(pData->oscData->target, targetPath, "iis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), name);
  2264. }
  2265. 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
  2266. {
  2267. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2268. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2269. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2270. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2271. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2272. carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  2273. char targetPath[std::strlen(pData->oscData->path)+23];
  2274. std::strcpy(targetPath, pData->oscData->path);
  2275. std::strcat(targetPath, "/set_midi_program_data");
  2276. 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);
  2277. }
  2278. void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept
  2279. {
  2280. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2281. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2282. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2283. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2284. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2285. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2286. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  2287. carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  2288. char targetPath[std::strlen(pData->oscData->path)+9];
  2289. std::strcpy(targetPath, pData->oscData->path);
  2290. std::strcat(targetPath, "/note_on");
  2291. 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));
  2292. }
  2293. void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept
  2294. {
  2295. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2296. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2297. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2298. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2299. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2300. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2301. carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
  2302. char targetPath[std::strlen(pData->oscData->path)+10];
  2303. std::strcpy(targetPath, pData->oscData->path);
  2304. std::strcat(targetPath, "/note_off");
  2305. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note));
  2306. }
  2307. void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) const noexcept
  2308. {
  2309. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2310. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2311. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2312. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2313. // TODO - try and see if we can get peaks[4] ref
  2314. const EnginePluginData& epData(pData->plugins[pluginId]);
  2315. char targetPath[std::strlen(pData->oscData->path)+11];
  2316. std::strcpy(targetPath, pData->oscData->path);
  2317. std::strcat(targetPath, "/set_peaks");
  2318. 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]);
  2319. }
  2320. void CarlaEngine::oscSend_control_exit() const noexcept
  2321. {
  2322. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2323. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2324. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2325. carla_debug("CarlaEngine::oscSend_control_exit()");
  2326. char targetPath[std::strlen(pData->oscData->path)+6];
  2327. std::strcpy(targetPath, pData->oscData->path);
  2328. std::strcat(targetPath, "/exit");
  2329. try_lo_send(pData->oscData->target, targetPath, "");
  2330. }
  2331. #endif
  2332. // -----------------------------------------------------------------------
  2333. CARLA_BACKEND_END_NAMESPACE