diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2003-08-16 08:13:16 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2003-08-16 08:13:16 +0000 |
commit | d553c8c877c2969345b1e237e08a40be05a9babd (patch) | |
tree | 24d653e8d2e04ce121dd1f6c44b7cb970621aa22 | |
parent | 46c90cd0fc550312658d6c35025d2eb57da1519e (diff) |
added files straight from Yves' sources
svn path=/trunk/externals/unauthorized/; revision=855
-rw-r--r-- | exciter/CHANGE.LOG | 5 | ||||
-rw-r--r-- | exciter/INSTALL | 15 | ||||
-rw-r--r-- | exciter/Makefile | 83 | ||||
-rw-r--r-- | exciter/README | 20 | ||||
-rw-r--r-- | exciter/exciter.c | 841 | ||||
-rw-r--r-- | exciter/exciter.h | 34 | ||||
-rw-r--r-- | exciter/exciter.tk | 123 | ||||
-rw-r--r-- | exciter/help-exciter.pd | 71 |
8 files changed, 1192 insertions, 0 deletions
diff --git a/exciter/CHANGE.LOG b/exciter/CHANGE.LOG new file mode 100644 index 0000000..358d509 --- /dev/null +++ b/exciter/CHANGE.LOG @@ -0,0 +1,5 @@ +0.2 + fixed : could set event nnumber to one + do not set "started" at initialization +0.1 + basic bang-events sequencer diff --git a/exciter/INSTALL b/exciter/INSTALL new file mode 100644 index 0000000..55894c3 --- /dev/null +++ b/exciter/INSTALL @@ -0,0 +1,15 @@ +untar in /my/pd/dir/externs + +cd /my/pd/dir/externs/exciter + +make clean + +make + +make install + +open help-exciter.pd + +Thanx for getting here. +Yves/ +comments and bugs @ ydegoyon@free.fr diff --git a/exciter/Makefile b/exciter/Makefile new file mode 100644 index 0000000..898abc1 --- /dev/null +++ b/exciter/Makefile @@ -0,0 +1,83 @@ +NAME=exciter +CSYM=exciter + +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\tcl\include /I\ftp\pd\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + \ftp\pd\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 -DUNIX -DICECAST -O2 -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wno-shadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch #-Werror + +LINUXINCLUDE = -I../../src + +.c.pd_linux: + ../tk2c.bash < $*.tk >$*.tk2c + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm + strip --strip-unneeded $*.pd_linux + rm -f $*.o ../$*.pd_linux + ln -s $*/$*.pd_linux .. + +# ---------------------------------------------------------- + +install: + cp help-*.pd ../../doc/5.reference + +clean: + rm -f *.o *.pd_* so_locations diff --git a/exciter/README b/exciter/README new file mode 100644 index 0000000..b57b6c9 --- /dev/null +++ b/exciter/README @@ -0,0 +1,20 @@ +Version 0.01
+copyright 2002 by Yves Degoyon.
+
+tarballs and updates available @ http://ydegoyon.free.fr
+
+exciter : a bang-events sequencer
+the need for it sprung out of a talking with Nicolas Lhommet.
+
+To install exciter, follow the steps from INSTALL
+
+This software is published under GPL terms.
+
+This is software with ABSOLUTELY NO WARRANTY.
+Use it at your OWN RISK. It's possible to damage e.g. hardware or your hearing
+due to a bug or for other reasons.
+We do not warrant that the program is free of infringement of any third-party
+patents.
+
+*****************************************************************************
+
diff --git a/exciter/exciter.c b/exciter/exciter.c new file mode 100644 index 0000000..4f15de2 --- /dev/null +++ b/exciter/exciter.c @@ -0,0 +1,841 @@ +/* Copyright (c) 2002 Yves Degoyon. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ +/* */ +/* exciter : a graphical object which enables */ +/* to schedule bang events on a time scale */ +/* */ +/* 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. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* 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; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* Made while listening to : */ +/* */ +/* "You're a maniac" */ +/* "To fullfill the emptyness" */ +/* Mecano ( no, not the spanish ones !!! ) - Escape The Human Myth */ +/* ---------------------------------------------------------------------------- */ + + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <math.h> +#include <ctype.h> +#include <time.h> +#include <sys/time.h> +#include "m_imp.h" +#include "g_canvas.h" +#include "t_tk.h" +#include "exciter.h" + +#ifdef NT +#include <io.h> +#else +#include <unistd.h> +#endif + +/* needed to create a exciter from PD's menu +void canvas_objtext(t_glist *gl, int xpos, int ypos, int selected, t_binbuf *b); +void canvas_startmotion(t_canvas *x); +*/ + +#define DEFAULT_EXCITER_WIDTH 200 +#define DEFAULT_EXCITER_HEIGHT 200 +#define DEFAULT_EXCITER_GRAIN 0.1 +#define DEFAULT_EXCITER_NBEVENTS 8 + +#define EXCITER_PIXEL_GRAIN 5 + +static char *exciter_version = "exciter: a bang-events sequencer, version 0.2 (ydegoyon@free.fr)"; + +t_widgetbehavior exciter_widgetbehavior; +static t_class *exciter_class; +static int excitercount=0; + +static int guidebug=0; +static int pointsize = 5; + +#define SYS_VGUI2(a,b) if (guidebug) \ + post(a,b);\ + sys_vgui(a,b) + +#define SYS_VGUI3(a,b,c) if (guidebug) \ + post(a,b,c);\ + sys_vgui(a,b,c) + +#define SYS_VGUI4(a,b,c,d) if (guidebug) \ + post(a,b,c,d);\ + sys_vgui(a,b,c,d) + +#define SYS_VGUI5(a,b,c,d,e) if (guidebug) \ + post(a,b,c,d,e);\ + sys_vgui(a,b,c,d,e) + +#define SYS_VGUI6(a,b,c,d,e,f) if (guidebug) \ + post(a,b,c,d,e,f);\ + sys_vgui(a,b,c,d,e,f) + +#define SYS_VGUI7(a,b,c,d,e,f,g) if (guidebug) \ + post(a,b,c,d,e,f,g);\ + sys_vgui(a,b,c,d,e,f,g) + +#define SYS_VGUI8(a,b,c,d,e,f,g,h) if (guidebug) \ + post(a,b,c,d,e,f,g,h);\ + sys_vgui(a,b,c,d,e,f,g,h) + +#define SYS_VGUI9(a,b,c,d,e,f,g,h,i) if (guidebug) \ + post(a,b,c,d,e,f,g,h,i);\ + sys_vgui(a,b,c,d,e,f,g,h,i) + +#define SYS_VGUI13(a,b,c,d,e,f,g,h,i,j,k,l,m) if (guidebug) \ + post(a,b,c,d,e,f,g,h,i,j,k,l,m);\ + sys_vgui(a,b,c,d,e,f,g,h,i,j,k,l,m) + +/* drawing functions */ + +/* draw an event */ +static void exciter_draw_gem(t_exciter *x, t_glist *glist, t_int ix, t_int iy) +{ + t_int polyray = ( x->x_height / x->x_nbevents) / 2; + t_canvas *canvas=glist_getcanvas(glist); + + SYS_VGUI13(".x%x.c create polygon %d %d %d %d %d %d %d %d -outline #000000 -fill #FFFFFF -tags %xEVENT%.4d%.4d\n", + canvas, + x->x_obj.te_xpix + ix*EXCITER_PIXEL_GRAIN, + x->x_obj.te_ypix + x->x_height - (iy+1)*x->x_height/x->x_nbevents + 2*polyray, + x->x_obj.te_xpix + ix*EXCITER_PIXEL_GRAIN + polyray, + x->x_obj.te_ypix + x->x_height - (iy+1)*x->x_height/x->x_nbevents + polyray, + x->x_obj.te_xpix + ix*EXCITER_PIXEL_GRAIN + 2*polyray, + x->x_obj.te_ypix + x->x_height - (iy+1)*x->x_height/x->x_nbevents, + x->x_obj.te_xpix + ix*EXCITER_PIXEL_GRAIN + polyray, + x->x_obj.te_ypix + x->x_height - (iy+1)*x->x_height/x->x_nbevents - polyray, + x, ix, iy); +} + +/* delete an event */ +static void exciter_delete_gem(t_exciter *x, t_glist *glist, t_int ix, t_int iy) +{ + t_canvas *canvas=glist_getcanvas(glist); + + SYS_VGUI5(".x%x.c delete %xEVENT%.4d%.4d\n", canvas, x, ix, iy ); +} + +static void exciter_draw_update(t_exciter *x, t_glist *glist) +{ + int ei, gi; + + t_canvas *canvas=glist_getcanvas(glist); + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ ) + { + if( *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi) == 1 ) + { + exciter_draw_gem(x, glist, gi, ei ); + } + else + { + exciter_delete_gem(x, glist, gi, ei ); + } + } + } +} + +static void exciter_draw_new(t_exciter *x, t_glist *glist) +{ + t_canvas *canvas=glist_getcanvas(glist); + t_int ei; + + SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -outline #000000 -fill #902181 -tags %xLINE\n", + canvas, x->x_obj.te_xpix, x->x_obj.te_ypix, + x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix+x->x_height, + x); + SYS_VGUI5(".x%x.c create text %d %d -font -*-courier-bold--normal--10-* -text \"0 s\" -tags %xLOWERCAPTION\n", + canvas, x->x_obj.te_xpix, x->x_obj.te_ypix + x->x_height + 10, x ); + SYS_VGUI6(".x%x.c create text %d %d -font -*-courier-bold--normal--10-* -text \"%.2f s\" -tags %xHIGHERCAPTION\n", + canvas, x->x_obj.te_xpix + x->x_width, x->x_obj.te_ypix + x->x_height + 10, + x->x_width/EXCITER_PIXEL_GRAIN*x->x_timegrain , x); + SYS_VGUI7(".x%x.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xIN\n", + canvas, x->x_obj.te_xpix, + x->x_obj.te_ypix - 2, + x->x_obj.te_xpix + 5, + x->x_obj.te_ypix , + x); + if ( x->x_nbevents > 1 ) + { + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + SYS_VGUI8(".x%x.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n", + canvas, x->x_obj.te_xpix + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1), + x->x_obj.te_ypix + x->x_height, + x->x_obj.te_xpix + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1) + 5, + x->x_obj.te_ypix + x->x_height + 2, + x, ei); + } + } + else + { + SYS_VGUI8(".x%x.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n", + canvas, x->x_obj.te_xpix, + x->x_obj.te_ypix + x->x_height, + x->x_obj.te_xpix + 5, + x->x_obj.te_ypix + x->x_height + 2, + x, 0); + } + canvas_fixlinesfor( canvas, (t_text*)x ); +} + +static void exciter_draw_move(t_exciter *x, t_glist *glist) +{ + t_canvas *canvas=glist_getcanvas(glist); + t_int polyray = ( x->x_height / x->x_nbevents) / 2; + t_int ei, gi; + + SYS_VGUI7(".x%x.c coords %xLINE %d %d %d %d \n", + canvas, x, x->x_obj.te_xpix, x->x_obj.te_ypix, + x->x_obj.te_xpix+x->x_width, x->x_obj.te_ypix+x->x_height + ); + SYS_VGUI5(".x%x.c coords %xLOWERCAPTION %d %d\n", + canvas, x, x->x_obj.te_xpix, x->x_obj.te_ypix + x->x_height + 10 ); + SYS_VGUI5(".x%x.c coords %xHIGHERCAPTION %d %d\n", + canvas, x, x->x_obj.te_xpix + x->x_width, x->x_obj.te_ypix + x->x_height + 10); + SYS_VGUI7(".x%x.c coords %xIN %d %d %d %d\n", + canvas, x, x->x_obj.te_xpix, + x->x_obj.te_ypix - 2, + x->x_obj.te_xpix + 5, + x->x_obj.te_ypix + ); + if ( x->x_nbevents > 1 ) + { + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + SYS_VGUI8(".x%x.c coords %xOUT%d %d %d %d %d\n", + canvas, x, ei, x->x_obj.te_xpix + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1), + x->x_obj.te_ypix + x->x_height, + x->x_obj.te_xpix + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1) + 5, + x->x_obj.te_ypix + x->x_height + 2 + ); + } + } + else + { + SYS_VGUI8(".x%x.c coords %xOUT%d %d %d %d %d\n", + canvas, x, 0, x->x_obj.te_xpix, + x->x_obj.te_ypix + x->x_height, + x->x_obj.te_xpix + 5, + x->x_obj.te_ypix + x->x_height + 2 + ); + } + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ ) + { + SYS_VGUI13(".x%x.c coords %xEVENT%.4d%.4d %d %d %d %d %d %d %d %d\n", + canvas, x, gi, ei, + x->x_obj.te_xpix + gi*EXCITER_PIXEL_GRAIN, + x->x_obj.te_ypix + x->x_height - (ei+1)*x->x_height/x->x_nbevents + 2*polyray, + x->x_obj.te_xpix + gi*EXCITER_PIXEL_GRAIN + polyray, + x->x_obj.te_ypix + x->x_height - (ei+1)*x->x_height/x->x_nbevents + polyray, + x->x_obj.te_xpix + gi*EXCITER_PIXEL_GRAIN + 2*polyray, + x->x_obj.te_ypix + x->x_height - (ei+1)*x->x_height/x->x_nbevents, + x->x_obj.te_xpix + gi*EXCITER_PIXEL_GRAIN + polyray, + x->x_obj.te_ypix + x->x_height - (ei+1)*x->x_height/x->x_nbevents - polyray + ); + } + } + canvas_fixlinesfor( canvas, (t_text*)x ); +} + +static void exciter_draw_erase(t_exciter* x,t_glist* glist) +{ + t_canvas *canvas=glist_getcanvas(glist); + int i, ei, gi; + + SYS_VGUI3(".x%x.c delete %xLINE\n", canvas, x ); + SYS_VGUI3(".x%x.c delete %xLOWERCAPTION\n", canvas, x ); + SYS_VGUI3(".x%x.c delete %xHIGHERCAPTION\n", canvas, x ); + SYS_VGUI3(".x%x.c delete %xIN\n", canvas, x ); + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ ) + { + if( *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi) != 0 ) + { + exciter_delete_gem( x, glist, gi, ei ); + } + } + SYS_VGUI4(".x%x.c delete %xOUT%d\n", canvas, x, ei ); + } +} + +static void exciter_draw_select(t_exciter* x,t_glist* glist) +{ + t_canvas *canvas=glist_getcanvas(glist); + + if(x->x_selected) + { + /* sets the main item in blue */ + SYS_VGUI3(".x%x.c itemconfigure %xLINE -outline #0000FF\n", glist_getcanvas(glist), x); + + } + else + { + /* sets the main item in black */ + SYS_VGUI3(".x%x.c itemconfigure %xLINE -outline #000000\n", glist_getcanvas(glist), x); + } +} + +/* ------------------------ exciter widgetbehaviour----------------------------- */ + + +static void exciter_getrect(t_gobj *z, t_glist *owner, + int *xp1, int *yp1, int *xp2, int *yp2) +{ + t_exciter* x = (t_exciter*)z; + + *xp1 = x->x_obj.te_xpix; + *yp1 = x->x_obj.te_ypix; + *xp2 = x->x_obj.te_xpix+x->x_width; + *yp2 = x->x_obj.te_ypix+x->x_height; +} + +static void exciter_save(t_gobj *z, t_binbuf *b) +{ + t_exciter *x = (t_exciter *)z; + int ei,gi; + + binbuf_addv(b, "ssiisiiifii", gensym("#X"),gensym("obj"), + (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix, + gensym("exciter"), x->x_width, x->x_height, + x->x_nbevents, x->x_timegrain, + x->x_loop, x->x_save + ); + if ( x->x_save ) + { + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ ) + { + if( *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi) == 1 ) + { + // post( "exciter : saving ( %d, %d )", ei, gi ); + binbuf_addv(b, "ii", ei, gi ); + } + } + } + } + binbuf_addv(b, ";"); +} + +static void exciter_properties(t_gobj *z, t_glist *owner) +{ + char buf[800]; + t_exciter *x=(t_exciter *)z; + + sprintf(buf, "pdtk_exciter_dialog %%s %d %d %d %.2f %d %d\n", + x->x_width, x->x_height, x->x_nbevents, x->x_timegrain, x->x_loop, x->x_save ); + // post("exciter_properties : %s", buf ); + gfxstub_new(&x->x_obj.ob_pd, x, buf); +} + +static void exciter_select(t_gobj *z, t_glist *glist, int selected) +{ + t_exciter *x = (t_exciter *)z; + + x->x_selected = selected; + exciter_draw_select( x, glist ); +} + +static void exciter_vis(t_gobj *z, t_glist *glist, int vis) +{ + t_exciter *x = (t_exciter *)z; + t_rtext *y; + + // post("exciter_vis : %d", vis ); + if (vis) + { + exciter_draw_new( x, glist ); + exciter_draw_update( x, glist ); + } + else + { + exciter_draw_erase( x, glist ); + } +} + + /* resuming the triggering of events */ +static void exciter_resume(t_exciter *x) +{ + x->x_started = 1; +} + + /* pausing the triggering of events */ +static void exciter_pause(t_exciter *x) +{ + x->x_started = 0; +} + + /* trigger events -- no dsp processing */ +static void exciter_dialog(t_exciter *x, t_symbol *s, int argc, t_atom *argv) +{ + t_int onbevents, owidth, ei, gi, bi; + t_canvas *canvas=glist_getcanvas(x->x_glist); + + if ( !x ) { + post( "exciter : error :tried to set properties on an unexisting object" ); + } + onbevents = x->x_nbevents; + owidth = x->x_width; + exciter_draw_erase(x, x->x_glist); + if ( argc < 6 ) + { + post( "exciter : error in the number of arguments ( %d )", argc ); + return; + } + if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT || + argv[2].a_type != A_FLOAT || argv[3].a_type != A_FLOAT || + argv[4].a_type != A_FLOAT || argv[5].a_type != A_FLOAT ) + { + post( "exciter : wrong arguments" ); + return; + } + + exciter_pause( x ); + x->x_width = argv[0].a_w.w_float; + if ( x->x_width <= 0 ) x->x_width = 100; + x->x_height = argv[1].a_w.w_float; + if ( x->x_height <= 0 ) x->x_height = 100; + x->x_nbevents = argv[2].a_w.w_float; + if ( x->x_nbevents < 1 ) x->x_nbevents = 1; + x->x_timegrain = argv[3].a_w.w_float; + if ( x->x_timegrain < 0.01 ) + { + post ("exciter : incorrect time grain : forced to 1 tick ( 10 ms )" ); + x->x_timegrain = 0.01; + } + x->x_loop = argv[4].a_w.w_float; + x->x_save = argv[5].a_w.w_float; + x->x_started = 0; + x->x_reltime = 0L; + x->x_plooptime = 0L; + x->x_gindex = -1; + x->x_looplength = x->x_timegrain * x->x_width * 1000 / EXCITER_PIXEL_GRAIN; + + // re-allocate arrays and keep old events + post( "exciter : re-allocate events" ); + if ( onbevents != x->x_nbevents || owidth != x->x_width ) + { + t_int mevents = ( onbevents > x->x_nbevents ) ? x->x_nbevents : onbevents; + t_int mwidth = ( owidth > x->x_width ) ? x->x_width : owidth; + t_int *newbangs; + + newbangs = (t_int*) getbytes( x->x_nbevents*x->x_width/EXCITER_PIXEL_GRAIN*sizeof(t_int) ); + memset( newbangs, 0x0, x->x_nbevents*x->x_width/EXCITER_PIXEL_GRAIN*sizeof(t_int) ); + for ( ei=0; ei<mevents; ei++ ) + { + for ( gi=0; gi<(mwidth/EXCITER_PIXEL_GRAIN); gi++ ) + { + *(newbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi ) = + *(x->x_sbangs+ei*(owidth/EXCITER_PIXEL_GRAIN)+gi ); + } + } + if ( x->x_sbangs ) + freebytes( x->x_sbangs, onbevents*owidth/EXCITER_PIXEL_GRAIN*sizeof(t_int) ); + x->x_sbangs = newbangs; + } + + // re-allocate outlets + post( "exciter : re-allocate outlets" ); + if ( onbevents != x->x_nbevents ) + { + post( "exciter : cleaning up old outlets" ); + if ( x->x_bangs ) + { + for ( ei=0; ei<onbevents; ei++ ) + { + outlet_free( x->x_bangs[ei] ); + } + freebytes( x->x_bangs, onbevents*sizeof(t_outlet*) ); + } + post( "exciter : creating new ones" ); + x->x_bangs = (t_outlet **) getbytes( x->x_nbevents*sizeof(t_outlet **) ); + for ( bi=0; bi<x->x_nbevents; bi++ ) + { + x->x_bangs[bi] = outlet_new( &x->x_obj, &s_bang ); + } + } + canvas_fixlinesfor( canvas, (t_text*)x ); + exciter_draw_new(x, x->x_glist); + exciter_draw_update(x, x->x_glist); + exciter_resume( x ); +} + +static void exciter_delete(t_gobj *z, t_glist *glist) +{ + canvas_deletelinesfor( glist_getcanvas(glist), (t_text *)z); +} + +static void exciter_displace(t_gobj *z, t_glist *glist, int dx, int dy) +{ + t_exciter *x = (t_exciter *)z; + int xold = x->x_obj.te_xpix; + int yold = x->x_obj.te_ypix; + + // post( "exciter_displace dx=%d dy=%d", dx, dy ); + + x->x_obj.te_xpix += dx; + x->x_obj.te_ypix += dy; + if(xold != x->x_obj.te_xpix || yold != x->x_obj.te_ypix) + { + exciter_draw_move(x, x->x_glist); + } +} + +static int exciter_click(t_gobj *z, struct _glist *glist, + int xpix, int ypix, int shift, int alt, int dbl, int doit) +{ + t_exciter* x = (t_exciter *)z; + t_canvas *canvas=glist_getcanvas(glist); + t_int nevent, npix; + + if ( doit) + { + nevent = ( 1 - ( ( ypix - ( (float)x->x_height / (float) x->x_nbevents / 2 ) + - x->x_obj.te_ypix) / (float)x->x_height ) )*(x->x_nbevents-1); + npix = ( xpix - 1 - x->x_obj.te_xpix) / EXCITER_PIXEL_GRAIN; + // post( "exciter : selected event (%d,%d)", nevent, npix ); + // set or unset event + { + if ( *(x->x_sbangs+nevent*(x->x_width/EXCITER_PIXEL_GRAIN)+npix ) == 1 ) + { + *(x->x_sbangs+nevent*(x->x_width/EXCITER_PIXEL_GRAIN)+npix ) = 0; + exciter_delete_gem( x, glist, npix, nevent ); + } + else + { + *(x->x_sbangs+nevent*(x->x_width/EXCITER_PIXEL_GRAIN)+npix ) = 1; + exciter_draw_gem( x, glist, npix, nevent ); + } + } + } + return (1); +} + +static t_exciter *exciter_new(t_symbol *s, int argc, t_atom *argv) +{ + int bi, i, ei, gi; + t_exciter *x; + t_pd *x2; + + // post( "exciter_new : create : %s argc =%d", s->s_name, argc ); + + x = (t_exciter *)pd_new(exciter_class); + // new exciter created from the gui + if ( argc != 0 ) + { + if ( argc < 6 ) + { + post( "exciter : error in the number of arguments ( %d )", argc ); + return NULL; + } + if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT || + argv[2].a_type != A_FLOAT || argv[3].a_type != A_FLOAT || + argv[4].a_type != A_FLOAT || argv[5].a_type != A_FLOAT ) + { + post( "exciter : wrong arguments" ); + return NULL; + } + + x->x_width = argv[0].a_w.w_float; + x->x_height = argv[1].a_w.w_float; + x->x_nbevents = argv[2].a_w.w_float; + if ( x->x_nbevents < 1 ) x->x_nbevents = 1; + x->x_timegrain = argv[3].a_w.w_float; + x->x_loop = argv[4].a_w.w_float; + x->x_save = argv[5].a_w.w_float; + } + else + { + x->x_width = DEFAULT_EXCITER_WIDTH; + x->x_height = DEFAULT_EXCITER_HEIGHT; + x->x_nbevents = DEFAULT_EXCITER_NBEVENTS; + x->x_timegrain = DEFAULT_EXCITER_GRAIN; + x->x_loop = 1; + x->x_save = 1; + + } + + // common fields for new and restored exciters + x->x_sbangs = (t_int*) getbytes( x->x_nbevents*x->x_width/EXCITER_PIXEL_GRAIN*sizeof(t_int) ); + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ ) + { + *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi) = 0; + } + } + memset( x->x_sbangs, 0x0, x->x_nbevents*x->x_width/EXCITER_PIXEL_GRAIN*sizeof(t_int) ); + x->x_selected = 0; + x->x_started = 0; + x->x_reltime = 0L; + x->x_plooptime = 0L; + x->x_gindex = -1; + x->x_looplength = x->x_timegrain * x->x_width * 1000 / EXCITER_PIXEL_GRAIN; + x->x_glist = (t_glist *) canvas_getcurrent(); + + x->x_bangs = (t_outlet **) getbytes( x->x_nbevents*sizeof(t_outlet **) ); + for ( bi=0; bi<x->x_nbevents; bi++ ) + { + x->x_bangs[bi] = outlet_new( &x->x_obj, &s_bang ); + } + + // post( "exciter : argc : %d", argc ); + if ( ( argc != 0 ) && ( x->x_save ) ) + { + int ai = 6; + int si = 0; + + while ( ai < argc - 1 ) + { + *(x->x_sbangs + +((int)argv[ai].a_w.w_float)*(x->x_width/EXCITER_PIXEL_GRAIN) + +(int)argv[ai+1].a_w.w_float) = 1; + ai += 2; + } + } + // post( "exciter_new width: %d height : %d", x->x_width, x->x_height ); + + return (x); +} + +static void exciter_dump(t_exciter *x) +{ + t_int ei, gi; + + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ ) + { + if ( *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi ) != 0 ) + { + post( "exciter : value ( %d, %d ) : %d", ei, gi, + *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi ) ); + } + } + } +} + + /* clearing all events */ +static void exciter_clear(t_exciter *x) +{ + t_int ei, gi; + + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ ) + { + *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi ) = 0; + } + } + exciter_draw_update( x, x->x_glist ); +} + + + /* starting the triggering of events */ +static void exciter_start(t_exciter *x) +{ + x->x_started = 1; + x->x_reltime = 0L; + x->x_plooptime = 0L; + x->x_gindex = -1; +} + + /* stop the triggering of events */ +static void exciter_stop(t_exciter *x) +{ + x->x_started = 0; +} + + /* reset the triggering of events */ +static void exciter_reset(t_exciter *x) +{ + x->x_reltime = 0L; + x->x_plooptime = 0L; + x->x_gindex = -1; +} + +static t_int *exciter_perform(t_int *w) +{ + t_int ei, gi; + t_int gstart, gend; + t_exciter* x = (t_exciter*)(w[1]); + struct timeval tv; + struct timezone tz; + long long looptime = 0L; + double preltime = x->x_reltime; + + if ( x->x_started ) + { + // get current time in ms + gettimeofday( &tv, &tz ); + looptime = tv.tv_sec*1000 + tv.tv_usec/1000; + if ( x->x_plooptime == 0L ) + { + x->x_plooptime = looptime; + } + x->x_reltime += ( looptime - x->x_plooptime ); + if ( x->x_reltime > x->x_looplength ) + { + if ( x->x_loop ) + { + // post( "exciter : restarting loop" ); + x->x_reltime = 0; + preltime = 0; + x->x_gindex = -1; + } + else + { + // post( "exciter : end of the loop" ); + x->x_reltime = 0; + x->x_started = 0; + } + } + gstart = preltime/(x->x_timegrain*1000); + gend = x->x_reltime/(x->x_timegrain*1000); + + // prevent overflow due to long long precision + if ( gstart > x->x_width/EXCITER_PIXEL_GRAIN-1 ) gstart = x->x_width/EXCITER_PIXEL_GRAIN-1; + if ( gstart < 0 ) gstart = 0; + if ( gend > x->x_width/EXCITER_PIXEL_GRAIN-1 ) gend = x->x_width/EXCITER_PIXEL_GRAIN-1 ; + if ( gend < 0 ) gend = 0; + if ( gstart > x->x_gindex ) + { + // post( "exciter : focus slice : (%d,%d)", gstart, gend ); + for ( gi=x->x_gindex+1; gi<=gend; gi++ ) + { + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + if ( *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi ) == 1 ) + { + outlet_bang( x->x_bangs[ ei ] ); + SYS_VGUI5(".x%x.c itemconfigure %xEVENT%.4d%.4d -fill #00FF00\n", + glist_getcanvas(x->x_glist), x, gi, ei); + } + } + } + // unfocus previous events + if ( gstart >= x->x_width/EXCITER_PIXEL_GRAIN - 1) + gstart = x->x_width/EXCITER_PIXEL_GRAIN; // not too proud of this one + // post( "exciter : unfocus slice : (%d,%d)", x->x_gindex, gstart-1 ); + for ( gi=x->x_gindex; gi<gstart; gi++ ) + { + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + if ( *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi ) == 1 ) + { + SYS_VGUI5(".x%x.c itemconfigure %xEVENT%.4d%.4d -fill #FFFFFF\n", + glist_getcanvas(x->x_glist), x, gi, ei); + } + } + } + x->x_gindex = gend; + } + } + + x->x_plooptime = looptime; + return (w+2); +} + +static void exciter_dsp(t_exciter *x, t_signal **sp) +{ + dsp_add(exciter_perform, 1, x); +} + +static void exciter_free(t_exciter *x) +{ + t_int ei; + + // post( "exciter~: exciter_free" ); + if ( x->x_bangs ) + { + for ( ei=0; ei<x->x_nbevents; ei++ ) + { + outlet_free( x->x_bangs[ei] ); + } + freebytes( x->x_bangs, x->x_nbevents*sizeof(t_outlet*) ); + } + if ( x->x_sbangs ) + { + freebytes( x->x_sbangs, x->x_nbevents*x->x_width/EXCITER_PIXEL_GRAIN*sizeof(t_int) ); + } +} + +void exciter_setup(void) +{ + post( exciter_version ); +#include "exciter.tk2c" + exciter_class = class_new(gensym("exciter"), (t_newmethod)exciter_new, + (t_method)exciter_free, sizeof(t_exciter), 0, A_GIMME, 0); + class_addmethod(exciter_class, (t_method)exciter_dialog, gensym("dialog"), A_GIMME, 0); + class_addmethod(exciter_class, (t_method)exciter_dump, gensym("dump"), 0); + class_addmethod(exciter_class, (t_method)exciter_clear, gensym("clear"), 0); + class_addmethod(exciter_class, (t_method)exciter_start, gensym("start"), 0); + class_addmethod(exciter_class, (t_method)exciter_stop, gensym("stop"), 0); + class_addmethod(exciter_class, (t_method)exciter_reset, gensym("reset"), 0); + class_addmethod(exciter_class, (t_method)exciter_pause, gensym("pause"), 0); + class_addmethod(exciter_class, (t_method)exciter_resume, gensym("resume"), 0); + class_addmethod(exciter_class, (t_method)exciter_dsp, gensym("dsp"), A_NULL); + exciter_widgetbehavior.w_getrectfn = exciter_getrect; + exciter_widgetbehavior.w_displacefn = exciter_displace; + exciter_widgetbehavior.w_selectfn = exciter_select; + exciter_widgetbehavior.w_activatefn = NULL; + exciter_widgetbehavior.w_deletefn = exciter_delete; + exciter_widgetbehavior.w_visfn = exciter_vis; + exciter_widgetbehavior.w_clickfn = exciter_click; + exciter_widgetbehavior.w_propertiesfn = exciter_properties; + exciter_widgetbehavior.w_savefn = exciter_save; + class_setwidget(exciter_class, &exciter_widgetbehavior); + class_sethelpsymbol(exciter_class, gensym("help-exciter.pd")); +} + +/* OPTIONAL */ + /* callback caught by canvas class for the creation of a exciter */ +/* +void canvas_exciter(t_glist *gl, t_symbol *s, int argc, t_atom *argv) +{ + t_atom at; + t_binbuf *b = binbuf_new(); + int xval, yval; + int i; + + pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1); + glist_noselect(gl); + if ( argc == 0 ) + { + SETSYMBOL(&at, gensym("exciter")); + } + else + { + SETSYMBOL(&at, argv[1].a_w.w_symbol); + } + binbuf_restore(b, 1, &at); + glist_getnextxy(gl, &xval, &yval); + canvas_objtext(gl, xval, yval, 1, b); + canvas_startmotion(glist_getcanvas(gl)); +} +*/ diff --git a/exciter/exciter.h b/exciter/exciter.h new file mode 100644 index 0000000..81076a1 --- /dev/null +++ b/exciter/exciter.h @@ -0,0 +1,34 @@ +/* Copyright (c) 2002 Yves Degoyon +* For information on usage and redistribution, and for a DISCLAIMER OF ALL +* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +/* a header for exciter which enables +* to trigger bang events scheduled with the mouse +*/ + +#ifndef __G_EXCITER_H +#define __G_EXCITER_H + +typedef struct _exciter +{ + t_object x_obj; + t_glist *x_glist; + t_outlet **x_bangs; + t_int x_height; /* height of the exciter */ + t_int x_width; /* width of the exciter */ + t_int x_nbevents; /* number of simultaneous events */ + t_float x_timegrain; /* time granularity for one pixel */ + t_int *x_sbangs; /* scheduled bangs */ + int x_selected; /* stores selected state */ + int x_loop; /* looping flag */ + int x_save; /* saving contents flag */ + + /* internal processing */ + long long x_plooptime; /* initial time */ + long long x_reltime; /* elapsed time since start */ + long long x_looplength; /* length of a loop */ + t_int x_started; /* start flag */ + t_int x_gindex; /* last scanned index */ +} t_exciter; + +#endif diff --git a/exciter/exciter.tk b/exciter/exciter.tk new file mode 100644 index 0000000..c0280e6 --- /dev/null +++ b/exciter/exciter.tk @@ -0,0 +1,123 @@ +############ exciter procedures -- ydegoyon@free.fr ######### + +proc exciter_apply {id} { +# strip "." from the TK id to make a variable name suffix + set vid [string trimleft $id .] +# for each variable, make a local variable to hold its name... + set var_graph_width [concat graph_width_$vid] + global $var_graph_width + set var_graph_height [concat graph_height_$vid] + global $var_graph_height + set var_graph_nbevents [concat graph_nbevents_$vid] + global $var_graph_nbevents + set var_graph_timegrain [concat graph_timegrain_$vid] + global $var_graph_timegrain + set var_graph_loop [concat graph_loop_$vid] + global $var_graph_loop + set var_graph_save [concat graph_save_$vid] + global $var_graph_save + + set cmd [concat $id dialog \ + [eval concat $$var_graph_width] \ + [eval concat $$var_graph_height] \ + [eval concat $$var_graph_nbevents] \ + [eval concat $$var_graph_timegrain] \ + [eval concat $$var_graph_loop] \ + [eval concat $$var_graph_save] \;] + #puts stderr $cmd + pd $cmd +} + +proc exciter_cancel {id} { + set cmd [concat $id cancel \;] + #puts stderr $cmd + pd $cmd +} + +proc exciter_ok {id} { + exciter_apply $id + exciter_cancel $id +} + +proc pdtk_exciter_dialog {id width height nbevents timegrain loop save } { + set vid [string trimleft $id .] + + set var_graph_width [concat graph_width_$vid] + global $var_graph_width + set var_graph_height [concat graph_height_$vid] + global $var_graph_height + set var_graph_nbevents [concat graph_nbevents_$vid] + global $var_graph_nbevents + set var_graph_timegrain [concat graph_timegrain_$vid] + global $var_graph_timegrain + set var_graph_loop [concat graph_loop_$vid] + global $var_graph_loop + set var_graph_save [concat graph_save_$vid] + global $var_graph_save + + set $var_graph_width $width + set $var_graph_height $height + set $var_graph_nbevents $nbevents + set $var_graph_timegrain $timegrain + set $var_graph_loop $loop + set $var_graph_save $save + + toplevel $id + wm title $id {exciter} + wm protocol $id WM_DELETE_WINDOW [concat exciter_cancel $id] + + label $id.label -text {EXCITER PROPERTIES} + pack $id.label -side top + + frame $id.buttonframe + pack $id.buttonframe -side bottom -fill x -pady 2m + button $id.buttonframe.cancel -text {Cancel}\ + -command "exciter_cancel $id" + button $id.buttonframe.apply -text {Apply}\ + -command "exciter_apply $id" + button $id.buttonframe.ok -text {OK}\ + -command "exciter_ok $id" + pack $id.buttonframe.cancel -side left -expand 1 + pack $id.buttonframe.apply -side left -expand 1 + pack $id.buttonframe.ok -side left -expand 1 + + frame $id.1rangef + pack $id.1rangef -side top + label $id.1rangef.lwidth -text "Width :" + entry $id.1rangef.width -textvariable $var_graph_width -width 7 + pack $id.1rangef.lwidth $id.1rangef.width -side left + + frame $id.2rangef + pack $id.2rangef -side top + label $id.2rangef.lheight -text "Height :" + entry $id.2rangef.height -textvariable $var_graph_height -width 7 + pack $id.2rangef.lheight $id.2rangef.height -side left + + frame $id.3rangef + pack $id.3rangef -side top + label $id.3rangef.lnbevents -text "Nb Events :" + entry $id.3rangef.nbevents -textvariable $var_graph_nbevents -width 7 + pack $id.3rangef.lnbevents $id.3rangef.nbevents -side left + + frame $id.4rangef + pack $id.4rangef -side top + label $id.4rangef.ltimegrain -text "Time Grain (seconds) :" + entry $id.4rangef.timegrain -textvariable $var_graph_timegrain -width 7 + pack $id.4rangef.ltimegrain $id.4rangef.timegrain -side left + + checkbutton $id.loop -text {Loop} -variable $var_graph_loop \ + -anchor w + pack $id.loop -side top + + checkbutton $id.save -text {Save contents} -variable $var_graph_save \ + -anchor w + pack $id.save -side top + + bind $id.1rangef.width <KeyPress-Return> [concat exciter_ok $id] + bind $id.2rangef.height <KeyPress-Return> [concat exciter_ok $id] + bind $id.3rangef.nbevents <KeyPress-Return> [concat exciter_ok $id] + bind $id.4rangef.timegrain <KeyPress-Return> [concat exciter_ok $id] + focus $id.1rangef.width +} + +############ exciter procedures END -- ydegoyon@free.fr ######### diff --git a/exciter/help-exciter.pd b/exciter/help-exciter.pd new file mode 100644 index 0000000..ab60831 --- /dev/null +++ b/exciter/help-exciter.pd @@ -0,0 +1,71 @@ +#N canvas 103 12 970 685 10; +#X text 457 89 (invoke with <right mouse>Properties ); +#X text 458 78 You can set the following properties :; +#X text 478 110 * Width : graphical x size; +#X text 478 121 * Height : graphical y size; +#X text 612 498 bugs and comments @ ydegoyon@free.fr; +#X msg 587 271 \; pd dsp 0; +#X msg 653 271 \; pd dsp 1; +#X obj 32 56 exciter 400 200 16 0.1 1 1 1 14 1 15 3 52 5 30 5 69 6 +8 8 20 9 32 9 74 10 79 11 14 11 74 12 79 13 40 13 79 15 78; +#X text 456 50 Exciter controls a list of bang-events scheduled in +time; +#X obj 22 282 print e1; +#X text 478 132 * Number of events : number of simultaneous events +; +#X text 477 155 * Loop : looping flag; +#X msg 193 29 reset; +#X msg 103 29 pause; +#X msg 31 29 start; +#X msg 145 29 resume; +#X msg 70 29 stop; +#X text 44 363 so that events are triggered; +#X obj 653 249 loadbang; +#X msg 239 30 clear; +#X text 102 389 Note 2 : the event happens in the center (?) of the +polygon; +#X msg 286 30 dump; +#X text 478 144 * Time Grain : time grain betweeen each event; +#X obj 80 283 print e3; +#X obj 137 284 print e5; +#X obj 194 283 print e7; +#X obj 252 284 print e9; +#X obj 308 284 print e11; +#X obj 366 284 print e13; +#X obj 429 285 print e15; +#X obj 45 307 print e2; +#X obj 103 308 print e4; +#X obj 217 308 print e8; +#X obj 275 309 print e10; +#X obj 335 310 print e12; +#X obj 396 309 print e14; +#X obj 457 309 print e16; +#X obj 160 309 print e6; +#X text 523 411 ( 10 ms ) \, it won't be processed properly; +#X text 523 399 WARNING : you can't set time grain below 1 clock tick +; +#X text 46 352 Note 1 : the dsp has to be on; +#X connect 7 0 9 0; +#X connect 7 1 30 0; +#X connect 7 2 23 0; +#X connect 7 3 31 0; +#X connect 7 4 24 0; +#X connect 7 5 37 0; +#X connect 7 6 25 0; +#X connect 7 7 32 0; +#X connect 7 8 26 0; +#X connect 7 9 33 0; +#X connect 7 10 27 0; +#X connect 7 11 34 0; +#X connect 7 12 28 0; +#X connect 7 13 35 0; +#X connect 7 14 29 0; +#X connect 7 15 36 0; +#X connect 12 0 7 0; +#X connect 13 0 7 0; +#X connect 14 0 7 0; +#X connect 15 0 7 0; +#X connect 16 0 7 0; +#X connect 18 0 6 0; +#X connect 19 0 7 0; +#X connect 21 0 7 0; |