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.

2444 lines
77KB

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