aboutsummaryrefslogtreecommitdiff
path: root/shared/common
diff options
context:
space:
mode:
authorN.N. <krzyszcz@users.sourceforge.net>2004-04-20 13:55:28 +0000
committerN.N. <krzyszcz@users.sourceforge.net>2004-04-20 13:55:28 +0000
commit6b30948a86211b4c8ca209d3025cd062f9366e3c (patch)
tree3fe120394de95b4a5c51903452f8f933b6f8524c /shared/common
parenta79ea60bfc5f20b37f1410fc589167c15f83cd1a (diff)
importing tables
svn path=/trunk/externals/miXed/; revision=1619
Diffstat (limited to 'shared/common')
-rw-r--r--shared/common/port.c78
-rw-r--r--shared/common/rand.c16
-rw-r--r--shared/common/rand.h5
3 files changed, 78 insertions, 21 deletions
diff --git a/shared/common/port.c b/shared/common/port.c
index e6de120..d09fa6f 100644
--- a/shared/common/port.c
+++ b/shared/common/port.c
@@ -14,6 +14,7 @@
#include <io.h>
#endif
#include <stdio.h>
+#include <stdarg.h>
#include <string.h>
#include "m_pd.h"
#include "g_canvas.h"
@@ -77,12 +78,6 @@ typedef struct _port
int x_emcount;
int x_dumping;
/* class-specifics, LATER find a better way */
- int x_tablerange;
- int x_tableleft;
- int x_tabletop;
- int x_tableright;
- int x_tablebottom;
- int x_tableflags;
FILE *x_pictfp;
int x_pictno;
} t_port;
@@ -342,6 +337,52 @@ static int import_emcopy(t_port *x, t_symbol *state)
else return (0);
}
+static int import_emadd(t_port *x, t_symbol *state, int ac, t_atom *av)
+{
+ if (import_emcheck(x, state))
+ {
+ t_atom at;
+ SETSYMBOL(&at, gensym("#C"));
+ binbuf_add(x->x_embb, 1, &at);
+ binbuf_add(x->x_embb, ac, av);
+ binbuf_addsemi(x->x_embb);
+ return (1);
+ }
+ else return (0);
+}
+
+static int import_emaddv(t_port *x, t_symbol *state, char *fmt, ...)
+{
+ va_list ap;
+ t_atom arg[64], *at = arg;
+ int nargs = 0;
+ char *fp = fmt;
+ va_start(ap, fmt);
+ SETSYMBOL(at, gensym("#C"));
+ at++; nargs++;
+ if (import_emcheck(x, state)) while (1)
+ {
+ switch(*fp++)
+ {
+ case 'i': SETFLOAT(at, va_arg(ap, t_int)); break;
+ case 'f': SETFLOAT(at, va_arg(ap, double)); break;
+ case 's': SETSYMBOL(at, va_arg(ap, t_symbol *)); break;
+ case ';': SETSEMI(at); break;
+ case 0: goto done;
+ default: nargs = 0; goto done;
+ }
+ at++; nargs++;
+ }
+done:
+ va_end(ap);
+ if (nargs > 1)
+ {
+ binbuf_add(x->x_embb, nargs, arg);
+ return (1);
+ }
+ else return (0);
+}
+
static void import_addclassname(t_port *x, char *outname, t_atom *inatom)
{
t_atom at;
@@ -430,19 +471,26 @@ static int imaction_N1_vpatcher(t_port *x, char *arg)
static int imaction_N1_vtable(t_port *x, char *arg)
{
+ int range = port_getint(x, 8),
+ left = port_getint(x, 3),
+ top = port_getint(x, 4),
+ right = port_getint(x, 5),
+ bottom = port_getint(x, 6),
+ flags = port_getint(x, 7);
import_emstart(x, portps_vtable, port_getsymbol(x, 9), port_getint(x, 2));
- x->x_tablerange = port_getint(x, 8);
- x->x_tableleft = port_getint(x, 3);
- x->x_tabletop = port_getint(x, 4);
- x->x_tableright = port_getint(x, 5);
- x->x_tablebottom = port_getint(x, 6);
- x->x_tableflags = port_getint(x, 7);
#ifdef PORT_DEBUG
post("vtable \"%s\": size %d, range %d, coords %d %d %d %d, flags %d",
- x->x_emname->s_name, x->x_emsize, x->x_tablerange,
- x->x_tableleft, x->x_tabletop, x->x_tableright, x->x_tablebottom,
- x->x_tableflags);
+ x->x_emname->s_name, x->x_emsize,
+ range, left, top, right, bottom, flags);
#endif
+ import_emaddv(x, portps_vtable, "si;", gensym("size"), x->x_emsize);
+ import_emaddv(x, portps_vtable, "siiii;", gensym("flags"),
+ /* CHECKED */
+ (flags & 16) != 0, (flags & 4) != 0,
+ (flags & 8) != 0, (flags & 2) != 0);
+ import_emaddv(x, portps_vtable, "si;", gensym("tabrange"), range);
+ import_emaddv(x, portps_vtable, "siiiii;", gensym("_coords"),
+ left, top, right, bottom, flags & 1);
return (PORT_NEXT);
}
diff --git a/shared/common/rand.c b/shared/common/rand.c
index 37dcf62..7a3fff4 100644
--- a/shared/common/rand.c
+++ b/shared/common/rand.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997-2003 Miller Puckette, krzYszcz, and others.
+/* Copyright (c) 1997-2004 Miller Puckette, krzYszcz, and others.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
@@ -51,11 +51,19 @@ int rand_int(unsigned int *statep, int range)
return (result < range ? result : range - 1);
}
+float rand_unipolar(unsigned int *statep)
+{
+ float result;
+ *statep = *statep * 472940017 + 832416023;
+ result = (float)((double)*statep * (1./4294967296.));
+ return (result);
+}
+
/* borrowed from d_osc.c, LATER rethink */
-float rand_float(unsigned int *statep)
+float rand_bipolar(unsigned int *statep)
{
- float result = ((float)((*statep & 0x7fffffff) - 0x40000000))
+ float result = ((float)(((int)*statep & 0x7fffffff) - 0x40000000))
* (float)(1.0 / 0x40000000);
- *statep = *statep * 435898247 + 382842987;
+ *statep = (unsigned)((int)*statep * 435898247 + 382842987);
return (result);
}
diff --git a/shared/common/rand.h b/shared/common/rand.h
index 75350d2..1590869 100644
--- a/shared/common/rand.h
+++ b/shared/common/rand.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2002-2003 krzYszcz and others.
+/* Copyright (c) 2002-2004 krzYszcz and others.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
@@ -9,6 +9,7 @@
void rand_seed(unsigned int *statep, unsigned int seed);
int rand_int(unsigned int *statep, int range);
-float rand_float(unsigned int *statep);
+float rand_unipolar(unsigned int *statep);
+float rand_bipolar(unsigned int *statep);
#endif