Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2433 lines
79KB

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