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.

2513 lines
86KB

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