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.

2498 lines
79KB

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