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/msp/MSPObject.java | 163 ++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 src/java/com/cycling74/msp/MSPObject.java (limited to 'src/java/com/cycling74/msp/MSPObject.java') diff --git a/src/java/com/cycling74/msp/MSPObject.java b/src/java/com/cycling74/msp/MSPObject.java new file mode 100644 index 0000000..be2d68b --- /dev/null +++ b/src/java/com/cycling74/msp/MSPObject.java @@ -0,0 +1,163 @@ +package com.cycling74.msp; + +import java.lang.reflect.Method; + +import com.cycling74.max.DataTypes; +import com.cycling74.max.MaxObject; + +/** + * Main object to extend to use dsp with pd. You will need to + * use the pdj~ external if you want to process signals. Before + * the dsp starts processing, the method dsp will be called and it must + * return the performer method that will process each dsp cycles. + * + *

Here is a basic guideline for using the MSPObject:

+ *

+ * import com.cycling74.max.*;
+ * import com.cycling74.msp.*;
+ * import java.lang.reflection.Method;
+ * 
+ * public class panner extends MSPObject {
+ *   float left = 1, right = 1;
+ *   
+ *   public panner() {
+ *       declareInlets( new int[] { SIGNAL, DataTypes.ANYTHING } );
+ *       declareOutlets( new int[] { SIGNAL, SIGNAL } );
+ *   }
+ *   
+ *   // From 0..127
+ *   public void inlet(float val) {
+ *       if ( val > 64 ) {
+ *           right = 1;
+ *           left = ((127-val) / 64);
+ *       } else {
+ *           left = 1;
+ *           right = val / 64;
+ *       }
+ *   }
+ *  
+ *   public Method dsp(MSPSignal[] ins, MSPSignal[] outs) {
+ *       return getPerformMethod("perform");
+ *   }
+ *
+ *   public void perform(MSPSignal[] ins, MSPSignal[] outs) {
+ *       for (int i=0;i<ins[0].n;i++) {
+ *           outs[0].vec[i] = ins[0].vec[i] * left;
+ *           outs[1].vec[i] = ins[0].vec[i] * right;
+ *       }
+ *   }
+ * }
+ * 

+ */ +public abstract class MSPObject extends MaxObject { + /** + * Use this value to indentify a signal intlet/outlet to + * the method declareInlet/declareOutlet. + */ + public final static int SIGNAL = 32; + + /** + * Initialize the dsp state. From the numbers of input/output this + * method must return a performing method. + * @param ins input signals + * @param outs output signals + * @return the method to execute at each dsp cycle + */ + public abstract Method dsp(MSPSignal[] ins, MSPSignal[] outs); + + /** + * Quicky method to be used with dsp(MSPSignal[], MSPSignal[]). It + * will return the method name methodName with signature + * (MSPSignal[], MSPSignal[]) in the current class. + * @param methodName the name of the method in the current class + * @return the method reflection + */ + protected Method getPerformMethod(String methodName) { + try { + Method m = getClass().getDeclaredMethod(methodName, new Class[] { + MSP_SIGNAL_ARRAY_CLZ, MSP_SIGNAL_ARRAY_CLZ }); + return m; + } catch ( NoSuchMethodException e ) { + error("pdj~: method: " + methodName + " not found in class in:" + getClass().toString()); + } + return null; + } + + /** + * Force to copy of each MSPBuffer when performer is called. Right now, + * on pdj the MSPBuffer is always copied. + * @param copyBuffer true if you need to copyBuffer + */ + protected void setNoInPlace(boolean copyBuffer) { + //this.copyBuffer = copyBuffer; + } + + /** + * This method is called when the dsp is start/stop. + * NOT USED ON PD. + * @param dspRunning true if the dsp is running + */ + protected void dspstate(boolean dspRunning) { + } + + + /** + * Declare the inlets used by this object. Use MSPObject.SIGNAL + * to define a signal inlet. Note: any signal inlet won't + * be able to process any atom messages. + */ + protected void declareInlets(int[] types) { + int i, inlets = 0; + for (i=0;i