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.

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