示例#1
0
vector<string>
PluginLoader::Impl::listLibraryFilesFor(Enumeration enumeration)
{
    Files::Filter filter;
    
    switch (enumeration.type) {

    case Enumeration::All:
        filter.type = Files::Filter::All;
        break;

    case Enumeration::SinglePlugin:
    {
        string libraryName, identifier;
        if (!decomposePluginKey(enumeration.key, libraryName, identifier)) {
            std::cerr << "WARNING: Vamp::HostExt::PluginLoader: "
                      << "Invalid plugin key \"" << enumeration.key
                      << "\" in enumerate" << std::endl;
            return vector<string>();
        }
        filter.type = Files::Filter::Matching;
        filter.libraryNames.clear();
        filter.libraryNames.push_back(libraryName);
        break;
    }

    case Enumeration::InLibraries:
        filter.type = Files::Filter::Matching;
        filter.libraryNames = enumeration.libraryNames;
        break;

    case Enumeration::NotInLibraries:
        filter.type = Files::Filter::NotMatching;
        filter.libraryNames = enumeration.libraryNames;
        break;
    }
        
    return Files::listLibraryFilesMatching(filter);
}
示例#2
0
Plugin *
PluginLoader::Impl::loadPlugin(PluginKey key,
                               float inputSampleRate, int adapterFlags)
{
    string libname, identifier;
    if (!decomposePluginKey(key, libname, identifier)) {
        std::cerr << "Vamp::HostExt::PluginLoader: Invalid plugin key \""
                  << key << "\" in loadPlugin" << std::endl;
        return 0;
    }
        
    string fullPath = getLibraryPathForPlugin(key);
    if (fullPath == "") {
        std::cerr << "Vamp::HostExt::PluginLoader: No library found in Vamp path for plugin \"" << key << "\"" << std::endl;
        return 0;
    }
    
    void *handle = Files::loadLibrary(fullPath);
    if (!handle) return 0;
    
    VampGetPluginDescriptorFunction fn =
        (VampGetPluginDescriptorFunction)Files::lookupInLibrary
        (handle, "vampGetPluginDescriptor");

    if (!fn) {
        cerr << "Vamp::HostExt::PluginLoader: No vampGetPluginDescriptor function found in library \""
             << fullPath << "\"" << endl;
        Files::unloadLibrary(handle);
        return 0;
    }

    int index = 0;
    const VampPluginDescriptor *descriptor = 0;

    while ((descriptor = fn(VAMP_API_VERSION, index))) {

        if (string(descriptor->identifier) == identifier) {

            Vamp::PluginHostAdapter *plugin =
                new Vamp::PluginHostAdapter(descriptor, inputSampleRate);

            Plugin *adapter = new PluginDeletionNotifyAdapter(plugin, this);

            m_pluginLibraryHandleMap[adapter] = handle;

            if (adapterFlags & ADAPT_INPUT_DOMAIN) {
                if (adapter->getInputDomain() == Plugin::FrequencyDomain) {
                    adapter = new PluginInputDomainAdapter(adapter);
                }
            }

            if (adapterFlags & ADAPT_BUFFER_SIZE) {
                adapter = new PluginBufferingAdapter(adapter);
            }

            if (adapterFlags & ADAPT_CHANNEL_COUNT) {
                adapter = new PluginChannelAdapter(adapter);
            }

            return adapter;
        }

        ++index;
    }

    cerr << "Vamp::HostExt::PluginLoader: Plugin \""
         << identifier << "\" not found in library \""
         << fullPath << "\"" << endl;

    return 0;
}
示例#3
0
vector<PluginLoader::PluginKey>
PluginLoader::Impl::enumeratePlugins(Enumeration enumeration)
{
    string libraryName, identifier;
    if (enumeration.type == Enumeration::SinglePlugin) {
        decomposePluginKey(enumeration.key, libraryName, identifier);
    }
    
    vector<string> fullPaths = listLibraryFilesFor(enumeration);

    // For these we should warn if a plugin can be loaded from a library
    bool specific = (enumeration.type == Enumeration::SinglePlugin ||
                     enumeration.type == Enumeration::InLibraries);

    vector<PluginKey> added;
    
    for (size_t i = 0; i < fullPaths.size(); ++i) {

        string fullPath = fullPaths[i];
        void *handle = Files::loadLibrary(fullPath);
        if (!handle) continue;
            
        VampGetPluginDescriptorFunction fn =
            (VampGetPluginDescriptorFunction)Files::lookupInLibrary
            (handle, "vampGetPluginDescriptor");
            
        if (!fn) {
            if (specific) {
                cerr << "Vamp::HostExt::PluginLoader: "
                    << "No vampGetPluginDescriptor function found in library \""
                     << fullPath << "\"" << endl;
            }
            Files::unloadLibrary(handle);
            continue;
        }
            
        int index = 0;
        const VampPluginDescriptor *descriptor = 0;
        bool found = false;
            
        while ((descriptor = fn(VAMP_API_VERSION, index))) {
            ++index;
            if (identifier != "") {
                if (descriptor->identifier != identifier) {
                    continue;
                }
            }
            found = true;
            PluginKey key = composePluginKey(fullPath, descriptor->identifier);
            if (m_pluginLibraryNameMap.find(key) ==
                m_pluginLibraryNameMap.end()) {
                m_pluginLibraryNameMap[key] = fullPath;
            }
            added.push_back(key);
        }

        if (!found && specific) {
            cerr << "Vamp::HostExt::PluginLoader: Plugin \""
                 << identifier << "\" not found in library \""
                 << fullPath << "\"" << endl;
        }
            
        Files::unloadLibrary(handle);
    }

    if (enumeration.type == Enumeration::All) {
        m_allPluginsEnumerated = true;
    }

    return added;
}
示例#4
0
void
PluginLoader::Impl::enumeratePlugins(PluginKey forPlugin)
{
    vector<string> path = PluginHostAdapter::getPluginPath();

    string libraryName, identifier;
    if (forPlugin != "") {
        if (!decomposePluginKey(forPlugin, libraryName, identifier)) {
            std::cerr << "WARNING: Vamp::HostExt::PluginLoader: Invalid plugin key \""
                      << forPlugin << "\" in enumerate" << std::endl;
            return;
        }
    }

    for (size_t i = 0; i < path.size(); ++i) {
        
        vector<string> files = listFiles(path[i], PLUGIN_SUFFIX);

        for (vector<string>::iterator fi = files.begin();
             fi != files.end(); ++fi) {
            
            if (libraryName != "") {
                // libraryName is lowercased and lacking an extension,
                // as it came from the plugin key
                string temp = *fi;
                for (size_t i = 0; i < temp.length(); ++i) {
                    temp[i] = tolower(temp[i]);
                }
                string::size_type pi = temp.find('.');
                if (pi == string::npos) {
                    if (libraryName != temp) continue;
                } else {
                    if (libraryName != temp.substr(0, pi)) continue;
                }
            }

            string fullPath = path[i];
            fullPath = splicePath(fullPath, *fi);
            void *handle = loadLibrary(fullPath);
            if (!handle) continue;
            
            VampGetPluginDescriptorFunction fn =
                (VampGetPluginDescriptorFunction)lookupInLibrary
                (handle, "vampGetPluginDescriptor");
            
            if (!fn) {
                unloadLibrary(handle);
                continue;
            }
            
            int index = 0;
            const VampPluginDescriptor *descriptor = 0;
            
            while ((descriptor = fn(VAMP_API_VERSION, index))) {
                ++index;
                if (identifier != "") {
                    if (descriptor->identifier != identifier) continue;
                }
                PluginKey key = composePluginKey(*fi, descriptor->identifier);
//                std::cerr << "enumerate: " << key << " (path: " << fullPath << ")" << std::endl;
                if (m_pluginLibraryNameMap.find(key) ==
                    m_pluginLibraryNameMap.end()) {
                    m_pluginLibraryNameMap[key] = fullPath;
                }
            }
            
            unloadLibrary(handle);
        }
    }

    if (forPlugin == "") m_allPluginsEnumerated = true;
}