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. ::QMainWindow* getEngineHostWindow(CarlaEngine* const engine)
  29. {
  30. return CarlaEngineProtectedData::getHostWindow(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. }
  516. // -----------------------------------------------------------------------
  517. // Virtual, per-engine type calls
  518. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  519. {
  520. return new CarlaEngineClient(type(), fOptions.processMode);
  521. }
  522. // -----------------------------------------------------------------------
  523. // Plugin management
  524. 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)
  525. {
  526. carla_debug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra);
  527. CARLA_ASSERT(btype != BINARY_NONE);
  528. CARLA_ASSERT(ptype != PLUGIN_NONE);
  529. if (kData->curPluginCount == kData->maxPluginNumber)
  530. {
  531. setLastError("Maximum number of plugins reached");
  532. return false;
  533. }
  534. const unsigned int id = kData->curPluginCount;
  535. CarlaPlugin::Initializer init = {
  536. this,
  537. id,
  538. filename,
  539. name,
  540. label
  541. };
  542. CarlaPlugin* plugin = nullptr;
  543. #ifndef BUILD_BRIDGE
  544. const char* bridgeBinary;
  545. switch (btype)
  546. {
  547. case BINARY_POSIX32:
  548. bridgeBinary = fOptions.bridge_posix32.isNotEmpty() ? (const char*)fOptions.bridge_posix32 : nullptr;
  549. break;
  550. case BINARY_POSIX64:
  551. bridgeBinary = fOptions.bridge_posix64.isNotEmpty() ? (const char*)fOptions.bridge_posix64 : nullptr;
  552. break;
  553. case BINARY_WIN32:
  554. bridgeBinary = fOptions.bridge_win32.isNotEmpty() ? (const char*)fOptions.bridge_win32 : nullptr;
  555. break;
  556. case BINARY_WIN64:
  557. bridgeBinary = fOptions.bridge_win64.isNotEmpty() ? (const char*)fOptions.bridge_win64 : nullptr;
  558. break;
  559. default:
  560. bridgeBinary = nullptr;
  561. break;
  562. }
  563. #ifndef Q_OS_WIN
  564. if (btype == BINARY_NATIVE && fOptions.bridge_native.isNotEmpty())
  565. bridgeBinary = (const char*)fOptions.bridge_native;
  566. #endif
  567. if (fOptions.preferPluginBridges && bridgeBinary != nullptr)
  568. {
  569. // TODO
  570. if (fOptions.processMode != PROCESS_MODE_MULTIPLE_CLIENTS)
  571. {
  572. setLastError("Can only use bridged plugins in JACK Multi-Client mode");
  573. return -1;
  574. }
  575. // TODO
  576. if (type() != kEngineTypeJack)
  577. {
  578. setLastError("Can only use bridged plugins with JACK backend");
  579. return -1;
  580. }
  581. #if 0
  582. plugin = CarlaPlugin::newBridge(init, btype, ptype, bridgeBinary);
  583. #endif
  584. setLastError("Bridged plugins are not implemented yet");
  585. }
  586. else
  587. #endif // BUILD_BRIDGE
  588. {
  589. switch (ptype)
  590. {
  591. case PLUGIN_NONE:
  592. break;
  593. case PLUGIN_INTERNAL:
  594. plugin = CarlaPlugin::newNative(init);
  595. break;
  596. case PLUGIN_LADSPA:
  597. plugin = CarlaPlugin::newLADSPA(init, (const LADSPA_RDF_Descriptor*)extra);
  598. break;
  599. case PLUGIN_DSSI:
  600. plugin = CarlaPlugin::newDSSI(init, (const char*)extra);
  601. break;
  602. case PLUGIN_LV2:
  603. plugin = CarlaPlugin::newLV2(init);
  604. break;
  605. case PLUGIN_VST:
  606. plugin = CarlaPlugin::newVST(init);
  607. break;
  608. case PLUGIN_VST3:
  609. plugin = CarlaPlugin::newVST3(init);
  610. break;
  611. case PLUGIN_GIG:
  612. plugin = CarlaPlugin::newGIG(init, (extra != nullptr));
  613. break;
  614. case PLUGIN_SF2:
  615. plugin = CarlaPlugin::newSF2(init, (extra != nullptr));
  616. break;
  617. case PLUGIN_SFZ:
  618. plugin = CarlaPlugin::newSFZ(init, (extra != nullptr));
  619. break;
  620. }
  621. }
  622. if (plugin == nullptr)
  623. return false;
  624. plugin->registerToOscClient();
  625. kData->plugins[id].plugin = plugin;
  626. kData->plugins[id].insPeak[0] = 0.0f;
  627. kData->plugins[id].insPeak[1] = 0.0f;
  628. kData->plugins[id].outsPeak[0] = 0.0f;
  629. kData->plugins[id].outsPeak[1] = 0.0f;
  630. kData->curPluginCount += 1;
  631. // FIXME
  632. callback(CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, nullptr);
  633. return true;
  634. }
  635. bool CarlaEngine::removePlugin(const unsigned int id)
  636. {
  637. carla_debug("CarlaEngine::removePlugin(%i)", id);
  638. CARLA_ASSERT(kData->curPluginCount > 0);
  639. CARLA_ASSERT(id < kData->curPluginCount);
  640. CARLA_ASSERT(kData->plugins != nullptr);
  641. if (kData->plugins == nullptr)
  642. {
  643. setLastError("Critical error: no plugins are currently loaded!");
  644. return false;
  645. }
  646. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  647. CARLA_ASSERT(plugin != nullptr);
  648. if (plugin != nullptr)
  649. {
  650. CARLA_ASSERT(plugin->id() == id);
  651. kData->thread.stopNow();
  652. kData->nextAction.pluginId = id;
  653. kData->nextAction.opcode = EnginePostActionRemovePlugin;
  654. kData->nextAction.mutex.lock();
  655. if (isRunning())
  656. {
  657. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking START", id);
  658. // block wait for unlock on proccessing side
  659. kData->nextAction.mutex.lock();
  660. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking DONE", id);
  661. }
  662. else
  663. {
  664. doPluginRemove(kData, false);
  665. }
  666. #ifndef BUILD_BRIDGE
  667. if (isOscControlRegistered())
  668. osc_send_control_remove_plugin(id);
  669. #endif
  670. delete plugin;
  671. kData->nextAction.mutex.unlock();
  672. if (isRunning() && ! kData->aboutToClose)
  673. kData->thread.startNow();
  674. // FIXME
  675. callback(CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  676. return true;
  677. }
  678. carla_stderr("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  679. setLastError("Could not find plugin to remove");
  680. return false;
  681. }
  682. void CarlaEngine::removeAllPlugins()
  683. {
  684. carla_debug("CarlaEngine::removeAllPlugins() - START");
  685. kData->thread.stopNow();
  686. if (kData->curPluginCount > 0)
  687. {
  688. const unsigned int oldCount = kData->curPluginCount;
  689. kData->curPluginCount = 0;
  690. for (unsigned int i=0; i < oldCount; i++)
  691. {
  692. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  693. CARLA_ASSERT(plugin != nullptr);
  694. kData->plugins[i].plugin = nullptr;
  695. if (plugin != nullptr)
  696. delete plugin;
  697. // clear this plugin
  698. kData->plugins[i].insPeak[0] = 0.0f;
  699. kData->plugins[i].insPeak[1] = 0.0f;
  700. kData->plugins[i].outsPeak[0] = 0.0f;
  701. kData->plugins[i].outsPeak[1] = 0.0f;
  702. }
  703. }
  704. if (isRunning() && ! kData->aboutToClose)
  705. kData->thread.startNow();
  706. carla_debug("CarlaEngine::removeAllPlugins() - END");
  707. }
  708. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  709. {
  710. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, kData->curPluginCount);
  711. CARLA_ASSERT(kData->curPluginCount > 0);
  712. CARLA_ASSERT(id < kData->curPluginCount);
  713. CARLA_ASSERT(kData->plugins != nullptr);
  714. if (id < kData->curPluginCount && kData->plugins != nullptr)
  715. return kData->plugins[id].plugin;
  716. return nullptr;
  717. }
  718. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const
  719. {
  720. return kData->plugins[id].plugin;
  721. }
  722. const char* CarlaEngine::getNewUniquePluginName(const char* const name)
  723. {
  724. carla_debug("CarlaEngine::getNewUniquePluginName(\"%s\")", name);
  725. CARLA_ASSERT(kData->maxPluginNumber > 0);
  726. CARLA_ASSERT(kData->plugins != nullptr);
  727. CARLA_ASSERT(name != nullptr);
  728. static CarlaString sname;
  729. sname = name;
  730. if (sname.isEmpty() || kData->plugins == nullptr)
  731. {
  732. sname = "(No name)";
  733. return (const char*)sname;
  734. }
  735. sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  736. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  737. for (unsigned short i=0; i < kData->curPluginCount; i++)
  738. {
  739. CARLA_ASSERT(kData->plugins[i].plugin);
  740. if (kData->plugins[i].plugin == nullptr)
  741. continue;
  742. // Check if unique name doesn't exist
  743. if (const char* const pluginName = kData->plugins[i].plugin->name())
  744. {
  745. if (sname != pluginName)
  746. continue;
  747. }
  748. // Check if string has already been modified
  749. {
  750. const size_t len = sname.length();
  751. // 1 digit, ex: " (2)"
  752. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  753. {
  754. int number = sname[len-2] - '0';
  755. if (number == 9)
  756. {
  757. // next number is 10, 2 digits
  758. sname.truncate(len-4);
  759. sname += " (10)";
  760. //sname.replace(" (9)", " (10)");
  761. }
  762. else
  763. sname[len-2] = char('0' + number + 1);
  764. continue;
  765. }
  766. // 2 digits, ex: " (11)"
  767. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  768. {
  769. char n2 = sname[len-2];
  770. char n3 = sname[len-3];
  771. if (n2 == '9')
  772. {
  773. n2 = '0';
  774. n3 += 1;
  775. }
  776. else
  777. n2 += 1;
  778. sname[len-2] = n2;
  779. sname[len-3] = n3;
  780. continue;
  781. }
  782. }
  783. // Modify string if not
  784. sname += " (2)";
  785. }
  786. return (const char*)sname;
  787. }
  788. #if 0
  789. void CarlaEngine::__bridgePluginRegister(const unsigned short id, CarlaPlugin* const plugin)
  790. {
  791. data->carlaPlugins[id] = plugin;
  792. }
  793. #endif
  794. // -----------------------------------------------------------------------
  795. // Information (base)
  796. bool CarlaEngine::loadProject(const char* const filename)
  797. {
  798. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  799. CARLA_ASSERT(filename != nullptr);
  800. QFile file(filename);
  801. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  802. return false;
  803. QDomDocument xml;
  804. xml.setContent(file.readAll());
  805. file.close();
  806. QDomNode xmlNode(xml.documentElement());
  807. if (xmlNode.toElement().tagName() != "CARLA-PROJECT")
  808. {
  809. carla_stderr2("Not a valid Carla project file");
  810. return false;
  811. }
  812. QDomNode node(xmlNode.firstChild());
  813. while (! node.isNull())
  814. {
  815. if (node.toElement().tagName() == "Plugin")
  816. {
  817. const SaveState& saveState = getSaveStateDictFromXML(node);
  818. CARLA_ASSERT(saveState.type != nullptr);
  819. if (saveState.type == nullptr)
  820. continue;
  821. const void* extraStuff = nullptr;
  822. if (std::strcmp(saveState.type, "DSSI") == 0)
  823. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  824. // TODO - proper find&load plugins
  825. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  826. {
  827. if (CarlaPlugin* plugin = getPlugin(kData->curPluginCount-1))
  828. plugin->loadSaveState(saveState);
  829. }
  830. }
  831. node = node.nextSibling();
  832. }
  833. return true;
  834. }
  835. bool CarlaEngine::saveProject(const char* const filename)
  836. {
  837. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  838. CARLA_ASSERT(filename != nullptr);
  839. QFile file(filename);
  840. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  841. return false;
  842. QTextStream out(&file);
  843. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  844. out << "<!DOCTYPE CARLA-PROJECT>\n";
  845. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  846. bool firstPlugin = true;
  847. char strBuf[STR_MAX];
  848. for (unsigned int i=0; i < kData->curPluginCount; i++)
  849. {
  850. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  851. if (plugin != nullptr && plugin->enabled())
  852. {
  853. if (! firstPlugin)
  854. out << "\n";
  855. plugin->getRealName(strBuf);
  856. if (*strBuf != 0)
  857. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  858. out << " <Plugin>\n";
  859. out << getXMLFromSaveState(plugin->getSaveState());
  860. out << " </Plugin>\n";
  861. firstPlugin = false;
  862. }
  863. }
  864. out << "</CARLA-PROJECT>\n";
  865. file.close();
  866. return true;
  867. }
  868. // -----------------------------------------------------------------------
  869. // Information (peaks)
  870. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  871. {
  872. CARLA_ASSERT(pluginId < kData->curPluginCount);
  873. CARLA_ASSERT(id-1 < MAX_PEAKS);
  874. if (id == 0 || id > MAX_PEAKS)
  875. return 0.0f;
  876. return kData->plugins[pluginId].insPeak[id-1];
  877. }
  878. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  879. {
  880. CARLA_ASSERT(pluginId < kData->curPluginCount);
  881. CARLA_ASSERT(id-1 < MAX_PEAKS);
  882. if (id == 0 || id > MAX_PEAKS)
  883. return 0.0f;
  884. return kData->plugins[pluginId].outsPeak[id-1];
  885. }
  886. // -----------------------------------------------------------------------
  887. // Callback
  888. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  889. {
  890. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  891. if (kData->callback)
  892. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  893. }
  894. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  895. {
  896. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  897. CARLA_ASSERT(func);
  898. kData->callback = func;
  899. kData->callbackPtr = ptr;
  900. }
  901. // -----------------------------------------------------------------------
  902. // Patchbay
  903. void CarlaEngine::patchbayConnect(int, int)
  904. {
  905. // nothing
  906. }
  907. void CarlaEngine::patchbayDisconnect(int)
  908. {
  909. // nothing
  910. }
  911. // -----------------------------------------------------------------------
  912. // Transport
  913. void CarlaEngine::transportPlay()
  914. {
  915. kData->time.playing = true;
  916. }
  917. void CarlaEngine::transportPause()
  918. {
  919. kData->time.playing = false;
  920. }
  921. void CarlaEngine::transportRelocate(const uint32_t frame)
  922. {
  923. kData->time.frame = frame;
  924. }
  925. // -----------------------------------------------------------------------
  926. // Error handling
  927. const char* CarlaEngine::getLastError() const
  928. {
  929. return (const char*)kData->lastError;
  930. }
  931. void CarlaEngine::setLastError(const char* const error)
  932. {
  933. kData->lastError = error;
  934. }
  935. void CarlaEngine::setAboutToClose()
  936. {
  937. carla_debug("CarlaEngine::setAboutToClose()");
  938. kData->aboutToClose = true;
  939. }
  940. // -----------------------------------------------------------------------
  941. // Global options
  942. #ifndef BUILD_BRIDGE
  943. const QProcessEnvironment& CarlaEngine::getOptionsAsProcessEnvironment() const
  944. {
  945. return kData->procEnv;
  946. }
  947. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  948. if (isRunning()) \
  949. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  950. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  951. {
  952. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  953. switch (option)
  954. {
  955. case OPTION_PROCESS_NAME:
  956. carla_setprocname(valueStr);
  957. break;
  958. case OPTION_PROCESS_MODE:
  959. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  960. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_PATCHBAY)
  961. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  962. fOptions.processMode = static_cast<ProcessMode>(value);
  963. break;
  964. case OPTION_TRANSPORT_MODE:
  965. // FIXME: Always enable JACK transport for now
  966. #if 0
  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. #endif
  971. break;
  972. case OPTION_MAX_PARAMETERS:
  973. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  974. if (value < 0)
  975. return; // TODO error here
  976. fOptions.maxParameters = static_cast<uint>(value);
  977. break;
  978. case OPTION_PREFERRED_BUFFER_SIZE:
  979. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  980. fOptions.preferredBufferSize = static_cast<uint>(value);
  981. break;
  982. case OPTION_PREFERRED_SAMPLE_RATE:
  983. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  984. fOptions.preferredSampleRate = static_cast<uint>(value);
  985. break;
  986. case OPTION_FORCE_STEREO:
  987. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  988. fOptions.forceStereo = (value != 0);
  989. break;
  990. #ifdef WANT_DSSI
  991. case OPTION_USE_DSSI_VST_CHUNKS:
  992. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  993. fOptions.useDssiVstChunks = (value != 0);
  994. break;
  995. #endif
  996. case OPTION_PREFER_PLUGIN_BRIDGES:
  997. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  998. fOptions.preferPluginBridges = (value != 0);
  999. break;
  1000. case OPTION_PREFER_UI_BRIDGES:
  1001. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1002. fOptions.preferUiBridges = (value != 0);
  1003. break;
  1004. case OPTION_OSC_UI_TIMEOUT:
  1005. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1006. fOptions.oscUiTimeout = static_cast<uint>(value);
  1007. break;
  1008. case OPTION_PATH_BRIDGE_NATIVE:
  1009. fOptions.bridge_native = valueStr;
  1010. break;
  1011. case OPTION_PATH_BRIDGE_POSIX32:
  1012. fOptions.bridge_posix32 = valueStr;
  1013. break;
  1014. case OPTION_PATH_BRIDGE_POSIX64:
  1015. fOptions.bridge_posix64 = valueStr;
  1016. break;
  1017. case OPTION_PATH_BRIDGE_WIN32:
  1018. fOptions.bridge_win32 = valueStr;
  1019. break;
  1020. case OPTION_PATH_BRIDGE_WIN64:
  1021. fOptions.bridge_win64 = valueStr;
  1022. break;
  1023. #ifdef WANT_LV2
  1024. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1025. fOptions.bridge_lv2gtk2 = valueStr;
  1026. break;
  1027. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1028. fOptions.bridge_lv2gtk3 = valueStr;
  1029. break;
  1030. case OPTION_PATH_BRIDGE_LV2_QT4:
  1031. fOptions.bridge_lv2qt4 = valueStr;
  1032. break;
  1033. case OPTION_PATH_BRIDGE_LV2_QT5:
  1034. fOptions.bridge_lv2qt5 = valueStr;
  1035. break;
  1036. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1037. fOptions.bridge_lv2cocoa = valueStr;
  1038. break;
  1039. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1040. fOptions.bridge_lv2win = valueStr;
  1041. break;
  1042. case OPTION_PATH_BRIDGE_LV2_X11:
  1043. fOptions.bridge_lv2x11 = valueStr;
  1044. break;
  1045. #endif
  1046. #ifdef WANT_VST
  1047. case OPTION_PATH_BRIDGE_VST_COCOA:
  1048. fOptions.bridge_vstcocoa = valueStr;
  1049. break;
  1050. case OPTION_PATH_BRIDGE_VST_HWND:
  1051. fOptions.bridge_vsthwnd = valueStr;
  1052. break;
  1053. case OPTION_PATH_BRIDGE_VST_X11:
  1054. fOptions.bridge_vstx11 = valueStr;
  1055. break;
  1056. #endif
  1057. }
  1058. }
  1059. #endif
  1060. // -----------------------------------------------------------------------
  1061. // OSC Stuff
  1062. #ifdef BUILD_BRIDGE
  1063. bool CarlaEngine::isOscBridgeRegistered() const
  1064. {
  1065. return (kData->oscData != nullptr);
  1066. }
  1067. #else
  1068. bool CarlaEngine::isOscControlRegistered() const
  1069. {
  1070. return kData->osc.isControlRegistered();
  1071. }
  1072. #endif
  1073. void CarlaEngine::idleOsc()
  1074. {
  1075. kData->osc.idle();
  1076. }
  1077. const char* CarlaEngine::getOscServerPathTCP() const
  1078. {
  1079. return kData->osc.getServerPathTCP();
  1080. }
  1081. const char* CarlaEngine::getOscServerPathUDP() const
  1082. {
  1083. return kData->osc.getServerPathUDP();
  1084. }
  1085. #ifdef BUILD_BRIDGE
  1086. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1087. {
  1088. kData->oscData = oscData;
  1089. }
  1090. #endif
  1091. // -----------------------------------------------------------------------
  1092. // protected calls
  1093. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1094. {
  1095. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1096. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1097. {
  1098. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1099. if (plugin != nullptr && plugin->enabled())
  1100. plugin->bufferSizeChanged(newBufferSize);
  1101. }
  1102. }
  1103. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1104. {
  1105. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1106. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1107. {
  1108. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1109. if (plugin != nullptr && plugin->enabled())
  1110. plugin->sampleRateChanged(newSampleRate);
  1111. }
  1112. }
  1113. void CarlaEngine::proccessPendingEvents()
  1114. {
  1115. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1116. switch (kData->nextAction.opcode)
  1117. {
  1118. case EnginePostActionNull:
  1119. break;
  1120. case EnginePostActionRemovePlugin:
  1121. doPluginRemove(kData, true);
  1122. break;
  1123. }
  1124. if (kData->time.playing)
  1125. kData->time.frame += fBufferSize;
  1126. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1127. {
  1128. fTimeInfo.playing = kData->time.playing;
  1129. fTimeInfo.frame = kData->time.frame;
  1130. }
  1131. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1132. {
  1133. // TODO - peak values?
  1134. }
  1135. }
  1136. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS])
  1137. {
  1138. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1139. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1140. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1141. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1142. }
  1143. #ifndef BUILD_BRIDGE
  1144. EngineEvent* CarlaEngine::getRackEventBuffer(const bool isInput)
  1145. {
  1146. return isInput ? kData->rack.in : kData->rack.out;
  1147. }
  1148. void setValueIfHigher(float& value, const float& compare)
  1149. {
  1150. if (value < compare)
  1151. value = compare;
  1152. }
  1153. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1154. {
  1155. // initialize outputs (zero)
  1156. carla_zeroFloat(outBuf[0], frames);
  1157. carla_zeroFloat(outBuf[1], frames);
  1158. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1159. bool processed = false;
  1160. // process plugins
  1161. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1162. {
  1163. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1164. if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock())
  1165. continue;
  1166. if (processed)
  1167. {
  1168. // initialize inputs (from previous outputs)
  1169. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1170. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1171. std::memcpy(kData->rack.in, kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1172. // initialize outputs (zero)
  1173. carla_zeroFloat(outBuf[0], frames);
  1174. carla_zeroFloat(outBuf[1], frames);
  1175. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1176. }
  1177. // process
  1178. plugin->initBuffers();
  1179. plugin->process(inBuf, outBuf, frames);
  1180. plugin->unlock();
  1181. #if 0
  1182. // if plugin has no audio inputs, add previous buffers
  1183. if (plugin->audioInCount() == 0)
  1184. {
  1185. for (uint32_t j=0; j < frames; j++)
  1186. {
  1187. outBuf[0][j] += inBuf[0][j];
  1188. outBuf[1][j] += inBuf[1][j];
  1189. }
  1190. }
  1191. // if plugin has no midi output, add previous events
  1192. if (plugin->midiOutCount() == 0)
  1193. {
  1194. for (uint32_t j=0, k=0; j < frames; j++)
  1195. {
  1196. }
  1197. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1198. }
  1199. #endif
  1200. // set peaks
  1201. {
  1202. float inPeak1 = 0.0f;
  1203. float inPeak2 = 0.0f;
  1204. float outPeak1 = 0.0f;
  1205. float outPeak2 = 0.0f;
  1206. for (uint32_t k=0; k < frames; k++)
  1207. {
  1208. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1209. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1210. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1211. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1212. }
  1213. kData->plugins[i].insPeak[0] = inPeak1;
  1214. kData->plugins[i].insPeak[1] = inPeak2;
  1215. kData->plugins[i].outsPeak[0] = outPeak1;
  1216. kData->plugins[i].outsPeak[1] = outPeak2;
  1217. }
  1218. processed = true;
  1219. }
  1220. }
  1221. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1222. {
  1223. // TODO
  1224. return;
  1225. // unused, for now
  1226. (void)inBuf;
  1227. (void)outBuf;
  1228. (void)bufCount;
  1229. (void)frames;
  1230. }
  1231. #endif
  1232. // -------------------------------------------------------------------------------------------------------------------
  1233. // Carla Engine OSC stuff
  1234. #ifndef BUILD_BRIDGE
  1235. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1236. {
  1237. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1238. CARLA_ASSERT(kData->oscData != nullptr);
  1239. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1240. CARLA_ASSERT(pluginName);
  1241. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1242. {
  1243. char targetPath[std::strlen(kData->oscData->path)+18];
  1244. std::strcpy(targetPath, kData->oscData->path);
  1245. std::strcat(targetPath, "/add_plugin_start");
  1246. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1247. }
  1248. }
  1249. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1250. {
  1251. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1252. CARLA_ASSERT(kData->oscData != nullptr);
  1253. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1254. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1255. {
  1256. char targetPath[std::strlen(kData->oscData->path)+16];
  1257. std::strcpy(targetPath, kData->oscData->path);
  1258. std::strcat(targetPath, "/add_plugin_end");
  1259. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1260. }
  1261. }
  1262. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1263. {
  1264. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1265. CARLA_ASSERT(kData->oscData != nullptr);
  1266. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1267. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1268. {
  1269. char targetPath[std::strlen(kData->oscData->path)+15];
  1270. std::strcpy(targetPath, kData->oscData->path);
  1271. std::strcat(targetPath, "/remove_plugin");
  1272. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1273. }
  1274. }
  1275. 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)
  1276. {
  1277. 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);
  1278. CARLA_ASSERT(kData->oscData != nullptr);
  1279. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1280. CARLA_ASSERT(type != PLUGIN_NONE);
  1281. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1282. {
  1283. char targetPath[std::strlen(kData->oscData->path)+17];
  1284. std::strcpy(targetPath, kData->oscData->path);
  1285. std::strcat(targetPath, "/set_plugin_data");
  1286. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1287. }
  1288. }
  1289. 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)
  1290. {
  1291. 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);
  1292. CARLA_ASSERT(kData->oscData != nullptr);
  1293. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1294. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1295. {
  1296. char targetPath[std::strlen(kData->oscData->path)+18];
  1297. std::strcpy(targetPath, kData->oscData->path);
  1298. std::strcat(targetPath, "/set_plugin_ports");
  1299. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1300. }
  1301. }
  1302. 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)
  1303. {
  1304. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1305. CARLA_ASSERT(kData->oscData != nullptr);
  1306. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1307. CARLA_ASSERT(index >= 0);
  1308. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1309. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1310. {
  1311. char targetPath[std::strlen(kData->oscData->path)+20];
  1312. std::strcpy(targetPath, kData->oscData->path);
  1313. std::strcat(targetPath, "/set_parameter_data");
  1314. lo_send(kData->oscData->target, targetPath, "iiiissd", pluginId, index, type, hints, name, label, current);
  1315. }
  1316. }
  1317. 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)
  1318. {
  1319. 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);
  1320. CARLA_ASSERT(kData->oscData != nullptr);
  1321. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1322. CARLA_ASSERT(index >= 0);
  1323. CARLA_ASSERT(min < max);
  1324. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1325. {
  1326. char targetPath[std::strlen(kData->oscData->path)+22];
  1327. std::strcpy(targetPath, kData->oscData->path);
  1328. std::strcat(targetPath, "/set_parameter_ranges");
  1329. lo_send(kData->oscData->target, targetPath, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1330. }
  1331. }
  1332. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1333. {
  1334. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1335. CARLA_ASSERT(kData->oscData != nullptr);
  1336. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1337. CARLA_ASSERT(index >= 0);
  1338. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1339. {
  1340. char targetPath[std::strlen(kData->oscData->path)+23];
  1341. std::strcpy(targetPath, kData->oscData->path);
  1342. std::strcat(targetPath, "/set_parameter_midi_cc");
  1343. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1344. }
  1345. }
  1346. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1347. {
  1348. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1349. CARLA_ASSERT(kData->oscData != nullptr);
  1350. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1351. CARLA_ASSERT(index >= 0);
  1352. CARLA_ASSERT(channel >= 0 && channel < 16);
  1353. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1354. {
  1355. char targetPath[std::strlen(kData->oscData->path)+28];
  1356. std::strcpy(targetPath, kData->oscData->path);
  1357. std::strcat(targetPath, "/set_parameter_midi_channel");
  1358. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1359. }
  1360. }
  1361. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1362. {
  1363. #if DEBUG
  1364. if (index < 0)
  1365. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1366. else
  1367. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1368. #endif
  1369. CARLA_ASSERT(kData->oscData != nullptr);
  1370. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1371. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1372. {
  1373. char targetPath[std::strlen(kData->oscData->path)+21];
  1374. std::strcpy(targetPath, kData->oscData->path);
  1375. std::strcat(targetPath, "/set_parameter_value");
  1376. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1377. }
  1378. }
  1379. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1380. {
  1381. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1382. CARLA_ASSERT(kData->oscData != nullptr);
  1383. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1384. CARLA_ASSERT(index >= 0);
  1385. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1386. {
  1387. char targetPath[std::strlen(kData->oscData->path)+19];
  1388. std::strcpy(targetPath, kData->oscData->path);
  1389. std::strcat(targetPath, "/set_default_value");
  1390. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1391. }
  1392. }
  1393. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1394. {
  1395. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1396. CARLA_ASSERT(kData->oscData != nullptr);
  1397. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1398. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1399. {
  1400. char targetPath[std::strlen(kData->oscData->path)+13];
  1401. std::strcpy(targetPath, kData->oscData->path);
  1402. std::strcat(targetPath, "/set_program");
  1403. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1404. }
  1405. }
  1406. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1407. {
  1408. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1409. CARLA_ASSERT(kData->oscData != nullptr);
  1410. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1411. CARLA_ASSERT(count >= 0);
  1412. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1413. {
  1414. char targetPath[std::strlen(kData->oscData->path)+19];
  1415. std::strcpy(targetPath, kData->oscData->path);
  1416. std::strcat(targetPath, "/set_program_count");
  1417. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1418. }
  1419. }
  1420. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1421. {
  1422. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1423. CARLA_ASSERT(kData->oscData != nullptr);
  1424. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1425. CARLA_ASSERT(index >= 0);
  1426. CARLA_ASSERT(name);
  1427. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1428. {
  1429. char targetPath[std::strlen(kData->oscData->path)+18];
  1430. std::strcpy(targetPath, kData->oscData->path);
  1431. std::strcat(targetPath, "/set_program_name");
  1432. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1433. }
  1434. }
  1435. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1436. {
  1437. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1438. CARLA_ASSERT(kData->oscData != nullptr);
  1439. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1440. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1441. {
  1442. char targetPath[std::strlen(kData->oscData->path)+18];
  1443. std::strcpy(targetPath, kData->oscData->path);
  1444. std::strcat(targetPath, "/set_midi_program");
  1445. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1446. }
  1447. }
  1448. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1449. {
  1450. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1451. CARLA_ASSERT(kData->oscData != nullptr);
  1452. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1453. CARLA_ASSERT(count >= 0);
  1454. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1455. {
  1456. char targetPath[std::strlen(kData->oscData->path)+24];
  1457. std::strcpy(targetPath, kData->oscData->path);
  1458. std::strcat(targetPath, "/set_midi_program_count");
  1459. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1460. }
  1461. }
  1462. 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)
  1463. {
  1464. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1465. CARLA_ASSERT(kData->oscData != nullptr);
  1466. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1467. CARLA_ASSERT(index >= 0);
  1468. CARLA_ASSERT(bank >= 0);
  1469. CARLA_ASSERT(program >= 0);
  1470. CARLA_ASSERT(name);
  1471. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1472. {
  1473. char targetPath[std::strlen(kData->oscData->path)+23];
  1474. std::strcpy(targetPath, kData->oscData->path);
  1475. std::strcat(targetPath, "/set_midi_program_data");
  1476. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1477. }
  1478. }
  1479. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1480. {
  1481. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1482. CARLA_ASSERT(kData->oscData != nullptr);
  1483. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1484. CARLA_ASSERT(channel >= 0 && channel < 16);
  1485. CARLA_ASSERT(note >= 0 && note < 128);
  1486. CARLA_ASSERT(velo > 0 && velo < 128);
  1487. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1488. {
  1489. char targetPath[std::strlen(kData->oscData->path)+9];
  1490. std::strcpy(targetPath, kData->oscData->path);
  1491. std::strcat(targetPath, "/note_on");
  1492. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1493. }
  1494. }
  1495. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1496. {
  1497. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1498. CARLA_ASSERT(kData->oscData != nullptr);
  1499. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1500. CARLA_ASSERT(channel >= 0 && channel < 16);
  1501. CARLA_ASSERT(note >= 0 && note < 128);
  1502. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1503. {
  1504. char targetPath[std::strlen(kData->oscData->path)+10];
  1505. std::strcpy(targetPath, kData->oscData->path);
  1506. std::strcat(targetPath, "/note_off");
  1507. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1508. }
  1509. }
  1510. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1511. {
  1512. CARLA_ASSERT(kData->oscData != nullptr);
  1513. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1514. const EnginePluginData& pData = kData->plugins[pluginId];
  1515. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1516. {
  1517. char targetPath[std::strlen(kData->oscData->path)+22];
  1518. std::strcpy(targetPath, kData->oscData->path);
  1519. std::strcat(targetPath, "/set_peaks");
  1520. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1521. }
  1522. }
  1523. void CarlaEngine::osc_send_control_exit()
  1524. {
  1525. carla_debug("CarlaEngine::osc_send_control_exit()");
  1526. CARLA_ASSERT(kData->oscData != nullptr);
  1527. if (kData->oscData && kData->oscData->target)
  1528. {
  1529. char targetPath[std::strlen(kData->oscData->path)+6];
  1530. std::strcpy(targetPath, kData->oscData->path);
  1531. std::strcat(targetPath, "/exit");
  1532. lo_send(kData->oscData->target, targetPath, "");
  1533. }
  1534. }
  1535. #else
  1536. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1537. {
  1538. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1539. CARLA_ASSERT(kData->oscData != nullptr);
  1540. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1541. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1542. {
  1543. char targetPath[std::strlen(kData->oscData->path)+20];
  1544. std::strcpy(targetPath, kData->oscData->path);
  1545. std::strcat(targetPath, "/bridge_audio_count");
  1546. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1547. }
  1548. }
  1549. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1550. {
  1551. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1552. CARLA_ASSERT(kData->oscData != nullptr);
  1553. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1554. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1555. {
  1556. char targetPath[std::strlen(kData->oscData->path)+19];
  1557. std::strcpy(targetPath, kData->oscData->path);
  1558. std::strcat(targetPath, "/bridge_midi_count");
  1559. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1560. }
  1561. }
  1562. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1563. {
  1564. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1565. CARLA_ASSERT(kData->oscData != nullptr);
  1566. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1567. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1568. {
  1569. char targetPath[std::strlen(kData->oscData->path)+24];
  1570. std::strcpy(targetPath, kData->oscData->path);
  1571. std::strcat(targetPath, "/bridge_parameter_count");
  1572. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1573. }
  1574. }
  1575. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1576. {
  1577. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1578. CARLA_ASSERT(kData->oscData != nullptr);
  1579. CARLA_ASSERT(count >= 0);
  1580. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1581. {
  1582. char targetPath[std::strlen(kData->oscData->path)+22];
  1583. std::strcpy(targetPath, kData->oscData->path);
  1584. std::strcat(targetPath, "/bridge_program_count");
  1585. lo_send(kData->oscData->target, targetPath, "i", count);
  1586. }
  1587. }
  1588. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1589. {
  1590. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1591. CARLA_ASSERT(kData->oscData != nullptr);
  1592. CARLA_ASSERT(count >= 0);
  1593. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1594. {
  1595. char targetPath[std::strlen(kData->oscData->path)+27];
  1596. std::strcpy(targetPath, kData->oscData->path);
  1597. std::strcat(targetPath, "/bridge_midi_program_count");
  1598. lo_send(kData->oscData->target, targetPath, "i", count);
  1599. }
  1600. }
  1601. 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)
  1602. {
  1603. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1604. CARLA_ASSERT(kData->oscData != nullptr);
  1605. CARLA_ASSERT(name != nullptr);
  1606. CARLA_ASSERT(label != nullptr);
  1607. CARLA_ASSERT(maker != nullptr);
  1608. CARLA_ASSERT(copyright != nullptr);
  1609. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1610. {
  1611. char targetPath[std::strlen(kData->oscData->path)+20];
  1612. std::strcpy(targetPath, kData->oscData->path);
  1613. std::strcat(targetPath, "/bridge_plugin_info");
  1614. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1615. }
  1616. }
  1617. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1618. {
  1619. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1620. CARLA_ASSERT(kData->oscData != nullptr);
  1621. CARLA_ASSERT(name != nullptr);
  1622. CARLA_ASSERT(unit != nullptr);
  1623. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1624. {
  1625. char targetPath[std::strlen(kData->oscData->path)+23];
  1626. std::strcpy(targetPath, kData->oscData->path);
  1627. std::strcat(targetPath, "/bridge_parameter_info");
  1628. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1629. }
  1630. }
  1631. 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)
  1632. {
  1633. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1634. CARLA_ASSERT(kData->oscData != nullptr);
  1635. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1636. {
  1637. char targetPath[std::strlen(kData->oscData->path)+23];
  1638. std::strcpy(targetPath, kData->oscData->path);
  1639. std::strcat(targetPath, "/bridge_parameter_data");
  1640. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1641. }
  1642. }
  1643. 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)
  1644. {
  1645. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1646. CARLA_ASSERT(kData->oscData != nullptr);
  1647. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1648. {
  1649. char targetPath[std::strlen(kData->oscData->path)+25];
  1650. std::strcpy(targetPath, kData->oscData->path);
  1651. std::strcat(targetPath, "/bridge_parameter_ranges");
  1652. lo_send(kData->oscData->target, targetPath, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1653. }
  1654. }
  1655. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1656. {
  1657. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1658. CARLA_ASSERT(kData->oscData != nullptr);
  1659. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1660. {
  1661. char targetPath[std::strlen(kData->oscData->path)+21];
  1662. std::strcpy(targetPath, kData->oscData->path);
  1663. std::strcat(targetPath, "/bridge_program_info");
  1664. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1665. }
  1666. }
  1667. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1668. {
  1669. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1670. CARLA_ASSERT(kData->oscData != nullptr);
  1671. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1672. {
  1673. char targetPath[std::strlen(kData->oscData->path)+26];
  1674. std::strcpy(targetPath, kData->oscData->path);
  1675. std::strcat(targetPath, "/bridge_midi_program_info");
  1676. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1677. }
  1678. }
  1679. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1680. {
  1681. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1682. CARLA_ASSERT(kData->oscData != nullptr);
  1683. CARLA_ASSERT(key != nullptr);
  1684. CARLA_ASSERT(value != nullptr);
  1685. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1686. {
  1687. char targetPath[std::strlen(kData->oscData->path)+18];
  1688. std::strcpy(targetPath, kData->oscData->path);
  1689. std::strcat(targetPath, "/bridge_configure");
  1690. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1691. }
  1692. }
  1693. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1694. {
  1695. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1696. CARLA_ASSERT(kData->oscData != nullptr);
  1697. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1698. {
  1699. char targetPath[std::strlen(kData->oscData->path)+28];
  1700. std::strcpy(targetPath, kData->oscData->path);
  1701. std::strcat(targetPath, "/bridge_set_parameter_value");
  1702. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1703. }
  1704. }
  1705. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1706. {
  1707. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1708. CARLA_ASSERT(kData->oscData != nullptr);
  1709. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1710. {
  1711. char targetPath[std::strlen(kData->oscData->path)+26];
  1712. std::strcpy(targetPath, kData->oscData->path);
  1713. std::strcat(targetPath, "/bridge_set_default_value");
  1714. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1715. }
  1716. }
  1717. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1718. {
  1719. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1720. CARLA_ASSERT(kData->oscData != nullptr);
  1721. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1722. {
  1723. char targetPath[std::strlen(kData->oscData->path)+20];
  1724. std::strcpy(targetPath, kData->oscData->path);
  1725. std::strcat(targetPath, "/bridge_set_program");
  1726. lo_send(kData->oscData->target, targetPath, "i", index);
  1727. }
  1728. }
  1729. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1730. {
  1731. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1732. CARLA_ASSERT(kData->oscData != nullptr);
  1733. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1734. {
  1735. char targetPath[std::strlen(kData->oscData->path)+25];
  1736. std::strcpy(targetPath, kData->oscData->path);
  1737. std::strcat(targetPath, "/bridge_set_midi_program");
  1738. lo_send(kData->oscData->target, targetPath, "i", index);
  1739. }
  1740. }
  1741. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1742. {
  1743. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1744. CARLA_ASSERT(kData->oscData != nullptr);
  1745. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1746. {
  1747. char targetPath[std::strlen(kData->oscData->path)+24];
  1748. std::strcpy(targetPath, kData->oscData->path);
  1749. std::strcat(targetPath, "/bridge_set_custom_data");
  1750. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  1751. }
  1752. }
  1753. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1754. {
  1755. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1756. CARLA_ASSERT(kData->oscData != nullptr);
  1757. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1758. {
  1759. char targetPath[std::strlen(kData->oscData->path)+23];
  1760. std::strcpy(targetPath, kData->oscData->path);
  1761. std::strcat(targetPath, "/bridge_set_chunk_data");
  1762. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  1763. }
  1764. }
  1765. void CarlaEngine::osc_send_bridge_set_peaks()
  1766. {
  1767. CARLA_ASSERT(kData->oscData != nullptr);
  1768. const EnginePluginData& pData = kData->plugins[0];
  1769. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1770. {
  1771. char targetPath[std::strlen(kData->oscData->path)+22];
  1772. std::strcpy(targetPath, kData->oscData->path);
  1773. std::strcat(targetPath, "/bridge_set_peaks");
  1774. lo_send(kData->oscData->target, targetPath, "ffff", pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1775. }
  1776. }
  1777. #endif
  1778. CARLA_BACKEND_END_NAMESPACE