diff options
Diffstat (limited to 'jack_transport')
-rw-r--r-- | jack_transport/jack_transport-help.pd | 32 | ||||
-rw-r--r-- | jack_transport/jack_transport.c | 146 | ||||
-rw-r--r-- | jack_transport/makefile | 94 |
3 files changed, 272 insertions, 0 deletions
diff --git a/jack_transport/jack_transport-help.pd b/jack_transport/jack_transport-help.pd new file mode 100644 index 0000000..f244c5d --- /dev/null +++ b/jack_transport/jack_transport-help.pd @@ -0,0 +1,32 @@ +#N canvas 617 189 486 323 10; +#X obj 100 141 jack_transport; +#X floatatom 140 118 5 0 0 0 - - -, f 5; +#X msg 191 120 stop; +#X msg 191 97 start; +#X obj 42 58 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 52 16 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1 +; +#X obj 190 178 route bar beat; +#X floatatom 237 223 0 0 0 0 - - -; +#X floatatom 288 243 0 0 0 0 - - -; +#X floatatom 340 263 0 0 0 0 - - -; +#X floatatom 392 283 0 0 0 0 - - -; +#X floatatom 156 233 0 0 0 0 - - -; +#X floatatom 100 173 0 0 0 0 - - -; +#X obj 237 201 route float type beats/bar bpm; +#X obj 43 35 metro 125; +#X connect 0 0 12 0; +#X connect 0 1 6 0; +#X connect 1 0 0 0; +#X connect 2 0 0 0; +#X connect 3 0 0 0; +#X connect 4 0 0 0; +#X connect 5 0 14 0; +#X connect 6 0 11 0; +#X connect 6 1 13 0; +#X connect 13 0 7 0; +#X connect 13 1 8 0; +#X connect 13 2 9 0; +#X connect 13 3 10 0; +#X connect 14 0 4 0; diff --git a/jack_transport/jack_transport.c b/jack_transport/jack_transport.c new file mode 100644 index 0000000..f781346 --- /dev/null +++ b/jack_transport/jack_transport.c @@ -0,0 +1,146 @@ +/* +* +* jack_transport Copyright (C) 2005 Tim Blechmann +* +* 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; see the file COPYING. If not, write to +* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 02111-1307, USA. +*/ + +#include "m_pd.h" +#include "jack/jack.h" +#include "stdio.h" + +static t_class *jack_transport_class; + + +typedef struct _jack_transport +{ + t_object x_obj; + t_outlet * x_outlet; + t_outlet * x_outlet_info; + jack_client_t* x_jack_client; + jack_position_t* x_pos; +} jack_transport_t; + +/* connect to jack server */ +static int jack_transport_connect(jack_transport_t * x) +{ + char port_name[80] = ""; + static int client = 0; + do + { + sprintf(port_name,"pure_data_jack_transport_%d",client); + client++; + } + while (((x->x_jack_client = jack_client_open (port_name, (jack_options_t)0, NULL)) == 0) && + client < 100); + client = 0; + + if (!x->x_jack_client) + { + post("jack_transport: can't connect to jack server"); + return 1; + } + + post("jack_transport: connecting as %s", port_name); + + jack_activate(x->x_jack_client); + + return 0; +} + + +static jack_transport_t * jack_transport_new(void) +{ + int status = 0; + jack_transport_t *x = (jack_transport_t*) pd_new(jack_transport_class); + + + x->x_outlet = outlet_new(&x->x_obj, NULL); + x->x_outlet_info = outlet_new(&x->x_obj, NULL); + x->x_pos = (jack_position_t*) getbytes(sizeof(jack_position_t)); + + status = jack_transport_connect(x); + + return x; +} + +static void jack_transport_starter(jack_transport_t * x) +{ + jack_transport_start(x->x_jack_client); + return; +} + +static void jack_transport_stoper(jack_transport_t * x) +{ + jack_transport_stop(x->x_jack_client); + return; +} + +static void jack_transport_timebase(jack_transport_t * x) +{ + jack_position_t pos; + t_atom ap[8]; + const int rolling = (jack_transport_query(x->x_jack_client, &pos) == JackTransportRolling); + SETFLOAT(ap+0, pos.bar); + SETFLOAT(ap+1, pos.beat); + SETSYMBOL(ap+2, gensym("type")); + SETFLOAT(ap+3, pos.beat_type); + SETSYMBOL(ap+4, gensym("beats/bar")); + SETFLOAT(ap+5, pos.beats_per_bar); + SETSYMBOL(ap+6, gensym("bpm")); + SETFLOAT(ap+7, pos.beats_per_minute); + + outlet_anything(x->x_outlet_info, gensym("beat"), 2, ap+2); + outlet_anything(x->x_outlet_info, gensym("beat"), 2, ap+4); + outlet_anything(x->x_outlet_info, gensym("beat"), 2, ap+6); + outlet_anything(x->x_outlet_info, gensym("beat"), 1, ap+1); + outlet_anything(x->x_outlet_info, gensym("bar"), 1, ap+0); +} + +static void jack_transport_bang(jack_transport_t * x) +{ + float f; + if (!x->x_jack_client) + return; + + f = (float)jack_get_current_transport_frame(x->x_jack_client); + jack_transport_timebase(x); + outlet_float(x->x_outlet, f); +} + +static void jack_transport_float(jack_transport_t * x, float f) +{ + if (!x->x_jack_client) + return; + + jack_transport_locate(x->x_jack_client, (jack_nframes_t)f); +} + + +void jack_transport_setup(void) +{ + jack_transport_class = class_new(gensym("jack_transport"), + (t_newmethod)jack_transport_new, + NULL, sizeof(jack_transport_t), + CLASS_DEFAULT, 0); + class_addmethod(jack_transport_class, (t_method)jack_transport_starter, + gensym("start"),0,0); + class_addmethod(jack_transport_class, (t_method)jack_transport_stoper, + gensym("stop"),0,0); + class_addbang(jack_transport_class, (t_method)jack_transport_bang); + class_addfloat(jack_transport_class, (t_method)jack_transport_float); + +} diff --git a/jack_transport/makefile b/jack_transport/makefile new file mode 100644 index 0000000..5419c2c --- /dev/null +++ b/jack_transport/makefile @@ -0,0 +1,94 @@ +NAME=jack_transport +CSYM=jack_transport + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch -g + +LINUXINCLUDE = -I../../../pd/src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations |