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.

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