Commit b36a9810 authored by thomas's avatar thomas
Browse files

no message


git-svn-id: https://svn.grrrr.org/ext/trunk@223 4d9ac71a-51e6-0310-8455-cad1006bcd31
parent 96e118b4
......@@ -79,6 +79,9 @@ see flext.h for the documented base classes
Version history:
0.3.1:
- added some more functionality to the AtomList class
0.3.0:
- added CYGWIN support
......@@ -202,6 +205,7 @@ bugs:
- PD: problems with timed buffer redrawing (takes a lot of cpu time)
- hard thread termination upon object destruction doesn't seem to work properly -> crash
- Max rounding bug (at least version 4.0.5) ... buffer resize could be one sample less!
- Sleep unimplemented for pd@linux
tests:
- PD: figure out what "pointer" messages do and where they occur
......
......@@ -14,41 +14,57 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include <flext.h>
flext_base::AtomList::AtomList(int argc,t_atom *argv):
cnt(argc)
flext_base::AtomList::AtomList(int argc,const t_atom *argv):
lst(NULL),cnt(0)
{
lst = new t_atom[cnt];
if(argv) {
for(int i = 0; i < argc; ++i) {
switch(lst[i].a_type = argv[i].a_type) {
case A_FLOAT:
lst[i].a_w.w_float = argv[i].a_w.w_float;
break;
operator()(argc,argv);
}
flext_base::AtomList::AtomList(const AtomList &a):
lst(NULL),cnt(0)
{
operator =(a);
}
flext_base::AtomList::~AtomList() { Clear(); }
flext_base::AtomList &flext_base::AtomList::operator()(int argc,const t_atom *argv)
{
if(lst && cnt != argc) { delete[] lst; lst = NULL; }
if(argc) {
cnt = argc;
lst = new t_atom[cnt];
if(argv) {
for(int i = 0; i < argc; ++i) {
switch(lst[i].a_type = argv[i].a_type) {
case A_FLOAT:
lst[i].a_w.w_float = argv[i].a_w.w_float;
break;
#ifdef MAXMSP
case A_LONG:
lst[i].a_w.w_int = argv[i].a_w.w_int;
break;
case A_LONG:
lst[i].a_w.w_int = argv[i].a_w.w_int;
break;
#endif
case A_SYMBOL:
lst[i].a_w.w_symbol = argv[i].a_w.w_symbol;
break;
case A_SYMBOL:
lst[i].a_w.w_symbol = argv[i].a_w.w_symbol;
break;
#ifdef PD
case A_POINTER:
lst[i].a_w.w_gpointer = argv[i].a_w.w_gpointer;
break;
case A_POINTER:
lst[i].a_w.w_gpointer = argv[i].a_w.w_gpointer;
break;
#endif
default:
post("AtomList - atom type (%i) not supported",lst[i].a_type);
lst[i].a_type = A_NULL;
break;
default:
post("AtomList - atom type (%i) not supported",lst[i].a_type);
lst[i].a_type = A_NULL;
break;
}
}
}
}
return *this;
}
flext_base::AtomList::~AtomList()
{
if(lst) delete[] lst;
}
......@@ -307,8 +307,10 @@ public:
static void *GetThing(const t_symbol *s) { return s->s_thing; }
static void SetThing(t_symbol *s,void *dt) { s->s_thing = (t_thing)dt; }
// --- argument list stuff ----------------------------------------
// --- atom stuff ----------------------------------------
static void SetAtom(t_atom &a,const t_atom &b) { CopyAtom(&a,&b); }
static bool IsFloat(const t_atom &a) { return a.a_type == A_FLOAT; }
static bool CanbeFloat(const t_atom &a) { return IsFloat(a) || IsInt(a); }
static float GetFloat(const t_atom &a) { return a.a_w.w_float; }
......@@ -414,9 +416,15 @@ public:
class AtomList
{
public:
AtomList(int argc,t_atom *argv = NULL);
AtomList(int argc = 0,const t_atom *argv = NULL);
AtomList(const AtomList &a);
~AtomList();
AtomList &Clear() { return operator()(); }
AtomList &operator()(int argc = 0,const t_atom *argv = NULL);
AtomList &operator =(const AtomList &a) { return operator()(a.Count(),a.Atoms()); }
int Count() const { return cnt; }
t_atom &operator [](int ix) { return lst[ix]; }
const t_atom &operator [](int ix) const { return lst[ix]; }
......
......@@ -18,9 +18,9 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#define __FLEXT_H
//! flext version number
#define FLEXT_VERSION 300
#define FLEXT_VERSION 301
//! flext version string
#define FLEXT_VERSTR "0.3.0"
#define FLEXT_VERSTR "0.3.1"
// include all the flext interface definitions
#include <fldefs.h>
......
/*
flext tutorial - simple 3
flext tutorial - advanced 1
Copyright (c) 2002 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
......@@ -7,7 +7,7 @@ WARRANTIES, see the file, "license.txt," in this distribution.
-------------------------------------------------------------------------
This is an example of a simple object doing number or string concatenation
This is an example of a simplified prepend object
*/
#include <flext.h>
......@@ -17,121 +17,89 @@ This is an example of a simple object doing number or string concatenation
#endif
class simple3:
class adv1:
public flext_base
{
FLEXT_HEADER(simple3,flext_base)
FLEXT_HEADER(adv1,flext_base)
public:
// constructor with variable argument list
simple3(int argc,t_atom *argv);
adv1(int argc,t_atom *argv);
~adv1();
protected:
void m_any(t_symbol *s,int argc,t_atom *argv); // method which digests anything
void m_int(int f);
void m_sym(t_symbol *s);
// stored argument of right inlet
bool isnumeric;
t_symbol *arg;
AtomList *lst;
private:
FLEXT_CALLBACK_A(m_any); // callback for method "m_any" (with anything argument)
FLEXT_CALLBACK_I(m_int); // callback for method "m_int" (with one integer argument)
FLEXT_CALLBACK_S(m_sym); // callback for method "m_sym" (with one symbol argument)
// that's a shortcut for FLEXT_CALLBACK_1(m_sym,t_symptr) ... you have to use t_symptr instead of t_symbol * !!!
FLEXT_CALLBACK_A(m_any); // callback for method "m_any" (with anything argument)
};
// instantiate the class (constructor has a variable argument list)
FLEXT_NEW_V("simple3",simple3)
// note the two words in the string: prepend acts as an alias for adv1!
FLEXT_NEW_V("adv1 prepend",adv1)
simple3::simple3(int argc,t_atom *argv):
// initalize default argument values
isnumeric(false),
arg(gensym(""))
// constructor
adv1::adv1(int argc,t_atom *argv):
lst(NULL)
{
// define inlets
AddInAnything(2); // make 2 inlets that can receive anything (indices 0 and 1)
// define outlets
AddOutAnything(); // one outlet for anything (has index 0)
AddInAnything(); // one inlet that can receive anything
AddOutAnything(); // one outlet for anything
// set up inlets and outlets
SetupInOut();
// register methods
// register method
FLEXT_ADDMETHOD(0,m_any); // register method "m_any" for inlet 0
FLEXT_ADDMETHOD(1,m_int); // register method (for integers) "m_int" for inlet 1
FLEXT_ADDMETHOD(1,m_sym); // register method (for symbols) "m_sym" for inlet 1
// check for too many arguments
if(argc > 1) {
post("%s - too many arguments given: only the first one is used",thisName());
}
// digest argument list
if(argc < 1) {
post("%s - no argument given: assume empty string",thisName());
// leave default values
}
else if(IsInt(argv[0])) { // check if first argument is an integer
// get the integer argument
m_int(GetInt(argv[0]));
}
else if(IsSymbol(argv[0])) { // check for symbol type
// get the symbol argument
m_sym(GetSymbol(argv[0]));
if(argc != 0) { // check for arg count
// store arg list
lst = new AtomList(argc,argv);
}
else { // unhandled type
post("%s - wrong argument type: assume empty string",thisName());
else {
// no args given
post("%s - no arguments given",thisName());
// tell flext that the initialization was not successful... object will not live
InitProblem();
}
}
void simple3::m_any(t_symbol *s,int argc,t_atom *argv)
// destructor
adv1::~adv1() { if(lst) delete lst; }
// method
void adv1::m_any(t_symbol *s,int argc,t_atom *argv)
{
char tmp[100]; // temporary space
int needed;
// reserve space for as many atoms as possibly necessary
AtomList result(lst->Count()+argc+2);
// sym_int and sym_float are predefined for gensym(int) and gensym(float), respectively
if(s == sym_int || s == sym_float) { // check for int or float tag
needed = 1;
int v = GetAInt(argv[0]);
// print concatenation
sprintf(tmp,"%i%s",v,GetString(arg));
if(isnumeric) // if both were numbers -> output as number
ToOutInt(0,atoi(tmp));
else
ToOutString(0,tmp);
}
else { // take s as symbol
needed = 0;
sprintf(tmp,"%s%s",GetString(s),GetString(arg));
ToOutString(0,tmp);
// ix is our counter of atoms to output
int ix = 0;
int i = 0;
if(!IsSymbol((*lst)[0])) {
// if first element to prepend is no symbol then make it a "list"
SetSymbol(result[ix++],sym_list);
}
if(argc > needed)
post("%s - superfluous arguments ignored!",thisName());
}
// copy atoms to prepend to result list
for(; i < lst->Count(); ++i) CopyAtom(&result[ix++],&(*lst)[i]);
void simple3::m_int(int n)
{
char tmp[20];
sprintf(tmp,"%i",n);
isnumeric = true;
arg = gensym(tmp);
}
// if anything is no "list" or "float" then append it to result list
if(s != sym_list && s != sym_float)
SetSymbol(result[ix++],s);
void simple3::m_sym(t_symbol *s)
{
isnumeric = false;
arg = s;
// append pending arguments to result list
for(i = 0; i < argc; ++i) CopyAtom(&result[ix++],argv+i);
// output result list as an anything
ToOutAnything(0,GetSymbol(result[0]),ix-1,result.Atoms()+1);
}
#N canvas 383 293 460 310 12;
#X msg 39 34 or two words;
#X msg 154 35 2 3;
#X msg 47 252 one or two words;
#X obj 85 154 print result;
#X obj 69 123 adv1 one;
#X obj 47 224 prepend set;
#X text 146 217 you can also use "prepend" if "adv1" has already been
loaded!;
#X connect 0 0 4 0;
#X connect 1 0 4 0;
#X connect 4 0 3 0;
#X connect 4 0 5 0;
#X connect 5 0 2 0;
#N canvas 391 528 450 300 10;
#X obj 179 144 pan~;
#X obj 221 104 hsl 128 15 0 1 0 0 empty empty empty 20 8 0 8 -260818
-1 -1 0 1;
#X obj 117 46 osc~ 440;
#X obj 179 171 *~ 0.6;
#X obj 172 205 dac~;
#X obj 184 47 osc~ 880;
#X floatatom 214 73 5 0 0;
#X connect 0 0 3 0;
#X connect 1 0 0 2;
#X connect 2 0 0 0;
#X connect 3 0 4 0;
#X connect 3 0 4 1;
#X connect 5 0 0 1;
#X connect 6 0 0 2;
#N canvas 251 267 454 304 12;
#X obj 89 68 signal2~;
#X floatatom 52 117 5 0 0;
#X floatatom 153 120 5 0 0;
#X floatatom 251 120 5 0 0;
#X floatatom 345 121 5 0 0;
#X obj 90 30 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X text 29 136 sample rate;
#X text 136 136 block size;
#X text 242 137 channels in;
#X text 342 137 and out;
#X text 116 29 bang to get audio system parameters;
#X connect 0 0 1 0;
#X connect 0 1 2 0;
#X connect 0 2 3 0;
#X connect 0 3 4 0;
#X connect 5 0 0 0;
#N canvas 197 285 460 310 12;
#X floatatom 85 47 5 0 0;
#X floatatom 85 142 5 0 0;
#X msg 22 44 help;
#X text 137 141 inverse;
#X text 139 45 input;
#X obj 85 90 simple1;
#X connect 0 0 5 0;
#X connect 2 0 5 0;
#X connect 5 0 1 0;
#N canvas 197 285 454 304 12;
#X obj 110 96 simple2 3;
#X floatatom 98 51 5 0 0;
#X floatatom 187 52 5 0 0;
#X floatatom 108 150 5 0 0;
#X msg 11 12 help;
#X text 90 30 triggering;
#X text 190 31 non-triggering;
#X text 187 95 default argument;
#X connect 0 0 3 0;
#X connect 1 0 0 0;
#X connect 2 0 0 1;
#X connect 4 0 0 0;
#N canvas 197 285 462 312 12;
#X msg 11 12 help;
#X obj 98 121 simple3 1 2 3;
#X msg 98 60 born;
#X msg 147 61 to;
#X msg 189 63 hula;
#X msg 312 62 yeah;
#X msg 241 65 hula 1;
#X connect 0 0 1 0;
#X connect 2 0 1 0;
#X connect 3 0 1 0;
#X connect 4 0 1 0;
#X connect 5 0 1 0;
#X connect 6 0 1 0;
#N canvas 105 266 672 310 12;
#X obj 54 29 bng 25 250 50 0 empty empty start 0 -6 0 8 -258699 -1
-1;
#X floatatom 54 216 8 0 0;
#X obj 54 182 thread1;
#X floatatom 145 218 8 0 0;
#X obj 145 184 thread1;
#X floatatom 235 219 8 0 0;
#X obj 235 185 thread1;
#X floatatom 327 219 8 0 0;
#X obj 327 185 thread1;
#X floatatom 420 219 8 0 0;
#X obj 420 185 thread1;
#X obj 146 123 delay 200;
#X obj 235 122 delay 200;
#X obj 328 124 delay 200;
#X obj 419 123 delay 200;
#X text 93 23 click to start;
#X text 141 41 (if you click twice \, the same thread is started a
second time);
#X connect 0 0 2 0;
#X connect 0 0 11 0;
#X connect 2 0 1 0;
#X connect 4 0 3 0;
#X connect 6 0 5 0;
#X connect 8 0 7 0;
#X connect 10 0 9 0;
#X connect 11 0 4 0;
#X connect 11 0 12 0;
#X connect 12 0 6 0;
#X connect 12 0 13 0;
#X connect 13 0 8 0;
#X connect 13 0 14 0;
#X connect 14 0 10 0;
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