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

audioTotal += 1;
}
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 audioIns = 0;
uint audioOuts = 0;
uint audioTotal = 0;
uint midiIns = 0;
uint parametersIns = 0;
uint parametersOuts = 0;
@@ -585,8 +581,6 @@ static void do_dssi_check(lib_t& libHandle, const char* const filename, const bo
audioIns += 1;
else if (LADSPA_IS_PORT_OUTPUT(portDescriptor))
audioOuts += 1;

audioTotal += 1;
}
else if (LADSPA_IS_PORT_CONTROL(portDescriptor))
{
@@ -1051,7 +1045,7 @@ static intptr_t VSTCALLBACK vstHostCallback(AEffect* const effect, const int32_t
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;

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

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)
{
DISCOVERY_OUT("error", "Not a VST2 plugin");
return;
return false;
}
}
else
@@ -1089,7 +1087,7 @@ static void do_vst2_check(lib_t& libHandle, const char* const filename, const bo
if (vstFn == nullptr)
{
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)
{
DISCOVERY_OUT("error", "Failed to init VST plugin, or VST magic failed");
return;
return false;
}

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");
effect->dispatcher(effect, effClose, 0, 0, nullptr, 0.0f);
return;
return false;
}

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);
}

#ifndef CARLA_OS_MAC
return;
return false;

#ifndef CARLA_OS_MAC
// unused
(void)filename;
#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 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_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
if (! bundleLoader.load(filename))
{
#ifdef __aarch64__
return true;
#else
DISCOVERY_OUT("error", "Failed to load VST3 bundle executable");
return;
return false;
#endif
}

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())
{
DISCOVERY_OUT("error", "Failed to find a suitable VST3 bundle binary");
return;
return false;
}

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)
{
print_lib_error(filename);
return;
return false;
}
#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)
{
DISCOVERY_OUT("error", "Not a VST3 plugin");
return;
return false;
}

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

// fetch initial factory
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
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
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
v3_plugin_factory_2** factory2 = nullptr;
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
{
@@ -1617,7 +1625,7 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo
v3_plugin_factory_3** factory3 = nullptr;
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
{
@@ -1910,6 +1918,7 @@ static void do_vst3_check(lib_t& libHandle, const char* const filename, const bo
v3_cpp_obj_unref(factory1);

v3_exit();
return false;
}
#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;

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

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)
{
DISCOVERY_OUT("error", "Not a CLAP plugin");
return;
return false;
}

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

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()))
{
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*>(
@@ -2001,7 +2020,7 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
CARLA_SAFE_ASSERT_RETURN(factory != nullptr
&& factory->get_plugin_count != 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))
{
@@ -2025,13 +2044,10 @@ static void do_clap_check(lib_t& libHandle, const char* const filename, const bo
uint hints = 0x0;
uint audioIns = 0;
uint audioOuts = 0;
// uint audioTotal = 0;
uint midiIns = 0;
uint midiOuts = 0;
// uint midiTotal = 0;
uint parametersIns = 0;
uint parametersOuts = 0;
// uint parametersTotal = 0;
PluginCategory category = PLUGIN_CATEGORY_NONE;

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;
}

// audioTotal = audioIns + audioOuts;
}

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)
++midiOuts;
}

// midiTotal = midiIns + midiOuts;
}

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

// parametersTotal = parametersIns + parametersOuts;
}

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

entry->deinit();
return false;
}

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

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

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

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

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();
#else
// single binary on all else
openLib = true;
#endif
break;

default:
openLib = false;
break;
}

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

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

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

@@ -2644,10 +2672,9 @@ int main(int argc, const char* argv[])
break;
}
#endif
#ifdef USING_JUCE
// 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)
{
@@ -2667,17 +2694,17 @@ int main(int argc, const char* argv[])

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

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

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

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

case PLUGIN_DLS:
@@ -2709,9 +2736,14 @@ int main(int argc, const char* argv[])
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");

cpu_type_t pref = CPU_TYPE_X86_64;
@@ -2728,13 +2760,8 @@ int main(int argc, const char* argv[])
int status;
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

return 0;

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

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

Loading…
Cancel
Save