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.

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