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.

carla-discovery.cpp 55KB

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