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.

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