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.

2644 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. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, portA, portB, 0.0f, nullptr);
  1279. rack->usedConnections.append(connectionToId);
  1280. rack->lastConnectionId++;
  1281. return true;
  1282. }
  1283. bool CarlaEngine::patchbayDisconnect(const int connectionId)
  1284. {
  1285. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1286. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1287. carla_debug("CarlaEngineRtAudio::patchbayDisconnect(%i)", connectionId);
  1288. if (pData->bufAudio.usePatchbay)
  1289. {
  1290. // not implemented yet
  1291. return false;
  1292. }
  1293. EngineRackBuffers* const rack(pData->bufAudio.rack);
  1294. CARLA_SAFE_ASSERT_RETURN_ERR(rack->usedConnections.count() > 0, "No connections available");
  1295. for (LinkedList<ConnectionToId>::Itenerator it=rack->usedConnections.begin(); it.valid(); it.next())
  1296. {
  1297. const ConnectionToId& connection(it.getValue());
  1298. if (connection.id == connectionId)
  1299. {
  1300. const int targetPort((connection.portOut >= 0) ? connection.portOut : connection.portIn);
  1301. const int carlaPort((targetPort == connection.portOut) ? connection.portIn : connection.portOut);
  1302. if (targetPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000)
  1303. {
  1304. const int portId(targetPort-RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1305. disconnectRackMidiInPort(portId);
  1306. }
  1307. else if (targetPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000)
  1308. {
  1309. const int portId(targetPort-RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1310. disconnectRackMidiOutPort(portId);
  1311. }
  1312. else if (targetPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000)
  1313. {
  1314. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT2, false);
  1315. const int portId(targetPort-RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1316. rack->connectLock.lock();
  1317. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1)
  1318. rack->connectedOuts[0].removeAll(portId);
  1319. else
  1320. rack->connectedOuts[1].removeAll(portId);
  1321. rack->connectLock.unlock();
  1322. }
  1323. else if (targetPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000)
  1324. {
  1325. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN2, false);
  1326. const int portId(targetPort-RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1327. rack->connectLock.lock();
  1328. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1)
  1329. rack->connectedIns[0].removeAll(portId);
  1330. else
  1331. rack->connectedIns[1].removeAll(portId);
  1332. rack->connectLock.unlock();
  1333. }
  1334. else
  1335. {
  1336. CARLA_SAFE_ASSERT_RETURN(false, false);
  1337. }
  1338. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED, connection.id, connection.portOut, connection.portIn, 0.0f, nullptr);
  1339. rack->usedConnections.remove(it);
  1340. break;
  1341. }
  1342. }
  1343. return true;
  1344. }
  1345. bool CarlaEngine::patchbayRefresh()
  1346. {
  1347. setLastError("Unsupported operation");
  1348. return false;
  1349. }
  1350. #endif
  1351. // -----------------------------------------------------------------------
  1352. // Transport
  1353. void CarlaEngine::transportPlay() noexcept
  1354. {
  1355. pData->time.playing = true;
  1356. }
  1357. void CarlaEngine::transportPause() noexcept
  1358. {
  1359. pData->time.playing = false;
  1360. }
  1361. void CarlaEngine::transportRelocate(const uint64_t frame) noexcept
  1362. {
  1363. pData->time.frame = frame;
  1364. }
  1365. // -----------------------------------------------------------------------
  1366. // Error handling
  1367. const char* CarlaEngine::getLastError() const noexcept
  1368. {
  1369. return pData->lastError.getBuffer();
  1370. }
  1371. void CarlaEngine::setLastError(const char* const error) const
  1372. {
  1373. pData->lastError = error;
  1374. }
  1375. void CarlaEngine::setAboutToClose() noexcept
  1376. {
  1377. carla_debug("CarlaEngine::setAboutToClose()");
  1378. pData->aboutToClose = true;
  1379. }
  1380. // -----------------------------------------------------------------------
  1381. // Global options
  1382. void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr)
  1383. {
  1384. carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
  1385. if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
  1386. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
  1387. switch (option)
  1388. {
  1389. case ENGINE_OPTION_DEBUG:
  1390. break;
  1391. case ENGINE_OPTION_PROCESS_MODE:
  1392. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
  1393. pData->options.processMode = static_cast<EngineProcessMode>(value);
  1394. break;
  1395. case ENGINE_OPTION_TRANSPORT_MODE:
  1396. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
  1397. pData->options.transportMode = static_cast<EngineTransportMode>(value);
  1398. break;
  1399. case ENGINE_OPTION_FORCE_STEREO:
  1400. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1401. pData->options.forceStereo = (value != 0);
  1402. break;
  1403. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  1404. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1405. pData->options.preferPluginBridges = (value != 0);
  1406. break;
  1407. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  1408. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1409. pData->options.preferUiBridges = (value != 0);
  1410. break;
  1411. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  1412. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1413. pData->options.uisAlwaysOnTop = (value != 0);
  1414. break;
  1415. case ENGINE_OPTION_MAX_PARAMETERS:
  1416. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1417. pData->options.maxParameters = static_cast<uint>(value);
  1418. break;
  1419. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  1420. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1421. pData->options.uiBridgesTimeout = static_cast<uint>(value);
  1422. break;
  1423. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  1424. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  1425. pData->options.audioNumPeriods = static_cast<uint>(value);
  1426. break;
  1427. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  1428. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  1429. pData->options.audioBufferSize = static_cast<uint>(value);
  1430. break;
  1431. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  1432. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  1433. pData->options.audioSampleRate = static_cast<uint>(value);
  1434. break;
  1435. case ENGINE_OPTION_AUDIO_DEVICE:
  1436. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1437. if (pData->options.audioDevice != nullptr)
  1438. delete[] pData->options.audioDevice;
  1439. pData->options.audioDevice = carla_strdup(valueStr);
  1440. break;
  1441. case ENGINE_OPTION_PATH_BINARIES:
  1442. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1443. if (pData->options.binaryDir != nullptr)
  1444. delete[] pData->options.binaryDir;
  1445. pData->options.binaryDir = carla_strdup(valueStr);
  1446. break;
  1447. case ENGINE_OPTION_PATH_RESOURCES:
  1448. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1449. if (pData->options.resourceDir != nullptr)
  1450. delete[] pData->options.resourceDir;
  1451. pData->options.resourceDir = carla_strdup(valueStr);
  1452. break;
  1453. }
  1454. }
  1455. // -----------------------------------------------------------------------
  1456. // OSC Stuff
  1457. #ifdef BUILD_BRIDGE
  1458. bool CarlaEngine::isOscBridgeRegistered() const noexcept
  1459. {
  1460. return (pData->oscData != nullptr);
  1461. }
  1462. #else
  1463. bool CarlaEngine::isOscControlRegistered() const noexcept
  1464. {
  1465. return pData->osc.isControlRegistered();
  1466. }
  1467. #endif
  1468. void CarlaEngine::idleOsc() const noexcept
  1469. {
  1470. try {
  1471. pData->osc.idle();
  1472. } catch(...) {}
  1473. }
  1474. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1475. {
  1476. return pData->osc.getServerPathTCP();
  1477. }
  1478. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1479. {
  1480. return pData->osc.getServerPathUDP();
  1481. }
  1482. #ifdef BUILD_BRIDGE
  1483. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept
  1484. {
  1485. pData->oscData = oscData;
  1486. }
  1487. #endif
  1488. // -----------------------------------------------------------------------
  1489. // Helper functions
  1490. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1491. {
  1492. return isInput ? pData->bufEvents.in : pData->bufEvents.out;
  1493. }
  1494. void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept
  1495. {
  1496. CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,);
  1497. carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin);
  1498. pData->plugins[id].plugin = plugin;
  1499. }
  1500. // -----------------------------------------------------------------------
  1501. // Internal stuff
  1502. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1503. {
  1504. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1505. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1506. {
  1507. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1508. if (plugin != nullptr && plugin->isEnabled())
  1509. plugin->bufferSizeChanged(newBufferSize);
  1510. }
  1511. callback(ENGINE_CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1512. }
  1513. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1514. {
  1515. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1516. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1517. {
  1518. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1519. if (plugin != nullptr && plugin->isEnabled())
  1520. plugin->sampleRateChanged(newSampleRate);
  1521. }
  1522. callback(ENGINE_CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, static_cast<float>(newSampleRate), nullptr);
  1523. }
  1524. void CarlaEngine::offlineModeChanged(const bool isOfflineNow)
  1525. {
  1526. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOfflineNow));
  1527. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1528. {
  1529. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1530. if (plugin != nullptr && plugin->isEnabled())
  1531. plugin->offlineModeChanged(isOfflineNow);
  1532. }
  1533. }
  1534. void CarlaEngine::runPendingRtEvents() noexcept
  1535. {
  1536. pData->doNextPluginAction(true);
  1537. if (pData->time.playing)
  1538. pData->time.frame += pData->bufferSize;
  1539. if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL)
  1540. {
  1541. pData->timeInfo.playing = pData->time.playing;
  1542. pData->timeInfo.frame = pData->time.frame;
  1543. }
  1544. }
  1545. void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1546. {
  1547. EnginePluginData& pluginData(pData->plugins[pluginId]);
  1548. pluginData.insPeak[0] = inPeaks[0];
  1549. pluginData.insPeak[1] = inPeaks[1];
  1550. pluginData.outsPeak[0] = outPeaks[0];
  1551. pluginData.outsPeak[1] = outPeaks[1];
  1552. }
  1553. // -----------------------------------------------------------------------
  1554. // Bridge/Controller OSC stuff
  1555. #ifdef BUILD_BRIDGE
  1556. void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const noexcept
  1557. {
  1558. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1559. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1560. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1561. carla_debug("CarlaEngine::oscSend_bridge_plugin_info1(%i:%s, %X, %l)", category, PluginCategory2Str(category), hints, uniqueId);
  1562. char targetPath[std::strlen(pData->oscData->path)+21];
  1563. std::strcpy(targetPath, pData->oscData->path);
  1564. std::strcat(targetPath, "/bridge_plugin_info1");
  1565. try_lo_send(pData->oscData->target, targetPath, "iih", static_cast<int32_t>(category), static_cast<int32_t>(hints), static_cast<int64_t>(uniqueId));
  1566. }
  1567. void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  1568. {
  1569. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1570. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1571. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1572. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  1573. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  1574. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  1575. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  1576. carla_debug("CarlaEngine::oscSend_bridge_plugin_info2(\"%s\", \"%s\", \"%s\", \"%s\")", realName, label, maker, copyright);
  1577. char targetPath[std::strlen(pData->oscData->path)+21];
  1578. std::strcpy(targetPath, pData->oscData->path);
  1579. std::strcat(targetPath, "/bridge_plugin_info2");
  1580. try_lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright);
  1581. }
  1582. void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept
  1583. {
  1584. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1585. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1586. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1587. carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i)", ins, outs);
  1588. char targetPath[std::strlen(pData->oscData->path)+20];
  1589. std::strcpy(targetPath, pData->oscData->path);
  1590. std::strcat(targetPath, "/bridge_audio_count");
  1591. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1592. }
  1593. void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept
  1594. {
  1595. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1596. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1597. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1598. carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i)", ins, outs);
  1599. char targetPath[std::strlen(pData->oscData->path)+19];
  1600. std::strcpy(targetPath, pData->oscData->path);
  1601. std::strcat(targetPath, "/bridge_midi_count");
  1602. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1603. }
  1604. void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept
  1605. {
  1606. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1607. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1608. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1609. carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i)", ins, outs);
  1610. char targetPath[std::strlen(pData->oscData->path)+24];
  1611. std::strcpy(targetPath, pData->oscData->path);
  1612. std::strcat(targetPath, "/bridge_parameter_count");
  1613. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1614. }
  1615. void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const noexcept
  1616. {
  1617. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1618. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1619. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1620. carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
  1621. char targetPath[std::strlen(pData->oscData->path)+22];
  1622. std::strcpy(targetPath, pData->oscData->path);
  1623. std::strcat(targetPath, "/bridge_program_count");
  1624. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1625. }
  1626. void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const noexcept
  1627. {
  1628. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1629. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1630. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1631. carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
  1632. char targetPath[std::strlen(pData->oscData->path)+27];
  1633. std::strcpy(targetPath, pData->oscData->path);
  1634. std::strcat(targetPath, "/bridge_midi_program_count");
  1635. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1636. }
  1637. 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
  1638. {
  1639. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1640. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1641. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1642. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  1643. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  1644. carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", index, rindex, type, ParameterType2Str(type), hints, name, unit);
  1645. char targetPath[std::strlen(pData->oscData->path)+23];
  1646. std::strcpy(targetPath, pData->oscData->path);
  1647. std::strcat(targetPath, "/bridge_parameter_data");
  1648. 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);
  1649. }
  1650. void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept
  1651. {
  1652. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1653. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1654. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1655. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, def, min, max);
  1656. char targetPath[std::strlen(pData->oscData->path)+26];
  1657. std::strcpy(targetPath, pData->oscData->path);
  1658. std::strcat(targetPath, "/bridge_parameter_ranges1");
  1659. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), def, min, max);
  1660. }
  1661. void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  1662. {
  1663. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1664. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1665. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1666. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, step, stepSmall, stepLarge);
  1667. char targetPath[std::strlen(pData->oscData->path)+26];
  1668. std::strcpy(targetPath, pData->oscData->path);
  1669. std::strcat(targetPath, "/bridge_parameter_ranges2");
  1670. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), step, stepSmall, stepLarge);
  1671. }
  1672. void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept
  1673. {
  1674. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1675. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1676. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1677. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_cc(%i, %i)", index, cc);
  1678. char targetPath[std::strlen(pData->oscData->path)+26];
  1679. std::strcpy(targetPath, pData->oscData->path);
  1680. std::strcat(targetPath, "/bridge_parameter_midi_cc");
  1681. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(cc));
  1682. }
  1683. void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept
  1684. {
  1685. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1686. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1687. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1688. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_channel(%i, %i)", index, channel);
  1689. char targetPath[std::strlen(pData->oscData->path)+31];
  1690. std::strcpy(targetPath, pData->oscData->path);
  1691. std::strcat(targetPath, "/bridge_parameter_midi_channel");
  1692. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(channel));
  1693. }
  1694. void CarlaEngine::oscSend_bridge_parameter_value(const int32_t index, const float value) const noexcept
  1695. {
  1696. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1697. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1698. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1699. CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
  1700. carla_debug("CarlaEngine::oscSend_bridge_parameter_value(%i, %f)", index, value);
  1701. char targetPath[std::strlen(pData->oscData->path)+24];
  1702. std::strcpy(targetPath, pData->oscData->path);
  1703. std::strcat(targetPath, "/bridge_parameter_value");
  1704. try_lo_send(pData->oscData->target, targetPath, "if", index, value);
  1705. }
  1706. void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept
  1707. {
  1708. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1709. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1710. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1711. carla_debug("CarlaEngine::oscSend_bridge_default_value(%i, %f)", index, value);
  1712. char targetPath[std::strlen(pData->oscData->path)+22];
  1713. std::strcpy(targetPath, pData->oscData->path);
  1714. std::strcat(targetPath, "/bridge_default_value");
  1715. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  1716. }
  1717. void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const noexcept
  1718. {
  1719. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1720. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1721. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1722. carla_debug("CarlaEngine::oscSend_bridge_current_program(%i)", index);
  1723. char targetPath[std::strlen(pData->oscData->path)+20];
  1724. std::strcpy(targetPath, pData->oscData->path);
  1725. std::strcat(targetPath, "/bridge_current_program");
  1726. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1727. }
  1728. void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const noexcept
  1729. {
  1730. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1731. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1732. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1733. carla_debug("CarlaEngine::oscSend_bridge_current_midi_program(%i)", index);
  1734. char targetPath[std::strlen(pData->oscData->path)+25];
  1735. std::strcpy(targetPath, pData->oscData->path);
  1736. std::strcat(targetPath, "/bridge_current_midi_program");
  1737. try_lo_send(pData->oscData->target, targetPath, "i", index);
  1738. }
  1739. void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept
  1740. {
  1741. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1742. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1743. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1744. carla_debug("CarlaEngine::oscSend_bridge_program_name(%i, \"%s\")", index, name);
  1745. char targetPath[std::strlen(pData->oscData->path)+21];
  1746. std::strcpy(targetPath, pData->oscData->path);
  1747. std::strcat(targetPath, "/bridge_program_name");
  1748. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(index), name);
  1749. }
  1750. 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
  1751. {
  1752. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1753. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1754. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1755. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  1756. carla_debug("CarlaEngine::oscSend_bridge_midi_program_data(%i, %i, %i, \"%s\")", index, bank, program, name);
  1757. char targetPath[std::strlen(pData->oscData->path)+26];
  1758. std::strcpy(targetPath, pData->oscData->path);
  1759. std::strcat(targetPath, "/bridge_midi_program_data");
  1760. try_lo_send(pData->oscData->target, targetPath, "iiis", static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  1761. }
  1762. void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const noexcept
  1763. {
  1764. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1765. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1766. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1767. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  1768. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  1769. carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
  1770. char targetPath[std::strlen(pData->oscData->path)+18];
  1771. std::strcpy(targetPath, pData->oscData->path);
  1772. std::strcat(targetPath, "/bridge_configure");
  1773. try_lo_send(pData->oscData->target, targetPath, "ss", key, value);
  1774. }
  1775. void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept
  1776. {
  1777. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1778. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1779. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1780. carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1781. char targetPath[std::strlen(pData->oscData->path)+24];
  1782. std::strcpy(targetPath, pData->oscData->path);
  1783. std::strcat(targetPath, "/bridge_set_custom_data");
  1784. try_lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
  1785. }
  1786. void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept
  1787. {
  1788. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1789. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1790. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1791. CARLA_SAFE_ASSERT_RETURN(chunkFile != nullptr && chunkFile[0] != '\0',);
  1792. carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
  1793. char targetPath[std::strlen(pData->oscData->path)+23];
  1794. std::strcpy(targetPath, pData->oscData->path);
  1795. std::strcat(targetPath, "/bridge_set_chunk_data");
  1796. try_lo_send(pData->oscData->target, targetPath, "s", chunkFile);
  1797. }
  1798. // TODO?
  1799. //void oscSend_bridge_set_peaks() const;
  1800. #else
  1801. void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept
  1802. {
  1803. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1804. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1805. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1806. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1807. CARLA_SAFE_ASSERT_RETURN(pluginName != nullptr && pluginName[0] != '\0',);
  1808. carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1809. char targetPath[std::strlen(pData->oscData->path)+18];
  1810. std::strcpy(targetPath, pData->oscData->path);
  1811. std::strcat(targetPath, "/add_plugin_start");
  1812. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(pluginId), pluginName);
  1813. }
  1814. void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const noexcept
  1815. {
  1816. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1817. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1818. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1819. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1820. carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
  1821. char targetPath[std::strlen(pData->oscData->path)+16];
  1822. std::strcpy(targetPath, pData->oscData->path);
  1823. std::strcat(targetPath, "/add_plugin_end");
  1824. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  1825. }
  1826. void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const noexcept
  1827. {
  1828. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1829. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1830. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1831. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1832. carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
  1833. char targetPath[std::strlen(pData->oscData->path)+15];
  1834. std::strcpy(targetPath, pData->oscData->path);
  1835. std::strcat(targetPath, "/remove_plugin");
  1836. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  1837. }
  1838. void CarlaEngine::oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const noexcept
  1839. {
  1840. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1841. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1842. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1843. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1844. CARLA_SAFE_ASSERT_RETURN(type != PLUGIN_NONE,);
  1845. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, %i:%s, %i:%s, %X, %l)", pluginId, type, PluginType2Str(type), category, PluginCategory2Str(category), hints, uniqueId);
  1846. char targetPath[std::strlen(pData->oscData->path)+18];
  1847. std::strcpy(targetPath, pData->oscData->path);
  1848. std::strcat(targetPath, "/set_plugin_info1");
  1849. 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));
  1850. }
  1851. 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
  1852. {
  1853. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1854. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1855. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1856. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1857. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  1858. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  1859. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  1860. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  1861. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, \"%s\", \"%s\", \"%s\", \"%s\")", pluginId, realName, label, maker, copyright);
  1862. char targetPath[std::strlen(pData->oscData->path)+18];
  1863. std::strcpy(targetPath, pData->oscData->path);
  1864. std::strcat(targetPath, "/set_plugin_info2");
  1865. try_lo_send(pData->oscData->target, targetPath, "issss", static_cast<int32_t>(pluginId), realName, label, maker, copyright);
  1866. }
  1867. void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  1868. {
  1869. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1870. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1871. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1872. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1873. carla_debug("CarlaEngine::oscSend_control_set_audio_count(%i, %i, %i)", pluginId, ins, outs);
  1874. char targetPath[std::strlen(pData->oscData->path)+18];
  1875. std::strcpy(targetPath, pData->oscData->path);
  1876. std::strcat(targetPath, "/set_audio_count");
  1877. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1878. }
  1879. void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  1880. {
  1881. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1882. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1883. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1884. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1885. carla_debug("CarlaEngine::oscSend_control_set_midi_count(%i, %i, %i)", pluginId, ins, outs);
  1886. char targetPath[std::strlen(pData->oscData->path)+18];
  1887. std::strcpy(targetPath, pData->oscData->path);
  1888. std::strcat(targetPath, "/set_midi_count");
  1889. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1890. }
  1891. void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  1892. {
  1893. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1894. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1895. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1896. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1897. carla_debug("CarlaEngine::oscSend_control_set_parameter_count(%i, %i, %i)", pluginId, ins, outs);
  1898. char targetPath[std::strlen(pData->oscData->path)+18];
  1899. std::strcpy(targetPath, pData->oscData->path);
  1900. std::strcat(targetPath, "/set_parameter_count");
  1901. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1902. }
  1903. void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept
  1904. {
  1905. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1906. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1907. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1908. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1909. carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
  1910. char targetPath[std::strlen(pData->oscData->path)+19];
  1911. std::strcpy(targetPath, pData->oscData->path);
  1912. std::strcat(targetPath, "/set_program_count");
  1913. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  1914. }
  1915. void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept
  1916. {
  1917. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1918. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1919. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1920. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1921. carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
  1922. char targetPath[std::strlen(pData->oscData->path)+24];
  1923. std::strcpy(targetPath, pData->oscData->path);
  1924. std::strcat(targetPath, "/set_midi_program_count");
  1925. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  1926. }
  1927. 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
  1928. {
  1929. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1930. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1931. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1932. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1933. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  1934. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  1935. carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", pluginId, index, type, ParameterType2Str(type), hints, name, unit);
  1936. char targetPath[std::strlen(pData->oscData->path)+20];
  1937. std::strcpy(targetPath, pData->oscData->path);
  1938. std::strcat(targetPath, "/set_parameter_data");
  1939. 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);
  1940. }
  1941. 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
  1942. {
  1943. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1944. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1945. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1946. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1947. CARLA_SAFE_ASSERT_RETURN(def <= min && def >= max,);
  1948. CARLA_SAFE_ASSERT_RETURN(min < max,);
  1949. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges1(%i, %i, %f, %f, %f)", pluginId, index, def, min, max, def);
  1950. char targetPath[std::strlen(pData->oscData->path)+23];
  1951. std::strcpy(targetPath, pData->oscData->path);
  1952. std::strcat(targetPath, "/set_parameter_ranges1");
  1953. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), def, min, max);
  1954. }
  1955. 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
  1956. {
  1957. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1958. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1959. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1960. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1961. CARLA_SAFE_ASSERT_RETURN(step <= stepSmall && step >= stepLarge,);
  1962. CARLA_SAFE_ASSERT_RETURN(stepSmall <= stepLarge,);
  1963. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges2(%i, %i, %f, %f, %f)", pluginId, index, step, stepSmall, stepLarge);
  1964. char targetPath[std::strlen(pData->oscData->path)+23];
  1965. std::strcpy(targetPath, pData->oscData->path);
  1966. std::strcat(targetPath, "/set_parameter_ranges");
  1967. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), step, stepSmall, stepLarge);
  1968. }
  1969. void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept
  1970. {
  1971. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1972. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1973. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1974. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1975. CARLA_SAFE_ASSERT_RETURN(cc <= 0x5F,);
  1976. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1977. char targetPath[std::strlen(pData->oscData->path)+23];
  1978. std::strcpy(targetPath, pData->oscData->path);
  1979. std::strcat(targetPath, "/set_parameter_midi_cc");
  1980. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(cc));
  1981. }
  1982. void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept
  1983. {
  1984. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1985. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1986. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1987. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  1988. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  1989. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1990. char targetPath[std::strlen(pData->oscData->path)+28];
  1991. std::strcpy(targetPath, pData->oscData->path);
  1992. std::strcat(targetPath, "/set_parameter_midi_channel");
  1993. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(channel));
  1994. }
  1995. void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept
  1996. {
  1997. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1998. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1999. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2000. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2001. CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
  2002. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i:%s, %f)", pluginId, index, (index < 0) ? InternalParameterIndex2Str(static_cast<InternalParameterIndex>(index)) : "(none)", value);
  2003. char targetPath[std::strlen(pData->oscData->path)+21];
  2004. std::strcpy(targetPath, pData->oscData->path);
  2005. std::strcat(targetPath, "/set_parameter_value");
  2006. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), index, value);
  2007. }
  2008. void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept
  2009. {
  2010. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2011. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2012. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2013. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2014. carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  2015. char targetPath[std::strlen(pData->oscData->path)+19];
  2016. std::strcpy(targetPath, pData->oscData->path);
  2017. std::strcat(targetPath, "/set_default_value");
  2018. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), value);
  2019. }
  2020. void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept
  2021. {
  2022. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2023. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2024. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2025. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2026. carla_debug("CarlaEngine::oscSend_control_set_current_program(%i, %i)", pluginId, index);
  2027. char targetPath[std::strlen(pData->oscData->path)+21];
  2028. std::strcpy(targetPath, pData->oscData->path);
  2029. std::strcat(targetPath, "/set_current_program");
  2030. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2031. }
  2032. void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept
  2033. {
  2034. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2035. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2036. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2037. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2038. carla_debug("CarlaEngine::oscSend_control_set_current_midi_program(%i, %i)", pluginId, index);
  2039. char targetPath[std::strlen(pData->oscData->path)+26];
  2040. std::strcpy(targetPath, pData->oscData->path);
  2041. std::strcat(targetPath, "/set_current_midi_program");
  2042. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2043. }
  2044. void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept
  2045. {
  2046. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2047. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2048. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2049. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2050. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2051. carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  2052. char targetPath[std::strlen(pData->oscData->path)+18];
  2053. std::strcpy(targetPath, pData->oscData->path);
  2054. std::strcat(targetPath, "/set_program_name");
  2055. try_lo_send(pData->oscData->target, targetPath, "iis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), name);
  2056. }
  2057. 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
  2058. {
  2059. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2060. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2061. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2062. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2063. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2064. carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  2065. char targetPath[std::strlen(pData->oscData->path)+23];
  2066. std::strcpy(targetPath, pData->oscData->path);
  2067. std::strcat(targetPath, "/set_midi_program_data");
  2068. 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);
  2069. }
  2070. void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept
  2071. {
  2072. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2073. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2074. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2075. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2076. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2077. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2078. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  2079. carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  2080. char targetPath[std::strlen(pData->oscData->path)+9];
  2081. std::strcpy(targetPath, pData->oscData->path);
  2082. std::strcat(targetPath, "/note_on");
  2083. 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));
  2084. }
  2085. void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept
  2086. {
  2087. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2088. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2089. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2090. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2091. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2092. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2093. carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
  2094. char targetPath[std::strlen(pData->oscData->path)+10];
  2095. std::strcpy(targetPath, pData->oscData->path);
  2096. std::strcat(targetPath, "/note_off");
  2097. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note));
  2098. }
  2099. void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) const noexcept
  2100. {
  2101. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2102. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2103. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2104. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2105. // TODO - try and see if we can get peaks[4] ref
  2106. const EnginePluginData& epData(pData->plugins[pluginId]);
  2107. char targetPath[std::strlen(pData->oscData->path)+11];
  2108. std::strcpy(targetPath, pData->oscData->path);
  2109. std::strcat(targetPath, "/set_peaks");
  2110. 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]);
  2111. }
  2112. void CarlaEngine::oscSend_control_exit() const noexcept
  2113. {
  2114. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2115. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2116. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2117. carla_debug("CarlaEngine::oscSend_control_exit()");
  2118. char targetPath[std::strlen(pData->oscData->path)+6];
  2119. std::strcpy(targetPath, pData->oscData->path);
  2120. std::strcat(targetPath, "/exit");
  2121. try_lo_send(pData->oscData->target, targetPath, "");
  2122. }
  2123. #endif
  2124. // -----------------------------------------------------------------------
  2125. CARLA_BACKEND_END_NAMESPACE