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.

2798 lines
106KB

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