From 90dcfc18b533454d99f1d02ee7f191c63e5ed728 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 8 Apr 2004 02:35:21 +0000 Subject: made all of the objects compile on MacOS X and GNU/Linux svn path=/trunk/externals/mjlib/; revision=1571 --- about.c | 3 +- about.h | 1 + makefile.darwin | 53 +++++++++++++ makefile.linux | 7 +- monorhythm.c | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ monorhythm.h | 33 ++++++++ morse.c | 12 ++- n2m.c | 10 +++ readme.txt | 30 ++++--- synapseA~.h | 21 +++++ 10 files changed, 389 insertions(+), 19 deletions(-) create mode 100644 makefile.darwin create mode 100644 monorhythm.c create mode 100644 monorhythm.h create mode 100644 synapseA~.h diff --git a/about.c b/about.c index 4161634..7b07543 100644 --- a/about.c +++ b/about.c @@ -2,9 +2,10 @@ #include "stdafx.h" #include #endif + #include "m_pd.h" #include -#include +#include #include "about.h" /** diff --git a/about.h b/about.h index 737f13a..389442d 100644 --- a/about.h +++ b/about.h @@ -1,3 +1,4 @@ +#include "m_pd.h" typedef struct _about { diff --git a/makefile.darwin b/makefile.darwin new file mode 100644 index 0000000..20d3d50 --- /dev/null +++ b/makefile.darwin @@ -0,0 +1,53 @@ + +EXT = pd_darwin +DEFS = -DHAVE_LIBC=1 -DHAVE_LIBM=1 -DHAVE_LIBPTHREAD=1 -DSTDC_HEADERS=1 -DHAVE_FCNTL_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_UNISTD_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_UNISTD_H=1 -DHAVE_GETPAGESIZE=1 -DHAVE_MMAP=1 -DHAVE_SELECT=1 -DHAVE_SOCKET=1 -DHAVE_STRERROR=1 -DPD_VERSION_MINOR=32 +CC = gcc +CXX = c++ +LD = ld +AFLAGS = +LFLAGS = -bundle -bundle_loader ../../pd/bin/pd -flat_namespace +WFLAGS = +IFLAGS = -I./include -I../src +INSTALL_PREFIX=/usr/local + +VERSION = \"$(shell cat VERSION)\" + +.SUFFIXES: .$(EXT) + +PDCFLAGS = -g -O2 $(DEFS) $(IFLAGS) $(WFLAGS) $(LFLAGS) $(AFLAGS) -DVERSION=$(VERSION) +CFLAGS = -g -O2 $(DEFS) $(IFLAGS) $(WFLAGS) -DVERSION=$(VERSION) +CXXFLAGS = $(CFLAGS) + +#LIBS = -lc -lm +LIBS = -lpthread -lm -lc +SOURCES = about.c convolve~.c pin~.c metroplus.c monorhythm.c morse.c n2m.c prob.c synapseA~.c +TARGETS = $(SOURCES:.c=.$(EXT)) + +all: $(TARGETS) + +clean:: + -rm *.$(EXT) *.o + +distclean: clean + -rm config.cache config.log config.status makefile + + +.c.o: + $(CC) -c -o $@ $(CFLAGS) -DPD $*.c + +# cp $@ $*_stat.o + +.o.pd_darwin: + $(CC) -o $@ $(PDCFLAGS) -DPD $*.o + + + +install:: + install -d $(INSTALL_PREFIX)/pd/externs + install -m 644 *.$(EXT) $(INSTALL_PREFIX)/pd/externs + -install -m 644 mjLib.pd_darwin $(INSTALL_PREFIX)/pd/externs + install -m 644 doc/*.pd $(INSTALL_PREFIX)/pd/doc/5.reference + + +dist: distclean + (cd ..;tar czvf mjLib.tar.gz mjLib) diff --git a/makefile.linux b/makefile.linux index 14f65e3..f1de6a1 100644 --- a/makefile.linux +++ b/makefile.linux @@ -20,16 +20,11 @@ CXXFLAGS = $(CFLAGS) #LIBS = -lc -lm LIBS = -lpthread -lm -lc -SOURCES = pin~.c mjLib.c metroplus.c monorythm.c prob.c +SOURCES = about.c convolve~.c pin~.c metroplus.c monorhythm.c morse.c n2m.c prob.c synapseA~.c TARGETS = $(SOURCES:.c=.$(EXT)) all: $(TARGETS) -mjLib: $(TARGETS) - cc -c $(CFLAGS) -DPD mjLib.c - $(LD) -export_dynamic -shared -o mjLib.pd_linux *.o $(LIBS) - strip --strip-unneeded mjLib.pd_linux - clean:: -rm *.$(EXT) *.o diff --git a/monorhythm.c b/monorhythm.c new file mode 100644 index 0000000..2855820 --- /dev/null +++ b/monorhythm.c @@ -0,0 +1,238 @@ +#ifdef NT +#include "stdafx.h" +#include +#endif +#include "m_pd.h" +#include +#include +#include "monorhythm.h" + +/** +* The monorhythm object is designed to help build polyrhythms. Given +* a time interval and a pattern it produces the pattern within the time +* interval given. Thus if two where set going with the same time interval +* the two patterns (assuming they where different) would play against +* each other. +* +* this filename is spelt wrong 'cos I can't spell +*/ + +static t_class *monorhythm_class; + +/** +* clock tick - do a bang and wait the next +* time delay in the list +*/ + +static void monorhythm_tick(t_monorhythm *x) +{ + if ( x->t_running ) + { + monorhythm_do_beat( x ); + clock_delay(x->x_clock, x->x_beattime ); + } +} + +static void monorhythm_do_beat( t_monorhythm* x ) +{ + float beat; + if ( x->x_idx == x->x_size ) + { + x->x_idx = 0; + + } + if ( x->x_idx == 0) + { + outlet_bang( x->x_sync ); + } + beat = x->x_pattern[ x->x_idx++ ]; + if ( beat > 1 ) + { + if ( x->t_exclusive == 0 ) + { + outlet_bang( x->x_bang ); + } + outlet_bang( x->x_accent ); + } + else if ( beat == 1 ) + { + outlet_bang( x->x_bang ); + } +} + + +/** +* a bang causes a reset to the start of the bar - used to +* synchronize multiple monorhythm's. If the rhythm is not +* running it is started +*/ + + +static void monorhythm_bang(t_monorhythm *x) +{ + if ( x->x_beattime > 0 ) + { + monorhythm_restart( x ); + } +} + +/** +* reset the rhythm to start at the beginning +*/ + +static void monorhythm_restart(t_monorhythm *x) +{ + if ( x->x_beattime > 0 ) + { + x->t_running = 1; + x->x_idx = 0; + monorhythm_do_beat( x ); + clock_delay(x->x_clock, x->x_beattime ); + } +} + +/** +* a stop message turns us off +*/ + +static void monorhythm_stop(t_monorhythm *x) +{ + x->t_running = 0; +} + +/** +* set exclusive mode +*/ + +static void monorhythm_set_exclusive(t_monorhythm *x) +{ + x->t_exclusive = 1; +} + +/** +* set nonexclusive mode +*/ + +static void monorhythm_set_nonexclusive(t_monorhythm *x) +{ + x->t_exclusive = 0; +} + +/** +* free our clock and our timer array +*/ + +static void monorhythm_free(t_monorhythm *x) +{ + clock_free(x->x_clock); + free( x->x_pattern ); +} + +/* +* make a new monorhythm - we can provide a list of times +* so read these in too +*/ + +static void *monorhythm_new(t_symbol *s, int argc, t_atom *argv) +{ + float f; + t_monorhythm *x = (t_monorhythm *)pd_new(monorhythm_class); + x->x_pattern = NULL; + // parse any settings + if ( argc > 0 ) + { + f = atom_getfloat( &argv[0] ); + monorhythm_set_time( x , f ); + monorhythm_pattern_seq( x, s , argc - 1 , argv + 1 ); + } + x->t_running=0; + x->t_exclusive = 0; + // make us some ins and outs + x->x_clock = clock_new(x, (t_method)monorhythm_tick); + x->x_bang = outlet_new(&x->x_obj, gensym("bang")); + x->x_accent = outlet_new(&x->x_obj, gensym("accent")); + x->x_sync = outlet_new(&x->x_obj, gensym("sync")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("pattern")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("timeinterval")); + return (x); +} + +/** +* set a time sequence and free the old array +*/ + +static void monorhythm_pattern_seq( t_monorhythm *x, t_symbol *s, int ac, t_atom *av ) +{ + int i; + if ( x->x_pattern != NULL ) + { + free( x->x_pattern ); + } + if ( ac > 0 ) + { + x->x_pattern = (float *) malloc( ac * sizeof( float )); + for( i = 0 ; i < ac ; i++ ) + { + float t = atom_getfloat( &av[i] ); + x->x_pattern[i] = t; + } + x->x_size=ac; + monorhythm_calculate_beat_interval( x ); + } + else + { + // if there is no pattern it doens't do anything + x->x_pattern = NULL; + x->x_size=0; + x->t_running = 0; + } + x->x_idx = 0; +} + +/** +* the time interval is divided by the number of beats that are +* going to happen in order to get the beat time. If this would +* be invallid for any reason it is set to 0 and the rhythm is stopped +*/ + +static void monorhythm_calculate_beat_interval( t_monorhythm *x ) +{ + if ( ( x->x_size > 0 ) && ( x->x_time > 0 )) + { + x->x_beattime = x->x_time / x->x_size; + } + else + { + x->x_beattime = 0; + x->t_running = 0; + } +} + +/** +* set the time - recalculate the beat time +*/ + +static void monorhythm_set_time( t_monorhythm *x, t_float f ) +{ + x->x_time = f; + monorhythm_calculate_beat_interval( x ); +} + +/** +* make a new one and setup all of our messages +*/ + + void monorhythm_setup(void) +{ + monorhythm_class = class_new(gensym("monorhythm"), (t_newmethod)monorhythm_new, + (t_method)monorhythm_free, sizeof(t_monorhythm), 0, A_GIMME, 0); + class_addbang(monorhythm_class, monorhythm_bang); + class_addmethod(monorhythm_class, (t_method)monorhythm_stop, gensym("stop"), 0); + class_addmethod(monorhythm_class, (t_method)monorhythm_bang, gensym("start"), 0); + class_addmethod(monorhythm_class, (t_method)monorhythm_pattern_seq, gensym("pattern" ), A_GIMME, 0); + class_addmethod(monorhythm_class, (t_method)monorhythm_set_time, gensym("timeinterval" ), A_FLOAT, 0); + class_addmethod(monorhythm_class, (t_method)monorhythm_set_exclusive,gensym("exclusive"),0); + class_addmethod(monorhythm_class, (t_method)monorhythm_set_nonexclusive,gensym("nonexclusive"),0); + class_sethelpsymbol(monorhythm_class, gensym("mjLib/monorhythm")); +} + diff --git a/monorhythm.h b/monorhythm.h new file mode 100644 index 0000000..4a0f503 --- /dev/null +++ b/monorhythm.h @@ -0,0 +1,33 @@ + +typedef struct _monorhythm +{ + t_object x_obj; + t_clock *x_clock; + t_float *x_pattern; + int x_idx; + int x_size; + t_float x_time; + t_float x_beattime; + int t_running; + int t_exclusive; + t_outlet *x_bang; + t_outlet *x_sync; + t_outlet *x_accent; +} t_monorhythm; + +static void monorhythm_tick(t_monorhythm *x); +static void monorhythm_start(t_monorhythm *x); +static void monorhythm_stop(t_monorhythm *x); +static void monorhythm_free(t_monorhythm *x); +static void *monorhythm_new(t_symbol *s, int argc, t_atom *argv); +static void monorhythm_pattern_seq( t_monorhythm *x, t_symbol *s, int ac, t_atom *av ); +static void monorhythm_time_float( t_monorhythm *x1, t_float f ); +static void monorhythm_calculate_beat_interval( t_monorhythm *x ); +static void monorhythm_set_time( t_monorhythm *x, t_float f ); +static void monorhythm_restart(t_monorhythm *x); +static void monorhythm_do_beat( t_monorhythm* x ); +static void monorhythm_set_exclusive(t_monorhythm *x); +static void monorhythm_set_nonexclusive(t_monorhythm *x); + + + diff --git a/morse.c b/morse.c index 2fa9c68..6c2eccf 100644 --- a/morse.c +++ b/morse.c @@ -2,9 +2,11 @@ #include "stdafx.h" #include #endif + #include "m_pd.h" #include -#include +#include +#include #include "morse.h" /** @@ -210,7 +212,15 @@ static void morse_message( t_morse *x, t_symbol *s, int ac, t_atom *av ) { atom_string( &av[i] , buf, 255 ); l = strlen( buf ); +#ifdef NT +/* this is not part of ANSI or ISO standard C, + only Microsoft and Borland use it. */ strlwr( buf ); +#else +/* Probably needs a loop using tolower(char c) from ctype.h + * This way it'll just be case sensitive + */ +#endif for( j = 0 ; j < l ; j++ ) { morse_add_msg_part( x , morse_lookup( buf[j] )); diff --git a/n2m.c b/n2m.c index bd0f0ee..87c0b74 100644 --- a/n2m.c +++ b/n2m.c @@ -120,11 +120,21 @@ static int midilookup( char* note , int octave ) int nnum = 4; for( i = 0 ; i < 12 ; i++ ) { +#ifdef NT +/* stricmp() is not an ANSI or ISO standard C function */ if ( stricmp( note , notes_up[i]) == 0) { nnum = i; break; } +#else +/* replacing with a ANSI function, but it'll now be case sensitive */ + if ( strcmp( note , notes_up[i]) == 0) + { + nnum = i; + break; + } +#endif } return octaveoffset[octave + 1 ] + nnum; } diff --git a/readme.txt b/readme.txt index 0fe0d9c..83c9ec5 100644 --- a/readme.txt +++ b/readme.txt @@ -5,19 +5,21 @@ mark williamson mailto:mark@junklight.com http://www.junklight.com -The code is free for anyone to use provided you mention me somewhere - its not -like its going to cost you anything :-). If you need support you can try -mailing me at the address above - I can be quite busy but I will try and -deal with any queries. +The code is free for anyone to use under the GNU GPL. But if you use it, +please mention me somewhere - its not like its going to cost you anything +:-). If you need support you can try mailing me at the address above - I +can be quite busy but I will try and deal with any queries. -Linux -It is built under windows but I have included the various build files needed -for linux - delete the file "makefile" and use the configure script to -make a new one for linux. The files needed by autoconf are there anyway -if that doesn't work. I can't run PD on the linux machine I have got -access to (only telnet access) so I am not sure about installing it but all the -stuff should be there. +GNU/Linux + +Run: "make -f makefile.linux" and all of the objects will be compiled individually. + + +MacOS X + +Run: "make -f makefile.darwin" and all of the objects will be compiled individually. + Windows @@ -35,6 +37,7 @@ and copy the contents of doc\mjLib into that should be you done. + General notes This library will grow a bit - there are a few more objects that I want to @@ -56,6 +59,11 @@ ___________________________________________________________ history: +6th April 2004 + + added code to the Pd CVS and made all of the objects compile on +MacOS X and GNU/Linux. + 1st February release 2 added new mode to monorhythm (exclusive - allows the beat and accent bangs to be mutually exclusive) diff --git a/synapseA~.h b/synapseA~.h new file mode 100644 index 0000000..265dd53 --- /dev/null +++ b/synapseA~.h @@ -0,0 +1,21 @@ +/* declarations for the pin~ object */ + +typedef struct _synapseA_tilde +{ + t_object x_obj; + t_float x_f; + t_float x_threshold; + t_outlet *x_onbang; + t_outlet *x_offbang; + t_float n_inv; + t_float x_state; +} t_synapseA_tilde; + +t_int *synapseA_tilde_perform(t_int *w); +static void synapseA_tilde_dsp(t_synapseA_tilde *x, t_signal **sp); +static void synapseA_tilde_free(t_synapseA_tilde *x); +static void *synapseA_tilde_new(t_floatarg prob , t_floatarg tick); +static void synapseA_tilde_float(t_synapseA_tilde* x, t_float n); +static void synapseA_tilde_threshold(t_synapseA_tilde *x, t_float f ); + + -- cgit v1.2.1