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.

2192 lines
69KB

  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 GPL.txt file
  16. */
  17. #include "CarlaEngineInternal.hpp"
  18. #include "CarlaBackendUtils.hpp"
  19. #include "CarlaStateUtils.hpp"
  20. #include "CarlaMIDI.h"
  21. #include <QtCore/QDir>
  22. #include <QtCore/QFile>
  23. #include <QtCore/QFileInfo>
  24. #include <QtCore/QTextStream>
  25. CARLA_BACKEND_START_NAMESPACE
  26. // -------------------------------------------------------------------------------------------------------------------
  27. // Carla Engine port (Abstract)
  28. CarlaEnginePort::CarlaEnginePort(const bool isInput, const ProcessMode processMode)
  29. : kIsInput(isInput),
  30. kProcessMode(processMode)
  31. {
  32. carla_debug("CarlaEnginePort::CarlaEnginePort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  33. }
  34. CarlaEnginePort::~CarlaEnginePort()
  35. {
  36. carla_debug("CarlaEnginePort::~CarlaEnginePort()");
  37. }
  38. // -------------------------------------------------------------------------------------------------------------------
  39. // Carla Engine Audio port
  40. CarlaEngineAudioPort::CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode)
  41. : CarlaEnginePort(isInput, processMode),
  42. fBuffer(nullptr)
  43. {
  44. carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  45. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  46. fBuffer = new float[PATCHBAY_BUFFER_SIZE];
  47. }
  48. CarlaEngineAudioPort::~CarlaEngineAudioPort()
  49. {
  50. carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()");
  51. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  52. {
  53. CARLA_ASSERT(fBuffer != nullptr);
  54. if (fBuffer != nullptr)
  55. delete[] fBuffer;
  56. }
  57. }
  58. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const)
  59. {
  60. if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  61. carla_zeroFloat(fBuffer, PATCHBAY_BUFFER_SIZE);
  62. }
  63. // -------------------------------------------------------------------------------------------------------------------
  64. // Carla Engine Event port
  65. static const EngineEvent kFallbackEngineEvent;
  66. CarlaEngineEventPort::CarlaEngineEventPort(const bool isInput, const ProcessMode processMode)
  67. : CarlaEnginePort(isInput, processMode),
  68. kMaxEventCount(processMode == PROCESS_MODE_CONTINUOUS_RACK ? RACK_EVENT_COUNT : PATCHBAY_EVENT_COUNT),
  69. fBuffer(nullptr)
  70. {
  71. carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  72. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  73. fBuffer = new EngineEvent[PATCHBAY_EVENT_COUNT];
  74. }
  75. CarlaEngineEventPort::~CarlaEngineEventPort()
  76. {
  77. carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()");
  78. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  79. {
  80. CARLA_ASSERT(fBuffer != nullptr);
  81. if (fBuffer != nullptr)
  82. delete[] fBuffer;
  83. }
  84. }
  85. void CarlaEngineEventPort::initBuffer(CarlaEngine* const engine)
  86. {
  87. CARLA_ASSERT(engine != nullptr);
  88. if (engine == nullptr)
  89. return;
  90. #ifndef BUILD_BRIDGE
  91. if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK)
  92. fBuffer = engine->getRackEventBuffer(kIsInput);
  93. else if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  94. carla_zeroMem(fBuffer, sizeof(EngineEvent)*PATCHBAY_EVENT_COUNT);
  95. #endif
  96. }
  97. uint32_t CarlaEngineEventPort::getEventCount()
  98. {
  99. CARLA_ASSERT(kIsInput);
  100. CARLA_ASSERT(fBuffer != nullptr);
  101. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY);
  102. if (! kIsInput)
  103. return 0;
  104. if (fBuffer == nullptr)
  105. return 0;
  106. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY)
  107. return 0;
  108. uint32_t count = 0;
  109. const EngineEvent* const events = fBuffer;
  110. for (uint32_t i=0; i < kMaxEventCount; i++, count++)
  111. {
  112. if (events[i].type == kEngineEventTypeNull)
  113. break;
  114. }
  115. return count;
  116. }
  117. const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index)
  118. {
  119. CARLA_ASSERT(kIsInput);
  120. CARLA_ASSERT(fBuffer != nullptr);
  121. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY);
  122. CARLA_ASSERT(index < kMaxEventCount);
  123. if (! kIsInput)
  124. return kFallbackEngineEvent;
  125. if (fBuffer == nullptr)
  126. return kFallbackEngineEvent;
  127. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY)
  128. return kFallbackEngineEvent;
  129. if (index >= kMaxEventCount)
  130. return kFallbackEngineEvent;
  131. return fBuffer[index];
  132. }
  133. void CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const double value)
  134. {
  135. CARLA_ASSERT(! kIsInput);
  136. CARLA_ASSERT(fBuffer != nullptr);
  137. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY);
  138. CARLA_ASSERT(type != kEngineControlEventTypeNull);
  139. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  140. CARLA_SAFE_ASSERT(value >= 0.0 && value <= 1.0);
  141. if (kIsInput)
  142. return;
  143. if (fBuffer == nullptr)
  144. return;
  145. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY)
  146. return;
  147. if (type == kEngineControlEventTypeNull)
  148. return;
  149. if (channel >= MAX_MIDI_CHANNELS)
  150. return;
  151. if (type == kEngineControlEventTypeParameter)
  152. {
  153. CARLA_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param));
  154. }
  155. for (uint32_t i=0; i < kMaxEventCount; i++)
  156. {
  157. if (fBuffer[i].type != kEngineEventTypeNull)
  158. continue;
  159. fBuffer[i].type = kEngineEventTypeControl;
  160. fBuffer[i].time = time;
  161. fBuffer[i].channel = channel;
  162. fBuffer[i].ctrl.type = type;
  163. fBuffer[i].ctrl.param = param;
  164. fBuffer[i].ctrl.value = carla_fixValue<double>(0.0, 1.0, value);
  165. return;
  166. }
  167. carla_stderr2("CarlaEngineEventPort::writeControlEvent() - buffer full");
  168. }
  169. void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t* const data, const uint8_t size)
  170. {
  171. CARLA_ASSERT(! kIsInput);
  172. CARLA_ASSERT(fBuffer != nullptr);
  173. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY);
  174. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  175. CARLA_ASSERT(data != nullptr);
  176. CARLA_ASSERT(size > 0);
  177. if (kIsInput)
  178. return;
  179. if (fBuffer == nullptr)
  180. return;
  181. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY)
  182. return;
  183. if (channel >= MAX_MIDI_CHANNELS)
  184. return;
  185. if (data == nullptr)
  186. return;
  187. if (size == 0)
  188. return;
  189. if (size > 3)
  190. return;
  191. for (uint32_t i=0; i < kMaxEventCount; i++)
  192. {
  193. if (fBuffer[i].type != kEngineEventTypeNull)
  194. continue;
  195. fBuffer[i].type = kEngineEventTypeMidi;
  196. fBuffer[i].time = time;
  197. fBuffer[i].channel = channel;
  198. fBuffer[i].midi.port = port;
  199. fBuffer[i].midi.data[0] = data[0];
  200. fBuffer[i].midi.data[1] = data[1];
  201. fBuffer[i].midi.data[2] = data[2];
  202. fBuffer[i].midi.size = size;
  203. return;
  204. }
  205. carla_stderr2("CarlaEngineEventPort::writeMidiEvent() - buffer full");
  206. }
  207. // -------------------------------------------------------------------------------------------------------------------
  208. // Carla Engine client (Abstract)
  209. CarlaEngineClient::CarlaEngineClient(const EngineType engineType, const ProcessMode processMode)
  210. : kEngineType(engineType),
  211. kProcessMode(processMode),
  212. fActive(false),
  213. fLatency(0)
  214. {
  215. carla_debug("CarlaEngineClient::CarlaEngineClient(%s, %s)", EngineType2Str(engineType), ProcessMode2Str(processMode));
  216. CARLA_ASSERT(engineType != kEngineTypeNull);
  217. }
  218. CarlaEngineClient::~CarlaEngineClient()
  219. {
  220. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  221. CARLA_ASSERT(! fActive);
  222. }
  223. void CarlaEngineClient::activate()
  224. {
  225. carla_debug("CarlaEngineClient::activate()");
  226. CARLA_ASSERT(! fActive);
  227. fActive = true;
  228. }
  229. void CarlaEngineClient::deactivate()
  230. {
  231. carla_debug("CarlaEngineClient::deactivate()");
  232. CARLA_ASSERT(fActive);
  233. fActive = false;
  234. }
  235. bool CarlaEngineClient::isActive() const
  236. {
  237. carla_debug("CarlaEngineClient::isActive()");
  238. return fActive;
  239. }
  240. bool CarlaEngineClient::isOk() const
  241. {
  242. carla_debug("CarlaEngineClient::isOk()");
  243. return true;
  244. }
  245. uint32_t CarlaEngineClient::getLatency() const
  246. {
  247. return fLatency;
  248. }
  249. void CarlaEngineClient::setLatency(const uint32_t samples)
  250. {
  251. fLatency = samples;
  252. }
  253. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  254. {
  255. carla_debug("CarlaEngineClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput));
  256. switch (portType)
  257. {
  258. case kEnginePortTypeNull:
  259. break;
  260. case kEnginePortTypeAudio:
  261. return new CarlaEngineAudioPort(isInput, kProcessMode);
  262. case kEnginePortTypeEvent:
  263. return new CarlaEngineEventPort(isInput, kProcessMode);
  264. }
  265. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  266. return nullptr;
  267. }
  268. // -------------------------------------------------------------------------------------------------------------------
  269. // Carla Engine
  270. CarlaEngine::CarlaEngine()
  271. : fBufferSize(0),
  272. fSampleRate(0.0),
  273. kData(new CarlaEngineProtectedData(this))
  274. {
  275. carla_debug("CarlaEngine::CarlaEngine()");
  276. }
  277. CarlaEngine::~CarlaEngine()
  278. {
  279. carla_debug("CarlaEngine::~CarlaEngine()");
  280. delete kData;
  281. }
  282. // -----------------------------------------------------------------------
  283. // Helpers
  284. void doIdle(CarlaEngineProtectedData* const kData, const bool unlock)
  285. {
  286. kData->nextAction.opcode = EnginePostActionNull;
  287. if (unlock)
  288. kData->nextAction.mutex.unlock();
  289. }
  290. void doPluginRemove(CarlaEngineProtectedData* const kData, const bool unlock)
  291. {
  292. CARLA_ASSERT(kData->curPluginCount > 0);
  293. kData->curPluginCount--;
  294. const unsigned int id = kData->nextAction.pluginId;
  295. // reset current plugin
  296. kData->plugins[id].plugin = nullptr;
  297. CarlaPlugin* plugin;
  298. // move all plugins 1 spot backwards
  299. for (unsigned int i=id; i < kData->curPluginCount; i++)
  300. {
  301. plugin = kData->plugins[i+1].plugin;
  302. CARLA_ASSERT(plugin);
  303. if (plugin == nullptr)
  304. break;
  305. plugin->setId(i);
  306. kData->plugins[i].plugin = plugin;
  307. kData->plugins[i].insPeak[0] = 0.0f;
  308. kData->plugins[i].insPeak[1] = 0.0f;
  309. kData->plugins[i].outsPeak[0] = 0.0f;
  310. kData->plugins[i].outsPeak[1] = 0.0f;
  311. }
  312. kData->nextAction.opcode = EnginePostActionNull;
  313. if (unlock)
  314. kData->nextAction.mutex.unlock();
  315. }
  316. const char* findDSSIGUI(const char* const filename, const char* const label)
  317. {
  318. QString guiFilename;
  319. guiFilename.clear();
  320. QString pluginDir(filename);
  321. pluginDir.resize(pluginDir.lastIndexOf("."));
  322. QString shortName = QFileInfo(pluginDir).baseName();
  323. QString checkLabel = QString(label);
  324. QString checkSName = shortName;
  325. if (! checkLabel.endsWith("_")) checkLabel += "_";
  326. if (! checkSName.endsWith("_")) checkSName += "_";
  327. QStringList guiFiles = QDir(pluginDir).entryList();
  328. foreach (const QString& gui, guiFiles)
  329. {
  330. if (gui.startsWith(checkLabel) || gui.startsWith(checkSName))
  331. {
  332. QFileInfo finalname(pluginDir + QDir::separator() + gui);
  333. guiFilename = finalname.absoluteFilePath();
  334. break;
  335. }
  336. }
  337. if (guiFilename.isEmpty())
  338. return nullptr;
  339. return carla_strdup(guiFilename.toUtf8().constData());
  340. }
  341. // -----------------------------------------------------------------------
  342. // Static values and calls
  343. unsigned int CarlaEngine::getDriverCount()
  344. {
  345. carla_debug("CarlaEngine::getDriverCount()");
  346. unsigned int count = 0;
  347. #ifdef WANT_JACK
  348. count += 1;
  349. #endif
  350. #ifdef WANT_RTAUDIO
  351. count += getRtAudioApiCount();
  352. #endif
  353. return count;
  354. }
  355. const char* CarlaEngine::getDriverName(unsigned int index)
  356. {
  357. carla_debug("CarlaEngine::getDriverName(%i)", index);
  358. #ifdef WANT_JACK
  359. if (index == 0)
  360. return "JACK";
  361. else
  362. index -= 1;
  363. #endif
  364. #ifdef WANT_RTAUDIO
  365. if (index < getRtAudioApiCount())
  366. return getRtAudioApiName(index);
  367. #endif
  368. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
  369. return nullptr;
  370. }
  371. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  372. {
  373. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  374. #ifdef WANT_JACK
  375. if (std::strcmp(driverName, "JACK") == 0)
  376. return newJack();
  377. #else
  378. if (false)
  379. pass();
  380. #endif
  381. #ifdef WANT_RTAUDIO
  382. # ifdef __LINUX_ALSA__
  383. else if (std::strcmp(driverName, "ALSA") == 0)
  384. return newRtAudio(RTAUDIO_LINUX_ALSA);
  385. # endif
  386. # ifdef __LINUX_PULSE__
  387. else if (std::strcmp(driverName, "PulseAudio") == 0)
  388. return newRtAudio(RTAUDIO_LINUX_PULSE);
  389. # endif
  390. # ifdef __LINUX_OSS__
  391. else if (std::strcmp(driverName, "OSS") == 0)
  392. return newRtAudio(RTAUDIO_LINUX_OSS);
  393. # endif
  394. # ifdef __UNIX_JACK__
  395. else if (std::strcmp(driverName, "JACK (RtAudio)") == 0)
  396. return newRtAudio(RTAUDIO_UNIX_JACK);
  397. # endif
  398. # ifdef __MACOSX_CORE__
  399. else if (std::strcmp(driverName, "CoreAudio") == 0)
  400. return newRtAudio(RTAUDIO_MACOSX_CORE);
  401. # endif
  402. # ifdef __WINDOWS_ASIO__
  403. else if (std::strcmp(driverName, "ASIO") == 0)
  404. return newRtAudio(RTAUDIO_WINDOWS_ASIO);
  405. # endif
  406. # ifdef __WINDOWS_DS__
  407. else if (std::strcmp(driverName, "DirectSound") == 0)
  408. return newRtAudio(RTAUDIO_WINDOWS_DS);
  409. # endif
  410. #endif
  411. return nullptr;
  412. }
  413. // -----------------------------------------------------------------------
  414. // Maximum values
  415. unsigned int CarlaEngine::maxClientNameSize() const
  416. {
  417. return STR_MAX/2;
  418. }
  419. unsigned int CarlaEngine::maxPortNameSize() const
  420. {
  421. return STR_MAX;
  422. }
  423. unsigned int CarlaEngine::currentPluginCount() const
  424. {
  425. return kData->curPluginCount;
  426. }
  427. unsigned int CarlaEngine::maxPluginNumber() const
  428. {
  429. return kData->maxPluginNumber;
  430. }
  431. // -----------------------------------------------------------------------
  432. // Virtual, per-engine type calls
  433. bool CarlaEngine::init(const char* const clientName)
  434. {
  435. carla_debug("CarlaEngine::init(\"%s\")", clientName);
  436. CARLA_ASSERT(kData->plugins == nullptr);
  437. fName = clientName;
  438. fName.toBasic();
  439. fTimeInfo.clear();
  440. kData->aboutToClose = false;
  441. kData->curPluginCount = 0;
  442. switch (fOptions.processMode)
  443. {
  444. case PROCESS_MODE_CONTINUOUS_RACK:
  445. kData->maxPluginNumber = MAX_RACK_PLUGINS;
  446. kData->rack.in = new EngineEvent[RACK_EVENT_COUNT];
  447. kData->rack.out = new EngineEvent[RACK_EVENT_COUNT];
  448. break;
  449. case PROCESS_MODE_PATCHBAY:
  450. kData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
  451. break;
  452. case PROCESS_MODE_BRIDGE:
  453. kData->maxPluginNumber = 1;
  454. break;
  455. default:
  456. kData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
  457. break;
  458. }
  459. kData->plugins = new EnginePluginData[kData->maxPluginNumber];
  460. kData->osc.init(clientName);
  461. #ifndef BUILD_BRIDGE
  462. kData->oscData = kData->osc.getControlData();
  463. #else
  464. kData->oscData = nullptr; // set later in setOscBridgeData()
  465. #endif
  466. #ifndef BUILD_BRIDGE
  467. //if (std::strcmp(clientName, "Carla") != 0)
  468. carla_setprocname(clientName);
  469. #endif
  470. kData->nextAction.ready();
  471. kData->thread.startNow();
  472. return true;
  473. }
  474. bool CarlaEngine::close()
  475. {
  476. carla_debug("CarlaEngine::close()");
  477. CARLA_ASSERT(kData->plugins != nullptr);
  478. kData->nextAction.ready();
  479. kData->thread.stopNow();
  480. #ifndef BUILD_BRIDGE
  481. osc_send_control_exit();
  482. #endif
  483. kData->osc.close();
  484. kData->oscData = nullptr;
  485. kData->aboutToClose = true;
  486. kData->curPluginCount = 0;
  487. kData->maxPluginNumber = 0;
  488. if (kData->plugins != nullptr)
  489. {
  490. delete[] kData->plugins;
  491. kData->plugins = nullptr;
  492. }
  493. if (kData->rack.in != nullptr)
  494. {
  495. delete[] kData->rack.in;
  496. kData->rack.in = nullptr;
  497. }
  498. if (kData->rack.out != nullptr)
  499. {
  500. delete[] kData->rack.out;
  501. kData->rack.out = nullptr;
  502. }
  503. fName.clear();
  504. return true;
  505. }
  506. void CarlaEngine::idle()
  507. {
  508. CARLA_ASSERT(kData->plugins != nullptr);
  509. CARLA_ASSERT(isRunning());
  510. for (unsigned int i=0; i < kData->curPluginCount; i++)
  511. {
  512. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  513. if (plugin && plugin->enabled())
  514. plugin->idleGui();
  515. }
  516. }
  517. // -----------------------------------------------------------------------
  518. // Virtual, per-engine type calls
  519. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  520. {
  521. return new CarlaEngineClient(type(), fOptions.processMode);
  522. }
  523. // -----------------------------------------------------------------------
  524. // Plugin management
  525. 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)
  526. {
  527. carla_debug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra);
  528. CARLA_ASSERT(btype != BINARY_NONE);
  529. CARLA_ASSERT(ptype != PLUGIN_NONE);
  530. if (kData->curPluginCount == kData->maxPluginNumber)
  531. {
  532. setLastError("Maximum number of plugins reached");
  533. return false;
  534. }
  535. const unsigned int id = kData->curPluginCount;
  536. CarlaPlugin::Initializer init = {
  537. this,
  538. id,
  539. filename,
  540. name,
  541. label
  542. };
  543. CarlaPlugin* plugin = nullptr;
  544. #ifndef BUILD_BRIDGE
  545. const char* bridgeBinary;
  546. switch (btype)
  547. {
  548. case BINARY_POSIX32:
  549. bridgeBinary = fOptions.bridge_posix32.isNotEmpty() ? (const char*)fOptions.bridge_posix32 : nullptr;
  550. break;
  551. case BINARY_POSIX64:
  552. bridgeBinary = fOptions.bridge_posix64.isNotEmpty() ? (const char*)fOptions.bridge_posix64 : nullptr;
  553. break;
  554. case BINARY_WIN32:
  555. bridgeBinary = fOptions.bridge_win32.isNotEmpty() ? (const char*)fOptions.bridge_win32 : nullptr;
  556. break;
  557. case BINARY_WIN64:
  558. bridgeBinary = fOptions.bridge_win64.isNotEmpty() ? (const char*)fOptions.bridge_win64 : nullptr;
  559. break;
  560. default:
  561. bridgeBinary = nullptr;
  562. break;
  563. }
  564. #ifndef Q_OS_WIN
  565. if (btype == BINARY_NATIVE && fOptions.bridge_native.isNotEmpty())
  566. bridgeBinary = (const char*)fOptions.bridge_native;
  567. #endif
  568. if (fOptions.preferPluginBridges && bridgeBinary != nullptr)
  569. {
  570. // TODO
  571. if (fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  572. {
  573. setLastError("Can only use bridged plugins in JACK Multi-Client mode");
  574. return -1;
  575. }
  576. // TODO
  577. if (type() != kEngineTypeJack)
  578. {
  579. setLastError("Can only use bridged plugins with JACK backend");
  580. return -1;
  581. }
  582. #if 0
  583. plugin = CarlaPlugin::newBridge(init, btype, ptype, bridgeBinary);
  584. #endif
  585. setLastError("Bridged plugins are not implemented yet");
  586. }
  587. else
  588. #endif // BUILD_BRIDGE
  589. {
  590. switch (ptype)
  591. {
  592. case PLUGIN_NONE:
  593. break;
  594. case PLUGIN_INTERNAL:
  595. plugin = CarlaPlugin::newNative(init);
  596. break;
  597. case PLUGIN_LADSPA:
  598. plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra);
  599. break;
  600. case PLUGIN_DSSI:
  601. plugin = CarlaPlugin::newDSSI(init, (const char*)extra);
  602. break;
  603. case PLUGIN_LV2:
  604. plugin = CarlaPlugin::newLV2(init);
  605. break;
  606. case PLUGIN_VST:
  607. plugin = CarlaPlugin::newVST(init);
  608. break;
  609. case PLUGIN_GIG:
  610. plugin = CarlaPlugin::newGIG(init);
  611. break;
  612. case PLUGIN_SF2:
  613. plugin = CarlaPlugin::newSF2(init, (extra != nullptr));
  614. break;
  615. case PLUGIN_SFZ:
  616. plugin = CarlaPlugin::newSFZ(init);
  617. break;
  618. }
  619. }
  620. if (plugin == nullptr)
  621. return false;
  622. plugin->registerToOscClient();
  623. kData->plugins[id].plugin = plugin;
  624. kData->plugins[id].insPeak[0] = 0.0f;
  625. kData->plugins[id].insPeak[1] = 0.0f;
  626. kData->plugins[id].outsPeak[0] = 0.0f;
  627. kData->plugins[id].outsPeak[1] = 0.0f;
  628. kData->curPluginCount += 1;
  629. // FIXME
  630. callback(CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, nullptr);
  631. return true;
  632. }
  633. bool CarlaEngine::removePlugin(const unsigned int id)
  634. {
  635. carla_debug("CarlaEngine::removePlugin(%i)", id);
  636. CARLA_ASSERT(kData->curPluginCount > 0);
  637. CARLA_ASSERT(id < kData->curPluginCount);
  638. CARLA_ASSERT(kData->plugins != nullptr);
  639. if (kData->plugins == nullptr)
  640. {
  641. setLastError("Critical error: no plugins are currently loaded!");
  642. return false;
  643. }
  644. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  645. CARLA_ASSERT(plugin != nullptr);
  646. if (plugin != nullptr)
  647. {
  648. CARLA_ASSERT(plugin->id() == id);
  649. kData->thread.stopNow();
  650. kData->nextAction.pluginId = id;
  651. kData->nextAction.opcode = EnginePostActionRemovePlugin;
  652. kData->nextAction.mutex.lock();
  653. if (isRunning())
  654. {
  655. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking START", id);
  656. // block wait for unlock on proccessing side
  657. kData->nextAction.mutex.lock();
  658. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking DONE", id);
  659. }
  660. else
  661. {
  662. doPluginRemove(kData, false);
  663. }
  664. #ifndef BUILD_BRIDGE
  665. if (isOscControlRegistered())
  666. osc_send_control_remove_plugin(id);
  667. #endif
  668. delete plugin;
  669. kData->nextAction.mutex.unlock();
  670. if (isRunning() && ! kData->aboutToClose)
  671. kData->thread.startNow();
  672. // FIXME
  673. callback(CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  674. return true;
  675. }
  676. carla_stderr("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  677. setLastError("Could not find plugin to remove");
  678. return false;
  679. }
  680. void CarlaEngine::removeAllPlugins()
  681. {
  682. carla_debug("CarlaEngine::removeAllPlugins()");
  683. kData->thread.stopNow();
  684. if (kData->curPluginCount > 0)
  685. {
  686. const unsigned int oldCount = kData->curPluginCount;
  687. kData->curPluginCount = 0;
  688. waitForProccessEnd(0); // FIXME - doesn't work for multi-client
  689. for (unsigned int i=0; i < oldCount; i++)
  690. {
  691. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  692. CARLA_ASSERT(plugin != nullptr);
  693. if (plugin != nullptr)
  694. delete plugin;
  695. // clear this plugin
  696. kData->plugins[i].plugin = nullptr;
  697. kData->plugins[i].insPeak[0] = 0.0;
  698. kData->plugins[i].insPeak[1] = 0.0;
  699. kData->plugins[i].outsPeak[0] = 0.0;
  700. kData->plugins[i].outsPeak[1] = 0.0;
  701. }
  702. }
  703. if (isRunning() && ! kData->aboutToClose)
  704. kData->thread.startNow();
  705. }
  706. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  707. {
  708. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, kData->curPluginCount);
  709. CARLA_ASSERT(kData->curPluginCount > 0);
  710. CARLA_ASSERT(id < kData->curPluginCount);
  711. CARLA_ASSERT(kData->plugins != nullptr);
  712. if (id < kData->curPluginCount && kData->plugins != nullptr)
  713. return kData->plugins[id].plugin;
  714. return nullptr;
  715. }
  716. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const
  717. {
  718. return kData->plugins[id].plugin;
  719. }
  720. const char* CarlaEngine::getNewUniquePluginName(const char* const name)
  721. {
  722. carla_debug("CarlaEngine::getNewUniquePluginName(\"%s\")", name);
  723. CARLA_ASSERT(kData->maxPluginNumber > 0);
  724. CARLA_ASSERT(kData->plugins != nullptr);
  725. CARLA_ASSERT(name != nullptr);
  726. static CarlaString sname;
  727. sname = name;
  728. if (sname.isEmpty() || kData->plugins == nullptr)
  729. {
  730. sname = "(No name)";
  731. return (const char*)sname;
  732. }
  733. sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  734. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  735. for (unsigned short i=0; i < kData->curPluginCount; i++)
  736. {
  737. CARLA_ASSERT(kData->plugins[i].plugin);
  738. if (kData->plugins[i].plugin == nullptr)
  739. continue;
  740. // Check if unique name doesn't exist
  741. if (const char* const pluginName = kData->plugins[i].plugin->name())
  742. {
  743. if (sname != pluginName)
  744. continue;
  745. }
  746. // Check if string has already been modified
  747. {
  748. const size_t len = sname.length();
  749. // 1 digit, ex: " (2)"
  750. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  751. {
  752. int number = sname[len-2] - '0';
  753. if (number == 9)
  754. {
  755. // next number is 10, 2 digits
  756. sname.truncate(len-4);
  757. sname += " (10)";
  758. //sname.replace(" (9)", " (10)");
  759. }
  760. else
  761. sname[len-2] = char('0' + number + 1);
  762. continue;
  763. }
  764. // 2 digits, ex: " (11)"
  765. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  766. {
  767. char n2 = sname[len-2];
  768. char n3 = sname[len-3];
  769. if (n2 == '9')
  770. {
  771. n2 = '0';
  772. n3 += 1;
  773. }
  774. else
  775. n2 += 1;
  776. sname[len-2] = n2;
  777. sname[len-3] = n3;
  778. continue;
  779. }
  780. }
  781. // Modify string if not
  782. sname += " (2)";
  783. }
  784. return (const char*)sname;
  785. }
  786. #if 0
  787. void CarlaEngine::__bridgePluginRegister(const unsigned short id, CarlaPlugin* const plugin)
  788. {
  789. data->carlaPlugins[id] = plugin;
  790. }
  791. #endif
  792. // -----------------------------------------------------------------------
  793. // Information (base)
  794. bool CarlaEngine::loadProject(const char* const filename)
  795. {
  796. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  797. CARLA_ASSERT(filename != nullptr);
  798. QFile file(filename);
  799. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  800. return false;
  801. QDomDocument xml;
  802. xml.setContent(file.readAll());
  803. file.close();
  804. QDomNode xmlNode(xml.documentElement());
  805. if (xmlNode.toElement().tagName() != "CARLA-PROJECT")
  806. {
  807. carla_stderr2("Not a valid Carla project file");
  808. return false;
  809. }
  810. QDomNode node(xmlNode.firstChild());
  811. while (! node.isNull())
  812. {
  813. if (node.toElement().tagName() == "Plugin")
  814. {
  815. const SaveState& saveState = getSaveStateDictFromXML(node);
  816. const void* extraStuff = nullptr;
  817. if (std::strcmp(saveState.type, "DSSI") == 0)
  818. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  819. // TODO - proper find&load plugins
  820. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  821. {
  822. if (CarlaPlugin* plugin = getPlugin(kData->curPluginCount-1))
  823. plugin->loadSaveState(saveState);
  824. }
  825. }
  826. node = node.nextSibling();
  827. }
  828. return true;
  829. }
  830. bool CarlaEngine::saveProject(const char* const filename)
  831. {
  832. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  833. CARLA_ASSERT(filename != nullptr);
  834. QFile file(filename);
  835. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  836. return false;
  837. QTextStream out(&file);
  838. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  839. out << "<!DOCTYPE CARLA-PROJECT>\n";
  840. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  841. bool firstPlugin = true;
  842. char strBuf[STR_MAX];
  843. for (unsigned int i=0; i < kData->curPluginCount; i++)
  844. {
  845. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  846. if (plugin != nullptr && plugin->enabled())
  847. {
  848. if (! firstPlugin)
  849. out << "\n";
  850. plugin->getRealName(strBuf);
  851. if (*strBuf != 0)
  852. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  853. out << " <Plugin>\n";
  854. out << getXMLFromSaveState(plugin->getSaveState());
  855. out << " </Plugin>\n";
  856. firstPlugin = false;
  857. }
  858. }
  859. out << "</CARLA-PROJECT>\n";
  860. file.close();
  861. return true;
  862. }
  863. // -----------------------------------------------------------------------
  864. // Information (peaks)
  865. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  866. {
  867. CARLA_ASSERT(pluginId < kData->curPluginCount);
  868. CARLA_ASSERT(id-1 < MAX_PEAKS);
  869. if (id > MAX_PEAKS)
  870. return 0.0f;
  871. return kData->plugins[pluginId].insPeak[id-1];
  872. }
  873. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  874. {
  875. CARLA_ASSERT(pluginId < kData->curPluginCount);
  876. CARLA_ASSERT(id-1 < MAX_PEAKS);
  877. if (id > MAX_PEAKS)
  878. return 0.0f;
  879. return kData->plugins[pluginId].outsPeak[id-1];
  880. }
  881. // -----------------------------------------------------------------------
  882. // Callback
  883. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  884. {
  885. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  886. if (kData->callback)
  887. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  888. }
  889. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  890. {
  891. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  892. CARLA_ASSERT(func);
  893. kData->callback = func;
  894. kData->callbackPtr = ptr;
  895. }
  896. // -----------------------------------------------------------------------
  897. // Transport
  898. void CarlaEngine::transportPlay()
  899. {
  900. kData->time.playing = true;
  901. }
  902. void CarlaEngine::transportPause()
  903. {
  904. kData->time.playing = false;
  905. }
  906. void CarlaEngine::transportRelocate(const uint32_t frame)
  907. {
  908. kData->time.frame = frame;
  909. }
  910. // -----------------------------------------------------------------------
  911. // Error handling
  912. const char* CarlaEngine::getLastError() const
  913. {
  914. return (const char*)kData->lastError;
  915. }
  916. void CarlaEngine::setLastError(const char* const error)
  917. {
  918. kData->lastError = error;
  919. }
  920. void CarlaEngine::setAboutToClose()
  921. {
  922. carla_debug("CarlaEngine::setAboutToClose()");
  923. kData->aboutToClose = true;
  924. }
  925. // -----------------------------------------------------------------------
  926. // Misc
  927. void CarlaEngine::waitForProccessEnd(const unsigned int pluginId)
  928. {
  929. carla_debug("CarlaEngine::waitForProccessEnd()");
  930. kData->nextAction.pluginId = pluginId;
  931. kData->nextAction.opcode = EnginePostActionIdle;
  932. kData->nextAction.mutex.lock();
  933. if (isRunning())
  934. {
  935. // block wait for unlock on proccessing side
  936. kData->nextAction.mutex.lock();
  937. }
  938. else
  939. {
  940. doIdle(kData, false);
  941. }
  942. kData->nextAction.mutex.unlock();
  943. }
  944. // -----------------------------------------------------------------------
  945. // Global options
  946. #ifndef BUILD_BRIDGE
  947. const QProcessEnvironment& CarlaEngine::getOptionsAsProcessEnvironment() const
  948. {
  949. return kData->procEnv;
  950. }
  951. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  952. if (isRunning()) \
  953. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  954. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  955. {
  956. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  957. switch (option)
  958. {
  959. case OPTION_PROCESS_NAME:
  960. carla_setprocname(valueStr);
  961. break;
  962. case OPTION_PROCESS_MODE:
  963. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  964. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_PATCHBAY)
  965. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  966. fOptions.processMode = static_cast<ProcessMode>(value);
  967. break;
  968. case OPTION_TRANSPORT_MODE:
  969. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_JACK)
  970. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  971. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  972. break;
  973. case OPTION_MAX_PARAMETERS:
  974. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  975. if (value < 0)
  976. return; // TODO error here
  977. fOptions.maxParameters = static_cast<uint>(value);
  978. break;
  979. case OPTION_PREFERRED_BUFFER_SIZE:
  980. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  981. fOptions.preferredBufferSize = static_cast<uint>(value);
  982. break;
  983. case OPTION_PREFERRED_SAMPLE_RATE:
  984. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  985. fOptions.preferredSampleRate = static_cast<uint>(value);
  986. break;
  987. case OPTION_FORCE_STEREO:
  988. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  989. fOptions.forceStereo = (value != 0);
  990. break;
  991. #ifdef WANT_DSSI
  992. case OPTION_USE_DSSI_VST_CHUNKS:
  993. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  994. fOptions.useDssiVstChunks = (value != 0);
  995. break;
  996. #endif
  997. case OPTION_PREFER_PLUGIN_BRIDGES:
  998. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  999. fOptions.preferPluginBridges = (value != 0);
  1000. break;
  1001. case OPTION_PREFER_UI_BRIDGES:
  1002. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1003. fOptions.preferUiBridges = (value != 0);
  1004. break;
  1005. case OPTION_OSC_UI_TIMEOUT:
  1006. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1007. fOptions.oscUiTimeout = static_cast<uint>(value);
  1008. break;
  1009. case OPTION_PATH_BRIDGE_NATIVE:
  1010. fOptions.bridge_native = valueStr;
  1011. break;
  1012. case OPTION_PATH_BRIDGE_POSIX32:
  1013. fOptions.bridge_posix32 = valueStr;
  1014. break;
  1015. case OPTION_PATH_BRIDGE_POSIX64:
  1016. fOptions.bridge_posix64 = valueStr;
  1017. break;
  1018. case OPTION_PATH_BRIDGE_WIN32:
  1019. fOptions.bridge_win32 = valueStr;
  1020. break;
  1021. case OPTION_PATH_BRIDGE_WIN64:
  1022. fOptions.bridge_win64 = valueStr;
  1023. break;
  1024. #ifdef WANT_LV2
  1025. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1026. fOptions.bridge_lv2gtk2 = valueStr;
  1027. break;
  1028. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1029. fOptions.bridge_lv2gtk3 = valueStr;
  1030. break;
  1031. case OPTION_PATH_BRIDGE_LV2_QT4:
  1032. fOptions.bridge_lv2qt4 = valueStr;
  1033. break;
  1034. case OPTION_PATH_BRIDGE_LV2_QT5:
  1035. fOptions.bridge_lv2qt5 = valueStr;
  1036. break;
  1037. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1038. fOptions.bridge_lv2cocoa = valueStr;
  1039. break;
  1040. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1041. fOptions.bridge_lv2win = valueStr;
  1042. break;
  1043. case OPTION_PATH_BRIDGE_LV2_X11:
  1044. fOptions.bridge_lv2x11 = valueStr;
  1045. break;
  1046. #endif
  1047. #ifdef WANT_VST
  1048. case OPTION_PATH_BRIDGE_VST_COCOA:
  1049. fOptions.bridge_vstcocoa = valueStr;
  1050. break;
  1051. case OPTION_PATH_BRIDGE_VST_HWND:
  1052. fOptions.bridge_vsthwnd = valueStr;
  1053. break;
  1054. case OPTION_PATH_BRIDGE_VST_X11:
  1055. fOptions.bridge_vstx11 = valueStr;
  1056. break;
  1057. #endif
  1058. }
  1059. }
  1060. #endif
  1061. // -----------------------------------------------------------------------
  1062. // OSC Stuff
  1063. #ifdef BUILD_BRIDGE
  1064. bool CarlaEngine::isOscBridgeRegistered() const
  1065. {
  1066. return (kData->oscData != nullptr);
  1067. }
  1068. #else
  1069. bool CarlaEngine::isOscControlRegistered() const
  1070. {
  1071. return kData->osc.isControlRegistered();
  1072. }
  1073. #endif
  1074. void CarlaEngine::idleOsc()
  1075. {
  1076. kData->osc.idle();
  1077. }
  1078. const char* CarlaEngine::getOscServerPathTCP() const
  1079. {
  1080. return kData->osc.getServerPathTCP();
  1081. }
  1082. const char* CarlaEngine::getOscServerPathUDP() const
  1083. {
  1084. return kData->osc.getServerPathUDP();
  1085. }
  1086. #ifdef BUILD_BRIDGE
  1087. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1088. {
  1089. kData->oscData = oscData;
  1090. }
  1091. #endif
  1092. // -----------------------------------------------------------------------
  1093. // protected calls
  1094. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1095. {
  1096. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1097. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1098. {
  1099. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1100. if (plugin != nullptr && plugin->enabled())
  1101. plugin->bufferSizeChanged(newBufferSize);
  1102. }
  1103. }
  1104. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1105. {
  1106. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1107. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1108. {
  1109. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1110. if (plugin != nullptr && plugin->enabled())
  1111. plugin->sampleRateChanged(newSampleRate);
  1112. }
  1113. }
  1114. void CarlaEngine::proccessPendingEvents()
  1115. {
  1116. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1117. switch (kData->nextAction.opcode)
  1118. {
  1119. case EnginePostActionNull:
  1120. break;
  1121. case EnginePostActionIdle:
  1122. doIdle(kData, true);
  1123. break;
  1124. case EnginePostActionRemovePlugin:
  1125. doPluginRemove(kData, true);
  1126. break;
  1127. }
  1128. if (kData->time.playing)
  1129. kData->time.frame += fBufferSize;
  1130. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1131. {
  1132. fTimeInfo.playing = kData->time.playing;
  1133. fTimeInfo.frame = kData->time.frame;
  1134. }
  1135. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1136. {
  1137. // TODO - peak values?
  1138. }
  1139. }
  1140. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS])
  1141. {
  1142. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1143. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1144. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1145. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1146. }
  1147. #ifndef BUILD_BRIDGE
  1148. EngineEvent* CarlaEngine::getRackEventBuffer(const bool isInput)
  1149. {
  1150. return isInput ? kData->rack.in : kData->rack.out;
  1151. }
  1152. void setValueIfHigher(float& value, const float& compare)
  1153. {
  1154. if (value < compare)
  1155. value = compare;
  1156. }
  1157. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1158. {
  1159. // initialize outputs (zero)
  1160. carla_zeroFloat(outBuf[0], frames);
  1161. carla_zeroFloat(outBuf[1], frames);
  1162. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1163. bool processed = false;
  1164. // process plugins
  1165. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1166. {
  1167. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1168. if (plugin == nullptr || ! plugin->enabled())
  1169. continue;
  1170. if (processed)
  1171. {
  1172. // initialize inputs (from previous outputs)
  1173. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1174. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1175. std::memcpy(kData->rack.in, kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1176. // initialize outputs (zero)
  1177. carla_zeroFloat(outBuf[0], frames);
  1178. carla_zeroFloat(outBuf[1], frames);
  1179. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1180. }
  1181. // process
  1182. plugin->initBuffers();
  1183. plugin->process(inBuf, outBuf, frames);
  1184. #if 0
  1185. // if plugin has no audio inputs, add previous buffers
  1186. if (plugin->audioInCount() == 0)
  1187. {
  1188. for (uint32_t j=0; j < frames; j++)
  1189. {
  1190. outBuf[0][j] += inBuf[0][j];
  1191. outBuf[1][j] += inBuf[1][j];
  1192. }
  1193. }
  1194. // if plugin has no midi output, add previous events
  1195. if (plugin->midiOutCount() == 0)
  1196. {
  1197. for (uint32_t j=0, k=0; j < frames; j++)
  1198. {
  1199. }
  1200. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1201. }
  1202. #endif
  1203. // set peaks
  1204. {
  1205. float inPeak1 = 0.0f;
  1206. float inPeak2 = 0.0f;
  1207. float outPeak1 = 0.0f;
  1208. float outPeak2 = 0.0f;
  1209. for (uint32_t k=0; k < frames; k++)
  1210. {
  1211. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1212. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1213. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1214. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1215. }
  1216. kData->plugins[i].insPeak[0] = inPeak1;
  1217. kData->plugins[i].insPeak[1] = inPeak2;
  1218. kData->plugins[i].outsPeak[0] = outPeak1;
  1219. kData->plugins[i].outsPeak[1] = outPeak2;
  1220. }
  1221. processed = true;
  1222. }
  1223. // if no plugins in the rack, copy inputs over outputs
  1224. if (! processed)
  1225. {
  1226. // FIXME
  1227. //carla_copyFloat(outBuf[0], inBuf[0], frames);
  1228. //carla_copyFloat(outBuf[1], inBuf[1], frames);
  1229. //std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1230. }
  1231. }
  1232. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1233. {
  1234. // TODO
  1235. return;
  1236. // unused, for now
  1237. (void)inBuf;
  1238. (void)outBuf;
  1239. (void)bufCount;
  1240. (void)frames;
  1241. }
  1242. #endif
  1243. // -------------------------------------------------------------------------------------------------------------------
  1244. // Carla Engine OSC stuff
  1245. #ifndef BUILD_BRIDGE
  1246. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1247. {
  1248. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1249. CARLA_ASSERT(kData->oscData != nullptr);
  1250. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1251. CARLA_ASSERT(pluginName);
  1252. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1253. {
  1254. char targetPath[std::strlen(kData->oscData->path)+18];
  1255. std::strcpy(targetPath, kData->oscData->path);
  1256. std::strcat(targetPath, "/add_plugin_start");
  1257. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1258. }
  1259. }
  1260. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1261. {
  1262. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1263. CARLA_ASSERT(kData->oscData != nullptr);
  1264. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1265. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1266. {
  1267. char targetPath[std::strlen(kData->oscData->path)+16];
  1268. std::strcpy(targetPath, kData->oscData->path);
  1269. std::strcat(targetPath, "/add_plugin_end");
  1270. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1271. }
  1272. }
  1273. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1274. {
  1275. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1276. CARLA_ASSERT(kData->oscData != nullptr);
  1277. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1278. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1279. {
  1280. char targetPath[std::strlen(kData->oscData->path)+15];
  1281. std::strcpy(targetPath, kData->oscData->path);
  1282. std::strcat(targetPath, "/remove_plugin");
  1283. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1284. }
  1285. }
  1286. void CarlaEngine::osc_send_control_set_plugin_data(const int32_t pluginId, const int32_t type, const int32_t category, const int32_t hints, const char* const realName, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1287. {
  1288. carla_debug("CarlaEngine::osc_send_control_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1289. CARLA_ASSERT(kData->oscData != nullptr);
  1290. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1291. CARLA_ASSERT(type != PLUGIN_NONE);
  1292. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1293. {
  1294. char targetPath[std::strlen(kData->oscData->path)+17];
  1295. std::strcpy(targetPath, kData->oscData->path);
  1296. std::strcat(targetPath, "/set_plugin_data");
  1297. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1298. }
  1299. }
  1300. void CarlaEngine::osc_send_control_set_plugin_ports(const int32_t pluginId, const int32_t audioIns, const int32_t audioOuts, const int32_t midiIns, const int32_t midiOuts, const int32_t cIns, const int32_t cOuts, const int32_t cTotals)
  1301. {
  1302. carla_debug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1303. CARLA_ASSERT(kData->oscData != nullptr);
  1304. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1305. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1306. {
  1307. char targetPath[std::strlen(kData->oscData->path)+18];
  1308. std::strcpy(targetPath, kData->oscData->path);
  1309. std::strcat(targetPath, "/set_plugin_ports");
  1310. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1311. }
  1312. }
  1313. void CarlaEngine::osc_send_control_set_parameter_data(const int32_t pluginId, const int32_t index, const int32_t type, const int32_t hints, const char* const name, const char* const label, const float current)
  1314. {
  1315. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1316. CARLA_ASSERT(kData->oscData != nullptr);
  1317. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1318. CARLA_ASSERT(index >= 0);
  1319. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1320. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1321. {
  1322. char targetPath[std::strlen(kData->oscData->path)+20];
  1323. std::strcpy(targetPath, kData->oscData->path);
  1324. std::strcat(targetPath, "/set_parameter_data");
  1325. lo_send(kData->oscData->target, targetPath, "iiiissd", pluginId, index, type, hints, name, label, current);
  1326. }
  1327. }
  1328. void CarlaEngine::osc_send_control_set_parameter_ranges(const int32_t pluginId, const int32_t index, const float min, const float max, const float def, const float step, const float stepSmall, const float stepLarge)
  1329. {
  1330. carla_debug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1331. CARLA_ASSERT(kData->oscData != nullptr);
  1332. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1333. CARLA_ASSERT(index >= 0);
  1334. CARLA_ASSERT(min < max);
  1335. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1336. {
  1337. char targetPath[std::strlen(kData->oscData->path)+22];
  1338. std::strcpy(targetPath, kData->oscData->path);
  1339. std::strcat(targetPath, "/set_parameter_ranges");
  1340. lo_send(kData->oscData->target, targetPath, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1341. }
  1342. }
  1343. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1344. {
  1345. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1346. CARLA_ASSERT(kData->oscData != nullptr);
  1347. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1348. CARLA_ASSERT(index >= 0);
  1349. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1350. {
  1351. char targetPath[std::strlen(kData->oscData->path)+23];
  1352. std::strcpy(targetPath, kData->oscData->path);
  1353. std::strcat(targetPath, "/set_parameter_midi_cc");
  1354. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1355. }
  1356. }
  1357. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1358. {
  1359. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1360. CARLA_ASSERT(kData->oscData != nullptr);
  1361. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1362. CARLA_ASSERT(index >= 0);
  1363. CARLA_ASSERT(channel >= 0 && channel < 16);
  1364. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1365. {
  1366. char targetPath[std::strlen(kData->oscData->path)+28];
  1367. std::strcpy(targetPath, kData->oscData->path);
  1368. std::strcat(targetPath, "/set_parameter_midi_channel");
  1369. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1370. }
  1371. }
  1372. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1373. {
  1374. #if DEBUG
  1375. if (index < 0)
  1376. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1377. else
  1378. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1379. #endif
  1380. CARLA_ASSERT(kData->oscData != nullptr);
  1381. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1382. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1383. {
  1384. char targetPath[std::strlen(kData->oscData->path)+21];
  1385. std::strcpy(targetPath, kData->oscData->path);
  1386. std::strcat(targetPath, "/set_parameter_value");
  1387. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1388. }
  1389. }
  1390. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1391. {
  1392. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1393. CARLA_ASSERT(kData->oscData != nullptr);
  1394. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1395. CARLA_ASSERT(index >= 0);
  1396. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1397. {
  1398. char targetPath[std::strlen(kData->oscData->path)+19];
  1399. std::strcpy(targetPath, kData->oscData->path);
  1400. std::strcat(targetPath, "/set_default_value");
  1401. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1402. }
  1403. }
  1404. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1405. {
  1406. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1407. CARLA_ASSERT(kData->oscData != nullptr);
  1408. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1409. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1410. {
  1411. char targetPath[std::strlen(kData->oscData->path)+13];
  1412. std::strcpy(targetPath, kData->oscData->path);
  1413. std::strcat(targetPath, "/set_program");
  1414. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1415. }
  1416. }
  1417. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1418. {
  1419. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1420. CARLA_ASSERT(kData->oscData != nullptr);
  1421. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1422. CARLA_ASSERT(count >= 0);
  1423. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1424. {
  1425. char targetPath[std::strlen(kData->oscData->path)+19];
  1426. std::strcpy(targetPath, kData->oscData->path);
  1427. std::strcat(targetPath, "/set_program_count");
  1428. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1429. }
  1430. }
  1431. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1432. {
  1433. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1434. CARLA_ASSERT(kData->oscData != nullptr);
  1435. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1436. CARLA_ASSERT(index >= 0);
  1437. CARLA_ASSERT(name);
  1438. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1439. {
  1440. char targetPath[std::strlen(kData->oscData->path)+18];
  1441. std::strcpy(targetPath, kData->oscData->path);
  1442. std::strcat(targetPath, "/set_program_name");
  1443. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1444. }
  1445. }
  1446. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1447. {
  1448. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1449. CARLA_ASSERT(kData->oscData != nullptr);
  1450. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1451. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1452. {
  1453. char targetPath[std::strlen(kData->oscData->path)+18];
  1454. std::strcpy(targetPath, kData->oscData->path);
  1455. std::strcat(targetPath, "/set_midi_program");
  1456. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1457. }
  1458. }
  1459. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1460. {
  1461. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1462. CARLA_ASSERT(kData->oscData != nullptr);
  1463. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1464. CARLA_ASSERT(count >= 0);
  1465. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1466. {
  1467. char targetPath[std::strlen(kData->oscData->path)+24];
  1468. std::strcpy(targetPath, kData->oscData->path);
  1469. std::strcat(targetPath, "/set_midi_program_count");
  1470. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1471. }
  1472. }
  1473. void CarlaEngine::osc_send_control_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name)
  1474. {
  1475. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1476. CARLA_ASSERT(kData->oscData != nullptr);
  1477. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1478. CARLA_ASSERT(index >= 0);
  1479. CARLA_ASSERT(bank >= 0);
  1480. CARLA_ASSERT(program >= 0);
  1481. CARLA_ASSERT(name);
  1482. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1483. {
  1484. char targetPath[std::strlen(kData->oscData->path)+23];
  1485. std::strcpy(targetPath, kData->oscData->path);
  1486. std::strcat(targetPath, "/set_midi_program_data");
  1487. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1488. }
  1489. }
  1490. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1491. {
  1492. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1493. CARLA_ASSERT(kData->oscData != nullptr);
  1494. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1495. CARLA_ASSERT(channel >= 0 && channel < 16);
  1496. CARLA_ASSERT(note >= 0 && note < 128);
  1497. CARLA_ASSERT(velo > 0 && velo < 128);
  1498. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1499. {
  1500. char targetPath[std::strlen(kData->oscData->path)+9];
  1501. std::strcpy(targetPath, kData->oscData->path);
  1502. std::strcat(targetPath, "/note_on");
  1503. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1504. }
  1505. }
  1506. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1507. {
  1508. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1509. CARLA_ASSERT(kData->oscData != nullptr);
  1510. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1511. CARLA_ASSERT(channel >= 0 && channel < 16);
  1512. CARLA_ASSERT(note >= 0 && note < 128);
  1513. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1514. {
  1515. char targetPath[std::strlen(kData->oscData->path)+10];
  1516. std::strcpy(targetPath, kData->oscData->path);
  1517. std::strcat(targetPath, "/note_off");
  1518. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1519. }
  1520. }
  1521. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1522. {
  1523. CARLA_ASSERT(kData->oscData != nullptr);
  1524. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1525. const EnginePluginData& pData = kData->plugins[pluginId];
  1526. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1527. {
  1528. char targetPath[std::strlen(kData->oscData->path)+22];
  1529. std::strcpy(targetPath, kData->oscData->path);
  1530. std::strcat(targetPath, "/set_peaks");
  1531. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1532. }
  1533. }
  1534. void CarlaEngine::osc_send_control_exit()
  1535. {
  1536. carla_debug("CarlaEngine::osc_send_control_exit()");
  1537. CARLA_ASSERT(kData->oscData != nullptr);
  1538. if (kData->oscData && kData->oscData->target)
  1539. {
  1540. char targetPath[std::strlen(kData->oscData->path)+6];
  1541. std::strcpy(targetPath, kData->oscData->path);
  1542. std::strcat(targetPath, "/exit");
  1543. lo_send(kData->oscData->target, targetPath, "");
  1544. }
  1545. }
  1546. #else
  1547. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1548. {
  1549. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1550. CARLA_ASSERT(kData->oscData != nullptr);
  1551. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1552. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1553. {
  1554. char targetPath[std::strlen(kData->oscData->path)+20];
  1555. std::strcpy(targetPath, kData->oscData->path);
  1556. std::strcat(targetPath, "/bridge_audio_count");
  1557. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1558. }
  1559. }
  1560. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1561. {
  1562. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1563. CARLA_ASSERT(kData->oscData != nullptr);
  1564. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1565. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1566. {
  1567. char targetPath[std::strlen(kData->oscData->path)+19];
  1568. std::strcpy(targetPath, kData->oscData->path);
  1569. std::strcat(targetPath, "/bridge_midi_count");
  1570. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1571. }
  1572. }
  1573. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1574. {
  1575. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1576. CARLA_ASSERT(kData->oscData != nullptr);
  1577. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1578. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1579. {
  1580. char targetPath[std::strlen(kData->oscData->path)+24];
  1581. std::strcpy(targetPath, kData->oscData->path);
  1582. std::strcat(targetPath, "/bridge_parameter_count");
  1583. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1584. }
  1585. }
  1586. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1587. {
  1588. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1589. CARLA_ASSERT(kData->oscData != nullptr);
  1590. CARLA_ASSERT(count >= 0);
  1591. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1592. {
  1593. char targetPath[std::strlen(kData->oscData->path)+22];
  1594. std::strcpy(targetPath, kData->oscData->path);
  1595. std::strcat(targetPath, "/bridge_program_count");
  1596. lo_send(kData->oscData->target, targetPath, "i", count);
  1597. }
  1598. }
  1599. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1600. {
  1601. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1602. CARLA_ASSERT(kData->oscData != nullptr);
  1603. CARLA_ASSERT(count >= 0);
  1604. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1605. {
  1606. char targetPath[std::strlen(kData->oscData->path)+27];
  1607. std::strcpy(targetPath, kData->oscData->path);
  1608. std::strcat(targetPath, "/bridge_midi_program_count");
  1609. lo_send(kData->oscData->target, targetPath, "i", count);
  1610. }
  1611. }
  1612. void CarlaEngine::osc_send_bridge_plugin_info(const int32_t category, const int32_t hints, const char* const name, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1613. {
  1614. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1615. CARLA_ASSERT(kData->oscData != nullptr);
  1616. CARLA_ASSERT(name != nullptr);
  1617. CARLA_ASSERT(label != nullptr);
  1618. CARLA_ASSERT(maker != nullptr);
  1619. CARLA_ASSERT(copyright != nullptr);
  1620. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1621. {
  1622. char targetPath[std::strlen(kData->oscData->path)+20];
  1623. std::strcpy(targetPath, kData->oscData->path);
  1624. std::strcat(targetPath, "/bridge_plugin_info");
  1625. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1626. }
  1627. }
  1628. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1629. {
  1630. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1631. CARLA_ASSERT(kData->oscData != nullptr);
  1632. CARLA_ASSERT(name != nullptr);
  1633. CARLA_ASSERT(unit != nullptr);
  1634. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1635. {
  1636. char targetPath[std::strlen(kData->oscData->path)+23];
  1637. std::strcpy(targetPath, kData->oscData->path);
  1638. std::strcat(targetPath, "/bridge_parameter_info");
  1639. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1640. }
  1641. }
  1642. void CarlaEngine::osc_send_bridge_parameter_data(const int32_t index, const int32_t type, const int32_t rindex, const int32_t hints, const int32_t midiChannel, const int32_t midiCC)
  1643. {
  1644. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1645. CARLA_ASSERT(kData->oscData != nullptr);
  1646. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1647. {
  1648. char targetPath[std::strlen(kData->oscData->path)+23];
  1649. std::strcpy(targetPath, kData->oscData->path);
  1650. std::strcat(targetPath, "/bridge_parameter_data");
  1651. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1652. }
  1653. }
  1654. void CarlaEngine::osc_send_bridge_parameter_ranges(const int32_t index, const float def, const float min, const float max, const float step, const float stepSmall, const float stepLarge)
  1655. {
  1656. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1657. CARLA_ASSERT(kData->oscData != nullptr);
  1658. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1659. {
  1660. char targetPath[std::strlen(kData->oscData->path)+25];
  1661. std::strcpy(targetPath, kData->oscData->path);
  1662. std::strcat(targetPath, "/bridge_parameter_ranges");
  1663. lo_send(kData->oscData->target, targetPath, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1664. }
  1665. }
  1666. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1667. {
  1668. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1669. CARLA_ASSERT(kData->oscData != nullptr);
  1670. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1671. {
  1672. char targetPath[std::strlen(kData->oscData->path)+21];
  1673. std::strcpy(targetPath, kData->oscData->path);
  1674. std::strcat(targetPath, "/bridge_program_info");
  1675. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1676. }
  1677. }
  1678. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1679. {
  1680. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1681. CARLA_ASSERT(kData->oscData != nullptr);
  1682. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1683. {
  1684. char targetPath[std::strlen(kData->oscData->path)+26];
  1685. std::strcpy(targetPath, kData->oscData->path);
  1686. std::strcat(targetPath, "/bridge_midi_program_info");
  1687. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1688. }
  1689. }
  1690. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1691. {
  1692. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1693. CARLA_ASSERT(kData->oscData != nullptr);
  1694. CARLA_ASSERT(key != nullptr);
  1695. CARLA_ASSERT(value != nullptr);
  1696. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1697. {
  1698. char targetPath[std::strlen(kData->oscData->path)+18];
  1699. std::strcpy(targetPath, kData->oscData->path);
  1700. std::strcat(targetPath, "/bridge_configure");
  1701. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1702. }
  1703. }
  1704. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1705. {
  1706. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1707. CARLA_ASSERT(kData->oscData != nullptr);
  1708. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1709. {
  1710. char targetPath[std::strlen(kData->oscData->path)+28];
  1711. std::strcpy(targetPath, kData->oscData->path);
  1712. std::strcat(targetPath, "/bridge_set_parameter_value");
  1713. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1714. }
  1715. }
  1716. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1717. {
  1718. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1719. CARLA_ASSERT(kData->oscData != nullptr);
  1720. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1721. {
  1722. char targetPath[std::strlen(kData->oscData->path)+26];
  1723. std::strcpy(targetPath, kData->oscData->path);
  1724. std::strcat(targetPath, "/bridge_set_default_value");
  1725. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1726. }
  1727. }
  1728. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1729. {
  1730. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1731. CARLA_ASSERT(kData->oscData != nullptr);
  1732. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1733. {
  1734. char targetPath[std::strlen(kData->oscData->path)+20];
  1735. std::strcpy(targetPath, kData->oscData->path);
  1736. std::strcat(targetPath, "/bridge_set_program");
  1737. lo_send(kData->oscData->target, targetPath, "i", index);
  1738. }
  1739. }
  1740. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1741. {
  1742. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1743. CARLA_ASSERT(kData->oscData != nullptr);
  1744. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1745. {
  1746. char targetPath[std::strlen(kData->oscData->path)+25];
  1747. std::strcpy(targetPath, kData->oscData->path);
  1748. std::strcat(targetPath, "/bridge_set_midi_program");
  1749. lo_send(kData->oscData->target, targetPath, "i", index);
  1750. }
  1751. }
  1752. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1753. {
  1754. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1755. CARLA_ASSERT(kData->oscData != nullptr);
  1756. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1757. {
  1758. char targetPath[std::strlen(kData->oscData->path)+24];
  1759. std::strcpy(targetPath, kData->oscData->path);
  1760. std::strcat(targetPath, "/bridge_set_custom_data");
  1761. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  1762. }
  1763. }
  1764. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1765. {
  1766. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1767. CARLA_ASSERT(kData->oscData != nullptr);
  1768. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1769. {
  1770. char targetPath[std::strlen(kData->oscData->path)+23];
  1771. std::strcpy(targetPath, kData->oscData->path);
  1772. std::strcat(targetPath, "/bridge_set_chunk_data");
  1773. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  1774. }
  1775. }
  1776. void CarlaEngine::osc_send_bridge_set_peaks()
  1777. {
  1778. CARLA_ASSERT(kData->oscData != nullptr);
  1779. const EnginePluginData& pData = kData->plugins[0];
  1780. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1781. {
  1782. char targetPath[std::strlen(kData->oscData->path)+22];
  1783. std::strcpy(targetPath, kData->oscData->path);
  1784. std::strcat(targetPath, "/bridge_set_peaks");
  1785. lo_send(kData->oscData->target, targetPath, "ffff", pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1786. }
  1787. }
  1788. #endif
  1789. CARLA_BACKEND_END_NAMESPACE