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.

2320 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_debug("CarlaEngineClient::CarlaEngineClient(%s, %s)", EngineType2Str(engineType), ProcessMode2Str(processMode));
  228. CARLA_ASSERT(engineType != kEngineTypeNull);
  229. }
  230. CarlaEngineClient::~CarlaEngineClient()
  231. {
  232. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  233. CARLA_ASSERT(! fActive);
  234. }
  235. void CarlaEngineClient::activate()
  236. {
  237. carla_debug("CarlaEngineClient::activate()");
  238. CARLA_ASSERT(! fActive);
  239. fActive = true;
  240. }
  241. void CarlaEngineClient::deactivate()
  242. {
  243. carla_debug("CarlaEngineClient::deactivate()");
  244. CARLA_ASSERT(fActive);
  245. fActive = false;
  246. }
  247. bool CarlaEngineClient::isActive() const
  248. {
  249. carla_debug("CarlaEngineClient::isActive()");
  250. return fActive;
  251. }
  252. bool CarlaEngineClient::isOk() const
  253. {
  254. carla_debug("CarlaEngineClient::isOk()");
  255. return true;
  256. }
  257. uint32_t CarlaEngineClient::getLatency() const
  258. {
  259. return fLatency;
  260. }
  261. void CarlaEngineClient::setLatency(const uint32_t samples)
  262. {
  263. fLatency = samples;
  264. }
  265. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  266. {
  267. carla_debug("CarlaEngineClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput));
  268. switch (portType)
  269. {
  270. case kEnginePortTypeNull:
  271. break;
  272. case kEnginePortTypeAudio:
  273. return new CarlaEngineAudioPort(isInput, kProcessMode);
  274. case kEnginePortTypeEvent:
  275. return new CarlaEngineEventPort(isInput, kProcessMode);
  276. }
  277. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  278. return nullptr;
  279. }
  280. // -------------------------------------------------------------------------------------------------------------------
  281. // Carla Engine
  282. CarlaEngine::CarlaEngine()
  283. : fBufferSize(0),
  284. fSampleRate(0.0),
  285. kData(new CarlaEngineProtectedData(this))
  286. {
  287. carla_debug("CarlaEngine::CarlaEngine()");
  288. }
  289. CarlaEngine::~CarlaEngine()
  290. {
  291. carla_debug("CarlaEngine::~CarlaEngine()");
  292. delete kData;
  293. }
  294. // -----------------------------------------------------------------------
  295. // Helpers
  296. void doPluginRemove(CarlaEngineProtectedData* const kData, const bool unlock)
  297. {
  298. CARLA_ASSERT(kData->curPluginCount > 0);
  299. kData->curPluginCount--;
  300. const unsigned int id = kData->nextAction.pluginId;
  301. // reset current plugin
  302. kData->plugins[id].plugin = nullptr;
  303. CarlaPlugin* plugin;
  304. // move all plugins 1 spot backwards
  305. for (unsigned int i=id; i < kData->curPluginCount; ++i)
  306. {
  307. plugin = kData->plugins[i+1].plugin;
  308. CARLA_ASSERT(plugin);
  309. if (plugin == nullptr)
  310. break;
  311. plugin->setId(i);
  312. kData->plugins[i].plugin = plugin;
  313. kData->plugins[i].insPeak[0] = 0.0f;
  314. kData->plugins[i].insPeak[1] = 0.0f;
  315. kData->plugins[i].outsPeak[0] = 0.0f;
  316. kData->plugins[i].outsPeak[1] = 0.0f;
  317. }
  318. kData->nextAction.opcode = EnginePostActionNull;
  319. if (unlock)
  320. kData->nextAction.mutex.unlock();
  321. }
  322. 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_debug("CarlaEngine::init(\"%s\")", clientName);
  444. CARLA_ASSERT(kData->plugins == nullptr);
  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_debug("CarlaEngine::close()");
  490. CARLA_ASSERT(kData->plugins != nullptr);
  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_debug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2Str(btype), PluginType2Str(ptype), filename, name, label, extra);
  540. CARLA_ASSERT(btype != BINARY_NONE);
  541. CARLA_ASSERT(ptype != PLUGIN_NONE);
  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_debug("CarlaEngine::removePlugin(%i)", id);
  635. CARLA_ASSERT(kData->curPluginCount > 0);
  636. CARLA_ASSERT(id < kData->curPluginCount);
  637. CARLA_ASSERT(kData->plugins != nullptr);
  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. if (kData->plugins == nullptr)
  709. {
  710. setLastError("Critical error: no plugins are currently loaded!");
  711. return nullptr;
  712. }
  713. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  714. if (plugin == nullptr)
  715. {
  716. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  717. return nullptr;
  718. }
  719. CARLA_ASSERT(plugin->id() == id);
  720. if (const char* const name = getUniquePluginName(newName))
  721. {
  722. plugin->setName(name);
  723. return name;
  724. }
  725. return nullptr;
  726. }
  727. bool CarlaEngine::clonePlugin(const unsigned int id)
  728. {
  729. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  730. CARLA_ASSERT(kData->curPluginCount > 0);
  731. CARLA_ASSERT(id < kData->curPluginCount);
  732. CARLA_ASSERT(kData->plugins != nullptr);
  733. if (kData->plugins == nullptr)
  734. {
  735. setLastError("Critical error: no plugins are currently loaded!");
  736. return false;
  737. }
  738. CarlaPlugin* const plugin = kData->plugins[id].plugin;
  739. if (plugin == nullptr)
  740. {
  741. carla_stderr("CarlaEngine::clonePlugin(%i) - could not find plugin", id);
  742. return false;
  743. }
  744. CARLA_ASSERT(plugin->id() == id);
  745. const SaveState& saveState(plugin->getSaveState());
  746. char label[STR_MAX+1] = { '\0' };
  747. plugin->getLabel(label);
  748. BinaryType binaryType = BINARY_NATIVE;
  749. #ifndef BUILD_BRIDGE
  750. if (plugin->hints() & PLUGIN_IS_BRIDGE)
  751. binaryType = CarlaPluginGetBridgeBinaryType(plugin);
  752. #endif
  753. const unsigned int pluginsBefore(kData->curPluginCount);
  754. if (! addPlugin(binaryType, plugin->type(), plugin->filename(), plugin->name(), label, plugin->getExtraStuff()))
  755. return false;
  756. CARLA_ASSERT(pluginsBefore+1 == kData->curPluginCount);
  757. CarlaPlugin* const newPlugin = kData->plugins[kData->curPluginCount-1].plugin;
  758. CARLA_ASSERT(newPlugin != nullptr);
  759. newPlugin->loadSaveState(saveState);
  760. return true;
  761. }
  762. bool CarlaEngine::replacePlugin(const unsigned int id)
  763. {
  764. setLastError("Not implemented yet");
  765. return false;
  766. }
  767. bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB)
  768. {
  769. CARLA_ASSERT(kData->curPluginCount > 0);
  770. CARLA_ASSERT(idA < kData->curPluginCount);
  771. CARLA_ASSERT(idB < kData->curPluginCount);
  772. CARLA_ASSERT(kData->plugins != nullptr);
  773. if (kData->plugins == nullptr)
  774. {
  775. setLastError("Critical error: no plugins are currently loaded!");
  776. return false;
  777. }
  778. kData->thread.stopNow();
  779. kData->nextAction.pluginId = idA;
  780. kData->nextAction.value = idB;
  781. kData->nextAction.opcode = EnginePostActionSwitchPlugins;
  782. kData->nextAction.mutex.lock();
  783. if (isRunning())
  784. {
  785. carla_stderr("CarlaEngine::switchPlugins(%i, %i) - switch blocking START", idA, idB);
  786. // block wait for unlock on proccessing side
  787. kData->nextAction.mutex.lock();
  788. carla_stderr("CarlaEngine::switchPlugins(%i, %i) - switch blocking DONE", idA, idB);
  789. }
  790. else
  791. {
  792. doPluginsSwitch(kData, false);
  793. }
  794. #ifndef BUILD_BRIDGE // TODO
  795. //if (isOscControlRegistered())
  796. // osc_send_control_remove_plugin(id);
  797. #endif
  798. kData->nextAction.mutex.unlock();
  799. if (isRunning() && ! kData->aboutToClose)
  800. kData->thread.startNow();
  801. return true;
  802. }
  803. CarlaPlugin* CarlaEngine::getPlugin(const unsigned int id) const
  804. {
  805. carla_debug("CarlaEngine::getPlugin(%i) [count:%i]", id, kData->curPluginCount);
  806. CARLA_ASSERT(kData->curPluginCount > 0);
  807. CARLA_ASSERT(id < kData->curPluginCount);
  808. CARLA_ASSERT(kData->plugins != nullptr);
  809. if (id < kData->curPluginCount && kData->plugins != nullptr)
  810. return kData->plugins[id].plugin;
  811. return nullptr;
  812. }
  813. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int id) const
  814. {
  815. return kData->plugins[id].plugin;
  816. }
  817. const char* CarlaEngine::getUniquePluginName(const char* const name)
  818. {
  819. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  820. CARLA_ASSERT(kData->maxPluginNumber > 0);
  821. CARLA_ASSERT(kData->plugins != nullptr);
  822. CARLA_ASSERT(name != nullptr);
  823. static CarlaString sname;
  824. sname = name;
  825. if (sname.isEmpty() || kData->plugins == nullptr)
  826. {
  827. sname = "(No name)";
  828. return (const char*)sname;
  829. }
  830. sname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  831. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  832. for (unsigned short i=0; i < kData->curPluginCount; ++i)
  833. {
  834. CARLA_ASSERT(kData->plugins[i].plugin);
  835. if (kData->plugins[i].plugin == nullptr)
  836. continue;
  837. // Check if unique name doesn't exist
  838. if (const char* const pluginName = kData->plugins[i].plugin->name())
  839. {
  840. if (sname != pluginName)
  841. continue;
  842. }
  843. // Check if string has already been modified
  844. {
  845. const size_t len = sname.length();
  846. // 1 digit, ex: " (2)"
  847. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  848. {
  849. int number = sname[len-2] - '0';
  850. if (number == 9)
  851. {
  852. // next number is 10, 2 digits
  853. sname.truncate(len-4);
  854. sname += " (10)";
  855. //sname.replace(" (9)", " (10)");
  856. }
  857. else
  858. sname[len-2] = char('0' + number + 1);
  859. continue;
  860. }
  861. // 2 digits, ex: " (11)"
  862. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  863. {
  864. char n2 = sname[len-2];
  865. char n3 = sname[len-3];
  866. if (n2 == '9')
  867. {
  868. n2 = '0';
  869. n3 += 1;
  870. }
  871. else
  872. n2 += 1;
  873. sname[len-2] = n2;
  874. sname[len-3] = n3;
  875. continue;
  876. }
  877. }
  878. // Modify string if not
  879. sname += " (2)";
  880. }
  881. return (const char*)sname;
  882. }
  883. // -----------------------------------------------------------------------
  884. // Project management
  885. bool CarlaEngine::loadFilename(const char* const filename)
  886. {
  887. carla_debug("CarlaEngine::loadFilename(\"%s\")", filename);
  888. CARLA_ASSERT(filename != nullptr);
  889. // TODO
  890. setLastError("Not implemented yet");
  891. return false;
  892. }
  893. bool CarlaEngine::loadProject(const char* const filename)
  894. {
  895. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  896. CARLA_ASSERT(filename != nullptr);
  897. QFile file(filename);
  898. if (! file.open(QIODevice::ReadOnly | QIODevice::Text))
  899. return false;
  900. QDomDocument xml;
  901. xml.setContent(file.readAll());
  902. file.close();
  903. QDomNode xmlNode(xml.documentElement());
  904. if (xmlNode.toElement().tagName() != "CARLA-PROJECT" && xmlNode.toElement().tagName() != "CARLA-PRESET")
  905. {
  906. setLastError("Not a valid Carla project or preset file");
  907. return false;
  908. }
  909. const bool isPreset(xmlNode.toElement().tagName() == "CARLA-PRESET");
  910. QDomNode node(xmlNode.firstChild());
  911. while (! node.isNull())
  912. {
  913. if (isPreset || node.toElement().tagName() == "Plugin")
  914. {
  915. const SaveState& saveState(getSaveStateDictFromXML(isPreset ? xmlNode : node));
  916. CARLA_ASSERT(saveState.type != nullptr);
  917. if (saveState.type == nullptr)
  918. continue;
  919. const void* extraStuff = nullptr;
  920. if (std::strcmp(saveState.type, "DSSI") == 0)
  921. extraStuff = findDSSIGUI(saveState.binary, saveState.label);
  922. // TODO - proper find&load plugins
  923. if (addPlugin(getPluginTypeFromString(saveState.type), saveState.binary, saveState.name, saveState.label, extraStuff))
  924. {
  925. if (CarlaPlugin* plugin = getPlugin(kData->curPluginCount-1))
  926. plugin->loadSaveState(saveState);
  927. }
  928. }
  929. if (isPreset)
  930. break;
  931. node = node.nextSibling();
  932. }
  933. // prevent wrong leak detection on close
  934. getSaveStateDictFromXML(QDomNode());
  935. return true;
  936. }
  937. bool CarlaEngine::saveProject(const char* const filename)
  938. {
  939. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  940. CARLA_ASSERT(filename != nullptr);
  941. QFile file(filename);
  942. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  943. return false;
  944. QTextStream out(&file);
  945. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  946. out << "<!DOCTYPE CARLA-PROJECT>\n";
  947. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  948. bool firstPlugin = true;
  949. char strBuf[STR_MAX+1];
  950. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  951. {
  952. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  953. if (plugin != nullptr && plugin->enabled())
  954. {
  955. if (! firstPlugin)
  956. out << "\n";
  957. plugin->getRealName(strBuf);
  958. if (*strBuf != 0)
  959. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  960. out << " <Plugin>\n";
  961. out << getXMLFromSaveState(plugin->getSaveState());
  962. out << " </Plugin>\n";
  963. firstPlugin = false;
  964. }
  965. }
  966. out << "</CARLA-PROJECT>\n";
  967. file.close();
  968. return true;
  969. }
  970. // -----------------------------------------------------------------------
  971. // Information (peaks)
  972. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  973. {
  974. CARLA_ASSERT(pluginId < kData->curPluginCount);
  975. CARLA_ASSERT(id-1 < MAX_PEAKS);
  976. if (id == 0 || id > MAX_PEAKS)
  977. return 0.0f;
  978. return kData->plugins[pluginId].insPeak[id-1];
  979. }
  980. float CarlaEngine::getOutputPeak(const unsigned int pluginId, const unsigned short id) const
  981. {
  982. CARLA_ASSERT(pluginId < kData->curPluginCount);
  983. CARLA_ASSERT(id-1 < MAX_PEAKS);
  984. if (id == 0 || id > MAX_PEAKS)
  985. return 0.0f;
  986. return kData->plugins[pluginId].outsPeak[id-1];
  987. }
  988. // -----------------------------------------------------------------------
  989. // Callback
  990. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  991. {
  992. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  993. if (kData->callback)
  994. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  995. }
  996. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  997. {
  998. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  999. CARLA_ASSERT(func);
  1000. kData->callback = func;
  1001. kData->callbackPtr = ptr;
  1002. }
  1003. // -----------------------------------------------------------------------
  1004. // Patchbay
  1005. bool CarlaEngine::patchbayConnect(int, int)
  1006. {
  1007. setLastError("Unsupported operation");
  1008. return false;
  1009. }
  1010. bool CarlaEngine::patchbayDisconnect(int)
  1011. {
  1012. setLastError("Unsupported operation");
  1013. return false;
  1014. }
  1015. void CarlaEngine::patchbayRefresh()
  1016. {
  1017. // nothing
  1018. }
  1019. // -----------------------------------------------------------------------
  1020. // Transport
  1021. void CarlaEngine::transportPlay()
  1022. {
  1023. kData->time.playing = true;
  1024. }
  1025. void CarlaEngine::transportPause()
  1026. {
  1027. kData->time.playing = false;
  1028. }
  1029. void CarlaEngine::transportRelocate(const uint32_t frame)
  1030. {
  1031. kData->time.frame = frame;
  1032. }
  1033. // -----------------------------------------------------------------------
  1034. // Error handling
  1035. const char* CarlaEngine::getLastError() const
  1036. {
  1037. return (const char*)kData->lastError;
  1038. }
  1039. void CarlaEngine::setLastError(const char* const error)
  1040. {
  1041. kData->lastError = error;
  1042. }
  1043. void CarlaEngine::setAboutToClose()
  1044. {
  1045. carla_debug("CarlaEngine::setAboutToClose()");
  1046. kData->aboutToClose = true;
  1047. }
  1048. // -----------------------------------------------------------------------
  1049. // Global options
  1050. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  1051. if (isRunning()) \
  1052. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  1053. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  1054. {
  1055. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  1056. switch (option)
  1057. {
  1058. case OPTION_PROCESS_NAME:
  1059. carla_setprocname(valueStr);
  1060. break;
  1061. case OPTION_PROCESS_MODE:
  1062. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1063. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_BRIDGE)
  1064. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  1065. fOptions.processMode = static_cast<ProcessMode>(value);
  1066. break;
  1067. case OPTION_TRANSPORT_MODE:
  1068. // FIXME: Always enable JACK transport for now
  1069. #if 0
  1070. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_BRIDGE)
  1071. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1072. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  1073. #endif
  1074. break;
  1075. case OPTION_MAX_PARAMETERS:
  1076. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1077. if (value < 0)
  1078. return; // TODO error here
  1079. fOptions.maxParameters = static_cast<uint>(value);
  1080. break;
  1081. case OPTION_PREFERRED_BUFFER_SIZE:
  1082. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1083. fOptions.preferredBufferSize = static_cast<uint>(value);
  1084. break;
  1085. case OPTION_PREFERRED_SAMPLE_RATE:
  1086. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1087. fOptions.preferredSampleRate = static_cast<uint>(value);
  1088. break;
  1089. case OPTION_FORCE_STEREO:
  1090. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1091. fOptions.forceStereo = (value != 0);
  1092. break;
  1093. #ifdef WANT_DSSI
  1094. case OPTION_USE_DSSI_VST_CHUNKS:
  1095. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1096. fOptions.useDssiVstChunks = (value != 0);
  1097. break;
  1098. #endif
  1099. case OPTION_PREFER_PLUGIN_BRIDGES:
  1100. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1101. fOptions.preferPluginBridges = (value != 0);
  1102. break;
  1103. case OPTION_PREFER_UI_BRIDGES:
  1104. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1105. fOptions.preferUiBridges = (value != 0);
  1106. break;
  1107. case OPTION_OSC_UI_TIMEOUT:
  1108. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1109. fOptions.oscUiTimeout = static_cast<uint>(value);
  1110. break;
  1111. #ifndef BUILD_BRIDGE
  1112. case OPTION_PATH_BRIDGE_NATIVE:
  1113. fOptions.bridge_native = valueStr;
  1114. break;
  1115. case OPTION_PATH_BRIDGE_POSIX32:
  1116. fOptions.bridge_posix32 = valueStr;
  1117. break;
  1118. case OPTION_PATH_BRIDGE_POSIX64:
  1119. fOptions.bridge_posix64 = valueStr;
  1120. break;
  1121. case OPTION_PATH_BRIDGE_WIN32:
  1122. fOptions.bridge_win32 = valueStr;
  1123. break;
  1124. case OPTION_PATH_BRIDGE_WIN64:
  1125. fOptions.bridge_win64 = valueStr;
  1126. break;
  1127. #endif
  1128. #ifdef WANT_LV2
  1129. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1130. fOptions.bridge_lv2Gtk2 = valueStr;
  1131. break;
  1132. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1133. fOptions.bridge_lv2Gtk3 = valueStr;
  1134. break;
  1135. case OPTION_PATH_BRIDGE_LV2_QT4:
  1136. fOptions.bridge_lv2Qt4 = valueStr;
  1137. break;
  1138. case OPTION_PATH_BRIDGE_LV2_QT5:
  1139. fOptions.bridge_lv2Qt5 = valueStr;
  1140. break;
  1141. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1142. fOptions.bridge_lv2Cocoa = valueStr;
  1143. break;
  1144. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1145. fOptions.bridge_lv2Win = valueStr;
  1146. break;
  1147. case OPTION_PATH_BRIDGE_LV2_X11:
  1148. fOptions.bridge_lv2X11 = valueStr;
  1149. break;
  1150. #endif
  1151. #ifdef WANT_VST
  1152. case OPTION_PATH_BRIDGE_VST_COCOA:
  1153. fOptions.bridge_vstCocoa = valueStr;
  1154. break;
  1155. case OPTION_PATH_BRIDGE_VST_HWND:
  1156. fOptions.bridge_vstHWND = valueStr;
  1157. break;
  1158. case OPTION_PATH_BRIDGE_VST_X11:
  1159. fOptions.bridge_vstX11 = valueStr;
  1160. break;
  1161. #endif
  1162. }
  1163. }
  1164. // -----------------------------------------------------------------------
  1165. // OSC Stuff
  1166. #ifdef BUILD_BRIDGE
  1167. bool CarlaEngine::isOscBridgeRegistered() const
  1168. {
  1169. return (kData->oscData != nullptr);
  1170. }
  1171. #else
  1172. bool CarlaEngine::isOscControlRegistered() const
  1173. {
  1174. return kData->osc.isControlRegistered();
  1175. }
  1176. #endif
  1177. void CarlaEngine::idleOsc()
  1178. {
  1179. kData->osc.idle();
  1180. }
  1181. const char* CarlaEngine::getOscServerPathTCP() const
  1182. {
  1183. return kData->osc.getServerPathTCP();
  1184. }
  1185. const char* CarlaEngine::getOscServerPathUDP() const
  1186. {
  1187. return kData->osc.getServerPathUDP();
  1188. }
  1189. #ifdef BUILD_BRIDGE
  1190. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1191. {
  1192. kData->oscData = oscData;
  1193. }
  1194. #endif
  1195. // -----------------------------------------------------------------------
  1196. // protected calls
  1197. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1198. {
  1199. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1200. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1201. {
  1202. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1203. if (plugin != nullptr && plugin->enabled())
  1204. plugin->bufferSizeChanged(newBufferSize);
  1205. }
  1206. callback(CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1207. }
  1208. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1209. {
  1210. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1211. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1212. {
  1213. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1214. if (plugin != nullptr && plugin->enabled())
  1215. plugin->sampleRateChanged(newSampleRate);
  1216. }
  1217. callback(CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, newSampleRate, nullptr);
  1218. }
  1219. void CarlaEngine::proccessPendingEvents()
  1220. {
  1221. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1222. switch (kData->nextAction.opcode)
  1223. {
  1224. case EnginePostActionNull:
  1225. break;
  1226. case EnginePostActionRemovePlugin:
  1227. doPluginRemove(kData, true);
  1228. break;
  1229. case EnginePostActionSwitchPlugins:
  1230. doPluginsSwitch(kData, true);
  1231. break;
  1232. }
  1233. if (kData->time.playing)
  1234. kData->time.frame += fBufferSize;
  1235. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1236. {
  1237. fTimeInfo.playing = kData->time.playing;
  1238. fTimeInfo.frame = kData->time.frame;
  1239. }
  1240. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1241. {
  1242. // TODO - peak values?
  1243. }
  1244. }
  1245. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS])
  1246. {
  1247. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1248. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1249. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1250. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1251. }
  1252. #ifndef BUILD_BRIDGE
  1253. EngineEvent* CarlaEngine::getRackEventBuffer(const bool isInput)
  1254. {
  1255. return isInput ? kData->rack.in : kData->rack.out;
  1256. }
  1257. void setValueIfHigher(float& value, const float& compare)
  1258. {
  1259. if (value < compare)
  1260. value = compare;
  1261. }
  1262. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1263. {
  1264. // initialize outputs (zero)
  1265. carla_zeroFloat(outBuf[0], frames);
  1266. carla_zeroFloat(outBuf[1], frames);
  1267. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1268. bool processed = false;
  1269. // process plugins
  1270. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1271. {
  1272. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1273. if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock())
  1274. continue;
  1275. if (processed)
  1276. {
  1277. // initialize inputs (from previous outputs)
  1278. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1279. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1280. std::memcpy(kData->rack.in, kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1281. // initialize outputs (zero)
  1282. carla_zeroFloat(outBuf[0], frames);
  1283. carla_zeroFloat(outBuf[1], frames);
  1284. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1285. }
  1286. // process
  1287. plugin->initBuffers();
  1288. plugin->process(inBuf, outBuf, frames);
  1289. plugin->unlock();
  1290. #if 0
  1291. // if plugin has no audio inputs, add previous buffers
  1292. if (plugin->audioInCount() == 0)
  1293. {
  1294. for (uint32_t j=0; j < frames; ++j)
  1295. {
  1296. outBuf[0][j] += inBuf[0][j];
  1297. outBuf[1][j] += inBuf[1][j];
  1298. }
  1299. }
  1300. // if plugin has no midi output, add previous events
  1301. if (plugin->midiOutCount() == 0)
  1302. {
  1303. for (uint32_t j=0, k=0; j < frames; ++j)
  1304. {
  1305. }
  1306. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1307. }
  1308. #endif
  1309. // set peaks
  1310. {
  1311. float inPeak1 = 0.0f;
  1312. float inPeak2 = 0.0f;
  1313. float outPeak1 = 0.0f;
  1314. float outPeak2 = 0.0f;
  1315. for (uint32_t k=0; k < frames; ++k)
  1316. {
  1317. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1318. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1319. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1320. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1321. }
  1322. kData->plugins[i].insPeak[0] = inPeak1;
  1323. kData->plugins[i].insPeak[1] = inPeak2;
  1324. kData->plugins[i].outsPeak[0] = outPeak1;
  1325. kData->plugins[i].outsPeak[1] = outPeak2;
  1326. }
  1327. processed = true;
  1328. }
  1329. }
  1330. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1331. {
  1332. // TODO
  1333. return;
  1334. // unused, for now
  1335. (void)inBuf;
  1336. (void)outBuf;
  1337. (void)bufCount;
  1338. (void)frames;
  1339. }
  1340. #endif
  1341. // -------------------------------------------------------------------------------------------------------------------
  1342. // Carla Engine OSC stuff
  1343. #ifndef BUILD_BRIDGE
  1344. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1345. {
  1346. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1347. CARLA_ASSERT(kData->oscData != nullptr);
  1348. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1349. CARLA_ASSERT(pluginName);
  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, "/add_plugin_start");
  1355. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1356. }
  1357. }
  1358. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1359. {
  1360. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1361. CARLA_ASSERT(kData->oscData != nullptr);
  1362. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1363. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1364. {
  1365. char targetPath[std::strlen(kData->oscData->path)+16];
  1366. std::strcpy(targetPath, kData->oscData->path);
  1367. std::strcat(targetPath, "/add_plugin_end");
  1368. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1369. }
  1370. }
  1371. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1372. {
  1373. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1374. CARLA_ASSERT(kData->oscData != nullptr);
  1375. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1376. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1377. {
  1378. char targetPath[std::strlen(kData->oscData->path)+15];
  1379. std::strcpy(targetPath, kData->oscData->path);
  1380. std::strcat(targetPath, "/remove_plugin");
  1381. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1382. }
  1383. }
  1384. 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)
  1385. {
  1386. 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);
  1387. CARLA_ASSERT(kData->oscData != nullptr);
  1388. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1389. CARLA_ASSERT(type != PLUGIN_NONE);
  1390. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1391. {
  1392. char targetPath[std::strlen(kData->oscData->path)+17];
  1393. std::strcpy(targetPath, kData->oscData->path);
  1394. std::strcat(targetPath, "/set_plugin_data");
  1395. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1396. }
  1397. }
  1398. 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)
  1399. {
  1400. 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);
  1401. CARLA_ASSERT(kData->oscData != nullptr);
  1402. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1403. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1404. {
  1405. char targetPath[std::strlen(kData->oscData->path)+18];
  1406. std::strcpy(targetPath, kData->oscData->path);
  1407. std::strcat(targetPath, "/set_plugin_ports");
  1408. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1409. }
  1410. }
  1411. 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)
  1412. {
  1413. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1414. CARLA_ASSERT(kData->oscData != nullptr);
  1415. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1416. CARLA_ASSERT(index >= 0);
  1417. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1418. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1419. {
  1420. char targetPath[std::strlen(kData->oscData->path)+20];
  1421. std::strcpy(targetPath, kData->oscData->path);
  1422. std::strcat(targetPath, "/set_parameter_data");
  1423. lo_send(kData->oscData->target, targetPath, "iiiissd", pluginId, index, type, hints, name, label, current);
  1424. }
  1425. }
  1426. 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)
  1427. {
  1428. 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);
  1429. CARLA_ASSERT(kData->oscData != nullptr);
  1430. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1431. CARLA_ASSERT(index >= 0);
  1432. CARLA_ASSERT(min < max);
  1433. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1434. {
  1435. char targetPath[std::strlen(kData->oscData->path)+22];
  1436. std::strcpy(targetPath, kData->oscData->path);
  1437. std::strcat(targetPath, "/set_parameter_ranges");
  1438. lo_send(kData->oscData->target, targetPath, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1439. }
  1440. }
  1441. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1442. {
  1443. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1444. CARLA_ASSERT(kData->oscData != nullptr);
  1445. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1446. CARLA_ASSERT(index >= 0);
  1447. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1448. {
  1449. char targetPath[std::strlen(kData->oscData->path)+23];
  1450. std::strcpy(targetPath, kData->oscData->path);
  1451. std::strcat(targetPath, "/set_parameter_midi_cc");
  1452. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1453. }
  1454. }
  1455. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1456. {
  1457. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1458. CARLA_ASSERT(kData->oscData != nullptr);
  1459. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1460. CARLA_ASSERT(index >= 0);
  1461. CARLA_ASSERT(channel >= 0 && channel < 16);
  1462. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1463. {
  1464. char targetPath[std::strlen(kData->oscData->path)+28];
  1465. std::strcpy(targetPath, kData->oscData->path);
  1466. std::strcat(targetPath, "/set_parameter_midi_channel");
  1467. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1468. }
  1469. }
  1470. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1471. {
  1472. #if DEBUG
  1473. if (index < 0)
  1474. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1475. else
  1476. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1477. #endif
  1478. CARLA_ASSERT(kData->oscData != nullptr);
  1479. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1480. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1481. {
  1482. char targetPath[std::strlen(kData->oscData->path)+21];
  1483. std::strcpy(targetPath, kData->oscData->path);
  1484. std::strcat(targetPath, "/set_parameter_value");
  1485. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1486. }
  1487. }
  1488. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1489. {
  1490. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1491. CARLA_ASSERT(kData->oscData != nullptr);
  1492. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1493. CARLA_ASSERT(index >= 0);
  1494. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1495. {
  1496. char targetPath[std::strlen(kData->oscData->path)+19];
  1497. std::strcpy(targetPath, kData->oscData->path);
  1498. std::strcat(targetPath, "/set_default_value");
  1499. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1500. }
  1501. }
  1502. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1503. {
  1504. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1505. CARLA_ASSERT(kData->oscData != nullptr);
  1506. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1507. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1508. {
  1509. char targetPath[std::strlen(kData->oscData->path)+13];
  1510. std::strcpy(targetPath, kData->oscData->path);
  1511. std::strcat(targetPath, "/set_program");
  1512. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1513. }
  1514. }
  1515. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1516. {
  1517. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1518. CARLA_ASSERT(kData->oscData != nullptr);
  1519. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1520. CARLA_ASSERT(count >= 0);
  1521. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1522. {
  1523. char targetPath[std::strlen(kData->oscData->path)+19];
  1524. std::strcpy(targetPath, kData->oscData->path);
  1525. std::strcat(targetPath, "/set_program_count");
  1526. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1527. }
  1528. }
  1529. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1530. {
  1531. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1532. CARLA_ASSERT(kData->oscData != nullptr);
  1533. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1534. CARLA_ASSERT(index >= 0);
  1535. CARLA_ASSERT(name);
  1536. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1537. {
  1538. char targetPath[std::strlen(kData->oscData->path)+18];
  1539. std::strcpy(targetPath, kData->oscData->path);
  1540. std::strcat(targetPath, "/set_program_name");
  1541. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1542. }
  1543. }
  1544. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1545. {
  1546. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1547. CARLA_ASSERT(kData->oscData != nullptr);
  1548. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1549. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1550. {
  1551. char targetPath[std::strlen(kData->oscData->path)+18];
  1552. std::strcpy(targetPath, kData->oscData->path);
  1553. std::strcat(targetPath, "/set_midi_program");
  1554. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1555. }
  1556. }
  1557. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1558. {
  1559. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1560. CARLA_ASSERT(kData->oscData != nullptr);
  1561. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1562. CARLA_ASSERT(count >= 0);
  1563. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1564. {
  1565. char targetPath[std::strlen(kData->oscData->path)+24];
  1566. std::strcpy(targetPath, kData->oscData->path);
  1567. std::strcat(targetPath, "/set_midi_program_count");
  1568. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1569. }
  1570. }
  1571. 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)
  1572. {
  1573. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1574. CARLA_ASSERT(kData->oscData != nullptr);
  1575. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1576. CARLA_ASSERT(index >= 0);
  1577. CARLA_ASSERT(bank >= 0);
  1578. CARLA_ASSERT(program >= 0);
  1579. CARLA_ASSERT(name);
  1580. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1581. {
  1582. char targetPath[std::strlen(kData->oscData->path)+23];
  1583. std::strcpy(targetPath, kData->oscData->path);
  1584. std::strcat(targetPath, "/set_midi_program_data");
  1585. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1586. }
  1587. }
  1588. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1589. {
  1590. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1591. CARLA_ASSERT(kData->oscData != nullptr);
  1592. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1593. CARLA_ASSERT(channel >= 0 && channel < 16);
  1594. CARLA_ASSERT(note >= 0 && note < 128);
  1595. CARLA_ASSERT(velo > 0 && velo < 128);
  1596. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1597. {
  1598. char targetPath[std::strlen(kData->oscData->path)+9];
  1599. std::strcpy(targetPath, kData->oscData->path);
  1600. std::strcat(targetPath, "/note_on");
  1601. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1602. }
  1603. }
  1604. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1605. {
  1606. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1607. CARLA_ASSERT(kData->oscData != nullptr);
  1608. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1609. CARLA_ASSERT(channel >= 0 && channel < 16);
  1610. CARLA_ASSERT(note >= 0 && note < 128);
  1611. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1612. {
  1613. char targetPath[std::strlen(kData->oscData->path)+10];
  1614. std::strcpy(targetPath, kData->oscData->path);
  1615. std::strcat(targetPath, "/note_off");
  1616. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1617. }
  1618. }
  1619. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1620. {
  1621. CARLA_ASSERT(kData->oscData != nullptr);
  1622. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1623. const EnginePluginData& pData = kData->plugins[pluginId];
  1624. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1625. {
  1626. char targetPath[std::strlen(kData->oscData->path)+22];
  1627. std::strcpy(targetPath, kData->oscData->path);
  1628. std::strcat(targetPath, "/set_peaks");
  1629. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1630. }
  1631. }
  1632. void CarlaEngine::osc_send_control_exit()
  1633. {
  1634. carla_debug("CarlaEngine::osc_send_control_exit()");
  1635. CARLA_ASSERT(kData->oscData != nullptr);
  1636. if (kData->oscData && kData->oscData->target)
  1637. {
  1638. char targetPath[std::strlen(kData->oscData->path)+6];
  1639. std::strcpy(targetPath, kData->oscData->path);
  1640. std::strcat(targetPath, "/exit");
  1641. lo_send(kData->oscData->target, targetPath, "");
  1642. }
  1643. }
  1644. #else
  1645. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1646. {
  1647. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1648. CARLA_ASSERT(kData->oscData != nullptr);
  1649. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1650. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1651. {
  1652. char targetPath[std::strlen(kData->oscData->path)+20];
  1653. std::strcpy(targetPath, kData->oscData->path);
  1654. std::strcat(targetPath, "/bridge_audio_count");
  1655. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1656. }
  1657. }
  1658. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1659. {
  1660. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1661. CARLA_ASSERT(kData->oscData != nullptr);
  1662. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1663. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1664. {
  1665. char targetPath[std::strlen(kData->oscData->path)+19];
  1666. std::strcpy(targetPath, kData->oscData->path);
  1667. std::strcat(targetPath, "/bridge_midi_count");
  1668. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1669. }
  1670. }
  1671. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1672. {
  1673. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1674. CARLA_ASSERT(kData->oscData != nullptr);
  1675. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1676. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1677. {
  1678. char targetPath[std::strlen(kData->oscData->path)+24];
  1679. std::strcpy(targetPath, kData->oscData->path);
  1680. std::strcat(targetPath, "/bridge_parameter_count");
  1681. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1682. }
  1683. }
  1684. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1685. {
  1686. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1687. CARLA_ASSERT(kData->oscData != nullptr);
  1688. CARLA_ASSERT(count >= 0);
  1689. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1690. {
  1691. char targetPath[std::strlen(kData->oscData->path)+22];
  1692. std::strcpy(targetPath, kData->oscData->path);
  1693. std::strcat(targetPath, "/bridge_program_count");
  1694. lo_send(kData->oscData->target, targetPath, "i", count);
  1695. }
  1696. }
  1697. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1698. {
  1699. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1700. CARLA_ASSERT(kData->oscData != nullptr);
  1701. CARLA_ASSERT(count >= 0);
  1702. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1703. {
  1704. char targetPath[std::strlen(kData->oscData->path)+27];
  1705. std::strcpy(targetPath, kData->oscData->path);
  1706. std::strcat(targetPath, "/bridge_midi_program_count");
  1707. lo_send(kData->oscData->target, targetPath, "i", count);
  1708. }
  1709. }
  1710. 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)
  1711. {
  1712. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1713. CARLA_ASSERT(kData->oscData != nullptr);
  1714. CARLA_ASSERT(name != nullptr);
  1715. CARLA_ASSERT(label != nullptr);
  1716. CARLA_ASSERT(maker != nullptr);
  1717. CARLA_ASSERT(copyright != nullptr);
  1718. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1719. {
  1720. char targetPath[std::strlen(kData->oscData->path)+20];
  1721. std::strcpy(targetPath, kData->oscData->path);
  1722. std::strcat(targetPath, "/bridge_plugin_info");
  1723. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1724. }
  1725. }
  1726. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1727. {
  1728. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1729. CARLA_ASSERT(kData->oscData != nullptr);
  1730. CARLA_ASSERT(name != nullptr);
  1731. CARLA_ASSERT(unit != nullptr);
  1732. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1733. {
  1734. char targetPath[std::strlen(kData->oscData->path)+23];
  1735. std::strcpy(targetPath, kData->oscData->path);
  1736. std::strcat(targetPath, "/bridge_parameter_info");
  1737. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1738. }
  1739. }
  1740. 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)
  1741. {
  1742. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1743. CARLA_ASSERT(kData->oscData != nullptr);
  1744. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1745. {
  1746. char targetPath[std::strlen(kData->oscData->path)+23];
  1747. std::strcpy(targetPath, kData->oscData->path);
  1748. std::strcat(targetPath, "/bridge_parameter_data");
  1749. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1750. }
  1751. }
  1752. 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)
  1753. {
  1754. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1755. CARLA_ASSERT(kData->oscData != nullptr);
  1756. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1757. {
  1758. char targetPath[std::strlen(kData->oscData->path)+25];
  1759. std::strcpy(targetPath, kData->oscData->path);
  1760. std::strcat(targetPath, "/bridge_parameter_ranges");
  1761. lo_send(kData->oscData->target, targetPath, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1762. }
  1763. }
  1764. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1765. {
  1766. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1767. CARLA_ASSERT(kData->oscData != nullptr);
  1768. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1769. {
  1770. char targetPath[std::strlen(kData->oscData->path)+21];
  1771. std::strcpy(targetPath, kData->oscData->path);
  1772. std::strcat(targetPath, "/bridge_program_info");
  1773. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1774. }
  1775. }
  1776. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1777. {
  1778. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1779. CARLA_ASSERT(kData->oscData != nullptr);
  1780. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1781. {
  1782. char targetPath[std::strlen(kData->oscData->path)+26];
  1783. std::strcpy(targetPath, kData->oscData->path);
  1784. std::strcat(targetPath, "/bridge_midi_program_info");
  1785. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1786. }
  1787. }
  1788. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1789. {
  1790. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1791. CARLA_ASSERT(kData->oscData != nullptr);
  1792. CARLA_ASSERT(key != nullptr);
  1793. CARLA_ASSERT(value != nullptr);
  1794. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1795. {
  1796. char targetPath[std::strlen(kData->oscData->path)+18];
  1797. std::strcpy(targetPath, kData->oscData->path);
  1798. std::strcat(targetPath, "/bridge_configure");
  1799. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1800. }
  1801. }
  1802. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1803. {
  1804. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1805. CARLA_ASSERT(kData->oscData != nullptr);
  1806. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1807. {
  1808. char targetPath[std::strlen(kData->oscData->path)+28];
  1809. std::strcpy(targetPath, kData->oscData->path);
  1810. std::strcat(targetPath, "/bridge_set_parameter_value");
  1811. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1812. }
  1813. }
  1814. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1815. {
  1816. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1817. CARLA_ASSERT(kData->oscData != nullptr);
  1818. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1819. {
  1820. char targetPath[std::strlen(kData->oscData->path)+26];
  1821. std::strcpy(targetPath, kData->oscData->path);
  1822. std::strcat(targetPath, "/bridge_set_default_value");
  1823. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1824. }
  1825. }
  1826. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1827. {
  1828. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1829. CARLA_ASSERT(kData->oscData != nullptr);
  1830. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1831. {
  1832. char targetPath[std::strlen(kData->oscData->path)+20];
  1833. std::strcpy(targetPath, kData->oscData->path);
  1834. std::strcat(targetPath, "/bridge_set_program");
  1835. lo_send(kData->oscData->target, targetPath, "i", index);
  1836. }
  1837. }
  1838. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1839. {
  1840. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1841. CARLA_ASSERT(kData->oscData != nullptr);
  1842. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1843. {
  1844. char targetPath[std::strlen(kData->oscData->path)+25];
  1845. std::strcpy(targetPath, kData->oscData->path);
  1846. std::strcat(targetPath, "/bridge_set_midi_program");
  1847. lo_send(kData->oscData->target, targetPath, "i", index);
  1848. }
  1849. }
  1850. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1851. {
  1852. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1853. CARLA_ASSERT(kData->oscData != nullptr);
  1854. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1855. {
  1856. char targetPath[std::strlen(kData->oscData->path)+24];
  1857. std::strcpy(targetPath, kData->oscData->path);
  1858. std::strcat(targetPath, "/bridge_set_custom_data");
  1859. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  1860. }
  1861. }
  1862. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1863. {
  1864. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1865. CARLA_ASSERT(kData->oscData != nullptr);
  1866. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1867. {
  1868. char targetPath[std::strlen(kData->oscData->path)+23];
  1869. std::strcpy(targetPath, kData->oscData->path);
  1870. std::strcat(targetPath, "/bridge_set_chunk_data");
  1871. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  1872. }
  1873. }
  1874. #endif
  1875. CARLA_BACKEND_END_NAMESPACE