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.

2244 lines
71KB

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