annotate src/getset.cpp @ 46:91259f3449ae

Win32/VC++ build fixes and project
author Chris Cannam <chris.cannam@eecs.qmul.ac.uk>
date Wed, 06 Mar 2013 13:38:05 +0000
parents c9515589be7d
children 2db3640905ef
rev   line source
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@7 34
Chris@7 35 #include "getset.h"
Chris@7 36
Chris@7 37 #include <iostream>
Chris@7 38
Chris@10 39 int
Chris@10 40 getIntField(JNIEnv *env, jobject obj, std::string name)
Chris@10 41 {
Chris@10 42 jclass cls = env->GetObjectClass(obj);
Chris@12 43 return env->GetIntField(obj,
Chris@12 44 env->GetFieldID(cls, name.c_str(), "I"));
Chris@10 45 }
Chris@10 46
Chris@7 47 void
Chris@7 48 setStringField(JNIEnv *env, jobject obj, std::string name, std::string value)
Chris@7 49 {
Chris@7 50 jclass cls = env->GetObjectClass(obj);
Chris@7 51 env->SetObjectField(obj,
Chris@7 52 env->GetFieldID(cls, name.c_str(), "Ljava/lang/String;"),
Chris@7 53 env->NewStringUTF(value.c_str()));
Chris@7 54 }
Chris@7 55
Chris@7 56 void
Chris@7 57 setFloatField(JNIEnv *env, jobject obj, std::string name, float value)
Chris@7 58 {
Chris@7 59 jclass cls = env->GetObjectClass(obj);
Chris@7 60 env->SetFloatField(obj,
Chris@7 61 env->GetFieldID(cls, name.c_str(), "F"),
Chris@7 62 value);
Chris@7 63 }
Chris@7 64
Chris@7 65 void
Chris@7 66 setBooleanField(JNIEnv *env, jobject obj, std::string name, bool value)
Chris@7 67 {
Chris@7 68 jclass cls = env->GetObjectClass(obj);
Chris@7 69 env->SetBooleanField(obj,
Chris@7 70 env->GetFieldID(cls, name.c_str(), "Z"),
Chris@7 71 value);
Chris@7 72 }
Chris@7 73
Chris@7 74 void
Chris@7 75 setIntField(JNIEnv *env, jobject obj, std::string name, int value)
Chris@7 76 {
Chris@7 77 jclass cls = env->GetObjectClass(obj);
Chris@7 78 env->SetIntField(obj,
Chris@7 79 env->GetFieldID(cls, name.c_str(), "I"),
Chris@7 80 value);
Chris@7 81 }
Chris@7 82
Chris@7 83 void
Chris@14 84 setRealTimeField(JNIEnv *env, jobject obj, std::string name, Vamp::RealTime rt)
Chris@14 85 {
Chris@14 86 jclass rtClass = env->FindClass("org/vamp_plugins/RealTime");
Chris@14 87 jmethodID ctor = env->GetMethodID(rtClass, "<init>", "(II)V");
Chris@14 88 jobject jrt = env->NewObject(rtClass, ctor, rt.sec, rt.nsec);
Chris@14 89 setObjectField(env, obj, name, "Lorg/vamp_plugins/RealTime;", jrt);
Chris@14 90 }
Chris@14 91
Chris@14 92 void
Chris@7 93 setObjectField(JNIEnv *env, jobject obj, std::string name, std::string type, jobject value)
Chris@7 94 {
Chris@7 95 jclass cls = env->GetObjectClass(obj);
Chris@7 96 jfieldID field = env->GetFieldID(cls, name.c_str(), type.c_str());
Chris@7 97 env->SetObjectField(obj, field, value);
Chris@7 98 }
Chris@7 99
Chris@7 100 void
Chris@14 101 setFloatArrayField(JNIEnv *env, jobject obj, std::string name, std::vector<float> values)
Chris@14 102 {
Chris@14 103 jfloatArray jarr = env->NewFloatArray(values.size());
Chris@14 104 env->SetFloatArrayRegion(jarr, 0, values.size(), values.data());
Chris@18 105 setObjectField(env, obj, name, "[F", jarr);
Chris@14 106 }
Chris@14 107
Chris@14 108 void
Chris@7 109 setStringArrayField(JNIEnv *env, jobject obj, std::string name, std::vector<std::string> values)
Chris@7 110 {
Chris@7 111 jclass strCls = env->FindClass("java/lang/String");
Chris@7 112 jobjectArray jarr = env->NewObjectArray(values.size(), strCls, 0);
chris@46 113 for (int i = 0; i < (int)values.size(); ++i) {
Chris@7 114 env->SetObjectArrayElement(jarr, i, env->NewStringUTF(values[i].c_str()));
Chris@7 115 }
Chris@7 116 setObjectField(env, obj, name, "[Ljava/lang/String;", jarr);
Chris@7 117 }
Chris@7 118
Chris@7 119 jmethodID
Chris@7 120 getEnumValueOfMethod(JNIEnv *env)
Chris@7 121 {
Chris@7 122 jclass enumClass = env->FindClass("java/lang/Enum");
Chris@7 123
Chris@7 124 // Enum.valueOf(Class, String) returns Enum
Chris@7 125 jmethodID valueOfMethod = env->GetStaticMethodID
Chris@7 126 (enumClass, "valueOf",
Chris@7 127 "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;");
Chris@7 128
Chris@7 129 return valueOfMethod;
Chris@7 130 }
Chris@7 131