Commit 2cf686e6 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@16 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 0768c0ea
......@@ -14,7 +14,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#define DIRTY_INTERVAL 0 // buffer dirty check in msec
#endif
buffer::buffer(t_symbol *bn):
ext_obj::buffer::buffer(t_symbol *bn):
sym(NULL),data(NULL),
chns(0),frames(0)
{
......@@ -28,14 +28,14 @@ buffer::buffer(t_symbol *bn):
if(bn) Set(bn);
}
buffer::~buffer()
ext_obj::buffer::~buffer()
{
#ifdef PD
clock_free(tick);
#endif
}
I buffer::Set(t_symbol *s)
I ext_obj::buffer::Set(t_symbol *s)
{
I ret = 0;
......@@ -102,7 +102,7 @@ I buffer::Set(t_symbol *s)
return ret;
}
V buffer::Dirty(BL force)
V ext_obj::buffer::Dirty(BL force)
{
if(sym) {
#ifdef PD
......@@ -131,7 +131,7 @@ V buffer::Dirty(BL force)
}
#ifdef PD
V buffer::cb_tick(buffer *b)
V ext_obj::buffer::cb_tick(buffer *b)
{
t_garray *a = (t_garray *)pd_findbyclass(b->sym, garray_class);
if (a) garray_redraw(a);
......
......@@ -12,6 +12,162 @@ WARRANTIES, see the file, "license.txt," in this distribution.
// -- ext_obj --------------------------
ext_obj::ext_obj():
inlist(NULL),outlist(NULL),
out(NULL),outcnt(0)
{}
ext_obj::~ext_obj()
{
if(inlist) delete inlist;
if(outlist) delete outlist;
if(out) delete[] out;
}
ext_obj::xlet::~xlet() { if(nxt) delete nxt; }
V ext_obj::AddXlet(xlet::type tp,I mult,xlet *&root)
{
if(!root && mult) { root = new xlet(tp); --mult; }
if(mult) {
xlet *xi = root;
while(xi->nxt) xi = xi->nxt;
while(mult--) xi = xi->nxt = new xlet(tp);
}
}
BL ext_obj::SetupInOut()
{
BL ok = true;
if(inlist) {
xlet *xi;
I i,cnt = 0;
for(xi = inlist; xi; xi = xi->nxt) ++cnt;
xlet::type *list = new xlet::type[cnt];
for(xi = inlist,i = 0; xi; xi = xi->nxt,++i) list[i] = xi->tp;
delete inlist; inlist = NULL;
// type info is now in list array
#ifdef PD
{
I ix;
if(cnt == 0) {;}
else if(cnt >= 1) {
switch(list[0].tp) {
case xlet::tp_def:
break;
case xlet::tp_sig:
break;
default:
error("%s: Leftmost inlet must be of type signal or default",thisName());
ok = false;
}
}
for(ix = 1; ix < cnt; ++ix) {
switch(list[ix].tp) {
case xlet::tp_float:
case xlet::tp_flint: {
const sym[] = "ft?";
sym[2] = ix; // what if ix > 9????
inlet_new(x_obj, &x_obj->ob_pd, &s_float, gensym(sym));
break;
}
case xlet::tp_sig:
inlet_new(x_obj, &x_obj->ob_pd, &s_signal, &s_signal);
break;
default:
error("%s: Wrong type for inlet #%i",thisName(),ix);
ok = false;
}
}
}
#elif defined(MAXMSP)
{
I ix,sigs = 0;
// count leftmost signal inlets
while(sigs < cnt && list[sigs] == xlet::tp_sig) ++sigs;
for(ix = cnt-1; ix >= sigs; --ix) {
switch(list[ix]) {
case xlet::tp_float:
floatin(x_obj,ix);
break;
case xlet::tp_flint:
intin(x_obj,ix);
break;
case xlet::tp_sig:
error("%s: Signal inlets must be at the left side",thisName());
ok = false;
break;
default:
error("%s: Wrong type for inlet #%i",thisName(),ix);
ok = false;
}
}
if(sigs) {
dsp_setup(x_obj,sigs); // signal inlets
}
else {
if(cnt && list[0] != xlet::tp_def) {
error("%s: Leftmost inlet must be of type signal or default",thisName());
ok = false;
}
}
}
#endif
delete[] list;
}
if(out) { delete[] out; out = NULL; outcnt = 0; }
if(outlist) {
xlet *xi;
outcnt = 0;
for(xi = outlist; xi; xi = xi->nxt) ++outcnt;
xlet::type *list = new xlet::type[outcnt];
I i;
for(xi = outlist,i = 0; xi; xi = xi->nxt,++i) list[i] = xi->tp;
delete outlist; outlist = NULL;
out = new t_outlet *[outcnt];
// type info is now in list array
#ifdef PD
for(I ix = 0; ix < outcnt; ++ix)
#elif defined(MAXMSP)
for(I ix = outcnt-1; ix >= 0; --ix)
#endif
{
switch(list[ix]) {
case xlet::tp_float:
case xlet::tp_flint:
out[ix] = newout_float(x_obj);
break;
case xlet::tp_sig:
out[ix] = newout_signal(x_obj);
break;
case xlet::tp_sym:
out[ix] = newout_symbol(x_obj);
break;
case xlet::tp_list:
out[ix] = newout_list(x_obj);
break;
default:
error("%s: Wrong type for outlet #%i",thisName(),ix);
ok = false;
}
}
delete[] list;
}
return ok;
}
V ext_obj::cb_setup(t_class *c)
{
add_method0(c,cb_help,"help");
......
......@@ -22,8 +22,8 @@ class ext_obj:
CPPEXTERN_HEADER(ext_obj,CPPExtern)
public:
// ext_obj();
// virtual ~ext_obj();
ext_obj();
virtual ~ext_obj();
virtual V m_help();
......@@ -32,9 +32,81 @@ public:
virtual V m_assist(L msg,L arg,C *s) = 0;
#endif
class buffer
{
public:
buffer(t_symbol *s = NULL);
~buffer();
I Set(t_symbol *s = NULL);
V Dirty(BL force = false);
t_symbol *Symbol() { return sym; }
const C *Name() const { return sym?sym->s_name:""; }
F *Data() { return data; }
I Channels() const { return chns; }
I Frames() const { return frames; }
#ifdef PD
V SetRefrIntv(F intv) { interval = intv; }
#else
V SetRefrIntv(F) {}
#endif
protected:
const C *thisName() const { return typeid(*this).name(); }
t_symbol *sym;
F *data;
I chns,frames;
#ifdef PD
F interval;
BL isdirty,ticking;
t_clock *tick;
#endif
private:
static V cb_tick(buffer *b);
};
protected:
V Inlet_def() { AddInlet(xlet::tp_def,1); }
V Inlet_float(I m = 1) { AddInlet(xlet::tp_float,m); }
V Inlet_flint(I m = 1) { AddInlet(xlet::tp_flint,m); }
V Inlet_signal(I m = 1) { AddInlet(xlet::tp_sig,m); }
V Outlet_float(I m = 1) { AddOutlet(xlet::tp_float,m); }
V Outlet_flint(I m = 1) { AddOutlet(xlet::tp_flint,m); }
V Outlet_sym(I m = 1) { AddOutlet(xlet::tp_sym,m); }
V Outlet_list(I m = 1) { AddOutlet(xlet::tp_list,m); }
V Outlet_signal(I m = 1) { AddOutlet(xlet::tp_sig,m); }
BL SetupInOut();
t_outlet *Outlet(I ix) { return (out && ix < outcnt)?out[ix]:NULL; }
private:
struct xlet {
enum type {
tp_none = 0,tp_def,tp_float,tp_flint,tp_sym,tp_list,tp_sig
};
xlet(type t): tp(t),nxt(NULL) {}
~xlet();
type tp;
xlet *nxt;
} *inlist,*outlist;
I outcnt;
t_outlet **out;
V AddXlet(xlet::type tp,I mult,xlet *&root);
V AddInlet(xlet::type tp,I mult) { AddXlet(tp,mult,inlist); }
V AddOutlet(xlet::type tp,I mult) { AddXlet(tp,mult,outlist); }
static V cb_help(V *c);
#ifdef MAXMSP
......@@ -46,38 +118,6 @@ private:
// ----------------------------
class buffer
{
public:
buffer(t_symbol *s = NULL);
~buffer();
I Set(t_symbol *s = NULL);
V Dirty(BL force = false);
t_symbol *Symbol() { return sym; }
const C *Name() const { return sym?sym->s_name:""; }
F *Data() { return data; }
I Channels() const { return chns; }
I Frames() const { return frames; }
V SetRefrIntv(F intv) { interval = intv; }
protected:
const C *thisName() const { return typeid(*this).name(); }
t_symbol *sym;
F *data;
I chns,frames;
#ifdef PD
F interval;
BL isdirty,ticking;
t_clock *tick;
#endif
private:
static V cb_tick(buffer *b);
};
// ----------------------------
......
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