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.

2532 lines
80KB

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