|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726 |
- /*
- * Carla Plugin discovery
- * Copyright (C) 2011-2020 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- #include "CarlaBackendUtils.hpp"
- #include "CarlaLibUtils.hpp"
- #include "CarlaMathUtils.hpp"
- #include "CarlaMIDI.h"
- #include "LinkedList.hpp"
-
- #ifdef BUILD_BRIDGE
- # undef HAVE_FLUIDSYNTH
- #endif
-
- #ifdef USING_JUCE
- # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
- # pragma GCC diagnostic push
- # pragma GCC diagnostic ignored "-Wdouble-promotion"
- # pragma GCC diagnostic ignored "-Weffc++"
- # pragma GCC diagnostic ignored "-Wfloat-equal"
- # endif
- # include "AppConfig.h"
- # include "juce_audio_processors/juce_audio_processors.h"
- # if JUCE_PLUGINHOST_VST
- # define USING_JUCE_FOR_VST2
- # endif
- # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
- # pragma GCC diagnostic pop
- # endif
- #endif
-
- #include "CarlaLadspaUtils.hpp"
- #include "CarlaLv2Utils.hpp"
- #include "CarlaVstUtils.hpp"
-
- #ifdef CARLA_OS_MAC
- # import <Foundation/Foundation.h>
- #endif
-
- #ifdef CARLA_OS_WIN
- # include <pthread.h>
- # include <objbase.h>
- #endif
-
- #ifdef HAVE_FLUIDSYNTH
- # include <fluidsynth.h>
- #endif
-
- #include <iostream>
-
- #ifndef BUILD_BRIDGE
- # include "water/files/File.h"
- # include "water/text/StringArray.h"
- # include "CarlaDssiUtils.cpp"
- # include "../backend/utils/CachedPlugins.cpp"
- #else
- # include "CarlaDssiUtils.hpp"
- #endif
-
- #define DISCOVERY_OUT(x, y) std::cout << "\ncarla-discovery::" << x << "::" << y << std::endl;
-
- using water::CharPointer_UTF8;
- using water::File;
- using water::StringArray;
-
- CARLA_BACKEND_USE_NAMESPACE
-
- // --------------------------------------------------------------------------
- // Dummy values to test plugins with
-
- static const uint32_t kBufferSize = 512;
- static const double kSampleRate = 44100.0;
- static const int32_t kSampleRatei = 44100;
- static const float kSampleRatef = 44100.0f;
-
- // --------------------------------------------------------------------------
- // Don't print ELF/EXE related errors since discovery can find multi-architecture binaries
-
- static void print_lib_error(const char* const filename)
- {
- const char* const error(lib_error(filename));
-
- if (error != nullptr &&
- std::strstr(error, "wrong ELF class") == nullptr &&
- std::strstr(error, "Bad EXE format") == nullptr &&
- std::strstr(error, "no suitable image found") == nullptr &&
- std::strstr(error, "not a valid Win32 application") == nullptr)
- {
- DISCOVERY_OUT("error", error);
- }
- }
-
- // ------------------------------ Plugin Checks -----------------------------
-
- #ifndef BUILD_BRIDGE
- static void print_cached_plugin(const CarlaCachedPluginInfo* const pinfo)
- {
- if (! pinfo->valid)
- return;
-
- DISCOVERY_OUT("init", "-----------");
- DISCOVERY_OUT("build", BINARY_NATIVE);
- DISCOVERY_OUT("hints", pinfo->hints);
- DISCOVERY_OUT("category", getPluginCategoryAsString(pinfo->category));
- DISCOVERY_OUT("name", pinfo->name);
- DISCOVERY_OUT("maker", pinfo->maker);
- DISCOVERY_OUT("label", pinfo->label);
- DISCOVERY_OUT("audio.ins", pinfo->audioIns);
- DISCOVERY_OUT("audio.outs", pinfo->audioOuts);
- DISCOVERY_OUT("cv.ins", pinfo->cvIns);
- DISCOVERY_OUT("cv.outs", pinfo->cvOuts);
- DISCOVERY_OUT("midi.ins", pinfo->midiIns);
- DISCOVERY_OUT("midi.outs", pinfo->midiOuts);
- DISCOVERY_OUT("parameters.ins", pinfo->parameterIns);
- DISCOVERY_OUT("parameters.outs", pinfo->parameterOuts);
- DISCOVERY_OUT("end", "------------");
- }
-
- static void do_cached_check(const PluginType type)
- {
- const char* plugPath;
-
- switch (type)
- {
- case PLUGIN_LV2:
- plugPath = std::getenv("LV2_PATH");
- break;
- case PLUGIN_SFZ:
- plugPath = std::getenv("SFZ_PATH");
- break;
- default:
- plugPath = nullptr;
- break;
- }
-
- const uint count = carla_get_cached_plugin_count(type, plugPath);
-
- for (uint i=0; i<count; ++i)
- {
- const CarlaCachedPluginInfo* pinfo(carla_get_cached_plugin_info(type, i));
- CARLA_SAFE_ASSERT_CONTINUE(pinfo != nullptr);
-
- print_cached_plugin(pinfo);
- }
- }
- #endif
-
- static void do_ladspa_check(lib_t& libHandle, const char* const filename, const bool doInit)
- {
- LADSPA_Descriptor_Function descFn = lib_symbol<LADSPA_Descriptor_Function>(libHandle, "ladspa_descriptor");
-
- if (descFn == nullptr)
- {
- DISCOVERY_OUT("error", "Not a LADSPA plugin");
- return;
- }
-
- const LADSPA_Descriptor* descriptor;
-
- {
- descriptor = descFn(0);
-
- if (descriptor == nullptr)
- {
- DISCOVERY_OUT("error", "Binary doesn't contain any plugins");
- return;
- }
-
- if (doInit && descriptor->instantiate != nullptr && descriptor->cleanup != nullptr)
- {
- LADSPA_Handle handle = descriptor->instantiate(descriptor, kSampleRatei);
-
- if (handle == nullptr)
- {
- DISCOVERY_OUT("error", "Failed to init first LADSPA plugin");
- return;
- }
-
- descriptor->cleanup(handle);
-
- lib_close(libHandle);
- libHandle = lib_open(filename);
-
- if (libHandle == nullptr)
- {
- print_lib_error(filename);
- return;
- }
-
- descFn = lib_symbol<LADSPA_Descriptor_Function>(libHandle, "ladspa_descriptor");
-
- if (descFn == nullptr)
- {
- DISCOVERY_OUT("error", "Not a LADSPA plugin (#2)");
- return;
- }
- }
- }
-
- unsigned long i = 0;
-
- while ((descriptor = descFn(i++)) != nullptr)
- {
- if (descriptor->instantiate == nullptr)
- {
- DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no instantiate()");
- continue;
- }
- if (descriptor->cleanup == nullptr)
- {
- DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no cleanup()");
- continue;
- }
- if (descriptor->run == nullptr)
- {
- DISCOVERY_OUT("error", "Plugin '" << descriptor->Name << "' has no run()");
- continue;
- }
- if (! LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties))
- {
- DISCOVERY_OUT("warning", "Plugin '" << descriptor->Name << "' is not hard real-time capable");
- }
-
- uint hints = 0x0;
- uint audioIns = 0;
- uint audioOuts = 0;
- uint audioTotal = 0;
- uint parametersIns = 0;
- uint parametersOuts = 0;
- uint parametersTotal = 0;
-
- if (LADSPA_IS_HARD_RT_CAPABLE(descriptor->Properties))
- hints |= PLUGIN_IS_RTSAFE;
-
- for (unsigned long j=0; j < descriptor->PortCount; ++j)
- {
- CARLA_ASSERT(descriptor->PortNames[j] != nullptr);
- const LADSPA_PortDescriptor portDescriptor = descriptor->PortDescriptors[j];
-
- if (LADSPA_IS_PORT_AUDIO(portDescriptor))
- {
- if (LADSPA_IS_PORT_INPUT(portDescriptor))
- audioIns += 1;
- else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
- audioOuts += 1;
-
- audioTotal += 1;
- }
- else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
- {
- if (LADSPA_IS_PORT_INPUT(portDescriptor))
- parametersIns += 1;
- else if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && std::strcmp(descriptor->PortNames[j], "latency") != 0 && std::strcmp(descriptor->PortNames[j], "_latency") != 0)
- parametersOuts += 1;
-
- parametersTotal += 1;
- }
- }
-
- if (doInit)
- {
- // -----------------------------------------------------------------------
- // start crash-free plugin test
-
- LADSPA_Handle handle = descriptor->instantiate(descriptor, kSampleRatei);
-
- if (handle == nullptr)
- {
- DISCOVERY_OUT("error", "Failed to init LADSPA plugin");
- continue;
- }
-
- // Test quick init and cleanup
- descriptor->cleanup(handle);
-
- handle = descriptor->instantiate(descriptor, kSampleRatei);
-
- if (handle == nullptr)
- {
- DISCOVERY_OUT("error", "Failed to init LADSPA plugin (#2)");
- continue;
- }
-
- LADSPA_Data bufferAudio[kBufferSize][audioTotal];
- LADSPA_Data bufferParams[parametersTotal];
- LADSPA_Data min, max, def;
-
- for (unsigned long j=0, iA=0, iC=0; j < descriptor->PortCount; ++j)
- {
- const LADSPA_PortDescriptor portDescriptor = descriptor->PortDescriptors[j];
- const LADSPA_PortRangeHint portRangeHints = descriptor->PortRangeHints[j];
- const char* const portName = descriptor->PortNames[j];
-
- if (LADSPA_IS_PORT_AUDIO(portDescriptor))
- {
- carla_zeroFloats(bufferAudio[iA], kBufferSize);
- descriptor->connect_port(handle, j, bufferAudio[iA++]);
- }
- else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
- {
- // min value
- if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
- min = portRangeHints.LowerBound;
- else
- min = 0.0f;
-
- // max value
- if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
- max = portRangeHints.UpperBound;
- else
- max = 1.0f;
-
- if (min > max)
- {
- DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: min > max");
- max = min + 0.1f;
- }
- else if (carla_isEqual(min, max))
- {
- DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: max == min");
- max = min + 0.1f;
- }
-
- // default value
- def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
-
- if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
- {
- min *= kSampleRatef;
- max *= kSampleRatef;
- def *= kSampleRatef;
- }
-
- if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && (std::strcmp(portName, "latency") == 0 || std::strcmp(portName, "_latency") == 0))
- {
- // latency parameter
- def = 0.0f;
- }
- else
- {
- if (def < min)
- def = min;
- else if (def > max)
- def = max;
- }
-
- bufferParams[iC] = def;
- descriptor->connect_port(handle, j, &bufferParams[iC++]);
- }
- }
-
- if (descriptor->activate != nullptr)
- descriptor->activate(handle);
-
- descriptor->run(handle, kBufferSize);
-
- if (descriptor->deactivate != nullptr)
- descriptor->deactivate(handle);
-
- descriptor->cleanup(handle);
-
- // end crash-free plugin test
- // -----------------------------------------------------------------------
- }
-
- DISCOVERY_OUT("init", "-----------");
- DISCOVERY_OUT("build", BINARY_NATIVE);
- DISCOVERY_OUT("hints", hints);
- DISCOVERY_OUT("name", descriptor->Name);
- DISCOVERY_OUT("label", descriptor->Label);
- DISCOVERY_OUT("maker", descriptor->Maker);
- DISCOVERY_OUT("uniqueId", descriptor->UniqueID);
- DISCOVERY_OUT("audio.ins", audioIns);
- DISCOVERY_OUT("audio.outs", audioOuts);
- DISCOVERY_OUT("parameters.ins", parametersIns);
- DISCOVERY_OUT("parameters.outs", parametersOuts);
- DISCOVERY_OUT("end", "------------");
- }
- }
-
- static void do_dssi_check(lib_t& libHandle, const char* const filename, const bool doInit)
- {
- DSSI_Descriptor_Function descFn = lib_symbol<DSSI_Descriptor_Function>(libHandle, "dssi_descriptor");
-
- if (descFn == nullptr)
- {
- DISCOVERY_OUT("error", "Not a DSSI plugin");
- return;
- }
-
- const DSSI_Descriptor* descriptor;
-
- {
- descriptor = descFn(0);
-
- if (descriptor == nullptr)
- {
- DISCOVERY_OUT("error", "Binary doesn't contain any plugins");
- return;
- }
-
- const LADSPA_Descriptor* const ldescriptor(descriptor->LADSPA_Plugin);
-
- if (ldescriptor == nullptr)
- {
- DISCOVERY_OUT("error", "DSSI plugin doesn't provide the LADSPA interface");
- return;
- }
-
- if (doInit && ldescriptor->instantiate != nullptr && ldescriptor->cleanup != nullptr)
- {
- LADSPA_Handle handle = ldescriptor->instantiate(ldescriptor, kSampleRatei);
-
- if (handle == nullptr)
- {
- DISCOVERY_OUT("error", "Failed to init first LADSPA plugin");
- return;
- }
-
- ldescriptor->cleanup(handle);
-
- lib_close(libHandle);
- libHandle = lib_open(filename);
-
- if (libHandle == nullptr)
- {
- print_lib_error(filename);
- return;
- }
-
- descFn = lib_symbol<DSSI_Descriptor_Function>(libHandle, "dssi_descriptor");
-
- if (descFn == nullptr)
- {
- DISCOVERY_OUT("error", "Not a DSSI plugin (#2)");
- return;
- }
- }
- }
-
- unsigned long i = 0;
-
- while ((descriptor = descFn(i++)) != nullptr)
- {
- const LADSPA_Descriptor* const ldescriptor = descriptor->LADSPA_Plugin;
-
- if (ldescriptor == nullptr)
- {
- DISCOVERY_OUT("error", "Plugin has no LADSPA interface");
- continue;
- }
- if (descriptor->DSSI_API_Version != DSSI_VERSION_MAJOR)
- {
- DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' uses an unsupported DSSI spec version " << descriptor->DSSI_API_Version);
- continue;
- }
- if (ldescriptor->instantiate == nullptr)
- {
- DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no instantiate()");
- continue;
- }
- if (ldescriptor->cleanup == nullptr)
- {
- DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no cleanup()");
- continue;
- }
- if (ldescriptor->run == nullptr && descriptor->run_synth == nullptr)
- {
- DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' has no run() or run_synth()");
- continue;
- }
- if (descriptor->run_synth == nullptr && descriptor->run_multiple_synths != nullptr)
- {
- DISCOVERY_OUT("error", "Plugin '" << ldescriptor->Name << "' requires run_multiple_synths which is not supported");
- continue;
- }
- if (! LADSPA_IS_HARD_RT_CAPABLE(ldescriptor->Properties))
- {
- DISCOVERY_OUT("warning", "Plugin '" << ldescriptor->Name << "' is not hard real-time capable");
- }
-
- uint hints = 0x0;
- uint audioIns = 0;
- uint audioOuts = 0;
- uint audioTotal = 0;
- uint midiIns = 0;
- uint parametersIns = 0;
- uint parametersOuts = 0;
- uint parametersTotal = 0;
-
- if (LADSPA_IS_HARD_RT_CAPABLE(ldescriptor->Properties))
- hints |= PLUGIN_IS_RTSAFE;
-
- for (unsigned long j=0; j < ldescriptor->PortCount; ++j)
- {
- CARLA_ASSERT(ldescriptor->PortNames[j] != nullptr);
- const LADSPA_PortDescriptor portDescriptor = ldescriptor->PortDescriptors[j];
-
- if (LADSPA_IS_PORT_AUDIO(portDescriptor))
- {
- if (LADSPA_IS_PORT_INPUT(portDescriptor))
- audioIns += 1;
- else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
- audioOuts += 1;
-
- audioTotal += 1;
- }
- else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
- {
- if (LADSPA_IS_PORT_INPUT(portDescriptor))
- parametersIns += 1;
- else if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && std::strcmp(ldescriptor->PortNames[j], "latency") != 0 && std::strcmp(ldescriptor->PortNames[j], "_latency") != 0)
- parametersOuts += 1;
-
- parametersTotal += 1;
- }
- }
-
- if (descriptor->run_synth != nullptr)
- midiIns = 1;
-
- if (midiIns > 0 && audioIns == 0 && audioOuts > 0)
- hints |= PLUGIN_IS_SYNTH;
-
- #ifndef BUILD_BRIDGE
- if (const char* const ui = find_dssi_ui(filename, ldescriptor->Label))
- {
- hints |= PLUGIN_HAS_CUSTOM_UI;
- delete[] ui;
- }
- #endif
-
- if (doInit)
- {
- // -----------------------------------------------------------------------
- // start crash-free plugin test
-
- LADSPA_Handle handle = ldescriptor->instantiate(ldescriptor, kSampleRatei);
-
- if (handle == nullptr)
- {
- DISCOVERY_OUT("error", "Failed to init DSSI plugin");
- continue;
- }
-
- // Test quick init and cleanup
- ldescriptor->cleanup(handle);
-
- handle = ldescriptor->instantiate(ldescriptor, kSampleRatei);
-
- if (handle == nullptr)
- {
- DISCOVERY_OUT("error", "Failed to init DSSI plugin (#2)");
- continue;
- }
-
- LADSPA_Data bufferAudio[kBufferSize][audioTotal];
- LADSPA_Data bufferParams[parametersTotal];
- LADSPA_Data min, max, def;
-
- for (unsigned long j=0, iA=0, iC=0; j < ldescriptor->PortCount; ++j)
- {
- const LADSPA_PortDescriptor portDescriptor = ldescriptor->PortDescriptors[j];
- const LADSPA_PortRangeHint portRangeHints = ldescriptor->PortRangeHints[j];
- const char* const portName = ldescriptor->PortNames[j];
-
- if (LADSPA_IS_PORT_AUDIO(portDescriptor))
- {
- carla_zeroFloats(bufferAudio[iA], kBufferSize);
- ldescriptor->connect_port(handle, j, bufferAudio[iA++]);
- }
- else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
- {
- // min value
- if (LADSPA_IS_HINT_BOUNDED_BELOW(portRangeHints.HintDescriptor))
- min = portRangeHints.LowerBound;
- else
- min = 0.0f;
-
- // max value
- if (LADSPA_IS_HINT_BOUNDED_ABOVE(portRangeHints.HintDescriptor))
- max = portRangeHints.UpperBound;
- else
- max = 1.0f;
-
- if (min > max)
- {
- DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: min > max");
- max = min + 0.1f;
- }
- else if (carla_isEqual(min, max))
- {
- DISCOVERY_OUT("warning", "Parameter '" << portName << "' is broken: max == min");
- max = min + 0.1f;
- }
-
- // default value
- def = get_default_ladspa_port_value(portRangeHints.HintDescriptor, min, max);
-
- if (LADSPA_IS_HINT_SAMPLE_RATE(portRangeHints.HintDescriptor))
- {
- min *= kSampleRatef;
- max *= kSampleRatef;
- def *= kSampleRatef;
- }
-
- if (LADSPA_IS_PORT_OUTPUT(portDescriptor) && (std::strcmp(portName, "latency") == 0 || std::strcmp(portName, "_latency") == 0))
- {
- // latency parameter
- def = 0.0f;
- }
- else
- {
- if (def < min)
- def = min;
- else if (def > max)
- def = max;
- }
-
- bufferParams[iC] = def;
- ldescriptor->connect_port(handle, j, &bufferParams[iC++]);
- }
- }
-
- // select first midi-program if available
- if (descriptor->get_program != nullptr && descriptor->select_program != nullptr)
- {
- if (const DSSI_Program_Descriptor* const pDesc = descriptor->get_program(handle, 0))
- descriptor->select_program(handle, pDesc->Bank, pDesc->Program);
- }
-
- if (ldescriptor->activate != nullptr)
- ldescriptor->activate(handle);
-
- if (descriptor->run_synth != nullptr)
- {
- snd_seq_event_t midiEvents[2];
- carla_zeroStructs(midiEvents, 2);
-
- const unsigned long midiEventCount = 2;
-
- midiEvents[0].type = SND_SEQ_EVENT_NOTEON;
- midiEvents[0].data.note.note = 64;
- midiEvents[0].data.note.velocity = 100;
-
- midiEvents[1].type = SND_SEQ_EVENT_NOTEOFF;
- midiEvents[1].data.note.note = 64;
- midiEvents[1].data.note.velocity = 0;
- midiEvents[1].time.tick = kBufferSize/2;
-
- descriptor->run_synth(handle, kBufferSize, midiEvents, midiEventCount);
- }
- else
- ldescriptor->run(handle, kBufferSize);
-
- if (ldescriptor->deactivate != nullptr)
- ldescriptor->deactivate(handle);
-
- ldescriptor->cleanup(handle);
-
- // end crash-free plugin test
- // -----------------------------------------------------------------------
- }
-
- DISCOVERY_OUT("init", "-----------");
- DISCOVERY_OUT("build", BINARY_NATIVE);
- DISCOVERY_OUT("hints", hints);
- DISCOVERY_OUT("name", ldescriptor->Name);
- DISCOVERY_OUT("label", ldescriptor->Label);
- DISCOVERY_OUT("maker", ldescriptor->Maker);
- DISCOVERY_OUT("uniqueId", ldescriptor->UniqueID);
- DISCOVERY_OUT("audio.ins", audioIns);
- DISCOVERY_OUT("audio.outs", audioOuts);
- DISCOVERY_OUT("midi.ins", midiIns);
- DISCOVERY_OUT("parameters.ins", parametersIns);
- DISCOVERY_OUT("parameters.outs", parametersOuts);
- DISCOVERY_OUT("end", "------------");
- }
- }
-
- #ifndef BUILD_BRIDGE
- static void do_lv2_check(const char* const bundle, const bool doInit)
- {
- Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
-
- Lilv::Node bundleNode(lv2World.new_file_uri(nullptr, bundle));
- CARLA_SAFE_ASSERT_RETURN(bundleNode.is_uri(),);
-
- CarlaString sBundle(bundleNode.as_uri());
-
- if (! sBundle.endsWith("/"))
- sBundle += "/";
-
- // Load bundle
- lv2World.load_bundle(sBundle);
-
- // Load plugins in this bundle
- const Lilv::Plugins lilvPlugins(lv2World.get_all_plugins());
-
- // Get all plugin URIs in this bundle
- StringArray URIs;
-
- LILV_FOREACH(plugins, it, lilvPlugins)
- {
- Lilv::Plugin lilvPlugin(lilv_plugins_get(lilvPlugins, it));
-
- if (const char* const uri = lilvPlugin.get_uri().as_string())
- URIs.addIfNotAlreadyThere(water::String(uri));
- }
-
- if (URIs.size() == 0)
- {
- DISCOVERY_OUT("warning", "LV2 Bundle doesn't provide any plugins");
- return;
- }
-
- // Get & check every plugin-instance
- for (int i=0, count=URIs.size(); i < count; ++i)
- {
- const char* const URI = URIs[i].toRawUTF8();
- CarlaScopedPointer<const LV2_RDF_Descriptor> rdfDescriptor(lv2_rdf_new(URI, false));
-
- if (rdfDescriptor == nullptr || rdfDescriptor->URI == nullptr)
- {
- DISCOVERY_OUT("error", "Failed to find LV2 plugin '" << URI << "'");
- continue;
- }
-
- if (doInit)
- {
- // test if lib is loadable, twice
- const lib_t libHandle1 = lib_open(rdfDescriptor->Binary);
-
- if (libHandle1 == nullptr)
- {
- print_lib_error(rdfDescriptor->Binary);
- delete rdfDescriptor;
- continue;
- }
-
- lib_close(libHandle1);
-
- const lib_t libHandle2 = lib_open(rdfDescriptor->Binary);
-
- if (libHandle2 == nullptr)
- {
- print_lib_error(rdfDescriptor->Binary);
- delete rdfDescriptor;
- continue;
- }
-
- lib_close(libHandle2);
- }
-
- const LilvPlugin* const cPlugin(lv2World.getPluginFromURI(URI));
- CARLA_SAFE_ASSERT_CONTINUE(cPlugin != nullptr);
-
- Lilv::Plugin lilvPlugin(cPlugin);
- CARLA_SAFE_ASSERT_CONTINUE(lilvPlugin.get_uri().is_uri());
-
- print_cached_plugin(get_cached_plugin_lv2(lv2World, lilvPlugin));
- }
- }
- #endif
-
- #ifndef USING_JUCE_FOR_VST2
- // --------------------------------------------------------------------------
- // VST stuff
-
- // Check if plugin is currently processing
- static bool gVstIsProcessing = false;
-
- // Check if plugin needs idle
- static bool gVstNeedsIdle = false;
-
- // Check if plugin wants midi
- static bool gVstWantsMidi = false;
-
- // Check if plugin wants time
- static bool gVstWantsTime = false;
-
- // Current uniqueId for VST shell plugins
- static intptr_t gVstCurrentUniqueId = 0;
-
- // Supported Carla features
- static intptr_t vstHostCanDo(const char* const feature)
- {
- carla_debug("vstHostCanDo(\"%s\")", feature);
-
- if (std::strcmp(feature, "supplyIdle") == 0)
- return 1;
- if (std::strcmp(feature, "sendVstEvents") == 0)
- return 1;
- if (std::strcmp(feature, "sendVstMidiEvent") == 0)
- return 1;
- if (std::strcmp(feature, "sendVstMidiEventFlagIsRealtime") == 0)
- return 1;
- if (std::strcmp(feature, "sendVstTimeInfo") == 0)
- {
- gVstWantsTime = true;
- return 1;
- }
- if (std::strcmp(feature, "receiveVstEvents") == 0)
- return 1;
- if (std::strcmp(feature, "receiveVstMidiEvent") == 0)
- return 1;
- if (std::strcmp(feature, "receiveVstTimeInfo") == 0)
- return -1;
- if (std::strcmp(feature, "reportConnectionChanges") == 0)
- return -1;
- if (std::strcmp(feature, "acceptIOChanges") == 0)
- return 1;
- if (std::strcmp(feature, "sizeWindow") == 0)
- return 1;
- if (std::strcmp(feature, "offline") == 0)
- return -1;
- if (std::strcmp(feature, "openFileSelector") == 0)
- return -1;
- if (std::strcmp(feature, "closeFileSelector") == 0)
- return -1;
- if (std::strcmp(feature, "startStopProcess") == 0)
- return 1;
- if (std::strcmp(feature, "supportShell") == 0)
- return 1;
- if (std::strcmp(feature, "shellCategory") == 0)
- return 1;
- if (std::strcmp(feature, "NIMKPIVendorSpecificCallbacks") == 0)
- return -1;
-
- // non-official features found in some plugins:
- // "asyncProcessing"
- // "editFile"
-
- // unimplemented
- carla_stderr("vstHostCanDo(\"%s\") - unknown feature", feature);
- return 0;
- }
-
- // Host-side callback
- static intptr_t VSTCALLBACK vstHostCallback(AEffect* const effect, const int32_t opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
- {
- carla_debug("vstHostCallback(%p, %i:%s, %i, " P_INTPTR ", %p, %f)",
- effect, opcode, vstMasterOpcode2str(opcode), index, value, ptr, static_cast<double>(opt));
-
- static VstTimeInfo timeInfo;
- intptr_t ret = 0;
-
- switch (opcode)
- {
- case audioMasterAutomate:
- ret = 1;
- break;
-
- case audioMasterVersion:
- ret = kVstVersion;
- break;
-
- case audioMasterCurrentId:
- ret = gVstCurrentUniqueId;
- break;
-
- case DECLARE_VST_DEPRECATED(audioMasterWantMidi):
- if (gVstWantsMidi) { DISCOVERY_OUT("warning", "Plugin requested MIDI more than once"); }
-
- gVstWantsMidi = true;
- ret = 1;
- break;
-
- case audioMasterGetTime:
- if (! gVstIsProcessing) { DISCOVERY_OUT("warning", "Plugin requested timeInfo out of process"); }
- if (! gVstWantsTime) { DISCOVERY_OUT("warning", "Plugin requested timeInfo but didn't ask if host could do \"sendVstTimeInfo\""); }
-
- carla_zeroStruct(timeInfo);
- timeInfo.sampleRate = kSampleRate;
-
- // Tempo
- timeInfo.tempo = 120.0;
- timeInfo.flags |= kVstTempoValid;
-
- // Time Signature
- timeInfo.timeSigNumerator = 4;
- timeInfo.timeSigDenominator = 4;
- timeInfo.flags |= kVstTimeSigValid;
-
- ret = (intptr_t)&timeInfo;
- break;
-
- case DECLARE_VST_DEPRECATED(audioMasterTempoAt):
- ret = 120 * 10000;
- break;
-
- case DECLARE_VST_DEPRECATED(audioMasterGetNumAutomatableParameters):
- ret = carla_minPositive(effect->numParams, static_cast<int>(MAX_DEFAULT_PARAMETERS));
- break;
-
- case DECLARE_VST_DEPRECATED(audioMasterGetParameterQuantization):
- ret = 1; // full single float precision
- break;
-
- case DECLARE_VST_DEPRECATED(audioMasterNeedIdle):
- if (gVstNeedsIdle) { DISCOVERY_OUT("warning", "Plugin requested idle more than once"); }
-
- gVstNeedsIdle = true;
- ret = 1;
- break;
-
- case audioMasterGetSampleRate:
- ret = kSampleRatei;
- break;
-
- case audioMasterGetBlockSize:
- ret = kBufferSize;
- break;
-
- case DECLARE_VST_DEPRECATED(audioMasterWillReplaceOrAccumulate):
- ret = 1; // replace
- break;
-
- case audioMasterGetCurrentProcessLevel:
- ret = gVstIsProcessing ? kVstProcessLevelRealtime : kVstProcessLevelUser;
- break;
-
- case audioMasterGetAutomationState:
- ret = kVstAutomationOff;
- break;
-
- case audioMasterGetVendorString:
- CARLA_SAFE_ASSERT_BREAK(ptr != nullptr);
- std::strcpy((char*)ptr, "falkTX");
- ret = 1;
- break;
-
- case audioMasterGetProductString:
- CARLA_SAFE_ASSERT_BREAK(ptr != nullptr);
- std::strcpy((char*)ptr, "Carla-Discovery");
- ret = 1;
- break;
-
- case audioMasterGetVendorVersion:
- ret = CARLA_VERSION_HEX;
- break;
-
- case audioMasterCanDo:
- CARLA_SAFE_ASSERT_BREAK(ptr != nullptr);
- ret = vstHostCanDo((const char*)ptr);
- break;
-
- case audioMasterGetLanguage:
- ret = kVstLangEnglish;
- break;
-
- default:
- carla_stdout("vstHostCallback(%p, %i:%s, %i, " P_INTPTR ", %p, %f)",
- effect, opcode, vstMasterOpcode2str(opcode), index, value, ptr, static_cast<double>(opt));
- break;
- }
-
- return ret;
- }
-
- static void do_vst_check(lib_t& libHandle, const char* const filename, const bool doInit)
- {
- VST_Function vstFn = nullptr;
-
- #ifdef CARLA_OS_MAC
- CFBundleRef bundleRef = nullptr;
- CFBundleRefNum resFileId = 0;
-
- if (libHandle == nullptr)
- {
- const CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(0, (const UInt8*)filename, (CFIndex)strlen(filename), true);
- CARLA_SAFE_ASSERT_RETURN(urlRef != nullptr,);
-
- bundleRef = CFBundleCreate(kCFAllocatorDefault, urlRef);
- CFRelease(urlRef);
- CARLA_SAFE_ASSERT_RETURN(bundleRef != nullptr,);
-
- if (! CFBundleLoadExecutable(bundleRef))
- {
- CFRelease(bundleRef);
- DISCOVERY_OUT("error", "Failed to load VST bundle executable");
- return;
- }
-
- vstFn = (VST_Function)CFBundleGetFunctionPointerForName(bundleRef, CFSTR("main_macho"));
-
- if (vstFn == nullptr)
- vstFn = (VST_Function)CFBundleGetFunctionPointerForName(bundleRef, CFSTR("VSTPluginMain"));
-
- if (vstFn == nullptr)
- {
- CFBundleUnloadExecutable(bundleRef);
- CFRelease(bundleRef);
- DISCOVERY_OUT("error", "Not a VST plugin");
- return;
- }
-
- resFileId = CFBundleOpenBundleResourceMap(bundleRef);
- }
- else
- #endif
- {
- vstFn = lib_symbol<VST_Function>(libHandle, "VSTPluginMain");
-
- if (vstFn == nullptr)
- {
- vstFn = lib_symbol<VST_Function>(libHandle, "main");
-
- if (vstFn == nullptr)
- {
- DISCOVERY_OUT("error", "Not a VST plugin");
- return;
- }
- }
- }
-
- AEffect* effect = vstFn(vstHostCallback);
-
- if (effect == nullptr || effect->magic != kEffectMagic)
- {
- DISCOVERY_OUT("error", "Failed to init VST plugin, or VST magic failed");
- return;
- }
-
- if (effect->uniqueID == 0)
- {
- DISCOVERY_OUT("warning", "Plugin doesn't have an Unique ID when first loaded");
- }
-
- effect->dispatcher(effect, DECLARE_VST_DEPRECATED(effIdentify), 0, 0, nullptr, 0.0f);
- effect->dispatcher(effect, DECLARE_VST_DEPRECATED(effSetBlockSizeAndSampleRate), 0, kBufferSize, nullptr, kSampleRatef);
- effect->dispatcher(effect, effSetSampleRate, 0, 0, nullptr, kSampleRatef);
- effect->dispatcher(effect, effSetBlockSize, 0, kBufferSize, nullptr, 0.0f);
- effect->dispatcher(effect, effSetProcessPrecision, 0, kVstProcessPrecision32, nullptr, 0.0f);
-
- effect->dispatcher(effect, effOpen, 0, 0, nullptr, 0.0f);
-
- if (effect->numPrograms > 0)
- effect->dispatcher(effect, effSetProgram, 0, 0, nullptr, 0.0f);
-
- const bool isShell = (effect->dispatcher(effect, effGetPlugCategory, 0, 0, nullptr, 0.0f) == kPlugCategShell);
-
- if (effect->uniqueID == 0 && !isShell)
- {
- DISCOVERY_OUT("error", "Plugin doesn't have an Unique ID after being open");
- effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
- return;
- }
-
- gVstCurrentUniqueId = effect->uniqueID;
-
- char strBuf[STR_MAX+1];
- CarlaString cName;
- CarlaString cProduct;
- CarlaString cVendor;
- PluginCategory category;
- LinkedList<intptr_t> uniqueIds;
-
- if (isShell)
- {
- for (;;)
- {
- carla_zeroChars(strBuf, STR_MAX+1);
-
- gVstCurrentUniqueId = effect->dispatcher(effect, effShellGetNextPlugin, 0, 0, strBuf, 0.0f);
-
- if (gVstCurrentUniqueId == 0)
- break;
-
- uniqueIds.append(gVstCurrentUniqueId);
- }
-
- effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
- effect = nullptr;
- }
- else
- {
- uniqueIds.append(gVstCurrentUniqueId);
- }
-
- for (LinkedList<intptr_t>::Itenerator it = uniqueIds.begin2(); it.valid(); it.next())
- {
- gVstCurrentUniqueId = it.getValue(0);
-
- if (effect == nullptr)
- {
- effect = vstFn(vstHostCallback);
-
- effect->dispatcher(effect, DECLARE_VST_DEPRECATED(effIdentify), 0, 0, nullptr, 0.0f);
- effect->dispatcher(effect, DECLARE_VST_DEPRECATED(effSetBlockSizeAndSampleRate), 0, kBufferSize, nullptr, kSampleRatef);
- effect->dispatcher(effect, effSetSampleRate, 0, 0, nullptr, kSampleRatef);
- effect->dispatcher(effect, effSetBlockSize, 0, kBufferSize, nullptr, 0.0f);
- effect->dispatcher(effect, effSetProcessPrecision, 0, kVstProcessPrecision32, nullptr, 0.0f);
-
- effect->dispatcher(effect, effOpen, 0, 0, nullptr, 0.0f);
-
- if (effect->numPrograms > 0)
- effect->dispatcher(effect, effSetProgram, 0, 0, nullptr, 0.0f);
- }
-
- // get name
- carla_zeroChars(strBuf, STR_MAX+1);
-
- if (effect->dispatcher(effect, effGetEffectName, 0, 0, strBuf, 0.0f) == 1)
- cName = strBuf;
- else
- cName.clear();
-
- // get product
- carla_zeroChars(strBuf, STR_MAX+1);
-
- if (effect->dispatcher(effect, effGetProductString, 0, 0, strBuf, 0.0f) == 1)
- cProduct = strBuf;
- else
- cProduct.clear();
-
- // get vendor
- carla_zeroChars(strBuf, STR_MAX+1);
-
- if (effect->dispatcher(effect, effGetVendorString, 0, 0, strBuf, 0.0f) == 1)
- cVendor = strBuf;
- else
- cVendor.clear();
-
- // get category
- switch (effect->dispatcher(effect, effGetPlugCategory, 0, 0, nullptr, 0.0f))
- {
- case kPlugCategSynth:
- category = PLUGIN_CATEGORY_SYNTH;
- break;
- case kPlugCategAnalysis:
- category = PLUGIN_CATEGORY_UTILITY;
- break;
- case kPlugCategMastering:
- category = PLUGIN_CATEGORY_DYNAMICS;
- break;
- case kPlugCategRoomFx:
- category = PLUGIN_CATEGORY_DELAY;
- break;
- case kPlugCategRestoration:
- category = PLUGIN_CATEGORY_UTILITY;
- break;
- case kPlugCategGenerator:
- category = PLUGIN_CATEGORY_SYNTH;
- break;
- default:
- if (effect->flags & effFlagsIsSynth)
- category = PLUGIN_CATEGORY_SYNTH;
- else
- category = PLUGIN_CATEGORY_NONE;
- break;
- }
-
- // get everything else
- uint hints = 0x0;
- uint audioIns = static_cast<uint>(std::max(0, effect->numInputs));
- uint audioOuts = static_cast<uint>(std::max(0, effect->numOutputs));
- uint midiIns = 0;
- uint midiOuts = 0;
- uint parameters = static_cast<uint>(std::max(0, effect->numParams));
-
- if (effect->flags & effFlagsHasEditor)
- hints |= PLUGIN_HAS_CUSTOM_UI;
-
- if (effect->flags & effFlagsIsSynth)
- hints |= PLUGIN_IS_SYNTH;
-
- if (vstPluginCanDo(effect, "receiveVstEvents") || vstPluginCanDo(effect, "receiveVstMidiEvent") || (effect->flags & effFlagsIsSynth) != 0)
- midiIns = 1;
-
- if (vstPluginCanDo(effect, "sendVstEvents") || vstPluginCanDo(effect, "sendVstMidiEvent"))
- midiOuts = 1;
-
- // -----------------------------------------------------------------------
- // start crash-free plugin test
-
- if (doInit)
- {
- if (gVstNeedsIdle)
- effect->dispatcher(effect, DECLARE_VST_DEPRECATED(effIdle), 0, 0, nullptr, 0.0f);
-
- effect->dispatcher(effect, effMainsChanged, 0, 1, nullptr, 0.0f);
- effect->dispatcher(effect, effStartProcess, 0, 0, nullptr, 0.0f);
-
- if (gVstNeedsIdle)
- effect->dispatcher(effect, DECLARE_VST_DEPRECATED(effIdle), 0, 0, nullptr, 0.0f);
-
- // Plugin might call wantMidi() during resume
- if (midiIns == 0 && gVstWantsMidi)
- {
- midiIns = 1;
- }
-
- float* bufferAudioIn[std::max(1U, audioIns)];
- float* bufferAudioOut[std::max(1U, audioOuts)];
-
- if (audioIns == 0)
- {
- bufferAudioIn[0] = nullptr;
- }
- else
- {
- for (uint j=0; j < audioIns; ++j)
- {
- bufferAudioIn[j] = new float[kBufferSize];
- carla_zeroFloats(bufferAudioIn[j], kBufferSize);
- }
- }
-
- if (audioOuts == 0)
- {
- bufferAudioOut[0] = nullptr;
- }
- else
- {
- for (uint j=0; j < audioOuts; ++j)
- {
- bufferAudioOut[j] = new float[kBufferSize];
- carla_zeroFloats(bufferAudioOut[j], kBufferSize);
- }
- }
-
- struct VstEventsFixed {
- int32_t numEvents;
- intptr_t reserved;
- VstEvent* data[2];
-
- VstEventsFixed()
- : numEvents(0),
- reserved(0)
- {
- data[0] = data[1] = nullptr;
- }
- } events;
-
- VstMidiEvent midiEvents[2];
- carla_zeroStructs(midiEvents, 2);
-
- midiEvents[0].type = kVstMidiType;
- midiEvents[0].byteSize = sizeof(VstMidiEvent);
- midiEvents[0].midiData[0] = char(MIDI_STATUS_NOTE_ON);
- midiEvents[0].midiData[1] = 64;
- midiEvents[0].midiData[2] = 100;
-
- midiEvents[1].type = kVstMidiType;
- midiEvents[1].byteSize = sizeof(VstMidiEvent);
- midiEvents[1].midiData[0] = char(MIDI_STATUS_NOTE_OFF);
- midiEvents[1].midiData[1] = 64;
- midiEvents[1].deltaFrames = kBufferSize/2;
-
- events.numEvents = 2;
- events.data[0] = (VstEvent*)&midiEvents[0];
- events.data[1] = (VstEvent*)&midiEvents[1];
-
- // processing
- gVstIsProcessing = true;
-
- if (midiIns > 0)
- effect->dispatcher(effect, effProcessEvents, 0, 0, &events, 0.0f);
-
- if ((effect->flags & effFlagsCanReplacing) > 0 && effect->processReplacing != nullptr && effect->processReplacing != effect->DECLARE_VST_DEPRECATED(process))
- effect->processReplacing(effect, bufferAudioIn, bufferAudioOut, kBufferSize);
- else if (effect->DECLARE_VST_DEPRECATED(process) != nullptr)
- effect->DECLARE_VST_DEPRECATED(process)(effect, bufferAudioIn, bufferAudioOut, kBufferSize);
- else
- DISCOVERY_OUT("error", "Plugin doesn't have a process function");
-
- gVstIsProcessing = false;
-
- effect->dispatcher(effect, effStopProcess, 0, 0, nullptr, 0.0f);
- effect->dispatcher(effect, effMainsChanged, 0, 0, nullptr, 0.0f);
-
- if (gVstNeedsIdle)
- effect->dispatcher(effect, DECLARE_VST_DEPRECATED(effIdle), 0, 0, nullptr, 0.0f);
-
- for (uint j=0; j < audioIns; ++j)
- delete[] bufferAudioIn[j];
- for (uint j=0; j < audioOuts; ++j)
- delete[] bufferAudioOut[j];
- }
-
- // end crash-free plugin test
- // -----------------------------------------------------------------------
-
- DISCOVERY_OUT("init", "-----------");
- DISCOVERY_OUT("build", BINARY_NATIVE);
- DISCOVERY_OUT("hints", hints);
- DISCOVERY_OUT("category", getPluginCategoryAsString(category));
- DISCOVERY_OUT("name", cName.buffer());
- DISCOVERY_OUT("label", cProduct.buffer());
- DISCOVERY_OUT("maker", cVendor.buffer());
- DISCOVERY_OUT("uniqueId", gVstCurrentUniqueId);
- DISCOVERY_OUT("audio.ins", audioIns);
- DISCOVERY_OUT("audio.outs", audioOuts);
- DISCOVERY_OUT("midi.ins", midiIns);
- DISCOVERY_OUT("midi.outs", midiOuts);
- DISCOVERY_OUT("parameters.ins", parameters);
- DISCOVERY_OUT("end", "------------");
-
- gVstWantsMidi = false;
- gVstWantsTime = false;
-
- if (! isShell)
- break;
-
- effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
- effect = nullptr;
- }
-
- uniqueIds.clear();
-
- if (effect != nullptr)
- {
- if (gVstNeedsIdle)
- effect->dispatcher(effect, DECLARE_VST_DEPRECATED(effIdle), 0, 0, nullptr, 0.0f);
-
- effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
- }
-
- #ifdef CARLA_OS_MAC
- if (bundleRef != nullptr)
- {
- CFBundleCloseBundleResourceMap(bundleRef, resFileId);
- CFBundleUnloadExecutable(bundleRef);
- CFRelease(bundleRef);
- }
- #else
- return;
-
- // unused
- (void)filename;
- #endif
- }
- #endif // ! USING_JUCE_FOR_VST2
-
- #ifdef USING_JUCE
- static void do_juce_check(const char* const filename_, const char* const stype, const bool doInit)
- {
- CARLA_SAFE_ASSERT_RETURN(stype != nullptr && stype[0] != 0,) // FIXME
- carla_debug("do_juce_check(%s, %s, %s)", filename_, stype, bool2str(doInit));
-
- juce::String filename;
-
- #ifdef CARLA_OS_WIN
- // Fix for wine usage
- if (juce::File("Z:\\usr\\").isDirectory() && filename_[0] == '/')
- {
- filename = filename_;
- filename.replace("/", "\\");
- filename = "Z:" + filename;
- }
- else
- #endif
- filename = juce::File(filename_).getFullPathName();
-
- CarlaScopedPointer<juce::AudioPluginFormat> pluginFormat;
-
- /* */ if (std::strcmp(stype, "VST2") == 0)
- {
- #if JUCE_PLUGINHOST_VST
- pluginFormat = new juce::VSTPluginFormat();
- #else
- DISCOVERY_OUT("error", "VST2 support not available");
- #endif
- }
- else if (std::strcmp(stype, "VST3") == 0)
- {
- #if JUCE_PLUGINHOST_VST3
- pluginFormat = new juce::VST3PluginFormat();
- #else
- DISCOVERY_OUT("error", "VST3 support not available");
- #endif
- }
- else if (std::strcmp(stype, "AU") == 0)
- {
- #if JUCE_PLUGINHOST_AU
- pluginFormat = new juce::AudioUnitPluginFormat();
- #else
- DISCOVERY_OUT("error", "AU support not available");
- #endif
- }
-
- if (pluginFormat == nullptr)
- {
- DISCOVERY_OUT("error", stype << " support not available");
- return;
- }
-
- #ifdef CARLA_OS_WIN
- CARLA_SAFE_ASSERT_RETURN(juce::File(filename).existsAsFile(),);
- #endif
- CARLA_SAFE_ASSERT_RETURN(pluginFormat->fileMightContainThisPluginType(filename),);
-
- juce::OwnedArray<juce::PluginDescription> results;
- pluginFormat->findAllTypesForFile(results, filename);
-
- if (results.size() == 0)
- {
- DISCOVERY_OUT("error", "No plugins found");
- return;
- }
-
- for (juce::PluginDescription **it = results.begin(), **end = results.end(); it != end; ++it)
- {
- juce::PluginDescription* const desc(*it);
-
- uint hints = 0x0;
- int audioIns = desc->numInputChannels;
- int audioOuts = desc->numOutputChannels;
- int midiIns = 0;
- int midiOuts = 0;
- int parameters = 0;
-
- if (desc->isInstrument)
- hints |= PLUGIN_IS_SYNTH;
-
- if (doInit)
- {
- if (std::unique_ptr<juce::AudioPluginInstance> instance
- = pluginFormat->createInstanceFromDescription(*desc, kSampleRate, kBufferSize))
- {
- instance->refreshParameterList();
-
- parameters = instance->getParameters().size();
-
- if (instance->hasEditor())
- hints |= PLUGIN_HAS_CUSTOM_UI;
- if (instance->acceptsMidi())
- midiIns = 1;
- if (instance->producesMidi())
- midiOuts = 1;
- }
- }
-
- DISCOVERY_OUT("init", "-----------");
- DISCOVERY_OUT("build", BINARY_NATIVE);
- DISCOVERY_OUT("hints", hints);
- DISCOVERY_OUT("name", desc->descriptiveName);
- DISCOVERY_OUT("label", desc->name);
- DISCOVERY_OUT("maker", desc->manufacturerName);
- DISCOVERY_OUT("uniqueId", desc->uid);
- DISCOVERY_OUT("audio.ins", audioIns);
- DISCOVERY_OUT("audio.outs", audioOuts);
- DISCOVERY_OUT("midi.ins", midiIns);
- DISCOVERY_OUT("midi.outs", midiOuts);
- DISCOVERY_OUT("parameters.ins", parameters);
- DISCOVERY_OUT("end", "------------");
- }
- }
- #endif // USING_JUCE_FOR_VST2
-
- static void do_fluidsynth_check(const char* const filename, const bool doInit)
- {
- #ifdef HAVE_FLUIDSYNTH
- const water::String jfilename = water::String(CharPointer_UTF8(filename));
- const File file(jfilename);
-
- if (! file.existsAsFile())
- {
- DISCOVERY_OUT("error", "Requested file is not valid or does not exist");
- return;
- }
-
- if (! fluid_is_soundfont(filename))
- {
- DISCOVERY_OUT("error", "Not a SF2 file");
- return;
- }
-
- int programs = 0;
-
- if (doInit)
- {
- fluid_settings_t* const f_settings = new_fluid_settings();
- CARLA_SAFE_ASSERT_RETURN(f_settings != nullptr,);
-
- fluid_synth_t* const f_synth = new_fluid_synth(f_settings);
- CARLA_SAFE_ASSERT_RETURN(f_synth != nullptr,);
-
- const int f_id = fluid_synth_sfload(f_synth, filename, 0);
-
- if (f_id < 0)
- {
- DISCOVERY_OUT("error", "Failed to load SF2 file");
- return;
- }
-
- if (fluid_sfont_t* const f_sfont = fluid_synth_get_sfont_by_id(f_synth, static_cast<uint>(f_id)))
- {
- #if FLUIDSYNTH_VERSION_MAJOR < 2
- fluid_preset_t f_preset;
-
- f_sfont->iteration_start(f_sfont);
- for (; f_sfont->iteration_next(f_sfont, &f_preset);)
- #else
- fluid_sfont_iteration_start(f_sfont);
- for (; fluid_sfont_iteration_next(f_sfont);)
- #endif
- ++programs;
- }
-
- delete_fluid_synth(f_synth);
- delete_fluid_settings(f_settings);
- }
-
- CarlaString name(file.getFileNameWithoutExtension().toRawUTF8());
- CarlaString label(name);
-
- // 2 channels
- DISCOVERY_OUT("init", "-----------");
- DISCOVERY_OUT("build", BINARY_NATIVE);
- DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
- DISCOVERY_OUT("name", name.buffer());
- DISCOVERY_OUT("label", label.buffer());
- DISCOVERY_OUT("audio.outs", 2);
- DISCOVERY_OUT("midi.ins", 1);
- DISCOVERY_OUT("parameters.ins", 13); // defined in Carla
- DISCOVERY_OUT("parameters.outs", 1);
- DISCOVERY_OUT("end", "------------");
-
- // 16 channels
- if (doInit && (name.isEmpty() || programs <= 1))
- return;
-
- name += " (16 outputs)";
-
- DISCOVERY_OUT("init", "-----------");
- DISCOVERY_OUT("build", BINARY_NATIVE);
- DISCOVERY_OUT("hints", PLUGIN_IS_SYNTH);
- DISCOVERY_OUT("name", name.buffer());
- DISCOVERY_OUT("label", label.buffer());
- DISCOVERY_OUT("audio.outs", 32);
- DISCOVERY_OUT("midi.ins", 1);
- DISCOVERY_OUT("parameters.ins", 13); // defined in Carla
- DISCOVERY_OUT("parameters.outs", 1);
- DISCOVERY_OUT("end", "------------");
- #else // HAVE_FLUIDSYNTH
- DISCOVERY_OUT("error", "SF2 support not available");
- return;
-
- // unused
- (void)filename;
- (void)doInit;
- #endif
- }
-
- // ------------------------------ main entry point ------------------------------
-
- int main(int argc, char* argv[])
- {
- if (argc != 3)
- {
- carla_stdout("usage: %s <type> </path/to/plugin>", argv[0]);
- return 1;
- }
-
- const char* const stype = argv[1];
- const char* const filename = argv[2];
- const PluginType type = getPluginTypeFromString(stype);
-
- CarlaString filenameCheck(filename);
- filenameCheck.toLower();
-
- bool openLib = false;
- lib_t handle = nullptr;
-
- switch (type)
- {
- case PLUGIN_LADSPA:
- case PLUGIN_DSSI:
- case PLUGIN_VST2:
- openLib = true;
- default:
- break;
- }
-
- if (type != PLUGIN_SF2 && filenameCheck.contains("fluidsynth", true))
- {
- DISCOVERY_OUT("info", "skipping fluidsynth based plugin");
- return 0;
- }
-
- #ifdef CARLA_OS_MAC
- if (type == PLUGIN_VST2 && (filenameCheck.endsWith(".vst") || filenameCheck.endsWith(".vst/")))
- openLib = false;
- #endif
-
- // ---------------------------------------------------------------------
- // Initialize OS features
-
- #ifdef CARLA_OS_WIN
- OleInitialize(nullptr);
- CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
- # ifndef __WINPTHREADS_VERSION
- // (non-portable) initialization of statically linked pthread library
- pthread_win32_process_attach_np();
- pthread_win32_thread_attach_np();
- # endif
- #endif
-
- // ---------------------------------------------------------------------
-
- if (openLib)
- {
- handle = lib_open(filename);
-
- if (handle == nullptr)
- {
- print_lib_error(filename);
- return 1;
- }
- }
-
- // never do init for dssi-vst, takes too long and it's crashy
- bool doInit = ! filenameCheck.contains("dssi-vst", true);
-
- if (doInit && getenv("CARLA_DISCOVERY_NO_PROCESSING_CHECKS") != nullptr)
- doInit = false;
-
- // ---------------------------------------------------------------------
-
- if (doInit && openLib && handle != nullptr)
- {
- // test fast loading & unloading DLL without initializing the plugin(s)
- if (! lib_close(handle))
- {
- print_lib_error(filename);
- return 1;
- }
-
- handle = lib_open(filename);
-
- if (handle == nullptr)
- {
- print_lib_error(filename);
- return 1;
- }
- }
-
- #ifndef BUILD_BRIDGE
- if (std::strcmp(filename, ":all") == 0)
- {
- do_cached_check(type);
- return 0;
- }
- #endif
-
- switch (type)
- {
- case PLUGIN_LADSPA:
- do_ladspa_check(handle, filename, doInit);
- break;
-
- case PLUGIN_DSSI:
- do_dssi_check(handle, filename, doInit);
- break;
-
- #ifndef BUILD_BRIDGE
- case PLUGIN_LV2:
- do_lv2_check(filename, doInit);
- break;
- #endif
-
- case PLUGIN_VST2:
- #if defined(USING_JUCE) && JUCE_PLUGINHOST_VST
- do_juce_check(filename, "VST2", doInit);
- #else
- do_vst_check(handle, filename, doInit);
- #endif
- break;
-
- case PLUGIN_VST3:
- #if defined(USING_JUCE) && JUCE_PLUGINHOST_VST3
- do_juce_check(filename, "VST3", doInit);
- #else
- DISCOVERY_OUT("error", "VST3 support not available");
- #endif
- break;
-
- case PLUGIN_AU:
- #if defined(USING_JUCE) && JUCE_PLUGINHOST_AU
- do_juce_check(filename, "AU", doInit);
- #else
- DISCOVERY_OUT("error", "AU support not available");
- #endif
- break;
-
- case PLUGIN_SF2:
- do_fluidsynth_check(filename, doInit);
- break;
-
- default:
- break;
- }
-
- if (openLib && handle != nullptr)
- lib_close(handle);
-
- // ---------------------------------------------------------------------
-
- #ifdef CARLA_OS_WIN
- #ifndef __WINPTHREADS_VERSION
- pthread_win32_thread_detach_np();
- pthread_win32_process_detach_np();
- #endif
- CoUninitialize();
- OleUninitialize();
- #endif
-
- return 0;
- }
-
- // --------------------------------------------------------------------------
|