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.

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