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 60KB

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