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.

2513 lines
79KB

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