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.

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