obex and MSP confusion


    Feb 07 2007 | 6:03 am
    Hi all,
    Is there any magic I should know about using ext_obex.h for MSP externals? I couldn't find anything in the pattrsdk.pdf about MSP objects (t_pxobject).
    I'm having trouble getting my dsp() and perform() calls to happen, and I wondered if it is a clash between dsp and obex.
    Should I use class_addmethod or addmess for "dsp" and "perform" ? Where should dsp_initclass() go? Should I be using class_new and object_alloc at all?
    Here's what (a simplified copy of) my code looks like - if you can see any obvious issues, let me know (thanks in advance!). It should print out messages when audio is enabled, but nothing happens.
    class La { public:
    // standard max objects: t_pxobject ob; void * obex;
    t_object * out;
    static void * alloc(t_symbol *s, long argc, t_atom *argv); static void free(La *x);
    // @attributes: uchar enable;
    long dspenabled; static void dsp(La *x, t_signal **sp, short *count); static t_int * perform(t_int *w); };
    extern "C" int main(void) { t_class * c; void * attr; long attrflags = 0;
    c = class_new( "la~", (method)La::alloc, (method)La::free, (short)sizeof(La), 0L, A_GIMME, 0);
    addmess((method)La::dsp, "dsp", A_CANT, 0); //required for all msp objects addmess((method)La::dspstate, "dspstate", A_CANT, 0); dsp_initclass();
    // initialize the common symbols, since we want to use them common_symbols_init();
    // register the byte offset of obex with the class class_obexoffset_set(c, calcoffset(La, obex));
    // add some attributes
    // @enable class_addattr(c, (t_object *)attr_offset_new( "enable", // name _sym_char, // type 0, // attrflags, (method)0L, // getter (method)0L, // setter calcoffset(La, enable) // position within class ));
    // add methods for dumpout and quickref class_addmethod(c, (method)object_obex_dumpout, "dumpout", A_CANT, 0); class_addmethod(c, (method)object_obex_quickref,"quickref", A_CANT, 0);
    class_register(CLASS_BOX, c); La_class = c; }
    void * La :: alloc(t_symbol *s, long ac, t_atom *av) { La * x; t_atom a;
    if (x = (La *)object_alloc((t_class *)La_class)) {
    // create inlets & outlets dsp_setup((t_pxobject *)x, 2); // create inlets x->out = (t_object *)outlet_new(x, NULL); // add generic outlet object_obex_store(x, _sym_dumpout, x->out); // also set it as dumpout for (int i=0;i signal outlets
    // process attributes x->enable = 1; attr_args_process(x, ac, av); } return (x); }
    void La :: dsp(La * x, t_signal **sp, short *count) { post("La~ dsp");
    void ** perform_args = (void **) sysmem_newptr(sizeof(void*) * 6); perform_args[0] = (void *) x; perform_args[1] = (void *) sp[0]->s_n; for (int i=0; is_vec; dsp_addv(La::perform, 6, perform_args); }
    t_int * La :: perform(t_int *w) { post("La~ perform");
    La * x = (La *)(w[1]); // this MSP object int woffset = 3;
    // ...
    return w + woffset + 4; // return the object and args for next CB, keep Max/MSP happy }
    void La :: free(La *x) { // call this first: dsp_free((t_pxobject *)x);
    x->enable = 0; }

    • Feb 07 2007 | 6:20 am
      Hi there,
      - Use class_addmethod for everything
      - Yes, you should be using class_new and object_alloc
      - Your code is not happening because calling dsp_initclass() is not gonna work with obex. Substitute dsp_initclass(); with class_dspinit(c); and it will work like a charm.
      Best.
      - Luigi
      --- Graham Wakefield wrote:
      > Hi all, > > Is there any magic I should know about using > ext_obex.h for MSP > externals? I couldn't find anything in the > pattrsdk.pdf about MSP > objects (t_pxobject). > > I'm having trouble getting my dsp() and perform() > calls to happen, > and I wondered if it is a clash between dsp and > obex. > > Should I use class_addmethod or addmess for "dsp" > and "perform" ? > Where should dsp_initclass() go? > Should I be using class_new and object_alloc at all? > > Here's what (a simplified copy of) my code looks > like - if you can > see any obvious issues, let me know (thanks in > advance!). It should > print out messages when audio is enabled, but > nothing happens. > > class La > { > public: > > // standard max objects: > t_pxobject ob; > void * obex; > > t_object * out; > > static void * alloc(t_symbol *s, long argc, t_atom > *argv); > static void free(La *x); > > // @attributes: > uchar enable; > > long dspenabled; > static void dsp(La *x, t_signal **sp, short > *count); > static t_int * perform(t_int *w); > }; > > extern "C" int main(void) > { > t_class * c; > void * attr; > long attrflags = 0; > > c = class_new( > "la~", > (method)La::alloc, > (method)La::free, > (short)sizeof(La), > 0L, > A_GIMME, > 0); > > addmess((method)La::dsp, "dsp", A_CANT, 0); > //required for all msp > objects > addmess((method)La::dspstate, "dspstate", A_CANT, > 0); > dsp_initclass(); > > // initialize the common symbols, since we want to > use them > common_symbols_init(); > > // register the byte offset of obex with the class > class_obexoffset_set(c, calcoffset(La, obex)); > > // add some attributes > > // @enable > class_addattr(c, (t_object *)attr_offset_new( > "enable", // name > _sym_char, // type > 0, // attrflags, > (method)0L, // getter > (method)0L, // setter > calcoffset(La, enable) // position within class > )); > > // add methods for dumpout and quickref > class_addmethod(c, (method)object_obex_dumpout, > "dumpout", A_CANT, 0); > class_addmethod(c, > (method)object_obex_quickref,"quickref", A_CANT, > 0); > > class_register(CLASS_BOX, c); > La_class = c; > } > > void * La :: alloc(t_symbol *s, long ac, t_atom *av) > { > La * x; > t_atom a; > > if (x = (La *)object_alloc((t_class *)La_class)) > { > > // create inlets & outlets > dsp_setup((t_pxobject *)x, 2); // create inlets > x->out = (t_object *)outlet_new(x, NULL); // add > generic outlet > object_obex_store(x, _sym_dumpout, x->out); // > also set it as dumpout > for (int i=0;i > "signal"); // add > signal outlets > > // process attributes > x->enable = 1; > attr_args_process(x, ac, av); > } > return (x); > } > > > void La :: dsp(La * x, t_signal **sp, short *count) > { > post("La~ dsp"); > > void ** perform_args = (void **) > sysmem_newptr(sizeof(void*) * 6); > perform_args[0] = (void *) x; > perform_args[1] = (void *) sp[0]->s_n; > for (int i=0; i > *)sp[i]->s_vec; > dsp_addv(La::perform, 6, perform_args); > } > > t_int * La :: perform(t_int *w) > { > post("La~ perform"); > > La * x = (La *)(w[1]); // this MSP object > int woffset = 3; > > // ... > > return w + woffset + 4; // return the object and > args for next CB, > keep Max/MSP happy > } > > > > void La :: free(La *x) > { > // call this first: > dsp_free((t_pxobject *)x); > > x->enable = 0; > } > >
      ------------------------------------------------------------ THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE SENDER BY E-MAIL AT SUPERBIGIO@YAHOO.COM AND DESTROY ALL COPIES OF THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC1-207. ------------------------------------------------------------
      Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097
    • Feb 07 2007 | 7:22 am
      Thanks - that works.
      Could it be noted that there is no reference to class_dspinit(c) in the pattrsdk PDF at all?
      Again, thanks.
      On Feb 6, 2007, at 10:20 PM, Luigi Castelli wrote:
      > Hi there, > > - Use class_addmethod for everything > > - Yes, you should be using class_new and object_alloc > > - Your code is not happening because calling > dsp_initclass() is not gonna work with obex. > Substitute dsp_initclass(); with class_dspinit(c); and > it will work like a charm. > > Best. > > - Luigi > > > > > --- Graham Wakefield > wrote: > >> Hi all, >> >> Is there any magic I should know about using >> ext_obex.h for MSP >> externals? I couldn't find anything in the >> pattrsdk.pdf about MSP >> objects (t_pxobject). >> >> I'm having trouble getting my dsp() and perform() >> calls to happen, >> and I wondered if it is a clash between dsp and >> obex. >> >> Should I use class_addmethod or addmess for "dsp" >> and "perform" ? >> Where should dsp_initclass() go? >> Should I be using class_new and object_alloc at all? >> >> Here's what (a simplified copy of) my code looks >> like - if you can >> see any obvious issues, let me know (thanks in >> advance!). It should >> print out messages when audio is enabled, but >> nothing happens. >> >> class La >> { >> public: >> >> // standard max objects: >> t_pxobject ob; >> void * obex; >> >> t_object * out; >> >> static void * alloc(t_symbol *s, long argc, t_atom >> *argv); >> static void free(La *x); >> >> // @attributes: >> uchar enable; >> >> long dspenabled; >> static void dsp(La *x, t_signal **sp, short >> *count); >> static t_int * perform(t_int *w); >> }; >> >> extern "C" int main(void) >> { >> t_class * c; >> void * attr; >> long attrflags = 0; >> >> c = class_new( >> "la~", >> (method)La::alloc, >> (method)La::free, >> (short)sizeof(La), >> 0L, >> A_GIMME, >> 0); >> >> addmess((method)La::dsp, "dsp", A_CANT, 0); >> //required for all msp >> objects >> addmess((method)La::dspstate, "dspstate", A_CANT, >> 0); >> dsp_initclass(); >> >> // initialize the common symbols, since we want to >> use them >> common_symbols_init(); >> >> // register the byte offset of obex with the class >> class_obexoffset_set(c, calcoffset(La, obex)); >> >> // add some attributes >> >> // @enable >> class_addattr(c, (t_object *)attr_offset_new( >> "enable", // name >> _sym_char, // type >> 0, // attrflags, >> (method)0L, // getter >> (method)0L, // setter >> calcoffset(La, enable) // position within class >> )); >> >> // add methods for dumpout and quickref >> class_addmethod(c, (method)object_obex_dumpout, >> "dumpout", A_CANT, 0); >> class_addmethod(c, >> (method)object_obex_quickref,"quickref", A_CANT, >> 0); >> >> class_register(CLASS_BOX, c); >> La_class = c; >> } >> >> void * La :: alloc(t_symbol *s, long ac, t_atom *av) >> { >> La * x; >> t_atom a; >> >> if (x = (La *)object_alloc((t_class *)La_class)) >> { >> >> // create inlets & outlets >> dsp_setup((t_pxobject *)x, 2); // create inlets >> x->out = (t_object *)outlet_new(x, NULL); // add >> generic outlet >> object_obex_store(x, _sym_dumpout, x->out); // >> also set it as dumpout >> for (int i=0;i >> "signal"); // add >> signal outlets >> >> // process attributes >> x->enable = 1; >> attr_args_process(x, ac, av); >> } >> return (x); >> } >> >> >> void La :: dsp(La * x, t_signal **sp, short *count) >> { >> post("La~ dsp"); >> >> void ** perform_args = (void **) >> sysmem_newptr(sizeof(void*) * 6); >> perform_args[0] = (void *) x; >> perform_args[1] = (void *) sp[0]->s_n; >> for (int i=0; i >> *)sp[i]->s_vec; >> dsp_addv(La::perform, 6, perform_args); >> } >> >> t_int * La :: perform(t_int *w) >> { >> post("La~ perform"); >> >> La * x = (La *)(w[1]); // this MSP object >> int woffset = 3; >> >> // ... >> >> return w + woffset + 4; // return the object and >> args for next CB, >> keep Max/MSP happy >> } >> >> >> >> void La :: free(La *x) >> { >> // call this first: >> dsp_free((t_pxobject *)x); >> >> x->enable = 0; >> } >> >> > > > > ------------------------------------------------------------ > THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT > AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY > UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS > PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE > SENDER BY E-MAIL AT SUPERBIGIO@YAHOO.COM AND DESTROY ALL COPIES OF > THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC1-207. > ------------------------------------------------------------ > > > > > ______________ > Now that's room service! Choose from over 150,000 hotels > in 45,000 destinations on Yahoo! Travel to find your fit. > http://farechase.yahoo.com/promo-generic-14795097
    • Feb 07 2007 | 8:50 am
      On Feb 6, 2007, at 11:22 PM, Graham Wakefield wrote:
      > Could it be noted that there is no reference to class_dspinit(c) in > the pattrsdk PDF at all?
      I suppose it could, as you just have ;)
      Here's a related dev forum archive. Don't forget to search for those little details that "slip through the cracks"...
      -Joshua