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.

2164 lines
69KB

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