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.

2446 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. QString baseName(fileInfo.baseName());
  912. QString extension(fileInfo.suffix().toLower());
  913. const char* const baseNameStr(baseName.toUtf8().constData());
  914. // -------------------------------------------------------------------
  915. if (extension == "carxp" || extension == "carxs")
  916. return loadProject(filename);
  917. // -------------------------------------------------------------------
  918. if (extension == "gig")
  919. return addPlugin(PLUGIN_GIG, filename, baseNameStr, baseNameStr);
  920. if (extension == "sf2")
  921. return addPlugin(PLUGIN_SF2, filename, baseNameStr, baseNameStr);
  922. if (extension == "sfz")
  923. return addPlugin(PLUGIN_SFZ, filename, baseNameStr, baseNameStr);
  924. // -------------------------------------------------------------------
  925. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  926. {
  927. #ifdef WANT_AUDIOFILE
  928. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseNameStr, "audiofile"))
  929. {
  930. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  931. plugin->setCustomData(CUSTOM_DATA_STRING, "file00", filename, true);
  932. return true;
  933. }
  934. return false;
  935. #else
  936. setLastError("This Carla build does not have Audio file support");
  937. return false;
  938. #endif
  939. }
  940. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  941. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  942. {
  943. #ifdef WANT_AUDIOFILE
  944. # ifdef HAVE_FFMPEG
  945. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseNameStr, "audiofile"))
  946. {
  947. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  948. plugin->setCustomData(CUSTOM_DATA_STRING, "file00", filename, true);
  949. return true;
  950. }
  951. return false;
  952. # else
  953. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  954. return false;
  955. # endif
  956. #else
  957. setLastError("This Carla build does not have Audio file support");
  958. return false;
  959. #endif
  960. }
  961. // -------------------------------------------------------------------
  962. if (extension == "mid" || extension == "midi")
  963. {
  964. #ifdef WANT_MIDIFILE
  965. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseNameStr, "midifile"))
  966. {
  967. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  968. plugin->setCustomData(CUSTOM_DATA_STRING, "file", filename, true);
  969. return true;
  970. }
  971. return false;
  972. #else
  973. setLastError("This Carla build does not have MIDI file support");
  974. return false;
  975. #endif
  976. }
  977. // -------------------------------------------------------------------
  978. // ZynAddSubFX
  979. if (extension == "xmz" || extension == "xiz")
  980. {
  981. #ifdef WANT_ZYNADDSUBFX
  982. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseNameStr, "zynaddsubfx"))
  983. {
  984. if (CarlaPlugin* const plugin = getPlugin(kData->curPluginCount-1))
  985. plugin->setCustomData(CUSTOM_DATA_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  986. return true;
  987. }
  988. return false;
  989. #else
  990. setLastError("This Carla build does not have ZynAddSubFX support");
  991. return false;
  992. #endif
  993. }
  994. // -------------------------------------------------------------------
  995. setLastError("Unknown file extension");
  996. return false;
  997. }
  998. bool CarlaEngine::loadProject(const char* const filename)
  999. {
  1000. CARLA_ASSERT(filename != nullptr);
  1001. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1002. QFile file(filename);
  1003. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  1004. return false;
  1005. QDomDocument xml;
  1006. xml.setContent(file.readAll());
  1007. file.close();
  1008. QDomNode xmlNode(xml.documentElement());
  1009. if (xmlNode.toElement().tagName() != "CARLA-PROJECT" && xmlNode.toElement().tagName() != "CARLA-PRESET")
  1010. {
  1011. setLastError("Not a valid Carla project or preset file");
  1012. return false;
  1013. }
  1014. const bool isPreset(xmlNode.toElement().tagName() == "CARLA-PRESET");
  1015. QDomNode node(xmlNode.firstChild());
  1016. while (! node.isNull())
  1017. {
  1018. if (isPreset || node.toElement().tagName() == "Plugin")
  1019. {
  1020. const SaveState& saveState(getSaveStateDictFromXML(isPreset ? xmlNode : node));
  1021. CARLA_ASSERT(saveState.type != nullptr);
  1022. if (saveState.type == nullptr)
  1023. continue;
  1024. const void* extraStuff = nullptr;
  1025. if (std::strcmp(saveState.type, "DSSI") == 0)
  1026. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  1027. // TODO - proper find&load plugins
  1028. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  1029. {
  1030. if (CarlaPlugin* plugin = getPlugin(kData->curPluginCount-1))
  1031. plugin->loadSaveState(saveState);
  1032. }
  1033. }
  1034. if (isPreset)
  1035. break;
  1036. node = node.nextSibling();
  1037. }
  1038. // prevent wrong leak detection on close
  1039. getSaveStateDictFromXML(QDomNode());
  1040. return true;
  1041. }
  1042. bool CarlaEngine::saveProject(const char* const filename)
  1043. {
  1044. CARLA_ASSERT(filename != nullptr);
  1045. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1046. QFile file(filename);
  1047. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1048. return false;
  1049. QTextStream out(&file);
  1050. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1051. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1052. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  1053. bool firstPlugin = true;
  1054. char strBuf[STR_MAX+1];
  1055. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1056. {
  1057. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1058. if (plugin != nullptr && plugin->enabled())
  1059. {
  1060. if (! firstPlugin)
  1061. out << "\n";
  1062. plugin->getRealName(strBuf);
  1063. if (*strBuf != 0)
  1064. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1065. out << " <Plugin>\n";
  1066. out << getXMLFromSaveState(plugin->getSaveState());
  1067. out << " </Plugin>\n";
  1068. firstPlugin = false;
  1069. }
  1070. }
  1071. out << "</CARLA-PROJECT>\n";
  1072. file.close();
  1073. return true;
  1074. }
  1075. // -----------------------------------------------------------------------
  1076. // Information (peaks)
  1077. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  1078. {
  1079. CARLA_ASSERT(pluginId < kData->curPluginCount);
  1080. CARLA_ASSERT(id-1 < MAX_PEAKS);
  1081. if (id == 0 || id > MAX_PEAKS)
  1082. return 0.0f;
  1083. return kData->plugins[pluginId].insPeak[id-1];
  1084. }
  1085. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  1086. {
  1087. CARLA_ASSERT(pluginId < kData->curPluginCount);
  1088. CARLA_ASSERT(id-1 < MAX_PEAKS);
  1089. if (id == 0 || id > MAX_PEAKS)
  1090. return 0.0f;
  1091. return kData->plugins[pluginId].outsPeak[id-1];
  1092. }
  1093. // -----------------------------------------------------------------------
  1094. // Callback
  1095. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  1096. {
  1097. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  1098. if (kData->callback)
  1099. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1100. }
  1101. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  1102. {
  1103. CARLA_ASSERT(func != nullptr);
  1104. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1105. kData->callback = func;
  1106. kData->callbackPtr = ptr;
  1107. }
  1108. // -----------------------------------------------------------------------
  1109. // Patchbay
  1110. bool CarlaEngine::patchbayConnect(int, int)
  1111. {
  1112. setLastError("Unsupported operation");
  1113. return false;
  1114. }
  1115. bool CarlaEngine::patchbayDisconnect(int)
  1116. {
  1117. setLastError("Unsupported operation");
  1118. return false;
  1119. }
  1120. void CarlaEngine::patchbayRefresh()
  1121. {
  1122. // nothing
  1123. }
  1124. // -----------------------------------------------------------------------
  1125. // Transport
  1126. void CarlaEngine::transportPlay()
  1127. {
  1128. kData->time.playing = true;
  1129. }
  1130. void CarlaEngine::transportPause()
  1131. {
  1132. kData->time.playing = false;
  1133. }
  1134. void CarlaEngine::transportRelocate(const uint32_t frame)
  1135. {
  1136. kData->time.frame = frame;
  1137. }
  1138. // -----------------------------------------------------------------------
  1139. // Error handling
  1140. const char* CarlaEngine::getLastError() const
  1141. {
  1142. return (const char*)kData->lastError;
  1143. }
  1144. void CarlaEngine::setLastError(const char* const error)
  1145. {
  1146. kData->lastError = error;
  1147. }
  1148. void CarlaEngine::setAboutToClose()
  1149. {
  1150. carla_debug("CarlaEngine::setAboutToClose()");
  1151. kData->aboutToClose = true;
  1152. }
  1153. // -----------------------------------------------------------------------
  1154. // Global options
  1155. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  1156. if (isRunning()) \
  1157. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  1158. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  1159. {
  1160. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  1161. switch (option)
  1162. {
  1163. case OPTION_PROCESS_NAME:
  1164. carla_setprocname(valueStr);
  1165. break;
  1166. case OPTION_PROCESS_MODE:
  1167. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1168. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_BRIDGE)
  1169. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  1170. fOptions.processMode = static_cast<ProcessMode>(value);
  1171. break;
  1172. case OPTION_TRANSPORT_MODE:
  1173. // FIXME: Always enable JACK transport for now
  1174. #if 0
  1175. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_BRIDGE)
  1176. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1177. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  1178. #endif
  1179. break;
  1180. case OPTION_MAX_PARAMETERS:
  1181. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1182. if (value < 0)
  1183. return; // TODO error here
  1184. fOptions.maxParameters = static_cast<uint>(value);
  1185. break;
  1186. case OPTION_PREFERRED_BUFFER_SIZE:
  1187. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1188. fOptions.preferredBufferSize = static_cast<uint>(value);
  1189. break;
  1190. case OPTION_PREFERRED_SAMPLE_RATE:
  1191. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1192. fOptions.preferredSampleRate = static_cast<uint>(value);
  1193. break;
  1194. case OPTION_FORCE_STEREO:
  1195. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1196. fOptions.forceStereo = (value != 0);
  1197. break;
  1198. #ifdef WANT_DSSI
  1199. case OPTION_USE_DSSI_VST_CHUNKS:
  1200. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1201. fOptions.useDssiVstChunks = (value != 0);
  1202. break;
  1203. #endif
  1204. case OPTION_PREFER_PLUGIN_BRIDGES:
  1205. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1206. fOptions.preferPluginBridges = (value != 0);
  1207. break;
  1208. case OPTION_PREFER_UI_BRIDGES:
  1209. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1210. fOptions.preferUiBridges = (value != 0);
  1211. break;
  1212. case OPTION_OSC_UI_TIMEOUT:
  1213. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1214. fOptions.oscUiTimeout = static_cast<uint>(value);
  1215. break;
  1216. #ifndef BUILD_BRIDGE
  1217. case OPTION_PATH_BRIDGE_NATIVE:
  1218. fOptions.bridge_native = valueStr;
  1219. break;
  1220. case OPTION_PATH_BRIDGE_POSIX32:
  1221. fOptions.bridge_posix32 = valueStr;
  1222. break;
  1223. case OPTION_PATH_BRIDGE_POSIX64:
  1224. fOptions.bridge_posix64 = valueStr;
  1225. break;
  1226. case OPTION_PATH_BRIDGE_WIN32:
  1227. fOptions.bridge_win32 = valueStr;
  1228. break;
  1229. case OPTION_PATH_BRIDGE_WIN64:
  1230. fOptions.bridge_win64 = valueStr;
  1231. break;
  1232. #endif
  1233. #ifdef WANT_LV2
  1234. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1235. fOptions.bridge_lv2Gtk2 = valueStr;
  1236. break;
  1237. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1238. fOptions.bridge_lv2Gtk3 = valueStr;
  1239. break;
  1240. case OPTION_PATH_BRIDGE_LV2_QT4:
  1241. fOptions.bridge_lv2Qt4 = valueStr;
  1242. break;
  1243. case OPTION_PATH_BRIDGE_LV2_QT5:
  1244. fOptions.bridge_lv2Qt5 = valueStr;
  1245. break;
  1246. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1247. fOptions.bridge_lv2Cocoa = valueStr;
  1248. break;
  1249. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1250. fOptions.bridge_lv2Win = valueStr;
  1251. break;
  1252. case OPTION_PATH_BRIDGE_LV2_X11:
  1253. fOptions.bridge_lv2X11 = valueStr;
  1254. break;
  1255. #endif
  1256. #ifdef WANT_VST
  1257. case OPTION_PATH_BRIDGE_VST_COCOA:
  1258. fOptions.bridge_vstCocoa = valueStr;
  1259. break;
  1260. case OPTION_PATH_BRIDGE_VST_HWND:
  1261. fOptions.bridge_vstHWND = valueStr;
  1262. break;
  1263. case OPTION_PATH_BRIDGE_VST_X11:
  1264. fOptions.bridge_vstX11 = valueStr;
  1265. break;
  1266. #endif
  1267. }
  1268. }
  1269. // -----------------------------------------------------------------------
  1270. // OSC Stuff
  1271. #ifdef BUILD_BRIDGE
  1272. bool CarlaEngine::isOscBridgeRegistered() const
  1273. {
  1274. return (kData->oscData != nullptr);
  1275. }
  1276. #else
  1277. bool CarlaEngine::isOscControlRegistered() const
  1278. {
  1279. return kData->osc.isControlRegistered();
  1280. }
  1281. #endif
  1282. void CarlaEngine::idleOsc()
  1283. {
  1284. kData->osc.idle();
  1285. }
  1286. const char* CarlaEngine::getOscServerPathTCP() const
  1287. {
  1288. return kData->osc.getServerPathTCP();
  1289. }
  1290. const char* CarlaEngine::getOscServerPathUDP() const
  1291. {
  1292. return kData->osc.getServerPathUDP();
  1293. }
  1294. #ifdef BUILD_BRIDGE
  1295. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1296. {
  1297. kData->oscData = oscData;
  1298. }
  1299. #endif
  1300. // -----------------------------------------------------------------------
  1301. // protected calls
  1302. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1303. {
  1304. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1305. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1306. {
  1307. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1308. if (plugin != nullptr && plugin->enabled())
  1309. plugin->bufferSizeChanged(newBufferSize);
  1310. }
  1311. callback(CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1312. }
  1313. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1314. {
  1315. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1316. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1317. {
  1318. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1319. if (plugin != nullptr && plugin->enabled())
  1320. plugin->sampleRateChanged(newSampleRate);
  1321. }
  1322. callback(CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, newSampleRate, nullptr);
  1323. }
  1324. void CarlaEngine::proccessPendingEvents()
  1325. {
  1326. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1327. switch (kData->nextAction.opcode)
  1328. {
  1329. case EnginePostActionNull:
  1330. break;
  1331. case EnginePostActionRemovePlugin:
  1332. doPluginRemove(kData, true);
  1333. break;
  1334. case EnginePostActionSwitchPlugins:
  1335. doPluginsSwitch(kData, true);
  1336. break;
  1337. }
  1338. if (kData->time.playing)
  1339. kData->time.frame += fBufferSize;
  1340. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1341. {
  1342. fTimeInfo.playing = kData->time.playing;
  1343. fTimeInfo.frame = kData->time.frame;
  1344. }
  1345. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1346. {
  1347. // TODO - peak values?
  1348. }
  1349. }
  1350. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS])
  1351. {
  1352. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1353. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1354. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1355. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1356. }
  1357. #ifndef BUILD_BRIDGE
  1358. EngineEvent* CarlaEngine::getRackEventBuffer(const bool isInput)
  1359. {
  1360. return isInput ? kData->rack.in : kData->rack.out;
  1361. }
  1362. void setValueIfHigher(float& value, const float& compare)
  1363. {
  1364. if (value < compare)
  1365. value = compare;
  1366. }
  1367. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1368. {
  1369. // initialize outputs (zero)
  1370. carla_zeroFloat(outBuf[0], frames);
  1371. carla_zeroFloat(outBuf[1], frames);
  1372. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1373. bool processed = false;
  1374. // process plugins
  1375. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1376. {
  1377. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1378. if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock())
  1379. continue;
  1380. if (processed)
  1381. {
  1382. // initialize inputs (from previous outputs)
  1383. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1384. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1385. std::memcpy(kData->rack.in, kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1386. // initialize outputs (zero)
  1387. carla_zeroFloat(outBuf[0], frames);
  1388. carla_zeroFloat(outBuf[1], frames);
  1389. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1390. }
  1391. // process
  1392. plugin->initBuffers();
  1393. plugin->process(inBuf, outBuf, frames);
  1394. plugin->unlock();
  1395. #if 0
  1396. // if plugin has no audio inputs, add previous buffers
  1397. if (plugin->audioInCount() == 0)
  1398. {
  1399. for (uint32_t j=0; j < frames; ++j)
  1400. {
  1401. outBuf[0][j] += inBuf[0][j];
  1402. outBuf[1][j] += inBuf[1][j];
  1403. }
  1404. }
  1405. // if plugin has no midi output, add previous events
  1406. if (plugin->midiOutCount() == 0)
  1407. {
  1408. for (uint32_t j=0, k=0; j < frames; ++j)
  1409. {
  1410. }
  1411. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1412. }
  1413. #endif
  1414. // set peaks
  1415. {
  1416. float inPeak1 = 0.0f;
  1417. float inPeak2 = 0.0f;
  1418. float outPeak1 = 0.0f;
  1419. float outPeak2 = 0.0f;
  1420. for (uint32_t k=0; k < frames; ++k)
  1421. {
  1422. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1423. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1424. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1425. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1426. }
  1427. kData->plugins[i].insPeak[0] = inPeak1;
  1428. kData->plugins[i].insPeak[1] = inPeak2;
  1429. kData->plugins[i].outsPeak[0] = outPeak1;
  1430. kData->plugins[i].outsPeak[1] = outPeak2;
  1431. }
  1432. processed = true;
  1433. }
  1434. }
  1435. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1436. {
  1437. // TODO
  1438. return;
  1439. // unused, for now
  1440. (void)inBuf;
  1441. (void)outBuf;
  1442. (void)bufCount;
  1443. (void)frames;
  1444. }
  1445. #endif
  1446. // -------------------------------------------------------------------------------------------------------------------
  1447. // Carla Engine OSC stuff
  1448. #ifndef BUILD_BRIDGE
  1449. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1450. {
  1451. CARLA_ASSERT(kData->oscData != nullptr);
  1452. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1453. CARLA_ASSERT(pluginName);
  1454. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1455. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1456. {
  1457. char targetPath[std::strlen(kData->oscData->path)+18];
  1458. std::strcpy(targetPath, kData->oscData->path);
  1459. std::strcat(targetPath, "/add_plugin_start");
  1460. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1461. }
  1462. }
  1463. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1464. {
  1465. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1466. CARLA_ASSERT(kData->oscData != nullptr);
  1467. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1468. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1469. {
  1470. char targetPath[std::strlen(kData->oscData->path)+16];
  1471. std::strcpy(targetPath, kData->oscData->path);
  1472. std::strcat(targetPath, "/add_plugin_end");
  1473. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1474. }
  1475. }
  1476. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1477. {
  1478. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1479. CARLA_ASSERT(kData->oscData != nullptr);
  1480. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1481. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1482. {
  1483. char targetPath[std::strlen(kData->oscData->path)+15];
  1484. std::strcpy(targetPath, kData->oscData->path);
  1485. std::strcat(targetPath, "/remove_plugin");
  1486. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1487. }
  1488. }
  1489. 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)
  1490. {
  1491. 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);
  1492. CARLA_ASSERT(kData->oscData != nullptr);
  1493. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1494. CARLA_ASSERT(type != PLUGIN_NONE);
  1495. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1496. {
  1497. char targetPath[std::strlen(kData->oscData->path)+17];
  1498. std::strcpy(targetPath, kData->oscData->path);
  1499. std::strcat(targetPath, "/set_plugin_data");
  1500. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1501. }
  1502. }
  1503. 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)
  1504. {
  1505. 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);
  1506. CARLA_ASSERT(kData->oscData != nullptr);
  1507. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  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, "/set_plugin_ports");
  1513. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1514. }
  1515. }
  1516. 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)
  1517. {
  1518. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1519. CARLA_ASSERT(kData->oscData != nullptr);
  1520. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1521. CARLA_ASSERT(index >= 0);
  1522. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1523. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1524. {
  1525. char targetPath[std::strlen(kData->oscData->path)+20];
  1526. std::strcpy(targetPath, kData->oscData->path);
  1527. std::strcat(targetPath, "/set_parameter_data");
  1528. lo_send(kData->oscData->target, targetPath, "iiiissd", pluginId, index, type, hints, name, label, current);
  1529. }
  1530. }
  1531. 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)
  1532. {
  1533. 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);
  1534. CARLA_ASSERT(kData->oscData != nullptr);
  1535. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1536. CARLA_ASSERT(index >= 0);
  1537. CARLA_ASSERT(min < max);
  1538. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1539. {
  1540. char targetPath[std::strlen(kData->oscData->path)+22];
  1541. std::strcpy(targetPath, kData->oscData->path);
  1542. std::strcat(targetPath, "/set_parameter_ranges");
  1543. lo_send(kData->oscData->target, targetPath, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1544. }
  1545. }
  1546. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1547. {
  1548. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1549. CARLA_ASSERT(kData->oscData != nullptr);
  1550. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1551. CARLA_ASSERT(index >= 0);
  1552. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1553. {
  1554. char targetPath[std::strlen(kData->oscData->path)+23];
  1555. std::strcpy(targetPath, kData->oscData->path);
  1556. std::strcat(targetPath, "/set_parameter_midi_cc");
  1557. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1558. }
  1559. }
  1560. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1561. {
  1562. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1563. CARLA_ASSERT(kData->oscData != nullptr);
  1564. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1565. CARLA_ASSERT(index >= 0);
  1566. CARLA_ASSERT(channel >= 0 && channel < 16);
  1567. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1568. {
  1569. char targetPath[std::strlen(kData->oscData->path)+28];
  1570. std::strcpy(targetPath, kData->oscData->path);
  1571. std::strcat(targetPath, "/set_parameter_midi_channel");
  1572. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1573. }
  1574. }
  1575. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1576. {
  1577. #if DEBUG
  1578. if (index < 0)
  1579. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1580. else
  1581. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1582. #endif
  1583. CARLA_ASSERT(kData->oscData != nullptr);
  1584. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1585. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1586. {
  1587. char targetPath[std::strlen(kData->oscData->path)+21];
  1588. std::strcpy(targetPath, kData->oscData->path);
  1589. std::strcat(targetPath, "/set_parameter_value");
  1590. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1591. }
  1592. }
  1593. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1594. {
  1595. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1596. CARLA_ASSERT(kData->oscData != nullptr);
  1597. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1598. CARLA_ASSERT(index >= 0);
  1599. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1600. {
  1601. char targetPath[std::strlen(kData->oscData->path)+19];
  1602. std::strcpy(targetPath, kData->oscData->path);
  1603. std::strcat(targetPath, "/set_default_value");
  1604. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1605. }
  1606. }
  1607. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1608. {
  1609. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1610. CARLA_ASSERT(kData->oscData != nullptr);
  1611. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1612. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1613. {
  1614. char targetPath[std::strlen(kData->oscData->path)+13];
  1615. std::strcpy(targetPath, kData->oscData->path);
  1616. std::strcat(targetPath, "/set_program");
  1617. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1618. }
  1619. }
  1620. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1621. {
  1622. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1623. CARLA_ASSERT(kData->oscData != nullptr);
  1624. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1625. CARLA_ASSERT(count >= 0);
  1626. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1627. {
  1628. char targetPath[std::strlen(kData->oscData->path)+19];
  1629. std::strcpy(targetPath, kData->oscData->path);
  1630. std::strcat(targetPath, "/set_program_count");
  1631. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1632. }
  1633. }
  1634. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1635. {
  1636. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1637. CARLA_ASSERT(kData->oscData != nullptr);
  1638. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1639. CARLA_ASSERT(index >= 0);
  1640. CARLA_ASSERT(name);
  1641. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1642. {
  1643. char targetPath[std::strlen(kData->oscData->path)+18];
  1644. std::strcpy(targetPath, kData->oscData->path);
  1645. std::strcat(targetPath, "/set_program_name");
  1646. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1647. }
  1648. }
  1649. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1650. {
  1651. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1652. CARLA_ASSERT(kData->oscData != nullptr);
  1653. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1654. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1655. {
  1656. char targetPath[std::strlen(kData->oscData->path)+18];
  1657. std::strcpy(targetPath, kData->oscData->path);
  1658. std::strcat(targetPath, "/set_midi_program");
  1659. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1660. }
  1661. }
  1662. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1663. {
  1664. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1665. CARLA_ASSERT(kData->oscData != nullptr);
  1666. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1667. CARLA_ASSERT(count >= 0);
  1668. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1669. {
  1670. char targetPath[std::strlen(kData->oscData->path)+24];
  1671. std::strcpy(targetPath, kData->oscData->path);
  1672. std::strcat(targetPath, "/set_midi_program_count");
  1673. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1674. }
  1675. }
  1676. 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)
  1677. {
  1678. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1679. CARLA_ASSERT(kData->oscData != nullptr);
  1680. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1681. CARLA_ASSERT(index >= 0);
  1682. CARLA_ASSERT(bank >= 0);
  1683. CARLA_ASSERT(program >= 0);
  1684. CARLA_ASSERT(name);
  1685. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1686. {
  1687. char targetPath[std::strlen(kData->oscData->path)+23];
  1688. std::strcpy(targetPath, kData->oscData->path);
  1689. std::strcat(targetPath, "/set_midi_program_data");
  1690. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1691. }
  1692. }
  1693. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1694. {
  1695. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1696. CARLA_ASSERT(kData->oscData != nullptr);
  1697. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1698. CARLA_ASSERT(channel >= 0 && channel < 16);
  1699. CARLA_ASSERT(note >= 0 && note < 128);
  1700. CARLA_ASSERT(velo > 0 && velo < 128);
  1701. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1702. {
  1703. char targetPath[std::strlen(kData->oscData->path)+9];
  1704. std::strcpy(targetPath, kData->oscData->path);
  1705. std::strcat(targetPath, "/note_on");
  1706. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1707. }
  1708. }
  1709. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1710. {
  1711. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1712. CARLA_ASSERT(kData->oscData != nullptr);
  1713. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1714. CARLA_ASSERT(channel >= 0 && channel < 16);
  1715. CARLA_ASSERT(note >= 0 && note < 128);
  1716. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1717. {
  1718. char targetPath[std::strlen(kData->oscData->path)+10];
  1719. std::strcpy(targetPath, kData->oscData->path);
  1720. std::strcat(targetPath, "/note_off");
  1721. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1722. }
  1723. }
  1724. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1725. {
  1726. CARLA_ASSERT(kData->oscData != nullptr);
  1727. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1728. const EnginePluginData& pData = kData->plugins[pluginId];
  1729. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1730. {
  1731. char targetPath[std::strlen(kData->oscData->path)+22];
  1732. std::strcpy(targetPath, kData->oscData->path);
  1733. std::strcat(targetPath, "/set_peaks");
  1734. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1735. }
  1736. }
  1737. void CarlaEngine::osc_send_control_exit()
  1738. {
  1739. carla_debug("CarlaEngine::osc_send_control_exit()");
  1740. CARLA_ASSERT(kData->oscData != nullptr);
  1741. if (kData->oscData && kData->oscData->target)
  1742. {
  1743. char targetPath[std::strlen(kData->oscData->path)+6];
  1744. std::strcpy(targetPath, kData->oscData->path);
  1745. std::strcat(targetPath, "/exit");
  1746. lo_send(kData->oscData->target, targetPath, "");
  1747. }
  1748. }
  1749. #else
  1750. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1751. {
  1752. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1753. CARLA_ASSERT(kData->oscData != nullptr);
  1754. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1755. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1756. {
  1757. char targetPath[std::strlen(kData->oscData->path)+20];
  1758. std::strcpy(targetPath, kData->oscData->path);
  1759. std::strcat(targetPath, "/bridge_audio_count");
  1760. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1761. }
  1762. }
  1763. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1764. {
  1765. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1766. CARLA_ASSERT(kData->oscData != nullptr);
  1767. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1768. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1769. {
  1770. char targetPath[std::strlen(kData->oscData->path)+19];
  1771. std::strcpy(targetPath, kData->oscData->path);
  1772. std::strcat(targetPath, "/bridge_midi_count");
  1773. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1774. }
  1775. }
  1776. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1777. {
  1778. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1779. CARLA_ASSERT(kData->oscData != nullptr);
  1780. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1781. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1782. {
  1783. char targetPath[std::strlen(kData->oscData->path)+24];
  1784. std::strcpy(targetPath, kData->oscData->path);
  1785. std::strcat(targetPath, "/bridge_parameter_count");
  1786. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1787. }
  1788. }
  1789. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1790. {
  1791. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1792. CARLA_ASSERT(kData->oscData != nullptr);
  1793. CARLA_ASSERT(count >= 0);
  1794. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1795. {
  1796. char targetPath[std::strlen(kData->oscData->path)+22];
  1797. std::strcpy(targetPath, kData->oscData->path);
  1798. std::strcat(targetPath, "/bridge_program_count");
  1799. lo_send(kData->oscData->target, targetPath, "i", count);
  1800. }
  1801. }
  1802. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1803. {
  1804. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1805. CARLA_ASSERT(kData->oscData != nullptr);
  1806. CARLA_ASSERT(count >= 0);
  1807. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1808. {
  1809. char targetPath[std::strlen(kData->oscData->path)+27];
  1810. std::strcpy(targetPath, kData->oscData->path);
  1811. std::strcat(targetPath, "/bridge_midi_program_count");
  1812. lo_send(kData->oscData->target, targetPath, "i", count);
  1813. }
  1814. }
  1815. 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)
  1816. {
  1817. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1818. CARLA_ASSERT(kData->oscData != nullptr);
  1819. CARLA_ASSERT(name != nullptr);
  1820. CARLA_ASSERT(label != nullptr);
  1821. CARLA_ASSERT(maker != nullptr);
  1822. CARLA_ASSERT(copyright != nullptr);
  1823. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1824. {
  1825. char targetPath[std::strlen(kData->oscData->path)+20];
  1826. std::strcpy(targetPath, kData->oscData->path);
  1827. std::strcat(targetPath, "/bridge_plugin_info");
  1828. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1829. }
  1830. }
  1831. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1832. {
  1833. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1834. CARLA_ASSERT(kData->oscData != nullptr);
  1835. CARLA_ASSERT(name != nullptr);
  1836. CARLA_ASSERT(unit != nullptr);
  1837. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1838. {
  1839. char targetPath[std::strlen(kData->oscData->path)+23];
  1840. std::strcpy(targetPath, kData->oscData->path);
  1841. std::strcat(targetPath, "/bridge_parameter_info");
  1842. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1843. }
  1844. }
  1845. 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)
  1846. {
  1847. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1848. CARLA_ASSERT(kData->oscData != nullptr);
  1849. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1850. {
  1851. char targetPath[std::strlen(kData->oscData->path)+23];
  1852. std::strcpy(targetPath, kData->oscData->path);
  1853. std::strcat(targetPath, "/bridge_parameter_data");
  1854. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1855. }
  1856. }
  1857. 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)
  1858. {
  1859. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1860. CARLA_ASSERT(kData->oscData != nullptr);
  1861. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1862. {
  1863. char targetPath[std::strlen(kData->oscData->path)+25];
  1864. std::strcpy(targetPath, kData->oscData->path);
  1865. std::strcat(targetPath, "/bridge_parameter_ranges");
  1866. lo_send(kData->oscData->target, targetPath, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1867. }
  1868. }
  1869. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1870. {
  1871. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1872. CARLA_ASSERT(kData->oscData != nullptr);
  1873. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1874. {
  1875. char targetPath[std::strlen(kData->oscData->path)+21];
  1876. std::strcpy(targetPath, kData->oscData->path);
  1877. std::strcat(targetPath, "/bridge_program_info");
  1878. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1879. }
  1880. }
  1881. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1882. {
  1883. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1884. CARLA_ASSERT(kData->oscData != nullptr);
  1885. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1886. {
  1887. char targetPath[std::strlen(kData->oscData->path)+26];
  1888. std::strcpy(targetPath, kData->oscData->path);
  1889. std::strcat(targetPath, "/bridge_midi_program_info");
  1890. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1891. }
  1892. }
  1893. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1894. {
  1895. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1896. CARLA_ASSERT(kData->oscData != nullptr);
  1897. CARLA_ASSERT(key != nullptr);
  1898. CARLA_ASSERT(value != nullptr);
  1899. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1900. {
  1901. char targetPath[std::strlen(kData->oscData->path)+18];
  1902. std::strcpy(targetPath, kData->oscData->path);
  1903. std::strcat(targetPath, "/bridge_configure");
  1904. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1905. }
  1906. }
  1907. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1908. {
  1909. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1910. CARLA_ASSERT(kData->oscData != nullptr);
  1911. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1912. {
  1913. char targetPath[std::strlen(kData->oscData->path)+28];
  1914. std::strcpy(targetPath, kData->oscData->path);
  1915. std::strcat(targetPath, "/bridge_set_parameter_value");
  1916. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1917. }
  1918. }
  1919. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1920. {
  1921. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1922. CARLA_ASSERT(kData->oscData != nullptr);
  1923. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1924. {
  1925. char targetPath[std::strlen(kData->oscData->path)+26];
  1926. std::strcpy(targetPath, kData->oscData->path);
  1927. std::strcat(targetPath, "/bridge_set_default_value");
  1928. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1929. }
  1930. }
  1931. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1932. {
  1933. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1934. CARLA_ASSERT(kData->oscData != nullptr);
  1935. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1936. {
  1937. char targetPath[std::strlen(kData->oscData->path)+20];
  1938. std::strcpy(targetPath, kData->oscData->path);
  1939. std::strcat(targetPath, "/bridge_set_program");
  1940. lo_send(kData->oscData->target, targetPath, "i", index);
  1941. }
  1942. }
  1943. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1944. {
  1945. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1946. CARLA_ASSERT(kData->oscData != nullptr);
  1947. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1948. {
  1949. char targetPath[std::strlen(kData->oscData->path)+25];
  1950. std::strcpy(targetPath, kData->oscData->path);
  1951. std::strcat(targetPath, "/bridge_set_midi_program");
  1952. lo_send(kData->oscData->target, targetPath, "i", index);
  1953. }
  1954. }
  1955. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1956. {
  1957. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1958. CARLA_ASSERT(kData->oscData != nullptr);
  1959. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1960. {
  1961. char targetPath[std::strlen(kData->oscData->path)+24];
  1962. std::strcpy(targetPath, kData->oscData->path);
  1963. std::strcat(targetPath, "/bridge_set_custom_data");
  1964. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  1965. }
  1966. }
  1967. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1968. {
  1969. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1970. CARLA_ASSERT(kData->oscData != nullptr);
  1971. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1972. {
  1973. char targetPath[std::strlen(kData->oscData->path)+23];
  1974. std::strcpy(targetPath, kData->oscData->path);
  1975. std::strcat(targetPath, "/bridge_set_chunk_data");
  1976. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  1977. }
  1978. }
  1979. #endif
  1980. CARLA_BACKEND_END_NAMESPACE