aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/flext/source
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/flext/source')
-rw-r--r--externals/grill/flext/source/flbind.cpp8
-rw-r--r--externals/grill/flext/source/flclass.h18
-rw-r--r--externals/grill/flext/source/fldefs.h24
3 files changed, 32 insertions, 18 deletions
diff --git a/externals/grill/flext/source/flbind.cpp b/externals/grill/flext/source/flbind.cpp
index 3eee25ae..18297c61 100644
--- a/externals/grill/flext/source/flbind.cpp
+++ b/externals/grill/flext/source/flbind.cpp
@@ -18,12 +18,12 @@ WARRANTIES, see the file, "license.txt," in this distribution.
t_class *flext_base::pxbnd_class = NULL;
-flext_base::binditem::binditem(int in,const t_symbol *sym,bool (*f)(flext_base *,t_symbol *s,int,t_atom *),pxbnd_object *p):
+flext_base::binditem::binditem(int in,const t_symbol *sym,bool (*f)(flext_base *,t_symbol *s,int,t_atom *,void *data),pxbnd_object *p):
item(sym,0,NULL),fun(f),px(p)
{}
-bool flext_base::BindMethod(const t_symbol *sym,bool (*fun)(flext_base *,t_symbol *s,int,t_atom *))
+bool flext_base::BindMethod(const t_symbol *sym,bool (*fun)(flext_base *,t_symbol *s,int argc,t_atom *argv,void *data),void *data)
{
if(!bindhead)
bindhead = new itemarr;
@@ -43,7 +43,7 @@ bool flext_base::BindMethod(const t_symbol *sym,bool (*fun)(flext_base *,t_symbo
binditem *mi = new binditem(0,sym,fun,px);
bindhead->Add(mi);
- px->init(this,mi);
+ px->init(this,mi,data);
#if FLEXT_SYS == FLEXT_SYS_PD
pd_bind(&px->obj.ob_pd,const_cast<t_symbol *>(sym));
@@ -91,5 +91,5 @@ bool flext_base::UnbindMethod(const t_symbol *sym)
void flext_base::pxbnd_object::px_method(pxbnd_object *c,const t_symbol *s,int argc,t_atom *argv)
{
- c->item->fun(c->base,(t_symbol *)s,argc,(t_atom *)argv);
+ c->item->fun(c->base,(t_symbol *)s,argc,(t_atom *)argv,c->data);
}
diff --git a/externals/grill/flext/source/flclass.h b/externals/grill/flext/source/flclass.h
index 67926266..216c35fc 100644
--- a/externals/grill/flext/source/flclass.h
+++ b/externals/grill/flext/source/flclass.h
@@ -83,12 +83,10 @@ public:
/*! \brief Called for every incoming message.
All method handling is done in there
\return True if a handler was found and called
- \todo Once, there should be a const modifier for argv
*/
virtual bool m_methodmain(int inlet,const t_symbol *s,int argc,const t_atom *argv);
/*! \brief Called for every unhandled message (by m_methodmain)
- \todo Once, there should be a const modifier for argv
*/
virtual bool m_method_(int inlet,const t_symbol *s,int argc,const t_atom *argv);
@@ -411,9 +409,16 @@ public:
bool Unbind(const char *c) { return Unbind(MakeSymbol(c)); }
#endif
- bool BindMethod(const t_symbol *s,bool (*m)(flext_base *,t_symbol *s,int,t_atom *));
+ //! Bind a method to a symbol
+ bool BindMethod(const t_symbol *s,bool (*m)(flext_base *,t_symbol *s,int argc,t_atom *argv,void *data),void *data = NULL);
+ //! Unbind a method from a symbol
bool UnbindMethod(const t_symbol *s);
+ //! Bind a method to a symbol (as string)
+ bool BindMethod(const char *c,bool (*m)(flext_base *,t_symbol *s,int argc,t_atom *argv,void *data),void *data = NULL) { return BindMethod(MakeSymbol(c),m,data); }
+ //! Unbind a method from a symbol (as string)
+ bool UnbindMethod(const char *c) { return UnbindMethod(MakeSymbol(c)); }
+
//! @} FLEXT_C_BIND
// --- thread stuff -----------------------------------------------
@@ -607,10 +612,10 @@ public:
class binditem:
public item {
public:
- binditem(int inlet,const t_symbol *sym,bool (*f)(flext_base *,t_symbol *s,int,t_atom *),pxbnd_object *px);
+ binditem(int inlet,const t_symbol *sym,bool (*f)(flext_base *,t_symbol *s,int,t_atom *,void *),pxbnd_object *px);
~binditem();
- bool (*fun)(flext_base *,t_symbol *s,int,t_atom *);
+ bool (*fun)(flext_base *,t_symbol *s,int,t_atom *,void *);
pxbnd_object *px;
};
@@ -763,8 +768,9 @@ private:
t_object obj; // MUST reside at memory offset 0
flext_base *base;
binditem *item;
+ void *data;
- void init(flext_base *b,binditem *it) { base = b; item = it; }
+ void init(flext_base *b,binditem *it,void *d) { base = b; item = it; data = d; }
static void px_method(pxbnd_object *c,const t_symbol *s,int argc,t_atom *argv);
};
diff --git a/externals/grill/flext/source/fldefs.h b/externals/grill/flext/source/fldefs.h
index 98461d56..19e9891d 100644
--- a/externals/grill/flext/source/fldefs.h
+++ b/externals/grill/flext/source/fldefs.h
@@ -283,17 +283,17 @@ REAL_NEW_3(NAME,NEW_CLASS, 1,1, TYPE1, TYPE2, TYPE3)
@{
*/
-/*! \brief Specify that to declare the library itself
+/*! \brief Specify that to declare the library itself.
\note If you have a library this is compulsory (to register all the objects of the library)
*/
#define FLEXT_LIB_SETUP(NAME,SETUPFUN) REAL_LIB_SETUP(NAME,SETUPFUN)
-/*! \brief Register an object in the library
+/*! \brief Register an object in the library.
\note This is used in the library setup function
*/
#define FLEXT_SETUP(cl) REAL_SETUP(cl,0)
-/*! \brief Register a DSP object in the library
+/*! \brief Register a DSP object in the library.
\note This is used in the library setup function
*/
#define FLEXT_DSP_SETUP(cl) REAL_SETUP(cl,1)
@@ -334,8 +334,15 @@ static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,int argc,t_atom *argv) \
static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,void *data) \
{ FLEXT_CAST<thisType *>(c)->M_FUN(data); return true; }
+//! Set up a method callback for an anything argument and a data package (e.g. for symbol-bound methods).
+#define FLEXT_CALLBACK_AX(M_FUN) \
+static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,t_symbol *s,int argc,t_atom *argv,void *data) \
+{ FLEXT_CAST<thisType *>(c)->M_FUN(s,argc,argv,data); return true; }
+
//! Set up a timer callback
-#define FLEXT_CALLBACK_T(M_FUN) FLEXT_CALLBACK_X(M_FUN)
+#define FLEXT_CALLBACK_T(M_FUN) \
+\
+FLEXT_CALLBACK_X(M_FUN)
//! Set up a method callback for a boolean argument
#define FLEXT_CALLBACK_B(M_FUN) \
@@ -471,7 +478,7 @@ static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
delete args; \
}
-/*! \brief Set up a threaded method callback for an arbitrary data struct
+/*! \brief Set up a threaded method callback for an arbitrary data struct.
\note Data is pure... no destructor is called upon delete
*/
#define FLEXT_THREAD_X(M_FUN) \
@@ -876,17 +883,18 @@ FLEXT_ADDMETHOD_3(IX,M_TAG,M_FUN,int,int,int)
-/*! \defgroup FLEXT_D_BINDMETHOD Call flext methods manually
+/*! \defgroup FLEXT_D_BINDMETHOD Bind flext methods to symbols
@{
*/
/*! \brief Bind a handler for a method with an anything argument to a symbol
*/
-#define FLEXT_BINDMETHOD(SYM,M_FUN) \
+#define FLEXT_BINDMETHOD(SYM,M_FUN,DATA) \
\
-BindMethod(SYM,FLEXT_CALL_PRE(M_FUN))
+BindMethod(SYM,FLEXT_CALL_PRE(M_FUN),DATA)
/*! \brief Unbind any handler for a method from a symbol
+ \note Memory associated to the DATA parameter of FLEXT_BINDMETHOD will *not* be freed here.
*/
#define FLEXT_UNBINDMETHOD(SYM) \
\