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.

2936 lines
110KB

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