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.

3046 lines
105KB

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