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.

2422 lines
78KB

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