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.

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