annotate org/vamp_plugins/PluginLoader.java @ 24:cd430fbf6795

Add getPluginCategory, more sensible return values, fix process, call new functions to test
author Chris Cannam
date Wed, 14 Nov 2012 18:10:40 +0000
parents cc9c503535d1
children 7d1118b3860d
rev   line source
Chris@0 1
Chris@0 2 package org.vamp_plugins;
Chris@0 3
Chris@23 4 /**
Chris@23 5 * PluginLoader loads a Vamp plugin by searching the standard Vamp
Chris@23 6 * installation path, and returns a Plugin object wrapping the native
Chris@23 7 * plugin.
Chris@23 8 *
Chris@23 9 * To load a plugin call PluginLoader.getInstance().loadPlugin(key,
Chris@23 10 * rate), where rate is the processing sample rate and key is the
Chris@23 11 * plugin key consisting of the plugin's library base name and its
Chris@23 12 * identifier, colon-separated. For example,
Chris@23 13 *
Chris@23 14 * Plugin p = PluginLoader.getInstance().loadPlugin("vamp-example-plugins:percussiononsets", 44100);
Chris@23 15 */
Chris@0 16 public class PluginLoader
Chris@0 17 {
Chris@0 18 public class LoadFailedException extends Exception { };
Chris@0 19
Chris@23 20 /**
Chris@23 21 * PluginLoader is a singleton. Return the instance of it.
Chris@23 22 */
Chris@0 23 public static synchronized PluginLoader getInstance() {
Chris@0 24 if (inst == null) {
Chris@0 25 inst = new PluginLoader();
Chris@0 26 inst.initialise();
Chris@0 27 }
Chris@0 28 return inst;
Chris@0 29 }
Chris@0 30
Chris@23 31 /**
Chris@23 32 * Search for all available Vamp plugins, and return a list of
Chris@23 33 * their plugin keys (suitable for passing to loadPlugin) in the
Chris@23 34 * order in which they were found.
Chris@23 35 */
Chris@24 36 public native String[] listPlugins();
Chris@23 37
Chris@23 38 /**
Chris@23 39 * Load a native Vamp plugin from the plugin path. If the plugin
Chris@23 40 * cannot be loaded, throw LoadFailedException.
Chris@23 41 *
Chris@23 42 * key is the plugin key consisting of the plugin's library base
Chris@23 43 * name and its identifier, colon-separated; inputSampleRate is
Chris@23 44 * the processing sample rate for input audio.
Chris@23 45 *
Chris@23 46 *!!! todo: adapter flags
Chris@23 47 */
Chris@0 48 public Plugin loadPlugin(String key, float inputSampleRate)
Chris@0 49 throws LoadFailedException {
Chris@0 50 long handle = loadPluginNative(key, inputSampleRate);
Chris@0 51 if (handle != 0) return new Plugin(handle);
Chris@0 52 else throw new LoadFailedException();
Chris@0 53 }
Chris@0 54
Chris@23 55 /**
Chris@23 56 * Return the category hierarchy for a Vamp plugin, given its
Chris@23 57 * identifying key. The hierarchy is a sequence of category names
Chris@23 58 * giving the location of a plugin within a category forest,
Chris@23 59 * containing the human-readable names of the plugin's category
Chris@23 60 * tree root, followed by each of the nodes down to the leaf
Chris@23 61 * containing the plugin.
Chris@23 62 *
Chris@23 63 * If the plugin has no category information, return an empty
Chris@23 64 * list.
Chris@23 65 */
Chris@24 66 public native String[] getPluginCategory(String key);
Chris@23 67
Chris@0 68 private PluginLoader() { initialise(); }
Chris@0 69 private native long loadPluginNative(String key, float inputSampleRate);
Chris@0 70 private native void initialise();
Chris@0 71 private static PluginLoader inst;
Chris@0 72 private long nativeHandle;
Chris@0 73
Chris@0 74 static {
Chris@0 75 System.loadLibrary("vamp-jni");
Chris@0 76 }
Chris@0 77 }
Chris@0 78