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.

3054 lines
111KB

  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. * - patchbayDisconnect should return false sometimes
  26. */
  27. #include "CarlaEngineInternal.hpp"
  28. #include "CarlaBackendUtils.hpp"
  29. #include "CarlaStateUtils.hpp"
  30. #include "CarlaMIDI.h"
  31. #include <cmath>
  32. #include <QtCore/QFile>
  33. #include <QtCore/QFileInfo>
  34. #include <QtCore/QTextStream>
  35. CARLA_BACKEND_START_NAMESPACE
  36. #if 0
  37. } // Fix editor indentation
  38. #endif
  39. // -----------------------------------------------------------------------
  40. // Fallback data
  41. static const EngineEvent kFallbackEngineEvent = { kEngineEventTypeNull, 0, 0, {{ kEngineControlEventTypeNull, 0, 0.0f }} };
  42. // -----------------------------------------------------------------------
  43. void EngineControlEvent::dumpToMidiData(const uint8_t channel, uint8_t& size, uint8_t data[3]) const noexcept
  44. {
  45. switch (type)
  46. {
  47. case kEngineControlEventTypeNull:
  48. break;
  49. case kEngineControlEventTypeParameter:
  50. if (MIDI_IS_CONTROL_BANK_SELECT(param))
  51. {
  52. size = 3;
  53. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
  54. data[1] = MIDI_CONTROL_BANK_SELECT;
  55. data[2] = static_cast<uint8_t>(value);
  56. }
  57. else
  58. {
  59. size = 3;
  60. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
  61. data[1] = static_cast<uint8_t>(param);
  62. data[2] = uint8_t(value * 127.0f);
  63. }
  64. break;
  65. case kEngineControlEventTypeMidiBank:
  66. size = 3;
  67. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
  68. data[1] = MIDI_CONTROL_BANK_SELECT;
  69. data[2] = static_cast<uint8_t>(param);
  70. break;
  71. case kEngineControlEventTypeMidiProgram:
  72. size = 2;
  73. data[0] = static_cast<uint8_t>(MIDI_STATUS_PROGRAM_CHANGE + channel);
  74. data[1] = static_cast<uint8_t>(param);
  75. break;
  76. case kEngineControlEventTypeAllSoundOff:
  77. size = 2;
  78. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
  79. data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  80. break;
  81. case kEngineControlEventTypeAllNotesOff:
  82. size = 2;
  83. data[0] = static_cast<uint8_t>(MIDI_STATUS_CONTROL_CHANGE + channel);
  84. data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  85. break;
  86. }
  87. }
  88. void EngineEvent::fillFromMidiData(const uint8_t size, const uint8_t* const data)
  89. {
  90. // get channel
  91. channel = uint8_t(MIDI_GET_CHANNEL_FROM_DATA(data));
  92. // get status
  93. const uint8_t midiStatus(uint8_t(MIDI_GET_STATUS_FROM_DATA(data)));
  94. if (midiStatus == MIDI_STATUS_CONTROL_CHANGE)
  95. {
  96. type = kEngineEventTypeControl;
  97. const uint8_t midiControl(data[1]);
  98. if (MIDI_IS_CONTROL_BANK_SELECT(midiControl))
  99. {
  100. CARLA_SAFE_ASSERT_INT(size == 3, size);
  101. const uint8_t midiBank(data[2]);
  102. ctrl.type = kEngineControlEventTypeMidiBank;
  103. ctrl.param = midiBank;
  104. ctrl.value = 0.0f;
  105. }
  106. else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF)
  107. {
  108. CARLA_SAFE_ASSERT_INT(size == 2, size);
  109. ctrl.type = kEngineControlEventTypeAllSoundOff;
  110. ctrl.param = 0;
  111. ctrl.value = 0.0f;
  112. }
  113. else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF)
  114. {
  115. CARLA_SAFE_ASSERT_INT(size == 2, size);
  116. ctrl.type = kEngineControlEventTypeAllNotesOff;
  117. ctrl.param = 0;
  118. ctrl.value = 0.0f;
  119. }
  120. else
  121. {
  122. CARLA_SAFE_ASSERT_INT2(size == 3, size, midiControl);
  123. const uint8_t midiValue(data[2]);
  124. ctrl.type = kEngineControlEventTypeParameter;
  125. ctrl.param = midiControl;
  126. ctrl.value = float(midiValue)/127.0f;
  127. }
  128. }
  129. else if (midiStatus == MIDI_STATUS_PROGRAM_CHANGE)
  130. {
  131. CARLA_SAFE_ASSERT_INT2(size == 2, size, data[1]);
  132. type = kEngineEventTypeControl;
  133. const uint8_t midiProgram(data[1]);
  134. ctrl.type = kEngineControlEventTypeMidiProgram;
  135. ctrl.param = midiProgram;
  136. ctrl.value = 0.0f;
  137. }
  138. else
  139. {
  140. type = kEngineEventTypeMidi;
  141. midi.port = 0;
  142. midi.size = size;
  143. if (size > EngineMidiEvent::kDataSize)
  144. {
  145. midi.dataExt = data;
  146. std::memset(midi.data, 0, sizeof(uint8_t)*EngineMidiEvent::kDataSize);
  147. }
  148. else
  149. {
  150. midi.data[0] = midiStatus;
  151. uint8_t i=1;
  152. for (; i < midi.size; ++i)
  153. midi.data[i] = data[i];
  154. for (; i < EngineMidiEvent::kDataSize; ++i)
  155. midi.data[i] = 0;
  156. midi.dataExt = nullptr;
  157. }
  158. }
  159. }
  160. // -----------------------------------------------------------------------
  161. #ifndef BUILD_BRIDGE
  162. void CarlaEngineProtectedData::processRack(float* inBufReal[2], float* outBuf[2], const uint32_t frames, const bool isOffline)
  163. {
  164. CARLA_SAFE_ASSERT_RETURN(bufEvents.in != nullptr,);
  165. CARLA_SAFE_ASSERT_RETURN(bufEvents.out != nullptr,);
  166. // safe copy
  167. float inBuf0[frames];
  168. float inBuf1[frames];
  169. float* inBuf[2] = { inBuf0, inBuf1 };
  170. // initialize audio inputs
  171. FLOAT_COPY(inBuf0, inBufReal[0], frames);
  172. FLOAT_COPY(inBuf1, inBufReal[1], frames);
  173. // initialize audio outputs (zero)
  174. FLOAT_CLEAR(outBuf[0], frames);
  175. FLOAT_CLEAR(outBuf[1], frames);
  176. // initialize event outputs (zero)
  177. carla_zeroStruct<EngineEvent>(bufEvents.out, kEngineMaxInternalEventCount);
  178. bool processed = false;
  179. uint32_t oldAudioInCount = 0;
  180. uint32_t oldMidiOutCount = 0;
  181. // process plugins
  182. for (unsigned int i=0; i < curPluginCount; ++i)
  183. {
  184. CarlaPlugin* const plugin = plugins[i].plugin;
  185. if (plugin == nullptr || ! plugin->isEnabled() || ! plugin->tryLock(isOffline))
  186. continue;
  187. if (processed)
  188. {
  189. // initialize audio inputs (from previous outputs)
  190. FLOAT_COPY(inBuf0, outBuf[0], frames);
  191. FLOAT_COPY(inBuf1, outBuf[1], frames);
  192. // initialize audio outputs (zero)
  193. FLOAT_CLEAR(outBuf[0], frames);
  194. FLOAT_CLEAR(outBuf[1], frames);
  195. // if plugin has no midi out, add previous events
  196. if (oldMidiOutCount == 0 && bufEvents.in[0].type != kEngineEventTypeNull)
  197. {
  198. if (bufEvents.out[0].type != kEngineEventTypeNull)
  199. {
  200. // TODO: carefully add to input, sorted events
  201. }
  202. // else nothing needed
  203. }
  204. else
  205. {
  206. // initialize event inputs from previous outputs
  207. carla_copyStruct<EngineEvent>(bufEvents.in, bufEvents.out, kEngineMaxInternalEventCount);
  208. // initialize event outputs (zero)
  209. carla_zeroStruct<EngineEvent>(bufEvents.out, kEngineMaxInternalEventCount);
  210. }
  211. }
  212. oldAudioInCount = plugin->getAudioInCount();
  213. oldMidiOutCount = plugin->getMidiOutCount();
  214. // process
  215. plugin->initBuffers();
  216. plugin->process(inBuf, outBuf, frames);
  217. plugin->unlock();
  218. // if plugin has no audio inputs, add input buffer
  219. if (oldAudioInCount == 0)
  220. {
  221. FLOAT_ADD(outBuf[0], inBuf0, frames);
  222. FLOAT_ADD(outBuf[1], inBuf1, frames);
  223. }
  224. // set peaks
  225. {
  226. EnginePluginData& pluginData(plugins[i]);
  227. #ifdef HAVE_JUCE
  228. float tmpMin, tmpMax;
  229. if (oldAudioInCount > 0)
  230. {
  231. FloatVectorOperations::findMinAndMax(inBuf0, frames, tmpMin, tmpMax);
  232. pluginData.insPeak[0] = carla_max<float>(std::abs(tmpMin), std::abs(tmpMax), 1.0f);
  233. FloatVectorOperations::findMinAndMax(inBuf1, frames, tmpMin, tmpMax);
  234. pluginData.insPeak[1] = carla_max<float>(std::abs(tmpMin), std::abs(tmpMax), 1.0f);
  235. }
  236. else
  237. {
  238. pluginData.insPeak[0] = 0.0f;
  239. pluginData.insPeak[1] = 0.0f;
  240. }
  241. if (plugin->getAudioOutCount() > 0)
  242. {
  243. FloatVectorOperations::findMinAndMax(outBuf[0], frames, tmpMin, tmpMax);
  244. pluginData.outsPeak[0] = carla_max<float>(std::abs(tmpMin), std::abs(tmpMax), 1.0f);
  245. FloatVectorOperations::findMinAndMax(outBuf[1], frames, tmpMin, tmpMax);
  246. pluginData.outsPeak[1] = carla_max<float>(std::abs(tmpMin), std::abs(tmpMax), 1.0f);
  247. }
  248. else
  249. {
  250. pluginData.outsPeak[0] = 0.0f;
  251. pluginData.outsPeak[1] = 0.0f;
  252. }
  253. #else
  254. float peak1, peak2;
  255. if (oldAudioInCount > 0)
  256. {
  257. peak1 = peak2 = 0.0f;
  258. for (uint32_t k=0; k < frames; ++k)
  259. {
  260. peak1 = carla_max<float>(peak1, std::fabs(inBuf0[k]), 1.0f);
  261. peak2 = carla_max<float>(peak2, std::fabs(inBuf1[k]), 1.0f);
  262. }
  263. pluginData.insPeak[0] = peak1;
  264. pluginData.insPeak[1] = peak2;
  265. }
  266. else
  267. {
  268. pluginData.insPeak[0] = 0.0f;
  269. pluginData.insPeak[1] = 0.0f;
  270. }
  271. if (plugin->getAudioOutCount() > 0)
  272. {
  273. peak1 = peak2 = 0.0f;
  274. for (uint32_t k=0; k < frames; ++k)
  275. {
  276. peak1 = carla_max<float>(peak1, std::fabs(outBuf[0][k]), 1.0f);
  277. peak2 = carla_max<float>(peak2, std::fabs(outBuf[1][k]), 1.0f);
  278. }
  279. pluginData.outsPeak[0] = peak1;
  280. pluginData.outsPeak[1] = peak2;
  281. }
  282. else
  283. {
  284. pluginData.outsPeak[0] = 0.0f;
  285. pluginData.outsPeak[1] = 0.0f;
  286. }
  287. #endif
  288. }
  289. processed = true;
  290. }
  291. }
  292. void CarlaEngineProtectedData::processRackFull(float** const inBuf, const uint32_t inCount, float** const outBuf, const uint32_t outCount, const uint32_t nframes, const bool isOffline)
  293. {
  294. EngineRackBuffers* const rack(bufAudio.rack);
  295. const CarlaMutex::ScopedLocker sl(rack->connectLock);
  296. // connect input buffers
  297. if (rack->connectedIns[0].count() == 0)
  298. {
  299. FLOAT_CLEAR(rack->in[0], nframes);
  300. }
  301. else
  302. {
  303. bool first = true;
  304. for (LinkedList<uint>::Itenerator it = rack->connectedIns[0].begin(); it.valid(); it.next())
  305. {
  306. const uint& port(it.getValue());
  307. CARLA_SAFE_ASSERT_CONTINUE(port < inCount);
  308. if (first)
  309. {
  310. FLOAT_COPY(rack->in[0], inBuf[port], nframes);
  311. first = false;
  312. }
  313. else
  314. {
  315. FLOAT_ADD(rack->in[0], inBuf[port], nframes);
  316. }
  317. }
  318. if (first)
  319. FLOAT_CLEAR(rack->in[0], nframes);
  320. }
  321. if (rack->connectedIns[1].count() == 0)
  322. {
  323. FLOAT_CLEAR(rack->in[1], nframes);
  324. }
  325. else
  326. {
  327. bool first = true;
  328. for (LinkedList<uint>::Itenerator it = rack->connectedIns[1].begin(); it.valid(); it.next())
  329. {
  330. const uint& port(it.getValue());
  331. CARLA_SAFE_ASSERT_CONTINUE(port < inCount);
  332. if (first)
  333. {
  334. FLOAT_COPY(rack->in[1], inBuf[port], nframes);
  335. first = false;
  336. }
  337. else
  338. {
  339. FLOAT_ADD(rack->in[1], inBuf[port], nframes);
  340. }
  341. }
  342. if (first)
  343. FLOAT_CLEAR(rack->in[1], nframes);
  344. }
  345. FLOAT_CLEAR(rack->out[0], nframes);
  346. FLOAT_CLEAR(rack->out[1], nframes);
  347. // process
  348. processRack(rack->in, rack->out, nframes, isOffline);
  349. // connect output buffers
  350. if (rack->connectedOuts[0].count() != 0)
  351. {
  352. for (LinkedList<uint>::Itenerator it = rack->connectedOuts[0].begin(); it.valid(); it.next())
  353. {
  354. const uint& port(it.getValue());
  355. CARLA_SAFE_ASSERT_CONTINUE(port < outCount);
  356. FLOAT_ADD(outBuf[port], rack->out[0], nframes);
  357. }
  358. }
  359. if (rack->connectedOuts[1].count() != 0)
  360. {
  361. for (LinkedList<uint>::Itenerator it = rack->connectedOuts[1].begin(); it.valid(); it.next())
  362. {
  363. const uint& port(it.getValue());
  364. CARLA_SAFE_ASSERT_CONTINUE(port < outCount);
  365. FLOAT_ADD(outBuf[port], rack->out[1], nframes);
  366. }
  367. }
  368. }
  369. #endif
  370. // -----------------------------------------------------------------------
  371. CarlaPlugin* CarlaPlugin::newGIG(const Initializer& init, const bool use16Outs)
  372. {
  373. carla_debug("CarlaPlugin::newGIG({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, bool2str(use16Outs));
  374. #ifdef WANT_LINUXSAMPLER
  375. return newLinuxSampler(init, "GIG", use16Outs);
  376. #else
  377. init.engine->setLastError("GIG support not available");
  378. return nullptr;
  379. // unused
  380. (void)use16Outs;
  381. #endif
  382. }
  383. CarlaPlugin* CarlaPlugin::newSF2(const Initializer& init, const bool use16Outs)
  384. {
  385. carla_debug("CarlaPlugin::newSF2({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, bool2str(use16Outs));
  386. #if defined(WANT_FLUIDSYNTH)
  387. return newFluidSynth(init, use16Outs);
  388. #elif defined(WANT_LINUXSAMPLER)
  389. return newLinuxSampler(init, "SF2", use16Outs);
  390. #else
  391. init.engine->setLastError("SF2 support not available");
  392. return nullptr;
  393. // unused
  394. (void)use16Outs;
  395. #endif
  396. }
  397. CarlaPlugin* CarlaPlugin::newSFZ(const Initializer& init, const bool use16Outs)
  398. {
  399. carla_debug("CarlaPlugin::newSFZ({%p, \"%s\", \"%s\", \"%s\"}, %s)", init.engine, init.filename, init.name, init.label, bool2str(use16Outs));
  400. #ifdef WANT_LINUXSAMPLER
  401. return newLinuxSampler(init, "SFZ", use16Outs);
  402. #else
  403. init.engine->setLastError("SFZ support not available");
  404. return nullptr;
  405. // unused
  406. (void)use16Outs;
  407. #endif
  408. }
  409. // -----------------------------------------------------------------------
  410. // Carla Engine port (Abstract)
  411. CarlaEnginePort::CarlaEnginePort(const CarlaEngine& engine, const bool isInput)
  412. : fEngine(engine),
  413. fIsInput(isInput)
  414. {
  415. carla_debug("CarlaEnginePort::CarlaEnginePort(%s)", bool2str(isInput));
  416. }
  417. CarlaEnginePort::~CarlaEnginePort()
  418. {
  419. carla_debug("CarlaEnginePort::~CarlaEnginePort()");
  420. }
  421. // -----------------------------------------------------------------------
  422. // Carla Engine Audio port
  423. CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInput)
  424. : CarlaEnginePort(engine, isInput),
  425. fBuffer(nullptr)
  426. {
  427. carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInput));
  428. }
  429. CarlaEngineAudioPort::~CarlaEngineAudioPort()
  430. {
  431. carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()");
  432. }
  433. void CarlaEngineAudioPort::initBuffer()
  434. {
  435. }
  436. // -----------------------------------------------------------------------
  437. // Carla Engine CV port
  438. CarlaEngineCVPort::CarlaEngineCVPort(const CarlaEngine& engine, const bool isInput)
  439. : CarlaEnginePort(engine, isInput),
  440. fBuffer(nullptr),
  441. fProcessMode(engine.getProccessMode())
  442. {
  443. carla_debug("CarlaEngineCVPort::CarlaEngineCVPort(%s)", bool2str(isInput));
  444. if (fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
  445. fBuffer = new float[engine.getBufferSize()];
  446. }
  447. CarlaEngineCVPort::~CarlaEngineCVPort()
  448. {
  449. carla_debug("CarlaEngineCVPort::~CarlaEngineCVPort()");
  450. if (fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
  451. {
  452. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
  453. delete[] fBuffer;
  454. fBuffer = nullptr;
  455. }
  456. }
  457. void CarlaEngineCVPort::initBuffer()
  458. {
  459. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
  460. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,);
  461. FLOAT_CLEAR(fBuffer, fEngine.getBufferSize());
  462. }
  463. void CarlaEngineCVPort::setBufferSize(const uint32_t bufferSize)
  464. {
  465. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
  466. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,);
  467. delete[] fBuffer;
  468. fBuffer = new float[bufferSize];
  469. }
  470. // -----------------------------------------------------------------------
  471. // Carla Engine Event port
  472. CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool isInput)
  473. : CarlaEnginePort(engine, isInput),
  474. fBuffer(nullptr),
  475. fProcessMode(engine.getProccessMode())
  476. {
  477. carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s)", bool2str(isInput));
  478. if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY)
  479. fBuffer = new EngineEvent[kEngineMaxInternalEventCount];
  480. }
  481. CarlaEngineEventPort::~CarlaEngineEventPort()
  482. {
  483. carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()");
  484. if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY)
  485. {
  486. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,);
  487. delete[] fBuffer;
  488. fBuffer = nullptr;
  489. }
  490. }
  491. void CarlaEngineEventPort::initBuffer()
  492. {
  493. if (fProcessMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || fProcessMode == ENGINE_PROCESS_MODE_BRIDGE)
  494. fBuffer = fEngine.getInternalEventBuffer(fIsInput);
  495. else if (fProcessMode == ENGINE_PROCESS_MODE_PATCHBAY && ! fIsInput)
  496. carla_zeroStruct<EngineEvent>(fBuffer, kEngineMaxInternalEventCount);
  497. }
  498. uint32_t CarlaEngineEventPort::getEventCount() const
  499. {
  500. CARLA_SAFE_ASSERT_RETURN(fIsInput, 0);
  501. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, 0);
  502. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, 0);
  503. uint32_t i=0;
  504. for (; i < kEngineMaxInternalEventCount; ++i)
  505. {
  506. if (fBuffer[i].type == kEngineEventTypeNull)
  507. break;
  508. }
  509. return i;
  510. }
  511. const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index)
  512. {
  513. CARLA_SAFE_ASSERT_RETURN(fIsInput, kFallbackEngineEvent);
  514. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, kFallbackEngineEvent);
  515. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, kFallbackEngineEvent);
  516. CARLA_SAFE_ASSERT_RETURN(index < kEngineMaxInternalEventCount, kFallbackEngineEvent);
  517. return fBuffer[index];
  518. }
  519. const EngineEvent& CarlaEngineEventPort::getEventUnchecked(const uint32_t index)
  520. {
  521. return fBuffer[index];
  522. }
  523. bool CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const float value)
  524. {
  525. CARLA_SAFE_ASSERT_RETURN(! fIsInput, false);
  526. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, false);
  527. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, false);
  528. CARLA_SAFE_ASSERT_RETURN(type != kEngineControlEventTypeNull, false);
  529. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, false);
  530. CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f);
  531. if (type == kEngineControlEventTypeParameter) {
  532. CARLA_SAFE_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param));
  533. }
  534. const float fixedValue(carla_fixValue<float>(0.0f, 1.0f, value));
  535. for (uint32_t i=0; i < kEngineMaxInternalEventCount; ++i)
  536. {
  537. if (fBuffer[i].type != kEngineEventTypeNull)
  538. continue;
  539. EngineEvent& event(fBuffer[i]);
  540. event.type = kEngineEventTypeControl;
  541. event.time = time;
  542. event.channel = channel;
  543. event.ctrl.type = type;
  544. event.ctrl.param = param;
  545. event.ctrl.value = fixedValue;
  546. return true;
  547. }
  548. carla_stderr2("CarlaEngineEventPort::writeControlEvent() - buffer full");
  549. return false;
  550. }
  551. bool CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data)
  552. {
  553. CARLA_SAFE_ASSERT_RETURN(! fIsInput, false);
  554. CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr, false);
  555. CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS, false);
  556. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, false);
  557. CARLA_SAFE_ASSERT_RETURN(size > 0 && size <= EngineMidiEvent::kDataSize, false);
  558. CARLA_SAFE_ASSERT_RETURN(data != nullptr, false);
  559. for (uint32_t i=0; i < kEngineMaxInternalEventCount; ++i)
  560. {
  561. if (fBuffer[i].type != kEngineEventTypeNull)
  562. continue;
  563. EngineEvent& event(fBuffer[i]);
  564. event.type = kEngineEventTypeMidi;
  565. event.time = time;
  566. event.channel = channel;
  567. event.midi.port = port;
  568. event.midi.size = size;
  569. event.midi.data[0] = uint8_t(MIDI_GET_STATUS_FROM_DATA(data));
  570. uint8_t j=1;
  571. for (; j < size; ++j)
  572. event.midi.data[j] = data[j];
  573. for (; j < EngineMidiEvent::kDataSize; ++j)
  574. event.midi.data[j] = 0;
  575. return true;
  576. }
  577. carla_stderr2("CarlaEngineEventPort::writeMidiEvent() - buffer full");
  578. return false;
  579. }
  580. // -----------------------------------------------------------------------
  581. // Carla Engine client (Abstract)
  582. CarlaEngineClient::CarlaEngineClient(const CarlaEngine& engine)
  583. : fEngine(engine),
  584. fActive(false),
  585. fLatency(0)
  586. {
  587. carla_debug("CarlaEngineClient::CarlaEngineClient()");
  588. }
  589. CarlaEngineClient::~CarlaEngineClient()
  590. {
  591. CARLA_ASSERT(! fActive);
  592. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  593. }
  594. void CarlaEngineClient::activate() noexcept
  595. {
  596. CARLA_ASSERT(! fActive);
  597. carla_debug("CarlaEngineClient::activate()");
  598. fActive = true;
  599. }
  600. void CarlaEngineClient::deactivate() noexcept
  601. {
  602. CARLA_ASSERT(fActive);
  603. carla_debug("CarlaEngineClient::deactivate()");
  604. fActive = false;
  605. }
  606. bool CarlaEngineClient::isActive() const noexcept
  607. {
  608. return fActive;
  609. }
  610. bool CarlaEngineClient::isOk() const noexcept
  611. {
  612. return true;
  613. }
  614. uint32_t CarlaEngineClient::getLatency() const noexcept
  615. {
  616. return fLatency;
  617. }
  618. void CarlaEngineClient::setLatency(const uint32_t samples) noexcept
  619. {
  620. fLatency = samples;
  621. }
  622. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  623. {
  624. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  625. carla_debug("CarlaEngineClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput));
  626. switch (portType)
  627. {
  628. case kEnginePortTypeNull:
  629. break;
  630. case kEnginePortTypeAudio:
  631. return new CarlaEngineAudioPort(fEngine, isInput);
  632. case kEnginePortTypeCV:
  633. return new CarlaEngineCVPort(fEngine, isInput);
  634. case kEnginePortTypeEvent:
  635. return new CarlaEngineEventPort(fEngine, isInput);
  636. }
  637. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  638. return nullptr;
  639. }
  640. // -----------------------------------------------------------------------
  641. // Carla Engine
  642. CarlaEngine::CarlaEngine()
  643. : pData(new CarlaEngineProtectedData(this))
  644. {
  645. carla_debug("CarlaEngine::CarlaEngine()");
  646. }
  647. CarlaEngine::~CarlaEngine()
  648. {
  649. carla_debug("CarlaEngine::~CarlaEngine()");
  650. delete pData;
  651. }
  652. // -----------------------------------------------------------------------
  653. // Static calls
  654. unsigned int CarlaEngine::getDriverCount()
  655. {
  656. carla_debug("CarlaEngine::getDriverCount()");
  657. unsigned int count = 1; // JACK
  658. #ifndef BUILD_BRIDGE
  659. count += getRtAudioApiCount();
  660. # ifdef HAVE_JUCE
  661. count += getJuceApiCount();
  662. # endif
  663. #endif
  664. return count;
  665. }
  666. const char* CarlaEngine::getDriverName(const unsigned int index)
  667. {
  668. carla_debug("CarlaEngine::getDriverName(%i)", index);
  669. if (index == 0)
  670. return "JACK";
  671. #ifndef BUILD_BRIDGE
  672. const unsigned int rtAudioIndex(index-1);
  673. if (rtAudioIndex < getRtAudioApiCount())
  674. return getRtAudioApiName(rtAudioIndex);
  675. # ifdef HAVE_JUCE
  676. const unsigned int juceIndex(index-rtAudioIndex-1);
  677. if (juceIndex < getJuceApiCount())
  678. return getJuceApiName(juceIndex);
  679. # endif
  680. #endif
  681. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
  682. return nullptr;
  683. }
  684. const char* const* CarlaEngine::getDriverDeviceNames(const unsigned int index)
  685. {
  686. carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index);
  687. if (index == 0) // JACK
  688. {
  689. static const char* ret[3] = { "Auto-Connect OFF", "Auto-Connect ON", nullptr };
  690. return ret;
  691. }
  692. #ifndef BUILD_BRIDGE
  693. const unsigned int rtAudioIndex(index-1);
  694. if (rtAudioIndex < getRtAudioApiCount())
  695. return getRtAudioApiDeviceNames(rtAudioIndex);
  696. # ifdef HAVE_JUCE
  697. const unsigned int juceIndex(index-rtAudioIndex-1);
  698. if (juceIndex < getJuceApiCount())
  699. return getJuceApiDeviceNames(juceIndex);
  700. # endif
  701. #endif
  702. carla_stderr("CarlaEngine::getDriverDeviceNames(%i) - invalid index", index);
  703. return nullptr;
  704. }
  705. const EngineDriverDeviceInfo* CarlaEngine::getDriverDeviceInfo(const unsigned int index, const char* const deviceName)
  706. {
  707. carla_debug("CarlaEngine::getDriverDeviceInfo(%i, \"%s\")", index, deviceName);
  708. if (index == 0) // JACK
  709. {
  710. static uint32_t bufSizes[11] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 0 };
  711. static EngineDriverDeviceInfo devInfo;
  712. devInfo.hints = ENGINE_DRIVER_DEVICE_VARIABLE_BUFFER_SIZE;
  713. devInfo.bufferSizes = bufSizes;
  714. devInfo.sampleRates = nullptr;
  715. return &devInfo;
  716. }
  717. #ifndef BUILD_BRIDGE
  718. const unsigned int rtAudioIndex(index-1);
  719. if (rtAudioIndex < getRtAudioApiCount())
  720. return getRtAudioDeviceInfo(rtAudioIndex, deviceName);
  721. # ifdef HAVE_JUCE
  722. const unsigned int juceIndex(index-rtAudioIndex-1);
  723. if (juceIndex < getJuceApiCount())
  724. return getJuceDeviceInfo(juceIndex, deviceName);
  725. # endif
  726. #endif
  727. carla_stderr("CarlaEngine::getDriverDeviceNames(%i, \"%s\") - invalid index", index, deviceName);
  728. return nullptr;
  729. }
  730. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  731. {
  732. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', nullptr);
  733. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  734. if (std::strcmp(driverName, "JACK") == 0)
  735. return newJack();
  736. // common
  737. if (std::strncmp(driverName, "JACK ", 5) == 0)
  738. return newRtAudio(AUDIO_API_JACK);
  739. // linux
  740. #ifdef HAVE_JUCE
  741. if (std::strcmp(driverName, "ALSA") == 0)
  742. return newJuce(AUDIO_API_ALSA);
  743. #else
  744. if (std::strcmp(driverName, "ALSA") == 0)
  745. return newRtAudio(AUDIO_API_ALSA);
  746. #endif
  747. if (std::strcmp(driverName, "OSS") == 0)
  748. return newRtAudio(AUDIO_API_OSS);
  749. if (std::strcmp(driverName, "PulseAudio") == 0)
  750. return newRtAudio(AUDIO_API_PULSE);
  751. // macos
  752. #ifdef HAVE_JUCE
  753. if (std::strcmp(driverName, "CoreAudio") == 0)
  754. return newJuce(AUDIO_API_CORE);
  755. #else
  756. if (std::strcmp(driverName, "CoreAudio") == 0)
  757. return newRtAudio(AUDIO_API_CORE);
  758. #endif
  759. // windows
  760. #ifdef HAVE_JUCE
  761. if (std::strcmp(driverName, "ASIO") == 0)
  762. return newJuce(AUDIO_API_ASIO);
  763. if (std::strcmp(driverName, "DirectSound") == 0)
  764. return newJuce(AUDIO_API_DS);
  765. #else
  766. if (std::strcmp(driverName, "ASIO") == 0)
  767. return newRtAudio(AUDIO_API_ASIO);
  768. if (std::strcmp(driverName, "DirectSound") == 0)
  769. return newRtAudio(AUDIO_API_DS);
  770. #endif
  771. carla_stderr("CarlaEngine::newDriverByName(\"%s\") - invalid driver name", driverName);
  772. return nullptr;
  773. }
  774. // -----------------------------------------------------------------------
  775. // Maximum values
  776. unsigned int CarlaEngine::getMaxClientNameSize() const noexcept
  777. {
  778. return STR_MAX/2;
  779. }
  780. unsigned int CarlaEngine::getMaxPortNameSize() const noexcept
  781. {
  782. return STR_MAX;
  783. }
  784. unsigned int CarlaEngine::getCurrentPluginCount() const noexcept
  785. {
  786. return pData->curPluginCount;
  787. }
  788. unsigned int CarlaEngine::getMaxPluginNumber() const noexcept
  789. {
  790. return pData->maxPluginNumber;
  791. }
  792. // -----------------------------------------------------------------------
  793. // Virtual, per-engine type calls
  794. bool CarlaEngine::init(const char* const clientName)
  795. {
  796. CARLA_SAFE_ASSERT_RETURN_ERR(pData->name.isEmpty(), "Invalid engine internal data (err #1)");
  797. CARLA_SAFE_ASSERT_RETURN_ERR(pData->oscData == nullptr, "Invalid engine internal data (err #2)");
  798. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins == nullptr, "Invalid engine internal data (err #3)");
  799. CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.in == nullptr, "Invalid engine internal data (err #4)");
  800. CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.out == nullptr, "Invalid engine internal data (err #5)");
  801. CARLA_SAFE_ASSERT_RETURN_ERR(clientName != nullptr && clientName[0] != '\0', "Invalid client name");
  802. carla_debug("CarlaEngine::init(\"%s\")", clientName);
  803. pData->aboutToClose = false;
  804. pData->curPluginCount = 0;
  805. pData->maxPluginNumber = 0;
  806. pData->nextPluginId = 0;
  807. switch (pData->options.processMode)
  808. {
  809. case ENGINE_PROCESS_MODE_SINGLE_CLIENT:
  810. case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS:
  811. pData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
  812. break;
  813. case ENGINE_PROCESS_MODE_CONTINUOUS_RACK:
  814. pData->maxPluginNumber = MAX_RACK_PLUGINS;
  815. pData->bufEvents.in = new EngineEvent[kEngineMaxInternalEventCount];
  816. pData->bufEvents.out = new EngineEvent[kEngineMaxInternalEventCount];
  817. break;
  818. case ENGINE_PROCESS_MODE_PATCHBAY:
  819. pData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
  820. break;
  821. case ENGINE_PROCESS_MODE_BRIDGE:
  822. pData->maxPluginNumber = 1;
  823. pData->bufEvents.in = new EngineEvent[kEngineMaxInternalEventCount];
  824. pData->bufEvents.out = new EngineEvent[kEngineMaxInternalEventCount];
  825. break;
  826. }
  827. CARLA_SAFE_ASSERT_RETURN_ERR(pData->maxPluginNumber != 0, "Invalid engine process mode");
  828. pData->nextPluginId = pData->maxPluginNumber;
  829. pData->name = clientName;
  830. pData->name.toBasic();
  831. pData->timeInfo.clear();
  832. pData->plugins = new EnginePluginData[pData->maxPluginNumber];
  833. for (uint i=0; i < pData->maxPluginNumber; ++i)
  834. pData->plugins[i].clear();
  835. pData->osc.init(clientName);
  836. #ifndef BUILD_BRIDGE
  837. pData->oscData = pData->osc.getControlData();
  838. #endif
  839. pData->nextAction.ready();
  840. pData->thread.start();
  841. callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, 0, 0, 0.0f, getCurrentDriverName());
  842. return true;
  843. }
  844. bool CarlaEngine::close()
  845. {
  846. CARLA_SAFE_ASSERT_RETURN_ERR(pData->name.isNotEmpty(), "Invalid engine internal data (err #6)");
  847. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #7)");
  848. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #8)");
  849. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #9)");
  850. carla_debug("CarlaEngine::close()");
  851. pData->thread.stop(500);
  852. pData->nextAction.ready();
  853. #ifndef BUILD_BRIDGE
  854. oscSend_control_exit();
  855. #endif
  856. pData->osc.close();
  857. pData->oscData = nullptr;
  858. pData->aboutToClose = true;
  859. pData->curPluginCount = 0;
  860. pData->maxPluginNumber = 0;
  861. pData->nextPluginId = 0;
  862. if (pData->plugins != nullptr)
  863. {
  864. delete[] pData->plugins;
  865. pData->plugins = nullptr;
  866. }
  867. if (pData->bufEvents.in != nullptr)
  868. {
  869. delete[] pData->bufEvents.in;
  870. pData->bufEvents.in = nullptr;
  871. }
  872. if (pData->bufEvents.out != nullptr)
  873. {
  874. delete[] pData->bufEvents.out;
  875. pData->bufEvents.out = nullptr;
  876. }
  877. pData->name.clear();
  878. callback(ENGINE_CALLBACK_ENGINE_STOPPED, 0, 0, 0, 0.0f, nullptr);
  879. return true;
  880. }
  881. void CarlaEngine::idle()
  882. {
  883. CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull); // TESTING, remove later
  884. CARLA_ASSERT(pData->nextPluginId == pData->maxPluginNumber); // TESTING, remove later
  885. CARLA_ASSERT(pData->plugins != nullptr); // this one too maybe
  886. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  887. {
  888. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  889. if (plugin != nullptr && plugin->isEnabled())
  890. plugin->idle();
  891. }
  892. }
  893. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  894. {
  895. return new CarlaEngineClient(*this);
  896. }
  897. // -----------------------------------------------------------------------
  898. // Plugin management
  899. 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)
  900. {
  901. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #10)");
  902. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId <= pData->maxPluginNumber, "Invalid engine internal data (err #11)");
  903. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #12)");
  904. CARLA_SAFE_ASSERT_RETURN_ERR(btype != BINARY_NONE, "Invalid plugin params (err #1)");
  905. CARLA_SAFE_ASSERT_RETURN_ERR(ptype != PLUGIN_NONE, "Invalid plugin params (err #2)");
  906. CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin params (err #3)");
  907. carla_debug("CarlaEngine::addPlugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", %p)", btype, BinaryType2Str(btype), ptype, PluginType2Str(ptype), filename, name, label, extra);
  908. unsigned int id;
  909. CarlaPlugin* oldPlugin = nullptr;
  910. if (pData->nextPluginId < pData->curPluginCount)
  911. {
  912. id = pData->nextPluginId;
  913. pData->nextPluginId = pData->maxPluginNumber;
  914. oldPlugin = pData->plugins[id].plugin;
  915. CARLA_SAFE_ASSERT_RETURN_ERR(oldPlugin != nullptr, "Invalid replace plugin Id");
  916. }
  917. else
  918. {
  919. id = pData->curPluginCount;
  920. if (id == pData->maxPluginNumber)
  921. {
  922. setLastError("Maximum number of plugins reached");
  923. return false;
  924. }
  925. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins[id].plugin == nullptr, "Invalid engine internal data (err #13)");
  926. }
  927. CarlaPlugin::Initializer init = {
  928. this,
  929. id,
  930. filename,
  931. name,
  932. label
  933. };
  934. CarlaPlugin* plugin = nullptr;
  935. #if 0 //ndef BUILD_BRIDGE
  936. const char* bridgeBinary;
  937. switch (btype)
  938. {
  939. case BINARY_POSIX32:
  940. bridgeBinary = pData->options.bridge_posix32.isNotEmpty() ? (const char*)pData->options.bridge_posix32 : nullptr;
  941. break;
  942. case BINARY_POSIX64:
  943. bridgeBinary = pData->options.bridge_posix64.isNotEmpty() ? (const char*)pData->options.bridge_posix64 : nullptr;
  944. break;
  945. case BINARY_WIN32:
  946. bridgeBinary = pData->options.bridge_win32.isNotEmpty() ? (const char*)pData->options.bridge_win32 : nullptr;
  947. break;
  948. case BINARY_WIN64:
  949. bridgeBinary = pData->options.bridge_win64.isNotEmpty() ? (const char*)pData->options.bridge_win64 : nullptr;
  950. break;
  951. default:
  952. bridgeBinary = nullptr;
  953. break;
  954. }
  955. # ifndef CARLA_OS_WIN
  956. if (btype == BINARY_NATIVE && pData->options.bridge_native.isNotEmpty())
  957. bridgeBinary = (const char*)pData->options.bridge_native;
  958. # endif
  959. if (btype != BINARY_NATIVE || (pData->options.preferPluginBridges && bridgeBinary != nullptr))
  960. {
  961. if (bridgeBinary != nullptr)
  962. {
  963. plugin = CarlaPlugin::newBridge(init, btype, ptype, bridgeBinary);
  964. }
  965. # ifdef CARLA_OS_LINUX
  966. else if (btype == BINARY_WIN32)
  967. {
  968. // fallback to dssi-vst
  969. QFileInfo fileInfo(filename);
  970. CarlaString label2(fileInfo.fileName().toUtf8().constData());
  971. label2.replace(' ', '*');
  972. CarlaPlugin::Initializer init2 = {
  973. this,
  974. id,
  975. "/usr/lib/dssi/dssi-vst.so",
  976. name,
  977. (const char*)label2
  978. };
  979. char* const oldVstPath(getenv("VST_PATH"));
  980. carla_setenv("VST_PATH", fileInfo.absoluteDir().absolutePath().toUtf8().constData());
  981. plugin = CarlaPlugin::newDSSI(init2);
  982. if (oldVstPath != nullptr)
  983. carla_setenv("VST_PATH", oldVstPath);
  984. }
  985. # endif
  986. else
  987. {
  988. setLastError("This Carla build cannot handle this binary");
  989. return false;
  990. }
  991. }
  992. else
  993. #endif // BUILD_BRIDGE
  994. {
  995. setLastError("Invalid or unsupported plugin type");
  996. switch (ptype)
  997. {
  998. case PLUGIN_NONE:
  999. break;
  1000. case PLUGIN_INTERNAL:
  1001. plugin = CarlaPlugin::newNative(init);
  1002. break;
  1003. case PLUGIN_LADSPA:
  1004. plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra);
  1005. break;
  1006. case PLUGIN_DSSI:
  1007. plugin = CarlaPlugin::newDSSI(init);
  1008. break;
  1009. case PLUGIN_LV2:
  1010. plugin = CarlaPlugin::newLV2(init);
  1011. break;
  1012. case PLUGIN_VST:
  1013. plugin = CarlaPlugin::newVST(init);
  1014. break;
  1015. case PLUGIN_AU:
  1016. plugin = CarlaPlugin::newAU(init);
  1017. break;
  1018. case PLUGIN_FILE_CSD:
  1019. plugin = CarlaPlugin::newCsound(init);
  1020. break;
  1021. case PLUGIN_FILE_GIG:
  1022. plugin = CarlaPlugin::newGIG(init, (extra != nullptr && std::strcmp((const char*)extra, "true")));
  1023. break;
  1024. case PLUGIN_FILE_SF2:
  1025. plugin = CarlaPlugin::newSF2(init, (extra != nullptr && std::strcmp((const char*)extra, "true")));
  1026. break;
  1027. case PLUGIN_FILE_SFZ:
  1028. plugin = CarlaPlugin::newSFZ(init, (extra != nullptr && std::strcmp((const char*)extra, "true")));
  1029. break;
  1030. }
  1031. }
  1032. if (plugin == nullptr)
  1033. return false;
  1034. plugin->registerToOscClient();
  1035. EnginePluginData& pluginData(pData->plugins[id]);
  1036. pluginData.plugin = plugin;
  1037. pluginData.insPeak[0] = 0.0f;
  1038. pluginData.insPeak[1] = 0.0f;
  1039. pluginData.outsPeak[0] = 0.0f;
  1040. pluginData.outsPeak[1] = 0.0f;
  1041. if (oldPlugin != nullptr)
  1042. {
  1043. delete oldPlugin;
  1044. callback(ENGINE_CALLBACK_RELOAD_ALL, id, 0, 0, 0.0f, plugin->getName());
  1045. }
  1046. else
  1047. {
  1048. ++pData->curPluginCount;
  1049. callback(ENGINE_CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
  1050. }
  1051. return true;
  1052. }
  1053. bool CarlaEngine::removePlugin(const unsigned int id)
  1054. {
  1055. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #14)");
  1056. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #15)");
  1057. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #16)");
  1058. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #1)");
  1059. carla_debug("CarlaEngine::removePlugin(%i)", id);
  1060. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  1061. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove");
  1062. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #17)");
  1063. pData->thread.stop(500);
  1064. const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
  1065. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionRemovePlugin, id, 0, lockWait);
  1066. #ifndef BUILD_BRIDGE
  1067. if (isOscControlRegistered())
  1068. oscSend_control_remove_plugin(id);
  1069. #endif
  1070. delete plugin;
  1071. if (isRunning() && ! pData->aboutToClose)
  1072. pData->thread.start();
  1073. callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  1074. return true;
  1075. }
  1076. bool CarlaEngine::removeAllPlugins()
  1077. {
  1078. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #18)");
  1079. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #19)");
  1080. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #20)");
  1081. carla_debug("CarlaEngine::removeAllPlugins()");
  1082. if (pData->curPluginCount == 0)
  1083. return true;
  1084. pData->thread.stop(500);
  1085. const bool lockWait(isRunning());
  1086. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait);
  1087. for (unsigned int i=0; i < pData->maxPluginNumber; ++i)
  1088. {
  1089. EnginePluginData& pluginData(pData->plugins[i]);
  1090. if (pluginData.plugin != nullptr)
  1091. {
  1092. delete pluginData.plugin;
  1093. pluginData.plugin = nullptr;
  1094. }
  1095. pluginData.insPeak[0] = 0.0f;
  1096. pluginData.insPeak[1] = 0.0f;
  1097. pluginData.outsPeak[0] = 0.0f;
  1098. pluginData.outsPeak[1] = 0.0f;
  1099. }
  1100. if (isRunning() && ! pData->aboutToClose)
  1101. pData->thread.start();
  1102. return true;
  1103. }
  1104. const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const newName)
  1105. {
  1106. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #21)");
  1107. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #22)");
  1108. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #23)");
  1109. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #2)");
  1110. CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name");
  1111. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  1112. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  1113. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin != nullptr, "Could not find plugin to rename");
  1114. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin->getId() == id, "Invalid engine internal data (err #24)");
  1115. if (const char* const name = getUniquePluginName(newName))
  1116. {
  1117. plugin->setName(name);
  1118. return name;
  1119. }
  1120. setLastError("Unable to get new unique plugin name");
  1121. return nullptr;
  1122. }
  1123. bool CarlaEngine::clonePlugin(const unsigned int id)
  1124. {
  1125. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #25)");
  1126. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #26)");
  1127. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #27)");
  1128. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #3)");
  1129. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  1130. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  1131. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to clone");
  1132. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #28)");
  1133. char label[STR_MAX+1];
  1134. carla_zeroChar(label, STR_MAX+1);
  1135. plugin->getLabel(label);
  1136. const unsigned int pluginCountBefore(pData->curPluginCount);
  1137. if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getExtraStuff()))
  1138. return false;
  1139. CARLA_ASSERT(pluginCountBefore+1 == pData->curPluginCount);
  1140. if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
  1141. newPlugin->loadSaveState(plugin->getSaveState());
  1142. return true;
  1143. }
  1144. bool CarlaEngine::replacePlugin(const unsigned int id)
  1145. {
  1146. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #29)");
  1147. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)");
  1148. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)");
  1149. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #4)");
  1150. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  1151. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  1152. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to replace");
  1153. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #32)");
  1154. pData->nextPluginId = id;
  1155. return true;
  1156. }
  1157. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  1158. {
  1159. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data (err #33)");
  1160. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount >= 2, "Invalid engine internal data (err #34)");
  1161. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #35)");
  1162. CARLA_SAFE_ASSERT_RETURN_ERR(idA != idB, "Invalid operation, cannot switch plugin with itself");
  1163. CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id (err #5)");
  1164. CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id (err #6)");
  1165. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  1166. CarlaPlugin* const pluginA(pData->plugins[idA].plugin);
  1167. CarlaPlugin* const pluginB(pData->plugins[idB].plugin);
  1168. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #1)");
  1169. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch (err #2)");
  1170. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data (err #36)");
  1171. CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data (err #37)");
  1172. pData->thread.stop(500);
  1173. const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS);
  1174. const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  1175. #ifndef BUILD_BRIDGE // TODO
  1176. //if (isOscControlRegistered())
  1177. // oscSend_control_switch_plugins(idA, idB);
  1178. #endif
  1179. if (isRunning() && ! pData->aboutToClose)
  1180. pData->thread.start();
  1181. return true;
  1182. }
  1183. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  1184. {
  1185. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data (err #38)");
  1186. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data (err #39)");
  1187. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #40)");
  1188. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #7)");
  1189. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, pData->curPluginCount);
  1190. return pData->plugins[id].plugin;
  1191. }
  1192. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const noexcept
  1193. {
  1194. return pData->plugins[id].plugin;
  1195. }
  1196. const char* CarlaEngine::getUniquePluginName(const char* const name) const
  1197. {
  1198. CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr, nullptr);
  1199. CARLA_SAFE_ASSERT_RETURN(pData->maxPluginNumber != 0, nullptr);
  1200. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr);
  1201. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  1202. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  1203. CarlaString sname;
  1204. sname = name;
  1205. if (sname.isEmpty())
  1206. {
  1207. sname = "(No name)";
  1208. return sname.dup();
  1209. }
  1210. sname.truncate(getMaxClientNameSize()-5-1); // 5 = strlen(" (10)")
  1211. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  1212. for (unsigned short i=0; i < pData->curPluginCount; ++i)
  1213. {
  1214. CARLA_SAFE_ASSERT_BREAK(pData->plugins[i].plugin != nullptr);
  1215. // Check if unique name doesn't exist
  1216. if (const char* const pluginName = pData->plugins[i].plugin->getName())
  1217. {
  1218. if (sname != pluginName)
  1219. continue;
  1220. }
  1221. // Check if string has already been modified
  1222. {
  1223. const size_t len(sname.length());
  1224. // 1 digit, ex: " (2)"
  1225. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  1226. {
  1227. int number = sname[len-2] - '0';
  1228. if (number == 9)
  1229. {
  1230. // next number is 10, 2 digits
  1231. sname.truncate(len-4);
  1232. sname += " (10)";
  1233. //sname.replace(" (9)", " (10)");
  1234. }
  1235. else
  1236. sname[len-2] = char('0' + number + 1);
  1237. continue;
  1238. }
  1239. // 2 digits, ex: " (11)"
  1240. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  1241. {
  1242. char n2 = sname[len-2];
  1243. char n3 = sname[len-3];
  1244. if (n2 == '9')
  1245. {
  1246. n2 = '0';
  1247. n3 = static_cast<char>(n3 + 1);
  1248. }
  1249. else
  1250. n2 = static_cast<char>(n2 + 1);
  1251. sname[len-2] = n2;
  1252. sname[len-3] = n3;
  1253. continue;
  1254. }
  1255. }
  1256. // Modify string if not
  1257. sname += " (2)";
  1258. }
  1259. return sname.dup();
  1260. }
  1261. // -----------------------------------------------------------------------
  1262. // Project management
  1263. bool CarlaEngine::loadFile(const char* const filename)
  1264. {
  1265. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #1)");
  1266. carla_debug("CarlaEngine::loadFile(\"%s\")", filename);
  1267. QFileInfo fileInfo(filename);
  1268. if (! fileInfo.exists())
  1269. {
  1270. setLastError("File does not exist");
  1271. return false;
  1272. }
  1273. if (! fileInfo.isFile())
  1274. {
  1275. setLastError("Not a file");
  1276. return false;
  1277. }
  1278. if (! fileInfo.isReadable())
  1279. {
  1280. setLastError("File is not readable");
  1281. return false;
  1282. }
  1283. CarlaString baseName(fileInfo.baseName().toUtf8().constData());
  1284. CarlaString extension(fileInfo.suffix().toLower().toUtf8().constData());
  1285. extension.toLower();
  1286. // -------------------------------------------------------------------
  1287. if (extension == "carxp" || extension == "carxs")
  1288. return loadProject(filename);
  1289. // -------------------------------------------------------------------
  1290. if (extension == "csd")
  1291. return addPlugin(PLUGIN_FILE_CSD, filename, baseName, baseName);
  1292. if (extension == "gig")
  1293. return addPlugin(PLUGIN_FILE_GIG, filename, baseName, baseName);
  1294. if (extension == "sf2")
  1295. return addPlugin(PLUGIN_FILE_SF2, filename, baseName, baseName);
  1296. if (extension == "sfz")
  1297. return addPlugin(PLUGIN_FILE_SFZ, filename, baseName, baseName);
  1298. // -------------------------------------------------------------------
  1299. if (extension == "aiff" || extension == "flac" || extension == "oga" || extension == "ogg" || extension == "w64" || extension == "wav")
  1300. {
  1301. #ifdef WANT_AUDIOFILE
  1302. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  1303. {
  1304. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1305. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1306. return true;
  1307. }
  1308. return false;
  1309. #else
  1310. setLastError("This Carla build does not have Audio file support");
  1311. return false;
  1312. #endif
  1313. }
  1314. if (extension == "3g2" || extension == "3gp" || extension == "aac" || extension == "ac3" || extension == "amr" || extension == "ape" ||
  1315. extension == "mp2" || extension == "mp3" || extension == "mpc" || extension == "wma")
  1316. {
  1317. #ifdef WANT_AUDIOFILE
  1318. # ifdef HAVE_FFMPEG
  1319. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile"))
  1320. {
  1321. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1322. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1323. return true;
  1324. }
  1325. return false;
  1326. # else
  1327. setLastError("This Carla build has Audio file support, but not libav/ffmpeg");
  1328. return false;
  1329. # endif
  1330. #else
  1331. setLastError("This Carla build does not have Audio file support");
  1332. return false;
  1333. #endif
  1334. }
  1335. // -------------------------------------------------------------------
  1336. if (extension == "mid" || extension == "midi")
  1337. {
  1338. #ifdef WANT_MIDIFILE
  1339. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile"))
  1340. {
  1341. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1342. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  1343. return true;
  1344. }
  1345. return false;
  1346. #else
  1347. setLastError("This Carla build does not have MIDI file support");
  1348. return false;
  1349. #endif
  1350. }
  1351. // -------------------------------------------------------------------
  1352. // ZynAddSubFX
  1353. if (extension == "xmz" || extension == "xiz")
  1354. {
  1355. #ifdef WANT_ZYNADDSUBFX
  1356. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "zynaddsubfx"))
  1357. {
  1358. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1359. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  1360. return true;
  1361. }
  1362. return false;
  1363. #else
  1364. setLastError("This Carla build does not have ZynAddSubFX support");
  1365. return false;
  1366. #endif
  1367. }
  1368. // -------------------------------------------------------------------
  1369. setLastError("Unknown file extension");
  1370. return false;
  1371. }
  1372. bool CarlaEngine::loadProject(const char* const filename)
  1373. {
  1374. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #2)");
  1375. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  1376. QFile file(filename);
  1377. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  1378. return false;
  1379. QDomDocument xml;
  1380. xml.setContent(file.readAll());
  1381. file.close();
  1382. QDomNode xmlNode(xml.documentElement());
  1383. const bool isPreset(xmlNode.toElement().tagName().compare("carla-preset", Qt::CaseInsensitive) == 0);
  1384. if (xmlNode.toElement().tagName().compare("carla-project", Qt::CaseInsensitive) != 0 && ! isPreset)
  1385. {
  1386. setLastError("Not a valid Carla project or preset file");
  1387. return false;
  1388. }
  1389. for (QDomNode node = xmlNode.firstChild(); ! node.isNull(); node = node.nextSibling())
  1390. {
  1391. if (isPreset || node.toElement().tagName().compare("plugin", Qt::CaseInsensitive) == 0)
  1392. {
  1393. SaveState saveState;
  1394. fillSaveStateFromXmlNode(saveState, isPreset ? xmlNode : node);
  1395. CARLA_SAFE_ASSERT_CONTINUE(saveState.type != nullptr);
  1396. const void* extraStuff = nullptr;
  1397. // check if using GIG, SF2 or SFZ 16outs
  1398. static const char kUse16OutsSuffix[] = " (16 outs)";
  1399. if (CarlaString(saveState.label).endsWith(kUse16OutsSuffix))
  1400. {
  1401. if (std::strcmp(saveState.type, "GIG") == 0 || std::strcmp(saveState.type, "SF2") == 0)
  1402. extraStuff = "true";
  1403. }
  1404. // TODO - proper find&load plugins
  1405. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  1406. {
  1407. if (CarlaPlugin* const plugin = getPlugin(pData->curPluginCount-1))
  1408. plugin->loadSaveState(saveState);
  1409. }
  1410. }
  1411. if (isPreset)
  1412. break;
  1413. }
  1414. return true;
  1415. }
  1416. bool CarlaEngine::saveProject(const char* const filename)
  1417. {
  1418. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #3)");
  1419. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  1420. QFile file(filename);
  1421. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  1422. return false;
  1423. QTextStream out(&file);
  1424. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1425. out << "<!DOCTYPE CARLA-PROJECT>\n";
  1426. out << "<CARLA-PROJECT VERSION='2.0'>\n";
  1427. bool firstPlugin = true;
  1428. char strBuf[STR_MAX+1];
  1429. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1430. {
  1431. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1432. if (plugin != nullptr && plugin->isEnabled())
  1433. {
  1434. if (! firstPlugin)
  1435. out << "\n";
  1436. strBuf[0] = '\0';
  1437. plugin->getRealName(strBuf);
  1438. if (strBuf[0] != '\0')
  1439. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  1440. QString content;
  1441. fillXmlStringFromSaveState(content, plugin->getSaveState());
  1442. out << " <Plugin>\n";
  1443. out << content;
  1444. out << " </Plugin>\n";
  1445. firstPlugin = false;
  1446. }
  1447. }
  1448. out << "</CARLA-PROJECT>\n";
  1449. file.close();
  1450. return true;
  1451. }
  1452. // -----------------------------------------------------------------------
  1453. // Information (base)
  1454. /*!
  1455. * Get the current engine driver hints.
  1456. */
  1457. unsigned int CarlaEngine::getHints() const noexcept
  1458. {
  1459. return pData->hints;
  1460. }
  1461. /*!
  1462. * Get the current buffer size.
  1463. */
  1464. uint32_t CarlaEngine::getBufferSize() const noexcept
  1465. {
  1466. return pData->bufferSize;
  1467. }
  1468. /*!
  1469. * Get the current sample rate.
  1470. */
  1471. double CarlaEngine::getSampleRate() const noexcept
  1472. {
  1473. return pData->sampleRate;
  1474. }
  1475. /*!
  1476. * Get the current engine name.
  1477. */
  1478. const char* CarlaEngine::getName() const noexcept
  1479. {
  1480. return (const char*)pData->name;
  1481. }
  1482. /*!
  1483. * Get the current engine proccess mode.
  1484. */
  1485. EngineProcessMode CarlaEngine::getProccessMode() const noexcept
  1486. {
  1487. return pData->options.processMode;
  1488. }
  1489. /*!
  1490. * Get the current engine options (read-only).
  1491. */
  1492. const EngineOptions& CarlaEngine::getOptions() const noexcept
  1493. {
  1494. return pData->options;
  1495. }
  1496. /*!
  1497. * Get the current Time information (read-only).
  1498. */
  1499. const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept
  1500. {
  1501. return pData->timeInfo;
  1502. }
  1503. // -----------------------------------------------------------------------
  1504. // Information (peaks)
  1505. float CarlaEngine::getInputPeak(const unsigned int pluginId, const bool isLeft) const noexcept
  1506. {
  1507. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1508. return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1];
  1509. }
  1510. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) const noexcept
  1511. {
  1512. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1513. return pData->plugins[pluginId].outsPeak[isLeft ? 0 : 1];
  1514. }
  1515. // -----------------------------------------------------------------------
  1516. // Callback
  1517. void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept
  1518. {
  1519. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  1520. if (pData->callback != nullptr)
  1521. {
  1522. try {
  1523. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1524. } catch(...) {}
  1525. }
  1526. }
  1527. void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept
  1528. {
  1529. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1530. pData->callback = func;
  1531. pData->callbackPtr = ptr;
  1532. }
  1533. #ifndef BUILD_BRIDGE
  1534. // -----------------------------------------------------------------------
  1535. // Patchbay
  1536. bool CarlaEngine::patchbayConnect(const int portA, const int portB)
  1537. {
  1538. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1539. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1540. carla_debug("CarlaEngineRtAudio::patchbayConnect(%i, %i)", portA, portB);
  1541. if (pData->bufAudio.usePatchbay)
  1542. {
  1543. // not implemented yet
  1544. return false;
  1545. }
  1546. EngineRackBuffers* const rack(pData->bufAudio.rack);
  1547. CARLA_SAFE_ASSERT_RETURN_ERR(portA > RACK_PATCHBAY_PORT_MAX, "Invalid output port");
  1548. CARLA_SAFE_ASSERT_RETURN_ERR(portB > RACK_PATCHBAY_PORT_MAX, "Invalid input port");
  1549. // only allow connections between Carla and other ports
  1550. if (portA < 0 && portB < 0)
  1551. {
  1552. setLastError("Invalid connection (1)");
  1553. return false;
  1554. }
  1555. if (portA >= 0 && portB >= 0)
  1556. {
  1557. setLastError("Invalid connection (2)");
  1558. return false;
  1559. }
  1560. const int carlaPort = (portA < 0) ? portA : portB;
  1561. const int targetPort = (carlaPort == portA) ? portB : portA;
  1562. bool makeConnection = false;
  1563. switch (carlaPort)
  1564. {
  1565. case RACK_PATCHBAY_PORT_AUDIO_IN1:
  1566. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1567. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_IN*1000+999);
  1568. rack->connectLock.lock();
  1569. rack->connectedIns[0].append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1570. rack->connectLock.unlock();
  1571. makeConnection = true;
  1572. break;
  1573. case RACK_PATCHBAY_PORT_AUDIO_IN2:
  1574. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1575. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_IN*1000+999);
  1576. rack->connectLock.lock();
  1577. rack->connectedIns[1].append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1578. rack->connectLock.unlock();
  1579. makeConnection = true;
  1580. break;
  1581. case RACK_PATCHBAY_PORT_AUDIO_OUT1:
  1582. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1583. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000+999);
  1584. rack->connectLock.lock();
  1585. rack->connectedOuts[0].append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1586. rack->connectLock.unlock();
  1587. makeConnection = true;
  1588. break;
  1589. case RACK_PATCHBAY_PORT_AUDIO_OUT2:
  1590. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1591. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000+999);
  1592. rack->connectLock.lock();
  1593. rack->connectedOuts[1].append(targetPort - RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1594. rack->connectLock.unlock();
  1595. makeConnection = true;
  1596. break;
  1597. case RACK_PATCHBAY_PORT_MIDI_IN:
  1598. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1599. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_MIDI_IN*1000+999);
  1600. makeConnection = connectRackMidiInPort(targetPort - RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1601. break;
  1602. case RACK_PATCHBAY_PORT_MIDI_OUT:
  1603. CARLA_SAFE_ASSERT_BREAK(targetPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1604. CARLA_SAFE_ASSERT_BREAK(targetPort <= RACK_PATCHBAY_GROUP_MIDI_OUT*1000+999);
  1605. makeConnection = connectRackMidiOutPort(targetPort - RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1606. break;
  1607. }
  1608. if (! makeConnection)
  1609. {
  1610. setLastError("Invalid connection (3)");
  1611. return false;
  1612. }
  1613. ConnectionToId connectionToId;
  1614. connectionToId.id = rack->lastConnectionId;
  1615. connectionToId.portOut = portA;
  1616. connectionToId.portIn = portB;
  1617. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_ADDED, rack->lastConnectionId, portA, portB, 0.0f, nullptr);
  1618. rack->usedConnections.append(connectionToId);
  1619. rack->lastConnectionId++;
  1620. return true;
  1621. }
  1622. bool CarlaEngine::patchbayDisconnect(const int connectionId)
  1623. {
  1624. CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false);
  1625. CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false);
  1626. carla_debug("CarlaEngineRtAudio::patchbayDisconnect(%i)", connectionId);
  1627. if (pData->bufAudio.usePatchbay)
  1628. {
  1629. // not implemented yet
  1630. return false;
  1631. }
  1632. EngineRackBuffers* const rack(pData->bufAudio.rack);
  1633. CARLA_SAFE_ASSERT_RETURN_ERR(rack->usedConnections.count() > 0, "No connections available");
  1634. for (LinkedList<ConnectionToId>::Itenerator it=rack->usedConnections.begin(); it.valid(); it.next())
  1635. {
  1636. const ConnectionToId& connection(it.getValue());
  1637. if (connection.id == connectionId)
  1638. {
  1639. const int targetPort((connection.portOut >= 0) ? connection.portOut : connection.portIn);
  1640. const int carlaPort((targetPort == connection.portOut) ? connection.portIn : connection.portOut);
  1641. if (targetPort >= RACK_PATCHBAY_GROUP_MIDI_OUT*1000)
  1642. {
  1643. const int portId(targetPort-RACK_PATCHBAY_GROUP_MIDI_OUT*1000);
  1644. disconnectRackMidiInPort(portId);
  1645. }
  1646. else if (targetPort >= RACK_PATCHBAY_GROUP_MIDI_IN*1000)
  1647. {
  1648. const int portId(targetPort-RACK_PATCHBAY_GROUP_MIDI_IN*1000);
  1649. disconnectRackMidiOutPort(portId);
  1650. }
  1651. else if (targetPort >= RACK_PATCHBAY_GROUP_AUDIO_OUT*1000)
  1652. {
  1653. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT2, false);
  1654. const int portId(targetPort-RACK_PATCHBAY_GROUP_AUDIO_OUT*1000);
  1655. rack->connectLock.lock();
  1656. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_OUT1)
  1657. rack->connectedOuts[0].removeAll(portId);
  1658. else
  1659. rack->connectedOuts[1].removeAll(portId);
  1660. rack->connectLock.unlock();
  1661. }
  1662. else if (targetPort >= RACK_PATCHBAY_GROUP_AUDIO_IN*1000)
  1663. {
  1664. CARLA_SAFE_ASSERT_RETURN(carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1 || carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN2, false);
  1665. const int portId(targetPort-RACK_PATCHBAY_GROUP_AUDIO_IN*1000);
  1666. rack->connectLock.lock();
  1667. if (carlaPort == RACK_PATCHBAY_PORT_AUDIO_IN1)
  1668. rack->connectedIns[0].removeAll(portId);
  1669. else
  1670. rack->connectedIns[1].removeAll(portId);
  1671. rack->connectLock.unlock();
  1672. }
  1673. else
  1674. {
  1675. CARLA_SAFE_ASSERT_RETURN(false, false);
  1676. }
  1677. callback(ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED, connection.id, connection.portOut, connection.portIn, 0.0f, nullptr);
  1678. rack->usedConnections.remove(it);
  1679. break;
  1680. }
  1681. }
  1682. return true;
  1683. }
  1684. bool CarlaEngine::patchbayRefresh()
  1685. {
  1686. setLastError("Unsupported operation");
  1687. return false;
  1688. }
  1689. #endif
  1690. // -----------------------------------------------------------------------
  1691. // Transport
  1692. void CarlaEngine::transportPlay() noexcept
  1693. {
  1694. pData->time.playing = true;
  1695. }
  1696. void CarlaEngine::transportPause() noexcept
  1697. {
  1698. pData->time.playing = false;
  1699. }
  1700. void CarlaEngine::transportRelocate(const uint64_t frame) noexcept
  1701. {
  1702. pData->time.frame = frame;
  1703. }
  1704. // -----------------------------------------------------------------------
  1705. // Error handling
  1706. const char* CarlaEngine::getLastError() const noexcept
  1707. {
  1708. return pData->lastError.getBuffer();
  1709. }
  1710. void CarlaEngine::setLastError(const char* const error) const
  1711. {
  1712. pData->lastError = error;
  1713. }
  1714. void CarlaEngine::setAboutToClose() noexcept
  1715. {
  1716. carla_debug("CarlaEngine::setAboutToClose()");
  1717. pData->aboutToClose = true;
  1718. }
  1719. // -----------------------------------------------------------------------
  1720. // Global options
  1721. void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr)
  1722. {
  1723. carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
  1724. if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
  1725. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
  1726. switch (option)
  1727. {
  1728. case ENGINE_OPTION_DEBUG:
  1729. break;
  1730. case ENGINE_OPTION_PROCESS_MODE:
  1731. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
  1732. pData->options.processMode = static_cast<EngineProcessMode>(value);
  1733. break;
  1734. case ENGINE_OPTION_TRANSPORT_MODE:
  1735. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
  1736. pData->options.transportMode = static_cast<EngineTransportMode>(value);
  1737. break;
  1738. case ENGINE_OPTION_FORCE_STEREO:
  1739. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1740. pData->options.forceStereo = (value != 0);
  1741. break;
  1742. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  1743. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1744. pData->options.preferPluginBridges = (value != 0);
  1745. break;
  1746. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  1747. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1748. pData->options.preferUiBridges = (value != 0);
  1749. break;
  1750. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  1751. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1752. pData->options.uisAlwaysOnTop = (value != 0);
  1753. break;
  1754. case ENGINE_OPTION_MAX_PARAMETERS:
  1755. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1756. pData->options.maxParameters = static_cast<uint>(value);
  1757. break;
  1758. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  1759. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1760. pData->options.uiBridgesTimeout = static_cast<uint>(value);
  1761. break;
  1762. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  1763. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  1764. pData->options.audioNumPeriods = static_cast<uint>(value);
  1765. break;
  1766. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  1767. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  1768. pData->options.audioBufferSize = static_cast<uint>(value);
  1769. break;
  1770. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  1771. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  1772. pData->options.audioSampleRate = static_cast<uint>(value);
  1773. break;
  1774. case ENGINE_OPTION_AUDIO_DEVICE:
  1775. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1776. if (pData->options.audioDevice != nullptr)
  1777. delete[] pData->options.audioDevice;
  1778. pData->options.audioDevice = carla_strdup(valueStr);
  1779. break;
  1780. case ENGINE_OPTION_PATH_BINARIES:
  1781. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1782. if (pData->options.binaryDir != nullptr)
  1783. delete[] pData->options.binaryDir;
  1784. pData->options.binaryDir = carla_strdup(valueStr);
  1785. break;
  1786. case ENGINE_OPTION_PATH_RESOURCES:
  1787. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1788. if (pData->options.resourceDir != nullptr)
  1789. delete[] pData->options.resourceDir;
  1790. pData->options.resourceDir = carla_strdup(valueStr);
  1791. break;
  1792. }
  1793. }
  1794. // -----------------------------------------------------------------------
  1795. // OSC Stuff
  1796. #ifdef BUILD_BRIDGE
  1797. bool CarlaEngine::isOscBridgeRegistered() const noexcept
  1798. {
  1799. return (pData->oscData != nullptr);
  1800. }
  1801. #else
  1802. bool CarlaEngine::isOscControlRegistered() const noexcept
  1803. {
  1804. return pData->osc.isControlRegistered();
  1805. }
  1806. #endif
  1807. void CarlaEngine::idleOsc() const noexcept
  1808. {
  1809. try {
  1810. pData->osc.idle();
  1811. } catch(...) {}
  1812. }
  1813. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1814. {
  1815. return pData->osc.getServerPathTCP();
  1816. }
  1817. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1818. {
  1819. return pData->osc.getServerPathUDP();
  1820. }
  1821. #ifdef BUILD_BRIDGE
  1822. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept
  1823. {
  1824. pData->oscData = oscData;
  1825. }
  1826. #endif
  1827. // -----------------------------------------------------------------------
  1828. // Helper functions
  1829. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1830. {
  1831. return isInput ? pData->bufEvents.in : pData->bufEvents.out;
  1832. }
  1833. void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept
  1834. {
  1835. CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,);
  1836. carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin);
  1837. pData->plugins[id].plugin = plugin;
  1838. }
  1839. // -----------------------------------------------------------------------
  1840. // Internal stuff
  1841. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1842. {
  1843. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1844. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1845. {
  1846. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1847. if (plugin != nullptr && plugin->isEnabled())
  1848. plugin->bufferSizeChanged(newBufferSize);
  1849. }
  1850. callback(ENGINE_CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1851. }
  1852. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1853. {
  1854. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1855. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1856. {
  1857. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1858. if (plugin != nullptr && plugin->isEnabled())
  1859. plugin->sampleRateChanged(newSampleRate);
  1860. }
  1861. callback(ENGINE_CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, static_cast<float>(newSampleRate), nullptr);
  1862. }
  1863. void CarlaEngine::offlineModeChanged(const bool isOffline)
  1864. {
  1865. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOffline));
  1866. for (unsigned int i=0; i < pData->curPluginCount; ++i)
  1867. {
  1868. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1869. if (plugin != nullptr && plugin->isEnabled())
  1870. plugin->offlineModeChanged(isOffline);
  1871. }
  1872. }
  1873. void CarlaEngine::runPendingRtEvents() noexcept
  1874. {
  1875. pData->doNextPluginAction(true);
  1876. if (pData->time.playing)
  1877. pData->time.frame += pData->bufferSize;
  1878. if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL)
  1879. {
  1880. pData->timeInfo.playing = pData->time.playing;
  1881. pData->timeInfo.frame = pData->time.frame;
  1882. }
  1883. }
  1884. void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1885. {
  1886. EnginePluginData& pluginData(pData->plugins[pluginId]);
  1887. pluginData.insPeak[0] = inPeaks[0];
  1888. pluginData.insPeak[1] = inPeaks[1];
  1889. pluginData.outsPeak[0] = outPeaks[0];
  1890. pluginData.outsPeak[1] = outPeaks[1];
  1891. }
  1892. // -----------------------------------------------------------------------
  1893. // Bridge/Controller OSC stuff
  1894. #ifdef BUILD_BRIDGE
  1895. void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const noexcept
  1896. {
  1897. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1898. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1899. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1900. carla_debug("CarlaEngine::oscSend_bridge_plugin_info1(%i:%s, %X, %l)", category, PluginCategory2Str(category), hints, uniqueId);
  1901. char targetPath[std::strlen(pData->oscData->path)+21];
  1902. std::strcpy(targetPath, pData->oscData->path);
  1903. std::strcat(targetPath, "/bridge_plugin_info1");
  1904. try_lo_send(pData->oscData->target, targetPath, "iih", static_cast<int32_t>(category), static_cast<int32_t>(hints), static_cast<int64_t>(uniqueId));
  1905. }
  1906. void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  1907. {
  1908. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1909. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1910. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1911. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  1912. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  1913. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  1914. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  1915. carla_debug("CarlaEngine::oscSend_bridge_plugin_info2(\"%s\", \"%s\", \"%s\", \"%s\")", realName, label, maker, copyright);
  1916. char targetPath[std::strlen(pData->oscData->path)+21];
  1917. std::strcpy(targetPath, pData->oscData->path);
  1918. std::strcat(targetPath, "/bridge_plugin_info2");
  1919. try_lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright);
  1920. }
  1921. void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept
  1922. {
  1923. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1924. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1925. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1926. carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i)", ins, outs);
  1927. char targetPath[std::strlen(pData->oscData->path)+20];
  1928. std::strcpy(targetPath, pData->oscData->path);
  1929. std::strcat(targetPath, "/bridge_audio_count");
  1930. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1931. }
  1932. void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept
  1933. {
  1934. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1935. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1936. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1937. carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i)", ins, outs);
  1938. char targetPath[std::strlen(pData->oscData->path)+19];
  1939. std::strcpy(targetPath, pData->oscData->path);
  1940. std::strcat(targetPath, "/bridge_midi_count");
  1941. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1942. }
  1943. void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept
  1944. {
  1945. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1946. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1947. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1948. carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i)", ins, outs);
  1949. char targetPath[std::strlen(pData->oscData->path)+24];
  1950. std::strcpy(targetPath, pData->oscData->path);
  1951. std::strcat(targetPath, "/bridge_parameter_count");
  1952. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  1953. }
  1954. void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const noexcept
  1955. {
  1956. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1957. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1958. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1959. carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count);
  1960. char targetPath[std::strlen(pData->oscData->path)+22];
  1961. std::strcpy(targetPath, pData->oscData->path);
  1962. std::strcat(targetPath, "/bridge_program_count");
  1963. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1964. }
  1965. void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const noexcept
  1966. {
  1967. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1968. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1969. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1970. carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count);
  1971. char targetPath[std::strlen(pData->oscData->path)+27];
  1972. std::strcpy(targetPath, pData->oscData->path);
  1973. std::strcat(targetPath, "/bridge_midi_program_count");
  1974. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(count));
  1975. }
  1976. void CarlaEngine::oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept
  1977. {
  1978. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1979. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1980. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1981. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  1982. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  1983. carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", index, rindex, type, ParameterType2Str(type), hints, name, unit);
  1984. char targetPath[std::strlen(pData->oscData->path)+23];
  1985. std::strcpy(targetPath, pData->oscData->path);
  1986. std::strcat(targetPath, "/bridge_parameter_data");
  1987. try_lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast<int32_t>(index), static_cast<int32_t>(rindex), static_cast<int32_t>(type), static_cast<int32_t>(hints), name, unit);
  1988. }
  1989. void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept
  1990. {
  1991. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  1992. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  1993. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  1994. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, def, min, max);
  1995. char targetPath[std::strlen(pData->oscData->path)+26];
  1996. std::strcpy(targetPath, pData->oscData->path);
  1997. std::strcat(targetPath, "/bridge_parameter_ranges1");
  1998. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), def, min, max);
  1999. }
  2000. void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  2001. {
  2002. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2003. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2004. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2005. carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, step, stepSmall, stepLarge);
  2006. char targetPath[std::strlen(pData->oscData->path)+26];
  2007. std::strcpy(targetPath, pData->oscData->path);
  2008. std::strcat(targetPath, "/bridge_parameter_ranges2");
  2009. try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast<int32_t>(index), step, stepSmall, stepLarge);
  2010. }
  2011. void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept
  2012. {
  2013. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2014. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2015. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2016. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_cc(%i, %i)", index, cc);
  2017. char targetPath[std::strlen(pData->oscData->path)+26];
  2018. std::strcpy(targetPath, pData->oscData->path);
  2019. std::strcat(targetPath, "/bridge_parameter_midi_cc");
  2020. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(cc));
  2021. }
  2022. void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept
  2023. {
  2024. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2025. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2026. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2027. carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_channel(%i, %i)", index, channel);
  2028. char targetPath[std::strlen(pData->oscData->path)+31];
  2029. std::strcpy(targetPath, pData->oscData->path);
  2030. std::strcat(targetPath, "/bridge_parameter_midi_channel");
  2031. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(index), static_cast<int32_t>(channel));
  2032. }
  2033. void CarlaEngine::oscSend_bridge_parameter_value(const int32_t index, const float value) const noexcept
  2034. {
  2035. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2036. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2037. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2038. CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
  2039. carla_debug("CarlaEngine::oscSend_bridge_parameter_value(%i, %f)", index, value);
  2040. char targetPath[std::strlen(pData->oscData->path)+24];
  2041. std::strcpy(targetPath, pData->oscData->path);
  2042. std::strcat(targetPath, "/bridge_parameter_value");
  2043. try_lo_send(pData->oscData->target, targetPath, "if", index, value);
  2044. }
  2045. void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept
  2046. {
  2047. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2048. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2049. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2050. carla_debug("CarlaEngine::oscSend_bridge_default_value(%i, %f)", index, value);
  2051. char targetPath[std::strlen(pData->oscData->path)+22];
  2052. std::strcpy(targetPath, pData->oscData->path);
  2053. std::strcat(targetPath, "/bridge_default_value");
  2054. try_lo_send(pData->oscData->target, targetPath, "if", static_cast<int32_t>(index), value);
  2055. }
  2056. void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const noexcept
  2057. {
  2058. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2059. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2060. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2061. carla_debug("CarlaEngine::oscSend_bridge_current_program(%i)", index);
  2062. char targetPath[std::strlen(pData->oscData->path)+20];
  2063. std::strcpy(targetPath, pData->oscData->path);
  2064. std::strcat(targetPath, "/bridge_current_program");
  2065. try_lo_send(pData->oscData->target, targetPath, "i", index);
  2066. }
  2067. void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const noexcept
  2068. {
  2069. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2070. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2071. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2072. carla_debug("CarlaEngine::oscSend_bridge_current_midi_program(%i)", index);
  2073. char targetPath[std::strlen(pData->oscData->path)+25];
  2074. std::strcpy(targetPath, pData->oscData->path);
  2075. std::strcat(targetPath, "/bridge_current_midi_program");
  2076. try_lo_send(pData->oscData->target, targetPath, "i", index);
  2077. }
  2078. void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept
  2079. {
  2080. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2081. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2082. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2083. carla_debug("CarlaEngine::oscSend_bridge_program_name(%i, \"%s\")", index, name);
  2084. char targetPath[std::strlen(pData->oscData->path)+21];
  2085. std::strcpy(targetPath, pData->oscData->path);
  2086. std::strcat(targetPath, "/bridge_program_name");
  2087. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(index), name);
  2088. }
  2089. void CarlaEngine::oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept
  2090. {
  2091. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2092. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2093. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2094. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2095. carla_debug("CarlaEngine::oscSend_bridge_midi_program_data(%i, %i, %i, \"%s\")", index, bank, program, name);
  2096. char targetPath[std::strlen(pData->oscData->path)+26];
  2097. std::strcpy(targetPath, pData->oscData->path);
  2098. std::strcat(targetPath, "/bridge_midi_program_data");
  2099. try_lo_send(pData->oscData->target, targetPath, "iiis", static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  2100. }
  2101. void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const noexcept
  2102. {
  2103. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2104. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2105. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2106. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  2107. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  2108. carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value);
  2109. char targetPath[std::strlen(pData->oscData->path)+18];
  2110. std::strcpy(targetPath, pData->oscData->path);
  2111. std::strcat(targetPath, "/bridge_configure");
  2112. try_lo_send(pData->oscData->target, targetPath, "ss", key, value);
  2113. }
  2114. void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept
  2115. {
  2116. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2117. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2118. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2119. carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  2120. char targetPath[std::strlen(pData->oscData->path)+24];
  2121. std::strcpy(targetPath, pData->oscData->path);
  2122. std::strcat(targetPath, "/bridge_set_custom_data");
  2123. try_lo_send(pData->oscData->target, targetPath, "sss", type, key, value);
  2124. }
  2125. void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept
  2126. {
  2127. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2128. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2129. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2130. CARLA_SAFE_ASSERT_RETURN(chunkFile != nullptr && chunkFile[0] != '\0',);
  2131. carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile);
  2132. char targetPath[std::strlen(pData->oscData->path)+23];
  2133. std::strcpy(targetPath, pData->oscData->path);
  2134. std::strcat(targetPath, "/bridge_set_chunk_data");
  2135. try_lo_send(pData->oscData->target, targetPath, "s", chunkFile);
  2136. }
  2137. // TODO?
  2138. //void oscSend_bridge_set_peaks() const;
  2139. #else
  2140. void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept
  2141. {
  2142. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2143. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2144. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2145. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2146. CARLA_SAFE_ASSERT_RETURN(pluginName != nullptr && pluginName[0] != '\0',);
  2147. carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  2148. char targetPath[std::strlen(pData->oscData->path)+18];
  2149. std::strcpy(targetPath, pData->oscData->path);
  2150. std::strcat(targetPath, "/add_plugin_start");
  2151. try_lo_send(pData->oscData->target, targetPath, "is", static_cast<int32_t>(pluginId), pluginName);
  2152. }
  2153. void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const noexcept
  2154. {
  2155. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2156. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2157. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2158. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2159. carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId);
  2160. char targetPath[std::strlen(pData->oscData->path)+16];
  2161. std::strcpy(targetPath, pData->oscData->path);
  2162. std::strcat(targetPath, "/add_plugin_end");
  2163. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2164. }
  2165. void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const noexcept
  2166. {
  2167. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2168. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2169. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2170. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2171. carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId);
  2172. char targetPath[std::strlen(pData->oscData->path)+15];
  2173. std::strcpy(targetPath, pData->oscData->path);
  2174. std::strcat(targetPath, "/remove_plugin");
  2175. try_lo_send(pData->oscData->target, targetPath, "i", static_cast<int32_t>(pluginId));
  2176. }
  2177. void CarlaEngine::oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const noexcept
  2178. {
  2179. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2180. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2181. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2182. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2183. CARLA_SAFE_ASSERT_RETURN(type != PLUGIN_NONE,);
  2184. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, %i:%s, %i:%s, %X, %l)", pluginId, type, PluginType2Str(type), category, PluginCategory2Str(category), hints, uniqueId);
  2185. char targetPath[std::strlen(pData->oscData->path)+18];
  2186. std::strcpy(targetPath, pData->oscData->path);
  2187. std::strcat(targetPath, "/set_plugin_info1");
  2188. try_lo_send(pData->oscData->target, targetPath, "iiiih", static_cast<int32_t>(pluginId), static_cast<int32_t>(type), static_cast<int32_t>(category), static_cast<int32_t>(hints), static_cast<int64_t>(uniqueId));
  2189. }
  2190. void CarlaEngine::oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept
  2191. {
  2192. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2193. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2194. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2195. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2196. CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',);
  2197. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',);
  2198. CARLA_SAFE_ASSERT_RETURN(maker != nullptr,);
  2199. CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,);
  2200. carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, \"%s\", \"%s\", \"%s\", \"%s\")", pluginId, realName, label, maker, copyright);
  2201. char targetPath[std::strlen(pData->oscData->path)+18];
  2202. std::strcpy(targetPath, pData->oscData->path);
  2203. std::strcat(targetPath, "/set_plugin_info2");
  2204. try_lo_send(pData->oscData->target, targetPath, "issss", static_cast<int32_t>(pluginId), realName, label, maker, copyright);
  2205. }
  2206. void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2207. {
  2208. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2209. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2210. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2211. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2212. carla_debug("CarlaEngine::oscSend_control_set_audio_count(%i, %i, %i)", pluginId, ins, outs);
  2213. char targetPath[std::strlen(pData->oscData->path)+18];
  2214. std::strcpy(targetPath, pData->oscData->path);
  2215. std::strcat(targetPath, "/set_audio_count");
  2216. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2217. }
  2218. void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2219. {
  2220. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2221. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2222. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2223. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2224. carla_debug("CarlaEngine::oscSend_control_set_midi_count(%i, %i, %i)", pluginId, ins, outs);
  2225. char targetPath[std::strlen(pData->oscData->path)+18];
  2226. std::strcpy(targetPath, pData->oscData->path);
  2227. std::strcat(targetPath, "/set_midi_count");
  2228. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2229. }
  2230. void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept
  2231. {
  2232. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2233. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2234. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2235. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2236. carla_debug("CarlaEngine::oscSend_control_set_parameter_count(%i, %i, %i)", pluginId, ins, outs);
  2237. char targetPath[std::strlen(pData->oscData->path)+18];
  2238. std::strcpy(targetPath, pData->oscData->path);
  2239. std::strcat(targetPath, "/set_parameter_count");
  2240. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(ins), static_cast<int32_t>(outs));
  2241. }
  2242. void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept
  2243. {
  2244. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2245. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2246. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2247. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2248. carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count);
  2249. char targetPath[std::strlen(pData->oscData->path)+19];
  2250. std::strcpy(targetPath, pData->oscData->path);
  2251. std::strcat(targetPath, "/set_program_count");
  2252. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2253. }
  2254. void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept
  2255. {
  2256. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2257. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2258. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2259. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2260. carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count);
  2261. char targetPath[std::strlen(pData->oscData->path)+24];
  2262. std::strcpy(targetPath, pData->oscData->path);
  2263. std::strcat(targetPath, "/set_midi_program_count");
  2264. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), static_cast<int32_t>(count));
  2265. }
  2266. void CarlaEngine::oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept
  2267. {
  2268. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2269. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2270. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2271. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2272. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  2273. CARLA_SAFE_ASSERT_RETURN(unit != nullptr,);
  2274. carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", pluginId, index, type, ParameterType2Str(type), hints, name, unit);
  2275. char targetPath[std::strlen(pData->oscData->path)+20];
  2276. std::strcpy(targetPath, pData->oscData->path);
  2277. std::strcat(targetPath, "/set_parameter_data");
  2278. try_lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(type), static_cast<int32_t>(hints), name, unit);
  2279. }
  2280. void CarlaEngine::oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept
  2281. {
  2282. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2283. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2284. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2285. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2286. CARLA_SAFE_ASSERT_RETURN(def <= min && def >= max,);
  2287. CARLA_SAFE_ASSERT_RETURN(min < max,);
  2288. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges1(%i, %i, %f, %f, %f)", pluginId, index, def, min, max, def);
  2289. char targetPath[std::strlen(pData->oscData->path)+23];
  2290. std::strcpy(targetPath, pData->oscData->path);
  2291. std::strcat(targetPath, "/set_parameter_ranges1");
  2292. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), def, min, max);
  2293. }
  2294. void CarlaEngine::oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept
  2295. {
  2296. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2297. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2298. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2299. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2300. CARLA_SAFE_ASSERT_RETURN(step <= stepSmall && step >= stepLarge,);
  2301. CARLA_SAFE_ASSERT_RETURN(stepSmall <= stepLarge,);
  2302. carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges2(%i, %i, %f, %f, %f)", pluginId, index, step, stepSmall, stepLarge);
  2303. char targetPath[std::strlen(pData->oscData->path)+23];
  2304. std::strcpy(targetPath, pData->oscData->path);
  2305. std::strcat(targetPath, "/set_parameter_ranges");
  2306. try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), step, stepSmall, stepLarge);
  2307. }
  2308. void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept
  2309. {
  2310. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2311. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2312. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2313. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2314. CARLA_SAFE_ASSERT_RETURN(cc <= 0x5F,);
  2315. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  2316. char targetPath[std::strlen(pData->oscData->path)+23];
  2317. std::strcpy(targetPath, pData->oscData->path);
  2318. std::strcat(targetPath, "/set_parameter_midi_cc");
  2319. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(cc));
  2320. }
  2321. void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept
  2322. {
  2323. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2324. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2325. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2326. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2327. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2328. carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  2329. char targetPath[std::strlen(pData->oscData->path)+28];
  2330. std::strcpy(targetPath, pData->oscData->path);
  2331. std::strcat(targetPath, "/set_parameter_midi_channel");
  2332. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(channel));
  2333. }
  2334. void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept
  2335. {
  2336. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2337. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2338. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2339. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2340. CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,);
  2341. carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i:%s, %f)", pluginId, index, (index < 0) ? InternalParameterIndex2Str(static_cast<InternalParameterIndex>(index)) : "(none)", value);
  2342. char targetPath[std::strlen(pData->oscData->path)+21];
  2343. std::strcpy(targetPath, pData->oscData->path);
  2344. std::strcat(targetPath, "/set_parameter_value");
  2345. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), index, value);
  2346. }
  2347. void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept
  2348. {
  2349. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2350. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2351. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2352. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2353. carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value);
  2354. char targetPath[std::strlen(pData->oscData->path)+19];
  2355. std::strcpy(targetPath, pData->oscData->path);
  2356. std::strcat(targetPath, "/set_default_value");
  2357. try_lo_send(pData->oscData->target, targetPath, "iif", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), value);
  2358. }
  2359. void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept
  2360. {
  2361. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2362. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2363. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2364. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2365. carla_debug("CarlaEngine::oscSend_control_set_current_program(%i, %i)", pluginId, index);
  2366. char targetPath[std::strlen(pData->oscData->path)+21];
  2367. std::strcpy(targetPath, pData->oscData->path);
  2368. std::strcat(targetPath, "/set_current_program");
  2369. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2370. }
  2371. void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept
  2372. {
  2373. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2374. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2375. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2376. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2377. carla_debug("CarlaEngine::oscSend_control_set_current_midi_program(%i, %i)", pluginId, index);
  2378. char targetPath[std::strlen(pData->oscData->path)+26];
  2379. std::strcpy(targetPath, pData->oscData->path);
  2380. std::strcat(targetPath, "/set_current_midi_program");
  2381. try_lo_send(pData->oscData->target, targetPath, "ii", static_cast<int32_t>(pluginId), index);
  2382. }
  2383. void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept
  2384. {
  2385. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2386. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2387. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2388. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2389. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2390. carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  2391. char targetPath[std::strlen(pData->oscData->path)+18];
  2392. std::strcpy(targetPath, pData->oscData->path);
  2393. std::strcat(targetPath, "/set_program_name");
  2394. try_lo_send(pData->oscData->target, targetPath, "iis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), name);
  2395. }
  2396. void CarlaEngine::oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept
  2397. {
  2398. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2399. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2400. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2401. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2402. CARLA_SAFE_ASSERT_RETURN(name != nullptr,);
  2403. carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  2404. char targetPath[std::strlen(pData->oscData->path)+23];
  2405. std::strcpy(targetPath, pData->oscData->path);
  2406. std::strcat(targetPath, "/set_midi_program_data");
  2407. try_lo_send(pData->oscData->target, targetPath, "iiiis", static_cast<int32_t>(pluginId), static_cast<int32_t>(index), static_cast<int32_t>(bank), static_cast<int32_t>(program), name);
  2408. }
  2409. void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept
  2410. {
  2411. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2412. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2413. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2414. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2415. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2416. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2417. CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,);
  2418. carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  2419. char targetPath[std::strlen(pData->oscData->path)+9];
  2420. std::strcpy(targetPath, pData->oscData->path);
  2421. std::strcat(targetPath, "/note_on");
  2422. try_lo_send(pData->oscData->target, targetPath, "iiii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note), static_cast<int32_t>(velo));
  2423. }
  2424. void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept
  2425. {
  2426. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2427. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2428. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2429. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2430. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  2431. CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,);
  2432. carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note);
  2433. char targetPath[std::strlen(pData->oscData->path)+10];
  2434. std::strcpy(targetPath, pData->oscData->path);
  2435. std::strcat(targetPath, "/note_off");
  2436. try_lo_send(pData->oscData->target, targetPath, "iii", static_cast<int32_t>(pluginId), static_cast<int32_t>(channel), static_cast<int32_t>(note));
  2437. }
  2438. void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) const noexcept
  2439. {
  2440. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2441. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2442. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2443. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,);
  2444. // TODO - try and see if we can get peaks[4] ref
  2445. const EnginePluginData& epData(pData->plugins[pluginId]);
  2446. char targetPath[std::strlen(pData->oscData->path)+11];
  2447. std::strcpy(targetPath, pData->oscData->path);
  2448. std::strcat(targetPath, "/set_peaks");
  2449. try_lo_send(pData->oscData->target, targetPath, "iffff", static_cast<int32_t>(pluginId), epData.insPeak[0], epData.insPeak[1], epData.outsPeak[0], epData.outsPeak[1]);
  2450. }
  2451. void CarlaEngine::oscSend_control_exit() const noexcept
  2452. {
  2453. CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,);
  2454. CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',);
  2455. CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,);
  2456. carla_debug("CarlaEngine::oscSend_control_exit()");
  2457. char targetPath[std::strlen(pData->oscData->path)+6];
  2458. std::strcpy(targetPath, pData->oscData->path);
  2459. std::strcat(targetPath, "/exit");
  2460. try_lo_send(pData->oscData->target, targetPath, "");
  2461. }
  2462. #endif
  2463. // -----------------------------------------------------------------------
  2464. #undef CARLA_SAFE_ASSERT_RETURN_ERR
  2465. CARLA_BACKEND_END_NAMESPACE