From a764e59e1d3a8e330f0d484fdb26b35ca3f0b2e4 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 22 Mar 2008 02:15:12 +0000 Subject: bringing pdj-0.8.3 into the main branch svn path=/trunk/externals/loaders/pdj/; revision=9621 --- src/java/com/cycling74/max/MaxClock.java | 113 +++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/java/com/cycling74/max/MaxClock.java (limited to 'src/java/com/cycling74/max/MaxClock.java') diff --git a/src/java/com/cycling74/max/MaxClock.java b/src/java/com/cycling74/max/MaxClock.java new file mode 100644 index 0000000..5c5acbb --- /dev/null +++ b/src/java/com/cycling74/max/MaxClock.java @@ -0,0 +1,113 @@ +package com.cycling74.max; + +/** + * Used to delay the execution of a block of code. Java implementation + * of a pdclock. + *

+ * 
+ * import com.cycling74.max.*;
+ * 
+ * class clocktest extends MaxObject implements Executable {
+ *     MaxClock clock;
+ *     float value; 
+ * 
+ *     public clocktest() {
+ *         clock = new MaxClock(this); 
+ *     }
+ *     
+ *     public void inlet(float f) {
+ *         value = f;
+ *         // ask to call execute after 250ms
+ *         clock.delay(250);
+ *     }
+ * 
+ *     // this is called after 250ms
+ *     public void execute() {
+ *         outlet(0, value)
+ *     }
+ * }
+ * 

+ */ +public class MaxClock { + private Executable exec; + private long _clock_ptr; + + /** + * Creates a pdclock without an executable. + */ + public MaxClock() { + create_clock(); + } + + /** + * Creates a pdclock with an executable e. + * @param e the executable to execute when the clock will be triggerd. + */ + public MaxClock(Executable e) { + create_clock(); + exec = e; + } + + /** + * Creates a pdclock with a specific method on a object. + * @param o the object that holds the method + * @param methodName the name of the method to execute when the clock + * will be triggerd. + */ + public MaxClock(Object o, String methodName) { + create_clock(); + exec = new Callback(o, methodName); + } + + /** + * Returns the Executable for this clock. + * @return the Executable for this clock + */ + public Executable getExecutable() { + return exec; + } + + /** + * Set the Executable for this clock. + * @param e the Executable to call for this clock + */ + public void setExecutable(Executable e) { + exec = e; + } + + /** + * The method to override if no Executable is provided. + */ + public void tick() { + exec.execute(); + } + + protected void finalize() throws Throwable { + release(); + super.finalize(); + } + + /** + * Returns pure-data time in milliseconds. + * @return pure-data time in milliseconds + */ + public static native double getTime(); + + /** + * Time to wait until next tick. + * @param time in miliseconds + */ + public native void delay(double time); + + /** + * Release the clock from pure-data. The clock becomes unless afterwards. + */ + public native void release(); + + /** + * Cancels the last delay call. + */ + public native void unset(); + + private native void create_clock(); +} -- cgit v1.2.1