#include "ext.h"
typedef struct {
t_object maxData; // Max/MSP data, MUST come first in struct
long leftval; // first input value
long rightval; // second input value
void* output; // output bang function pointer
} MyObject;
void* objectdata = NULL;
void* createObject (long value);
void InputLeft (MyObject* mo, long value);
void InputRight (MyObject* mo, long value);
void Bang (MyObject* mo);
void main(void) {
setup((t_messlist**)&objectdata, (method)createObject, NULL,
sizeof(MyObject), NULL, A_DEFLONG, A_NOTHING);
addbang((method)Bang);
addint ((method)InputLeft);
addint ((method)InputRight, 1);
}
void* createObject(long value) {
MyObject *mo;
mo = (MyObject*)newobject(objectdata);
mo->leftval = 0;
mo->rightval = value;
mo->output = intout(mo);
intin(mo, 1);
return mo;
}
void InputLeft(MyObject* mo, long value) {
mo->leftval = value;
Bang(mo);
}
void InputRight(MyObject* mo, long value) {
mo->rightval = value;
}
void Bang(MyObject* mo) {
outlet_int(mo->output, mo->leftval - mo->rightval);
}
|