Collection of tools useful for audio production
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.

1455 lines
41KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 2012 Filipe Coelho <falktx@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #include "carla_engine.h"
  18. #include "carla_plugin.h"
  19. CARLA_BACKEND_START_NAMESPACE
  20. // -----------------------------------------------------------------------
  21. CarlaEngine::CarlaEngine()
  22. : m_checkThread(this),
  23. #ifndef BUILD_BRIDGE
  24. m_osc(this),
  25. m_oscData(nullptr),
  26. #endif
  27. m_callback(nullptr),
  28. #ifdef Q_COMPILER_INITIALIZER_LISTS
  29. m_callbackPtr(nullptr),
  30. m_carlaPlugins{nullptr},
  31. m_uniqueNames{nullptr},
  32. m_insPeak{0.0},
  33. m_outsPeak{0.0}
  34. #else
  35. m_callbackPtr(nullptr)
  36. #endif
  37. {
  38. qDebug("CarlaEngine::CarlaEngine()");
  39. type = CarlaEngineTypeNull;
  40. name = nullptr;
  41. bufferSize = 0;
  42. sampleRate = 0.0;
  43. maxPluginNumber = 0;
  44. #ifndef Q_COMPILER_INITIALIZER_LISTS
  45. for (unsigned short i=0; i < MAX_PLUGINS; i++)
  46. {
  47. m_carlaPlugins[i] = nullptr;
  48. m_uniqueNames[i] = nullptr;
  49. }
  50. for (unsigned short i=0; i < MAX_PLUGINS * MAX_PEAKS; i++)
  51. {
  52. m_insPeak[i] = 0.0;
  53. m_outsPeak[i] = 0.0;
  54. }
  55. #endif
  56. }
  57. CarlaEngine::~CarlaEngine()
  58. {
  59. qDebug("CarlaEngine::~CarlaEngine()");
  60. if (name)
  61. free((void*)name);
  62. }
  63. // -----------------------------------------------------------------------
  64. // Static values
  65. int CarlaEngine::maxClientNameSize()
  66. {
  67. #ifdef CARLA_ENGINE_JACK
  68. # ifndef BUILD_BRIDGE
  69. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  70. # endif
  71. return jack_client_name_size();
  72. #endif
  73. return STR_MAX/2;
  74. }
  75. int CarlaEngine::maxPortNameSize()
  76. {
  77. #ifdef CARLA_ENGINE_JACK
  78. # ifndef BUILD_BRIDGE
  79. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  80. # endif
  81. return jack_port_name_size();
  82. #endif
  83. return STR_MAX;
  84. }
  85. bool CarlaEngine::init(const char* const clientName)
  86. {
  87. qDebug("CarlaEngine::init(\"%s\")", clientName);
  88. #ifndef BUILD_BRIDGE
  89. m_osc.init(clientName);
  90. m_oscData = m_osc.getControllerData();
  91. #endif
  92. return true;
  93. }
  94. bool CarlaEngine::close()
  95. {
  96. qDebug("CarlaEngine::close()");
  97. m_checkThread.stopNow();
  98. #ifndef BUILD_BRIDGE
  99. m_oscData = nullptr;
  100. m_osc.close();
  101. #endif
  102. maxPluginNumber = 0;
  103. return true;
  104. }
  105. // -----------------------------------------------------------------------
  106. // plugin management
  107. short CarlaEngine::getNewPluginId() const
  108. {
  109. qDebug("CarlaEngine::getNewPluginId()");
  110. for (unsigned short i=0; i < maxPluginNumber; i++)
  111. {
  112. if (! m_carlaPlugins[i])
  113. return i;
  114. }
  115. return -1;
  116. }
  117. CarlaPlugin* CarlaEngine::getPlugin(const unsigned short id) const
  118. {
  119. qDebug("CarlaEngine::getPlugin(%i/%i)", id, maxPluginNumber);
  120. Q_ASSERT(maxPluginNumber != 0);
  121. Q_ASSERT(id < maxPluginNumber);
  122. if (id < maxPluginNumber)
  123. return m_carlaPlugins[id];
  124. return nullptr;
  125. }
  126. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned short id) const
  127. {
  128. Q_ASSERT(maxPluginNumber != 0);
  129. Q_ASSERT(id < maxPluginNumber);
  130. return m_carlaPlugins[id];
  131. }
  132. const char* CarlaEngine::getUniqueName(const char* const name)
  133. {
  134. qDebug("CarlaEngine::getUniqueName(\"%s\")", name);
  135. QString qname(name);
  136. if (qname.isEmpty())
  137. qname = "(No name)";
  138. qname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  139. qname.replace(":", "."); // ":" is used in JACK1 to split client/port names
  140. for (unsigned short i=0; i < maxPluginNumber; i++)
  141. {
  142. // Check if unique name already exists
  143. if (m_uniqueNames[i] && qname == m_uniqueNames[i])
  144. {
  145. // Check if string has already been modified
  146. uint len = qname.size();
  147. // 1 digit, ex: " (2)"
  148. if (qname.at(len-4) == QChar(' ') && qname.at(len-3) == QChar('(') && qname.at(len-2).isDigit() && qname.at(len-1) == QChar(')'))
  149. {
  150. int number = qname.at(len-2).toAscii()-'0';
  151. if (number == 9)
  152. // next number is 10, 2 digits
  153. qname.replace(" (9)", " (10)");
  154. else
  155. qname[len-2] = QChar('0'+number+1);
  156. continue;
  157. }
  158. // 2 digits, ex: " (11)"
  159. if (qname.at(len-5) == QChar(' ') && qname.at(len-4) == QChar('(') && qname.at(len-3).isDigit() && qname.at(len-2).isDigit() && qname.at(len-1) == QChar(')'))
  160. {
  161. QChar n2 = qname.at(len-2);
  162. QChar n3 = qname.at(len-3);
  163. if (n2 == QChar('9'))
  164. {
  165. n2 = QChar('0');
  166. n3 = QChar(n3.toAscii()+1);
  167. }
  168. else
  169. n2 = QChar(n2.toAscii()+1);
  170. qname[len-2] = n2;
  171. qname[len-3] = n3;
  172. continue;
  173. }
  174. // Modify string if not
  175. qname += " (2)";
  176. }
  177. }
  178. return strdup(qname.toUtf8().constData());
  179. }
  180. short CarlaEngine::addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  181. {
  182. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  183. }
  184. short CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  185. {
  186. qDebug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2str(btype), PluginType2str(ptype), filename, name, label, extra);
  187. Q_ASSERT(btype != BINARY_NONE);
  188. Q_ASSERT(ptype != PLUGIN_NONE);
  189. Q_ASSERT(filename);
  190. Q_ASSERT(label);
  191. if (maxPluginNumber == 0)
  192. #ifdef BUILD_BRIDGE
  193. maxPluginNumber = MAX_PLUGINS;
  194. #else
  195. maxPluginNumber = (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK) ? 16 : MAX_PLUGINS;
  196. #endif
  197. CarlaPlugin::initializer init = {
  198. this,
  199. filename,
  200. name,
  201. label
  202. };
  203. CarlaPlugin* plugin = nullptr;
  204. #ifndef BUILD_BRIDGE
  205. if (btype != BINARY_NATIVE)
  206. {
  207. # ifdef CARLA_ENGINE_JACK
  208. if (carlaOptions.processMode != CarlaBackend::PROCESS_MODE_MULTIPLE_CLIENTS)
  209. {
  210. setLastError("Can only use bridged plugins in JACK Multi-Client mode");
  211. return -1;
  212. }
  213. # endif
  214. if (type != CarlaEngineTypeJack)
  215. {
  216. setLastError("Can only use bridged plugins with JACK backend");
  217. return -1;
  218. }
  219. plugin = CarlaPlugin::newBridge(init, btype, ptype);
  220. }
  221. else
  222. #endif
  223. {
  224. switch (ptype)
  225. {
  226. case PLUGIN_NONE:
  227. break;
  228. case PLUGIN_LADSPA:
  229. plugin = CarlaPlugin::newLADSPA(init, extra);
  230. break;
  231. case PLUGIN_DSSI:
  232. plugin = CarlaPlugin::newDSSI(init, extra);
  233. break;
  234. case PLUGIN_LV2:
  235. plugin = CarlaPlugin::newLV2(init);
  236. break;
  237. case PLUGIN_VST:
  238. plugin = CarlaPlugin::newVST(init);
  239. break;
  240. #ifdef BUILD_BRIDGE
  241. case PLUGIN_GIG:
  242. case PLUGIN_SF2:
  243. case PLUGIN_SFZ:
  244. break;
  245. #else
  246. case PLUGIN_GIG:
  247. plugin = CarlaPlugin::newGIG(init);
  248. break;
  249. case PLUGIN_SF2:
  250. plugin = CarlaPlugin::newSF2(init);
  251. break;
  252. case PLUGIN_SFZ:
  253. plugin = CarlaPlugin::newSFZ(init);
  254. break;
  255. #endif
  256. }
  257. }
  258. if (! plugin)
  259. return -1;
  260. const short id = plugin->id();
  261. m_carlaPlugins[id] = plugin;
  262. m_uniqueNames[id] = plugin->name();
  263. if (! m_checkThread.isRunning())
  264. m_checkThread.startNow(maxPluginNumber);
  265. return id;
  266. }
  267. bool CarlaEngine::removePlugin(const unsigned short id)
  268. {
  269. qDebug("CarlaEngine::removePlugin(%i)", id);
  270. Q_ASSERT(maxPluginNumber != 0);
  271. Q_ASSERT(id < maxPluginNumber);
  272. CarlaPlugin* const plugin = m_carlaPlugins[id];
  273. if (plugin /*&& plugin->id() == id*/)
  274. {
  275. Q_ASSERT(plugin->id() == id);
  276. m_checkThread.stopNow();
  277. processLock();
  278. plugin->setEnabled(false);
  279. processUnlock();
  280. delete plugin;
  281. m_carlaPlugins[id] = nullptr;
  282. m_uniqueNames[id] = nullptr;
  283. #ifndef BUILD_BRIDGE
  284. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  285. {
  286. for (unsigned short i=id; i < maxPluginNumber-1; i++)
  287. {
  288. m_carlaPlugins[i] = m_carlaPlugins[i+1];
  289. m_uniqueNames[i] = m_uniqueNames[i+1];
  290. if (m_carlaPlugins[i])
  291. m_carlaPlugins[i]->setId(i);
  292. }
  293. }
  294. #endif
  295. if (isRunning())
  296. m_checkThread.startNow(maxPluginNumber);
  297. return true;
  298. }
  299. qCritical("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  300. setLastError("Could not find plugin to remove");
  301. return false;
  302. }
  303. void CarlaEngine::removeAllPlugins()
  304. {
  305. qDebug("CarlaEngine::removeAllPlugins()");
  306. m_checkThread.stopNow();
  307. for (unsigned short i=0; i < maxPluginNumber; i++)
  308. {
  309. CarlaPlugin* const plugin = m_carlaPlugins[i];
  310. if (plugin)
  311. {
  312. processLock();
  313. plugin->setEnabled(false);
  314. processUnlock();
  315. delete plugin;
  316. m_carlaPlugins[i] = nullptr;
  317. m_uniqueNames[i] = nullptr;
  318. }
  319. }
  320. maxPluginNumber = 0;
  321. }
  322. void CarlaEngine::idlePluginGuis()
  323. {
  324. Q_ASSERT(maxPluginNumber != 0);
  325. for (unsigned short i=0; i < maxPluginNumber; i++)
  326. {
  327. CarlaPlugin* const plugin = m_carlaPlugins[i];
  328. if (plugin && plugin->enabled())
  329. plugin->idleGui();
  330. }
  331. }
  332. // -----------------------------------------------------------------------
  333. // Information (base)
  334. const char* CarlaEngine::getName() const
  335. {
  336. Q_ASSERT(name);
  337. return name;
  338. }
  339. double CarlaEngine::getSampleRate() const
  340. {
  341. Q_ASSERT(sampleRate != 0.0);
  342. return sampleRate;
  343. }
  344. uint32_t CarlaEngine::getBufferSize() const
  345. {
  346. Q_ASSERT(bufferSize != 0);
  347. return bufferSize;
  348. }
  349. const CarlaTimeInfo* CarlaEngine::getTimeInfo() const
  350. {
  351. return &timeInfo;
  352. }
  353. // -----------------------------------------------------------------------
  354. // Information (audio peaks)
  355. double CarlaEngine::getInputPeak(const unsigned short pluginId, const unsigned short id) const
  356. {
  357. Q_ASSERT(pluginId < maxPluginNumber);
  358. Q_ASSERT(id < MAX_PEAKS);
  359. return m_insPeak[pluginId*MAX_PEAKS + id];
  360. }
  361. double CarlaEngine::getOutputPeak(const unsigned short pluginId, const unsigned short id) const
  362. {
  363. Q_ASSERT(pluginId < maxPluginNumber);
  364. Q_ASSERT(id < MAX_PEAKS);
  365. return m_outsPeak[pluginId*MAX_PEAKS + id];
  366. }
  367. void CarlaEngine::setInputPeak(const unsigned short pluginId, const unsigned short id, double value)
  368. {
  369. Q_ASSERT(pluginId < maxPluginNumber);
  370. Q_ASSERT(id < MAX_PEAKS);
  371. m_insPeak[pluginId*MAX_PEAKS + id] = value;
  372. }
  373. void CarlaEngine::setOutputPeak(const unsigned short pluginId, const unsigned short id, double value)
  374. {
  375. Q_ASSERT(pluginId < maxPluginNumber);
  376. Q_ASSERT(id < MAX_PEAKS);
  377. m_outsPeak[pluginId*MAX_PEAKS + id] = value;
  378. }
  379. // -----------------------------------------------------------------------
  380. // Callback
  381. void CarlaEngine::callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3)
  382. {
  383. qDebug("CarlaEngine::callback(%s, %i, %i, %i, %f)", CallbackType2str(action), pluginId, value1, value2, value3);
  384. if (m_callback)
  385. m_callback(m_callbackPtr, action, pluginId, value1, value2, value3);
  386. }
  387. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  388. {
  389. qDebug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  390. m_callback = func;
  391. m_callbackPtr = ptr;
  392. }
  393. // -----------------------------------------------------------------------
  394. // Mutex locks
  395. void CarlaEngine::processLock()
  396. {
  397. m_procLock.lock();
  398. }
  399. void CarlaEngine::processUnlock()
  400. {
  401. m_procLock.unlock();
  402. }
  403. void CarlaEngine::midiLock()
  404. {
  405. m_midiLock.lock();
  406. }
  407. void CarlaEngine::midiUnlock()
  408. {
  409. m_midiLock.unlock();
  410. }
  411. // -----------------------------------------------------------------------
  412. // OSC Stuff
  413. bool CarlaEngine::isOscControllerRegisted() const
  414. {
  415. #ifdef BUILD_BRIDGE
  416. return (bool)m_oscData;
  417. #else
  418. return m_osc.isControllerRegistered();
  419. #endif
  420. }
  421. #ifndef BUILD_BRIDGE
  422. const char* CarlaEngine::getOscServerPath() const
  423. {
  424. return m_osc.getServerPath();
  425. }
  426. #else
  427. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  428. {
  429. m_oscData = oscData;
  430. }
  431. #endif
  432. // -----------------------------------------------------------------------
  433. // protected calls
  434. void CarlaEngine::bufferSizeChanged(uint32_t newBufferSize)
  435. {
  436. qDebug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  437. bufferSize = newBufferSize;
  438. for (unsigned short i=0; i < maxPluginNumber; i++)
  439. {
  440. if (m_carlaPlugins[i] && m_carlaPlugins[i]->enabled())
  441. m_carlaPlugins[i]->bufferSizeChanged(newBufferSize);
  442. }
  443. }
  444. // -------------------------------------------------------------------------------------------------------------------
  445. // Carla Engine Client
  446. CarlaEngineClient::CarlaEngineClient(const CarlaEngineType& type_, const CarlaEngineClientNativeHandle& handle_)
  447. : type(type_),
  448. handle(handle_)
  449. {
  450. qDebug("CarlaEngineClient::CarlaEngineClient()");
  451. Q_ASSERT(type != CarlaEngineTypeNull);
  452. m_active = false;
  453. }
  454. CarlaEngineClient::~CarlaEngineClient()
  455. {
  456. qDebug("CarlaEngineClient::~CarlaEngineClient()");
  457. Q_ASSERT(! m_active);
  458. #ifndef BUILD_BRIDGE
  459. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  460. #endif
  461. {
  462. #ifdef CARLA_ENGINE_JACK
  463. if (handle.jackClient)
  464. jack_client_close(handle.jackClient);
  465. #endif
  466. #ifdef CARLA_ENGINE_RTAUDIO
  467. if (handle.rtAudioPtr)
  468. delete handle.rtAudioPtr;
  469. #endif
  470. }
  471. }
  472. void CarlaEngineClient::activate()
  473. {
  474. qDebug("CarlaEngineClient::activate()");
  475. Q_ASSERT(! m_active);
  476. #ifndef BUILD_BRIDGE
  477. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  478. #endif
  479. {
  480. if (! m_active)
  481. {
  482. #ifdef CARLA_ENGINE_JACK
  483. if (handle.jackClient)
  484. jack_activate(handle.jackClient);
  485. #endif
  486. #ifdef CARLA_ENGINE_RTAUDIO
  487. if (handle.rtAudioPtr)
  488. handle.rtAudioPtr->startStream();
  489. #endif
  490. }
  491. }
  492. m_active = true;
  493. }
  494. void CarlaEngineClient::deactivate()
  495. {
  496. qDebug("CarlaEngineClient::deactivate()");
  497. Q_ASSERT(m_active);
  498. #ifndef BUILD_BRIDGE
  499. if (carlaOptions.processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  500. #endif
  501. {
  502. if (m_active)
  503. {
  504. #ifdef CARLA_ENGINE_JACK
  505. if (handle.jackClient)
  506. jack_deactivate(handle.jackClient);
  507. #endif
  508. #ifdef CARLA_ENGINE_RTAUDIO
  509. if (handle.rtAudioPtr)
  510. handle.rtAudioPtr->stopStream();
  511. #endif
  512. }
  513. }
  514. m_active = false;
  515. }
  516. bool CarlaEngineClient::isActive() const
  517. {
  518. qDebug("CarlaEngineClient::isActive()");
  519. return m_active;
  520. }
  521. bool CarlaEngineClient::isOk() const
  522. {
  523. qDebug("CarlaEngineClient::isOk()");
  524. #ifndef BUILD_BRIDGE
  525. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  526. #endif
  527. {
  528. #ifdef CARLA_ENGINE_JACK
  529. return bool(handle.jackClient);
  530. // FIXME
  531. #endif
  532. }
  533. return true;
  534. }
  535. const CarlaEngineBasePort* CarlaEngineClient::addPort(const CarlaEnginePortType type, const char* const name, const bool isInput)
  536. {
  537. qDebug("CarlaEngineClient::addPort(%i, \"%s\", %s)", type, name, bool2str(isInput));
  538. CarlaEnginePortNativeHandle portHandle;
  539. #ifdef CARLA_ENGINE_JACK
  540. portHandle.jackClient = handle.jackClient;
  541. #endif
  542. #ifdef CARLA_ENGINE_JACK
  543. # ifndef BUILD_BRIDGE
  544. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  545. # endif
  546. {
  547. switch (type)
  548. {
  549. case CarlaEnginePortTypeAudio:
  550. portHandle.jackPort = jack_port_register(handle.jackClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  551. break;
  552. case CarlaEnginePortTypeControl:
  553. case CarlaEnginePortTypeMIDI:
  554. portHandle.jackPort = jack_port_register(handle.jackClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  555. break;
  556. }
  557. }
  558. #else
  559. Q_UNUSED(name);
  560. #endif
  561. switch (type)
  562. {
  563. case CarlaEnginePortTypeAudio:
  564. return new CarlaEngineAudioPort(portHandle, isInput);
  565. case CarlaEnginePortTypeControl:
  566. return new CarlaEngineControlPort(portHandle, isInput);
  567. case CarlaEnginePortTypeMIDI:
  568. return new CarlaEngineMidiPort(portHandle, isInput);
  569. }
  570. qCritical("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", type, name, bool2str(isInput));
  571. return nullptr;
  572. }
  573. // -------------------------------------------------------------------------------------------------------------------
  574. // Carla Engine Port (Base class)
  575. CarlaEngineBasePort::CarlaEngineBasePort(const CarlaEnginePortNativeHandle& handle_, const bool isInput_)
  576. : isInput(isInput_),
  577. handle(handle_)
  578. {
  579. qDebug("CarlaEngineBasePort::CarlaEngineBasePort(%s)", bool2str(isInput_));
  580. buffer = nullptr;
  581. }
  582. CarlaEngineBasePort::~CarlaEngineBasePort()
  583. {
  584. qDebug("CarlaEngineBasePort::~CarlaEngineBasePort()");
  585. #ifdef CARLA_ENGINE_JACK
  586. # ifndef BUILD_BRIDGE
  587. if (carlaOptions.processMode != PROCESS_MODE_CONTINUOUS_RACK)
  588. # endif
  589. {
  590. if (handle.jackClient && handle.jackPort)
  591. jack_port_unregister(handle.jackClient, handle.jackPort);
  592. }
  593. #endif
  594. }
  595. // -------------------------------------------------------------------------------------------------------------------
  596. // Carla Engine Port (Audio)
  597. CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  598. : CarlaEngineBasePort(handle, isInput)
  599. {
  600. qDebug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInput));
  601. }
  602. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const /*engine*/)
  603. {
  604. }
  605. #ifdef CARLA_ENGINE_JACK
  606. float* CarlaEngineAudioPort::getJackAudioBuffer(uint32_t nframes)
  607. {
  608. # ifndef BUILD_BRIDGE
  609. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  610. return nullptr;
  611. # endif
  612. Q_ASSERT(handle.jackPort);
  613. return (float*)jack_port_get_buffer(handle.jackPort, nframes);
  614. }
  615. #endif
  616. // -------------------------------------------------------------------------------------------------------------------
  617. // Carla Engine Port (Control)
  618. CarlaEngineControlPort::CarlaEngineControlPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  619. : CarlaEngineBasePort(handle, isInput)
  620. {
  621. qDebug("CarlaEngineControlPort::CarlaEngineControlPort(%s)", bool2str(isInput));
  622. }
  623. void CarlaEngineControlPort::initBuffer(CarlaEngine* const engine)
  624. {
  625. Q_ASSERT(engine);
  626. #ifndef BUILD_BRIDGE
  627. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  628. {
  629. buffer = isInput ? engine->rackControlEventsIn : engine->rackControlEventsOut;
  630. return;
  631. }
  632. #endif
  633. #ifdef CARLA_ENGINE_JACK
  634. if (handle.jackPort)
  635. {
  636. buffer = jack_port_get_buffer(handle.jackPort, engine->getBufferSize());
  637. if (! isInput)
  638. jack_midi_clear_buffer(buffer);
  639. }
  640. #endif
  641. }
  642. uint32_t CarlaEngineControlPort::getEventCount()
  643. {
  644. if (! isInput)
  645. return 0;
  646. Q_ASSERT(buffer);
  647. #ifndef BUILD_BRIDGE
  648. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  649. {
  650. uint32_t count = 0;
  651. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  652. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  653. {
  654. if (events[i].type != CarlaEngineEventNull)
  655. count++;
  656. else
  657. break;
  658. }
  659. return count;
  660. }
  661. #endif
  662. #ifdef CARLA_ENGINE_JACK
  663. return jack_midi_get_event_count(buffer);
  664. #else
  665. return 0;
  666. #endif
  667. }
  668. const CarlaEngineControlEvent* CarlaEngineControlPort::getEvent(uint32_t index)
  669. {
  670. if (! isInput)
  671. return nullptr;
  672. Q_ASSERT(buffer);
  673. #ifndef BUILD_BRIDGE
  674. Q_ASSERT(index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS);
  675. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  676. {
  677. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  678. if (index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS)
  679. return &events[index];
  680. return nullptr;
  681. }
  682. #endif
  683. #ifdef CARLA_ENGINE_JACK
  684. static jack_midi_event_t jackEvent;
  685. static CarlaEngineControlEvent carlaEvent;
  686. if (jack_midi_event_get(&jackEvent, buffer, index) != 0)
  687. return nullptr;
  688. memset(&carlaEvent, 0, sizeof(CarlaEngineControlEvent));
  689. uint8_t midiStatus = jackEvent.buffer[0];
  690. uint8_t midiChannel = midiStatus & 0x0F;
  691. carlaEvent.time = jackEvent.time;
  692. carlaEvent.channel = midiChannel;
  693. if (MIDI_IS_STATUS_CONTROL_CHANGE(midiStatus))
  694. {
  695. uint8_t midiControl = jackEvent.buffer[1];
  696. if (MIDI_IS_CONTROL_BANK_SELECT(midiControl))
  697. {
  698. uint8_t midiBank = jackEvent.buffer[2];
  699. carlaEvent.type = CarlaEngineEventMidiBankChange;
  700. carlaEvent.value = midiBank;
  701. }
  702. else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF)
  703. {
  704. carlaEvent.type = CarlaEngineEventAllSoundOff;
  705. }
  706. else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF)
  707. {
  708. carlaEvent.type = CarlaEngineEventAllNotesOff;
  709. }
  710. else
  711. {
  712. uint8_t midiValue = jackEvent.buffer[2];
  713. carlaEvent.type = CarlaEngineEventControlChange;
  714. carlaEvent.controller = midiControl;
  715. carlaEvent.value = double(midiValue)/127;
  716. }
  717. return &carlaEvent;
  718. }
  719. else if (MIDI_IS_STATUS_PROGRAM_CHANGE(midiStatus))
  720. {
  721. uint8_t midiProgram = jackEvent.buffer[1];
  722. carlaEvent.type = CarlaEngineEventMidiProgramChange;
  723. carlaEvent.value = midiProgram;
  724. return &carlaEvent;
  725. }
  726. #endif
  727. return nullptr;
  728. }
  729. void CarlaEngineControlPort::writeEvent(CarlaEngineControlEventType type, uint32_t time, uint8_t channel, uint8_t controller, double value)
  730. {
  731. if (isInput)
  732. return;
  733. Q_ASSERT(buffer);
  734. Q_ASSERT(type != CarlaEngineEventNull);
  735. #ifndef BUILD_BRIDGE
  736. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  737. {
  738. CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  739. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  740. {
  741. if (events[i].type == CarlaEngineEventNull)
  742. {
  743. events[i].type = type;
  744. events[i].time = time;
  745. events[i].value = value;
  746. events[i].channel = channel;
  747. events[i].controller = controller;
  748. break;
  749. }
  750. }
  751. return;
  752. }
  753. #endif
  754. #ifdef CARLA_ENGINE_JACK
  755. if (type == CarlaEngineEventControlChange && MIDI_IS_CONTROL_BANK_SELECT(controller))
  756. type = CarlaEngineEventMidiBankChange;
  757. uint8_t data[4] = { 0 };
  758. switch (type)
  759. {
  760. case CarlaEngineEventNull:
  761. break;
  762. case CarlaEngineEventControlChange:
  763. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  764. data[1] = controller;
  765. data[2] = value * 127;
  766. jack_midi_event_write(buffer, time, data, 3);
  767. break;
  768. case CarlaEngineEventMidiBankChange:
  769. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  770. data[1] = MIDI_CONTROL_BANK_SELECT;
  771. data[2] = value;
  772. jack_midi_event_write(buffer, time, data, 3);
  773. break;
  774. case CarlaEngineEventMidiProgramChange:
  775. data[0] = MIDI_STATUS_PROGRAM_CHANGE + channel;
  776. data[1] = value;
  777. jack_midi_event_write(buffer, time, data, 2);
  778. break;
  779. case CarlaEngineEventAllSoundOff:
  780. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  781. data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  782. jack_midi_event_write(buffer, time, data, 2);
  783. break;
  784. case CarlaEngineEventAllNotesOff:
  785. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  786. data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  787. jack_midi_event_write(buffer, time, data, 2);
  788. break;
  789. }
  790. #endif
  791. }
  792. // -------------------------------------------------------------------------------------------------------------------
  793. // Carla Engine Port (MIDI)
  794. CarlaEngineMidiPort::CarlaEngineMidiPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  795. : CarlaEngineBasePort(handle, isInput)
  796. {
  797. qDebug("CarlaEngineMidiPort::CarlaEngineMidiPort(%s)", bool2str(isInput));
  798. }
  799. void CarlaEngineMidiPort::initBuffer(CarlaEngine* const engine)
  800. {
  801. Q_ASSERT(engine);
  802. #ifndef BUILD_BRIDGE
  803. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  804. {
  805. buffer = isInput ? engine->rackMidiEventsIn : engine->rackMidiEventsOut;
  806. return;
  807. }
  808. #endif
  809. #ifdef CARLA_ENGINE_JACK
  810. if (handle.jackPort)
  811. {
  812. buffer = jack_port_get_buffer(handle.jackPort, engine->getBufferSize());
  813. if (! isInput)
  814. jack_midi_clear_buffer(buffer);
  815. }
  816. #endif
  817. }
  818. uint32_t CarlaEngineMidiPort::getEventCount()
  819. {
  820. if (! isInput)
  821. return 0;
  822. Q_ASSERT(buffer);
  823. #ifndef BUILD_BRIDGE
  824. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  825. {
  826. uint32_t count = 0;
  827. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  828. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  829. {
  830. if (events[i].size > 0)
  831. count++;
  832. else
  833. break;
  834. }
  835. return count;
  836. }
  837. #endif
  838. #ifdef CARLA_ENGINE_JACK
  839. return jack_midi_get_event_count(buffer);
  840. #else
  841. return 0;
  842. #endif
  843. }
  844. const CarlaEngineMidiEvent* CarlaEngineMidiPort::getEvent(uint32_t index)
  845. {
  846. if (! isInput)
  847. return nullptr;
  848. Q_ASSERT(buffer);
  849. #ifndef BUILD_BRIDGE
  850. Q_ASSERT(index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS);
  851. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  852. {
  853. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  854. if (index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS)
  855. return &events[index];
  856. return nullptr;
  857. }
  858. #endif
  859. #ifdef CARLA_ENGINE_JACK
  860. static jack_midi_event_t jackEvent;
  861. static CarlaEngineMidiEvent carlaEvent;
  862. if (jack_midi_event_get(&jackEvent, buffer, index) == 0 && jackEvent.size <= 4)
  863. {
  864. carlaEvent.time = jackEvent.time;
  865. carlaEvent.size = jackEvent.size;
  866. memcpy(carlaEvent.data, jackEvent.buffer, jackEvent.size);
  867. return &carlaEvent;
  868. }
  869. #endif
  870. return nullptr;
  871. }
  872. void CarlaEngineMidiPort::writeEvent(uint32_t time, const uint8_t* data, uint8_t size)
  873. {
  874. if (isInput)
  875. return;
  876. Q_ASSERT(buffer);
  877. Q_ASSERT(data);
  878. Q_ASSERT(size > 0);
  879. #ifndef BUILD_BRIDGE
  880. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  881. {
  882. if (size > 4)
  883. return;
  884. CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  885. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  886. {
  887. if (events[i].size == 0)
  888. {
  889. events[i].time = time;
  890. events[i].size = size;
  891. memcpy(events[i].data, data, size);
  892. break;
  893. }
  894. }
  895. return;
  896. }
  897. #endif
  898. #ifdef CARLA_ENGINE_JACK
  899. jack_midi_event_write(buffer, time, data, size);
  900. #endif
  901. }
  902. // -------------------------------------------------------------------------------------------------------------------
  903. // Carla Engine OSC stuff
  904. #ifndef BUILD_BRIDGE
  905. void CarlaEngine::osc_send_add_plugin(const int32_t pluginId, const char* const pluginName)
  906. {
  907. qDebug("CarlaEngine::osc_send_add_plugin(%i, \"%s\")", pluginId, pluginName);
  908. Q_ASSERT(m_oscData);
  909. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  910. Q_ASSERT(pluginName);
  911. if (m_oscData && m_oscData->target)
  912. {
  913. char target_path[strlen(m_oscData->path)+12];
  914. strcpy(target_path, m_oscData->path);
  915. strcat(target_path, "/add_plugin");
  916. lo_send(m_oscData->target, target_path, "is", pluginId, pluginName);
  917. }
  918. }
  919. void CarlaEngine::osc_send_remove_plugin(const int32_t pluginId)
  920. {
  921. qDebug("CarlaEngine::osc_send_remove_plugin(%i)", pluginId);
  922. Q_ASSERT(m_oscData);
  923. if (m_oscData && m_oscData->target)
  924. {
  925. char target_path[strlen(m_oscData->path)+15];
  926. strcpy(target_path, m_oscData->path);
  927. strcat(target_path, "/remove_plugin");
  928. lo_send(m_oscData->target, target_path, "i", pluginId);
  929. }
  930. }
  931. void CarlaEngine::osc_send_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)
  932. {
  933. qDebug("CarlaEngine::osc_send_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", %li)", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  934. Q_ASSERT(m_oscData);
  935. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  936. Q_ASSERT(type != PLUGIN_NONE);
  937. if (m_oscData && m_oscData->target)
  938. {
  939. char target_path[strlen(m_oscData->path)+17];
  940. strcpy(target_path, m_oscData->path);
  941. strcat(target_path, "/set_plugin_data");
  942. lo_send(m_oscData->target, target_path, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  943. }
  944. }
  945. void CarlaEngine::osc_send_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)
  946. {
  947. qDebug("CarlaEngine::osc_send_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  948. Q_ASSERT(m_oscData);
  949. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  950. if (m_oscData && m_oscData->target)
  951. {
  952. char target_path[strlen(m_oscData->path)+18];
  953. strcpy(target_path, m_oscData->path);
  954. strcat(target_path, "/set_plugin_ports");
  955. lo_send(m_oscData->target, target_path, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  956. }
  957. }
  958. void CarlaEngine::osc_send_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)
  959. {
  960. qDebug("CarlaEngine::osc_send_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  961. Q_ASSERT(m_oscData);
  962. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  963. Q_ASSERT(index >= 0);
  964. Q_ASSERT(type != PARAMETER_UNKNOWN);
  965. if (m_oscData && m_oscData->target)
  966. {
  967. char target_path[strlen(m_oscData->path)+20];
  968. strcpy(target_path, m_oscData->path);
  969. strcat(target_path, "/set_parameter_data");
  970. lo_send(m_oscData->target, target_path, "iiiissd", pluginId, index, type, hints, name, label, current);
  971. }
  972. }
  973. void CarlaEngine::osc_send_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)
  974. {
  975. qDebug("CarlaEngine::osc_send_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  976. Q_ASSERT(m_oscData);
  977. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  978. Q_ASSERT(index >= 0);
  979. Q_ASSERT(min < max);
  980. if (m_oscData && m_oscData->target)
  981. {
  982. char target_path[strlen(m_oscData->path)+22];
  983. strcpy(target_path, m_oscData->path);
  984. strcat(target_path, "/set_parameter_ranges");
  985. lo_send(m_oscData->target, target_path, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  986. }
  987. }
  988. void CarlaEngine::osc_send_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  989. {
  990. qDebug("CarlaEngine::osc_send_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  991. Q_ASSERT(m_oscData);
  992. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  993. Q_ASSERT(index >= 0);
  994. if (m_oscData && m_oscData->target)
  995. {
  996. char target_path[strlen(m_oscData->path)+23];
  997. strcpy(target_path, m_oscData->path);
  998. strcat(target_path, "/set_parameter_midi_cc");
  999. lo_send(m_oscData->target, target_path, "iii", pluginId, index, cc);
  1000. }
  1001. }
  1002. void CarlaEngine::osc_send_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1003. {
  1004. qDebug("CarlaEngine::osc_send_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1005. Q_ASSERT(m_oscData);
  1006. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1007. Q_ASSERT(index >= 0);
  1008. Q_ASSERT(channel >= 0 && channel < 16);
  1009. if (m_oscData && m_oscData->target)
  1010. {
  1011. char target_path[strlen(m_oscData->path)+28];
  1012. strcpy(target_path, m_oscData->path);
  1013. strcat(target_path, "/set_parameter_midi_channel");
  1014. lo_send(m_oscData->target, target_path, "iii", pluginId, index, channel);
  1015. }
  1016. }
  1017. void CarlaEngine::osc_send_set_parameter_value(const int32_t pluginId, const int32_t index, const double value)
  1018. {
  1019. #if DEBUG
  1020. if (index < 0)
  1021. qDebug("CarlaEngine::osc_send_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2str((InternalParametersIndex)index), value);
  1022. else
  1023. qDebug("CarlaEngine::osc_send_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1024. #endif
  1025. Q_ASSERT(m_oscData);
  1026. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1027. if (m_oscData && m_oscData->target)
  1028. {
  1029. char target_path[strlen(m_oscData->path)+21];
  1030. strcpy(target_path, m_oscData->path);
  1031. strcat(target_path, "/set_parameter_value");
  1032. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1033. }
  1034. }
  1035. void CarlaEngine::osc_send_set_default_value(const int32_t pluginId, const int32_t index, const double value)
  1036. {
  1037. qDebug("CarlaEngine::osc_send_set_default_value(%i, %i, %g)", pluginId, index, value);
  1038. Q_ASSERT(m_oscData);
  1039. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1040. Q_ASSERT(index >= 0);
  1041. if (m_oscData && m_oscData->target)
  1042. {
  1043. char target_path[strlen(m_oscData->path)+19];
  1044. strcpy(target_path, m_oscData->path);
  1045. strcat(target_path, "/set_default_value");
  1046. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1047. }
  1048. }
  1049. void CarlaEngine::osc_send_set_program(const int32_t pluginId, const int32_t index)
  1050. {
  1051. qDebug("CarlaEngine::osc_send_set_program(%i, %i)", pluginId, index);
  1052. Q_ASSERT(m_oscData);
  1053. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1054. if (m_oscData && m_oscData->target)
  1055. {
  1056. char target_path[strlen(m_oscData->path)+13];
  1057. strcpy(target_path, m_oscData->path);
  1058. strcat(target_path, "/set_program");
  1059. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1060. }
  1061. }
  1062. void CarlaEngine::osc_send_set_program_count(const int32_t pluginId, const int32_t count)
  1063. {
  1064. qDebug("CarlaEngine::osc_send_set_program_count(%i, %i)", pluginId, count);
  1065. Q_ASSERT(m_oscData);
  1066. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1067. Q_ASSERT(count >= 0);
  1068. if (m_oscData && m_oscData->target)
  1069. {
  1070. char target_path[strlen(m_oscData->path)+19];
  1071. strcpy(target_path, m_oscData->path);
  1072. strcat(target_path, "/set_program_count");
  1073. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1074. }
  1075. }
  1076. void CarlaEngine::osc_send_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1077. {
  1078. qDebug("CarlaEngine::osc_send_set_program_name(%i, %i, %s)", pluginId, index, name);
  1079. Q_ASSERT(m_oscData);
  1080. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1081. Q_ASSERT(index >= 0);
  1082. Q_ASSERT(name);
  1083. if (m_oscData && m_oscData->target)
  1084. {
  1085. char target_path[strlen(m_oscData->path)+18];
  1086. strcpy(target_path, m_oscData->path);
  1087. strcat(target_path, "/set_program_name");
  1088. lo_send(m_oscData->target, target_path, "iis", pluginId, index, name);
  1089. }
  1090. }
  1091. void CarlaEngine::osc_send_set_midi_program(const int32_t pluginId, const int32_t index)
  1092. {
  1093. qDebug("CarlaEngine::osc_send_set_midi_program(%i, %i)", pluginId, index);
  1094. Q_ASSERT(m_oscData);
  1095. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1096. if (m_oscData && m_oscData->target)
  1097. {
  1098. char target_path[strlen(m_oscData->path)+18];
  1099. strcpy(target_path, m_oscData->path);
  1100. strcat(target_path, "/set_midi_program");
  1101. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1102. }
  1103. }
  1104. void CarlaEngine::osc_send_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1105. {
  1106. qDebug("CarlaEngine::osc_send_set_midi_program_count(%i, %i)", pluginId, count);
  1107. Q_ASSERT(m_oscData);
  1108. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1109. Q_ASSERT(count >= 0);
  1110. if (m_oscData && m_oscData->target)
  1111. {
  1112. char target_path[strlen(m_oscData->path)+24];
  1113. strcpy(target_path, m_oscData->path);
  1114. strcat(target_path, "/set_midi_program_count");
  1115. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1116. }
  1117. }
  1118. void CarlaEngine::osc_send_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name)
  1119. {
  1120. qDebug("CarlaEngine::osc_send_set_midi_program_data(%i, %i, %i, %i, %s)", pluginId, index, bank, program, name);
  1121. Q_ASSERT(m_oscData);
  1122. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1123. Q_ASSERT(index >= 0);
  1124. Q_ASSERT(bank >= 0);
  1125. Q_ASSERT(program >= 0);
  1126. Q_ASSERT(name);
  1127. if (m_oscData && m_oscData->target)
  1128. {
  1129. char target_path[strlen(m_oscData->path)+23];
  1130. strcpy(target_path, m_oscData->path);
  1131. strcat(target_path, "/set_midi_program_data");
  1132. lo_send(m_oscData->target, target_path, "iiiis", pluginId, index, bank, program, name);
  1133. }
  1134. }
  1135. void CarlaEngine::osc_send_set_input_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1136. {
  1137. qDebug("CarlaEngine::osc_send_set_input_peak_value(%i, %i, %g)", pluginId, portId, value);
  1138. Q_ASSERT(m_oscData);
  1139. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1140. Q_ASSERT(portId == 1 || portId == 2);
  1141. if (m_oscData && m_oscData->target)
  1142. {
  1143. char target_path[strlen(m_oscData->path)+22];
  1144. strcpy(target_path, m_oscData->path);
  1145. strcat(target_path, "/set_input_peak_value");
  1146. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1147. }
  1148. }
  1149. void CarlaEngine::osc_send_set_output_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1150. {
  1151. qDebug("CarlaEngine::osc_send_set_output_peak_value(%i, %i, %g)", pluginId, portId, value);
  1152. Q_ASSERT(m_oscData);
  1153. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1154. Q_ASSERT(portId == 1 || portId == 2);
  1155. if (m_oscData && m_oscData->target)
  1156. {
  1157. char target_path[strlen(m_oscData->path)+23];
  1158. strcpy(target_path, m_oscData->path);
  1159. strcat(target_path, "/set_output_peak_value");
  1160. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1161. }
  1162. }
  1163. void CarlaEngine::osc_send_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1164. {
  1165. qDebug("CarlaEngine::osc_send_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1166. Q_ASSERT(m_oscData);
  1167. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1168. Q_ASSERT(channel >= 0 && channel < 16);
  1169. Q_ASSERT(note >= 0 && note < 128);
  1170. Q_ASSERT(velo >= 0 && velo < 128);
  1171. if (m_oscData && m_oscData->target)
  1172. {
  1173. char target_path[strlen(m_oscData->path)+9];
  1174. strcpy(target_path, m_oscData->path);
  1175. strcat(target_path, "/note_on");
  1176. lo_send(m_oscData->target, target_path, "iiii", pluginId, channel, note, velo);
  1177. }
  1178. }
  1179. void CarlaEngine::osc_send_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1180. {
  1181. qDebug("CarlaEngine::osc_send_note_off(%i, %i, %i)", pluginId, channel, note);
  1182. Q_ASSERT(m_oscData);
  1183. Q_ASSERT(pluginId >= 0 && pluginId < maxPluginNumber);
  1184. Q_ASSERT(channel >= 0 && channel < 16);
  1185. Q_ASSERT(note >= 0 && note < 128);
  1186. if (m_oscData && m_oscData->target)
  1187. {
  1188. char target_path[strlen(m_oscData->path)+10];
  1189. strcpy(target_path, m_oscData->path);
  1190. strcat(target_path, "/note_off");
  1191. lo_send(m_oscData->target, target_path, "iii", pluginId, channel, note);
  1192. }
  1193. }
  1194. void CarlaEngine::osc_send_exit()
  1195. {
  1196. qDebug("CarlaEngine::osc_send_exit()");
  1197. Q_ASSERT(m_oscData);
  1198. if (m_oscData && m_oscData->target)
  1199. {
  1200. char target_path[strlen(m_oscData->path)+6];
  1201. strcpy(target_path, m_oscData->path);
  1202. strcat(target_path, "/exit");
  1203. lo_send(m_oscData->target, target_path, "");
  1204. }
  1205. }
  1206. #endif
  1207. CARLA_BACKEND_END_NAMESPACE