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.

2870 lines
109KB

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