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.

2436 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->curPluginCount != 0, "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. pData->thread.stopThread(500);
  646. const bool lockWait(isRunning());
  647. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait);
  648. for (unsigned int i=0; i < pData->maxPluginNumber; ++i)
  649. {
  650. EnginePluginData& pluginData(pData->plugins[i]);
  651. if (pluginData.plugin != nullptr)
  652. {
  653. delete pluginData.plugin;
  654. pluginData.plugin = nullptr;
  655. }
  656. pluginData.insPeak[0] = 0.0f;
  657. pluginData.insPeak[1] = 0.0f;
  658. pluginData.outsPeak[0] = 0.0f;
  659. pluginData.outsPeak[1] = 0.0f;
  660. }
  661. if (isRunning() && ! pData->aboutToClose)
  662. pData->thread.startThread();
  663. return true;
  664. }
  665. const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
  666. {
  667. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #21)");
  668. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #22)");
  669. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #23)");
  670. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #2)");
  671. CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name");
  672. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  673. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  674. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin != nullptr, "Could not find plugin to rename");
  675. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin->getId() == id, "Invalid engine internal data (err #24)");
  676. if (const char* const name = getUniquePluginName(newName))
  677. {
  678. plugin->setName(name);
  679. return name;
  680. }
  681. setLastError("Unable to get new unique plugin name");
  682. return nullptr;
  683. }
  684. bool CarlaEngine::clonePlugin(const unsigned int id)
  685. {
  686. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #25)");
  687. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #26)");
  688. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #27)");
  689. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #3)");
  690. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  691. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  692. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to clone");
  693. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #28)");
  694. char label[STR_MAX+1];
  695. carla_zeroChar(label, STR_MAX+1);
  696. plugin->getLabel(label);
  697. const unsigned int pluginCountBefore(pData->curPluginCount);
  698. if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getExtraStuff()))
  699. return false;
  700. CARLA_ASSERT(pluginCountBefore+1 == pData->curPluginCount);
  701. if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
  702. newPlugin->loadSaveState(plugin->getSaveState());
  703. return true;
  704. }
  705. bool CarlaEngine::replacePlugin(const unsigned int id)
  706. {
  707. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #29)");
  708. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)");
  709. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)");
  710. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #4)");
  711. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  712. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  713. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to replace");
  714. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #32)");
  715. pData->nextPluginId = id;
  716. return true;
  717. }
  718. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  719. {
  720. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #33)");
  721. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount >= 2, "Invalid engine internal data (err #34)");
  722. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #35)");
  723. CARLA_SAFE_ASSERT_RETURN_ERR(idA != idB, "Invalid operation, cannot switch plugin with itself");
  724. CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id (err #5)");
  725. CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id (err #6)");
  726. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  727. CarlaPlugin* const pluginA(pData->plugins[idA].plugin);
  728. CarlaPlugin* const pluginB(pData->plugins[idB].plugin);
  729. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #1)");
  730. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #2)");
  731. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data (err #36)");
  732. CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data (err #37)");
  733. pData->thread.stopThread(500);
  734. const bool lockWait(isRunning() && fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS);
  735. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  736. #ifndef BUILD_BRIDGE // TODO
  737. //if (isOscControlRegistered())
  738. // oscSend_control_switch_plugins(idA, idB);
  739. #endif
  740. if (isRunning() && ! pData->aboutToClose)
  741. pData->thread.startThread();
  742. return true;
  743. }
  744. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id)
  745. {
  746. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #38)");
  747. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #39)");
  748. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #40)");
  749. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #7)");
  750. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, pData->curPluginCount);
  751. return pData->plugins[id].plugin;
  752. }
  753. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const noexcept
  754. {
  755. return pData->plugins[id].plugin;
  756. }
  757. const char* CarlaEngine::getUniquePluginName(const char* const name)
  758. {
  759. CARLA_SAFE_ASSERT_RETURN(pData->maxPluginNumber != 0, nullptr);
  760. CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr, nullptr);
  761. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr);
  762. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  763. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  764. static CarlaMutex m;
  765. const CarlaMutex::ScopedLocker sl(m);
  766. static CarlaString sname;
  767. sname = name;
  768. if (sname.isEmpty())
  769. {
  770. sname = "(No name)";
  771. return (const char*)sname;
  772. }
  773. if (pData->plugins == nullptr || pData->maxPluginNumber == 0)
  774. return (const char*)sname;
  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("loadFilename 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_ASSERT(pluginId < pData->curPluginCount);
  1035. CARLA_ASSERT(id-1 < 2);
  1036. if (id == 0 || id > 2)
  1037. return 0.0f;
  1038. return pData->plugins[pluginId].insPeak[id-1];
  1039. }
  1040. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  1041. {
  1042. CARLA_ASSERT(pluginId < pData->curPluginCount);
  1043. CARLA_ASSERT(id-1 < 2);
  1044. if (id == 0 || id > 2)
  1045. return 0.0f;
  1046. return pData->plugins[pluginId].outsPeak[id-1];
  1047. }
  1048. // -----------------------------------------------------------------------
  1049. // Callback
  1050. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  1051. {
  1052. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  1053. if (pData->callback != nullptr)
  1054. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1055. }
  1056. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  1057. {
  1058. CARLA_ASSERT(func != nullptr);
  1059. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1060. pData->callback = func;
  1061. pData->callbackPtr = ptr;
  1062. }
  1063. // -----------------------------------------------------------------------
  1064. // Patchbay
  1065. bool CarlaEngine::patchbayConnect(int, int)
  1066. {
  1067. setLastError("Unsupported operation");
  1068. return false;
  1069. }
  1070. bool CarlaEngine::patchbayDisconnect(int)
  1071. {
  1072. setLastError("Unsupported operation");
  1073. return false;
  1074. }
  1075. void CarlaEngine::patchbayRefresh()
  1076. {
  1077. // nothing
  1078. }
  1079. // -----------------------------------------------------------------------
  1080. // Transport
  1081. void CarlaEngine::transportPlay()
  1082. {
  1083. pData->time.playing = true;
  1084. }
  1085. void CarlaEngine::transportPause()
  1086. {
  1087. pData->time.playing = false;
  1088. }
  1089. void CarlaEngine::transportRelocate(const uint32_t frame)
  1090. {
  1091. pData->time.frame = frame;
  1092. }
  1093. // -----------------------------------------------------------------------
  1094. // Error handling
  1095. const char* CarlaEngine::getLastError() const noexcept
  1096. {
  1097. return (const char*)pData->lastError;
  1098. }
  1099. void CarlaEngine::setLastError(const char* const error)
  1100. {
  1101. pData->lastError = error;
  1102. }
  1103. void CarlaEngine::setAboutToClose()
  1104. {
  1105. carla_debug("CarlaEngine::setAboutToClose()");
  1106. pData->aboutToClose = true;
  1107. }
  1108. // -----------------------------------------------------------------------
  1109. // Global options
  1110. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  1111. {
  1112. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  1113. #ifndef BUILD_BRIDGE
  1114. if (option >= OPTION_PROCESS_MODE && option < OPTION_PATH_RESOURCES && isRunning())
  1115. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  1116. #endif
  1117. switch (option)
  1118. {
  1119. case OPTION_PROCESS_NAME:
  1120. break;
  1121. case OPTION_PROCESS_MODE:
  1122. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_PATCHBAY)
  1123. return carla_stderr("CarlaEngine::setOption(OPTION_PROCESS_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1124. fOptions.processMode = static_cast<ProcessMode>(value);
  1125. break;
  1126. case OPTION_TRANSPORT_MODE:
  1127. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_JACK)
  1128. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1129. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  1130. break;
  1131. case OPTION_FORCE_STEREO:
  1132. fOptions.forceStereo = (value != 0);
  1133. break;
  1134. case OPTION_PREFER_PLUGIN_BRIDGES:
  1135. fOptions.preferPluginBridges = (value != 0);
  1136. break;
  1137. case OPTION_PREFER_UI_BRIDGES:
  1138. fOptions.preferUiBridges = (value != 0);
  1139. break;
  1140. case OPTION_UIS_ALWAYS_ON_TOP:
  1141. fOptions.uisAlwaysOnTop = (value != 0);
  1142. break;
  1143. case OPTION_MAX_PARAMETERS:
  1144. if (value < 1)
  1145. return carla_stderr2("carla_set_engine_option(OPTION_MAX_PARAMETERS, %i, \"%s\") - invalid value", value, valueStr);
  1146. fOptions.maxParameters = static_cast<uint>(value);
  1147. break;
  1148. case OPTION_UI_BRIDGES_TIMEOUT:
  1149. if (value < 1)
  1150. return carla_stderr2("carla_set_engine_option(OPTION_UI_BRIDGES_TIMEOUT, %i, \"%s\") - invalid value", value, valueStr);
  1151. fOptions.uiBridgesTimeout = static_cast<uint>(value);
  1152. break;
  1153. case OPTION_AUDIO_NUM_PERIODS:
  1154. if (value < 2 || value > 3)
  1155. return carla_stderr2("carla_set_engine_option(OPTION_AUDIO_NUM_PERIODS, %i, \"%s\") - invalid value", value, valueStr);
  1156. fOptions.audioNumPeriods = static_cast<uint>(value);
  1157. break;
  1158. case OPTION_AUDIO_BUFFER_SIZE:
  1159. if (value < 8)
  1160. return carla_stderr2("carla_set_engine_option(OPTION_AUDIO_BUFFER_SIZE, %i, \"%s\") - invalid value", value, valueStr);
  1161. fOptions.audioBufferSize = static_cast<uint>(value);
  1162. break;
  1163. case OPTION_AUDIO_SAMPLE_RATE:
  1164. if (value < 22050)
  1165. return carla_stderr2("carla_set_engine_option(OPTION_AUDIO_SAMPLE_RATE, %i, \"%s\") - invalid value", value, valueStr);
  1166. fOptions.audioSampleRate = static_cast<uint>(value);
  1167. break;
  1168. case OPTION_AUDIO_DEVICE:
  1169. fOptions.audioDevice = valueStr;
  1170. break;
  1171. case OPTION_PATH_RESOURCES:
  1172. fOptions.resourceDir = valueStr;
  1173. break;
  1174. #ifndef BUILD_BRIDGE
  1175. case OPTION_PATH_BRIDGE_NATIVE:
  1176. fOptions.bridge_native = valueStr;
  1177. break;
  1178. case OPTION_PATH_BRIDGE_POSIX32:
  1179. fOptions.bridge_posix32 = valueStr;
  1180. break;
  1181. case OPTION_PATH_BRIDGE_POSIX64:
  1182. fOptions.bridge_posix64 = valueStr;
  1183. break;
  1184. case OPTION_PATH_BRIDGE_WIN32:
  1185. fOptions.bridge_win32 = valueStr;
  1186. break;
  1187. case OPTION_PATH_BRIDGE_WIN64:
  1188. fOptions.bridge_win64 = valueStr;
  1189. break;
  1190. #endif
  1191. #ifdef WANT_LV2
  1192. case OPTION_PATH_BRIDGE_LV2_EXTERNAL:
  1193. fOptions.bridge_lv2Extrn = valueStr;
  1194. break;
  1195. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1196. fOptions.bridge_lv2Gtk2 = valueStr;
  1197. break;
  1198. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1199. fOptions.bridge_lv2Gtk3 = valueStr;
  1200. break;
  1201. case OPTION_PATH_BRIDGE_LV2_QT4:
  1202. fOptions.bridge_lv2Qt4 = valueStr;
  1203. break;
  1204. case OPTION_PATH_BRIDGE_LV2_QT5:
  1205. fOptions.bridge_lv2Qt5 = valueStr;
  1206. break;
  1207. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1208. fOptions.bridge_lv2Cocoa = valueStr;
  1209. break;
  1210. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1211. fOptions.bridge_lv2Win = valueStr;
  1212. break;
  1213. case OPTION_PATH_BRIDGE_LV2_X11:
  1214. fOptions.bridge_lv2X11 = valueStr;
  1215. break;
  1216. #endif
  1217. #ifdef WANT_VST
  1218. case OPTION_PATH_BRIDGE_VST_MAC:
  1219. fOptions.bridge_vstMac = valueStr;
  1220. break;
  1221. case OPTION_PATH_BRIDGE_VST_HWND:
  1222. fOptions.bridge_vstHWND = valueStr;
  1223. break;
  1224. case OPTION_PATH_BRIDGE_VST_X11:
  1225. fOptions.bridge_vstX11 = valueStr;
  1226. break;
  1227. #endif
  1228. }
  1229. }
  1230. // -----------------------------------------------------------------------
  1231. // OSC Stuff
  1232. #ifdef BUILD_BRIDGE
  1233. bool CarlaEngine::isOscBridgeRegistered() const noexcept
  1234. {
  1235. return (pData->oscData != nullptr);
  1236. }
  1237. #else
  1238. bool CarlaEngine::isOscControlRegistered() const noexcept
  1239. {
  1240. return pData->osc.isControlRegistered();
  1241. }
  1242. #endif
  1243. void CarlaEngine::idleOsc()
  1244. {
  1245. pData->osc.idle();
  1246. }
  1247. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1248. {
  1249. return pData->osc.getServerPathTCP();
  1250. }
  1251. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1252. {
  1253. return pData->osc.getServerPathUDP();
  1254. }
  1255. #ifdef BUILD_BRIDGE
  1256. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) noexcept
  1257. {
  1258. pData->oscData = oscData;
  1259. }
  1260. #endif
  1261. // -----------------------------------------------------------------------
  1262. // protected calls
  1263. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1264. {
  1265. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1266. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1267. {
  1268. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1269. if (plugin != nullptr && plugin->isEnabled())
  1270. plugin->bufferSizeChanged(newBufferSize);
  1271. }
  1272. callback(CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1273. }
  1274. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1275. {
  1276. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1277. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1278. {
  1279. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1280. if (plugin != nullptr && plugin->isEnabled())
  1281. plugin->sampleRateChanged(newSampleRate);
  1282. }
  1283. callback(CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, newSampleRate, nullptr);
  1284. }
  1285. void CarlaEngine::offlineModeChanged(const bool isOffline)
  1286. {
  1287. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOffline));
  1288. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1289. {
  1290. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1291. if (plugin != nullptr && plugin->isEnabled())
  1292. plugin->offlineModeChanged(isOffline);
  1293. }
  1294. }
  1295. void CarlaEngine::runPendingRtEvents()
  1296. {
  1297. pData->doNextPluginAction(true);
  1298. if (pData->time.playing)
  1299. pData->time.frame += fBufferSize;
  1300. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1301. {
  1302. fTimeInfo.playing = pData->time.playing;
  1303. fTimeInfo.frame = pData->time.frame;
  1304. }
  1305. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1306. {
  1307. // TODO - peak values?
  1308. }
  1309. }
  1310. void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1311. {
  1312. pData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1313. pData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1314. pData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1315. pData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1316. }
  1317. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1318. {
  1319. return isInput ? pData->bufEvents.in : pData->bufEvents.out;
  1320. }
  1321. void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin)
  1322. {
  1323. CARLA_ASSERT(id == pData->curPluginCount);
  1324. if (id == pData->curPluginCount)
  1325. pData->plugins[id].plugin = plugin;
  1326. }
  1327. #ifndef BUILD_BRIDGE
  1328. void setValueIfHigher(float& value, const float& compare)
  1329. {
  1330. if (value < compare)
  1331. value = compare;
  1332. }
  1333. void CarlaEngine::processRack(float* inBufReal[2], float* outBuf[2], const uint32_t frames)
  1334. {
  1335. CARLA_ASSERT(pData->bufEvents.in != nullptr);
  1336. CARLA_ASSERT(pData->bufEvents.out != nullptr);
  1337. // safe copy
  1338. float inBuf0[frames];
  1339. float inBuf1[frames];
  1340. float* inBuf[2] = { inBuf0, inBuf1 };
  1341. // initialize inputs
  1342. FloatVectorOperations::copy(inBuf0, inBufReal[0], frames);
  1343. FloatVectorOperations::copy(inBuf1, inBufReal[1], frames);
  1344. // initialize outputs (zero)
  1345. FloatVectorOperations::clear(outBuf[0], frames);
  1346. FloatVectorOperations::clear(outBuf[1], frames);
  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 inputs (from previous outputs)
  1360. FloatVectorOperations::copy(inBuf0, outBuf[0], frames);
  1361. FloatVectorOperations::copy(inBuf1, outBuf[1], frames);
  1362. // initialize 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 != CarlaBackend::kEngineEventTypeNull)
  1367. {
  1368. if (pData->bufEvents.out[0].type != CarlaBackend::kEngineEventTypeNull)
  1369. {
  1370. // TODO: carefully add to input, sorted events
  1371. }
  1372. // else nothing needed
  1373. }
  1374. else
  1375. {
  1376. // initialize input from previous output and zero output
  1377. std::memcpy(pData->bufEvents.in, pData->bufEvents.out, sizeof(EngineEvent)*kEngineMaxInternalEventCount);
  1378. std::memset(pData->bufEvents.out, 0, sizeof(EngineEvent)*kEngineMaxInternalEventCount);
  1379. }
  1380. }
  1381. oldAudioInCount = plugin->getAudioInCount();
  1382. oldMidiOutCount = plugin->getMidiOutCount();
  1383. // process
  1384. plugin->initBuffers();
  1385. plugin->process(inBuf, outBuf, frames);
  1386. plugin->unlock();
  1387. // if plugin has no audio inputs, add input buffer
  1388. if (oldAudioInCount == 0)
  1389. {
  1390. FloatVectorOperations::add(outBuf[0], inBuf0, frames);
  1391. FloatVectorOperations::add(outBuf[1], inBuf1, frames);
  1392. }
  1393. // set peaks
  1394. {
  1395. float inPeak1 = 0.0f;
  1396. float inPeak2 = 0.0f;
  1397. float outPeak1 = 0.0f;
  1398. float outPeak2 = 0.0f;
  1399. for (uint32_t k=0; k < frames; ++k)
  1400. {
  1401. setValueIfHigher(inPeak1, std::fabs(inBuf0[k]));
  1402. setValueIfHigher(inPeak2, std::fabs(inBuf1[k]));
  1403. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1404. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1405. }
  1406. pData->plugins[i].insPeak[0] = inPeak1;
  1407. pData->plugins[i].insPeak[1] = inPeak2;
  1408. pData->plugins[i].outsPeak[0] = outPeak1;
  1409. pData->plugins[i].outsPeak[1] = outPeak2;
  1410. }
  1411. processed = true;
  1412. }
  1413. }
  1414. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1415. {
  1416. // TODO
  1417. return;
  1418. // unused, for now
  1419. (void)inBuf;
  1420. (void)outBuf;
  1421. (void)bufCount;
  1422. (void)frames;
  1423. }
  1424. #endif
  1425. // -----------------------------------------------------------------------
  1426. // Carla Engine OSC stuff
  1427. #ifndef BUILD_BRIDGE
  1428. void CarlaEngine::oscSend_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1429. {
  1430. CARLA_ASSERT(pData->oscData != nullptr);
  1431. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1432. CARLA_ASSERT(pluginName != nullptr);
  1433. carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1434. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1435. {
  1436. char targetPath[std::strlen(pData->oscData->path)+18];
  1437. std::strcpy(targetPath, pData->oscData->path);
  1438. std::strcat(targetPath, "/add_plugin_start");
  1439. lo_send(pData->oscData->target, targetPath, "is", pluginId, pluginName);
  1440. }
  1441. }
  1442. void CarlaEngine::oscSend_control_add_plugin_end(const int32_t pluginId)
  1443. {
  1444. CARLA_ASSERT(pData->oscData != nullptr);
  1445. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1446. carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
  1447. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1448. {
  1449. char targetPath[std::strlen(pData->oscData->path)+16];
  1450. std::strcpy(targetPath, pData->oscData->path);
  1451. std::strcat(targetPath, "/add_plugin_end");
  1452. lo_send(pData->oscData->target, targetPath, "i", pluginId);
  1453. }
  1454. }
  1455. void CarlaEngine::oscSend_control_remove_plugin(const int32_t pluginId)
  1456. {
  1457. CARLA_ASSERT(pData->oscData != nullptr);
  1458. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->curPluginCount));
  1459. carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
  1460. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1461. {
  1462. char targetPath[std::strlen(pData->oscData->path)+15];
  1463. std::strcpy(targetPath, pData->oscData->path);
  1464. std::strcat(targetPath, "/remove_plugin");
  1465. lo_send(pData->oscData->target, targetPath, "i", pluginId);
  1466. }
  1467. }
  1468. 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)
  1469. {
  1470. CARLA_ASSERT(pData->oscData != nullptr);
  1471. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1472. CARLA_ASSERT(type != PLUGIN_NONE);
  1473. CARLA_ASSERT(realName != nullptr);
  1474. CARLA_ASSERT(label != nullptr);
  1475. CARLA_ASSERT(maker != nullptr);
  1476. CARLA_ASSERT(copyright != nullptr);
  1477. 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);
  1478. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1479. {
  1480. char targetPath[std::strlen(pData->oscData->path)+17];
  1481. std::strcpy(targetPath, pData->oscData->path);
  1482. std::strcat(targetPath, "/set_plugin_data");
  1483. lo_send(pData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1484. }
  1485. }
  1486. 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)
  1487. {
  1488. CARLA_ASSERT(pData->oscData != nullptr);
  1489. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1490. carla_debug("CarlaEngine::oscSend_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1491. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1492. {
  1493. char targetPath[std::strlen(pData->oscData->path)+18];
  1494. std::strcpy(targetPath, pData->oscData->path);
  1495. std::strcat(targetPath, "/set_plugin_ports");
  1496. lo_send(pData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1497. }
  1498. }
  1499. 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)
  1500. {
  1501. CARLA_ASSERT(pData->oscData != nullptr);
  1502. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1503. CARLA_ASSERT(index >= 0);
  1504. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1505. CARLA_ASSERT(name != nullptr);
  1506. CARLA_ASSERT(label != nullptr);
  1507. carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %f)", pluginId, index, type, hints, name, label, current);
  1508. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1509. {
  1510. char targetPath[std::strlen(pData->oscData->path)+20];
  1511. std::strcpy(targetPath, pData->oscData->path);
  1512. std::strcat(targetPath, "/set_parameter_data");
  1513. lo_send(pData->oscData->target, targetPath, "iiiissf", pluginId, index, type, hints, name, label, current);
  1514. }
  1515. }
  1516. 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)
  1517. {
  1518. CARLA_ASSERT(pData->oscData != nullptr);
  1519. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1520. CARLA_ASSERT(index >= 0);
  1521. CARLA_ASSERT(min < max);
  1522. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges(%i, %i, %f, %f, %f, %f, %f, %f)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1523. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1524. {
  1525. char targetPath[std::strlen(pData->oscData->path)+22];
  1526. std::strcpy(targetPath, pData->oscData->path);
  1527. std::strcat(targetPath, "/set_parameter_ranges");
  1528. lo_send(pData->oscData->target, targetPath, "iiffffff", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1529. }
  1530. }
  1531. void CarlaEngine::oscSend_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1532. {
  1533. CARLA_ASSERT(pData->oscData != nullptr);
  1534. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1535. CARLA_ASSERT(index >= 0);
  1536. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1537. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1538. {
  1539. char targetPath[std::strlen(pData->oscData->path)+23];
  1540. std::strcpy(targetPath, pData->oscData->path);
  1541. std::strcat(targetPath, "/set_parameter_midi_cc");
  1542. lo_send(pData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1543. }
  1544. }
  1545. void CarlaEngine::oscSend_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1546. {
  1547. CARLA_ASSERT(pData->oscData != nullptr);
  1548. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1549. CARLA_ASSERT(index >= 0);
  1550. CARLA_ASSERT(channel >= 0 && channel < 16);
  1551. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1552. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1553. {
  1554. char targetPath[std::strlen(pData->oscData->path)+28];
  1555. std::strcpy(targetPath, pData->oscData->path);
  1556. std::strcat(targetPath, "/set_parameter_midi_channel");
  1557. lo_send(pData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1558. }
  1559. }
  1560. void CarlaEngine::oscSend_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1561. {
  1562. CARLA_ASSERT(pData->oscData != nullptr);
  1563. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1564. #if DEBUG
  1565. if (index < 0)
  1566. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %s, %f)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1567. else
  1568. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i, %f)", pluginId, index, value);
  1569. #endif
  1570. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1571. {
  1572. char targetPath[std::strlen(pData->oscData->path)+21];
  1573. std::strcpy(targetPath, pData->oscData->path);
  1574. std::strcat(targetPath, "/set_parameter_value");
  1575. lo_send(pData->oscData->target, targetPath, "iif", pluginId, index, value);
  1576. }
  1577. }
  1578. void CarlaEngine::oscSend_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1579. {
  1580. CARLA_ASSERT(pData->oscData != nullptr);
  1581. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1582. CARLA_ASSERT(index >= 0);
  1583. carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  1584. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1585. {
  1586. char targetPath[std::strlen(pData->oscData->path)+19];
  1587. std::strcpy(targetPath, pData->oscData->path);
  1588. std::strcat(targetPath, "/set_default_value");
  1589. lo_send(pData->oscData->target, targetPath, "iif", pluginId, index, value);
  1590. }
  1591. }
  1592. void CarlaEngine::oscSend_control_set_program(const int32_t pluginId, const int32_t index)
  1593. {
  1594. CARLA_ASSERT(pData->oscData != nullptr);
  1595. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1596. carla_debug("CarlaEngine::oscSend_control_set_program(%i, %i)", pluginId, index);
  1597. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1598. {
  1599. char targetPath[std::strlen(pData->oscData->path)+13];
  1600. std::strcpy(targetPath, pData->oscData->path);
  1601. std::strcat(targetPath, "/set_program");
  1602. lo_send(pData->oscData->target, targetPath, "ii", pluginId, index);
  1603. }
  1604. }
  1605. void CarlaEngine::oscSend_control_set_program_count(const int32_t pluginId, const int32_t count)
  1606. {
  1607. CARLA_ASSERT(pData->oscData != nullptr);
  1608. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1609. CARLA_ASSERT(count >= 0);
  1610. carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
  1611. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1612. {
  1613. char targetPath[std::strlen(pData->oscData->path)+19];
  1614. std::strcpy(targetPath, pData->oscData->path);
  1615. std::strcat(targetPath, "/set_program_count");
  1616. lo_send(pData->oscData->target, targetPath, "ii", pluginId, count);
  1617. }
  1618. }
  1619. void CarlaEngine::oscSend_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1620. {
  1621. CARLA_ASSERT(pData->oscData != nullptr);
  1622. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1623. CARLA_ASSERT(index >= 0);
  1624. CARLA_ASSERT(name != nullptr);
  1625. carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1626. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1627. {
  1628. char targetPath[std::strlen(pData->oscData->path)+18];
  1629. std::strcpy(targetPath, pData->oscData->path);
  1630. std::strcat(targetPath, "/set_program_name");
  1631. lo_send(pData->oscData->target, targetPath, "iis", pluginId, index, name);
  1632. }
  1633. }
  1634. void CarlaEngine::oscSend_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1635. {
  1636. CARLA_ASSERT(pData->oscData != nullptr);
  1637. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1638. carla_debug("CarlaEngine::oscSend_control_set_midi_program(%i, %i)", pluginId, index);
  1639. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1640. {
  1641. char targetPath[std::strlen(pData->oscData->path)+18];
  1642. std::strcpy(targetPath, pData->oscData->path);
  1643. std::strcat(targetPath, "/set_midi_program");
  1644. lo_send(pData->oscData->target, targetPath, "ii", pluginId, index);
  1645. }
  1646. }
  1647. void CarlaEngine::oscSend_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1648. {
  1649. CARLA_ASSERT(pData->oscData != nullptr);
  1650. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1651. CARLA_ASSERT(count >= 0);
  1652. carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
  1653. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1654. {
  1655. char targetPath[std::strlen(pData->oscData->path)+24];
  1656. std::strcpy(targetPath, pData->oscData->path);
  1657. std::strcat(targetPath, "/set_midi_program_count");
  1658. lo_send(pData->oscData->target, targetPath, "ii", pluginId, count);
  1659. }
  1660. }
  1661. 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)
  1662. {
  1663. CARLA_ASSERT(pData->oscData != nullptr);
  1664. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->maxPluginNumber));
  1665. CARLA_ASSERT(index >= 0);
  1666. CARLA_ASSERT(bank >= 0);
  1667. CARLA_ASSERT(program >= 0);
  1668. CARLA_ASSERT(name != nullptr);
  1669. carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1670. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1671. {
  1672. char targetPath[std::strlen(pData->oscData->path)+23];
  1673. std::strcpy(targetPath, pData->oscData->path);
  1674. std::strcat(targetPath, "/set_midi_program_data");
  1675. lo_send(pData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1676. }
  1677. }
  1678. void CarlaEngine::oscSend_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1679. {
  1680. CARLA_ASSERT(pData->oscData != nullptr);
  1681. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->curPluginCount));
  1682. CARLA_ASSERT(channel >= 0 && channel < MAX_MIDI_CHANNELS);
  1683. CARLA_ASSERT(note >= 0 && note < MAX_MIDI_NOTE);
  1684. CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE);
  1685. carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1686. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1687. {
  1688. char targetPath[std::strlen(pData->oscData->path)+9];
  1689. std::strcpy(targetPath, pData->oscData->path);
  1690. std::strcat(targetPath, "/note_on");
  1691. lo_send(pData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1692. }
  1693. }
  1694. void CarlaEngine::oscSend_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1695. {
  1696. CARLA_ASSERT(pData->oscData != nullptr);
  1697. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->curPluginCount));
  1698. CARLA_ASSERT(channel >= 0 && channel < MAX_MIDI_CHANNELS);
  1699. CARLA_ASSERT(note >= 0 && note < MAX_MIDI_NOTE);
  1700. carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1701. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1702. {
  1703. char targetPath[std::strlen(pData->oscData->path)+10];
  1704. std::strcpy(targetPath, pData->oscData->path);
  1705. std::strcat(targetPath, "/note_off");
  1706. lo_send(pData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1707. }
  1708. }
  1709. void CarlaEngine::oscSend_control_set_peaks(const int32_t pluginId)
  1710. {
  1711. CARLA_ASSERT(pData->oscData != nullptr);
  1712. CARLA_ASSERT(pluginId >= 0 && pluginId < static_cast<int32_t>(pData->curPluginCount));
  1713. const EnginePluginData& epData(pData->plugins[pluginId]);
  1714. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1715. {
  1716. char targetPath[std::strlen(pData->oscData->path)+22];
  1717. std::strcpy(targetPath, pData->oscData->path);
  1718. std::strcat(targetPath, "/set_peaks");
  1719. lo_send(pData->oscData->target, targetPath, "iffff", pluginId, epData.insPeak[0], epData.insPeak[1], epData.outsPeak[0], epData.outsPeak[1]);
  1720. }
  1721. }
  1722. void CarlaEngine::oscSend_control_exit()
  1723. {
  1724. CARLA_ASSERT(pData->oscData != nullptr);
  1725. carla_debug("CarlaEngine::oscSend_control_exit()");
  1726. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1727. {
  1728. char targetPath[std::strlen(pData->oscData->path)+6];
  1729. std::strcpy(targetPath, pData->oscData->path);
  1730. std::strcat(targetPath, "/exit");
  1731. lo_send(pData->oscData->target, targetPath, "");
  1732. }
  1733. }
  1734. #else
  1735. void CarlaEngine::oscSend_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1736. {
  1737. CARLA_ASSERT(pData->oscData != nullptr);
  1738. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1739. carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1740. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1741. {
  1742. char targetPath[std::strlen(pData->oscData->path)+20];
  1743. std::strcpy(targetPath, pData->oscData->path);
  1744. std::strcat(targetPath, "/bridge_audio_count");
  1745. lo_send(pData->oscData->target, targetPath, "iii", ins, outs, total);
  1746. }
  1747. }
  1748. void CarlaEngine::oscSend_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1749. {
  1750. CARLA_ASSERT(pData->oscData != nullptr);
  1751. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1752. carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1753. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1754. {
  1755. char targetPath[std::strlen(pData->oscData->path)+19];
  1756. std::strcpy(targetPath, pData->oscData->path);
  1757. std::strcat(targetPath, "/bridge_midi_count");
  1758. lo_send(pData->oscData->target, targetPath, "iii", ins, outs, total);
  1759. }
  1760. }
  1761. void CarlaEngine::oscSend_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1762. {
  1763. CARLA_ASSERT(pData->oscData != nullptr);
  1764. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1765. carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1766. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1767. {
  1768. char targetPath[std::strlen(pData->oscData->path)+24];
  1769. std::strcpy(targetPath, pData->oscData->path);
  1770. std::strcat(targetPath, "/bridge_parameter_count");
  1771. lo_send(pData->oscData->target, targetPath, "iii", ins, outs, total);
  1772. }
  1773. }
  1774. void CarlaEngine::oscSend_bridge_program_count(const int32_t count)
  1775. {
  1776. CARLA_ASSERT(pData->oscData != nullptr);
  1777. CARLA_ASSERT(count >= 0);
  1778. carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
  1779. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1780. {
  1781. char targetPath[std::strlen(pData->oscData->path)+22];
  1782. std::strcpy(targetPath, pData->oscData->path);
  1783. std::strcat(targetPath, "/bridge_program_count");
  1784. lo_send(pData->oscData->target, targetPath, "i", count);
  1785. }
  1786. }
  1787. void CarlaEngine::oscSend_bridge_midi_program_count(const int32_t count)
  1788. {
  1789. CARLA_ASSERT(pData->oscData != nullptr);
  1790. CARLA_ASSERT(count >= 0);
  1791. carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
  1792. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1793. {
  1794. char targetPath[std::strlen(pData->oscData->path)+27];
  1795. std::strcpy(targetPath, pData->oscData->path);
  1796. std::strcat(targetPath, "/bridge_midi_program_count");
  1797. lo_send(pData->oscData->target, targetPath, "i", count);
  1798. }
  1799. }
  1800. 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)
  1801. {
  1802. CARLA_ASSERT(pData->oscData != nullptr);
  1803. CARLA_ASSERT(name != nullptr);
  1804. CARLA_ASSERT(label != nullptr);
  1805. CARLA_ASSERT(maker != nullptr);
  1806. CARLA_ASSERT(copyright != nullptr);
  1807. carla_debug("CarlaEngine::oscSend_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1808. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1809. {
  1810. char targetPath[std::strlen(pData->oscData->path)+20];
  1811. std::strcpy(targetPath, pData->oscData->path);
  1812. std::strcat(targetPath, "/bridge_plugin_info");
  1813. lo_send(pData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1814. }
  1815. }
  1816. void CarlaEngine::oscSend_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1817. {
  1818. CARLA_ASSERT(pData->oscData != nullptr);
  1819. CARLA_ASSERT(name != nullptr);
  1820. CARLA_ASSERT(unit != nullptr);
  1821. carla_debug("CarlaEngine::oscSend_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1822. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1823. {
  1824. char targetPath[std::strlen(pData->oscData->path)+23];
  1825. std::strcpy(targetPath, pData->oscData->path);
  1826. std::strcat(targetPath, "/bridge_parameter_info");
  1827. lo_send(pData->oscData->target, targetPath, "iss", index, name, unit);
  1828. }
  1829. }
  1830. 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)
  1831. {
  1832. CARLA_ASSERT(pData->oscData != nullptr);
  1833. carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1834. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1835. {
  1836. char targetPath[std::strlen(pData->oscData->path)+23];
  1837. std::strcpy(targetPath, pData->oscData->path);
  1838. std::strcat(targetPath, "/bridge_parameter_data");
  1839. lo_send(pData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1840. }
  1841. }
  1842. 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)
  1843. {
  1844. CARLA_ASSERT(pData->oscData != nullptr);
  1845. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f, %f, %f, %f)", index, def, min, max, step, stepSmall, stepLarge);
  1846. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1847. {
  1848. char targetPath[std::strlen(pData->oscData->path)+25];
  1849. std::strcpy(targetPath, pData->oscData->path);
  1850. std::strcat(targetPath, "/bridge_parameter_ranges");
  1851. lo_send(pData->oscData->target, targetPath, "iffffff", index, def, min, max, step, stepSmall, stepLarge);
  1852. }
  1853. }
  1854. void CarlaEngine::oscSend_bridge_program_info(const int32_t index, const char* const name)
  1855. {
  1856. CARLA_ASSERT(pData->oscData != nullptr);
  1857. carla_debug("CarlaEngine::oscSend_bridge_program_info(%i, \"%s\")", index, name);
  1858. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1859. {
  1860. char targetPath[std::strlen(pData->oscData->path)+21];
  1861. std::strcpy(targetPath, pData->oscData->path);
  1862. std::strcat(targetPath, "/bridge_program_info");
  1863. lo_send(pData->oscData->target, targetPath, "is", index, name);
  1864. }
  1865. }
  1866. void CarlaEngine::oscSend_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1867. {
  1868. CARLA_ASSERT(pData->oscData != nullptr);
  1869. carla_debug("CarlaEngine::oscSend_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1870. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1871. {
  1872. char targetPath[std::strlen(pData->oscData->path)+26];
  1873. std::strcpy(targetPath, pData->oscData->path);
  1874. std::strcat(targetPath, "/bridge_midi_program_info");
  1875. lo_send(pData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1876. }
  1877. }
  1878. void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value)
  1879. {
  1880. CARLA_ASSERT(pData->oscData != nullptr);
  1881. CARLA_ASSERT(key != nullptr);
  1882. CARLA_ASSERT(value != nullptr);
  1883. carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
  1884. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1885. {
  1886. char targetPath[std::strlen(pData->oscData->path)+18];
  1887. std::strcpy(targetPath, pData->oscData->path);
  1888. std::strcat(targetPath, "/bridge_configure");
  1889. lo_send(pData->oscData->target, targetPath, "ss", key, value);
  1890. }
  1891. }
  1892. void CarlaEngine::oscSend_bridge_set_parameter_value(const int32_t index, const float value)
  1893. {
  1894. CARLA_ASSERT(pData->oscData != nullptr);
  1895. carla_debug("CarlaEngine::oscSend_bridge_set_parameter_value(%i, %f)", index, value);
  1896. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1897. {
  1898. char targetPath[std::strlen(pData->oscData->path)+28];
  1899. std::strcpy(targetPath, pData->oscData->path);
  1900. std::strcat(targetPath, "/bridge_set_parameter_value");
  1901. lo_send(pData->oscData->target, targetPath, "if", index, value);
  1902. }
  1903. }
  1904. void CarlaEngine::oscSend_bridge_set_default_value(const int32_t index, const float value)
  1905. {
  1906. CARLA_ASSERT(pData->oscData != nullptr);
  1907. carla_debug("CarlaEngine::oscSend_bridge_set_default_value(%i, %f)", index, value);
  1908. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1909. {
  1910. char targetPath[std::strlen(pData->oscData->path)+26];
  1911. std::strcpy(targetPath, pData->oscData->path);
  1912. std::strcat(targetPath, "/bridge_set_default_value");
  1913. lo_send(pData->oscData->target, targetPath, "if", index, value);
  1914. }
  1915. }
  1916. void CarlaEngine::oscSend_bridge_set_program(const int32_t index)
  1917. {
  1918. CARLA_ASSERT(pData->oscData != nullptr);
  1919. carla_debug("CarlaEngine::oscSend_bridge_set_program(%i)", index);
  1920. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1921. {
  1922. char targetPath[std::strlen(pData->oscData->path)+20];
  1923. std::strcpy(targetPath, pData->oscData->path);
  1924. std::strcat(targetPath, "/bridge_set_program");
  1925. lo_send(pData->oscData->target, targetPath, "i", index);
  1926. }
  1927. }
  1928. void CarlaEngine::oscSend_bridge_set_midi_program(const int32_t index)
  1929. {
  1930. CARLA_ASSERT(pData->oscData != nullptr);
  1931. carla_debug("CarlaEngine::oscSend_bridge_set_midi_program(%i)", index);
  1932. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1933. {
  1934. char targetPath[std::strlen(pData->oscData->path)+25];
  1935. std::strcpy(targetPath, pData->oscData->path);
  1936. std::strcat(targetPath, "/bridge_set_midi_program");
  1937. lo_send(pData->oscData->target, targetPath, "i", index);
  1938. }
  1939. }
  1940. void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1941. {
  1942. CARLA_ASSERT(pData->oscData != nullptr);
  1943. carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1944. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1945. {
  1946. char targetPath[std::strlen(pData->oscData->path)+24];
  1947. std::strcpy(targetPath, pData->oscData->path);
  1948. std::strcat(targetPath, "/bridge_set_custom_data");
  1949. lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
  1950. }
  1951. }
  1952. void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile)
  1953. {
  1954. CARLA_ASSERT(pData->oscData != nullptr);
  1955. carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
  1956. if (pData->oscData != nullptr && pData->oscData->target != nullptr)
  1957. {
  1958. char targetPath[std::strlen(pData->oscData->path)+23];
  1959. std::strcpy(targetPath, pData->oscData->path);
  1960. std::strcat(targetPath, "/bridge_set_chunk_data");
  1961. lo_send(pData->oscData->target, targetPath, "s", chunkFile);
  1962. }
  1963. }
  1964. #endif
  1965. // -----------------------------------------------------------------------
  1966. #undef CARLA_SAFE_ASSERT_RETURN_ERR
  1967. CARLA_BACKEND_END_NAMESPACE