diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2012-02-16 17:33:59 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2012-02-16 17:33:59 +0000 |
commit | 85d0912d11556a293503f3e9fc97390147a5965f (patch) | |
tree | 05dbf40b10978964cfdf91f6a00e5695963561dc | |
parent | 8c1363b2f4d4c006f97c5fe66c8e01e5b779b911 (diff) |
added [atof]
svn path=/trunk/externals/zexy/; revision=15967
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/atof.c | 81 | ||||
-rw-r--r-- | src/z_zexy.c | 11 | ||||
-rw-r--r-- | src/z_zexy.h | 11 |
4 files changed, 96 insertions, 11 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8ab1f84..a89b3e7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,6 +33,7 @@ pkglib_LTLIBRARIES+= \ abs~.la \ absgn~.la \ atoi.la \ + atof.la \ avg~.la \ blockmirror~.la \ blockshuffle~.la \ @@ -132,6 +133,7 @@ any2list_la_SOURCES = a2l.c abs__la_SOURCES = abs~.c absgn__la_SOURCES = absgn~.c atoi_la_SOURCES = atoi.c +atof_la_SOURCES = atof.c avg__la_SOURCES = avg~.c blockmirror__la_SOURCES = blockmirror~.c blockshuffle__la_SOURCES= blockshuffle~.c @@ -225,7 +227,7 @@ z__la_SOURCES = z~.c zexy_la_SOURCES = zexy.c z_zexy.c \ zexy.h zexySIMD.h z_zexy.h zexyconf.h \ 0x260x260x7e.c 0x2e.c 0x3c0x7e.c 0x3d0x3d0x7e.c 0x3e0x7e.c 0x7c0x7c0x7e.c \ - a2l.c abs~.c absgn~.c atoi.c avg~.c \ + a2l.c abs~.c absgn~.c atoi.c atof.c avg~.c \ blockmirror~.c blockshuffle~.c blockswap~.c \ date.c demultiplex~.c demultiplex.c dfreq~.c dirac~.c drip.c envrms~.c \ fifop.c freadln.c fwriteln.c glue.c index.c length.c lifop.c limiter~.c \ diff --git a/src/atof.c b/src/atof.c new file mode 100644 index 0000000..e49d8a8 --- /dev/null +++ b/src/atof.c @@ -0,0 +1,81 @@ +/* + * atof: ascii to A_FLOAT converter + * + * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include "zexy.h" +#include <stdlib.h> + +static t_class *atof_class; + +typedef struct _atof +{ + t_object x_obj; + t_float f; +} t_atof; +static void atof_bang(t_atof *x) +{ + outlet_float(x->x_obj.ob_outlet, (t_float)x->f); +} +static void atof_float(t_atof *x, t_floatarg f) +{ + x->f = f; + outlet_float(x->x_obj.ob_outlet, (t_float)x->f); +} +static void atof_symbol(t_atof *x, t_symbol *s) +{ + const char* c = s->s_name; + x->f=strtod(c, 0); + outlet_float(x->x_obj.ob_outlet, (t_float)x->f); +} +static void atof_list(t_atof *x, t_symbol *s, int argc, t_atom *argv) +{ + const char* c; + ZEXY_USEVAR(s); + + if (argv->a_type==A_FLOAT){ + x->f=atom_getfloat(argv); + outlet_float(x->x_obj.ob_outlet, (t_float)x->f); + return; + } + + c=atom_getsymbol(argv)->s_name; + x->f=strtod(c, 0); + outlet_float(x->x_obj.ob_outlet, (t_float)x->f); +} + +static void *atof_new(void) +{ + t_atof *x = (t_atof *)pd_new(atof_class); + x->f = 0.; + outlet_new(&x->x_obj, gensym("float")); + return (x); +} + +void atof_setup(void) +{ + atof_class = class_new(gensym("atof"), (t_newmethod)atof_new, 0, + sizeof(t_atof), 0, A_DEFFLOAT, 0); + + class_addbang(atof_class, (t_method)atof_bang); + class_addfloat(atof_class, (t_method)atof_float); + class_addlist(atof_class, (t_method)atof_list); + class_addsymbol(atof_class, (t_method)atof_symbol); + class_addanything(atof_class, (t_method)atof_symbol); + + zexy_register("atof"); +} diff --git a/src/z_zexy.c b/src/z_zexy.c index 6b78079..35e3ba6 100644 --- a/src/z_zexy.c +++ b/src/z_zexy.c @@ -14,16 +14,17 @@ void z_zexy_setup(void) setup_0x3e0x7e(); /* 0x3e0x7e */ setup_0x7c0x7c0x7e(); /* 0x7c0x7c0x7e */ a2l_setup(); /* a2l */ - abs_tilde_setup(); /* abs~ */ absgn_tilde_setup(); /* absgn~ */ + abs_tilde_setup(); /* abs~ */ + atof_setup(); /* atof */ atoi_setup(); /* atoi */ avg_tilde_setup(); /* avg~ */ blockmirror_tilde_setup(); /* blockmirror~ */ blockshuffle_tilde_setup(); /* blockshuffle~ */ blockswap_tilde_setup(); /* blockswap~ */ date_setup(); /* date */ - demultiplex_tilde_setup(); /* demultiplex~ */ demultiplex_setup(); /* demultiplex */ + demultiplex_tilde_setup(); /* demultiplex~ */ dfreq_tilde_setup(); /* dfreq~ */ dirac_tilde_setup(); /* dirac~ */ drip_setup(); /* drip */ @@ -49,16 +50,16 @@ void z_zexy_setup(void) minmax_setup(); /* minmax */ msgfile_setup(); /* msgfile */ multiline_tilde_setup(); /* multiline~ */ - multiplex_tilde_setup(); /* multiplex~ */ multiplex_setup(); /* multiplex */ + multiplex_tilde_setup(); /* multiplex~ */ multireceive_setup(); /* multireceive */ niagara_setup(); /* niagara */ noish_tilde_setup(); /* noish~ */ noisi_tilde_setup(); /* noisi~ */ operating_system_setup(); /* operating_system */ - pack_tilde_setup(); /* pack~ */ pack_setup(); /* pack */ packel_setup(); /* packel */ + pack_tilde_setup(); /* pack~ */ pdf_tilde_setup(); /* pdf~ */ prime_setup(); /* prime */ quantize_tilde_setup(); /* quantize~ */ @@ -85,8 +86,8 @@ void z_zexy_setup(void) tabset_setup(); /* tabset */ tavg_tilde_setup(); /* tavg~ */ time_setup(); /* time */ - unpack_tilde_setup(); /* unpack~ */ unpack_setup(); /* unpack */ + unpack_tilde_setup(); /* unpack~ */ urn_setup(); /* urn */ wrap_setup(); /* wrap */ z_tilde_setup(); /* z~ */ diff --git a/src/z_zexy.h b/src/z_zexy.h index c1eb3af..c35e767 100644 --- a/src/z_zexy.h +++ b/src/z_zexy.h @@ -12,16 +12,17 @@ void setup_0x3d0x3d0x7e(void); /* 0x3d0x3d0x7e */ void setup_0x3e0x7e(void); /* 0x3e0x7e */ void setup_0x7c0x7c0x7e(void); /* 0x7c0x7c0x7e */ void a2l_setup(void); /* a2l */ -void abs_tilde_setup(void); /* abs~ */ void absgn_tilde_setup(void); /* absgn~ */ +void abs_tilde_setup(void); /* abs~ */ +void atof_setup(void); /* atof */ void atoi_setup(void); /* atoi */ void avg_tilde_setup(void); /* avg~ */ void blockmirror_tilde_setup(void); /* blockmirror~ */ void blockshuffle_tilde_setup(void); /* blockshuffle~ */ void blockswap_tilde_setup(void); /* blockswap~ */ void date_setup(void); /* date */ -void demultiplex_tilde_setup(void); /* demultiplex~ */ void demultiplex_setup(void); /* demultiplex */ +void demultiplex_tilde_setup(void); /* demultiplex~ */ void dfreq_tilde_setup(void); /* dfreq~ */ void dirac_tilde_setup(void); /* dirac~ */ void drip_setup(void); /* drip */ @@ -47,16 +48,16 @@ void mavg_setup(void); /* mavg */ void minmax_setup(void); /* minmax */ void msgfile_setup(void); /* msgfile */ void multiline_tilde_setup(void); /* multiline~ */ -void multiplex_tilde_setup(void); /* multiplex~ */ void multiplex_setup(void); /* multiplex */ +void multiplex_tilde_setup(void); /* multiplex~ */ void multireceive_setup(void); /* multireceive */ void niagara_setup(void); /* niagara */ void noish_tilde_setup(void); /* noish~ */ void noisi_tilde_setup(void); /* noisi~ */ void operating_system_setup(void); /* operating_system */ -void pack_tilde_setup(void); /* pack~ */ void pack_setup(void); /* pack */ void packel_setup(void); /* packel */ +void pack_tilde_setup(void); /* pack~ */ void pdf_tilde_setup(void); /* pdf~ */ void prime_setup(void); /* prime */ void quantize_tilde_setup(void); /* quantize~ */ @@ -83,8 +84,8 @@ void tabread4_tilde_tilde_setup(void); /* tabread4~~ */ void tabset_setup(void); /* tabset */ void tavg_tilde_setup(void); /* tavg~ */ void time_setup(void); /* time */ -void unpack_tilde_setup(void); /* unpack~ */ void unpack_setup(void); /* unpack */ +void unpack_tilde_setup(void); /* unpack~ */ void urn_setup(void); /* urn */ void wrap_setup(void); /* wrap */ void z_tilde_setup(void); /* z~ */ |