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.

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