diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 146 | ||||
-rw-r--r-- | src/any2string.c | 210 | ||||
-rw-r--r-- | src/pdstring-help.pd | 59 | ||||
-rw-r--r-- | src/pdstring.c | 99 | ||||
-rw-r--r-- | src/string2any.c | 181 |
5 files changed, 695 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..2ff35cd --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,146 @@ +# File: ./src/Makefile.am +# Package: pdstring +# Description: +# + src-level automake file +# +# Process this file with Automake to create Makefile.in. +#----------------------------------------------------------------------- + +#----------------------------------------------------------------------- +# Options & Subdirectories +#----------------------------------------------------------------------- + +## --- recursion subdirectories +#SUBDIRS = + +## --- pseudo-deps for '.SUFFIXES' +SUFFIXES = .@PDEXT@ + +#----------------------------------------------------------------------- +# Flags and variables +#----------------------------------------------------------------------- +PDEXT = @PDEXT@ +EXEEXT = .@PDEXT@ + +#----------------------------------------------------------------------- +# pd externals (hacked _PROGRAMS target) +#----------------------------------------------------------------------- + +## --- externals +pdexterns_PROGRAMS = @PD_OBJECT_EXTERNALS@ + +## --- possible externals +EXTRA_PROGRAMS = \ + pdstring \ + any2string \ + string2any + +## --- patches +pdexterns_DATA = + +## --- documentation +pddoc_DATA = pdstring-help.pd + + +#----------------------------------------------------------------------- +# sources +#----------------------------------------------------------------------- + +pdstring_SOURCES = \ + any2string.c \ + string2any.c \ + pdstring.c + +any2string_SOURCES = any2string.c + +string2any_SOURCES = string2any.c + +#----------------------------------------------------------------------- +# external compilation : flags +#----------------------------------------------------------------------- +DEFS = @DEFS@ +AFLAGS = @AFLAGS@ +DFLAGS = @DFLAGS@ +IFLAGS = @IFLAGS@ +LFLAGS = @LFLAGS@ +OFLAGS = @OFLAGS@ +WFLAGS = -Wall -Winline + +#GLIB_IFLAGS = @GLIB_IFLAGS@ +#GLIB_LFLAGS = @GLIB_LFLAGS@ + +AM_CPPFLAGS = $(IFLAGS) $(GLIB_IFLAGS) $(DFLAGS) +AM_CFLAGS = $(OFLAGS) $(WFLAGS) $(AFLAGS) + +pdstring_LDFLAGS = $(LFLAGS) + +string2any_LDFLAGS = $(LFLAGS) + +any2string_LDFLAGS = $(LFLAGS) + +#----------------------------------------------------------------------- +# Variables: cleanup +#----------------------------------------------------------------------- +## --- mostlyclean: built by 'make' & commonly rebuilt +#MOSTLYCLEANFILES = + +## --- clean: built by 'make' +CLEANFILES = *$(EXEEXT) + +## --- distclean: built by 'configure' +DISTCLEANFILES = \ + config.log \ + config.cache \ + config.status + +## -- maintainerclean: built by maintainer / by hand +MAINTAINERCLEANFILES = *~ \ + $(PODS:.pod=.txt) \ + Makefile Makefile.in \ + aclocal.m4 \ + configure \ + install-sh \ + stamp-h.in \ + config.h.in + +maintainer-clean-local: + rm -rf autom4te.cache + +#CVSCLEAN_SUBDIRS = $(SUBDIRS) + +#CVSCLEANFILES = Makefile.in Makefile + + +#----------------------------------------------------------------------- +# Variables: distribution +#----------------------------------------------------------------------- + +## --- extra distribution files +EXTRA_DIST = \ + $(pddoc_DATA) \ + $(pdexterns_DATA) + +## --- recursion subdirectories for 'make dist' +DIST_SUBDIRS = $(SUBDIRS) + +## --- dist-hook: when another 'Makefile.am' is overkill +#DISTHOOK_DIRS = foo +#DISTHOOK_FILES = foo/bar.txt foo/baz.txt +#dist-hook: +# for d in $(DISTHOOK_DIRS); do\ +# mkdir -p $(distdir)/$$d ;\ +# done +# for f in $(DISTHOOK_FILES); do\ +# cp -p $(srcdir)/$$f $(distdir)/$$f ;\ +# done + +#dist-bz2: dist-bzip2 ; + + +#----------------------------------------------------------------------- +# Rules: cleanup +#----------------------------------------------------------------------- +.PHONY: cvsclean cvsclean-hook + +cvsclean: maintainer-clean ; + diff --git a/src/any2string.c b/src/any2string.c new file mode 100644 index 0000000..3bcaa3a --- /dev/null +++ b/src/any2string.c @@ -0,0 +1,210 @@ +/* -*- Mode: C -*- */ +/*=============================================================================*\ + * File: any2string.c + * Author: Bryan Jurish <moocow@ling.uni-potsdam.de> + * Description: convert pd messages to strings + * + * Copyright (c) 2004 Bryan Jurish. + * + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file "COPYING", in this distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *=============================================================================*/ + +#include <string.h> + +#include <m_pd.h> + +/* black magic */ +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/*-------------------------------------------------------------------- + * DEBUG + *--------------------------------------------------------------------*/ +//#define ANY2STRING_DEBUG 1 + +#ifdef ANY2STRING_DEBUG +# define A2SDEBUG(x) x +#else +# define A2SDEBUG(x) +#endif + +#define ANY2STRING_INITIAL_BUFLEN 32 + + +/*===================================================================== + * Structures and Types: any2string + *=====================================================================*/ +static t_class *any2string_class; + +typedef struct _any2string +{ + t_object x_obj; + int x_alloc; + int x_argc; + t_atom *x_argv; + t_binbuf *x_binbuf; + t_outlet *x_outlet; +} t_any2string; + + +/*===================================================================== + * Constants + *=====================================================================*/ + +/*===================================================================== + * Methods + *=====================================================================*/ + +/*-------------------------------------------------------------------- + * anything + */ +static void any2string_anything(t_any2string *x, t_symbol *sel, int argc, t_atom *argv) +{ + t_atom *a; + char *text, *s; + int len; + + A2SDEBUG(post("-------any2string_anything()---------")); + + /*-- set up binbuf --*/ + A2SDEBUG(post("any2string: binbuf_clear()")); + binbuf_clear(x->x_binbuf); + A2SDEBUG(post("any2string: binbuf_add()")); + binbuf_add(x->x_binbuf, argc, argv); + A2SDEBUG(binbuf_print(x->x_binbuf)); + + A2SDEBUG(post("any2string: binbuf_gettext()")); + binbuf_gettext(x->x_binbuf, &text, &len); + A2SDEBUG(post("any2string: binbuf_gettext() = \"%s\" ; len=%d", text, len)); + text[len] = 0; + + /*-- get string length --*/ + x->x_argc = len+1; + if (sel != &s_float && sel != &s_list && sel != &s_) { + x->x_argc += strlen(sel->s_name); + if (argc > 0) x->x_argc++; + } + A2SDEBUG(post("any2string: argc=%d", x->x_argc)); + + /*-- (re-)allocate --*/ + if (x->x_alloc < x->x_argc) { + A2SDEBUG(post("any2string: reallocate(%d->%d)", x->x_alloc, x->x_argc)); + freebytes(x->x_argv, x->x_alloc * sizeof(t_atom)); + x->x_argv = (t_atom *)getbytes(x->x_argc * sizeof(t_atom)); + x->x_alloc = x->x_argc; + } + + /*-- add selector --*/ + a=x->x_argv; + if (sel != &s_float && sel != &s_list && sel != &s_) { + A2SDEBUG(post("any2string: for {...} //sel")); + for (s=sel->s_name; *s; s++, a++) { + A2SDEBUG(post("any2string: for: SETFLOAT(a,'%c'=%d) //sel", *s, *s)); + SETFLOAT(a,*s); + } + A2SDEBUG(post("any2string: /for {...} //sel")); + + if (argc > 0) { + SETFLOAT(a,' '); + a++; + } + } + + /*-- add binbuf text --*/ + A2SDEBUG(post("any2string: for {...}")); + for (s=text; *s; s++, a++) { + A2SDEBUG(post("any2string: for: //SETFLOAT(a,'%c'=%d)", *s, *s)); + SETFLOAT(a,*s); + } + A2SDEBUG(post("any2string: /for {...}")); + + /*-- add terminating NUL --*/ + SETFLOAT(a,0); + + A2SDEBUG(post("any2string: freebytes()")); + freebytes(text, strlen(text)); + + /* + A2SDEBUG(post("any2string: binbuf_free()")); + binbuf_free(x->x_binbuf); + */ + + A2SDEBUG(post("any2string: outlet_list(..., %d, ...)", x->x_argc)); + outlet_list(x->x_outlet, &s_list, x->x_argc, x->x_argv); +} + + +/*-------------------------------------------------------------------- + * new + */ +static void *any2string_new(void) +{ + t_any2string *x = (t_any2string *)pd_new(any2string_class); + + //-- defaults + x->x_alloc = ANY2STRING_INITIAL_BUFLEN; + x->x_argc = 0; + x->x_argv = (t_atom *)getbytes(x->x_alloc * sizeof(t_atom)); + x->x_binbuf = binbuf_new(); + + //-- outlets + x->x_outlet = outlet_new(&x->x_obj, &s_list); + + return (void *)x; +} + +/*-------------------------------------------------------------------- + * free + */ +static void any2string_free(t_any2string *x) +{ + if (x->x_argv) { + freebytes(x->x_argv, x->x_alloc * sizeof(t_atom)); + x->x_argv = NULL; + } + binbuf_free(x->x_binbuf); + outlet_free(x->x_outlet); + return; +} + +/*-------------------------------------------------------------------- + * setup + */ +void any2string_setup(void) +{ + //-- class + any2string_class = class_new(gensym("any2string"), + (t_newmethod)any2string_new, + (t_method)any2string_free, + sizeof(t_any2string), + CLASS_DEFAULT, + 0); + + //-- methods + /*class_addmethod(any2string_class, (t_method)any2string_symbol, &s_symbol, + A_DEFSYMBOL, 0); + */ + class_addanything(any2string_class, + (t_method)any2string_anything); + + + //-- help symbol + class_sethelpsymbol(any2string_class, gensym("pdstring-help.pd")); +} diff --git a/src/pdstring-help.pd b/src/pdstring-help.pd new file mode 100644 index 0000000..e83b9db --- /dev/null +++ b/src/pdstring-help.pd @@ -0,0 +1,59 @@ +#N canvas 381 42 563 311 10; +#X text 258 284 Bryan Jurish <moocow@ling.uni-potsdam.de>; +#X floatatom 56 81 8 0 0 0 - - -; +#X symbolatom 46 59 10 0 0 0 - - -; +#X text 201 59 ... no special handling for symbols; +#X text 200 37 anything can be converted to a list...; +#X obj 383 3 pdstring; +#X text 54 3 any2string \, string2any : ASCII conversions in; +#X obj 37 108 any2string; +#X obj 37 230 string2any; +#X floatatom 54 178 4 0 0 0 - - -; +#X text 213 230 string2any converts ASCII lists to Pd messages...; +#X text 202 81 ... but "float" selector is silently dropped; +#N canvas 0 0 448 335 ascii-table 0; +#X obj 162 144 f 0; +#X obj 134 153 + 1; +#X obj 161 165 t f f f; +#X obj 133 198 string2any; +#X obj 154 243 pack s 0; +#X obj 162 119 until; +#X obj 133 218 symbol; +#X msg 162 84 256; +#X msg 208 119 0; +#X obj 162 23 inlet; +#X obj 162 54 t b b; +#X obj 154 266 route list; +#X obj 154 293 print charset; +#X connect 0 0 2 0; +#X connect 1 0 0 1; +#X connect 2 0 1 0; +#X connect 2 1 3 0; +#X connect 2 2 4 1; +#X connect 3 0 6 0; +#X connect 4 0 11 0; +#X connect 5 0 0 0; +#X connect 6 0 4 0; +#X connect 7 0 5 0; +#X connect 8 0 0 1; +#X connect 9 0 10 0; +#X connect 10 0 7 0; +#X connect 10 1 8 0; +#X connect 11 0 12 0; +#X connect 11 1 12 0; +#X restore 249 144 pd ascii-table; +#X msg 249 121 bang; +#X text 361 143 know your charset; +#X obj 58 139 print any2string-out; +#X obj 37 254 print string2any-out; +#X msg 37 38 A B C; +#X msg 55 199 list 49 50 51; +#X connect 1 0 7 0; +#X connect 2 0 7 0; +#X connect 7 0 15 0; +#X connect 7 0 8 0; +#X connect 8 0 16 0; +#X connect 9 0 8 0; +#X connect 13 0 12 0; +#X connect 17 0 7 0; +#X connect 18 0 8 0; diff --git a/src/pdstring.c b/src/pdstring.c new file mode 100644 index 0000000..c77b68e --- /dev/null +++ b/src/pdstring.c @@ -0,0 +1,99 @@ +/* -*- Mode: C -*- */ +/*=============================================================================*\ + * File: pdstring.c + * Author: Bryan Jurish <moocow@ling.uni-potsdam.de> + * Description: pd string conversions : library + * + * Copyright (c) 2004-2006 Bryan Jurish. + * + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file "COPYING", in this distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *=============================================================================*/ +#include <m_pd.h> + +/* black magic */ +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/*===================================================================== + * Constants + *=====================================================================*/ +static char *pdstring_version = "\npdstring version " PACKAGE_VERSION " by Bryan Jurish"; + +/*===================================================================== + * Structures and Types: pdstring [dummy] + *=====================================================================*/ +static t_class *pdstring_class; + +typedef struct _pdstring +{ + t_object x_obj; +} t_pdstring; + + +/*===================================================================== + * External declarations + *=====================================================================*/ +extern void any2string_setup(void); +extern void string2any_setup(void); + +/*-------------------------------------------------------------------- + * new + */ +static void *pdstring_new(void) +{ + t_pdstring *x = (t_pdstring *)pd_new(pdstring_class); + return x; +} + +/*-------------------------------------------------------------------- + * help + */ +static void pdstring_help(t_pdstring *x) +{ + post(pdstring_version); +} + +/*===================================================================== + * Setup + *=====================================================================*/ +void pdstring_setup(void) +{ + post(pdstring_version); + + any2string_setup(); + string2any_setup(); + + pdstring_class = class_new(gensym("pdstring"), + (t_newmethod)pdstring_new, + 0, + sizeof(t_pdstring), + CLASS_DEFAULT, + 0); + + //-- help method + class_addmethod(pdstring_class, (t_method)pdstring_help, gensym("help"), A_NULL); + + //-- help symbol + class_sethelpsymbol(pdstring_class, gensym("pdstring-help.pd")); +} diff --git a/src/string2any.c b/src/string2any.c new file mode 100644 index 0000000..93756ec --- /dev/null +++ b/src/string2any.c @@ -0,0 +1,181 @@ +/* -*- Mode: C -*- */ +/*=============================================================================*\ + * File: string2any.c + * Author: Bryan Jurish <moocow@ling.uni-potsdam.de> + * Description: convert strings to pd messages + * + * Copyright (c) 2004 Bryan Jurish. + * + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file "COPYING", in this distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *=============================================================================*/ + +#include <string.h> + +#include <m_pd.h> + +/* black magic */ +#ifdef NT +#pragma warning( disable : 4244 ) +#pragma warning( disable : 4305 ) +#endif + +/*-------------------------------------------------------------------- + * DEBUG + *--------------------------------------------------------------------*/ +//#define STRING2ANY_DEBUG 1 + +#ifdef STRING2ANY_DEBUG +# define S2ADEBUG(x) x +#else +# define S2ADEBUG(x) +#endif + +#define STRING2ANY_INITIAL_BUFLEN 32 + + +/*===================================================================== + * Constants + *=====================================================================*/ + +/*===================================================================== + * Structures and Types: any2string + *=====================================================================*/ + +static t_class *string2any_class; + +typedef struct _string2any +{ + t_object x_obj; + size_t x_size; + char *x_text; + t_binbuf *x_binbuf; + t_outlet *x_outlet; +} t_string2any; + + +/*===================================================================== + * Constants + *=====================================================================*/ + +/*===================================================================== + * Methods + *=====================================================================*/ + +/*-------------------------------------------------------------------- + * anything + */ +static void string2any_anything(t_string2any *x, t_symbol *sel, int argc, t_atom *argv) +{ + char *s; + int x_argc; + t_atom *x_argv; + + /*-- allocate --*/ + if (x->x_size <= argc) { + freebytes(x->x_text, x->x_size*sizeof(char)); + x->x_size = argc+1; + x->x_text = (char *)getbytes(x->x_size * sizeof(char)); + } + + /*-- get text --*/ + for (s=x->x_text; argc > 0; argc--, argv++, s++) { + *s = atom_getfloat(argv); + } + *s = 0; + S2ADEBUG(post("string2any: text: \"%s\"", x->x_text)); + + /*-- clear and fill binbuf --*/ + binbuf_clear(x->x_binbuf); + binbuf_text(x->x_binbuf, x->x_text, strlen(x->x_text)); + S2ADEBUG(startpost("string2any: buf: ")); + S2ADEBUG(binbuf_print(x->x_binbuf)); + + /*-- output --*/ + x_argc = binbuf_getnatom(x->x_binbuf); + x_argv = binbuf_getvec(x->x_binbuf); + if (x_argc && x_argv->a_type == A_SYMBOL) { + outlet_anything(x->x_outlet, + x_argv->a_w.w_symbol, + x_argc-1, + x_argv+1); + } + else { + outlet_anything(x->x_outlet, + &s_list, + x_argc, + x_argv); + } +} + + +/*-------------------------------------------------------------------- + * new + */ +static void *string2any_new(void) +{ + t_string2any *x = (t_string2any *)pd_new(string2any_class); + + //-- defaults + x->x_binbuf = binbuf_new(); + x->x_size = STRING2ANY_INITIAL_BUFLEN; + x->x_text = (char *)getbytes(x->x_size * sizeof(char)); + + //-- outlets + x->x_outlet = outlet_new(&x->x_obj, &s_list); + + return (void *)x; +} + +/*-------------------------------------------------------------------- + * free + */ +static void string2any_free(t_string2any *x) +{ + if (x->x_text) { + freebytes(x->x_text, x->x_size * sizeof(char)); + x->x_text = NULL; + } + binbuf_free(x->x_binbuf); + outlet_free(x->x_outlet); + return; +} + +/*-------------------------------------------------------------------- + * setup + */ +void string2any_setup(void) +{ + //-- class + string2any_class = class_new(gensym("string2any"), + (t_newmethod)string2any_new, + (t_method)string2any_free, + sizeof(t_string2any), + CLASS_DEFAULT, + 0); + + //-- methods + /*class_addmethod(string2any_class, (t_method)string2any_symbol, &s_symbol, + A_DEFSYMBOL, 0); + */ + class_addanything(string2any_class, + (t_method)string2any_anything); + + + //-- help symbol + class_sethelpsymbol(string2any_class, gensym("pdstring-help.pd")); +} |