Chris@37
|
1 /*
|
Chris@37
|
2 jVamp
|
Chris@37
|
3
|
Chris@37
|
4 A Java host interface for Vamp audio analysis plugins
|
Chris@37
|
5
|
Chris@37
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@37
|
7 Copyright 2012 Chris Cannam and QMUL.
|
Chris@37
|
8
|
Chris@37
|
9 Permission is hereby granted, free of charge, to any person
|
Chris@37
|
10 obtaining a copy of this software and associated documentation
|
Chris@37
|
11 files (the "Software"), to deal in the Software without
|
Chris@37
|
12 restriction, including without limitation the rights to use, copy,
|
Chris@37
|
13 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@37
|
14 of the Software, and to permit persons to whom the Software is
|
Chris@37
|
15 furnished to do so, subject to the following conditions:
|
Chris@37
|
16
|
Chris@37
|
17 The above copyright notice and this permission notice shall be
|
Chris@37
|
18 included in all copies or substantial portions of the Software.
|
Chris@37
|
19
|
Chris@37
|
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@37
|
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@37
|
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@37
|
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
Chris@37
|
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@37
|
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@37
|
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@37
|
27
|
Chris@37
|
28 Except as contained in this notice, the names of the Centre for
|
Chris@37
|
29 Digital Music; Queen Mary, University of London; and Chris Cannam
|
Chris@37
|
30 shall not be used in advertising or otherwise to promote the sale,
|
Chris@37
|
31 use or other dealings in this Software without prior written
|
Chris@37
|
32 authorization.
|
Chris@37
|
33 */
|
Chris@37
|
34
|
Chris@0
|
35 #include "org_vamp_plugins_PluginLoader.h"
|
Chris@0
|
36
|
Chris@0
|
37 #include <vamp-hostsdk/PluginLoader.h>
|
Chris@0
|
38
|
Chris@0
|
39 #include "handle.h"
|
Chris@0
|
40
|
Chris@0
|
41 using Vamp::Plugin;
|
Chris@0
|
42 using Vamp::HostExt::PluginLoader;
|
Chris@0
|
43
|
Chris@30
|
44 JNIEXPORT void JNICALL
|
Chris@0
|
45 Java_org_vamp_1plugins_PluginLoader_initialise(JNIEnv *env, jobject obj)
|
Chris@0
|
46 {
|
Chris@0
|
47 PluginLoader *inst = PluginLoader::getInstance();
|
Chris@0
|
48 setHandle(env, obj, inst);
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@30
|
51 JNIEXPORT jobjectArray JNICALL
|
Chris@23
|
52 Java_org_vamp_1plugins_PluginLoader_listPlugins(JNIEnv *env, jobject obj)
|
Chris@23
|
53 {
|
Chris@23
|
54 PluginLoader *inst = getHandle<PluginLoader>(env, obj);
|
Chris@23
|
55 PluginLoader::PluginKeyList plugins = inst->listPlugins();
|
Chris@23
|
56 jobjectArray result = env->NewObjectArray
|
Chris@23
|
57 (plugins.size(), env->FindClass("java/lang/String"), 0);
|
Chris@23
|
58 for (int i = 0; i < plugins.size(); ++i) {
|
Chris@23
|
59 env->SetObjectArrayElement(result, i,
|
Chris@23
|
60 env->NewStringUTF(plugins[i].c_str()));
|
Chris@23
|
61 }
|
Chris@23
|
62 return result;
|
Chris@23
|
63 }
|
Chris@23
|
64
|
Chris@30
|
65 JNIEXPORT jlong JNICALL
|
Chris@0
|
66 Java_org_vamp_1plugins_PluginLoader_loadPluginNative(JNIEnv *env, jobject obj,
|
Chris@29
|
67 jstring key, jfloat rate,
|
Chris@29
|
68 jint flags)
|
Chris@0
|
69 {
|
Chris@0
|
70 PluginLoader *inst = getHandle<PluginLoader>(env, obj);
|
Chris@0
|
71 const char *kstr = env->GetStringUTFChars(key, 0);
|
Chris@29
|
72 Plugin *p = inst->loadPlugin(kstr, rate, flags);
|
Chris@0
|
73 env->ReleaseStringUTFChars(key, kstr);
|
Chris@0
|
74 return (jlong)p;
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@30
|
77 JNIEXPORT jobjectArray JNICALL
|
Chris@24
|
78 Java_org_vamp_1plugins_PluginLoader_getPluginCategory(JNIEnv *env, jobject obj,
|
Chris@24
|
79 jstring key)
|
Chris@24
|
80 {
|
Chris@24
|
81 PluginLoader *inst = getHandle<PluginLoader>(env, obj);
|
Chris@24
|
82 const char *kstr = env->GetStringUTFChars(key, 0);
|
Chris@24
|
83 PluginLoader::PluginCategoryHierarchy cat = inst->getPluginCategory(kstr);
|
Chris@24
|
84 jobjectArray result = env->NewObjectArray
|
Chris@24
|
85 (cat.size(), env->FindClass("java/lang/String"), 0);
|
Chris@24
|
86 for (int i = 0; i < cat.size(); ++i) {
|
Chris@24
|
87 env->SetObjectArrayElement(result, i,
|
Chris@24
|
88 env->NewStringUTF(cat[i].c_str()));
|
Chris@24
|
89 }
|
Chris@24
|
90 return result;
|
Chris@24
|
91 }
|
Chris@0
|
92
|
Chris@23
|
93
|