From 53f05d96ff8e49c87977fa91a06ebade8893606e Mon Sep 17 00:00:00 2001 From: "N.N." Date: Fri, 5 Sep 2003 10:03:46 +0000 Subject: *** empty log message *** svn path=/trunk/externals/miXed/; revision=931 --- Makefile.common | 39 ++++---- ViCious/cyclone/sources | 1 + cyclone/Makefile.objects | 11 ++- cyclone/Makefile.sources | 7 +- cyclone/build_counter | 2 +- cyclone/hammer/comment.c | 15 +-- cyclone/shadow/Makefile.objects | 1 + cyclone/shadow/Makefile.sources | 6 +- cyclone/shadow/cyclone.c | 48 ++++++--- cyclone/shadow/dummies.c | 51 ++++++---- cyclone/shadow/shadow.h | 3 - cyclone/sickle/Makefile.sources | 1 + cyclone/sickle/Scope.c | 14 +-- cyclone/sickle/allsickles.c | 2 + cyclone/sickle/buffir.c | 213 ++++++++++++++++++++++++++++++++++++++++ shared/hammer/file.c | 8 +- shared/unstable/forky.c | 29 +++++- shared/unstable/forky.h | 17 ++++ 18 files changed, 375 insertions(+), 93 deletions(-) create mode 100644 cyclone/sickle/buffir.c diff --git a/Makefile.common b/Makefile.common index 32a92ab..00530a3 100644 --- a/Makefile.common +++ b/Makefile.common @@ -14,15 +14,25 @@ TILDE = ~ include Makefile.sources include Makefile.objects -ifneq ($(OS_NAME),Darwin) +default: define_build all + +ifeq ($(OS_NAME),Linux) # FIXME CC = gcc-2.95 -else -# for MacOS X -CC = gcc2 +X_SUFFIX = pd_linux +DEFINES = -DUNIX +OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer +LFLAGS = -export_dynamic -shared endif -default: define_build all +ifeq ($(OS_NAME),Darwin) +CC = gcc2 +X_SUFFIX = pd_darwin +DEFINES = -DUNIX -DMACOSX +OPT_CFLAGS = -O2 -funroll-loops -fomit-frame-pointer +# -private_bundle is a guess, LATER check this +LFLAGS = -bundle -undefined suppress -flat_namespace +endif SHARED_DIR = $(ROOT_DIR)/shared OBJ_DIR = . @@ -57,21 +67,6 @@ SOURCES = $(CX_SOURCES) $(AX_SOURCES) $(LX_SOURCES) $(OTHER_SOURCES) \ INCLUDES = -I. -I$(PD_DIR) -I$(SHARED_DIR) -ifeq ($(OS_NAME),Linux) -X_SUFFIX = pd_linux -DEFINES = -DUNIX -OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer -LFLAGS = -export_dynamic -shared -endif - -ifeq ($(OS_NAME),Darwin) -X_SUFFIX = pd_darwin -DEFINES = -DUNIX -DMACOSX -OPT_CFLAGS = -O2 -funroll-loops -fomit-frame-pointer -# -private_bundle is a guess, LATER check this -LFLAGS = -bundle -undefined suppress -flat_namespace -endif - WARN_CFLAGS = -Wall -W -Wstrict-prototypes -Werror \ -Wno-unused -Wno-parentheses -Wno-switch DBG_CFLAGS = @@ -327,6 +322,10 @@ Makefile.deps: # added by Hans-Christoph Steiner # to generate MacOS X packages +# krzYszcz: +# LATER try making cyclone-specifics abstracted out ala linux release +# btw, why libs have to be removed from an install? + PACKAGE_PREFIX = pd-$(BASE_NAME) PACKAGE_NAME = $(PACKAGE_PREFIX)-$(VERSION)-$(RELEASE)$(BUILD) diff --git a/ViCious/cyclone/sources b/ViCious/cyclone/sources index df02eb2..1aaf7af 100644 --- a/ViCious/cyclone/sources +++ b/ViCious/cyclone/sources @@ -137,6 +137,7 @@ ALL_SICKLES = \ sickle\bitor.c \ sickle\bitshift.c \ sickle\bitxor.c \ + sickle\buffir.c \ sickle\capture.c \ sickle\cartopol.c \ sickle\change.c \ diff --git a/cyclone/Makefile.objects b/cyclone/Makefile.objects index 9b421fe..87d7ae4 100644 --- a/cyclone/Makefile.objects +++ b/cyclone/Makefile.objects @@ -1,16 +1,17 @@ HLOUD_OBJECTS = common/loud.o +HFORKY_OBJECTS = common/loud.o unstable/forky.o HFRAGILE_OBJECTS = common/loud.o unstable/fragile.o HGROW_OBJECTS = common/grow.o common/loud.o -HFILE_OBJECTS = hammer/file.o common/loud.o +HFILE_OBJECTS = hammer/file.o common/loud.o unstable/forky.o HRAND_OBJECTS = common/rand.o common/loud.o -HRANDFILE_OBJECTS = common/rand.o hammer/file.o common/loud.o +HRANDFILE_OBJECTS = common/rand.o hammer/file.o common/loud.o unstable/forky.o HRANDGROW_OBJECTS = common/rand.o common/grow.o common/loud.o HTREE_OBJECTS = hammer/tree.o common/loud.o HTREEFILEVEFL_OBJECTS = hammer/tree.o hammer/file.o \ - common/vefl.o common/loud.o unstable/fragile.o + common/vefl.o common/loud.o unstable/forky.o unstable/fragile.o HGUI_OBJECTS = hammer/gui.o common/loud.o HSEQ_OBJECTS = common/sq.o common/bifi.o common/mifi.o \ - hammer/file.o common/grow.o common/loud.o + hammer/file.o common/grow.o common/loud.o unstable/forky.o SSIC_OBJECTS = sickle/sic.o common/loud.o SFORKY_OBJECTS = sickle/sic.o common/loud.o unstable/forky.o SFRAGILE_OBJECTS = sickle/sic.o common/loud.o unstable/fragile.o @@ -19,6 +20,6 @@ SGROWFORKY_OBJECTS = common/grow.o sickle/sic.o common/loud.o unstable/forky.o SVEFL_OBJECTS = common/vefl.o sickle/sic.o common/loud.o unstable/fragile.o SARSIC_OBJECTS = sickle/sic.o sickle/arsic.o common/vefl.o \ common/loud.o unstable/fragile.o -SFILE_OBJECTS = hammer/file.o sickle/sic.o common/loud.o +SFILE_OBJECTS = hammer/file.o sickle/sic.o common/loud.o unstable/forky.o RELEASE_LIBS = cyclone hammer sickle RELEASE_APPS = cyclist diff --git a/cyclone/Makefile.sources b/cyclone/Makefile.sources index 818d8c8..f6e69bf 100644 --- a/cyclone/Makefile.sources +++ b/cyclone/Makefile.sources @@ -1,4 +1,4 @@ -TYPES = HPLAIN HLOUD HFRAGILE HGROW HFILE HRAND HRANDFILE HRANDGROW \ +TYPES = HPLAIN HLOUD HFORKY HFRAGILE HGROW HFILE HRAND HRANDFILE HRANDGROW \ HTREE HTREEFILEVEFL HGUI HSEQ \ SPLAINNOTILDE SPLAIN SSIC SFORKY SFRAGILE SGROW SGROWFORKY \ SVEFL SARSIC SFILE @@ -40,7 +40,6 @@ HLOUD_SOURCES = \ hammer/anal.c \ hammer/bangbang.c \ hammer/Borax.c \ -hammer/comment.c \ hammer/cycle.c \ hammer/decide.c \ hammer/Decode.c \ @@ -54,6 +53,9 @@ hammer/sprintf.c \ hammer/switch.c \ hammer/TogEdge.c +HFORKY_SOURCES = \ +hammer/comment.c + HFRAGILE_SOURCES = \ hammer/grab.c \ hammer/universal.c @@ -192,6 +194,7 @@ sickle/cycle.c SARSIC_TILDE = $(TILDE) SARSIC_SOURCES = \ +sickle/buffir.c \ sickle/index.c \ sickle/lookup.c \ sickle/peek.c \ diff --git a/cyclone/build_counter b/cyclone/build_counter index bce8105..0414f92 100644 --- a/cyclone/build_counter +++ b/cyclone/build_counter @@ -1,3 +1,3 @@ #define CYCLONE_VERSION "0.1" #define CYCLONE_RELEASE "alpha" -#define CYCLONE_BUILD 44 +#define CYCLONE_BUILD 45 diff --git a/cyclone/hammer/comment.c b/cyclone/hammer/comment.c index 8e3baeb..3fe6ec6 100644 --- a/cyclone/hammer/comment.c +++ b/cyclone/hammer/comment.c @@ -13,6 +13,7 @@ #include "m_pd.h" #include "g_canvas.h" #include "common/loud.h" +#include "unstable/forky.h" /* our proxy of the text_class (not in the API), LATER do not cheat */ static t_class *makeshift_class; @@ -443,7 +444,7 @@ static void comment_vis(t_gobj *z, t_glist *glist, int vis) than complying to a Pd's assumption about every visible object having an rtext (thus preventing canvas_doclick() from sending garbage warnings). LATER revisit. */ -#ifndef PD_MINOR_VERSION +#if FORKY_VERSION < 37 rtext_new(glist, t, glist->gl_editor->e_rtext, 0); #endif if (glist->gl_havewindow) @@ -451,7 +452,7 @@ static void comment_vis(t_gobj *z, t_glist *glist, int vis) } else { -#ifndef PD_MINOR_VERSION +#if FORKY_VERSION < 37 t_rtext *rt = glist_findrtext(glist, t); if (rt) rtext_free(rt); #endif @@ -488,14 +489,7 @@ static t_widgetbehavior comment_widgetbehavior = 0, comment_vis, 0, - /* As of 0.37, pd does not have these last two elements in */ - /* a t_widgetbehavoir anymore. */ -#if PD_MAJOR_VERSION == 0 -#if PD_MINOR_VERSION < 37 || !defined(PD_MINOR_VERSION) - comment_save, - 0, -#endif -#endif + FORKY_WIDGETPADDING }; /* this fires if a transform request was sent to a symbol we are bound to */ @@ -813,6 +807,7 @@ void comment_setup(void) class_addmethod(comment_class, (t_method)comment__motionhook, gensym("_motion"), A_SYMBOL, A_FLOAT, A_FLOAT, 0); class_setwidget(comment_class, &comment_widgetbehavior); + forky_setsavefn(comment_class, comment_save); makeshift_class = class_new(gensym("text"), 0, 0, sizeof(t_text), diff --git a/cyclone/shadow/Makefile.objects b/cyclone/shadow/Makefile.objects index f77675c..f06e939 100644 --- a/cyclone/shadow/Makefile.objects +++ b/cyclone/shadow/Makefile.objects @@ -5,5 +5,6 @@ common/binport.o \ common/port.o \ hammer/file.o \ sickle/sic.o \ +unstable/forky.o \ unstable/fragile.o \ unstable/loader.o diff --git a/cyclone/shadow/Makefile.sources b/cyclone/shadow/Makefile.sources index 8ba4681..061f37b 100644 --- a/cyclone/shadow/Makefile.sources +++ b/cyclone/shadow/Makefile.sources @@ -1,6 +1,6 @@ CX_SOURCES = \ -cyclone.c +cyclone.c \ +dummies.c OTHER_SOURCES = \ -nettles.c \ -dummies.c +nettles.c diff --git a/cyclone/shadow/cyclone.c b/cyclone/shadow/cyclone.c index 047d39d..10ae142 100644 --- a/cyclone/shadow/cyclone.c +++ b/cyclone/shadow/cyclone.c @@ -28,6 +28,8 @@ static int cyclone_nettlesndx; static int cyclone_dummiesndx; static int cyclone_lastndx; +static t_pd *cyclone_dproxy = 0; + static void cyclone_readhook(t_pd *z, t_symbol *fn, int ac, t_atom *av) { import_max(fn->s_name, ""); @@ -59,28 +61,33 @@ static void cyclone_bang(t_cyclone *x) cyclone_sicklendx, cyclone_nettlesndx - 1); fragile_class_printnames("nettles are: ", cyclone_nettlesndx, cyclone_dummiesndx - 1); - if (i = dummy_nreplacements()) - post("send 'reps' message to see the list of %d \ -replacement abstractions", i); + if (cyclone_dproxy) + pd_bang(cyclone_dproxy); else post("no replacement abstractions"); - post("send 'dummies' message to see the list of %d dummy classes", - /* cyclone_lastndx points to the "_dummy" sentinel class */ - cyclone_lastndx - cyclone_dummiesndx); + if (cyclone_lastndx > cyclone_dummiesndx) + post("send 'dummies' message to see the list of %d dummy classes", + /* cyclone_lastndx points to the "_dummy" sentinel class */ + cyclone_lastndx - cyclone_dummiesndx); + else + post("no dummies"); } static void cyclone_reps(t_cyclone *x) { - if (dummy_nreplacements()) - dummy_printreplacements("replacement abstractions are: "); + if (cyclone_dproxy) + typedmess(cyclone_dproxy, gensym("reps"), 0, 0); else post("no replacement abstractions"); } static void cyclone_dummies(t_cyclone *x) { - fragile_class_printnames("dummies are: ", - cyclone_dummiesndx, cyclone_lastndx); + if (cyclone_lastndx > cyclone_dummiesndx) + fragile_class_printnames("dummies are: ", + cyclone_dummiesndx, cyclone_lastndx); + else + post("no dummies"); } static void cyclone_free(t_cyclone *x) @@ -98,8 +105,8 @@ static void *cyclone_new(t_symbol *s) void cyclone_setup(void) { - int hresult, sresult; - hresult = sresult = LOADER_OK; + int hresult, sresult, dresult; + hresult = sresult = dresult = LOADER_OK; if (canvas_getcurrent()) { /* Loading the library by object creation is banned, because of a danger @@ -142,7 +149,11 @@ void cyclone_setup(void) allnettles_setup(); cyclone_dummiesndx = fragile_class_count(); - alldummies_setup(); + if (zgetfn(&pd_objectmaker, gensym("dummies"))) + loud_warning(0, "dummies are already loaded"); + else + dresult = unstable_load_lib("", "dummies"); + cyclone_lastndx = fragile_class_count() - 1; if (hresult == LOADER_NOFILE) @@ -156,4 +167,15 @@ void cyclone_setup(void) loud_errand(0, "use a more recent Pd release (or recompile the cyclone)."); } + else if (dresult == LOADER_NOFILE) + loud_warning(0, "dummies not found"); + else + { + t_symbol *s = gensym("_ccdummies"); + if (s->s_thing && !s->s_next + && !strcmp(class_getname(*s->s_thing), "_ccdummies")) + cyclone_dproxy = s->s_thing; + else + bug("cyclone_setup"); /* FIXME */ + } } diff --git a/cyclone/shadow/dummies.c b/cyclone/shadow/dummies.c index be9a886..c6d53fe 100644 --- a/cyclone/shadow/dummies.c +++ b/cyclone/shadow/dummies.c @@ -11,8 +11,8 @@ #endif #include "m_pd.h" #include "common/loud.h" -#include "shadow.h" +static t_class *ccdummies_class; static int dummy_nclasses = 0; static t_class **dummy_classes; static int dummy_nreps = 0; @@ -351,7 +351,6 @@ static t_dummy_slot dummy_slots[] = { "Biquad~", 6, 1, 0, 0 }, /* LATER try mapping bpatcher to a gop abstraction/subpatch */ { "buffer~", 1, 2, 0, 0 }, - { "buffir~", 3, 1, 0, 0 }, { "cd", 1, 2, 0, 0 }, /* CHECKED (refman error?) */ { "cd~", 1, 6, 0, 0 }, /* CHECKED (refman error?) */ { "Change", 1, 3, 0, 0 }, @@ -554,34 +553,43 @@ static t_object *dummy_newobject(t_symbol *s, t_dummy_slot **slotp) return (x); } -int dummy_nreplacements(void) +static void ccdummies_bang(t_pd *x) { - return (dummy_nreps); + if (dummy_nreps) + post("send 'reps' message to see the list of %d \ +replacement abstractions", dummy_nreps); + else + post("no replacement abstractions"); } -void dummy_printreplacements(char *msg) +static void ccdummies_reps(t_pd *x) { - int i, len = strlen(msg); - t_dummy_slot *sl; - startpost(msg); - for (i = 0, sl = dummy_slots; i < dummy_nclasses; i++, sl++) + if (dummy_nreps) { - if (!dummy_classes[i]) + char *msg = "replacement abstractions are: "; + int i, len = strlen(msg); + t_dummy_slot *sl; + startpost(msg); + for (i = 0, sl = dummy_slots; i < dummy_nclasses; i++, sl++) { - int l = 1 + strlen(sl->s_name); - if ((len += l) > 66) + if (!dummy_classes[i]) { - endpost(); - startpost(" "); - len = 3 + l; + int l = 1 + strlen(sl->s_name); + if ((len += l) > 66) + { + endpost(); + startpost(" "); + len = 3 + l; + } + poststring(sl->s_name); } - poststring(sl->s_name); } + endpost(); } - endpost(); + else post("no replacement abstractions"); } -void alldummies_setup(void) +void dummies_setup(void) { t_dummy_slot *sl; int i; @@ -606,4 +614,11 @@ void alldummies_setup(void) (sl->s_nins ? 0 : CLASS_NOINLET), A_GIMME, 0); } dummy_nclasses--; /* use "_dummy" as a sentinel */ + + ccdummies_class = class_new(gensym("_ccdummies"), 0, 0, + sizeof(t_pd), CLASS_PD | CLASS_NOINLET, 0); + class_addbang(ccdummies_class, ccdummies_bang); + class_addmethod(ccdummies_class, (t_method)ccdummies_reps, + gensym("reps"), 0); + pd_bind(pd_new(ccdummies_class), gensym("_ccdummies")); /* never freed */ } diff --git a/cyclone/shadow/shadow.h b/cyclone/shadow/shadow.h index aefc46e..878a95b 100644 --- a/cyclone/shadow/shadow.h +++ b/cyclone/shadow/shadow.h @@ -6,8 +6,5 @@ #define __SHADOW_H__ void allnettles_setup(void); -void alldummies_setup(void); -int dummy_nreplacements(void); -void dummy_printreplacements(char *msg); #endif diff --git a/cyclone/sickle/Makefile.sources b/cyclone/sickle/Makefile.sources index d39cc17..901be5b 100644 --- a/cyclone/sickle/Makefile.sources +++ b/cyclone/sickle/Makefile.sources @@ -19,6 +19,7 @@ bitnot.c \ bitor.c \ bitshift.c \ bitxor.c \ +buffir.c \ capture.c \ cartopol.c \ change.c \ diff --git a/cyclone/sickle/Scope.c b/cyclone/sickle/Scope.c index 8a09d78..adfa51b 100644 --- a/cyclone/sickle/Scope.c +++ b/cyclone/sickle/Scope.c @@ -794,7 +794,7 @@ static void scope_vis(t_gobj *z, t_glist *glist, int vis) if (vis) { t_scopehandle *sh = (t_scopehandle *)x->x_handle; -#ifndef PD_MINOR_VERSION +#if FORKY_VERSION < 37 rtext_new(glist, t, glist->gl_editor->e_rtext, 0); #endif sprintf(sh->h_pathname, ".x%x.h%x", (int)cv, (int)sh); @@ -805,7 +805,7 @@ static void scope_vis(t_gobj *z, t_glist *glist, int vis) } else { -#ifndef PD_MINOR_VERSION +#if FORKY_VERSION < 37 t_rtext *rt = glist_findrtext(glist, t); if (rt) rtext_free(rt); #endif @@ -848,14 +848,7 @@ static t_widgetbehavior scope_widgetbehavior = scope_delete, scope_vis, scope_click, - /* As of 0.37, pd does not have these last two elements in */ - /* a t_widgetbehavoir anymore. */ -#if PD_MAJOR_VERSION == 0 -#if PD_MINOR_VERSION < 37 || !defined(PD_MINOR_VERSION) - scope_save, - 0 -#endif -#endif + FORKY_WIDGETPADDING }; static void scope_setxymode(t_scope *x, int xymode) @@ -1040,6 +1033,7 @@ void Scope_tilde_setup(void) gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); class_setwidget(scope_class, &scope_widgetbehavior); + forky_setsavefn(scope_class, scope_save); scopehandle_class = class_new(gensym("_scopehandle"), 0, 0, sizeof(t_scopehandle), CLASS_PD, 0); class_addmethod(scopehandle_class, (t_method)scopehandle__clickhook, diff --git a/cyclone/sickle/allsickles.c b/cyclone/sickle/allsickles.c index d062c61..7771cf8 100644 --- a/cyclone/sickle/allsickles.c +++ b/cyclone/sickle/allsickles.c @@ -20,6 +20,7 @@ void bitnot_tilde_setup(void); void bitor_tilde_setup(void); void bitshift_tilde_setup(void); void bitxor_tilde_setup(void); +void buffir_tilde_setup(void); void capture_tilde_setup(void); void cartopol_tilde_setup(void); void change_tilde_setup(void); @@ -98,6 +99,7 @@ void allsickles_setup(void) bitor_tilde_setup(); bitshift_tilde_setup(); bitxor_tilde_setup(); + buffir_tilde_setup(); capture_tilde_setup(); cartopol_tilde_setup(); change_tilde_setup(); diff --git a/cyclone/sickle/buffir.c b/cyclone/sickle/buffir.c new file mode 100644 index 0000000..0551501 --- /dev/null +++ b/cyclone/sickle/buffir.c @@ -0,0 +1,213 @@ +/* Copyright (c) 2003 krzYszcz and others. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +#include +#include "m_pd.h" +#include "common/loud.h" +#include "sickle/sic.h" +#include "sickle/arsic.h" + +#define BUFFIR_DEFSIZE 0 /* CHECKED */ +#define BUFFIR_MAXSIZE 128 + +typedef struct _buffir +{ + t_arsic x_arsic; + t_pd *x_offinlet; + t_pd *x_sizinlet; + t_float *x_lohead; + t_float *x_hihead; + int x_histsize; + t_float *x_histlo; + t_float *x_histhi; + t_float x_histini[2 * BUFFIR_MAXSIZE]; +} t_buffir; + +static t_class *buffir_class; + +static void buffir_setrange(t_buffir *x, t_floatarg f1, t_floatarg f2) +{ + int off = (int)f1; + int siz = (int)f2; + if (off < 0) + off = 0; + if (siz <= 0) + siz = BUFFIR_DEFSIZE; + if (siz > x->x_histsize) + { + int newsize, pos = x->x_lohead - x->x_histlo; + int oldbytes = x->x_histsize * sizeof(*x->x_histlo); + static int warned = 0; + if (!warned) + { + loud_incompatible(buffir_class, "stretching history buffer"); + warned = 1; + } + newsize = x->x_histsize * 2; + while (newsize < siz) newsize *= 2; + if (x->x_histlo == x->x_histini) + { + if (!(x->x_histlo = getbytes(2 * newsize * sizeof(*x->x_histlo)))) + x->x_histlo = x->x_histini; + else + { + x->x_histhi = x->x_histlo + newsize; + memcpy(x->x_histhi + pos - x->x_histsize, + x->x_lohead, oldbytes); + x->x_lohead = x->x_histlo + pos; + x->x_hihead = x->x_histhi + pos; + x->x_histsize = newsize; + } + } + else + { + if (!(x->x_histlo = + resizebytes(x->x_histlo, 2 * oldbytes, + 2 * newsize * sizeof(*x->x_histlo)))) + { + x->x_histsize = BUFFIR_MAXSIZE; + x->x_histlo = x->x_histini; + memset(x->x_histlo, 0, + 2 * x->x_histsize * sizeof(*x->x_histlo)); + x->x_lohead = x->x_histlo; + x->x_hihead = x->x_histhi = x->x_histlo + x->x_histsize; + } + else + { + x->x_histhi = x->x_histlo + newsize; + memcpy(x->x_histhi + pos - x->x_histsize, + x->x_lohead, oldbytes); + x->x_lohead = x->x_histlo + pos; + x->x_hihead = x->x_histhi + pos; + x->x_histsize = newsize; + } + } + } + pd_float(x->x_offinlet, off); + pd_float(x->x_sizinlet, siz); +} + +static void buffir_clear(t_buffir *x) +{ + memset(x->x_histlo, 0, 2 * x->x_histsize * sizeof(*x->x_histlo)); + x->x_lohead = x->x_histlo; + x->x_hihead = x->x_histhi = x->x_histlo + x->x_histsize; +} + +static void buffir_set(t_buffir *x, t_symbol *s, t_floatarg f1, t_floatarg f2) +{ + arsic_setarray((t_arsic *)x, s, 1); + buffir_setrange(x, f1, f2); +} + +static t_int *buffir_perform(t_int *w) +{ + t_arsic *sic = (t_arsic *)(w[1]); + t_buffir *x = (t_buffir *)sic; + int nblock = (int)(w[2]); + t_float *xin = (t_float *)(w[3]); + t_float *out = (t_float *)(w[6]); + t_float *lohead = x->x_lohead; + t_float *hihead = x->x_hihead; + if (sic->s_playable) + { + t_float *oin = (t_float *)(w[4]); + t_float *sin = (t_float *)(w[5]); + int vecsize = sic->s_vecsize; + t_float *vec = sic->s_vectors[0]; /* playable implies nonzero (mono) */ + int histsize = x->x_histsize; + while (nblock--) + { + /* CHECKME every sample or once per block. + If once per block, then LATER think about performance. */ + /* CHECKME rounding */ + int off = (int)*oin++; + int npoints = (int)*sin++; + if (off < 0) + off = 0; + if (npoints > histsize) + npoints = histsize; + if (npoints > vecsize - off) + npoints = vecsize - off; + if (npoints > 0) + { + t_float *coefp = vec + off; + t_float *hp = hihead; + t_float sum = 0.; + *lohead++ = *hihead++ = *xin++; + while (npoints--) + sum += *coefp++ * *hp--; + *out++ = sum; + } + else + { + *lohead++ = *hihead++ = *xin++; + *out++ = 0.; + } + if (lohead >= x->x_histhi) + { + lohead = x->x_histlo; + hihead = x->x_histhi; + } + } + } + else while (nblock--) + { + *lohead++ = *hihead++ = *xin++; + *out++ = 0.; + if (lohead >= x->x_histhi) + { + lohead = x->x_histlo; + hihead = x->x_histhi; + } + } + x->x_lohead = lohead; + x->x_hihead = hihead; + return (w + 7); +} + +static void buffir_dsp(t_buffir *x, t_signal **sp) +{ + arsic_dsp((t_arsic *)x, sp, buffir_perform, 1); +} + +static void buffir_free(t_buffir *x) +{ + if (x->x_histlo != x->x_histini) + freebytes(x->x_histlo, 2 * x->x_histsize * sizeof(*x->x_histlo)); + arsic_free((t_arsic *)x); +} + +static void *buffir_new(t_symbol *s, t_floatarg f1, t_floatarg f2) +{ + /* CHECKME always the first channel used. */ + /* three auxiliary signals: main, offset and size inputs */ + t_buffir *x = (t_buffir *)arsic_new(buffir_class, s, 0, 0, 3); + if (x) + { + arsic_setminsize((t_arsic *)x, 1); + x->x_offinlet = (t_pd *)sic_newinlet((t_sic *)x, f1); + x->x_sizinlet = (t_pd *)sic_newinlet((t_sic *)x, f2); + outlet_new((t_object *)x, &s_signal); + x->x_histsize = BUFFIR_MAXSIZE; + x->x_histlo = x->x_histini; + buffir_clear(x); + buffir_setrange(x, f1, f2); + } + return (x); +} + +void buffir_tilde_setup(void) +{ + buffir_class = class_new(gensym("buffir~"), + (t_newmethod)buffir_new, + (t_method)buffir_free, + sizeof(t_buffir), 0, + A_DEFSYM, A_DEFFLOAT, A_DEFFLOAT, 0); + arsic_setup(buffir_class, buffir_dsp, SIC_FLOATTOSIGNAL); + class_addmethod(buffir_class, (t_method)buffir_clear, + gensym("clear"), 0); + class_addmethod(buffir_class, (t_method)buffir_set, + gensym("set"), A_SYMBOL, A_DEFFLOAT, A_DEFFLOAT, 0); +} diff --git a/shared/hammer/file.c b/shared/hammer/file.c index 6a94c92..635c9bc 100644 --- a/shared/hammer/file.c +++ b/shared/hammer/file.c @@ -20,8 +20,7 @@ #include #include "m_pd.h" #include "g_canvas.h" -/* need this for t_class::c_wb field access, LATER find a better way... */ -#include "unstable/pd_imp.h" +#include "unstable/forky.h" #include "hammer/file.h" static t_class *hammerfile_class = 0; @@ -375,10 +374,7 @@ void hammerfile_setup(t_class *c, int embeddable) { if (embeddable) { - t_widgetbehavior *newwb = getbytes(sizeof(*newwb)); /* never freed */ - *newwb = *c->c_wb; - newwb->w_savefn = hammerembed_save; - class_setwidget(c, newwb); + forky_setsavefn(c, hammerembed_save); class_addmethod(c, (t_method)hammerembed_restore, gensym("restore"), 0); } diff --git a/shared/unstable/forky.c b/shared/unstable/forky.c index 7fb6b08..1feae26 100644 --- a/shared/unstable/forky.c +++ b/shared/unstable/forky.c @@ -7,7 +7,32 @@ #include "shared.h" #include "unstable/forky.h" -//#define FORKY_DEBUG +#if FORKY_VERSION < 37 +/* need this for t_class::c_wb field access */ +#include "unstable/pd_imp.h" +#endif + +#define FORKY_DEBUG + +void forky_setsavefn(t_class *c, t_forkysavefn fn) +{ +#if FORKY_VERSION >= 37 + class_setsavefn(c, fn); +#else + if (c->c_wb->w_savefn) + { + /* cloning is necessary, because class_setwidget has not been called */ + t_widgetbehavior *wb = getbytes(sizeof(*wb)); /* never freed */ +#ifdef FORKY_DEBUG + post("cloning widgetbehavior..."); +#endif + *wb = *c->c_wb; + wb->w_savefn = fn; + class_setwidget(c, wb); + } + else c->c_wb->w_savefn = fn; +#endif +} /* To be called in a 'dsp' method -- e.g. if there are no feeders, the caller might use an optimized version of a 'perform' routine. @@ -18,7 +43,7 @@ int forky_hasfeeders(t_object *x, t_glist *glist, int inno, t_symbol *outsym) linetraverser_start(&t, glist); while (linetraverser_next(&t)) if (t.tr_ob2 == x && t.tr_inno == inno -#ifdef PD_VERSION /* FIXME ask Miller */ +#if FORKY_VERSION >= 36 && (!outsym || outsym == outlet_getsymbol(t.tr_outlet)) #endif ) diff --git a/shared/unstable/forky.h b/shared/unstable/forky.h index 0d27080..df27690 100644 --- a/shared/unstable/forky.h +++ b/shared/unstable/forky.h @@ -5,6 +5,23 @@ #ifndef __FORKY_H__ #define __FORKY_H__ +#ifdef PD_MINOR_VERSION +#define FORKY_VERSION PD_MINOR_VERSION +#elif defined(PD_VERSION) +#define FORKY_VERSION 36 +#else +#define FORKY_VERSION 35 +#endif + +#if FORKY_VERSION >= 37 +#define FORKY_WIDGETPADDING +#else +#define FORKY_WIDGETPADDING 0,0 +#endif + +typedef void (*t_forkysavefn)(t_gobj *x, t_binbuf *b); + +void forky_setsavefn(t_class *c, t_forkysavefn fn); int forky_hasfeeders(t_object *x, t_glist *glist, int inno, t_symbol *outsym); t_int forky_getbitmask(int ac, t_atom *av); -- cgit v1.2.1