#include "ext.h" /* ---- simp.c --- example of using save and restore to save something in patcher files. NOTE: Do NOT use the symbol "save" in a method unless you want to save something in a patcher. Your object will crash or corrupt patcher files otherwise. updated 6/6/95 updated for CodeWarrior 11/08/96 updated for CodeWarrior Pro6/PPC 03/26/01 -- */ /* data structure */ typedef struct simp { struct object s_ob; /* object header */ long s_state; /* state to save */ } Simp; /* prototypes */ void main(fptr *f); void simp_int(Simp *x, long n); void simp_bang(Simp *x); void simp_save(Simp *x, void *w); void simp_restore(Simp *x, long n); void *simp_new(long n); /* globals */ t_symbol *bindMeBaby; void *simp_class; /* initialization */ void main() { setup((t_messlist **)&simp_class, (method)simp_new, (method)0L, (short)sizeof(struct simp), 0L, A_DEFLONG, 0); addint((method)simp_int); addbang((method)simp_bang); addmess((method)simp_save, "save", A_CANT, 0); /* needed to save state */ addmess((method)simp_restore, "restore", A_LONG, 0); /* used to restore state */ finder_addclass("Control","simp"); bindMeBaby = gensym("#X"); /* t_symbol that we will use for restore */ } /* change state and report */ void simp_int(Simp *x, long n) { post("my state is now %ld",n); x->s_state = n; } /* report state */ void simp_bang(Simp *x) { post("my state is %ld",x->s_state); } /* save state with patcher */ void simp_save(Simp *x, void *w) { post("simp is saving..."); binbuf_vinsert(w,"ssl",gensym("#N"),gensym("simp"),0L); /* recreate me */ binbuf_vinsert(w,"ssl",bindMeBaby,gensym("restore"),x->s_state); /* send me a message with my state */ } /* called when file is read in to restore state */ void simp_restore(Simp *x, long n) { x->s_state = n; bindMeBaby->s_thing = 0; /* somewhat important */ post("simp restored to %ld",n); } /* metrowerks - declare this as "long simp_new(long n)" */ /* instance creation function */ void *simp_new(long n) { Simp *x; x = (Simp *)newobject(simp_class); x->s_state = n; bindMeBaby->s_thing = (t_object *)x; /* so you'll get the restore message */ return (x); }