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.

2167 lines
68KB

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