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.

1695 lines
52KB

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