aboutsummaryrefslogtreecommitdiff
path: root/src/MaxClock.c
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2008-03-22 02:15:12 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2008-03-22 02:15:12 +0000
commita764e59e1d3a8e330f0d484fdb26b35ca3f0b2e4 (patch)
treec4ecadccdecf2809b99c0da0545f255a6ad25bb5 /src/MaxClock.c
bringing pdj-0.8.3 into the main branchsvn2git-root
svn path=/trunk/externals/loaders/pdj/; revision=9621
Diffstat (limited to 'src/MaxClock.c')
-rw-r--r--src/MaxClock.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/MaxClock.c b/src/MaxClock.c
new file mode 100644
index 0000000..e7e5886
--- /dev/null
+++ b/src/MaxClock.c
@@ -0,0 +1,74 @@
+#include <stdlib.h>
+#include "native_classes.h"
+#include "type_handler.h"
+#include "pdj.h"
+
+typedef struct _clockCtnr {
+ jobject instance;
+ jmethodID tick;
+ t_clock *pd_clock;
+} t_clockCtnr;
+
+
+static t_clockCtnr *getClock(JNIEnv *env, jobject obj) {
+ return (t_clockCtnr *) (*env)->GetLongField(env, obj, pdjCaching.FIDMaxClock_clock_ptr);
+}
+
+
+void clock_callback(t_clockCtnr *clk) {
+ JNIEnv *env = pdjAttachVM();
+ JASSERT(clk->instance);
+
+ (*env)->CallVoidMethod(env, clk->instance , clk->tick, NULL);
+ pdjDetachVM(env);
+}
+
+
+JNIEXPORT jdouble JNICALL Java_com_cycling74_max_MaxClock_getTime
+ (JNIEnv *env, jclass cls) {
+ return sys_getrealtime() * 1000;
+}
+
+
+JNIEXPORT void JNICALL Java_com_cycling74_max_MaxClock_create_1clock
+ (JNIEnv *env, jobject obj) {
+ jclass cls = (*env)->GetObjectClass(env, obj);
+ t_clockCtnr *clk;
+
+ clk = malloc(sizeof(t_clockCtnr));
+ ASSERT(clk);
+
+ clk->pd_clock = clock_new(clk, (t_method) clock_callback);
+ (*env)->SetLongField(env, obj, pdjCaching.FIDMaxClock_clock_ptr, (long) clk);
+
+ clk->instance = (*env)->NewGlobalRef(env, obj);
+ JASSERT(clk->instance);
+ clk->tick = (*env)->GetMethodID(env, cls, "tick", "()V");
+ JASSERT(clk->tick);
+}
+
+
+JNIEXPORT void JNICALL Java_com_cycling74_max_MaxClock_delay
+ (JNIEnv *env, jobject obj, jdouble value) {
+ t_clockCtnr *clk = getClock(env, obj);
+ clock_delay(clk->pd_clock, value);
+}
+
+
+JNIEXPORT void JNICALL Java_com_cycling74_max_MaxClock_unset
+ (JNIEnv *env, jobject obj) {
+ t_clockCtnr *clk = getClock(env, obj);
+ clock_unset(clk->pd_clock);
+}
+
+
+JNIEXPORT void JNICALL Java_com_cycling74_max_MaxClock_release
+ (JNIEnv *env, jobject obj) {
+ t_clockCtnr *clk = getClock(env, obj);
+ clock_unset(clk->pd_clock);
+ clock_free(clk->pd_clock);
+ free(clk);
+
+ (*env)->SetObjectField(env, obj, pdjCaching.FIDMaxClock_clock_ptr, 0);
+ (*env)->DeleteGlobalRef(env, obj);
+}