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.

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