Commit 7362ab0f authored by thomas's avatar thomas
Browse files

fixed and cleaned up library related stuff, especially co-existance of Max...

fixed and cleaned up library related stuff, especially co-existance of Max message and DSP library objects

git-svn-id: https://svn.grrrr.org/ext/trunk@1132 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 6c1cafff
......@@ -19,6 +19,8 @@ Version history:
- fixed severe Altivec bug (load unaligned)... thanks to Ian Ollmann
- restructured initialization and finalization (esp. Max DSP stuff)
- real class names now also reflect debug mode (like in flext_base_shared_d)
- cleaned up internals (like Max/MSP typedefs)
- fixed coexistence of message and signal objects in Max/MSP object libraries
0.5.0:
- fixes for 64 bit builds (size_t is integer type of pointer size)
......
......@@ -478,7 +478,7 @@ void flext_base::SetGfx(t_classid c)
widgetbehavior.w_selectfn = cb_GfxSelect;
#if PD_MINOR_VERSION >= 37
class_setsavefn(cl,cb_GfxSave);
class_setsavefn(cl,(t_savefn)cb_GfxSave);
#else
widgetbehavior.w_savefn = cb_GfxSave;
#endif
......@@ -489,7 +489,7 @@ void flext_base::SetGfx(t_classid c)
#ifndef FLEXT_NOATTREDIT
#if PD_MINOR_VERSION >= 37
class_setpropertiesfn(cl,cb_GfxProperties);
class_setpropertiesfn(cl,(t_propertiesfn)cb_GfxProperties);
#else
widgetbehavior.w_propertiesfn = cb_GfxProperties;
#endif
......@@ -518,7 +518,7 @@ static size_t escapeit(char *dst,size_t maxlen,const char *src)
return d-dst;
}
void flext_base::cb_GfxProperties(t_gobj *c, t_glist *)
void flext_base::cb_GfxProperties(flext_hdr *c, t_glist *)
{
flext_base *th = thisObject(c);
char buf[1000];
......@@ -784,7 +784,7 @@ void flext_base::BinbufAttr(t_binbuf *b,bool transdoll)
}
//! Strip the attributes off the object command line
void flext_base::cb_GfxVis(t_gobj *c, t_glist *gl, int vis)
void flext_base::cb_GfxVis(flext_hdr *c, t_glist *gl, int vis)
{
if(!gl->gl_isgraph || gl->gl_havewindow) {
// show object if it's not inside a GOP
......@@ -814,7 +814,7 @@ void flext_base::cb_GfxVis(t_gobj *c, t_glist *gl, int vis)
// else don't show
}
void flext_base::cb_GfxSelect(t_gobj *c,t_glist *gl,int state)
void flext_base::cb_GfxSelect(flext_hdr *c,t_glist *gl,int state)
{
t_text *x = (t_text *)c;
flext_base *th = thisObject(c);
......@@ -853,7 +853,7 @@ void flext_base::cb_GfxSelect(t_gobj *c,t_glist *gl,int state)
}
}
void flext_base::cb_GfxSave(t_gobj *c, t_binbuf *b)
void flext_base::cb_GfxSave(flext_hdr *c, t_binbuf *b)
{
flext_base *th = thisObject(c);
t_text *t = (t_text *)c;
......
......@@ -154,10 +154,20 @@ class FLEXT_SHARE FLEXT_CLASSDEF(flext_obj):
t_classid thisClassId() const { return clss; }
//! Get class pointer from class id
static t_class *getClass(t_classid);
static t_class *getClass(t_classid id);
static bool IsDSP(t_classid id);
static bool IsLib(t_classid id);
bool HasAttributes() const;
bool HasDSP() const;
bool IsDSP() const;
bool IsLib() const;
#if FLEXT_SYS == FLEXT_SYS_MAX
// under Max/MSP it could be necessary to activate DSP also for message objects
// namely for those coexisting with DSP objects in a library
bool NeedDSP() const;
#endif
//! @} FLEXT_OBJ_INFO
......@@ -242,17 +252,12 @@ class FLEXT_SHARE FLEXT_CLASSDEF(flext_obj):
// Definitions for library objects
static void lib_init(const char *name,void setupfun(),bool attr);
static void obj_add(bool lib,bool dsp,bool attr,const char *idname,const char *names,void setupfun(t_classid),FLEXT_CLASSDEF(flext_obj) *(*newfun)(int,t_atom *),void (*freefun)(flext_hdr *),int argtp1,...);
#if FLEXT_SYS == FLEXT_SYS_JMAX
static void obj_new(fts_object_t *o, int winlet, fts_symbol_t s, int ac, const fts_atom_t *at);
static void obj_free(fts_object_t *o, int winlet, fts_symbol_t s, int ac, const fts_atom_t *at);
#else
#if FLEXT_SYS == FLEXT_SYS_MAX
static flext_hdr *obj_new(const t_symbol *s,short argc,t_atom *argv);
#else
static flext_hdr *obj_new(const t_symbol *s,int argc,t_atom *argv);
#endif
static void obj_free(flext_hdr *o);
#endif
//! Convert $0 or #0 symbol into appropriate value
static bool GetParamSym(t_atom &dst,const t_symbol *s,t_canvas *c);
......@@ -303,77 +308,52 @@ class FLEXT_SHARE FLEXT_CLASSDEF(flext_obj):
public: \
typedef NEW_CLASS thisType; \
static FLEXT_CLASSDEF(flext_obj) *__init__(int argc,t_atom *argv); \
static void __free__(flext_hdr *hdr) \
{ FLEXT_CLASSDEF(flext_obj) *mydata = hdr->data; delete mydata; \
hdr->flext_hdr::~flext_hdr(); } \
static void __setup__(t_classid classid) { \
PARENT_CLASS::__setup__(classid); } \
protected: \
static inline NEW_CLASS *thisObject(void *c) { return FLEXT_CAST<NEW_CLASS *>(((flext_hdr *)c)->data); }
static void __free__(flext_hdr *hdr) { \
FLEXT_CLASSDEF(flext_obj) *mydata = hdr->data; delete mydata; \
hdr->flext_hdr::~flext_hdr(); \
} \
static void __setup__(t_classid classid) { PARENT_CLASS::__setup__(classid); }
#define FLEXT_REALHDR_S(NEW_CLASS, PARENT_CLASS,SETUPFUN) \
public: \
typedef NEW_CLASS thisType; \
static FLEXT_CLASSDEF(flext_obj) *__init__(int argc,t_atom *argv); \
static void __free__(flext_hdr *hdr) \
{ FLEXT_CLASSDEF(flext_obj) *mydata = hdr->data; delete mydata; \
hdr->flext_hdr::~flext_hdr(); } \
static void __setup__(t_classid classid) \
{ PARENT_CLASS::__setup__(classid); \
NEW_CLASS::SETUPFUN(classid); } \
protected: \
static inline NEW_CLASS *thisObject(void *c) { return FLEXT_CAST<NEW_CLASS *>(((flext_hdr *)c)->data); }
static void __free__(flext_hdr *hdr) { \
FLEXT_CLASSDEF(flext_obj) *mydata = hdr->data; delete mydata; \
hdr->flext_hdr::~flext_hdr(); \
} \
static void __setup__(t_classid classid) { \
PARENT_CLASS::__setup__(classid); \
NEW_CLASS::SETUPFUN(classid); \
}
// generate name of dsp/non-dsp setup function
#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX
#define FLEXT_STPF_0(NAME) NAME##_setup
#define FLEXT_STPF_1(NAME) NAME##_tilde_setup
#else
#define FLEXT_STPF_0(NAME) NAME##_config
#define FLEXT_STPF_1(NAME) signal_##NAME##_config
#error Platform not supported
#endif
#define FLEXT_STPF_(DSP) FLEXT_STPF_##DSP
#define FLEXT_STPF(NAME,DSP) FLEXT_STPF_(DSP)(NAME)
// --------------------------------------------------------------------------------------
// these can be used in library setup functions
// to register the individual objects in the library
#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX
#define REAL_SETUP_0(cl) \
extern void cl##_setup(); cl##_setup()
#define REAL_SETUP_1(cl) \
extern void cl##_tilde_setup(); cl##_tilde_setup()
#else
#define REAL_SETUP_0(cl) \
extern void cl##_config(); cl##_config()
#define REAL_SETUP_1(cl) \
extern void signal_##cl##_config(); signal_##cl##_config()
#endif
#define REAL_SETUP(cl,DSP) REAL_SETUP_##DSP(cl)
// used in library setup functions to register the individual objects in the library
#define REAL_SETUP(cl,DSP) extern void FLEXT_STPF(cl,DSP)(); FLEXT_STPF(cl,DSP)();
// specify that to define the library itself
#if FLEXT_SYS == FLEXT_SYS_PD
#define REAL_LIB_SETUP(NAME,SETUPFUN) extern "C" FLEXT_EXT void NAME##_setup() { flext_obj::lib_init(#NAME,SETUPFUN,FLEXT_ATTRIBUTES); }
#elif FLEXT_SYS == FLEXT_SYS_MAX
#define REAL_LIB_SETUP(NAME,SETUPFUN) extern "C" FLEXT_EXT int main() { flext_obj::lib_init(#NAME,SETUPFUN,FLEXT_ATTRIBUTES); return 0; }
#elif FLEXT_SYS == FLEXT_SYS_JMAX
#define REAL_LIB_SETUP(NAME,SETUPFUN) \
static void __##NAME##_initfun() { flext_obj::lib_init(#NAME,SETUPFUN,FLEXT_ATTRIBUTES); } \
fts_module_t __##NAME##_module = {#NAME,#NAME,__##NAME##_initfun,0,0};
#else
#error
#error Platform not supported
#endif
......@@ -384,7 +364,7 @@ fts_module_t __##NAME##_module = {#NAME,#NAME,__##NAME##_initfun,0,0};
#define FLEXT_EXP_1
#define FLEXT_EXP(LIB) FLEXT_EXP_##LIB
#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_JMAX
#if FLEXT_SYS == FLEXT_SYS_PD
#define FLEXT_OBJ_SETUP_0(NEW_CLASS,DSP)
#elif FLEXT_SYS == FLEXT_SYS_MAX
#define FLEXT_OBJ_SETUP_0(NEW_CLASS,DSP) extern "C" FLEXT_EXT int main() { FLEXT_STPF(NEW_CLASS,DSP)(); return 0; }
......@@ -444,7 +424,7 @@ fts_module_t __##NAME##_module = {#NAME,#NAME,__##NAME##_initfun,0,0};
#define FLEXTTYPE_bool FLEXTTPN_FLOAT
#define FLEXTTYPE_bool0 FLEXTTPN_DEFFLOAT
#define CALLBTYPE_bool float
#elif FLEXT_SYS == FLEXT_SYS_MAX || FLEXT_SYS == FLEXT_SYS_JMAX
#elif FLEXT_SYS == FLEXT_SYS_MAX
#define FLEXTTYPE_int FLEXTTPN_INT
#define FLEXTTYPE_int0 FLEXTTPN_DEFINT
#define CALLBTYPE_int int
......@@ -452,7 +432,7 @@ fts_module_t __##NAME##_module = {#NAME,#NAME,__##NAME##_initfun,0,0};
#define FLEXTTYPE_bool0 FLEXTTPN_DEFINT
#define CALLBTYPE_bool int
#else
#error
#error Platform not supported
#endif
#define FLEXTTYPE_t_symptr FLEXTTPN_SYM
......
......@@ -198,12 +198,11 @@ public:
//! Retrieve currently processed message tag (NULL if no message processing)
static const t_symbol *thisTag() { return curtag; }
#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX
class outlet;
//! Get pointer to outlet (not in the constructor!)
outlet *GetOut(int ix) const { return outlets[ix]; }
#endif
int GetOutAttr() const { return HasAttributes()?CntOut():0; }
//! @} FLEXT_C_IO_MISC
......@@ -349,10 +348,8 @@ public:
void AddMethod(int inlet,bool (*m)(flext_base *,float &,float &,float &)) { AddMethod(ThMeths(),inlet,sym_list,(methfun)m,a_float,a_float,a_float,a_null); } // list of 3 floats
#if FLEXT_SYS == FLEXT_SYS_PD
void AddMethod(int inlet,bool (*m)(flext_base *,int &)) { AddMethod(ThMeths(),inlet,sym_float,(methfun)m,a_int,a_null); } // single float
#elif FLEXT_SYS == FLEXT_SYS_MAX || FLEXT_SYS == FLEXT_SYS_JMAX
void AddMethod(int inlet,bool (*m)(flext_base *,int &)) { AddMethod(ThMeths(),inlet,sym_int,(methfun)m,a_int,a_null); } // single float
#else
#error
void AddMethod(int inlet,bool (*m)(flext_base *,int &)) { AddMethod(ThMeths(),inlet,sym_int,(methfun)m,a_int,a_null); } // single float
#endif
void AddMethod(int inlet,bool (*m)(flext_base *,int &,int &)) { AddMethod(ThMeths(),inlet,sym_list,(methfun)m,a_int,a_int,a_null); } // list of 2 floats
void AddMethod(int inlet,bool (*m)(flext_base *,int &,int &,int &)) { AddMethod(ThMeths(),inlet,sym_list,(methfun)m,a_int,a_int,a_int,a_null); } // list of 3 floats
......@@ -399,10 +396,8 @@ public:
static void AddMethod(t_classid c,int inlet,bool (*m)(flext_base *,float &,float &,float &)) { AddMethod(ClMeths(c),inlet,sym_list,(methfun)m,a_float,a_float,a_float,a_null); } // list of 3 floats
#if FLEXT_SYS == FLEXT_SYS_PD
static void AddMethod(t_classid c,int inlet,bool (*m)(flext_base *,int &)) { AddMethod(ClMeths(c),inlet,sym_float,(methfun)m,a_int,a_null); } // single integer
#elif FLEXT_SYS == FLEXT_SYS_MAX || FLEXT_SYS == FLEXT_SYS_JMAX
static void AddMethod(t_classid c,int inlet,bool (*m)(flext_base *,int &)) { AddMethod(ClMeths(c),inlet,sym_int,(methfun)m,a_int,a_null); } // single integer
#else
#error
static void AddMethod(t_classid c,int inlet,bool (*m)(flext_base *,int &)) { AddMethod(ClMeths(c),inlet,sym_int,(methfun)m,a_int,a_null); } // single integer
#endif
static void AddMethod(t_classid c,int inlet,bool (*m)(flext_base *,int &,int &)) { AddMethod(ClMeths(c),inlet,sym_list,(methfun)m,a_int,a_int,a_null); } // list of 2 floats
static void AddMethod(t_classid c,int inlet,bool (*m)(flext_base *,int &,int &,int &)) { AddMethod(ClMeths(c),inlet,sym_list,(methfun)m,a_int,a_int,a_int,a_null); } // list of 3 floats
......@@ -432,24 +427,15 @@ public:
@{
*/
#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX
//! Bind object to a symbol
bool Bind(const t_symbol *sym);
//! Unbind object from a symbol
bool Unbind(const t_symbol *sym);
#endif
#if FLEXT_SYS == FLEXT_SYS_JMAX
//! Bind object to a symbol (as string)
bool Bind(const char *sym); // ** TODO **
//! Unbind object from a symbol (as string)
bool Unbind(const char *sym); // ** TODO **
#else
//! Bind object to a symbol (as string)
bool Bind(const char *sym) { return Bind(MakeSymbol(sym)); }
//! Unbind object from a symbol (as string)
bool Unbind(const char *sym) { return Unbind(MakeSymbol(sym)); }
#endif
/*! \brief Bind a method to a symbol
\param sym Symbol to bind to
......@@ -768,26 +754,20 @@ protected:
};
// these outlet functions don't check for thread but send directly to the real-time system
#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX
void ToSysBang(int n) const { outlet *o = GetOut(n); if(o) { CRITON(); outlet_bang((t_outlet *)o); CRITOFF(); } }
void ToSysFloat(int n,float f) const { outlet *o = GetOut(n); if(o) { CRITON(); outlet_float((t_outlet *)o,f); CRITOFF(); } }
void ToSysInt(int n,int f) const { outlet *o = GetOut(n); if(o) { CRITON(); outlet_flint((t_outlet *)o,f); CRITOFF(); } }
void ToSysSymbol(int n,const t_symbol *s) const { outlet *o = GetOut(n); if(o) { CRITON(); outlet_symbol((t_outlet *)o,const_cast<t_symbol *>(s)); CRITOFF(); } }
void ToSysList(int n,int argc,const t_atom *argv) const { outlet *o = GetOut(n); if(o) { CRITON(); outlet_list((t_outlet *)o,const_cast<t_symbol *>(sym_list),argc,(t_atom *)argv); CRITOFF(); } }
void ToSysAnything(int n,const t_symbol *s,int argc,const t_atom *argv) const { outlet *o = GetOut(n); if(o) { CRITON(); outlet_anything((t_outlet *)o,const_cast<t_symbol *>(s),argc,(t_atom *)argv); CRITOFF(); } }
#elif FLEXT_SYS == FLEXT_SYS_JMAX
void ToSysBang(int n) const { fts_outlet_bang((fts_object *)thisHdr(),n); }
void ToSysFloat(int n,float f) const { fts_outlet_float((fts_object *)thisHdr(),n,f); }
void ToSysInt(int n,int f) const { fts_outlet_int((fts_object *)thisHdr(),n,f); }
void ToSysSymbol(int n,const t_symbol *s) const { fts_outlet_symbol((fts_object *)thisHdr(),n,s); }
void ToSysList(int n,int argc,const t_atom *argv) const { fts_outlet_send((fts_object *)thisHdr(),n,sym_list,argc,(t_atom *)argv); }
void ToSysAnything(int n,const t_symbol *s,int argc,const t_atom *argv) const { fts_outlet_send((fts_object *)thisHdr(),n,const_cast<t_symbol *>(s),argc,(t_atom *)argv); }
#else
#error Not implemented
#endif
void ToSysBool(int n,bool f) const { ToSysInt(n,f?1:0); }
void ToSysAtom(int n,const t_atom &at) const;
// add class method handlers
static void AddMessageMethods(t_class *c);
static void AddSignalMethods(t_class *c);
private:
class pxbnd_object;
public:
......@@ -823,6 +803,8 @@ public:
private:
static inline flext_base *thisObject(flext_hdr *c) { return FLEXT_CAST<flext_base *>(c->data); }
static void Setup(t_classid c);
//! \brief This represents either an inlet or outlet during construction
......@@ -845,9 +827,7 @@ private:
//! number of message and signal inlets/outlets
unsigned char incnt,outcnt,insigs,outsigs;
#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX
outlet **outlets;
#endif
union t_any {
float ft;
......@@ -918,13 +898,13 @@ private:
#ifndef FLEXT_NOATTREDIT
// attribute editor
static bool cb_AttrDialog(flext_base *c,int argc,const t_atom *argv);
static void cb_GfxProperties(t_gobj *c, t_glist *);
static void cb_GfxProperties(flext_hdr *c, t_glist *);
#endif
#ifdef FLEXT_ATTRHIDE
static void cb_GfxVis(t_gobj *c, t_glist *gl, int vis);
static void cb_GfxSave(t_gobj *c, t_binbuf *b);
static void cb_GfxSelect(t_gobj *x, struct _glist *glist, int state);
static void cb_GfxVis(flext_hdr *c, t_glist *gl, int vis);
static void cb_GfxSave(flext_hdr *c, t_binbuf *b);
static void cb_GfxSelect(flext_hdr *x, struct _glist *glist, int state);
void BinbufArgs(t_binbuf *b,t_binbuf *args,bool withname,bool transdoll);
void BinbufAttr(t_binbuf *b,bool transdoll);
......@@ -943,52 +923,48 @@ private:
static void px_method(px_object *c,const t_symbol *s,int argc,t_atom *argv);
};
static void cb_px_anything(t_class *c,const t_symbol *s,int argc,t_atom *argv);
static void cb_px_anything(flext_hdr *c,const t_symbol *s,int argc,t_atom *argv);
static void cb_px_ft1(t_class *c,float f);
static void cb_px_ft2(t_class *c,float f);
static void cb_px_ft3(t_class *c,float f);
static void cb_px_ft4(t_class *c,float f);
static void cb_px_ft5(t_class *c,float f);
static void cb_px_ft6(t_class *c,float f);
static void cb_px_ft7(t_class *c,float f);
static void cb_px_ft8(t_class *c,float f);
static void cb_px_ft9(t_class *c,float f);
static void cb_px_ft1(flext_hdr *c,float f);
static void cb_px_ft2(flext_hdr *c,float f);
static void cb_px_ft3(flext_hdr *c,float f);
static void cb_px_ft4(flext_hdr *c,float f);
static void cb_px_ft5(flext_hdr *c,float f);
static void cb_px_ft6(flext_hdr *c,float f);
static void cb_px_ft7(flext_hdr *c,float f);
static void cb_px_ft8(flext_hdr *c,float f);
static void cb_px_ft9(flext_hdr *c,float f);
#elif FLEXT_SYS == FLEXT_SYS_MAX
typedef object px_object;
static void cb_px_float(t_class *c,double f);
static void cb_px_int(t_class *c,long v);
static void cb_px_bang(t_class *c);
static void cb_px_in1(t_class *c,long v);
static void cb_px_in2(t_class *c,long v);
static void cb_px_in3(t_class *c,long v);
static void cb_px_in4(t_class *c,long v);
static void cb_px_in5(t_class *c,long v);
static void cb_px_in6(t_class *c,long v);
static void cb_px_in7(t_class *c,long v);
static void cb_px_in8(t_class *c,long v);
static void cb_px_in9(t_class *c,long v);
static void cb_px_ft1(t_class *c,double f);
static void cb_px_ft2(t_class *c,double f);
static void cb_px_ft3(t_class *c,double f);
static void cb_px_ft4(t_class *c,double f);
static void cb_px_ft5(t_class *c,double f);
static void cb_px_ft6(t_class *c,double f);
static void cb_px_ft7(t_class *c,double f);
static void cb_px_ft8(t_class *c,double f);
static void cb_px_ft9(t_class *c,double f);
static void cb_px_anything(t_class *c,const t_symbol *s,short argc,t_atom *argv);
static void cb_px_float(flext_hdr *c,double f);
static void cb_px_int(flext_hdr *c,long v);
static void cb_px_bang(flext_hdr *c);
static void cb_px_in1(flext_hdr *c,long v);
static void cb_px_in2(flext_hdr *c,long v);
static void cb_px_in3(flext_hdr *c,long v);
static void cb_px_in4(flext_hdr *c,long v);
static void cb_px_in5(flext_hdr *c,long v);
static void cb_px_in6(flext_hdr *c,long v);
static void cb_px_in7(flext_hdr *c,long v);
static void cb_px_in8(flext_hdr *c,long v);
static void cb_px_in9(flext_hdr *c,long v);
static void cb_px_ft1(flext_hdr *c,double f);
static void cb_px_ft2(flext_hdr *c,double f);
static void cb_px_ft3(flext_hdr *c,double f);
static void cb_px_ft4(flext_hdr *c,double f);
static void cb_px_ft5(flext_hdr *c,double f);
static void cb_px_ft6(flext_hdr *c,double f);
static void cb_px_ft7(flext_hdr *c,double f);
static void cb_px_ft8(flext_hdr *c,double f);
static void cb_px_ft9(flext_hdr *c,double f);
static void cb_px_anything(flext_hdr *c,const t_symbol *s,short argc,t_atom *argv);
#endif
#if FLEXT_SYS == FLEXT_SYS_PD || FLEXT_SYS == FLEXT_SYS_MAX
px_object **inlets;
#elif FLEXT_SYS == FLEXT_SYS_JMAX
static void jmax_proxy(fts_object_t *c, int winlet, fts_symbol_t s, int ac, const fts_atom_t *at);
#endif
// --------- symbol-bound proxy
......@@ -1024,17 +1000,19 @@ private:
// callback functions
static void cb_loadbang(t_class *c);
#if FLEXT_SYS == FLEXT_SYS_PD
static void cb_click(t_gobj *z,t_floatarg xpos,t_floatarg ypos,t_floatarg shift,t_floatarg ctrl,t_floatarg alt);
#endif
static void cb_loadbang(flext_hdr *c);
#if FLEXT_SYS == FLEXT_SYS_MAX
char **indesc,**outdesc;
static void cb_assist(t_class *c,void *b,long msg,long arg,char *s);
static void cb_click (t_class *c, Point pt, short mods);
static void cb_assist(flext_hdr *c,void *b,long msg,long arg,char *s);
static void cb_click (flext_hdr *c, Point pt, short mods);
static void cb_dsp(flext_hdr *c,t_signal **s,short *count);
#elif FLEXT_SYS == FLEXT_SYS_PD
static void cb_click(flext_hdr *z,t_floatarg xpos,t_floatarg ypos,t_floatarg shift,t_floatarg ctrl,t_floatarg alt);
static void cb_dsp(flext_hdr *c,t_signal **s);
#endif
};
......
......@@ -23,14 +23,12 @@ void flext_dsp::Setup(t_classid id)
t_class *c = getClass(id);
#if FLEXT_SYS == FLEXT_SYS_MAX
dsp_initclass();
add_dsp(c,cb_dsp);
#elif FLEXT_SYS == FLEXT_SYS_PD
CLASS_MAINSIGNALIN(c,flext_hdr,defsig); // float messages going into the left inlet are converted to signal
add_dsp(c,cb_dsp);
if(!IsLib(id))
#endif
AddSignalMethods(c);
#if FLEXT_SYS == FLEXT_SYS_PD
add_method1(c,cb_enable,"enable",A_FLOAT);
#else
#error Platform not supported!
#endif
}
......@@ -42,26 +40,8 @@ flext_dsp::FLEXT_CLASSDEF(flext_dsp)()
#endif
{}
#if FLEXT_SYS == FLEXT_SYS_MAX
bool flext_dsp::Init()
{
if(!flext_base::Init())
return false;
// according to the Max/MSP SDK this should be prior to any inlet creation, BUT
// that doesn't seem to be true... multiple signal ins and additional inlets don't seem to work then
dsp_setup(thisHdr(),CntInSig()); // signal inlets
return true;
}
#endif
void flext_dsp::Exit()
{
#if FLEXT_SYS == FLEXT_SYS_MAX
// according to David Z. one should do that first...
dsp_free(thisHdr());
#endif
flext_base::Exit();
if(vecs) delete[] vecs;
......@@ -85,50 +65,37 @@ t_int *flext_dsp::dspmeth(t_int *w)
return w+2;
}
#if FLEXT_SYS == FLEXT_SYS_MAX
void flext_dsp::cb_dsp(t_class *c,t_signal **sp,short *count)
#else
void flext_dsp::cb_dsp(t_class *c,t_signal **sp)
#endif
void flext_dsp::SetupDsp(t_signal **sp)
{
flext_dsp *obj = thisObject(c);
#if FLEXT_SYS == FLEXT_SYS_MAX
// we must extra-check here if it is really a DSP object
// obviously, for objects that are part of a library, one dsp_initclass enables DSP for all
if(!obj->HasDSP()) return;
#endif
int i;
int in = obj->CntInSig();
int out = obj->CntOutSig();
int in = CntInSig();
int out = CntOutSig();
#if FLEXT_SYS == FLEXT_SYS_PD
// min. 1 input channel! (CLASS_MAININLET in pd...)
if(!in) in = 1;
#endif
// store current dsp parameters
obj->srate = sp[0]->s_sr;
obj->blksz = sp[0]->s_n; // is this guaranteed to be the same as sys_getblksize() ?
srate = sp[0]->s_sr;
blksz = sp[0]->s_n; // is this guaranteed to be the same as sys_getblksize() ?
// store in and out signal vectors
if((in+out) && !obj->vecs)
obj->vecs = new t_signalvec[in+out];
if((in+out) && !vecs)
vecs = new t_signalvec[in+out];
for(i = 0; i < in; ++i)
obj->vecs[i] = sp[i]->s_vec;
vecs[i] = sp[i]->s_vec;
for(i = 0; i < out; ++i)
obj->vecs[in+i] = sp[in+i]->s_vec;
vecs[in+i] = sp[in+i]->s_vec;
// with the following call derived classes can do their eventual DSP setup
if(obj->CbDsp()) {
if(CbDsp()) {
// set the DSP function
dsp_add((t_dspmethod)dspmeth,1,obj);
dsp_add((t_dspmethod)dspmeth,1,this);
}
}
void flext_dsp::m_dsp(int /*n*/,t_signalvec const * /*insigs*/,t_signalvec const * /*outsigs*/) {}
bool flext_dsp::CbDsp()
......@@ -152,5 +119,5 @@ void flext_dsp::CbSignal()
#if FLEXT_SYS == FLEXT_SYS_PD
void flext_dsp::cb_enable(t_class *c,t_float on) { thisObject(c)->dspon = on != 0; }
void flext_dsp::cb_enable(flext_hdr *c,t_float on) { thisObject(c)->dspon = on != 0; }
#endif
......@@ -33,6 +33,8 @@ class FLEXT_SHARE FLEXT_CLASSDEF(flext_dsp):
{
FLEXT_HEADER_S(FLEXT_CLASSDEF(flext_dsp),flext_base,Setup)
friend class FLEXT_SHARE FLEXT_CLASSDEF(flext_base);
public:
/*! \defgroup FLEXT_DSP Flext dsp class
......@@ -148,10 +150,6 @@ protected:
FLEXT_CLASSDEF(flext_dsp)();
#if FLEXT_SYS == FLEXT_SYS_MAX
virtual bool Init();
#endif
virtual void Exit();