|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.cycling74.max.MaxObject
com.cycling74.msp.MSPObject
public abstract class MSPObject
Base class for a Java signal processing object. Subclass this directly or indirectly to create your own Java signal processing objects for use in Max. See the mxj~ examples directory in the java-doc directory of your Max install for more sample code. See also 'WritingMaxExternalsInJava.pdf' for a more detailed discussion about writing Max signal processing classes in Java.
//This example adds two signals together. If only one signal is connected //it adds the last floating point or integer value received to that signal. //If neither signal is connected it outlets the last floating point or integer //value received. import com.cycling74.max.*; import com.cycling74.msp.*; import java.lang.reflect.Method; public class sigadd extends MSPObject { private float addend; private Method _p1; private Method _p2; private Method _p3; public sigadd() { this(0); } public sigadd(float f) { addend = f; declareInlets(new int[]{SIGNAL,SIGNAL}); declareOutlets(new int[]{SIGNAL}); _p1 = getPerformMethod(Òp1Ó); _p2 = getPerformMethod(Òp2Ó); _p3 = getPerformMethod(Òp3Ó); _p4 = getPerformMethod(Òp4Ó); } public void inlet(float f) { addend = f; } public Method dsp(MSPSignal[] in, MSPSignal[] out) { if(in[0].connected && !in[1].connected) return _p1; else if(!in[0].connected && in[1].connected) return _p2; else if(in[0].connected && in[1].connected) return _p3; else return _p4; } public void p1(MSPSignal[] in, MSPSignal[] out) { float[] in1 = in[0].vec; float[] o = out[0].vec; int vec_size = in[0].n; int i; //2nd signal inlet is not connected for(i = 0;i < vec_size;i++) o[i] = in1[i] + addend; } public void p2(MSPSignal[] in, MSPSignal[] out) { float[] in2 = in[1].vec; float[] o = out[0].vec; int vec_size = in[0].n; int i; //1st signal inlet is not connected for(i = 0;i < vec_size;i++) o[i] = in2[i] + addend; } public void p3(MSPSignal[] in, MSPSignal[] out) { float[] in1 = in[0].vec; float[] in2 = in[1].vec; float[] o = out[0].vec; int vec_size = in[0].n; int i; //both signals inlet are connected for(i = 0;i < vec_size;i++) o[i] = in1[i] + in2[i]; } public void p4(MSPSignal[] in, MSPSignal[] out) { //neither signal inlet is connected for(i = 0;i < vec_size;i++) o[i] = addend; } }
Field Summary | |
---|---|
static java.lang.Class |
MSP_SIGNAL_ARRAY_CLZ
A convenience constant initialized to the contain the Class Object for MSPSignal[] |
static int |
SIGNAL
A constant for use with declareInlets() and declareOutlets() to enable the creation of MSP signal inlets and outlets. |
Fields inherited from class com.cycling74.max.MaxObject |
---|
EMPTY_STRING_ARRAY, NO_INLETS, NO_OUTLETS |
Constructor Summary | |
---|---|
MSPObject()
|
Method Summary | |
---|---|
abstract java.lang.reflect.Method |
dsp(MSPSignal[] inlets,
MSPSignal[] outlets)
Since it is abstract, the dsp method must be implemented by your MSPObject subclass. |
protected void |
dspstate(boolean b)
Called by Max when the dsp chain is started or stopped. |
protected java.lang.reflect.Method |
getPerformMethod(java.lang.String name)
Helper to aide in the creation of java.lang.reflect.Method instances which could be returned by your dsp method. |
protected void |
setNoInPlace(boolean b)
If you set this to true, the compiler will guarantee that all the signal vectors passed to your object will be unique. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int SIGNAL
public static final java.lang.Class MSP_SIGNAL_ARRAY_CLZ
Constructor Detail |
---|
public MSPObject()
Method Detail |
---|
public abstract java.lang.reflect.Method dsp(MSPSignal[] inlets, MSPSignal[] outlets)
private void myPerformMethod(MSPSignal[] inlets, MSPSignal[] outlets)The dsp method is called once when the MSP signal compiler is building the dsp chain for the patch which contains your MSPObject instance. You are passed two arrays of MSPSiganl objects corresponding to the SIGNAL inlets/outlets you declared in your declareInlets/decalreOutlets calls in your constructor. You can interrogate any of these MSPSiganl instances for meta information about the current dsp context including sampling rate, sample vector size etc.
inlets
- array of MSPSiganl objects corresponding to the type SIGNAL inlets declared in
your constructor.outlets
- array of MSPSiganl objects corresponding to the type SIGNAL outlets declared in
your constructor.
com.cycling74.msp
protected java.lang.reflect.Method getPerformMethod(java.lang.String name)
private void myPerformMethod(MSPSignal[] inlets, MSPSignal[] outlets)
name
- the name of the method you would like returned as a
java.lang.reflect.Method instance.
protected void setNoInPlace(boolean b)
protected void dspstate(boolean b)
b
- The current state (on/off) of the MSP dsp chain.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |