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.

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