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.

2176 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_GIG:
  615. plugin = CarlaPlugin::newGIG(init, (extra != nullptr));
  616. break;
  617. case PLUGIN_SF2:
  618. plugin = CarlaPlugin::newSF2(init, (extra != nullptr));
  619. break;
  620. case PLUGIN_SFZ:
  621. plugin = CarlaPlugin::newSFZ(init, (extra != nullptr));
  622. break;
  623. }
  624. }
  625. if (plugin == nullptr)
  626. return false;
  627. plugin->registerToOscClient();
  628. kData->plugins[id].plugin = plugin;
  629. kData->plugins[id].insPeak[0] = 0.0f;
  630. kData->plugins[id].insPeak[1] = 0.0f;
  631. kData->plugins[id].outsPeak[0] = 0.0f;
  632. kData->plugins[id].outsPeak[1] = 0.0f;
  633. kData->curPluginCount += 1;
  634. // FIXME
  635. callback(CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, nullptr);
  636. return true;
  637. }
  638. bool CarlaEngine::removePlugin(const unsigned int id)
  639. {
  640. carla_debug("CarlaEngine::removePlugin(%i)", id);
  641. CARLA_ASSERT(kData->curPluginCount > 0);
  642. CARLA_ASSERT(id < kData->curPluginCount);
  643. CARLA_ASSERT(kData->plugins != nullptr);
  644. if (kData->plugins == nullptr)
  645. {
  646. setLastError("Critical error: no plugins are currently loaded!");
  647. return false;
  648. }
  649. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  650. CARLA_ASSERT(plugin != nullptr);
  651. if (plugin != nullptr)
  652. {
  653. CARLA_ASSERT(plugin->id() == id);
  654. kData->thread.stopNow();
  655. kData->nextAction.pluginId = id;
  656. kData->nextAction.opcode = EnginePostActionRemovePlugin;
  657. kData->nextAction.mutex.lock();
  658. if (isRunning())
  659. {
  660. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking START", id);
  661. // block wait for unlock on proccessing side
  662. kData->nextAction.mutex.lock();
  663. carla_stderr("CarlaEngine::removePlugin(%i) - remove blocking DONE", id);
  664. }
  665. else
  666. {
  667. doPluginRemove(kData, false);
  668. }
  669. #ifndef BUILD_BRIDGE
  670. if (isOscControlRegistered())
  671. osc_send_control_remove_plugin(id);
  672. #endif
  673. delete plugin;
  674. kData->nextAction.mutex.unlock();
  675. if (isRunning() && ! kData->aboutToClose)
  676. kData->thread.startNow();
  677. // FIXME
  678. callback(CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  679. return true;
  680. }
  681. carla_stderr("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  682. setLastError("Could not find plugin to remove");
  683. return false;
  684. }
  685. void CarlaEngine::removeAllPlugins()
  686. {
  687. carla_debug("CarlaEngine::removeAllPlugins() - START");
  688. kData->thread.stopNow();
  689. if (kData->curPluginCount > 0)
  690. {
  691. const unsigned int oldCount = kData->curPluginCount;
  692. kData->curPluginCount = 0;
  693. for (unsigned int i=0; i < oldCount; i++)
  694. {
  695. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  696. CARLA_ASSERT(plugin != nullptr);
  697. kData->plugins[i].plugin = nullptr;
  698. if (plugin != nullptr)
  699. delete plugin;
  700. // clear this plugin
  701. kData->plugins[i].insPeak[0] = 0.0f;
  702. kData->plugins[i].insPeak[1] = 0.0f;
  703. kData->plugins[i].outsPeak[0] = 0.0f;
  704. kData->plugins[i].outsPeak[1] = 0.0f;
  705. }
  706. }
  707. if (isRunning() && ! kData->aboutToClose)
  708. kData->thread.startNow();
  709. carla_debug("CarlaEngine::removeAllPlugins() - END");
  710. }
  711. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  712. {
  713. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, kData->curPluginCount);
  714. CARLA_ASSERT(kData->curPluginCount > 0);
  715. CARLA_ASSERT(id < kData->curPluginCount);
  716. CARLA_ASSERT(kData->plugins != nullptr);
  717. if (id < kData->curPluginCount && kData->plugins != nullptr)
  718. return kData->plugins[id].plugin;
  719. return nullptr;
  720. }
  721. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const
  722. {
  723. return kData->plugins[id].plugin;
  724. }
  725. const char* CarlaEngine::getNewUniquePluginName(const char* const name)
  726. {
  727. carla_debug("CarlaEngine::getNewUniquePluginName(\"%s\")", name);
  728. CARLA_ASSERT(kData->maxPluginNumber > 0);
  729. CARLA_ASSERT(kData->plugins != nullptr);
  730. CARLA_ASSERT(name != nullptr);
  731. static CarlaString sname;
  732. sname = name;
  733. if (sname.isEmpty() || kData->plugins == nullptr)
  734. {
  735. sname = "(No name)";
  736. return (const char*)sname;
  737. }
  738. sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  739. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  740. for (unsigned short i=0; i < kData->curPluginCount; i++)
  741. {
  742. CARLA_ASSERT(kData->plugins[i].plugin);
  743. if (kData->plugins[i].plugin == nullptr)
  744. continue;
  745. // Check if unique name doesn't exist
  746. if (const char* const pluginName = kData->plugins[i].plugin->name())
  747. {
  748. if (sname != pluginName)
  749. continue;
  750. }
  751. // Check if string has already been modified
  752. {
  753. const size_t len = sname.length();
  754. // 1 digit, ex: " (2)"
  755. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  756. {
  757. int number = sname[len-2] - '0';
  758. if (number == 9)
  759. {
  760. // next number is 10, 2 digits
  761. sname.truncate(len-4);
  762. sname += " (10)";
  763. //sname.replace(" (9)", " (10)");
  764. }
  765. else
  766. sname[len-2] = char('0' + number + 1);
  767. continue;
  768. }
  769. // 2 digits, ex: " (11)"
  770. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  771. {
  772. char n2 = sname[len-2];
  773. char n3 = sname[len-3];
  774. if (n2 == '9')
  775. {
  776. n2 = '0';
  777. n3 += 1;
  778. }
  779. else
  780. n2 += 1;
  781. sname[len-2] = n2;
  782. sname[len-3] = n3;
  783. continue;
  784. }
  785. }
  786. // Modify string if not
  787. sname += " (2)";
  788. }
  789. return (const char*)sname;
  790. }
  791. #if 0
  792. void CarlaEngine::__bridgePluginRegister(const unsigned short id, CarlaPlugin* const plugin)
  793. {
  794. data->carlaPlugins[id] = plugin;
  795. }
  796. #endif
  797. // -----------------------------------------------------------------------
  798. // Information (base)
  799. bool CarlaEngine::loadProject(const char* const filename)
  800. {
  801. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  802. CARLA_ASSERT(filename != nullptr);
  803. QFile file(filename);
  804. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  805. return false;
  806. QDomDocument xml;
  807. xml.setContent(file.readAll());
  808. file.close();
  809. QDomNode xmlNode(xml.documentElement());
  810. if (xmlNode.toElement().tagName() != "CARLA-PROJECT")
  811. {
  812. carla_stderr2("Not a valid Carla project file");
  813. return false;
  814. }
  815. QDomNode node(xmlNode.firstChild());
  816. while (! node.isNull())
  817. {
  818. if (node.toElement().tagName() == "Plugin")
  819. {
  820. const SaveState& saveState = getSaveStateDictFromXML(node);
  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. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_JACK)
  966. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  967. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  968. break;
  969. case OPTION_MAX_PARAMETERS:
  970. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  971. if (value < 0)
  972. return; // TODO error here
  973. fOptions.maxParameters = static_cast<uint>(value);
  974. break;
  975. case OPTION_PREFERRED_BUFFER_SIZE:
  976. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  977. fOptions.preferredBufferSize = static_cast<uint>(value);
  978. break;
  979. case OPTION_PREFERRED_SAMPLE_RATE:
  980. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  981. fOptions.preferredSampleRate = static_cast<uint>(value);
  982. break;
  983. case OPTION_FORCE_STEREO:
  984. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  985. fOptions.forceStereo = (value != 0);
  986. break;
  987. #ifdef WANT_DSSI
  988. case OPTION_USE_DSSI_VST_CHUNKS:
  989. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  990. fOptions.useDssiVstChunks = (value != 0);
  991. break;
  992. #endif
  993. case OPTION_PREFER_PLUGIN_BRIDGES:
  994. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  995. fOptions.preferPluginBridges = (value != 0);
  996. break;
  997. case OPTION_PREFER_UI_BRIDGES:
  998. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  999. fOptions.preferUiBridges = (value != 0);
  1000. break;
  1001. case OPTION_OSC_UI_TIMEOUT:
  1002. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1003. fOptions.oscUiTimeout = static_cast<uint>(value);
  1004. break;
  1005. case OPTION_PATH_BRIDGE_NATIVE:
  1006. fOptions.bridge_native = valueStr;
  1007. break;
  1008. case OPTION_PATH_BRIDGE_POSIX32:
  1009. fOptions.bridge_posix32 = valueStr;
  1010. break;
  1011. case OPTION_PATH_BRIDGE_POSIX64:
  1012. fOptions.bridge_posix64 = valueStr;
  1013. break;
  1014. case OPTION_PATH_BRIDGE_WIN32:
  1015. fOptions.bridge_win32 = valueStr;
  1016. break;
  1017. case OPTION_PATH_BRIDGE_WIN64:
  1018. fOptions.bridge_win64 = valueStr;
  1019. break;
  1020. #ifdef WANT_LV2
  1021. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1022. fOptions.bridge_lv2gtk2 = valueStr;
  1023. break;
  1024. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1025. fOptions.bridge_lv2gtk3 = valueStr;
  1026. break;
  1027. case OPTION_PATH_BRIDGE_LV2_QT4:
  1028. fOptions.bridge_lv2qt4 = valueStr;
  1029. break;
  1030. case OPTION_PATH_BRIDGE_LV2_QT5:
  1031. fOptions.bridge_lv2qt5 = valueStr;
  1032. break;
  1033. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1034. fOptions.bridge_lv2cocoa = valueStr;
  1035. break;
  1036. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1037. fOptions.bridge_lv2win = valueStr;
  1038. break;
  1039. case OPTION_PATH_BRIDGE_LV2_X11:
  1040. fOptions.bridge_lv2x11 = valueStr;
  1041. break;
  1042. #endif
  1043. #ifdef WANT_VST
  1044. case OPTION_PATH_BRIDGE_VST_COCOA:
  1045. fOptions.bridge_vstcocoa = valueStr;
  1046. break;
  1047. case OPTION_PATH_BRIDGE_VST_HWND:
  1048. fOptions.bridge_vsthwnd = valueStr;
  1049. break;
  1050. case OPTION_PATH_BRIDGE_VST_X11:
  1051. fOptions.bridge_vstx11 = valueStr;
  1052. break;
  1053. #endif
  1054. }
  1055. }
  1056. #endif
  1057. // -----------------------------------------------------------------------
  1058. // OSC Stuff
  1059. #ifdef BUILD_BRIDGE
  1060. bool CarlaEngine::isOscBridgeRegistered() const
  1061. {
  1062. return (kData->oscData != nullptr);
  1063. }
  1064. #else
  1065. bool CarlaEngine::isOscControlRegistered() const
  1066. {
  1067. return kData->osc.isControlRegistered();
  1068. }
  1069. #endif
  1070. void CarlaEngine::idleOsc()
  1071. {
  1072. kData->osc.idle();
  1073. }
  1074. const char* CarlaEngine::getOscServerPathTCP() const
  1075. {
  1076. return kData->osc.getServerPathTCP();
  1077. }
  1078. const char* CarlaEngine::getOscServerPathUDP() const
  1079. {
  1080. return kData->osc.getServerPathUDP();
  1081. }
  1082. #ifdef BUILD_BRIDGE
  1083. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1084. {
  1085. kData->oscData = oscData;
  1086. }
  1087. #endif
  1088. // -----------------------------------------------------------------------
  1089. // protected calls
  1090. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1091. {
  1092. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1093. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1094. {
  1095. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1096. if (plugin != nullptr && plugin->enabled())
  1097. plugin->bufferSizeChanged(newBufferSize);
  1098. }
  1099. }
  1100. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1101. {
  1102. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1103. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1104. {
  1105. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1106. if (plugin != nullptr && plugin->enabled())
  1107. plugin->sampleRateChanged(newSampleRate);
  1108. }
  1109. }
  1110. void CarlaEngine::proccessPendingEvents()
  1111. {
  1112. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1113. switch (kData->nextAction.opcode)
  1114. {
  1115. case EnginePostActionNull:
  1116. break;
  1117. case EnginePostActionRemovePlugin:
  1118. doPluginRemove(kData, true);
  1119. break;
  1120. }
  1121. if (kData->time.playing)
  1122. kData->time.frame += fBufferSize;
  1123. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1124. {
  1125. fTimeInfo.playing = kData->time.playing;
  1126. fTimeInfo.frame = kData->time.frame;
  1127. }
  1128. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1129. {
  1130. // TODO - peak values?
  1131. }
  1132. }
  1133. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS])
  1134. {
  1135. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1136. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1137. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1138. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1139. }
  1140. #ifndef BUILD_BRIDGE
  1141. EngineEvent* CarlaEngine::getRackEventBuffer(const bool isInput)
  1142. {
  1143. return isInput ? kData->rack.in : kData->rack.out;
  1144. }
  1145. void setValueIfHigher(float& value, const float& compare)
  1146. {
  1147. if (value < compare)
  1148. value = compare;
  1149. }
  1150. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1151. {
  1152. // initialize outputs (zero)
  1153. carla_zeroFloat(outBuf[0], frames);
  1154. carla_zeroFloat(outBuf[1], frames);
  1155. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1156. bool processed = false;
  1157. // process plugins
  1158. for (unsigned int i=0; i < kData->curPluginCount; i++)
  1159. {
  1160. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1161. if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock())
  1162. continue;
  1163. if (processed)
  1164. {
  1165. // initialize inputs (from previous outputs)
  1166. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1167. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1168. std::memcpy(kData->rack.in, kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1169. // initialize outputs (zero)
  1170. carla_zeroFloat(outBuf[0], frames);
  1171. carla_zeroFloat(outBuf[1], frames);
  1172. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1173. }
  1174. // process
  1175. plugin->initBuffers();
  1176. plugin->process(inBuf, outBuf, frames);
  1177. plugin->unlock();
  1178. #if 0
  1179. // if plugin has no audio inputs, add previous buffers
  1180. if (plugin->audioInCount() == 0)
  1181. {
  1182. for (uint32_t j=0; j < frames; j++)
  1183. {
  1184. outBuf[0][j] += inBuf[0][j];
  1185. outBuf[1][j] += inBuf[1][j];
  1186. }
  1187. }
  1188. // if plugin has no midi output, add previous events
  1189. if (plugin->midiOutCount() == 0)
  1190. {
  1191. for (uint32_t j=0, k=0; j < frames; j++)
  1192. {
  1193. }
  1194. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1195. }
  1196. #endif
  1197. // set peaks
  1198. {
  1199. float inPeak1 = 0.0f;
  1200. float inPeak2 = 0.0f;
  1201. float outPeak1 = 0.0f;
  1202. float outPeak2 = 0.0f;
  1203. for (uint32_t k=0; k < frames; k++)
  1204. {
  1205. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1206. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1207. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1208. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1209. }
  1210. kData->plugins[i].insPeak[0] = inPeak1;
  1211. kData->plugins[i].insPeak[1] = inPeak2;
  1212. kData->plugins[i].outsPeak[0] = outPeak1;
  1213. kData->plugins[i].outsPeak[1] = outPeak2;
  1214. }
  1215. processed = true;
  1216. }
  1217. }
  1218. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1219. {
  1220. // TODO
  1221. return;
  1222. // unused, for now
  1223. (void)inBuf;
  1224. (void)outBuf;
  1225. (void)bufCount;
  1226. (void)frames;
  1227. }
  1228. #endif
  1229. // -------------------------------------------------------------------------------------------------------------------
  1230. // Carla Engine OSC stuff
  1231. #ifndef BUILD_BRIDGE
  1232. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1233. {
  1234. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1235. CARLA_ASSERT(kData->oscData != nullptr);
  1236. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1237. CARLA_ASSERT(pluginName);
  1238. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1239. {
  1240. char targetPath[std::strlen(kData->oscData->path)+18];
  1241. std::strcpy(targetPath, kData->oscData->path);
  1242. std::strcat(targetPath, "/add_plugin_start");
  1243. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1244. }
  1245. }
  1246. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1247. {
  1248. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1249. CARLA_ASSERT(kData->oscData != nullptr);
  1250. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1251. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1252. {
  1253. char targetPath[std::strlen(kData->oscData->path)+16];
  1254. std::strcpy(targetPath, kData->oscData->path);
  1255. std::strcat(targetPath, "/add_plugin_end");
  1256. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1257. }
  1258. }
  1259. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1260. {
  1261. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1262. CARLA_ASSERT(kData->oscData != nullptr);
  1263. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1264. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1265. {
  1266. char targetPath[std::strlen(kData->oscData->path)+15];
  1267. std::strcpy(targetPath, kData->oscData->path);
  1268. std::strcat(targetPath, "/remove_plugin");
  1269. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1270. }
  1271. }
  1272. 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)
  1273. {
  1274. 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);
  1275. CARLA_ASSERT(kData->oscData != nullptr);
  1276. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1277. CARLA_ASSERT(type != PLUGIN_NONE);
  1278. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1279. {
  1280. char targetPath[std::strlen(kData->oscData->path)+17];
  1281. std::strcpy(targetPath, kData->oscData->path);
  1282. std::strcat(targetPath, "/set_plugin_data");
  1283. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1284. }
  1285. }
  1286. 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)
  1287. {
  1288. 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);
  1289. CARLA_ASSERT(kData->oscData != nullptr);
  1290. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1291. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1292. {
  1293. char targetPath[std::strlen(kData->oscData->path)+18];
  1294. std::strcpy(targetPath, kData->oscData->path);
  1295. std::strcat(targetPath, "/set_plugin_ports");
  1296. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1297. }
  1298. }
  1299. 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)
  1300. {
  1301. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1302. CARLA_ASSERT(kData->oscData != nullptr);
  1303. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1304. CARLA_ASSERT(index >= 0);
  1305. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1306. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1307. {
  1308. char targetPath[std::strlen(kData->oscData->path)+20];
  1309. std::strcpy(targetPath, kData->oscData->path);
  1310. std::strcat(targetPath, "/set_parameter_data");
  1311. lo_send(kData->oscData->target, targetPath, "iiiissd", pluginId, index, type, hints, name, label, current);
  1312. }
  1313. }
  1314. 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)
  1315. {
  1316. 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);
  1317. CARLA_ASSERT(kData->oscData != nullptr);
  1318. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1319. CARLA_ASSERT(index >= 0);
  1320. CARLA_ASSERT(min < max);
  1321. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1322. {
  1323. char targetPath[std::strlen(kData->oscData->path)+22];
  1324. std::strcpy(targetPath, kData->oscData->path);
  1325. std::strcat(targetPath, "/set_parameter_ranges");
  1326. lo_send(kData->oscData->target, targetPath, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1327. }
  1328. }
  1329. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1330. {
  1331. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1332. CARLA_ASSERT(kData->oscData != nullptr);
  1333. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1334. CARLA_ASSERT(index >= 0);
  1335. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1336. {
  1337. char targetPath[std::strlen(kData->oscData->path)+23];
  1338. std::strcpy(targetPath, kData->oscData->path);
  1339. std::strcat(targetPath, "/set_parameter_midi_cc");
  1340. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1341. }
  1342. }
  1343. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1344. {
  1345. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1346. CARLA_ASSERT(kData->oscData != nullptr);
  1347. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1348. CARLA_ASSERT(index >= 0);
  1349. CARLA_ASSERT(channel >= 0 && channel < 16);
  1350. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1351. {
  1352. char targetPath[std::strlen(kData->oscData->path)+28];
  1353. std::strcpy(targetPath, kData->oscData->path);
  1354. std::strcat(targetPath, "/set_parameter_midi_channel");
  1355. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1356. }
  1357. }
  1358. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1359. {
  1360. #if DEBUG
  1361. if (index < 0)
  1362. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1363. else
  1364. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1365. #endif
  1366. CARLA_ASSERT(kData->oscData != nullptr);
  1367. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1368. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1369. {
  1370. char targetPath[std::strlen(kData->oscData->path)+21];
  1371. std::strcpy(targetPath, kData->oscData->path);
  1372. std::strcat(targetPath, "/set_parameter_value");
  1373. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1374. }
  1375. }
  1376. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1377. {
  1378. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1379. CARLA_ASSERT(kData->oscData != nullptr);
  1380. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1381. CARLA_ASSERT(index >= 0);
  1382. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1383. {
  1384. char targetPath[std::strlen(kData->oscData->path)+19];
  1385. std::strcpy(targetPath, kData->oscData->path);
  1386. std::strcat(targetPath, "/set_default_value");
  1387. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1388. }
  1389. }
  1390. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1391. {
  1392. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1393. CARLA_ASSERT(kData->oscData != nullptr);
  1394. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1395. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1396. {
  1397. char targetPath[std::strlen(kData->oscData->path)+13];
  1398. std::strcpy(targetPath, kData->oscData->path);
  1399. std::strcat(targetPath, "/set_program");
  1400. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1401. }
  1402. }
  1403. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1404. {
  1405. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1406. CARLA_ASSERT(kData->oscData != nullptr);
  1407. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1408. CARLA_ASSERT(count >= 0);
  1409. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1410. {
  1411. char targetPath[std::strlen(kData->oscData->path)+19];
  1412. std::strcpy(targetPath, kData->oscData->path);
  1413. std::strcat(targetPath, "/set_program_count");
  1414. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1415. }
  1416. }
  1417. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1418. {
  1419. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1420. CARLA_ASSERT(kData->oscData != nullptr);
  1421. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1422. CARLA_ASSERT(index >= 0);
  1423. CARLA_ASSERT(name);
  1424. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1425. {
  1426. char targetPath[std::strlen(kData->oscData->path)+18];
  1427. std::strcpy(targetPath, kData->oscData->path);
  1428. std::strcat(targetPath, "/set_program_name");
  1429. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1430. }
  1431. }
  1432. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1433. {
  1434. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1435. CARLA_ASSERT(kData->oscData != nullptr);
  1436. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1437. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1438. {
  1439. char targetPath[std::strlen(kData->oscData->path)+18];
  1440. std::strcpy(targetPath, kData->oscData->path);
  1441. std::strcat(targetPath, "/set_midi_program");
  1442. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1443. }
  1444. }
  1445. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1446. {
  1447. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1448. CARLA_ASSERT(kData->oscData != nullptr);
  1449. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1450. CARLA_ASSERT(count >= 0);
  1451. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1452. {
  1453. char targetPath[std::strlen(kData->oscData->path)+24];
  1454. std::strcpy(targetPath, kData->oscData->path);
  1455. std::strcat(targetPath, "/set_midi_program_count");
  1456. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1457. }
  1458. }
  1459. 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)
  1460. {
  1461. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1462. CARLA_ASSERT(kData->oscData != nullptr);
  1463. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1464. CARLA_ASSERT(index >= 0);
  1465. CARLA_ASSERT(bank >= 0);
  1466. CARLA_ASSERT(program >= 0);
  1467. CARLA_ASSERT(name);
  1468. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1469. {
  1470. char targetPath[std::strlen(kData->oscData->path)+23];
  1471. std::strcpy(targetPath, kData->oscData->path);
  1472. std::strcat(targetPath, "/set_midi_program_data");
  1473. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1474. }
  1475. }
  1476. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1477. {
  1478. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1479. CARLA_ASSERT(kData->oscData != nullptr);
  1480. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1481. CARLA_ASSERT(channel >= 0 && channel < 16);
  1482. CARLA_ASSERT(note >= 0 && note < 128);
  1483. CARLA_ASSERT(velo > 0 && velo < 128);
  1484. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1485. {
  1486. char targetPath[std::strlen(kData->oscData->path)+9];
  1487. std::strcpy(targetPath, kData->oscData->path);
  1488. std::strcat(targetPath, "/note_on");
  1489. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1490. }
  1491. }
  1492. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1493. {
  1494. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1495. CARLA_ASSERT(kData->oscData != nullptr);
  1496. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1497. CARLA_ASSERT(channel >= 0 && channel < 16);
  1498. CARLA_ASSERT(note >= 0 && note < 128);
  1499. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1500. {
  1501. char targetPath[std::strlen(kData->oscData->path)+10];
  1502. std::strcpy(targetPath, kData->oscData->path);
  1503. std::strcat(targetPath, "/note_off");
  1504. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1505. }
  1506. }
  1507. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1508. {
  1509. CARLA_ASSERT(kData->oscData != nullptr);
  1510. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1511. const EnginePluginData& pData = kData->plugins[pluginId];
  1512. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1513. {
  1514. char targetPath[std::strlen(kData->oscData->path)+22];
  1515. std::strcpy(targetPath, kData->oscData->path);
  1516. std::strcat(targetPath, "/set_peaks");
  1517. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1518. }
  1519. }
  1520. void CarlaEngine::osc_send_control_exit()
  1521. {
  1522. carla_debug("CarlaEngine::osc_send_control_exit()");
  1523. CARLA_ASSERT(kData->oscData != nullptr);
  1524. if (kData->oscData && kData->oscData->target)
  1525. {
  1526. char targetPath[std::strlen(kData->oscData->path)+6];
  1527. std::strcpy(targetPath, kData->oscData->path);
  1528. std::strcat(targetPath, "/exit");
  1529. lo_send(kData->oscData->target, targetPath, "");
  1530. }
  1531. }
  1532. #else
  1533. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1534. {
  1535. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1536. CARLA_ASSERT(kData->oscData != nullptr);
  1537. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1538. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1539. {
  1540. char targetPath[std::strlen(kData->oscData->path)+20];
  1541. std::strcpy(targetPath, kData->oscData->path);
  1542. std::strcat(targetPath, "/bridge_audio_count");
  1543. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1544. }
  1545. }
  1546. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1547. {
  1548. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1549. CARLA_ASSERT(kData->oscData != nullptr);
  1550. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1551. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1552. {
  1553. char targetPath[std::strlen(kData->oscData->path)+19];
  1554. std::strcpy(targetPath, kData->oscData->path);
  1555. std::strcat(targetPath, "/bridge_midi_count");
  1556. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1557. }
  1558. }
  1559. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1560. {
  1561. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1562. CARLA_ASSERT(kData->oscData != nullptr);
  1563. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1564. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1565. {
  1566. char targetPath[std::strlen(kData->oscData->path)+24];
  1567. std::strcpy(targetPath, kData->oscData->path);
  1568. std::strcat(targetPath, "/bridge_parameter_count");
  1569. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1570. }
  1571. }
  1572. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1573. {
  1574. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1575. CARLA_ASSERT(kData->oscData != nullptr);
  1576. CARLA_ASSERT(count >= 0);
  1577. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1578. {
  1579. char targetPath[std::strlen(kData->oscData->path)+22];
  1580. std::strcpy(targetPath, kData->oscData->path);
  1581. std::strcat(targetPath, "/bridge_program_count");
  1582. lo_send(kData->oscData->target, targetPath, "i", count);
  1583. }
  1584. }
  1585. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1586. {
  1587. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1588. CARLA_ASSERT(kData->oscData != nullptr);
  1589. CARLA_ASSERT(count >= 0);
  1590. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1591. {
  1592. char targetPath[std::strlen(kData->oscData->path)+27];
  1593. std::strcpy(targetPath, kData->oscData->path);
  1594. std::strcat(targetPath, "/bridge_midi_program_count");
  1595. lo_send(kData->oscData->target, targetPath, "i", count);
  1596. }
  1597. }
  1598. 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)
  1599. {
  1600. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1601. CARLA_ASSERT(kData->oscData != nullptr);
  1602. CARLA_ASSERT(name != nullptr);
  1603. CARLA_ASSERT(label != nullptr);
  1604. CARLA_ASSERT(maker != nullptr);
  1605. CARLA_ASSERT(copyright != nullptr);
  1606. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1607. {
  1608. char targetPath[std::strlen(kData->oscData->path)+20];
  1609. std::strcpy(targetPath, kData->oscData->path);
  1610. std::strcat(targetPath, "/bridge_plugin_info");
  1611. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1612. }
  1613. }
  1614. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1615. {
  1616. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1617. CARLA_ASSERT(kData->oscData != nullptr);
  1618. CARLA_ASSERT(name != nullptr);
  1619. CARLA_ASSERT(unit != nullptr);
  1620. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1621. {
  1622. char targetPath[std::strlen(kData->oscData->path)+23];
  1623. std::strcpy(targetPath, kData->oscData->path);
  1624. std::strcat(targetPath, "/bridge_parameter_info");
  1625. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1626. }
  1627. }
  1628. 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)
  1629. {
  1630. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1631. CARLA_ASSERT(kData->oscData != nullptr);
  1632. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1633. {
  1634. char targetPath[std::strlen(kData->oscData->path)+23];
  1635. std::strcpy(targetPath, kData->oscData->path);
  1636. std::strcat(targetPath, "/bridge_parameter_data");
  1637. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1638. }
  1639. }
  1640. 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)
  1641. {
  1642. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1643. CARLA_ASSERT(kData->oscData != nullptr);
  1644. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1645. {
  1646. char targetPath[std::strlen(kData->oscData->path)+25];
  1647. std::strcpy(targetPath, kData->oscData->path);
  1648. std::strcat(targetPath, "/bridge_parameter_ranges");
  1649. lo_send(kData->oscData->target, targetPath, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1650. }
  1651. }
  1652. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1653. {
  1654. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1655. CARLA_ASSERT(kData->oscData != nullptr);
  1656. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1657. {
  1658. char targetPath[std::strlen(kData->oscData->path)+21];
  1659. std::strcpy(targetPath, kData->oscData->path);
  1660. std::strcat(targetPath, "/bridge_program_info");
  1661. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1662. }
  1663. }
  1664. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1665. {
  1666. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1667. CARLA_ASSERT(kData->oscData != nullptr);
  1668. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1669. {
  1670. char targetPath[std::strlen(kData->oscData->path)+26];
  1671. std::strcpy(targetPath, kData->oscData->path);
  1672. std::strcat(targetPath, "/bridge_midi_program_info");
  1673. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1674. }
  1675. }
  1676. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1677. {
  1678. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1679. CARLA_ASSERT(kData->oscData != nullptr);
  1680. CARLA_ASSERT(key != nullptr);
  1681. CARLA_ASSERT(value != nullptr);
  1682. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1683. {
  1684. char targetPath[std::strlen(kData->oscData->path)+18];
  1685. std::strcpy(targetPath, kData->oscData->path);
  1686. std::strcat(targetPath, "/bridge_configure");
  1687. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1688. }
  1689. }
  1690. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1691. {
  1692. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1693. CARLA_ASSERT(kData->oscData != nullptr);
  1694. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1695. {
  1696. char targetPath[std::strlen(kData->oscData->path)+28];
  1697. std::strcpy(targetPath, kData->oscData->path);
  1698. std::strcat(targetPath, "/bridge_set_parameter_value");
  1699. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1700. }
  1701. }
  1702. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1703. {
  1704. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1705. CARLA_ASSERT(kData->oscData != nullptr);
  1706. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1707. {
  1708. char targetPath[std::strlen(kData->oscData->path)+26];
  1709. std::strcpy(targetPath, kData->oscData->path);
  1710. std::strcat(targetPath, "/bridge_set_default_value");
  1711. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1712. }
  1713. }
  1714. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1715. {
  1716. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1717. CARLA_ASSERT(kData->oscData != nullptr);
  1718. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1719. {
  1720. char targetPath[std::strlen(kData->oscData->path)+20];
  1721. std::strcpy(targetPath, kData->oscData->path);
  1722. std::strcat(targetPath, "/bridge_set_program");
  1723. lo_send(kData->oscData->target, targetPath, "i", index);
  1724. }
  1725. }
  1726. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1727. {
  1728. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1729. CARLA_ASSERT(kData->oscData != nullptr);
  1730. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1731. {
  1732. char targetPath[std::strlen(kData->oscData->path)+25];
  1733. std::strcpy(targetPath, kData->oscData->path);
  1734. std::strcat(targetPath, "/bridge_set_midi_program");
  1735. lo_send(kData->oscData->target, targetPath, "i", index);
  1736. }
  1737. }
  1738. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1739. {
  1740. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1741. CARLA_ASSERT(kData->oscData != nullptr);
  1742. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1743. {
  1744. char targetPath[std::strlen(kData->oscData->path)+24];
  1745. std::strcpy(targetPath, kData->oscData->path);
  1746. std::strcat(targetPath, "/bridge_set_custom_data");
  1747. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  1748. }
  1749. }
  1750. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1751. {
  1752. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1753. CARLA_ASSERT(kData->oscData != nullptr);
  1754. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1755. {
  1756. char targetPath[std::strlen(kData->oscData->path)+23];
  1757. std::strcpy(targetPath, kData->oscData->path);
  1758. std::strcat(targetPath, "/bridge_set_chunk_data");
  1759. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  1760. }
  1761. }
  1762. void CarlaEngine::osc_send_bridge_set_peaks()
  1763. {
  1764. CARLA_ASSERT(kData->oscData != nullptr);
  1765. const EnginePluginData& pData = kData->plugins[0];
  1766. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1767. {
  1768. char targetPath[std::strlen(kData->oscData->path)+22];
  1769. std::strcpy(targetPath, kData->oscData->path);
  1770. std::strcat(targetPath, "/bridge_set_peaks");
  1771. lo_send(kData->oscData->target, targetPath, "ffff", pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1772. }
  1773. }
  1774. #endif
  1775. CARLA_BACKEND_END_NAMESPACE