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.

2432 lines
84KB

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