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.

2650 lines
100KB

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