# HG changeset patch # User Andrew N Robertson # Date 1325809339 0 # Node ID 690ec1eb8180a8ada410a509820b7c00a78d76c9 # Parent 0f9165f96bdb16c0b993d5d16db32d536d73e2a1 Adding Bonzo max external object diff -r 0f9165f96bdb -r 690ec1eb8180 BonzoExternalDev/Source/Bonzo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BonzoExternalDev/Source/Bonzo.cpp Fri Jan 06 00:22:19 2012 +0000 @@ -0,0 +1,238 @@ +/** + @file + Bonzo - a max object shell + jeremy bernstein - jeremy@bootsquad.com + + @ingroup examples +*/ + +#include "ext.h" // standard Max include, always required +#include "ext_obex.h" // required for new style Max object +//#include "BKeeperlass.h" + +////////////////////////// object struct + + +typedef struct _Bonzo +{ + t_object ob; // the object itself (must be first) +// BonzoClass* bk; +// void* clickclock; +// void* bangOut; + void* tatumEstimateOut; +// void* latencyOut; + + +} t_Bonzo; + +///////////////////////// function prototypes +//// standard set +void *Bonzo_new(t_symbol *s, long argc, t_atom *argv); +void Bonzo_bang(t_Bonzo *x); +void Bonzo_reset(t_Bonzo *x); +void Bonzo_click(t_Bonzo *x); +void Bonzo_kick(t_Bonzo *x); +void Bonzo_snare(t_Bonzo *x); +void Bonzo_kickstart(t_Bonzo *x, int kicks); +void Bonzo_latency(t_Bonzo *x, int latency); +void Bonzo_fix_latency(t_Bonzo *x, int fix_latency_mode); + +void Bonzo_setTatum(t_Bonzo *x, double f); +void Bonzo_free(t_Bonzo *x); +void Bonzo_printtime(t_Bonzo *x); +void Bonzo_assist(t_Bonzo *x, void *b, long m, long a, char *s); + +//////////////////////// global class pointer variable +void *Bonzo_class; + + +int main(void) +{ + // object initialization, OLD STYLE + // setup((t_messlist **)&Bonzo_class, (method)Bonzo_new, (method)Bonzo_free, (short)sizeof(t_Bonzo), + // 0L, A_GIMME, 0); + // addmess((method)Bonzo_assist, "assist", A_CANT, 0); + + // object initialization, NEW STYLE + t_class *c; + + c = class_new("Bonzo", (method)Bonzo_new, (method)Bonzo_free, (long)sizeof(t_Bonzo), + 0L /* leave NULL!! */, A_GIMME, 0); + + /* you CAN'T call this from the patcher */ + class_addmethod(c, (method)Bonzo_assist, "assist", A_CANT, 0); + class_addmethod(c, (method) Bonzo_bang, "bang", 0); + class_addmethod(c, (method) Bonzo_click, "click", 0); + class_addmethod(c, (method) Bonzo_kick, "kick", 0); + class_addmethod(c, (method) Bonzo_snare, "snare", 0); + class_addmethod(c, (method) Bonzo_kickstart, "kickstart", A_LONG, 0); + class_addmethod(c, (method) Bonzo_fix_latency, "fix_latency", A_LONG, 0); + class_addmethod(c, (method) Bonzo_latency, "latency", A_LONG, 0); + + class_addmethod(c, (method) Bonzo_setTatum, "set_tatum", A_FLOAT, 0); + + + class_addmethod(c, (method) Bonzo_reset, "reset", 0); + class_register(CLASS_BOX, c); /* CLASS_NOBOX */ + Bonzo_class = c; + + post("I am the Bonzo max external object"); + return 0; +} + +void Bonzo_assist(t_Bonzo *x, void *b, long m, long a, char *s) +{ + if (m == ASSIST_INLET) { // inlet + sprintf(s, " BONZO Inlet takes messages for click, kick and snare %ld", a); + } + else { // outlet + sprintf(s, "BONZO Outlet is duration of an eighth note in milliseconds required to synchronise the click track to the drum events %ld", a); + } +} + +void Bonzo_free(t_Bonzo *x) +{ +// object_free(x->clickclock);; +} + + + +void Bonzo_bang(t_Bonzo *x){ + + + object_post((t_object *)x, "Bonzo got banggggg!"); + //x->bk->bang(0); + + +/* + if (x->timer->send_start_bang){ + clock_fdelay(x->clickclock, x->timer->start_delay); + x->timer->send_start_bang = false; + } +*/ + } + +void Bonzo_kick(t_Bonzo *x){ +// x->bk->bang(0); + post("BONZO kick"); +// outlet_float(x->tatumEstimateOut, x->bk->main_tatum_output); +} + +void Bonzo_snare(t_Bonzo *x){ +// x->bk->bang(2); + post("Bonzo SNARE"); +// outlet_float(x->tatumEstimateOut, x->bk->main_tatum_output); +} + +void Bonzo_click(t_Bonzo *x){ +// x->bk->bang(1); + post("BOnzo click"); +// outlet_float(x->tatumEstimateOut, x->bk->main_tatum_output); +} + + +void Bonzo_reset(t_Bonzo *x){ +// object_post((t_object *)x, "B-Keeper reset!"); +// x->bk->reset(); +} + + + +void Bonzo_kickstart(t_Bonzo *x, int kicks){ +// if (kicks >= 0 && kicks <= 8){ +// x->timer->start_index = kicks; +// } +} + +void Bonzo_setTatum(t_Bonzo *x, double f){ + post("Bonzo set tatum called with arg %f\n", f); +// x->bk->setTatum(f); +} + + +void Bonzo_latency(t_Bonzo *x, int latency){ +//if (latency >= 0 && latency < 100) +// x->timer->latency = latency; +} + +void Bonzo_fix_latency(t_Bonzo *x, int fix_latency_mode){ +/* + if (fix_latency_mode == 1){ + x->timer->saved_latency_mode = true; + x->timer->saved_latency = x->timer->latency; + post("Latency FIXED at %i msec \n", x->timer->latency); + } + else{ + x->timer->saved_latency_mode = false; + post("Latency to be calculated from ableton click track arriving...now at %i ms\n", x->timer->latency); + } + */ +} + +void Bonzo_printtime(t_Bonzo *x) +{ +// double time; +// sched_getftime(&time); +// post("instance %lx is executing at time %.2f", x, time); + + long timeMillis = gettime(); + post("current time is %ld \n", timeMillis); + +} + +/* + A_GIMME signature = + t_symbol *s objectname + long argc num additonal args + t_atom *argv array of t_atom structs + type = argv->a_type + if (type == A_LONG) ; + else if (type == A_FLOAT) ; + else if (type == A_SYM) ; +*/ +/* + t_symbol { + char *s_name; + t_object *s_thing; + } +*/ +void *Bonzo_new(t_symbol *s, long argc, t_atom *argv) +{ + t_Bonzo *x = NULL; + //long i; + + // object instantiation, OLD STYLE + // if (x = (t_Bonzo *)newobject(Bonzo_class)) { + // ; + // } + + // object instantiation, NEW STYLE + if (x = (t_Bonzo *)object_alloc((t_class *) Bonzo_class)) { + //(t_class *) allows this to be a cpp file + + // object_post((t_object *)x, "a new %s object was instantiated: 0x%X", s->s_name, x); + // object_post((t_object *)x, "it has %ld arguments", argc); + + /* + for (i = 0; i < argc; i++) { + if ((argv + i)->a_type == A_LONG) { + object_post((t_object *)x, "arg %ld: long (%ld)", i, atom_getlong(argv+i)); + } else if ((argv + i)->a_type == A_FLOAT) { + object_post((t_object *)x, "arg %ld: float (%f)", i, atom_getfloat(argv+i)); + } else if ((argv + i)->a_type == A_SYM) { + object_post((t_object *)x, "arg %ld: symbol (%s)", i, atom_getsym(argv+i)->s_name); + } else { + object_error((t_object *)x, "forbidden argument"); + } + } + */ + + +// x->bk = new BonzoClass();//imer = new clicktimer(); +// x->clickclock = clock_new((t_object *)x, (method) Bonzo_sendDelayedBang); +// x->latencyOut = intout((t_object *)x); + x->tatumEstimateOut = floatout((t_object *)x); +// x->bangOut = bangout((t_object *)x); + } + return (x); +}