Chris@37: /* Chris@37: jVamp Chris@37: Chris@37: A Java host interface for Vamp audio analysis plugins Chris@37: Chris@37: Centre for Digital Music, Queen Mary, University of London. Chris@37: Copyright 2012 Chris Cannam and QMUL. Chris@37: Chris@37: Permission is hereby granted, free of charge, to any person Chris@37: obtaining a copy of this software and associated documentation Chris@37: files (the "Software"), to deal in the Software without Chris@37: restriction, including without limitation the rights to use, copy, Chris@37: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@37: of the Software, and to permit persons to whom the Software is Chris@37: furnished to do so, subject to the following conditions: Chris@37: Chris@37: The above copyright notice and this permission notice shall be Chris@37: included in all copies or substantial portions of the Software. Chris@37: Chris@37: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@37: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@37: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@37: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@37: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@37: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@37: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@37: Chris@37: Except as contained in this notice, the names of the Centre for Chris@37: Digital Music; Queen Mary, University of London; and Chris Cannam Chris@37: shall not be used in advertising or otherwise to promote the sale, Chris@37: use or other dealings in this Software without prior written Chris@37: authorization. Chris@37: */ Chris@37: Chris@20: #include "org_vamp_plugins_RealTime.h" Chris@20: Chris@20: #include Chris@20: Chris@20: #include "handle.h" Chris@20: Chris@20: using Vamp::RealTime; Chris@20: using std::string; Chris@20: Chris@30: JNIEXPORT void JNICALL Chris@20: Java_org_vamp_1plugins_RealTime_dispose(JNIEnv *env, jobject obj) Chris@20: { Chris@20: RealTime *rt = getHandle(env, obj); Chris@20: setHandle(env, obj, 0); Chris@20: delete rt; Chris@20: } Chris@20: Chris@30: JNIEXPORT jint JNICALL Chris@20: Java_org_vamp_1plugins_RealTime_sec(JNIEnv *env, jobject obj) Chris@20: { Chris@20: RealTime *rt = getHandle(env, obj); Chris@20: return rt->sec; Chris@20: } Chris@20: Chris@30: JNIEXPORT jint JNICALL Chris@20: Java_org_vamp_1plugins_RealTime_nsec(JNIEnv *env, jobject obj) Chris@20: { Chris@20: RealTime *rt = getHandle(env, obj); Chris@20: return rt->nsec; Chris@20: } Chris@20: Chris@30: JNIEXPORT jint JNICALL Chris@20: Java_org_vamp_1plugins_RealTime_usec(JNIEnv *env, jobject obj) Chris@20: { Chris@20: RealTime *rt = getHandle(env, obj); Chris@20: return rt->usec(); Chris@20: } Chris@20: Chris@30: JNIEXPORT jint JNICALL Chris@20: Java_org_vamp_1plugins_RealTime_msec(JNIEnv *env, jobject obj) Chris@20: { Chris@20: RealTime *rt = getHandle(env, obj); Chris@20: return rt->msec(); Chris@20: } Chris@20: Chris@30: JNIEXPORT jstring JNICALL Chris@20: Java_org_vamp_1plugins_RealTime_toString(JNIEnv *env, jobject obj) Chris@20: { Chris@20: RealTime *rt = getHandle(env, obj); Chris@20: return env->NewStringUTF(rt->toString().c_str()); Chris@20: } Chris@20: Chris@30: JNIEXPORT jstring JNICALL Chris@20: Java_org_vamp_1plugins_RealTime_toText(JNIEnv *env, jobject obj) Chris@20: { Chris@20: RealTime *rt = getHandle(env, obj); Chris@20: return env->NewStringUTF(rt->toText().c_str()); Chris@20: } Chris@20: Chris@30: JNIEXPORT jobject JNICALL Chris@20: Java_org_vamp_1plugins_RealTime_fromSeconds(JNIEnv *env, jclass cls, jdouble s) Chris@20: { Chris@21: jclass rtClass = env->FindClass("org/vamp_plugins/RealTime"); Chris@21: jmethodID rtCtor = env->GetMethodID(rtClass, "", "(II)V"); Chris@21: RealTime rt = RealTime::fromSeconds(s); Chris@21: return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec); Chris@20: } Chris@20: Chris@30: JNIEXPORT jobject JNICALL Chris@30: Java_org_vamp_1plugins_RealTime_fromMilliseconds(JNIEnv *env, jclass cls, jint ms) Chris@20: { Chris@21: jclass rtClass = env->FindClass("org/vamp_plugins/RealTime"); Chris@21: jmethodID rtCtor = env->GetMethodID(rtClass, "", "(II)V"); Chris@21: RealTime rt = RealTime::fromMilliseconds(ms); Chris@21: return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec); Chris@20: } Chris@20: Chris@30: JNIEXPORT jobject JNICALL Chris@30: Java_org_vamp_1plugins_RealTime_frame2RealTime(JNIEnv *env, jclass cls, jlong frame, jint sampleRate) Chris@21: { Chris@21: jclass rtClass = env->FindClass("org/vamp_plugins/RealTime"); Chris@21: jmethodID rtCtor = env->GetMethodID(rtClass, "", "(II)V"); Chris@21: RealTime rt = RealTime::frame2RealTime(frame, sampleRate); Chris@21: return env->NewObject(rtClass, rtCtor, rt.sec, rt.nsec); Chris@21: } Chris@20: Chris@30: JNIEXPORT jlong JNICALL Chris@30: Java_org_vamp_1plugins_RealTime_realTime2Frame(JNIEnv *env, jclass cls, jobject obj, jint sampleRate) Chris@21: { Chris@21: RealTime *rt = getHandle(env, obj); Chris@21: return RealTime::realTime2Frame(*rt, sampleRate); Chris@21: } Chris@20: Chris@30: JNIEXPORT void JNICALL Chris@30: Java_org_vamp_1plugins_RealTime_initialise(JNIEnv *env, jobject obj, jint sec, jint nsec) Chris@21: { Chris@21: RealTime *rt = new RealTime(sec, nsec); Chris@21: setHandle(env, obj, rt); Chris@21: } Chris@21: Chris@21: Chris@21: