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.

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