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.

2536 lines
81KB

  1. /*
  2. * Carla Engine
  3. * Copyright (C) 2012-2013 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 GPL.txt file
  16. */
  17. #include "CarlaEngineInternal.hpp"
  18. #include "CarlaBackendUtils.hpp"
  19. #include "CarlaStateUtils.hpp"
  20. #include "CarlaMIDI.h"
  21. #include <cmath>
  22. #include <QtCore/QDir>
  23. #include <QtCore/QFile>
  24. #include <QtCore/QFileInfo>
  25. #include <QtCore/QTextStream>
  26. // -------------------------------------------------------------------------------------------------------------------
  27. // Register native engine plugin
  28. #ifndef BUILD_BRIDGE
  29. # include "CarlaNative.h"
  30. void carla_register_native_plugin_carla()
  31. {
  32. CARLA_BACKEND_USE_NAMESPACE
  33. CarlaEngine::registerNativePlugin();
  34. }
  35. #endif
  36. // -------------------------------------------------------------------------------------------------------------------
  37. CARLA_BACKEND_START_NAMESPACE
  38. // -------------------------------------------------------------------------------------------------------------------
  39. // Fallback data
  40. static const EngineEvent kFallbackEngineEvent;
  41. #ifndef BUILD_BRIDGE
  42. // -------------------------------------------------------------------------------------------------------------------
  43. // Bridge Helper, defined in CarlaPlugin.cpp
  44. extern BinaryType CarlaPluginGetBridgeBinaryType(CarlaPlugin* const plugin);
  45. // -------------------------------------------------------------------------------------------------------------------
  46. // Engine Helpers
  47. void registerEnginePlugin(CarlaEngine* const engine, const unsigned int id, CarlaPlugin* const plugin)
  48. {
  49. CarlaEngineProtectedData::registerEnginePlugin(engine, id, plugin);
  50. }
  51. #endif
  52. // -------------------------------------------------------------------------------------------------------------------
  53. // Carla Engine port (Abstract)
  54. CarlaEnginePort::CarlaEnginePort(const bool isInput, const ProcessMode processMode)
  55. : kIsInput(isInput),
  56. kProcessMode(processMode)
  57. {
  58. carla_debug("CarlaEnginePort::CarlaEnginePort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  59. }
  60. CarlaEnginePort::~CarlaEnginePort()
  61. {
  62. carla_debug("CarlaEnginePort::~CarlaEnginePort()");
  63. }
  64. // -------------------------------------------------------------------------------------------------------------------
  65. // Carla Engine Audio port
  66. CarlaEngineAudioPort::CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode)
  67. : CarlaEnginePort(isInput, processMode),
  68. fBuffer(nullptr)
  69. {
  70. carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  71. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  72. fBuffer = new float[PATCHBAY_BUFFER_SIZE];
  73. }
  74. CarlaEngineAudioPort::~CarlaEngineAudioPort()
  75. {
  76. carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()");
  77. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  78. {
  79. CARLA_ASSERT(fBuffer != nullptr);
  80. if (fBuffer != nullptr)
  81. {
  82. delete[] fBuffer;
  83. fBuffer = nullptr;
  84. }
  85. }
  86. }
  87. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const)
  88. {
  89. if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  90. carla_zeroFloat(fBuffer, PATCHBAY_BUFFER_SIZE);
  91. }
  92. // -------------------------------------------------------------------------------------------------------------------
  93. // Carla Engine CV port
  94. CarlaEngineCVPort::CarlaEngineCVPort(const bool isInput, const ProcessMode processMode, const uint32_t bufferSize)
  95. : CarlaEnginePort(isInput, processMode),
  96. fBuffer(new float[bufferSize]),
  97. fBufferSize(bufferSize)
  98. {
  99. carla_debug("CarlaEngineCVPort::CarlaEngineCVPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  100. }
  101. CarlaEngineCVPort::~CarlaEngineCVPort()
  102. {
  103. carla_debug("CarlaEngineCVPort::~CarlaEngineCVPort()");
  104. CARLA_ASSERT(fBuffer != nullptr);
  105. if (fBuffer != nullptr)
  106. {
  107. delete[] fBuffer;
  108. fBuffer = nullptr;
  109. }
  110. }
  111. void CarlaEngineCVPort::initBuffer(CarlaEngine* const engine)
  112. {
  113. CARLA_ASSERT(engine != nullptr && engine->getBufferSize() == fBufferSize);
  114. if (! kIsInput)
  115. carla_zeroFloat(fBuffer, fBufferSize);
  116. }
  117. void CarlaEngineCVPort::writeBuffer(CarlaEngine* const engine)
  118. {
  119. CARLA_ASSERT(! kIsInput);
  120. CARLA_ASSERT(engine != nullptr);
  121. if (kIsInput)
  122. return;
  123. if (engine == nullptr)
  124. return;
  125. CARLA_ASSERT(engine->getBufferSize() == fBufferSize);
  126. }
  127. void CarlaEngineCVPort::setBufferSize(const uint32_t bufferSize)
  128. {
  129. CARLA_ASSERT(fBuffer != nullptr);
  130. if (fBufferSize == bufferSize)
  131. return;
  132. if (fBuffer != nullptr)
  133. delete[] fBuffer;
  134. fBuffer = new float[bufferSize];
  135. fBufferSize = bufferSize;
  136. }
  137. // -------------------------------------------------------------------------------------------------------------------
  138. // Carla Engine Event port
  139. CarlaEngineEventPort::CarlaEngineEventPort(const bool isInput, const ProcessMode processMode)
  140. : CarlaEnginePort(isInput, processMode),
  141. pBuffer(nullptr)
  142. {
  143. carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  144. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  145. pBuffer = new EngineEvent[INTERNAL_EVENT_COUNT];
  146. }
  147. CarlaEngineEventPort::~CarlaEngineEventPort()
  148. {
  149. carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()");
  150. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  151. {
  152. CARLA_ASSERT(pBuffer != nullptr);
  153. if (pBuffer != nullptr)
  154. {
  155. delete[] pBuffer;
  156. pBuffer = nullptr;
  157. }
  158. }
  159. }
  160. void CarlaEngineEventPort::initBuffer(CarlaEngine* const engine)
  161. {
  162. CARLA_ASSERT(engine != nullptr);
  163. if (engine == nullptr)
  164. return;
  165. if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_BRIDGE)
  166. pBuffer = engine->getInternalEventBuffer(kIsInput);
  167. else if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  168. carla_zeroStruct<EngineEvent>(pBuffer, INTERNAL_EVENT_COUNT);
  169. }
  170. uint32_t CarlaEngineEventPort::getEventCount() const
  171. {
  172. CARLA_ASSERT(kIsInput);
  173. CARLA_ASSERT(pBuffer != nullptr);
  174. CARLA_ASSERT(kProcessMode != PROCESS_MODE_SINGLE_CLIENT && kProcessMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  175. if (! kIsInput)
  176. return 0;
  177. if (pBuffer == nullptr)
  178. return 0;
  179. if (kProcessMode == PROCESS_MODE_SINGLE_CLIENT || kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  180. return 0;
  181. for (uint32_t i=0; i < INTERNAL_EVENT_COUNT; ++i)
  182. {
  183. if (pBuffer[i].type == kEngineEventTypeNull)
  184. return i;
  185. }
  186. // buffer full
  187. return INTERNAL_EVENT_COUNT;
  188. }
  189. const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index)
  190. {
  191. CARLA_ASSERT(kIsInput);
  192. CARLA_ASSERT(pBuffer != nullptr);
  193. CARLA_ASSERT(kProcessMode != PROCESS_MODE_SINGLE_CLIENT && kProcessMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  194. CARLA_ASSERT(index < INTERNAL_EVENT_COUNT);
  195. if (! kIsInput)
  196. return kFallbackEngineEvent;
  197. if (pBuffer == nullptr)
  198. return kFallbackEngineEvent;
  199. if (kProcessMode == PROCESS_MODE_SINGLE_CLIENT || kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  200. return kFallbackEngineEvent;
  201. if (index >= INTERNAL_EVENT_COUNT)
  202. return kFallbackEngineEvent;
  203. return pBuffer[index];
  204. }
  205. void CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value)
  206. {
  207. CARLA_ASSERT(! kIsInput);
  208. CARLA_ASSERT(pBuffer != nullptr);
  209. CARLA_ASSERT(kProcessMode != PROCESS_MODE_SINGLE_CLIENT && kProcessMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  210. CARLA_ASSERT(type != kEngineControlEventTypeNull);
  211. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  212. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  213. if (kIsInput)
  214. return;
  215. if (pBuffer == nullptr)
  216. return;
  217. if (kProcessMode == PROCESS_MODE_SINGLE_CLIENT || kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  218. return;
  219. if (type == kEngineControlEventTypeNull)
  220. return;
  221. if (channel >= MAX_MIDI_CHANNELS)
  222. return;
  223. if (type == kEngineControlEventTypeParameter)
  224. {
  225. CARLA_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param));
  226. }
  227. for (uint32_t i=0; i < INTERNAL_EVENT_COUNT; ++i)
  228. {
  229. if (pBuffer[i].type != kEngineEventTypeNull)
  230. continue;
  231. pBuffer[i].type = kEngineEventTypeControl;
  232. pBuffer[i].time = time;
  233. pBuffer[i].channel = channel;
  234. pBuffer[i].ctrl.type = type;
  235. pBuffer[i].ctrl.param = param;
  236. pBuffer[i].ctrl.value = carla_fixValue<float>(0.0f, 1.0f, value);
  237. return;
  238. }
  239. carla_stderr2("CarlaEngineEventPort::writeControlEvent() - buffer full");
  240. }
  241. void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t* const data, const uint8_t size)
  242. {
  243. CARLA_ASSERT(! kIsInput);
  244. CARLA_ASSERT(pBuffer != nullptr);
  245. CARLA_ASSERT(kProcessMode != PROCESS_MODE_SINGLE_CLIENT && kProcessMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  246. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  247. CARLA_ASSERT(data != nullptr);
  248. CARLA_ASSERT(size != 0 && size <= 4);
  249. if (kIsInput)
  250. return;
  251. if (pBuffer == nullptr)
  252. return;
  253. if (kProcessMode == PROCESS_MODE_SINGLE_CLIENT || kProcessMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  254. return;
  255. if (channel >= MAX_MIDI_CHANNELS)
  256. return;
  257. if (data == nullptr)
  258. return;
  259. if (size == 0 || size > 4)
  260. return;
  261. for (uint32_t i=0; i < INTERNAL_EVENT_COUNT; ++i)
  262. {
  263. if (pBuffer[i].type != kEngineEventTypeNull)
  264. continue;
  265. pBuffer[i].type = kEngineEventTypeMidi;
  266. pBuffer[i].time = time;
  267. pBuffer[i].channel = channel;
  268. pBuffer[i].midi.port = port;
  269. pBuffer[i].midi.size = size;
  270. carla_copy<uint8_t>(pBuffer[i].midi.data, data, size);
  271. // strip MIDI channel from 1st byte
  272. pBuffer[i].midi.data[0] = MIDI_GET_STATUS_FROM_DATA(pBuffer[i].midi.data);
  273. return;
  274. }
  275. carla_stderr2("CarlaEngineEventPort::writeMidiEvent() - buffer full");
  276. }
  277. // -------------------------------------------------------------------------------------------------------------------
  278. // Carla Engine client (Abstract)
  279. CarlaEngineClient::CarlaEngineClient(const CarlaEngine& engine)
  280. : kEngine(engine),
  281. fActive(false),
  282. fLatency(0)
  283. {
  284. carla_debug("CarlaEngineClient::CarlaEngineClient(name:\"%s\")", engine.getName());
  285. }
  286. CarlaEngineClient::~CarlaEngineClient()
  287. {
  288. CARLA_ASSERT(! fActive);
  289. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  290. }
  291. void CarlaEngineClient::activate()
  292. {
  293. CARLA_ASSERT(! fActive);
  294. carla_debug("CarlaEngineClient::activate()");
  295. fActive = true;
  296. }
  297. void CarlaEngineClient::deactivate()
  298. {
  299. CARLA_ASSERT(fActive);
  300. carla_debug("CarlaEngineClient::deactivate()");
  301. fActive = false;
  302. }
  303. bool CarlaEngineClient::isActive() const
  304. {
  305. carla_debug("CarlaEngineClient::isActive()");
  306. return fActive;
  307. }
  308. bool CarlaEngineClient::isOk() const
  309. {
  310. carla_debug("CarlaEngineClient::isOk()");
  311. return true;
  312. }
  313. uint32_t CarlaEngineClient::getLatency() const
  314. {
  315. return fLatency;
  316. }
  317. void CarlaEngineClient::setLatency(const uint32_t samples)
  318. {
  319. fLatency = samples;
  320. }
  321. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  322. {
  323. carla_debug("CarlaEngineClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput));
  324. switch (portType)
  325. {
  326. case kEnginePortTypeNull:
  327. break;
  328. case kEnginePortTypeAudio:
  329. return new CarlaEngineAudioPort(isInput, kEngine.getProccessMode());
  330. case kEnginePortTypeCV:
  331. return new CarlaEngineCVPort(isInput, kEngine.getProccessMode(), kEngine.getBufferSize());
  332. case kEnginePortTypeEvent:
  333. return new CarlaEngineEventPort(isInput, kEngine.getProccessMode());
  334. }
  335. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  336. return nullptr;
  337. }
  338. // -------------------------------------------------------------------------------------------------------------------
  339. // Carla Engine
  340. CarlaEngine::CarlaEngine()
  341. : fBufferSize(0),
  342. fSampleRate(0.0),
  343. kData(new CarlaEngineProtectedData(this))
  344. {
  345. carla_debug("CarlaEngine::CarlaEngine()");
  346. }
  347. CarlaEngine::~CarlaEngine()
  348. {
  349. carla_debug("CarlaEngine::~CarlaEngine()");
  350. delete kData;
  351. }
  352. // -----------------------------------------------------------------------
  353. // Helpers
  354. // returned value must be deleted
  355. const char* findDSSIGUI(const char* const filename, const char* const label)
  356. {
  357. QString guiFilename;
  358. QString pluginDir(filename);
  359. pluginDir.resize(pluginDir.lastIndexOf("."));
  360. QString shortName(QFileInfo(pluginDir).baseName());
  361. QString checkLabel(label);
  362. QString checkSName(shortName);
  363. if (! checkLabel.endsWith("_")) checkLabel += "_";
  364. if (! checkSName.endsWith("_")) checkSName += "_";
  365. QStringList guiFiles(QDir(pluginDir).entryList());
  366. foreach (const QString& gui, guiFiles)
  367. {
  368. if (gui.startsWith(checkLabel) || gui.startsWith(checkSName))
  369. {
  370. QFileInfo finalname(pluginDir + QDir::separator() + gui);
  371. guiFilename = finalname.absoluteFilePath();
  372. break;
  373. }
  374. }
  375. if (guiFilename.isEmpty())
  376. return nullptr;
  377. return carla_strdup(guiFilename.toUtf8().constData());
  378. }
  379. // -----------------------------------------------------------------------
  380. // Static values and calls
  381. unsigned int CarlaEngine::getDriverCount()
  382. {
  383. carla_debug("CarlaEngine::getDriverCount()");
  384. unsigned int count = 1; // JACK
  385. #ifdef WANT_RTAUDIO
  386. count += getRtAudioApiCount();
  387. #endif
  388. return count;
  389. }
  390. const char* CarlaEngine::getDriverName(const unsigned int index)
  391. {
  392. carla_debug("CarlaEngine::getDriverName(%i)", index);
  393. if (index == 0)
  394. return "JACK";
  395. #ifdef WANT_RTAUDIO
  396. const unsigned int rtIndex(index-1);
  397. if (rtIndex < getRtAudioApiCount())
  398. return getRtAudioApiName(rtIndex);
  399. #endif
  400. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
  401. return nullptr;
  402. }
  403. const char** CarlaEngine::getDriverDeviceNames(const unsigned int index)
  404. {
  405. carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index);
  406. if (index == 0)
  407. return nullptr;
  408. #ifdef WANT_RTAUDIO
  409. const unsigned int rtIndex(index-1);
  410. if (rtIndex < getRtAudioApiCount())
  411. return getRtAudioApiDeviceNames(rtIndex);
  412. #endif
  413. carla_stderr("CarlaEngine::getDriverDeviceNames(%i) - invalid index", index);
  414. return nullptr;
  415. }
  416. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  417. {
  418. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  419. if (std::strcmp(driverName, "JACK") == 0)
  420. return newJack();
  421. #ifdef WANT_RTAUDIO
  422. # ifdef __LINUX_ALSA__
  423. if (std::strcmp(driverName, "ALSA") == 0)
  424. return newRtAudio(RTAUDIO_LINUX_ALSA);
  425. # endif
  426. # ifdef __LINUX_PULSE__
  427. if (std::strcmp(driverName, "PulseAudio") == 0)
  428. return newRtAudio(RTAUDIO_LINUX_PULSE);
  429. # endif
  430. # ifdef __LINUX_OSS__
  431. if (std::strcmp(driverName, "OSS") == 0)
  432. return newRtAudio(RTAUDIO_LINUX_OSS);
  433. # endif
  434. # ifdef __UNIX_JACK__
  435. if (std::strncmp(driverName, "JACK ", 5) == 0)
  436. return newRtAudio(RTAUDIO_UNIX_JACK);
  437. # endif
  438. # ifdef __MACOSX_CORE__
  439. if (std::strcmp(driverName, "CoreAudio") == 0)
  440. return newRtAudio(RTAUDIO_MACOSX_CORE);
  441. # endif
  442. # ifdef __WINDOWS_ASIO__
  443. if (std::strcmp(driverName, "ASIO") == 0)
  444. return newRtAudio(RTAUDIO_WINDOWS_ASIO);
  445. # endif
  446. # ifdef __WINDOWS_DS__
  447. if (std::strcmp(driverName, "DirectSound") == 0)
  448. return newRtAudio(RTAUDIO_WINDOWS_DS);
  449. # endif
  450. #endif
  451. carla_stderr("CarlaEngine::newDriverByName(\"%s\") - invalid driver name", driverName);
  452. return nullptr;
  453. }
  454. // -----------------------------------------------------------------------
  455. // Maximum values
  456. unsigned int CarlaEngine::maxClientNameSize() const
  457. {
  458. return STR_MAX/2;
  459. }
  460. unsigned int CarlaEngine::maxPortNameSize() const
  461. {
  462. return STR_MAX;
  463. }
  464. unsigned int CarlaEngine::currentPluginCount() const
  465. {
  466. return kData->curPluginCount;
  467. }
  468. unsigned int CarlaEngine::maxPluginNumber() const
  469. {
  470. return kData->maxPluginNumber;
  471. }
  472. // -----------------------------------------------------------------------
  473. // Virtual, per-engine type calls
  474. bool CarlaEngine::init(const char* const clientName)
  475. {
  476. CARLA_ASSERT(fName.isEmpty());
  477. CARLA_ASSERT(kData->oscData == nullptr);
  478. CARLA_ASSERT(kData->plugins == nullptr);
  479. CARLA_ASSERT(kData->bufEvents.in == nullptr);
  480. CARLA_ASSERT(kData->bufEvents.out == nullptr);
  481. carla_debug("CarlaEngine::init(\"%s\")", clientName);
  482. kData->aboutToClose = false;
  483. kData->curPluginCount = 0;
  484. kData->maxPluginNumber = 0;
  485. kData->nextPluginId = 0;
  486. switch (fOptions.processMode)
  487. {
  488. case PROCESS_MODE_SINGLE_CLIENT:
  489. case PROCESS_MODE_MULTIPLE_CLIENTS:
  490. kData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
  491. break;
  492. case PROCESS_MODE_CONTINUOUS_RACK:
  493. kData->maxPluginNumber = MAX_RACK_PLUGINS;
  494. kData->bufEvents.in = new EngineEvent[INTERNAL_EVENT_COUNT];
  495. kData->bufEvents.out = new EngineEvent[INTERNAL_EVENT_COUNT];
  496. break;
  497. case PROCESS_MODE_PATCHBAY:
  498. kData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
  499. break;
  500. case PROCESS_MODE_BRIDGE:
  501. kData->maxPluginNumber = 1;
  502. kData->bufEvents.in = new EngineEvent[INTERNAL_EVENT_COUNT];
  503. kData->bufEvents.out = new EngineEvent[INTERNAL_EVENT_COUNT];
  504. break;
  505. }
  506. if (kData->maxPluginNumber == 0)
  507. return false;
  508. kData->nextPluginId = kData->maxPluginNumber;
  509. fName = clientName;
  510. fName.toBasic();
  511. fTimeInfo.clear();
  512. kData->plugins = new EnginePluginData[kData->maxPluginNumber];
  513. kData->osc.init(clientName);
  514. #ifndef BUILD_BRIDGE
  515. kData->oscData = kData->osc.getControlData();
  516. #endif
  517. if (type() != kEngineTypePlugin)
  518. carla_setprocname(clientName);
  519. kData->nextAction.ready();
  520. kData->thread.startNow();
  521. return true;
  522. }
  523. bool CarlaEngine::close()
  524. {
  525. CARLA_ASSERT(fName.isNotEmpty());
  526. CARLA_ASSERT(kData->plugins != nullptr);
  527. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  528. CARLA_ASSERT(kData->nextPluginId == kData->maxPluginNumber);
  529. carla_debug("CarlaEngine::close()");
  530. kData->thread.stopNow();
  531. kData->nextAction.ready();
  532. #ifndef BUILD_BRIDGE
  533. osc_send_control_exit();
  534. #endif
  535. kData->osc.close();
  536. kData->oscData = nullptr;
  537. kData->aboutToClose = true;
  538. kData->curPluginCount = 0;
  539. kData->maxPluginNumber = 0;
  540. kData->nextPluginId = 0;
  541. if (kData->plugins != nullptr)
  542. {
  543. delete[] kData->plugins;
  544. kData->plugins = nullptr;
  545. }
  546. if (kData->bufEvents.in != nullptr)
  547. {
  548. delete[] kData->bufEvents.in;
  549. kData->bufEvents.in = nullptr;
  550. }
  551. if (kData->bufEvents.out != nullptr)
  552. {
  553. delete[] kData->bufEvents.out;
  554. kData->bufEvents.out = nullptr;
  555. }
  556. fName.clear();
  557. return true;
  558. }
  559. void CarlaEngine::idle()
  560. {
  561. CARLA_ASSERT(kData->plugins != nullptr); // this one too maybe
  562. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull); // TESTING, remove later
  563. CARLA_ASSERT(kData->nextPluginId == kData->maxPluginNumber); // TESTING, remove later
  564. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  565. {
  566. CarlaPlugin* const plugin(kData->plugins[i].plugin);
  567. if (plugin != nullptr && plugin->enabled())
  568. plugin->idleGui();
  569. }
  570. }
  571. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  572. {
  573. return new CarlaEngineClient(*this);
  574. }
  575. // -----------------------------------------------------------------------
  576. // Plugin management
  577. 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)
  578. {
  579. CARLA_ASSERT(btype != BINARY_NONE);
  580. CARLA_ASSERT(ptype != PLUGIN_NONE);
  581. CARLA_ASSERT(kData->plugins != nullptr);
  582. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  583. carla_debug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra);
  584. unsigned int id;
  585. if (kData->nextPluginId < kData->curPluginCount)
  586. {
  587. id = kData->nextPluginId;
  588. kData->nextPluginId = kData->maxPluginNumber;
  589. CARLA_ASSERT(kData->plugins[id].plugin != nullptr);
  590. }
  591. else
  592. {
  593. id = kData->curPluginCount;
  594. if (id == kData->maxPluginNumber)
  595. {
  596. setLastError("Maximum number of plugins reached");
  597. return false;
  598. }
  599. CARLA_ASSERT(kData->plugins[id].plugin == nullptr);
  600. }
  601. CarlaPlugin::Initializer init = {
  602. this,
  603. id,
  604. filename,
  605. name,
  606. label
  607. };
  608. CarlaPlugin* plugin = nullptr;
  609. #ifndef BUILD_BRIDGE
  610. const char* bridgeBinary;
  611. switch (btype)
  612. {
  613. case BINARY_POSIX32:
  614. bridgeBinary = fOptions.bridge_posix32.isNotEmpty() ? (const char*)fOptions.bridge_posix32 : nullptr;
  615. break;
  616. case BINARY_POSIX64:
  617. bridgeBinary = fOptions.bridge_posix64.isNotEmpty() ? (const char*)fOptions.bridge_posix64 : nullptr;
  618. break;
  619. case BINARY_WIN32:
  620. bridgeBinary = fOptions.bridge_win32.isNotEmpty() ? (const char*)fOptions.bridge_win32 : nullptr;
  621. break;
  622. case BINARY_WIN64:
  623. bridgeBinary = fOptions.bridge_win64.isNotEmpty() ? (const char*)fOptions.bridge_win64 : nullptr;
  624. break;
  625. default:
  626. bridgeBinary = nullptr;
  627. break;
  628. }
  629. # ifndef Q_OS_WIN
  630. if (btype == BINARY_NATIVE && fOptions.bridge_native.isNotEmpty())
  631. bridgeBinary = (const char*)fOptions.bridge_native;
  632. # endif
  633. if (bridgeBinary != nullptr && (btype != BINARY_NATIVE || fOptions.preferPluginBridges))
  634. {
  635. plugin = CarlaPlugin::newBridge(init, btype, ptype, bridgeBinary);
  636. }
  637. else
  638. #endif // BUILD_BRIDGE
  639. {
  640. switch (ptype)
  641. {
  642. case PLUGIN_NONE:
  643. break;
  644. case PLUGIN_INTERNAL:
  645. plugin = CarlaPlugin::newNative(init);
  646. break;
  647. case PLUGIN_LADSPA:
  648. plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra);
  649. break;
  650. case PLUGIN_DSSI:
  651. plugin = CarlaPlugin::newDSSI(init, (const char*)extra);
  652. break;
  653. case PLUGIN_LV2:
  654. plugin = CarlaPlugin::newLV2(init);
  655. break;
  656. case PLUGIN_VST:
  657. plugin = CarlaPlugin::newVST(init);
  658. break;
  659. case PLUGIN_VST3:
  660. plugin = CarlaPlugin::newVST3(init);
  661. break;
  662. case PLUGIN_GIG:
  663. plugin = CarlaPlugin::newGIG(init, (extra != nullptr));
  664. break;
  665. case PLUGIN_SF2:
  666. plugin = CarlaPlugin::newSF2(init, (extra != nullptr));
  667. break;
  668. case PLUGIN_SFZ:
  669. plugin = CarlaPlugin::newSFZ(init, (extra != nullptr));
  670. break;
  671. }
  672. }
  673. if (plugin == nullptr)
  674. return false;
  675. plugin->registerToOscClient();
  676. kData->plugins[id].plugin = plugin;
  677. kData->plugins[id].insPeak[0] = 0.0f;
  678. kData->plugins[id].insPeak[1] = 0.0f;
  679. kData->plugins[id].outsPeak[0] = 0.0f;
  680. kData->plugins[id].outsPeak[1] = 0.0f;
  681. ++kData->curPluginCount;
  682. callback(CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->name());
  683. return true;
  684. }
  685. bool CarlaEngine::removePlugin(const unsigned int id)
  686. {
  687. CARLA_ASSERT(kData->curPluginCount != 0);
  688. CARLA_ASSERT(id < kData->curPluginCount);
  689. CARLA_ASSERT(kData->plugins != nullptr);
  690. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  691. carla_debug("CarlaEngine::removePlugin(%i)", id);
  692. if (kData->plugins == nullptr || kData->curPluginCount == 0)
  693. {
  694. setLastError("Critical error: no plugins are currently loaded!");
  695. return false;
  696. }
  697. CarlaPlugin* const plugin(kData->plugins[id].plugin);
  698. if (plugin == nullptr)
  699. {
  700. setLastError("Could not find plugin to remove");
  701. return false;
  702. }
  703. CARLA_ASSERT(plugin->id() == id);
  704. kData->thread.stopNow();
  705. const bool lockWait(isRunning() && fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  706. const CarlaEngineProtectedData::ScopedPluginAction spa(kData, kEnginePostActionRemovePlugin, id, 0, lockWait);
  707. #ifndef BUILD_BRIDGE
  708. if (isOscControlRegistered())
  709. osc_send_control_remove_plugin(id);
  710. #endif
  711. delete plugin;
  712. if (isRunning() && ! kData->aboutToClose)
  713. kData->thread.startNow();
  714. callback(CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  715. return true;
  716. }
  717. void CarlaEngine::removeAllPlugins()
  718. {
  719. CARLA_ASSERT(kData->plugins != nullptr);
  720. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  721. carla_debug("CarlaEngine::removeAllPlugins() - START");
  722. if (kData->plugins == nullptr || kData->curPluginCount == 0)
  723. return;
  724. kData->thread.stopNow();
  725. const bool lockWait(isRunning());
  726. const CarlaEngineProtectedData::ScopedPluginAction spa(kData, kEnginePostActionZeroCount, 0, 0, lockWait);
  727. for (unsigned int i=0; i < kData->maxPluginNumber; ++i)
  728. {
  729. CarlaPlugin* const plugin(kData->plugins[i].plugin);
  730. kData->plugins[i].plugin = nullptr;
  731. if (plugin != nullptr)
  732. delete plugin;
  733. // clear this plugin
  734. kData->plugins[i].insPeak[0] = 0.0f;
  735. kData->plugins[i].insPeak[1] = 0.0f;
  736. kData->plugins[i].outsPeak[0] = 0.0f;
  737. kData->plugins[i].outsPeak[1] = 0.0f;
  738. }
  739. if (isRunning() && ! kData->aboutToClose)
  740. kData->thread.startNow();
  741. carla_debug("CarlaEngine::removeAllPlugins() - END");
  742. }
  743. const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
  744. {
  745. CARLA_ASSERT(kData->curPluginCount != 0);
  746. CARLA_ASSERT(id < kData->curPluginCount);
  747. CARLA_ASSERT(kData->plugins != nullptr);
  748. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  749. CARLA_ASSERT(newName != nullptr);
  750. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  751. if (kData->plugins == nullptr || kData->curPluginCount == 0)
  752. {
  753. setLastError("Critical error: no plugins are currently loaded!");
  754. return nullptr;
  755. }
  756. CarlaPlugin* const plugin(kData->plugins[id].plugin);
  757. if (plugin == nullptr)
  758. {
  759. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  760. return nullptr;
  761. }
  762. CARLA_ASSERT(plugin->id() == id);
  763. if (const char* const name = getUniquePluginName(newName))
  764. {
  765. plugin->setName(name);
  766. return name;
  767. }
  768. return nullptr;
  769. }
  770. bool CarlaEngine::clonePlugin(const unsigned int id)
  771. {
  772. CARLA_ASSERT(kData->curPluginCount > 0);
  773. CARLA_ASSERT(id < kData->curPluginCount);
  774. CARLA_ASSERT(kData->plugins != nullptr);
  775. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  776. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  777. if (kData->plugins == nullptr || kData->curPluginCount == 0)
  778. {
  779. setLastError("Critical error: no plugins are currently loaded!");
  780. return false;
  781. }
  782. CarlaPlugin* const plugin(kData->plugins[id].plugin);
  783. if (plugin == nullptr)
  784. {
  785. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  786. return false;
  787. }
  788. CARLA_ASSERT(plugin->id() == id);
  789. char label[STR_MAX+1] = { '\0' };
  790. plugin->getLabel(label);
  791. BinaryType binaryType = BINARY_NATIVE;
  792. #ifndef BUILD_BRIDGE
  793. if (plugin->hints() & PLUGIN_IS_BRIDGE)
  794. binaryType = CarlaPluginGetBridgeBinaryType(plugin);
  795. #endif
  796. const unsigned int pluginCountBefore(kData->curPluginCount);
  797. if (! addPlugin(binaryType, plugin->type(), plugin->filename(), plugin->name(), label, plugin->getExtraStuff()))
  798. return false;
  799. CARLA_ASSERT(pluginCountBefore+1 == kData->curPluginCount);
  800. if (CarlaPlugin* const newPlugin = kData->plugins[pluginCountBefore].plugin)
  801. newPlugin->loadSaveState(plugin->getSaveState());
  802. return true;
  803. }
  804. bool CarlaEngine::replacePlugin(const unsigned int id)
  805. {
  806. CARLA_ASSERT(kData->curPluginCount > 0);
  807. CARLA_ASSERT(id < kData->curPluginCount);
  808. CARLA_ASSERT(kData->plugins != nullptr);
  809. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  810. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  811. if (id < kData->curPluginCount)
  812. kData->nextPluginId = id;
  813. return false;
  814. }
  815. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  816. {
  817. CARLA_ASSERT(kData->curPluginCount >= 2);
  818. CARLA_ASSERT(kData->plugins != nullptr);
  819. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  820. CARLA_ASSERT(idA != idB);
  821. CARLA_ASSERT(idA < kData->curPluginCount);
  822. CARLA_ASSERT(idB < kData->curPluginCount);
  823. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  824. if (kData->plugins == nullptr || kData->curPluginCount == 0)
  825. {
  826. setLastError("Critical error: no plugins are currently loaded!");
  827. return false;
  828. }
  829. kData->thread.stopNow();
  830. const bool lockWait(isRunning() && fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  831. const CarlaEngineProtectedData::ScopedPluginAction spa(kData, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  832. #ifndef BUILD_BRIDGE // TODO
  833. //if (isOscControlRegistered())
  834. // osc_send_control_switch_plugins(idA, idB);
  835. #endif
  836. if (isRunning() && ! kData->aboutToClose)
  837. kData->thread.startNow();
  838. return true;
  839. }
  840. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  841. {
  842. CARLA_ASSERT(kData->curPluginCount != 0);
  843. CARLA_ASSERT(id < kData->curPluginCount);
  844. CARLA_ASSERT(kData->plugins != nullptr);
  845. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull); // TESTING, remove later
  846. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, kData->curPluginCount);
  847. if (id < kData->curPluginCount && kData->plugins != nullptr)
  848. return kData->plugins[id].plugin;
  849. return nullptr;
  850. }
  851. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const
  852. {
  853. return kData->plugins[id].plugin;
  854. }
  855. const char* CarlaEngine::getUniquePluginName(const char* const name)
  856. {
  857. CARLA_ASSERT(kData->maxPluginNumber != 0);
  858. CARLA_ASSERT(kData->plugins != nullptr);
  859. CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
  860. CARLA_ASSERT(name != nullptr);
  861. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  862. static CarlaString sname;
  863. sname = name;
  864. if (sname.isEmpty())
  865. {
  866. sname = "(No name)";
  867. return (const char*)sname;
  868. }
  869. if (kData->plugins == nullptr || kData->maxPluginNumber == 0)
  870. return (const char*)sname;
  871. sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  872. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  873. for (unsigned short i=0; i < kData->curPluginCount; ++i)
  874. {
  875. CARLA_ASSERT(kData->plugins[i].plugin != nullptr);
  876. if (kData->plugins[i].plugin == nullptr)
  877. break;
  878. // Check if unique name doesn't exist
  879. if (const char* const pluginName = kData->plugins[i].plugin->name())
  880. {
  881. if (sname != pluginName)
  882. continue;
  883. }
  884. // Check if string has already been modified
  885. {
  886. const size_t len(sname.length());
  887. // 1 digit, ex: " (2)"
  888. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  889. {
  890. int number = sname[len-2] - '0';
  891. if (number == 9)
  892. {
  893. // next number is 10, 2 digits
  894. sname.truncate(len-4);
  895. sname += " (10)";
  896. //sname.replace(" (9)", " (10)");
  897. }
  898. else
  899. sname[len-2] = char('0' + number + 1);
  900. continue;
  901. }
  902. // 2 digits, ex: " (11)"
  903. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  904. {
  905. char n2 = sname[len-2];
  906. char n3 = sname[len-3];
  907. if (n2 == '9')
  908. {
  909. n2 = '0';
  910. n3 += 1;
  911. }
  912. else
  913. n2 += 1;
  914. sname[len-2] = n2;
  915. sname[len-3] = n3;
  916. continue;
  917. }
  918. }
  919. // Modify string if not
  920. sname += " (2)";
  921. }
  922. return (const char*)sname;
  923. }
  924. // -----------------------------------------------------------------------
  925. // Project management
  926. bool CarlaEngine::loadFilename(const char* const filename)
  927. {
  928. CARLA_ASSERT(filename != nullptr);
  929. carla_debug("CarlaEngine::loadFilename(\"%s\")", filename);
  930. QFileInfo fileInfo(filename);
  931. if (! fileInfo.exists())
  932. {
  933. setLastError("File does not exist");
  934. return false;
  935. }
  936. if (! fileInfo.isFile())
  937. {
  938. setLastError("Not a file");
  939. return false;
  940. }
  941. if (! fileInfo.isReadable())
  942. {
  943. setLastError("File is not readable");
  944. return false;
  945. }
  946. CarlaString baseName(fileInfo.baseName().toUtf8().constData());
  947. CarlaString extension(fileInfo.suffix().toLower().toUtf8().constData());
  948. // -------------------------------------------------------------------
  949. if (extension == "carxp" || extension == "carxs")
  950. return loadProject(filename);
  951. // -------------------------------------------------------------------
  952. if (extension == "gig")
  953. return addPlugin(PLUGIN_GIG, filename, baseName, baseName);
  954. if (extension == "sf2")
  955. return addPlugin(PLUGIN_SF2, filename, baseName, baseName);
  956. if (extension == "sfz")
  957. return addPlugin(PLUGIN_SFZ, filename, baseName, baseName);
  958. // -------------------------------------------------------------------
  959. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  960. {
  961. #ifdef WANT_AUDIOFILE
  962. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  963. {
  964. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  965. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  966. return true;
  967. }
  968. return false;
  969. #else
  970. setLastError("This Carla build does not have Audio file support");
  971. return false;
  972. #endif
  973. }
  974. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  975. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  976. {
  977. #ifdef WANT_AUDIOFILE
  978. # ifdef HAVE_FFMPEG
  979. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  980. {
  981. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  982. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  983. return true;
  984. }
  985. return false;
  986. # else
  987. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  988. return false;
  989. # endif
  990. #else
  991. setLastError("This Carla build does not have Audio file support");
  992. return false;
  993. #endif
  994. }
  995. // -------------------------------------------------------------------
  996. if (extension == "mid" || extension == "midi")
  997. {
  998. #ifdef WANT_MIDIFILE
  999. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile"))
  1000. {
  1001. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  1002. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  1003. return true;
  1004. }
  1005. return false;
  1006. #else
  1007. setLastError("This Carla build does not have MIDI file support");
  1008. return false;
  1009. #endif
  1010. }
  1011. // -------------------------------------------------------------------
  1012. // ZynAddSubFX
  1013. if (extension == "xmz" || extension == "xiz")
  1014. {
  1015. #ifdef WANT_ZYNADDSUBFX
  1016. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx"))
  1017. {
  1018. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  1019. plugin->setCustomData(CUSTOM_DATA_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  1020. return true;
  1021. }
  1022. return false;
  1023. #else
  1024. setLastError("This Carla build does not have ZynAddSubFX support");
  1025. return false;
  1026. #endif
  1027. }
  1028. // -------------------------------------------------------------------
  1029. setLastError("Unknown file extension");
  1030. return false;
  1031. }
  1032. bool charEndsWith(const char* const str, const char* const suffix)
  1033. {
  1034. if (str == nullptr || suffix == nullptr)
  1035. return false;
  1036. const size_t strLen(std::strlen(str));
  1037. const size_t suffixLen(std::strlen(suffix));
  1038. if (strLen < suffixLen)
  1039. return false;
  1040. return (std::strncmp(str + (strLen-suffixLen), suffix, suffixLen) == 0);
  1041. }
  1042. bool CarlaEngine::loadProject(const char* const filename)
  1043. {
  1044. CARLA_ASSERT(filename != nullptr);
  1045. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1046. QFile file(filename);
  1047. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  1048. return false;
  1049. QDomDocument xml;
  1050. xml.setContent(file.readAll());
  1051. file.close();
  1052. QDomNode xmlNode(xml.documentElement());
  1053. if (xmlNode.toElement().tagName() != "CARLA-PROJECT" && xmlNode.toElement().tagName() != "CARLA-PRESET")
  1054. {
  1055. setLastError("Not a valid Carla project or preset file");
  1056. return false;
  1057. }
  1058. const bool isPreset(xmlNode.toElement().tagName() == "CARLA-PRESET");
  1059. QDomNode node(xmlNode.firstChild());
  1060. while (! node.isNull())
  1061. {
  1062. if (isPreset || node.toElement().tagName() == "Plugin")
  1063. {
  1064. const SaveState& saveState(getSaveStateDictFromXML(isPreset ? xmlNode : node));
  1065. CARLA_ASSERT(saveState.type != nullptr);
  1066. if (saveState.type == nullptr)
  1067. continue;
  1068. const void* extraStuff = nullptr;
  1069. if (std::strcmp(saveState.type, "DSSI") == 0)
  1070. {
  1071. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  1072. }
  1073. else if (std::strcmp(saveState.type, "SF2") == 0)
  1074. {
  1075. const char use16OutsSuffix[] = " (16 outs)";
  1076. if (charEndsWith(saveState.label, use16OutsSuffix))
  1077. extraStuff = (void*)0x1; // non-null
  1078. }
  1079. // TODO - proper find&load plugins
  1080. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  1081. {
  1082. if (CarlaPlugin* plugin = getPlugin(kData->curPluginCount-1))
  1083. plugin->loadSaveState(saveState);
  1084. }
  1085. }
  1086. if (isPreset)
  1087. break;
  1088. node = node.nextSibling();
  1089. }
  1090. return true;
  1091. }
  1092. bool CarlaEngine::saveProject(const char* const filename)
  1093. {
  1094. CARLA_ASSERT(filename != nullptr);
  1095. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1096. QFile file(filename);
  1097. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1098. return false;
  1099. QTextStream out(&file);
  1100. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1101. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1102. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  1103. bool firstPlugin = true;
  1104. char strBuf[STR_MAX+1];
  1105. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1106. {
  1107. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1108. if (plugin != nullptr && plugin->enabled())
  1109. {
  1110. if (! firstPlugin)
  1111. out << "\n";
  1112. plugin->getRealName(strBuf);
  1113. if (*strBuf != 0)
  1114. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1115. out << " <Plugin>\n";
  1116. out << getXMLFromSaveState(plugin->getSaveState());
  1117. out << " </Plugin>\n";
  1118. firstPlugin = false;
  1119. }
  1120. }
  1121. out << "</CARLA-PROJECT>\n";
  1122. file.close();
  1123. return true;
  1124. }
  1125. // -----------------------------------------------------------------------
  1126. // Information (peaks)
  1127. // FIXME
  1128. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  1129. {
  1130. CARLA_ASSERT(pluginId < kData->curPluginCount);
  1131. CARLA_ASSERT(id-1 < 2);
  1132. if (id == 0 || id > 2)
  1133. return 0.0f;
  1134. return kData->plugins[pluginId].insPeak[id-1];
  1135. }
  1136. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  1137. {
  1138. CARLA_ASSERT(pluginId < kData->curPluginCount);
  1139. CARLA_ASSERT(id-1 < 2);
  1140. if (id == 0 || id > 2)
  1141. return 0.0f;
  1142. return kData->plugins[pluginId].outsPeak[id-1];
  1143. }
  1144. // -----------------------------------------------------------------------
  1145. // Callback
  1146. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  1147. {
  1148. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  1149. if (kData->callback)
  1150. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1151. }
  1152. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  1153. {
  1154. CARLA_ASSERT(func != nullptr);
  1155. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1156. kData->callback = func;
  1157. kData->callbackPtr = ptr;
  1158. }
  1159. // -----------------------------------------------------------------------
  1160. // Patchbay
  1161. bool CarlaEngine::patchbayConnect(int, int)
  1162. {
  1163. setLastError("Unsupported operation");
  1164. return false;
  1165. }
  1166. bool CarlaEngine::patchbayDisconnect(int)
  1167. {
  1168. setLastError("Unsupported operation");
  1169. return false;
  1170. }
  1171. void CarlaEngine::patchbayRefresh()
  1172. {
  1173. // nothing
  1174. }
  1175. // -----------------------------------------------------------------------
  1176. // Transport
  1177. void CarlaEngine::transportPlay()
  1178. {
  1179. kData->time.playing = true;
  1180. }
  1181. void CarlaEngine::transportPause()
  1182. {
  1183. kData->time.playing = false;
  1184. }
  1185. void CarlaEngine::transportRelocate(const uint32_t frame)
  1186. {
  1187. kData->time.frame = frame;
  1188. }
  1189. // -----------------------------------------------------------------------
  1190. // Error handling
  1191. const char* CarlaEngine::getLastError() const
  1192. {
  1193. return (const char*)kData->lastError;
  1194. }
  1195. void CarlaEngine::setLastError(const char* const error)
  1196. {
  1197. kData->lastError = error;
  1198. }
  1199. void CarlaEngine::setAboutToClose()
  1200. {
  1201. carla_debug("CarlaEngine::setAboutToClose()");
  1202. kData->aboutToClose = true;
  1203. }
  1204. // -----------------------------------------------------------------------
  1205. // Global options
  1206. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  1207. if (isRunning()) \
  1208. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  1209. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  1210. {
  1211. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  1212. switch (option)
  1213. {
  1214. case OPTION_PROCESS_NAME:
  1215. carla_setprocname(valueStr);
  1216. break;
  1217. case OPTION_PROCESS_MODE:
  1218. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1219. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_BRIDGE)
  1220. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  1221. fOptions.processMode = static_cast<ProcessMode>(value);
  1222. break;
  1223. case OPTION_TRANSPORT_MODE:
  1224. // FIXME: Always enable JACK transport for now
  1225. #if 0
  1226. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_BRIDGE)
  1227. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1228. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  1229. #endif
  1230. break;
  1231. case OPTION_MAX_PARAMETERS:
  1232. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1233. if (value < 0)
  1234. return; // TODO error here
  1235. fOptions.maxParameters = static_cast<uint>(value);
  1236. break;
  1237. case OPTION_FORCE_STEREO:
  1238. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1239. fOptions.forceStereo = (value != 0);
  1240. break;
  1241. #ifdef WANT_DSSI
  1242. case OPTION_USE_DSSI_VST_CHUNKS:
  1243. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1244. fOptions.useDssiVstChunks = (value != 0);
  1245. break;
  1246. #endif
  1247. case OPTION_PREFER_PLUGIN_BRIDGES:
  1248. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1249. fOptions.preferPluginBridges = (value != 0);
  1250. break;
  1251. case OPTION_PREFER_UI_BRIDGES:
  1252. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1253. fOptions.preferUiBridges = (value != 0);
  1254. break;
  1255. case OPTION_OSC_UI_TIMEOUT:
  1256. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1257. fOptions.oscUiTimeout = static_cast<uint>(value);
  1258. break;
  1259. case OPTION_JACK_AUTOCONNECT:
  1260. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1261. fOptions.jackAutoConnect = (value != 0);
  1262. break;
  1263. case OPTION_JACK_TIMEMASTER:
  1264. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1265. fOptions.jackTimeMaster = (value != 0);
  1266. break;
  1267. #ifdef WANT_RTAUDIO
  1268. case OPTION_RTAUDIO_BUFFER_SIZE:
  1269. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1270. fOptions.rtaudioBufferSize = static_cast<uint>(value);
  1271. break;
  1272. case OPTION_RTAUDIO_SAMPLE_RATE:
  1273. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1274. fOptions.rtaudioSampleRate = static_cast<uint>(value);
  1275. break;
  1276. case OPTION_RTAUDIO_DEVICE:
  1277. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1278. fOptions.rtaudioDevice = valueStr;
  1279. break;
  1280. #endif
  1281. case OPTION_PATH_RESOURCES:
  1282. fOptions.resourceDir = valueStr;
  1283. break;
  1284. #ifndef BUILD_BRIDGE
  1285. case OPTION_PATH_BRIDGE_NATIVE:
  1286. fOptions.bridge_native = valueStr;
  1287. break;
  1288. case OPTION_PATH_BRIDGE_POSIX32:
  1289. fOptions.bridge_posix32 = valueStr;
  1290. break;
  1291. case OPTION_PATH_BRIDGE_POSIX64:
  1292. fOptions.bridge_posix64 = valueStr;
  1293. break;
  1294. case OPTION_PATH_BRIDGE_WIN32:
  1295. fOptions.bridge_win32 = valueStr;
  1296. break;
  1297. case OPTION_PATH_BRIDGE_WIN64:
  1298. fOptions.bridge_win64 = valueStr;
  1299. break;
  1300. #endif
  1301. #ifdef WANT_LV2
  1302. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1303. fOptions.bridge_lv2Gtk2 = valueStr;
  1304. break;
  1305. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1306. fOptions.bridge_lv2Gtk3 = valueStr;
  1307. break;
  1308. case OPTION_PATH_BRIDGE_LV2_QT4:
  1309. fOptions.bridge_lv2Qt4 = valueStr;
  1310. break;
  1311. case OPTION_PATH_BRIDGE_LV2_QT5:
  1312. fOptions.bridge_lv2Qt5 = valueStr;
  1313. break;
  1314. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1315. fOptions.bridge_lv2Cocoa = valueStr;
  1316. break;
  1317. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1318. fOptions.bridge_lv2Win = valueStr;
  1319. break;
  1320. case OPTION_PATH_BRIDGE_LV2_X11:
  1321. fOptions.bridge_lv2X11 = valueStr;
  1322. break;
  1323. #endif
  1324. #ifdef WANT_VST
  1325. case OPTION_PATH_BRIDGE_VST_COCOA:
  1326. fOptions.bridge_vstCocoa = valueStr;
  1327. break;
  1328. case OPTION_PATH_BRIDGE_VST_HWND:
  1329. fOptions.bridge_vstHWND = valueStr;
  1330. break;
  1331. case OPTION_PATH_BRIDGE_VST_X11:
  1332. fOptions.bridge_vstX11 = valueStr;
  1333. break;
  1334. #endif
  1335. }
  1336. }
  1337. // -----------------------------------------------------------------------
  1338. // OSC Stuff
  1339. #ifdef BUILD_BRIDGE
  1340. bool CarlaEngine::isOscBridgeRegistered() const
  1341. {
  1342. return (kData->oscData != nullptr);
  1343. }
  1344. #else
  1345. bool CarlaEngine::isOscControlRegistered() const
  1346. {
  1347. return kData->osc.isControlRegistered();
  1348. }
  1349. #endif
  1350. void CarlaEngine::idleOsc()
  1351. {
  1352. kData->osc.idle();
  1353. }
  1354. const char* CarlaEngine::getOscServerPathTCP() const
  1355. {
  1356. return kData->osc.getServerPathTCP();
  1357. }
  1358. const char* CarlaEngine::getOscServerPathUDP() const
  1359. {
  1360. return kData->osc.getServerPathUDP();
  1361. }
  1362. #ifdef BUILD_BRIDGE
  1363. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1364. {
  1365. kData->oscData = oscData;
  1366. }
  1367. #endif
  1368. // -----------------------------------------------------------------------
  1369. // protected calls
  1370. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1371. {
  1372. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1373. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1374. {
  1375. CarlaPlugin* const plugin(kData->plugins[i].plugin);
  1376. if (plugin != nullptr && plugin->enabled())
  1377. plugin->bufferSizeChanged(newBufferSize);
  1378. }
  1379. callback(CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1380. }
  1381. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1382. {
  1383. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1384. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1385. {
  1386. CarlaPlugin* const plugin(kData->plugins[i].plugin);
  1387. if (plugin != nullptr && plugin->enabled())
  1388. plugin->sampleRateChanged(newSampleRate);
  1389. }
  1390. callback(CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, newSampleRate, nullptr);
  1391. }
  1392. void CarlaEngine::offlineModeChanged(const bool isOffline)
  1393. {
  1394. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOffline));
  1395. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1396. {
  1397. CarlaPlugin* const plugin(kData->plugins[i].plugin);
  1398. if (plugin != nullptr && plugin->enabled())
  1399. plugin->offlineModeChanged(isOffline);
  1400. }
  1401. }
  1402. void CarlaEngine::proccessPendingEvents()
  1403. {
  1404. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1405. kData->doNextPluginAction(true);
  1406. if (kData->time.playing)
  1407. kData->time.frame += fBufferSize;
  1408. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1409. {
  1410. fTimeInfo.playing = kData->time.playing;
  1411. fTimeInfo.frame = kData->time.frame;
  1412. }
  1413. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1414. {
  1415. // TODO - peak values?
  1416. }
  1417. }
  1418. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2])
  1419. {
  1420. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1421. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1422. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1423. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1424. }
  1425. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const
  1426. {
  1427. return isInput ? kData->bufEvents.in : kData->bufEvents.out;
  1428. }
  1429. #ifndef BUILD_BRIDGE
  1430. void setValueIfHigher(float& value, const float& compare)
  1431. {
  1432. if (value < compare)
  1433. value = compare;
  1434. }
  1435. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1436. {
  1437. CARLA_ASSERT(kData->bufEvents.in != nullptr);
  1438. CARLA_ASSERT(kData->bufEvents.out != nullptr);
  1439. // initialize outputs (zero)
  1440. carla_zeroFloat(outBuf[0], frames);
  1441. carla_zeroFloat(outBuf[1], frames);
  1442. carla_zeroMem(kData->bufEvents.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1443. bool processed = false;
  1444. // process plugins
  1445. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1446. {
  1447. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1448. if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock())
  1449. continue;
  1450. if (processed)
  1451. {
  1452. // initialize inputs (from previous outputs)
  1453. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1454. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1455. std::memcpy(kData->bufEvents.in, kData->bufEvents.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1456. // initialize outputs (zero)
  1457. carla_zeroFloat(outBuf[0], frames);
  1458. carla_zeroFloat(outBuf[1], frames);
  1459. carla_zeroMem(kData->bufEvents.out, sizeof(EngineEvent)*INTERNAL_EVENT_COUNT);
  1460. }
  1461. // process
  1462. plugin->initBuffers();
  1463. plugin->process(inBuf, outBuf, frames);
  1464. plugin->unlock();
  1465. #if 0
  1466. // if plugin has no audio inputs, add previous buffers
  1467. if (plugin->audioInCount() == 0)
  1468. {
  1469. for (uint32_t j=0; j < frames; ++j)
  1470. {
  1471. outBuf[0][j] += inBuf[0][j];
  1472. outBuf[1][j] += inBuf[1][j];
  1473. }
  1474. }
  1475. // if plugin has no midi output, add previous events
  1476. if (plugin->midiOutCount() == 0)
  1477. {
  1478. for (uint32_t j=0, k=0; j < frames; ++j)
  1479. {
  1480. }
  1481. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1482. }
  1483. #endif
  1484. // set peaks
  1485. {
  1486. float inPeak1 = 0.0f;
  1487. float inPeak2 = 0.0f;
  1488. float outPeak1 = 0.0f;
  1489. float outPeak2 = 0.0f;
  1490. for (uint32_t k=0; k < frames; ++k)
  1491. {
  1492. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1493. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1494. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1495. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1496. }
  1497. kData->plugins[i].insPeak[0] = inPeak1;
  1498. kData->plugins[i].insPeak[1] = inPeak2;
  1499. kData->plugins[i].outsPeak[0] = outPeak1;
  1500. kData->plugins[i].outsPeak[1] = outPeak2;
  1501. }
  1502. processed = true;
  1503. }
  1504. }
  1505. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1506. {
  1507. // TODO
  1508. return;
  1509. // unused, for now
  1510. (void)inBuf;
  1511. (void)outBuf;
  1512. (void)bufCount;
  1513. (void)frames;
  1514. }
  1515. #endif
  1516. // -------------------------------------------------------------------------------------------------------------------
  1517. // Carla Engine OSC stuff
  1518. #ifndef BUILD_BRIDGE
  1519. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1520. {
  1521. CARLA_ASSERT(kData->oscData != nullptr);
  1522. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1523. CARLA_ASSERT(pluginName != nullptr);
  1524. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1525. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1526. {
  1527. char targetPath[std::strlen(kData->oscData->path)+18];
  1528. std::strcpy(targetPath, kData->oscData->path);
  1529. std::strcat(targetPath, "/add_plugin_start");
  1530. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1531. }
  1532. }
  1533. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1534. {
  1535. CARLA_ASSERT(kData->oscData != nullptr);
  1536. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1537. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1538. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1539. {
  1540. char targetPath[std::strlen(kData->oscData->path)+16];
  1541. std::strcpy(targetPath, kData->oscData->path);
  1542. std::strcat(targetPath, "/add_plugin_end");
  1543. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1544. }
  1545. }
  1546. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1547. {
  1548. CARLA_ASSERT(kData->oscData != nullptr);
  1549. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->curPluginCount));
  1550. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1551. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1552. {
  1553. char targetPath[std::strlen(kData->oscData->path)+15];
  1554. std::strcpy(targetPath, kData->oscData->path);
  1555. std::strcat(targetPath, "/remove_plugin");
  1556. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1557. }
  1558. }
  1559. void CarlaEngine::osc_send_control_set_plugin_data(const int32_t pluginId, const int32_t type, const int32_t category, const int32_t hints, const char* const realName, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1560. {
  1561. CARLA_ASSERT(kData->oscData != nullptr);
  1562. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1563. CARLA_ASSERT(type != PLUGIN_NONE);
  1564. CARLA_ASSERT(realName != nullptr);
  1565. CARLA_ASSERT(label != nullptr);
  1566. CARLA_ASSERT(maker != nullptr);
  1567. CARLA_ASSERT(copyright != nullptr);
  1568. carla_debug("CarlaEngine::osc_send_control_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1569. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1570. {
  1571. char targetPath[std::strlen(kData->oscData->path)+17];
  1572. std::strcpy(targetPath, kData->oscData->path);
  1573. std::strcat(targetPath, "/set_plugin_data");
  1574. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1575. }
  1576. }
  1577. void CarlaEngine::osc_send_control_set_plugin_ports(const int32_t pluginId, const int32_t audioIns, const int32_t audioOuts, const int32_t midiIns, const int32_t midiOuts, const int32_t cIns, const int32_t cOuts, const int32_t cTotals)
  1578. {
  1579. CARLA_ASSERT(kData->oscData != nullptr);
  1580. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1581. carla_debug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1582. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1583. {
  1584. char targetPath[std::strlen(kData->oscData->path)+18];
  1585. std::strcpy(targetPath, kData->oscData->path);
  1586. std::strcat(targetPath, "/set_plugin_ports");
  1587. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1588. }
  1589. }
  1590. void CarlaEngine::osc_send_control_set_parameter_data(const int32_t pluginId, const int32_t index, const int32_t type, const int32_t hints, const char* const name, const char* const label, const float current)
  1591. {
  1592. CARLA_ASSERT(kData->oscData != nullptr);
  1593. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1594. CARLA_ASSERT(index >= 0);
  1595. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1596. CARLA_ASSERT(name != nullptr);
  1597. CARLA_ASSERT(label != nullptr);
  1598. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %f)", pluginId, index, type, hints, name, label, current);
  1599. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1600. {
  1601. char targetPath[std::strlen(kData->oscData->path)+20];
  1602. std::strcpy(targetPath, kData->oscData->path);
  1603. std::strcat(targetPath, "/set_parameter_data");
  1604. lo_send(kData->oscData->target, targetPath, "iiiissf", pluginId, index, type, hints, name, label, current);
  1605. }
  1606. }
  1607. void CarlaEngine::osc_send_control_set_parameter_ranges(const int32_t pluginId, const int32_t index, const float min, const float max, const float def, const float step, const float stepSmall, const float stepLarge)
  1608. {
  1609. CARLA_ASSERT(kData->oscData != nullptr);
  1610. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1611. CARLA_ASSERT(index >= 0);
  1612. CARLA_ASSERT(min < max);
  1613. carla_debug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %f, %f, %f, %f, %f, %f)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1614. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1615. {
  1616. char targetPath[std::strlen(kData->oscData->path)+22];
  1617. std::strcpy(targetPath, kData->oscData->path);
  1618. std::strcat(targetPath, "/set_parameter_ranges");
  1619. lo_send(kData->oscData->target, targetPath, "iiffffff", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1620. }
  1621. }
  1622. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1623. {
  1624. CARLA_ASSERT(kData->oscData != nullptr);
  1625. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1626. CARLA_ASSERT(index >= 0);
  1627. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1628. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1629. {
  1630. char targetPath[std::strlen(kData->oscData->path)+23];
  1631. std::strcpy(targetPath, kData->oscData->path);
  1632. std::strcat(targetPath, "/set_parameter_midi_cc");
  1633. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1634. }
  1635. }
  1636. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1637. {
  1638. CARLA_ASSERT(kData->oscData != nullptr);
  1639. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1640. CARLA_ASSERT(index >= 0);
  1641. CARLA_ASSERT(channel >= 0 && channel < 16);
  1642. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1643. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1644. {
  1645. char targetPath[std::strlen(kData->oscData->path)+28];
  1646. std::strcpy(targetPath, kData->oscData->path);
  1647. std::strcat(targetPath, "/set_parameter_midi_channel");
  1648. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1649. }
  1650. }
  1651. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1652. {
  1653. CARLA_ASSERT(kData->oscData != nullptr);
  1654. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1655. #if DEBUG
  1656. if (index < 0)
  1657. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %f)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1658. else
  1659. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %f)", pluginId, index, value);
  1660. #endif
  1661. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1662. {
  1663. char targetPath[std::strlen(kData->oscData->path)+21];
  1664. std::strcpy(targetPath, kData->oscData->path);
  1665. std::strcat(targetPath, "/set_parameter_value");
  1666. lo_send(kData->oscData->target, targetPath, "iif", pluginId, index, value);
  1667. }
  1668. }
  1669. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1670. {
  1671. CARLA_ASSERT(kData->oscData != nullptr);
  1672. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1673. CARLA_ASSERT(index >= 0);
  1674. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  1675. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1676. {
  1677. char targetPath[std::strlen(kData->oscData->path)+19];
  1678. std::strcpy(targetPath, kData->oscData->path);
  1679. std::strcat(targetPath, "/set_default_value");
  1680. lo_send(kData->oscData->target, targetPath, "iif", pluginId, index, value);
  1681. }
  1682. }
  1683. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1684. {
  1685. CARLA_ASSERT(kData->oscData != nullptr);
  1686. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1687. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1688. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1689. {
  1690. char targetPath[std::strlen(kData->oscData->path)+13];
  1691. std::strcpy(targetPath, kData->oscData->path);
  1692. std::strcat(targetPath, "/set_program");
  1693. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1694. }
  1695. }
  1696. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1697. {
  1698. CARLA_ASSERT(kData->oscData != nullptr);
  1699. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1700. CARLA_ASSERT(count >= 0);
  1701. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1702. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1703. {
  1704. char targetPath[std::strlen(kData->oscData->path)+19];
  1705. std::strcpy(targetPath, kData->oscData->path);
  1706. std::strcat(targetPath, "/set_program_count");
  1707. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1708. }
  1709. }
  1710. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1711. {
  1712. CARLA_ASSERT(kData->oscData != nullptr);
  1713. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1714. CARLA_ASSERT(index >= 0);
  1715. CARLA_ASSERT(name != nullptr);
  1716. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1717. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1718. {
  1719. char targetPath[std::strlen(kData->oscData->path)+18];
  1720. std::strcpy(targetPath, kData->oscData->path);
  1721. std::strcat(targetPath, "/set_program_name");
  1722. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1723. }
  1724. }
  1725. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1726. {
  1727. CARLA_ASSERT(kData->oscData != nullptr);
  1728. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1729. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1730. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1731. {
  1732. char targetPath[std::strlen(kData->oscData->path)+18];
  1733. std::strcpy(targetPath, kData->oscData->path);
  1734. std::strcat(targetPath, "/set_midi_program");
  1735. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1736. }
  1737. }
  1738. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1739. {
  1740. CARLA_ASSERT(kData->oscData != nullptr);
  1741. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1742. CARLA_ASSERT(count >= 0);
  1743. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1744. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1745. {
  1746. char targetPath[std::strlen(kData->oscData->path)+24];
  1747. std::strcpy(targetPath, kData->oscData->path);
  1748. std::strcat(targetPath, "/set_midi_program_count");
  1749. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1750. }
  1751. }
  1752. void CarlaEngine::osc_send_control_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name)
  1753. {
  1754. CARLA_ASSERT(kData->oscData != nullptr);
  1755. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->maxPluginNumber));
  1756. CARLA_ASSERT(index >= 0);
  1757. CARLA_ASSERT(bank >= 0);
  1758. CARLA_ASSERT(program >= 0);
  1759. CARLA_ASSERT(name != nullptr);
  1760. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1761. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1762. {
  1763. char targetPath[std::strlen(kData->oscData->path)+23];
  1764. std::strcpy(targetPath, kData->oscData->path);
  1765. std::strcat(targetPath, "/set_midi_program_data");
  1766. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1767. }
  1768. }
  1769. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1770. {
  1771. CARLA_ASSERT(kData->oscData != nullptr);
  1772. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->curPluginCount));
  1773. CARLA_ASSERT(channel >= 0 && channel < MAX_MIDI_CHANNELS);
  1774. CARLA_ASSERT(note >= 0 && note < MAX_MIDI_NOTE);
  1775. CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE);
  1776. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1777. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1778. {
  1779. char targetPath[std::strlen(kData->oscData->path)+9];
  1780. std::strcpy(targetPath, kData->oscData->path);
  1781. std::strcat(targetPath, "/note_on");
  1782. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1783. }
  1784. }
  1785. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1786. {
  1787. CARLA_ASSERT(kData->oscData != nullptr);
  1788. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->curPluginCount));
  1789. CARLA_ASSERT(channel >= 0 && channel < MAX_MIDI_CHANNELS);
  1790. CARLA_ASSERT(note >= 0 && note < MAX_MIDI_NOTE);
  1791. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1792. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1793. {
  1794. char targetPath[std::strlen(kData->oscData->path)+10];
  1795. std::strcpy(targetPath, kData->oscData->path);
  1796. std::strcat(targetPath, "/note_off");
  1797. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1798. }
  1799. }
  1800. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1801. {
  1802. CARLA_ASSERT(kData->oscData != nullptr);
  1803. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(kData->curPluginCount));
  1804. const EnginePluginData& pData = kData->plugins[pluginId];
  1805. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1806. {
  1807. char targetPath[std::strlen(kData->oscData->path)+22];
  1808. std::strcpy(targetPath, kData->oscData->path);
  1809. std::strcat(targetPath, "/set_peaks");
  1810. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1811. }
  1812. }
  1813. void CarlaEngine::osc_send_control_exit()
  1814. {
  1815. CARLA_ASSERT(kData->oscData != nullptr);
  1816. carla_debug("CarlaEngine::osc_send_control_exit()");
  1817. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1818. {
  1819. char targetPath[std::strlen(kData->oscData->path)+6];
  1820. std::strcpy(targetPath, kData->oscData->path);
  1821. std::strcat(targetPath, "/exit");
  1822. lo_send(kData->oscData->target, targetPath, "");
  1823. }
  1824. }
  1825. #else
  1826. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1827. {
  1828. CARLA_ASSERT(kData->oscData != nullptr);
  1829. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1830. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1831. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1832. {
  1833. char targetPath[std::strlen(kData->oscData->path)+20];
  1834. std::strcpy(targetPath, kData->oscData->path);
  1835. std::strcat(targetPath, "/bridge_audio_count");
  1836. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1837. }
  1838. }
  1839. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1840. {
  1841. CARLA_ASSERT(kData->oscData != nullptr);
  1842. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1843. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1844. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1845. {
  1846. char targetPath[std::strlen(kData->oscData->path)+19];
  1847. std::strcpy(targetPath, kData->oscData->path);
  1848. std::strcat(targetPath, "/bridge_midi_count");
  1849. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1850. }
  1851. }
  1852. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1853. {
  1854. CARLA_ASSERT(kData->oscData != nullptr);
  1855. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1856. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1857. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1858. {
  1859. char targetPath[std::strlen(kData->oscData->path)+24];
  1860. std::strcpy(targetPath, kData->oscData->path);
  1861. std::strcat(targetPath, "/bridge_parameter_count");
  1862. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1863. }
  1864. }
  1865. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1866. {
  1867. CARLA_ASSERT(kData->oscData != nullptr);
  1868. CARLA_ASSERT(count >= 0);
  1869. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1870. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1871. {
  1872. char targetPath[std::strlen(kData->oscData->path)+22];
  1873. std::strcpy(targetPath, kData->oscData->path);
  1874. std::strcat(targetPath, "/bridge_program_count");
  1875. lo_send(kData->oscData->target, targetPath, "i", count);
  1876. }
  1877. }
  1878. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1879. {
  1880. CARLA_ASSERT(kData->oscData != nullptr);
  1881. CARLA_ASSERT(count >= 0);
  1882. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1883. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1884. {
  1885. char targetPath[std::strlen(kData->oscData->path)+27];
  1886. std::strcpy(targetPath, kData->oscData->path);
  1887. std::strcat(targetPath, "/bridge_midi_program_count");
  1888. lo_send(kData->oscData->target, targetPath, "i", count);
  1889. }
  1890. }
  1891. void CarlaEngine::osc_send_bridge_plugin_info(const int32_t category, const int32_t hints, const char* const name, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1892. {
  1893. CARLA_ASSERT(kData->oscData != nullptr);
  1894. CARLA_ASSERT(name != nullptr);
  1895. CARLA_ASSERT(label != nullptr);
  1896. CARLA_ASSERT(maker != nullptr);
  1897. CARLA_ASSERT(copyright != nullptr);
  1898. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1899. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1900. {
  1901. char targetPath[std::strlen(kData->oscData->path)+20];
  1902. std::strcpy(targetPath, kData->oscData->path);
  1903. std::strcat(targetPath, "/bridge_plugin_info");
  1904. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1905. }
  1906. }
  1907. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1908. {
  1909. CARLA_ASSERT(kData->oscData != nullptr);
  1910. CARLA_ASSERT(name != nullptr);
  1911. CARLA_ASSERT(unit != nullptr);
  1912. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1913. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1914. {
  1915. char targetPath[std::strlen(kData->oscData->path)+23];
  1916. std::strcpy(targetPath, kData->oscData->path);
  1917. std::strcat(targetPath, "/bridge_parameter_info");
  1918. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1919. }
  1920. }
  1921. void CarlaEngine::osc_send_bridge_parameter_data(const int32_t index, const int32_t type, const int32_t rindex, const int32_t hints, const int32_t midiChannel, const int32_t midiCC)
  1922. {
  1923. CARLA_ASSERT(kData->oscData != nullptr);
  1924. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1925. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1926. {
  1927. char targetPath[std::strlen(kData->oscData->path)+23];
  1928. std::strcpy(targetPath, kData->oscData->path);
  1929. std::strcat(targetPath, "/bridge_parameter_data");
  1930. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1931. }
  1932. }
  1933. void CarlaEngine::osc_send_bridge_parameter_ranges(const int32_t index, const float def, const float min, const float max, const float step, const float stepSmall, const float stepLarge)
  1934. {
  1935. CARLA_ASSERT(kData->oscData != nullptr);
  1936. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %f, %f, %f, %f, %f, %f)", index, def, min, max, step, stepSmall, stepLarge);
  1937. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1938. {
  1939. char targetPath[std::strlen(kData->oscData->path)+25];
  1940. std::strcpy(targetPath, kData->oscData->path);
  1941. std::strcat(targetPath, "/bridge_parameter_ranges");
  1942. lo_send(kData->oscData->target, targetPath, "iffffff", index, def, min, max, step, stepSmall, stepLarge);
  1943. }
  1944. }
  1945. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1946. {
  1947. CARLA_ASSERT(kData->oscData != nullptr);
  1948. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1949. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1950. {
  1951. char targetPath[std::strlen(kData->oscData->path)+21];
  1952. std::strcpy(targetPath, kData->oscData->path);
  1953. std::strcat(targetPath, "/bridge_program_info");
  1954. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1955. }
  1956. }
  1957. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1958. {
  1959. CARLA_ASSERT(kData->oscData != nullptr);
  1960. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1961. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1962. {
  1963. char targetPath[std::strlen(kData->oscData->path)+26];
  1964. std::strcpy(targetPath, kData->oscData->path);
  1965. std::strcat(targetPath, "/bridge_midi_program_info");
  1966. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1967. }
  1968. }
  1969. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1970. {
  1971. CARLA_ASSERT(kData->oscData != nullptr);
  1972. CARLA_ASSERT(key != nullptr);
  1973. CARLA_ASSERT(value != nullptr);
  1974. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1975. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1976. {
  1977. char targetPath[std::strlen(kData->oscData->path)+18];
  1978. std::strcpy(targetPath, kData->oscData->path);
  1979. std::strcat(targetPath, "/bridge_configure");
  1980. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1981. }
  1982. }
  1983. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1984. {
  1985. CARLA_ASSERT(kData->oscData != nullptr);
  1986. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %f)", index, value);
  1987. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1988. {
  1989. char targetPath[std::strlen(kData->oscData->path)+28];
  1990. std::strcpy(targetPath, kData->oscData->path);
  1991. std::strcat(targetPath, "/bridge_set_parameter_value");
  1992. lo_send(kData->oscData->target, targetPath, "if", index, value);
  1993. }
  1994. }
  1995. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1996. {
  1997. CARLA_ASSERT(kData->oscData != nullptr);
  1998. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %f)", index, value);
  1999. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  2000. {
  2001. char targetPath[std::strlen(kData->oscData->path)+26];
  2002. std::strcpy(targetPath, kData->oscData->path);
  2003. std::strcat(targetPath, "/bridge_set_default_value");
  2004. lo_send(kData->oscData->target, targetPath, "if", index, value);
  2005. }
  2006. }
  2007. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  2008. {
  2009. CARLA_ASSERT(kData->oscData != nullptr);
  2010. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  2011. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  2012. {
  2013. char targetPath[std::strlen(kData->oscData->path)+20];
  2014. std::strcpy(targetPath, kData->oscData->path);
  2015. std::strcat(targetPath, "/bridge_set_program");
  2016. lo_send(kData->oscData->target, targetPath, "i", index);
  2017. }
  2018. }
  2019. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  2020. {
  2021. CARLA_ASSERT(kData->oscData != nullptr);
  2022. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  2023. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  2024. {
  2025. char targetPath[std::strlen(kData->oscData->path)+25];
  2026. std::strcpy(targetPath, kData->oscData->path);
  2027. std::strcat(targetPath, "/bridge_set_midi_program");
  2028. lo_send(kData->oscData->target, targetPath, "i", index);
  2029. }
  2030. }
  2031. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  2032. {
  2033. CARLA_ASSERT(kData->oscData != nullptr);
  2034. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  2035. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  2036. {
  2037. char targetPath[std::strlen(kData->oscData->path)+24];
  2038. std::strcpy(targetPath, kData->oscData->path);
  2039. std::strcat(targetPath, "/bridge_set_custom_data");
  2040. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  2041. }
  2042. }
  2043. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  2044. {
  2045. CARLA_ASSERT(kData->oscData != nullptr);
  2046. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  2047. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  2048. {
  2049. char targetPath[std::strlen(kData->oscData->path)+23];
  2050. std::strcpy(targetPath, kData->oscData->path);
  2051. std::strcat(targetPath, "/bridge_set_chunk_data");
  2052. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  2053. }
  2054. }
  2055. #endif
  2056. CARLA_BACKEND_END_NAMESPACE