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/flatom.cpp13
-rw-r--r--externals/grill/flext/source/flatom_pr.cpp16
-rw-r--r--externals/grill/flext/source/flattr.cpp96
-rw-r--r--externals/grill/flext/source/flattr_ed.cpp2
-rw-r--r--externals/grill/flext/source/flclass.h36
-rwxr-xr-xexternals/grill/flext/source/flmsg.cpp2
-rw-r--r--externals/grill/flext/source/flsupport.h5
7 files changed, 146 insertions, 24 deletions
diff --git a/externals/grill/flext/source/flatom.cpp b/externals/grill/flext/source/flatom.cpp
index 45739e66..afed8dec 100644
--- a/externals/grill/flext/source/flatom.cpp
+++ b/externals/grill/flext/source/flatom.cpp
@@ -91,6 +91,19 @@ int flext::AtomList::Compare(const AtomList &a) const
return Count() < a.Count()?-1:1;
}
+std::string flext::AtomList::Print() const
+{
+ char buffer[256];
+ std::string ret;
+ for(int i = 0; i < Count(); ++i) {
+ char *b = buffer;
+ if(i) *(b++) = ' '; // prepend space
+ PrintAtom((*this)[i],b,sizeof buffer-1);
+ ret += buffer;
+ }
+ return ret;
+}
+
#if FLEXT_SYS != FLEXT_SYS_JMAX
// not for jmax as long as t_symbol * == char *
diff --git a/externals/grill/flext/source/flatom_pr.cpp b/externals/grill/flext/source/flatom_pr.cpp
index e4989320..639bca63 100644
--- a/externals/grill/flext/source/flatom_pr.cpp
+++ b/externals/grill/flext/source/flatom_pr.cpp
@@ -18,9 +18,23 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <string.h>
#include <stdio.h>
+// \TODO take bufsz into account!
void flext::PrintAtom(const t_atom &a,char *buf,int bufsz)
{
- GetAString(a,buf,bufsz?bufsz:100000);
+ if(IsFloat(a)) {
+ sprintf(buf,"%g",GetFloat(a));
+ }
+ else if(IsInt(a)) {
+ sprintf(buf,"%i",GetInt(a));
+ }
+ else if(IsSymbol(a)) {
+ strcpy(buf,GetString(a));
+ }
+ else if(IsPointer(a)) {
+ sprintf(buf,"%p",GetPointer(a));
+ }
+ else
+ ERRINTERNAL();
}
bool flext::ScanAtom(t_atom &a,const char *buf)
diff --git a/externals/grill/flext/source/flattr.cpp b/externals/grill/flext/source/flattr.cpp
index 40c811de..e754c87b 100644
--- a/externals/grill/flext/source/flattr.cpp
+++ b/externals/grill/flext/source/flattr.cpp
@@ -26,7 +26,8 @@ WARRANTIES, see the file, "license.txt," in this distribution.
flext_base::AttrItem::AttrItem(const t_symbol *t,metharg tp,methfun f,int fl):
Item(t,0,NULL),index(0),
- flags(fl),argtp(tp),fun(f)
+ flags(fl|afl_shown),counter(NULL),
+ argtp(tp),fun(f)
{}
flext_base::AttrItem::~AttrItem()
@@ -39,10 +40,11 @@ flext_base::AttrItem::~AttrItem()
void flext_base::AddAttrib(ItemCont *aa,ItemCont *ma,const char *attr,metharg tp,methfun gfun,methfun sfun)
{
const t_symbol *asym = MakeSymbol(attr);
+ AttrItem *a,*b;
if(sfun) // if commented out, there will be a warning at run-time (more user-friendly)
{
- AttrItem *a = new AttrItem(asym,tp,sfun,AttrItem::afl_bothexist|AttrItem::afl_set);
+ a = new AttrItem(asym,tp,sfun,AttrItem::afl_set);
// set index of item to the next higher value
AttrItem *last = (AttrItem *)aa->Last();
@@ -55,25 +57,34 @@ void flext_base::AddAttrib(ItemCont *aa,ItemCont *ma,const char *attr,metharg tp
mi->SetArgs(sfun,1,new metharg(tp));
ma->Add(mi);
}
+ else
+ a = NULL;
if(gfun) // if commented out, there will be a warning at run-time (more user-friendly)
{
- AttrItem *a = new AttrItem(asym,tp,gfun,AttrItem::afl_bothexist|AttrItem::afl_get);
+ b = new AttrItem(asym,tp,gfun,AttrItem::afl_get);
// set index of item to the next higher value
AttrItem *last = (AttrItem *)aa->Last();
- if(last) a->index = last->index+1;
+ if(last) b->index = last->index+1;
- aa->Add(a);
+ aa->Add(b);
static char tmp[256] = "get";
strcpy(tmp+3,attr);
// bind attribute to a method
- MethItem *mi = new MethItem(0,MakeSymbol(tmp),a);
+ MethItem *mi = new MethItem(0,MakeSymbol(tmp),b);
mi->SetArgs(gfun,0,NULL);
ma->Add(mi);
}
+ else
+ b = NULL;
+
+ if(a && b) {
+ a->counter = b;
+ b->counter = a;
+ }
}
void flext_base::AddAttrib(const char *attr,metharg tp,methfun gfun,methfun sfun)
@@ -300,7 +311,13 @@ bool flext_base::GetAttrib(AttrItem *a,AtomList &la) const
return ok;
}
-bool flext_base::GetAttrib(AttrItem *a)
+bool flext_base::GetAttrib(const t_symbol *s,AtomList &a) const
+{
+ AttrItem *attr = FindAttrib(s,true);
+ return attr && GetAttrib(attr,a);
+}
+
+bool flext_base::DumpAttrib(AttrItem *a) const
{
AtomList la;
bool ret = GetAttrib(a,la);
@@ -308,15 +325,70 @@ bool flext_base::GetAttrib(AttrItem *a)
return ret;
}
-bool flext_base::GetAttrib(const t_symbol *s,AtomList &a) const
+bool flext_base::DumpAttrib(const t_symbol *attr) const
{
- AttrItem *attr = FindAttrib(s,true);
- return attr && GetAttrib(attr,a);
+ AttrItem *item = FindAttrib(attr,true);
+ return item && DumpAttrib(item);
}
+bool flext_base::BangAttrib(AttrItem *item)
+{
+ AtomList val;
+ AttrItem *item2;
+ if(!item->IsGet())
+ item = item->Counterpart();
+ if(item) {
+ item2 = item->Counterpart();
+ return item2 && GetAttrib(item,val) && SetAttrib(item2,val);
+ }
+ else
+ return false;
+}
-bool flext_base::DumpAttrib(const t_symbol *attr) const
+bool flext_base::BangAttrib(const t_symbol *attr)
+{
+ AttrItem *item = FindAttrib(attr,true);
+ return item && BangAttrib(item);
+}
+
+bool flext_base::BangAttribAll()
+{
+ int i,cnt = clattrhead->Ready()?clattrhead->Size():2;
+ for(i = 0; i < cnt; ++i) {
+ AttrItem *a = (AttrItem *)clattrhead->GetItem(i);
+ for(; a; a = (AttrItem *)a->nxt) {
+ if(a->IsGet() && a->BothExist())
+ BangAttrib(a);
+ }
+ }
+
+ cnt = attrhead->Ready()?attrhead->Size():2;
+ for(i = 0; i < cnt; ++i) {
+ AttrItem *a = (AttrItem *)attrhead->GetItem(i);
+ for(; a; a = (AttrItem *)a->nxt) {
+ if(a->IsGet() && a->BothExist())
+ BangAttrib(a);
+ }
+ }
+ return true;
+}
+
+bool flext_base::ShowAttrib(AttrItem *a,bool show) const
+{
+ if(show) a->flags |= AttrItem::afl_shown;
+ else a->flags &= ~AttrItem::afl_shown;
+
+ // also change counterpart, if present
+ AttrItem *ca = a->Counterpart();
+ if(ca) {
+ if(show) ca->flags |= AttrItem::afl_shown;
+ else ca->flags &= ~AttrItem::afl_shown;
+ }
+ return true;
+}
+
+bool flext_base::ShowAttrib(const t_symbol *attr,bool show) const
{
AttrItem *item = FindAttrib(attr,true);
- return item && const_cast<flext_base *>(this)->GetAttrib(item);
+ return item && ShowAttrib(item,show);
}
diff --git a/externals/grill/flext/source/flattr_ed.cpp b/externals/grill/flext/source/flattr_ed.cpp
index 8a5f6c7d..0722ea10 100644
--- a/externals/grill/flext/source/flattr_ed.cpp
+++ b/externals/grill/flext/source/flattr_ed.cpp
@@ -328,7 +328,7 @@ void flext_base::cb_GfxProperties(t_gobj *c, t_glist *)
STD::sprintf(b, "} {"); b += strlen(b);
// get puttable attribute
- AttrItem *pattr = th->FindAttrib(GetSymbol(la[i]),false);
+ AttrItem *pattr = gattr->Counterpart();
if(pattr) {
// if there is initialization data take this, otherwise take the current data
diff --git a/externals/grill/flext/source/flclass.h b/externals/grill/flext/source/flclass.h
index 0f7df9c2..f4328d1e 100644
--- a/externals/grill/flext/source/flclass.h
+++ b/externals/grill/flext/source/flclass.h
@@ -537,6 +537,17 @@ protected:
//! Set an attribute value
bool SetAttrib(const t_symbol *s,const AtomList &a) { return SetAttrib(s,a.Count(),a.Atoms()); }
+ // get and set the attribute
+ bool BangAttrib(const t_symbol *a);
+ // get and set the attribute
+ bool BangAttrib(const char *a) { return BangAttrib(MakeSymbol(a)); }
+ // get and set all (both get- and settables)
+ bool BangAttribAll();
+ // show/hide the attribute
+ bool ShowAttrib(const t_symbol *a,bool show) const;
+ // show/hide the attribute
+ bool ShowAttrib(const char *a,bool show) { return ShowAttrib(MakeSymbol(a),show); }
+
//! List methods
void ListMethods(AtomList &a,int inlet = 0) const;
@@ -653,19 +664,22 @@ protected:
virtual ~AttrItem();
enum {
- afl_getset = 0x01, afl_get = 0x00, afl_set = 0x01,
- afl_bothexist = 0x02,
- afl_save = 0x04,afl_init = 0x08,afl_inited = 0x10
+ afl_get = 0x01, afl_set = 0x02,
+ afl_getset = afl_get|afl_set,
+ afl_shown = 0x08
};
bool IsGet() const { return (flags&afl_getset) == afl_get; }
bool IsSet() const { return (flags&afl_getset) == afl_set; }
- bool BothExist() const { return (flags&afl_bothexist) != 0; }
+ bool IsShown() const { return (flags&afl_shown) != 0; }
+ bool BothExist() const { return counter != NULL; }
+ AttrItem *Counterpart() { return counter; }
int index;
int flags;
metharg argtp;
methfun fun;
+ AttrItem *counter;
};
//! Represent a data value of an attribute
@@ -768,8 +782,8 @@ private:
static ItemCont *GetClassArr(t_classid,int ix);
- ItemCont *methhead,*clmethhead;
- ItemCont *bindhead;
+ mutable ItemCont *methhead,*clmethhead;
+ mutable ItemCont *bindhead;
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);
@@ -777,8 +791,8 @@ private:
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);
- ItemCont *attrhead,*clattrhead;
- AttrDataCont *attrdata;
+ mutable ItemCont *attrhead,*clattrhead;
+ mutable AttrDataCont *attrdata;
AttrItem *FindAttrib(const t_symbol *tag,bool get,bool msg = false) const;
@@ -787,11 +801,15 @@ private:
bool ListMethods(int inlet = 0) const;
bool ListAttrib() const;
- bool GetAttrib(AttrItem *a);
+ bool DumpAttrib(AttrItem *a) const;
bool GetAttrib(AttrItem *a,AtomList &l) const;
bool SetAttrib(const t_symbol *s,int argc,const t_atom *argv);
bool SetAttrib(AttrItem *a,int argc,const t_atom *argv);
bool SetAttrib(AttrItem *a,const AtomList &l) { return SetAttrib(a,l.Count(),l.Atoms()); }
+ // get and set the attribute
+ bool BangAttrib(AttrItem *a);
+ // show/hide the attribute
+ bool ShowAttrib(AttrItem *a,bool show) const;
static bool cb_ListMethods(flext_base *c,int argc,const t_atom *argv);
static bool cb_ListAttrib(flext_base *c) { return c->ListAttrib(); }
diff --git a/externals/grill/flext/source/flmsg.cpp b/externals/grill/flext/source/flmsg.cpp
index 9b1eba40..3086ff74 100755
--- a/externals/grill/flext/source/flmsg.cpp
+++ b/externals/grill/flext/source/flmsg.cpp
@@ -82,7 +82,7 @@ bool flext_base::TryMethTag(const MethItem *m,int inlet,const t_symbol *t,int ar
// attributes are treated differently
if(m->attr->IsGet())
- return GetAttrib(m->attr);
+ return DumpAttrib(m->attr);
else
return SetAttrib(m->attr,argc,argv);
}
diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h
index 6db7a7b0..60b7db3d 100644
--- a/externals/grill/flext/source/flsupport.h
+++ b/externals/grill/flext/source/flsupport.h
@@ -17,6 +17,8 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "flstdc.h"
+#include <string>
+
class FLEXT_SHARE FLEXT_CLASSDEF(flext);
typedef class FLEXT_CLASSDEF(flext) flext;
@@ -523,6 +525,9 @@ public:
//! Set to a part of the list
AtomList &Part(int offs,int len) { return (*this = GetPart(offs,len)); }
+ //! Represent as a string
+ std::string Print() const;
+
protected:
int cnt;
t_atom *lst;