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.

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