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