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.

2180 lines
69KB

  1. /*
  2. * Carla Engine
  3. * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the GPL.txt file
  16. */
  17. #include "CarlaEngineInternal.hpp"
  18. #include "CarlaBackendUtils.hpp"
  19. #include "CarlaStateUtils.hpp"
  20. #include "CarlaMIDI.h"
  21. #include <QtCore/QDir>
  22. #include <QtCore/QFile>
  23. #include <QtCore/QFileInfo>
  24. #include <QtCore/QTextStream>
  25. CARLA_BACKEND_START_NAMESPACE
  26. // -------------------------------------------------------------------------------------------------------------------
  27. // Carla Engine port (Abstract)
  28. CarlaEnginePort::CarlaEnginePort(const bool isInput, const ProcessMode processMode)
  29. : kIsInput(isInput),
  30. kProcessMode(processMode)
  31. {
  32. carla_debug("CarlaEnginePort::CarlaEnginePort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  33. }
  34. CarlaEnginePort::~CarlaEnginePort()
  35. {
  36. carla_debug("CarlaEnginePort::~CarlaEnginePort()");
  37. }
  38. // -------------------------------------------------------------------------------------------------------------------
  39. // Carla Engine Audio port
  40. CarlaEngineAudioPort::CarlaEngineAudioPort(const bool isInput, const ProcessMode processMode)
  41. : CarlaEnginePort(isInput, processMode),
  42. fBuffer(nullptr)
  43. {
  44. carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  45. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  46. fBuffer = new float[PATCHBAY_BUFFER_SIZE];
  47. }
  48. CarlaEngineAudioPort::~CarlaEngineAudioPort()
  49. {
  50. carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()");
  51. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  52. {
  53. CARLA_ASSERT(fBuffer != nullptr);
  54. if (fBuffer != nullptr)
  55. delete[] fBuffer;
  56. }
  57. }
  58. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const)
  59. {
  60. if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  61. carla_zeroFloat(fBuffer, PATCHBAY_BUFFER_SIZE);
  62. }
  63. // -------------------------------------------------------------------------------------------------------------------
  64. // Carla Engine Event port
  65. static const EngineEvent kFallbackEngineEvent;
  66. CarlaEngineEventPort::CarlaEngineEventPort(const bool isInput, const ProcessMode processMode)
  67. : CarlaEnginePort(isInput, processMode),
  68. kMaxEventCount(processMode == PROCESS_MODE_CONTINUOUS_RACK ? RACK_EVENT_COUNT : PATCHBAY_EVENT_COUNT),
  69. fBuffer(nullptr)
  70. {
  71. carla_debug("CarlaEngineEventPort::CarlaEngineEventPort(%s, %s)", bool2str(isInput), ProcessMode2Str(processMode));
  72. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  73. fBuffer = new EngineEvent[PATCHBAY_EVENT_COUNT];
  74. }
  75. CarlaEngineEventPort::~CarlaEngineEventPort()
  76. {
  77. carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()");
  78. if (kProcessMode == PROCESS_MODE_PATCHBAY)
  79. {
  80. CARLA_ASSERT(fBuffer != nullptr);
  81. if (fBuffer != nullptr)
  82. delete[] fBuffer;
  83. }
  84. }
  85. void CarlaEngineEventPort::initBuffer(CarlaEngine* const engine)
  86. {
  87. CARLA_ASSERT(engine != nullptr);
  88. if (engine == nullptr)
  89. return;
  90. #ifndef BUILD_BRIDGE
  91. if (kProcessMode == PROCESS_MODE_CONTINUOUS_RACK)
  92. fBuffer = engine->getRackEventBuffer(kIsInput);
  93. else if (kProcessMode == PROCESS_MODE_PATCHBAY && ! kIsInput)
  94. carla_zeroMem(fBuffer, sizeof(EngineEvent)*PATCHBAY_EVENT_COUNT);
  95. #endif
  96. }
  97. uint32_t CarlaEngineEventPort::getEventCount()
  98. {
  99. CARLA_ASSERT(kIsInput);
  100. CARLA_ASSERT(fBuffer != nullptr);
  101. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY);
  102. if (! kIsInput)
  103. return 0;
  104. if (fBuffer == nullptr)
  105. return 0;
  106. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY)
  107. return 0;
  108. uint32_t count = 0;
  109. const EngineEvent* const events = fBuffer;
  110. for (uint32_t i=0; i < kMaxEventCount; i++, count++)
  111. {
  112. if (events[i].type == kEngineEventTypeNull)
  113. break;
  114. }
  115. return count;
  116. }
  117. const EngineEvent& CarlaEngineEventPort::getEvent(const uint32_t index)
  118. {
  119. CARLA_ASSERT(kIsInput);
  120. CARLA_ASSERT(fBuffer != nullptr);
  121. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY);
  122. CARLA_ASSERT(index < kMaxEventCount);
  123. if (! kIsInput)
  124. return kFallbackEngineEvent;
  125. if (fBuffer == nullptr)
  126. return kFallbackEngineEvent;
  127. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY)
  128. return kFallbackEngineEvent;
  129. if (index >= kMaxEventCount)
  130. return kFallbackEngineEvent;
  131. return fBuffer[index];
  132. }
  133. void CarlaEngineEventPort::writeControlEvent(const uint32_t time, const uint8_t channel, const EngineControlEventType type, const uint16_t param, const double value)
  134. {
  135. CARLA_ASSERT(! kIsInput);
  136. CARLA_ASSERT(fBuffer != nullptr);
  137. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY);
  138. CARLA_ASSERT(type != kEngineControlEventTypeNull);
  139. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  140. CARLA_SAFE_ASSERT(value >= 0.0 && value <= 1.0);
  141. if (kIsInput)
  142. return;
  143. if (fBuffer == nullptr)
  144. return;
  145. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY)
  146. return;
  147. if (type == kEngineControlEventTypeNull)
  148. return;
  149. if (channel >= MAX_MIDI_CHANNELS)
  150. return;
  151. if (type == kEngineControlEventTypeParameter)
  152. {
  153. CARLA_ASSERT(! MIDI_IS_CONTROL_BANK_SELECT(param));
  154. }
  155. for (uint32_t i=0; i < kMaxEventCount; i++)
  156. {
  157. if (fBuffer[i].type != kEngineEventTypeNull)
  158. continue;
  159. fBuffer[i].type = kEngineEventTypeControl;
  160. fBuffer[i].time = time;
  161. fBuffer[i].channel = channel;
  162. fBuffer[i].ctrl.type = type;
  163. fBuffer[i].ctrl.param = param;
  164. fBuffer[i].ctrl.value = carla_fixValue<double>(0.0, 1.0, value);
  165. return;
  166. }
  167. carla_stderr2("CarlaEngineEventPort::writeControlEvent() - buffer full");
  168. }
  169. void CarlaEngineEventPort::writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t* const data, const uint8_t size)
  170. {
  171. CARLA_ASSERT(! kIsInput);
  172. CARLA_ASSERT(fBuffer != nullptr);
  173. CARLA_ASSERT(kProcessMode == PROCESS_MODE_CONTINUOUS_RACK || kProcessMode == PROCESS_MODE_PATCHBAY);
  174. CARLA_ASSERT(channel < MAX_MIDI_CHANNELS);
  175. CARLA_ASSERT(data != nullptr);
  176. CARLA_ASSERT(size > 0);
  177. if (kIsInput)
  178. return;
  179. if (fBuffer == nullptr)
  180. return;
  181. if (kProcessMode != PROCESS_MODE_CONTINUOUS_RACK && kProcessMode != PROCESS_MODE_PATCHBAY)
  182. return;
  183. if (channel >= MAX_MIDI_CHANNELS)
  184. return;
  185. if (data == nullptr)
  186. return;
  187. if (size == 0)
  188. return;
  189. if (size > 3)
  190. return;
  191. for (uint32_t i=0; i < kMaxEventCount; i++)
  192. {
  193. if (fBuffer[i].type != kEngineEventTypeNull)
  194. continue;
  195. fBuffer[i].type = kEngineEventTypeMidi;
  196. fBuffer[i].time = time;
  197. fBuffer[i].channel = channel;
  198. fBuffer[i].midi.port = port;
  199. fBuffer[i].midi.data[0] = data[0];
  200. fBuffer[i].midi.data[1] = data[1];
  201. fBuffer[i].midi.data[2] = data[2];
  202. fBuffer[i].midi.size = size;
  203. return;
  204. }
  205. carla_stderr2("CarlaEngineEventPort::writeMidiEvent() - buffer full");
  206. }
  207. // -------------------------------------------------------------------------------------------------------------------
  208. // Carla Engine client (Abstract)
  209. CarlaEngineClient::CarlaEngineClient(const EngineType engineType, const ProcessMode processMode)
  210. : kEngineType(engineType),
  211. kProcessMode(processMode),
  212. fActive(false),
  213. fLatency(0)
  214. {
  215. carla_debug("CarlaEngineClient::CarlaEngineClient(%s, %s)", EngineType2Str(engineType), ProcessMode2Str(processMode));
  216. CARLA_ASSERT(engineType != kEngineTypeNull);
  217. }
  218. CarlaEngineClient::~CarlaEngineClient()
  219. {
  220. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  221. CARLA_ASSERT(! fActive);
  222. }
  223. void CarlaEngineClient::activate()
  224. {
  225. carla_debug("CarlaEngineClient::activate()");
  226. CARLA_ASSERT(! fActive);
  227. fActive = true;
  228. }
  229. void CarlaEngineClient::deactivate()
  230. {
  231. carla_debug("CarlaEngineClient::deactivate()");
  232. CARLA_ASSERT(fActive);
  233. fActive = false;
  234. }
  235. bool CarlaEngineClient::isActive() const
  236. {
  237. carla_debug("CarlaEngineClient::isActive()");
  238. return fActive;
  239. }
  240. bool CarlaEngineClient::isOk() const
  241. {
  242. carla_debug("CarlaEngineClient::isOk()");
  243. return true;
  244. }
  245. uint32_t CarlaEngineClient::getLatency() const
  246. {
  247. return fLatency;
  248. }
  249. void CarlaEngineClient::setLatency(const uint32_t samples)
  250. {
  251. fLatency = samples;
  252. }
  253. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  254. {
  255. carla_debug("CarlaEngineClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput));
  256. switch (portType)
  257. {
  258. case kEnginePortTypeNull:
  259. break;
  260. case kEnginePortTypeAudio:
  261. return new CarlaEngineAudioPort(isInput, kProcessMode);
  262. case kEnginePortTypeEvent:
  263. return new CarlaEngineEventPort(isInput, kProcessMode);
  264. }
  265. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  266. return nullptr;
  267. }
  268. // -------------------------------------------------------------------------------------------------------------------
  269. // Carla Engine
  270. CarlaEngine::CarlaEngine()
  271. : fBufferSize(0),
  272. fSampleRate(0.0),
  273. kData(new CarlaEngineProtectedData(this))
  274. {
  275. carla_debug("CarlaEngine::CarlaEngine()");
  276. }
  277. CarlaEngine::~CarlaEngine()
  278. {
  279. carla_debug("CarlaEngine::~CarlaEngine()");
  280. delete kData;
  281. }
  282. // -----------------------------------------------------------------------
  283. // Helpers
  284. void doPluginRemove(CarlaEngineProtectedData* const kData, const bool unlock)
  285. {
  286. CARLA_ASSERT(kData->curPluginCount > 0);
  287. kData->curPluginCount--;
  288. const unsigned int id = kData->nextAction.pluginId;
  289. // reset current plugin
  290. kData->plugins[id].plugin = nullptr;
  291. CarlaPlugin* plugin;
  292. // move all plugins 1 spot backwards
  293. for (unsigned int i=id; i < kData->curPluginCount; i++)
  294. {
  295. plugin = kData->plugins[i+1].plugin;
  296. CARLA_ASSERT(plugin);
  297. if (plugin == nullptr)
  298. break;
  299. plugin->setId(i);
  300. kData->plugins[i].plugin = plugin;
  301. kData->plugins[i].insPeak[0] = 0.0f;
  302. kData->plugins[i].insPeak[1] = 0.0f;
  303. kData->plugins[i].outsPeak[0] = 0.0f;
  304. kData->plugins[i].outsPeak[1] = 0.0f;
  305. }
  306. kData->nextAction.opcode = EnginePostActionNull;
  307. if (unlock)
  308. kData->nextAction.mutex.unlock();
  309. }
  310. const char* findDSSIGUI(const char* const filename, const char* const label)
  311. {
  312. QString guiFilename;
  313. guiFilename.clear();
  314. QString pluginDir(filename);
  315. pluginDir.resize(pluginDir.lastIndexOf("."));
  316. QString shortName = QFileInfo(pluginDir).baseName();
  317. QString checkLabel = QString(label);
  318. QString checkSName = shortName;
  319. if (! checkLabel.endsWith("_")) checkLabel += "_";
  320. if (! checkSName.endsWith("_")) checkSName += "_";
  321. QStringList guiFiles = QDir(pluginDir).entryList();
  322. foreach (const QString& gui, guiFiles)
  323. {
  324. if (gui.startsWith(checkLabel) || gui.startsWith(checkSName))
  325. {
  326. QFileInfo finalname(pluginDir + QDir::separator() + gui);
  327. guiFilename = finalname.absoluteFilePath();
  328. break;
  329. }
  330. }
  331. if (guiFilename.isEmpty())
  332. return nullptr;
  333. return carla_strdup(guiFilename.toUtf8().constData());
  334. }
  335. // -----------------------------------------------------------------------
  336. // Static values and calls
  337. unsigned int CarlaEngine::getDriverCount()
  338. {
  339. carla_debug("CarlaEngine::getDriverCount()");
  340. unsigned int count = 0;
  341. #ifdef WANT_JACK
  342. count += 1;
  343. #endif
  344. #ifdef WANT_RTAUDIO
  345. count += getRtAudioApiCount();
  346. #endif
  347. return count;
  348. }
  349. const char* CarlaEngine::getDriverName(unsigned int index)
  350. {
  351. carla_debug("CarlaEngine::getDriverName(%i)", index);
  352. #ifdef WANT_JACK
  353. if (index == 0)
  354. return "JACK";
  355. else
  356. index -= 1;
  357. #endif
  358. #ifdef WANT_RTAUDIO
  359. if (index < getRtAudioApiCount())
  360. return getRtAudioApiName(index);
  361. #endif
  362. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index);
  363. return nullptr;
  364. }
  365. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  366. {
  367. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  368. #ifdef WANT_JACK
  369. if (std::strcmp(driverName, "JACK") == 0)
  370. return newJack();
  371. #else
  372. if (false)
  373. pass();
  374. #endif
  375. #ifdef WANT_RTAUDIO
  376. # ifdef __LINUX_ALSA__
  377. else if (std::strcmp(driverName, "ALSA") == 0)
  378. return newRtAudio(RTAUDIO_LINUX_ALSA);
  379. # endif
  380. # ifdef __LINUX_PULSE__
  381. else if (std::strcmp(driverName, "PulseAudio") == 0)
  382. return newRtAudio(RTAUDIO_LINUX_PULSE);
  383. # endif
  384. # ifdef __LINUX_OSS__
  385. else if (std::strcmp(driverName, "OSS") == 0)
  386. return newRtAudio(RTAUDIO_LINUX_OSS);
  387. # endif
  388. # ifdef __UNIX_JACK__
  389. else if (std::strcmp(driverName, "JACK (RtAudio)") == 0)
  390. return newRtAudio(RTAUDIO_UNIX_JACK);
  391. # endif
  392. # ifdef __MACOSX_CORE__
  393. else if (std::strcmp(driverName, "CoreAudio") == 0)
  394. return newRtAudio(RTAUDIO_MACOSX_CORE);
  395. # endif
  396. # ifdef __WINDOWS_ASIO__
  397. else if (std::strcmp(driverName, "ASIO") == 0)
  398. return newRtAudio(RTAUDIO_WINDOWS_ASIO);
  399. # endif
  400. # ifdef __WINDOWS_DS__
  401. else if (std::strcmp(driverName, "DirectSound") == 0)
  402. return newRtAudio(RTAUDIO_WINDOWS_DS);
  403. # endif
  404. #endif
  405. return nullptr;
  406. }
  407. // -----------------------------------------------------------------------
  408. // Maximum values
  409. unsigned int CarlaEngine::maxClientNameSize() const
  410. {
  411. return STR_MAX/2;
  412. }
  413. unsigned int CarlaEngine::maxPortNameSize() const
  414. {
  415. return STR_MAX;
  416. }
  417. unsigned int CarlaEngine::currentPluginCount() const
  418. {
  419. return kData->curPluginCount;
  420. }
  421. unsigned int CarlaEngine::maxPluginNumber() const
  422. {
  423. return kData->maxPluginNumber;
  424. }
  425. // -----------------------------------------------------------------------
  426. // Virtual, per-engine type calls
  427. bool CarlaEngine::init(const char* const clientName)
  428. {
  429. carla_debug("CarlaEngine::init(\"%s\")", clientName);
  430. CARLA_ASSERT(kData->plugins == nullptr);
  431. fName = clientName;
  432. fName.toBasic();
  433. fTimeInfo.clear();
  434. kData->aboutToClose = false;
  435. kData->curPluginCount = 0;
  436. switch (fOptions.processMode)
  437. {
  438. case PROCESS_MODE_CONTINUOUS_RACK:
  439. kData->maxPluginNumber = MAX_RACK_PLUGINS;
  440. kData->rack.in = new EngineEvent[RACK_EVENT_COUNT];
  441. kData->rack.out = new EngineEvent[RACK_EVENT_COUNT];
  442. break;
  443. case PROCESS_MODE_PATCHBAY:
  444. kData->maxPluginNumber = MAX_PATCHBAY_PLUGINS;
  445. break;
  446. case PROCESS_MODE_BRIDGE:
  447. kData->maxPluginNumber = 1;
  448. break;
  449. default:
  450. kData->maxPluginNumber = MAX_DEFAULT_PLUGINS;
  451. break;
  452. }
  453. //kData->pluginsPool.resize(maxPluginNumber, 999);
  454. kData->plugins = new EnginePluginData[kData->maxPluginNumber];
  455. kData->osc.init(clientName);
  456. #ifndef BUILD_BRIDGE
  457. kData->oscData = kData->osc.getControlData();
  458. #else
  459. kData->oscData = nullptr; // set later in setOscBridgeData()
  460. #endif
  461. #ifndef BUILD_BRIDGE
  462. //if (std::strcmp(clientName, "Carla") != 0)
  463. carla_setprocname(clientName);
  464. #endif
  465. kData->nextAction.ready();
  466. kData->thread.startNow();
  467. return true;
  468. }
  469. bool CarlaEngine::close()
  470. {
  471. carla_debug("CarlaEngine::close()");
  472. CARLA_ASSERT(kData->plugins != nullptr);
  473. kData->nextAction.ready();
  474. kData->thread.stopNow();
  475. #ifndef BUILD_BRIDGE
  476. osc_send_control_exit();
  477. #endif
  478. kData->osc.close();
  479. kData->oscData = nullptr;
  480. kData->aboutToClose = true;
  481. kData->curPluginCount = 0;
  482. kData->maxPluginNumber = 0;
  483. //kData->plugins.clear();
  484. if (kData->plugins != nullptr)
  485. {
  486. delete[] kData->plugins;
  487. kData->plugins = nullptr;
  488. }
  489. if (kData->rack.in != nullptr)
  490. {
  491. delete[] kData->rack.in;
  492. kData->rack.in = nullptr;
  493. }
  494. if (kData->rack.out != nullptr)
  495. {
  496. delete[] kData->rack.out;
  497. kData->rack.out = nullptr;
  498. }
  499. fName.clear();
  500. return true;
  501. }
  502. void CarlaEngine::idle()
  503. {
  504. CARLA_ASSERT(kData->plugins != nullptr);
  505. CARLA_ASSERT(isRunning());
  506. #if 0
  507. for (auto it = kData->plugins.begin(); it.valid(); it.next())
  508. {
  509. CarlaPlugin* const plugin = (*it).plugin;
  510. CARLA_ASSERT(plugin != nullptr);
  511. if (plugin && plugin->enabled())
  512. plugin->idleGui();
  513. }
  514. #endif
  515. for (unsigned int i=0; i < kData->curPluginCount; i++)
  516. {
  517. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  518. if (plugin && 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. const void* extraStuff = nullptr;
  825. if (std::strcmp(saveState.type, "DSSI") == 0)
  826. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  827. // TODO - proper find&load plugins
  828. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  829. {
  830. if (CarlaPlugin* plugin = getPlugin(kData->curPluginCount-1))
  831. plugin->loadSaveState(saveState);
  832. }
  833. }
  834. node = node.nextSibling();
  835. }
  836. return true;
  837. }
  838. bool CarlaEngine::saveProject(const char* const filename)
  839. {
  840. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  841. CARLA_ASSERT(filename != nullptr);
  842. QFile file(filename);
  843. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  844. return false;
  845. QTextStream out(&file);
  846. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  847. out << "<!DOCTYPE CARLA-PROJECT>\n";
  848. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  849. bool firstPlugin = true;
  850. char strBuf[STR_MAX];
  851. for (unsigned int i=0; i < kData->curPluginCount; i++)
  852. {
  853. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  854. if (plugin != nullptr && plugin->enabled())
  855. {
  856. if (! firstPlugin)
  857. out << "\n";
  858. plugin->getRealName(strBuf);
  859. if (*strBuf != 0)
  860. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  861. out << " <Plugin>\n";
  862. out << getXMLFromSaveState(plugin->getSaveState());
  863. out << " </Plugin>\n";
  864. firstPlugin = false;
  865. }
  866. }
  867. out << "</CARLA-PROJECT>\n";
  868. file.close();
  869. return true;
  870. }
  871. // -----------------------------------------------------------------------
  872. // Information (peaks)
  873. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  874. {
  875. CARLA_ASSERT(pluginId < kData->curPluginCount);
  876. CARLA_ASSERT(id-1 < MAX_PEAKS);
  877. if (id == 0 || id > MAX_PEAKS)
  878. return 0.0f;
  879. return kData->plugins[pluginId].insPeak[id-1];
  880. }
  881. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  882. {
  883. CARLA_ASSERT(pluginId < kData->curPluginCount);
  884. CARLA_ASSERT(id-1 < MAX_PEAKS);
  885. if (id == 0 || id > MAX_PEAKS)
  886. return 0.0f;
  887. return kData->plugins[pluginId].outsPeak[id-1];
  888. }
  889. // -----------------------------------------------------------------------
  890. // Callback
  891. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  892. {
  893. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  894. if (kData->callback)
  895. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  896. }
  897. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  898. {
  899. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  900. CARLA_ASSERT(func);
  901. kData->callback = func;
  902. kData->callbackPtr = ptr;
  903. }
  904. // -----------------------------------------------------------------------
  905. // Patchbay
  906. void CarlaEngine::patchbayConnect(int, int)
  907. {
  908. // nothing
  909. }
  910. void CarlaEngine::patchbayDisconnect(int)
  911. {
  912. // nothing
  913. }
  914. // -----------------------------------------------------------------------
  915. // Transport
  916. void CarlaEngine::transportPlay()
  917. {
  918. kData->time.playing = true;
  919. }
  920. void CarlaEngine::transportPause()
  921. {
  922. kData->time.playing = false;
  923. }
  924. void CarlaEngine::transportRelocate(const uint32_t frame)
  925. {
  926. kData->time.frame = frame;
  927. }
  928. // -----------------------------------------------------------------------
  929. // Error handling
  930. const char* CarlaEngine::getLastError() const
  931. {
  932. return (const char*)kData->lastError;
  933. }
  934. void CarlaEngine::setLastError(const char* const error)
  935. {
  936. kData->lastError = error;
  937. }
  938. void CarlaEngine::setAboutToClose()
  939. {
  940. carla_debug("CarlaEngine::setAboutToClose()");
  941. kData->aboutToClose = true;
  942. }
  943. // -----------------------------------------------------------------------
  944. // Global options
  945. #ifndef BUILD_BRIDGE
  946. const QProcessEnvironment& CarlaEngine::getOptionsAsProcessEnvironment() const
  947. {
  948. return kData->procEnv;
  949. }
  950. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  951. if (isRunning()) \
  952. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  953. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  954. {
  955. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  956. switch (option)
  957. {
  958. case OPTION_PROCESS_NAME:
  959. carla_setprocname(valueStr);
  960. break;
  961. case OPTION_PROCESS_MODE:
  962. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  963. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_PATCHBAY)
  964. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  965. fOptions.processMode = static_cast<ProcessMode>(value);
  966. break;
  967. case OPTION_TRANSPORT_MODE:
  968. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_JACK)
  969. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  970. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  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