From 2b60d55c919e7588f5aff15936e83c300b3660bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Tue, 22 Mar 2005 20:58:25 +0000 Subject: zexy-2.0: - use of abstractions for objects that allow it - some objects are build both as externals and abstractions (as slower fallbacks) - code-layout is now 1:1 c-file<->object (this should allow for building of zexy as a collection of externals instead as a big library) - matrix-objects have moved to iemmatrix !! svn path=/trunk/externals/zexy/; revision=2641 --- src/makesymbol.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/makesymbol.c (limited to 'src/makesymbol.c') diff --git a/src/makesymbol.c b/src/makesymbol.c new file mode 100644 index 0000000..662089a --- /dev/null +++ b/src/makesymbol.c @@ -0,0 +1,146 @@ +/****************************************************** + * + * zexy - implementation file + * + * copyleft (c) IOhannes m zmölnig + * + * 1999:forum::für::umläute:2004 + * + * institute of electronic music and acoustics (iem) + * + ****************************************************** + * + * license: GNU General Public License v.2 + * + ******************************************************/ + + +/* +(l) 1210:forum::für::umläute:1999 + + "makesymbol" is something between "symbol" and "makefilename", thus storing and creating (formatted) + symbols... + +*/ + +#include "zexy.h" + +#include +#include + +#define MAXSTRINGARGS 10 +#define MAXSTRINGLENG 80 + +/* ----------------------- makesymbol --------------------- */ + +static t_class *makesymbol_class; + +typedef struct _makesymbol +{ + t_object x_obj; + t_symbol *x_sym; + + char* mask; + char* buf; +} t_makesymbol; + +static void reset_mask(t_makesymbol *x, t_symbol *s) +{ + if (*s->s_name) { + x->mask = s->s_name; + x->x_sym = s; + } else { + x->mask = "%s%s%s%s%s%s%s%s%s%s"; + x->x_sym = gensym(""); + } +} + +t_symbol* list2symbol(char *masque, int argc, t_atom *argv) +{ + typedef char cstring[MAXSTRINGLENG]; + + cstring buf[MAXSTRINGARGS]; + cstring buffer; + int i; + + for(i=0; ix_sym = list2symbol(x->mask, argc, argv); + outlet_symbol(x->x_obj.ob_outlet, x->x_sym); +} + +static void makesymbol_bang(t_makesymbol *x) +{ + outlet_symbol(x->x_obj.ob_outlet, x->x_sym); +} + + +static void *makesymbol_new(t_symbol *s, int argc, t_atom *argv) +{ + t_makesymbol *x = (t_makesymbol *)pd_new(makesymbol_class); + + x->buf = (char *)getbytes(MAXSTRINGLENG * sizeof(char)); + + x->mask = x->buf; + + if (argc) { + atom_string(argv, x->buf, MAXSTRINGLENG); + x->x_sym = gensym(x->buf); + } else { + x->mask = "%s%s%s%s%s%s%s%s%s%s"; + x->x_sym = gensym(""); + } + + outlet_new(&x->x_obj, &s_symbol); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym("sym1")); + + return (x); +} + +static void makesymbol_free(t_makesymbol *x) +{ + freebytes(x->buf, MAXSTRINGLENG*sizeof(char)); +} + + +static void helper(t_makesymbol *x) +{ + post("\n%c makesymbol :: create a formatted symbol", HEARTSYMBOL); + post("\t: glue up to 10 list-elements to 1 formatted symbol\n" + "'bang'\t\t\t: re-output\n" + "'help'\t\t\t: view this" + "\ninlet2 : : new format-string (symbol !)" + "\noutlet : \t: formatted concatenation"); + post("\ncreation:\"makesymbol []\": C-style format-string (%s only)", "%s"); + +post("\n\nmasq = %s", x->mask); +} + +void makesymbol_setup(void) +{ + makesymbol_class = class_new(gensym("makesymbol"), + (t_newmethod)makesymbol_new, (t_method)makesymbol_free, + sizeof(t_makesymbol), 0, A_GIMME, 0); + + class_addlist(makesymbol_class, makesymbol_list); + class_addbang(makesymbol_class, makesymbol_bang); + + class_addmethod(makesymbol_class, (t_method)reset_mask, gensym("sym1"), A_SYMBOL, 0); + + class_addmethod(makesymbol_class, (t_method)helper, gensym("help"), 0); + class_sethelpsymbol(makesymbol_class, gensym("zexy/makesymbol")); + zexy_register("makesymbol"); +} -- cgit v1.2.1