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.

2327 lines
73KB

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