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.

2456 lines
85KB

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