Chris@0: Chris@0: package org.vamp_plugins; Chris@0: Chris@23: /** Chris@23: * PluginLoader loads a Vamp plugin by searching the standard Vamp Chris@23: * installation path, and returns a Plugin object wrapping the native Chris@23: * plugin. Chris@23: * Chris@23: * To load a plugin call PluginLoader.getInstance().loadPlugin(key, Chris@23: * rate), where rate is the processing sample rate and key is the Chris@23: * plugin key consisting of the plugin's library base name and its Chris@23: * identifier, colon-separated. For example, Chris@23: * Chris@23: * Plugin p = PluginLoader.getInstance().loadPlugin("vamp-example-plugins:percussiononsets", 44100); Chris@23: */ Chris@0: public class PluginLoader Chris@0: { Chris@0: public class LoadFailedException extends Exception { }; Chris@0: Chris@23: /** Chris@23: * PluginLoader is a singleton. Return the instance of it. Chris@23: */ Chris@0: public static synchronized PluginLoader getInstance() { Chris@0: if (inst == null) { Chris@0: inst = new PluginLoader(); Chris@0: inst.initialise(); Chris@0: } Chris@0: return inst; Chris@0: } Chris@0: Chris@23: /** Chris@23: * Search for all available Vamp plugins, and return a list of Chris@23: * their plugin keys (suitable for passing to loadPlugin) in the Chris@23: * order in which they were found. Chris@23: */ Chris@24: public native String[] listPlugins(); Chris@23: Chris@23: /** Chris@23: * Load a native Vamp plugin from the plugin path. If the plugin Chris@23: * cannot be loaded, throw LoadFailedException. Chris@23: * Chris@23: * key is the plugin key consisting of the plugin's library base Chris@23: * name and its identifier, colon-separated; inputSampleRate is Chris@23: * the processing sample rate for input audio. Chris@23: * Chris@23: *!!! todo: adapter flags Chris@23: */ Chris@0: public Plugin loadPlugin(String key, float inputSampleRate) Chris@0: throws LoadFailedException { Chris@0: long handle = loadPluginNative(key, inputSampleRate); Chris@0: if (handle != 0) return new Plugin(handle); Chris@0: else throw new LoadFailedException(); Chris@0: } Chris@0: Chris@23: /** Chris@23: * Return the category hierarchy for a Vamp plugin, given its Chris@23: * identifying key. The hierarchy is a sequence of category names Chris@23: * giving the location of a plugin within a category forest, Chris@23: * containing the human-readable names of the plugin's category Chris@23: * tree root, followed by each of the nodes down to the leaf Chris@23: * containing the plugin. Chris@23: * Chris@23: * If the plugin has no category information, return an empty Chris@23: * list. Chris@23: */ Chris@24: public native String[] getPluginCategory(String key); Chris@23: Chris@0: private PluginLoader() { initialise(); } Chris@0: private native long loadPluginNative(String key, float inputSampleRate); Chris@0: private native void initialise(); Chris@0: private static PluginLoader inst; Chris@0: private long nativeHandle; Chris@0: Chris@0: static { Chris@0: System.loadLibrary("vamp-jni"); Chris@0: } Chris@0: } Chris@0: