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.

1614 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 = 0x080; // 0.8.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. #ifdef CARLA_PROPER_CPP11_SUPPORT
  1013. reserved(0),
  1014. data{0} {}
  1015. #else
  1016. reserved(0)
  1017. {
  1018. data[0] = data[1] = nullptr;
  1019. }
  1020. #endif
  1021. } events;
  1022. VstMidiEvent midiEvents[2];
  1023. carla_zeroStruct<VstMidiEvent>(midiEvents, 2);
  1024. midiEvents[0].type = kVstMidiType;
  1025. midiEvents[0].byteSize = sizeof(VstMidiEvent);
  1026. midiEvents[0].midiData[0] = MIDI_STATUS_NOTE_ON;
  1027. midiEvents[0].midiData[1] = 64;
  1028. midiEvents[0].midiData[2] = 100;
  1029. midiEvents[1].type = kVstMidiType;
  1030. midiEvents[1].byteSize = sizeof(VstMidiEvent);
  1031. midiEvents[1].midiData[0] = MIDI_STATUS_NOTE_OFF;
  1032. midiEvents[1].midiData[1] = 64;
  1033. midiEvents[1].deltaFrames = kBufferSize/2;
  1034. events.numEvents = 2;
  1035. events.reserved = 0;
  1036. events.data[0] = (VstEvent*)&midiEvents[0];
  1037. events.data[1] = (VstEvent*)&midiEvents[1];
  1038. // processing
  1039. {
  1040. if (midiIns > 0)
  1041. effect->dispatcher(effect, effProcessEvents, 0, 0, &events, 0.0f);
  1042. #if ! VST_FORCE_DEPRECATED
  1043. if ((effect->flags & effFlagsCanReplacing) > 0 && effect->processReplacing != nullptr && effect->processReplacing != effect->process)
  1044. effect->processReplacing(effect, bufferAudioIn, bufferAudioOut, kBufferSize);
  1045. else if (effect->process != nullptr)
  1046. effect->process(effect, bufferAudioIn, bufferAudioOut, kBufferSize);
  1047. else
  1048. DISCOVERY_OUT("error", "Plugin doesn't have a process function");
  1049. #else
  1050. CARLA_ASSERT(effect->flags & effFlagsCanReplacing);
  1051. if (effect->flags & effFlagsCanReplacing)
  1052. {
  1053. if (effect->processReplacing != nullptr)
  1054. effect->processReplacing(effect, bufferAudioIn, bufferAudioOut, bufferSize);
  1055. else
  1056. DISCOVERY_OUT("error", "Plugin doesn't have a process function");
  1057. }
  1058. else
  1059. DISCOVERY_OUT("error", "Plugin doesn't have can't do process replacing");
  1060. #endif
  1061. }
  1062. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  1063. effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  1064. if (gVstNeedsIdle)
  1065. effect->dispatcher(effect, effIdle, 0, 0, nullptr, 0.0f);
  1066. for (int j=0; j < audioIns; ++j)
  1067. delete[] bufferAudioIn[j];
  1068. for (int j=0; j < audioOuts; ++j)
  1069. delete[] bufferAudioOut[j];
  1070. }
  1071. // end crash-free plugin test
  1072. // -----------------------------------------------------------------------
  1073. DISCOVERY_OUT("init", "-----------");
  1074. DISCOVERY_OUT("name", (const char*)cName);
  1075. DISCOVERY_OUT("label", (const char*)cProduct);
  1076. DISCOVERY_OUT("maker", (const char*)cVendor);
  1077. DISCOVERY_OUT("copyright", (const char*)cVendor);
  1078. DISCOVERY_OUT("unique_id", gVstCurrentUniqueId);
  1079. DISCOVERY_OUT("hints", hints);
  1080. DISCOVERY_OUT("audio.ins", audioIns);
  1081. DISCOVERY_OUT("audio.outs", audioOuts);
  1082. DISCOVERY_OUT("audio.total", audioTotal);
  1083. DISCOVERY_OUT("midi.ins", midiIns);
  1084. DISCOVERY_OUT("midi.outs", midiOuts);
  1085. DISCOVERY_OUT("midi.total", midiTotal);
  1086. DISCOVERY_OUT("parameters.ins", parametersIns);
  1087. DISCOVERY_OUT("parameters.total", parametersTotal);
  1088. DISCOVERY_OUT("programs.total", programsTotal);
  1089. DISCOVERY_OUT("build", BINARY_NATIVE);
  1090. DISCOVERY_OUT("end", "------------");
  1091. if (vstCategory == kPlugCategShell)
  1092. {
  1093. carla_fill<char>(strBuf, STR_MAX+1, '\0');
  1094. if ((gVstCurrentUniqueId = effect->dispatcher(effect, effShellGetNextPlugin, 0, 0, strBuf, 0.0f)) != 0)
  1095. cName = strBuf;
  1096. }
  1097. else
  1098. break;
  1099. }
  1100. if (gVstNeedsIdle)
  1101. effect->dispatcher(effect, effIdle, 0, 0, nullptr, 0.0f);
  1102. effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
  1103. #else
  1104. DISCOVERY_OUT("error", "VST support not available");
  1105. return;
  1106. // unused
  1107. (void)libHandle;
  1108. (void)init;
  1109. #endif
  1110. }
  1111. void do_fluidsynth_check(const char* const filename, const bool init)
  1112. {
  1113. #ifdef WANT_FLUIDSYNTH
  1114. if (! fluid_is_soundfont(filename))
  1115. {
  1116. DISCOVERY_OUT("error", "Not a SF2 file");
  1117. return;
  1118. }
  1119. int programs = 0;
  1120. if (init)
  1121. {
  1122. fluid_settings_t* const f_settings = new_fluid_settings();
  1123. fluid_synth_t* const f_synth = new_fluid_synth(f_settings);
  1124. const int f_id = fluid_synth_sfload(f_synth, filename, 0);
  1125. if (f_id < 0)
  1126. {
  1127. DISCOVERY_OUT("error", "Failed to load SF2 file");
  1128. return;
  1129. }
  1130. fluid_sfont_t* f_sfont;
  1131. fluid_preset_t f_preset;
  1132. f_sfont = fluid_synth_get_sfont_by_id(f_synth, f_id);
  1133. f_sfont->iteration_start(f_sfont);
  1134. while (f_sfont->iteration_next(f_sfont, &f_preset))
  1135. programs += 1;
  1136. delete_fluid_synth(f_synth);
  1137. delete_fluid_settings(f_settings);
  1138. }
  1139. #ifdef CARLA_OS_WIN
  1140. int sep = '\\';
  1141. #else
  1142. int sep = '/';
  1143. #endif
  1144. CarlaString name(std::strrchr(filename, sep)+1);
  1145. name.truncate(name.rfind('.'));
  1146. CarlaString label(name);
  1147. // 2 channels
  1148. DISCOVERY_OUT("init", "-----------");
  1149. DISCOVERY_OUT("name", (const char*)name);
  1150. DISCOVERY_OUT("label", (const char*)label);
  1151. DISCOVERY_OUT("maker", "");
  1152. DISCOVERY_OUT("copyright", "");
  1153. DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
  1154. DISCOVERY_OUT("audio.outs", 2);
  1155. DISCOVERY_OUT("audio.total", 2);
  1156. DISCOVERY_OUT("midi.ins", 1);
  1157. DISCOVERY_OUT("midi.total", 1);
  1158. DISCOVERY_OUT("programs.total", programs);
  1159. DISCOVERY_OUT("parameters.ins", 13); // defined in Carla
  1160. DISCOVERY_OUT("parameters.outs", 1);
  1161. DISCOVERY_OUT("parameters.total", 14);
  1162. DISCOVERY_OUT("build", BINARY_NATIVE);
  1163. DISCOVERY_OUT("end", "------------");
  1164. // 16 channels
  1165. if (name.isNotEmpty())
  1166. name += " (16 outputs)";
  1167. DISCOVERY_OUT("init", "-----------");
  1168. DISCOVERY_OUT("name", "");
  1169. DISCOVERY_OUT("name", (const char*)name);
  1170. DISCOVERY_OUT("label", (const char*)label);
  1171. DISCOVERY_OUT("copyright", "");
  1172. DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
  1173. DISCOVERY_OUT("audio.outs", 32);
  1174. DISCOVERY_OUT("audio.total", 32);
  1175. DISCOVERY_OUT("midi.ins", 1);
  1176. DISCOVERY_OUT("midi.total", 1);
  1177. DISCOVERY_OUT("programs.total", programs);
  1178. DISCOVERY_OUT("parameters.ins", 13); // defined in Carla
  1179. DISCOVERY_OUT("parameters.outs", 1);
  1180. DISCOVERY_OUT("parameters.total", 14);
  1181. DISCOVERY_OUT("build", BINARY_NATIVE);
  1182. DISCOVERY_OUT("end", "------------");
  1183. #else
  1184. DISCOVERY_OUT("error", "SF2 support not available");
  1185. return;
  1186. // unused
  1187. (void)filename;
  1188. (void)init;
  1189. #endif
  1190. }
  1191. void do_linuxsampler_check(const char* const filename, const char* const stype, const bool init)
  1192. {
  1193. #ifdef WANT_LINUXSAMPLER
  1194. const QFileInfo file(filename);
  1195. if (! file.exists())
  1196. {
  1197. DISCOVERY_OUT("error", "Requested file does not exist");
  1198. return;
  1199. }
  1200. if (! file.isFile())
  1201. {
  1202. DISCOVERY_OUT("error", "Requested file is not valid");
  1203. return;
  1204. }
  1205. if (! file.isReadable())
  1206. {
  1207. DISCOVERY_OUT("error", "Requested file is not readable");
  1208. return;
  1209. }
  1210. if (init)
  1211. const LinuxSamplerScopedEngine engine(filename, stype);
  1212. else
  1213. LinuxSamplerScopedEngine::outputInfo(nullptr, 0, file.baseName().toUtf8().constData());
  1214. #else
  1215. DISCOVERY_OUT("error", stype << " support not available");
  1216. return;
  1217. // unused
  1218. (void)filename;
  1219. (void)init;
  1220. #endif
  1221. }
  1222. // ------------------------------ main entry point ------------------------------
  1223. int main(int argc, char* argv[])
  1224. {
  1225. if (argc == 2 && std::strcmp(argv[1], "-formats") == 0)
  1226. {
  1227. printf("Available plugin formats:\n");
  1228. printf("LADSPA: ");
  1229. #ifdef WANT_LADSPA
  1230. printf("yes\n");
  1231. #else
  1232. printf("no\n");
  1233. #endif
  1234. printf("DSSI: ");
  1235. #ifdef WANT_DSSI
  1236. printf("yes\n");
  1237. #else
  1238. printf("no\n");
  1239. #endif
  1240. printf("LV2: ");
  1241. #ifdef WANT_LV2
  1242. printf("yes\n");
  1243. #else
  1244. printf("no\n");
  1245. #endif
  1246. printf("VST: ");
  1247. #ifdef WANT_VST
  1248. printf("yes\n");
  1249. #else
  1250. printf("no\n");
  1251. #endif
  1252. printf("\n");
  1253. printf("Available sampler formats:\n");
  1254. printf("GIG (LinuxSampler): ");
  1255. #ifdef WANT_LINUXSAMPLER
  1256. printf("yes\n");
  1257. #else
  1258. printf("no\n");
  1259. #endif
  1260. printf("SF2 (FluidSynth): ");
  1261. #ifdef WANT_FLUIDSYNTH
  1262. printf("yes\n");
  1263. #else
  1264. printf("no\n");
  1265. #endif
  1266. printf("SFZ (LinuxSampler): ");
  1267. #ifdef WANT_LINUXSAMPLER
  1268. printf("yes\n");
  1269. #else
  1270. printf("no\n");
  1271. #endif
  1272. return 0;
  1273. }
  1274. if (argc != 3)
  1275. {
  1276. carla_stdout("usage: %s <type> </path/to/plugin>", argv[0]);
  1277. return 1;
  1278. }
  1279. const char* const stype = argv[1];
  1280. const char* const filename = argv[2];
  1281. const PluginType type = getPluginTypeFromString(stype);
  1282. bool openLib = false;
  1283. void* handle = nullptr;
  1284. switch (type)
  1285. {
  1286. case PLUGIN_LADSPA:
  1287. case PLUGIN_DSSI:
  1288. case PLUGIN_VST:
  1289. case PLUGIN_VST3:
  1290. openLib = true;
  1291. default:
  1292. break;
  1293. }
  1294. if (openLib)
  1295. {
  1296. handle = lib_open(filename);
  1297. if (handle == nullptr)
  1298. {
  1299. print_lib_error(filename);
  1300. return 1;
  1301. }
  1302. }
  1303. // never do init for dssi-vst, takes too long and it's crashy
  1304. #ifdef __USE_GNU
  1305. bool doInit = (strcasestr(filename, "dssi-vst") != nullptr);
  1306. #else
  1307. bool doInit = (std::strstr(filename, "dssi-vst") != nullptr);
  1308. #endif
  1309. if (doInit && getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS") != nullptr)
  1310. doInit = false;
  1311. if (doInit && handle != nullptr)
  1312. {
  1313. // test fast loading & unloading DLL without initializing the plugin(s)
  1314. if (! lib_close(handle))
  1315. {
  1316. print_lib_error(filename);
  1317. return 1;
  1318. }
  1319. handle = lib_open(filename);
  1320. if (handle == nullptr)
  1321. {
  1322. print_lib_error(filename);
  1323. return 1;
  1324. }
  1325. }
  1326. switch (type)
  1327. {
  1328. case PLUGIN_LADSPA:
  1329. do_ladspa_check(handle, doInit);
  1330. break;
  1331. case PLUGIN_DSSI:
  1332. do_dssi_check(handle, doInit);
  1333. break;
  1334. case PLUGIN_LV2:
  1335. do_lv2_check(filename, doInit);
  1336. break;
  1337. case PLUGIN_VST:
  1338. case PLUGIN_VST3:
  1339. do_vst_check(handle, doInit);
  1340. break;
  1341. case PLUGIN_GIG:
  1342. do_linuxsampler_check(filename, "gig", doInit);
  1343. break;
  1344. case PLUGIN_SF2:
  1345. do_fluidsynth_check(filename, doInit);
  1346. break;
  1347. case PLUGIN_SFZ:
  1348. do_linuxsampler_check(filename, "sfz", doInit);
  1349. break;
  1350. default:
  1351. break;
  1352. }
  1353. if (openLib && handle != nullptr)
  1354. lib_close(handle);
  1355. return 0;
  1356. }