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.

2122 lines
66KB

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