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.

2108 lines
67KB

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