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.

2248 lines
71KB

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