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.

2317 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. return true;
  934. }
  935. bool CarlaEngine::saveProject(const char* const filename)
  936. {
  937. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  938. CARLA_ASSERT(filename != nullptr);
  939. QFile file(filename);
  940. if (! file.open(QIODevice::WriteOnly | QIODevice::Text))
  941. return false;
  942. QTextStream out(&file);
  943. out << "<?xml version='1.0' encoding='UTF-8'?>\n";
  944. out << "<!DOCTYPE CARLA-PROJECT>\n";
  945. out << "<CARLA-PROJECT VERSION='1.0'>\n";
  946. bool firstPlugin = true;
  947. char strBuf[STR_MAX+1];
  948. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  949. {
  950. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  951. if (plugin != nullptr && plugin->enabled())
  952. {
  953. if (! firstPlugin)
  954. out << "\n";
  955. plugin->getRealName(strBuf);
  956. if (*strBuf != 0)
  957. out << QString(" <!-- %1 -->\n").arg(xmlSafeString(strBuf, true));
  958. out << " <Plugin>\n";
  959. out << getXMLFromSaveState(plugin->getSaveState());
  960. out << " </Plugin>\n";
  961. firstPlugin = false;
  962. }
  963. }
  964. out << "</CARLA-PROJECT>\n";
  965. file.close();
  966. return true;
  967. }
  968. // -----------------------------------------------------------------------
  969. // Information (peaks)
  970. float CarlaEngine::getInputPeak(const unsigned int pluginId, const unsigned short id) const
  971. {
  972. CARLA_ASSERT(pluginId < kData->curPluginCount);
  973. CARLA_ASSERT(id-1 < MAX_PEAKS);
  974. if (id == 0 || id > MAX_PEAKS)
  975. return 0.0f;
  976. return kData->plugins[pluginId].insPeak[id-1];
  977. }
  978. float CarlaEngine::getOutputPeak(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].outsPeak[id-1];
  985. }
  986. // -----------------------------------------------------------------------
  987. // Callback
  988. void CarlaEngine::callback(const CallbackType action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr)
  989. {
  990. carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", CallbackType2Str(action), pluginId, value1, value2, value3, valueStr);
  991. if (kData->callback)
  992. kData->callback(kData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  993. }
  994. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  995. {
  996. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  997. CARLA_ASSERT(func);
  998. kData->callback = func;
  999. kData->callbackPtr = ptr;
  1000. }
  1001. // -----------------------------------------------------------------------
  1002. // Patchbay
  1003. bool CarlaEngine::patchbayConnect(int, int)
  1004. {
  1005. setLastError("Unsupported operation");
  1006. return false;
  1007. }
  1008. bool CarlaEngine::patchbayDisconnect(int)
  1009. {
  1010. setLastError("Unsupported operation");
  1011. return false;
  1012. }
  1013. void CarlaEngine::patchbayRefresh()
  1014. {
  1015. // nothing
  1016. }
  1017. // -----------------------------------------------------------------------
  1018. // Transport
  1019. void CarlaEngine::transportPlay()
  1020. {
  1021. kData->time.playing = true;
  1022. }
  1023. void CarlaEngine::transportPause()
  1024. {
  1025. kData->time.playing = false;
  1026. }
  1027. void CarlaEngine::transportRelocate(const uint32_t frame)
  1028. {
  1029. kData->time.frame = frame;
  1030. }
  1031. // -----------------------------------------------------------------------
  1032. // Error handling
  1033. const char* CarlaEngine::getLastError() const
  1034. {
  1035. return (const char*)kData->lastError;
  1036. }
  1037. void CarlaEngine::setLastError(const char* const error)
  1038. {
  1039. kData->lastError = error;
  1040. }
  1041. void CarlaEngine::setAboutToClose()
  1042. {
  1043. carla_debug("CarlaEngine::setAboutToClose()");
  1044. kData->aboutToClose = true;
  1045. }
  1046. // -----------------------------------------------------------------------
  1047. // Global options
  1048. #define CARLA_ENGINE_SET_OPTION_RUNNING_CHECK \
  1049. if (isRunning()) \
  1050. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr);
  1051. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  1052. {
  1053. carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr);
  1054. switch (option)
  1055. {
  1056. case OPTION_PROCESS_NAME:
  1057. carla_setprocname(valueStr);
  1058. break;
  1059. case OPTION_PROCESS_MODE:
  1060. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1061. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_BRIDGE)
  1062. return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2Str(option), value, valueStr);
  1063. fOptions.processMode = static_cast<ProcessMode>(value);
  1064. break;
  1065. case OPTION_TRANSPORT_MODE:
  1066. // FIXME: Always enable JACK transport for now
  1067. #if 0
  1068. if (value < CarlaBackend::TRANSPORT_MODE_INTERNAL || value > CarlaBackend::TRANSPORT_MODE_BRIDGE)
  1069. return carla_stderr2("carla_set_engine_option(OPTION_TRANSPORT_MODE, %i, \"%s\") - invalid value", value, valueStr);
  1070. fOptions.transportMode = static_cast<CarlaBackend::TransportMode>(value);
  1071. #endif
  1072. break;
  1073. case OPTION_MAX_PARAMETERS:
  1074. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1075. if (value < 0)
  1076. return; // TODO error here
  1077. fOptions.maxParameters = static_cast<uint>(value);
  1078. break;
  1079. case OPTION_PREFERRED_BUFFER_SIZE:
  1080. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1081. fOptions.preferredBufferSize = static_cast<uint>(value);
  1082. break;
  1083. case OPTION_PREFERRED_SAMPLE_RATE:
  1084. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1085. fOptions.preferredSampleRate = static_cast<uint>(value);
  1086. break;
  1087. case OPTION_FORCE_STEREO:
  1088. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1089. fOptions.forceStereo = (value != 0);
  1090. break;
  1091. #ifdef WANT_DSSI
  1092. case OPTION_USE_DSSI_VST_CHUNKS:
  1093. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1094. fOptions.useDssiVstChunks = (value != 0);
  1095. break;
  1096. #endif
  1097. case OPTION_PREFER_PLUGIN_BRIDGES:
  1098. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1099. fOptions.preferPluginBridges = (value != 0);
  1100. break;
  1101. case OPTION_PREFER_UI_BRIDGES:
  1102. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1103. fOptions.preferUiBridges = (value != 0);
  1104. break;
  1105. case OPTION_OSC_UI_TIMEOUT:
  1106. CARLA_ENGINE_SET_OPTION_RUNNING_CHECK
  1107. fOptions.oscUiTimeout = static_cast<uint>(value);
  1108. break;
  1109. #ifndef BUILD_BRIDGE
  1110. case OPTION_PATH_BRIDGE_NATIVE:
  1111. fOptions.bridge_native = valueStr;
  1112. break;
  1113. case OPTION_PATH_BRIDGE_POSIX32:
  1114. fOptions.bridge_posix32 = valueStr;
  1115. break;
  1116. case OPTION_PATH_BRIDGE_POSIX64:
  1117. fOptions.bridge_posix64 = valueStr;
  1118. break;
  1119. case OPTION_PATH_BRIDGE_WIN32:
  1120. fOptions.bridge_win32 = valueStr;
  1121. break;
  1122. case OPTION_PATH_BRIDGE_WIN64:
  1123. fOptions.bridge_win64 = valueStr;
  1124. break;
  1125. #endif
  1126. #ifdef WANT_LV2
  1127. case OPTION_PATH_BRIDGE_LV2_GTK2:
  1128. fOptions.bridge_lv2Gtk2 = valueStr;
  1129. break;
  1130. case OPTION_PATH_BRIDGE_LV2_GTK3:
  1131. fOptions.bridge_lv2Gtk3 = valueStr;
  1132. break;
  1133. case OPTION_PATH_BRIDGE_LV2_QT4:
  1134. fOptions.bridge_lv2Qt4 = valueStr;
  1135. break;
  1136. case OPTION_PATH_BRIDGE_LV2_QT5:
  1137. fOptions.bridge_lv2Qt5 = valueStr;
  1138. break;
  1139. case OPTION_PATH_BRIDGE_LV2_COCOA:
  1140. fOptions.bridge_lv2Cocoa = valueStr;
  1141. break;
  1142. case OPTION_PATH_BRIDGE_LV2_WINDOWS:
  1143. fOptions.bridge_lv2Win = valueStr;
  1144. break;
  1145. case OPTION_PATH_BRIDGE_LV2_X11:
  1146. fOptions.bridge_lv2X11 = valueStr;
  1147. break;
  1148. #endif
  1149. #ifdef WANT_VST
  1150. case OPTION_PATH_BRIDGE_VST_COCOA:
  1151. fOptions.bridge_vstCocoa = valueStr;
  1152. break;
  1153. case OPTION_PATH_BRIDGE_VST_HWND:
  1154. fOptions.bridge_vstHWND = valueStr;
  1155. break;
  1156. case OPTION_PATH_BRIDGE_VST_X11:
  1157. fOptions.bridge_vstX11 = valueStr;
  1158. break;
  1159. #endif
  1160. }
  1161. }
  1162. // -----------------------------------------------------------------------
  1163. // OSC Stuff
  1164. #ifdef BUILD_BRIDGE
  1165. bool CarlaEngine::isOscBridgeRegistered() const
  1166. {
  1167. return (kData->oscData != nullptr);
  1168. }
  1169. #else
  1170. bool CarlaEngine::isOscControlRegistered() const
  1171. {
  1172. return kData->osc.isControlRegistered();
  1173. }
  1174. #endif
  1175. void CarlaEngine::idleOsc()
  1176. {
  1177. kData->osc.idle();
  1178. }
  1179. const char* CarlaEngine::getOscServerPathTCP() const
  1180. {
  1181. return kData->osc.getServerPathTCP();
  1182. }
  1183. const char* CarlaEngine::getOscServerPathUDP() const
  1184. {
  1185. return kData->osc.getServerPathUDP();
  1186. }
  1187. #ifdef BUILD_BRIDGE
  1188. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  1189. {
  1190. kData->oscData = oscData;
  1191. }
  1192. #endif
  1193. // -----------------------------------------------------------------------
  1194. // protected calls
  1195. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1196. {
  1197. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1198. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1199. {
  1200. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1201. if (plugin != nullptr && plugin->enabled())
  1202. plugin->bufferSizeChanged(newBufferSize);
  1203. }
  1204. callback(CALLBACK_BUFFER_SIZE_CHANGED, 0, newBufferSize, 0, 0.0f, nullptr);
  1205. }
  1206. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1207. {
  1208. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1209. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1210. {
  1211. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1212. if (plugin != nullptr && plugin->enabled())
  1213. plugin->sampleRateChanged(newSampleRate);
  1214. }
  1215. callback(CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, newSampleRate, nullptr);
  1216. }
  1217. void CarlaEngine::proccessPendingEvents()
  1218. {
  1219. //carla_stderr("proccessPendingEvents(%i)", kData->nextAction.opcode);
  1220. switch (kData->nextAction.opcode)
  1221. {
  1222. case EnginePostActionNull:
  1223. break;
  1224. case EnginePostActionRemovePlugin:
  1225. doPluginRemove(kData, true);
  1226. break;
  1227. case EnginePostActionSwitchPlugins:
  1228. doPluginsSwitch(kData, true);
  1229. break;
  1230. }
  1231. if (kData->time.playing)
  1232. kData->time.frame += fBufferSize;
  1233. if (fOptions.transportMode == CarlaBackend::TRANSPORT_MODE_INTERNAL)
  1234. {
  1235. fTimeInfo.playing = kData->time.playing;
  1236. fTimeInfo.frame = kData->time.frame;
  1237. }
  1238. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1239. {
  1240. // TODO - peak values?
  1241. }
  1242. }
  1243. void CarlaEngine::setPeaks(const unsigned int pluginId, float const inPeaks[MAX_PEAKS], float const outPeaks[MAX_PEAKS])
  1244. {
  1245. kData->plugins[pluginId].insPeak[0] = inPeaks[0];
  1246. kData->plugins[pluginId].insPeak[1] = inPeaks[1];
  1247. kData->plugins[pluginId].outsPeak[0] = outPeaks[0];
  1248. kData->plugins[pluginId].outsPeak[1] = outPeaks[1];
  1249. }
  1250. #ifndef BUILD_BRIDGE
  1251. EngineEvent* CarlaEngine::getRackEventBuffer(const bool isInput)
  1252. {
  1253. return isInput ? kData->rack.in : kData->rack.out;
  1254. }
  1255. void setValueIfHigher(float& value, const float& compare)
  1256. {
  1257. if (value < compare)
  1258. value = compare;
  1259. }
  1260. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], const uint32_t frames)
  1261. {
  1262. // initialize outputs (zero)
  1263. carla_zeroFloat(outBuf[0], frames);
  1264. carla_zeroFloat(outBuf[1], frames);
  1265. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1266. bool processed = false;
  1267. // process plugins
  1268. for (unsigned int i=0; i < kData->curPluginCount; ++i)
  1269. {
  1270. CarlaPlugin* const plugin = kData->plugins[i].plugin;
  1271. if (plugin == nullptr || ! plugin->enabled() || ! plugin->tryLock())
  1272. continue;
  1273. if (processed)
  1274. {
  1275. // initialize inputs (from previous outputs)
  1276. carla_copyFloat(inBuf[0], outBuf[0], frames);
  1277. carla_copyFloat(inBuf[1], outBuf[1], frames);
  1278. std::memcpy(kData->rack.in, kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1279. // initialize outputs (zero)
  1280. carla_zeroFloat(outBuf[0], frames);
  1281. carla_zeroFloat(outBuf[1], frames);
  1282. carla_zeroMem(kData->rack.out, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1283. }
  1284. // process
  1285. plugin->initBuffers();
  1286. plugin->process(inBuf, outBuf, frames);
  1287. plugin->unlock();
  1288. #if 0
  1289. // if plugin has no audio inputs, add previous buffers
  1290. if (plugin->audioInCount() == 0)
  1291. {
  1292. for (uint32_t j=0; j < frames; ++j)
  1293. {
  1294. outBuf[0][j] += inBuf[0][j];
  1295. outBuf[1][j] += inBuf[1][j];
  1296. }
  1297. }
  1298. // if plugin has no midi output, add previous events
  1299. if (plugin->midiOutCount() == 0)
  1300. {
  1301. for (uint32_t j=0, k=0; j < frames; ++j)
  1302. {
  1303. }
  1304. std::memcpy(kData->rack.out, kData->rack.in, sizeof(EngineEvent)*RACK_EVENT_COUNT);
  1305. }
  1306. #endif
  1307. // set peaks
  1308. {
  1309. float inPeak1 = 0.0f;
  1310. float inPeak2 = 0.0f;
  1311. float outPeak1 = 0.0f;
  1312. float outPeak2 = 0.0f;
  1313. for (uint32_t k=0; k < frames; ++k)
  1314. {
  1315. setValueIfHigher(inPeak1, std::fabs(inBuf[0][k]));
  1316. setValueIfHigher(inPeak2, std::fabs(inBuf[1][k]));
  1317. setValueIfHigher(outPeak1, std::fabs(outBuf[0][k]));
  1318. setValueIfHigher(outPeak2, std::fabs(outBuf[1][k]));
  1319. }
  1320. kData->plugins[i].insPeak[0] = inPeak1;
  1321. kData->plugins[i].insPeak[1] = inPeak2;
  1322. kData->plugins[i].outsPeak[0] = outPeak1;
  1323. kData->plugins[i].outsPeak[1] = outPeak2;
  1324. }
  1325. processed = true;
  1326. }
  1327. }
  1328. void CarlaEngine::processPatchbay(float** inBuf, float** outBuf, const uint32_t bufCount[2], const uint32_t frames)
  1329. {
  1330. // TODO
  1331. return;
  1332. // unused, for now
  1333. (void)inBuf;
  1334. (void)outBuf;
  1335. (void)bufCount;
  1336. (void)frames;
  1337. }
  1338. #endif
  1339. // -------------------------------------------------------------------------------------------------------------------
  1340. // Carla Engine OSC stuff
  1341. #ifndef BUILD_BRIDGE
  1342. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1343. {
  1344. carla_debug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1345. CARLA_ASSERT(kData->oscData != nullptr);
  1346. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1347. CARLA_ASSERT(pluginName);
  1348. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1349. {
  1350. char targetPath[std::strlen(kData->oscData->path)+18];
  1351. std::strcpy(targetPath, kData->oscData->path);
  1352. std::strcat(targetPath, "/add_plugin_start");
  1353. lo_send(kData->oscData->target, targetPath, "is", pluginId, pluginName);
  1354. }
  1355. }
  1356. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1357. {
  1358. carla_debug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1359. CARLA_ASSERT(kData->oscData != nullptr);
  1360. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1361. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1362. {
  1363. char targetPath[std::strlen(kData->oscData->path)+16];
  1364. std::strcpy(targetPath, kData->oscData->path);
  1365. std::strcat(targetPath, "/add_plugin_end");
  1366. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1367. }
  1368. }
  1369. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1370. {
  1371. carla_debug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1372. CARLA_ASSERT(kData->oscData != nullptr);
  1373. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1374. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1375. {
  1376. char targetPath[std::strlen(kData->oscData->path)+15];
  1377. std::strcpy(targetPath, kData->oscData->path);
  1378. std::strcat(targetPath, "/remove_plugin");
  1379. lo_send(kData->oscData->target, targetPath, "i", pluginId);
  1380. }
  1381. }
  1382. 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)
  1383. {
  1384. 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);
  1385. CARLA_ASSERT(kData->oscData != nullptr);
  1386. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1387. CARLA_ASSERT(type != PLUGIN_NONE);
  1388. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1389. {
  1390. char targetPath[std::strlen(kData->oscData->path)+17];
  1391. std::strcpy(targetPath, kData->oscData->path);
  1392. std::strcat(targetPath, "/set_plugin_data");
  1393. lo_send(kData->oscData->target, targetPath, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1394. }
  1395. }
  1396. 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)
  1397. {
  1398. 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);
  1399. CARLA_ASSERT(kData->oscData != nullptr);
  1400. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1401. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1402. {
  1403. char targetPath[std::strlen(kData->oscData->path)+18];
  1404. std::strcpy(targetPath, kData->oscData->path);
  1405. std::strcat(targetPath, "/set_plugin_ports");
  1406. lo_send(kData->oscData->target, targetPath, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1407. }
  1408. }
  1409. 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)
  1410. {
  1411. carla_debug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1412. CARLA_ASSERT(kData->oscData != nullptr);
  1413. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1414. CARLA_ASSERT(index >= 0);
  1415. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1416. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1417. {
  1418. char targetPath[std::strlen(kData->oscData->path)+20];
  1419. std::strcpy(targetPath, kData->oscData->path);
  1420. std::strcat(targetPath, "/set_parameter_data");
  1421. lo_send(kData->oscData->target, targetPath, "iiiissd", pluginId, index, type, hints, name, label, current);
  1422. }
  1423. }
  1424. 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)
  1425. {
  1426. 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);
  1427. CARLA_ASSERT(kData->oscData != nullptr);
  1428. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1429. CARLA_ASSERT(index >= 0);
  1430. CARLA_ASSERT(min < max);
  1431. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1432. {
  1433. char targetPath[std::strlen(kData->oscData->path)+22];
  1434. std::strcpy(targetPath, kData->oscData->path);
  1435. std::strcat(targetPath, "/set_parameter_ranges");
  1436. lo_send(kData->oscData->target, targetPath, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1437. }
  1438. }
  1439. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1440. {
  1441. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1442. CARLA_ASSERT(kData->oscData != nullptr);
  1443. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1444. CARLA_ASSERT(index >= 0);
  1445. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1446. {
  1447. char targetPath[std::strlen(kData->oscData->path)+23];
  1448. std::strcpy(targetPath, kData->oscData->path);
  1449. std::strcat(targetPath, "/set_parameter_midi_cc");
  1450. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, cc);
  1451. }
  1452. }
  1453. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1454. {
  1455. carla_debug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1456. CARLA_ASSERT(kData->oscData != nullptr);
  1457. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1458. CARLA_ASSERT(index >= 0);
  1459. CARLA_ASSERT(channel >= 0 && channel < 16);
  1460. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1461. {
  1462. char targetPath[std::strlen(kData->oscData->path)+28];
  1463. std::strcpy(targetPath, kData->oscData->path);
  1464. std::strcat(targetPath, "/set_parameter_midi_channel");
  1465. lo_send(kData->oscData->target, targetPath, "iii", pluginId, index, channel);
  1466. }
  1467. }
  1468. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const float value)
  1469. {
  1470. #if DEBUG
  1471. if (index < 0)
  1472. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2Str((InternalParametersIndex)index), value);
  1473. else
  1474. carla_debug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1475. #endif
  1476. CARLA_ASSERT(kData->oscData != nullptr);
  1477. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->curPluginCount);
  1478. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1479. {
  1480. char targetPath[std::strlen(kData->oscData->path)+21];
  1481. std::strcpy(targetPath, kData->oscData->path);
  1482. std::strcat(targetPath, "/set_parameter_value");
  1483. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1484. }
  1485. }
  1486. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const float value)
  1487. {
  1488. carla_debug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1489. CARLA_ASSERT(kData->oscData != nullptr);
  1490. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1491. CARLA_ASSERT(index >= 0);
  1492. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1493. {
  1494. char targetPath[std::strlen(kData->oscData->path)+19];
  1495. std::strcpy(targetPath, kData->oscData->path);
  1496. std::strcat(targetPath, "/set_default_value");
  1497. lo_send(kData->oscData->target, targetPath, "iid", pluginId, index, value);
  1498. }
  1499. }
  1500. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1501. {
  1502. carla_debug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1503. CARLA_ASSERT(kData->oscData != nullptr);
  1504. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1505. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1506. {
  1507. char targetPath[std::strlen(kData->oscData->path)+13];
  1508. std::strcpy(targetPath, kData->oscData->path);
  1509. std::strcat(targetPath, "/set_program");
  1510. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1511. }
  1512. }
  1513. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1514. {
  1515. carla_debug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1516. CARLA_ASSERT(kData->oscData != nullptr);
  1517. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1518. CARLA_ASSERT(count >= 0);
  1519. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1520. {
  1521. char targetPath[std::strlen(kData->oscData->path)+19];
  1522. std::strcpy(targetPath, kData->oscData->path);
  1523. std::strcat(targetPath, "/set_program_count");
  1524. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1525. }
  1526. }
  1527. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1528. {
  1529. carla_debug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1530. CARLA_ASSERT(kData->oscData != nullptr);
  1531. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1532. CARLA_ASSERT(index >= 0);
  1533. CARLA_ASSERT(name);
  1534. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1535. {
  1536. char targetPath[std::strlen(kData->oscData->path)+18];
  1537. std::strcpy(targetPath, kData->oscData->path);
  1538. std::strcat(targetPath, "/set_program_name");
  1539. lo_send(kData->oscData->target, targetPath, "iis", pluginId, index, name);
  1540. }
  1541. }
  1542. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1543. {
  1544. carla_debug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1545. CARLA_ASSERT(kData->oscData != nullptr);
  1546. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1547. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1548. {
  1549. char targetPath[std::strlen(kData->oscData->path)+18];
  1550. std::strcpy(targetPath, kData->oscData->path);
  1551. std::strcat(targetPath, "/set_midi_program");
  1552. lo_send(kData->oscData->target, targetPath, "ii", pluginId, index);
  1553. }
  1554. }
  1555. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1556. {
  1557. carla_debug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1558. CARLA_ASSERT(kData->oscData != nullptr);
  1559. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1560. CARLA_ASSERT(count >= 0);
  1561. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1562. {
  1563. char targetPath[std::strlen(kData->oscData->path)+24];
  1564. std::strcpy(targetPath, kData->oscData->path);
  1565. std::strcat(targetPath, "/set_midi_program_count");
  1566. lo_send(kData->oscData->target, targetPath, "ii", pluginId, count);
  1567. }
  1568. }
  1569. 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)
  1570. {
  1571. carla_debug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1572. CARLA_ASSERT(kData->oscData != nullptr);
  1573. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1574. CARLA_ASSERT(index >= 0);
  1575. CARLA_ASSERT(bank >= 0);
  1576. CARLA_ASSERT(program >= 0);
  1577. CARLA_ASSERT(name);
  1578. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1579. {
  1580. char targetPath[std::strlen(kData->oscData->path)+23];
  1581. std::strcpy(targetPath, kData->oscData->path);
  1582. std::strcat(targetPath, "/set_midi_program_data");
  1583. lo_send(kData->oscData->target, targetPath, "iiiis", pluginId, index, bank, program, name);
  1584. }
  1585. }
  1586. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1587. {
  1588. carla_debug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1589. CARLA_ASSERT(kData->oscData != nullptr);
  1590. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1591. CARLA_ASSERT(channel >= 0 && channel < 16);
  1592. CARLA_ASSERT(note >= 0 && note < 128);
  1593. CARLA_ASSERT(velo > 0 && velo < 128);
  1594. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1595. {
  1596. char targetPath[std::strlen(kData->oscData->path)+9];
  1597. std::strcpy(targetPath, kData->oscData->path);
  1598. std::strcat(targetPath, "/note_on");
  1599. lo_send(kData->oscData->target, targetPath, "iiii", pluginId, channel, note, velo);
  1600. }
  1601. }
  1602. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1603. {
  1604. carla_debug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1605. CARLA_ASSERT(kData->oscData != nullptr);
  1606. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1607. CARLA_ASSERT(channel >= 0 && channel < 16);
  1608. CARLA_ASSERT(note >= 0 && note < 128);
  1609. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1610. {
  1611. char targetPath[std::strlen(kData->oscData->path)+10];
  1612. std::strcpy(targetPath, kData->oscData->path);
  1613. std::strcat(targetPath, "/note_off");
  1614. lo_send(kData->oscData->target, targetPath, "iii", pluginId, channel, note);
  1615. }
  1616. }
  1617. void CarlaEngine::osc_send_control_set_peaks(const int32_t pluginId)
  1618. {
  1619. CARLA_ASSERT(kData->oscData != nullptr);
  1620. CARLA_ASSERT(pluginId >= 0 && pluginId < (int32_t)kData->maxPluginNumber);
  1621. const EnginePluginData& pData = kData->plugins[pluginId];
  1622. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1623. {
  1624. char targetPath[std::strlen(kData->oscData->path)+22];
  1625. std::strcpy(targetPath, kData->oscData->path);
  1626. std::strcat(targetPath, "/set_peaks");
  1627. lo_send(kData->oscData->target, targetPath, "iffff", pluginId, pData.insPeak[0], pData.insPeak[1], pData.outsPeak[0], pData.outsPeak[1]);
  1628. }
  1629. }
  1630. void CarlaEngine::osc_send_control_exit()
  1631. {
  1632. carla_debug("CarlaEngine::osc_send_control_exit()");
  1633. CARLA_ASSERT(kData->oscData != nullptr);
  1634. if (kData->oscData && kData->oscData->target)
  1635. {
  1636. char targetPath[std::strlen(kData->oscData->path)+6];
  1637. std::strcpy(targetPath, kData->oscData->path);
  1638. std::strcat(targetPath, "/exit");
  1639. lo_send(kData->oscData->target, targetPath, "");
  1640. }
  1641. }
  1642. #else
  1643. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1644. {
  1645. carla_debug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1646. CARLA_ASSERT(kData->oscData != nullptr);
  1647. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1648. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1649. {
  1650. char targetPath[std::strlen(kData->oscData->path)+20];
  1651. std::strcpy(targetPath, kData->oscData->path);
  1652. std::strcat(targetPath, "/bridge_audio_count");
  1653. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1654. }
  1655. }
  1656. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1657. {
  1658. carla_debug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1659. CARLA_ASSERT(kData->oscData != nullptr);
  1660. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1661. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1662. {
  1663. char targetPath[std::strlen(kData->oscData->path)+19];
  1664. std::strcpy(targetPath, kData->oscData->path);
  1665. std::strcat(targetPath, "/bridge_midi_count");
  1666. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1667. }
  1668. }
  1669. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1670. {
  1671. carla_debug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1672. CARLA_ASSERT(kData->oscData != nullptr);
  1673. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1674. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1675. {
  1676. char targetPath[std::strlen(kData->oscData->path)+24];
  1677. std::strcpy(targetPath, kData->oscData->path);
  1678. std::strcat(targetPath, "/bridge_parameter_count");
  1679. lo_send(kData->oscData->target, targetPath, "iii", ins, outs, total);
  1680. }
  1681. }
  1682. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1683. {
  1684. carla_debug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1685. CARLA_ASSERT(kData->oscData != nullptr);
  1686. CARLA_ASSERT(count >= 0);
  1687. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1688. {
  1689. char targetPath[std::strlen(kData->oscData->path)+22];
  1690. std::strcpy(targetPath, kData->oscData->path);
  1691. std::strcat(targetPath, "/bridge_program_count");
  1692. lo_send(kData->oscData->target, targetPath, "i", count);
  1693. }
  1694. }
  1695. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1696. {
  1697. carla_debug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1698. CARLA_ASSERT(kData->oscData != nullptr);
  1699. CARLA_ASSERT(count >= 0);
  1700. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1701. {
  1702. char targetPath[std::strlen(kData->oscData->path)+27];
  1703. std::strcpy(targetPath, kData->oscData->path);
  1704. std::strcat(targetPath, "/bridge_midi_program_count");
  1705. lo_send(kData->oscData->target, targetPath, "i", count);
  1706. }
  1707. }
  1708. 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)
  1709. {
  1710. carla_debug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1711. CARLA_ASSERT(kData->oscData != nullptr);
  1712. CARLA_ASSERT(name != nullptr);
  1713. CARLA_ASSERT(label != nullptr);
  1714. CARLA_ASSERT(maker != nullptr);
  1715. CARLA_ASSERT(copyright != nullptr);
  1716. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1717. {
  1718. char targetPath[std::strlen(kData->oscData->path)+20];
  1719. std::strcpy(targetPath, kData->oscData->path);
  1720. std::strcat(targetPath, "/bridge_plugin_info");
  1721. lo_send(kData->oscData->target, targetPath, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1722. }
  1723. }
  1724. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1725. {
  1726. carla_debug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1727. CARLA_ASSERT(kData->oscData != nullptr);
  1728. CARLA_ASSERT(name != nullptr);
  1729. CARLA_ASSERT(unit != nullptr);
  1730. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1731. {
  1732. char targetPath[std::strlen(kData->oscData->path)+23];
  1733. std::strcpy(targetPath, kData->oscData->path);
  1734. std::strcat(targetPath, "/bridge_parameter_info");
  1735. lo_send(kData->oscData->target, targetPath, "iss", index, name, unit);
  1736. }
  1737. }
  1738. 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)
  1739. {
  1740. carla_debug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1741. CARLA_ASSERT(kData->oscData != nullptr);
  1742. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1743. {
  1744. char targetPath[std::strlen(kData->oscData->path)+23];
  1745. std::strcpy(targetPath, kData->oscData->path);
  1746. std::strcat(targetPath, "/bridge_parameter_data");
  1747. lo_send(kData->oscData->target, targetPath, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1748. }
  1749. }
  1750. 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)
  1751. {
  1752. carla_debug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1753. CARLA_ASSERT(kData->oscData != nullptr);
  1754. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1755. {
  1756. char targetPath[std::strlen(kData->oscData->path)+25];
  1757. std::strcpy(targetPath, kData->oscData->path);
  1758. std::strcat(targetPath, "/bridge_parameter_ranges");
  1759. lo_send(kData->oscData->target, targetPath, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1760. }
  1761. }
  1762. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1763. {
  1764. carla_debug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1765. CARLA_ASSERT(kData->oscData != nullptr);
  1766. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1767. {
  1768. char targetPath[std::strlen(kData->oscData->path)+21];
  1769. std::strcpy(targetPath, kData->oscData->path);
  1770. std::strcat(targetPath, "/bridge_program_info");
  1771. lo_send(kData->oscData->target, targetPath, "is", index, name);
  1772. }
  1773. }
  1774. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1775. {
  1776. carla_debug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1777. CARLA_ASSERT(kData->oscData != nullptr);
  1778. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1779. {
  1780. char targetPath[std::strlen(kData->oscData->path)+26];
  1781. std::strcpy(targetPath, kData->oscData->path);
  1782. std::strcat(targetPath, "/bridge_midi_program_info");
  1783. lo_send(kData->oscData->target, targetPath, "iiis", index, bank, program, label);
  1784. }
  1785. }
  1786. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1787. {
  1788. carla_debug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1789. CARLA_ASSERT(kData->oscData != nullptr);
  1790. CARLA_ASSERT(key != nullptr);
  1791. CARLA_ASSERT(value != nullptr);
  1792. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1793. {
  1794. char targetPath[std::strlen(kData->oscData->path)+18];
  1795. std::strcpy(targetPath, kData->oscData->path);
  1796. std::strcat(targetPath, "/bridge_configure");
  1797. lo_send(kData->oscData->target, targetPath, "ss", key, value);
  1798. }
  1799. }
  1800. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const float value)
  1801. {
  1802. carla_debug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1803. CARLA_ASSERT(kData->oscData != nullptr);
  1804. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1805. {
  1806. char targetPath[std::strlen(kData->oscData->path)+28];
  1807. std::strcpy(targetPath, kData->oscData->path);
  1808. std::strcat(targetPath, "/bridge_set_parameter_value");
  1809. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1810. }
  1811. }
  1812. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const float value)
  1813. {
  1814. carla_debug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1815. CARLA_ASSERT(kData->oscData != nullptr);
  1816. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1817. {
  1818. char targetPath[std::strlen(kData->oscData->path)+26];
  1819. std::strcpy(targetPath, kData->oscData->path);
  1820. std::strcat(targetPath, "/bridge_set_default_value");
  1821. lo_send(kData->oscData->target, targetPath, "id", index, value);
  1822. }
  1823. }
  1824. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1825. {
  1826. carla_debug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1827. CARLA_ASSERT(kData->oscData != nullptr);
  1828. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1829. {
  1830. char targetPath[std::strlen(kData->oscData->path)+20];
  1831. std::strcpy(targetPath, kData->oscData->path);
  1832. std::strcat(targetPath, "/bridge_set_program");
  1833. lo_send(kData->oscData->target, targetPath, "i", index);
  1834. }
  1835. }
  1836. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1837. {
  1838. carla_debug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1839. CARLA_ASSERT(kData->oscData != nullptr);
  1840. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1841. {
  1842. char targetPath[std::strlen(kData->oscData->path)+25];
  1843. std::strcpy(targetPath, kData->oscData->path);
  1844. std::strcat(targetPath, "/bridge_set_midi_program");
  1845. lo_send(kData->oscData->target, targetPath, "i", index);
  1846. }
  1847. }
  1848. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const type, const char* const key, const char* const value)
  1849. {
  1850. carla_debug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value);
  1851. CARLA_ASSERT(kData->oscData != nullptr);
  1852. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1853. {
  1854. char targetPath[std::strlen(kData->oscData->path)+24];
  1855. std::strcpy(targetPath, kData->oscData->path);
  1856. std::strcat(targetPath, "/bridge_set_custom_data");
  1857. lo_send(kData->oscData->target, targetPath, "sss", type, key, value);
  1858. }
  1859. }
  1860. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1861. {
  1862. carla_debug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1863. CARLA_ASSERT(kData->oscData != nullptr);
  1864. if (kData->oscData != nullptr && kData->oscData->target != nullptr)
  1865. {
  1866. char targetPath[std::strlen(kData->oscData->path)+23];
  1867. std::strcpy(targetPath, kData->oscData->path);
  1868. std::strcat(targetPath, "/bridge_set_chunk_data");
  1869. lo_send(kData->oscData->target, targetPath, "s", chunkFile);
  1870. }
  1871. }
  1872. #endif
  1873. CARLA_BACKEND_END_NAMESPACE