Commit d5688248 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@321 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 525afdd2
......@@ -196,10 +196,6 @@ SOURCE=.\source\flmspbuffer.h
# End Source File
# Begin Source File
SOURCE=.\source\flsetup.cpp
# End Source File
# Begin Source File
SOURCE=.\source\flsndobj.cpp
# End Source File
# Begin Source File
......
......@@ -180,24 +180,13 @@ class FLEXT_EXT flext_obj:
//! Definitions for library objects
static void lib_init(const char *name,void setupfun());
static void obj_add(bool lib,bool dsp,const char *name,void setupfun(t_class *),flext_obj *(*newfun)(int,t_atom *),void (*freefun)(flext_hdr *),int argtp1,...);
static void obj_add(bool lib,bool dsp,const char *idname,const char *names,void setupfun(t_class *),flext_obj *(*newfun)(int,t_atom *),void (*freefun)(flext_hdr *),int argtp1,...);
static flext_hdr *obj_new(const t_symbol *s,int argc,t_atom *argv);
static void obj_free(flext_hdr *o);
//@}
};
//@{
//! Some utility functions for class setup
namespace flext_util {
const char *extract(const char *name,int ix = 0);
char *strdup(const char *name);
bool chktilde(const char *name);
}
//@}
// max. 4 creation args (see the following macros)
#define FLEXT_MAXNEWARGS 4
......@@ -329,7 +318,7 @@ flext_obj *NEW_CLASS::__init__(int argc,t_atom *argv) \
} \
FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
flext_obj::obj_add(LIB,DSP,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,&NEW_CLASS::__free__,A_NULL); \
flext_obj::obj_add(LIB,DSP,#NEW_CLASS,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,&NEW_CLASS::__free__,A_NULL); \
}
#define REAL_NEW_V(NAME,NEW_CLASS,DSP,LIB) \
......@@ -340,7 +329,7 @@ flext_obj *NEW_CLASS::__init__(int argc,t_atom *argv) \
} \
FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
flext_obj::obj_add(LIB,DSP,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,&NEW_CLASS::__free__,A_GIMME,A_NULL); \
flext_obj::obj_add(LIB,DSP,#NEW_CLASS,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,&NEW_CLASS::__free__,A_GIMME,A_NULL); \
}
#define REAL_NEW_1(NAME,NEW_CLASS,DSP,LIB, TYPE1) \
......@@ -351,7 +340,7 @@ flext_obj *NEW_CLASS::__init__(int argc,t_atom *argv) \
} \
FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
flext_obj::obj_add(LIB,DSP,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,NEW_CLASS::__free__,FLEXTTP(TYPE1),A_NULL); \
flext_obj::obj_add(LIB,DSP,#NEW_CLASS,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,NEW_CLASS::__free__,FLEXTTP(TYPE1),A_NULL); \
}
#define REAL_NEW_2(NAME,NEW_CLASS,DSP,LIB, TYPE1,TYPE2) \
......@@ -362,7 +351,7 @@ flext_obj *NEW_CLASS::__init__(int argc,t_atom *argv) \
} \
FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
flext_obj::obj_add(LIB,DSP,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,NEW_CLASS::__free__,FLEXTTP(TYPE1),FLEXTTP(TYPE2),A_NULL); \
flext_obj::obj_add(LIB,DSP,#NEW_CLASS,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,NEW_CLASS::__free__,FLEXTTP(TYPE1),FLEXTTP(TYPE2),A_NULL); \
}
#define REAL_NEW_3(NAME,NEW_CLASS,DSP,LIB, TYPE1, TYPE2, TYPE3) \
......@@ -373,7 +362,7 @@ flext_obj *NEW_CLASS::__init__(int argc,t_atom *argv) \
} \
FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
flext_obj::obj_add(LIB,DSP,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,NEW_CLASS::__free__,FLEXTTP(TYPE1),FLEXTTP(TYPE2),FLEXTTP(TYPE3),A_NULL); \
flext_obj::obj_add(LIB,DSP,#NEW_CLASS,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,NEW_CLASS::__free__,FLEXTTP(TYPE1),FLEXTTP(TYPE2),FLEXTTP(TYPE3),A_NULL); \
}
#define REAL_NEW_4(NAME,NEW_CLASS,DSP,LIB, TYPE1,TYPE2, TYPE3, TYPE4) \
......@@ -384,7 +373,7 @@ flext_obj *NEW_CLASS::__init__(int argc,t_atom *argv) \
} \
FLEXT_EXP(LIB) void FLEXT_STPF(NEW_CLASS,DSP)() \
{ \
flext_obj::obj_add(LIB,DSP,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,NEW_CLASS::__free__,FLEXTTP(TYPE1),FLEXTTP(TYPE2),FLEXTTP(TYPE3),FLEXTTP(TYPE4),A_NULL); \
flext_obj::obj_add(LIB,DSP,#NEW_CLASS,NAME,NEW_CLASS::__setup__,NEW_CLASS::__init__,NEW_CLASS::__free__,FLEXTTP(TYPE1),FLEXTTP(TYPE2),FLEXTTP(TYPE3),FLEXTTP(TYPE4),A_NULL); \
}
......
......@@ -143,9 +143,13 @@ public:
//! Add outlet(s) for lists
void AddOutList(int m = 1) { AddOutlet(xlet::tp_list,m); }
void AddOutList(const char *desc,int m = 1) { AddOutlet(xlet::tp_list,m,desc); }
//! Add outlet(s) for attribute dump
void AddOutAttr();
/*! \brief Set up inlets and outlets
\remark Must be called ONCE to actually set up the defined inlets/outlets.
\param attr Set to false to inhibit procession of attributes (default = true)
\return True on successful creation of all inlets and outlets
*/
bool SetupInOut();
......@@ -342,12 +346,19 @@ protected:
flext_base();
virtual ~flext_base();
// attributes
//! Flag for attribute procession
bool procattr;
// inlets and outlets
struct xlet {
enum type {
tp_none = 0,
tp_float,tp_int,tp_sym,tp_list,tp_sig,tp_any
tp_float,tp_int,tp_sym,tp_list,tp_any,
tp_sig,
tp_attr
};
xlet(type t,const char *desc = NULL);
......@@ -358,6 +369,19 @@ protected:
xlet *nxt;
};
/*! \addtogroup FLEXT_C_ATTR
@{
*/
void AddAttrib(const char *attr,xlet::type tp,void (*set)(flext_obj &,float),void (*dump)(flext_obj &));
void AddAttrib(const char *attr,xlet::type tp,void (*set)(flext_obj &,int),void (*dump)(flext_obj &));
void AddAttrib(const char *attr,xlet::type tp,void (*set)(flext_obj &,const t_symbol *),void (*dump)(flext_obj &));
void AddAttrib(const char *attr,xlet::type tp,void (*set)(flext_obj &,const AtomList &),void (*dump)(flext_obj &));
void AddAttrib(const char *attr,xlet::type tp,void (*set)(flext_obj &,const AtomAnything &),void (*dump)(flext_obj &));
//! @}
/*! \addtogroup FLEXT_C_INOUT
@{
......
......@@ -73,6 +73,12 @@ t_int *flext_dsp::dspmeth(t_int *w)
void flext_dsp::m_dsp(int /*n*/,t_sample *const * /*insigs*/,t_sample *const * /*outsigs*/) {}
void flext_dsp::m_signal(int n,t_sample *const * /*insigs*/,t_sample *const *outsigs)
{
for(int i = 0; i < CntOutSig(); ++i)
memset(outsigs[i],0,n*sizeof(*outsigs[i]));
}
void flext_dsp::cb_dsp(t_class *c,t_signal **sp)
{
flext_dsp *obj = thisObject(c);
......
......@@ -76,7 +76,7 @@ public:
\param insigs: array of input vectors (get number with function CntInSig())
\param outsigs: array of output vectors (get number with function CntOutSig())
*/
virtual void m_signal(int n,t_sample *const *insigs,t_sample *const *outsigs) = 0;
virtual void m_signal(int n,t_sample *const *insigs,t_sample *const *outsigs);
#ifndef MAXMSP
/*! \brief called with "enable" message: pauses/resumes dsp
......
......@@ -123,6 +123,7 @@ flext_base::flext_base():
incnt(0),outcnt(0),
insigs(0),outsigs(0),
outlets(NULL),inlets(NULL),
procattr(true),
mlst(NULL),
distmsgs(false)
{
......
......@@ -14,6 +14,82 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "flsupport.h"
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#define ALIASDEL ','
#define ALIASSLASHES ":/\\"
#ifdef MAXMSP
#define ALIASSLASH ':'
#elif defined(NT)
#define ALIASSLASH '/'
#else
#define ALIASSLASH '/'
#endif
//! Extract space-delimited words from a string
static const char *extract(const char *name,int ix = 0)
{
static char tmp[1024];
const char *n = name;
const char *del = strchr(name,ALIASDEL);
if(del) {
if(ix < 0) {
char *t = tmp;
while(n < del && (isspace(*n) || strchr(ALIASSLASHES,*n))) ++n;
while(n < del && !isspace(*n)) {
char c = *(n++);
*(t++) = strchr(ALIASSLASHES,c)?ALIASSLASH:c;
}
while(*t == ALIASSLASH && t > tmp) --t;
*t = 0;
return tmp;
}
n = del+1;
}
while(*n && isspace(*n)) ++n;
for(int i = 0; n && *n; ++i) {
if(i == ix) {
char *t = tmp;
for(; *n && !isspace(*n); ++t,++n) *t = *n;
*t = 0;
return *tmp?tmp:NULL;
}
else {
while(*n && !isspace(*n)) ++n;
while(*n && isspace(*n)) ++n;
}
}
return NULL;
}
//! Check if object's name ends with a tilde
static bool chktilde(const char *objname)
{
// int stplen = strlen(setupfun);
bool tilde = true; //!strncmp(setupfun,"_tilde",6);
if((objname[strlen(objname)-1] == '~'?1:0)^(tilde?1:0)) {
if(tilde)
error("flext: %s (no trailing ~) is defined as a tilde object",objname);
else
error("flext::check_tilde: %s is no tilde object",objname);
return true;
}
else
return false;
}
// this class stands for one registered object
......@@ -90,16 +166,18 @@ void flext_obj::lib_init(const char *name,void setupfun())
setupfun();
}
void flext_obj::obj_add(bool lib,bool dsp,const char *name,void setupfun(t_class *),flext_obj *(*newfun)(int,t_atom *),void (*freefun)(flext_hdr *),int argtp1,...)
void flext_obj::obj_add(bool lib,bool dsp,const char *idname,const char *names,void setupfun(t_class *),flext_obj *(*newfun)(int,t_atom *),void (*freefun)(flext_hdr *),int argtp1,...)
{
if(dsp) flext_util::chktilde(name);
#ifdef _DEBUG
if(dsp) chktilde(idname);
#endif
t_class **cl =
#ifdef MAXMSP
lib?&lib_class:
#endif
new t_class *;
const t_symbol *nsym = MakeSymbol(flext_util::extract(name));
const t_symbol *nsym = MakeSymbol(extract(names));
// register object class
#ifdef PD
......@@ -145,12 +223,12 @@ void flext_obj::obj_add(bool lib,bool dsp,const char *name,void setupfun(t_class
}
// make help reference
flext_obj::DefineHelp(lo->clss,GetString(nsym),flext_util::extract(name,-1),dsp);
flext_obj::DefineHelp(lo->clss,idname,extract(names,-1),dsp);
for(int ix = 0; ; ++ix) {
// in this loop register all the possible aliases of the object
const char *c = ix?flext_util::extract(name,ix):GetString(nsym);
const char *c = ix?extract(names,ix):GetString(nsym);
if(!c || !*c) break;
// add to name list
......@@ -270,12 +348,13 @@ void flext_obj::obj_free(flext_hdr *hdr)
const t_symbol *name = hdr->data->thisNameSym();
libname *l = libname::find(name);
if(l)
if(l) {
// call virtual exit function
hdr->data->Exit();
// now call object destructor and deallocate
l->obj->freefun(hdr);
}
#ifdef _DEBUG
else
#ifdef MAXMSP
......
/*
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 flsetup.cpp
\brief Implementation of helper functions for object setup.
*/
#include "flext.h"
#include <ctype.h>
#include <string.h>
#define ALIASDEL ','
#define ALIASSLASHES ":/\\"
#ifdef MAXMSP
#define ALIASSLASH ':'
#elif defined(NT)
#define ALIASSLASH '/'
#else
#define ALIASSLASH '/'
#endif
//! C++ strdup function
char *flext_util::strdup(const char *t)
{
if(!t) return NULL;
int len = strlen(t);
char *r = new char[len+1];
memcpy(r,t,len+1);
return r;
}
//! Extract space-delimited words from a string
const char *flext_util::extract(const char *name,int ix)
{
static char tmp[1024];
const char *n = name;
const char *del = strchr(name,ALIASDEL);
if(del) {
if(ix < 0) {
char *t = tmp;
while(n < del && (isspace(*n) || strchr(ALIASSLASHES,*n))) ++n;
while(n < del && !isspace(*n)) {
char c = *(n++);
*(t++) = strchr(ALIASSLASHES,c)?ALIASSLASH:c;
}
while(*t == ALIASSLASH && t > tmp) --t;
*t = 0;
return tmp;
}
n = del+1;
}
while(*n && isspace(*n)) ++n;
for(int i = 0; n && *n; ++i) {
if(i == ix) {
char *t = tmp;
for(; *n && !isspace(*n); ++t,++n) *t = *n;
*t = 0;
return *tmp?tmp:NULL;
}
else {
while(*n && !isspace(*n)) ++n;
while(*n && isspace(*n)) ++n;
}
}
return NULL;
}
//! Check if object's name ends with a tilde
bool flext_util::chktilde(const char *objname)
{
// int stplen = strlen(setupfun);
bool tilde = true; //!strncmp(setupfun,"_tilde",6);
if((objname[strlen(objname)-1] == '~'?1:0)^(tilde?1:0)) {
if(tilde)
error("flext: %s (no trailing ~) is defined as a tilde object",objname);
else
error("flext::check_tilde: %s is no tilde object",objname);
return true;
}
else
return false;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment