From 05b4b22c2d70dee18187de8a9f9b5a5e59a72a40 Mon Sep 17 00:00:00 2001 From: Miller Puckette <msp@ucsd.edu> Date: Thu, 20 Dec 2007 10:07:14 -0800 Subject: [PATCH] loads more patches --- doc/5.reference/my_canvas-help.pd | 75 ++++++---- extra/sigmund~/sigmund~-help.pd | 4 +- src/CHANGELOG.txt | 5 +- src/configure.in | 10 +- src/d_soundfile.c | 236 ++++++++++++++++++++++++++---- src/g_text.c | 12 +- src/makefile.in | 12 +- src/s_audio_jack.c | 50 +++++-- src/u_main.tk | 10 +- src/x_connective.c | 54 ++++++- 10 files changed, 378 insertions(+), 90 deletions(-) diff --git a/doc/5.reference/my_canvas-help.pd b/doc/5.reference/my_canvas-help.pd index decda6289..65f9976fe 100644 --- a/doc/5.reference/my_canvas-help.pd +++ b/doc/5.reference/my_canvas-help.pd @@ -1,25 +1,25 @@ -#N canvas 482 81 568 339 10; -#X obj 1 1 cnv 15 300 60 foo10_snd foo10_rcv my_canvas=cnv 63 37 192 +#N canvas 0 22 500 292 10; +#X obj 1 1 cnv 15 300 60 foo10_snd foo10_rcv my_canvas=cnv 63 37 0 17 -257472 -355 0; #X text 4 232 (c) musil@iem.kug.ac.at; #X text 46 245 IEM KUG; #N canvas 219 100 699 530 edit 0; #X obj 39 226 f; #X msg 17 205 bang; -#X floatatom 55 204 3 63 88; -#X floatatom 90 226 3 0 37; +#X floatatom 55 204 3 63 88 0 - - -; +#X floatatom 90 226 3 0 37 0 - - -; #X obj 39 249 pack 0 0; #X text 117 226 y-label; #X text 83 204 x-label; #X obj 297 281 f; #X msg 275 260 bang; -#X floatatom 313 259 3 -10 10; -#X floatatom 348 281 3 -10 10; +#X floatatom 313 259 3 -10 10 0 - - -; +#X floatatom 348 281 3 -10 10 0 - - -; #X obj 297 304 pack 0 0; #X obj 309 396 f; #X msg 287 375 bang; -#X floatatom 325 374 3 20 60; -#X floatatom 360 396 3 150 200; +#X floatatom 325 374 3 20 60 0 - - -; +#X floatatom 360 396 3 150 200 0 - - -; #X obj 309 419 pack 0 0; #X text 341 259 x-delta; #X text 375 281 y-delta; @@ -27,12 +27,12 @@ #X text 387 396 y-position; #X obj 59 341 f; #X msg 37 320 bang; -#X floatatom 75 319 3 0 2; -#X floatatom 110 341 3 4 36; +#X floatatom 75 319 3 0 2 0 - - -; +#X floatatom 110 341 3 4 36 0 - - -; #X obj 59 364 pack 0 0; #X text 103 319 font; #X text 139 341 height; -#X floatatom 275 183 3 2 20; +#X floatatom 275 183 3 2 20 0 - - -; #X msg 52 137 \; foo10_rcv color \$1 \$2; #X msg 39 274 \; foo10_rcv label_pos \$1 \$2; #X msg 59 390 \; foo10_rcv label_font \$1 \$2; @@ -42,8 +42,8 @@ #X msg 297 329 \; foo10_rcv delta \$1 \$2; #X obj 505 234 f; #X msg 483 213 bang; -#X floatatom 521 212 5 100 1000; -#X floatatom 556 234 4 50 500; +#X floatatom 521 212 5 100 1000 0 - - -; +#X floatatom 556 234 4 50 500 0 - - -; #X obj 505 257 pack 0 0; #X text 566 212 width; #X text 594 236 height; @@ -57,14 +57,14 @@ #X msg 509 372 \; foo10_rcv get_pos; #X obj 510 407 r foo10_snd; #X obj 510 428 unpack 0 0; -#X floatatom 510 453 4 0 0; -#X floatatom 575 452 4 0 0; +#X floatatom 510 453 4 0 0 0 - - -; +#X floatatom 575 452 4 0 0 0 - - -; #X text 490 452 x=; #X text 557 452 y=; #X obj 52 79 f; #X msg 29 31 bang; -#X floatatom 68 29 3 0 29; -#X floatatom 103 47 3 0 29; +#X floatatom 68 29 3 0 29 0 - - -; +#X floatatom 103 47 3 0 29 0 - - -; #X text 96 29 background; #X text 131 48 label-color; #X msg 290 25 back; @@ -137,9 +137,9 @@ #X connect 30 1 23 0; #X connect 30 2 28 0; #X restore 290 86 pd RGB_____________; -#X floatatom 332 55 3 0 255; -#X floatatom 375 55 3 0 255; -#X floatatom 418 56 3 0 255; +#X floatatom 332 55 3 0 255 0 - - -; +#X floatatom 375 55 3 0 255 0 - - -; +#X floatatom 418 56 3 0 255 0 - - -; #X text 39 3 preset-colors; #X text 301 0 RGB-colors; #X text 332 37 red; @@ -188,22 +188,22 @@ #X connect 68 0 66 2; #X connect 69 0 66 3; #X connect 75 0 29 0; -#X restore 305 20 pd edit; -#X floatatom 110 193 4 0 0; -#X floatatom 147 193 4 0 0; +#X restore 315 20 pd edit; +#X floatatom 110 193 4 0 0 0 - - -; +#X floatatom 147 193 4 0 0 0 - - -; #X text 121 209 x; #X text 158 209 y; #X obj 7 161 metro 100; #X obj 33 141 tgl 15 1 empty empty empty 20 8 0 10 -262144 -1 -1 1 1; #X obj 110 145 r from_K1; -#X floatatom 188 194 4 0 0; -#X floatatom 225 194 4 0 0; +#X floatatom 188 194 4 0 0 0 - - -; +#X floatatom 225 194 4 0 0 0 - - -; #X text 198 210 x; #X text 236 210 y; #X obj 188 146 r from_K2; #X msg 7 185 \; to_K get_pos; -#N canvas 0 296 395 395 room 1; +#N canvas 0 296 395 395 room 0; #X obj 1 1 cnv 1 400 400 empty empty type...ctrl+e 150 140 2 17 -33289 -24198 0; #X obj 15 16 cnv 1 1 360 empty empty move_K1_and_K2 115 160 2 17 -166441 @@ -214,9 +214,9 @@ 0; #X obj 17 375 cnv 1 358 1 empty empty empty 20 12 2 20 -99865 -66577 0; -#X obj 23 22 cnv 25 25 25 from_K1 to_K K1 1 13 194 14 -261681 -123526 +#X obj 23 22 cnv 25 25 25 from_K1 to_K K1 1 13 2 14 -261681 -123526 0; -#X obj 342 342 cnv 25 25 25 from_K2 to_K K2 1 13 194 14 -225280 -1109 +#X obj 342 342 cnv 25 25 25 from_K2 to_K K2 1 13 2 14 -225280 -1109 0; #X restore 307 147 pd room; #X obj 110 169 unpack; @@ -229,9 +229,26 @@ #X text 5 64 click the properties-dialog on the top-left corner; #X obj 361 195 r foo10_rcv; #X obj 403 215 s ggg; -#X text 172 257 updated for Pd version 0.35; #X text 21 257 graz \, austria 2002; #X obj 187 236 x_all_guis aaa bbb ccc ddd eee fff ggg hhh iii; +#X text 313 46 For cnv's creation arguments:; +#N canvas 881 440 467 369 canvas-creation-arguments 0; +#X msg 7 12 canvas: cnv selectableSize xSize ySize sendName recieveName +Label labelXOff labelYOff Font# fontSize bgColor lblColor 0; +#X text 9 169 For example \, a canvas called thusly:; +#X obj 9 248 cnv 15 200 100 myCanvas myCanvasR Canvas_Demo 20 12 2 +14 -62784 -195568 0; +#X text 9 226 will result in this:; +#X text 8 59 Canvas can be called with 13 creation arguments. These +are not "optional" - all parameters must be filled or the canvas will +not instantiate correctly.; +#X text 10 114 The function of the final "0" is unknown to me (it is +found in the textual entry for a canvas object in a .pd file) but can +be safely left off without ill effects.; +#X msg 9 191 cnv 15 200 100 myCanvas myCanvasR Canvas_Demo 20 12 2 +14 18 20; +#X restore 314 63 pd canvas-creation-arguments; +#X text 172 257 updated for Pd version 0.35; #X connect 8 0 16 0; #X connect 9 0 8 0; #X connect 10 0 18 0; diff --git a/extra/sigmund~/sigmund~-help.pd b/extra/sigmund~/sigmund~-help.pd index c60ca9a81..5f57271de 100644 --- a/extra/sigmund~/sigmund~-help.pd +++ b/extra/sigmund~/sigmund~-help.pd @@ -91,7 +91,7 @@ of a note at or near the previously output pitch.; #X connect 1 0 2 0; #X connect 2 0 3 0; #X restore 330 531 pd setting-parameters; -#N canvas 149 65 641 815 sinusoid-tracking 1; +#N canvas 149 65 641 815 sinusoid-tracking 0; #X obj 124 267 sigmund~ -npeak 10 peaks; #X obj 124 214 phasor~; #X obj 124 144 loadbang; @@ -127,7 +127,7 @@ claw them apart). The other four are as shown:; #X floatatom 245 760 5 0 0 0 - - -; #X floatatom 285 737 5 0 0 0 - - -; #X floatatom 326 713 5 0 0 0 - - -; -#X obj 246 638 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 +#X obj 246 638 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; #X text 43 535 If you ask for "tracks" \, the output is four numbers: index \, frequency \, and amplitude as before \, and finally a flag diff --git a/src/CHANGELOG.txt b/src/CHANGELOG.txt index 6c0dc1e39..9620a7fae 100644 --- a/src/CHANGELOG.txt +++ b/src/CHANGELOG.txt @@ -4,7 +4,10 @@ for original notes on source stype and organization. 0.41.0 -add support for callback-based audio I/O; changes in +add support for callback-based audio I/O +headers & code changed to use t_float or t_sample instead of float (patches +by zmoelnig). + 0.40.0 diff --git a/src/configure.in b/src/configure.in index 66940f6ef..2aa54d0b5 100644 --- a/src/configure.in +++ b/src/configure.in @@ -7,6 +7,7 @@ AC_SUBST(portaudio, no) AC_SUBST(portmidi, no) AC_SUBST(binarymode, -m755) AC_SUBST(fftw, no) +AC_SUBST(tk, yes) AC_SUBST(PDLIB) AC_SUBST(CPPFLAGS) AC_SUBST(MORECFLAGS) @@ -21,6 +22,7 @@ AC_SUBST(GUIFLAGS) AC_SUBST(OSNUMBER) AC_SUBST(EXTERNTARGET) AC_SUBST(ASIOSRC) +AC_SUBST(GUISRC) dnl other defaults @@ -42,8 +44,10 @@ AC_ARG_ENABLE(setuid, [ --enable-setuid install as setuid (linux)], setuid=$enableval) AC_ARG_ENABLE(fftw, [ --enable-fftw use FFTW package], fftw=$enableval) -AC_ARG_ENABLE(fat, [ --disable-fat build fat binary on Mac OS X], +AC_ARG_ENABLE(fat, [ --disable-fat build fat binary on Mac OS X], fat=$enableval, fat="yes") +AC_ARG_ENABLE(tk, [ --disable-tk build without tcl/tk-GUI], + tk=$enableval) dnl Checks for programs. AC_PROG_CC @@ -97,6 +101,10 @@ fi dnl look for tcl 8.x... do I really have to go through all this!? +if test x$tk != "xno"; then +GUISRC="t_main.c t_tkcmd.c" +fi + foundit=no if test $foundit = "no"; then diff --git a/src/d_soundfile.c b/src/d_soundfile.c index 4be42615e..8768fa553 100644 --- a/src/d_soundfile.c +++ b/src/d_soundfile.c @@ -425,13 +425,81 @@ int open_soundfile_via_canvas(t_canvas *canvas, const char *filename, int header p_bigendian, p_nchannels, p_bytelimit, skipframes)); } -static void soundfile_xferin(int sfchannels, int nvecs, float **vecs, +static void soundfile_xferin_sample(int sfchannels, int nvecs, t_sample **vecs, long itemsread, unsigned char *buf, int nitems, int bytespersamp, int bigendian, int spread) { int i, j; unsigned char *sp, *sp2; - float *fp; + t_sample *fp; + int nchannels = (sfchannels < nvecs ? sfchannels : nvecs); + int bytesperframe = bytespersamp * sfchannels; + for (i = 0, sp = buf; i < nchannels; i++, sp += bytespersamp) + { + if (bytespersamp == 2) + { + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + spread * itemsread; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16)); + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + spread * itemsread; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + *fp = SCALE * ((sp2[1] << 24) | (sp2[0] << 16)); + } + } + else if (bytespersamp == 3) + { + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + spread * itemsread; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + *fp = SCALE * ((sp2[0] << 24) | (sp2[1] << 16) + | (sp2[2] << 8)); + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + spread * itemsread; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + *fp = SCALE * ((sp2[2] << 24) | (sp2[1] << 16) + | (sp2[0] << 8)); + } + } + else if (bytespersamp == 4) + { + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + spread * itemsread; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + *(long *)fp = ((sp2[0] << 24) | (sp2[1] << 16) + | (sp2[2] << 8) | sp2[3]); + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + spread * itemsread; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + *(long *)fp = ((sp2[3] << 24) | (sp2[2] << 16) + | (sp2[1] << 8) | sp2[0]); + } + } + } + /* zero out other outputs */ + for (i = sfchannels; i < nvecs; i++) + for (j = nitems, fp = vecs[i]; j--; ) + *fp++ = 0; + +} + +static void soundfile_xferin_float(int sfchannels, int nvecs, t_float **vecs, + long itemsread, unsigned char *buf, int nitems, int bytespersamp, + int bigendian, int spread) +{ + int i, j; + unsigned char *sp, *sp2; + t_float *fp; int nchannels = (sfchannels < nvecs ? sfchannels : nvecs); int bytesperframe = bytespersamp * sfchannels; for (i = 0, sp = buf; i < nchannels; i++, sp += bytespersamp) @@ -518,7 +586,7 @@ static void soundfile_xferin(int sfchannels, int nvecs, float **vecs, static int soundfiler_writeargparse(void *obj, int *p_argc, t_atom **p_argv, t_symbol **p_filesym, int *p_filetype, int *p_bytespersamp, int *p_swap, int *p_bigendian, - int *p_normalize, long *p_onset, long *p_nframes, float *p_rate) + int *p_normalize, long *p_onset, long *p_nframes, t_float *p_rate) { int argc = *p_argc; t_atom *argv = *p_argv; @@ -526,7 +594,7 @@ static int soundfiler_writeargparse(void *obj, int *p_argc, t_atom **p_argv, endianness = -1, swap, filetype = -1, normalize = 0; long onset = 0, nframes = 0x7fffffff; t_symbol *filesym; - float rate = -1; + t_float rate = -1; while (argc > 0 && argv->a_type == A_SYMBOL && *argv->a_w.w_symbol->s_name == '-') @@ -668,7 +736,7 @@ usage: static int create_soundfile(t_canvas *canvas, const char *filename, int filetype, int nframes, int bytespersamp, - int bigendian, int nchannels, int swap, float samplerate) + int bigendian, int nchannels, int swap, t_float samplerate) { char filenamebuf[MAXPDSTRING], buf2[MAXPDSTRING]; char headerbuf[WRITEHDRSIZE]; @@ -827,20 +895,20 @@ baddonewrite: post("%s: %s", filename, strerror(errno)); } -static void soundfile_xferout(int nchannels, float **vecs, +static void soundfile_xferout_sample(int nchannels, t_sample **vecs, unsigned char *buf, int nitems, long onset, int bytespersamp, - int bigendian, float normalfactor, int spread) + int bigendian, t_sample normalfactor, int spread) { int i, j; unsigned char *sp, *sp2; - float *fp; + t_sample *fp; int bytesperframe = bytespersamp * nchannels; long xx; for (i = 0, sp = buf; i < nchannels; i++, sp += bytespersamp) { if (bytespersamp == 2) { - float ff = normalfactor * 32768.; + t_sample ff = normalfactor * 32768.; if (bigendian) { for (j = 0, sp2 = sp, fp = vecs[i] + onset; @@ -874,7 +942,7 @@ static void soundfile_xferout(int nchannels, float **vecs, } else if (bytespersamp == 3) { - float ff = normalfactor * 8388608.; + t_sample ff = normalfactor * 8388608.; if (bigendian) { for (j = 0, sp2 = sp, fp=vecs[i] + onset; @@ -915,7 +983,7 @@ static void soundfile_xferout(int nchannels, float **vecs, for (j = 0, sp2 = sp, fp=vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp += spread) { - float f2 = *fp * normalfactor; + t_sample f2 = *fp * normalfactor; xx = *(long *)&f2; sp2[0] = (xx >> 24); sp2[1] = (xx >> 16); sp2[2] = (xx >> 8); sp2[3] = xx; @@ -926,7 +994,115 @@ static void soundfile_xferout(int nchannels, float **vecs, for (j = 0, sp2 = sp, fp=vecs[i] + onset; j < nitems; j++, sp2 += bytesperframe, fp += spread) { - float f2 = *fp * normalfactor; + t_sample f2 = *fp * normalfactor; + xx = *(long *)&f2; + sp2[3] = (xx >> 24); sp2[2] = (xx >> 16); + sp2[1] = (xx >> 8); sp2[0] = xx; + } + } + } + } +} +static void soundfile_xferout_float(int nchannels, t_float **vecs, + unsigned char *buf, int nitems, long onset, int bytespersamp, + int bigendian, t_sample normalfactor, int spread) +{ + int i, j; + unsigned char *sp, *sp2; + t_float *fp; + int bytesperframe = bytespersamp * nchannels; + long xx; + for (i = 0, sp = buf; i < nchannels; i++, sp += bytespersamp) + { + if (bytespersamp == 2) + { + t_sample ff = normalfactor * 32768.; + if (bigendian) + { + for (j = 0, sp2 = sp, fp = vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + { + int xx = 32768. + (*fp * ff); + xx -= 32768; + if (xx < -32767) + xx = -32767; + if (xx > 32767) + xx = 32767; + sp2[0] = (xx >> 8); + sp2[1] = xx; + } + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + { + int xx = 32768. + (*fp * ff); + xx -= 32768; + if (xx < -32767) + xx = -32767; + if (xx > 32767) + xx = 32767; + sp2[1] = (xx >> 8); + sp2[0] = xx; + } + } + } + else if (bytespersamp == 3) + { + t_sample ff = normalfactor * 8388608.; + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + { + int xx = 8388608. + (*fp * ff); + xx -= 8388608; + if (xx < -8388607) + xx = -8388607; + if (xx > 8388607) + xx = 8388607; + sp2[0] = (xx >> 16); + sp2[1] = (xx >> 8); + sp2[2] = xx; + } + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + { + int xx = 8388608. + (*fp * ff); + xx -= 8388608; + if (xx < -8388607) + xx = -8388607; + if (xx > 8388607) + xx = 8388607; + sp2[2] = (xx >> 16); + sp2[1] = (xx >> 8); + sp2[0] = xx; + } + } + } + else if (bytespersamp == 4) + { + if (bigendian) + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + { + t_sample f2 = *fp * normalfactor; + xx = *(long *)&f2; + sp2[0] = (xx >> 24); sp2[1] = (xx >> 16); + sp2[2] = (xx >> 8); sp2[3] = xx; + } + } + else + { + for (j = 0, sp2 = sp, fp=vecs[i] + onset; + j < nitems; j++, sp2 += bytesperframe, fp += spread) + { + t_sample f2 = *fp * normalfactor; xx = *(long *)&f2; sp2[3] = (xx >> 24); sp2[2] = (xx >> 16); sp2[1] = (xx >> 8); sp2[0] = xx; @@ -935,7 +1111,6 @@ static void soundfile_xferout(int nchannels, float **vecs, } } } - /* ------- soundfiler - reads and writes soundfiles to/from "garrays" ---- */ #define DEFMAXSIZE 4000000 /* default maximum 16 MB per channel */ @@ -1121,9 +1296,9 @@ static void soundfiler_read(t_soundfiler *x, t_symbol *s, thisread = (thisread > bufframes ? bufframes : thisread); nitems = fread(sampbuf, channels * bytespersamp, thisread, fp); if (nitems <= 0) break; - soundfile_xferin(channels, argc, (float **)vecs, itemsread, + soundfile_xferin_float(channels, argc, (t_float **)vecs, itemsread, (unsigned char *)sampbuf, nitems, bytespersamp, bigendian, - sizeof(t_word)/sizeof(float)); + sizeof(t_word)/sizeof(t_sample)); itemsread += nitems; } /* zero out remaining elements of vectors */ @@ -1157,7 +1332,7 @@ usage: done: if (fd >= 0) close (fd); - outlet_float(x->x_obj.ob_outlet, (float)itemsread); + outlet_float(x->x_obj.ob_outlet, (t_float)itemsread); } /* this is broken out from soundfiler_write below so garray_write can @@ -1175,7 +1350,8 @@ long soundfiler_dowrite(void *obj, t_canvas *canvas, char sampbuf[SAMPBUFSIZE]; int bufframes, nitems; int fd = -1; - float normfactor, biggest = 0, samplerate; + t_sample normfactor, biggest = 0; + t_float samplerate; t_symbol *filesym; if (soundfiler_writeargparse(obj, &argc, &argv, &filesym, &filetype, @@ -1244,9 +1420,9 @@ long soundfiler_dowrite(void *obj, t_canvas *canvas, { int thiswrite = nframes - itemswritten, nitems, nbytes; thiswrite = (thiswrite > bufframes ? bufframes : thiswrite); - soundfile_xferout(argc, (t_float **)vecs, (unsigned char *)sampbuf, + soundfile_xferout_float(argc, (t_float **)vecs, (unsigned char *)sampbuf, thiswrite, onset, bytespersamp, bigendian, normfactor, - sizeof(t_word)/sizeof(float)); + sizeof(t_word)/sizeof(t_sample)); nbytes = write(fd, sampbuf, nchannels * bytespersamp * thiswrite); if (nbytes < nchannels * bytespersamp * thiswrite) { @@ -1281,7 +1457,7 @@ static void soundfiler_write(t_soundfiler *x, t_symbol *s, { long bozo = soundfiler_dowrite(x, x->x_canvas, argc, argv); - outlet_float(x->x_obj.ob_outlet, (float)bozo); + outlet_float(x->x_obj.ob_outlet, (t_float)bozo); } static void soundfiler_setup(void) @@ -1343,7 +1519,7 @@ typedef struct _readsf int x_vecsize; /* vector size for transfers */ t_outlet *x_bangout; /* bang-on-done outlet */ int x_state; /* opened, running, or idle */ - float x_insamplerate; /* sample rate of input signal if known */ + t_float x_insamplerate; /* sample rate of input signal if known */ /* parameters to communicate with subthread */ int x_requestcode; /* pending request from parent to I/O thread */ char *x_filename; /* file to open (string is permanently allocated) */ @@ -1352,7 +1528,7 @@ typedef struct _readsf int x_bytespersample; /* bytes per sample (2 or 3) */ int x_bigendian; /* true if file is big-endian */ int x_sfchannels; /* number of channels in soundfile */ - float x_samplerate; /* sample rate of soundfile */ + t_float x_samplerate; /* sample rate of soundfile */ long x_onsetframes; /* number of sample frames to skip */ long x_bytelimit; /* max number of data bytes to read */ int x_fd; /* filedesc */ @@ -1365,7 +1541,7 @@ typedef struct _readsf int x_filetype; /* writesf~ only; type of file to create */ int x_itemswritten; /* writesf~ only; items writen */ int x_swap; /* writesf~ only; true if byte swapping */ - float x_f; /* writesf~ only; scalar for signal inlet */ + t_float x_f; /* writesf~ only; scalar for signal inlet */ pthread_mutex_t x_mutex; pthread_cond_t x_requestcondition; pthread_cond_t x_answercondition; @@ -1744,7 +1920,7 @@ static t_int *readsf_perform(t_int *w) int vecsize = x->x_vecsize, noutlets = x->x_noutlets, i, j, bytespersample = x->x_bytespersample, bigendian = x->x_bigendian; - float *fp; + t_sample *fp; if (x->x_state == STATE_STREAM) { int wantbytes, nchannels, sfchannels = x->x_sfchannels; @@ -1788,7 +1964,7 @@ static t_int *readsf_perform(t_int *w) (sfchannels * bytespersample); if (xfersize) { - soundfile_xferin(sfchannels, noutlets, x->x_outvec, 0, + soundfile_xferin_sample(sfchannels, noutlets, x->x_outvec, 0, (unsigned char *)(x->x_buf + x->x_fifotail), xfersize, bytespersample, bigendian, 1); vecsize -= xfersize; @@ -1803,7 +1979,7 @@ static t_int *readsf_perform(t_int *w) return (w+2); } - soundfile_xferin(sfchannels, noutlets, x->x_outvec, 0, + soundfile_xferin_sample(sfchannels, noutlets, x->x_outvec, 0, (unsigned char *)(x->x_buf + x->x_fifotail), vecsize, bytespersample, bigendian, 1); @@ -1999,7 +2175,7 @@ static void *writesf_child_main(void *zz) int filetype = x->x_filetype; char *filename = x->x_filename; t_canvas *canvas = x->x_canvas; - float samplerate = x->x_samplerate; + t_float samplerate = x->x_samplerate; /* alter the request code so that an ensuing "open" will get noticed. */ @@ -2244,7 +2420,7 @@ static t_int *writesf_perform(t_int *w) int vecsize = x->x_vecsize, sfchannels = x->x_sfchannels, i, j, bytespersample = x->x_bytespersample, bigendian = x->x_bigendian; - float *fp; + t_sample *fp; if (x->x_state == STATE_STREAM) { int wantbytes; @@ -2263,7 +2439,7 @@ static t_int *writesf_perform(t_int *w) #endif } - soundfile_xferout(sfchannels, x->x_outvec, + soundfile_xferout_sample(sfchannels, x->x_outvec, (unsigned char *)(x->x_buf + x->x_fifohead), vecsize, 0, bytespersample, bigendian, 1., 1); @@ -2316,7 +2492,7 @@ static void writesf_open(t_writesf *x, t_symbol *s, int argc, t_atom *argv) t_symbol *filesym; int filetype, bytespersamp, swap, bigendian, normalize; long onset, nframes; - float samplerate; + t_float samplerate; if (x->x_state != STATE_IDLE) { writesf_stop(x); diff --git a/src/g_text.c b/src/g_text.c index 5affd00c9..bbdb7729d 100644 --- a/src/g_text.c +++ b/src/g_text.c @@ -145,8 +145,11 @@ void canvas_obj(t_glist *gl, t_symbol *s, int argc, t_atom *argv) canvas_objtext(gl, atom_getintarg(0, argc, argv), atom_getintarg(1, argc, argv), 0, b); } - else - { + else if(!glist_isvisible(gl)){ + /* JMZ: not a good idea to go into interactive mode in a closed canvas... */ + post("unable to create stub object in closed canvas!"); + return; + } else { t_binbuf *b = binbuf_new(); int xpix, ypix; pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1); @@ -417,6 +420,11 @@ void canvas_msg(t_glist *gl, t_symbol *s, int argc, t_atom *argv) else { int xpix, ypix; + /* JMZ: not a good idea to go into interactive mode in a closed canvas... */ + if(!glist_isvisible(gl)){ + post("unable to create stub message in closed canvas!"); + return; + } pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1); glist_noselect(gl); glist_getnextxy(gl, &xpix, &ypix); diff --git a/src/makefile.in b/src/makefile.in index c019c078f..b4ad82177 100644 --- a/src/makefile.in +++ b/src/makefile.in @@ -59,7 +59,7 @@ SRC = g_canvas.c g_graph.c g_text.c g_rtext.c g_array.c g_template.c g_io.c \ OBJ = $(SRC:.c=.o) -GSRC = t_main.c t_tkcmd.c +GSRC = @GUISRC@ GOBJ = $(GSRC:.c=.o) @@ -83,10 +83,10 @@ endif .PHONY: pd gui externs all -all: $(PDEXEC) $(BIN_DIR)/pd-watchdog $(BIN_DIR)/$(GUINAME) $(BIN_DIR)/pdsend \ +all: pd $(BIN_DIR)/pd-watchdog gui $(BIN_DIR)/pdsend \ $(BIN_DIR)/pdreceive $(BIN_DIR)/pd.tk externs -bin: $(PDEXEC) $(BIN_DIR)/pd-watchdog $(BIN_DIR)/$(GUINAME) $(BIN_DIR)/pdsend \ +bin: pd $(BIN_DIR)/pd-watchdog gui $(BIN_DIR)/pdsend \ $(BIN_DIR)/pdreceive $(BIN_DIR)/pd.tk $(OBJ) : %.o : %.c @@ -100,7 +100,11 @@ $(ASIOOBJ): %.o : %.cpp pd: $(PDEXEC) +ifneq ($(GSRC),) gui: $(BIN_DIR)/$(GUINAME) +else +gui: +endif pd-watchdog: $(BIN_DIR)/pd-watchdog @@ -118,7 +122,7 @@ $(BIN_DIR)/pdreceive: u_pdreceive.c $(BIN_DIR) $(PDEXEC): $(OBJ) $(BIN_DIR) cd ../obj; $(CC) $(LDFLAGS) $(DBG_CFLAGS) -o $(PDEXEC) $(OBJ) $(LIB) - + $(BIN_DIR)/pd-gui: $(GOBJ) $(GSRC) cd ../obj; $(CC) $(INCLUDE) -o $(BIN_DIR)/$(GUINAME) $(GOBJ) $(GLIB) diff --git a/src/s_audio_jack.c b/src/s_audio_jack.c index 92f652e97..f00e2f134 100644 --- a/src/s_audio_jack.c +++ b/src/s_audio_jack.c @@ -18,8 +18,8 @@ static jack_nframes_t jack_out_max; #define JACK_OUT_MAX 64 static jack_nframes_t jack_filled = 0; -static float jack_outbuf[NUM_JACK_PORTS*BUF_JACK]; -static float jack_inbuf[NUM_JACK_PORTS*BUF_JACK]; +static t_sample jack_outbuf[NUM_JACK_PORTS*BUF_JACK]; +static t_sample jack_inbuf[NUM_JACK_PORTS*BUF_JACK]; static int jack_started = 0; @@ -39,22 +39,42 @@ static int process (jack_nframes_t nframes, void *arg) { int j; - float *out; - float *in; - + jack_default_audio_sample_t *out, *in; if (nframes > JACK_OUT_MAX) jack_out_max = nframes; else jack_out_max = JACK_OUT_MAX; if (jack_filled >= nframes) { if (jack_filled != nframes) fprintf(stderr,"Partial read"); - - for (j = 0; j < sys_outchannels; j++) { + /* hmm, how to find out whether 't_sample' and 'jack_default_audio_sample_t' are actually the same type??? */ + if(sizeof(t_sample)==sizeof(jack_default_audio_sample_t)) + { + for (j = 0; j < sys_outchannels; j++) { out = jack_port_get_buffer (output_port[j], nframes); - memcpy(out, jack_outbuf + (j * BUF_JACK), sizeof (float) * nframes); - } - for (j = 0; j < sys_inchannels; j++) { + memcpy(out, jack_outbuf + (j * BUF_JACK), sizeof (jack_default_audio_sample_t) * nframes); + } + for (j = 0; j < sys_inchannels; j++) { + in = jack_port_get_buffer( input_port[j], nframes); + memcpy(jack_inbuf + (j * BUF_JACK), in, sizeof (jack_default_audio_sample_t) * nframes); + } + } + else + { + unsigned int frame=0; + t_sample*data; + for (j = 0; j < sys_outchannels; j++) { + out = jack_port_get_buffer (output_port[j], nframes); + data=jack_outbuf + (j * BUF_JACK); + for(frame=0; frame<nframes; frame++) { + *out++=*data++; + } + } + for (j = 0; j < sys_inchannels; j++) { in = jack_port_get_buffer( input_port[j], nframes); - memcpy(jack_inbuf + (j * BUF_JACK), in, sizeof (float) * nframes); + data=jack_inbuf+(j*BUF_JACK); + for(frame=0; frame<nframes; frame++) { + *data++=*in++; + } + } } jack_filled -= nframes; } else { /* PD could not keep up ! */ @@ -322,7 +342,7 @@ void jack_close_audio(void) int jack_send_dacs(void) { - float * fp; + t_sample * fp; int j; int rtnval = SENDDACS_YES; int timenow; @@ -343,12 +363,12 @@ int jack_send_dacs(void) fp = sys_soundout; for (j = 0; j < sys_outchannels; j++) { - memcpy(jack_outbuf + (j * BUF_JACK) + jack_filled,fp, DEFDACBLKSIZE*sizeof(float)); + memcpy(jack_outbuf + (j * BUF_JACK) + jack_filled,fp, DEFDACBLKSIZE*sizeof(t_sample)); fp += DEFDACBLKSIZE; } fp = sys_soundin; for (j = 0; j < sys_inchannels; j++) { - memcpy(fp, jack_inbuf + (j * BUF_JACK) + jack_filled, DEFDACBLKSIZE*sizeof(float)); + memcpy(fp, jack_inbuf + (j * BUF_JACK) + jack_filled, DEFDACBLKSIZE*sizeof(t_sample)); fp += DEFDACBLKSIZE; } @@ -357,7 +377,7 @@ int jack_send_dacs(void) rtnval = SENDDACS_SLEPT; } - memset(sys_soundout,0,DEFDACBLKSIZE*sizeof(float)*sys_outchannels); + memset(sys_soundout,0,DEFDACBLKSIZE*sizeof(t_sample)*sys_outchannels); jack_filled += DEFDACBLKSIZE; return rtnval; } diff --git a/src/u_main.tk b/src/u_main.tk index dc3cc8013..08d429a1f 100644 --- a/src/u_main.tk +++ b/src/u_main.tk @@ -168,15 +168,14 @@ set ctrls_outlevel 0 frame .controls.switches checkbutton .controls.switches.audiobutton -text {compute audio} \ -variable ctrls_audio_on \ - -anchor w \ -command {pd [concat pd dsp $ctrls_audio_on \;]} checkbutton .controls.switches.meterbutton -text {peak meters} \ -variable ctrls_meter_on \ - -anchor w \ -command {pd [concat pd meters $ctrls_meter_on \;]} -pack .controls.switches.audiobutton .controls.switches.meterbutton -side top +pack .controls.switches.audiobutton .controls.switches.meterbutton \ + -side top -anchor w frame .controls.inout frame .controls.inout.in @@ -1209,6 +1208,7 @@ if {$pd_nt == 1} { bind $name.c <Option-Button> {pdtk_canvas_click %W %x %y %b 4} bind $name.c <Option-Shift-Button> {pdtk_canvas_click %W %x %y %b 5} bind $name.c <Option-Control-Button> {pdtk_canvas_click %W %x %y %b 6} + bind $name.c <Mod1-Button> {pdtk_canvas_click %W %x %y %b 6} bind $name.c <Option-Control-Shift-Button> \ {pdtk_canvas_click %W %x %y %b 7} } else { @@ -2873,7 +2873,7 @@ proc array_apply {id} { } # jsarlo -proc array_viewlist {id name page} { +proc array_viewlist {id} { pd [concat $id arrayviewlistnew\;] } # end jsarlo @@ -2963,7 +2963,7 @@ proc pdtk_array_dialog {id name n flags newone} { # jsarlo if {$newone == 0} { button $id.listview -text {View list}\ - -command "array_viewlist $id $name 0" + -command "array_viewlist $id" pack $id.listview -side left } # end jsarlo diff --git a/src/x_connective.c b/src/x_connective.c index 83d7f34ac..2f291f506 100644 --- a/src/x_connective.c +++ b/src/x_connective.c @@ -1204,34 +1204,86 @@ typedef struct _makefilename { t_object x_obj; t_symbol *x_format; + t_atomtype x_accept; + int x_intconvert; } t_makefilename; +static void makefilename_scanformat(t_makefilename *x) +{ + int num=0, infmt=0; + char *str,*chr; + if (!x->x_format) return; + x->x_accept = A_NULL; + for (str=x->x_format->s_name; *str; str++) { + if (!infmt && *str=='%') { + infmt=1; + continue; + } + if (infmt) { + if (strchr("-.#0123456789",*str)!=0) + continue; + if (*str=='s') { + x->x_accept = A_SYMBOL; + x->x_intconvert = 0; + break; + } + if (strchr("fgGeE",*str)!=0) { + x->x_accept = A_FLOAT; + x->x_intconvert = 0; + break; + } + if (strchr("xXdiou",*str)!=0) { + x->x_accept = A_FLOAT; + x->x_intconvert = 1; + break; + } + infmt=0; + } + } +} + static void *makefilename_new(t_symbol *s) { t_makefilename *x = (t_makefilename *)pd_new(makefilename_class); - if (!s->s_name) s = gensym("file.%d"); + if (!s || !s->s_name) s = gensym("file.%d"); outlet_new(&x->x_obj, &s_symbol); x->x_format = s; + x->x_accept = A_NULL; + x->x_intconvert = 0; + makefilename_scanformat(x); return (x); } static void makefilename_float(t_makefilename *x, t_floatarg f) { char buf[MAXPDSTRING]; + if (x->x_accept == A_FLOAT) { + if (x->x_intconvert) sprintf(buf, x->x_format->s_name, (int)f); + else + sprintf(buf, x->x_format->s_name, f); + } + else + sprintf(buf, x->x_format->s_name, ""); + if (buf[0]!=0) outlet_symbol(x->x_obj.ob_outlet, gensym(buf)); } static void makefilename_symbol(t_makefilename *x, t_symbol *s) { char buf[MAXPDSTRING]; + if (x->x_accept == A_SYMBOL) sprintf(buf, x->x_format->s_name, s->s_name); + else + sprintf(buf, x->x_format->s_name, 0); + if (buf[0]!=0) outlet_symbol(x->x_obj.ob_outlet, gensym(buf)); } static void makefilename_set(t_makefilename *x, t_symbol *s) { x->x_format = s; + makefilename_scanformat(x); } static void makefilename_setup(void) -- GitLab