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.

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