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.

1607 lines
50KB

  1. /*
  2. * Carla Plugin discovery
  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 "CarlaBackendUtils.hpp"
  18. #include "CarlaJuceUtils.hpp"
  19. #include "CarlaLibUtils.hpp"
  20. #include "CarlaString.hpp"
  21. #include "CarlaMIDI.h"
  22. #ifdef WANT_LADSPA
  23. # include "CarlaLadspaUtils.hpp"
  24. #endif
  25. #ifdef WANT_DSSI
  26. # include "CarlaLadspaUtils.hpp"
  27. # include "dssi/dssi.h"
  28. #endif
  29. #ifdef WANT_LV2
  30. # include <QtCore/QUrl>
  31. # include "CarlaLv2Utils.hpp"
  32. #endif
  33. #ifdef WANT_VST
  34. # include "CarlaVstUtils.hpp"
  35. #endif
  36. #ifdef WANT_FLUIDSYNTH
  37. # include <fluidsynth.h>
  38. #endif
  39. #ifdef WANT_LINUXSAMPLER
  40. # include <QtCore/QFileInfo>
  41. # include "linuxsampler/EngineFactory.h"
  42. #endif
  43. #include <iostream>
  44. #define DISCOVERY_OUT(x, y) std::cout << "\ncarla-discovery::" << x << "::" << y << std::endl;
  45. CARLA_BACKEND_USE_NAMESPACE
  46. #ifdef WANT_LV2
  47. // --------------------------------------------------------------------------
  48. // Our LV2 World class object
  49. Lv2WorldClass gLv2World;
  50. #endif
  51. // --------------------------------------------------------------------------
  52. // Dummy values to test plugins with
  53. const uint32_t kBufferSize = 512;
  54. const double kSampleRate = 44100.0;
  55. // --------------------------------------------------------------------------
  56. // Don't print ELF/EXE related errors since discovery can find multi-architecture binaries
  57. void print_lib_error(const char* const filename)
  58. {
  59. const char* const error = lib_error(filename);
  60. if (error && strstr(error, "wrong ELF class") == nullptr && strstr(error, "Bad EXE format") == nullptr)
  61. DISCOVERY_OUT("error", error);
  62. }
  63. #ifdef WANT_VST
  64. // --------------------------------------------------------------------------
  65. // VST stuff
  66. // Check if plugin needs idle
  67. bool gVstNeedsIdle = false;
  68. // Check if plugin wants midi
  69. bool gVstWantsMidi = false;
  70. // Current uniqueId for VST shell plugins
  71. intptr_t gVstCurrentUniqueId = 0;
  72. // Supported Carla features
  73. intptr_t vstHostCanDo(const char* const feature)
  74. {
  75. carla_debug("vstHostCanDo(\"%s\")", feature);
  76. if (std::strcmp(feature, "supplyIdle") == 0)
  77. return 1;
  78. if (std::strcmp(feature, "sendVstEvents") == 0)
  79. return 1;
  80. if (std::strcmp(feature, "sendVstMidiEvent") == 0)
  81. return 1;
  82. if (std::strcmp(feature, "sendVstMidiEventFlagIsRealtime") == 0)
  83. return 1;
  84. if (std::strcmp(feature, "sendVstTimeInfo") == 0)
  85. return 1;
  86. if (std::strcmp(feature, "receiveVstEvents") == 0)
  87. return 1;
  88. if (std::strcmp(feature, "receiveVstMidiEvent") == 0)
  89. return 1;
  90. if (std::strcmp(feature, "receiveVstTimeInfo") == 0)
  91. return -1;
  92. if (std::strcmp(feature, "reportConnectionChanges") == 0)
  93. return -1;
  94. if (std::strcmp(feature, "acceptIOChanges") == 0)
  95. return 1;
  96. if (std::strcmp(feature, "sizeWindow") == 0)
  97. return -1;
  98. if (std::strcmp(feature, "offline") == 0)
  99. return -1;
  100. if (std::strcmp(feature, "openFileSelector") == 0)
  101. return -1;
  102. if (std::strcmp(feature, "closeFileSelector") == 0)
  103. return -1;
  104. if (std::strcmp(feature, "startStopProcess") == 0)
  105. return 1;
  106. if (std::strcmp(feature, "supportShell") == 0)
  107. return 1;
  108. if (std::strcmp(feature, "shellCategory") == 0)
  109. return 1;
  110. // unimplemented
  111. carla_stderr("vstHostCanDo(\"%s\") - unknown feature", feature);
  112. return 0;
  113. }
  114. // Host-side callback
  115. intptr_t VSTCALLBACK vstHostCallback(AEffect* const effect, const int32_t opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
  116. {
  117. carla_debug("vstHostCallback(%p, %s, %i, " P_INTPTR ", %p, %f)", effect, vstMasterOpcode2str(opcode), index, value, ptr, opt);
  118. intptr_t ret = 0;
  119. switch (opcode)
  120. {
  121. case audioMasterAutomate:
  122. ret = 1;
  123. break;
  124. case audioMasterVersion:
  125. ret = kVstVersion;
  126. break;
  127. case audioMasterCurrentId:
  128. ret = gVstCurrentUniqueId;
  129. break;
  130. #if ! VST_FORCE_DEPRECATED
  131. case audioMasterWantMidi:
  132. gVstWantsMidi = true;
  133. ret = 1;
  134. break;
  135. #endif
  136. case audioMasterGetTime:
  137. static VstTimeInfo_R timeInfo;
  138. carla_zeroStruct<VstTimeInfo_R>(timeInfo);
  139. timeInfo.sampleRate = kSampleRate;
  140. // Tempo
  141. timeInfo.tempo = 120.0;
  142. timeInfo.flags |= kVstTempoValid;
  143. // Time Signature
  144. timeInfo.timeSigNumerator = 4;
  145. timeInfo.timeSigDenominator = 4;
  146. timeInfo.flags |= kVstTimeSigValid;
  147. #ifdef VESTIGE_HEADER
  148. ret = getAddressFromPointer(&timeInfo);
  149. #else
  150. ret = ToVstPtr<VstTimeInfo_R>(&timeInfo);
  151. #endif
  152. break;
  153. #if ! VST_FORCE_DEPRECATED
  154. case audioMasterTempoAt:
  155. ret = 120 * 10000;
  156. break;
  157. case audioMasterGetNumAutomatableParameters:
  158. ret = carla_min<int32_t>(effect->numParams, MAX_DEFAULT_PARAMETERS, 0);
  159. break;
  160. case audioMasterGetParameterQuantization:
  161. ret = 1; // full single float precision
  162. break;
  163. #endif
  164. case audioMasterNeedIdle:
  165. // Deprecated in VST SDK 2.4
  166. gVstNeedsIdle = true;
  167. ret = 1;
  168. break;
  169. case audioMasterGetSampleRate:
  170. ret = kSampleRate;
  171. break;
  172. case audioMasterGetBlockSize:
  173. ret = kBufferSize;
  174. break;
  175. #if ! VST_FORCE_DEPRECATED
  176. case audioMasterWillReplaceOrAccumulate:
  177. ret = 1; // replace
  178. break;
  179. #endif
  180. case audioMasterGetCurrentProcessLevel:
  181. ret = kVstProcessLevelUser;
  182. break;
  183. case audioMasterGetAutomationState:
  184. ret = kVstAutomationOff;
  185. break;
  186. case audioMasterGetVendorString:
  187. if (ptr != nullptr)
  188. {
  189. std::strcpy((char*)ptr, "falkTX");
  190. ret = 1;
  191. }
  192. break;
  193. case audioMasterGetProductString:
  194. if (ptr != nullptr)
  195. {
  196. std::strcpy((char*)ptr, "Carla-Discovery");
  197. ret = 1;
  198. }
  199. break;
  200. case audioMasterGetVendorVersion:
  201. ret = 0x1000; // 1.0.0
  202. break;
  203. case audioMasterCanDo:
  204. if (ptr != nullptr)
  205. ret = vstHostCanDo((const char*)ptr);
  206. break;
  207. case audioMasterGetLanguage:
  208. ret = kVstLangEnglish;
  209. break;
  210. default:
  211. carla_stdout("vstHostCallback(%p, %s, %i, " P_INTPTR ", %p, %f)", effect, vstMasterOpcode2str(opcode), index, value, ptr, opt);
  212. break;
  213. }
  214. return ret;
  215. // unused
  216. (void)index;
  217. (void)value;
  218. (void)opt;
  219. }
  220. #endif
  221. #ifdef WANT_LINUXSAMPLER
  222. // --------------------------------------------------------------------------
  223. // LinuxSampler stuff
  224. class LinuxSamplerScopedEngine
  225. {
  226. public:
  227. LinuxSamplerScopedEngine(const char* const filename, const char* const stype)
  228. : fEngine(nullptr),
  229. fIns(nullptr)
  230. {
  231. using namespace LinuxSampler;
  232. try {
  233. fEngine = EngineFactory::Create(stype);
  234. }
  235. catch (const Exception& e)
  236. {
  237. DISCOVERY_OUT("error", e.what());
  238. return;
  239. }
  240. if (fEngine == nullptr)
  241. return;
  242. fIns = fEngine->GetInstrumentManager();
  243. if (fIns == nullptr)
  244. {
  245. DISCOVERY_OUT("error", "Failed to get LinuxSampler instrument manager");
  246. return;
  247. }
  248. std::vector<InstrumentManager::instrument_id_t> ids;
  249. try {
  250. ids = fIns->GetInstrumentFileContent(filename);
  251. }
  252. catch (const InstrumentManagerException& e)
  253. {
  254. DISCOVERY_OUT("error", e.what());
  255. return;
  256. }
  257. if (ids.size() == 0)
  258. return;
  259. InstrumentManager::instrument_info_t info;
  260. try {
  261. info = fIns->GetInstrumentInfo(ids[0]);
  262. }
  263. catch (const InstrumentManagerException& e)
  264. {
  265. DISCOVERY_OUT("error", e.what());
  266. return;
  267. }
  268. outputInfo(&info, ids.size());
  269. }
  270. ~LinuxSamplerScopedEngine()
  271. {
  272. if (fEngine != nullptr)
  273. LinuxSampler::EngineFactory::Destroy(fEngine);
  274. }
  275. static void outputInfo(LinuxSampler::InstrumentManager::instrument_info_t* const info, const int programs, const char* const basename = nullptr)
  276. {
  277. DISCOVERY_OUT("init", "-----------");
  278. if (info != nullptr)
  279. {
  280. DISCOVERY_OUT("name", info->InstrumentName);
  281. DISCOVERY_OUT("label", info->Product);
  282. DISCOVERY_OUT("maker", info->Artists);
  283. DISCOVERY_OUT("copyright", info->Artists);
  284. }
  285. else if (basename != nullptr)
  286. {
  287. DISCOVERY_OUT("name", basename);
  288. DISCOVERY_OUT("label", basename);
  289. }
  290. DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
  291. DISCOVERY_OUT("audio.outs", 2);
  292. DISCOVERY_OUT("audio.total", 2);
  293. DISCOVERY_OUT("midi.ins", 1);
  294. DISCOVERY_OUT("midi.total", 1);
  295. DISCOVERY_OUT("programs.total", programs);
  296. //DISCOVERY_OUT("parameters.ins", 13); // defined in Carla, TODO
  297. //DISCOVERY_OUT("parameters.outs", 1);
  298. //DISCOVERY_OUT("parameters.total", 14);
  299. DISCOVERY_OUT("build", BINARY_NATIVE);
  300. DISCOVERY_OUT("end", "------------");
  301. }
  302. private:
  303. LinuxSampler::Engine* fEngine;
  304. LinuxSampler::InstrumentManager* fIns;
  305. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LinuxSamplerScopedEngine)
  306. };
  307. #endif
  308. // ------------------------------ Plugin Checks -----------------------------
  309. void do_ladspa_check(void* const libHandle, const bool init)
  310. {
  311. #ifdef WANT_LADSPA
  312. const LADSPA_Descriptor_Function descFn = (LADSPA_Descriptor_Function)lib_symbol(libHandle, "ladspa_descriptor");
  313. if (descFn == nullptr)
  314. {
  315. DISCOVERY_OUT("error", "Not a LADSPA plugin");
  316. return;
  317. }
  318. unsigned long i = 0;
  319. const LADSPA_Descriptor* descriptor;
  320. while ((descriptor = descFn(i++)) != nullptr)
  321. {
  322. if (descriptor->instantiate == nullptr)
  323. {
  324. DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no instantiate()");
  325. continue;
  326. }
  327. if (descriptor->cleanup == nullptr)
  328. {
  329. DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no cleanup()");
  330. continue;
  331. }
  332. if (descriptor->run == nullptr)
  333. {
  334. DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no run()");
  335. continue;
  336. }
  337. if (! LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties))
  338. {
  339. DISCOVERY_OUT("warning", "Plugin '" << descriptor->Name << "' is not hard real-time capable");
  340. }
  341. int hints = 0;
  342. int audioIns = 0;
  343. int audioOuts = 0;
  344. int audioTotal = 0;
  345. int parametersIns = 0;
  346. int parametersOuts = 0;
  347. int parametersTotal = 0;
  348. if (LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties))
  349. hints |= PLUGIN_IS_RTSAFE;
  350. for (unsigned long j=0; j < descriptor->PortCount; j++)
  351. {
  352. CARLA_ASSERT(descriptor->PortNames[j] != nullptr);
  353. const LADSPA_PortDescriptor portDescriptor = descriptor->PortDescriptors[j];
  354. if (LADSPA_IS_PORT_AUDIO(portDescriptor))
  355. {
  356. if (LADSPA_IS_PORT_INPUT(portDescriptor))
  357. audioIns += 1;
  358. else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
  359. audioOuts += 1;
  360. audioTotal += 1;
  361. }
  362. else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
  363. {
  364. if (LADSPA_IS_PORT_INPUT(portDescriptor))
  365. parametersIns += 1;
  366. else if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && std::strcmp(descriptor->PortNames[j], "latency") && std::strcmp(descriptor->PortNames[j], "_latency"))
  367. parametersOuts += 1;
  368. parametersTotal += 1;
  369. }
  370. }
  371. if (init)
  372. {
  373. // -----------------------------------------------------------------------
  374. // start crash-free plugin test
  375. LADSPA_Handle handle = descriptor->instantiate(descriptor, kSampleRate);
  376. if (handle == nullptr)
  377. {
  378. DISCOVERY_OUT("error", "Failed to init LADSPA plugin");
  379. continue;
  380. }
  381. // Test quick init and cleanup
  382. descriptor->cleanup(handle);
  383. handle = descriptor->instantiate(descriptor, kSampleRate);
  384. if (handle == nullptr)
  385. {
  386. DISCOVERY_OUT("error", "Failed to init LADSPA plugin #2");
  387. continue;
  388. }
  389. LADSPA_Data bufferAudio[kBufferSize][audioTotal];
  390. LADSPA_Data bufferParams[parametersTotal];
  391. LADSPA_Data min, max, def;
  392. for (unsigned long j=0, iA=0, iC=0; j < descriptor->PortCount; j++)
  393. {
  394. const LADSPA_PortDescriptor portDescriptor = descriptor->PortDescriptors[j];
  395. const LADSPA_PortRangeHint portRangeHints = descriptor->PortRangeHints[j];
  396. const char* const portName = descriptor->PortNames[j];
  397. if (LADSPA_IS_PORT_AUDIO(portDescriptor))
  398. {
  399. carla_zeroFloat(bufferAudio[iA], kBufferSize);
  400. descriptor->connect_port(handle, j, bufferAudio[iA++]);
  401. }
  402. else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
  403. {
  404. // min value
  405. if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
  406. min = portRangeHints.LowerBound;
  407. else
  408. min = 0.0f;
  409. // max value
  410. if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
  411. max = portRangeHints.UpperBound;
  412. else
  413. max = 1.0f;
  414. if (min > max)
  415. {
  416. DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: min > max");
  417. max = min + 0.1f;
  418. }
  419. else if (max - min == 0.0f)
  420. {
  421. DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: max - min == 0");
  422. max = min + 0.1f;
  423. }
  424. // default value
  425. def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
  426. if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
  427. {
  428. min *= kSampleRate;
  429. max *= kSampleRate;
  430. def *= kSampleRate;
  431. }
  432. if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && (std::strcmp(portName, "latency") == 0 || std::strcmp(portName, "_latency") == 0))
  433. {
  434. // latency parameter
  435. def = 0.0f;
  436. }
  437. else
  438. {
  439. if (def < min)
  440. def = min;
  441. else if (def > max)
  442. def = max;
  443. }
  444. bufferParams[iC] = def;
  445. descriptor->connect_port(handle, j, &bufferParams[iC++]);
  446. }
  447. }
  448. if (descriptor->activate != nullptr)
  449. descriptor->activate(handle);
  450. descriptor->run(handle, kBufferSize);
  451. if (descriptor->deactivate != nullptr)
  452. descriptor->deactivate(handle);
  453. descriptor->cleanup(handle);
  454. // end crash-free plugin test
  455. // -----------------------------------------------------------------------
  456. }
  457. DISCOVERY_OUT("init", "-----------");
  458. DISCOVERY_OUT("name", descriptor->Name);
  459. DISCOVERY_OUT("label", descriptor->Label);
  460. DISCOVERY_OUT("maker", descriptor->Maker);
  461. DISCOVERY_OUT("copyright", descriptor->Copyright);
  462. DISCOVERY_OUT("uniqueId", descriptor->UniqueID);
  463. DISCOVERY_OUT("hints", hints);
  464. DISCOVERY_OUT("audio.ins", audioIns);
  465. DISCOVERY_OUT("audio.outs", audioOuts);
  466. DISCOVERY_OUT("audio.total", audioTotal);
  467. DISCOVERY_OUT("parameters.ins", parametersIns);
  468. DISCOVERY_OUT("parameters.outs", parametersOuts);
  469. DISCOVERY_OUT("parameters.total", parametersTotal);
  470. DISCOVERY_OUT("build", BINARY_NATIVE);
  471. DISCOVERY_OUT("end", "------------");
  472. }
  473. #else
  474. DISCOVERY_OUT("error", "LADSPA support not available");
  475. return;
  476. // unused
  477. (void)libHandle;
  478. (void)init;
  479. #endif
  480. }
  481. void do_dssi_check(void* const libHandle, const bool init)
  482. {
  483. #ifdef WANT_DSSI
  484. const DSSI_Descriptor_Function descFn = (DSSI_Descriptor_Function)lib_symbol(libHandle, "dssi_descriptor");
  485. if (descFn == nullptr)
  486. {
  487. DISCOVERY_OUT("error", "Not a DSSI plugin");
  488. return;
  489. }
  490. unsigned long i = 0;
  491. const DSSI_Descriptor* descriptor;
  492. while ((descriptor = descFn(i++)) != nullptr)
  493. {
  494. const LADSPA_Descriptor* const ldescriptor = descriptor->LADSPA_Plugin;
  495. if (ldescriptor == nullptr)
  496. {
  497. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no LADSPA interface");
  498. continue;
  499. }
  500. if (descriptor->DSSI_API_Version != DSSI_VERSION_MAJOR)
  501. {
  502. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' uses an unsupported DSSI spec version " << descriptor->DSSI_API_Version);
  503. continue;
  504. }
  505. if (ldescriptor->instantiate == nullptr)
  506. {
  507. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no instantiate()");
  508. continue;
  509. }
  510. if (ldescriptor->cleanup == nullptr)
  511. {
  512. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no cleanup()");
  513. continue;
  514. }
  515. if (ldescriptor->run == nullptr && descriptor->run_synth == nullptr && descriptor->run_multiple_synths == nullptr)
  516. {
  517. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no run(), run_synth() or run_multiple_synths()");
  518. continue;
  519. }
  520. if (! LADSPA_IS_HARD_RT_CAPABLE(ldescriptor->Properties))
  521. {
  522. DISCOVERY_OUT("warning", "Plugin '" << ldescriptor->Name << "' is not hard real-time capable");
  523. }
  524. int hints = 0;
  525. int audioIns = 0;
  526. int audioOuts = 0;
  527. int audioTotal = 0;
  528. int midiIns = 0;
  529. int midiTotal = 0;
  530. int parametersIns = 0;
  531. int parametersOuts = 0;
  532. int parametersTotal = 0;
  533. int programsTotal = 0;
  534. if (LADSPA_IS_HARD_RT_CAPABLE(ldescriptor->Properties))
  535. hints |= PLUGIN_IS_RTSAFE;
  536. for (unsigned long j=0; j < ldescriptor->PortCount; j++)
  537. {
  538. CARLA_ASSERT(ldescriptor->PortNames[j] != nullptr);
  539. const LADSPA_PortDescriptor portDescriptor = ldescriptor->PortDescriptors[j];
  540. if (LADSPA_IS_PORT_AUDIO(portDescriptor))
  541. {
  542. if (LADSPA_IS_PORT_INPUT(portDescriptor))
  543. audioIns += 1;
  544. else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
  545. audioOuts += 1;
  546. audioTotal += 1;
  547. }
  548. else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
  549. {
  550. if (LADSPA_IS_PORT_INPUT(portDescriptor))
  551. parametersIns += 1;
  552. else if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && std::strcmp(ldescriptor->PortNames[j], "latency") && std::strcmp(ldescriptor->PortNames[j], "_latency"))
  553. parametersOuts += 1;
  554. parametersTotal += 1;
  555. }
  556. }
  557. if (descriptor->run_synth || descriptor->run_multiple_synths)
  558. midiIns = midiTotal = 1;
  559. if (midiIns > 0 && audioIns == 0 && audioOuts > 0)
  560. hints |= PLUGIN_IS_SYNTH;
  561. if (init)
  562. {
  563. // -----------------------------------------------------------------------
  564. // start crash-free plugin test
  565. LADSPA_Handle handle = ldescriptor->instantiate(ldescriptor, kSampleRate);
  566. if (handle == nullptr)
  567. {
  568. DISCOVERY_OUT("error", "Failed to init DSSI plugin");
  569. continue;
  570. }
  571. // Test quick init and cleanup
  572. ldescriptor->cleanup(handle);
  573. handle = ldescriptor->instantiate(ldescriptor, kSampleRate);
  574. if (handle == nullptr)
  575. {
  576. DISCOVERY_OUT("error", "Failed to init DSSI plugin #2");
  577. continue;
  578. }
  579. if (descriptor->get_program != nullptr && descriptor->select_program != nullptr)
  580. {
  581. while (descriptor->get_program(handle, programsTotal++))
  582. continue;
  583. }
  584. LADSPA_Data bufferAudio[kBufferSize][audioTotal];
  585. LADSPA_Data bufferParams[parametersTotal];
  586. LADSPA_Data min, max, def;
  587. for (unsigned long j=0, iA=0, iC=0; j < ldescriptor->PortCount; j++)
  588. {
  589. const LADSPA_PortDescriptor portDescriptor = ldescriptor->PortDescriptors[j];
  590. const LADSPA_PortRangeHint portRangeHints = ldescriptor->PortRangeHints[j];
  591. const char* const portName = ldescriptor->PortNames[j];
  592. if (LADSPA_IS_PORT_AUDIO(portDescriptor))
  593. {
  594. carla_zeroFloat(bufferAudio[iA], kBufferSize);
  595. ldescriptor->connect_port(handle, j, bufferAudio[iA++]);
  596. }
  597. else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
  598. {
  599. // min value
  600. if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
  601. min = portRangeHints.LowerBound;
  602. else
  603. min = 0.0f;
  604. // max value
  605. if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
  606. max = portRangeHints.UpperBound;
  607. else
  608. max = 1.0f;
  609. if (min > max)
  610. {
  611. DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: min > max");
  612. max = min + 0.1f;
  613. }
  614. else if (max - min == 0.0f)
  615. {
  616. DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: max - min == 0");
  617. max = min + 0.1f;
  618. }
  619. // default value
  620. def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
  621. if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
  622. {
  623. min *= kSampleRate;
  624. max *= kSampleRate;
  625. def *= kSampleRate;
  626. }
  627. if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && (std::strcmp(portName, "latency") == 0 || std::strcmp(portName, "_latency") == 0))
  628. {
  629. // latency parameter
  630. def = 0.0f;
  631. }
  632. else
  633. {
  634. if (def < min)
  635. def = min;
  636. else if (def > max)
  637. def = max;
  638. }
  639. bufferParams[iC] = def;
  640. ldescriptor->connect_port(handle, j, &bufferParams[iC++]);
  641. }
  642. }
  643. // select first midi-program if available
  644. if (programsTotal > 0)
  645. {
  646. if (const DSSI_Program_Descriptor* const pDesc = descriptor->get_program(handle, 0))
  647. descriptor->select_program(handle, pDesc->Bank, pDesc->Program);
  648. }
  649. if (ldescriptor->activate != nullptr)
  650. ldescriptor->activate(handle);
  651. if (descriptor->run_synth != nullptr || descriptor->run_multiple_synths != nullptr)
  652. {
  653. snd_seq_event_t midiEvents[2];
  654. memset(midiEvents, 0, sizeof(snd_seq_event_t)*2); //FIXME
  655. const unsigned long midiEventCount = 2;
  656. midiEvents[0].type = SND_SEQ_EVENT_NOTEON;
  657. midiEvents[0].data.note.note = 64;
  658. midiEvents[0].data.note.velocity = 100;
  659. midiEvents[1].type = SND_SEQ_EVENT_NOTEOFF;
  660. midiEvents[1].data.note.note = 64;
  661. midiEvents[1].data.note.velocity = 0;
  662. midiEvents[1].time.tick = kBufferSize/2;
  663. if (descriptor->run_multiple_synths != nullptr && descriptor->run_synth == nullptr)
  664. {
  665. LADSPA_Handle handlePtr[1] = { handle };
  666. snd_seq_event_t* midiEventsPtr[1] = { midiEvents };
  667. unsigned long midiEventCountPtr[1] = { midiEventCount };
  668. descriptor->run_multiple_synths(1, handlePtr, kBufferSize, midiEventsPtr, midiEventCountPtr);
  669. }
  670. else
  671. descriptor->run_synth(handle, kBufferSize, midiEvents, midiEventCount);
  672. }
  673. else
  674. ldescriptor->run(handle, kBufferSize);
  675. if (ldescriptor->deactivate != nullptr)
  676. ldescriptor->deactivate(handle);
  677. ldescriptor->cleanup(handle);
  678. // end crash-free plugin test
  679. // -----------------------------------------------------------------------
  680. }
  681. DISCOVERY_OUT("init", "-----------");
  682. DISCOVERY_OUT("name", ldescriptor->Name);
  683. DISCOVERY_OUT("label", ldescriptor->Label);
  684. DISCOVERY_OUT("maker", ldescriptor->Maker);
  685. DISCOVERY_OUT("copyright", ldescriptor->Copyright);
  686. DISCOVERY_OUT("unique_id", ldescriptor->UniqueID);
  687. DISCOVERY_OUT("hints", hints);
  688. DISCOVERY_OUT("audio.ins", audioIns);
  689. DISCOVERY_OUT("audio.outs", audioOuts);
  690. DISCOVERY_OUT("audio.total", audioTotal);
  691. DISCOVERY_OUT("midi.ins", midiIns);
  692. DISCOVERY_OUT("midi.total", midiTotal);
  693. DISCOVERY_OUT("parameters.ins", parametersIns);
  694. DISCOVERY_OUT("parameters.outs", parametersOuts);
  695. DISCOVERY_OUT("parameters.total", parametersTotal);
  696. DISCOVERY_OUT("programs.total", programsTotal);
  697. DISCOVERY_OUT("build", BINARY_NATIVE);
  698. DISCOVERY_OUT("end", "------------");
  699. }
  700. #else
  701. DISCOVERY_OUT("error", "DSSI support not available");
  702. return;
  703. // unused
  704. (void)libHandle;
  705. (void)init;
  706. #endif
  707. }
  708. void do_lv2_check(const char* const bundle, const bool init)
  709. {
  710. #ifdef WANT_LV2
  711. // Convert bundle filename to URI
  712. QString qBundle(QUrl::fromLocalFile(bundle).toString());
  713. if (! qBundle.endsWith(QChar(OS_SEP)))
  714. qBundle += QChar(OS_SEP);
  715. // Load bundle
  716. Lilv::Node lilvBundle(gLv2World.new_uri(qBundle.toUtf8().constData()));
  717. gLv2World.load_bundle(lilvBundle);
  718. // Load plugins in this bundle
  719. const Lilv::Plugins lilvPlugins(gLv2World.get_all_plugins());
  720. // Get all plugin URIs in this bundle
  721. QStringList URIs;
  722. LILV_FOREACH(plugins, i, lilvPlugins)
  723. {
  724. Lilv::Plugin lilvPlugin(lilv_plugins_get(lilvPlugins, i));
  725. if (const char* const uri = lilvPlugin.get_uri().as_string())
  726. URIs.append(QString(uri));
  727. }
  728. if (URIs.count() == 0)
  729. {
  730. DISCOVERY_OUT("warning", "LV2 Bundle doesn't provide any plugins");
  731. return;
  732. }
  733. // Get & check every plugin-instance
  734. for (int i=0; i < URIs.count(); i++)
  735. {
  736. const LV2_RDF_Descriptor* const rdfDescriptor = lv2_rdf_new(URIs.at(i).toUtf8().constData());
  737. CARLA_ASSERT(rdfDescriptor != nullptr && rdfDescriptor->URI != nullptr);
  738. if (rdfDescriptor == nullptr || rdfDescriptor->URI == nullptr)
  739. {
  740. DISCOVERY_OUT("error", "Failed to find LV2 plugin '" << URIs.at(i).toUtf8().constData() << "'");
  741. continue;
  742. }
  743. if (init)
  744. {
  745. // test if DLL is loadable, twice
  746. void* const libHandle1 = lib_open(rdfDescriptor->Binary);
  747. if (libHandle1 == nullptr)
  748. {
  749. print_lib_error(rdfDescriptor->Binary);
  750. delete rdfDescriptor;
  751. continue;
  752. }
  753. lib_close(libHandle1);
  754. void* const libHandle2 = lib_open(rdfDescriptor->Binary);
  755. if (libHandle2 == nullptr)
  756. {
  757. print_lib_error(rdfDescriptor->Binary);
  758. delete rdfDescriptor;
  759. continue;
  760. }
  761. lib_close(libHandle2);
  762. }
  763. // test if we support all required ports and features
  764. {
  765. bool supported = true;
  766. for (uint32_t j=0; j < rdfDescriptor->PortCount && supported; j++)
  767. {
  768. const LV2_RDF_Port* const rdfPort = &rdfDescriptor->Ports[j];
  769. if (is_lv2_port_supported(rdfPort->Types))
  770. {
  771. pass();
  772. }
  773. else if (! LV2_IS_PORT_OPTIONAL(rdfPort->Properties))
  774. {
  775. DISCOVERY_OUT("error", "Plugin '" << rdfDescriptor->URI << "' requires a non-supported port type (portName: '" << rdfPort->Name << "')");
  776. supported = false;
  777. break;
  778. }
  779. }
  780. for (uint32_t j=0; j < rdfDescriptor->FeatureCount && supported; j++)
  781. {
  782. const LV2_RDF_Feature* const rdfFeature = &rdfDescriptor->Features[j];
  783. if (is_lv2_feature_supported(rdfFeature->URI))
  784. {
  785. pass();
  786. }
  787. else if (LV2_IS_FEATURE_REQUIRED(rdfFeature->Type))
  788. {
  789. DISCOVERY_OUT("error", "Plugin '" << rdfDescriptor->URI << "' requires a non-supported feature '" << rdfFeature->URI << "'");
  790. supported = false;
  791. break;
  792. }
  793. }
  794. if (! supported)
  795. {
  796. delete rdfDescriptor;
  797. continue;
  798. }
  799. }
  800. int hints = 0;
  801. int audioIns = 0;
  802. int audioOuts = 0;
  803. int audioTotal = 0;
  804. int midiIns = 0;
  805. int midiOuts = 0;
  806. int midiTotal = 0;
  807. int parametersIns = 0;
  808. int parametersOuts = 0;
  809. int parametersTotal = 0;
  810. int programsTotal = rdfDescriptor->PresetCount;
  811. for (uint32_t j=0; j < rdfDescriptor->FeatureCount; j++)
  812. {
  813. const LV2_RDF_Feature* const rdfFeature = &rdfDescriptor->Features[j];
  814. if (std::strcmp(rdfFeature->URI, LV2_CORE__hardRTCapable) == 0)
  815. hints |= PLUGIN_IS_RTSAFE;
  816. }
  817. for (uint32_t j=0; j < rdfDescriptor->PortCount; j++)
  818. {
  819. const LV2_RDF_Port* const rdfPort = &rdfDescriptor->Ports[j];
  820. if (LV2_IS_PORT_AUDIO(rdfPort->Types))
  821. {
  822. if (LV2_IS_PORT_INPUT(rdfPort->Types))
  823. audioIns += 1;
  824. else if (LV2_IS_PORT_OUTPUT(rdfPort->Types))
  825. audioOuts += 1;
  826. audioTotal += 1;
  827. }
  828. else if (LV2_IS_PORT_CONTROL(rdfPort->Types))
  829. {
  830. if (LV2_IS_PORT_DESIGNATION_LATENCY(rdfPort->Designation))
  831. {
  832. pass();
  833. }
  834. else if (LV2_IS_PORT_DESIGNATION_SAMPLE_RATE(rdfPort->Designation))
  835. {
  836. pass();
  837. }
  838. else if (LV2_IS_PORT_DESIGNATION_FREEWHEELING(rdfPort->Designation))
  839. {
  840. pass();
  841. }
  842. else if (LV2_IS_PORT_DESIGNATION_TIME(rdfPort->Designation))
  843. {
  844. pass();
  845. }
  846. else
  847. {
  848. if (LV2_IS_PORT_INPUT(rdfPort->Types))
  849. parametersIns += 1;
  850. else if (LV2_IS_PORT_OUTPUT(rdfPort->Types))
  851. parametersOuts += 1;
  852. parametersTotal += 1;
  853. }
  854. }
  855. else if (LV2_PORT_SUPPORTS_MIDI_EVENT(rdfPort->Types))
  856. {
  857. if (LV2_IS_PORT_INPUT(rdfPort->Types))
  858. midiIns += 1;
  859. else if (LV2_IS_PORT_OUTPUT(rdfPort->Types))
  860. midiOuts += 1;
  861. midiTotal += 1;
  862. }
  863. }
  864. if (rdfDescriptor->Type[1] & LV2_PLUGIN_INSTRUMENT)
  865. hints |= PLUGIN_IS_SYNTH;
  866. if (rdfDescriptor->UICount > 0)
  867. hints |= PLUGIN_HAS_GUI;
  868. DISCOVERY_OUT("init", "-----------");
  869. DISCOVERY_OUT("uri", rdfDescriptor->URI);
  870. if (rdfDescriptor->Name != nullptr)
  871. DISCOVERY_OUT("name", rdfDescriptor->Name);
  872. if (rdfDescriptor->Author != nullptr)
  873. DISCOVERY_OUT("maker", rdfDescriptor->Author);
  874. if (rdfDescriptor->License != nullptr)
  875. DISCOVERY_OUT("copyright", rdfDescriptor->License);
  876. DISCOVERY_OUT("unique_id", rdfDescriptor->UniqueID);
  877. DISCOVERY_OUT("hints", hints);
  878. DISCOVERY_OUT("audio.ins", audioIns);
  879. DISCOVERY_OUT("audio.outs", audioOuts);
  880. DISCOVERY_OUT("audio.total", audioTotal);
  881. DISCOVERY_OUT("midi.ins", midiIns);
  882. DISCOVERY_OUT("midi.outs", midiOuts);
  883. DISCOVERY_OUT("midi.total", midiTotal);
  884. DISCOVERY_OUT("parameters.ins", parametersIns);
  885. DISCOVERY_OUT("parameters.outs", parametersOuts);
  886. DISCOVERY_OUT("parameters.total", parametersTotal);
  887. DISCOVERY_OUT("programs.total", programsTotal);
  888. DISCOVERY_OUT("build", BINARY_NATIVE);
  889. DISCOVERY_OUT("end", "------------");
  890. delete rdfDescriptor;
  891. }
  892. #else
  893. DISCOVERY_OUT("error", "LV2 support not available");
  894. return;
  895. // unused
  896. (void)bundle;
  897. (void)init;
  898. #endif
  899. }
  900. void do_vst_check(void* const libHandle, const bool init)
  901. {
  902. #ifdef WANT_VST
  903. VST_Function vstFn = (VST_Function)lib_symbol(libHandle, "VSTPluginMain");
  904. if (vstFn == nullptr)
  905. {
  906. vstFn = (VST_Function)lib_symbol(libHandle, "main");
  907. if (vstFn == nullptr)
  908. {
  909. DISCOVERY_OUT("error", "Not a VST plugin");
  910. return;
  911. }
  912. }
  913. AEffect* const effect = vstFn(vstHostCallback);
  914. if (effect == nullptr || effect->magic != kEffectMagic)
  915. {
  916. DISCOVERY_OUT("error", "Failed to init VST plugin, or VST magic failed");
  917. return;
  918. }
  919. char strBuf[STR_MAX+1] = { '\0' };
  920. CarlaString cName;
  921. CarlaString cProduct;
  922. CarlaString cVendor;
  923. effect->dispatcher(effect, effOpen, 0, 0, nullptr, 0.0f);
  924. const intptr_t vstCategory = effect->dispatcher(effect, effGetPlugCategory, 0, 0, nullptr, 0.0f);
  925. if (vstCategory == kPlugCategShell)
  926. {
  927. if ((gVstCurrentUniqueId = effect->dispatcher(effect, effShellGetNextPlugin, 0, 0, strBuf, 0.0f)) != 0)
  928. cName = strBuf;
  929. }
  930. else
  931. {
  932. gVstCurrentUniqueId = effect->uniqueID;
  933. if (gVstCurrentUniqueId != 0 && effect->dispatcher(effect, effGetEffectName, 0, 0, strBuf, 0.0f) == 1)
  934. cName = strBuf;
  935. }
  936. if (gVstCurrentUniqueId == 0)
  937. {
  938. DISCOVERY_OUT("error", "Plugin doesn't have an Unique ID");
  939. effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
  940. return;
  941. }
  942. carla_fill<char>(strBuf, STR_MAX+1, '\0');
  943. if (effect->dispatcher(effect, effGetVendorString, 0, 0, strBuf, 0.0f) == 1)
  944. cVendor = strBuf;
  945. while (gVstCurrentUniqueId != 0)
  946. {
  947. carla_fill<char>(strBuf, STR_MAX+1, '\0');
  948. if (effect->dispatcher(effect, effGetProductString, 0, 0, strBuf, 0.0f) == 1)
  949. cProduct = strBuf;
  950. else
  951. cProduct.clear();
  952. gVstWantsMidi = false;
  953. int hints = 0;
  954. int audioIns = effect->numInputs;
  955. int audioOuts = effect->numOutputs;
  956. int audioTotal = audioIns + audioOuts;
  957. int midiIns = 0;
  958. int midiOuts = 0;
  959. int midiTotal = 0;
  960. int parametersIns = effect->numParams;
  961. int parametersTotal = parametersIns;
  962. int programsTotal = effect->numPrograms;
  963. if (effect->flags & effFlagsHasEditor)
  964. hints |= PLUGIN_HAS_GUI;
  965. if (effect->flags & effFlagsIsSynth)
  966. hints |= PLUGIN_IS_SYNTH;
  967. if (vstPluginCanDo(effect, "receiveVstEvents") || vstPluginCanDo(effect, "receiveVstMidiEvent") || (effect->flags & effFlagsIsSynth) > 0)
  968. midiIns = 1;
  969. if (vstPluginCanDo(effect, "sendVstEvents") || vstPluginCanDo(effect, "sendVstMidiEvent"))
  970. midiOuts = 1;
  971. midiTotal = midiIns + midiOuts;
  972. // -----------------------------------------------------------------------
  973. // start crash-free plugin test
  974. if (init)
  975. {
  976. if (gVstNeedsIdle)
  977. effect->dispatcher(effect, effIdle, 0, 0, nullptr, 0.0f);
  978. #if ! VST_FORCE_DEPRECATED
  979. effect->dispatcher(effect, effSetBlockSizeAndSampleRate, 0, kBufferSize, nullptr, kSampleRate);
  980. #endif
  981. effect->dispatcher(effect, effSetBlockSize, 0, kBufferSize, nullptr, 0.0f);
  982. effect->dispatcher(effect, effSetSampleRate, 0, 0, nullptr, kSampleRate);
  983. effect->dispatcher(effect, effSetProcessPrecision, 0, kVstProcessPrecision32, nullptr, 0.0f);
  984. effect->dispatcher(effect, effMainsChanged, 0, 1, nullptr, 0.0f);
  985. effect->dispatcher(effect, effStartProcess, 0, 0, nullptr, 0.0f);
  986. if (gVstNeedsIdle)
  987. effect->dispatcher(effect, effIdle, 0, 0, nullptr, 0.0f);
  988. // Plugin might call wantMidi() during resume
  989. if (midiIns == 0 && gVstWantsMidi)
  990. {
  991. midiIns = 1;
  992. midiTotal = midiIns + midiOuts;
  993. }
  994. float* bufferAudioIn[audioIns];
  995. for (int j=0; j < audioIns; j++)
  996. {
  997. bufferAudioIn[j] = new float[kBufferSize];
  998. carla_zeroFloat(bufferAudioIn[j], kBufferSize);
  999. }
  1000. float* bufferAudioOut[audioOuts];
  1001. for (int j=0; j < audioOuts; j++)
  1002. {
  1003. bufferAudioOut[j] = new float[kBufferSize];
  1004. carla_zeroFloat(bufferAudioOut[j], kBufferSize);
  1005. }
  1006. struct VstEventsFixed {
  1007. int32_t numEvents;
  1008. intptr_t reserved;
  1009. VstEvent* data[2];
  1010. VstEventsFixed()
  1011. : numEvents(0),
  1012. reserved(0),
  1013. data{0} {}
  1014. } events;
  1015. VstMidiEvent midiEvents[2];
  1016. carla_zeroStruct<VstMidiEvent>(midiEvents, 2);
  1017. midiEvents[0].type = kVstMidiType;
  1018. midiEvents[0].byteSize = sizeof(VstMidiEvent);
  1019. midiEvents[0].midiData[0] = MIDI_STATUS_NOTE_ON;
  1020. midiEvents[0].midiData[1] = 64;
  1021. midiEvents[0].midiData[2] = 100;
  1022. midiEvents[1].type = kVstMidiType;
  1023. midiEvents[1].byteSize = sizeof(VstMidiEvent);
  1024. midiEvents[1].midiData[0] = MIDI_STATUS_NOTE_OFF;
  1025. midiEvents[1].midiData[1] = 64;
  1026. midiEvents[1].deltaFrames = kBufferSize/2;
  1027. events.numEvents = 2;
  1028. events.reserved = 0;
  1029. events.data[0] = (VstEvent*)&midiEvents[0];
  1030. events.data[1] = (VstEvent*)&midiEvents[1];
  1031. // processing
  1032. {
  1033. if (midiIns > 0)
  1034. effect->dispatcher(effect, effProcessEvents, 0, 0, &events, 0.0f);
  1035. #if ! VST_FORCE_DEPRECATED
  1036. if ((effect->flags & effFlagsCanReplacing) > 0 && effect->processReplacing != nullptr && effect->processReplacing != effect->process)
  1037. effect->processReplacing(effect, bufferAudioIn, bufferAudioOut, kBufferSize);
  1038. else if (effect->process != nullptr)
  1039. effect->process(effect, bufferAudioIn, bufferAudioOut, kBufferSize);
  1040. else
  1041. DISCOVERY_OUT("error", "Plugin doesn't have a process function");
  1042. #else
  1043. CARLA_ASSERT(effect->flags & effFlagsCanReplacing);
  1044. if (effect->flags & effFlagsCanReplacing)
  1045. {
  1046. if (effect->processReplacing != nullptr)
  1047. effect->processReplacing(effect, bufferAudioIn, bufferAudioOut, bufferSize);
  1048. else
  1049. DISCOVERY_OUT("error", "Plugin doesn't have a process function");
  1050. }
  1051. else
  1052. DISCOVERY_OUT("error", "Plugin doesn't have can't do process replacing");
  1053. #endif
  1054. }
  1055. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  1056. effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  1057. if (gVstNeedsIdle)
  1058. effect->dispatcher(effect, effIdle, 0, 0, nullptr, 0.0f);
  1059. for (int j=0; j < audioIns; j++)
  1060. delete[] bufferAudioIn[j];
  1061. for (int j=0; j < audioOuts; j++)
  1062. delete[] bufferAudioOut[j];
  1063. }
  1064. // end crash-free plugin test
  1065. // -----------------------------------------------------------------------
  1066. DISCOVERY_OUT("init", "-----------");
  1067. DISCOVERY_OUT("name", (const char*)cName);
  1068. DISCOVERY_OUT("label", (const char*)cProduct);
  1069. DISCOVERY_OUT("maker", (const char*)cVendor);
  1070. DISCOVERY_OUT("copyright", (const char*)cVendor);
  1071. DISCOVERY_OUT("unique_id", gVstCurrentUniqueId);
  1072. DISCOVERY_OUT("hints", hints);
  1073. DISCOVERY_OUT("audio.ins", audioIns);
  1074. DISCOVERY_OUT("audio.outs", audioOuts);
  1075. DISCOVERY_OUT("audio.total", audioTotal);
  1076. DISCOVERY_OUT("midi.ins", midiIns);
  1077. DISCOVERY_OUT("midi.outs", midiOuts);
  1078. DISCOVERY_OUT("midi.total", midiTotal);
  1079. DISCOVERY_OUT("parameters.ins", parametersIns);
  1080. DISCOVERY_OUT("parameters.total", parametersTotal);
  1081. DISCOVERY_OUT("programs.total", programsTotal);
  1082. DISCOVERY_OUT("build", BINARY_NATIVE);
  1083. DISCOVERY_OUT("end", "------------");
  1084. if (vstCategory == kPlugCategShell)
  1085. {
  1086. carla_fill<char>(strBuf, STR_MAX+1, '\0');
  1087. if ((gVstCurrentUniqueId = effect->dispatcher(effect, effShellGetNextPlugin, 0, 0, strBuf, 0.0f)) != 0)
  1088. cName = strBuf;
  1089. }
  1090. else
  1091. break;
  1092. }
  1093. if (gVstNeedsIdle)
  1094. effect->dispatcher(effect, effIdle, 0, 0, nullptr, 0.0f);
  1095. effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
  1096. #else
  1097. DISCOVERY_OUT("error", "VST support not available");
  1098. return;
  1099. // unused
  1100. (void)libHandle;
  1101. (void)init;
  1102. #endif
  1103. }
  1104. void do_fluidsynth_check(const char* const filename, const bool init)
  1105. {
  1106. #ifdef WANT_FLUIDSYNTH
  1107. if (! fluid_is_soundfont(filename))
  1108. {
  1109. DISCOVERY_OUT("error", "Not a SF2 file");
  1110. return;
  1111. }
  1112. int programs = 0;
  1113. if (init)
  1114. {
  1115. fluid_settings_t* const f_settings = new_fluid_settings();
  1116. fluid_synth_t* const f_synth = new_fluid_synth(f_settings);
  1117. const int f_id = fluid_synth_sfload(f_synth, filename, 0);
  1118. if (f_id < 0)
  1119. {
  1120. DISCOVERY_OUT("error", "Failed to load SF2 file");
  1121. return;
  1122. }
  1123. fluid_sfont_t* f_sfont;
  1124. fluid_preset_t f_preset;
  1125. f_sfont = fluid_synth_get_sfont_by_id(f_synth, f_id);
  1126. f_sfont->iteration_start(f_sfont);
  1127. while (f_sfont->iteration_next(f_sfont, &f_preset))
  1128. programs += 1;
  1129. delete_fluid_synth(f_synth);
  1130. delete_fluid_settings(f_settings);
  1131. }
  1132. #ifdef CARLA_OS_WIN
  1133. int sep = '\\';
  1134. #else
  1135. int sep = '/';
  1136. #endif
  1137. CarlaString name(std::strrchr(filename, sep)+1);
  1138. name.truncate(name.rfind('.'));
  1139. CarlaString label(name);
  1140. // 2 channels
  1141. DISCOVERY_OUT("init", "-----------");
  1142. DISCOVERY_OUT("name", (const char*)name);
  1143. DISCOVERY_OUT("label", (const char*)label);
  1144. DISCOVERY_OUT("maker", "");
  1145. DISCOVERY_OUT("copyright", "");
  1146. DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
  1147. DISCOVERY_OUT("audio.outs", 2);
  1148. DISCOVERY_OUT("audio.total", 2);
  1149. DISCOVERY_OUT("midi.ins", 1);
  1150. DISCOVERY_OUT("midi.total", 1);
  1151. DISCOVERY_OUT("programs.total", programs);
  1152. DISCOVERY_OUT("parameters.ins", 13); // defined in Carla
  1153. DISCOVERY_OUT("parameters.outs", 1);
  1154. DISCOVERY_OUT("parameters.total", 14);
  1155. DISCOVERY_OUT("build", BINARY_NATIVE);
  1156. DISCOVERY_OUT("end", "------------");
  1157. // 16 channels
  1158. if (name.isNotEmpty())
  1159. name += " (16 outputs)";
  1160. DISCOVERY_OUT("init", "-----------");
  1161. DISCOVERY_OUT("name", "");
  1162. DISCOVERY_OUT("name", (const char*)name);
  1163. DISCOVERY_OUT("label", (const char*)label);
  1164. DISCOVERY_OUT("copyright", "");
  1165. DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
  1166. DISCOVERY_OUT("audio.outs", 32);
  1167. DISCOVERY_OUT("audio.total", 32);
  1168. DISCOVERY_OUT("midi.ins", 1);
  1169. DISCOVERY_OUT("midi.total", 1);
  1170. DISCOVERY_OUT("programs.total", programs);
  1171. DISCOVERY_OUT("parameters.ins", 13); // defined in Carla
  1172. DISCOVERY_OUT("parameters.outs", 1);
  1173. DISCOVERY_OUT("parameters.total", 14);
  1174. DISCOVERY_OUT("build", BINARY_NATIVE);
  1175. DISCOVERY_OUT("end", "------------");
  1176. #else
  1177. DISCOVERY_OUT("error", "SF2 support not available");
  1178. return;
  1179. // unused
  1180. (void)filename;
  1181. (void)init;
  1182. #endif
  1183. }
  1184. void do_linuxsampler_check(const char* const filename, const char* const stype, const bool init)
  1185. {
  1186. #ifdef WANT_LINUXSAMPLER
  1187. const QFileInfo file(filename);
  1188. if (! file.exists())
  1189. {
  1190. DISCOVERY_OUT("error", "Requested file does not exist");
  1191. return;
  1192. }
  1193. if (! file.isFile())
  1194. {
  1195. DISCOVERY_OUT("error", "Requested file is not valid");
  1196. return;
  1197. }
  1198. if (! file.isReadable())
  1199. {
  1200. DISCOVERY_OUT("error", "Requested file is not readable");
  1201. return;
  1202. }
  1203. if (init)
  1204. const LinuxSamplerScopedEngine engine(filename, stype);
  1205. else
  1206. LinuxSamplerScopedEngine::outputInfo(nullptr, 0, file.baseName().toUtf8().constData());
  1207. #else
  1208. DISCOVERY_OUT("error", stype << " support not available");
  1209. return;
  1210. // unused
  1211. (void)filename;
  1212. (void)init;
  1213. #endif
  1214. }
  1215. // ------------------------------ main entry point ------------------------------
  1216. int main(int argc, char* argv[])
  1217. {
  1218. if (argc == 2 && std::strcmp(argv[1], "-formats") == 0)
  1219. {
  1220. printf("Available plugin formats:\n");
  1221. printf("LADSPA: ");
  1222. #ifdef WANT_LADSPA
  1223. printf("yes\n");
  1224. #else
  1225. printf("no\n");
  1226. #endif
  1227. printf("DSSI: ");
  1228. #ifdef WANT_DSSI
  1229. printf("yes\n");
  1230. #else
  1231. printf("no\n");
  1232. #endif
  1233. printf("LV2: ");
  1234. #ifdef WANT_LV2
  1235. printf("yes\n");
  1236. #else
  1237. printf("no\n");
  1238. #endif
  1239. printf("VST: ");
  1240. #ifdef WANT_VST
  1241. printf("yes\n");
  1242. #else
  1243. printf("no\n");
  1244. #endif
  1245. printf("\n");
  1246. printf("Available sampler formats:\n");
  1247. printf("GIG (LinuxSampler): ");
  1248. #ifdef WANT_LINUXSAMPLER
  1249. printf("yes\n");
  1250. #else
  1251. printf("no\n");
  1252. #endif
  1253. printf("SF2 (FluidSynth): ");
  1254. #ifdef WANT_FLUIDSYNTH
  1255. printf("yes\n");
  1256. #else
  1257. printf("no\n");
  1258. #endif
  1259. printf("SFZ (LinuxSampler): ");
  1260. #ifdef WANT_LINUXSAMPLER
  1261. printf("yes\n");
  1262. #else
  1263. printf("no\n");
  1264. #endif
  1265. return 0;
  1266. }
  1267. if (argc != 3)
  1268. {
  1269. carla_stdout("usage: %s <type> </path/to/plugin>", argv[0]);
  1270. return 1;
  1271. }
  1272. const char* const stype = argv[1];
  1273. const char* const filename = argv[2];
  1274. const PluginType type = getPluginTypeFromString(stype);
  1275. bool openLib = false;
  1276. void* handle = nullptr;
  1277. switch (type)
  1278. {
  1279. case PLUGIN_LADSPA:
  1280. case PLUGIN_DSSI:
  1281. case PLUGIN_VST:
  1282. case PLUGIN_VST3:
  1283. openLib = true;
  1284. default:
  1285. break;
  1286. }
  1287. if (openLib)
  1288. {
  1289. handle = lib_open(filename);
  1290. if (handle == nullptr)
  1291. {
  1292. print_lib_error(filename);
  1293. return 1;
  1294. }
  1295. }
  1296. // never do init for dssi-vst, takes too long and it's crashy
  1297. #ifdef __USE_GNU
  1298. bool doInit = (strcasestr(filename, "dssi-vst") != nullptr);
  1299. #else
  1300. bool doInit = (std::strstr(filename, "dssi-vst") != nullptr);
  1301. #endif
  1302. if (doInit && getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS") != nullptr)
  1303. doInit = false;
  1304. if (doInit && handle != nullptr)
  1305. {
  1306. // test fast loading & unloading DLL without initializing the plugin(s)
  1307. if (! lib_close(handle))
  1308. {
  1309. print_lib_error(filename);
  1310. return 1;
  1311. }
  1312. handle = lib_open(filename);
  1313. if (handle == nullptr)
  1314. {
  1315. print_lib_error(filename);
  1316. return 1;
  1317. }
  1318. }
  1319. switch (type)
  1320. {
  1321. case PLUGIN_LADSPA:
  1322. do_ladspa_check(handle, doInit);
  1323. break;
  1324. case PLUGIN_DSSI:
  1325. do_dssi_check(handle, doInit);
  1326. break;
  1327. case PLUGIN_LV2:
  1328. do_lv2_check(filename, doInit);
  1329. break;
  1330. case PLUGIN_VST:
  1331. case PLUGIN_VST3:
  1332. do_vst_check(handle, doInit);
  1333. break;
  1334. case PLUGIN_GIG:
  1335. do_linuxsampler_check(filename, "gig", doInit);
  1336. break;
  1337. case PLUGIN_SF2:
  1338. do_fluidsynth_check(filename, doInit);
  1339. break;
  1340. case PLUGIN_SFZ:
  1341. do_linuxsampler_check(filename, "sfz", doInit);
  1342. break;
  1343. default:
  1344. break;
  1345. }
  1346. if (openLib && handle != nullptr)
  1347. lib_close(handle);
  1348. return 0;
  1349. }