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.

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