summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/m_class.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/m_class.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/m_class.c823
1 files changed, 0 insertions, 823 deletions
diff --git a/apps/plugins/pdbox/PDa/src/m_class.c b/apps/plugins/pdbox/PDa/src/m_class.c
index 0b6d4df885..66cb34d921 100644
--- a/apps/plugins/pdbox/PDa/src/m_class.c
+++ b/apps/plugins/pdbox/PDa/src/m_class.c
@@ -822,827 +822,4 @@ t_gotfn zgetfn(t_pd *x, t_symbol *s)
822 if (m->me_name == s) return(m->me_fun); 822 if (m->me_name == s) return(m->me_fun);
823 return(0); 823 return(0);
824} 824}
825/* Copyright (c) 1997-1999 Miller Puckette.
826* For information on usage and redistribution, and for a DISCLAIMER OF ALL
827* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
828
829#define PD_CLASS_DEF
830#include "m_pd.h"
831#include "m_imp.h"
832#include "s_stuff.h"
833#include <stdlib.h>
834#ifdef UNIX
835#include <unistd.h>
836#endif
837#ifdef MSW
838#include <io.h>
839#endif
840
841#include <stdarg.h>
842#include <string.h>
843
844static t_symbol *class_loadsym; /* name under which an extern is invoked */
845static void pd_defaultfloat(t_pd *x, t_float f);
846static void pd_defaultlist(t_pd *x, t_symbol *s, int argc, t_atom *argv);
847t_pd pd_objectmaker; /* factory for creating "object" boxes */
848t_pd pd_canvasmaker; /* factory for creating canvases */
849
850static t_symbol *class_extern_dir = &s_;
851
852static void pd_defaultanything(t_pd *x, t_symbol *s, int argc, t_atom *argv)
853{
854 pd_error(x, "%s: no method for '%s'", (*x)->c_name->s_name, s->s_name);
855}
856
857static void pd_defaultbang(t_pd *x)
858{
859 if (*(*x)->c_listmethod != pd_defaultlist)
860 (*(*x)->c_listmethod)(x, 0, 0, 0);
861 else (*(*x)->c_anymethod)(x, &s_bang, 0, 0);
862}
863
864static void pd_defaultpointer(t_pd *x, t_gpointer *gp)
865{
866 if (*(*x)->c_listmethod != pd_defaultlist)
867 {
868 t_atom at;
869 SETPOINTER(&at, gp);
870 (*(*x)->c_listmethod)(x, 0, 1, &at);
871 }
872 else
873 {
874 t_atom at;
875 SETPOINTER(&at, gp);
876 (*(*x)->c_anymethod)(x, &s_pointer, 1, &at);
877 }
878}
879
880static void pd_defaultfloat(t_pd *x, t_float f)
881{
882 if (*(*x)->c_listmethod != pd_defaultlist)
883 {
884 t_atom at;
885 SETFLOAT(&at, f);
886 (*(*x)->c_listmethod)(x, 0, 1, &at);
887 }
888 else
889 {
890 t_atom at;
891 SETFLOAT(&at, f);
892 (*(*x)->c_anymethod)(x, &s_float, 1, &at);
893 }
894}
895
896static void pd_defaultsymbol(t_pd *x, t_symbol *s)
897{
898 if (*(*x)->c_listmethod != pd_defaultlist)
899 {
900 t_atom at;
901 SETSYMBOL(&at, s);
902 (*(*x)->c_listmethod)(x, 0, 1, &at);
903 }
904 else
905 {
906 t_atom at;
907 SETSYMBOL(&at, s);
908 (*(*x)->c_anymethod)(x, &s_symbol, 1, &at);
909 }
910}
911
912void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv);
913static void class_nosavefn(t_gobj *z, t_binbuf *b);
914
915 /* handle "list" messages to Pds without explicit list methods defined. */
916static void pd_defaultlist(t_pd *x, t_symbol *s, int argc, t_atom *argv)
917{
918 /* a list with one element which is a number can be handled by a
919 "float" method if any is defined; same for "symbol", "pointer". */
920 if (argc == 1)
921 {
922 if (argv->a_type == A_FLOAT &&
923 *(*x)->c_floatmethod != pd_defaultfloat)
924 {
925 (*(*x)->c_floatmethod)(x, argv->a_w.w_float);
926 return;
927 }
928 else if (argv->a_type == A_SYMBOL &&
929 *(*x)->c_symbolmethod != pd_defaultsymbol)
930 {
931 (*(*x)->c_symbolmethod)(x, argv->a_w.w_symbol);
932 return;
933 }
934 else if (argv->a_type == A_POINTER &&
935 *(*x)->c_pointermethod != pd_defaultpointer)
936 {
937 (*(*x)->c_pointermethod)(x, argv->a_w.w_gpointer);
938 return;
939 }
940 }
941 /* Next try for an "anything" method */
942 if ((*x)->c_anymethod != pd_defaultanything)
943 (*(*x)->c_anymethod)(x, &s_list, argc, argv);
944
945 /* if the object is patchable (i.e., can have proper inlets)
946 send it on to obj_list which will unpack the list into the inlets */
947 else if ((*x)->c_patchable)
948 obj_list((t_object *)x, s, argc, argv);
949 /* otherwise gove up and complain. */
950 else pd_defaultanything(x, &s_list, argc, argv);
951}
952
953 /* for now we assume that all "gobjs" are text unless explicitly
954 overridden later by calling class_setbehavior(). I'm not sure
955 how to deal with Pds that aren't gobjs; shouldn't there be a
956 way to check that at run time? Perhaps the presence of a "newmethod"
957 should be our cue, or perhaps the "tiny" flag. */
958
959 /* another matter. This routine does two unrelated things: it creates
960 a Pd class, but also adds a "new" method to create an instance of it.
961 These are combined for historical reasons and for brevity in writing
962 objects. To avoid adding a "new" method send a null function pointer.
963 To add additional ones, use class_addcreator below. Some "classes", like
964 "select", are actually two classes of the same name, one for the single-
965 argument form, one for the multiple one; see select_setup() to find out
966 how this is handled. */
967
968extern t_widgetbehavior text_widgetbehavior;
969extern void text_save(t_gobj *z, t_binbuf *b);
970
971t_class *class_new(t_symbol *s, t_newmethod newmethod, t_method freemethod,
972 size_t size, int flags, t_atomtype type1, ...)
973{
974 va_list ap;
975 t_atomtype vec[MAXPDARG+1], *vp = vec;
976 int count = 0;
977 t_class *c;
978 int typeflag = flags & CLASS_TYPEMASK;
979 if (!typeflag) typeflag = CLASS_PATCHABLE;
980 *vp = type1;
981
982 va_start(ap, type1);
983 while (*vp)
984 {
985 if (count == MAXPDARG)
986 {
987 error("class %s: sorry: only %d creation args allowed",
988 s->s_name, MAXPDARG);
989 break;
990 }
991 vp++;
992 count++;
993 *vp = va_arg(ap, t_atomtype);
994 }
995 va_end(ap);
996 if (pd_objectmaker && newmethod)
997 {
998 /* add a "new" method by the name specified by the object */
999 class_addmethod(pd_objectmaker, (t_method)newmethod, s,
1000 vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
1001 if (class_loadsym)
1002 {
1003 /* if we're loading an extern it might have been invoked by a
1004 longer file name; in this case, make this an admissible name
1005 too. */
1006 char *loadstring = class_loadsym->s_name,
1007 l1 = strlen(s->s_name), l2 = strlen(loadstring);
1008 if (l2 > l1 && !strcmp(s->s_name, loadstring + (l2 - l1)))
1009 class_addmethod(pd_objectmaker, (t_method)newmethod,
1010 class_loadsym,
1011 vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
1012 }
1013 }
1014 c = (t_class *)t_getbytes(sizeof(*c));
1015 c->c_name = c->c_helpname = s;
1016 c->c_size = size;
1017 c->c_methods = t_getbytes(0);
1018 c->c_nmethod = 0;
1019 c->c_freemethod = (t_method)freemethod;
1020 c->c_bangmethod = pd_defaultbang;
1021 c->c_pointermethod = pd_defaultpointer;
1022 c->c_floatmethod = pd_defaultfloat;
1023 c->c_symbolmethod = pd_defaultsymbol;
1024 c->c_listmethod = pd_defaultlist;
1025 c->c_anymethod = pd_defaultanything;
1026 c->c_wb = (typeflag == CLASS_PATCHABLE ? &text_widgetbehavior : 0);
1027 c->c_pwb = 0;
1028 c->c_firstin = ((flags & CLASS_NOINLET) == 0);
1029 c->c_patchable = (typeflag == CLASS_PATCHABLE);
1030 c->c_gobj = (typeflag >= CLASS_GOBJ);
1031 c->c_drawcommand = 0;
1032 c->c_floatsignalin = 0;
1033 c->c_externdir = class_extern_dir;
1034 c->c_savefn = (typeflag == CLASS_PATCHABLE ? text_save : class_nosavefn);
1035#if 0
1036 post("class: %s", c->c_name->s_name);
1037#endif
1038 return (c);
1039}
1040
1041 /* add a creation method, which is a function that returns a Pd object
1042 suitable for putting in an object box. We presume you've got a class it
1043 can belong to, but this won't be used until the newmethod is actually
1044 called back (and the new method explicitly takes care of this.) */
1045
1046void class_addcreator(t_newmethod newmethod, t_symbol *s,
1047 t_atomtype type1, ...)
1048{
1049 va_list ap;
1050 t_atomtype vec[MAXPDARG+1], *vp = vec;
1051 int count = 0;
1052 *vp = type1;
1053
1054 va_start(ap, type1);
1055 while (*vp)
1056 {
1057 if (count == MAXPDARG)
1058 {
1059 error("class %s: sorry: only %d creation args allowed",
1060 s->s_name, MAXPDARG);
1061 break;
1062 }
1063 vp++;
1064 count++;
1065 *vp = va_arg(ap, t_atomtype);
1066 }
1067 va_end(ap);
1068 class_addmethod(pd_objectmaker, (t_method)newmethod, s,
1069 vec[0], vec[1], vec[2], vec[3], vec[4], vec[5]);
1070}
1071
1072void class_addmethod(t_class *c, t_method fn, t_symbol *sel,
1073 t_atomtype arg1, ...)
1074{
1075 va_list ap;
1076 t_methodentry *m;
1077 t_atomtype argtype = arg1;
1078 int nargs;
1079
1080 va_start(ap, arg1);
1081 /* "signal" method specifies that we take audio signals but
1082 that we don't want automatic float to signal conversion. This
1083 is obsolete; you should now use the CLASS_MAINSIGNALIN macro. */
1084 if (sel == &s_signal)
1085 {
1086 if (c->c_floatsignalin)
1087 post("warning: signal method overrides class_mainsignalin");
1088 c->c_floatsignalin = -1;
1089 }
1090 /* check for special cases. "Pointer" is missing here so that
1091 pd_objectmaker's pointer method can be typechecked differently. */
1092 if (sel == &s_bang)
1093 {
1094 if (argtype) goto phooey;
1095 class_addbang(c, fn);
1096 }
1097 else if (sel == &s_float)
1098 {
1099 if (argtype != A_FLOAT || va_arg(ap, t_atomtype)) goto phooey;
1100 class_doaddfloat(c, fn);
1101 }
1102 else if (sel == &s_symbol)
1103 {
1104 if (argtype != A_SYMBOL || va_arg(ap, t_atomtype)) goto phooey;
1105 class_addsymbol(c, fn);
1106 }
1107 else if (sel == &s_list)
1108 {
1109 if (argtype != A_GIMME) goto phooey;
1110 class_addlist(c, fn);
1111 }
1112 else if (sel == &s_anything)
1113 {
1114 if (argtype != A_GIMME) goto phooey;
1115 class_addanything(c, fn);
1116 }
1117 else
1118 {
1119 c->c_methods = t_resizebytes(c->c_methods,
1120 c->c_nmethod * sizeof(*c->c_methods),
1121 (c->c_nmethod + 1) * sizeof(*c->c_methods));
1122 m = c->c_methods + c->c_nmethod;
1123 c->c_nmethod++;
1124 m->me_name = sel;
1125 m->me_fun = (t_gotfn)fn;
1126 nargs = 0;
1127 while (argtype != A_NULL && nargs < MAXPDARG)
1128 {
1129 m->me_arg[nargs++] = argtype;
1130 argtype = va_arg(ap, t_atomtype);
1131 }
1132 if (argtype != A_NULL)
1133 error("%s_%s: only 5 arguments are typecheckable; use A_GIMME",
1134 c->c_name->s_name, sel->s_name);
1135 va_end(ap);
1136 m->me_arg[nargs] = A_NULL;
1137 }
1138 return;
1139phooey:
1140 bug("class_addmethod: %s_%s: bad argument types\n",
1141 c->c_name->s_name, sel->s_name);
1142}
1143
1144 /* Instead of these, see the "class_addfloat", etc., macros in m_pd.h */
1145void class_addbang(t_class *c, t_method fn)
1146{
1147 c->c_bangmethod = (t_bangmethod)fn;
1148}
1149
1150void class_addpointer(t_class *c, t_method fn)
1151{
1152 c->c_pointermethod = (t_pointermethod)fn;
1153}
1154
1155void class_doaddfloat(t_class *c, t_method fn)
1156{
1157 c->c_floatmethod = (t_floatmethod)fn;
1158}
1159
1160void class_addsymbol(t_class *c, t_method fn)
1161{
1162 c->c_symbolmethod = (t_symbolmethod)fn;
1163}
1164
1165void class_addlist(t_class *c, t_method fn)
1166{
1167 c->c_listmethod = (t_listmethod)fn;
1168}
1169
1170void class_addanything(t_class *c, t_method fn)
1171{
1172 c->c_anymethod = (t_anymethod)fn;
1173}
1174 825
1175void class_setwidget(t_class *c, t_widgetbehavior *w)
1176{
1177 c->c_wb = w;
1178}
1179
1180void class_setparentwidget(t_class *c, t_parentwidgetbehavior *pw)
1181{
1182 c->c_pwb = pw;
1183}
1184
1185char *class_getname(t_class *c)
1186{
1187 return (c->c_name->s_name);
1188}
1189
1190char *class_gethelpname(t_class *c)
1191{
1192 return (c->c_helpname->s_name);
1193}
1194
1195void class_sethelpsymbol(t_class *c, t_symbol *s)
1196{
1197 c->c_helpname = s;
1198}
1199
1200t_parentwidgetbehavior *pd_getparentwidget(t_pd *x)
1201{
1202 return ((*x)->c_pwb);
1203}
1204
1205void class_setdrawcommand(t_class *c)
1206{
1207 c->c_drawcommand = 1;
1208}
1209
1210int class_isdrawcommand(t_class *c)
1211{
1212 return (c->c_drawcommand);
1213}
1214
1215static void pd_floatforsignal(t_pd *x, t_float f)
1216{
1217 int offset = (*x)->c_floatsignalin;
1218 if (offset > 0)
1219 *(t_sample *)(((char *)x) + offset) = ftofix(f);
1220 else
1221 pd_error(x, "%s: float unexpected for signal input",
1222 (*x)->c_name->s_name);
1223}
1224
1225void class_domainsignalin(t_class *c, int onset)
1226{
1227 if (onset <= 0) onset = -1;
1228 else
1229 {
1230 if (c->c_floatmethod != pd_defaultfloat)
1231 post("warning: %s: float method overwritten", c->c_name->s_name);
1232 c->c_floatmethod = (t_floatmethod)pd_floatforsignal;
1233 }
1234 c->c_floatsignalin = onset;
1235}
1236
1237void class_set_extern_dir(t_symbol *s)
1238{
1239 class_extern_dir = s;
1240}
1241
1242char *class_gethelpdir(t_class *c)
1243{
1244 return (c->c_externdir->s_name);
1245}
1246
1247static void class_nosavefn(t_gobj *z, t_binbuf *b)
1248{
1249 bug("save function called but not defined");
1250}
1251
1252void class_setsavefn(t_class *c, t_savefn f)
1253{
1254 c->c_savefn = f;
1255}
1256
1257t_savefn class_getsavefn(t_class *c)
1258{
1259 return (c->c_savefn);
1260}
1261
1262void class_setpropertiesfn(t_class *c, t_propertiesfn f)
1263{
1264 c->c_propertiesfn = f;
1265}
1266
1267t_propertiesfn class_getpropertiesfn(t_class *c)
1268{
1269 return (c->c_propertiesfn);
1270}
1271
1272/* ---------------- the symbol table ------------------------ */
1273
1274#define HASHSIZE 1024
1275
1276static t_symbol *symhash[HASHSIZE];
1277
1278t_symbol *dogensym(char *s, t_symbol *oldsym)
1279{
1280 t_symbol **sym1, *sym2;
1281 unsigned int hash1 = 0, hash2 = 0;
1282 int length = 0;
1283 char *s2 = s;
1284 while (*s2)
1285 {
1286 hash1 += *s2;
1287 hash2 += hash1;
1288 length++;
1289 s2++;
1290 }
1291 sym1 = symhash + (hash2 & (HASHSIZE-1));
1292 while (sym2 = *sym1)
1293 {
1294 if (!strcmp(sym2->s_name, s)) return(sym2);
1295 sym1 = &sym2->s_next;
1296 }
1297 if (oldsym) sym2 = oldsym;
1298 else
1299 {
1300 sym2 = (t_symbol *)t_getbytes(sizeof(*sym2));
1301 sym2->s_name = t_getbytes(length+1);
1302 sym2->s_next = 0;
1303 sym2->s_thing = 0;
1304 strcpy(sym2->s_name, s);
1305 }
1306 *sym1 = sym2;
1307 return (sym2);
1308}
1309
1310t_symbol *gensym(char *s)
1311{
1312 return(dogensym(s, 0));
1313}
1314
1315static t_symbol *addfileextent(t_symbol *s)
1316{
1317 char namebuf[MAXPDSTRING], *str = s->s_name;
1318 int ln = strlen(str);
1319 if (!strcmp(str + ln - 3, ".pd")) return (s);
1320 strcpy(namebuf, str);
1321 strcpy(namebuf+ln, ".pd");
1322 return (gensym(namebuf));
1323}
1324
1325static int tryingalready;
1326
1327void canvas_popabstraction(t_canvas *x);
1328extern t_pd *newest;
1329
1330t_symbol* pathsearch(t_symbol *s,char* ext);
1331int pd_setloadingabstraction(t_symbol *sym);
1332
1333 /* this routine is called when a new "object" is requested whose class Pd
1334 doesn't know. Pd tries to load it as an extern, then as an abstraction. */
1335void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv)
1336{
1337 t_pd *current;
1338 t_symbol *dir = canvas_getcurrentdir();
1339 int fd;
1340 char dirbuf[MAXPDSTRING], *nameptr;
1341 if (tryingalready) return;
1342 newest = 0;
1343 class_loadsym = s;
1344 if (sys_load_lib(dir->s_name, s->s_name))
1345 {
1346 tryingalready = 1;
1347 typedmess(dummy, s, argc, argv);
1348 tryingalready = 0;
1349 return;
1350 }
1351 class_loadsym = 0;
1352 current = s__X.s_thing;
1353 if ((fd = open_via_path(dir->s_name, s->s_name, ".pd",
1354 dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
1355 (fd = open_via_path(dir->s_name, s->s_name, ".pat",
1356 dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
1357 {
1358 close (fd);
1359 if (!pd_setloadingabstraction(s))
1360 {
1361 canvas_setargs(argc, argv); /* bug fix by Krzysztof Czaja */
1362 binbuf_evalfile(gensym(nameptr), gensym(dirbuf));
1363 if (s__X.s_thing != current)
1364 canvas_popabstraction((t_canvas *)(s__X.s_thing));
1365 canvas_setargs(0, 0);
1366 }
1367 else error("%s: can't load abstraction within itself\n", s->s_name);
1368 }
1369 else newest = 0;
1370}
1371
1372t_symbol s_pointer = {"pointer", 0, 0};
1373t_symbol s_float = {"float", 0, 0};
1374t_symbol s_symbol = {"symbol", 0, 0};
1375t_symbol s_bang = {"bang", 0, 0};
1376t_symbol s_list = {"list", 0, 0};
1377t_symbol s_anything = {"anything", 0, 0};
1378t_symbol s_signal = {"signal", 0, 0};
1379t_symbol s__N = {"#N", 0, 0};
1380t_symbol s__X = {"#X", 0, 0};
1381t_symbol s_x = {"x", 0, 0};
1382t_symbol s_y = {"y", 0, 0};
1383t_symbol s_ = {"", 0, 0};
1384
1385static t_symbol *symlist[] = { &s_pointer, &s_float, &s_symbol, &s_bang,
1386 &s_list, &s_anything, &s_signal, &s__N, &s__X, &s_x, &s_y, &s_};
1387
1388void mess_init(void)
1389{
1390 t_symbol **sp;
1391 int i;
1392
1393 if (pd_objectmaker) return;
1394 for (i = sizeof(symlist)/sizeof(*symlist), sp = symlist; i--; sp++)
1395 (void) dogensym((*sp)->s_name, *sp);
1396 pd_objectmaker = class_new(gensym("objectmaker"), 0, 0, sizeof(t_pd),
1397 CLASS_DEFAULT, A_NULL);
1398 pd_canvasmaker = class_new(gensym("classmaker"), 0, 0, sizeof(t_pd),
1399 CLASS_DEFAULT, A_NULL);
1400 pd_bind(&pd_canvasmaker, &s__N);
1401 class_addanything(pd_objectmaker, (t_method)new_anything);
1402}
1403
1404t_pd *newest;
1405
1406/* This is externally available, but note that it might later disappear; the
1407whole "newest" thing is a hack which needs to be redesigned. */
1408t_pd *pd_newest(void)
1409{
1410 return (newest);
1411}
1412
1413 /* horribly, we need prototypes for each of the artificial function
1414 calls in typedmess(), to keep the compiler quiet. */
1415typedef t_pd *(*t_newgimme)(t_symbol *s, int argc, t_atom *argv);
1416typedef void(*t_messgimme)(t_pd *x, t_symbol *s, int argc, t_atom *argv);
1417
1418typedef t_pd *(*t_fun0)(
1419 t_floatarg d1, t_floatarg d2, t_floatarg d3, t_floatarg d4, t_floatarg d5);
1420typedef t_pd *(*t_fun1)(t_int i1,
1421 t_floatarg d1, t_floatarg d2, t_floatarg d3, t_floatarg d4, t_floatarg d5);
1422typedef t_pd *(*t_fun2)(t_int i1, t_int i2,
1423 t_floatarg d1, t_floatarg d2, t_floatarg d3, t_floatarg d4, t_floatarg d5);
1424typedef t_pd *(*t_fun3)(t_int i1, t_int i2, t_int i3,
1425 t_floatarg d1, t_floatarg d2, t_floatarg d3, t_floatarg d4, t_floatarg d5);
1426typedef t_pd *(*t_fun4)(t_int i1, t_int i2, t_int i3, t_int i4,
1427 t_floatarg d1, t_floatarg d2, t_floatarg d3, t_floatarg d4, t_floatarg d5);
1428typedef t_pd *(*t_fun5)(t_int i1, t_int i2, t_int i3, t_int i4, t_int i5,
1429 t_floatarg d1, t_floatarg d2, t_floatarg d3, t_floatarg d4, t_floatarg d5);
1430typedef t_pd *(*t_fun6)(t_int i1, t_int i2, t_int i3, t_int i4, t_int i5, t_int i6,
1431 t_floatarg d1, t_floatarg d2, t_floatarg d3, t_floatarg d4, t_floatarg d5);
1432
1433void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv)
1434{
1435 t_method *f;
1436 t_class *c = *x;
1437 t_methodentry *m;
1438 t_atomtype *wp, wanttype;
1439 int i;
1440 t_int ai[MAXPDARG+1], *ap = ai;
1441 t_floatarg ad[MAXPDARG+1], *dp = ad;
1442 int narg = 0;
1443 t_pd *bonzo;
1444
1445 /* check for messages that are handled by fixed slots in the class
1446 structure. We don't catch "pointer" though so that sending "pointer"
1447 to pd_objectmaker doesn't require that we supply a pointer value. */
1448 if (s == &s_float)
1449 {
1450 if (!argc) (*c->c_floatmethod)(x, 0.);
1451 else if (argv->a_type == A_FLOAT)
1452 (*c->c_floatmethod)(x, argv->a_w.w_float);
1453 else goto badarg;
1454 return;
1455 }
1456 if (s == &s_bang)
1457 {
1458 (*c->c_bangmethod)(x);
1459 return;
1460 }
1461 if (s == &s_list)
1462 {
1463 (*c->c_listmethod)(x, s, argc, argv);
1464 return;
1465 }
1466 if (s == &s_symbol)
1467 {
1468 if (argc && argv->a_type == A_SYMBOL)
1469 (*c->c_symbolmethod)(x, argv->a_w.w_symbol);
1470 else
1471 (*c->c_symbolmethod)(x, &s_);
1472 return;
1473 }
1474 for (i = c->c_nmethod, m = c->c_methods; i--; m++)
1475 if (m->me_name == s)
1476 {
1477 wp = m->me_arg;
1478 if (*wp == A_GIMME)
1479 {
1480 if (x == &pd_objectmaker)
1481 newest = (*((t_newgimme)(m->me_fun)))(s, argc, argv);
1482 else (*((t_messgimme)(m->me_fun)))(x, s, argc, argv);
1483 return;
1484 }
1485 if (argc > MAXPDARG) argc = MAXPDARG;
1486 if (x != &pd_objectmaker) *(ap++) = (t_int)x, narg++;
1487 while (wanttype = *wp++)
1488 {
1489 switch (wanttype)
1490 {
1491 case A_POINTER:
1492 if (!argc) goto badarg;
1493 else
1494 {
1495 if (argv->a_type == A_POINTER)
1496 *ap = (t_int)(argv->a_w.w_gpointer);
1497 else goto badarg;
1498 argc--;
1499 argv++;
1500 }
1501 narg++;
1502 ap++;
1503 break;
1504 case A_FLOAT:
1505 if (!argc) goto badarg;
1506 case A_DEFFLOAT:
1507 if (!argc) *dp = 0;
1508 else
1509 {
1510 if (argv->a_type == A_FLOAT)
1511 *dp = argv->a_w.w_float;
1512 else goto badarg;
1513 argc--;
1514 argv++;
1515 }
1516 dp++;
1517 break;
1518 case A_SYMBOL:
1519 if (!argc) goto badarg;
1520 case A_DEFSYM:
1521 if (!argc) *ap = (t_int)(&s_);
1522 else
1523 {
1524 if (argv->a_type == A_SYMBOL)
1525 *ap = (t_int)(argv->a_w.w_symbol);
1526 /* if it's an unfilled "dollar" argument it appears
1527 as zero here; cheat and bash it to the null
1528 symbol. Unfortunately, this lets real zeros
1529 pass as symbols too, which seems wrong... */
1530 else if (x == &pd_objectmaker && argv->a_type == A_FLOAT
1531 && argv->a_w.w_float == 0)
1532 *ap = (t_int)(&s_);
1533 else goto badarg;
1534 argc--;
1535 argv++;
1536 }
1537 narg++;
1538 ap++;
1539 }
1540 }
1541 switch (narg)
1542 {
1543 case 0 : bonzo = (*(t_fun0)(m->me_fun))
1544 (ad[0], ad[1], ad[2], ad[3], ad[4]); break;
1545 case 1 : bonzo = (*(t_fun1)(m->me_fun))
1546 (ai[0], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
1547 case 2 : bonzo = (*(t_fun2)(m->me_fun))
1548 (ai[0], ai[1], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
1549 case 3 : bonzo = (*(t_fun3)(m->me_fun))
1550 (ai[0], ai[1], ai[2], ad[0], ad[1], ad[2], ad[3], ad[4]); break;
1551 case 4 : bonzo = (*(t_fun4)(m->me_fun))
1552 (ai[0], ai[1], ai[2], ai[3],
1553 ad[0], ad[1], ad[2], ad[3], ad[4]); break;
1554 case 5 : bonzo = (*(t_fun5)(m->me_fun))
1555 (ai[0], ai[1], ai[2], ai[3], ai[4],
1556 ad[0], ad[1], ad[2], ad[3], ad[4]); break;
1557 case 6 : bonzo = (*(t_fun6)(m->me_fun))
1558 (ai[0], ai[1], ai[2], ai[3], ai[4], ai[5],
1559 ad[0], ad[1], ad[2], ad[3], ad[4]); break;
1560 default: bonzo = 0;
1561 }
1562 if (x == &pd_objectmaker)
1563 newest = bonzo;
1564 return;
1565 }
1566 (*c->c_anymethod)(x, s, argc, argv);
1567 return;
1568badarg:
1569 pd_error(x, "Bad arguments for message '%s' to object '%s'",
1570 s->s_name, c->c_name->s_name);
1571}
1572
1573void pd_vmess(t_pd *x, t_symbol *sel, char *fmt, ...)
1574{
1575 va_list ap;
1576 t_atom arg[MAXPDARG], *at =arg;
1577 int nargs = 0;
1578 char *fp = fmt;
1579
1580 va_start(ap, fmt);
1581 while (1)
1582 {
1583 if (nargs > MAXPDARG)
1584 {
1585 pd_error(x, "pd_vmess: only %d allowed", MAXPDARG);
1586 break;
1587 }
1588 switch(*fp++)
1589 {
1590 case 'f': SETFLOAT(at, va_arg(ap, double)); break;
1591 case 's': SETSYMBOL(at, va_arg(ap, t_symbol *)); break;
1592 case 'i': SETFLOAT(at, va_arg(ap, t_int)); break;
1593 case 'p': SETPOINTER(at, va_arg(ap, t_gpointer *)); break;
1594 default: goto done;
1595 }
1596 at++;
1597 nargs++;
1598 }
1599done:
1600 va_end(ap);
1601 typedmess(x, sel, nargs, arg);
1602}
1603
1604void pd_forwardmess(t_pd *x, int argc, t_atom *argv)
1605{
1606 if (argc)
1607 {
1608 t_atomtype t = argv->a_type;
1609 if (t == A_SYMBOL) pd_typedmess(x, argv->a_w.w_symbol, argc-1, argv+1);
1610 else if (t == A_POINTER)
1611 {
1612 if (argc == 1) pd_pointer(x, argv->a_w.w_gpointer);
1613 else pd_list(x, &s_list, argc, argv);
1614 }
1615 else if (t == A_FLOAT)
1616 {
1617 if (argc == 1) pd_float(x, argv->a_w.w_float);
1618 else pd_list(x, &s_list, argc, argv);
1619 }
1620 else bug("pd_forwardmess");
1621 }
1622
1623}
1624
1625void nullfn(void) {}
1626
1627t_gotfn getfn(t_pd *x, t_symbol *s)
1628{
1629 t_class *c = *x;
1630 t_methodentry *m;
1631 int i;
1632
1633 for (i = c->c_nmethod, m = c->c_methods; i--; m++)
1634 if (m->me_name == s) return(m->me_fun);
1635 pd_error(x, "%s: no method for message '%s'", c->c_name->s_name, s->s_name);
1636 return((t_gotfn)nullfn);
1637}
1638
1639t_gotfn zgetfn(t_pd *x, t_symbol *s)
1640{
1641 t_class *c = *x;
1642 t_methodentry *m;
1643 int i;
1644
1645 for (i = c->c_nmethod, m = c->c_methods; i--; m++)
1646 if (m->me_name == s) return(m->me_fun);
1647 return(0);
1648}