// // Programmer: Craig Stuart Sapp // Creation Date: Wed Jan 29 04:20:01 PST 2003 // Last Modified: Tue Feb 4 05:47:19 PST 2003 // Filename: mydiff.c // Web Address: http://peabody.sapp.org/class/dmp2/lab/mydiff/mydiff.c // Derived from: Fujinaga's Max/MSP Externals Tutorial, v2.41, p. 7-8 // Syntax: C; Max4/MSP2 External Object; CodeWarrior 6.0 // OS: Mac OS 9; PPC // // Description: Subtracts the second input integer from the // first input integer. // #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; // function declarations: void* createObject (long value); void InputLeft (MyObject* mo, long value); void InputRight (MyObject* mo, long value); void Bang (MyObject* mo); ////////////////////////////// // // main -- called once when the object is created in a patcher window. // 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); } ////////////////////////////// // // createObject -- create the data storage for the mydiff object and // and setup input 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; } ////////////////////////////// // // InputLeft -- behavior of the object when a new number comes // in on inlet 0. // void InputLeft(MyObject* mo, long value) { mo->leftval = value; Bang(mo); } ////////////////////////////// // // InputRight -- behavior of the object when a new number comes // in on inlet 1. // void InputRight(MyObject* mo, long value) { mo->rightval = value; } ////////////////////////////// // // Bang -- behaviour of the object when a "bang" message is received. // void Bang(MyObject* mo) { outlet_int(mo->output, mo->leftval - mo->rightval); }