// // Copyright: Copyright 2003 Craig Stuart Sapp // Programmer: Craig Stuart Sapp // Creation Date: Tue Feb 11 12:46:06 PST 2003 // Last Modified: Tue Feb 11 12:46:11 PST 2003 // Filename: monoflip.c // Web Address: http://peabody.sapp.org/class/dmp2/lab/flip/monoflip.c // Syntax: C; Max4/MSP2 External Object; CodeWarrior 6.0 // OS: Mac OS 9; PPC // // Description: Flips the key number and duration of MIDI notes. // Works for mononphonic music input. Only one note // on at one time. // #include "ext.h" typedef struct { t_object max_data; // Max/MSP data, MUST come first in struct long keyout; // last note sent out long velin; // current input velocity void* outputKeyNumber; // output the note number of the note void* outputVelocity; // output the duration of note in milliseconds } MyObject; void* object_data = NULL; // function declarations: void* create_object (void); void InputKeyNumber (MyObject* mo, long value); void InputVelocity (MyObject* mo, long value); ///////////////////////////////////////////////////////////////////////// // // Initialization functions // ////////////////////////////// // // main -- called once when the object is created in a patcher window. // void main(void) { setup((t_messlist**)&object_data, (method)create_object, NULL, sizeof(MyObject), NULL, A_NOTHING); addint ((method)InputKeyNumber); // inlet 1 addinx ((method)InputVelocity, 1); // inlet 2 } ////////////////////////////// // // create_object -- create the data storage for the mydiff object and // and setup input 1. // void* create_object(void) { int i; MyObject* mo = (MyObject*)newobject(object_data); mo->velin = 0; for (i=0; i<128; i++) { mo->keymap[i] = 0; } mo->outputVelocity = intout(mo); // outlet 2 mo->outputKeyNumber = intout(mo); // outlet 1 intin(mo, 1); // inlet 2 return mo; } ///////////////////////////////////////////////////////////////////////// // // Behavior functions // ////////////////////////////// // // InputKeyNumber -- behavior of the object when a new number comes // in on inlet 1. // void InputKeyNumber(MyObject* mo, long value) { if (mo->velin == 0) { outlet_int(mo->outputVelocity, mo->velin); outlet_int(mo->outputKeyNumber, mo->keyout); } else { outlet_int(mo->outputVelocity, value); outlet_int(mo->outputKeyNumber, mo->velin); mo->keyout = mo->velin; } } ////////////////////////////// // // InputVelocity -- behavior of the object when a new number comes // in on inlet 2. // void InputVelocity(MyObject* mo, long value) { mo->velin = value; }