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.

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