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.

2879 lines
109KB

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