Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created July 16, 2023 16:11
Show Gist options
  • Save Xenakios/86491f352db09fae9ce887b74e69f16f to your computer and use it in GitHub Desktop.
Save Xenakios/86491f352db09fae9ce887b74e69f16f to your computer and use it in GitHub Desktop.
struct ClapManufacturingInfo
{
ClapManufacturingInfo() {}
ClapManufacturingInfo(int index, juce::String fn, const clap_plugin_descriptor_t* desc)
: filename(fn), subpluginindex(index)
{
manufacturer = desc->vendor;
name = desc->name;
auto ptr = desc->features;
while (ptr)
{
features.add(*ptr);
if (*ptr==nullptr)
break;
++ptr;
}
}
juce::String filename;
juce::String manufacturer;
juce::String name;
int subpluginindex = 0;
juce::StringArray features;
};
std::vector<ClapManufacturingInfo> ClapProcessor::getAvailablePlugins()
{
std::vector<ClapManufacturingInfo> result;
#if JUCE_WINDOWS
// gotta figure out a more general way to get this path...
juce::File clapdir("C:\\Program Files\\Common Files\\CLAP");
#else
juce::File clapdir("/Library/Audio/Plug-Ins/CLAP");
#endif
juce::RangedDirectoryIterator iter(clapdir,true,"*.clap",juce::File::TypesOfFileToFind::findFilesAndDirectories);
for (auto& iterentry : iter)
{
std::cout << "trying to open " << iterentry.getFile().getFullPathName() << "...";
juce::DynamicLibrary dll;
juce::String clapfilename = iterentry.getFile().getFullPathName();
#if JUCE_MAC
clapfilename += "/Contents/MacOS/"+iterentry.getFile().getFileNameWithoutExtension();
#endif
if (dll.open(clapfilename))
{
std::cout << "OK\n";
clap_plugin_entry_t* entry = (clap_plugin_entry_t*)dll.getFunction("clap_entry");
if (entry)
{
entry->init(clapfilename.getCharPointer());
auto fac = (clap_plugin_factory_t *)entry->get_factory(CLAP_PLUGIN_FACTORY_ID);
auto plugin_count = fac->get_plugin_count(fac);
if (plugin_count<=0)
{
std::cout << "no plugins to manufacture from " << clapfilename << "\n";
} else
{
for (int i=0;i<plugin_count;++i)
{
auto desc = fac->get_plugin_descriptor(fac, i);
if (desc)
{
//std::cout << "can manufacture " << desc->name << "\n";
result.emplace_back(i,clapfilename,desc);
}
}
}
entry->deinit();
}
} else
{
std::cout << clapfilename << " FAILED!\n";
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment