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.

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