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.

1444 lines
45KB

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