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.

2152 lines
68KB

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