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.

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