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.

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