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.

1511 lines
46KB

  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, "falkTX");
  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. if (! descriptor->instantiate)
  230. {
  231. DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no instantiate()");
  232. continue;
  233. }
  234. if (! descriptor->cleanup)
  235. {
  236. DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no cleanup()");
  237. continue;
  238. }
  239. if (! descriptor->run)
  240. {
  241. DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no run()");
  242. continue;
  243. }
  244. if (! LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties))
  245. {
  246. DISCOVERY_OUT("warning", "Plugin '" << descriptor->Name << "' is not hard real-time capable");
  247. }
  248. int hints = 0;
  249. int audioIns = 0;
  250. int audioOuts = 0;
  251. int audioTotal = 0;
  252. int parametersIns = 0;
  253. int parametersOuts = 0;
  254. int parametersTotal = 0;
  255. if (LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties))
  256. hints |= PLUGIN_IS_RTSAFE;
  257. for (unsigned long j=0; j < descriptor->PortCount; j++)
  258. {
  259. const LADSPA_PortDescriptor portDescriptor = descriptor->PortDescriptors[j];
  260. if (LADSPA_IS_PORT_AUDIO(portDescriptor))
  261. {
  262. if (LADSPA_IS_PORT_INPUT(portDescriptor))
  263. audioIns += 1;
  264. else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
  265. audioOuts += 1;
  266. audioTotal += 1;
  267. }
  268. else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
  269. {
  270. if (LADSPA_IS_PORT_INPUT(portDescriptor))
  271. parametersIns += 1;
  272. else if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && strcmp(descriptor->PortNames[j], "latency") && strcmp(descriptor->PortNames[j], "_latency"))
  273. parametersOuts += 1;
  274. parametersTotal += 1;
  275. }
  276. }
  277. if (init)
  278. {
  279. // -----------------------------------------------------------------------
  280. // start crash-free plugin test
  281. const LADSPA_Handle handle = descriptor->instantiate(descriptor, sampleRate);
  282. if (! handle)
  283. {
  284. DISCOVERY_OUT("error", "Failed to init LADSPA plugin");
  285. continue;
  286. }
  287. LADSPA_Data bufferAudio[bufferSize][audioTotal];
  288. LADSPA_Data bufferParams[parametersTotal];
  289. LADSPA_Data min, max, def;
  290. for (unsigned long j=0, iA=0, iC=0; j < descriptor->PortCount; j++)
  291. {
  292. const LADSPA_PortDescriptor portDescriptor = descriptor->PortDescriptors[j];
  293. const LADSPA_PortRangeHint portRangeHints = descriptor->PortRangeHints[j];
  294. const char* const portName = descriptor->PortNames[j];
  295. if (LADSPA_IS_PORT_AUDIO(portDescriptor))
  296. {
  297. carla_zeroFloat(bufferAudio[iA], bufferSize);
  298. descriptor->connect_port(handle, j, bufferAudio[iA++]);
  299. }
  300. else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
  301. {
  302. // min value
  303. if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
  304. min = portRangeHints.LowerBound;
  305. else
  306. min = 0.0f;
  307. // max value
  308. if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
  309. max = portRangeHints.UpperBound;
  310. else
  311. max = 1.0f;
  312. if (min > max)
  313. {
  314. DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: min > max");
  315. max = min + 0.1f;
  316. }
  317. else if (max - min == 0.0f)
  318. {
  319. DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: max - min == 0");
  320. max = min + 0.1f;
  321. }
  322. // default value
  323. def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
  324. if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
  325. {
  326. min *= sampleRate;
  327. max *= sampleRate;
  328. def *= sampleRate;
  329. }
  330. if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && (strcmp(portName, "latency") == 0 || strcmp(portName, "_latency") == 0))
  331. {
  332. // latency parameter
  333. def = 0.0f;
  334. }
  335. else
  336. {
  337. if (def < min)
  338. def = min;
  339. else if (def > max)
  340. def = max;
  341. }
  342. bufferParams[iC] = def;
  343. descriptor->connect_port(handle, j, &bufferParams[iC++]);
  344. }
  345. }
  346. if (descriptor->activate)
  347. descriptor->activate(handle);
  348. descriptor->run(handle, bufferSize);
  349. if (descriptor->deactivate)
  350. descriptor->deactivate(handle);
  351. descriptor->cleanup(handle);
  352. // end crash-free plugin test
  353. // -----------------------------------------------------------------------
  354. }
  355. DISCOVERY_OUT("init", "-----------");
  356. DISCOVERY_OUT("name", descriptor->Name);
  357. DISCOVERY_OUT("label", descriptor->Label);
  358. DISCOVERY_OUT("maker", descriptor->Maker);
  359. DISCOVERY_OUT("copyright", descriptor->Copyright);
  360. DISCOVERY_OUT("uniqueId", descriptor->UniqueID);
  361. DISCOVERY_OUT("hints", hints);
  362. DISCOVERY_OUT("audio.ins", audioIns);
  363. DISCOVERY_OUT("audio.outs", audioOuts);
  364. DISCOVERY_OUT("audio.total", audioTotal);
  365. DISCOVERY_OUT("parameters.ins", parametersIns);
  366. DISCOVERY_OUT("parameters.outs", parametersOuts);
  367. DISCOVERY_OUT("parameters.total", parametersTotal);
  368. DISCOVERY_OUT("build", BINARY_NATIVE);
  369. DISCOVERY_OUT("end", "------------");
  370. }
  371. #else
  372. DISCOVERY_OUT("error", "LADSPA support not available");
  373. Q_UNUSED(libHandle);
  374. Q_UNUSED(init);
  375. #endif
  376. }
  377. void do_dssi_check(void* const libHandle, const bool init)
  378. {
  379. #ifdef WANT_DSSI
  380. const DSSI_Descriptor_Function descFn = (DSSI_Descriptor_Function)lib_symbol(libHandle, "dssi_descriptor");
  381. if (! descFn)
  382. {
  383. DISCOVERY_OUT("error", "Not a DSSI plugin");
  384. return;
  385. }
  386. unsigned long i = 0;
  387. const DSSI_Descriptor* descriptor;
  388. while ((descriptor = descFn(i++)))
  389. {
  390. const LADSPA_Descriptor* const ldescriptor = descriptor->LADSPA_Plugin;
  391. if (! ldescriptor)
  392. {
  393. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no LADSPA interface");
  394. continue;
  395. }
  396. if (! ldescriptor->instantiate)
  397. {
  398. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no instantiate()");
  399. continue;
  400. }
  401. if (! ldescriptor->cleanup)
  402. {
  403. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no cleanup()");
  404. continue;
  405. }
  406. if (! (ldescriptor->run || descriptor->run_synth || descriptor->run_multiple_synths))
  407. {
  408. DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no run(), run_synth() or run_multiple_synths()");
  409. continue;
  410. }
  411. if (! LADSPA_IS_HARD_RT_CAPABLE(ldescriptor->Properties))
  412. {
  413. DISCOVERY_OUT("warning", "Plugin '" << ldescriptor->Name << "' is not hard real-time capable");
  414. }
  415. int hints = 0;
  416. int audioIns = 0;
  417. int audioOuts = 0;
  418. int audioTotal = 0;
  419. int midiIns = 0;
  420. int midiTotal = 0;
  421. int parametersIns = 0;
  422. int parametersOuts = 0;
  423. int parametersTotal = 0;
  424. int programsTotal = 0;
  425. if (LADSPA_IS_HARD_RT_CAPABLE(ldescriptor->Properties))
  426. hints |= PLUGIN_IS_RTSAFE;
  427. for (unsigned long j=0; j < ldescriptor->PortCount; j++)
  428. {
  429. const LADSPA_PortDescriptor portDescriptor = ldescriptor->PortDescriptors[j];
  430. if (LADSPA_IS_PORT_AUDIO(portDescriptor))
  431. {
  432. if (LADSPA_IS_PORT_INPUT(portDescriptor))
  433. audioIns += 1;
  434. else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
  435. audioOuts += 1;
  436. audioTotal += 1;
  437. }
  438. else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
  439. {
  440. if (LADSPA_IS_PORT_INPUT(portDescriptor))
  441. parametersIns += 1;
  442. else if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && strcmp(ldescriptor->PortNames[j], "latency") && strcmp(ldescriptor->PortNames[j], "_latency"))
  443. parametersOuts += 1;
  444. parametersTotal += 1;
  445. }
  446. }
  447. if (descriptor->run_synth || descriptor->run_multiple_synths)
  448. midiIns = midiTotal = 1;
  449. if (midiIns > 0 && audioIns == 0 && audioOuts > 0)
  450. hints |= PLUGIN_IS_SYNTH;
  451. if (init)
  452. {
  453. // -----------------------------------------------------------------------
  454. // start crash-free plugin test
  455. const LADSPA_Handle handle = ldescriptor->instantiate(ldescriptor, sampleRate);
  456. if (! handle)
  457. {
  458. DISCOVERY_OUT("error", "Failed to init DSSI plugin");
  459. continue;
  460. }
  461. if (descriptor->get_program && descriptor->select_program)
  462. {
  463. while (descriptor->get_program(handle, programsTotal++))
  464. continue;
  465. }
  466. LADSPA_Data bufferAudio[bufferSize][audioTotal];
  467. LADSPA_Data bufferParams[parametersTotal];
  468. LADSPA_Data min, max, def;
  469. for (unsigned long j=0, iA=0, iC=0; j < ldescriptor->PortCount; j++)
  470. {
  471. const LADSPA_PortDescriptor portDescriptor = ldescriptor->PortDescriptors[j];
  472. const LADSPA_PortRangeHint portRangeHints = ldescriptor->PortRangeHints[j];
  473. const char* const portName = ldescriptor->PortNames[j];
  474. if (LADSPA_IS_PORT_AUDIO(portDescriptor))
  475. {
  476. carla_zeroFloat(bufferAudio[iA], bufferSize);
  477. ldescriptor->connect_port(handle, j, bufferAudio[iA++]);
  478. }
  479. else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
  480. {
  481. // min value
  482. if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
  483. min = portRangeHints.LowerBound;
  484. else
  485. min = 0.0f;
  486. // max value
  487. if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
  488. max = portRangeHints.UpperBound;
  489. else
  490. max = 1.0f;
  491. if (min > max)
  492. {
  493. DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: min > max");
  494. max = min + 0.1f;
  495. }
  496. else if (max - min == 0.0f)
  497. {
  498. DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: max - min == 0");
  499. max = min + 0.1f;
  500. }
  501. // default value
  502. def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
  503. if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
  504. {
  505. min *= sampleRate;
  506. max *= sampleRate;
  507. def *= sampleRate;
  508. }
  509. if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && (strcmp(portName, "latency") == 0 || strcmp(portName, "_latency") == 0))
  510. {
  511. // latency parameter
  512. def = 0.0f;
  513. }
  514. else
  515. {
  516. if (def < min)
  517. def = min;
  518. else if (def > max)
  519. def = max;
  520. }
  521. bufferParams[iC] = def;
  522. ldescriptor->connect_port(handle, j, &bufferParams[iC++]);
  523. }
  524. }
  525. // select first midi-program if available
  526. if (programsTotal > 0)
  527. {
  528. if (const DSSI_Program_Descriptor* const pDesc = descriptor->get_program(handle, 0))
  529. descriptor->select_program(handle, pDesc->Bank, pDesc->Program);
  530. }
  531. if (ldescriptor->activate)
  532. ldescriptor->activate(handle);
  533. if (descriptor->run_synth || descriptor->run_multiple_synths)
  534. {
  535. snd_seq_event_t midiEvents[2];
  536. memset(midiEvents, 0, sizeof(snd_seq_event_t)*2);
  537. const unsigned long midiEventCount = 2;
  538. midiEvents[0].type = SND_SEQ_EVENT_NOTEON;
  539. midiEvents[0].data.note.note = 64;
  540. midiEvents[0].data.note.velocity = 100;
  541. midiEvents[1].type = SND_SEQ_EVENT_NOTEOFF;
  542. midiEvents[1].data.note.note = 64;
  543. midiEvents[1].data.note.velocity = 0;
  544. midiEvents[1].time.tick = bufferSize/2;
  545. if (descriptor->run_multiple_synths && ! descriptor->run_synth)
  546. {
  547. LADSPA_Handle handlePtr[1] = { handle };
  548. snd_seq_event_t* midiEventsPtr[1] = { midiEvents };
  549. unsigned long midiEventCountPtr[1] = { midiEventCount };
  550. descriptor->run_multiple_synths(1, handlePtr, bufferSize, midiEventsPtr, midiEventCountPtr);
  551. }
  552. else
  553. descriptor->run_synth(handle, bufferSize, midiEvents, midiEventCount);
  554. }
  555. else
  556. ldescriptor->run(handle, bufferSize);
  557. if (ldescriptor->deactivate)
  558. ldescriptor->deactivate(handle);
  559. ldescriptor->cleanup(handle);
  560. // end crash-free plugin test
  561. // -----------------------------------------------------------------------
  562. }
  563. DISCOVERY_OUT("init", "-----------");
  564. DISCOVERY_OUT("name", ldescriptor->Name);
  565. DISCOVERY_OUT("label", ldescriptor->Label);
  566. DISCOVERY_OUT("maker", ldescriptor->Maker);
  567. DISCOVERY_OUT("copyright", ldescriptor->Copyright);
  568. DISCOVERY_OUT("unique_id", ldescriptor->UniqueID);
  569. DISCOVERY_OUT("hints", hints);
  570. DISCOVERY_OUT("audio.ins", audioIns);
  571. DISCOVERY_OUT("audio.outs", audioOuts);
  572. DISCOVERY_OUT("audio.total", audioTotal);
  573. DISCOVERY_OUT("midi.ins", midiIns);
  574. DISCOVERY_OUT("midi.total", midiTotal);
  575. DISCOVERY_OUT("parameters.ins", parametersIns);
  576. DISCOVERY_OUT("parameters.outs", parametersOuts);
  577. DISCOVERY_OUT("parameters.total", parametersTotal);
  578. DISCOVERY_OUT("programs.total", programsTotal);
  579. DISCOVERY_OUT("build", BINARY_NATIVE);
  580. DISCOVERY_OUT("end", "------------");
  581. }
  582. #else
  583. DISCOVERY_OUT("error", "DSSI support not available");
  584. Q_UNUSED(libHandle);
  585. Q_UNUSED(init);
  586. #endif
  587. }
  588. void do_lv2_check(const char* const bundle, const bool init)
  589. {
  590. #ifdef WANT_LV2
  591. // Convert bundle filename to URI
  592. QString qBundle(QUrl::fromLocalFile(bundle).toString());
  593. if (! qBundle.endsWith(QDir::separator()))
  594. qBundle += QDir::separator();
  595. // Load bundle
  596. Lilv::Node lilvBundle(lv2World.new_uri(qBundle.toUtf8().constData()));
  597. lv2World.load_bundle(lilvBundle);
  598. // Load plugins in this bundle
  599. const Lilv::Plugins lilvPlugins = lv2World.get_all_plugins();
  600. // Get all plugin URIs in this bundle
  601. QStringList URIs;
  602. LILV_FOREACH(plugins, i, lilvPlugins)
  603. {
  604. Lilv::Plugin lilvPlugin(lilv_plugins_get(lilvPlugins, i));
  605. if (const char* const uri = lilvPlugin.get_uri().as_string())
  606. URIs.append(QString(uri));
  607. }
  608. // Get & check every plugin-instance
  609. for (int i=0; i < URIs.count(); i++)
  610. {
  611. const LV2_RDF_Descriptor* const rdfDescriptor = lv2_rdf_new(URIs.at(i).toUtf8().constData());
  612. CARLA_ASSERT(rdfDescriptor && rdfDescriptor->URI);
  613. if (! (rdfDescriptor && rdfDescriptor->URI))
  614. {
  615. DISCOVERY_OUT("error", "Failed to find LV2 plugin '" << URIs.at(i).toUtf8().constData() << "'");
  616. continue;
  617. }
  618. if (init)
  619. {
  620. // test if DLL is loadable, twice
  621. bool isLoadable = true;
  622. for (int j=0; j < 2; j++)
  623. {
  624. void* const libHandle = lib_open(rdfDescriptor->Binary);
  625. if (! libHandle)
  626. {
  627. isLoadable = false;
  628. print_lib_error(rdfDescriptor->Binary);
  629. delete rdfDescriptor;
  630. break;
  631. }
  632. lib_close(libHandle);
  633. }
  634. if (! isLoadable)
  635. continue;
  636. }
  637. // test if we support all required ports and features
  638. {
  639. bool supported = true;
  640. for (uint32_t j=0; j < rdfDescriptor->PortCount && supported; j++)
  641. {
  642. const LV2_RDF_Port* const rdfPort = &rdfDescriptor->Ports[j];
  643. if (is_lv2_port_supported(rdfPort->Types))
  644. {
  645. pass();
  646. }
  647. else if (! LV2_IS_PORT_OPTIONAL(rdfPort->Properties))
  648. {
  649. DISCOVERY_OUT("error", "Plugin '" << rdfDescriptor->URI << "' requires a non-supported port type (portName: '" << rdfPort->Name << "')");
  650. supported = false;
  651. break;
  652. }
  653. }
  654. for (uint32_t j=0; j < rdfDescriptor->FeatureCount && supported; j++)
  655. {
  656. const LV2_RDF_Feature* const rdfFeature = &rdfDescriptor->Features[j];
  657. if (is_lv2_feature_supported(rdfFeature->URI))
  658. {
  659. pass();
  660. }
  661. else if (LV2_IS_FEATURE_REQUIRED(rdfFeature->Type))
  662. {
  663. DISCOVERY_OUT("error", "Plugin '" << rdfDescriptor->URI << "' requires a non-supported feature '" << rdfFeature->URI << "'");
  664. supported = false;
  665. break;
  666. }
  667. }
  668. if (! supported)
  669. {
  670. delete rdfDescriptor;
  671. continue;
  672. }
  673. }
  674. int hints = 0;
  675. int audioIns = 0;
  676. int audioOuts = 0;
  677. int audioTotal = 0;
  678. int midiIns = 0;
  679. int midiOuts = 0;
  680. int midiTotal = 0;
  681. int parametersIns = 0;
  682. int parametersOuts = 0;
  683. int parametersTotal = 0;
  684. int programsTotal = rdfDescriptor->PresetCount;
  685. for (uint32_t j=0; j < rdfDescriptor->FeatureCount; j++)
  686. {
  687. const LV2_RDF_Feature* const rdfFeature = &rdfDescriptor->Features[j];
  688. if (strcmp(rdfFeature->URI, LV2_CORE__hardRTCapable) == 0)
  689. hints |= PLUGIN_IS_RTSAFE;
  690. }
  691. for (uint32_t j=0; j < rdfDescriptor->PortCount; j++)
  692. {
  693. const LV2_RDF_Port* const rdfPort = &rdfDescriptor->Ports[j];
  694. if (LV2_IS_PORT_AUDIO(rdfPort->Types))
  695. {
  696. if (LV2_IS_PORT_INPUT(rdfPort->Types))
  697. audioIns += 1;
  698. else if (LV2_IS_PORT_OUTPUT(rdfPort->Types))
  699. audioOuts += 1;
  700. audioTotal += 1;
  701. }
  702. else if (LV2_IS_PORT_CONTROL(rdfPort->Types))
  703. {
  704. if (LV2_IS_PORT_DESIGNATION_LATENCY(rdfPort->Designation))
  705. {
  706. pass();
  707. }
  708. else if (LV2_IS_PORT_DESIGNATION_SAMPLE_RATE(rdfPort->Designation))
  709. {
  710. pass();
  711. }
  712. else if (LV2_IS_PORT_DESIGNATION_FREEWHEELING(rdfPort->Designation))
  713. {
  714. pass();
  715. }
  716. else if (LV2_IS_PORT_DESIGNATION_TIME(rdfPort->Designation))
  717. {
  718. pass();
  719. }
  720. else
  721. {
  722. if (LV2_IS_PORT_INPUT(rdfPort->Types))
  723. parametersIns += 1;
  724. else if (LV2_IS_PORT_OUTPUT(rdfPort->Types))
  725. parametersOuts += 1;
  726. parametersTotal += 1;
  727. }
  728. }
  729. else if (LV2_PORT_SUPPORTS_MIDI_EVENT(rdfPort->Types))
  730. {
  731. if (LV2_IS_PORT_INPUT(rdfPort->Types))
  732. midiIns += 1;
  733. else if (LV2_IS_PORT_OUTPUT(rdfPort->Types))
  734. midiOuts += 1;
  735. midiTotal += 1;
  736. }
  737. }
  738. if (rdfDescriptor->Type[1] & LV2_PLUGIN_INSTRUMENT)
  739. hints |= PLUGIN_IS_SYNTH;
  740. if (rdfDescriptor->UICount > 0)
  741. hints |= PLUGIN_HAS_GUI;
  742. DISCOVERY_OUT("init", "-----------");
  743. DISCOVERY_OUT("label", rdfDescriptor->URI);
  744. if (rdfDescriptor->Name)
  745. DISCOVERY_OUT("name", rdfDescriptor->Name);
  746. if (rdfDescriptor->Author)
  747. DISCOVERY_OUT("maker", rdfDescriptor->Author);
  748. if (rdfDescriptor->License)
  749. DISCOVERY_OUT("copyright", rdfDescriptor->License);
  750. DISCOVERY_OUT("unique_id", rdfDescriptor->UniqueID);
  751. DISCOVERY_OUT("hints", hints);
  752. DISCOVERY_OUT("audio.ins", audioIns);
  753. DISCOVERY_OUT("audio.outs", audioOuts);
  754. DISCOVERY_OUT("audio.total", audioTotal);
  755. DISCOVERY_OUT("midi.ins", midiIns);
  756. DISCOVERY_OUT("midi.outs", midiOuts);
  757. DISCOVERY_OUT("midi.total", midiTotal);
  758. DISCOVERY_OUT("parameters.ins", parametersIns);
  759. DISCOVERY_OUT("parameters.outs", parametersOuts);
  760. DISCOVERY_OUT("parameters.total", parametersTotal);
  761. DISCOVERY_OUT("programs.total", programsTotal);
  762. DISCOVERY_OUT("build", BINARY_NATIVE);
  763. DISCOVERY_OUT("end", "------------");
  764. delete rdfDescriptor;
  765. }
  766. #else
  767. DISCOVERY_OUT("error", "LV2 support not available");
  768. Q_UNUSED(bundle);
  769. Q_UNUSED(init);
  770. #endif
  771. }
  772. void do_vst_check(void* const libHandle, const bool init)
  773. {
  774. #ifdef WANT_VST
  775. VST_Function vstFn = (VST_Function)lib_symbol(libHandle, "VSTPluginMain");
  776. if (! vstFn)
  777. {
  778. vstFn = (VST_Function)lib_symbol(libHandle, "main");
  779. if (! vstFn)
  780. {
  781. DISCOVERY_OUT("error", "Not a VST plugin");
  782. return;
  783. }
  784. }
  785. AEffect* const effect = vstFn(vstHostCallback);
  786. if (! (effect && effect->magic == kEffectMagic))
  787. {
  788. DISCOVERY_OUT("error", "Failed to init VST plugin, or VST magic failed");
  789. return;
  790. }
  791. char strBuf[STR_MAX] = { 0 };
  792. CarlaString cName;
  793. CarlaString cProduct;
  794. CarlaString cVendor;
  795. effect->dispatcher(effect, effOpen, 0, 0, nullptr, 0.0f);
  796. intptr_t vstCategory = effect->dispatcher(effect, effGetPlugCategory, 0, 0, nullptr, 0.0f);
  797. if (vstCategory == kPlugCategShell && effect->uniqueID == 0)
  798. {
  799. if ((vstCurrentUniqueId = effect->dispatcher(effect, effShellGetNextPlugin, 0, 0, strBuf, 0.0f)) != 0)
  800. cName = strBuf;
  801. }
  802. else
  803. {
  804. vstCurrentUniqueId = effect->uniqueID;
  805. if (effect->dispatcher(effect, effGetEffectName, 0, 0, strBuf, 0.0f) == 1)
  806. cName = strBuf;
  807. }
  808. memset(strBuf, 0, sizeof(char)*STR_MAX);
  809. if (effect->dispatcher(effect, effGetVendorString, 0, 0, strBuf, 0.0f) == 1)
  810. cVendor = strBuf;
  811. // FIXME: Waves crash during processing
  812. if (cVendor == "Waves")
  813. memset((void*)&init, 0, sizeof(bool));
  814. if (vstCurrentUniqueId == 0)
  815. {
  816. DISCOVERY_OUT("error", "Plugin doesn't have an Unique ID");
  817. return;
  818. }
  819. while (vstCurrentUniqueId != 0)
  820. {
  821. memset(strBuf, 0, sizeof(char)*STR_MAX);
  822. if (effect->dispatcher(effect, effGetProductString, 0, 0, strBuf, 0.0f) == 1)
  823. cProduct = strBuf;
  824. else
  825. cProduct.clear();
  826. vstWantsMidi = false;
  827. int hints = 0;
  828. int audioIns = effect->numInputs;
  829. int audioOuts = effect->numOutputs;
  830. int audioTotal = audioIns + audioOuts;
  831. int midiIns = 0;
  832. int midiOuts = 0;
  833. int midiTotal = 0;
  834. int parametersIns = effect->numParams;
  835. int parametersTotal = parametersIns;
  836. int programsTotal = effect->numPrograms;
  837. if (effect->flags & effFlagsHasEditor)
  838. hints |= PLUGIN_HAS_GUI;
  839. if (effect->flags & effFlagsIsSynth)
  840. hints |= PLUGIN_IS_SYNTH;
  841. if (vstPluginCanDo(effect, "receiveVstEvents") || vstPluginCanDo(effect, "receiveVstMidiEvent") || (effect->flags & effFlagsIsSynth) > 0)
  842. midiIns = 1;
  843. if (vstPluginCanDo(effect, "sendVstEvents") || vstPluginCanDo(effect, "sendVstMidiEvent"))
  844. midiOuts = 1;
  845. midiTotal = midiIns + midiOuts;
  846. // -----------------------------------------------------------------------
  847. // start crash-free plugin test
  848. if (init)
  849. {
  850. #if ! VST_FORCE_DEPRECATED
  851. effect->dispatcher(effect, effSetBlockSizeAndSampleRate, 0, bufferSize, nullptr, sampleRate);
  852. #endif
  853. effect->dispatcher(effect, effSetBlockSize, 0, bufferSize, nullptr, 0.0f);
  854. effect->dispatcher(effect, effSetSampleRate, 0, 0, nullptr, sampleRate);
  855. effect->dispatcher(effect, effSetProcessPrecision, 0, kVstProcessPrecision32, nullptr, 0.0f);
  856. effect->dispatcher(effect, effMainsChanged, 0, 1, nullptr, 0.0f);
  857. effect->dispatcher(effect, effStartProcess, 0, 0, nullptr, 0.0f);
  858. // Plugin might call wantMidi() during resume
  859. if (midiIns == 0 && vstWantsMidi)
  860. {
  861. midiIns = 1;
  862. midiTotal = midiIns + midiOuts;
  863. }
  864. float* bufferAudioIn[audioIns];
  865. for (int j=0; j < audioIns; j++)
  866. {
  867. bufferAudioIn[j] = new float [bufferSize];
  868. carla_zeroFloat(bufferAudioIn[j], bufferSize);
  869. }
  870. float* bufferAudioOut[audioOuts];
  871. for (int j=0; j < audioOuts; j++)
  872. {
  873. bufferAudioOut[j] = new float [bufferSize];
  874. carla_zeroFloat(bufferAudioOut[j], bufferSize);
  875. }
  876. struct VstEventsFixed {
  877. int32_t numEvents;
  878. intptr_t reserved;
  879. VstEvent* data[2];
  880. };
  881. VstEventsFixed events;
  882. VstMidiEvent midiEvents[2];
  883. memset(&events, 0, sizeof(VstEventsFixed));
  884. memset(midiEvents, 0, sizeof(VstMidiEvent)*2);
  885. midiEvents[0].type = kVstMidiType;
  886. midiEvents[0].byteSize = sizeof(VstMidiEvent);
  887. midiEvents[0].midiData[0] = MIDI_STATUS_NOTE_ON;
  888. midiEvents[0].midiData[1] = 64;
  889. midiEvents[0].midiData[2] = 100;
  890. midiEvents[1].type = kVstMidiType;
  891. midiEvents[1].byteSize = sizeof(VstMidiEvent);
  892. midiEvents[1].midiData[0] = MIDI_STATUS_NOTE_OFF;
  893. midiEvents[1].midiData[1] = 64;
  894. midiEvents[1].deltaFrames = bufferSize/2;
  895. events.numEvents = 2;
  896. events.data[0] = (VstEvent*)&midiEvents[0];
  897. events.data[1] = (VstEvent*)&midiEvents[1];
  898. // processing
  899. {
  900. vstIsProcessing = true;
  901. if (midiIns > 0)
  902. effect->dispatcher(effect, effProcessEvents, 0, 0, &events, 0.0f);
  903. #if ! VST_FORCE_DEPRECATED
  904. if ((effect->flags & effFlagsCanReplacing) > 0 && effect->processReplacing && effect->processReplacing != effect->process)
  905. effect->processReplacing(effect, bufferAudioIn, bufferAudioOut, bufferSize);
  906. else if (effect->process)
  907. effect->process(effect, bufferAudioIn, bufferAudioOut, bufferSize);
  908. else
  909. DISCOVERY_OUT("error", "Plugin doesn't have a process function");
  910. #else
  911. CARLA_ASSERT(effect->flags & effFlagsCanReplacing);
  912. if (effect->flags & effFlagsCanReplacing)
  913. {
  914. if (effect->processReplacing)
  915. effect->processReplacing(effect, bufferAudioIn, bufferAudioOut, bufferSize);
  916. else
  917. DISCOVERY_OUT("error", "Plugin doesn't have a process function");
  918. }
  919. else
  920. DISCOVERY_OUT("error", "Plugin doesn't have can't do process replacing");
  921. #endif
  922. vstIsProcessing = false;
  923. }
  924. effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
  925. effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
  926. for (int j=0; j < audioIns; j++)
  927. delete[] bufferAudioIn[j];
  928. for (int j=0; j < audioOuts; j++)
  929. delete[] bufferAudioOut[j];
  930. }
  931. // end crash-free plugin test
  932. // -----------------------------------------------------------------------
  933. DISCOVERY_OUT("init", "-----------");
  934. DISCOVERY_OUT("name", (const char*)cName);
  935. DISCOVERY_OUT("label", (const char*)cProduct);
  936. DISCOVERY_OUT("maker", (const char*)cVendor);
  937. DISCOVERY_OUT("copyright", (const char*)cVendor);
  938. DISCOVERY_OUT("unique_id", vstCurrentUniqueId);
  939. DISCOVERY_OUT("hints", hints);
  940. DISCOVERY_OUT("audio.ins", audioIns);
  941. DISCOVERY_OUT("audio.outs", audioOuts);
  942. DISCOVERY_OUT("audio.total", audioTotal);
  943. DISCOVERY_OUT("midi.ins", midiIns);
  944. DISCOVERY_OUT("midi.outs", midiOuts);
  945. DISCOVERY_OUT("midi.total", midiTotal);
  946. DISCOVERY_OUT("parameters.ins", parametersIns);
  947. DISCOVERY_OUT("parameters.total", parametersTotal);
  948. DISCOVERY_OUT("programs.total", programsTotal);
  949. DISCOVERY_OUT("build", BINARY_NATIVE);
  950. DISCOVERY_OUT("end", "------------");
  951. if (vstCategory != kPlugCategShell)
  952. break;
  953. // request next Unique ID
  954. intptr_t nextUniqueId = vstCurrentUniqueId;
  955. // FIXME: Waves sometimes return the same ID
  956. while (nextUniqueId == vstCurrentUniqueId)
  957. {
  958. memset(strBuf, 0, sizeof(char)*STR_MAX);
  959. if ((vstCurrentUniqueId = effect->dispatcher(effect, effShellGetNextPlugin, 0, 0, strBuf, 0.0f)) != 0)
  960. cName = strBuf;
  961. }
  962. }
  963. effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
  964. #else
  965. DISCOVERY_OUT("error", "VST support not available");
  966. Q_UNUSED(libHandle);
  967. Q_UNUSED(init);
  968. #endif
  969. }
  970. void do_fluidsynth_check(const char* const filename, const bool init)
  971. {
  972. #ifdef WANT_FLUIDSYNTH
  973. if (! fluid_is_soundfont(filename))
  974. {
  975. DISCOVERY_OUT("error", "Not a SF2 file");
  976. return;
  977. }
  978. int programs = 0;
  979. if (init)
  980. {
  981. fluid_settings_t* const f_settings = new_fluid_settings();
  982. fluid_synth_t* const f_synth = new_fluid_synth(f_settings);
  983. const int f_id = fluid_synth_sfload(f_synth, filename, 0);
  984. if (f_id < 0)
  985. {
  986. DISCOVERY_OUT("error", "Failed to load SF2 file");
  987. return;
  988. }
  989. fluid_sfont_t* f_sfont;
  990. fluid_preset_t f_preset;
  991. f_sfont = fluid_synth_get_sfont_by_id(f_synth, f_id);
  992. f_sfont->iteration_start(f_sfont);
  993. while (f_sfont->iteration_next(f_sfont, &f_preset))
  994. programs += 1;
  995. delete_fluid_synth(f_synth);
  996. delete_fluid_settings(f_settings);
  997. }
  998. DISCOVERY_OUT("init", "-----------");
  999. DISCOVERY_OUT("name", "");
  1000. DISCOVERY_OUT("label", "");
  1001. DISCOVERY_OUT("maker", "");
  1002. DISCOVERY_OUT("copyright", "");
  1003. DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
  1004. DISCOVERY_OUT("audio.outs", 2);
  1005. DISCOVERY_OUT("audio.total", 2);
  1006. DISCOVERY_OUT("midi.ins", 1);
  1007. DISCOVERY_OUT("midi.total", 1);
  1008. DISCOVERY_OUT("programs.total", programs);
  1009. DISCOVERY_OUT("parameters.ins", 13); // defined in Carla
  1010. DISCOVERY_OUT("parameters.outs", 1);
  1011. DISCOVERY_OUT("parameters.total", 14);
  1012. DISCOVERY_OUT("build", BINARY_NATIVE);
  1013. DISCOVERY_OUT("end", "------------");
  1014. #else
  1015. DISCOVERY_OUT("error", "SF2 support not available");
  1016. Q_UNUSED(filename);
  1017. Q_UNUSED(init);
  1018. #endif
  1019. }
  1020. void do_linuxsampler_check(const char* const filename, const char* const stype, const bool init)
  1021. {
  1022. #ifdef WANT_LINUXSAMPLER
  1023. const QFileInfo file(filename);
  1024. if (! file.exists())
  1025. {
  1026. DISCOVERY_OUT("error", "Requested file does not exist");
  1027. return;
  1028. }
  1029. if (! file.isFile())
  1030. {
  1031. DISCOVERY_OUT("error", "Requested file is not valid");
  1032. return;
  1033. }
  1034. if (! file.isReadable())
  1035. {
  1036. DISCOVERY_OUT("error", "Requested file is not readable");
  1037. return;
  1038. }
  1039. using namespace LinuxSampler;
  1040. class LinuxSamplerScopedEngine {
  1041. public:
  1042. LinuxSamplerScopedEngine(const char* const filename, const char* const stype)
  1043. {
  1044. engine = nullptr;
  1045. try {
  1046. engine = EngineFactory::Create(stype);
  1047. }
  1048. catch (const Exception& e)
  1049. {
  1050. DISCOVERY_OUT("error", e.what());
  1051. return;
  1052. }
  1053. if (! engine)
  1054. return;
  1055. ins = engine->GetInstrumentManager();
  1056. if (! ins)
  1057. {
  1058. DISCOVERY_OUT("error", "Failed to get LinuxSampler instrument manager");
  1059. return;
  1060. }
  1061. std::vector<InstrumentManager::instrument_id_t> ids;
  1062. try {
  1063. ids = ins->GetInstrumentFileContent(filename);
  1064. }
  1065. catch (const Exception& e)
  1066. {
  1067. DISCOVERY_OUT("error", e.what());
  1068. return;
  1069. }
  1070. if (ids.size() > 0)
  1071. {
  1072. InstrumentManager::instrument_info_t info = ins->GetInstrumentInfo(ids[0]);
  1073. outputInfo(&info, ids.size());
  1074. }
  1075. }
  1076. ~LinuxSamplerScopedEngine()
  1077. {
  1078. if (engine)
  1079. EngineFactory::Destroy(engine);
  1080. }
  1081. static void outputInfo(InstrumentManager::instrument_info_t* const info, const int programs, const char* const basename = nullptr)
  1082. {
  1083. DISCOVERY_OUT("init", "-----------");
  1084. if (info)
  1085. {
  1086. DISCOVERY_OUT("name", info->InstrumentName);
  1087. DISCOVERY_OUT("label", info->Product);
  1088. DISCOVERY_OUT("maker", info->Artists);
  1089. DISCOVERY_OUT("copyright", info->Artists);
  1090. }
  1091. else
  1092. {
  1093. DISCOVERY_OUT("name", basename);
  1094. DISCOVERY_OUT("label", basename);
  1095. }
  1096. DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
  1097. DISCOVERY_OUT("audio.outs", 2);
  1098. DISCOVERY_OUT("audio.total", 2);
  1099. DISCOVERY_OUT("midi.ins", 1);
  1100. DISCOVERY_OUT("midi.total", 1);
  1101. DISCOVERY_OUT("programs.total", programs);
  1102. //DISCOVERY_OUT("parameters.ins", 13); // defined in Carla - TODO
  1103. //DISCOVERY_OUT("parameters.outs", 1);
  1104. //DISCOVERY_OUT("parameters.total", 14);
  1105. DISCOVERY_OUT("build", BINARY_NATIVE);
  1106. DISCOVERY_OUT("end", "------------");
  1107. }
  1108. private:
  1109. Engine* engine;
  1110. InstrumentManager* ins;
  1111. };
  1112. if (init)
  1113. const LinuxSamplerScopedEngine engine(filename, stype);
  1114. else
  1115. LinuxSamplerScopedEngine::outputInfo(nullptr, 0, file.baseName().toUtf8().constData());
  1116. #else
  1117. DISCOVERY_OUT("error", stype << " support not available");
  1118. Q_UNUSED(filename);
  1119. Q_UNUSED(init);
  1120. #endif
  1121. }
  1122. // ------------------------------ main entry point ------------------------------
  1123. int main(int argc, char* argv[])
  1124. {
  1125. if (argc == 2 && strcmp(argv[1], "-formats") == 0)
  1126. {
  1127. printf("Available plugin formats:\n");
  1128. printf("LADSPA: ");
  1129. #ifdef WANT_LADSPA
  1130. printf("yes\n");
  1131. #else
  1132. printf("no\n");
  1133. #endif
  1134. printf("DSSI: ");
  1135. #ifdef WANT_DSSI
  1136. printf("yes\n");
  1137. #else
  1138. printf("no\n");
  1139. #endif
  1140. printf("LV2: ");
  1141. #ifdef WANT_LV2
  1142. printf("yes\n");
  1143. #else
  1144. printf("no\n");
  1145. #endif
  1146. printf("VST: ");
  1147. #ifdef WANT_VST
  1148. printf("yes\n");
  1149. #else
  1150. printf("no\n");
  1151. #endif
  1152. printf("\n");
  1153. printf("Available sampler formats:\n");
  1154. printf("GIG (LinuxSampler): ");
  1155. #ifdef WANT_LINUXSAMPLER
  1156. printf("yes\n");
  1157. #else
  1158. printf("no\n");
  1159. #endif
  1160. printf("SF2 (FluidSynth): ");
  1161. #ifdef WANT_FLUIDSYNTH
  1162. printf("yes\n");
  1163. #else
  1164. printf("no\n");
  1165. #endif
  1166. printf("SFZ (LinuxSampler): ");
  1167. #ifdef WANT_LINUXSAMPLER
  1168. printf("yes\n");
  1169. #else
  1170. printf("no\n");
  1171. #endif
  1172. return 0;
  1173. }
  1174. if (argc != 3)
  1175. {
  1176. qWarning("usage: %s <type> </path/to/plugin>", argv[0]);
  1177. return 1;
  1178. }
  1179. const char* const stype = argv[1];
  1180. const char* const filename = argv[2];
  1181. bool openLib;
  1182. PluginType type;
  1183. void* handle = nullptr;
  1184. if (strcmp(stype, "LADSPA") == 0)
  1185. {
  1186. openLib = true;
  1187. type = PLUGIN_LADSPA;
  1188. }
  1189. else if (strcmp(stype, "DSSI") == 0)
  1190. {
  1191. openLib = true;
  1192. type = PLUGIN_DSSI;
  1193. }
  1194. else if (strcmp(stype, "LV2") == 0)
  1195. {
  1196. openLib = false;
  1197. type = PLUGIN_LV2;
  1198. }
  1199. else if (strcmp(stype, "VST") == 0)
  1200. {
  1201. openLib = true;
  1202. type = PLUGIN_VST;
  1203. }
  1204. else if (strcmp(stype, "GIG") == 0)
  1205. {
  1206. openLib = false;
  1207. type = PLUGIN_GIG;
  1208. }
  1209. else if (strcmp(stype, "SF2") == 0)
  1210. {
  1211. openLib = false;
  1212. type = PLUGIN_SF2;
  1213. }
  1214. else if (strcmp(stype, "SFZ") == 0)
  1215. {
  1216. openLib = false;
  1217. type = PLUGIN_SFZ;
  1218. }
  1219. else
  1220. {
  1221. DISCOVERY_OUT("error", "Invalid plugin type");
  1222. return 1;
  1223. }
  1224. if (openLib)
  1225. {
  1226. handle = lib_open(filename);
  1227. if (! handle)
  1228. {
  1229. print_lib_error(filename);
  1230. return 1;
  1231. }
  1232. }
  1233. bool doInit = ! QString(filename).endsWith("dssi-vst.so", Qt::CaseInsensitive);
  1234. if (doInit && getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS"))
  1235. doInit = false;
  1236. if (doInit && handle)
  1237. {
  1238. // test fast loading & unloading DLL without initializing the plugin(s)
  1239. if (! lib_close(handle))
  1240. {
  1241. print_lib_error(filename);
  1242. return 1;
  1243. }
  1244. handle = lib_open(filename);
  1245. if (! handle)
  1246. {
  1247. print_lib_error(filename);
  1248. return 1;
  1249. }
  1250. }
  1251. switch (type)
  1252. {
  1253. case PLUGIN_LADSPA:
  1254. do_ladspa_check(handle, doInit);
  1255. break;
  1256. case PLUGIN_DSSI:
  1257. do_dssi_check(handle, doInit);
  1258. break;
  1259. case PLUGIN_LV2:
  1260. do_lv2_check(filename, doInit);
  1261. break;
  1262. case PLUGIN_VST:
  1263. do_vst_check(handle, doInit);
  1264. break;
  1265. case PLUGIN_GIG:
  1266. do_linuxsampler_check(filename, "gig", doInit);
  1267. break;
  1268. case PLUGIN_SF2:
  1269. do_fluidsynth_check(filename, doInit);
  1270. break;
  1271. case PLUGIN_SFZ:
  1272. do_linuxsampler_check(filename, "sfz", doInit);
  1273. break;
  1274. default:
  1275. break;
  1276. }
  1277. if (openLib && handle)
  1278. lib_close(handle);
  1279. return 0;
  1280. }