From 50a389bea35a91ddae1394c5d35a6f1c703f5bdd Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 9 Mar 2004 03:51:28 +0000 Subject: Checked in Olaf's 1.5.2 sources. Here are the changes: v 1.5.2 (17. december 2003): - modified netclient for not to drop received data: use of syspollfn instead of clock to poll for incoming data, circular recv buffer v 1.5 (18. october 2003): - added some usefull features to arraycopy (i.e. copying just parts of an array and copying to specified position in destination array) - new object: nchange - IRIX 6.5 port (for GCC 3.3) - OS X binary (Jaguar 10.2.6) v 1.4 (22. may 2003): - updated sources to compile with Pd0.37-test4 - new object: arraycopy v 1.3 (12. april 2003): - new objects: sync listfifo - all setup routines renamed to maxlib__setup() to avoid name clashes, old names still work via class_addcreator() - some improvements for the help files svn path=/trunk/externals/maxlib/; revision=1394 --- src/allow.c | 14 ++--- src/arbran.c | 27 ++------ src/arraycopy.c | 26 ++++---- src/beta.c | 18 +++--- src/chord.c | 4 ++ src/deny.c | 14 ++--- src/expo.c | 10 +-- src/fifo.c | 2 +- src/gestalt.c | 3 + src/lifo.c | 2 +- src/linear.c | 10 +-- src/listfifo.c | 2 +- src/mlife.c | 2 +- src/nchange.c | 2 +- src/netclient.c | 184 +++++++++++++++++++++++++++++++----------------------- src/netrec.c | 4 +- src/netserver.c | 4 +- src/nroute.c | 92 +++++++++++++-------------- src/pitch.c | 2 +- src/plus.c | 2 +- src/poisson.c | 10 +-- src/pong.c | 14 ++--- src/pulse.c | 2 +- src/remote.c | 2 +- src/rewrap.c | 2 +- src/rhythm.c | 3 + src/score.c | 2 +- src/step.c | 2 +- src/subst.c | 2 +- src/sync.c | 2 +- src/temperature.c | 2 +- src/tilt.c | 2 +- src/triang.c | 10 +-- src/unroute.c | 2 +- src/urn.c | 8 +-- 35 files changed, 255 insertions(+), 234 deletions(-) (limited to 'src') diff --git a/src/allow.c b/src/allow.c index c5d57ac..f835dc5 100644 --- a/src/allow.c +++ b/src/allow.c @@ -27,12 +27,12 @@ static char *version = "allow v0.1, written by Olaf Matthes "; -typedef struct allow -{ +typedef struct allow +{ t_object x_obj; t_outlet *x_out; t_atom *x_elem; // list of elemets that are allowed to pass - t_int x_numelem; // the number of elemetns in our allow-list + t_int x_numelem; // the number of elemetns in our allow-list } t_allow; /* we got a symbol... */ @@ -73,7 +73,7 @@ static void allow_free(t_allow *x) } static void *allow_new(t_symbol *s, int argc, t_atom *argv) -{ +{ t_allow *x = (t_allow *)pd_new(allow_class); x->x_numelem = argc; // get the number of elements @@ -84,10 +84,10 @@ static void *allow_new(t_symbol *s, int argc, t_atom *argv) // post("allow: got %d elements", x->x_numelem); - return (x); + return (x); } -#ifndef MAXLIB +#ifndef MAXLIB void allow_setup(void) { /* the object's class: */ @@ -109,4 +109,4 @@ void maxlib_allow_setup(void) #else class_sethelpsymbol(allow_class, gensym("maxlib/help-allow.pd")); #endif -} \ No newline at end of file +} diff --git a/src/arbran.c b/src/arbran.c index cb39963..ba19976 100644 --- a/src/arbran.c +++ b/src/arbran.c @@ -58,14 +58,7 @@ static void rand_arbran_pdfscale(t_rand_arbran *x) t_int k = 0; t_float *tx, *tp; t_int ix, ip; - - if(!bx || !bp) - { - post("arbran: no arrays: pdfscale!"); - return; - } - - if (!garray_getfloatarray(bx, &ix, &tx)) + if (!garray_getfloatarray(bx, &ix, &tx)) { post("arbran: couldn't read from array!"); return; @@ -94,19 +87,11 @@ static void rand_arbran_bang(t_rand_arbran *x) t_int k = 0; t_float *tx, *tp; t_int ix, ip; - - if(!bx || !bp) - { - post("arbran: no arrays: bang!"); - return; - } - - if (!garray_getfloatarray(bx, &ix, &tx)) + if (!garray_getfloatarray(bx, &ix, &tx)) { post("arbran: couldn't read from array!"); return; } - if (!garray_getfloatarray(bp, &ip, &tp)) { post("arbran: couldn't read from array!"); @@ -114,6 +99,7 @@ static void rand_arbran_bang(t_rand_arbran *x) } a = 0; + a0 = 0; u = fran(); while(u > a) { @@ -173,10 +159,9 @@ static void *rand_arbran_new(t_symbol *s1, t_symbol *s2) t_rand_arbran *x = (t_rand_arbran *)pd_new(rand_arbran_class); srand( (unsigned)time( NULL ) ); outlet_new(&x->x_obj, &s_float); - rand_arbran_setarrays(x, s1, s2); - /* x->x_x = s1; - x->x_p = s2; - rand_arbran_set(x); */ + x->x_x = s1; + x->x_p = s2; + rand_arbran_set(x); return (x); } diff --git a/src/arraycopy.c b/src/arraycopy.c index cc36913..b71f7f3 100644 --- a/src/arraycopy.c +++ b/src/arraycopy.c @@ -27,9 +27,9 @@ static char *version = "arraycopy v0.2, written by Olaf Matthes "; -typedef struct arraycopy -{ - t_object x_obj; +typedef struct arraycopy +{ + t_object x_obj; t_symbol *x_destarray; t_symbol *x_sourcearray; t_garray *x_destbuf; @@ -78,7 +78,7 @@ static void arraycopy_setsourcearray(t_arraycopy *x, t_symbol *s) /* this is the routine that actually does the copying */ /* get's called directly when we get a 'bang' */ -static void arraycopy_docopy(t_arraycopy *x) +static void arraycopy_docopy(t_arraycopy *x) { t_garray *b; /* make local copy of array */ t_float *tab; /* the content itselfe */ @@ -147,8 +147,8 @@ static void arraycopy_docopy(t_arraycopy *x) if(x->x_print)post("arraycopy: copied %d values from array \"%s\" to array \"%s\"", x->x_end-x->x_start, x->x_sourcearray->s_name, x->x_destarray->s_name); } -} - +} + static void arraycopy_list(t_arraycopy *x, t_symbol *s, int argc, t_atom *argv) { if(argc > 1) { @@ -242,19 +242,19 @@ static void arraycopy_copy(t_arraycopy *x, t_symbol *s, int argc, t_atom *argv) static t_class *arraycopy_class; static void *arraycopy_new(t_symbol *s, int argc, t_atom *argv) -{ +{ t_arraycopy *x = (t_arraycopy *)pd_new(arraycopy_class); - if (argc > 0) { + if (argc > 0) { x->x_destarray = atom_getsymbolarg(0, argc, argv); - arraycopy_setdestarray(x, x->x_destarray); + arraycopy_setdestarray(x, x->x_destarray); } inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("symbol"), gensym("dest")); - x->x_start = x->x_end = x->x_pos = x->x_print = 0; - return (x); + x->x_start = x->x_end = x->x_pos = x->x_print = 0; + return (x); } -#ifndef MAXLIB +#ifndef MAXLIB void arraycopy_setup(void) { /* the object's class: */ @@ -280,4 +280,4 @@ void maxlib_arraycopy_setup(void) #else class_sethelpsymbol(arraycopy_class, gensym("maxlib/help-arraycopy.pd")); #endif -} \ No newline at end of file +} diff --git a/src/beta.c b/src/beta.c index ebc7a14..391dc48 100644 --- a/src/beta.c +++ b/src/beta.c @@ -22,8 +22,8 @@ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */ - -#include "m_pd.h" + +#include "m_pd.h" #include #include #include @@ -32,10 +32,10 @@ #ifndef M_PI #define M_PI 3.1415927 #endif - + static char *version = "beta v0.1, generates a beta distributed random variable\n" " written by Olaf Matthes "; - + /* -------------------------- rand_beta ------------------------------ */ static t_class *rand_beta_class; @@ -61,7 +61,7 @@ static void *rand_beta_new(t_floatarg a, t_floatarg b) static void rand_beta_bang(t_rand_beta *x) { - t_float u1, u2, y1, y2, sum, a, b, ainv, binv; + t_float u1, u2, y01, y2, sum, a, b, ainv, binv; a = (x->x_a <= 0 ? 0.0001 : x->x_a); b = (x->x_b <= 0 ? 0.0001 : x->x_b); ainv = 1/a; @@ -78,12 +78,12 @@ static void rand_beta_bang(t_rand_beta *x) u2 = fran(); } while(u2 == 0); - y1 = pow(u1, ainv); + y01 = pow(u1, ainv); y2 = pow(u2, binv); - sum = y1 + y2; + sum = y01 + y2; } while(sum > 1); - outlet_float(x->x_obj.ob_outlet, y1/sum); + outlet_float(x->x_obj.ob_outlet, y01/sum); } #ifndef MAXLIB @@ -104,4 +104,4 @@ void maxlib_beta_setup(void) class_addcreator((t_newmethod)rand_beta_new, gensym("beta"), A_DEFFLOAT, A_DEFFLOAT, 0); class_sethelpsymbol(rand_beta_class, gensym("maxlib/help-beta.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/chord.c b/src/chord.c index f0dc4a3..670ac0a 100644 --- a/src/chord.c +++ b/src/chord.c @@ -25,6 +25,10 @@ #include "m_pd.h" #include #include +#ifdef UNIX +#include +#endif + #define MAX_POLY 32 /* maximum number of notes played at a time */ diff --git a/src/deny.c b/src/deny.c index 9d0ef35..d447adc 100644 --- a/src/deny.c +++ b/src/deny.c @@ -27,12 +27,12 @@ static char *version = "deny v0.1, written by Olaf Matthes "; -typedef struct deny -{ +typedef struct deny +{ t_object x_obj; t_outlet *x_out; t_atom *x_elem; // list of elemets that are denyed to pass - t_int x_numelem; // the number of elemetns in our deny-list + t_int x_numelem; // the number of elemetns in our deny-list } t_deny; /* we got a symbol... */ @@ -75,7 +75,7 @@ static void deny_free(t_deny *x) } static void *deny_new(t_symbol *s, int argc, t_atom *argv) -{ +{ t_deny *x = (t_deny *)pd_new(deny_class); x->x_numelem = argc; // get the number of elements @@ -86,10 +86,10 @@ static void *deny_new(t_symbol *s, int argc, t_atom *argv) // post("deny: got %d elements", x->x_numelem); - return (x); + return (x); } -#ifndef MAXLIB +#ifndef MAXLIB void deny_setup(void) { /* the object's class: */ @@ -111,4 +111,4 @@ void maxlib_deny_setup(void) #else class_sethelpsymbol(deny_class, gensym("maxlib/help-deny.pd")); #endif -} \ No newline at end of file +} diff --git a/src/expo.c b/src/expo.c index 7100417..7ba78cb 100644 --- a/src/expo.c +++ b/src/expo.c @@ -22,17 +22,17 @@ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */ - -#include "m_pd.h" + +#include "m_pd.h" #include #include #include #define fran() (t_float)rand()/(t_float)RAND_MAX - + static char *version = "expo v0.1, generates exponentially distributed random variable\n" " written by Olaf Matthes "; - + /* -------------------------- rand_expo ------------------------------ */ static t_class *rand_expo_class; @@ -83,4 +83,4 @@ void maxlib_expo_setup(void) class_addcreator((t_newmethod)rand_expo_new, gensym("expo"), A_DEFFLOAT, 0); class_sethelpsymbol(rand_expo_class, gensym("maxlib/help-expo.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/fifo.c b/src/fifo.c index c0f73be..246205e 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -93,4 +93,4 @@ void maxlib_fifo_setup(void) class_addbang(fifo_class, fifo_bang); class_sethelpsymbol(fifo_class, gensym("maxlib/help-fifo.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/gestalt.c b/src/gestalt.c index 650efdb..b8e0af8 100644 --- a/src/gestalt.c +++ b/src/gestalt.c @@ -25,6 +25,9 @@ #include "m_pd.h" #include #include +#ifdef UNIX +#include +#endif static char *version = "gestalt v0.1, written by Olaf Matthes "; diff --git a/src/lifo.c b/src/lifo.c index d2983e4..beb0eda 100644 --- a/src/lifo.c +++ b/src/lifo.c @@ -104,4 +104,4 @@ void maxlib_lifo_setup(void) class_addmethod(lifo_class, (t_method)lifo_clear, gensym("clear"), 0); class_sethelpsymbol(lifo_class, gensym("maxlib/help-lifo.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/linear.c b/src/linear.c index a5869a2..cbac438 100644 --- a/src/linear.c +++ b/src/linear.c @@ -22,17 +22,17 @@ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */ - -#include "m_pd.h" + +#include "m_pd.h" #include #include #include #define fran() (t_float)rand()/(t_float)RAND_MAX - + static char *version = "linear v0.1, generates linearly distributed random variable\n" " written by Olaf Matthes "; - + /* -------------------------- rand_linear ------------------------------ */ static t_class *rand_linear_class; @@ -78,4 +78,4 @@ void maxlib_linear_setup(void) class_addbang(rand_linear_class, rand_linear_bang); class_sethelpsymbol(rand_linear_class, gensym("maxlib/help-linear.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/listfifo.c b/src/listfifo.c index dda9eeb..5daf908 100644 --- a/src/listfifo.c +++ b/src/listfifo.c @@ -106,4 +106,4 @@ void maxlib_listfifo_setup(void) class_addlist(listfifo_class, listfifo_list); class_sethelpsymbol(listfifo_class, gensym("maxlib/help-listfifo.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/mlife.c b/src/mlife.c index 47960dd..f592672 100644 --- a/src/mlife.c +++ b/src/mlife.c @@ -512,4 +512,4 @@ void maxlib_mlife_setup(void) class_addbang(mlife_class, ml_bang); class_sethelpsymbol(mlife_class, gensym("maxlib/help-mlife.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/nchange.c b/src/nchange.c index a7e7eb5..4f4c2fe 100644 --- a/src/nchange.c +++ b/src/nchange.c @@ -202,4 +202,4 @@ void maxlib_nchange_setup(void) class_addmethod(nchange_class, (t_method)nchange_set, gensym("set"), A_GIMME, 0); class_sethelpsymbol(nchange_class, gensym("maxlib/help-nchange.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/netclient.c b/src/netclient.c index 406ae19..35658ba 100644 --- a/src/netclient.c +++ b/src/netclient.c @@ -22,14 +22,20 @@ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */ +/* Changes: use circular message buffer for receive */ +/* using pollfunction instead of clock (suggested by HCS) */ - +#ifdef PD_0_37 #include "m_pd.h" +#include "s_stuff.h" +#endif +#include "m_imp.h" #include #include #include #ifdef UNIX +#include #include #include #include @@ -41,18 +47,17 @@ #include #endif -#define STRBUF_SIZE 32 /* maximum numbers of characters to read */ -#define DEFPOLLTIME 20 /* check for input every 20 ms */ +#define INBUFSIZE 4096 /* maximum numbers of characters to read */ -static char *version = "netclient v0.1, written by Olaf Matthes "; +static char *version = "netclient v0.3, written by Olaf Matthes "; static t_class *netclient_class; +static t_binbuf *inbinbuf; typedef struct _netclient { t_object x_obj; t_clock *x_clock; - t_clock *x_poll; t_outlet *x_outdata; t_outlet *x_outconnect; int x_fd; @@ -60,37 +65,28 @@ typedef struct _netclient int x_connectstate; int x_port; int x_protocol; + char x_inbuf[INBUFSIZE]; /* circular message buffer for received data */ + int x_intail; + int x_inhead; /* multithread stuff */ pthread_t x_threadid; /* id of child thread */ pthread_attr_t x_threadattr; /* attributes of child thread */ } t_netclient; -static void sys_sockerror(char *s) -{ -#ifdef NT - int err = WSAGetLastError(); - if (err == 10054) return; -#endif -#ifdef UNIX - int err = errno; +#ifdef USE_CIRCULAR +static t_binbuf *inbinbuf; #endif - post("%s: %s (%d)\n", s, strerror(err), err); -} -static void sys_closesocket(int fd) { - -#ifdef UNIX - close(fd); -#endif -#ifdef NT - closesocket(fd); -#endif -} + /* one lonlely prototype */ +static void netclient_rcv(t_netclient *x); + /* get's called when connection has been made */ static void netclient_tick(t_netclient *x) { outlet_float(x->x_outconnect, 1); + /* add pollfunction for checking for input */ + sys_addpollfn(x->x_fd, (t_fdpollfn)netclient_rcv, x); } static void *netclient_child_connect(void *w) @@ -163,6 +159,7 @@ static void netclient_disconnect(t_netclient *x) { if (x->x_fd >= 0) { + sys_rmpollfn(x->x_fd); sys_closesocket(x->x_fd); x->x_fd = -1; x->x_connectstate = 0; @@ -219,14 +216,39 @@ static void netclient_send(t_netclient *x, t_symbol *s, int argc, t_atom *argv) else error("netclient: not connected"); } + /* this is in a separately called subroutine so that the buffer isn't + sitting on the stack while the messages are getting passed. */ +static int netclient_doread(t_netclient *x) +{ + char messbuf[INBUFSIZE], *bp = messbuf; + int indx; + int inhead = x->x_inhead; + int intail = x->x_intail; + char *inbuf = x->x_inbuf; + if (intail == inhead) return (0); + for (indx = intail; indx != inhead; indx = (indx+1)&(INBUFSIZE-1)) + { + char c = *bp++ = inbuf[indx]; + if (c == ';' && (!indx || inbuf[indx-1] != '\\')) + { + intail = (indx+1)&(INBUFSIZE-1); + binbuf_text(inbinbuf, messbuf, bp - messbuf); + x->x_inhead = inhead; + x->x_intail = intail; + return (1); + } + } + return (0); +} + static void netclient_rcv(t_netclient *x) { - int sockfd = x->x_fd; + int fd = x->x_fd; int ret; - char resp[STRBUF_SIZE]; + char resp[INBUFSIZE]; fd_set readset; fd_set exceptset; - struct timeval ztout; + struct timeval ztout; /* output data */ t_binbuf *binbuf; t_atom messbuf[1024]; @@ -239,83 +261,88 @@ static void netclient_rcv(t_netclient *x) /* check if we can read/write from/to the socket */ FD_ZERO(&readset); FD_ZERO(&exceptset); - FD_SET(x->x_fd, &readset ); - FD_SET(x->x_fd, &exceptset ); + FD_SET(fd, &readset ); + FD_SET(fd, &exceptset ); ztout.tv_sec = 0; ztout.tv_usec = 0; - - ret = select(sockfd+1, &readset, NULL, &exceptset, &ztout); + ret = select(fd+1, &readset, NULL, &exceptset, &ztout); if(ret < 0) { error("netclient: can not read from socket"); - sys_closesocket(sockfd); + sys_closesocket(fd); return; } - if(FD_ISSET(sockfd, &readset) || FD_ISSET(sockfd, &exceptset)) + if(FD_ISSET(fd, &readset) || FD_ISSET(fd, &exceptset)) { - /* read from server */ - ret = recv(sockfd, resp, STRBUF_SIZE, 0); - if(ret > 0) + int readto = (x->x_inhead >= x->x_intail ? INBUFSIZE : x->x_intail-1); + + ret = recv(fd, x->x_inbuf + x->x_inhead, readto - x->x_inhead, 0); + if (ret < 0) + { + sys_sockerror("recv"); + sys_rmpollfn(fd); + sys_closesocket(fd); + } + else if (ret == 0) + { + post("netclient: connection closed on socket %d", fd); + sys_rmpollfn(fd); + sys_closesocket(fd); + } + else { - // post("netclient: received: %s, %d bytes, %d stringlen", resp, ret, strlen(resp)); - /* convert string into atoms using a binbuf */ - binbuf = binbuf_new(); - binbuf_text(binbuf, resp, ret); //strlen(resp)); - natom = binbuf_getnatom(binbuf); /* get number of atoms */ - at = binbuf_getvec(binbuf); /* get the atoms */ - /* now split it into several parts at every A_SEMI because - we probably received more than one message at a time */ - for (msg = 0; msg < natom;) + x->x_inhead += ret; + if (x->x_inhead >= INBUFSIZE) x->x_inhead = 0; + while (netclient_doread(x)) { - int emsg; - for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA - && at[emsg].a_type != A_SEMI; emsg++); - - if (emsg > msg) + /* output binbuf */ + natom = binbuf_getnatom(inbinbuf); /* get number of atoms */ + at = binbuf_getvec(inbinbuf); /* get the atoms */ + /* now split it into several parts at every A_SEMI because + we probably received more than one message at a time */ + for (msg = 0; msg < natom;) { - int ii; - for (ii = msg; ii < emsg; ii++) - if (at[ii].a_type == A_DOLLAR || at[ii].a_type == A_DOLLSYM) + int emsg; + for (emsg = msg; emsg < natom && at[emsg].a_type != A_COMMA + && at[emsg].a_type != A_SEMI; emsg++); + + if (emsg > msg) + { + int ii; + for (ii = msg; ii < emsg; ii++) + if (at[ii].a_type == A_DOLLAR || at[ii].a_type == A_DOLLSYM) + { + pd_error(x, "netserver: -- got dollar sign in message"); + goto nodice; + } + if (at[msg].a_type == A_FLOAT) { - pd_error(x, "netserver: -- got dollar sign in message"); - goto nodice; + if (emsg > msg + 1) + outlet_list(x->x_outdata, 0, emsg-msg, at + msg); + else outlet_float(x->x_outdata, at[msg].a_w.w_float); } - if (at[msg].a_type == A_FLOAT) - { - if (emsg > msg + 1) - outlet_list(x->x_outdata, 0, emsg-msg, at + msg); - else outlet_float(x->x_outdata, at[msg].a_w.w_float); + else if (at[msg].a_type == A_SYMBOL) + outlet_anything(x->x_outdata, at[msg].a_w.w_symbol, + emsg-msg-1, at + msg + 1); } - else if (at[msg].a_type == A_SYMBOL) - outlet_anything(x->x_outdata, at[msg].a_w.w_symbol, - emsg-msg-1, at + msg + 1); + nodice: + msg = emsg + 1; } - nodice: - msg = emsg + 1; - } - binbuf_free(binbuf); + } } - else post("netclient: read() did not return any data"); } } else post("netclient: not connected"); } -static void netclient_poll(t_netclient *x) -{ - if(x->x_connectstate) - netclient_rcv(x); /* try to read in case we're connected */ - clock_delay(x->x_poll, DEFPOLLTIME); /* see you later */ -} - static void *netclient_new(t_floatarg udpflag) { t_netclient *x = (t_netclient *)pd_new(netclient_class); x->x_outdata = outlet_new(&x->x_obj, &s_anything); /* received data */ x->x_outconnect = outlet_new(&x->x_obj, &s_float); /* connection state */ x->x_clock = clock_new(x, (t_method)netclient_tick); - x->x_poll = clock_new(x, (t_method)netclient_poll); + inbinbuf = binbuf_new(); x->x_fd = -1; x->x_protocol = (udpflag != 0 ? SOCK_DGRAM : SOCK_STREAM); /* prepare child thread */ @@ -323,15 +350,14 @@ static void *netclient_new(t_floatarg udpflag) post("netclient: warning: could not prepare child thread" ); if(pthread_attr_setdetachstate(&x->x_threadattr, PTHREAD_CREATE_DETACHED) < 0) post("netclient: warning: could not prepare child thread" ); - clock_delay(x->x_poll, 0); /* start polling the input */ return (x); } static void netclient_free(t_netclient *x) { netclient_disconnect(x); - clock_free(x->x_poll); clock_free(x->x_clock); + binbuf_free(inbinbuf); } #ifndef MAXLIB @@ -362,4 +388,4 @@ void maxlib_netclient_setup(void) class_addmethod(netclient_class, (t_method)netclient_rcv, gensym("rcv"), 0); class_sethelpsymbol(netclient_class, gensym("maxlib/help-netclient.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/netrec.c b/src/netrec.c index c747736..dc8e44f 100644 --- a/src/netrec.c +++ b/src/netrec.c @@ -22,7 +22,7 @@ /* */ /* ---------------------------------------------------------------------------- */ -#ifndef PD_0_36 +#ifdef PD_0_37 #include "m_pd.h" #include "s_stuff.h" #endif @@ -446,4 +446,4 @@ void maxlib_netrec_setup(void) class_addmethod(netrec_class, (t_method)netrec_print, gensym("print"), 0); class_sethelpsymbol(netrec_class, gensym("maxlib/help-netrec.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/netserver.c b/src/netserver.c index c8e22f6..1141cb9 100644 --- a/src/netserver.c +++ b/src/netserver.c @@ -23,7 +23,7 @@ /* */ /* ---------------------------------------------------------------------------- */ -#ifndef PD_0_36 +#ifdef PD_0_37 #include "m_pd.h" #include "s_stuff.h" #endif @@ -582,4 +582,4 @@ void maxlib_netserver_setup(void) class_addmethod(netserver_class, (t_method)netserver_broadcast, gensym("broadcast"), A_GIMME, 0); class_sethelpsymbol(netserver_class, gensym("maxlib/help-netserver.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/nroute.c b/src/nroute.c index c8c94c5..e0f6ea4 100644 --- a/src/nroute.c +++ b/src/nroute.c @@ -35,12 +35,12 @@ static char *version = "nroute v0.1, written by Olaf Matthes "; -typedef struct nroute -{ - t_object x_obj; - t_outlet *out1; +typedef struct nroute +{ + t_object x_obj; + t_outlet *out1; t_outlet *out2; - t_int pos; + t_int pos; t_atom match; } t_nroute; @@ -54,36 +54,36 @@ typedef struct proxy /* this is the routine that actually does the routing / matching */ /* it get's called by all other routines that get any input and */ - /* even handles the second (proxy) inlet ! */ -static void nroute_any(t_nroute *x, t_symbol *s, int argc, t_atom *argv) + /* even handles the second (proxy) inlet ! */ +static void nroute_any(t_nroute *x, t_symbol *s, int argc, t_atom *argv) { if(s) { - if (x->pos == 1 && x->match.a_type == A_SYMBOL && x->match.a_w.w_symbol == s) - outlet_anything (x->out1,s,argc,argv); - else if (x->pos > 1 && x->pos <= argc + 1 && - argv[x->pos-2].a_type == x->match.a_type && - argv[x->pos-2].a_w.w_float == x->match.a_w.w_float) - outlet_anything (x->out1,s,argc,argv); - else outlet_anything (x->out2,s,argc,argv); - } + if (x->pos == 1 && x->match.a_type == A_SYMBOL && x->match.a_w.w_symbol == s) + outlet_anything (x->out1,s,argc,argv); + else if (x->pos > 1 && x->pos <= argc + 1 && + argv[x->pos-2].a_type == x->match.a_type && + argv[x->pos-2].a_w.w_float == x->match.a_w.w_float) + outlet_anything (x->out1,s,argc,argv); + else outlet_anything (x->out2,s,argc,argv); + } else - { - if (x->pos > 0 && x->pos <= argc && - argv[x->pos-1].a_type == x->match.a_type && - argv[x->pos-1].a_w.w_float == x->match.a_w.w_float) - outlet_list (x->out1,0,argc,argv); - else outlet_list (x->out2,0,argc,argv); - } -} - -static void nroute_float(t_nroute *x, float f) -{ - t_atom a; + { + if (x->pos > 0 && x->pos <= argc && + argv[x->pos-1].a_type == x->match.a_type && + argv[x->pos-1].a_w.w_float == x->match.a_w.w_float) + outlet_list (x->out1,0,argc,argv); + else outlet_list (x->out2,0,argc,argv); + } +} + +static void nroute_float(t_nroute *x, float f) +{ + t_atom a; - SETFLOAT (&a,f); - nroute_any(x,0,1,&a); -} + SETFLOAT (&a,f); + nroute_any(x,0,1,&a); +} static void nroute_list(t_nroute *x, t_symbol *s, int argc, t_atom *argv) { @@ -120,34 +120,34 @@ static t_class *nroute_class; static t_class *proxy_class; static void *nroute_new(t_symbol *s, int argc, t_atom *argv) -{ +{ t_nroute *x = (t_nroute *)pd_new(nroute_class); t_proxy *inlet = (t_proxy *)pd_new(proxy_class); /* for the proxy inlet */ inlet->x = x; /* make x visible to the proxy inlets */ - x->pos = 1; - x->match.a_type = A_NULL; - if (argc > 2) { error ("nroute: extra arguments"); return 0; } - if (argc > 1) { - if (argv[1].a_type == A_FLOAT) x->pos = argv[1].a_w.w_float; - else { post ("nroute: second argument must be (int) position"); return 0; } - } - if (argc > 0) { - x->match.a_type = argv[0].a_type; - x->match.a_w.w_float = argv[0].a_w.w_float; - } + x->pos = 1; + x->match.a_type = A_NULL; + if (argc > 2) { error ("nroute: extra arguments"); return 0; } + if (argc > 1) { + if (argv[1].a_type == A_FLOAT) x->pos = argv[1].a_w.w_float; + else { post ("nroute: second argument must be (int) position"); return 0; } + } + if (argc > 0) { + x->match.a_type = argv[0].a_type; + x->match.a_w.w_float = argv[0].a_w.w_float; + } inlet->index = 0; /* we are going to create a proxy inlet no. 0 */ /* it belongs to the object t_nroute but the destination is t_proxy */ inlet_new(&x->x_obj, &inlet->obj.ob_pd, 0,0); /* and now a 'normal' third inlet */ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("right")); - x->out1 = outlet_new(&x->x_obj, gensym("list")); + x->out1 = outlet_new(&x->x_obj, gensym("list")); x->out2 = outlet_new(&x->x_obj, gensym("list")); - return (x); + return (x); } -#ifndef MAXLIB +#ifndef MAXLIB void nroute_setup(void) { /* the object's class: */ @@ -176,4 +176,4 @@ void maxlib_nroute_setup(void) #else class_sethelpsymbol(nroute_class, gensym("maxlib/help-nroute.pd")); #endif -} \ No newline at end of file +} diff --git a/src/pitch.c b/src/pitch.c index 95fac90..01ab4e4 100644 --- a/src/pitch.c +++ b/src/pitch.c @@ -111,4 +111,4 @@ void maxlib_pitch_setup(void) class_addfloat(pitch_class, pitch_float); class_sethelpsymbol(pitch_class, gensym("maxlib/help-pitch.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/plus.c b/src/plus.c index b34ffbf..12a5415 100644 --- a/src/plus.c +++ b/src/plus.c @@ -107,4 +107,4 @@ void maxlib_plus_setup(void) class_addbang(plus_class, (t_method)plus_bang); class_sethelpsymbol(plus_class, gensym("maxlib/help-plus.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/poisson.c b/src/poisson.c index d7164ef..92469ad 100644 --- a/src/poisson.c +++ b/src/poisson.c @@ -22,8 +22,8 @@ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */ - -#include "m_pd.h" + +#include "m_pd.h" #include #include #include @@ -32,10 +32,10 @@ #ifndef M_PI #define M_PI 3.1415927 #endif - + static char *version = "poisson v0.1, generates a poisson distributed random variable\n" " written by Olaf Matthes "; - + /* -------------------------- rand_poisson ------------------------------ */ static t_class *rand_poisson_class; @@ -88,4 +88,4 @@ void maxlib_poisson_setup(void) class_addbang(rand_poisson_class, rand_poisson_bang); class_sethelpsymbol(rand_poisson_class, gensym("maxlib/help-poisson.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/pong.c b/src/pong.c index c2deb50..9d269ab 100644 --- a/src/pong.c +++ b/src/pong.c @@ -28,9 +28,9 @@ static char *version = "pong v0.1, ported by Olaf Matthes \n" " written for Max by Richard Dudas"; -typedef struct pong -{ - t_object x_obj; +typedef struct pong +{ + t_object x_obj; t_outlet *p_bounceout; t_outlet *p_handout; t_outlet *p_velout; @@ -250,7 +250,7 @@ static void pong_force(t_pong *x, t_floatarg n) static t_class *pong_class; static void *pong_new(t_floatarg n) -{ +{ t_pong *x = (t_pong *)pd_new(pong_class); x->p_klok = clock_new(x, (t_method)pong_tick); @@ -293,10 +293,10 @@ static void *pong_new(t_floatarg n) x->p_velout = outlet_new(&x->x_obj, gensym("float")); x->p_heightout = outlet_new(&x->x_obj, gensym("float")); - return (x); + return (x); } -#ifndef MAXLIB +#ifndef MAXLIB void pong_setup(void) { pong_class = class_new(gensym("pong"), (t_newmethod)pong_new, @@ -329,4 +329,4 @@ void maxlib_pong_setup(void) #else class_sethelpsymbol(pong_class, gensym("maxlib/help-pong.pd")); #endif -} \ No newline at end of file +} diff --git a/src/pulse.c b/src/pulse.c index afa133c..b188532 100644 --- a/src/pulse.c +++ b/src/pulse.c @@ -298,4 +298,4 @@ void maxlib_pulse_setup(void) class_addbang(pulse_class, pulse_bang); class_sethelpsymbol(pulse_class, gensym("maxlib/help-pulse.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/remote.c b/src/remote.c index d4c5771..7c22901 100644 --- a/src/remote.c +++ b/src/remote.c @@ -105,4 +105,4 @@ void maxlib_remote_setup(void) class_addanything(remote_class, remote_anything); class_sethelpsymbol(remote_class, gensym("maxlib/help-remote.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/rewrap.c b/src/rewrap.c index b8d3242..e02f239 100644 --- a/src/rewrap.c +++ b/src/rewrap.c @@ -152,4 +152,4 @@ void maxlib_rewrap_setup(void) class_addmethod(rewrap_class, (t_method)rewrap_b, gensym("b"), A_FLOAT, 0); class_sethelpsymbol(rewrap_class, gensym("maxlib/help-rewrap.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/rhythm.c b/src/rhythm.c index 7796a61..f4dcf6c 100644 --- a/src/rhythm.c +++ b/src/rhythm.c @@ -26,6 +26,9 @@ #include "m_pd.h" #include #include +#ifdef UNIX +#include +#endif #define ALPHA 10 #define ADAPT_ARRAY_SIZE 1000 diff --git a/src/score.c b/src/score.c index 0f96229..940bf0b 100644 --- a/src/score.c +++ b/src/score.c @@ -306,4 +306,4 @@ void maxlib_score_setup(void) class_addfloat(score_class, score_float); class_sethelpsymbol(score_class, gensym("maxlib/help-score.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/step.c b/src/step.c index 819a157..ecdbe2f 100644 --- a/src/step.c +++ b/src/step.c @@ -176,4 +176,4 @@ void maxlib_step_setup(void) class_addfloat(step_class, (t_method)step_float); class_sethelpsymbol(step_class, gensym("maxlib/help-step.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/subst.c b/src/subst.c index f473d53..04219ec 100644 --- a/src/subst.c +++ b/src/subst.c @@ -421,4 +421,4 @@ void maxlib_subst_setup(void) class_addbang(subst_class, subst_bang); class_sethelpsymbol(subst_class, gensym("maxlib/help-subst.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/sync.c b/src/sync.c index 21e05f9..810706e 100644 --- a/src/sync.c +++ b/src/sync.c @@ -27,7 +27,7 @@ #include #include -#define SYNC_MAX_SIZE (sizeof(unsigned int) * 8) +#define SYNC_MAX_SIZE (int)(sizeof(unsigned int) * 8) static char *version = "sync v0.1, written by Olaf Matthes \n" " based on sync from jMax"; diff --git a/src/temperature.c b/src/temperature.c index 509db76..7c71c84 100644 --- a/src/temperature.c +++ b/src/temperature.c @@ -117,4 +117,4 @@ void maxlib_temperature_setup(void) class_addanything(temperature_class, temperature_anything); class_sethelpsymbol(temperature_class, gensym("maxlib/help-temperature.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/tilt.c b/src/tilt.c index ca67914..c86afe2 100644 --- a/src/tilt.c +++ b/src/tilt.c @@ -186,4 +186,4 @@ void maxlib_tilt_setup(void) class_addmethod(tilt_class, (t_method)tilt_trip_point, gensym("trip"), A_FLOAT, 0); class_sethelpsymbol(tilt_class, gensym("maxlib/help-tilt.pd")); } -#endif \ No newline at end of file +#endif diff --git a/src/triang.c b/src/triang.c index 832bced..c6e4879 100644 --- a/src/triang.c +++ b/src/triang.c @@ -22,17 +22,17 @@ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */ - -#include "m_pd.h" + +#include "m_pd.h" #include #include #include #define fran() (t_float)rand()/(t_float)RAND_MAX - + static char *version = "triang v0.1, generates triangularly distributed random variable\n" " written by Olaf Matthes "; - + /* -------------------------- rand_triang ------------------------------ */ static t_class *rand_triang_class; @@ -77,4 +77,4 @@ void maxlib_triang_setup(void) #else class_sethelpsymbol(rand_triang_class, gensym("maxlib/help-triang.pd")); #endif -} \ No newline at end of file +} diff --git a/src/unroute.c b/src/unroute.c index e6131e4..680653d 100644 --- a/src/unroute.c +++ b/src/unroute.c @@ -172,4 +172,4 @@ void maxlib_unroute_setup(void) class_addcreator((t_newmethod)unroute_new, gensym("unroute"), A_GIMME, 0); class_sethelpsymbol(unroute_class, gensym("maxlib/help-unroute.pd")); #endif -} \ No newline at end of file +} diff --git a/src/urn.c b/src/urn.c index a657d42..3bf5f35 100644 --- a/src/urn.c +++ b/src/urn.c @@ -22,15 +22,15 @@ /* Based on PureData by Miller Puckette and others. */ /* */ /* ---------------------------------------------------------------------------- */ - -#include "m_pd.h" + +#include "m_pd.h" #include #include #include static char *version = "urn v0.1, urn selection model\n" " written by Olaf Matthes "; - + /* -------------------------- urn ------------------------------ */ static t_class *urn_class; @@ -149,4 +149,4 @@ void maxlib_urn_setup(void) #else class_sethelpsymbol(urn_class, gensym("maxlib/help-urn.pd")); #endif -} \ No newline at end of file +} -- cgit v1.2.1