Browse Source

discovery: try same plugin under macos x64 rosetta for non-juce

Signed-off-by: falkTX <falktx@falktx.com>
pull/1775/head
falkTX 1 year ago
parent
commit
b160a9b189
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 91 additions and 69 deletions
  1. +91
    -69
      source/discovery/carla-discovery.cpp

+ 91
- 69
source/discovery/carla-discovery.cpp View File

@@ -301,7 +301,6 @@ static void do_ladspa_check(lib_t& libHandle, const char* const filename, const
uint hints = 0x0; uint hints = 0x0;
uint audioIns = 0; uint audioIns = 0;
uint audioOuts = 0; uint audioOuts = 0;
uint audioTotal = 0;
uint parametersIns = 0; uint parametersIns = 0;
uint parametersOuts = 0; uint parametersOuts = 0;
uint parametersTotal = 0; uint parametersTotal = 0;
@@ -320,8 +319,6 @@ static void do_ladspa_check(lib_t& libHandle, const char* const filename, const
audioIns += 1; audioIns += 1;
else if (LADSPA_IS_PORT_OUTPUT(portDescriptor)) else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
audioOuts += 1; audioOuts += 1;

audioTotal += 1;
} }
else if (LADSPA_IS_PORT_CONTROL(portDescriptor)) else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
{ {
@@ -565,7 +562,6 @@ static void do_dssi_check(lib_t& libHandle, const char* const filename, const bo
uint hints = 0x0; uint hints = 0x0;
uint audioIns = 0; uint audioIns = 0;
uint audioOuts = 0; uint audioOuts = 0;
uint audioTotal = 0;
uint midiIns = 0; uint midiIns = 0;
uint parametersIns = 0; uint parametersIns = 0;
uint parametersOuts = 0; uint parametersOuts = 0;
@@ -585,8 +581,6 @@ static void do_dssi_check(lib_t& libHandle, const char* const filename, const bo
audioIns += 1; audioIns += 1;
else if (LADSPA_IS_PORT_OUTPUT(portDescriptor)) else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
audioOuts += 1; audioOuts += 1;

audioTotal += 1;
} }
else if (LADSPA_IS_PORT_CONTROL(portDescriptor)) else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
{ {
@@ -1051,7 +1045,7 @@ static intptr_t VSTCALLBACK vstHostCallback(AEffect* const effect, const int32_t
return ret; return ret;
} }


static void do_vst2_check(lib_t& libHandle, const char* const filename, const bool doInit)
static bool do_vst2_check(lib_t& libHandle, const char* const filename, const bool doInit)
{ {
VST_Function vstFn = nullptr; VST_Function vstFn = nullptr;


@@ -1062,8 +1056,12 @@ static void do_vst2_check(lib_t& libHandle, const char* const filename, const bo
{ {
if (! bundleLoader.load(filename)) if (! bundleLoader.load(filename))
{ {
#ifdef __aarch64__
return true;
#else
DISCOVERY_OUT("error", "Failed to load VST2 bundle executable"); DISCOVERY_OUT("error", "Failed to load VST2 bundle executable");
return;
return false;
#endif
} }


vstFn = bundleLoader.getSymbol<VST_Function>(CFSTR("main_macho")); vstFn = bundleLoader.getSymbol<VST_Function>(CFSTR("main_macho"));
@@ -1074,7 +1072,7 @@ static void do_vst2_check(lib_t& libHandle, const char* const filename, const bo
if (vstFn == nullptr) if (vstFn == nullptr)
{ {
DISCOVERY_OUT("error", "Not a VST2 plugin"); DISCOVERY_OUT("error", "Not a VST2 plugin");
return;
return false;
} }
} }
else else
@@ -1089,7 +1087,7 @@ static void do_vst2_check(lib_t& libHandle, const char* const filename, const bo
if (vstFn == nullptr) if (vstFn == nullptr)
{ {
DISCOVERY_OUT("error", "Not a VST plugin"); DISCOVERY_OUT("error", "Not a VST plugin");
return;
return false;
} }
} }
} }
@@ -1099,7 +1097,7 @@ static void do_vst2_check(lib_t& libHandle, const char* const filename, const bo
if (effect == nullptr || effect->magic != kEffectMagic) if (effect == nullptr || effect->magic != kEffectMagic)
{ {
DISCOVERY_OUT("error", "Failed to init VST plugin, or VST magic failed"); DISCOVERY_OUT("error", "Failed to init VST plugin, or VST magic failed");
return;
return false;
} }


if (effect->uniqueID == 0) if (effect->uniqueID == 0)
@@ -1124,7 +1122,7 @@ static void do_vst2_check(lib_t& libHandle, const char* const filename, const bo
{ {
DISCOVERY_OUT("error", "Plugin doesn't have an Unique ID after being open"); DISCOVERY_OUT("error", "Plugin doesn't have an Unique ID after being open");
effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f); effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
return;
return false;
} }


gVstCurrentUniqueId = effect->uniqueID; gVstCurrentUniqueId = effect->uniqueID;
@@ -1403,9 +1401,9 @@ static void do_vst2_check(lib_t& libHandle, const char* const filename, const bo
effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f); effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
} }


#ifndef CARLA_OS_MAC
return;
return false;


#ifndef CARLA_OS_MAC
// unused // unused
(void)filename; (void)filename;
#endif #endif
@@ -1510,7 +1508,13 @@ struct carla_v3_event_list : v3_event_list_cpp {
static v3_result V3_API carla_add_event(void*, v3_event*) { return V3_NOT_IMPLEMENTED; } static v3_result V3_API carla_add_event(void*, v3_event*) { return V3_NOT_IMPLEMENTED; }
}; };


static void do_vst3_check(lib_t& libHandle, const char* const filename, const bool doInit)
static bool v3_exit_false(const V3_EXITFN v3_exit)
{
v3_exit();
return false;
}

static bool do_vst3_check(lib_t& libHandle, const char* const filename, const bool doInit)
{ {
V3_ENTRYFN v3_entry = nullptr; V3_ENTRYFN v3_entry = nullptr;
V3_EXITFN v3_exit = nullptr; V3_EXITFN v3_exit = nullptr;
@@ -1526,8 +1530,12 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo
#ifdef CARLA_OS_MAC #ifdef CARLA_OS_MAC
if (! bundleLoader.load(filename)) if (! bundleLoader.load(filename))
{ {
#ifdef __aarch64__
return true;
#else
DISCOVERY_OUT("error", "Failed to load VST3 bundle executable"); DISCOVERY_OUT("error", "Failed to load VST3 bundle executable");
return;
return false;
#endif
} }


v3_entry = bundleLoader.getSymbol<V3_ENTRYFN>(CFSTR(V3_ENTRYFNNAME)); v3_entry = bundleLoader.getSymbol<V3_ENTRYFN>(CFSTR(V3_ENTRYFNNAME));
@@ -1550,7 +1558,7 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo
if (! water::File(binaryfilename).existsAsFile()) if (! water::File(binaryfilename).existsAsFile())
{ {
DISCOVERY_OUT("error", "Failed to find a suitable VST3 bundle binary"); DISCOVERY_OUT("error", "Failed to find a suitable VST3 bundle binary");
return;
return false;
} }


libHandle = lib_open(binaryfilename.toRawUTF8()); libHandle = lib_open(binaryfilename.toRawUTF8());
@@ -1558,7 +1566,7 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo
if (libHandle == nullptr) if (libHandle == nullptr)
{ {
print_lib_error(filename); print_lib_error(filename);
return;
return false;
} }
#endif #endif
} }
@@ -1573,7 +1581,7 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo
if (v3_entry == nullptr || v3_exit == nullptr || v3_get == nullptr) if (v3_entry == nullptr || v3_exit == nullptr || v3_get == nullptr)
{ {
DISCOVERY_OUT("error", "Not a VST3 plugin"); DISCOVERY_OUT("error", "Not a VST3 plugin");
return;
return false;
} }


// call entry point // call entry point
@@ -1591,21 +1599,21 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo


// fetch initial factory // fetch initial factory
v3_plugin_factory** factory1 = v3_get(); v3_plugin_factory** factory1 = v3_get();
CARLA_SAFE_ASSERT_RETURN(factory1 != nullptr, v3_exit());
CARLA_SAFE_ASSERT_RETURN(factory1 != nullptr, v3_exit_false(v3_exit));


// get factory info // get factory info
v3_factory_info factoryInfo = {}; v3_factory_info factoryInfo = {};
CARLA_SAFE_ASSERT_RETURN(v3_cpp_obj(factory1)->get_factory_info(factory1, &factoryInfo) == V3_OK, v3_exit());
CARLA_SAFE_ASSERT_RETURN(v3_cpp_obj(factory1)->get_factory_info(factory1, &factoryInfo) == V3_OK, v3_exit_false(v3_exit));


// get num classes // get num classes
const int32_t numClasses = v3_cpp_obj(factory1)->num_classes(factory1); const int32_t numClasses = v3_cpp_obj(factory1)->num_classes(factory1);
CARLA_SAFE_ASSERT_RETURN(numClasses > 0, v3_exit());
CARLA_SAFE_ASSERT_RETURN(numClasses > 0, v3_exit_false(v3_exit));


// query 2nd factory // query 2nd factory
v3_plugin_factory_2** factory2 = nullptr; v3_plugin_factory_2** factory2 = nullptr;
if (v3_cpp_obj_query_interface(factory1, v3_plugin_factory_2_iid, &factory2) == V3_OK) if (v3_cpp_obj_query_interface(factory1, v3_plugin_factory_2_iid, &factory2) == V3_OK)
{ {
CARLA_SAFE_ASSERT_RETURN(factory2 != nullptr, v3_exit());
CARLA_SAFE_ASSERT_RETURN(factory2 != nullptr, v3_exit_false(v3_exit));
} }
else else
{ {
@@ -1617,7 +1625,7 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo
v3_plugin_factory_3** factory3 = nullptr; v3_plugin_factory_3** factory3 = nullptr;
if (factory2 != nullptr && v3_cpp_obj_query_interface(factory2, v3_plugin_factory_3_iid, &factory3) == V3_OK) if (factory2 != nullptr && v3_cpp_obj_query_interface(factory2, v3_plugin_factory_3_iid, &factory3) == V3_OK)
{ {
CARLA_SAFE_ASSERT_RETURN(factory3 != nullptr, v3_exit());
CARLA_SAFE_ASSERT_RETURN(factory3 != nullptr, v3_exit_false(v3_exit));
} }
else else
{ {
@@ -1910,6 +1918,7 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo
v3_cpp_obj_unref(factory1); v3_cpp_obj_unref(factory1);


v3_exit(); v3_exit();
return false;
} }
#endif // ! USING_JUCE_FOR_VST3 #endif // ! USING_JUCE_FOR_VST3


@@ -1950,7 +1959,13 @@ struct carla_clap_host : clap_host_t {
} }
}; };


static void do_clap_check(lib_t& libHandle, const char* const filename, const bool doInit)
static bool clap_deinit_false(const clap_plugin_entry_t* const entry)
{
entry->deinit();
return false;
}

static bool do_clap_check(lib_t& libHandle, const char* const filename, const bool doInit)
{ {
const clap_plugin_entry_t* entry = nullptr; const clap_plugin_entry_t* entry = nullptr;


@@ -1962,8 +1977,12 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
{ {
if (! bundleLoader.load(filename)) if (! bundleLoader.load(filename))
{ {
#ifdef __aarch64__
return true;
#else
DISCOVERY_OUT("error", "Failed to load CLAP bundle executable"); DISCOVERY_OUT("error", "Failed to load CLAP bundle executable");
return;
return false;
#endif
} }


entry = bundleLoader.getSymbol<const clap_plugin_entry_t*>(CFSTR("clap_entry")); entry = bundleLoader.getSymbol<const clap_plugin_entry_t*>(CFSTR("clap_entry"));
@@ -1978,14 +1997,14 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
if (entry == nullptr || entry->init == nullptr || entry->deinit == nullptr || entry->get_factory == nullptr) if (entry == nullptr || entry->init == nullptr || entry->deinit == nullptr || entry->get_factory == nullptr)
{ {
DISCOVERY_OUT("error", "Not a CLAP plugin"); DISCOVERY_OUT("error", "Not a CLAP plugin");
return;
return false;
} }


// ensure compatible version // ensure compatible version
if (!clap_version_is_compatible(entry->clap_version)) if (!clap_version_is_compatible(entry->clap_version))
{ {
DISCOVERY_OUT("error", "Incompatible CLAP plugin"); DISCOVERY_OUT("error", "Incompatible CLAP plugin");
return;
return false;
} }


const water::String pluginPath(water::File(filename).getParentDirectory().getFullPathName()); const water::String pluginPath(water::File(filename).getParentDirectory().getFullPathName());
@@ -1993,7 +2012,7 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
if (!entry->init(pluginPath.toRawUTF8())) if (!entry->init(pluginPath.toRawUTF8()))
{ {
DISCOVERY_OUT("error", "CLAP plugin failed to initialize"); DISCOVERY_OUT("error", "CLAP plugin failed to initialize");
return;
return false;
} }


const clap_plugin_factory_t* const factory = static_cast<const clap_plugin_factory_t*>( const clap_plugin_factory_t* const factory = static_cast<const clap_plugin_factory_t*>(
@@ -2001,7 +2020,7 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
CARLA_SAFE_ASSERT_RETURN(factory != nullptr CARLA_SAFE_ASSERT_RETURN(factory != nullptr
&& factory->get_plugin_count != nullptr && factory->get_plugin_count != nullptr
&& factory->get_plugin_descriptor != nullptr && factory->get_plugin_descriptor != nullptr
&& factory->create_plugin != nullptr, entry->deinit());
&& factory->create_plugin != nullptr, clap_deinit_false(entry));


if (const uint32_t count = factory->get_plugin_count(factory)) if (const uint32_t count = factory->get_plugin_count(factory))
{ {
@@ -2025,13 +2044,10 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
uint hints = 0x0; uint hints = 0x0;
uint audioIns = 0; uint audioIns = 0;
uint audioOuts = 0; uint audioOuts = 0;
// uint audioTotal = 0;
uint midiIns = 0; uint midiIns = 0;
uint midiOuts = 0; uint midiOuts = 0;
// uint midiTotal = 0;
uint parametersIns = 0; uint parametersIns = 0;
uint parametersOuts = 0; uint parametersOuts = 0;
// uint parametersTotal = 0;
PluginCategory category = PLUGIN_CATEGORY_NONE; PluginCategory category = PLUGIN_CATEGORY_NONE;


const clap_plugin_audio_ports_t* const audioPorts = static_cast<const clap_plugin_audio_ports_t*>( const clap_plugin_audio_ports_t* const audioPorts = static_cast<const clap_plugin_audio_ports_t*>(
@@ -2069,8 +2085,6 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo


audioOuts += info.channel_count; audioOuts += info.channel_count;
} }

// audioTotal = audioIns + audioOuts;
} }


if (notePorts != nullptr) if (notePorts != nullptr)
@@ -2096,8 +2110,6 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
if (info.supported_dialects & CLAP_NOTE_DIALECT_MIDI) if (info.supported_dialects & CLAP_NOTE_DIALECT_MIDI)
++midiOuts; ++midiOuts;
} }

// midiTotal = midiIns + midiOuts;
} }


if (params != nullptr) if (params != nullptr)
@@ -2118,8 +2130,6 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
else else
++parametersIns; ++parametersIns;
} }

// parametersTotal = parametersIns + parametersOuts;
} }


if (desc->features != nullptr) if (desc->features != nullptr)
@@ -2167,6 +2177,7 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
} }


entry->deinit(); entry->deinit();
return false;
} }


#ifdef USING_JUCE #ifdef USING_JUCE
@@ -2266,10 +2277,10 @@ static bool do_juce_check(const char* const filename_, const char* const stype,


if (results.size() == 0) if (results.size() == 0)
{ {
#if defined(CARLA_OS_MAC) && defined(__aarch64__)
#if defined(CARLA_OS_MAC) && defined(__aarch64__)
if (std::strcmp(stype, "VST2") == 0 || std::strcmp(stype, "VST3") == 0) if (std::strcmp(stype, "VST2") == 0 || std::strcmp(stype, "VST3") == 0)
return true; return true;
#endif
#endif
DISCOVERY_OUT("error", "No plugins found"); DISCOVERY_OUT("error", "No plugins found");
return false; return false;
} }
@@ -2523,21 +2534,43 @@ int main(int argc, const char* argv[])
CarlaString filenameCheck(filename); CarlaString filenameCheck(filename);
filenameCheck.toLower(); filenameCheck.toLower();


bool openLib = false;
bool openLib;
lib_t handle = nullptr; lib_t handle = nullptr;


switch (type) switch (type)
{ {
case PLUGIN_LADSPA: case PLUGIN_LADSPA:
case PLUGIN_DSSI: case PLUGIN_DSSI:
// only available as single binary
openLib = true;
break;

case PLUGIN_VST2: case PLUGIN_VST2:
case PLUGIN_CLAP:
#ifdef CARLA_OS_MAC
// bundle on macOS
openLib = false;
#else
// single binary on all else
openLib = true; openLib = true;
#endif
break; break;

case PLUGIN_VST3: case PLUGIN_VST3:
case PLUGIN_CLAP:
#if defined(CARLA_OS_MAC)
// bundle on macOS
openLib = false;
#elif defined(CARLA_OS_WIN)
// either file or bundle on Windows
openLib = water::File(filename).existsAsFile(); openLib = water::File(filename).existsAsFile();
#else
// single binary on all else
openLib = true;
#endif
break; break;

default: default:
openLib = false;
break; break;
} }


@@ -2547,11 +2580,6 @@ int main(int argc, const char* argv[])
return 0; return 0;
} }


#ifdef CARLA_OS_MAC
if (type == PLUGIN_VST2 && (filenameCheck.endsWith(".vst") || filenameCheck.endsWith(".vst/")))
openLib = false;
#endif

// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
// Initialize OS features // Initialize OS features


@@ -2644,10 +2672,9 @@ int main(int argc, const char* argv[])
break; break;
} }
#endif #endif
#ifdef USING_JUCE
// some macOS plugins have not been yet ported to arm64, re-run them in x86_64 mode if discovery fails // some macOS plugins have not been yet ported to arm64, re-run them in x86_64 mode if discovery fails
bool retryJucePlugin = false;
#endif
bool retryAsX64lugin = false;


switch (type) switch (type)
{ {
@@ -2667,17 +2694,17 @@ int main(int argc, const char* argv[])


case PLUGIN_VST2: case PLUGIN_VST2:
#if defined(USING_JUCE) && JUCE_PLUGINHOST_VST #if defined(USING_JUCE) && JUCE_PLUGINHOST_VST
retryJucePlugin = do_juce_check(filename, "VST2", doInit);
retryAsX64lugin = do_juce_check(filename, "VST2", doInit);
#else #else
do_vst2_check(handle, filename, doInit);
retryAsX64lugin = do_vst2_check(handle, filename, doInit);
#endif #endif
break; break;


case PLUGIN_VST3: case PLUGIN_VST3:
#if defined(USING_JUCE) && JUCE_PLUGINHOST_VST3 #if defined(USING_JUCE) && JUCE_PLUGINHOST_VST3
retryJucePlugin = do_juce_check(filename, "VST3", doInit);
retryAsX64lugin = do_juce_check(filename, "VST3", doInit);
#else #else
do_vst3_check(handle, filename, doInit);
retryAsX64lugin = do_vst3_check(handle, filename, doInit);
#endif #endif
break; break;


@@ -2696,7 +2723,7 @@ int main(int argc, const char* argv[])
#endif #endif


case PLUGIN_CLAP: case PLUGIN_CLAP:
do_clap_check(handle, filename, doInit);
retryAsX64lugin = do_clap_check(handle, filename, doInit);
break; break;


case PLUGIN_DLS: case PLUGIN_DLS:
@@ -2709,9 +2736,14 @@ int main(int argc, const char* argv[])
break; break;
} }


#if defined(CARLA_OS_MAC) && defined(USING_JUCE) && defined(__aarch64__)
if (retryJucePlugin)
if (openLib && handle != nullptr)
lib_close(handle);

gPipe = nullptr;

if (retryAsX64lugin)
{ {
#if defined(CARLA_OS_MAC) && defined(__aarch64__)
DISCOVERY_OUT("warning", "No plugins found while scanning in arm64 mode, will try x86_64 now"); DISCOVERY_OUT("warning", "No plugins found while scanning in arm64 mode, will try x86_64 now");


cpu_type_t pref = CPU_TYPE_X86_64; cpu_type_t pref = CPU_TYPE_X86_64;
@@ -2728,13 +2760,8 @@ int main(int argc, const char* argv[])
int status; int status;
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
} }
#endif
} }
#endif

if (openLib && handle != nullptr)
lib_close(handle);

gPipe = nullptr;


// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------


@@ -2748,11 +2775,6 @@ int main(int argc, const char* argv[])
#endif #endif


return 0; return 0;

#ifdef USING_JUCE
// might be unused
(void)retryJucePlugin;
#endif
} }


// ------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------

Loading…
Cancel
Save