Commit fd984628 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@442 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent d3cc649a
No preview for this file type
SRCS=flbase.cpp flext.cpp flbuf.cpp fldsp.cpp fllib.cpp flxlet.cpp flattr.cpp flsupport.cpp \
flutil.cpp flatom.cpp flatom_pr.cpp flthr.cpp flout.cpp
flutil.cpp flatom.cpp flatom_pr.cpp flthr.cpp flout.cpp \
flatom_app.cpp flatom_part.cpp flitem.cpp flmeth.cpp flmsg.cpp \
flproxy.cpp flqueue.cpp
HDRS=flprefix.h flstdc.h flbase.h flclass.h fldefs.h flext.h flsupport.h fldsp.h flinternal.h
SRCS_SNDOBJ=flsndobj.cpp
HDRS_SNDOBJ=flsndobj.h
......@@ -36,6 +36,7 @@ flext::AtomList::AtomList(const AtomList &a):
flext::AtomList::~AtomList() { Clear(); }
flext::AtomList &flext::AtomList::Set(int argc,const t_atom *argv,int offs,bool resize)
{
int ncnt = argc+offs;
......@@ -51,85 +52,6 @@ flext::AtomList &flext::AtomList::Set(int argc,const t_atom *argv,int offs,bool
return *this;
}
int flext::AtomList::Get(t_atom *argv,int mxsz) const
{
int argc = Count();
if(mxsz >= 0 && argc > mxsz) argc = mxsz;
for(int i = 0; i < argc; ++i) SetAtom(argv[i],lst[i]);
return argc;
}
flext::AtomList &flext::AtomList::Append(const t_atom &a)
{
t_atom *nlst = new t_atom[cnt+1];
for(int i = 0; i < cnt; ++i) SetAtom(nlst[i],lst[i]);
SetAtom(nlst[cnt],a);
if(lst) delete[] lst;
lst = nlst;
++cnt;
return *this;
}
flext::AtomList &flext::AtomList::Append(int argc,const t_atom *argv)
{
if(argc) {
t_atom *nlst = new t_atom[cnt+argc];
int i;
for(i = 0; i < cnt; ++i) SetAtom(nlst[i],lst[i]);
if(argv)
for(i = 0; i < argc; ++i) SetAtom(nlst[cnt+i],argv[i]);
if(lst) delete[] lst;
lst = nlst;
cnt += argc;
}
return *this;
}
flext::AtomList &flext::AtomList::Prepend(const t_atom &a)
{
t_atom *nlst = new t_atom[cnt+1];
for(int i = 0; i < cnt; ++i) SetAtom(nlst[i+1],lst[i]);
SetAtom(nlst[0],a);
if(lst) delete[] lst;
lst = nlst;
++cnt;
return *this;
}
flext::AtomList &flext::AtomList::Prepend(int argc,const t_atom *argv)
{
if(argc) {
t_atom *nlst = new t_atom[cnt+argc];
int i;
if(argv)
for(i = 0; i < argc; ++i) SetAtom(nlst[i],argv[i]);
for(i = 0; i < cnt; ++i) SetAtom(nlst[argc+i],lst[i]);
if(lst) delete[] lst;
lst = nlst;
cnt += argc;
}
return *this;
}
flext::AtomList flext::AtomList::GetPart(int offs,int len) const
{
if(offs+len > Count()) {
len = Count()-offs;
if(len < 0) len = 0;
}
return AtomList(len,Atoms()+offs);
}
flext::AtomAnything::AtomAnything(const t_symbol *h,int argc,const t_atom *argv):
......
/*
flext - C++ layer for Max/MSP and pd (pure data) externals
Copyright (c) 2001,2002 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
/*! \file flatom_app.cpp
\brief Definitions for handling the t_atom type and lists thereof.
*/
#include "flext.h"
flext::AtomList &flext::AtomList::Append(const t_atom &a)
{
t_atom *nlst = new t_atom[cnt+1];
for(int i = 0; i < cnt; ++i) SetAtom(nlst[i],lst[i]);
SetAtom(nlst[cnt],a);
if(lst) delete[] lst;
lst = nlst;
++cnt;
return *this;
}
flext::AtomList &flext::AtomList::Append(int argc,const t_atom *argv)
{
if(argc) {
t_atom *nlst = new t_atom[cnt+argc];
int i;
for(i = 0; i < cnt; ++i) SetAtom(nlst[i],lst[i]);
if(argv)
for(i = 0; i < argc; ++i) SetAtom(nlst[cnt+i],argv[i]);
if(lst) delete[] lst;
lst = nlst;
cnt += argc;
}
return *this;
}
flext::AtomList &flext::AtomList::Prepend(const t_atom &a)
{
t_atom *nlst = new t_atom[cnt+1];
for(int i = 0; i < cnt; ++i) SetAtom(nlst[i+1],lst[i]);
SetAtom(nlst[0],a);
if(lst) delete[] lst;
lst = nlst;
++cnt;
return *this;
}
flext::AtomList &flext::AtomList::Prepend(int argc,const t_atom *argv)
{
if(argc) {
t_atom *nlst = new t_atom[cnt+argc];
int i;
if(argv)
for(i = 0; i < argc; ++i) SetAtom(nlst[i],argv[i]);
for(i = 0; i < cnt; ++i) SetAtom(nlst[argc+i],lst[i]);
if(lst) delete[] lst;
lst = nlst;
cnt += argc;
}
return *this;
}
/*
flext - C++ layer for Max/MSP and pd (pure data) externals
Copyright (c) 2001,2002 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
/*! \file flatom_part.cpp
\brief Definitions for handling the t_atom type and lists thereof.
*/
#include "flext.h"
int flext::AtomList::Get(t_atom *argv,int mxsz) const
{
int argc = Count();
if(mxsz >= 0 && argc > mxsz) argc = mxsz;
for(int i = 0; i < argc; ++i) SetAtom(argv[i],lst[i]);
return argc;
}
flext::AtomList flext::AtomList::GetPart(int offs,int len) const
{
if(offs+len > Count()) {
len = Count()-offs;
if(len < 0) len = 0;
}
return AtomList(len,Atoms()+offs);
}
......@@ -21,36 +21,48 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#define STD
#endif
flext_base::attritem::attritem(const t_symbol *t,const t_symbol *gt,metharg tp,methfun gf,methfun sf):
tag(t),gtag(gt),argtp(tp),gfun(gf),sfun(sf),nxt(NULL)
{}
flext_base::attritem::attritem(const t_symbol *t,metharg tp,methfun gf,methfun sf):
item(t),argtp(tp),
gfun(gf),sfun(sf)
// ,nxt(NULL)
{
}
flext_base::attritem::~attritem()
{
if(nxt) delete nxt;
// if(nxt) delete nxt;
}
/*
void flext_base::AddAttrItem(attritem *m)
{
if(attrhead) {
int ix = m->Hash();
post("attr index %x",ix);
attritem *&aix = attrhead[ix];
if(aix) {
attritem *mi;
for(mi = attrhead; mi->nxt; mi = mi->nxt) {}
for(mi = aix; mi->nxt; mi = mi->nxt) {}
mi->nxt = m;
}
else
attrhead = m;
attrcnt++;
aix = m;
// m->th->attrcnt++;
}
*/
//! Add get and set attributes
void flext_base::AddAttrib(const char *attr,metharg tp,methfun gfun,methfun sfun)
{
if(procattr) {
char tmp[256] = "get";
strcpy(tmp+3,attr);
AddAttrItem(new attritem(MakeSymbol(attr),MakeSymbol(tmp),tp,gfun,sfun));
AddMethod(0,attr,(methfun)cb_SetAttrib,a_any,a_null);
AddMethod(0,tmp,(methfun)cb_GetAttrib,a_any,a_null);
AddAttrItem(new attritem(MakeSymbol(attr),tp,gfun,sfun));
if(sfun) AddMethod(0,attr,(methfun)cb_SetAttrib,a_any,a_null); // SET
if(gfun) {
static char tmp[256] = "get";
strcpy(tmp+3,attr);
AddMethod(0,tmp,(methfun)cb_GetAttrib,a_any,a_null); // GET
}
}
else
error("%s - attribute procession is not enabled!",thisName());
......@@ -81,9 +93,13 @@ bool flext_base::InitAttrib(int argc,const t_atom *argv)
bool flext_base::ListAttrib()
{
if(outattr) {
AtomList la(attrcnt);
attritem *a = attrhead;
for(int i = 0; i < attrcnt; ++i,a = a->nxt) SetSymbol(la[i],a->tag);
int cnt = attrhead->Count(),ccnt = clattrhead->Count();
AtomList la(ccnt+cnt);
for(int i = 0,ix = 0; i <= 1; ++i) {
itemarr *a = i?attrhead:clattrhead;
}
ToOutAnything(outattr,MakeSymbol("attributes"),la.Count(),la.Atoms());
return true;
......@@ -94,9 +110,10 @@ bool flext_base::ListAttrib()
bool flext_base::SetAttrib(const t_symbol *tag,int argc,const t_atom *argv)
{
attritem *a = attrhead;
for(; a && a->tag != tag; a = a->nxt) {}
// search for attribute
attritem *a = (attritem *)attrhead->Find(tag);
if(!a) a = (attritem *)clattrhead->Find(tag);
if(a) {
if(a->sfun) {
bool ok = true;
......@@ -149,8 +166,18 @@ bool flext_base::GetAttrib(const t_symbol *tag,int argc,const t_atom *argv)
if(argc)
post("%s - %s: arguments ignored",thisName(),GetString(tag));
attritem *a = attrhead;
for(; a && a->gtag != tag; a = a->nxt) {}
#ifdef FLEXT_DEBUG
if(strncpy(GetString(tag),"get",3)) {
post("%s - %s: tag has no 'get' prefix",thisName(),GetString(tag));
return false;
}
#endif
// main attribute tag
const t_symbol *mtag = MakeSymbol(GetString(tag)+3);
// search for attribute
attritem *a = (attritem *)attrhead->Find(tag);
if(!a) a = (attritem *)clattrhead->Find(tag);
if(a) {
if(a->gfun) {
......@@ -183,13 +210,13 @@ bool flext_base::GetAttrib(const t_symbol *tag,int argc,const t_atom *argv)
default:
ERRINTERNAL();
}
ToOutAnything(outattr,a->tag,la.Count(),la.Atoms());
ToOutAnything(outattr,mtag,la.Count(),la.Atoms());
}
else
post("%s - attribute %s has no set method",thisName(),GetString(tag));
post("%s - attribute %s has no set method",thisName(),GetString(mtag));
}
else
error("%s - %s: attribute not found",thisName(),GetString(tag));
error("%s - %s: attribute not found",thisName(),GetString(mtag));
return true;
}
......@@ -56,6 +56,10 @@ flext_obj :: flext_obj()
flext_obj :: ~flext_obj() {}
bool flext_obj::Init() { return true; }
bool flext_obj::Finalize() { return true; }
void flext_obj::Exit() {}
void flext_obj::DefineHelp(t_class *c,const char *ref,const char *dir,bool addtilde)
{
#if FLEXT_SYS == FLEXT_SYS_PD
......
......@@ -117,10 +117,13 @@ class FLEXT_EXT flext_obj:
//! Virtual function called at creation time (but after the constructor)
// this also guarantees that there are no instances of flext_obj
virtual bool Init() = 0;
virtual bool Init();
//! Virtual function called after Init() has succeeded
virtual bool Finalize();
//! Virtual function called at destruction (before the destructor)
virtual void Exit() {}
virtual void Exit();
//! @} FLEXT_O_CREATION
......
......@@ -77,10 +77,10 @@ public:
virtual void m_help();
//! called on patcher load (not on mere object creation!)
virtual void m_loadbang() {}
virtual void m_loadbang();
//! quickhelp for inlets/outlets (gets called in Max/MSP only)
virtual void m_assist(long /*msg*/,long /*arg*/,char * /*s*/) {}
virtual void m_assist(long /*msg*/,long /*arg*/,char * /*s*/);
/*! \brief Called for every incoming message.
All method handling is done in there
......@@ -411,14 +411,10 @@ protected:
flext_base();
virtual ~flext_base();
// inlets and outlets
/*! \brief Set up inlets and outlets
\ingroup FLEXT_C_INOUT
\return True on successful creation of all inlets and outlets
/*! \brief Set up inlets and outlets, method and attribute lists
*/
virtual bool Init();
virtual bool Finalize();
//! \brief This represents either an inlet or outlet
struct xlet {
......@@ -483,34 +479,62 @@ protected:
// method handling
class item {
public:
item(const t_symbol *t,int inl = 0);
~item();
bool operator <(const item &it) const { return inlet == it.inlet?tag < it.tag:inlet < it.inlet; }
const t_symbol *tag;
int inlet;
item *nxt;
};
class itemarr {
public:
itemarr();
~itemarr();
void Add(item *it);
item *Find(const t_symbol *tag,int inlet = 0) const;
void Finalize();
bool Ready() const { return bits >= 0; }
int Count() const { return cnt; }
protected:
int Size() const { return bits?1<<bits:0; }
static int Hash(const t_symbol *,int inlet,int bits);
item **arr;
int cnt,bits;
};
//! \brief This represents an item of the method list
class methitem {
class methitem:
public item {
public:
methitem(int inlet,const t_symbol *t);
methitem(int inlet,const t_symbol *tg);
~methitem();
void SetArgs(methfun fun,int argc,metharg *args);
const t_symbol *tag;
int inlet;
int argc;
metharg *args;
methfun fun;
methitem *nxt;
};
//! \brief This represents an item of the attribute list
class attritem {
class attritem:
public item {
public:
attritem(const t_symbol *tag,const t_symbol *gtag,metharg tp,methfun gfun,methfun sfun);
attritem(const t_symbol *tag,metharg tp,methfun gfun,methfun sfun);
~attritem();
const t_symbol *tag,*gtag;
metharg argtp;
methfun gfun,sfun;
attritem *nxt;
methfun gfun,sfun;
};
//! @} FLEXT_CLASS
......@@ -546,13 +570,23 @@ private:
typedef bool (*methfun_3)(flext_base *c,t_any &,t_any &,t_any &);
typedef bool (*methfun_4)(flext_base *c,t_any &,t_any &,t_any &,t_any &);
typedef bool (*methfun_5)(flext_base *c,t_any &,t_any &,t_any &,t_any &,t_any &);
itemarr *GetClassArr(int ix) const;
itemarr *methhead,*clmethhead;
void AddMethItem(methitem *m) { methhead->Add(m); }
void AddClMethItem(methitem *m) { clmethhead->Add(m); }
methitem *methhead;
void AddMethItem(methitem *m);
bool CallMeth(const methitem &m,int argc,const t_atom *argv);
bool FindMeth(int inlet,const t_symbol *s,int argc,const t_atom *argv);
bool TryMethTag(const methitem *m,int inlet,const t_symbol *t,int argc,const t_atom *argv);
bool TryMethSym(const methitem *m,int inlet,const t_symbol *t,const t_symbol *s);
bool TryMethAny(const methitem *m,int inlet,const t_symbol *t,const t_symbol *s,int argc,const t_atom *argv);
attritem *attrhead;
int attrcnt;
void AddAttrItem(attritem *m);
itemarr *attrhead,*clattrhead;
// int attrcnt;
void AddAttrItem(attritem *m) { attrhead->Add(m); }
void AddClAttrItem(attritem *m) { clattrhead->Add(m); }
void AddAttrib(const char *attr,metharg tp,methfun gfun,methfun sfun);
......@@ -567,7 +601,6 @@ private:
static bool cb_GetAttrib(flext_base *c,const t_symbol *s,int argc,const t_atom *argv) { return c->GetAttrib(s,argc,argv); }
static bool cb_SetAttrib(flext_base *c,const t_symbol *s,int argc,const t_atom *argv) { return c->SetAttrib(s,argc,argv); }
// queue stuff
class qmsg;
......@@ -616,6 +649,11 @@ private:
px_object **inlets;
static void SetProxies(t_class *c);
bool InitInlets();
bool InitOutlets();
// callback functions
static void cb_help(t_class *c);
......
......@@ -14,104 +14,6 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "flext.h"
#include "flinternal.h"
#include <string.h>
#include <stdarg.h>
// === proxy class for flext_base ============================
#if FLEXT_SYS == FLEXT_SYS_PD
static t_class *px_class;
struct flext_base::px_object // no virtual table!
{
t_object obj; // MUST reside at memory offset 0
flext_base *base;
int index;
void init(flext_base *b,int ix) { base = b; index = ix; }
static void px_method(px_object *c,const t_symbol *s,int argc,t_atom *argv);
};
void flext_base::px_object::px_method(px_object *obj,const t_symbol *s,int argc,t_atom *argv)
{
obj->base->m_methodmain(obj->index,s,argc,argv);
}
void flext_base::cb_px_anything(t_class *c,const t_symbol *s,int argc,t_atom *argv)
{
thisObject(c)->m_methodmain(0,s,argc,argv);
}
#define DEF_IN_FT(IX) \
void flext_base::cb_px_ft ## IX(t_class *c,float v) { \
t_atom atom; SETFLOAT(&atom,v); \
thisObject(c)->m_methodmain(IX,&s_float,1,&atom); \
}
#define ADD_IN_FT(IX) \
add_method1(c,cb_px_ft ## IX,"ft" #IX,A_FLOAT)
#elif FLEXT_SYS == FLEXT_SYS_MAX
void flext_base::cb_px_anything(t_class *c,const t_symbol *s,int argc,t_atom *argv)
{
// check if inlet allows anything (or list)
flext_base *o = thisObject(c);
int ci = ((flext_hdr *)o->x_obj)->curinlet;
o->m_methodmain(ci,s,argc,argv);
}
void flext_base::cb_px_int(t_class *c,int v)
{
// check if inlet allows int type
t_atom atom;
SetInt(atom,v);
cb_px_anything(c,sym_int,1,&atom);
}
void flext_base::cb_px_float(t_class *c,float v)
{
// check if inlet allows float type
t_atom atom;
SetFloat(atom,v);
cb_px_anything(c,sym_float,1,&atom);
}
void flext_base::cb_px_bang(t_class *c)
{
// check if inlet allows bang
cb_px_anything(c,sym_bang,0,NULL);
}
#define DEF_IN_FT(IX) \
void flext_base::cb_px_in ## IX(t_class *c,int v) { long &ci = ((flext_hdr *)thisObject(c)->x_obj)->curinlet; ci = IX; cb_px_int(c,v); ci = 0; } \
void flext_base::cb_px_ft ## IX(t_class *c,float v) { long &ci = ((flext_hdr *)thisObject(c)->x_obj)->curinlet; ci = IX; cb_px_float(c,v); ci = 0; }
#define ADD_IN_FT(IX) \
add_method1(c,cb_px_in ## IX,"in" #IX,A_INT); \
add_method1(c,cb_px_ft ## IX,"ft" #IX,A_FLOAT)
#else