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.

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