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.

2661 lines
100KB

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