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.

2819 lines
107KB

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