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.

1427 lines
49KB

  1. /*
  2. * Carla LADSPA Plugin
  3. * Copyright (C) 2011-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 "CarlaPluginInternal.hpp"
  18. #ifdef WANT_LADSPA
  19. #include "CarlaLadspaUtils.hpp"
  20. CARLA_BACKEND_START_NAMESPACE
  21. class LadspaPlugin : public CarlaPlugin
  22. {
  23. public:
  24. LadspaPlugin(CarlaEngine* const engine, const unsigned int id)
  25. : CarlaPlugin(engine, id),
  26. fHandle(nullptr),
  27. fHandle2(nullptr),
  28. fDescriptor(nullptr),
  29. fRdfDescriptor(nullptr),
  30. fAudioInBuffers(nullptr),
  31. fAudioOutBuffers(nullptr),
  32. fParamBuffers(nullptr)
  33. {
  34. carla_debug("LadspaPlugin::LadspaPlugin(%p, %i)", engine, id);
  35. }
  36. ~LadspaPlugin()
  37. {
  38. carla_debug("LadspaPlugin::~LadspaPlugin()");
  39. if (fDescriptor != nullptr)
  40. {
  41. if (fDescriptor->deactivate != nullptr && kData->activeBefore)
  42. {
  43. if (fHandle != nullptr)
  44. fDescriptor->deactivate(fHandle);
  45. if (fHandle2 != nullptr)
  46. fDescriptor->deactivate(fHandle2);
  47. }
  48. if (fDescriptor->cleanup != nullptr)
  49. {
  50. if (fHandle != nullptr)
  51. fDescriptor->cleanup(fHandle);
  52. if (fHandle2 != nullptr)
  53. fDescriptor->cleanup(fHandle2);
  54. }
  55. fHandle = nullptr;
  56. fHandle2 = nullptr;
  57. fDescriptor = nullptr;
  58. }
  59. if (fRdfDescriptor != nullptr)
  60. {
  61. delete fRdfDescriptor;
  62. fRdfDescriptor = nullptr;
  63. }
  64. deleteBuffers();
  65. }
  66. // -------------------------------------------------------------------
  67. // Information (base)
  68. PluginType type() const
  69. {
  70. return PLUGIN_LADSPA;
  71. }
  72. PluginCategory category() const
  73. {
  74. if (fRdfDescriptor != nullptr)
  75. {
  76. const LADSPA_PluginType category = fRdfDescriptor->Type;
  77. // Specific Types
  78. if (category & (LADSPA_PLUGIN_DELAY|LADSPA_PLUGIN_REVERB))
  79. return PLUGIN_CATEGORY_DELAY;
  80. if (category & (LADSPA_PLUGIN_PHASER|LADSPA_PLUGIN_FLANGER|LADSPA_PLUGIN_CHORUS))
  81. return PLUGIN_CATEGORY_MODULATOR;
  82. if (category & (LADSPA_PLUGIN_AMPLIFIER))
  83. return PLUGIN_CATEGORY_DYNAMICS;
  84. if (category & (LADSPA_PLUGIN_UTILITY|LADSPA_PLUGIN_SPECTRAL|LADSPA_PLUGIN_FREQUENCY_METER))
  85. return PLUGIN_CATEGORY_UTILITY;
  86. // Pre-set LADSPA Types
  87. if (LADSPA_IS_PLUGIN_DYNAMICS(category))
  88. return PLUGIN_CATEGORY_DYNAMICS;
  89. if (LADSPA_IS_PLUGIN_AMPLITUDE(category))
  90. return PLUGIN_CATEGORY_MODULATOR;
  91. if (LADSPA_IS_PLUGIN_EQ(category))
  92. return PLUGIN_CATEGORY_EQ;
  93. if (LADSPA_IS_PLUGIN_FILTER(category))
  94. return PLUGIN_CATEGORY_FILTER;
  95. if (LADSPA_IS_PLUGIN_FREQUENCY(category))
  96. return PLUGIN_CATEGORY_UTILITY;
  97. if (LADSPA_IS_PLUGIN_SIMULATOR(category))
  98. return PLUGIN_CATEGORY_OTHER;
  99. if (LADSPA_IS_PLUGIN_TIME(category))
  100. return PLUGIN_CATEGORY_DELAY;
  101. if (LADSPA_IS_PLUGIN_GENERATOR(category))
  102. return PLUGIN_CATEGORY_SYNTH;
  103. }
  104. return getPluginCategoryFromName(fName);
  105. }
  106. long uniqueId() const
  107. {
  108. CARLA_ASSERT(fDescriptor != nullptr);
  109. return (fDescriptor != nullptr) ? static_cast<long>(fDescriptor->UniqueID) : 0;
  110. }
  111. // -------------------------------------------------------------------
  112. // Information (count)
  113. uint32_t parameterScalePointCount(const uint32_t parameterId) const
  114. {
  115. CARLA_ASSERT(parameterId < kData->param.count);
  116. const int32_t rindex = kData->param.data[parameterId].rindex;
  117. if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
  118. {
  119. const LADSPA_RDF_Port& port = fRdfDescriptor->Ports[rindex];
  120. return static_cast<uint32_t>(port.ScalePointCount);
  121. }
  122. return 0;
  123. }
  124. // -------------------------------------------------------------------
  125. // Information (per-plugin data)
  126. unsigned int availableOptions()
  127. {
  128. const bool isDssiVst = fFilename.contains("dssi-vst", true);
  129. unsigned int options = 0x0;
  130. if (! isDssiVst)
  131. options |= PLUGIN_OPTION_FIXED_BUFFER;
  132. //if ((kData->audioIns.count() == 1 || kData->audioOuts.count() == 0) || (kData->audioIns.count() == 0 || kData->audioOuts.count() == 1))
  133. // options |= PLUGIN_OPTION_FORCE_STEREO;
  134. return options;
  135. }
  136. float getParameterValue(const uint32_t parameterId)
  137. {
  138. CARLA_ASSERT(parameterId < kData->param.count);
  139. return fParamBuffers[parameterId];
  140. }
  141. float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId)
  142. {
  143. CARLA_ASSERT(fRdfDescriptor != nullptr);
  144. CARLA_ASSERT(parameterId < kData->param.count);
  145. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  146. const int32_t rindex = kData->param.data[parameterId].rindex;
  147. if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
  148. {
  149. const LADSPA_RDF_Port& port = fRdfDescriptor->Ports[rindex];
  150. if (scalePointId < port.ScalePointCount)
  151. {
  152. const LADSPA_RDF_ScalePoint& scalePoint = port.ScalePoints[scalePointId];
  153. return scalePoint.Value;
  154. }
  155. }
  156. return 0.0f;
  157. }
  158. void getLabel(char* const strBuf)
  159. {
  160. CARLA_ASSERT(fDescriptor != nullptr);
  161. if (fDescriptor != nullptr && fDescriptor->Label != nullptr)
  162. std::strncpy(strBuf, fDescriptor->Label, STR_MAX);
  163. else
  164. CarlaPlugin::getLabel(strBuf);
  165. }
  166. void getMaker(char* const strBuf)
  167. {
  168. CARLA_ASSERT(fDescriptor != nullptr);
  169. if (fRdfDescriptor != nullptr && fRdfDescriptor->Creator != nullptr)
  170. std::strncpy(strBuf, fRdfDescriptor->Creator, STR_MAX);
  171. else if (fDescriptor != nullptr && fDescriptor->Maker != nullptr)
  172. std::strncpy(strBuf, fDescriptor->Maker, STR_MAX);
  173. else
  174. CarlaPlugin::getMaker(strBuf);
  175. }
  176. void getCopyright(char* const strBuf)
  177. {
  178. CARLA_ASSERT(fDescriptor != nullptr);
  179. if (fDescriptor != nullptr && fDescriptor->Copyright != nullptr)
  180. std::strncpy(strBuf, fDescriptor->Copyright, STR_MAX);
  181. else
  182. CarlaPlugin::getCopyright(strBuf);
  183. }
  184. void getRealName(char* const strBuf)
  185. {
  186. CARLA_ASSERT(fDescriptor != nullptr);
  187. if (fRdfDescriptor != nullptr && fRdfDescriptor->Title != nullptr)
  188. std::strncpy(strBuf, fRdfDescriptor->Title, STR_MAX);
  189. else if (fDescriptor != nullptr && fDescriptor->Name != nullptr)
  190. std::strncpy(strBuf, fDescriptor->Name, STR_MAX);
  191. else
  192. CarlaPlugin::getRealName(strBuf);
  193. }
  194. void getParameterName(const uint32_t parameterId, char* const strBuf)
  195. {
  196. CARLA_ASSERT(fDescriptor != nullptr);
  197. CARLA_ASSERT(parameterId < kData->param.count);
  198. const int32_t rindex = kData->param.data[parameterId].rindex;
  199. if (fDescriptor != nullptr && rindex < static_cast<int32_t>(fDescriptor->PortCount))
  200. std::strncpy(strBuf, fDescriptor->PortNames[rindex], STR_MAX);
  201. else
  202. CarlaPlugin::getParameterName(parameterId, strBuf);
  203. }
  204. void getParameterSymbol(const uint32_t parameterId, char* const strBuf)
  205. {
  206. CARLA_ASSERT(parameterId < kData->param.count);
  207. const int32_t rindex = kData->param.data[parameterId].rindex;
  208. if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
  209. {
  210. const LADSPA_RDF_Port& port = fRdfDescriptor->Ports[rindex];
  211. if (LADSPA_PORT_HAS_LABEL(port.Hints) && port.Label != nullptr)
  212. {
  213. std::strncpy(strBuf, port.Label, STR_MAX);
  214. return;
  215. }
  216. }
  217. CarlaPlugin::getParameterSymbol(parameterId, strBuf);
  218. }
  219. void getParameterUnit(const uint32_t parameterId, char* const strBuf)
  220. {
  221. CARLA_ASSERT(parameterId < kData->param.count);
  222. const int32_t rindex = kData->param.data[parameterId].rindex;
  223. if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
  224. {
  225. const LADSPA_RDF_Port& port = fRdfDescriptor->Ports[rindex];
  226. if (LADSPA_PORT_HAS_UNIT(port.Hints))
  227. {
  228. switch (port.Unit)
  229. {
  230. case LADSPA_UNIT_DB:
  231. std::strncpy(strBuf, "dB", STR_MAX);
  232. return;
  233. case LADSPA_UNIT_COEF:
  234. std::strncpy(strBuf, "(coef)", STR_MAX);
  235. return;
  236. case LADSPA_UNIT_HZ:
  237. std::strncpy(strBuf, "Hz", STR_MAX);
  238. return;
  239. case LADSPA_UNIT_S:
  240. std::strncpy(strBuf, "s", STR_MAX);
  241. return;
  242. case LADSPA_UNIT_MS:
  243. std::strncpy(strBuf, "ms", STR_MAX);
  244. return;
  245. case LADSPA_UNIT_MIN:
  246. std::strncpy(strBuf, "min", STR_MAX);
  247. return;
  248. }
  249. }
  250. }
  251. CarlaPlugin::getParameterUnit(parameterId, strBuf);
  252. }
  253. void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf)
  254. {
  255. CARLA_ASSERT(fRdfDescriptor != nullptr);
  256. CARLA_ASSERT(parameterId < kData->param.count);
  257. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  258. const int32_t rindex = kData->param.data[parameterId].rindex;
  259. if (fRdfDescriptor != nullptr && rindex < static_cast<int32_t>(fRdfDescriptor->PortCount))
  260. {
  261. const LADSPA_RDF_Port& port = fRdfDescriptor->Ports[rindex];
  262. if (scalePointId < port.ScalePointCount)
  263. {
  264. const LADSPA_RDF_ScalePoint& scalePoint = port.ScalePoints[scalePointId];
  265. if (scalePoint.Label != nullptr)
  266. {
  267. std::strncpy(strBuf, scalePoint.Label, STR_MAX);
  268. return;
  269. }
  270. }
  271. }
  272. CarlaPlugin::getParameterScalePointLabel(parameterId, scalePointId, strBuf);
  273. }
  274. // -------------------------------------------------------------------
  275. // Set data (plugin-specific stuff)
  276. void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  277. {
  278. CARLA_ASSERT(parameterId < kData->param.count);
  279. const float fixedValue = kData->param.fixValue(parameterId, value);
  280. fParamBuffers[parameterId] = fixedValue;
  281. CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback);
  282. }
  283. // -------------------------------------------------------------------
  284. // Plugin state
  285. void reload()
  286. {
  287. carla_debug("LadspaPlugin::reload() - start");
  288. CARLA_ASSERT(kData->engine != nullptr);
  289. CARLA_ASSERT(fDescriptor != nullptr);
  290. CARLA_ASSERT(fHandle != nullptr);
  291. const ProcessMode processMode(kData->engine->getProccessMode());
  292. // Safely disable plugin for reload
  293. const ScopedDisabler sd(this);
  294. deleteBuffers();
  295. const float sampleRate = (float)kData->engine->getSampleRate();
  296. const uint32_t portCount = static_cast<uint32_t>(fDescriptor->PortCount);
  297. uint32_t aIns, aOuts, params, j;
  298. aIns = aOuts = params = 0;
  299. bool forcedStereoIn, forcedStereoOut;
  300. forcedStereoIn = forcedStereoOut = false;
  301. bool needsCtrlIn, needsCtrlOut;
  302. needsCtrlIn = needsCtrlOut = false;
  303. if (portCount > 0)
  304. {
  305. CARLA_ASSERT(fDescriptor->PortDescriptors != nullptr);
  306. CARLA_ASSERT(fDescriptor->PortRangeHints != nullptr);
  307. CARLA_ASSERT(fDescriptor->PortNames != nullptr);
  308. for (uint32_t i=0; i < portCount; i++)
  309. {
  310. const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i];
  311. if (LADSPA_IS_PORT_AUDIO(portType))
  312. {
  313. if (LADSPA_IS_PORT_INPUT(portType))
  314. aIns += 1;
  315. else if (LADSPA_IS_PORT_OUTPUT(portType))
  316. aOuts += 1;
  317. }
  318. else if (LADSPA_IS_PORT_CONTROL(portType))
  319. params += 1;
  320. }
  321. }
  322. if ((fOptions & PLUGIN_OPTION_FORCE_STEREO) != 0 && (aIns == 1 || aOuts == 1))
  323. {
  324. if (fHandle2 == nullptr)
  325. fHandle2 = fDescriptor->instantiate(fDescriptor, (unsigned long)sampleRate);
  326. if (aIns == 1)
  327. {
  328. aIns = 2;
  329. forcedStereoIn = true;
  330. }
  331. if (aOuts == 1)
  332. {
  333. aOuts = 2;
  334. forcedStereoOut = true;
  335. }
  336. }
  337. if (aIns > 0)
  338. {
  339. kData->audioIn.createNew(aIns);
  340. fAudioInBuffers = new float*[aIns];
  341. for (uint32_t i=0; i < aIns; i++)
  342. fAudioInBuffers[i] = nullptr;
  343. }
  344. if (aOuts > 0)
  345. {
  346. kData->audioOut.createNew(aOuts);
  347. fAudioOutBuffers = new float*[aOuts];
  348. needsCtrlIn = true;
  349. for (uint32_t i=0; i < aOuts; i++)
  350. fAudioOutBuffers[i] = nullptr;
  351. }
  352. if (params > 0)
  353. {
  354. kData->param.createNew(params);
  355. fParamBuffers = new float[params];
  356. for (uint32_t i=0; i < params; i++)
  357. fParamBuffers[i] = 0.0f;
  358. }
  359. const uint portNameSize = kData->engine->maxPortNameSize();
  360. CarlaString portName;
  361. for (uint32_t i=0, iAudioIn=0, iAudioOut=0, iCtrl=0; i < portCount; i++)
  362. {
  363. const LADSPA_PortDescriptor portType = fDescriptor->PortDescriptors[i];
  364. const LADSPA_PortRangeHint portRangeHints = fDescriptor->PortRangeHints[i];
  365. const bool hasPortRDF = (fRdfDescriptor != nullptr && i < fRdfDescriptor->PortCount);
  366. CARLA_ASSERT(fDescriptor->PortNames[i] != nullptr);
  367. if (LADSPA_IS_PORT_AUDIO(portType))
  368. {
  369. portName.clear();
  370. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  371. {
  372. portName = fName;
  373. portName += ":";
  374. }
  375. portName += fDescriptor->PortNames[i];
  376. portName.truncate(portNameSize);
  377. if (LADSPA_IS_PORT_INPUT(portType))
  378. {
  379. j = iAudioIn++;
  380. kData->audioIn.ports[j].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, true);
  381. kData->audioIn.ports[j].rindex = i;
  382. if (forcedStereoIn)
  383. {
  384. portName += "_2";
  385. kData->audioIn.ports[1].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, true);
  386. kData->audioIn.ports[1].rindex = i;
  387. }
  388. }
  389. else if (LADSPA_IS_PORT_OUTPUT(portType))
  390. {
  391. j = iAudioOut++;
  392. kData->audioOut.ports[j].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, false);
  393. kData->audioOut.ports[j].rindex = i;
  394. if (forcedStereoOut)
  395. {
  396. portName += "_2";
  397. kData->audioOut.ports[1].port = (CarlaEngineAudioPort*)kData->client->addPort(kEnginePortTypeAudio, portName, false);
  398. kData->audioOut.ports[1].rindex = i;
  399. }
  400. }
  401. else
  402. carla_stderr2("WARNING - Got a broken Port (Audio, but not input or output)");
  403. }
  404. else if (LADSPA_IS_PORT_CONTROL(portType))
  405. {
  406. j = iCtrl++;
  407. kData->param.data[j].index = j;
  408. kData->param.data[j].rindex = i;
  409. kData->param.data[j].hints = 0x0;
  410. kData->param.data[j].midiChannel = 0;
  411. kData->param.data[j].midiCC = -1;
  412. float min, max, def, step, stepSmall, stepLarge;
  413. // min value
  414. if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
  415. min = portRangeHints.LowerBound;
  416. else
  417. min = 0.0f;
  418. // max value
  419. if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
  420. max = portRangeHints.UpperBound;
  421. else
  422. max = 1.0f;
  423. if (min > max)
  424. max = min;
  425. else if (max < min)
  426. min = max;
  427. if (max - min == 0.0f)
  428. {
  429. carla_stderr2("WARNING - Broken plugin parameter '%s': max - min == 0.0f", fDescriptor->PortNames[i]);
  430. max = min + 0.1f;
  431. }
  432. // default value
  433. if (hasPortRDF && LADSPA_PORT_HAS_DEFAULT(fRdfDescriptor->Ports[i].Hints))
  434. def = fRdfDescriptor->Ports[i].Default;
  435. else
  436. def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
  437. if (def < min)
  438. def = min;
  439. else if (def > max)
  440. def = max;
  441. if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
  442. {
  443. min *= sampleRate;
  444. max *= sampleRate;
  445. def *= sampleRate;
  446. kData->param.data[j].hints |= PARAMETER_USES_SAMPLERATE;
  447. }
  448. if (LADSPA_IS_HINT_TOGGLED(portRangeHints.HintDescriptor))
  449. {
  450. step = max - min;
  451. stepSmall = step;
  452. stepLarge = step;
  453. kData->param.data[j].hints |= PARAMETER_IS_BOOLEAN;
  454. }
  455. else if (LADSPA_IS_HINT_INTEGER(portRangeHints.HintDescriptor))
  456. {
  457. step = 1.0f;
  458. stepSmall = 1.0f;
  459. stepLarge = 10.0f;
  460. kData->param.data[j].hints |= PARAMETER_IS_INTEGER;
  461. }
  462. else
  463. {
  464. float range = max - min;
  465. step = range/100.0f;
  466. stepSmall = range/1000.0f;
  467. stepLarge = range/10.0f;
  468. }
  469. if (LADSPA_IS_PORT_INPUT(portType))
  470. {
  471. kData->param.data[j].type = PARAMETER_INPUT;
  472. kData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  473. kData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  474. needsCtrlIn = true;
  475. }
  476. else if (LADSPA_IS_PORT_OUTPUT(portType))
  477. {
  478. if (std::strcmp(fDescriptor->PortNames[i], "latency") == 0 || std::strcmp(fDescriptor->PortNames[i], "_latency") == 0)
  479. {
  480. min = 0.0f;
  481. max = sampleRate;
  482. def = 0.0f;
  483. step = 1.0f;
  484. stepSmall = 1.0f;
  485. stepLarge = 1.0f;
  486. kData->param.data[j].type = PARAMETER_LATENCY;
  487. kData->param.data[j].hints = 0;
  488. }
  489. else if (std::strcmp(fDescriptor->PortNames[i], "_sample-rate") == 0)
  490. {
  491. def = sampleRate;
  492. step = 1.0f;
  493. stepSmall = 1.0f;
  494. stepLarge = 1.0f;
  495. kData->param.data[j].type = PARAMETER_SAMPLE_RATE;
  496. kData->param.data[j].hints = 0;
  497. }
  498. else
  499. {
  500. kData->param.data[j].type = PARAMETER_OUTPUT;
  501. kData->param.data[j].hints |= PARAMETER_IS_ENABLED;
  502. kData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE;
  503. needsCtrlOut = true;
  504. }
  505. }
  506. else
  507. {
  508. kData->param.data[j].type = PARAMETER_UNKNOWN;
  509. carla_stderr2("WARNING - Got a broken Port (Control, but not input or output)");
  510. }
  511. // extra parameter hints
  512. if (LADSPA_IS_HINT_LOGARITHMIC(portRangeHints.HintDescriptor))
  513. kData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC;
  514. // check for scalepoints, require at least 2 to make it useful
  515. if (hasPortRDF && fRdfDescriptor->Ports[i].ScalePointCount > 1)
  516. kData->param.data[j].hints |= PARAMETER_USES_SCALEPOINTS;
  517. kData->param.ranges[j].min = min;
  518. kData->param.ranges[j].max = max;
  519. kData->param.ranges[j].def = def;
  520. kData->param.ranges[j].step = step;
  521. kData->param.ranges[j].stepSmall = stepSmall;
  522. kData->param.ranges[j].stepLarge = stepLarge;
  523. // Start parameters in their default values
  524. fParamBuffers[j] = def;
  525. fDescriptor->connect_port(fHandle, i, &fParamBuffers[j]);
  526. if (fHandle2 != nullptr)
  527. fDescriptor->connect_port(fHandle2, i, &fParamBuffers[j]);
  528. }
  529. else
  530. {
  531. // Not Audio or Control
  532. carla_stderr2("ERROR - Got a broken Port (neither Audio or Control)");
  533. fDescriptor->connect_port(fHandle, i, nullptr);
  534. if (fHandle2 != nullptr)
  535. fDescriptor->connect_port(fHandle2, i, nullptr);
  536. }
  537. }
  538. if (needsCtrlIn)
  539. {
  540. portName.clear();
  541. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  542. {
  543. portName = fName;
  544. portName += ":";
  545. }
  546. portName += "event-in";
  547. portName.truncate(portNameSize);
  548. kData->event.portIn = (CarlaEngineEventPort*)kData->client->addPort(kEnginePortTypeEvent, portName, true);
  549. }
  550. if (needsCtrlOut)
  551. {
  552. portName.clear();
  553. if (processMode == PROCESS_MODE_SINGLE_CLIENT)
  554. {
  555. portName = fName;
  556. portName += ":";
  557. }
  558. portName += "event-out";
  559. portName.truncate(portNameSize);
  560. kData->event.portOut = (CarlaEngineEventPort*)kData->client->addPort(kEnginePortTypeEvent, portName, false);
  561. }
  562. // plugin hints
  563. fHints = 0x0;
  564. if (aOuts > 0 && (aIns == aOuts || aIns == 1))
  565. fHints |= PLUGIN_CAN_DRYWET;
  566. if (aOuts > 0)
  567. fHints |= PLUGIN_CAN_VOLUME;
  568. if (aOuts >= 2 && aOuts % 2 == 0)
  569. fHints |= PLUGIN_CAN_BALANCE;
  570. // extra plugin hints
  571. kData->extraHints = 0x0;
  572. if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0))
  573. kData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK;
  574. // plugin options
  575. fOptions = 0x0;
  576. if (forcedStereoIn || forcedStereoOut)
  577. fOptions |= PLUGIN_OPTION_FORCE_STEREO;
  578. // check latency
  579. if (fHints & PLUGIN_CAN_DRYWET)
  580. {
  581. for (uint32_t i=0; i < kData->param.count; i++)
  582. {
  583. if (kData->param.data[i].type != PARAMETER_LATENCY)
  584. continue;
  585. // we need to pre-run the plugin so it can update its latency control-port
  586. float tmpIn[aIns][2];
  587. float tmpOut[aOuts][2];
  588. for (j=0; j < aIns; j++)
  589. {
  590. tmpIn[j][0] = 0.0f;
  591. tmpIn[j][1] = 0.0f;
  592. fDescriptor->connect_port(fHandle, kData->audioIn.ports[j].rindex, tmpIn[j]);
  593. }
  594. for (j=0; j < aOuts; j++)
  595. {
  596. tmpOut[j][0] = 0.0f;
  597. tmpOut[j][1] = 0.0f;
  598. fDescriptor->connect_port(fHandle, kData->audioOut.ports[j].rindex, tmpOut[j]);
  599. }
  600. if (fDescriptor->activate != nullptr)
  601. fDescriptor->activate(fHandle);
  602. fDescriptor->run(fHandle, 2);
  603. if (fDescriptor->deactivate != nullptr)
  604. fDescriptor->deactivate(fHandle);
  605. const uint32_t latency = (uint32_t)fParamBuffers[i];
  606. if (kData->latency != latency)
  607. {
  608. kData->latency = latency;
  609. kData->client->setLatency(latency);
  610. recreateLatencyBuffers();
  611. }
  612. break;
  613. }
  614. }
  615. bufferSizeChanged(kData->engine->getBufferSize());
  616. carla_debug("LadspaPlugin::reload() - end");
  617. }
  618. // -------------------------------------------------------------------
  619. // Plugin processing
  620. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames)
  621. {
  622. uint32_t i, k;
  623. // --------------------------------------------------------------------------------------------------------
  624. // Check if active
  625. if (! kData->active)
  626. {
  627. // disable any output sound
  628. for (i=0; i < kData->audioOut.count; i++)
  629. carla_zeroFloat(outBuffer[i], frames);
  630. if (kData->activeBefore)
  631. {
  632. if (fDescriptor->deactivate != nullptr)
  633. {
  634. fDescriptor->deactivate(fHandle);
  635. if (fHandle2 != nullptr)
  636. fDescriptor->deactivate(fHandle2);
  637. }
  638. }
  639. kData->activeBefore = kData->active;
  640. return;
  641. }
  642. // --------------------------------------------------------------------------------------------------------
  643. // Check if not active before
  644. if (kData->needsReset || ! kData->activeBefore)
  645. {
  646. if (kData->latency > 0)
  647. {
  648. for (i=0; i < kData->audioIn.count; i++)
  649. carla_zeroFloat(kData->latencyBuffers[i], kData->latency);
  650. }
  651. if (kData->activeBefore)
  652. {
  653. if (fDescriptor->deactivate != nullptr)
  654. {
  655. fDescriptor->deactivate(fHandle);
  656. if (fHandle2 != nullptr)
  657. fDescriptor->deactivate(fHandle2);
  658. }
  659. }
  660. if (fDescriptor->activate != nullptr)
  661. {
  662. fDescriptor->activate(fHandle);
  663. if (fHandle2 != nullptr)
  664. fDescriptor->activate(fHandle2);
  665. }
  666. kData->needsReset = false;
  667. }
  668. // --------------------------------------------------------------------------------------------------------
  669. // Event Input and Processing
  670. if (kData->event.portIn != nullptr && kData->activeBefore)
  671. {
  672. // ----------------------------------------------------------------------------------------------------
  673. // Event Input (System)
  674. bool sampleAccurate = (fOptions & PLUGIN_OPTION_FIXED_BUFFER) == 0;
  675. uint32_t time, nEvents = kData->event.portIn->getEventCount();
  676. uint32_t timeOffset = 0;
  677. for (i=0; i < nEvents; i++)
  678. {
  679. const EngineEvent& event = kData->event.portIn->getEvent(i);
  680. time = event.time;
  681. if (time >= frames)
  682. continue;
  683. CARLA_ASSERT_INT2(time >= timeOffset, time, timeOffset);
  684. if (time > timeOffset && sampleAccurate)
  685. {
  686. if (processSingle(inBuffer, outBuffer, time - timeOffset, timeOffset))
  687. timeOffset = time;
  688. }
  689. // Control change
  690. switch (event.type)
  691. {
  692. case kEngineEventTypeNull:
  693. break;
  694. case kEngineEventTypeControl:
  695. {
  696. const EngineControlEvent& ctrlEvent = event.ctrl;
  697. switch (ctrlEvent.type)
  698. {
  699. case kEngineControlEventTypeNull:
  700. break;
  701. case kEngineControlEventTypeParameter:
  702. {
  703. // Control backend stuff
  704. if (event.channel == kData->ctrlChannel)
  705. {
  706. float value;
  707. if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (fHints & PLUGIN_CAN_DRYWET) > 0)
  708. {
  709. value = ctrlEvent.value;
  710. setDryWet(value, false, false);
  711. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value);
  712. continue;
  713. }
  714. if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (fHints & PLUGIN_CAN_VOLUME) > 0)
  715. {
  716. value = ctrlEvent.value*127.0f/100.0f;
  717. setVolume(value, false, false);
  718. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value);
  719. continue;
  720. }
  721. if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (fHints & PLUGIN_CAN_BALANCE) > 0)
  722. {
  723. float left, right;
  724. value = ctrlEvent.value/0.5f - 1.0f;
  725. if (value < 0.0f)
  726. {
  727. left = -1.0f;
  728. right = (value*2.0f)+1.0f;
  729. }
  730. else if (value > 0.0f)
  731. {
  732. left = (value*2.0f)-1.0f;
  733. right = 1.0f;
  734. }
  735. else
  736. {
  737. left = -1.0f;
  738. right = 1.0f;
  739. }
  740. setBalanceLeft(left, false, false);
  741. setBalanceRight(right, false, false);
  742. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left);
  743. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right);
  744. continue;
  745. }
  746. }
  747. // Control plugin parameters
  748. for (k=0; k < kData->param.count; k++)
  749. {
  750. if (kData->param.data[k].midiChannel != event.channel)
  751. continue;
  752. if (kData->param.data[k].midiCC != ctrlEvent.param)
  753. continue;
  754. if (kData->param.data[k].type != PARAMETER_INPUT)
  755. continue;
  756. if ((kData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0)
  757. continue;
  758. float value;
  759. if (kData->param.data[k].hints & PARAMETER_IS_BOOLEAN)
  760. {
  761. value = (ctrlEvent.value < 0.5f) ? kData->param.ranges[k].min : kData->param.ranges[k].max;
  762. }
  763. else
  764. {
  765. value = kData->param.ranges[i].unnormalizeValue(ctrlEvent.value);
  766. if (kData->param.data[k].hints & PARAMETER_IS_INTEGER)
  767. value = std::rint(value);
  768. }
  769. setParameterValue(k, value, false, false, false);
  770. postponeRtEvent(kPluginPostRtEventParameterChange, static_cast<int32_t>(k), 0, value);
  771. }
  772. break;
  773. }
  774. case kEngineControlEventTypeMidiBank:
  775. case kEngineControlEventTypeMidiProgram:
  776. break;
  777. case kEngineControlEventTypeAllSoundOff:
  778. if (event.channel == kData->ctrlChannel)
  779. {
  780. if (fDescriptor->deactivate != nullptr)
  781. {
  782. fDescriptor->deactivate(fHandle);
  783. if (fHandle2 != nullptr)
  784. fDescriptor->deactivate(fHandle2);
  785. }
  786. if (fDescriptor->activate != nullptr)
  787. {
  788. fDescriptor->activate(fHandle);
  789. if (fHandle2 != nullptr)
  790. fDescriptor->activate(fHandle2);
  791. }
  792. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_ACTIVE, 0, 0.0);
  793. postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_ACTIVE, 0, 1.0);
  794. }
  795. break;
  796. case kEngineControlEventTypeAllNotesOff:
  797. break;
  798. }
  799. break;
  800. }
  801. case kEngineEventTypeMidi:
  802. // ignored in LADSPA
  803. break;
  804. }
  805. }
  806. kData->postRtEvents.trySplice();
  807. if (frames > timeOffset)
  808. processSingle(inBuffer, outBuffer, frames - timeOffset, timeOffset);
  809. } // End of Event Input and Processing
  810. // --------------------------------------------------------------------------------------------------------
  811. // Plugin processing (no events)
  812. else
  813. {
  814. processSingle(inBuffer, outBuffer, frames, 0);
  815. } // End of Plugin processing (no events)
  816. // --------------------------------------------------------------------------------------------------------
  817. // Special Parameters
  818. #if 0
  819. CARLA_PROCESS_CONTINUE_CHECK;
  820. for (k=0; k < param.count; k++)
  821. {
  822. if (param.data[k].type == PARAMETER_LATENCY)
  823. {
  824. // TODO
  825. }
  826. }
  827. CARLA_PROCESS_CONTINUE_CHECK;
  828. #endif
  829. CARLA_PROCESS_CONTINUE_CHECK;
  830. // --------------------------------------------------------------------------------------------------------
  831. // Control Output
  832. if (kData->event.portOut != nullptr)
  833. {
  834. uint8_t channel;
  835. uint16_t param;
  836. float value;
  837. for (k=0; k < kData->param.count; k++)
  838. {
  839. if (kData->param.data[k].type != PARAMETER_OUTPUT)
  840. continue;
  841. kData->param.ranges[k].fixValue(fParamBuffers[k]);
  842. if (kData->param.data[k].midiCC > 0)
  843. {
  844. channel = kData->param.data[k].midiChannel;
  845. param = static_cast<uint16_t>(kData->param.data[k].midiCC);
  846. value = kData->param.ranges[k].normalizeValue(fParamBuffers[k]);
  847. kData->event.portOut->writeControlEvent(0, channel, kEngineControlEventTypeParameter, param, value);
  848. }
  849. }
  850. } // End of Control Output
  851. // --------------------------------------------------------------------------------------------------------
  852. kData->activeBefore = kData->active;
  853. }
  854. bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset)
  855. {
  856. uint32_t i, k;
  857. // --------------------------------------------------------------------------------------------------------
  858. // Try lock, silence otherwise
  859. if (kData->engine->isOffline())
  860. {
  861. kData->mutex.lock();
  862. }
  863. else if (! kData->mutex.tryLock())
  864. {
  865. for (i=0; i < kData->audioOut.count; i++)
  866. {
  867. for (k=0; k < frames; k++)
  868. outBuffer[i][k+timeOffset] = 0.0f;
  869. }
  870. return false;
  871. }
  872. // --------------------------------------------------------------------------------------------------------
  873. // Fill plugin buffers
  874. for (i=0; i < kData->audioIn.count; i++)
  875. carla_copyFloat(fAudioInBuffers[i], inBuffer[i]+timeOffset, frames);
  876. for (i=0; i < kData->audioOut.count; i++)
  877. carla_zeroFloat(fAudioOutBuffers[i], frames);
  878. // --------------------------------------------------------------------------------------------------------
  879. // Run plugin
  880. fDescriptor->run(fHandle, frames);
  881. if (fHandle2 != nullptr)
  882. fDescriptor->run(fHandle2, frames);
  883. // --------------------------------------------------------------------------------------------------------
  884. // Post-processing (dry/wet, volume and balance)
  885. {
  886. const bool doDryWet = (fHints & PLUGIN_CAN_DRYWET) > 0 && kData->postProc.dryWet != 1.0f;
  887. const bool doBalance = (fHints & PLUGIN_CAN_BALANCE) > 0 && (kData->postProc.balanceLeft != -1.0f || kData->postProc.balanceRight != 1.0f);
  888. float bufValue, oldBufLeft[doBalance ? frames : 1];
  889. for (i=0; i < kData->audioOut.count; i++)
  890. {
  891. // Dry/Wet
  892. if (doDryWet)
  893. {
  894. for (k=0; k < frames; k++)
  895. {
  896. // TODO
  897. //if (k < kData->latency && kData->latency < frames)
  898. // bufValue = (kData->audioIn.count == 1) ? kData->latencyBuffers[0][k] : kData->latencyBuffers[i][k];
  899. //else
  900. // bufValue = (kData->audioIn.count == 1) ? inBuffer[0][k-m_latency] : inBuffer[i][k-m_latency];
  901. bufValue = fAudioInBuffers[(kData->audioIn.count == 1) ? 0 : i][k];
  902. fAudioOutBuffers[i][k] = (fAudioOutBuffers[i][k] * kData->postProc.dryWet) + (bufValue * (1.0f - kData->postProc.dryWet));
  903. }
  904. }
  905. // Balance
  906. if (doBalance)
  907. {
  908. if (i % 2 == 0)
  909. carla_copyFloat(oldBufLeft, fAudioOutBuffers[i], frames);
  910. float balRangeL = (kData->postProc.balanceLeft + 1.0f)/2.0f;
  911. float balRangeR = (kData->postProc.balanceRight + 1.0f)/2.0f;
  912. for (k=0; k < frames; k++)
  913. {
  914. if (i % 2 == 0)
  915. {
  916. // left
  917. fAudioOutBuffers[i][k] = oldBufLeft[k] * (1.0f - balRangeL);
  918. fAudioOutBuffers[i][k] += fAudioOutBuffers[i+1][k] * (1.0f - balRangeR);
  919. }
  920. else
  921. {
  922. // right
  923. fAudioOutBuffers[i][k] = fAudioOutBuffers[i][k] * balRangeR;
  924. fAudioOutBuffers[i][k] += oldBufLeft[k] * balRangeL;
  925. }
  926. }
  927. }
  928. // Volume (and buffer copy)
  929. {
  930. for (k=0; k < frames; k++)
  931. outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k] * kData->postProc.volume;
  932. }
  933. }
  934. #if 0
  935. // Latency, save values for next callback, TODO
  936. if (kData->latency > 0 && kData->latency < frames)
  937. {
  938. for (i=0; i < kData->audioIn.count; i++)
  939. carla_copyFloat(kData->latencyBuffers[i], inBuffer[i] + (frames - kData->latency), kData->latency);
  940. }
  941. #endif
  942. } // End of Post-processing
  943. // --------------------------------------------------------------------------------------------------------
  944. kData->mutex.unlock();
  945. return true;
  946. }
  947. void bufferSizeChanged(const uint32_t newBufferSize)
  948. {
  949. carla_debug("LadspaPlugin::bufferSizeChanged(%i) - start", newBufferSize);
  950. for (uint32_t i=0; i < kData->audioIn.count; i++)
  951. {
  952. if (fAudioInBuffers[i] != nullptr)
  953. delete[] fAudioInBuffers[i];
  954. fAudioInBuffers[i] = new float[newBufferSize];
  955. }
  956. for (uint32_t i=0; i < kData->audioOut.count; i++)
  957. {
  958. if (fAudioOutBuffers[i] != nullptr)
  959. delete[] fAudioOutBuffers[i];
  960. fAudioOutBuffers[i] = new float[newBufferSize];
  961. }
  962. if (fHandle2 == nullptr)
  963. {
  964. for (uint32_t i=0; i < kData->audioIn.count; i++)
  965. {
  966. CARLA_ASSERT(fAudioInBuffers[i] != nullptr);
  967. fDescriptor->connect_port(fHandle, kData->audioIn.ports[i].rindex, fAudioInBuffers[i]);
  968. }
  969. for (uint32_t i=0; i < kData->audioOut.count; i++)
  970. {
  971. CARLA_ASSERT(fAudioOutBuffers[i] != nullptr);
  972. fDescriptor->connect_port(fHandle, kData->audioOut.ports[i].rindex, fAudioOutBuffers[i]);
  973. }
  974. }
  975. else
  976. {
  977. if (kData->audioIn.count > 0)
  978. {
  979. CARLA_ASSERT(kData->audioIn.count == 2);
  980. CARLA_ASSERT(fAudioInBuffers[0] != nullptr);
  981. CARLA_ASSERT(fAudioInBuffers[1] != nullptr);
  982. fDescriptor->connect_port(fHandle, kData->audioIn.ports[0].rindex, fAudioInBuffers[0]);
  983. fDescriptor->connect_port(fHandle2, kData->audioIn.ports[1].rindex, fAudioInBuffers[1]);
  984. }
  985. if (kData->audioOut.count > 0)
  986. {
  987. CARLA_ASSERT(kData->audioOut.count == 2);
  988. CARLA_ASSERT(fAudioOutBuffers[0] != nullptr);
  989. CARLA_ASSERT(fAudioOutBuffers[1] != nullptr);
  990. fDescriptor->connect_port(fHandle, kData->audioOut.ports[0].rindex, fAudioOutBuffers[0]);
  991. fDescriptor->connect_port(fHandle2, kData->audioOut.ports[1].rindex, fAudioOutBuffers[1]);
  992. }
  993. }
  994. carla_debug("LadspaPlugin::bufferSizeChanged(%i) - end", newBufferSize);
  995. }
  996. // -------------------------------------------------------------------
  997. // Cleanup
  998. void deleteBuffers()
  999. {
  1000. carla_debug("LadspaPlugin::deleteBuffers() - start");
  1001. if (fAudioInBuffers != nullptr)
  1002. {
  1003. for (uint32_t i=0; i < kData->audioIn.count; i++)
  1004. {
  1005. if (fAudioInBuffers[i] != nullptr)
  1006. {
  1007. delete[] fAudioInBuffers[i];
  1008. fAudioInBuffers[i] = nullptr;
  1009. }
  1010. }
  1011. delete[] fAudioInBuffers;
  1012. fAudioInBuffers = nullptr;
  1013. }
  1014. if (fAudioOutBuffers != nullptr)
  1015. {
  1016. for (uint32_t i=0; i < kData->audioOut.count; i++)
  1017. {
  1018. if (fAudioOutBuffers[i] != nullptr)
  1019. {
  1020. delete[] fAudioOutBuffers[i];
  1021. fAudioOutBuffers[i] = nullptr;
  1022. }
  1023. }
  1024. delete[] fAudioOutBuffers;
  1025. fAudioOutBuffers = nullptr;
  1026. }
  1027. if (fParamBuffers != nullptr)
  1028. {
  1029. delete[] fParamBuffers;
  1030. fParamBuffers = nullptr;
  1031. }
  1032. CarlaPlugin::deleteBuffers();
  1033. carla_debug("LadspaPlugin::deleteBuffers() - end");
  1034. }
  1035. // -------------------------------------------------------------------
  1036. bool init(const char* const filename, const char* const name, const char* const label, const LADSPA_RDF_Descriptor* const rdfDescriptor)
  1037. {
  1038. CARLA_ASSERT(kData->engine != nullptr);
  1039. CARLA_ASSERT(kData->client == nullptr);
  1040. CARLA_ASSERT(filename != nullptr);
  1041. CARLA_ASSERT(label != nullptr);
  1042. // ---------------------------------------------------------------
  1043. // open DLL
  1044. if (! libOpen(filename))
  1045. {
  1046. kData->engine->setLastError(libError(filename));
  1047. return false;
  1048. }
  1049. // ---------------------------------------------------------------
  1050. // get DLL main entry
  1051. const LADSPA_Descriptor_Function descFn = (LADSPA_Descriptor_Function)libSymbol("ladspa_descriptor");
  1052. if (descFn == nullptr)
  1053. {
  1054. kData->engine->setLastError("Could not find the LASDPA Descriptor in the plugin library");
  1055. return false;
  1056. }
  1057. // ---------------------------------------------------------------
  1058. // get descriptor that matches label
  1059. unsigned long i = 0;
  1060. while ((fDescriptor = descFn(i++)) != nullptr)
  1061. {
  1062. if (fDescriptor->Label != nullptr && std::strcmp(fDescriptor->Label, label) == 0)
  1063. break;
  1064. }
  1065. if (fDescriptor == nullptr)
  1066. {
  1067. kData->engine->setLastError("Could not find the requested plugin label in the plugin library");
  1068. return false;
  1069. }
  1070. // ---------------------------------------------------------------
  1071. // get info
  1072. if (is_ladspa_rdf_descriptor_valid(rdfDescriptor, fDescriptor))
  1073. fRdfDescriptor = ladspa_rdf_dup(rdfDescriptor);
  1074. if (name != nullptr)
  1075. fName = kData->engine->getNewUniquePluginName(name);
  1076. else if (fRdfDescriptor != nullptr && fRdfDescriptor->Title != nullptr)
  1077. fName = kData->engine->getNewUniquePluginName(fRdfDescriptor->Title);
  1078. else if (fDescriptor->Name != nullptr)
  1079. fName = kData->engine->getNewUniquePluginName(fDescriptor->Name);
  1080. else
  1081. fName = kData->engine->getNewUniquePluginName(fDescriptor->Label);
  1082. fFilename = filename;
  1083. // ---------------------------------------------------------------
  1084. // register client
  1085. kData->client = kData->engine->addClient(this);
  1086. if (kData->client == nullptr || ! kData->client->isOk())
  1087. {
  1088. kData->engine->setLastError("Failed to register plugin client");
  1089. return false;
  1090. }
  1091. // ---------------------------------------------------------------
  1092. // initialize plugin
  1093. fHandle = fDescriptor->instantiate(fDescriptor, (unsigned long)kData->engine->getSampleRate());
  1094. if (fHandle == nullptr)
  1095. {
  1096. kData->engine->setLastError("Plugin failed to initialize");
  1097. return false;
  1098. }
  1099. return true;
  1100. }
  1101. private:
  1102. LADSPA_Handle fHandle;
  1103. LADSPA_Handle fHandle2;
  1104. const LADSPA_Descriptor* fDescriptor;
  1105. const LADSPA_RDF_Descriptor* fRdfDescriptor;
  1106. float** fAudioInBuffers;
  1107. float** fAudioOutBuffers;
  1108. float* fParamBuffers;
  1109. };
  1110. CARLA_BACKEND_END_NAMESPACE
  1111. #else // WANT_LADSPA
  1112. # warning Building without LADSPA support
  1113. #endif
  1114. CARLA_BACKEND_START_NAMESPACE
  1115. CarlaPlugin* CarlaPlugin::newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* const rdfDescriptor)
  1116. {
  1117. carla_debug("CarlaPlugin::newLADSPA({%p, \"%s\", \"%s\", \"%s\"}, %p)", init.engine, init.filename, init.name, init.label, rdfDescriptor);
  1118. #ifdef WANT_LADSPA
  1119. LadspaPlugin* const plugin = new LadspaPlugin(init.engine, init.id);
  1120. if (! plugin->init(init.filename, init.name, init.label, rdfDescriptor))
  1121. {
  1122. delete plugin;
  1123. return nullptr;
  1124. }
  1125. plugin->reload();
  1126. if (init.engine->getProccessMode() == PROCESS_MODE_CONTINUOUS_RACK && ! CarlaPluginProtectedData::canRunInRack(plugin))
  1127. {
  1128. init.engine->setLastError("Carla's rack mode can only work with Mono or Stereo LADSPA plugins, sorry!");
  1129. delete plugin;
  1130. return nullptr;
  1131. }
  1132. return plugin;
  1133. #else
  1134. init.engine->setLastError("LADSPA support not available");
  1135. return nullptr;
  1136. #endif
  1137. }
  1138. CARLA_BACKEND_END_NAMESPACE