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.

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