aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2012-02-19 03:03:32 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 15:23:30 +0200
commitb317e860079c1fb166a95d0b5c17574cb6a32d4f (patch)
tree4c887f7c644f618763b656fe4297509c07f36000
parentfb95f8f94849db058a566cde134f52b5f50ddfcf (diff)
reformat code to match Pd style by running 'astyle --style=ansi *.c'
svn path=/trunk/externals/unauthorized/; revision=15994
-rw-r--r--audience~.c1281
-rw-r--r--beatify~.c69
-rw-r--r--blinkenlights.c1122
-rw-r--r--compressor~.c20
-rw-r--r--cooled~.c1437
-rw-r--r--countund.c89
-rw-r--r--disto~.c342
-rw-r--r--exciter.c869
-rw-r--r--filterbank~.c606
-rw-r--r--filters.c42
-rw-r--r--formant~.c151
-rw-r--r--grid.c640
-rw-r--r--lpc.c392
-rw-r--r--mp3amp~.c1236
-rw-r--r--mp3cast~.c397
-rw-r--r--mp3fileout~.c491
-rw-r--r--mp3streamin~.c704
-rw-r--r--mp3streamout~.c291
-rw-r--r--mp3write~.c329
-rw-r--r--pianoroll.c959
-rw-r--r--playlist.c1294
-rw-r--r--probalizer.c585
-rw-r--r--randomblock~.c83
-rw-r--r--samplebox~.c520
-rw-r--r--scratcher~.c794
-rw-r--r--scrolllist.c1218
-rw-r--r--sonogram~.c2543
-rw-r--r--speexin~.c558
-rw-r--r--speexout~.c207
-rw-r--r--spigot~.c26
-rw-r--r--tables.c574
-rw-r--r--vocoder~.c88
-rw-r--r--wahwah~.c246
33 files changed, 10409 insertions, 9794 deletions
diff --git a/audience~.c b/audience~.c
index 2188204..7af1a5a 100644
--- a/audience~.c
+++ b/audience~.c
@@ -107,206 +107,206 @@ static int guidebug=0;
/* drawing functions */
static void audience_draw_update(t_audience_tilde *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int ei;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int ei;
for ( ei=0; ei<x->x_nbinputs; ei++ )
{
- SYS_VGUI6(".x%lx.c coords %xISPEAKER%d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei],
- text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei]
- );
- SYS_VGUI6(".x%lx.c coords %xSPEAKERNUM%d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei] - SPEAKER_WIDTH/2,
- text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei] - SPEAKER_HEIGHT/2
- );
+ SYS_VGUI6(".x%lx.c coords %xISPEAKER%d %d %d\n",
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei],
+ text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei]
+ );
+ SYS_VGUI6(".x%lx.c coords %xSPEAKERNUM%d %d %d\n",
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei] - SPEAKER_WIDTH/2,
+ text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei] - SPEAKER_HEIGHT/2
+ );
}
for ( ei=0; ei<x->x_nboutputs; ei++ )
{
- SYS_VGUI6(".x%lx.c coords %xILISTENER%d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei],
- text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei]
- );
- SYS_VGUI6(".x%lx.c coords %xLISTENERNUM%d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei] + LISTENER_WIDTH/2,
- text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei] + LISTENER_HEIGHT/2
- );
+ SYS_VGUI6(".x%lx.c coords %xILISTENER%d %d %d\n",
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei],
+ text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei]
+ );
+ SYS_VGUI6(".x%lx.c coords %xLISTENERNUM%d %d %d\n",
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei] + LISTENER_WIDTH/2,
+ text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei] + LISTENER_HEIGHT/2
+ );
}
}
static void audience_draw_new(t_audience_tilde *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- int ei;
+ t_canvas *canvas=glist_getcanvas(glist);
+ int ei;
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #EAF1E2 -tags %xAAUDIENCE\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
- x);
- // create captions
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
+ x);
+ // create captions
SYS_VGUI5(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"0m\" -tags %xBLCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist) - 10 , text_ypix(&x->x_obj, glist) + x->x_height + 10, x );
+ canvas, text_xpix(&x->x_obj, glist) - 10 , text_ypix(&x->x_obj, glist) + x->x_height + 10, x );
SYS_VGUI6(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"%dm\" -tags %xBRCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist) + x->x_width + 10 , text_ypix(&x->x_obj, glist) + x->x_height + 10, x->x_width, x );
+ canvas, text_xpix(&x->x_obj, glist) + x->x_width + 10 , text_ypix(&x->x_obj, glist) + x->x_height + 10, x->x_width, x );
SYS_VGUI6(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"%dm\" -tags %xULCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist) - 10 , text_ypix(&x->x_obj, glist), x->x_height, x );
+ canvas, text_xpix(&x->x_obj, glist) - 10 , text_ypix(&x->x_obj, glist), x->x_height, x );
// draw all outlets
if ( x->x_nboutputs > 1 )
{
- for ( ei=0; ei<x->x_nboutputs; ei++ )
- {
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n",
- canvas, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nboutputs-1),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nboutputs-1) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2,
- x, ei);
- }
+ for ( ei=0; ei<x->x_nboutputs; ei++ )
+ {
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n",
+ canvas, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nboutputs-1),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nboutputs-1) + 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2,
+ x, ei);
+ }
}
else
{
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n",
- canvas, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2,
- x, 0);
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n",
+ canvas, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2,
+ x, 0);
}
// draw all inlets
for ( ei=0; ei<x->x_nbinputs+1; ei++ )
{
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xIN%d\n",
- canvas, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbinputs),
- text_ypix(&x->x_obj, glist) - 2,
- text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbinputs) + 5,
- text_ypix(&x->x_obj, glist),
- x, ei);
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xIN%d\n",
+ canvas, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbinputs),
+ text_ypix(&x->x_obj, glist) - 2,
+ text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbinputs) + 5,
+ text_ypix(&x->x_obj, glist),
+ x, ei);
}
// create speaker images
for ( ei=0; ei<x->x_nbinputs; ei++ )
{
- SYS_VGUI6("image create photo %xSPEAKER%d -file %s/examples/speaker.gif -format gif -width %d -height %d\n",
- x, ei, audience_class_tilde->c_externdir->s_name, SPEAKER_WIDTH, SPEAKER_HEIGHT );
- SYS_VGUI8(".x%lx.c create image %d %d -image %xSPEAKER%d -tags %xISPEAKER%d\n",
- canvas,
- text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei],
- text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei],
- x, ei, x, ei );
- SYS_VGUI7(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"s%d\" -tags %xSPEAKERNUM%d\n",
- canvas, text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei] - SPEAKER_WIDTH/2,
- text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei] - SPEAKER_HEIGHT/2, ei+1, x, ei );
+ SYS_VGUI6("image create photo %xSPEAKER%d -file %s/examples/speaker.gif -format gif -width %d -height %d\n",
+ x, ei, audience_class_tilde->c_externdir->s_name, SPEAKER_WIDTH, SPEAKER_HEIGHT );
+ SYS_VGUI8(".x%lx.c create image %d %d -image %xSPEAKER%d -tags %xISPEAKER%d\n",
+ canvas,
+ text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei],
+ text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei],
+ x, ei, x, ei );
+ SYS_VGUI7(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"s%d\" -tags %xSPEAKERNUM%d\n",
+ canvas, text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei] - SPEAKER_WIDTH/2,
+ text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei] - SPEAKER_HEIGHT/2, ei+1, x, ei );
}
- // create listener images
+ // create listener images
for ( ei=0; ei<x->x_nboutputs; ei++ )
{
- SYS_VGUI6("image create photo %xLISTENER%d -file %s/examples/wanderer.gif -format gif -width %d -height %d\n",
- x, ei, audience_class_tilde->c_externdir->s_name, LISTENER_WIDTH, LISTENER_HEIGHT );
- SYS_VGUI8(".x%lx.c create image %d %d -image %xLISTENER%d -tags %xILISTENER%d\n",
- canvas,
- text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei],
- text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei],
- x, ei, x, ei );
- SYS_VGUI7(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"l%d\" -tags %xLISTENERNUM%d\n",
- canvas, text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei] + LISTENER_WIDTH/2,
- text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei] + LISTENER_HEIGHT/2, ei+1, x, ei );
+ SYS_VGUI6("image create photo %xLISTENER%d -file %s/examples/wanderer.gif -format gif -width %d -height %d\n",
+ x, ei, audience_class_tilde->c_externdir->s_name, LISTENER_WIDTH, LISTENER_HEIGHT );
+ SYS_VGUI8(".x%lx.c create image %d %d -image %xLISTENER%d -tags %xILISTENER%d\n",
+ canvas,
+ text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei],
+ text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei],
+ x, ei, x, ei );
+ SYS_VGUI7(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"l%d\" -tags %xLISTENERNUM%d\n",
+ canvas, text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei] + LISTENER_WIDTH/2,
+ text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei] + LISTENER_HEIGHT/2, ei+1, x, ei );
}
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void audience_draw_move(t_audience_tilde *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int ei;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int ei;
SYS_VGUI7(".x%lx.c coords %xAAUDIENCE %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height);
+ canvas, x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height);
SYS_VGUI5(".x%lx.c coords %xBLCAPTION %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist) - 10 , text_ypix(&x->x_obj, glist) + x->x_height + 10);
+ canvas, x,
+ text_xpix(&x->x_obj, glist) - 10 , text_ypix(&x->x_obj, glist) + x->x_height + 10);
SYS_VGUI5(".x%lx.c coords %xBRCAPTION %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist) + x->x_width + 10 , text_ypix(&x->x_obj, glist) + x->x_height + 10 );
+ canvas, x,
+ text_xpix(&x->x_obj, glist) + x->x_width + 10 , text_ypix(&x->x_obj, glist) + x->x_height + 10 );
SYS_VGUI5(".x%lx.c coords %xULCAPTION %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist) - 10 , text_ypix(&x->x_obj, glist) );
+ canvas, x,
+ text_xpix(&x->x_obj, glist) - 10 , text_ypix(&x->x_obj, glist) );
for ( ei=0; ei<x->x_nbinputs+1; ei++ )
{
- SYS_VGUI8(".x%lx.c coords %xIN%d %d %d %d %d\n",
- canvas, x, ei, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbinputs),
- text_ypix(&x->x_obj, glist) - 2,
- text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbinputs) + 5,
- text_ypix(&x->x_obj, glist)
- );
+ SYS_VGUI8(".x%lx.c coords %xIN%d %d %d %d %d\n",
+ canvas, x, ei, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbinputs),
+ text_ypix(&x->x_obj, glist) - 2,
+ text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbinputs) + 5,
+ text_ypix(&x->x_obj, glist)
+ );
}
for ( ei=0; ei<x->x_nbinputs+1; ei++ )
{
SYS_VGUI6(".x%lx.c coords %xISPEAKER%d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei],
- text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei]
- );
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei],
+ text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei]
+ );
SYS_VGUI6(".x%lx.c coords %xSPEAKERNUM%d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei] - SPEAKER_WIDTH/2,
- text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei] - SPEAKER_HEIGHT/2
- );
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + x->x_inputs_x[ei] - SPEAKER_WIDTH/2,
+ text_ypix(&x->x_obj, glist) + x->x_inputs_y[ei] - SPEAKER_HEIGHT/2
+ );
}
if ( x->x_nboutputs > 1 )
{
- for ( ei=0; ei<x->x_nboutputs; ei++ )
- {
- SYS_VGUI8(".x%lx.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, ei, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nboutputs-1),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nboutputs-1) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2
- );
- SYS_VGUI6(".x%lx.c coords %xILISTENER%d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei],
- text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei]
- );
- SYS_VGUI6(".x%lx.c coords %xLISTENERNUM%d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei] + LISTENER_WIDTH/2,
- text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei] + LISTENER_HEIGHT/2
- );
- }
+ for ( ei=0; ei<x->x_nboutputs; ei++ )
+ {
+ SYS_VGUI8(".x%lx.c coords %xOUT%d %d %d %d %d\n",
+ canvas, x, ei, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nboutputs-1),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nboutputs-1) + 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2
+ );
+ SYS_VGUI6(".x%lx.c coords %xILISTENER%d %d %d\n",
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei],
+ text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei]
+ );
+ SYS_VGUI6(".x%lx.c coords %xLISTENERNUM%d %d %d\n",
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + x->x_outputs_x[ei] + LISTENER_WIDTH/2,
+ text_ypix(&x->x_obj, glist) + x->x_outputs_y[ei] + LISTENER_HEIGHT/2
+ );
+ }
}
else
{
- SYS_VGUI8(".x%lx.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2
- );
- SYS_VGUI6(".x%lx.c coords %xILISTENER%d %d %d\n",
- canvas, x, 0,
- text_xpix(&x->x_obj, glist) + x->x_outputs_x[0],
- text_ypix(&x->x_obj, glist) + x->x_outputs_y[0]
- );
- SYS_VGUI6(".x%lx.c coords %xLISTENERNUM%d %d %d\n",
- canvas, x, 0,
- text_xpix(&x->x_obj, glist) + x->x_outputs_x[0] + LISTENER_WIDTH/2,
- text_ypix(&x->x_obj, glist) + x->x_outputs_y[0] + LISTENER_HEIGHT/2
- );
+ SYS_VGUI8(".x%lx.c coords %xOUT%d %d %d %d %d\n",
+ canvas, x, 0, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2
+ );
+ SYS_VGUI6(".x%lx.c coords %xILISTENER%d %d %d\n",
+ canvas, x, 0,
+ text_xpix(&x->x_obj, glist) + x->x_outputs_x[0],
+ text_ypix(&x->x_obj, glist) + x->x_outputs_y[0]
+ );
+ SYS_VGUI6(".x%lx.c coords %xLISTENERNUM%d %d %d\n",
+ canvas, x, 0,
+ text_xpix(&x->x_obj, glist) + x->x_outputs_x[0] + LISTENER_WIDTH/2,
+ text_ypix(&x->x_obj, glist) + x->x_outputs_y[0] + LISTENER_HEIGHT/2
+ );
}
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void audience_draw_erase(t_audience_tilde* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- int ei;
+ t_canvas *canvas=glist_getcanvas(glist);
+ int ei;
SYS_VGUI3(".x%lx.c delete %xAAUDIENCE\n", canvas, x);
SYS_VGUI3(".x%lx.c delete %xBLCAPTION\n", canvas, x);
@@ -314,7 +314,7 @@ static void audience_draw_erase(t_audience_tilde* x,t_glist* glist)
SYS_VGUI3(".x%lx.c delete %xULCAPTION\n", canvas, x);
for ( ei=0; ei<x->x_nbinputs+1; ei++ )
{
- SYS_VGUI4(".x%lx.c delete %xIN%d\n", canvas, x, ei );
+ SYS_VGUI4(".x%lx.c delete %xIN%d\n", canvas, x, ei );
}
for ( ei=0; ei<x->x_nbinputs; ei++ )
{
@@ -324,10 +324,10 @@ static void audience_draw_erase(t_audience_tilde* x,t_glist* glist)
}
for ( ei=0; ei<x->x_nboutputs; ei++ )
{
- SYS_VGUI4(".x%lx.c delete %xOUT%d\n", canvas, x, ei );
- SYS_VGUI4(".x%lx.c delete %xILISTENER%d\n", canvas, x, ei );
- SYS_VGUI4(".x%lx.c delete %xLISTENERNUM%d\n", canvas, x, ei );
- // SYS_VGUI3("image delete %xLISTENER%d\n", x, ei );
+ SYS_VGUI4(".x%lx.c delete %xOUT%d\n", canvas, x, ei );
+ SYS_VGUI4(".x%lx.c delete %xILISTENER%d\n", canvas, x, ei );
+ SYS_VGUI4(".x%lx.c delete %xLISTENERNUM%d\n", canvas, x, ei );
+ // SYS_VGUI3("image delete %xLISTENER%d\n", x, ei );
}
}
@@ -338,11 +338,11 @@ static void audience_draw_select(t_audience_tilde* x,t_glist* glist)
if(x->x_selected)
{
/* sets the item in blue */
- SYS_VGUI3(".x%lx.c itemconfigure %xAAUDIENCE -outline #0000FF\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xAAUDIENCE -outline #0000FF\n", canvas, x);
}
else
{
- SYS_VGUI3(".x%lx.c itemconfigure %xAAUDIENCE -outline #000000\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xAAUDIENCE -outline #000000\n", canvas, x);
}
}
@@ -350,235 +350,237 @@ static void audience_draw_select(t_audience_tilde* x,t_glist* glist)
static void audience_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_audience_tilde* x = (t_audience_tilde*)z;
+ t_audience_tilde* x = (t_audience_tilde*)z;
- *xp1 = text_xpix(&x->x_obj, owner);
- *yp1 = text_ypix(&x->x_obj, owner);
- *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, owner);
+ *yp1 = text_ypix(&x->x_obj, owner);
+ *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
}
static void audience_save(t_gobj *z, t_binbuf *b)
{
- t_audience_tilde *x = (t_audience_tilde *)z;
- t_int ii;
-
- binbuf_addv(b, "ssiisiiiifi", gensym("#X"),gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_width, x->x_height,
- x->x_nbinputs, x->x_nboutputs, x->x_attenuation, x->x_applydelay );
- for ( ii=0; ii<x->x_nbinputs; ii++ )
- {
- binbuf_addv(b, "ii", x->x_inputs_x[ii], x->x_inputs_y[ii] );
- }
- for ( ii=0; ii<x->x_nboutputs; ii++ )
- {
- binbuf_addv(b, "ii", x->x_outputs_x[ii], x->x_outputs_y[ii] );
- }
- binbuf_addv(b, ";");
+ t_audience_tilde *x = (t_audience_tilde *)z;
+ t_int ii;
+
+ binbuf_addv(b, "ssiisiiiifi", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_width, x->x_height,
+ x->x_nbinputs, x->x_nboutputs, x->x_attenuation, x->x_applydelay );
+ for ( ii=0; ii<x->x_nbinputs; ii++ )
+ {
+ binbuf_addv(b, "ii", x->x_inputs_x[ii], x->x_inputs_y[ii] );
+ }
+ for ( ii=0; ii<x->x_nboutputs; ii++ )
+ {
+ binbuf_addv(b, "ii", x->x_outputs_x[ii], x->x_outputs_y[ii] );
+ }
+ binbuf_addv(b, ";");
}
static void audience_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_audience_tilde *x=(t_audience_tilde *)z;
-
- sprintf(buf, "pdtk_audience_dialog %%s %d %d %d\n",
- x->x_width, x->x_height, x->x_nboutputs
- );
- // post("audience_properties : %s", buf );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ char buf[800];
+ t_audience_tilde *x=(t_audience_tilde *)z;
+
+ sprintf(buf, "pdtk_audience_dialog %%s %d %d %d\n",
+ x->x_width, x->x_height, x->x_nboutputs
+ );
+ // post("audience_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
static void audience_select(t_gobj *z, t_glist *glist, int selected)
{
- t_audience_tilde *x = (t_audience_tilde *)z;
+ t_audience_tilde *x = (t_audience_tilde *)z;
- x->x_selected = selected;
- audience_draw_select( x, glist );
+ x->x_selected = selected;
+ audience_draw_select( x, glist );
}
static void audience_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_audience_tilde *x = (t_audience_tilde *)z;
-
- // post( "audience~ : vis : %d", vis );
- if (vis)
- {
- audience_draw_new( x, glist );
- }
- else
- {
- audience_draw_erase( x, glist );
- }
+ t_audience_tilde *x = (t_audience_tilde *)z;
+
+ // post( "audience~ : vis : %d", vis );
+ if (vis)
+ {
+ audience_draw_new( x, glist );
+ }
+ else
+ {
+ audience_draw_erase( x, glist );
+ }
}
static void audience_dialog(t_audience_tilde *x, t_symbol *s, int argc, t_atom *argv)
{
- t_int onbinputs = x->x_nbinputs;
- t_int onboutputs = x->x_nboutputs;
- t_int owidth = x->x_width;
- t_int oheight = x->x_height;
- t_int bi, ei;
- t_int dspstate;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- if ( !x ) {
- post( "audience~ : error :tried to set properties on an unexisting object" );
- }
- if ( argc != 3 )
- {
- post( "audience : error in the number of arguments ( %d instead of 3 )", argc );
- return;
- }
- if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT ||
- argv[2].a_type != A_FLOAT ) {
- post( "audience~ : wrong arguments" );
- return;
- }
-
- dspstate = canvas_suspend_dsp();
- audience_draw_erase(x, x->x_glist);
-
- x->x_width = (int)argv[0].a_w.w_float;
- if ( x->x_width < 10 ) x->x_width = 10;
- x->x_height = (int)argv[1].a_w.w_float;
- if ( x->x_height < 10 ) x->x_height = 10;
- x->x_nboutputs = (int)argv[2].a_w.w_float;
- if ( x->x_nboutputs < 1 ) x->x_nboutputs = 1;
-
- // re-allocate audio buffers if needed
- if ( ( owidth != x->x_width ) || ( oheight != x->x_height ) )
- {
- if ( x->x_audiobuffer )
- {
- for ( ei=0; ei<onbinputs; ei++ )
+ t_int onbinputs = x->x_nbinputs;
+ t_int onboutputs = x->x_nboutputs;
+ t_int owidth = x->x_width;
+ t_int oheight = x->x_height;
+ t_int bi, ei;
+ t_int dspstate;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ if ( !x )
+ {
+ post( "audience~ : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 3 )
+ {
+ post( "audience : error in the number of arguments ( %d instead of 3 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT ||
+ argv[2].a_type != A_FLOAT )
+ {
+ post( "audience~ : wrong arguments" );
+ return;
+ }
+
+ dspstate = canvas_suspend_dsp();
+ audience_draw_erase(x, x->x_glist);
+
+ x->x_width = (int)argv[0].a_w.w_float;
+ if ( x->x_width < 10 ) x->x_width = 10;
+ x->x_height = (int)argv[1].a_w.w_float;
+ if ( x->x_height < 10 ) x->x_height = 10;
+ x->x_nboutputs = (int)argv[2].a_w.w_float;
+ if ( x->x_nboutputs < 1 ) x->x_nboutputs = 1;
+
+ // re-allocate audio buffers if needed
+ if ( ( owidth != x->x_width ) || ( oheight != x->x_height ) )
+ {
+ if ( x->x_audiobuffer )
{
- freebytes( x->x_audiobuffer[ei], x->x_audiobuffersize*sizeof(t_float) );
+ for ( ei=0; ei<onbinputs; ei++ )
+ {
+ freebytes( x->x_audiobuffer[ei], x->x_audiobuffersize*sizeof(t_float) );
+ }
+ freebytes( x->x_audiobuffer, onbinputs*sizeof(t_float*) );
}
- freebytes( x->x_audiobuffer, onbinputs*sizeof(t_float*) );
- }
- // allocate audio buffer
- x->x_audiobuffer = (t_float **) getbytes( x->x_nbinputs*sizeof(t_float *) );
- if ( !x->x_audiobuffer )
- {
- post( "audience~ : could not allocate audio buffer" );
- return;
- }
- x->x_audiobuffersize = ( t_int ) ( ( ( ( t_float ) sqrt( pow( x->x_width, 2 )
- + pow( x->x_height, 2 ) ) ) / SOUNDSPEED )
- * ( (float ) sys_getsr() ) );
- post( "audience~ : audio buffer size : %d samples", x->x_audiobuffersize );
- for ( bi=0; bi<x->x_nbinputs; bi++ )
- {
- x->x_audiobuffer[bi] = (t_float *) getbytes( x->x_audiobuffersize*sizeof(t_float) );
- if ( !x->x_audiobuffer[bi] )
+ // allocate audio buffer
+ x->x_audiobuffer = (t_float **) getbytes( x->x_nbinputs*sizeof(t_float *) );
+ if ( !x->x_audiobuffer )
{
- post( "audience~ : could not allocate audio buffer" );
- return;
+ post( "audience~ : could not allocate audio buffer" );
+ return;
}
- }
- x->x_audiowritepos = 0;
- }
-
- // re-allocate inlets : CRASHES PD,I GUESS IT'S NOT SUPPORTED
- if ( onbinputs != x->x_nbinputs )
- {
- // post( "audience~ : cleaning up old inlets" );
- if ( x->x_inputs )
- {
- for ( ei=0; ei<onbinputs; ei++ )
+ x->x_audiobuffersize = ( t_int ) ( ( ( ( t_float ) sqrt( pow( x->x_width, 2 )
+ + pow( x->x_height, 2 ) ) ) / SOUNDSPEED )
+ * ( (float ) sys_getsr() ) );
+ post( "audience~ : audio buffer size : %d samples", x->x_audiobuffersize );
+ for ( bi=0; bi<x->x_nbinputs; bi++ )
{
- // post( "audience~ : freeing input ! %d", ei );
- inlet_free( x->x_inputs[ei] );
+ x->x_audiobuffer[bi] = (t_float *) getbytes( x->x_audiobuffersize*sizeof(t_float) );
+ if ( !x->x_audiobuffer[bi] )
+ {
+ post( "audience~ : could not allocate audio buffer" );
+ return;
+ }
+ }
+ x->x_audiowritepos = 0;
+ }
+
+ // re-allocate inlets : CRASHES PD,I GUESS IT'S NOT SUPPORTED
+ if ( onbinputs != x->x_nbinputs )
+ {
+ // post( "audience~ : cleaning up old inlets" );
+ if ( x->x_inputs )
+ {
+ for ( ei=0; ei<onbinputs; ei++ )
+ {
+ // post( "audience~ : freeing input ! %d", ei );
+ inlet_free( x->x_inputs[ei] );
+ }
+ freebytes( x->x_inputs, onbinputs*sizeof(t_inlet*) );
}
- freebytes( x->x_inputs, onbinputs*sizeof(t_inlet*) );
- }
- if ( x->x_inputs_x )
- {
- freebytes( x->x_inputs_x, onbinputs*sizeof(t_int) );
- }
- if ( x->x_inputs_y )
- {
- freebytes( x->x_inputs_y, onbinputs*sizeof(t_int) );
- }
- // post( "audience~ : creating new ones" );
- x->x_inputs = (t_inlet **) getbytes( x->x_nbinputs*sizeof(t_inlet *) );
- x->x_inputs_x = (t_int *) getbytes( x->x_nbinputs*sizeof(t_int) );
- x->x_inputs_y = (t_int *) getbytes( x->x_nbinputs*sizeof(t_int) );
- if ( !x->x_inputs || !x->x_inputs_x || !x->x_inputs_y )
- {
- error( "audience~ : fatal : could not create new object" );
- return;
- }
- for ( bi=0; bi<x->x_nbinputs; bi++ )
- {
- // post( "audience~ : allocating input ! %d", bi );
- x->x_inputs[bi] = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
- }
- }
-
- // re-allocate outlets
- if ( onboutputs != x->x_nboutputs )
- {
- // post( "audience~ : cleaning up old outlets" );
- if ( x->x_outputs )
- {
- for ( ei=0; ei<onboutputs; ei++ )
+ if ( x->x_inputs_x )
{
- canvas_rmoutlet(canvas, x->x_outputs[ei] );
- // outlet_free( x->x_outputs[ei] );
+ freebytes( x->x_inputs_x, onbinputs*sizeof(t_int) );
}
- freebytes( x->x_outputs, onboutputs*sizeof(t_outlet*) );
- }
- if ( x->x_outputs_x )
- {
- freebytes( x->x_outputs_x, onboutputs*sizeof(t_int) );
- }
- if ( x->x_outputs_y )
- {
- freebytes( x->x_outputs_y, onboutputs*sizeof(t_int) );
- }
- // post( "audience~ : creating new ones" );
- x->x_outputs = (t_outlet **) getbytes( x->x_nboutputs*sizeof(t_outlet *) );
- x->x_outputs_x = (t_int *) getbytes( x->x_nboutputs*sizeof(t_int) );
- x->x_outputs_y = (t_int *) getbytes( x->x_nboutputs*sizeof(t_int) );
- if ( !x->x_outputs || !x->x_outputs_x || !x->x_outputs_y )
- {
- // error( "audience~ : fatal : could not create new object" );
- return;
- }
- for ( bi=0; bi<x->x_nboutputs; bi++ )
- {
- x->x_outputs[bi] = outlet_new( &x->x_obj, &s_signal );
- }
- // set default coordinates
- if ( x->x_nboutputs > 1 )
- {
- for ( ei=0; ei<x->x_nboutputs; ei++ )
+ if ( x->x_inputs_y )
{
- x->x_outputs_x[ei] = ei * (x->x_width - 5) / ( x->x_nboutputs - 1 );
- x->x_outputs_y[ei] = x->x_height - LISTENER_HEIGHT/2;
+ freebytes( x->x_inputs_y, onbinputs*sizeof(t_int) );
}
- }
- else
- {
- x->x_outputs_x[0] = x->x_width;
- x->x_outputs_y[0] = x->x_height - LISTENER_HEIGHT/2;
- }
- }
-
- canvas_fixlinesfor( canvas, (t_text*)x );
- audience_draw_new(x, x->x_glist);
- canvas_resume_dsp(dspstate);
+ // post( "audience~ : creating new ones" );
+ x->x_inputs = (t_inlet **) getbytes( x->x_nbinputs*sizeof(t_inlet *) );
+ x->x_inputs_x = (t_int *) getbytes( x->x_nbinputs*sizeof(t_int) );
+ x->x_inputs_y = (t_int *) getbytes( x->x_nbinputs*sizeof(t_int) );
+ if ( !x->x_inputs || !x->x_inputs_x || !x->x_inputs_y )
+ {
+ error( "audience~ : fatal : could not create new object" );
+ return;
+ }
+ for ( bi=0; bi<x->x_nbinputs; bi++ )
+ {
+ // post( "audience~ : allocating input ! %d", bi );
+ x->x_inputs[bi] = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ }
+ }
+
+ // re-allocate outlets
+ if ( onboutputs != x->x_nboutputs )
+ {
+ // post( "audience~ : cleaning up old outlets" );
+ if ( x->x_outputs )
+ {
+ for ( ei=0; ei<onboutputs; ei++ )
+ {
+ canvas_rmoutlet(canvas, x->x_outputs[ei] );
+ // outlet_free( x->x_outputs[ei] );
+ }
+ freebytes( x->x_outputs, onboutputs*sizeof(t_outlet*) );
+ }
+ if ( x->x_outputs_x )
+ {
+ freebytes( x->x_outputs_x, onboutputs*sizeof(t_int) );
+ }
+ if ( x->x_outputs_y )
+ {
+ freebytes( x->x_outputs_y, onboutputs*sizeof(t_int) );
+ }
+ // post( "audience~ : creating new ones" );
+ x->x_outputs = (t_outlet **) getbytes( x->x_nboutputs*sizeof(t_outlet *) );
+ x->x_outputs_x = (t_int *) getbytes( x->x_nboutputs*sizeof(t_int) );
+ x->x_outputs_y = (t_int *) getbytes( x->x_nboutputs*sizeof(t_int) );
+ if ( !x->x_outputs || !x->x_outputs_x || !x->x_outputs_y )
+ {
+ // error( "audience~ : fatal : could not create new object" );
+ return;
+ }
+ for ( bi=0; bi<x->x_nboutputs; bi++ )
+ {
+ x->x_outputs[bi] = outlet_new( &x->x_obj, &s_signal );
+ }
+ // set default coordinates
+ if ( x->x_nboutputs > 1 )
+ {
+ for ( ei=0; ei<x->x_nboutputs; ei++ )
+ {
+ x->x_outputs_x[ei] = ei * (x->x_width - 5) / ( x->x_nboutputs - 1 );
+ x->x_outputs_y[ei] = x->x_height - LISTENER_HEIGHT/2;
+ }
+ }
+ else
+ {
+ x->x_outputs_x[0] = x->x_width;
+ x->x_outputs_y[0] = x->x_height - LISTENER_HEIGHT/2;
+ }
+ }
+
+ canvas_fixlinesfor( canvas, (t_text*)x );
+ audience_draw_new(x, x->x_glist);
+ canvas_resume_dsp(dspstate);
}
static void audience_delete(t_gobj *z, t_glist *glist)
{
- t_audience_tilde *x = (t_audience_tilde *)z;
+ t_audience_tilde *x = (t_audience_tilde *)z;
// post( "audience~ : delete" );
audience_draw_erase( x, glist );
@@ -587,9 +589,9 @@ static void audience_delete(t_gobj *z, t_glist *glist)
static void audience_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
- t_audience_tilde *x = (t_audience_tilde *)z;
- int xold = text_xpix(&x->x_obj, glist);
- int yold = text_ypix(&x->x_obj, glist);
+ t_audience_tilde *x = (t_audience_tilde *)z;
+ int xold = text_xpix(&x->x_obj, glist);
+ int yold = text_ypix(&x->x_obj, glist);
// post( "audience_displace dx=%d dy=%d", dx, dy );
@@ -597,76 +599,78 @@ static void audience_displace(t_gobj *z, t_glist *glist, int dx, int dy)
x->x_obj.te_ypix += dy;
if(xold != x->x_obj.te_xpix || yold != x->x_obj.te_ypix)
{
- audience_draw_move(x, x->x_glist);
+ audience_draw_move(x, x->x_glist);
}
}
static void audience_motion(t_audience_tilde *x, t_floatarg dx, t_floatarg dy)
{
// post( "audience_motion dx=%f dy=%f", dx, dy );
-
+
switch( x->x_type_selected )
{
- case AUDIENCE_INPUT:
- x->x_inputs_x[ x->x_nselected ] += dx;
- if ( x->x_inputs_x[ x->x_nselected ] < 0 ) x->x_inputs_x[ x->x_nselected ] = 0;
- if ( x->x_inputs_x[ x->x_nselected ] > x->x_width ) x->x_inputs_x[ x->x_nselected ] = x->x_width;
- x->x_inputs_y[ x->x_nselected ] += dy;
- if ( x->x_inputs_y[ x->x_nselected ] < 0 ) x->x_inputs_y[ x->x_nselected ] = 0;
- if ( x->x_inputs_y[ x->x_nselected ] > x->x_height ) x->x_inputs_y[ x->x_nselected ] = x->x_height;
- break;
- case AUDIENCE_OUTPUT:
- x->x_outputs_x[ x->x_nselected ] += dx;
- if ( x->x_outputs_x[ x->x_nselected ] < 0 ) x->x_outputs_x[ x->x_nselected ] = 0;
- if ( x->x_outputs_x[ x->x_nselected ] > x->x_width ) x->x_outputs_x[ x->x_nselected ] = x->x_width;
- x->x_outputs_y[ x->x_nselected ] += dy;
- if ( x->x_outputs_y[ x->x_nselected ] < 0 ) x->x_outputs_y[ x->x_nselected ] = 0;
- if ( x->x_outputs_y[ x->x_nselected ] > x->x_height ) x->x_outputs_y[ x->x_nselected ] = x->x_height;
- break;
+ case AUDIENCE_INPUT:
+ x->x_inputs_x[ x->x_nselected ] += dx;
+ if ( x->x_inputs_x[ x->x_nselected ] < 0 ) x->x_inputs_x[ x->x_nselected ] = 0;
+ if ( x->x_inputs_x[ x->x_nselected ] > x->x_width ) x->x_inputs_x[ x->x_nselected ] = x->x_width;
+ x->x_inputs_y[ x->x_nselected ] += dy;
+ if ( x->x_inputs_y[ x->x_nselected ] < 0 ) x->x_inputs_y[ x->x_nselected ] = 0;
+ if ( x->x_inputs_y[ x->x_nselected ] > x->x_height ) x->x_inputs_y[ x->x_nselected ] = x->x_height;
+ break;
+ case AUDIENCE_OUTPUT:
+ x->x_outputs_x[ x->x_nselected ] += dx;
+ if ( x->x_outputs_x[ x->x_nselected ] < 0 ) x->x_outputs_x[ x->x_nselected ] = 0;
+ if ( x->x_outputs_x[ x->x_nselected ] > x->x_width ) x->x_outputs_x[ x->x_nselected ] = x->x_width;
+ x->x_outputs_y[ x->x_nselected ] += dy;
+ if ( x->x_outputs_y[ x->x_nselected ] < 0 ) x->x_outputs_y[ x->x_nselected ] = 0;
+ if ( x->x_outputs_y[ x->x_nselected ] > x->x_height ) x->x_outputs_y[ x->x_nselected ] = x->x_height;
+ break;
}
audience_draw_update(x, x->x_glist);
}
static int audience_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
t_audience_tilde* x = (t_audience_tilde *)z;
t_int bi;
// post( "audience_click doit=%d x=%d y=%d", doit, xpix, ypix );
- if ( doit)
+ if ( doit)
{
- t_int relx = xpix-text_xpix(&x->x_obj, glist);
- t_int rely = ypix-text_ypix(&x->x_obj, glist);
-
- // post( "audience~ : relx : %d : rely : %d", relx, rely );
- x->x_type_selected = AUDIENCE_NONE;
- x->x_nselected = -1;
- for ( bi=0; bi<x->x_nbinputs; bi++ )
- {
- if ( ( abs( relx - x->x_inputs_x[bi] ) < SPEAKER_WIDTH ) &&
- ( abs( rely - x->x_inputs_y[bi] ) < SPEAKER_HEIGHT ) ) {
- x->x_type_selected = AUDIENCE_INPUT;
- x->x_nselected = bi;
- break;
- }
- }
- if ( x->x_type_selected == AUDIENCE_NONE )
- {
- for ( bi=0; bi<x->x_nboutputs; bi++ )
+ t_int relx = xpix-text_xpix(&x->x_obj, glist);
+ t_int rely = ypix-text_ypix(&x->x_obj, glist);
+
+ // post( "audience~ : relx : %d : rely : %d", relx, rely );
+ x->x_type_selected = AUDIENCE_NONE;
+ x->x_nselected = -1;
+ for ( bi=0; bi<x->x_nbinputs; bi++ )
+ {
+ if ( ( abs( relx - x->x_inputs_x[bi] ) < SPEAKER_WIDTH ) &&
+ ( abs( rely - x->x_inputs_y[bi] ) < SPEAKER_HEIGHT ) )
+ {
+ x->x_type_selected = AUDIENCE_INPUT;
+ x->x_nselected = bi;
+ break;
+ }
+ }
+ if ( x->x_type_selected == AUDIENCE_NONE )
{
- if ( ( abs( relx - x->x_outputs_x[bi] ) < LISTENER_WIDTH ) &&
- ( abs( rely - x->x_outputs_y[bi] ) < LISTENER_HEIGHT ) ) {
- x->x_type_selected = AUDIENCE_OUTPUT;
- x->x_nselected = bi;
- break;
- }
+ for ( bi=0; bi<x->x_nboutputs; bi++ )
+ {
+ if ( ( abs( relx - x->x_outputs_x[bi] ) < LISTENER_WIDTH ) &&
+ ( abs( rely - x->x_outputs_y[bi] ) < LISTENER_HEIGHT ) )
+ {
+ x->x_type_selected = AUDIENCE_OUTPUT;
+ x->x_nselected = bi;
+ break;
+ }
+ }
}
- }
- audience_draw_update(x, glist);
- glist_grab(glist, &x->x_obj.te_g, (t_glistmotionfn)audience_motion,
- 0, xpix, ypix);
+ audience_draw_update(x, glist);
+ glist_grab(glist, &x->x_obj.te_g, (t_glistmotionfn)audience_motion,
+ 0, xpix, ypix);
}
return (1);
}
@@ -677,45 +681,46 @@ static t_audience_tilde *audience_new(t_symbol *s, int argc, t_atom *argv)
t_audience_tilde *x;
t_pd *x2;
char *str;
-
+
// post( "audience_new : create : %s argc =%d", s->s_name, argc );
x = (t_audience_tilde *)pd_new(audience_class_tilde);
- // new audience created from the gui
+ // new audience created from the gui
if ( argc != 0 )
{
- if ( argc < 5 )
- {
- post( "audience~ : 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( "audience~ : wrong arguments" );
- return NULL;
- }
-
- x->x_width = (int)argv[0].a_w.w_float;
- if ( x->x_width < 10 ) x->x_width = 10;
- x->x_height = (int)argv[1].a_w.w_float;
- if ( x->x_height < 10 ) x->x_height = 10;
- x->x_nbinputs = (int)argv[2].a_w.w_float;
- if ( x->x_nbinputs < 1 ) x->x_nbinputs = 1;
- x->x_nboutputs = (int)argv[3].a_w.w_float;
- if ( x->x_nboutputs < 1 ) x->x_nboutputs = 1;
- x->x_attenuation = argv[4].a_w.w_float;
- if ( x->x_attenuation < 0 ) x->x_attenuation = 0;
- x->x_applydelay = argv[5].a_w.w_float;
+ if ( argc < 5 )
+ {
+ post( "audience~ : 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( "audience~ : wrong arguments" );
+ return NULL;
+ }
+
+ x->x_width = (int)argv[0].a_w.w_float;
+ if ( x->x_width < 10 ) x->x_width = 10;
+ x->x_height = (int)argv[1].a_w.w_float;
+ if ( x->x_height < 10 ) x->x_height = 10;
+ x->x_nbinputs = (int)argv[2].a_w.w_float;
+ if ( x->x_nbinputs < 1 ) x->x_nbinputs = 1;
+ x->x_nboutputs = (int)argv[3].a_w.w_float;
+ if ( x->x_nboutputs < 1 ) x->x_nboutputs = 1;
+ x->x_attenuation = argv[4].a_w.w_float;
+ if ( x->x_attenuation < 0 ) x->x_attenuation = 0;
+ x->x_applydelay = argv[5].a_w.w_float;
}
else
{
- x->x_width = DEFAULT_AUDIENCE_WIDTH;
- x->x_height = DEFAULT_AUDIENCE_HEIGHT;
- x->x_nbinputs = DEFAULT_AUDIENCE_NBINPUTS;
- x->x_nboutputs = DEFAULT_AUDIENCE_NBOUTPUTS;
- x->x_attenuation = DEFAULT_AUDIENCE_ATTENUATION;
- x->x_applydelay = 0;
+ x->x_width = DEFAULT_AUDIENCE_WIDTH;
+ x->x_height = DEFAULT_AUDIENCE_HEIGHT;
+ x->x_nbinputs = DEFAULT_AUDIENCE_NBINPUTS;
+ x->x_nboutputs = DEFAULT_AUDIENCE_NBOUTPUTS;
+ x->x_attenuation = DEFAULT_AUDIENCE_ATTENUATION;
+ x->x_applydelay = 0;
}
// create inlets and outlets
@@ -724,24 +729,24 @@ static t_audience_tilde *audience_new(t_symbol *s, int argc, t_atom *argv)
x->x_outputs_y = (t_int *) getbytes( x->x_nboutputs*sizeof(t_int) );
if ( !x->x_outputs || !x->x_outputs_x || !x->x_outputs_y )
{
- post( "audience~ : could not allocate outputs" );
- return NULL;
+ post( "audience~ : could not allocate outputs" );
+ return NULL;
}
for ( bi=0; bi<x->x_nboutputs; bi++ )
{
- x->x_outputs[bi] = outlet_new( &x->x_obj, &s_signal );
+ x->x_outputs[bi] = outlet_new( &x->x_obj, &s_signal );
}
x->x_inputs = (t_inlet **) getbytes( x->x_nbinputs*sizeof(t_inlet *) );
x->x_inputs_x = (t_int *) getbytes( x->x_nbinputs*sizeof(t_int) );
x->x_inputs_y = (t_int *) getbytes( x->x_nbinputs*sizeof(t_int) );
if ( !x->x_inputs || !x->x_inputs_x || !x->x_inputs_y )
{
- post( "audience~ : could not allocate inputs" );
- return NULL;
+ post( "audience~ : could not allocate inputs" );
+ return NULL;
}
for ( bi=0; bi<x->x_nbinputs; bi++ )
{
- x->x_inputs[bi] = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ x->x_inputs[bi] = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
}
// allocate audio buffer
@@ -749,69 +754,69 @@ static t_audience_tilde *audience_new(t_symbol *s, int argc, t_atom *argv)
x->x_audiobuffer = (t_float **) getbytes( x->x_nbinputs*sizeof(t_float *) );
if ( !x->x_audiobuffer )
{
- post( "audience~ : could not allocate audio buffer" );
- return NULL;
+ post( "audience~ : could not allocate audio buffer" );
+ return NULL;
}
- x->x_audiobuffersize = ( t_int ) ( ( ( ( t_float ) sqrt( pow( x->x_width, 2 )
- + pow( x->x_height, 2 ) ) ) / SOUNDSPEED )
- * ( (float ) sys_getsr() ) );
+ x->x_audiobuffersize = ( t_int ) ( ( ( ( t_float ) sqrt( pow( x->x_width, 2 )
+ + pow( x->x_height, 2 ) ) ) / SOUNDSPEED )
+ * ( (float ) sys_getsr() ) );
post( "audience~ : audio buffer size : %d samples", x->x_audiobuffersize );
for ( bi=0; bi<x->x_nbinputs; bi++ )
{
x->x_audiobuffer[bi] = (t_float *) getbytes( x->x_audiobuffersize*sizeof(t_float) );
if ( !x->x_audiobuffer[bi] )
{
- post( "audience~ : could not allocate audio buffer" );
- return NULL;
+ post( "audience~ : could not allocate audio buffer" );
+ return NULL;
}
}
if ( argc == 0 )
{
- // set default coordinates
- if ( x->x_nbinputs > 1 )
- {
- for ( ei=0; ei<x->x_nbinputs; ei++ )
+ // set default coordinates
+ if ( x->x_nbinputs > 1 )
{
- x->x_inputs_x[ei] = (ei+1) * (x->x_width - 5) / x->x_nbinputs;
- x->x_inputs_y[ei] = SPEAKER_HEIGHT/2;
+ for ( ei=0; ei<x->x_nbinputs; ei++ )
+ {
+ x->x_inputs_x[ei] = (ei+1) * (x->x_width - 5) / x->x_nbinputs;
+ x->x_inputs_y[ei] = SPEAKER_HEIGHT/2;
+ }
}
- }
- else
- {
- x->x_inputs_x[0] = x->x_width;
- x->x_inputs_y[0] = SPEAKER_HEIGHT/2;
- }
-
- if ( x->x_nboutputs > 1 )
- {
- for ( ei=0; ei<x->x_nboutputs; ei++ )
+ else
{
- x->x_outputs_x[ei] = ei * (x->x_width - 5) / ( x->x_nboutputs - 1 );
- x->x_outputs_y[ei] = x->x_height - LISTENER_HEIGHT/2;
+ x->x_inputs_x[0] = x->x_width;
+ x->x_inputs_y[0] = SPEAKER_HEIGHT/2;
+ }
+
+ if ( x->x_nboutputs > 1 )
+ {
+ for ( ei=0; ei<x->x_nboutputs; ei++ )
+ {
+ x->x_outputs_x[ei] = ei * (x->x_width - 5) / ( x->x_nboutputs - 1 );
+ x->x_outputs_y[ei] = x->x_height - LISTENER_HEIGHT/2;
+ }
+ }
+ else
+ {
+ x->x_outputs_x[0] = x->x_width;
+ x->x_outputs_y[0] = x->x_height - LISTENER_HEIGHT/2;
}
- }
- else
- {
- x->x_outputs_x[0] = x->x_width;
- x->x_outputs_y[0] = x->x_height - LISTENER_HEIGHT/2;
- }
}
else
{
- t_int ai = 6;
-
- // restore coordinates from arguments
- for ( ei=0; ei<x->x_nbinputs; ei++ )
- {
- x->x_inputs_x[ei] = argv[ai++].a_w.w_float;
- x->x_inputs_y[ei] = argv[ai++].a_w.w_float;
- }
- for ( ei=0; ei<x->x_nboutputs; ei++ )
- {
- x->x_outputs_x[ei] = argv[ai++].a_w.w_float;
- x->x_outputs_y[ei] = argv[ai++].a_w.w_float;
- }
+ t_int ai = 6;
+
+ // restore coordinates from arguments
+ for ( ei=0; ei<x->x_nbinputs; ei++ )
+ {
+ x->x_inputs_x[ei] = argv[ai++].a_w.w_float;
+ x->x_inputs_y[ei] = argv[ai++].a_w.w_float;
+ }
+ for ( ei=0; ei<x->x_nboutputs; ei++ )
+ {
+ x->x_outputs_x[ei] = argv[ai++].a_w.w_float;
+ x->x_outputs_y[ei] = argv[ai++].a_w.w_float;
+ }
}
x->x_glist = (t_glist *) canvas_getcurrent();
@@ -824,32 +829,32 @@ static t_audience_tilde *audience_new(t_symbol *s, int argc, t_atom *argv)
static void audience_free(t_audience_tilde *x)
{
- t_int ei;
-
- if ( x->x_outputs )
- {
- for ( ei=0; ei<x->x_nboutputs; ei++ )
- {
- outlet_free( x->x_outputs[ei] );
- }
- freebytes( x->x_outputs, x->x_nboutputs*sizeof(t_outlet*) );
- }
- if ( x->x_inputs )
- {
- for ( ei=0; ei<x->x_nbinputs; ei++ )
- {
- inlet_free( x->x_inputs[ei] );
- }
- freebytes( x->x_inputs, x->x_nbinputs*sizeof(t_outlet*) );
- }
- if ( x->x_audiobuffer )
- {
- for ( ei=0; ei<x->x_nbinputs; ei++ )
- {
- freebytes( x->x_audiobuffer[ei], x->x_audiobuffersize*sizeof(t_float) );
- }
- freebytes( x->x_audiobuffer, x->x_nbinputs*sizeof(t_float*) );
- }
+ t_int ei;
+
+ if ( x->x_outputs )
+ {
+ for ( ei=0; ei<x->x_nboutputs; ei++ )
+ {
+ outlet_free( x->x_outputs[ei] );
+ }
+ freebytes( x->x_outputs, x->x_nboutputs*sizeof(t_outlet*) );
+ }
+ if ( x->x_inputs )
+ {
+ for ( ei=0; ei<x->x_nbinputs; ei++ )
+ {
+ inlet_free( x->x_inputs[ei] );
+ }
+ freebytes( x->x_inputs, x->x_nbinputs*sizeof(t_outlet*) );
+ }
+ if ( x->x_audiobuffer )
+ {
+ for ( ei=0; ei<x->x_nbinputs; ei++ )
+ {
+ freebytes( x->x_audiobuffer[ei], x->x_audiobuffersize*sizeof(t_float) );
+ }
+ freebytes( x->x_audiobuffer, x->x_nbinputs*sizeof(t_float*) );
+ }
}
static t_int *audience_perform(t_int *w)
@@ -859,96 +864,96 @@ static t_int *audience_perform(t_int *w)
t_int bsize = w[2];
{
- // save input sounds in the audio buffer
- for ( ii=0; ii<x->x_nbinputs; ii++ )
- {
- t_float* isound = (t_float*)w[ii+3];
-
- if ( x->x_audiobuffer[ii] )
- {
- op = 0;
- while ( op < bsize )
- {
- *(x->x_audiobuffer[ii] + x->x_audiowritepos + op ) = *(isound + op);
- op++;
- }
- }
- }
-
- // set outputs
- for ( oi=0; oi<x->x_nboutputs; oi++ )
- {
- t_float* osound = (t_float*)w[oi+3+x->x_nbinputs];
-
- // zeroing output
- memset( osound, 0x00, bsize*sizeof( t_float ) );
-
- for ( ii=0; ii<x->x_nbinputs; ii++ )
- {
- t_int delay;
- t_int dist;
- t_int readpos;
- t_int maxwritepos;
-
- maxwritepos = ( x->x_audiobuffersize / bsize ) * bsize;
- dist = sqrt( pow( (x->x_outputs_x[oi] - x->x_inputs_x[ii]), 2 )
- + pow( (x->x_outputs_y[oi] - x->x_inputs_y[ii]), 2 ) );
- delay = ( t_int ) ( ( ( ( t_float ) dist ) * ( (float ) sys_getsr() ) ) / SOUNDSPEED );
- delay = ( delay / bsize ) * bsize; // set a block frontier
- if ( x->x_applydelay )
- {
- if ( x->x_audiowritepos >= delay )
- {
- readpos = x->x_audiowritepos - delay;
- }
- else
- {
- readpos = maxwritepos - delay + x->x_audiowritepos;
- }
- }
- else
+ // save input sounds in the audio buffer
+ for ( ii=0; ii<x->x_nbinputs; ii++ )
+ {
+ t_float* isound = (t_float*)w[ii+3];
+
+ if ( x->x_audiobuffer[ii] )
{
- readpos = x->x_audiowritepos;
+ op = 0;
+ while ( op < bsize )
+ {
+ *(x->x_audiobuffer[ii] + x->x_audiowritepos + op ) = *(isound + op);
+ op++;
+ }
}
- // if ( ii == 0 )
- // {
- // post( "audience~ : dist : %d : delay : %d : readpos : %d : writepos : %d",
- // dist, delay, readpos, x->x_audiowritepos );
- // }
-
- op = 0;
- while ( op < bsize )
+ }
+
+ // set outputs
+ for ( oi=0; oi<x->x_nboutputs; oi++ )
+ {
+ t_float* osound = (t_float*)w[oi+3+x->x_nbinputs];
+
+ // zeroing output
+ memset( osound, 0x00, bsize*sizeof( t_float ) );
+
+ for ( ii=0; ii<x->x_nbinputs; ii++ )
{
- if ( ( readpos < x->x_audiobuffersize ) && ( readpos >= 0 ) )
- {
- if ( 1.0-x->x_attenuation*dist < 0 )
- {
- *(osound+op) += 0.0;
- }
- else
- {
- *(osound+op) += *(x->x_audiobuffer[ii] + readpos + op)*(1.0-x->x_attenuation*dist);
- }
- }
- else
- {
- error( "audience~ : delay : %d : wrong readpos !!! : %d >= %d or < 0", delay, readpos, x->x_audiobuffersize );
- }
- op++;
+ t_int delay;
+ t_int dist;
+ t_int readpos;
+ t_int maxwritepos;
+
+ maxwritepos = ( x->x_audiobuffersize / bsize ) * bsize;
+ dist = sqrt( pow( (x->x_outputs_x[oi] - x->x_inputs_x[ii]), 2 )
+ + pow( (x->x_outputs_y[oi] - x->x_inputs_y[ii]), 2 ) );
+ delay = ( t_int ) ( ( ( ( t_float ) dist ) * ( (float ) sys_getsr() ) ) / SOUNDSPEED );
+ delay = ( delay / bsize ) * bsize; // set a block frontier
+ if ( x->x_applydelay )
+ {
+ if ( x->x_audiowritepos >= delay )
+ {
+ readpos = x->x_audiowritepos - delay;
+ }
+ else
+ {
+ readpos = maxwritepos - delay + x->x_audiowritepos;
+ }
+ }
+ else
+ {
+ readpos = x->x_audiowritepos;
+ }
+ // if ( ii == 0 )
+ // {
+ // post( "audience~ : dist : %d : delay : %d : readpos : %d : writepos : %d",
+ // dist, delay, readpos, x->x_audiowritepos );
+ // }
+
+ op = 0;
+ while ( op < bsize )
+ {
+ if ( ( readpos < x->x_audiobuffersize ) && ( readpos >= 0 ) )
+ {
+ if ( 1.0-x->x_attenuation*dist < 0 )
+ {
+ *(osound+op) += 0.0;
+ }
+ else
+ {
+ *(osound+op) += *(x->x_audiobuffer[ii] + readpos + op)*(1.0-x->x_attenuation*dist);
+ }
+ }
+ else
+ {
+ error( "audience~ : delay : %d : wrong readpos !!! : %d >= %d or < 0", delay, readpos, x->x_audiobuffersize );
+ }
+ op++;
+ }
}
- }
- }
+ }
- // update write position
- if ( x->x_audiowritepos + bsize > x->x_audiobuffersize - bsize )
- {
- // post( "audience~ : write back to zero @ %d", x->x_audiowritepos );
- x->x_audiowritepos = 0;
- }
- else
- {
- x->x_audiowritepos += bsize;
- }
+ // update write position
+ if ( x->x_audiowritepos + bsize > x->x_audiobuffersize - bsize )
+ {
+ // post( "audience~ : write back to zero @ %d", x->x_audiowritepos );
+ x->x_audiowritepos = 0;
+ }
+ else
+ {
+ x->x_audiowritepos += bsize;
+ }
}
@@ -959,83 +964,83 @@ static void audience_dsp(t_audience_tilde *x, t_signal **sp)
{
switch ( x->x_nbinputs+x->x_nboutputs )
{
- case 2 :
- dsp_add(audience_perform, 4, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec );
- break;
-
- case 3 :
- dsp_add(audience_perform, 5, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec );
- break;
-
- case 4 :
- dsp_add(audience_perform, 6, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec );
- break;
-
- case 5 :
- dsp_add(audience_perform, 7, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec, sp[5]->s_vec );
- break;
-
- case 6 :
- dsp_add(audience_perform, 8, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
- sp[5]->s_vec, sp[6]->s_vec );
- break;
-
- case 7 :
- dsp_add(audience_perform, 9, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
- sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec );
- break;
-
- case 8 :
- dsp_add(audience_perform, 10, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
- sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec, sp[8]->s_vec );
- break;
-
- case 9 :
- dsp_add(audience_perform, 11, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
- sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec, sp[8]->s_vec, sp[9]->s_vec );
- break;
-
- case 10 :
- dsp_add(audience_perform, 12, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
- sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec, sp[8]->s_vec,
- sp[9]->s_vec, sp[10]->s_vec );
- break;
-
- default :
- post( "audience~ : number of inlets/outlets not supported" );
- break;
- }
+ case 2 :
+ dsp_add(audience_perform, 4, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec );
+ break;
+
+ case 3 :
+ dsp_add(audience_perform, 5, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec );
+ break;
+
+ case 4 :
+ dsp_add(audience_perform, 6, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec );
+ break;
+
+ case 5 :
+ dsp_add(audience_perform, 7, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec, sp[5]->s_vec );
+ break;
+
+ case 6 :
+ dsp_add(audience_perform, 8, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
+ sp[5]->s_vec, sp[6]->s_vec );
+ break;
+
+ case 7 :
+ dsp_add(audience_perform, 9, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
+ sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec );
+ break;
+
+ case 8 :
+ dsp_add(audience_perform, 10, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
+ sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec, sp[8]->s_vec );
+ break;
+
+ case 9 :
+ dsp_add(audience_perform, 11, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
+ sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec, sp[8]->s_vec, sp[9]->s_vec );
+ break;
+
+ case 10 :
+ dsp_add(audience_perform, 12, x, sp[1]->s_n, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec,
+ sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec, sp[8]->s_vec,
+ sp[9]->s_vec, sp[10]->s_vec );
+ break;
+
+ default :
+ post( "audience~ : number of inlets/outlets not supported" );
+ break;
+ }
}
// set attenuation
static void audience_attenuation(t_audience_tilde *x, t_floatarg fattenuation )
{
- if ( fattenuation < 0 )
- {
- post( "audience~ : error : wrong attenuation : %f", fattenuation );
- return;
- }
- x->x_attenuation = fattenuation;
+ if ( fattenuation < 0 )
+ {
+ post( "audience~ : error : wrong attenuation : %f", fattenuation );
+ return;
+ }
+ x->x_attenuation = fattenuation;
}
// set delay
static void audience_delay(t_audience_tilde *x, t_floatarg fdelay )
{
- if ( fdelay == 0. )
- {
- x->x_applydelay = 0;
- }
- else
- {
- x->x_applydelay = 1;
- }
+ if ( fdelay == 0. )
+ {
+ x->x_applydelay = 0;
+ }
+ else
+ {
+ x->x_applydelay = 1;
+ }
}
void audience_tilde_setup(void)
{
verbose(0, audience_version );
audience_class_tilde = class_new(gensym("audience~"), (t_newmethod)audience_new,
- (t_method)audience_free, sizeof(t_audience_tilde), 0, A_GIMME, 0);
+ (t_method)audience_free, sizeof(t_audience_tilde), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN( audience_class_tilde, t_audience_tilde, x_f );
class_addmethod(audience_class_tilde, (t_method)audience_dsp, gensym("dsp"), 0);
class_addmethod(audience_class_tilde, (t_method)audience_dialog, gensym("dialog"), A_GIMME, 0);
diff --git a/beatify~.c b/beatify~.c
index 0f74796..8b2f36a 100644
--- a/beatify~.c
+++ b/beatify~.c
@@ -54,60 +54,65 @@ static t_class *beatify_class;
static void beatify_attack(t_beatify *x, t_floatarg fattack )
{
- if (fattack < 1.0)
+ if (fattack < 1.0)
{
- x->x_attack = 1.0;
+ x->x_attack = 1.0;
}
else
{
- x->x_attack = fattack;
+ x->x_attack = fattack;
}
}
static void beatify_sustain(t_beatify *x, t_floatarg fsustain )
{
- if (fsustain < 0.0)
+ if (fsustain < 0.0)
{
- x->x_sustain = 0.0;
+ x->x_sustain = 0.0;
}
else
{
- x->x_sustain = fsustain;
+ x->x_sustain = fsustain;
}
}
static void beatify_decay(t_beatify *x, t_floatarg fdecay )
{
- if (fdecay < 1.0)
+ if (fdecay < 1.0)
{
- x->x_decay = 1.0;
+ x->x_decay = 1.0;
}
else
{
- x->x_decay = fdecay;
+ x->x_decay = fdecay;
}
}
static void beatify_size(t_beatify *x, t_floatarg fsize )
{
- if (fsize < 100.0)
+ if (fsize < 100.0)
{
- x->x_size = 100.0;
+ x->x_size = 100.0;
}
else
{
- x->x_size = fsize;
+ x->x_size = fsize;
}
}
static void beatify_gamplitude(t_beatify *x, t_floatarg fgamplitude )
{
- if (fgamplitude < 0.0) {
- x->x_gamplitude = 0.0;
- } else if (fgamplitude > 1.0) {
- x->x_gamplitude = 1.0;
- } else {
- x->x_gamplitude = fgamplitude;
+ if (fgamplitude < 0.0)
+ {
+ x->x_gamplitude = 0.0;
+ }
+ else if (fgamplitude > 1.0)
+ {
+ x->x_gamplitude = 1.0;
+ }
+ else
+ {
+ x->x_gamplitude = fgamplitude;
}
}
@@ -137,22 +142,24 @@ static t_int *beatify_perform(t_int *w)
t_beatify *x = (t_beatify*)(w[4]);
t_float adelta = 0., ddelta = 0.;
- while (n--) {
- if ( x->x_current>=x->x_size )
- {
+ while (n--)
+ {
+ if ( x->x_current>=x->x_size )
+ {
adelta = (x->x_gamplitude-x->x_vol)/x->x_attack;
ddelta = x->x_gamplitude/x->x_decay;
x->x_current = 0;
- }
- if ( x->x_current<x->x_attack ) x->x_vol+= adelta;
- if ( x->x_current>x->x_attack+x->x_sustain && x->x_current<x->x_attack+x->x_sustain+x->x_decay )
- {
- x->x_vol-= ddelta;
- }
- x->x_current++;
+ }
+ if ( x->x_current<x->x_attack ) x->x_vol+= adelta;
+ if ( x->x_current>x->x_attack+x->x_sustain && x->x_current<x->x_attack+x->x_sustain+x->x_decay )
+ {
+ x->x_vol-= ddelta;
+ }
+ x->x_current++;
- *(out) = *(in)*x->x_vol;
- out++; in++;
+ *(out) = *(in)*x->x_vol;
+ out++;
+ in++;
}
return (w+5);
}
@@ -166,7 +173,7 @@ void beatify_tilde_setup(void)
{
verbose(0, beatify_version );
beatify_class = class_new(gensym("beatify~"), (t_newmethod)beatify_new, 0,
- sizeof(t_beatify), 0, 0);
+ sizeof(t_beatify), 0, 0);
CLASS_MAINSIGNALIN( beatify_class, t_beatify, x_f );
class_addmethod(beatify_class, (t_method)beatify_dsp, gensym("dsp"), 0);
class_addmethod(beatify_class, (t_method)beatify_attack, gensym("attack"), A_FLOAT, 0);
diff --git a/blinkenlights.c b/blinkenlights.c
index 177cb30..c9f0a81 100644
--- a/blinkenlights.c
+++ b/blinkenlights.c
@@ -31,7 +31,7 @@
//this is to remember the frame positions in the .blm file
//"static void blinkenlights_goto(t_blinkenlights* x, t_float frame)"
-//with a "goto $1" message, you can stratch the blm film. note that the
+//with a "goto $1" message, you can stratch the blm film. note that the
//range of $1 is 0 to 1
@@ -115,475 +115,492 @@ typedef struct _blinkenlights
t_int *x_frame; /* frame contents */
t_clock *x_clock; /* clock used for reading frames */
t_outlet *outlet_bang;
- t_int frame_no;
+ t_int frame_no;
t_int frame_pos[BL_MAX_LENGTH];
t_clock *x_clock2;
t_int x_timer2;
t_float frame_inc;
-
+
} t_blinkenlights;
static void blinkenlights_close(t_blinkenlights *x);
- /* clean up */
-static void blinkenlights_free(t_blinkenlights *x)
+/* clean up */
+static void blinkenlights_free(t_blinkenlights *x)
{
- post( "blinkenlights : freeing colors" );
- if ( x->x_background ) freebytes( x->x_background, 8 );
- if ( x->x_foreground ) freebytes( x->x_foreground, 8 );
- post( "blinkenlights : closing file" );
- blinkenlights_close(x);
- post( "blinkenlights : cancelling clock" );
- if ( x->x_clock != NULL )
- {
- clock_unset( x->x_clock );
- clock_free( x->x_clock );
- }
- if ( x->x_clock2 != NULL )
- {
- clock_unset( x->x_clock2 );
- clock_free( x->x_clock2 );
- }
- post( "blinkenlights : done" );
+ post( "blinkenlights : freeing colors" );
+ if ( x->x_background ) freebytes( x->x_background, 8 );
+ if ( x->x_foreground ) freebytes( x->x_foreground, 8 );
+ post( "blinkenlights : closing file" );
+ blinkenlights_close(x);
+ post( "blinkenlights : cancelling clock" );
+ if ( x->x_clock != NULL )
+ {
+ clock_unset( x->x_clock );
+ clock_free( x->x_clock );
+ }
+ if ( x->x_clock2 != NULL )
+ {
+ clock_unset( x->x_clock2 );
+ clock_free( x->x_clock2 );
+ }
+ post( "blinkenlights : done" );
}
static void *blinkenlights_new(t_float fwidth, t_float fheight, t_float fxpixsize, t_float fypixsize )
{
- t_blinkenlights *x = (t_blinkenlights *)pd_new(blinkenlights_class);
- if ( fwidth <= 0 ) {
- post( "blinkenlights: wrong creation argument : width : %f", fwidth );
- return NULL;
- }
- if ( fheight <= 0 ) {
- post( "blinkenlights: wrong creation argument : height : %f", fheight );
- return NULL;
- }
- if ( fxpixsize <= 0 ) {
- post( "blinkenlights: wrong creation argument : x pixel size : %f", fxpixsize );
- return NULL;
- }
- if ( fypixsize <= 0 ) {
- post( "blinkenlights: wrong creation argument : y pixel size : %f", fypixsize );
- return NULL;
- }
- x->x_width = (int) fwidth;
- x->x_height = (int) fheight;
- x->x_xsize = (int) fxpixsize;
- x->x_ysize = (int) fypixsize;
- x->x_ecanvas = 0;
- x->x_filed = NULL;
- x->x_frame = NULL;
- x->x_clock = NULL;
- x->x_glist = (t_glist *) canvas_getcurrent();
- x->x_background = (char*) getbytes( 8 );
- strncpy( x->x_background, BL_BACKGROUND_COLOR, 7 );
- x->x_background[7] = '\0';
- x->x_foreground = (char*) getbytes( 8 );
- strncpy( x->x_foreground, BL_FOREGROUND_COLOR, 7 );
- x->x_foreground[7] = '\0';
- x->x_timer2 = 40;
- x->frame_inc = 0;
-
- x->outlet_bang = outlet_new(&x->x_obj, &s_bang);
-
- return(x);
+ t_blinkenlights *x = (t_blinkenlights *)pd_new(blinkenlights_class);
+ if ( fwidth <= 0 )
+ {
+ post( "blinkenlights: wrong creation argument : width : %f", fwidth );
+ return NULL;
+ }
+ if ( fheight <= 0 )
+ {
+ post( "blinkenlights: wrong creation argument : height : %f", fheight );
+ return NULL;
+ }
+ if ( fxpixsize <= 0 )
+ {
+ post( "blinkenlights: wrong creation argument : x pixel size : %f", fxpixsize );
+ return NULL;
+ }
+ if ( fypixsize <= 0 )
+ {
+ post( "blinkenlights: wrong creation argument : y pixel size : %f", fypixsize );
+ return NULL;
+ }
+ x->x_width = (int) fwidth;
+ x->x_height = (int) fheight;
+ x->x_xsize = (int) fxpixsize;
+ x->x_ysize = (int) fypixsize;
+ x->x_ecanvas = 0;
+ x->x_filed = NULL;
+ x->x_frame = NULL;
+ x->x_clock = NULL;
+ x->x_glist = (t_glist *) canvas_getcurrent();
+ x->x_background = (char*) getbytes( 8 );
+ strncpy( x->x_background, BL_BACKGROUND_COLOR, 7 );
+ x->x_background[7] = '\0';
+ x->x_foreground = (char*) getbytes( 8 );
+ strncpy( x->x_foreground, BL_FOREGROUND_COLOR, 7 );
+ x->x_foreground[7] = '\0';
+ x->x_timer2 = 40;
+ x->frame_inc = 0;
+
+ x->outlet_bang = outlet_new(&x->x_obj, &s_bang);
+
+ return(x);
}
static void blinkenlights_draw_new(t_blinkenlights* x)
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
- t_int xi, yi;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_int xi, yi;
- SYS_VGUI4("toplevel .x%lx -width %d -height %d -borderwidth 0 -background #000000\n", x,
- x->x_width*x->x_xsize, x->x_height*x->x_ysize );
- SYS_VGUI2("frame .x%lx.m -relief raised -bd 2\n", x);
- SYS_VGUI2("wm title .x%lx blinkenlights\n", x);
+ SYS_VGUI4("toplevel .x%lx -width %d -height %d -borderwidth 0 -background #000000\n", x,
+ x->x_width*x->x_xsize, x->x_height*x->x_ysize );
+ SYS_VGUI2("frame .x%lx.m -relief raised -bd 2\n", x);
+ SYS_VGUI2("wm title .x%lx blinkenlights\n", x);
- SYS_VGUI4("canvas .x%lx.c -width %d -height %d\n",
- x,
- x->x_width*x->x_xsize, x->x_height*x->x_ysize );
- x->x_ecanvas = 1;
+ SYS_VGUI4("canvas .x%lx.c -width %d -height %d\n",
+ x,
+ x->x_width*x->x_xsize, x->x_height*x->x_ysize );
+ x->x_ecanvas = 1;
- for ( xi=1; xi<=x->x_width; xi++ )
- {
- for ( yi=1; yi<=x->x_height; yi++ )
+ for ( xi=1; xi<=x->x_width; xi++ )
{
- SYS_VGUI10(".x%lx.c create rectangle %d %d %d %d -fill %s -outline #555555 -tags %xPIX%.5d%.5d\n",
- x,
- (xi-1)*x->x_xsize, (yi-1)*x->x_ysize,
- xi*x->x_xsize, yi*x->x_ysize,
- x->x_background,
- x, xi, yi);
+ for ( yi=1; yi<=x->x_height; yi++ )
+ {
+ SYS_VGUI10(".x%lx.c create rectangle %d %d %d %d -fill %s -outline #555555 -tags %xPIX%.5d%.5d\n",
+ x,
+ (xi-1)*x->x_xsize, (yi-1)*x->x_ysize,
+ xi*x->x_xsize, yi*x->x_ysize,
+ x->x_background,
+ x, xi, yi);
+ }
}
- }
- SYS_VGUI2("pack .x%lx.c -side left -expand 1 -fill both\n", x);
- SYS_VGUI2("pack .x%lx.m -side top -fill x\n", x);
- SYS_VGUI2("wm geometry .x%lx +0+0\n", x);
- SYS_VGUI2("wm geometry .x%lx +0+0\n", x);
+ SYS_VGUI2("pack .x%lx.c -side left -expand 1 -fill both\n", x);
+ SYS_VGUI2("pack .x%lx.m -side top -fill x\n", x);
+ SYS_VGUI2("wm geometry .x%lx +0+0\n", x);
+ SYS_VGUI2("wm geometry .x%lx +0+0\n", x);
}
static void blinkenlights_create(t_blinkenlights* x)
{
- if ( x->x_ecanvas )
- {
- post("blinkenlights : create : canvas already exists" );
- return;
- }
+ if ( x->x_ecanvas )
+ {
+ post("blinkenlights : create : canvas already exists" );
+ return;
+ }
- blinkenlights_draw_new(x);
+ blinkenlights_draw_new(x);
}
static void blinkenlights_erase(t_blinkenlights* x)
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
- t_int xi, yi;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_int xi, yi;
- for ( xi=1; xi<=x->x_width; xi++ )
- {
- for ( yi=1; yi<=x->x_height; yi++ )
+ for ( xi=1; xi<=x->x_width; xi++ )
{
- SYS_VGUI5(".x%lx.c delete %xPIX%.5d%.5d\n", x, x, xi, yi);
+ for ( yi=1; yi<=x->x_height; yi++ )
+ {
+ SYS_VGUI5(".x%lx.c delete %xPIX%.5d%.5d\n", x, x, xi, yi);
+ }
}
- }
- SYS_VGUI2("destroy .x%lx\n", x);
- x->x_ecanvas=0;
+ SYS_VGUI2("destroy .x%lx\n", x);
+ x->x_ecanvas=0;
}
static void blinkenlights_destroy(t_blinkenlights* x)
{
- if ( !x->x_ecanvas )
- {
- post("blinkenlights : destroy : canvas does not exist" );
- return;
- }
+ if ( !x->x_ecanvas )
+ {
+ post("blinkenlights : destroy : canvas does not exist" );
+ return;
+ }
- blinkenlights_erase(x);
+ blinkenlights_erase(x);
}
static void blinkenlights_width(t_blinkenlights* x, t_float fwidth)
{
- if ( fwidth <= 0 ) {
- post( "blinkenlights~: wrong width : ignored" );
- return;
- } else {
- if ( x->x_width == (int)fwidth ) return;
- x->x_width=(int)fwidth;
- }
- if (x->x_ecanvas) blinkenlights_erase( x );
- blinkenlights_draw_new( x );
+ if ( fwidth <= 0 )
+ {
+ post( "blinkenlights~: wrong width : ignored" );
+ return;
+ }
+ else
+ {
+ if ( x->x_width == (int)fwidth ) return;
+ x->x_width=(int)fwidth;
+ }
+ if (x->x_ecanvas) blinkenlights_erase( x );
+ blinkenlights_draw_new( x );
}
static void blinkenlights_height(t_blinkenlights* x, t_float fheight)
{
- if ( fheight <= 0 ) {
- post( "blinkenlights~: wrong height : ignored" );
- return;
- } else {
- if ( x->x_height == (int)fheight ) return;
- x->x_height=(int)fheight;
- }
- if (x->x_ecanvas) blinkenlights_erase( x );
- blinkenlights_draw_new( x );
+ if ( fheight <= 0 )
+ {
+ post( "blinkenlights~: wrong height : ignored" );
+ return;
+ }
+ else
+ {
+ if ( x->x_height == (int)fheight ) return;
+ x->x_height=(int)fheight;
+ }
+ if (x->x_ecanvas) blinkenlights_erase( x );
+ blinkenlights_draw_new( x );
}
static void blinkenlights_xsize(t_blinkenlights* x, t_float fxsize)
{
- if ( fxsize <= 0 ) {
- post( "blinkenlights~: wrong x pixel size : ignored" );
- return;
- } else {
- if ( x->x_xsize == (int)fxsize ) return;
- x->x_xsize=(int)fxsize;
- }
- if (x->x_ecanvas) blinkenlights_erase( x );
- blinkenlights_draw_new( x );
+ if ( fxsize <= 0 )
+ {
+ post( "blinkenlights~: wrong x pixel size : ignored" );
+ return;
+ }
+ else
+ {
+ if ( x->x_xsize == (int)fxsize ) return;
+ x->x_xsize=(int)fxsize;
+ }
+ if (x->x_ecanvas) blinkenlights_erase( x );
+ blinkenlights_draw_new( x );
}
static void blinkenlights_ysize(t_blinkenlights* x, t_float fysize)
{
- if ( fysize <= 0 ) {
- post( "blinkenlights~: wrong y pixel size : ignored" );
- return;
- } else {
- if ( x->x_ysize == (int)fysize ) return;
- x->x_ysize=(int)fysize;
- }
- if (x->x_ecanvas) blinkenlights_erase( x );
- blinkenlights_draw_new( x );
+ if ( fysize <= 0 )
+ {
+ post( "blinkenlights~: wrong y pixel size : ignored" );
+ return;
+ }
+ else
+ {
+ if ( x->x_ysize == (int)fysize ) return;
+ x->x_ysize=(int)fysize;
+ }
+ if (x->x_ecanvas) blinkenlights_erase( x );
+ blinkenlights_draw_new( x );
}
static void blinkenlights_background(t_blinkenlights* x, t_float fR, t_float fG, t_float fB)
{
- if ( fR <0 || fR>255 )
- {
- post("blinkenlights : wrong color component : fR : %d", fR);
- return;
- }
- if ( fG <0 || fG>255 )
- {
- post("blinkenlights : wrong color component : fG : %d", fG);
- return;
- }
- if ( fB <0 || fB>255 )
- {
- post("blinkenlights : wrong color component : fB : %d", fB);
- return;
- }
- sprintf( x->x_background, "#%.2x%.2x%.2x", (int)fR, (int)fG, (int)fB );
- post("blinkenlights : background color set to : %s", x->x_background );
+ if ( fR <0 || fR>255 )
+ {
+ post("blinkenlights : wrong color component : fR : %d", fR);
+ return;
+ }
+ if ( fG <0 || fG>255 )
+ {
+ post("blinkenlights : wrong color component : fG : %d", fG);
+ return;
+ }
+ if ( fB <0 || fB>255 )
+ {
+ post("blinkenlights : wrong color component : fB : %d", fB);
+ return;
+ }
+ sprintf( x->x_background, "#%.2x%.2x%.2x", (int)fR, (int)fG, (int)fB );
+ post("blinkenlights : background color set to : %s", x->x_background );
}
static void blinkenlights_foreground(t_blinkenlights* x, t_float fR, t_float fG, t_float fB)
{
- if ( fR <0 || fR>255 )
- {
- post("blinkenlights : wrong color component : fR : %d", fR);
- return;
- }
- if ( fG <0 || fG>255 )
- {
- post("blinkenlights : wrong color component : fG : %d", fG);
- return;
- }
- if ( fB <0 || fB>255 )
- {
- post("blinkenlights : wrong color component : fB : %d", fB);
- return;
- }
- sprintf( x->x_foreground, "#%.2x%.2x%.2x", (int)fR, (int)fG, (int)fB );
- post("blinkenlights : foreground color set to : %s", x->x_foreground );
+ if ( fR <0 || fR>255 )
+ {
+ post("blinkenlights : wrong color component : fR : %d", fR);
+ return;
+ }
+ if ( fG <0 || fG>255 )
+ {
+ post("blinkenlights : wrong color component : fG : %d", fG);
+ return;
+ }
+ if ( fB <0 || fB>255 )
+ {
+ post("blinkenlights : wrong color component : fB : %d", fB);
+ return;
+ }
+ sprintf( x->x_foreground, "#%.2x%.2x%.2x", (int)fR, (int)fG, (int)fB );
+ post("blinkenlights : foreground color set to : %s", x->x_foreground );
}
static void blinkenlights_pixon(t_blinkenlights* x, t_float fX, t_float fY)
{
- if ( !x->x_ecanvas )
- {
- post("blinkenlights : pixon : canvas does not exist" );
- return;
- }
- if ( fX<1 || fX>x->x_width )
- {
- post("blinkenlights : pixon : wrong x coordinate : %d : should be in [1,%d]", (int)fX, x->x_width );
- return;
- }
- if ( fY<1 || fY>x->x_height )
- {
- post("blinkenlights : pixon : wrong y coordinate : %d : should be in [1,%d]", (int)fY, x->x_height );
- return;
- }
- SYS_VGUI6(".x%lx.c itemconfigure %xPIX%.5d%.5d -fill %s\n", x, x, (int)fX, (int)fY, x->x_foreground );
+ if ( !x->x_ecanvas )
+ {
+ post("blinkenlights : pixon : canvas does not exist" );
+ return;
+ }
+ if ( fX<1 || fX>x->x_width )
+ {
+ post("blinkenlights : pixon : wrong x coordinate : %d : should be in [1,%d]", (int)fX, x->x_width );
+ return;
+ }
+ if ( fY<1 || fY>x->x_height )
+ {
+ post("blinkenlights : pixon : wrong y coordinate : %d : should be in [1,%d]", (int)fY, x->x_height );
+ return;
+ }
+ SYS_VGUI6(".x%lx.c itemconfigure %xPIX%.5d%.5d -fill %s\n", x, x, (int)fX, (int)fY, x->x_foreground );
}
static void blinkenlights_pixoff(t_blinkenlights* x, t_float fX, t_float fY)
{
- if ( !x->x_ecanvas )
- {
- post("blinkenlights : pixoff : canvas does not exist" );
- return;
- }
- if ( fX<1 || fX>x->x_width )
- {
- post("blinkenlights : pixoff : wrong x coordinate : %d : should be in [1,%d]", (int)fX, x->x_width );
- return;
- }
- if ( fY<1 || fY>x->x_height )
- {
- post("blinkenlights : pixoff : wrong y coordinate : %d : should be in [1,%d]", (int)fY, x->x_height );
- return;
- }
- SYS_VGUI6(".x%lx.c itemconfigure %xPIX%.5d%.5d -fill %s\n", x, x, (int)fX, (int)fY, x->x_background );
+ if ( !x->x_ecanvas )
+ {
+ post("blinkenlights : pixoff : canvas does not exist" );
+ return;
+ }
+ if ( fX<1 || fX>x->x_width )
+ {
+ post("blinkenlights : pixoff : wrong x coordinate : %d : should be in [1,%d]", (int)fX, x->x_width );
+ return;
+ }
+ if ( fY<1 || fY>x->x_height )
+ {
+ post("blinkenlights : pixoff : wrong y coordinate : %d : should be in [1,%d]", (int)fY, x->x_height );
+ return;
+ }
+ SYS_VGUI6(".x%lx.c itemconfigure %xPIX%.5d%.5d -fill %s\n", x, x, (int)fX, (int)fY, x->x_background );
}
static void blinkenlights_pixel(t_blinkenlights* x, t_float fX, t_float fY, t_float fR, t_float fG, t_float fB)
{
- if ( !x->x_ecanvas )
- {
- post("blinkenlights : pixel : canvas does not exist" );
- return;
- }
- if ( fX<1 || fX>x->x_width )
- {
- post("blinkenlights : pixel : wrong x coordinate : %d : should be in [1,%d]", (int)fX, x->x_width );
- return;
- }
- if ( fY<1 || fY>x->x_height )
- {
- post("blinkenlights : pixel : wrong y coordinate : %d : should be in [1,%d]", (int)fY, x->x_height );
- return;
- }
- if ( fR <0 || fR>255 )
- {
- post("blinkenlights : pixel : wrong color component : fR : %d", fR);
- return;
- }
- if ( fG <0 || fG>255 )
- {
- post("blinkenlights : pixel : wrong color component : fG : %d", fG);
- return;
- }
- if ( fB <0 || fB>255 )
- {
- post("blinkenlights : pixel : wrong color component : fB : %d", fB);
- return;
- }
- SYS_VGUI8(".x%lx.c itemconfigure %xPIX%.5d%.5d -fill #%.2X%.2X%.2X\n", x, x, (int)fX, (int)fY, (int)fR, (int)fG, (int)fB );
+ if ( !x->x_ecanvas )
+ {
+ post("blinkenlights : pixel : canvas does not exist" );
+ return;
+ }
+ if ( fX<1 || fX>x->x_width )
+ {
+ post("blinkenlights : pixel : wrong x coordinate : %d : should be in [1,%d]", (int)fX, x->x_width );
+ return;
+ }
+ if ( fY<1 || fY>x->x_height )
+ {
+ post("blinkenlights : pixel : wrong y coordinate : %d : should be in [1,%d]", (int)fY, x->x_height );
+ return;
+ }
+ if ( fR <0 || fR>255 )
+ {
+ post("blinkenlights : pixel : wrong color component : fR : %d", fR);
+ return;
+ }
+ if ( fG <0 || fG>255 )
+ {
+ post("blinkenlights : pixel : wrong color component : fG : %d", fG);
+ return;
+ }
+ if ( fB <0 || fB>255 )
+ {
+ post("blinkenlights : pixel : wrong color component : fB : %d", fB);
+ return;
+ }
+ SYS_VGUI8(".x%lx.c itemconfigure %xPIX%.5d%.5d -fill #%.2X%.2X%.2X\n", x, x, (int)fX, (int)fY, (int)fR, (int)fG, (int)fB );
}
static void blinkenlights_clear(t_blinkenlights* x)
{
- t_int xi, yi;
+ t_int xi, yi;
- for ( xi=1; xi<=x->x_width; xi++ )
- {
- for ( yi=1; yi<=x->x_height; yi++ )
+ for ( xi=1; xi<=x->x_width; xi++ )
{
- blinkenlights_pixoff( x, xi, yi );
+ for ( yi=1; yi<=x->x_height; yi++ )
+ {
+ blinkenlights_pixoff( x, xi, yi );
+ }
}
- }
}
- /* close the current movie */
+/* close the current movie */
static void blinkenlights_close(t_blinkenlights *x)
{
/* closing previous file descriptor */
- if ( x->x_filed != NULL ) {
- if(fclose(x->x_filed) < 0)
- {
- perror( "blinkenlights : closing file" );
- }
- x->x_filed = NULL;
+ if ( x->x_filed != NULL )
+ {
+ if(fclose(x->x_filed) < 0)
+ {
+ perror( "blinkenlights : closing file" );
+ }
+ x->x_filed = NULL;
}
if ( x->x_frame )
{
- freebytes( x->x_frame, x->x_width*x->x_height*sizeof(t_int) );
- x->x_frame = NULL;
+ freebytes( x->x_frame, x->x_width*x->x_height*sizeof(t_int) );
+ x->x_frame = NULL;
}
}
- /* read the next frame */
+/* read the next frame */
static void blinkenlights_readframe(t_blinkenlights *x)
{
- char *lineread = (char*) getbytes( BL_MAX_LENGTH );
- t_int flineno = 0;
- t_int width, height, nwidth;
-
- //post( "blinkenlights: being readframe:>%s<", lineread );
+ char *lineread = (char*) getbytes( BL_MAX_LENGTH );
+ t_int flineno = 0;
+ t_int width, height, nwidth;
+
+ //post( "blinkenlights: being readframe:>%s<", lineread );
if ( !x->x_ecanvas )
{
- post("blinkenlights : next : canvas does not exist" );
- return;
+ post("blinkenlights : next : canvas does not exist" );
+ return;
}
if ( x->x_filed == NULL )
{
- post( "blinkenlights : no file is opened for reading a frame" );
- blinkenlights_close(x);
- return;
+ post( "blinkenlights : no file is opened for reading a frame" );
+ blinkenlights_close(x);
+ return;
}
// skip header and empty lines
- while ( lineread[0] == '#' || lineread[0] == '\n' || lineread[0] == '\0' )
- {
-
- //post( "blinkenlights : skipped line : >%s<", lineread );
- if ( fgets( lineread, BL_MAX_LENGTH, x->x_filed ) == 0 )
- {
- post( "blinkenlights : end of file detected : looping..." );
- fseek( x->x_filed, 0L, SEEK_SET );
- outlet_bang(x->outlet_bang);
- }
- }
-
- if ( lineread[0] != '@' )
- {
- post( "blinkenlights : format error : should find a time lime here : @XXX : got : >%s<", lineread );
- blinkenlights_close(x);
- return;
- }
+ while ( lineread[0] == '#' || lineread[0] == '\n' || lineread[0] == '\0' )
+ {
+
+ //post( "blinkenlights : skipped line : >%s<", lineread );
+ if ( fgets( lineread, BL_MAX_LENGTH, x->x_filed ) == 0 )
+ {
+ post( "blinkenlights : end of file detected : looping..." );
+ fseek( x->x_filed, 0L, SEEK_SET );
+ outlet_bang(x->outlet_bang);
+ }
+ }
+
+ if ( lineread[0] != '@' )
+ {
+ post( "blinkenlights : format error : should find a time lime here : @XXX : got : >%s<", lineread );
+ blinkenlights_close(x);
+ return;
+ }
else
{
- x->x_timer = atoi( lineread+1 );
- // post( "blinkenlights : setting timer to %d", x->x_timer );
+ x->x_timer = atoi( lineread+1 );
+ // post( "blinkenlights : setting timer to %d", x->x_timer );
}
// read the contents of one frame
-
+
// when reading first frame the height and width are read from the file
height = 0;
width = 0;
while ( 1 )
{
- if ( fgets( lineread, BL_MAX_LENGTH, x->x_filed ) == NULL )
+ if ( fgets( lineread, BL_MAX_LENGTH, x->x_filed ) == NULL )
{
- post( "blinkenlights : EOF not expected here !!! ");
- blinkenlights_close(x);
- return;
+ post( "blinkenlights : EOF not expected here !!! ");
+ blinkenlights_close(x);
+ return;
}
else
{
- if ( (lineread[0] == '\0') || (lineread[0] == '#') || (lineread[0] == '\n') ) break;
- // post( "blinkenlights : lineread : %s", lineread );
-
- nwidth = strlen( lineread )-1; // because of the carriage return
- flineno++;
- height = flineno;
- if ( ( nwidth != width ) && ( width != 0 ) )
- {
- post( "blinkenlights : weird file : width has changed (nwidth=%d) (width=%d)", nwidth, width );
- blinkenlights_close( x );
- return;
- }
- width = nwidth;
- if ( x->x_frame != NULL )
- {
- t_int pint = 0;
- t_int newvalue;
-
- while ( pint < width )
- {
- newvalue = (int) *(lineread+pint) - 48 /* ascii value for '0' */;
- if ( newvalue != *(x->x_frame+(flineno-1)*x->x_width+pint ) )
- {
- *(x->x_frame+(flineno-1)*x->x_width+pint ) = newvalue;
- switch ( newvalue )
+ if ( (lineread[0] == '\0') || (lineread[0] == '#') || (lineread[0] == '\n') ) break;
+ // post( "blinkenlights : lineread : %s", lineread );
+
+ nwidth = strlen( lineread )-1; // because of the carriage return
+ flineno++;
+ height = flineno;
+ if ( ( nwidth != width ) && ( width != 0 ) )
+ {
+ post( "blinkenlights : weird file : width has changed (nwidth=%d) (width=%d)", nwidth, width );
+ blinkenlights_close( x );
+ return;
+ }
+ width = nwidth;
+ if ( x->x_frame != NULL )
+ {
+ t_int pint = 0;
+ t_int newvalue;
+
+ while ( pint < width )
+ {
+ newvalue = (int) *(lineread+pint) - 48 /* ascii value for '0' */;
+ if ( newvalue != *(x->x_frame+(flineno-1)*x->x_width+pint ) )
{
- case 0:
- // post( "pixoff %d %d", pint+1, flineno );
- blinkenlights_pixoff( x, pint+1, flineno );
- break;
- case 1:
- // post( "pixon %d %d", pint+1, flineno );
- blinkenlights_pixon( x, pint+1, flineno );
- break;
- default:
- // post("blinkenlights : wrong value found for pixel : %d (c=%c)", newvalue, *(lineread+pint) );
- break;
+ *(x->x_frame+(flineno-1)*x->x_width+pint ) = newvalue;
+ switch ( newvalue )
+ {
+ case 0:
+ // post( "pixoff %d %d", pint+1, flineno );
+ blinkenlights_pixoff( x, pint+1, flineno );
+ break;
+ case 1:
+ // post( "pixon %d %d", pint+1, flineno );
+ blinkenlights_pixon( x, pint+1, flineno );
+ break;
+ default:
+ // post("blinkenlights : wrong value found for pixel : %d (c=%c)", newvalue, *(lineread+pint) );
+ break;
+ }
}
- }
- pint++;
- }
- }
- if ( x->x_frame == NULL ) x->x_height++;
+ pint++;
+ }
+ }
+ if ( x->x_frame == NULL ) x->x_height++;
}
}
if ( x->x_frame == NULL )
{
- if ( x->x_filed != NULL ) if ( fseek(x->x_filed, 0L, SEEK_SET) < 0 )
- {
- post( "blinkenlights : could not rewind file" );
- blinkenlights_close( x );
- return;
- }
- blinkenlights_width(x, width);
- blinkenlights_height(x, height);
- x->x_frame = ( t_int* ) getbytes( x->x_width*x->x_height*sizeof(t_int) );
- blinkenlights_readframe(x);
+ if ( x->x_filed != NULL ) if ( fseek(x->x_filed, 0L, SEEK_SET) < 0 )
+ {
+ post( "blinkenlights : could not rewind file" );
+ blinkenlights_close( x );
+ return;
+ }
+ blinkenlights_width(x, width);
+ blinkenlights_height(x, height);
+ x->x_frame = ( t_int* ) getbytes( x->x_width*x->x_height*sizeof(t_int) );
+ blinkenlights_readframe(x);
}
if ( lineread ) freebytes( lineread, BL_MAX_LENGTH );
@@ -594,276 +611,277 @@ static void blinkenlights_readframe(t_blinkenlights *x)
/* remember all the frame positions */
static void blinkenlights_findframes(t_blinkenlights *x)
{
- int i =0;
-
- x->frame_no = 0;
-
- for(i=0;;i++)
- {
- char *lineread = (char*) getbytes( BL_MAX_LENGTH );
-
- fgets( lineread, BL_MAX_LENGTH, x->x_filed );
- if(strlen(lineread) == 0) break;
-
- if(lineread[0] == '@')
- {
- x->frame_pos[x->frame_no] = ftell(x->x_filed);
- x->frame_no++;
- }
- if (lineread) freebytes( lineread, BL_MAX_LENGTH );
- }
- fseek( x->x_filed, 0L, SEEK_SET );
- post("the end:: %d frames!", x->frame_no);
+ int i =0;
+
+ x->frame_no = 0;
+
+ for(i=0;; i++)
+ {
+ char *lineread = (char*) getbytes( BL_MAX_LENGTH );
+
+ fgets( lineread, BL_MAX_LENGTH, x->x_filed );
+ if(strlen(lineread) == 0) break;
+
+ if(lineread[0] == '@')
+ {
+ x->frame_pos[x->frame_no] = ftell(x->x_filed);
+ x->frame_no++;
+ }
+ if (lineread) freebytes( lineread, BL_MAX_LENGTH );
+ }
+ fseek( x->x_filed, 0L, SEEK_SET );
+ post("the end:: %d frames!", x->frame_no);
}
//-------------------------------------------------------------------------
static void blinkenlights_goto(t_blinkenlights* x)
{
- //char *lineread = (char*) getbytes( BL_MAX_LENGTH );
- char lineread[BL_MAX_LENGTH];
- int current_frame = x->frame_pos[(int)(x->frame_inc * (x->frame_no-1))];
- int i, n, width, newvalue, height, nwidth;
-
- t_int flineno = 0;
-
- fseek(x->x_filed, current_frame, SEEK_SET);
-
- height = 0;
+//char *lineread = (char*) getbytes( BL_MAX_LENGTH );
+ char lineread[BL_MAX_LENGTH];
+ int current_frame = x->frame_pos[(int)(x->frame_inc * (x->frame_no-1))];
+ int i, n, width, newvalue, height, nwidth;
+
+ t_int flineno = 0;
+
+ fseek(x->x_filed, current_frame, SEEK_SET);
+
+ height = 0;
width = 0;
while ( 1 )
{
- if ( fgets( lineread, BL_MAX_LENGTH, x->x_filed ) == NULL )
+ if ( fgets( lineread, BL_MAX_LENGTH, x->x_filed ) == NULL )
{
- post( "blinkenlights : EOF not expected here !!! ");
- blinkenlights_close(x);
- return;
+ post( "blinkenlights : EOF not expected here !!! ");
+ blinkenlights_close(x);
+ return;
}
else
{
- if ( (lineread[0] == '\0') || (lineread[0] == '#') || (lineread[0] == '\n') ) break;
- // post( "blinkenlights : lineread : %s", lineread );
-
- nwidth = strlen( lineread )-1; // because of the carriage return
- flineno++;
- height = flineno;
- if ( ( nwidth != width ) && ( width != 0 ) )
- {
- post( "blinkenlights : weird file : width has changed (nwidth=%d) (width=%d)", nwidth, width );
- blinkenlights_close( x );
- return;
- }
- width = nwidth;
- if ( x->x_frame != NULL )
- {
- t_int pint = 0;
- t_int newvalue;
-
- while ( pint < width )
- {
- newvalue = (int) *(lineread+pint) - 48 /* ascii value for '0' */;
- if ( newvalue != *(x->x_frame+(flineno-1)*x->x_width+pint ) )
- {
- *(x->x_frame+(flineno-1)*x->x_width+pint ) = newvalue;
- switch ( newvalue )
+ if ( (lineread[0] == '\0') || (lineread[0] == '#') || (lineread[0] == '\n') ) break;
+ // post( "blinkenlights : lineread : %s", lineread );
+
+ nwidth = strlen( lineread )-1; // because of the carriage return
+ flineno++;
+ height = flineno;
+ if ( ( nwidth != width ) && ( width != 0 ) )
+ {
+ post( "blinkenlights : weird file : width has changed (nwidth=%d) (width=%d)", nwidth, width );
+ blinkenlights_close( x );
+ return;
+ }
+ width = nwidth;
+ if ( x->x_frame != NULL )
+ {
+ t_int pint = 0;
+ t_int newvalue;
+
+ while ( pint < width )
+ {
+ newvalue = (int) *(lineread+pint) - 48 /* ascii value for '0' */;
+ if ( newvalue != *(x->x_frame+(flineno-1)*x->x_width+pint ) )
{
- case 0:
- // post( "pixoff %d %d", pint+1, flineno );
- blinkenlights_pixoff( x, pint+1, flineno );
- break;
- case 1:
- // post( "pixon %d %d", pint+1, flineno );
- blinkenlights_pixon( x, pint+1, flineno );
- break;
- default:
- // post("blinkenlights : wrong value found for pixel : %d (c=%c)", newvalue, *(lineread+pint) );
- break;
+ *(x->x_frame+(flineno-1)*x->x_width+pint ) = newvalue;
+ switch ( newvalue )
+ {
+ case 0:
+ // post( "pixoff %d %d", pint+1, flineno );
+ blinkenlights_pixoff( x, pint+1, flineno );
+ break;
+ case 1:
+ // post( "pixon %d %d", pint+1, flineno );
+ blinkenlights_pixon( x, pint+1, flineno );
+ break;
+ default:
+ // post("blinkenlights : wrong value found for pixel : %d (c=%c)", newvalue, *(lineread+pint) );
+ break;
+ }
}
- }
- pint++;
- }
- }
- if ( x->x_frame == NULL ) x->x_height++;
+ pint++;
+ }
+ }
+ if ( x->x_frame == NULL ) x->x_height++;
}
}
if ( x->x_frame == NULL )
{
- if ( x->x_filed != NULL ) if ( fseek(x->x_filed, 0L, SEEK_SET) < 0 )
- {
- post( "blinkenlights : could not rewind file" );
- blinkenlights_close( x );
- return;
- }
- blinkenlights_width(x, width);
- blinkenlights_height(x, height);
- x->x_frame = ( t_int* ) getbytes( x->x_width*x->x_height*sizeof(t_int) );
- blinkenlights_readframe(x);
- }
-
+ if ( x->x_filed != NULL ) if ( fseek(x->x_filed, 0L, SEEK_SET) < 0 )
+ {
+ post( "blinkenlights : could not rewind file" );
+ blinkenlights_close( x );
+ return;
+ }
+ blinkenlights_width(x, width);
+ blinkenlights_height(x, height);
+ x->x_frame = ( t_int* ) getbytes( x->x_width*x->x_height*sizeof(t_int) );
+ blinkenlights_readframe(x);
+ }
+
}
static void blinkenlights_frame_pos(t_blinkenlights* x, t_float pos)
{
- if(pos > 1 | pos < 0) post ("dude, don't be crazy!");
- else x->frame_inc = pos;;
- //post("frame %d", x->frame_inc);
+ if(pos > 1 | pos < 0) post ("dude, don't be crazy!");
+ else x->frame_inc = pos;;
+//post("frame %d", x->frame_inc);
}
static void blinkenlights_timer2(t_blinkenlights* x, t_float timer)
{
- x->x_timer2 = timer;
- //post("frame %d", x->frame_inc);
+ x->x_timer2 = timer;
+//post("frame %d", x->frame_inc);
}
- /* open movie */
+/* open movie */
static void blinkenlights_open(t_blinkenlights *x, t_symbol *sfile)
{
- if ( !x->x_ecanvas )
- {
- post("blinkenlights : open : canvas does not exist" );
- return;
- }
-
- //----------------------------------
- /* closing previous file descriptor */
- if ( x->x_filed != NULL ) {
- if(fclose(x->x_filed) < 0)
- {
- perror( "blinkenlights : closing file" );
- }
- x->x_filed = NULL;
- }
- if ( x->x_frame )
- {
- blinkenlights_clear(x);
- }
-
- //--------------------------------
-
- if ( ( x->x_filed = fopen( sfile->s_name, "r" ) ) == NULL )
- {
- error( "blinkenlights : cannot open >%s<", sfile->s_name);
- return;
- }
- post( "blinkenlights : opened >%s<", sfile->s_name);
- // don't read the first frame when open..
- //blinkenlights_readframe(x);
- blinkenlights_findframes(x);
+ if ( !x->x_ecanvas )
+ {
+ post("blinkenlights : open : canvas does not exist" );
+ return;
+ }
+
+ //----------------------------------
+ /* closing previous file descriptor */
+ if ( x->x_filed != NULL )
+ {
+ if(fclose(x->x_filed) < 0)
+ {
+ perror( "blinkenlights : closing file" );
+ }
+ x->x_filed = NULL;
+ }
+ if ( x->x_frame )
+ {
+ blinkenlights_clear(x);
+ }
+
+ //--------------------------------
+
+ if ( ( x->x_filed = fopen( sfile->s_name, "r" ) ) == NULL )
+ {
+ error( "blinkenlights : cannot open >%s<", sfile->s_name);
+ return;
+ }
+ post( "blinkenlights : opened >%s<", sfile->s_name);
+ // don't read the first frame when open..
+ //blinkenlights_readframe(x);
+ blinkenlights_findframes(x);
}
- /* play frames */
+/* play frames */
static void blinkenlights_playframes(t_blinkenlights *x)
{
- blinkenlights_readframe( x );
- clock_delay( x->x_clock, (double)x->x_timer );
+ blinkenlights_readframe( x );
+ clock_delay( x->x_clock, (double)x->x_timer );
}
/* play frames2 */
static void blinkenlights_playframes2(t_blinkenlights *x)
{
- blinkenlights_goto(x);
- clock_delay( x->x_clock2, (double)x->x_timer2 );
+ blinkenlights_goto(x);
+ clock_delay( x->x_clock2, (double)x->x_timer2 );
}
- /* play movie */
+/* play movie */
static void blinkenlights_play(t_blinkenlights *x)
{
- if ( !x->x_ecanvas )
- {
- post("blinkenlights : play : canvas does not exist" );
- return;
- }
-
- if ( x->x_filed == NULL )
- {
- post( "blinkenlights : no file is opened for playing" );
- blinkenlights_close(x);
- return;
- }
-
- if ( x->x_clock == NULL ) x->x_clock = clock_new( x, (t_method)blinkenlights_playframes);
- clock_delay( x->x_clock, (double)x->x_timer );
+ if ( !x->x_ecanvas )
+ {
+ post("blinkenlights : play : canvas does not exist" );
+ return;
+ }
+
+ if ( x->x_filed == NULL )
+ {
+ post( "blinkenlights : no file is opened for playing" );
+ blinkenlights_close(x);
+ return;
+ }
+
+ if ( x->x_clock == NULL ) x->x_clock = clock_new( x, (t_method)blinkenlights_playframes);
+ clock_delay( x->x_clock, (double)x->x_timer );
}
- /* vj movie */
+/* vj movie */
static void blinkenlights_vj(t_blinkenlights *x, t_float start_vj)
{
- if ( !x->x_ecanvas )
- {
- post("blinkenlights : play : canvas does not exist" );
- return;
- }
-
- if ( x->x_filed == NULL )
- {
- post( "blinkenlights : no file is opened for playing" );
- blinkenlights_close(x);
- return;
- }
-
- if(start_vj)
- {
- if ( x->x_clock2 == NULL ) x->x_clock2 = clock_new( x, (t_method)blinkenlights_playframes2);
- clock_delay( x->x_clock2, (double)x->x_timer2 );
- }
- else
- {
- clock_unset( x->x_clock2 );
- }
+ if ( !x->x_ecanvas )
+ {
+ post("blinkenlights : play : canvas does not exist" );
+ return;
+ }
+
+ if ( x->x_filed == NULL )
+ {
+ post( "blinkenlights : no file is opened for playing" );
+ blinkenlights_close(x);
+ return;
+ }
+
+ if(start_vj)
+ {
+ if ( x->x_clock2 == NULL ) x->x_clock2 = clock_new( x, (t_method)blinkenlights_playframes2);
+ clock_delay( x->x_clock2, (double)x->x_timer2 );
+ }
+ else
+ {
+ clock_unset( x->x_clock2 );
+ }
}
- /* stop movie */
+/* stop movie */
static void blinkenlights_stop(t_blinkenlights *x)
{
- if ( !x->x_ecanvas )
- {
- post("blinkenlights : play : canvas does not exist" );
- return;
- }
-
- if ( x->x_filed == NULL )
- {
- post( "blinkenlights : no file is opened for playing" );
- blinkenlights_close(x);
- return;
- }
-
- if ( x->x_clock != NULL )
- {
- clock_unset( x->x_clock );
- }
+ if ( !x->x_ecanvas )
+ {
+ post("blinkenlights : play : canvas does not exist" );
+ return;
+ }
+
+ if ( x->x_filed == NULL )
+ {
+ post( "blinkenlights : no file is opened for playing" );
+ blinkenlights_close(x);
+ return;
+ }
+
+ if ( x->x_clock != NULL )
+ {
+ clock_unset( x->x_clock );
+ }
}
- /* jump to next frame */
+/* jump to next frame */
static void blinkenlights_next(t_blinkenlights *x)
{
- blinkenlights_readframe(x);
+ blinkenlights_readframe(x);
}
void blinkenlights_setup(void)
{
- verbose(0, blinkenlights_version);
- blinkenlights_class = class_new(gensym("blinkenlights"), (t_newmethod)blinkenlights_new,
- (t_method)blinkenlights_free,
- sizeof(t_blinkenlights), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_width, gensym("width"), A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_height, gensym("height"), A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_xsize, gensym("xsize"), A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_ysize, gensym("ysize"), A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_open, gensym("open"), A_SYMBOL, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_create, gensym("create"), 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_destroy, gensym("destroy"), 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_next, gensym("next"), 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_play, gensym("play"), 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_stop, gensym("stop"), 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_frame_pos, gensym("goto"), A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_vj, gensym("vj"), A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_timer2, gensym("timer2"), A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_background, gensym("background"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_foreground, gensym("foreground"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_destroy, gensym("destroy"), 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_pixon, gensym("pixon"), A_FLOAT, A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_pixoff, gensym("pixoff"), A_FLOAT, A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_pixel, gensym("pixel"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
- class_addmethod( blinkenlights_class, (t_method)blinkenlights_clear, gensym("clear"), 0);
+ verbose(0, blinkenlights_version);
+ blinkenlights_class = class_new(gensym("blinkenlights"), (t_newmethod)blinkenlights_new,
+ (t_method)blinkenlights_free,
+ sizeof(t_blinkenlights), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_width, gensym("width"), A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_height, gensym("height"), A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_xsize, gensym("xsize"), A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_ysize, gensym("ysize"), A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_open, gensym("open"), A_SYMBOL, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_create, gensym("create"), 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_destroy, gensym("destroy"), 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_next, gensym("next"), 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_play, gensym("play"), 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_stop, gensym("stop"), 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_frame_pos, gensym("goto"), A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_vj, gensym("vj"), A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_timer2, gensym("timer2"), A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_background, gensym("background"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_foreground, gensym("foreground"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_destroy, gensym("destroy"), 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_pixon, gensym("pixon"), A_FLOAT, A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_pixoff, gensym("pixoff"), A_FLOAT, A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_pixel, gensym("pixel"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ class_addmethod( blinkenlights_class, (t_method)blinkenlights_clear, gensym("clear"), 0);
}
diff --git a/compressor~.c b/compressor~.c
index 4fef61c..f2dc545 100644
--- a/compressor~.c
+++ b/compressor~.c
@@ -47,17 +47,17 @@ static t_class *compressor_class;
static void compressor_strength(t_compressor *x, t_floatarg fstrength )
{
- if (fstrength < -1.0)
+ if (fstrength < -1.0)
{
- x->x_strength = -1.0;
+ x->x_strength = -1.0;
}
- else if (fstrength > 5)
+ else if (fstrength > 5)
{
- x->x_strength = 5;
+ x->x_strength = 5;
}
else
{
- x->x_strength = fstrength;
+ x->x_strength = fstrength;
}
x->x_pifactor = pow( M_PI, x->x_strength );
}
@@ -81,9 +81,11 @@ static t_int *compressor_perform(t_int *w)
t_float isample_fact = x->x_pifactor;
t_float osample_fact = 2.0 / M_PI;
- while (n--) {
- *out = atan (*in * isample_fact) * osample_fact;
- out++; in++;
+ while (n--)
+ {
+ *out = atan (*in * isample_fact) * osample_fact;
+ out++;
+ in++;
}
return (w+5);
}
@@ -97,7 +99,7 @@ void compressor_tilde_setup(void)
{
verbose(0, compressor_version );
compressor_class = class_new(gensym("compressor~"), (t_newmethod)compressor_new, 0,
- sizeof(t_compressor), 0, 0);
+ sizeof(t_compressor), 0, 0);
CLASS_MAINSIGNALIN( compressor_class, t_compressor, x_f );
class_addmethod(compressor_class, (t_method)compressor_dsp, gensym("dsp"), 0);
class_addmethod(compressor_class, (t_method)compressor_strength, gensym("strength"), A_FLOAT, 0);
diff --git a/cooled~.c b/cooled~.c
index 136018c..3f43b1a 100644
--- a/cooled~.c
+++ b/cooled~.c
@@ -142,7 +142,7 @@ typedef struct _cooled
char* x_guicommand; /* buffer to store gui command */
int x_draw; /* drawing option */
- /* graphical data block */
+ /* graphical data block */
int x_width; /* graphical width */
int x_height; /* graphical height */
int x_selected; /* flag to remember if we are seleted or not */
@@ -178,362 +178,365 @@ static void cooled_update_block(t_cooled *x, t_glist *glist, int bnumber)
// update cooled~
for ( hi=x->x_height-1; hi>=0; hi-- )
{
- if ( ( hi == x->x_height/4) || ( hi == 3*x->x_height/4) )
- {
- sprintf( color, "%s ", COOLED_FGCOLOR );
- }
- else if ( hi == x->x_height/2)
- {
- sprintf( color, "%s ", COOLED_FRCOLOR );
- }
- else
- {
- sprintf( color, "%s ", COOLED_BGCOLOR );
- }
- for ( i=0; i<x->x_zoom; i++ )
- {
- strncpy( x->x_gifdata+(hi*x->x_zoom+i)*8, color, 8 );
- }
+ if ( ( hi == x->x_height/4) || ( hi == 3*x->x_height/4) )
+ {
+ sprintf( color, "%s ", COOLED_FGCOLOR );
+ }
+ else if ( hi == x->x_height/2)
+ {
+ sprintf( color, "%s ", COOLED_FRCOLOR );
+ }
+ else
+ {
+ sprintf( color, "%s ", COOLED_BGCOLOR );
+ }
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ strncpy( x->x_gifdata+(hi*x->x_zoom+i)*8, color, 8 );
+ }
}
// set all points
{
- int fsamp = ( bnumber * x->x_size ) / x->x_width;
- int lsamp = ( ( bnumber+1) * x->x_size ) / x->x_width;
- int si;
+ int fsamp = ( bnumber * x->x_size ) / x->x_width;
+ int lsamp = ( ( bnumber+1) * x->x_size ) / x->x_width;
+ int si;
- // post ( "cooled~ : updating samples [%d,%d]", fsamp, lsamp );
+ // post ( "cooled~ : updating samples [%d,%d]", fsamp, lsamp );
- for ( si=fsamp;si<lsamp; si++ )
- {
- // calculate right channel index
- {
- int rind = 3*x->x_height/4 + ( *(x->x_rdata+si) * (x->x_height/4) ) - 1;
+ for ( si=fsamp; si<lsamp; si++ )
+ {
+ // calculate right channel index
+ {
+ int rind = 3*x->x_height/4 + ( *(x->x_rdata+si) * (x->x_height/4) ) - 1;
- if ( rind > x->x_height - 1 ) rind = x->x_height - 1;
- if ( rind < x->x_height/2 ) rind = x->x_height/2;
+ if ( rind > x->x_height - 1 ) rind = x->x_height - 1;
+ if ( rind < x->x_height/2 ) rind = x->x_height/2;
- sprintf( color, "%s ", COOLED_FGCOLOR );
- for ( i=0; i<x->x_zoom; i++ )
- {
- strncpy( x->x_gifdata+(rind*x->x_zoom+i)*8, color, 8 );
+ sprintf( color, "%s ", COOLED_FGCOLOR );
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ strncpy( x->x_gifdata+(rind*x->x_zoom+i)*8, color, 8 );
+ }
}
- }
- // calculate left channel index
- {
- int lind = x->x_height/4 + ( *(x->x_ldata+si) * (x->x_height/4) ) - 1;
+ // calculate left channel index
+ {
+ int lind = x->x_height/4 + ( *(x->x_ldata+si) * (x->x_height/4) ) - 1;
- if ( lind > x->x_height/2 - 1 ) lind = x->x_height/2 - 1;
- if ( lind < 0 ) lind = 0;
+ if ( lind > x->x_height/2 - 1 ) lind = x->x_height/2 - 1;
+ if ( lind < 0 ) lind = 0;
- sprintf( color, "%s ", COOLED_FGCOLOR );
- for ( i=0; i<x->x_zoom; i++ )
- {
- strncpy( x->x_gifdata+(lind*x->x_zoom+i)*8, color, 8 );
+ sprintf( color, "%s ", COOLED_FGCOLOR );
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ strncpy( x->x_gifdata+(lind*x->x_zoom+i)*8, color, 8 );
+ }
}
- }
- }
+ }
}
for ( i=0; i<x->x_zoom; i++ )
{
sprintf( x->x_guicommand, "COOLEDIMAGE%x put {%s} -to %d 0\n", x, x->x_gifdata, (bnumber*x->x_zoom)+i );
if ( glist_isvisible( x->x_glist ) )
- sys_gui( x->x_guicommand );
+ sys_gui( x->x_guicommand );
}
}
static void cooled_erase_block(t_cooled *x, t_glist *glist, int sample )
{
- t_canvas *canvas=glist_getcanvas(glist);
- int hi;
- t_float fspectrum=0.0;
- char fillColor[ 16 ];
+ t_canvas *canvas=glist_getcanvas(glist);
+ int hi;
+ t_float fspectrum=0.0;
+ char fillColor[ 16 ];
- for ( hi=0; hi<x->x_height; hi++)
- {
+ for ( hi=0; hi<x->x_height; hi++)
+ {
{
- int i;
+ int i;
- for ( i=0; i<x->x_zoom; i++ )
- {
+ for ( i=0; i<x->x_zoom; i++ )
+ {
strcpy( x->x_gifdata+i*sizeof("#FFFFFF "), strcat( COOLED_BGCOLOR, " ") );
- }
- if ( glist_isvisible( x->x_glist ) )
- SYS_VGUI5("COOLEDIMAGE%x put {%s} -to %d %d\n", x, x->x_gifdata,
- sample*x->x_zoom, (x->x_height-hi)*x->x_zoom );
+ }
+ if ( glist_isvisible( x->x_glist ) )
+ SYS_VGUI5("COOLEDIMAGE%x put {%s} -to %d %d\n", x, x->x_gifdata,
+ sample*x->x_zoom, (x->x_height-hi)*x->x_zoom );
}
- }
+ }
}
static void *cooled_do_update_part(void *tdata)
{
- t_cooled *x = (t_cooled*) tdata;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
- int si;
- int nbpoints = 0;
- t_float percentage = 0, opercentage = 0;
-
- // loose synchro
- usleep( THREAD_SLEEP_TIME );
-
- // check bounds
- if ( x->x_updateend > x->x_size-1 ) x->x_updateend = x->x_size-1;
- if ( x->x_updatestart < 0 ) x->x_updatestart = 0;
-
- post("cooled~ : ok, let's go [updating %d, %d]", x->x_updatestart, x->x_updateend );
-
- if ( x->x_erase )
- {
- for ( si=x->x_updatestart; si<=x->x_updateend; si++ )
- {
- cooled_erase_block(x, x->x_glist, si);
- nbpoints++;
- percentage = (nbpoints*100/(x->x_updateend-x->x_updatestart+1));
- if ( (percentage == (int) percentage) && ((int)percentage%5 == 0) && ( percentage != opercentage ) )
- {
- // post( "cooled~ : erase part : %d %% completed", (int)percentage );
- opercentage = percentage;
- }
- }
- }
-
- percentage = opercentage = nbpoints = 0;
-
- if ( x->x_redraw )
- {
- for ( si=x->x_updatestart; si<=x->x_updateend; si++ )
- {
- cooled_update_block(x, x->x_glist, si);
- nbpoints++;
- percentage = (nbpoints*100/(x->x_updateend-x->x_updatestart+1));
- if ( (percentage == (int) percentage) && ((int)percentage%5 == 0) && ( percentage != opercentage ) )
- {
- // post( "cooled~ : update part : %d %% completed", (int)percentage );
- opercentage = percentage;
- }
- }
- }
-
- if ( glist_isvisible( x->x_glist ) )
- {
- SYS_VGUI3( ".x%lx.c delete rectangle %xCLIPZONE\n",
- canvas, x);
- if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
- {
- SYS_VGUI7( ".x%lx.c create rectangle %d %d %d %d -outline #FF0000 -tags %xCLIPZONE -width 2\n",
- canvas, x->x_xpos+(int)(x->x_readstart*(x->x_width)/100 ),
- x->x_ypos, x->x_xpos+(int)(x->x_readend*(x->x_width)/100 ),
- x->x_ypos+x->x_height*x->x_zoom, x );
- }
- // set borders in black
- SYS_VGUI3(".x%lx.c itemconfigure %xCOOLED -outline #000000\n", canvas, x);
- }
+ t_cooled *x = (t_cooled*) tdata;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+ int si;
+ int nbpoints = 0;
+ t_float percentage = 0, opercentage = 0;
+
+ // loose synchro
+ usleep( THREAD_SLEEP_TIME );
+
+ // check bounds
+ if ( x->x_updateend > x->x_size-1 ) x->x_updateend = x->x_size-1;
+ if ( x->x_updatestart < 0 ) x->x_updatestart = 0;
+
+ post("cooled~ : ok, let's go [updating %d, %d]", x->x_updatestart, x->x_updateend );
+
+ if ( x->x_erase )
+ {
+ for ( si=x->x_updatestart; si<=x->x_updateend; si++ )
+ {
+ cooled_erase_block(x, x->x_glist, si);
+ nbpoints++;
+ percentage = (nbpoints*100/(x->x_updateend-x->x_updatestart+1));
+ if ( (percentage == (int) percentage) && ((int)percentage%5 == 0) && ( percentage != opercentage ) )
+ {
+ // post( "cooled~ : erase part : %d %% completed", (int)percentage );
+ opercentage = percentage;
+ }
+ }
+ }
+
+ percentage = opercentage = nbpoints = 0;
+
+ if ( x->x_redraw )
+ {
+ for ( si=x->x_updatestart; si<=x->x_updateend; si++ )
+ {
+ cooled_update_block(x, x->x_glist, si);
+ nbpoints++;
+ percentage = (nbpoints*100/(x->x_updateend-x->x_updatestart+1));
+ if ( (percentage == (int) percentage) && ((int)percentage%5 == 0) && ( percentage != opercentage ) )
+ {
+ // post( "cooled~ : update part : %d %% completed", (int)percentage );
+ opercentage = percentage;
+ }
+ }
+ }
+
+ if ( glist_isvisible( x->x_glist ) )
+ {
+ SYS_VGUI3( ".x%lx.c delete rectangle %xCLIPZONE\n",
+ canvas, x);
+ if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
+ {
+ SYS_VGUI7( ".x%lx.c create rectangle %d %d %d %d -outline #FF0000 -tags %xCLIPZONE -width 2\n",
+ canvas, x->x_xpos+(int)(x->x_readstart*(x->x_width)/100 ),
+ x->x_ypos, x->x_xpos+(int)(x->x_readend*(x->x_width)/100 ),
+ x->x_ypos+x->x_height*x->x_zoom, x );
+ }
+ // set borders in black
+ SYS_VGUI3(".x%lx.c itemconfigure %xCOOLED -outline #000000\n", canvas, x);
+ }
#ifndef _WIN32
- post("cooled~ : child thread %d ended", (int)x->x_updatechild );
- x->x_updatechild = NULL;
+ post("cooled~ : child thread %d ended", (int)x->x_updatechild );
+ x->x_updatechild = NULL;
#endif
- return NULL;
+ return NULL;
}
-static void cooled_update_part(t_cooled *x, t_glist *glist, int bstart, int bend,
- int erase, int redraw, int keepframe)
+static void cooled_update_part(t_cooled *x, t_glist *glist, int bstart, int bend,
+ int erase, int redraw, int keepframe)
{
- pthread_attr_t update_child_attr;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ pthread_attr_t update_child_attr;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
#ifndef _WIN32
if ( x->x_updatechild != 0 )
{
- // post( "cooled~ : error : no update is possible for now" );
- return;
+ // post( "cooled~ : error : no update is possible for now" );
+ return;
}
#endif
x->x_updatestart = bstart;
x->x_updateend = bend;
- if ( !keepframe )
+ if ( !keepframe )
{
- x->x_erase = 0;
+ x->x_erase = 0;
}
else
{
- x->x_erase = erase;
+ x->x_erase = erase;
}
x->x_redraw = redraw;
// recreate the square if needed
if ( glist_isvisible( x->x_glist ) )
{
- if ( ( bstart == 0 ) && ( bend == x->x_width-1 ) && !keepframe )
- {
- SYS_VGUI3(".x%lx.c delete %xCOOLEDL\n", canvas, x );
- SYS_VGUI3(".x%lx.c delete %xCOOLEDR\n", canvas, x );
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xCOOLEDR\n",
- canvas, x->x_xpos, x->x_ypos,
- x->x_xpos + x->x_width*x->x_zoom,
- x->x_ypos + x->x_height/2*x->x_zoom,
- x);
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xCOOLEDL\n",
- canvas, x->x_xpos,
- x->x_ypos + x->x_height/2*x->x_zoom,
- x->x_xpos + x->x_width*x->x_zoom,
- x->x_ypos + x->x_height*x->x_zoom,
- x);
- SYS_VGUI2("image delete COOLEDIMAGE%x\n", x );
- SYS_VGUI3(".x%lx.c delete ICOOLEDIMAGE%x\n", canvas, x );
- SYS_VGUI4("image create photo COOLEDIMAGE%x -format gif -width %d -height %d\n",
- x, x->x_width*x->x_zoom, x->x_height*x->x_zoom );
- SYS_VGUI2("COOLEDIMAGE%x blank\n", x );
- SYS_VGUI6(".x%lx.c create image %d %d -image COOLEDIMAGE%x -tags ICOOLEDIMAGE%x\n",
- canvas,
- x->x_xpos+(x->x_width*x->x_zoom)/2,
- x->x_ypos+(x->x_height*x->x_zoom)/2, x, x );
- canvas_fixlinesfor( canvas, (t_text*)x );
- }
- // set borders in red
- SYS_VGUI3(".x%lx.c itemconfigure %xCOOLED -outline #FF0000\n", canvas, x);
+ if ( ( bstart == 0 ) && ( bend == x->x_width-1 ) && !keepframe )
+ {
+ SYS_VGUI3(".x%lx.c delete %xCOOLEDL\n", canvas, x );
+ SYS_VGUI3(".x%lx.c delete %xCOOLEDR\n", canvas, x );
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xCOOLEDR\n",
+ canvas, x->x_xpos, x->x_ypos,
+ x->x_xpos + x->x_width*x->x_zoom,
+ x->x_ypos + x->x_height/2*x->x_zoom,
+ x);
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xCOOLEDL\n",
+ canvas, x->x_xpos,
+ x->x_ypos + x->x_height/2*x->x_zoom,
+ x->x_xpos + x->x_width*x->x_zoom,
+ x->x_ypos + x->x_height*x->x_zoom,
+ x);
+ SYS_VGUI2("image delete COOLEDIMAGE%x\n", x );
+ SYS_VGUI3(".x%lx.c delete ICOOLEDIMAGE%x\n", canvas, x );
+ SYS_VGUI4("image create photo COOLEDIMAGE%x -format gif -width %d -height %d\n",
+ x, x->x_width*x->x_zoom, x->x_height*x->x_zoom );
+ SYS_VGUI2("COOLEDIMAGE%x blank\n", x );
+ SYS_VGUI6(".x%lx.c create image %d %d -image COOLEDIMAGE%x -tags ICOOLEDIMAGE%x\n",
+ canvas,
+ x->x_xpos+(x->x_width*x->x_zoom)/2,
+ x->x_ypos+(x->x_height*x->x_zoom)/2, x, x );
+ canvas_fixlinesfor( canvas, (t_text*)x );
+ }
+ // set borders in red
+ SYS_VGUI3(".x%lx.c itemconfigure %xCOOLED -outline #FF0000\n", canvas, x);
}
// launch update thread
- if ( pthread_attr_init( &update_child_attr ) < 0 ) {
- post( "cooled~ : could not launch update thread" );
- perror( "pthread_attr_init" );
- return;
+ if ( pthread_attr_init( &update_child_attr ) < 0 )
+ {
+ post( "cooled~ : could not launch update thread" );
+ perror( "pthread_attr_init" );
+ return;
}
- if ( pthread_attr_setdetachstate( &update_child_attr, PTHREAD_CREATE_DETACHED ) < 0 ) {
- post( "cooled~ : could not launch update thread" );
- perror( "pthread_attr_setdetachstate" );
- return;
+ if ( pthread_attr_setdetachstate( &update_child_attr, PTHREAD_CREATE_DETACHED ) < 0 )
+ {
+ post( "cooled~ : could not launch update thread" );
+ perror( "pthread_attr_setdetachstate" );
+ return;
}
- if ( pthread_create( &x->x_updatechild, &update_child_attr, cooled_do_update_part, x ) < 0 ) {
- post( "cooled~ : could not launch update thread" );
- perror( "pthread_create" );
- return;
+ if ( pthread_create( &x->x_updatechild, &update_child_attr, cooled_do_update_part, x ) < 0 )
+ {
+ post( "cooled~ : could not launch update thread" );
+ perror( "pthread_create" );
+ return;
}
- else
+ else
{
- // post( "cooled~ : drawing thread %d launched", (int)x->x_updatechild );
+ // post( "cooled~ : drawing thread %d launched", (int)x->x_updatechild );
}
}
-
+
static void cooled_draw_new(t_cooled *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
-
- x->x_xpos=text_xpix(&x->x_obj, glist);
- x->x_ypos=text_ypix(&x->x_obj, glist);
- x->x_xdraw=text_xpix(&x->x_obj, glist);
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xCOOLEDR\n",
- canvas, x->x_xpos, x->x_ypos,
- x->x_xpos + x->x_width*x->x_zoom,
- x->x_ypos + x->x_height/2*x->x_zoom,
- x);
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xCOOLEDL\n",
- canvas, x->x_xpos,
- x->x_ypos + x->x_height/2*x->x_zoom,
- x->x_xpos + x->x_width*x->x_zoom,
- x->x_ypos + x->x_height*x->x_zoom,
- x);
- SYS_VGUI4("image create photo COOLEDIMAGE%x -format gif -width %d -height %d\n",
- x, x->x_width*x->x_zoom, x->x_height*x->x_zoom );
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ x->x_xpos=text_xpix(&x->x_obj, glist);
+ x->x_ypos=text_ypix(&x->x_obj, glist);
+ x->x_xdraw=text_xpix(&x->x_obj, glist);
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xCOOLEDR\n",
+ canvas, x->x_xpos, x->x_ypos,
+ x->x_xpos + x->x_width*x->x_zoom,
+ x->x_ypos + x->x_height/2*x->x_zoom,
+ x);
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xCOOLEDL\n",
+ canvas, x->x_xpos,
+ x->x_ypos + x->x_height/2*x->x_zoom,
+ x->x_xpos + x->x_width*x->x_zoom,
+ x->x_ypos + x->x_height*x->x_zoom,
+ x);
+ SYS_VGUI4("image create photo COOLEDIMAGE%x -format gif -width %d -height %d\n",
+ x, x->x_width*x->x_zoom, x->x_height*x->x_zoom );
SYS_VGUI2("COOLEDIMAGE%x blank\n", x );
- SYS_VGUI6(".x%lx.c create image %d %d -image COOLEDIMAGE%x -tags ICOOLEDIMAGE%x\n",
- canvas,
- x->x_xpos+(x->x_width*x->x_zoom)/2,
- x->x_ypos+(x->x_height*x->x_zoom)/2, x, x );
+ SYS_VGUI6(".x%lx.c create image %d %d -image COOLEDIMAGE%x -tags ICOOLEDIMAGE%x\n",
+ canvas,
+ x->x_xpos+(x->x_width*x->x_zoom)/2,
+ x->x_ypos+(x->x_height*x->x_zoom)/2, x, x );
if ( x->x_draw) cooled_update_part(x, x->x_glist, 0, x->x_width-1, 0, 1, 0);
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void cooled_draw_delete(t_cooled *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
if ( glist_isvisible( glist ) )
{
- SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
- if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
- {
- SYS_VGUI3( ".x%lx.c delete rectangle %xCLIPZONE\n", canvas, x);
- }
- SYS_VGUI3( ".x%lx.c delete line %xINSERTHERE\n", canvas, x);
- SYS_VGUI3(".x%lx.c delete %xCOOLEDR\n", canvas, x );
- SYS_VGUI3(".x%lx.c delete %xCOOLEDL\n", canvas, x );
- SYS_VGUI3(".x%lx.c delete ICOOLEDIMAGE%x\n", canvas, x );
- SYS_VGUI2("image delete COOLEDIMAGE%x\n", x );
+ SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
+ if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
+ {
+ SYS_VGUI3( ".x%lx.c delete rectangle %xCLIPZONE\n", canvas, x);
+ }
+ SYS_VGUI3( ".x%lx.c delete line %xINSERTHERE\n", canvas, x);
+ SYS_VGUI3(".x%lx.c delete %xCOOLEDR\n", canvas, x );
+ SYS_VGUI3(".x%lx.c delete %xCOOLEDL\n", canvas, x );
+ SYS_VGUI3(".x%lx.c delete ICOOLEDIMAGE%x\n", canvas, x );
+ SYS_VGUI2("image delete COOLEDIMAGE%x\n", x );
}
}
static void cooled_draw_move(t_cooled *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
-
- if ( glist_isvisible( x->x_glist ) )
- {
- SYS_VGUI7(".x%lx.c coords %xCOOLEDR %d %d %d %d\n",
- canvas, x,
- x->x_xpos, x->x_ypos,
- x->x_xpos + x->x_width*x->x_zoom,
- x->x_ypos + x->x_height/2*x->x_zoom);
- SYS_VGUI7(".x%lx.c coords %xCOOLEDL %d %d %d %d\n",
- canvas, x,
- x->x_xpos,
- x->x_ypos + x->x_height/2*x->x_zoom,
- x->x_xpos + x->x_width*x->x_zoom,
- x->x_ypos + x->x_height*x->x_zoom );
- if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
- {
- SYS_VGUI7(".x%lx.c coords %xCLIPZONE %d %d %d %d\n",
- canvas, x,
- x->x_xpos+(int)(x->x_readstart*(x->x_width)/100*x->x_zoom ),
- x->x_ypos,
- x->x_xpos+(int)(x->x_readend*(x->x_width)/100*x->x_zoom ),
- x->x_ypos+x->x_height*x->x_zoom );
- }
- SYS_VGUI7(".x%lx.c coords %xINSERTHERE %d %d %d %d\n",
- canvas, x,
- x->x_xdraw,
- x->x_ypos,
- x->x_xdraw,
- x->x_ypos+x->x_height*x->x_zoom );
- SYS_VGUI5(".x%lx.c coords ICOOLEDIMAGE%x %d %d\n",
- canvas, x,
- x->x_xpos+((x->x_width*x->x_zoom)/2),
- (x->x_ypos+((x->x_height*x->x_zoom)/2)) );
- canvas_fixlinesfor( canvas, (t_text*)x );
- }
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ if ( glist_isvisible( x->x_glist ) )
+ {
+ SYS_VGUI7(".x%lx.c coords %xCOOLEDR %d %d %d %d\n",
+ canvas, x,
+ x->x_xpos, x->x_ypos,
+ x->x_xpos + x->x_width*x->x_zoom,
+ x->x_ypos + x->x_height/2*x->x_zoom);
+ SYS_VGUI7(".x%lx.c coords %xCOOLEDL %d %d %d %d\n",
+ canvas, x,
+ x->x_xpos,
+ x->x_ypos + x->x_height/2*x->x_zoom,
+ x->x_xpos + x->x_width*x->x_zoom,
+ x->x_ypos + x->x_height*x->x_zoom );
+ if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
+ {
+ SYS_VGUI7(".x%lx.c coords %xCLIPZONE %d %d %d %d\n",
+ canvas, x,
+ x->x_xpos+(int)(x->x_readstart*(x->x_width)/100*x->x_zoom ),
+ x->x_ypos,
+ x->x_xpos+(int)(x->x_readend*(x->x_width)/100*x->x_zoom ),
+ x->x_ypos+x->x_height*x->x_zoom );
+ }
+ SYS_VGUI7(".x%lx.c coords %xINSERTHERE %d %d %d %d\n",
+ canvas, x,
+ x->x_xdraw,
+ x->x_ypos,
+ x->x_xdraw,
+ x->x_ypos+x->x_height*x->x_zoom );
+ SYS_VGUI5(".x%lx.c coords ICOOLEDIMAGE%x %d %d\n",
+ canvas, x,
+ x->x_xpos+((x->x_width*x->x_zoom)/2),
+ (x->x_ypos+((x->x_height*x->x_zoom)/2)) );
+ canvas_fixlinesfor( canvas, (t_text*)x );
+ }
}
static void cooled_draw_select(t_cooled* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
- if ( glist_isvisible( x->x_glist ) )
- {
- if(x->x_selected)
- {
- /* sets the item in blue */
- SYS_VGUI3(".x%lx.c itemconfigure %xCOOLEDR -outline #0000FF\n", canvas, x);
- SYS_VGUI3(".x%lx.c itemconfigure %xCOOLEDL -outline #0000FF\n", canvas, x);
- }
- else
+ if ( glist_isvisible( x->x_glist ) )
{
- SYS_VGUI3(".x%lx.c itemconfigure %xCOOLEDR -outline #000000\n", canvas, x);
- SYS_VGUI3(".x%lx.c itemconfigure %xCOOLEDL -outline #000000\n", canvas, x);
+ if(x->x_selected)
+ {
+ /* sets the item in blue */
+ SYS_VGUI3(".x%lx.c itemconfigure %xCOOLEDR -outline #0000FF\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xCOOLEDL -outline #0000FF\n", canvas, x);
+ }
+ else
+ {
+ SYS_VGUI3(".x%lx.c itemconfigure %xCOOLEDR -outline #000000\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xCOOLEDL -outline #000000\n", canvas, x);
+ }
}
- }
}
/* ------------------------ widget callbacks ----------------------------- */
- /* setting the starting point for reading ( in percent ) */
+/* setting the starting point for reading ( in percent ) */
static void cooled_readstart(t_cooled *x, t_floatarg fstart)
{
- t_float startpoint = fstart;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_float startpoint = fstart;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
if (startpoint < 0) startpoint = 0;
if (startpoint > 100) startpoint = 100;
@@ -543,24 +546,24 @@ static void cooled_readstart(t_cooled *x, t_floatarg fstart)
if ( ( x->x_readstart < x->x_readend ) && ( x->x_readspeed < 0 ) ) x->x_readspeed = -x->x_readspeed;
if ( glist_isvisible( x->x_glist ) )
{
- SYS_VGUI3( ".x%lx.c delete rectangle %xCLIPZONE\n",
+ SYS_VGUI3( ".x%lx.c delete rectangle %xCLIPZONE\n",
canvas, x);
- if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
- {
- SYS_VGUI7( ".x%lx.c create rectangle %d %d %d %d -outline #FF0000 -tags %xCLIPZONE -width 2\n",
- canvas, x->x_xpos+(int)(x->x_readstart*x->x_width*x->x_zoom/100 ),
- x->x_ypos, x->x_xpos+(int)(x->x_readend*x->x_width*x->x_zoom/100 ),
- x->x_ypos+x->x_height*x->x_zoom, x );
- }
+ if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
+ {
+ SYS_VGUI7( ".x%lx.c create rectangle %d %d %d %d -outline #FF0000 -tags %xCLIPZONE -width 2\n",
+ canvas, x->x_xpos+(int)(x->x_readstart*x->x_width*x->x_zoom/100 ),
+ x->x_ypos, x->x_xpos+(int)(x->x_readend*x->x_width*x->x_zoom/100 ),
+ x->x_ypos+x->x_height*x->x_zoom, x );
+ }
}
outlet_float( x->x_sampstart, (x->x_readstart*x->x_size)/100 );
}
- /* setting the ending point for reading ( in percent ) */
+/* setting the ending point for reading ( in percent ) */
static void cooled_readend(t_cooled *x, t_floatarg fend)
{
- t_float endpoint = fend;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_float endpoint = fend;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
if (endpoint < 0) endpoint = 0;
if (endpoint > 100) endpoint = 100;
@@ -570,64 +573,64 @@ static void cooled_readend(t_cooled *x, t_floatarg fend)
if ( ( x->x_readstart < x->x_readend ) && ( x->x_readspeed < 0 ) ) x->x_readspeed = -x->x_readspeed;
if ( glist_isvisible( x->x_glist ) )
{
- SYS_VGUI3( ".x%lx.c delete rectangle %xCLIPZONE\n",
+ SYS_VGUI3( ".x%lx.c delete rectangle %xCLIPZONE\n",
canvas, x);
- if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
- {
- SYS_VGUI7( ".x%lx.c create rectangle %d %d %d %d -outline #FF0000 -tags %xCLIPZONE -width 2\n",
- canvas,
- x->x_xpos+(int)(x->x_readstart*x->x_width*x->x_zoom/100 ),
- x->x_ypos, x->x_xpos+(int)(x->x_readend*x->x_width*x->x_zoom/100 ),
- x->x_ypos+x->x_height*x->x_zoom, x );
- }
+ if ( ( x->x_readstart != 0 ) || ( x->x_readend != 100 ) )
+ {
+ SYS_VGUI7( ".x%lx.c create rectangle %d %d %d %d -outline #FF0000 -tags %xCLIPZONE -width 2\n",
+ canvas,
+ x->x_xpos+(int)(x->x_readstart*x->x_width*x->x_zoom/100 ),
+ x->x_ypos, x->x_xpos+(int)(x->x_readend*x->x_width*x->x_zoom/100 ),
+ x->x_ypos+x->x_height*x->x_zoom, x );
+ }
}
outlet_float( x->x_sampend, (x->x_readend*x->x_size)/100 );
}
static void cooled_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_cooled* x = (t_cooled*)z;
+ t_cooled* x = (t_cooled*)z;
- *xp1 = x->x_xpos;
- *yp1 = x->x_ypos;
- *xp2 = x->x_xpos+x->x_width*x->x_zoom;
- *yp2 = x->x_ypos+x->x_height*x->x_zoom+1;
+ *xp1 = x->x_xpos;
+ *yp1 = x->x_ypos;
+ *xp2 = x->x_xpos+x->x_width*x->x_zoom;
+ *yp2 = x->x_ypos+x->x_height*x->x_zoom+1;
}
static void cooled_save(t_gobj *z, t_binbuf *b)
{
- t_cooled *x = (t_cooled *)z;
+ t_cooled *x = (t_cooled *)z;
- binbuf_addv(b, "ssiisiiii", gensym("#X"),gensym("obj"),
- (int)x->x_obj.te_xpix, (int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_size, x->x_width, x->x_height, x->x_draw );
- binbuf_addv(b, ";");
+ binbuf_addv(b, "ssiisiiii", gensym("#X"),gensym("obj"),
+ (int)x->x_obj.te_xpix, (int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_size, x->x_width, x->x_height, x->x_draw );
+ binbuf_addv(b, ";");
}
static void cooled_select(t_gobj *z, t_glist *glist, int selected)
{
- t_cooled *x = (t_cooled *)z;
+ t_cooled *x = (t_cooled *)z;
- x->x_selected = selected;
- cooled_draw_select( x, glist );
+ x->x_selected = selected;
+ cooled_draw_select( x, glist );
}
static void cooled_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_cooled *x = (t_cooled *)z;
- t_rtext *y;
-
- if (vis)
- {
- cooled_draw_new( x, glist );
- }
- else
- {
- // erase all points
- cooled_draw_delete( x, glist );
- }
+ t_cooled *x = (t_cooled *)z;
+ t_rtext *y;
+
+ if (vis)
+ {
+ cooled_draw_new( x, glist );
+ }
+ else
+ {
+ // erase all points
+ cooled_draw_delete( x, glist );
+ }
}
static void cooled_delete(t_gobj *z, t_glist *glist)
@@ -637,51 +640,52 @@ static void cooled_delete(t_gobj *z, t_glist *glist)
static void cooled_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
- t_cooled *x = (t_cooled *)z;
- int xold = x->x_xpos;
- int yold = x->x_ypos;
+ t_cooled *x = (t_cooled *)z;
+ int xold = x->x_xpos;
+ int yold = x->x_ypos;
x->x_xpos += dx;
x->x_ypos += dy;
if ( ( x->x_xpos != xold ) || ( x->x_ypos != yold ) )
{
- cooled_draw_move( x, glist );
+ cooled_draw_move( x, glist );
}
}
static void cooled_motion(t_cooled *x, t_floatarg dx, t_floatarg dy)
{
- // post( "cooled_motion @ [%d,%d] dx=%f dy=%f alt=%d", x->x_xdraw, x->x_ydraw, dx, dy, x->x_alted );
- if ( dx != 0 )
- {
- cooled_readstart( x, ((t_float)( x->x_xdraw - x->x_xpos ) * 100 )/ (t_float)( x->x_width * x->x_zoom ) );
- x->x_edraw += dx;
- cooled_readend( x, ((t_float)( x->x_edraw - x->x_xpos ) * 100 )/ (t_float)( x->x_width * x->x_zoom ) );
- }
+ // post( "cooled_motion @ [%d,%d] dx=%f dy=%f alt=%d", x->x_xdraw, x->x_ydraw, dx, dy, x->x_alted );
+ if ( dx != 0 )
+ {
+ cooled_readstart( x, ((t_float)( x->x_xdraw - x->x_xpos ) * 100 )/ (t_float)( x->x_width * x->x_zoom ) );
+ x->x_edraw += dx;
+ cooled_readend( x, ((t_float)( x->x_edraw - x->x_xpos ) * 100 )/ (t_float)( x->x_width * x->x_zoom ) );
+ }
}
- /* erase data form readstart to readend */
+/* erase data form readstart to readend */
static void cooled_erase( t_cooled *x )
{
- int startsamp, endsamp, si;
- int lreadstart = x->x_readstart, lreadend = x->x_readend;
+ int startsamp, endsamp, si;
+ int lreadstart = x->x_readstart, lreadend = x->x_readend;
- if (x->x_allocate) {
+ if (x->x_allocate)
+ {
post( "cooled~ : error : cannot erase while re-allocation" );
return;
}
// post( "cooled~ : erase" );
if ( lreadstart <= lreadend )
{
- startsamp = (lreadstart*x->x_size)/100;
- endsamp = (lreadend*x->x_size)/100;
+ startsamp = (lreadstart*x->x_size)/100;
+ endsamp = (lreadend*x->x_size)/100;
}
else
{
- startsamp = (lreadend*x->x_size)/100;
- endsamp = (lreadstart*x->x_size)/100;
+ startsamp = (lreadend*x->x_size)/100;
+ endsamp = (lreadstart*x->x_size)/100;
}
for ( si=startsamp; si<=endsamp; si++ )
@@ -691,27 +695,28 @@ static void cooled_erase( t_cooled *x )
}
if ( x->x_draw ) cooled_update_part(x, x->x_glist, startsamp*x->x_width/x->x_size, endsamp*(x->x_width-1)/x->x_size, 0, 1, 1);
}
- /* paste data form readstart to readend */
+/* paste data form readstart to readend */
static void cooled_paste( t_cooled *x )
{
- int startsamp, endsamp, si, inssamp, hlimit, csize;
- int lreadstart = x->x_readstart, lreadend = x->x_readend;
+ int startsamp, endsamp, si, inssamp, hlimit, csize;
+ int lreadstart = x->x_readstart, lreadend = x->x_readend;
- if (x->x_allocate) {
+ if (x->x_allocate)
+ {
post( "cooled~ : error : cannot paste while re-allocation" );
return;
}
if ( lreadstart <= lreadend )
{
- startsamp = (lreadstart*x->x_size)/100;
- endsamp = (lreadend*x->x_size)/100;
+ startsamp = (lreadstart*x->x_size)/100;
+ endsamp = (lreadend*x->x_size)/100;
}
else
{
- startsamp = (lreadend*x->x_size)/100;
- endsamp = (lreadstart*x->x_size)/100;
+ startsamp = (lreadend*x->x_size)/100;
+ endsamp = (lreadstart*x->x_size)/100;
}
-
+
// insert data at insertion point
inssamp = ( x->x_xdraw - x->x_xpos) * x->x_size / ( x->x_width * x->x_zoom );
// post( "cooled~ : replace [%d,%d] to %d", startsamp, endsamp, inssamp );
@@ -724,7 +729,7 @@ static void cooled_paste( t_cooled *x )
}
hlimit = si;
for ( si=0 ; si<=hlimit; si++ )
- {
+ {
*(x->x_rdata+inssamp+si) += *(x->x_rsemp+si);
*(x->x_ldata+inssamp+si) += *(x->x_lsemp+si);
}
@@ -732,27 +737,28 @@ static void cooled_paste( t_cooled *x )
// post( "cooled~ : updating [%d,%d]", inssamp*x->x_width/x->x_size, (inssamp+hlimit)*x->x_width/x->x_size );
if ( x->x_draw ) cooled_update_part(x, x->x_glist, inssamp*x->x_width/x->x_size, (inssamp+hlimit)*(x->x_width-1)/x->x_size, 0, 1, 1);
}
- /* replace data form readstart to readend */
+/* replace data form readstart to readend */
static void cooled_replace( t_cooled *x )
{
- int startsamp, endsamp, si, inssamp, hlimit, csize;
- int lreadstart = x->x_readstart, lreadend = x->x_readend;
+ int startsamp, endsamp, si, inssamp, hlimit, csize;
+ int lreadstart = x->x_readstart, lreadend = x->x_readend;
- if (x->x_allocate) {
+ if (x->x_allocate)
+ {
post( "cooled~ : error : cannot replace while re-allocation" );
return;
}
if ( lreadstart <= lreadend )
{
- startsamp = (lreadstart*x->x_size)/100;
- endsamp = (lreadend*x->x_size)/100;
+ startsamp = (lreadstart*x->x_size)/100;
+ endsamp = (lreadend*x->x_size)/100;
}
else
{
- startsamp = (lreadend*x->x_size)/100;
- endsamp = (lreadstart*x->x_size)/100;
+ startsamp = (lreadend*x->x_size)/100;
+ endsamp = (lreadstart*x->x_size)/100;
}
-
+
// insert data at insertion point
inssamp = ( x->x_xdraw - x->x_xpos) * x->x_size / ( x->x_width * x->x_zoom );
// post( "cooled~ : replace [%d,%d] to %d", startsamp, endsamp, inssamp );
@@ -765,7 +771,7 @@ static void cooled_replace( t_cooled *x )
}
hlimit = si;
for ( si=0 ; si<=hlimit; si++ )
- {
+ {
*(x->x_rdata+inssamp+si) = *(x->x_rsemp+si);
*(x->x_ldata+inssamp+si) = *(x->x_lsemp+si);
}
@@ -775,264 +781,314 @@ static void cooled_replace( t_cooled *x )
}
- /* call editor's property dialog */
+/* call editor's property dialog */
static void cooled_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_cooled *x=(t_cooled *)z;
+ char buf[800];
+ t_cooled *x=(t_cooled *)z;
- sprintf(buf, "pdtk_cooled_dialog %%s %d %d %d\n",
+ sprintf(buf, "pdtk_cooled_dialog %%s %d %d %d\n",
x->x_width, x->x_height, x->x_draw);
- // post("cooled_properties : %s", buf );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ // post("cooled_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
- /* handle properties change */
+/* handle properties change */
static void cooled_dialog(t_cooled *x, t_symbol *s, int argc, t_atom *argv)
{
- if ( !x ) {
- post( "cooled~ : error :tried to set properties on an unexisting object" );
- }
- if ( argc != 3 )
- {
- post( "cooled~ : error in the number of arguments ( %d instead of 3 )", argc );
- return;
- }
- if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT || argv[2].a_type != A_FLOAT ) {
- post( "cooled~ : wrong arguments" );
- return;
- }
- cooled_draw_delete(x, x->x_glist);
- if ( x->x_gifdata != NULL ) {
- freebytes(x->x_gifdata, x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_gifdata = NULL;
- }
- if ( x->x_guicommand != NULL ) {
- freebytes(x->x_guicommand, 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_guicommand = NULL;
- }
- x->x_width = (int)argv[0].a_w.w_float;
- if ( x->x_width < 0 ) x->x_width = 100;
- x->x_height = (int)argv[1].a_w.w_float;
- if ( x->x_height < 0 ) x->x_height = 100;
- x->x_draw = (int)argv[2].a_w.w_float;
- if ( !(x->x_gifdata = ( char* ) getbytes( x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return;
- } else {
- post( "cooled~ : allocated %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- }
- if ( !(x->x_guicommand = ( char* ) getbytes( 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return;
- } else {
- post( "cooled~ : allocated %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- }
- cooled_draw_new(x, x->x_glist);
+ if ( !x )
+ {
+ post( "cooled~ : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 3 )
+ {
+ post( "cooled~ : error in the number of arguments ( %d instead of 3 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT || argv[2].a_type != A_FLOAT )
+ {
+ post( "cooled~ : wrong arguments" );
+ return;
+ }
+ cooled_draw_delete(x, x->x_glist);
+ if ( x->x_gifdata != NULL )
+ {
+ freebytes(x->x_gifdata, x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_gifdata = NULL;
+ }
+ if ( x->x_guicommand != NULL )
+ {
+ freebytes(x->x_guicommand, 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_guicommand = NULL;
+ }
+ x->x_width = (int)argv[0].a_w.w_float;
+ if ( x->x_width < 0 ) x->x_width = 100;
+ x->x_height = (int)argv[1].a_w.w_float;
+ if ( x->x_height < 0 ) x->x_height = 100;
+ x->x_draw = (int)argv[2].a_w.w_float;
+ if ( !(x->x_gifdata = ( char* ) getbytes( x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ }
+ if ( !(x->x_guicommand = ( char* ) getbytes( 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ }
+ cooled_draw_new(x, x->x_glist);
}
- /* handle clicks */
+/* handle clicks */
static int cooled_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
- t_cooled* x = (t_cooled *)z;
- int pipos;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_cooled* x = (t_cooled *)z;
+ int pipos;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
// post( "cooled_click : x=%d y=%d doit=%d alt=%d, shift=%d", xpix, ypix, doit, alt, shift );
if ( doit )
{
- if ( shift && alt )
- {
- cooled_paste(x);
- }
- else if ( shift )
- {
- cooled_replace(x);
- }
- else if ( alt )
- {
- cooled_erase(x);
- }
- else
- {
- x->x_xdraw = xpix;
- x->x_edraw = xpix;
- x->x_shifted = shift;
- x->x_alted = alt;
- // activate motion callback
- glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)cooled_motion,
- 0, xpix, ypix );
-
- // draw insertion line
- if ( glist_isvisible( x->x_glist ) )
- {
- SYS_VGUI3( ".x%lx.c delete line %xINSERTHERE\n",
- canvas, x);
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #00FFFF -tags %xINSERTHERE -width 2\n",
- canvas, x->x_xdraw,
- x->x_ypos, x->x_xdraw,
- x->x_ypos+x->x_height*x->x_zoom, x );
- }
-
- }
+ if ( shift && alt )
+ {
+ cooled_paste(x);
+ }
+ else if ( shift )
+ {
+ cooled_replace(x);
+ }
+ else if ( alt )
+ {
+ cooled_erase(x);
+ }
+ else
+ {
+ x->x_xdraw = xpix;
+ x->x_edraw = xpix;
+ x->x_shifted = shift;
+ x->x_alted = alt;
+ // activate motion callback
+ glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)cooled_motion,
+ 0, xpix, ypix );
+
+ // draw insertion line
+ if ( glist_isvisible( x->x_glist ) )
+ {
+ SYS_VGUI3( ".x%lx.c delete line %xINSERTHERE\n",
+ canvas, x);
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #00FFFF -tags %xINSERTHERE -width 2\n",
+ canvas, x->x_xdraw,
+ x->x_ypos, x->x_xdraw,
+ x->x_ypos+x->x_height*x->x_zoom, x );
+ }
+
+ }
}
else
{
- // nothing
+ // nothing
}
return (1);
}
- /* clean up */
-static void cooled_free(t_cooled *x)
+/* clean up */
+static void cooled_free(t_cooled *x)
{
- if ( x->x_rdata != NULL ) {
- freebytes(x->x_rdata, x->x_size*sizeof(float) );
- post( "Freed %d bytes", x->x_size*sizeof(float) );
- x->x_rdata = NULL;
- }
- if ( x->x_ldata != NULL ) {
- freebytes(x->x_ldata, x->x_size*sizeof(float) );
- post( "Freed %d bytes", x->x_size*sizeof(float) );
- x->x_ldata = NULL;
- }
- if ( x->x_rsemp != NULL ) {
- freebytes(x->x_rsemp, x->x_size*sizeof(float) );
- post( "Freed %d bytes", x->x_size*sizeof(float) );
- x->x_rsemp = NULL;
- }
- if ( x->x_lsemp != NULL ) {
- freebytes(x->x_lsemp, x->x_size*sizeof(float) );
- post( "Freed %d bytes", x->x_size*sizeof(float) );
- x->x_lsemp = NULL;
- }
- if ( x->x_gifdata != NULL ) {
- freebytes(x->x_gifdata, x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_gifdata = NULL;
- }
- if ( x->x_guicommand != NULL ) {
- freebytes(x->x_guicommand, 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_guicommand = NULL;
+ if ( x->x_rdata != NULL )
+ {
+ freebytes(x->x_rdata, x->x_size*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*sizeof(float) );
+ x->x_rdata = NULL;
+ }
+ if ( x->x_ldata != NULL )
+ {
+ freebytes(x->x_ldata, x->x_size*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*sizeof(float) );
+ x->x_ldata = NULL;
+ }
+ if ( x->x_rsemp != NULL )
+ {
+ freebytes(x->x_rsemp, x->x_size*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*sizeof(float) );
+ x->x_rsemp = NULL;
+ }
+ if ( x->x_lsemp != NULL )
+ {
+ freebytes(x->x_lsemp, x->x_size*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*sizeof(float) );
+ x->x_lsemp = NULL;
+ }
+ if ( x->x_gifdata != NULL )
+ {
+ freebytes(x->x_gifdata, x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_gifdata = NULL;
+ }
+ if ( x->x_guicommand != NULL )
+ {
+ freebytes(x->x_guicommand, 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_guicommand = NULL;
}
}
- /* allocate tables for storing sound and temporary copy */
+/* allocate tables for storing sound and temporary copy */
static int cooled_allocate(t_cooled *x)
{
- int fi;
-
- if ( !(x->x_rdata = getbytes( x->x_size*sizeof(float) ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", x->x_size*sizeof(float) );
- }
- if ( !(x->x_ldata = getbytes( x->x_size*sizeof(float) ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", x->x_size*sizeof(float) );
- }
- if ( !(x->x_rsemp = getbytes( x->x_size*sizeof(float) ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", x->x_size*sizeof(float) );
- }
- if ( !(x->x_lsemp = getbytes( x->x_size*sizeof(float) ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", x->x_size*sizeof(float) );
- }
- if ( !(x->x_gifdata = ( char* ) getbytes( x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- }
- if ( !(x->x_guicommand = ( char* ) getbytes( 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- }
-
+ int fi;
+
+ if ( !(x->x_rdata = getbytes( x->x_size*sizeof(float) ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", x->x_size*sizeof(float) );
+ }
+ if ( !(x->x_ldata = getbytes( x->x_size*sizeof(float) ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", x->x_size*sizeof(float) );
+ }
+ if ( !(x->x_rsemp = getbytes( x->x_size*sizeof(float) ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", x->x_size*sizeof(float) );
+ }
+ if ( !(x->x_lsemp = getbytes( x->x_size*sizeof(float) ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", x->x_size*sizeof(float) );
+ }
+ if ( !(x->x_gifdata = ( char* ) getbytes( x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ }
+ if ( !(x->x_guicommand = ( char* ) getbytes( 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ }
+
return 0;
}
- /* allocate tables for storing sound and temporary copy */
+/* allocate tables for storing sound and temporary copy */
static int cooled_reallocate(t_cooled *x, int ioldsize, int inewsize)
{
- int fi, csize;
- t_float *prdata=x->x_rdata, *pldata=x->x_ldata, *prsemp=x->x_rsemp, *plsemp=x->x_lsemp;
-
- if ( !(x->x_rdata = getbytes( inewsize*sizeof(float) ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", inewsize*sizeof(float) );
- }
- if ( !(x->x_ldata = getbytes( inewsize*sizeof(float) ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", inewsize*sizeof(float) );
- }
- if ( !(x->x_rsemp = getbytes( inewsize*sizeof(float) ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", inewsize*sizeof(float) );
- }
- if ( !(x->x_lsemp = getbytes( inewsize*sizeof(float) ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "cooled~ : allocated %d bytes", inewsize*sizeof(float) );
+ int fi, csize;
+ t_float *prdata=x->x_rdata, *pldata=x->x_ldata, *prsemp=x->x_rsemp, *plsemp=x->x_lsemp;
+
+ if ( !(x->x_rdata = getbytes( inewsize*sizeof(float) ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", inewsize*sizeof(float) );
+ }
+ if ( !(x->x_ldata = getbytes( inewsize*sizeof(float) ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", inewsize*sizeof(float) );
+ }
+ if ( !(x->x_rsemp = getbytes( inewsize*sizeof(float) ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", inewsize*sizeof(float) );
+ }
+ if ( !(x->x_lsemp = getbytes( inewsize*sizeof(float) ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", inewsize*sizeof(float) );
}
if ( ioldsize <= inewsize )
{
- csize = ioldsize;
+ csize = ioldsize;
}
else
{
- csize = inewsize;
+ csize = inewsize;
}
memcpy( x->x_rdata, prdata, csize*sizeof(float) );
memcpy( x->x_ldata, pldata, csize*sizeof(float) );
memcpy( x->x_rsemp, prsemp, csize*sizeof(float) );
memcpy( x->x_lsemp, plsemp, csize*sizeof(float) );
- if ( prdata != NULL ) {
- freebytes(prdata, ioldsize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*sizeof(float) );
+ if ( prdata != NULL )
+ {
+ freebytes(prdata, ioldsize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*sizeof(float) );
}
- if ( pldata != NULL ) {
- freebytes(pldata, ioldsize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*sizeof(float) );
+ if ( pldata != NULL )
+ {
+ freebytes(pldata, ioldsize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*sizeof(float) );
}
- if ( prsemp != NULL ) {
- freebytes(prsemp, ioldsize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*sizeof(float) );
+ if ( prsemp != NULL )
+ {
+ freebytes(prsemp, ioldsize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*sizeof(float) );
}
- if ( plsemp != NULL ) {
- freebytes(plsemp, ioldsize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*sizeof(float) );
+ if ( plsemp != NULL )
+ {
+ freebytes(plsemp, ioldsize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*sizeof(float) );
}
-
+
return 0;
}
- /* records and playback the sound */
+/* records and playback the sound */
static t_int *cooled_perform(t_int *w)
{
t_float *lin = (t_float *)(w[1]);
@@ -1047,55 +1103,62 @@ static t_int *cooled_perform(t_int *w)
if ( lreadstart <= lreadend )
{
- startsamp = (lreadstart*x->x_size)/100;
- endsamp = (lreadend*x->x_size)/100;
+ startsamp = (lreadstart*x->x_size)/100;
+ endsamp = (lreadend*x->x_size)/100;
}
else
{
- startsamp = (lreadend*x->x_size)/100;
- endsamp = (lreadstart*x->x_size)/100;
+ startsamp = (lreadend*x->x_size)/100;
+ endsamp = (lreadstart*x->x_size)/100;
}
- while (n--)
+ while (n--)
{
// eventually records input
- if ( x->x_record ) {
- *(x->x_ldata+x->x_writepos)=*(lin);
- *(x->x_rdata+x->x_writepos)=*(rin);
- x->x_writepos++;
- if ( x->x_writepos >= x->x_size ) {
- x->x_record=0;
- x->x_writepos=0;
- if ( x->x_draw ) cooled_update_part(x, x->x_glist, 0, x->x_width-1, 0, 1, 0);
- outlet_bang(x->x_recend);
- if ( x->x_empty ) x->x_empty = 0;
- // post( "cooled~ : stopped recording" );
- }
+ if ( x->x_record )
+ {
+ *(x->x_ldata+x->x_writepos)=*(lin);
+ *(x->x_rdata+x->x_writepos)=*(rin);
+ x->x_writepos++;
+ if ( x->x_writepos >= x->x_size )
+ {
+ x->x_record=0;
+ x->x_writepos=0;
+ if ( x->x_draw ) cooled_update_part(x, x->x_glist, 0, x->x_width-1, 0, 1, 0);
+ outlet_bang(x->x_recend);
+ if ( x->x_empty ) x->x_empty = 0;
+ // post( "cooled~ : stopped recording" );
+ }
}
// set outputs
*rout = 0.0;
*lout = 0.0;
- if ( x->x_play) {
+ if ( x->x_play)
+ {
is=0;
*lout = *(x->x_ldata+(int)x->x_readpos);
*rout = *(x->x_rdata+(int)x->x_readpos);
x->x_readpos+=x->x_readspeed;
// post( "xreadpos : %f (added %f) %d", x->x_readpos, x->x_readspeed, x->x_readend );
- if ( ( x->x_readspeed >= 0 ) && ( x->x_readpos >= endsamp ) ) {
- x->x_play=0;
- x->x_readpos=(float)(startsamp);
- // post( "cooled~ : stopped playing (readpos=%d)", x->x_readpos );
- outlet_bang(x->x_end);
+ if ( ( x->x_readspeed >= 0 ) && ( x->x_readpos >= endsamp ) )
+ {
+ x->x_play=0;
+ x->x_readpos=(float)(startsamp);
+ // post( "cooled~ : stopped playing (readpos=%d)", x->x_readpos );
+ outlet_bang(x->x_end);
}
- if ( ( x->x_readspeed < 0 ) && ( x->x_readpos <= startsamp ) ) {
- x->x_play=0;
- x->x_readpos = (float)(endsamp);
- // post( "cooled~ : stopped playing (readpos=%d)", x->x_readpos );
- outlet_bang(x->x_end);
+ if ( ( x->x_readspeed < 0 ) && ( x->x_readpos <= startsamp ) )
+ {
+ x->x_play=0;
+ x->x_readpos = (float)(endsamp);
+ // post( "cooled~ : stopped playing (readpos=%d)", x->x_readpos );
+ outlet_bang(x->x_end);
}
}
- rout++;lout++;
- rin++;lin++;
+ rout++;
+ lout++;
+ rin++;
+ lin++;
}
// post( "cooled~ : read : %f:%d : write: %d:%d", x->x_readpos, x->x_play, x->x_writepos, x->x_record );
return (w+7);
@@ -1106,10 +1169,11 @@ static void cooled_dsp(t_cooled *x, t_signal **sp)
dsp_add(cooled_perform, 6, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[0]->s_n, x);
}
- /* record the cooled */
+/* record the cooled */
static void cooled_record(t_cooled *x)
{
- if (x->x_allocate) {
+ if (x->x_allocate)
+ {
post( "cooled~ : error : cannot record while re-allocation" );
return;
}
@@ -1118,12 +1182,13 @@ static void cooled_record(t_cooled *x)
post( "cooled~ : recording on" );
}
- /* map to stereo */
+/* map to stereo */
static void cooled_stereo(t_cooled *x)
{
- int si;
+ int si;
- if (x->x_allocate) {
+ if (x->x_allocate)
+ {
post( "cooled~ : error : cannot map to stereo while re-allocation" );
return;
}
@@ -1134,32 +1199,35 @@ static void cooled_stereo(t_cooled *x)
if ( x->x_draw ) cooled_update_part(x, x->x_glist, 0, x->x_width-1, !x->x_empty, !x->x_empty, 0);
}
- /* play the cooled */
+/* play the cooled */
static void cooled_play(t_cooled *x)
{
x->x_play=1;
// post( "cooled~ : playing on" );
}
- /* sets the reading speed */
+/* sets the reading speed */
static void cooled_readspeed(t_cooled *x, t_floatarg freadspeed)
{
x->x_readspeed=freadspeed;
}
- /* resize cooled */
+/* resize cooled */
static void cooled_resize(t_cooled *x, t_floatarg fnewsize )
{
- if (fnewsize <= 0) {
+ if (fnewsize <= 0)
+ {
post( "cooled~ : error : wrong size" );
return;
}
- if (x->x_allocate) {
+ if (x->x_allocate)
+ {
post( "cooled~ : error : cannot resize while re-allocation" );
return;
}
#ifndef _WIN32
- if (x->x_updatechild > 0) {
+ if (x->x_updatechild > 0)
+ {
post( "cooled~ : can't resize now, an update is pending." );
return;
}
@@ -1175,99 +1243,115 @@ static void cooled_resize(t_cooled *x, t_floatarg fnewsize )
x->x_empty = 1;
if ( x->x_readstart <= x->x_readend )
{
- x->x_readpos = (x->x_readstart*x->x_size)/100;
+ x->x_readpos = (x->x_readstart*x->x_size)/100;
}
else
{
- x->x_readpos = (x->x_readend*x->x_size)/100;
+ x->x_readpos = (x->x_readend*x->x_size)/100;
}
// erase all points, as data is zero no drawing is needed
if ( x->x_draw) cooled_update_part(x, x->x_glist, 0, x->x_width-1, 0, !x->x_empty, 1);
x->x_allocate = 0;
}
- /* set zoom factor */
+/* set zoom factor */
static void cooled_zoom(t_cooled *x, t_floatarg fzoom )
{
- if (fzoom < 1) {
+ if (fzoom < 1)
+ {
post( "cooled~ : error : wrong zoom factor" );
return;
}
- if (x->x_allocate) {
+ if (x->x_allocate)
+ {
post( "cooled~ : error : cannot zoom while re-allocation" );
return;
}
- if ( x->x_gifdata != NULL ) {
- freebytes(x->x_gifdata, x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_gifdata = NULL;
+ if ( x->x_gifdata != NULL )
+ {
+ freebytes(x->x_gifdata, x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_gifdata = NULL;
}
- if ( x->x_guicommand != NULL ) {
- freebytes(x->x_guicommand, 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_guicommand = NULL;
+ if ( x->x_guicommand != NULL )
+ {
+ freebytes(x->x_guicommand, 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_guicommand = NULL;
}
x->x_zoom = (int)fzoom;
- if ( !(x->x_gifdata = ( char* ) getbytes( x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return;
- } else {
- post( "cooled~ : allocated %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
- }
- if ( !(x->x_guicommand = ( char* ) getbytes( 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "cooled~ : error : could not allocate buffers" );
- return;
- } else {
- post( "cooled~ : allocated %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ if ( !(x->x_gifdata = ( char* ) getbytes( x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
+ }
+ if ( !(x->x_guicommand = ( char* ) getbytes( 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "cooled~ : error : could not allocate buffers" );
+ return;
+ }
+ else
+ {
+ post( "cooled~ : allocated %d bytes", 128+x->x_height*x->x_zoom*sizeof("#FFFFFF ") );
}
if ( x->x_draw) cooled_update_part(x, x->x_glist, 0, x->x_width-1, !x->x_empty, !x->x_empty, 0);
canvas_fixlinesfor(x->x_glist, (t_text*)x );
}
- /* modify the loop positions */
+/* modify the loop positions */
static void cooled_loop(t_cooled *x, t_symbol *soperator )
{
- char *operator = soperator->s_name;
- int ci;
- t_float fvalue, freadstart = x->x_readstart, freadend = x->x_readend;
-
- if ( (soperator->s_name[0] != '*') &&
- (soperator->s_name[0] != '/') &&
- (soperator->s_name[0] != '>') &&
- (soperator->s_name[0] != '<') ) {
+ char *operator = soperator->s_name;
+ int ci;
+ t_float fvalue, freadstart = x->x_readstart, freadend = x->x_readend;
+
+ if ( (soperator->s_name[0] != '*') &&
+ (soperator->s_name[0] != '/') &&
+ (soperator->s_name[0] != '>') &&
+ (soperator->s_name[0] != '<') )
+ {
post( "cooled~ : error : wrong operator argument : should be *|/|>|<" );
return;
}
for ( ci=1; ci<(int)strlen( soperator->s_name ); ci++ )
{
- if ( !(isdigit(soperator->s_name[ci])||(soperator->s_name[ci]=='.')) ) {
- post( "cooled~ : error : wrong operation value : %s : should be in a float format", soperator->s_name+1 );
- return;
- }
+ if ( !(isdigit(soperator->s_name[ci])||(soperator->s_name[ci]=='.')) )
+ {
+ post( "cooled~ : error : wrong operation value : %s : should be in a float format", soperator->s_name+1 );
+ return;
+ }
}
- if ( sscanf( soperator->s_name+1, "%f", &fvalue ) != 1 ) {
+ if ( sscanf( soperator->s_name+1, "%f", &fvalue ) != 1 )
+ {
post( "cooled~ : error : can't get operation value" );
return;
}
switch( soperator->s_name[0] )
{
- case '*' :
- freadend = x->x_readstart + fvalue*(x->x_readend-x->x_readstart);
- break;
+ case '*' :
+ freadend = x->x_readstart + fvalue*(x->x_readend-x->x_readstart);
+ break;
- case '/' :
- if ( fvalue != 0 ) { freadend = x->x_readstart + (x->x_readend-x->x_readstart)/fvalue; };
- break;
+ case '/' :
+ if ( fvalue != 0 )
+ {
+ freadend = x->x_readstart + (x->x_readend-x->x_readstart)/fvalue;
+ };
+ break;
- case '>' :
- freadstart = x->x_readstart + fvalue*(x->x_readend-x->x_readstart);
- freadend = x->x_readend + fvalue*(x->x_readend-x->x_readstart);
- break;
+ case '>' :
+ freadstart = x->x_readstart + fvalue*(x->x_readend-x->x_readstart);
+ freadend = x->x_readend + fvalue*(x->x_readend-x->x_readstart);
+ break;
- case '<' :
- freadstart = x->x_readstart - fvalue*(x->x_readend-x->x_readstart);
- freadend = x->x_readend - fvalue*(x->x_readend-x->x_readstart);
- break;
+ case '<' :
+ freadstart = x->x_readstart - fvalue*(x->x_readend-x->x_readstart);
+ freadend = x->x_readend - fvalue*(x->x_readend-x->x_readstart);
+ break;
}
if ( freadstart < 0.0 ) freadstart = 0.0;
if ( freadend < 0.0 ) freadend = 0.0;
@@ -1277,10 +1361,11 @@ static void cooled_loop(t_cooled *x, t_symbol *soperator )
cooled_readend( x, freadend);
}
- /* refresh data */
+/* refresh data */
static void cooled_refresh(t_cooled *x)
{
- if (x->x_allocate) {
+ if (x->x_allocate)
+ {
post( "cooled~ : error : cannot refresh while re-allocation" );
return;
}
@@ -1299,41 +1384,42 @@ static void *cooled_new(t_symbol *s, int argc, t_atom *argv)
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("readstart"));
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("readend"));
-
+
if ( argc != 0 )
{
- if ( argc < 3 )
- {
- post( "audience~ : 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 ) {
- post( "audience~ : wrong arguments" );
- return NULL;
- }
- x->x_size = (int)argv[0].a_w.w_float;
- if ( x->x_size < 1 ) x->x_size = 1;
- x->x_width = (int)argv[1].a_w.w_float;
- if ( x->x_width < 10 ) x->x_width = 10;
- x->x_height = (int)argv[2].a_w.w_float;
- if ( x->x_height < 10 ) x->x_height = 10;
- if ( argc == 3 )
- x->x_draw = 1;
- else
- x->x_draw = (int)argv[3].a_w.w_float;
+ if ( argc < 3 )
+ {
+ post( "audience~ : 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 )
+ {
+ post( "audience~ : wrong arguments" );
+ return NULL;
+ }
+ x->x_size = (int)argv[0].a_w.w_float;
+ if ( x->x_size < 1 ) x->x_size = 1;
+ x->x_width = (int)argv[1].a_w.w_float;
+ if ( x->x_width < 10 ) x->x_width = 10;
+ x->x_height = (int)argv[2].a_w.w_float;
+ if ( x->x_height < 10 ) x->x_height = 10;
+ if ( argc == 3 )
+ x->x_draw = 1;
+ else
+ x->x_draw = (int)argv[3].a_w.w_float;
}
else
{
- x->x_size = COOLED_DEFAULT_SIZE;
- x->x_width = COOLED_DEFAULT_WIDTH;
- x->x_height = COOLED_DEFAULT_HEIGHT;
- x->x_draw = 1;
+ x->x_size = COOLED_DEFAULT_SIZE;
+ x->x_width = COOLED_DEFAULT_WIDTH;
+ x->x_height = COOLED_DEFAULT_HEIGHT;
+ x->x_draw = 1;
}
// activate graphical callbacks
class_setwidget(cooled_class, &cooled_widgetbehavior);
-
+
x->x_play = 0;
x->x_readspeed = 1.;
x->x_record = 0;
@@ -1356,10 +1442,13 @@ static void *cooled_new(t_symbol *s, int argc, t_atom *argv)
cooled_readstart( x, 0);
cooled_readend( x, 100);
- if ( cooled_allocate(x) <0 ) {
- return NULL;
- } else {
- return(x);
+ if ( cooled_allocate(x) <0 )
+ {
+ return NULL;
+ }
+ else
+ {
+ return(x);
}
}
@@ -1368,7 +1457,7 @@ void cooled_tilde_setup(void)
{
verbose(0, cooled_version);
cooled_class = class_new(gensym("cooled~"), (t_newmethod)cooled_new, (t_method)cooled_free,
- sizeof(t_cooled), 0, A_GIMME, 0);
+ sizeof(t_cooled), 0, A_GIMME, 0);
// set callbacks
diff --git a/countund.c b/countund.c
index f2b1fb3..47aac77 100644
--- a/countund.c
+++ b/countund.c
@@ -54,62 +54,71 @@ typedef struct _countund
t_int x_up;
} t_countund;
- /* clean up */
-static void countund_free(t_countund *x)
+/* clean up */
+static void countund_free(t_countund *x)
{
}
static void *countund_new(t_float flimit)
{
- t_countund *x = (t_countund *)pd_new(countund_class);
- outlet_new(&x->x_obj, &s_float);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("limit"));
- if ( flimit < 0 ) {
- post( "countund~: wrong creation argument" );
- return NULL;
- }
- x->x_limit = (int) flimit;
- x->x_value = 0;
- x->x_up = 1;
- return(x);
+ t_countund *x = (t_countund *)pd_new(countund_class);
+ outlet_new(&x->x_obj, &s_float);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("limit"));
+ if ( flimit < 0 )
+ {
+ post( "countund~: wrong creation argument" );
+ return NULL;
+ }
+ x->x_limit = (int) flimit;
+ x->x_value = 0;
+ x->x_up = 1;
+ return(x);
}
static void *countund_limit(t_countund* x, t_float flimit)
{
- if ( flimit < 0 ) {
- post( "countund~: wrong count limit" );
- return;
- } else {
- x->x_limit=(int)flimit;
- }
+ if ( flimit < 0 )
+ {
+ post( "countund~: wrong count limit" );
+ return;
+ }
+ else
+ {
+ x->x_limit=(int)flimit;
+ }
}
static void *countund_bang(t_countund *x)
{
- if ( x->x_up ) {
- x->x_value+=1;
- if (x->x_value>x->x_limit) {
- x->x_value=x->x_limit-1;
- x->x_up=0;
- }
- } else {
- x->x_value-=1;
- if (x->x_value<0) {
- x->x_value=1;
- x->x_up=1;
- }
- }
- outlet_float( x->x_obj.ob_outlet, x->x_value );
- return;
+ if ( x->x_up )
+ {
+ x->x_value+=1;
+ if (x->x_value>x->x_limit)
+ {
+ x->x_value=x->x_limit-1;
+ x->x_up=0;
+ }
+ }
+ else
+ {
+ x->x_value-=1;
+ if (x->x_value<0)
+ {
+ x->x_value=1;
+ x->x_up=1;
+ }
+ }
+ outlet_float( x->x_obj.ob_outlet, x->x_value );
+ return;
}
void countund_setup(void)
{
- verbose(0, countund_version);
- countund_class = class_new(gensym("countund"), (t_newmethod)countund_new,
- (t_method)countund_free,
- sizeof(t_countund), 0, A_DEFFLOAT, 0);
- class_addmethod( countund_class, (t_method)countund_bang, &s_bang, 0);
- class_addmethod( countund_class, (t_method)countund_limit, gensym("limit"), A_FLOAT, 0);
+ verbose(0, countund_version);
+ countund_class = class_new(gensym("countund"), (t_newmethod)countund_new,
+ (t_method)countund_free,
+ sizeof(t_countund), 0, A_DEFFLOAT, 0);
+ class_addmethod( countund_class, (t_method)countund_bang, &s_bang, 0);
+ class_addmethod( countund_class, (t_method)countund_limit, gensym("limit"), A_FLOAT, 0);
}
diff --git a/disto~.c b/disto~.c
index c22efd7..db5c5dc 100644
--- a/disto~.c
+++ b/disto~.c
@@ -46,34 +46,36 @@
#define BFSZ 4096 /* main delay buffer */
#define BLOCK_DELAY 10 /* number of blocks to delay */
#define NA 0.0 /* param not applicable */
-#define NBEXPS 129
+#define NBEXPS 129
static char *disto_version = "disto~: distortion, version 0.1 (ydegoyon@free.fr)";
-struct hipass {
- /* few intermediate variables */
- double omega;
- double sn,cs;
- double alpha;
- /* filter coefficients */
- double a0,a1,a2,b0,b1,b2;
- double k0,k1,k2,k3,k4;
- /* amplitudes */
- double x0,x1,x2;
- double y0,y1,y2;
+struct hipass
+{
+ /* few intermediate variables */
+ double omega;
+ double sn,cs;
+ double alpha;
+ /* filter coefficients */
+ double a0,a1,a2,b0,b1,b2;
+ double k0,k1,k2,k3,k4;
+ /* amplitudes */
+ double x0,x1,x2;
+ double y0,y1,y2;
} hipass;
-struct lowpass {
- /* few intermediate variables */
- double omega;
- double sn,cs;
- double alpha;
- /* filter coefficients */
- double a0,a1,a2,b0,b1,b2;
- double k0,k1,k2,k3,k4;
- /* amplitudes */
- double x0,x1,x2;
- double y0,y1,y2;
+struct lowpass
+{
+ /* few intermediate variables */
+ double omega;
+ double sn,cs;
+ double alpha;
+ /* filter coefficients */
+ double a0,a1,a2,b0,b1,b2;
+ double k0,k1,k2,k3,k4;
+ /* amplitudes */
+ double x0,x1,x2;
+ double y0,y1,y2;
} lowpass;
typedef struct _disto
@@ -91,7 +93,7 @@ typedef struct _disto
double x_hipassQ; /* the EE kinda definition for hi pass filter */ /* 0.1< <=1 */
double x_lowpassQ; /* the EE kinda definition for low pass filter */ /* 0.1< <=1 */
- /* audio processing data ( not setable ) */
+ /* audio processing data ( not setable ) */
double data,pred;
double outval,outvol;
double exps[NBEXPS];
@@ -107,11 +109,11 @@ static t_class *disto_class;
static void disto_init_filters (t_disto *x)
{
- t_int i;
+ t_int i;
for (i=0; i<130; i++)
{
- x->exps[i]=exp((double)i*x->x_drive)*x->x_wetmix;
+ x->exps[i]=exp((double)i*x->x_drive)*x->x_wetmix;
}
x->HPF.omega = 2.0*M_PI*x->x_hipassfreq/(double)x->x_samplerate;
@@ -151,11 +153,11 @@ static void disto_drive(t_disto *x, t_floatarg fdrive )
{
if ( fdrive > 25.0 )
{
- fdrive = 25.0;
+ fdrive = 25.0;
}
if ( fdrive < 0.0 )
{
- fdrive = 0.0;
+ fdrive = 0.0;
}
x->x_drive = fdrive;
// post( "disto~ : drive: %f", x->x_drive );
@@ -166,11 +168,11 @@ static void disto_drymix(t_disto *x, t_floatarg fdrymix )
{
if ( fdrymix > 5.0 )
{
- fdrymix = 5.0;
+ fdrymix = 5.0;
}
if ( fdrymix < -5.0 )
{
- fdrymix = -5.0;
+ fdrymix = -5.0;
}
x->x_drymix = fdrymix;
// post( "disto~ : drymix: %f", x->x_drymix );
@@ -181,11 +183,11 @@ static void disto_wetmix(t_disto *x, t_floatarg fwetmix )
{
if ( fwetmix > 5.0 )
{
- fwetmix = 5.0;
+ fwetmix = 5.0;
}
if ( fwetmix < -5.0 )
{
- fwetmix = -5.0;
+ fwetmix = -5.0;
}
x->x_wetmix = fwetmix;
// post( "disto~ : wetmix: %f", x->x_wetmix );
@@ -196,11 +198,11 @@ static void disto_feedback(t_disto *x, t_floatarg ffeedback )
{
if ( ffeedback > 10.0 )
{
- ffeedback = 10.0;
+ ffeedback = 10.0;
}
if ( ffeedback < -10.0 )
{
- ffeedback = -10.0;
+ ffeedback = -10.0;
}
x->x_feedback = ffeedback;
// post( "disto~ : feedback: %f", x->x_feedback );
@@ -211,11 +213,11 @@ static void disto_volume(t_disto *x, t_floatarg fvolume )
{
if ( fvolume > 5.0 )
{
- fvolume = 5.0;
+ fvolume = 5.0;
}
if ( fvolume < 0.0 )
{
- fvolume = 0.0;
+ fvolume = 0.0;
}
x->x_volume = fvolume;
// post( "disto~ : volume: %f", x->x_volume );
@@ -226,11 +228,11 @@ static void disto_hipassfreq(t_disto *x, t_floatarg fhipassfreq )
{
if ( fhipassfreq > x->x_samplerate/2 )
{
- fhipassfreq = x->x_samplerate/2;
+ fhipassfreq = x->x_samplerate/2;
}
if ( fhipassfreq < 0.0 )
{
- fhipassfreq = 0.0;
+ fhipassfreq = 0.0;
}
x->x_hipassfreq = fhipassfreq;
// post( "disto~ : hipassfreq: %f", x->x_hipassfreq );
@@ -241,11 +243,11 @@ static void disto_hipassQ(t_disto *x, t_floatarg fhipassQ )
{
if ( fhipassQ > 1.0 )
{
- fhipassQ = 1.0;
+ fhipassQ = 1.0;
}
if ( fhipassQ < 0.1 )
{
- fhipassQ = 0.1;
+ fhipassQ = 0.1;
}
x->x_hipassQ = fhipassQ;
// post( "disto~ : hipassQ: %f", x->x_hipassQ );
@@ -256,11 +258,11 @@ static void disto_lowpassfreq(t_disto *x, t_floatarg flowpassfreq )
{
if ( flowpassfreq > x->x_samplerate/2 )
{
- flowpassfreq = x->x_samplerate/2;
+ flowpassfreq = x->x_samplerate/2;
}
if ( flowpassfreq < 0.0 )
{
- flowpassfreq = 0.0;
+ flowpassfreq = 0.0;
}
x->x_lowpassfreq = flowpassfreq;
// post( "disto~ : lowpassfreq: %f", x->x_lowpassfreq );
@@ -271,11 +273,11 @@ static void disto_lowpassQ(t_disto *x, t_floatarg flowpassQ )
{
if ( flowpassQ > 1.0 )
{
- flowpassQ = 1.0;
+ flowpassQ = 1.0;
}
if ( flowpassQ < 0.1 )
{
- flowpassQ = 0.1;
+ flowpassQ = 0.1;
}
x->x_lowpassQ = flowpassQ;
// post( "disto~ : lowpassQ: %f", x->x_lowpassQ );
@@ -284,49 +286,48 @@ static void disto_lowpassQ(t_disto *x, t_floatarg flowpassQ )
static t_int *disto_perform(t_int *w)
{
- t_float *in = (t_float *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- t_int n = (int)(w[3]);
- t_disto *x = (t_disto*)(w[4]);
- t_int i;
+ t_float *in = (t_float *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ t_int n = (int)(w[3]);
+ t_disto *x = (t_disto*)(w[4]);
+ t_int i;
for (i = 0; i < n; i++)
{
- x->HPF.x0 = *(in++);
- x->HPF.y0 = (x->HPF.k0*x->HPF.x0+x->HPF.k1*x->HPF.x1+x->HPF.k2*x->HPF.x2-x->HPF.k3*x->HPF.y1-x->HPF.k4*x->HPF.y2);
- x->HPF.y2 = x->HPF.y1;
- x->HPF.y1 = x->HPF.y0;
- x->HPF.x2 = x->HPF.x1;
- x->HPF.x1 = x->HPF.x0;
- x->data = (int)x->HPF.y0;
-
- if ((x->data-x->pred)>0)
- x->outval += (x->data*x->x_drymix+ x->exps[abs(x->data)]);
- else
- if ((x->data-x->pred)<0)
- x->outval += (x->data*x->x_drymix- x->exps[abs(x->data)]);
- x->pred = x->data;
-
- x->LPF.x0 = *(out);
- x->LPF.y0 = (x->LPF.k0*x->LPF.x0+x->LPF.k1*x->LPF.x1+x->LPF.k2*x->LPF.x2-x->LPF.k3*x->LPF.y1-x->LPF.k4*x->LPF.y2);
- x->LPF.y2 = x->LPF.y1;
- x->LPF.y1 = x->LPF.y0;
- x->LPF.x2 = x->LPF.x1;
- x->LPF.x1 = x->LPF.x0;
-
- x->outvol = x->LPF.y0*x->x_volume;
-
- if(x->outvol > 1.0)
- x->data = 1.0;
- else if(x->outvol < -1.0)
- x->data = -1.0;
+ x->HPF.x0 = *(in++);
+ x->HPF.y0 = (x->HPF.k0*x->HPF.x0+x->HPF.k1*x->HPF.x1+x->HPF.k2*x->HPF.x2-x->HPF.k3*x->HPF.y1-x->HPF.k4*x->HPF.y2);
+ x->HPF.y2 = x->HPF.y1;
+ x->HPF.y1 = x->HPF.y0;
+ x->HPF.x2 = x->HPF.x1;
+ x->HPF.x1 = x->HPF.x0;
+ x->data = (int)x->HPF.y0;
+
+ if ((x->data-x->pred)>0)
+ x->outval += (x->data*x->x_drymix+ x->exps[abs(x->data)]);
+ else if ((x->data-x->pred)<0)
+ x->outval += (x->data*x->x_drymix- x->exps[abs(x->data)]);
+ x->pred = x->data;
+
+ x->LPF.x0 = *(out);
+ x->LPF.y0 = (x->LPF.k0*x->LPF.x0+x->LPF.k1*x->LPF.x1+x->LPF.k2*x->LPF.x2-x->LPF.k3*x->LPF.y1-x->LPF.k4*x->LPF.y2);
+ x->LPF.y2 = x->LPF.y1;
+ x->LPF.y1 = x->LPF.y0;
+ x->LPF.x2 = x->LPF.x1;
+ x->LPF.x1 = x->LPF.x0;
+
+ x->outvol = x->LPF.y0*x->x_volume;
+
+ if(x->outvol > 1.0)
+ x->data = 1.0;
+ else if(x->outvol < -1.0)
+ x->data = -1.0;
else
- x->data = x->outvol;
+ x->data = x->outvol;
- *(out++) = x->data;
+ *(out++) = x->data;
- x->outval *= x->x_feedback;
+ x->outval *= x->x_feedback;
}
@@ -337,88 +338,88 @@ static void disto_preset(t_disto *x, t_float pnumber)
{
switch ( (int)pnumber )
{
- /* "Hard Distortion 100-10000Hz" */
- case 1:
- x->x_drive = 1.5;
- x->x_drymix = 1.0;
- x->x_wetmix = 0.5;
- x->x_feedback = 0.0;
- x->x_volume = 1.0;
- x->x_hipassfreq = 100.0;
- x->x_hipassQ = 0.5;
- x->x_lowpassfreq = 10000.0;
- x->x_lowpassQ = 0.5;
- break;
-
- /* "Hard Distortion 100-6000Hz" */
- case 2:
- x->x_drive = 1.5;
- x->x_drymix = 1.0;
- x->x_wetmix = 0.5;
- x->x_feedback = 0.0;
- x->x_volume = 1.0;
- x->x_hipassfreq = 100.0;
- x->x_hipassQ = 0.5;
- x->x_lowpassfreq = 2000.0;
- x->x_lowpassQ = 0.5;
- break;
-
- /* "Very Hard Distortion" */
- case 3:
- x->x_drive = 2.0;
- x->x_drymix = 0.0;
- x->x_wetmix = 1.0;
- x->x_feedback = 1.0;
- x->x_volume = 5.0;
- x->x_hipassfreq = 100.0;
- x->x_hipassQ = 0.5;
- x->x_lowpassfreq = 6000.0;
- x->x_lowpassQ = 0.5;
- break;
-
- /* "Medium Distortion 0.2" */
- case 4:
- x->x_drive = 0.2;
- x->x_drymix = 1.0;
- x->x_wetmix = 1.0;
- x->x_feedback = 0.1;
- x->x_volume = 1.0;
- x->x_hipassfreq = 100.0;
- x->x_hipassQ = 0.5;
- x->x_lowpassfreq = 6000.0;
- x->x_lowpassQ = 0.5;
- break;
-
- /* "Medium Distortion 0.8" */
- case 5:
- x->x_drive = 0.8;
- x->x_drymix = 1.0;
- x->x_wetmix = 1.0;
- x->x_feedback = 0.1;
- x->x_volume = 1.0;
- x->x_hipassfreq = 100.0;
- x->x_hipassQ = 1.0;
- x->x_lowpassfreq = 6000.0;
- x->x_lowpassQ = 0.5;
- break;
-
- /* "Soft Distortion 0.8" */
- case 6:
- x->x_drive = 0.8;
- x->x_drymix = 0.4;
- x->x_wetmix = 0.8;
- x->x_feedback = 0.0;
- x->x_volume = 0.5;
- x->x_hipassfreq = 100.0;
- x->x_hipassQ = 1.0;
- x->x_lowpassfreq = 10000.0;
- x->x_lowpassQ = 0.5;
- break;
-
- default:
- post( "disto~ : unknown preset requested : %d", pnumber );
- return;
- break;
+ /* "Hard Distortion 100-10000Hz" */
+ case 1:
+ x->x_drive = 1.5;
+ x->x_drymix = 1.0;
+ x->x_wetmix = 0.5;
+ x->x_feedback = 0.0;
+ x->x_volume = 1.0;
+ x->x_hipassfreq = 100.0;
+ x->x_hipassQ = 0.5;
+ x->x_lowpassfreq = 10000.0;
+ x->x_lowpassQ = 0.5;
+ break;
+
+ /* "Hard Distortion 100-6000Hz" */
+ case 2:
+ x->x_drive = 1.5;
+ x->x_drymix = 1.0;
+ x->x_wetmix = 0.5;
+ x->x_feedback = 0.0;
+ x->x_volume = 1.0;
+ x->x_hipassfreq = 100.0;
+ x->x_hipassQ = 0.5;
+ x->x_lowpassfreq = 2000.0;
+ x->x_lowpassQ = 0.5;
+ break;
+
+ /* "Very Hard Distortion" */
+ case 3:
+ x->x_drive = 2.0;
+ x->x_drymix = 0.0;
+ x->x_wetmix = 1.0;
+ x->x_feedback = 1.0;
+ x->x_volume = 5.0;
+ x->x_hipassfreq = 100.0;
+ x->x_hipassQ = 0.5;
+ x->x_lowpassfreq = 6000.0;
+ x->x_lowpassQ = 0.5;
+ break;
+
+ /* "Medium Distortion 0.2" */
+ case 4:
+ x->x_drive = 0.2;
+ x->x_drymix = 1.0;
+ x->x_wetmix = 1.0;
+ x->x_feedback = 0.1;
+ x->x_volume = 1.0;
+ x->x_hipassfreq = 100.0;
+ x->x_hipassQ = 0.5;
+ x->x_lowpassfreq = 6000.0;
+ x->x_lowpassQ = 0.5;
+ break;
+
+ /* "Medium Distortion 0.8" */
+ case 5:
+ x->x_drive = 0.8;
+ x->x_drymix = 1.0;
+ x->x_wetmix = 1.0;
+ x->x_feedback = 0.1;
+ x->x_volume = 1.0;
+ x->x_hipassfreq = 100.0;
+ x->x_hipassQ = 1.0;
+ x->x_lowpassfreq = 6000.0;
+ x->x_lowpassQ = 0.5;
+ break;
+
+ /* "Soft Distortion 0.8" */
+ case 6:
+ x->x_drive = 0.8;
+ x->x_drymix = 0.4;
+ x->x_wetmix = 0.8;
+ x->x_feedback = 0.0;
+ x->x_volume = 0.5;
+ x->x_hipassfreq = 100.0;
+ x->x_hipassQ = 1.0;
+ x->x_lowpassfreq = 10000.0;
+ x->x_lowpassQ = 0.5;
+ break;
+
+ default:
+ post( "disto~ : unknown preset requested : %d", pnumber );
+ return;
+ break;
}
disto_init_filters( x );
}
@@ -428,13 +429,14 @@ static void disto_dsp(t_disto *x, t_signal **sp)
dsp_add(disto_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x );
}
- /* clean up */
+/* clean up */
static void disto_free(t_disto *x)
{
- if ( x->x_buf != NULL ) {
- freebytes(x->x_buf, BFSZ*sizeof( double ) );
- post( "Freed %d bytes", BFSZ*sizeof( double ) );
- x->x_buf = NULL;
+ if ( x->x_buf != NULL )
+ {
+ freebytes(x->x_buf, BFSZ*sizeof( double ) );
+ post( "Freed %d bytes", BFSZ*sizeof( double ) );
+ x->x_buf = NULL;
}
}
@@ -458,8 +460,8 @@ static void *disto_new(void)
if ( !( x->x_buf = ( double* ) getbytes( BFSZ*sizeof( double ) ) ) )
{
- post ("disto~ : could not allocate buffer" );
- return NULL;
+ post ("disto~ : could not allocate buffer" );
+ return NULL;
}
// set default parameters
@@ -473,7 +475,7 @@ void disto_tilde_setup(void)
{
verbose(0, disto_version );
disto_class = class_new(gensym("disto~"), (t_newmethod)disto_new, (t_method)disto_free,
- sizeof(t_disto), 0, 0);
+ sizeof(t_disto), 0, 0);
CLASS_MAINSIGNALIN( disto_class, t_disto, x_f );
class_addmethod(disto_class, (t_method)disto_drive, gensym("drive"), A_FLOAT, 0);
diff --git a/exciter.c b/exciter.c
index 1b6ff52..59ef414 100644
--- a/exciter.c
+++ b/exciter.c
@@ -62,7 +62,7 @@ void canvas_startmotion(t_canvas *x);
#define EXCITER_PIXEL_GRAIN 5
-static char *exciter_version = "exciter: a bang-events sequencer, version 0.5 (ydegoyon@free.fr)";
+static char *exciter_version = "exciter: a bang-events sequencer, version 0.5 (ydegoyon@free.fr)";
t_widgetbehavior exciter_widgetbehavior;
static t_class *exciter_class;
@@ -112,160 +112,160 @@ static int pointsize = 5;
/* 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);
+ t_int polyray = ( x->x_height / x->x_nbevents) / 2;
+ t_canvas *canvas=glist_getcanvas(glist);
SYS_VGUI13(".x%lx.c create polygon %d %d %d %d %d %d %d %d -outline #000000 -fill #FFFFFF -tags %xEVENT%.4d%.4d\n",
- canvas,
- text_xpix(&x->x_obj, glist) + ix*EXCITER_PIXEL_GRAIN,
- text_ypix(&x->x_obj, glist) + x->x_height - (iy+1)*x->x_height/x->x_nbevents + 2*polyray,
- text_xpix(&x->x_obj, glist) + ix*EXCITER_PIXEL_GRAIN + polyray,
- text_ypix(&x->x_obj, glist) + x->x_height - (iy+1)*x->x_height/x->x_nbevents + polyray,
- text_xpix(&x->x_obj, glist) + ix*EXCITER_PIXEL_GRAIN + 2*polyray,
- text_ypix(&x->x_obj, glist) + x->x_height - (iy+1)*x->x_height/x->x_nbevents,
- text_xpix(&x->x_obj, glist) + ix*EXCITER_PIXEL_GRAIN + polyray,
- text_ypix(&x->x_obj, glist) + x->x_height - (iy+1)*x->x_height/x->x_nbevents - polyray,
- x, ix, iy);
+ canvas,
+ text_xpix(&x->x_obj, glist) + ix*EXCITER_PIXEL_GRAIN,
+ text_ypix(&x->x_obj, glist) + x->x_height - (iy+1)*x->x_height/x->x_nbevents + 2*polyray,
+ text_xpix(&x->x_obj, glist) + ix*EXCITER_PIXEL_GRAIN + polyray,
+ text_ypix(&x->x_obj, glist) + x->x_height - (iy+1)*x->x_height/x->x_nbevents + polyray,
+ text_xpix(&x->x_obj, glist) + ix*EXCITER_PIXEL_GRAIN + 2*polyray,
+ text_ypix(&x->x_obj, glist) + x->x_height - (iy+1)*x->x_height/x->x_nbevents,
+ text_xpix(&x->x_obj, glist) + ix*EXCITER_PIXEL_GRAIN + polyray,
+ text_ypix(&x->x_obj, glist) + 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);
+ t_canvas *canvas=glist_getcanvas(glist);
SYS_VGUI5(".x%lx.c delete %xEVENT%.4d%.4d\n", canvas, x, ix, iy );
}
static void exciter_draw_update(t_exciter *x, t_glist *glist)
{
- int ei, gi;
+ 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
+ for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ )
{
- exciter_delete_gem(x, glist, gi, ei );
+ 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;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int ei;
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #902181 -tags %xLINE\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height,
- x);
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height,
+ x);
SYS_VGUI5(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"0 s\" -tags %xLOWERCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height + 10, x );
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height + 10, x );
SYS_VGUI6(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"%.2f s\" -tags %xHIGHERCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height + 10,
- x->x_width/EXCITER_PIXEL_GRAIN*x->x_timegrain , x);
+ canvas, text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height + 10,
+ x->x_width/EXCITER_PIXEL_GRAIN*x->x_timegrain , x);
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xIN\n",
- canvas, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) - 2,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist) ,
- x);
+ canvas, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) - 2,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist) ,
+ x);
if ( x->x_nbevents > 1 )
{
- for ( ei=0; ei<x->x_nbevents; ei++ )
- {
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n",
- canvas, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2,
- x, ei);
- }
+ for ( ei=0; ei<x->x_nbevents; ei++ )
+ {
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n",
+ canvas, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1) + 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2,
+ x, ei);
+ }
}
else
{
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n",
- canvas, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2,
- x, 0);
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT%d\n",
+ canvas, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist) + 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;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int polyray = ( x->x_height / x->x_nbevents) / 2;
+ t_int ei, gi;
SYS_VGUI7(".x%lx.c coords %xLINE %d %d %d %d \n",
- canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height
- );
+ canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height
+ );
SYS_VGUI5(".x%lx.c coords %xLOWERCAPTION %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height + 10 );
+ canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height + 10 );
SYS_VGUI5(".x%lx.c coords %xHIGHERCAPTION %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height + 10);
+ canvas, x, text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height + 10);
SYS_VGUI7(".x%lx.c coords %xIN %d %d %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) - 2,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist)
- );
+ canvas, x, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) - 2,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist)
+ );
if ( x->x_nbevents > 1 )
{
- for ( ei=0; ei<x->x_nbevents; ei++ )
- {
- SYS_VGUI8(".x%lx.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, ei, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2
- );
- }
+ for ( ei=0; ei<x->x_nbevents; ei++ )
+ {
+ SYS_VGUI8(".x%lx.c coords %xOUT%d %d %d %d %d\n",
+ canvas, x, ei, text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + ( ei * (x->x_width - 5) )/ (x->x_nbevents-1) + 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2
+ );
+ }
}
else
{
- SYS_VGUI8(".x%lx.c coords %xOUT%d %d %d %d %d\n",
- canvas, x, 0, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2
- );
+ SYS_VGUI8(".x%lx.c coords %xOUT%d %d %d %d %d\n",
+ canvas, x, 0, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist) + 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%lx.c coords %xEVENT%.4d%.4d %d %d %d %d %d %d %d %d\n",
- canvas, x, gi, ei,
- text_xpix(&x->x_obj, glist) + gi*EXCITER_PIXEL_GRAIN,
- text_ypix(&x->x_obj, glist) + x->x_height - (ei+1)*x->x_height/x->x_nbevents + 2*polyray,
- text_xpix(&x->x_obj, glist) + gi*EXCITER_PIXEL_GRAIN + polyray,
- text_ypix(&x->x_obj, glist) + x->x_height - (ei+1)*x->x_height/x->x_nbevents + polyray,
- text_xpix(&x->x_obj, glist) + gi*EXCITER_PIXEL_GRAIN + 2*polyray,
- text_ypix(&x->x_obj, glist) + x->x_height - (ei+1)*x->x_height/x->x_nbevents,
- text_xpix(&x->x_obj, glist) + gi*EXCITER_PIXEL_GRAIN + polyray,
- text_ypix(&x->x_obj, glist) + x->x_height - (ei+1)*x->x_height/x->x_nbevents - polyray
- );
- }
+ for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ )
+ {
+ SYS_VGUI13(".x%lx.c coords %xEVENT%.4d%.4d %d %d %d %d %d %d %d %d\n",
+ canvas, x, gi, ei,
+ text_xpix(&x->x_obj, glist) + gi*EXCITER_PIXEL_GRAIN,
+ text_ypix(&x->x_obj, glist) + x->x_height - (ei+1)*x->x_height/x->x_nbevents + 2*polyray,
+ text_xpix(&x->x_obj, glist) + gi*EXCITER_PIXEL_GRAIN + polyray,
+ text_ypix(&x->x_obj, glist) + x->x_height - (ei+1)*x->x_height/x->x_nbevents + polyray,
+ text_xpix(&x->x_obj, glist) + gi*EXCITER_PIXEL_GRAIN + 2*polyray,
+ text_ypix(&x->x_obj, glist) + x->x_height - (ei+1)*x->x_height/x->x_nbevents,
+ text_xpix(&x->x_obj, glist) + gi*EXCITER_PIXEL_GRAIN + polyray,
+ text_ypix(&x->x_obj, glist) + 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;
+ t_canvas *canvas=glist_getcanvas(glist);
+ int i, ei, gi;
SYS_VGUI3(".x%lx.c delete %xLINE\n", canvas, x );
SYS_VGUI3(".x%lx.c delete %xLOWERCAPTION\n", canvas, x );
@@ -273,31 +273,31 @@ static void exciter_draw_erase(t_exciter* x,t_glist* glist)
SYS_VGUI3(".x%lx.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 )
+ for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ )
{
- exciter_delete_gem( x, glist, gi, ei );
+ if( *(x->x_sbangs+ei*(x->x_width/EXCITER_PIXEL_GRAIN)+gi) != 0 )
+ {
+ exciter_delete_gem( x, glist, gi, ei );
+ }
}
- }
- SYS_VGUI4(".x%lx.c delete %xOUT%d\n", canvas, x, ei );
+ SYS_VGUI4(".x%lx.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);
+ t_canvas *canvas=glist_getcanvas(glist);
if(x->x_selected)
{
/* sets the main item in blue */
- SYS_VGUI3(".x%lx.c itemconfigure %xLINE -outline #0000FF\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xLINE -outline #0000FF\n", canvas, x);
}
else
{
/* sets the main item in black */
- SYS_VGUI3(".x%lx.c itemconfigure %xLINE -outline #000000\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xLINE -outline #000000\n", canvas, x);
}
}
@@ -305,185 +305,186 @@ static void exciter_draw_select(t_exciter* x,t_glist* glist)
static void exciter_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_exciter* x = (t_exciter*)z;
+ t_exciter* x = (t_exciter*)z;
- *xp1 = text_xpix(&x->x_obj, owner);
- *yp1 = text_ypix(&x->x_obj, owner);
- *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, owner);
+ *yp1 = text_ypix(&x->x_obj, owner);
+ *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, owner)+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,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- 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++ )
+ 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,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ 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++ )
{
- 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 );
- }
+ 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, ";");
+ }
+ binbuf_addv(b, ";");
}
static void exciter_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_exciter *x=(t_exciter *)z;
+ char buf[800];
+ t_exciter *x=(t_exciter *)z;
- sprintf(buf, "pdtk_exciter_dialog %%s %d %d %d %.2f %d %d\n",
+ 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);
+ // 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;
+ t_exciter *x = (t_exciter *)z;
- x->x_selected = selected;
- exciter_draw_select( x, glist );
+ 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;
-
- post("exciter_vis : %d", vis );
- if (vis)
- {
- exciter_draw_new( x, glist );
- exciter_draw_update( x, glist );
- }
- else
- {
- exciter_draw_erase( x, glist );
- }
+ t_exciter *x = (t_exciter *)z;
+
+ 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 */
+/* resuming the triggering of events */
static void exciter_resume(t_exciter *x)
{
- x->x_started = 1;
+ x->x_started = 1;
}
- /* pausing the triggering of events */
+/* pausing the triggering of events */
static void exciter_pause(t_exciter *x)
{
- x->x_started = 0;
+ x->x_started = 0;
}
- /* trigger events -- no dsp processing */
+/* 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;
+ 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 );
- }
+ 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) );
+ 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++ )
+ }
+
+ // re-allocate outlets
+ post( "exciter : re-allocate outlets" );
+ if ( onbevents != x->x_nbevents )
+ {
+ post( "exciter : cleaning up old outlets" );
+ if ( x->x_bangs )
{
- outlet_free( x->x_bangs[ei] );
+ for ( ei=0; ei<onbevents; ei++ )
+ {
+ outlet_free( x->x_bangs[ei] );
+ }
+ freebytes( x->x_bangs, onbevents*sizeof(t_outlet*) );
}
- 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 );
+ 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)
@@ -493,9 +494,9 @@ static void exciter_delete(t_gobj *z, t_glist *glist)
static void exciter_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
- t_exciter *x = (t_exciter *)z;
- t_int xold = text_xpix(&x->x_obj, glist);
- t_int yold = text_ypix(&x->x_obj, glist);
+ t_exciter *x = (t_exciter *)z;
+ t_int xold = text_xpix(&x->x_obj, glist);
+ t_int yold = text_ypix(&x->x_obj, glist);
// post( "exciter_displace dx=%d dy=%d", dx, dy );
@@ -503,81 +504,81 @@ static void exciter_displace(t_gobj *z, t_glist *glist, int dx, int dy)
x->x_obj.te_ypix += dy;
if(xold != text_xpix(&x->x_obj, glist) || yold != text_ypix(&x->x_obj, glist))
{
- exciter_draw_move(x, glist);
+ exciter_draw_move(x, glist);
}
}
static int exciter_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
- t_exciter* x = (t_exciter *)z;
- t_int nevent, npix;
+ t_exciter* x = (t_exciter *)z;
+ t_int nevent, npix;
- if ( doit)
+ if ( doit)
{
- nevent = ( 1 - ( ( ypix - ( (float)x->x_height / (float) x->x_nbevents / 2 )
- - text_ypix(&x->x_obj, glist)) / (float)x->x_height ) )*(x->x_nbevents-1);
- npix = ( xpix - 1 - text_xpix(&x->x_obj, glist)) / 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 );
- }
- }
+ nevent = ( 1 - ( ( ypix - ( (float)x->x_height / (float) x->x_nbevents / 2 )
+ - text_ypix(&x->x_obj, glist)) / (float)x->x_height ) )*(x->x_nbevents-1);
+ npix = ( xpix - 1 - text_xpix(&x->x_obj, glist)) / 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;
-
+ 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);
x->x_glist = (t_glist *) canvas_getcurrent();
- // new exciter created from the gui
+ // 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;
+ 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;
+ 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;
}
@@ -585,38 +586,38 @@ static t_exciter *exciter_new(t_symbol *s, int argc, t_atom *argv)
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;
- }
+ 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_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_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 );
+ 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;
- }
+ 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 );
@@ -625,139 +626,139 @@ static t_exciter *exciter_new(t_symbol *s, int argc, t_atom *argv)
static void exciter_dump(t_exciter *x)
{
- t_int ei, gi;
+ 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 )
+ for ( ei=0; ei<x->x_nbevents; ei++ )
+ {
+ for ( gi=0; gi<(x->x_width/EXCITER_PIXEL_GRAIN); gi++ )
{
- post( "exciter : value ( %d, %d ) : %d", ei, 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 */
+/* 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 );
+ 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 */
+/* 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;
+ x->x_started = 1;
+ x->x_reltime = 0L;
+ x->x_plooptime = 0L;
+ x->x_gindex = -1;
}
- /* stop the triggering of events */
+/* stop the triggering of events */
static void exciter_stop(t_exciter *x)
{
- x->x_started = 0;
+ x->x_started = 0;
}
- /* reset the triggering of events */
+/* reset the triggering of events */
static void exciter_reset(t_exciter *x)
{
- x->x_reltime = 0L;
- x->x_plooptime = 0L;
- x->x_gindex = -1;
+ 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;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ 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;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
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%lx.c itemconfigure %xEVENT%.4d%.4d -fill #00FF00\n",
- canvas, x, gi, ei);
- }
- }
- }
- // unfocus previous events
- if ( gstart >= x->x_width/EXCITER_PIXEL_GRAIN - 1)
+ // 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%lx.c itemconfigure %xEVENT%.4d%.4d -fill #00FF00\n",
+ canvas, 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%lx.c itemconfigure %xEVENT%.4d%.4d -fill #FFFFFF\n",
- canvas, x, gi, ei);
- }
- }
- }
- x->x_gindex = gend;
- }
+ // 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%lx.c itemconfigure %xEVENT%.4d%.4d -fill #FFFFFF\n",
+ canvas, x, gi, ei);
+ }
+ }
+ }
+ x->x_gindex = gend;
+ }
}
-
+
x->x_plooptime = looptime;
return (w+2);
}
@@ -769,28 +770,28 @@ static void exciter_dsp(t_exciter *x, t_signal **sp)
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) );
- }
+ 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)
{
verbose(0, exciter_version );
exciter_class = class_new(gensym("exciter"), (t_newmethod)exciter_new,
- (t_method)exciter_free, sizeof(t_exciter), 0, A_GIMME, 0);
+ (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);
diff --git a/filterbank~.c b/filterbank~.c
index 37d40c9..4fab001 100644
--- a/filterbank~.c
+++ b/filterbank~.c
@@ -126,44 +126,44 @@ static void miller_sigbp_docoef(t_filterbank_tilde *x, t_int index, t_floatarg f
static void filterbank_draw_new(t_filterbank_tilde *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- int fi;
-
- // draw the square
- {
-
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xFILTERBANK\n",
- canvas,
- text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width,
- text_ypix(&x->x_obj, glist) + x->x_height,
- x);
-
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #000000 -tags %xSIN\n",
- canvas,
- text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist)-1,
- text_xpix(&x->x_obj, glist)+7,
- text_ypix(&x->x_obj, glist),
- x);
-
- for ( fi=0; fi<x->x_nbfilters; fi++ )
- {
- char color[8];
-
- sprintf( color, "#%.2x%.2x%.2x", (int)random() % 256, (int)random() % 256, (int)random() % 256 );
-
- SYS_VGUI11(".x%lx.c create polygon %d %d %d %d %d %d -outline #000000 -fill %s -tags %xFILTER%d\n",
- canvas,
- text_xpix(&x->x_obj, glist) + fi*x->x_width/x->x_nbfilters,
- text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + fi*x->x_width/x->x_nbfilters + x->x_width/(2*x->x_nbfilters),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + (fi+1)*x->x_width/x->x_nbfilters,
- text_ypix(&x->x_obj, glist),
- color, x, fi);
- }
+ t_canvas *canvas=glist_getcanvas(glist);
+ int fi;
+
+ // draw the square
+ {
+
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xFILTERBANK\n",
+ canvas,
+ text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width,
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ x);
+
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #000000 -tags %xSIN\n",
+ canvas,
+ text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist)-1,
+ text_xpix(&x->x_obj, glist)+7,
+ text_ypix(&x->x_obj, glist),
+ x);
+
+ for ( fi=0; fi<x->x_nbfilters; fi++ )
+ {
+ char color[8];
+
+ sprintf( color, "#%.2x%.2x%.2x", (int)random() % 256, (int)random() % 256, (int)random() % 256 );
+
+ SYS_VGUI11(".x%lx.c create polygon %d %d %d %d %d %d -outline #000000 -fill %s -tags %xFILTER%d\n",
+ canvas,
+ text_xpix(&x->x_obj, glist) + fi*x->x_width/x->x_nbfilters,
+ text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + fi*x->x_width/x->x_nbfilters + x->x_width/(2*x->x_nbfilters),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + (fi+1)*x->x_width/x->x_nbfilters,
+ text_ypix(&x->x_obj, glist),
+ color, x, fi);
+ }
}
canvas_fixlinesfor( canvas, (t_text*)x );
@@ -175,32 +175,32 @@ static void filterbank_draw_move(t_filterbank_tilde *x, t_glist *glist)
t_int fi;
SYS_VGUI7(".x%lx.c coords %xFILTERBANK %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width,
- text_ypix(&x->x_obj, glist) + x->x_height
+ canvas, x,
+ text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width,
+ text_ypix(&x->x_obj, glist) + x->x_height
);
SYS_VGUI7(".x%lx.c coords %xSIN %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist)-1,
- text_xpix(&x->x_obj, glist)+7,
- text_ypix(&x->x_obj, glist)
+ canvas, x,
+ text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist)-1,
+ text_xpix(&x->x_obj, glist)+7,
+ text_ypix(&x->x_obj, glist)
);
for ( fi=0; fi<x->x_nbfilters; fi++ )
{
- SYS_VGUI10(".x%lx.c coords %xFILTER%d %d %d %d %d %d %d\n",
- canvas, x, fi,
- text_xpix(&x->x_obj, glist) + fi*x->x_width/x->x_nbfilters,
- text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + fi*x->x_width/x->x_nbfilters + x->x_width/(2*x->x_nbfilters),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + (fi+1)*x->x_width/x->x_nbfilters,
- text_ypix(&x->x_obj, glist)
- );
+ SYS_VGUI10(".x%lx.c coords %xFILTER%d %d %d %d %d %d %d\n",
+ canvas, x, fi,
+ text_xpix(&x->x_obj, glist) + fi*x->x_width/x->x_nbfilters,
+ text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + fi*x->x_width/x->x_nbfilters + x->x_width/(2*x->x_nbfilters),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + (fi+1)*x->x_width/x->x_nbfilters,
+ text_ypix(&x->x_obj, glist)
+ );
}
canvas_fixlinesfor( canvas, (t_text*)x );
@@ -208,14 +208,14 @@ static void filterbank_draw_move(t_filterbank_tilde *x, t_glist *glist)
static void filterbank_draw_erase(t_filterbank_tilde* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- int fi;
-
+ t_canvas *canvas=glist_getcanvas(glist);
+ int fi;
+
SYS_VGUI3(".x%lx.c delete %xFILTERBANK\n", canvas, x );
SYS_VGUI3(".x%lx.c delete %xSIN\n", canvas, x );
for ( fi=0; fi<x->x_nbfilters; fi++ )
{
- SYS_VGUI4(".x%lx.c delete %xFILTER%d\n", canvas, x, fi );
+ SYS_VGUI4(".x%lx.c delete %xFILTER%d\n", canvas, x, fi );
}
}
@@ -227,11 +227,11 @@ static void filterbank_draw_select(t_filterbank_tilde* x,t_glist* glist)
if(x->x_selected)
{
/* sets the item in blue */
- SYS_VGUI3(".x%lx.c itemconfigure %xFILTERBANK -outline #0000FF\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xFILTERBANK -outline #0000FF\n", canvas, x);
}
else
{
- SYS_VGUI3(".x%lx.c itemconfigure %xFILTERBANK -outline #000000\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xFILTERBANK -outline #000000\n", canvas, x);
}
}
@@ -239,152 +239,154 @@ static void filterbank_draw_select(t_filterbank_tilde* x,t_glist* glist)
static void filterbank_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_filterbank_tilde* x = (t_filterbank_tilde*)z;
+ t_filterbank_tilde* x = (t_filterbank_tilde*)z;
- *xp1 = text_xpix(&x->x_obj, owner);
- *yp1 = text_ypix(&x->x_obj, owner);
- *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, owner);
+ *yp1 = text_ypix(&x->x_obj, owner);
+ *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
}
static void filterbank_save(t_gobj *z, t_binbuf *b)
{
- t_filterbank_tilde *x = (t_filterbank_tilde *)z;
- t_int ii;
+ t_filterbank_tilde *x = (t_filterbank_tilde *)z;
+ t_int ii;
- binbuf_addv(b, "ssiisiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_lowfreq, x->x_highfreq,
+ binbuf_addv(b, "ssiisiii", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_lowfreq, x->x_highfreq,
x->x_nbfilters );
- binbuf_addv(b, ";");
+ binbuf_addv(b, ";");
}
static void filterbank_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_filterbank_tilde *x=(t_filterbank_tilde *)z;
+ char buf[800];
+ t_filterbank_tilde *x=(t_filterbank_tilde *)z;
- sprintf(buf, "pdtk_filterbank_dialog %%s %d %d\n",
+ sprintf(buf, "pdtk_filterbank_dialog %%s %d %d\n",
x->x_lowfreq, x->x_highfreq );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
static void filterbank_select(t_gobj *z, t_glist *glist, int selected)
{
- t_filterbank_tilde *x = (t_filterbank_tilde *)z;
+ t_filterbank_tilde *x = (t_filterbank_tilde *)z;
- x->x_selected = selected;
- filterbank_draw_select( x, glist );
+ x->x_selected = selected;
+ filterbank_draw_select( x, glist );
}
static void filterbank_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_filterbank_tilde *x = (t_filterbank_tilde *)z;
-
- // post( "filterbank~ : vis : %d", vis );
- if (vis)
- {
- filterbank_draw_new( x, glist );
- }
- else
- {
- filterbank_draw_erase( x, glist );
- }
+ t_filterbank_tilde *x = (t_filterbank_tilde *)z;
+
+ // post( "filterbank~ : vis : %d", vis );
+ if (vis)
+ {
+ filterbank_draw_new( x, glist );
+ }
+ else
+ {
+ filterbank_draw_erase( x, glist );
+ }
}
static void filterbank_dialog(t_filterbank_tilde *x, t_symbol *s, int argc, t_atom *argv)
{
- t_int olowfreq = x->x_lowfreq;
- t_int ohighfreq = x->x_highfreq;
- t_int fi, ei;
- t_int dspstate;
- t_float Q;
- t_float afreq, abandwidth;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- // !!paranoid
- if ( !x ) {
- post( "filterbank~ : error :tried to set properties on an unexisting object" );
- }
- if ( argc != 2 )
- {
- post( "filterbank : error in the number of arguments ( %d instead of 2 )", argc );
- return;
- }
- if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT ) {
- post( "filterbank~ : wrong arguments" );
- return;
- }
-
- x->x_allocate = 1;
- x->x_lowfreq = (int)argv[0].a_w.w_float;
- if ( x->x_lowfreq < 0 ) x->x_lowfreq = 0;
- x->x_highfreq = (int)argv[1].a_w.w_float;
- if ( x->x_highfreq < x->x_lowfreq ) x->x_highfreq = x->x_lowfreq + 100;
-
- // recalculate filters if needed
- if ( ( olowfreq != x->x_lowfreq ) || ( ohighfreq != x->x_highfreq ) )
- {
- // free filters
- if ( x->x_freq )
- {
- freebytes( x->x_freq, x->x_nbfilters*sizeof(t_float) );
- }
- if ( x->x_q )
- {
- freebytes( x->x_q, x->x_nbfilters*sizeof(t_float) );
- }
- if ( x->x_cspace )
- {
- freebytes( x->x_cspace, x->x_nbfilters*sizeof(t_bpctl) );
- }
- if ( x->x_ctl )
- {
- freebytes( x->x_ctl, x->x_nbfilters*sizeof(t_bpctl*) );
- }
- // create filters
- x->x_freq = (t_float *) getbytes( x->x_nbfilters*sizeof(t_float) );
- x->x_q = (t_float *) getbytes( x->x_nbfilters*sizeof(t_float) );
- x->x_cspace = (t_bpctl *) getbytes( x->x_nbfilters*sizeof(t_bpctl) );
- x->x_ctl = (t_bpctl **) getbytes( x->x_nbfilters*sizeof(t_bpctl*) );
- if ( !x->x_freq || !x->x_q || !x->x_cspace || !x->x_ctl )
- {
- post( "filterbank~ : could not allocate filters" );
- return;
- }
- abandwidth = ( x->x_highfreq - x->x_lowfreq ) / x->x_nbfilters;
- afreq = x->x_lowfreq + ( abandwidth / 2 );
- for ( fi=0; fi<x->x_nbfilters; fi++ )
- {
- x->x_ctl[fi] = &x->x_cspace[fi];
- x->x_cspace[fi].c_x1 = 0;
- x->x_cspace[fi].c_x2 = 0;
- Q = ( (t_float) afreq )/ ( (t_float) abandwidth );
- miller_sigbp_docoef( x, fi, afreq, Q );
- afreq += abandwidth;
- }
- }
-
- x->x_allocate = 0;
+ t_int olowfreq = x->x_lowfreq;
+ t_int ohighfreq = x->x_highfreq;
+ t_int fi, ei;
+ t_int dspstate;
+ t_float Q;
+ t_float afreq, abandwidth;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ // !!paranoid
+ if ( !x )
+ {
+ post( "filterbank~ : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 2 )
+ {
+ post( "filterbank : error in the number of arguments ( %d instead of 2 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT )
+ {
+ post( "filterbank~ : wrong arguments" );
+ return;
+ }
+
+ x->x_allocate = 1;
+ x->x_lowfreq = (int)argv[0].a_w.w_float;
+ if ( x->x_lowfreq < 0 ) x->x_lowfreq = 0;
+ x->x_highfreq = (int)argv[1].a_w.w_float;
+ if ( x->x_highfreq < x->x_lowfreq ) x->x_highfreq = x->x_lowfreq + 100;
+
+ // recalculate filters if needed
+ if ( ( olowfreq != x->x_lowfreq ) || ( ohighfreq != x->x_highfreq ) )
+ {
+ // free filters
+ if ( x->x_freq )
+ {
+ freebytes( x->x_freq, x->x_nbfilters*sizeof(t_float) );
+ }
+ if ( x->x_q )
+ {
+ freebytes( x->x_q, x->x_nbfilters*sizeof(t_float) );
+ }
+ if ( x->x_cspace )
+ {
+ freebytes( x->x_cspace, x->x_nbfilters*sizeof(t_bpctl) );
+ }
+ if ( x->x_ctl )
+ {
+ freebytes( x->x_ctl, x->x_nbfilters*sizeof(t_bpctl*) );
+ }
+ // create filters
+ x->x_freq = (t_float *) getbytes( x->x_nbfilters*sizeof(t_float) );
+ x->x_q = (t_float *) getbytes( x->x_nbfilters*sizeof(t_float) );
+ x->x_cspace = (t_bpctl *) getbytes( x->x_nbfilters*sizeof(t_bpctl) );
+ x->x_ctl = (t_bpctl **) getbytes( x->x_nbfilters*sizeof(t_bpctl*) );
+ if ( !x->x_freq || !x->x_q || !x->x_cspace || !x->x_ctl )
+ {
+ post( "filterbank~ : could not allocate filters" );
+ return;
+ }
+ abandwidth = ( x->x_highfreq - x->x_lowfreq ) / x->x_nbfilters;
+ afreq = x->x_lowfreq + ( abandwidth / 2 );
+ for ( fi=0; fi<x->x_nbfilters; fi++ )
+ {
+ x->x_ctl[fi] = &x->x_cspace[fi];
+ x->x_cspace[fi].c_x1 = 0;
+ x->x_cspace[fi].c_x2 = 0;
+ Q = ( (t_float) afreq )/ ( (t_float) abandwidth );
+ miller_sigbp_docoef( x, fi, afreq, Q );
+ afreq += abandwidth;
+ }
+ }
+
+ x->x_allocate = 0;
}
static void filterbank_delete(t_gobj *z, t_glist *glist)
{
- t_filterbank_tilde *x = (t_filterbank_tilde *)z;
+ t_filterbank_tilde *x = (t_filterbank_tilde *)z;
- // post( "filterbank~ : delete" );
- filterbank_draw_erase( x, glist );
- canvas_deletelinesfor(glist, (t_text *)z);
+ // post( "filterbank~ : delete" );
+ filterbank_draw_erase( x, glist );
+ canvas_deletelinesfor(glist, (t_text *)z);
}
static void filterbank_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
- t_filterbank_tilde *x = (t_filterbank_tilde *)z;
- int xold = text_xpix(&x->x_obj, glist);
- int yold = text_ypix(&x->x_obj, glist);
+ t_filterbank_tilde *x = (t_filterbank_tilde *)z;
+ int xold = text_xpix(&x->x_obj, glist);
+ int yold = text_ypix(&x->x_obj, glist);
// post( "filterbank_displace dx=%d dy=%d", dx, dy );
@@ -392,31 +394,36 @@ static void filterbank_displace(t_gobj *z, t_glist *glist, int dx, int dy)
x->x_obj.te_ypix += dy;
if(xold != text_xpix(&x->x_obj, glist) || yold != text_ypix(&x->x_obj, glist) )
{
- filterbank_draw_move(x, x->x_glist);
+ filterbank_draw_move(x, x->x_glist);
}
}
static void filterbank_randomize(t_filterbank_tilde *x, t_floatarg fflag )
{
- t_int shind, tmpi, fi;
-
- if ( fflag != 0.0 && fflag != 1.0 ) {
- post( "filterbank~ : wrong argument in randomize message : should be 0 or 1" );
- return;
- } else if ( fflag == 1 ) {
- for ( fi=0; fi<x->x_nbfilters; fi++ )
- {
- shind = rand() % x->x_nbfilters;
- tmpi = x->x_outmapping[ shind ];
- x->x_outmapping[ shind ] = x->x_outmapping[ fi ];
- x->x_outmapping[ fi ] = tmpi;
- }
- } else {
- for ( fi=0; fi<x->x_nbfilters; fi++ )
- {
- x->x_outmapping[ fi ] = fi;
- }
+ t_int shind, tmpi, fi;
+
+ if ( fflag != 0.0 && fflag != 1.0 )
+ {
+ post( "filterbank~ : wrong argument in randomize message : should be 0 or 1" );
+ return;
+ }
+ else if ( fflag == 1 )
+ {
+ for ( fi=0; fi<x->x_nbfilters; fi++ )
+ {
+ shind = rand() % x->x_nbfilters;
+ tmpi = x->x_outmapping[ shind ];
+ x->x_outmapping[ shind ] = x->x_outmapping[ fi ];
+ x->x_outmapping[ fi ] = tmpi;
+ }
+ }
+ else
+ {
+ for ( fi=0; fi<x->x_nbfilters; fi++ )
+ {
+ x->x_outmapping[ fi ] = fi;
+ }
}
}
@@ -427,38 +434,39 @@ static t_filterbank_tilde *filterbank_new(t_symbol *s, int argc, t_atom *argv)
char *str;
t_float Q;
t_float afreq, abandwidth;
-
+
x = (t_filterbank_tilde *)pd_new(filterbank_class_tilde);
x->x_samplerate = (int)sys_getsr();
x->x_sr = 44100;
- // new filterbank created from the gui
+ // new filterbank created from the gui
if ( argc != 0 )
{
- if ( argc != 3 )
- {
- post( "filterbank~ : 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 ) {
- post( "filterbank~ : wrong arguments" );
- return NULL;
- }
+ if ( argc != 3 )
+ {
+ post( "filterbank~ : 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 )
+ {
+ post( "filterbank~ : wrong arguments" );
+ return NULL;
+ }
- x->x_lowfreq = (int)argv[0].a_w.w_float;
- if ( x->x_lowfreq < 0 ) x->x_lowfreq = 0;
- x->x_highfreq = (int)argv[1].a_w.w_float;
- if ( x->x_highfreq < x->x_lowfreq ) x->x_highfreq = x->x_lowfreq + 100;
- x->x_nbfilters = (int)argv[2].a_w.w_float;
- if ( x->x_nbfilters < 1 ) x->x_nbfilters = 1;
+ x->x_lowfreq = (int)argv[0].a_w.w_float;
+ if ( x->x_lowfreq < 0 ) x->x_lowfreq = 0;
+ x->x_highfreq = (int)argv[1].a_w.w_float;
+ if ( x->x_highfreq < x->x_lowfreq ) x->x_highfreq = x->x_lowfreq + 100;
+ x->x_nbfilters = (int)argv[2].a_w.w_float;
+ if ( x->x_nbfilters < 1 ) x->x_nbfilters = 1;
}
else
{
- x->x_lowfreq = DEFAULT_FILTERBANK_LOWFREQ;
- x->x_highfreq = DEFAULT_FILTERBANK_HIGHFREQ;
- x->x_nbfilters = DEFAULT_FILTERBANK_NBFILTERS;
+ x->x_lowfreq = DEFAULT_FILTERBANK_LOWFREQ;
+ x->x_highfreq = DEFAULT_FILTERBANK_HIGHFREQ;
+ x->x_nbfilters = DEFAULT_FILTERBANK_NBFILTERS;
}
// post( "filterbank~ : new [ %d,%d ] with %d filters", x->x_lowfreq, x->x_highfreq, x->x_nbfilters );
@@ -467,34 +475,34 @@ static t_filterbank_tilde *filterbank_new(t_symbol *s, int argc, t_atom *argv)
x->x_outputs = (t_outlet **) getbytes( x->x_nbfilters*sizeof(t_outlet *) );
if ( !x->x_outputs )
{
- post( "filterbank~ : could not allocate outputs" );
- return NULL;
+ post( "filterbank~ : could not allocate outputs" );
+ return NULL;
}
for ( fi=0; fi<x->x_nbfilters; fi++ )
{
- x->x_outputs[fi] = outlet_new( &x->x_obj, &s_signal );
+ x->x_outputs[fi] = outlet_new( &x->x_obj, &s_signal );
}
- // create filters
+ // create filters
x->x_freq = (t_float *) getbytes( x->x_nbfilters*sizeof(t_float) );
x->x_q = (t_float *) getbytes( x->x_nbfilters*sizeof(t_float) );
x->x_cspace = (t_bpctl *) getbytes( x->x_nbfilters*sizeof(t_bpctl) );
x->x_ctl = (t_bpctl **) getbytes( x->x_nbfilters*sizeof(t_bpctl*) );
if ( !x->x_freq || !x->x_q || !x->x_cspace || !x->x_ctl )
{
- post( "filterbank~ : could not allocate filters" );
- return NULL;
+ post( "filterbank~ : could not allocate filters" );
+ return NULL;
}
abandwidth = ( x->x_highfreq - x->x_lowfreq ) / x->x_nbfilters;
afreq = x->x_lowfreq + ( abandwidth / 2 );
for ( fi=0; fi<x->x_nbfilters; fi++ )
{
- x->x_ctl[fi] = &x->x_cspace[fi];
- x->x_cspace[fi].c_x1 = 0;
- x->x_cspace[fi].c_x2 = 0;
- Q = ( (t_float) afreq ) / ( (t_float) abandwidth );
- miller_sigbp_docoef( x, fi, afreq, Q );
- afreq += abandwidth;
+ x->x_ctl[fi] = &x->x_cspace[fi];
+ x->x_cspace[fi].c_x1 = 0;
+ x->x_cspace[fi].c_x2 = 0;
+ Q = ( (t_float) afreq ) / ( (t_float) abandwidth );
+ miller_sigbp_docoef( x, fi, afreq, Q );
+ afreq += abandwidth;
}
x->x_width = x->x_nbfilters*FILTERBANK_OUTLET_WIDTH*2;
@@ -506,48 +514,48 @@ static t_filterbank_tilde *filterbank_new(t_symbol *s, int argc, t_atom *argv)
x->x_outmapping = (t_int*) getbytes( x->x_nbfilters*sizeof( t_int ) );
if ( !x->x_outmapping )
{
- post( "filterbank~ : cannot allocate mapping array" );
- return NULL; // otherwise, pd schrieks
+ post( "filterbank~ : cannot allocate mapping array" );
+ return NULL; // otherwise, pd schrieks
}
for ( fi=0; fi<x->x_nbfilters; fi++ )
{
- x->x_outmapping[fi] = fi;
+ x->x_outmapping[fi] = fi;
}
return (x);
}
static void filterbank_free(t_filterbank_tilde *x)
{
- t_int ei, fi;
-
- if ( x->x_outputs )
- {
- for ( ei=0; ei<x->x_nbfilters; ei++ )
- {
- outlet_free( x->x_outputs[ei] );
- }
- freebytes( x->x_outputs, x->x_nbfilters*sizeof(t_outlet*) );
- }
- if ( x->x_freq )
- {
- freebytes( x->x_freq, x->x_nbfilters*sizeof(t_float) );
- }
- if ( x->x_q )
- {
- freebytes( x->x_q, x->x_nbfilters*sizeof(t_float) );
- }
- if ( x->x_cspace )
- {
- freebytes( x->x_cspace, x->x_nbfilters*sizeof(t_bpctl) );
- }
- if ( x->x_ctl )
- {
- freebytes( x->x_ctl, x->x_nbfilters*sizeof(t_bpctl*) );
- }
- if ( x->x_outmapping )
- {
- freebytes( x->x_outmapping, x->x_nbfilters*sizeof(t_int) );
- }
+ t_int ei, fi;
+
+ if ( x->x_outputs )
+ {
+ for ( ei=0; ei<x->x_nbfilters; ei++ )
+ {
+ outlet_free( x->x_outputs[ei] );
+ }
+ freebytes( x->x_outputs, x->x_nbfilters*sizeof(t_outlet*) );
+ }
+ if ( x->x_freq )
+ {
+ freebytes( x->x_freq, x->x_nbfilters*sizeof(t_float) );
+ }
+ if ( x->x_q )
+ {
+ freebytes( x->x_q, x->x_nbfilters*sizeof(t_float) );
+ }
+ if ( x->x_cspace )
+ {
+ freebytes( x->x_cspace, x->x_nbfilters*sizeof(t_bpctl) );
+ }
+ if ( x->x_ctl )
+ {
+ freebytes( x->x_ctl, x->x_nbfilters*sizeof(t_bpctl*) );
+ }
+ if ( x->x_outmapping )
+ {
+ freebytes( x->x_outmapping, x->x_nbfilters*sizeof(t_int) );
+ }
}
static t_int *filterbank_perform(t_int *w)
@@ -558,8 +566,8 @@ static t_int *filterbank_perform(t_int *w)
t_float *in, *out;
int i;
t_float last, prev, coef1, coef2, gain;
- t_float *acopy;
- t_int noneedtofilter = 1;
+ t_float *acopy;
+ t_int noneedtofilter = 1;
in = (t_float*)w[3];
@@ -567,51 +575,53 @@ static t_int *filterbank_perform(t_int *w)
acopy = (t_float*) getbytes( n*sizeof( t_float ) );
if ( !acopy )
{
- post( "filterbank~ : cannot allocate audio copy block" );
- return 0; // otherwise, pd schrieks
+ post( "filterbank~ : cannot allocate audio copy block" );
+ return 0; // otherwise, pd schrieks
}
memcpy( acopy, in, n*sizeof(t_float) );
for ( i=0; i<n; i++ )
{
- if ( *(acopy+i) != 0.0 ) noneedtofilter = 0;
+ if ( *(acopy+i) != 0.0 ) noneedtofilter = 0;
}
if ( !noneedtofilter )
{
- for ( fi=0; fi<x->x_nbfilters; fi++ )
- {
- out = (t_float *)(w[x->x_outmapping[fi]+4]);
-
- last = x->x_ctl[fi]->c_x1;
- prev = x->x_ctl[fi]->c_x2;
- coef1 = x->x_ctl[fi]->c_coef1;
- coef2 = x->x_ctl[fi]->c_coef2;
- gain = x->x_ctl[fi]->c_gain;
- for (i=0; i < n; i++)
+ for ( fi=0; fi<x->x_nbfilters; fi++ )
{
- float output = *(acopy+i) + coef1 * last + coef2 * prev;
- *out++ = gain * output;
- prev = last;
- last = output;
- }
+ out = (t_float *)(w[x->x_outmapping[fi]+4]);
+
+ last = x->x_ctl[fi]->c_x1;
+ prev = x->x_ctl[fi]->c_x2;
+ coef1 = x->x_ctl[fi]->c_coef1;
+ coef2 = x->x_ctl[fi]->c_coef2;
+ gain = x->x_ctl[fi]->c_gain;
+ for (i=0; i < n; i++)
+ {
+ float output = *(acopy+i) + coef1 * last + coef2 * prev;
+ *out++ = gain * output;
+ prev = last;
+ last = output;
+ }
/* NAN protect */
- if (!((last <= 0) || (last >= 0)))
- last = 0;
- if (!((prev <= 0) || (prev >= 0)))
- prev = 0;
- x->x_ctl[fi]->c_x1 = last;
- x->x_ctl[fi]->c_x2 = prev;
- }
- } else {
- for ( fi=0; fi<x->x_nbfilters; fi++ )
- {
- out = (t_float *)(w[x->x_outmapping[fi]+4]);
- for (i=0; i < n; i++)
+ if (!((last <= 0) || (last >= 0)))
+ last = 0;
+ if (!((prev <= 0) || (prev >= 0)))
+ prev = 0;
+ x->x_ctl[fi]->c_x1 = last;
+ x->x_ctl[fi]->c_x2 = prev;
+ }
+ }
+ else
+ {
+ for ( fi=0; fi<x->x_nbfilters; fi++ )
{
- *out++ = 0.0;
+ out = (t_float *)(w[x->x_outmapping[fi]+4]);
+ for (i=0; i < n; i++)
+ {
+ *out++ = 0.0;
+ }
}
- }
}
if ( acopy ) freebytes( acopy, n*sizeof(t_float) );
@@ -621,7 +631,7 @@ static t_int *filterbank_perform(t_int *w)
static void filterbank_dsp(t_filterbank_tilde *x, t_signal **sp)
{
- t_int *dspargs, fi, nbargs;
+ t_int *dspargs, fi, nbargs;
dspargs = (t_int*) getbytes( (x->x_nbfilters+3)*sizeof(t_int) );
@@ -632,10 +642,10 @@ static void filterbank_dsp(t_filterbank_tilde *x, t_signal **sp)
nbargs = 3;
for ( fi=0; fi<x->x_nbfilters; fi++ )
{
- dspargs[3+fi] = (t_int)sp[fi+1]->s_vec;
- nbargs++;
+ dspargs[3+fi] = (t_int)sp[fi+1]->s_vec;
+ nbargs++;
}
-
+
dsp_addv(filterbank_perform, nbargs, dspargs );
if ( dspargs ) freebytes( dspargs, (x->x_nbfilters+3)*sizeof(t_int) );
@@ -645,7 +655,7 @@ void filterbank_tilde_setup(void)
{
verbose(0, filterbank_version );
filterbank_class_tilde = class_new(gensym("filterbank~"), (t_newmethod)filterbank_new,
- (t_method)filterbank_free, sizeof(t_filterbank_tilde), 0, A_GIMME, 0);
+ (t_method)filterbank_free, sizeof(t_filterbank_tilde), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN( filterbank_class_tilde, t_filterbank_tilde, x_f );
class_addmethod(filterbank_class_tilde, (t_method)filterbank_dsp, gensym("dsp"), 0);
class_addmethod(filterbank_class_tilde, (t_method)filterbank_dialog, gensym("dialog"), A_GIMME, 0);
@@ -668,6 +678,6 @@ void filterbank_tilde_setup(void)
class_setwidget(filterbank_class_tilde, &filterbank_widgetbehavior);
sys_vgui("eval [read [open {%s/%s.tcl}]]\n",
- filterbank_class_tilde->c_externdir->s_name,
+ filterbank_class_tilde->c_externdir->s_name,
filterbank_class_tilde->c_name->s_name);
}
diff --git a/filters.c b/filters.c
index 2bf9253..64f079d 100644
--- a/filters.c
+++ b/filters.c
@@ -21,29 +21,29 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void lpc_filter(double *buf_ppf, double *lpc_coef, double *buf_sy, int n)
{
- int i,j;
- double acc;
-
- for(i=0;i<n;i++)
- {
- acc=buf_ppf[i]*lpc_coef[0];
- for(j=1;j<11;j++)
- {
- acc=acc-lpc_coef[j]*buf_sy[i-j];
- };
- buf_sy[i]=acc;
- };
+ int i,j;
+ double acc;
+
+ for(i=0; i<n; i++)
+ {
+ acc=buf_ppf[i]*lpc_coef[0];
+ for(j=1; j<11; j++)
+ {
+ acc=acc-lpc_coef[j]*buf_sy[i-j];
+ };
+ buf_sy[i]=acc;
+ };
}
void hp_filter(double *in,double cut,int n)
{
- int i;
- double prev_e,s_out;
- prev_e=s_out=0;
- for(i=0;i<n;i++)
- {
- s_out=in[i]-prev_e+cut*s_out;
- prev_e=in[i];
- in[i]=s_out;
- };
+ int i;
+ double prev_e,s_out;
+ prev_e=s_out=0;
+ for(i=0; i<n; i++)
+ {
+ s_out=in[i]-prev_e+cut*s_out;
+ prev_e=in[i];
+ in[i]=s_out;
+ };
}
diff --git a/formant~.c b/formant~.c
index 265d868..b2c2c33 100644
--- a/formant~.c
+++ b/formant~.c
@@ -70,44 +70,51 @@ typedef struct _formant
} t_formant;
- /* clean up */
-static void formant_free(t_formant *x)
+/* clean up */
+static void formant_free(t_formant *x)
{
- if ( x->x_data != NULL ) {
- freebytes(x->x_data, x->x_size*sizeof(float) );
- x->x_data = NULL;
+ if ( x->x_data != NULL )
+ {
+ freebytes(x->x_data, x->x_size*sizeof(float) );
+ x->x_data = NULL;
}
}
- /* generate sample data */
+/* generate sample data */
static t_int formant_gendata(t_formant *x)
{
t_float t, b, fs;
- if ( x->x_size <= 0 || x->x_central_freq <= 0 || x->x_filter_width <= 0 || x->x_skirt_width <= 0 ) {
- error( "formant~ : error generating data : negative or null parameter(s)" );
- return -1;
+ if ( x->x_size <= 0 || x->x_central_freq <= 0 || x->x_filter_width <= 0 || x->x_skirt_width <= 0 )
+ {
+ error( "formant~ : error generating data : negative or null parameter(s)" );
+ return -1;
}
-
+
x->x_gendata = 1;
/* freeing data */
formant_free( x );
- if ( !( x->x_data = (float*) getbytes( x->x_size*sizeof(float) ) ) ) {
- post( "formant~ : error generating data : cannot allocate table" );
- return -1;
+ if ( !( x->x_data = (float*) getbytes( x->x_size*sizeof(float) ) ) )
+ {
+ post( "formant~ : error generating data : cannot allocate table" );
+ return -1;
}
-
+
fs = 0;
- while( fs < x->x_size-1 ) {
- t = (fs/x->x_samplerate) * x->x_time_stretch; /* time taken from zero */
- b = M_PI / x->x_skirt_width ;
- if ( t < b ) {
- *(x->x_data+(int)fs) = 0.5*(1-cos(x->x_skirt_width*t))*exp(- x->x_filter_width*t )*sin( x->x_central_freq*t);
- } else {
- *(x->x_data+(int)fs) = exp(- x->x_filter_width*t )*sin( x->x_central_freq*t);
- }
- fs++;
+ while( fs < x->x_size-1 )
+ {
+ t = (fs/x->x_samplerate) * x->x_time_stretch; /* time taken from zero */
+ b = M_PI / x->x_skirt_width ;
+ if ( t < b )
+ {
+ *(x->x_data+(int)fs) = 0.5*(1-cos(x->x_skirt_width*t))*exp(- x->x_filter_width*t )*sin( x->x_central_freq*t);
+ }
+ else
+ {
+ *(x->x_data+(int)fs) = exp(- x->x_filter_width*t )*sin( x->x_central_freq*t);
+ }
+ fs++;
}
/* everything went fine */
@@ -115,25 +122,30 @@ static t_int formant_gendata(t_formant *x)
return 0;
}
- /* generates a formant */
+/* generates a formant */
static t_int *formant_perform(t_int *w)
{
t_formant *x = (t_formant *)(w[1]);
t_float *out = (t_float *)(w[2]);
int n = (int)(w[3]); /* number of samples */
- while (n--) {
- if ( !x->x_gendata && x->x_play) {
- *out=*(x->x_data+x->x_readpos);
- x->x_readpos = (x->x_readpos+1)%x->x_size;
- if ( x->x_readpos == 0 ) {
- x->x_play=0;
- outlet_bang(x->x_end);
- }
- } else {
- *out=0.0;
- }
- out++;
+ while (n--)
+ {
+ if ( !x->x_gendata && x->x_play)
+ {
+ *out=*(x->x_data+x->x_readpos);
+ x->x_readpos = (x->x_readpos+1)%x->x_size;
+ if ( x->x_readpos == 0 )
+ {
+ x->x_play=0;
+ outlet_bang(x->x_end);
+ }
+ }
+ else
+ {
+ *out=0.0;
+ }
+ out++;
}
return (w+4);
}
@@ -143,63 +155,68 @@ static void formant_dsp(t_formant *x, t_signal **sp)
dsp_add(formant_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
}
- /* replay the sample */
+/* replay the sample */
static void formant_bang(t_formant *x, t_floatarg fsize)
{
x->x_play=1;
x->x_readpos=0;
}
- /* set size of the sample */
+/* set size of the sample */
static void formant_size(t_formant *x, t_floatarg fsize)
{
- if ( fsize <= 0 ) {
- post( "formant~ : error : sample size should be >0" );
- return;
+ if ( fsize <= 0 )
+ {
+ post( "formant~ : error : sample size should be >0" );
+ return;
}
x->x_size = fsize;
formant_gendata( x );
}
- /* set central frequency of the formant */
+/* set central frequency of the formant */
static void formant_central_freq(t_formant *x, t_floatarg ffreq)
{
- if ( ffreq <= 0 ) {
- post( "formant~ : error : filter central frequency should be >0" );
- return;
+ if ( ffreq <= 0 )
+ {
+ post( "formant~ : error : filter central frequency should be >0" );
+ return;
}
x->x_central_freq = ffreq;
formant_gendata( x );
}
- /* set filter width of the formant */
+/* set filter width of the formant */
static void formant_filter_width(t_formant *x, t_floatarg fwidth)
{
- if ( fwidth <= 0 ) {
- post( "formant~ : error : filter width should be >0" );
- return;
+ if ( fwidth <= 0 )
+ {
+ post( "formant~ : error : filter width should be >0" );
+ return;
}
x->x_filter_width = fwidth;
formant_gendata( x );
}
- /* set skirt width of the formant */
+/* set skirt width of the formant */
static void formant_skirt_width(t_formant *x, t_floatarg swidth)
{
- if ( swidth <= 0 ) {
- post( "formant~ : error : skirt width should be >0" );
- return;
+ if ( swidth <= 0 )
+ {
+ post( "formant~ : error : skirt width should be >0" );
+ return;
}
x->x_skirt_width = swidth;
formant_gendata( x );
}
- /* set time stretch factor */
+/* set time stretch factor */
static void formant_time_stretch(t_formant *x, t_floatarg fstretch)
{
- if ( fstretch <= 0 ) {
- post( "formant~ : error : time stretch should be >0" );
- return;
+ if ( fstretch <= 0 )
+ {
+ post( "formant~ : error : time stretch should be >0" );
+ return;
}
x->x_time_stretch = fstretch;
formant_gendata( x );
@@ -209,12 +226,13 @@ static void *formant_new(t_floatarg fsize, t_floatarg ffreq, t_floatarg ffwidth,
{
t_formant *x = (t_formant *)pd_new(formant_class);
outlet_new(&x->x_obj, &s_signal);
-
- if ( fsize <= 0 || ffreq <= 0 || ffwidth <= 0 || fswidth <= 0 ) {
- error( "formant~ : missing or negative creation arguments" );
- return NULL;
+
+ if ( fsize <= 0 || ffreq <= 0 || ffwidth <= 0 || fswidth <= 0 )
+ {
+ error( "formant~ : missing or negative creation arguments" );
+ return NULL;
}
-
+
x->x_size = fsize;
x->x_central_freq = ffreq;
x->x_filter_width = ffwidth;
@@ -229,10 +247,13 @@ static void *formant_new(t_floatarg fsize, t_floatarg ffreq, t_floatarg ffwidth,
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("swidth"));
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("stretch"));
x->x_end = outlet_new( &x->x_obj, &s_bang );
- if ( formant_gendata( x ) ) {
+ if ( formant_gendata( x ) )
+ {
post( "formant~ : error generating data" );
return NULL;
- } else {
+ }
+ else
+ {
return(x);
}
}
@@ -241,7 +262,7 @@ void formant_tilde_setup(void)
{
verbose(0, formant_version);
formant_class = class_new(gensym("formant~"), (t_newmethod)formant_new, (t_method)formant_free,
- sizeof(t_formant), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ sizeof(t_formant), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(formant_class, (t_method)formant_dsp, gensym("dsp"), 0);
class_addmethod(formant_class, (t_method)formant_size, gensym("size"), A_FLOAT, 0);
class_addmethod(formant_class, (t_method)formant_bang, gensym("bang"), 0);
diff --git a/grid.c b/grid.c
index bfa4cec..4759543 100644
--- a/grid.c
+++ b/grid.c
@@ -64,30 +64,30 @@ static char *grid_version = "grid: version 0.8, written by Yves Degoyon (ydego
/* drawing functions */
static void grid_draw_update(t_grid *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int xpoint=x->x_current, ypoint=x->y_current;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int xpoint=x->x_current, ypoint=x->y_current;
- // later : try to figure out what's this test for ??
+ // later : try to figure out what's this test for ??
// if (glist_isvisible(glist))
// {
- // delete previous point if existing
- if (x->x_point)
- {
- GRID_SYS_VGUI3(".x%lx.c delete %lxPOINT\n", canvas, x);
- }
-
- if ( x->x_current < text_xpix(&x->x_obj, glist) ) xpoint = text_xpix(&x->x_obj, glist);
- if ( x->x_current > text_xpix(&x->x_obj, glist) + x->x_width - pointsize )
- xpoint = text_xpix(&x->x_obj, glist) + x->x_width - pointsize;
- if ( x->y_current < text_ypix(&x->x_obj, glist) ) ypoint = text_ypix(&x->x_obj, glist);
- if ( x->y_current > text_ypix(&x->x_obj, glist) + x->x_height - pointsize )
- ypoint = text_ypix(&x->x_obj, glist) + x->x_height - pointsize;
- // draw the selected point
- GRID_SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FF0000 -tags %lxPOINT\n",
- canvas, xpoint, ypoint, xpoint+pointsize, ypoint+pointsize, x);
- x->x_point = 1;
- // }
- // else
+ // delete previous point if existing
+ if (x->x_point)
+ {
+ GRID_SYS_VGUI3(".x%lx.c delete %lxPOINT\n", canvas, x);
+ }
+
+ if ( x->x_current < text_xpix(&x->x_obj, glist) ) xpoint = text_xpix(&x->x_obj, glist);
+ if ( x->x_current > text_xpix(&x->x_obj, glist) + x->x_width - pointsize )
+ xpoint = text_xpix(&x->x_obj, glist) + x->x_width - pointsize;
+ if ( x->y_current < text_ypix(&x->x_obj, glist) ) ypoint = text_ypix(&x->x_obj, glist);
+ if ( x->y_current > text_ypix(&x->x_obj, glist) + x->x_height - pointsize )
+ ypoint = text_ypix(&x->x_obj, glist) + x->x_height - pointsize;
+ // draw the selected point
+ GRID_SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FF0000 -tags %lxPOINT\n",
+ canvas, xpoint, ypoint, xpoint+pointsize, ypoint+pointsize, x);
+ x->x_point = 1;
+ // }
+ // else
// {
// post( "grid : position updated in an invisible grid" );
// }
@@ -95,142 +95,142 @@ static void grid_draw_update(t_grid *x, t_glist *glist)
static void grid_draw_new(t_grid *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
GRID_SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %lxGRID\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
- x->x_bgcolor, x);
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
+ x->x_bgcolor, x);
GRID_SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -tags %lxo0\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height+1,
- text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist) + x->x_height+2,
- x);
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height+1,
+ text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist) + x->x_height+2,
+ x);
GRID_SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -tags %lxo1\n",
- canvas, text_xpix(&x->x_obj, glist)+x->x_width-7, text_ypix(&x->x_obj, glist) + x->x_height+1,
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist) + x->x_height+2,
- x);
+ canvas, text_xpix(&x->x_obj, glist)+x->x_width-7, text_ypix(&x->x_obj, glist) + x->x_height+1,
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist) + x->x_height+2,
+ x);
- if ( x->x_grid )
+ if ( x->x_grid )
{
- int xlpos = text_xpix(&x->x_obj, glist)+x->x_width/x->x_xlines;
- int ylpos = text_ypix(&x->x_obj, glist)+x->x_height/x->x_ylines;
- int xcount = 1;
- int ycount = 1;
- while ( xlpos < text_xpix(&x->x_obj, glist)+x->x_width )
- {
- GRID_SYS_VGUI9(".x%lx.c create line %d %d %d %d -fill #FFFFFF -tags %lxLINE%d%d\n",
- canvas, xlpos, text_ypix(&x->x_obj, glist),
- xlpos, text_ypix(&x->x_obj, glist)+x->x_height,
- x, xcount, 0 );
- xlpos+=x->x_width/x->x_xlines;
- xcount++;
- }
- while ( ylpos < text_ypix(&x->x_obj, glist)+x->x_height )
- {
- GRID_SYS_VGUI9(".x%lx.c create line %d %d %d %d -fill #FFFFFF -tags %lxLINE%d%d\n",
- canvas, text_xpix(&x->x_obj, glist), ylpos,
- text_xpix(&x->x_obj, glist)+x->x_width, ylpos,
- x, 0, ycount);
- ylpos+=x->x_height/x->x_ylines;
- ycount++;
- }
+ int xlpos = text_xpix(&x->x_obj, glist)+x->x_width/x->x_xlines;
+ int ylpos = text_ypix(&x->x_obj, glist)+x->x_height/x->x_ylines;
+ int xcount = 1;
+ int ycount = 1;
+ while ( xlpos < text_xpix(&x->x_obj, glist)+x->x_width )
+ {
+ GRID_SYS_VGUI9(".x%lx.c create line %d %d %d %d -fill #FFFFFF -tags %lxLINE%d%d\n",
+ canvas, xlpos, text_ypix(&x->x_obj, glist),
+ xlpos, text_ypix(&x->x_obj, glist)+x->x_height,
+ x, xcount, 0 );
+ xlpos+=x->x_width/x->x_xlines;
+ xcount++;
+ }
+ while ( ylpos < text_ypix(&x->x_obj, glist)+x->x_height )
+ {
+ GRID_SYS_VGUI9(".x%lx.c create line %d %d %d %d -fill #FFFFFF -tags %lxLINE%d%d\n",
+ canvas, text_xpix(&x->x_obj, glist), ylpos,
+ text_xpix(&x->x_obj, glist)+x->x_width, ylpos,
+ x, 0, ycount);
+ ylpos+=x->x_height/x->x_ylines;
+ ycount++;
+ }
}
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void grid_draw_move(t_grid *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
GRID_SYS_VGUI7(".x%lx.c coords %lxGRID %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height);
+ canvas, x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height);
GRID_SYS_VGUI7(".x%lx.c coords %lxo0 %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height+1,
- text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist) + x->x_height+2 );
+ canvas, x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height+1,
+ text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist) + x->x_height+2 );
GRID_SYS_VGUI7(".x%lx.c coords %lxo1 %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist)+x->x_width-7, text_ypix(&x->x_obj, glist) + x->x_height+1,
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist) + x->x_height+2 );
- if ( x->x_point )
+ canvas, x,
+ text_xpix(&x->x_obj, glist)+x->x_width-7, text_ypix(&x->x_obj, glist) + x->x_height+1,
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist) + x->x_height+2 );
+ if ( x->x_point )
{
- grid_draw_update(x, glist);
+ grid_draw_update(x, glist);
}
- if ( x->x_grid )
+ if ( x->x_grid )
{
- int xlpos = text_xpix(&x->x_obj, glist)+x->x_width/x->x_xlines;
- int ylpos = text_ypix(&x->x_obj, glist)+x->x_height/x->x_ylines;
- int xcount = 1;
- int ycount = 1;
- while ( xlpos < text_xpix(&x->x_obj, glist)+x->x_width )
- {
- GRID_SYS_VGUI9(".x%lx.c coords %lxLINE%d%d %d %d %d %d\n",
- canvas, x, xcount, 0, xlpos, text_ypix(&x->x_obj, glist),
- xlpos, text_ypix(&x->x_obj, glist) + x->x_height);
- xlpos+=x->x_width/x->x_xlines;
- xcount++;
- }
- while ( ylpos < text_ypix(&x->x_obj, glist)+x->x_height )
- {
- GRID_SYS_VGUI9(".x%lx.c coords %lxLINE%d%d %d %d %d %d\n",
- canvas, x, 0, ycount, text_xpix(&x->x_obj, glist), ylpos,
- text_xpix(&x->x_obj, glist) + x->x_width, ylpos);
- ylpos+=x->x_height/x->x_ylines;
- ycount++;
- }
+ int xlpos = text_xpix(&x->x_obj, glist)+x->x_width/x->x_xlines;
+ int ylpos = text_ypix(&x->x_obj, glist)+x->x_height/x->x_ylines;
+ int xcount = 1;
+ int ycount = 1;
+ while ( xlpos < text_xpix(&x->x_obj, glist)+x->x_width )
+ {
+ GRID_SYS_VGUI9(".x%lx.c coords %lxLINE%d%d %d %d %d %d\n",
+ canvas, x, xcount, 0, xlpos, text_ypix(&x->x_obj, glist),
+ xlpos, text_ypix(&x->x_obj, glist) + x->x_height);
+ xlpos+=x->x_width/x->x_xlines;
+ xcount++;
+ }
+ while ( ylpos < text_ypix(&x->x_obj, glist)+x->x_height )
+ {
+ GRID_SYS_VGUI9(".x%lx.c coords %lxLINE%d%d %d %d %d %d\n",
+ canvas, x, 0, ycount, text_xpix(&x->x_obj, glist), ylpos,
+ text_xpix(&x->x_obj, glist) + x->x_width, ylpos);
+ ylpos+=x->x_height/x->x_ylines;
+ ycount++;
+ }
}
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void grid_draw_erase(t_grid* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- int i;
+ t_canvas *canvas=glist_getcanvas(glist);
+ int i;
GRID_SYS_VGUI3(".x%lx.c delete %lxGRID\n", canvas, x);
GRID_SYS_VGUI3(".x%lx.c delete %lxo0\n", canvas, x);
GRID_SYS_VGUI3(".x%lx.c delete %lxo1\n", canvas, x);
- if (x->x_grid)
+ if (x->x_grid)
{
- for (i=1; i<x->x_xlines; i++ )
- {
- GRID_SYS_VGUI4(".x%lx.c delete %lxLINE%d0\n", canvas, x, i);
- }
- for (i=1; i<x->x_ylines; i++ )
- {
- GRID_SYS_VGUI4(".x%lx.c delete %lxLINE0%d\n", canvas, x, i);
- }
+ for (i=1; i<x->x_xlines; i++ )
+ {
+ GRID_SYS_VGUI4(".x%lx.c delete %lxLINE%d0\n", canvas, x, i);
+ }
+ for (i=1; i<x->x_ylines; i++ )
+ {
+ GRID_SYS_VGUI4(".x%lx.c delete %lxLINE0%d\n", canvas, x, i);
+ }
}
- if (x->x_point)
+ if (x->x_point)
{
- GRID_SYS_VGUI3(".x%lx.c delete %lxPOINT\n", canvas, x);
- x->x_point = 0;
+ GRID_SYS_VGUI3(".x%lx.c delete %lxPOINT\n", canvas, x);
+ x->x_point = 0;
}
}
static void grid_draw_select(t_grid* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
if(x->x_selected)
{
- pd_bind(&x->x_obj.ob_pd, x->x_name);
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
/* sets the item in blue */
- GRID_SYS_VGUI3(".x%lx.c itemconfigure %lxGRID -outline #0000FF\n", canvas, x);
+ GRID_SYS_VGUI3(".x%lx.c itemconfigure %lxGRID -outline #0000FF\n", canvas, x);
}
else
{
- pd_unbind(&x->x_obj.ob_pd, x->x_name);
- GRID_SYS_VGUI3(".x%lx.c itemconfigure %lxGRID -outline #000000\n", canvas, x);
+ pd_unbind(&x->x_obj.ob_pd, x->x_name);
+ GRID_SYS_VGUI3(".x%lx.c itemconfigure %lxGRID -outline #000000\n", canvas, x);
}
}
static void grid_output_current(t_grid* x)
{
- t_float xvalue, yvalue;
- t_float xmodstep, ymodstep;
+ t_float xvalue, yvalue;
+ t_float xmodstep, ymodstep;
xvalue = x->x_min + (x->x_current - text_xpix(&x->x_obj, x->x_glist)) * (x->x_max-x->x_min) / x->x_width ;
if (xvalue < x->x_min ) xvalue = x->x_min;
@@ -251,103 +251,105 @@ static void grid_output_current(t_grid* x)
static void grid_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_grid* x = (t_grid*)z;
+ t_grid* x = (t_grid*)z;
- *xp1 = text_xpix(&x->x_obj, x->x_glist);
- *yp1 = text_ypix(&x->x_obj, x->x_glist);
- *xp2 = text_xpix(&x->x_obj, x->x_glist)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, x->x_glist)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, x->x_glist);
+ *yp1 = text_ypix(&x->x_obj, x->x_glist);
+ *xp2 = text_xpix(&x->x_obj, x->x_glist)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, x->x_glist)+x->x_height;
}
static void grid_save(t_gobj *z, t_binbuf *b)
{
- t_grid *x = (t_grid *)z;
-
- // post( "saving grid : %s", x->x_name->s_name );
- binbuf_addv(b, "ssiissiffiffiffiiff", gensym("#X"),gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_name, x->x_width, x->x_min,
- x->x_max, x->x_height,
+ t_grid *x = (t_grid *)z;
+
+ // post( "saving grid : %s", x->x_name->s_name );
+ binbuf_addv(b, "ssiissiffiffiffiiff", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_name, x->x_width, x->x_min,
+ x->x_max, x->x_height,
x->y_min, x->y_max,
- x->x_grid, x->x_xstep,
- x->x_ystep, x->x_xlines, x->x_ylines,
+ x->x_grid, x->x_xstep,
+ x->x_ystep, x->x_xlines, x->x_ylines,
x->x_current, x->y_current );
- binbuf_addv(b, ";");
+ binbuf_addv(b, ";");
}
static void grid_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_grid *x=(t_grid *)z;
+ char buf[800];
+ t_grid *x=(t_grid *)z;
- sprintf(buf, "pdtk_grid_dialog %%s %s %d %.2f %.2f %d %.2f %.2f %d %.2f %.2f %d %d\n",
- x->x_name->s_name, x->x_width, x->x_min, x->x_max, x->x_height,
+ sprintf(buf, "pdtk_grid_dialog %%s %s %d %.2f %.2f %d %.2f %.2f %d %.2f %.2f %d %d\n",
+ x->x_name->s_name, x->x_width, x->x_min, x->x_max, x->x_height,
x->y_min, x->y_max, x->x_grid, x->x_xstep, x->x_ystep,
x->x_xlines, x->x_ylines );
- // post("grid_properties : %s", buf );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ // post("grid_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
static void grid_select(t_gobj *z, t_glist *glist, int selected)
{
- t_grid *x = (t_grid *)z;
+ t_grid *x = (t_grid *)z;
- x->x_selected = selected;
- grid_draw_select( x, glist );
+ x->x_selected = selected;
+ grid_draw_select( x, glist );
}
static void grid_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_grid *x = (t_grid *)z;
-
- if (vis)
- {
- grid_draw_new( x, glist );
- grid_draw_update( x, glist );
- grid_output_current(x);
- }
- else
- {
- grid_draw_erase( x, glist );
- }
+ t_grid *x = (t_grid *)z;
+
+ if (vis)
+ {
+ grid_draw_new( x, glist );
+ grid_draw_update( x, glist );
+ grid_output_current(x);
+ }
+ else
+ {
+ grid_draw_erase( x, glist );
+ }
}
static void grid_dialog(t_grid *x, t_symbol *s, int argc, t_atom *argv)
{
- if ( !x ) {
- post( "grid : error :tried to set properties on an unexisting object" );
- }
- if ( argc != 12 )
- {
- pd_error(x, "grid : error in the number of arguments ( %d instead of 12 )", argc );
- return;
- }
- if ( argv[0].a_type != A_SYMBOL || 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 ||
- argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
- argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ||
- argv[10].a_type != A_FLOAT || argv[11].a_type != A_FLOAT ) {
- pd_error(x, "grid : wrong arguments" );
- return;
- }
- x->x_name = argv[0].a_w.w_symbol;
- x->x_width = (int)argv[1].a_w.w_float;
- x->x_min = argv[2].a_w.w_float;
- x->x_max = argv[3].a_w.w_float;
- x->x_height = (int)argv[4].a_w.w_float;
- x->y_min = argv[5].a_w.w_float;
- x->y_max = argv[6].a_w.w_float;
- x->x_grid = argv[7].a_w.w_float;
- x->x_xstep = argv[8].a_w.w_float;
- x->x_ystep = argv[9].a_w.w_float;
- x->x_xlines = argv[10].a_w.w_float;
- x->x_ylines = argv[11].a_w.w_float;
- grid_draw_erase(x, x->x_glist);
- grid_draw_new(x, x->x_glist);
+ if ( !x )
+ {
+ post( "grid : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 12 )
+ {
+ pd_error(x, "grid : error in the number of arguments ( %d instead of 12 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_SYMBOL || 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 ||
+ argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
+ argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ||
+ argv[10].a_type != A_FLOAT || argv[11].a_type != A_FLOAT )
+ {
+ pd_error(x, "grid : wrong arguments" );
+ return;
+ }
+ x->x_name = argv[0].a_w.w_symbol;
+ x->x_width = (int)argv[1].a_w.w_float;
+ x->x_min = argv[2].a_w.w_float;
+ x->x_max = argv[3].a_w.w_float;
+ x->x_height = (int)argv[4].a_w.w_float;
+ x->y_min = argv[5].a_w.w_float;
+ x->y_max = argv[6].a_w.w_float;
+ x->x_grid = argv[7].a_w.w_float;
+ x->x_xstep = argv[8].a_w.w_float;
+ x->x_ystep = argv[9].a_w.w_float;
+ x->x_xlines = argv[10].a_w.w_float;
+ x->x_ylines = argv[11].a_w.w_float;
+ grid_draw_erase(x, x->x_glist);
+ grid_draw_new(x, x->x_glist);
}
static void grid_delete(t_gobj *z, t_glist *glist)
@@ -369,7 +371,7 @@ static void grid_displace(t_gobj *z, t_glist *glist, int dx, int dy)
x->y_current += dy;
if(xold != text_xpix(&x->x_obj, glist) || yold != text_ypix(&x->x_obj, glist))
{
- grid_draw_move(x, x->x_glist);
+ grid_draw_move(x, x->x_glist);
}
}
@@ -385,24 +387,24 @@ static void grid_motion(t_grid *x, t_floatarg dx, t_floatarg dy)
if(xold != x->x_current || yold != x->y_current)
{
grid_output_current(x);
- grid_draw_update(x, x->x_glist);
+ grid_draw_update(x, x->x_glist);
}
}
static int grid_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
t_grid* x = (t_grid *)z;
// post( "grid_click doit=%d x=%d y=%d", doit, xpix, ypix );
- if ( doit)
+ if ( doit)
{
- x->x_current = xpix;
- x->y_current = ypix;
- grid_output_current(x);
- grid_draw_update(x, glist);
- glist_grab(glist, &x->x_obj.te_g, (t_glistmotionfn)grid_motion,
- 0, xpix, ypix);
+ x->x_current = xpix;
+ x->y_current = ypix;
+ grid_output_current(x);
+ grid_draw_update(x, glist);
+ glist_grab(glist, &x->x_obj.te_g, (t_glistmotionfn)grid_motion,
+ 0, xpix, ypix);
}
return (1);
}
@@ -468,112 +470,117 @@ static void grid_new_color(t_grid *x, t_floatarg color1, t_floatarg color2, t_fl
static void grid_values(t_grid* x, t_floatarg xvalue, t_floatarg yvalue)
{
- int xold = x->x_current;
- int yold = x->y_current;
+ int xold = x->x_current;
+ int yold = x->y_current;
- if (xvalue < x->x_min ) xvalue = x->x_min;
- if (xvalue > x->x_max ) xvalue = x->x_max;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
- x->x_current = text_xpix(&x->x_obj, x->x_glist) + ((xvalue - x->x_min) / x->x_max) * x->x_width;
+ x->x_current = text_xpix(&x->x_obj, x->x_glist) + ((xvalue - x->x_min) / x->x_max) * x->x_width;
- if (yvalue < x->y_min ) yvalue = x->y_min;
- if (yvalue > x->y_max ) yvalue = x->y_max;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
- x->y_current = text_ypix(&x->x_obj, x->x_glist) + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
+ x->y_current = text_ypix(&x->x_obj, x->x_glist) + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
- if(xold != x->x_current || yold != x->y_current) {
+ if(xold != x->x_current || yold != x->y_current)
+ {
grid_output_current(x);
grid_draw_update(x, x->x_glist);
- }
+ }
}
static void grid_xvalues(t_grid* x, t_floatarg xvalue, t_floatarg yvalue)
{
- int xold = x->x_current;
- int yold = x->y_current;
+ int xold = x->x_current;
+ int yold = x->y_current;
- if (xvalue < x->x_min ) xvalue = x->x_min;
- if (xvalue > x->x_max ) xvalue = x->x_max;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
- x->x_current = text_xpix(&x->x_obj, x->x_glist) + ((xvalue - x->x_min) / x->x_max) * x->x_width;
+ x->x_current = text_xpix(&x->x_obj, x->x_glist) + ((xvalue - x->x_min) / x->x_max) * x->x_width;
- if (yvalue < x->y_min ) yvalue = x->y_min;
- if (yvalue > x->y_max ) yvalue = x->y_max;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
- x->y_current = text_ypix(&x->x_obj, x->x_glist) + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
+ x->y_current = text_ypix(&x->x_obj, x->x_glist) + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
- if(xold != x->x_current || yold != x->y_current) {
+ if(xold != x->x_current || yold != x->y_current)
+ {
grid_draw_update(x, x->x_glist);
- }
+ }
}
static void grid_valuemotion(t_grid* x, t_floatarg dx, t_floatarg dy)
{
- int xold = x->x_current;
- int yold = x->y_current;
- t_float xvalue, yvalue;
+ int xold = x->x_current;
+ int yold = x->y_current;
+ t_float xvalue, yvalue;
- xvalue = x->x_min + (x->x_current - text_xpix(&x->x_obj, x->x_glist)) * (x->x_max-x->x_min) / x->x_width ;
- if (xvalue < x->x_min ) xvalue = x->x_min;
- if (xvalue > x->x_max ) xvalue = x->x_max;
+ xvalue = x->x_min + (x->x_current - text_xpix(&x->x_obj, x->x_glist)) * (x->x_max-x->x_min) / x->x_width ;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
- yvalue = x->y_max - (x->y_current - text_ypix(&x->x_obj, x->x_glist) ) * (x->y_max-x->y_min) / x->x_height ;
- if (yvalue < x->y_min ) yvalue = x->y_min;
- if (yvalue > x->y_max ) yvalue = x->y_max;
+ yvalue = x->y_max - (x->y_current - text_ypix(&x->x_obj, x->x_glist) ) * (x->y_max-x->y_min) / x->x_height ;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
- xvalue += dx;
- yvalue += dy;
+ xvalue += dx;
+ yvalue += dy;
- if (xvalue < x->x_min ) xvalue = x->x_min;
- if (xvalue > x->x_max ) xvalue = x->x_max;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
- x->x_current = text_xpix(&x->x_obj, x->x_glist) + ((xvalue - x->x_min) / x->x_max) * x->x_width;
+ x->x_current = text_xpix(&x->x_obj, x->x_glist) + ((xvalue - x->x_min) / x->x_max) * x->x_width;
- if (yvalue < x->y_min ) yvalue = x->y_min;
- if (yvalue > x->y_max ) yvalue = x->y_max;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
- x->y_current = text_ypix(&x->x_obj, x->x_glist) + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
+ x->y_current = text_ypix(&x->x_obj, x->x_glist) + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
- if(xold != x->x_current || yold != x->y_current) {
+ if(xold != x->x_current || yold != x->y_current)
+ {
grid_output_current(x);
grid_draw_update(x, x->x_glist);
- }
+ }
}
static void grid_xvaluemotion(t_grid* x, t_floatarg dx, t_floatarg dy)
{
- int xold = x->x_current;
- int yold = x->y_current;
- t_float xvalue, yvalue;
+ int xold = x->x_current;
+ int yold = x->y_current;
+ t_float xvalue, yvalue;
- xvalue = x->x_min + (x->x_current - text_xpix(&x->x_obj, x->x_glist)) * (x->x_max-x->x_min) / x->x_width ;
- if (xvalue < x->x_min ) xvalue = x->x_min;
- if (xvalue > x->x_max ) xvalue = x->x_max;
+ xvalue = x->x_min + (x->x_current - text_xpix(&x->x_obj, x->x_glist)) * (x->x_max-x->x_min) / x->x_width ;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
- yvalue = x->y_max - (x->y_current - text_ypix(&x->x_obj, x->x_glist) ) * (x->y_max-x->y_min) / x->x_height ;
- if (yvalue < x->y_min ) yvalue = x->y_min;
- if (yvalue > x->y_max ) yvalue = x->y_max;
+ yvalue = x->y_max - (x->y_current - text_ypix(&x->x_obj, x->x_glist) ) * (x->y_max-x->y_min) / x->x_height ;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
- xvalue += dx;
- yvalue += dy;
+ xvalue += dx;
+ yvalue += dy;
- if (xvalue < x->x_min ) xvalue = x->x_min;
- if (xvalue > x->x_max ) xvalue = x->x_max;
+ if (xvalue < x->x_min ) xvalue = x->x_min;
+ if (xvalue > x->x_max ) xvalue = x->x_max;
- x->x_current = text_xpix(&x->x_obj, x->x_glist) + ((xvalue - x->x_min) / x->x_max) * x->x_width;
+ x->x_current = text_xpix(&x->x_obj, x->x_glist) + ((xvalue - x->x_min) / x->x_max) * x->x_width;
- if (yvalue < x->y_min ) yvalue = x->y_min;
- if (yvalue > x->y_max ) yvalue = x->y_max;
+ if (yvalue < x->y_min ) yvalue = x->y_min;
+ if (yvalue > x->y_max ) yvalue = x->y_max;
- x->y_current = text_ypix(&x->x_obj, x->x_glist) + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
+ x->y_current = text_ypix(&x->x_obj, x->x_glist) + (1 - ((yvalue - x->y_min) / x->y_max)) * x->x_height;
- if(xold != x->x_current || yold != x->y_current) {
+ if(xold != x->x_current || yold != x->y_current)
+ {
grid_draw_update(x, x->x_glist);
- }
+ }
}
-static void grid_bang(t_grid *x) {
- grid_output_current(x);
+static void grid_bang(t_grid *x)
+{
+ grid_output_current(x);
}
static t_grid *grid_new(t_symbol *s, int argc, t_atom *argv)
@@ -581,87 +588,88 @@ static t_grid *grid_new(t_symbol *s, int argc, t_atom *argv)
int zz;
t_grid *x;
char *str;
-
+
// post( "grid_new : create : %s argc =%d", s->s_name, argc );
x = (t_grid *)pd_new(grid_class);
- // new grid created from the gui
+ // new grid created from the gui
if ( argc != 0 )
{
- if ( argc != 14 )
- {
- pd_error(x, "grid : error in the number of arguments ( %d instead of 14 )", argc );
- return NULL;
- }
- if ( argv[0].a_type != A_SYMBOL || 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 ||
- argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
- argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ||
- argv[10].a_type != A_FLOAT || argv[11].a_type != A_FLOAT ||
- argv[12].a_type != A_FLOAT || argv[13].a_type != A_FLOAT ) {
- pd_error(x, "grid : wrong arguments" );
- return NULL;
- }
-
- // update grid count
- if (!strncmp((str = argv[0].a_w.w_symbol->s_name), "grid", 5)
- && (zz = atoi(str + 5)) > gridcount)
- {
- gridcount = zz;
- }
- x->x_name = argv[0].a_w.w_symbol;
- pd_bind(&x->x_obj.ob_pd, x->x_name);
- x->x_width = argv[1].a_w.w_float;
- x->x_min = argv[2].a_w.w_float;
- x->x_max = argv[3].a_w.w_float;
- x->x_height = argv[4].a_w.w_float;
- x->y_min = argv[5].a_w.w_float;
- x->y_max = argv[6].a_w.w_float;
- x->x_grid = argv[7].a_w.w_float;
- x->x_xstep = argv[8].a_w.w_float;
- x->x_ystep = argv[9].a_w.w_float;
- x->x_xlines = argv[10].a_w.w_float;
- x->x_ylines = argv[11].a_w.w_float;
- x->x_current = argv[12].a_w.w_float;
- x->y_current = argv[13].a_w.w_float;
- x->x_point = 1;
+ if ( argc != 14 )
+ {
+ pd_error(x, "grid : error in the number of arguments ( %d instead of 14 )", argc );
+ return NULL;
+ }
+ if ( argv[0].a_type != A_SYMBOL || 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 ||
+ argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
+ argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ||
+ argv[10].a_type != A_FLOAT || argv[11].a_type != A_FLOAT ||
+ argv[12].a_type != A_FLOAT || argv[13].a_type != A_FLOAT )
+ {
+ pd_error(x, "grid : wrong arguments" );
+ return NULL;
+ }
+
+ // update grid count
+ if (!strncmp((str = argv[0].a_w.w_symbol->s_name), "grid", 5)
+ && (zz = atoi(str + 5)) > gridcount)
+ {
+ gridcount = zz;
+ }
+ x->x_name = argv[0].a_w.w_symbol;
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+ x->x_width = argv[1].a_w.w_float;
+ x->x_min = argv[2].a_w.w_float;
+ x->x_max = argv[3].a_w.w_float;
+ x->x_height = argv[4].a_w.w_float;
+ x->y_min = argv[5].a_w.w_float;
+ x->y_max = argv[6].a_w.w_float;
+ x->x_grid = argv[7].a_w.w_float;
+ x->x_xstep = argv[8].a_w.w_float;
+ x->x_ystep = argv[9].a_w.w_float;
+ x->x_xlines = argv[10].a_w.w_float;
+ x->x_ylines = argv[11].a_w.w_float;
+ x->x_current = argv[12].a_w.w_float;
+ x->y_current = argv[13].a_w.w_float;
+ x->x_point = 1;
}
else
{
- char buf[40];
-
- sprintf(buf, "grid%d", ++gridcount);
- s = gensym(buf);
-
- x->x_name = s;
- pd_bind(&x->x_obj.ob_pd, x->x_name);
-
- x->x_width = DEFAULT_GRID_WIDTH;
- x->x_min = 0;
- x->x_max = DEFAULT_GRID_WIDTH - 1;
- x->x_height = DEFAULT_GRID_HEIGHT;
- x->y_min = 0;
- x->y_max = DEFAULT_GRID_HEIGHT - 1;
- x->x_grid = 1;
- x->x_xstep = 1.0;
- x->x_ystep = 1.0;
- x->x_xlines = DEFAULT_GRID_NBLINES;
- x->x_ylines = DEFAULT_GRID_NBLINES;
- x->x_current = 0;
- x->y_current = 0;
+ char buf[40];
+
+ sprintf(buf, "grid%d", ++gridcount);
+ s = gensym(buf);
+
+ x->x_name = s;
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+
+ x->x_width = DEFAULT_GRID_WIDTH;
+ x->x_min = 0;
+ x->x_max = DEFAULT_GRID_WIDTH - 1;
+ x->x_height = DEFAULT_GRID_HEIGHT;
+ x->y_min = 0;
+ x->y_max = DEFAULT_GRID_HEIGHT - 1;
+ x->x_grid = 1;
+ x->x_xstep = 1.0;
+ x->x_ystep = 1.0;
+ x->x_xlines = DEFAULT_GRID_NBLINES;
+ x->x_ylines = DEFAULT_GRID_NBLINES;
+ x->x_current = 0;
+ x->y_current = 0;
}
// common fields for new and restored grids
- x->x_point = 0;
- x->x_selected = 0;
+ x->x_point = 0;
+ x->x_selected = 0;
x->x_glist = (t_glist *) canvas_getcurrent();
- x->x_xoutlet = outlet_new(&x->x_obj, &s_float );
- x->x_youtlet = outlet_new(&x->x_obj, &s_float );
+ x->x_xoutlet = outlet_new(&x->x_obj, &s_float );
+ x->x_youtlet = outlet_new(&x->x_obj, &s_float );
x->x_bgcolor = (char*)getbytes(12);
- strcpy( x->x_bgcolor, "#123589" );
+ strcpy( x->x_bgcolor, "#123589" );
// post( "grid_new name : %s width: %d height : %d", x->x_name->s_name, x->x_width, x->x_height );
@@ -676,11 +684,11 @@ void grid_setup(void)
{
verbose(0, grid_version );
grid_class = class_new(gensym("grid"), (t_newmethod)grid_new,
- (t_method)grid_free, sizeof(t_grid), 0, A_GIMME, 0);
+ (t_method)grid_free, sizeof(t_grid), 0, A_GIMME, 0);
class_addmethod(grid_class, (t_method)grid_click, gensym("click"),
- A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(grid_class, (t_method)grid_motion, gensym("motion"),
- A_FLOAT, A_FLOAT, 0);
+ A_FLOAT, A_FLOAT, 0);
class_addmethod(grid_class, (t_method)grid_bang, gensym("bang"), 0);
class_addmethod(grid_class, (t_method)grid_values, gensym("values"),
A_FLOAT, A_FLOAT, 0);
diff --git a/lpc.c b/lpc.c
index 33159d4..e680588 100644
--- a/lpc.c
+++ b/lpc.c
@@ -22,86 +22,86 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define THRES 0.06
#define Dmin 10.81e-3
-/* Levinson Durbin algorithm for computing LPC coefficients using
+/* Levinson Durbin algorithm for computing LPC coefficients using
autocorrelation fonction */
void lev_durb(double *corr,double *lpc_coef)
{
- double k[11],tab[11];
- double err,acc;
- int i,j;
- double *a=tab;
- double *prev_a=lpc_coef;
- double *exch;
-
-
- /*init vectors*/
- for (i=0;i<11;i++)
- {
- prev_a[i]=0;
- a[i]=0;
- };
- err=corr[0];
- for(i=1;i<11;i++)
- {
- prev_a[0]=1;
- acc=0;
- for(j=0;j<i;j++)
- {
- acc=acc+prev_a[j]*corr[i-j];
- };
- a[i]=k[i]=-acc/err;
- for(j=1;j<i;j++)
- {
- a[j]=prev_a[j]+k[i]*prev_a[i-j];
- };
- err=(1-k[i]*k[i])*err;
- exch=prev_a;
- prev_a=a;
- a=exch;
- };
+ double k[11],tab[11];
+ double err,acc;
+ int i,j;
+ double *a=tab;
+ double *prev_a=lpc_coef;
+ double *exch;
+
+
+ /*init vectors*/
+ for (i=0; i<11; i++)
+ {
+ prev_a[i]=0;
+ a[i]=0;
+ };
+ err=corr[0];
+ for(i=1; i<11; i++)
+ {
+ prev_a[0]=1;
+ acc=0;
+ for(j=0; j<i; j++)
+ {
+ acc=acc+prev_a[j]*corr[i-j];
+ };
+ a[i]=k[i]=-acc/err;
+ for(j=1; j<i; j++)
+ {
+ a[j]=prev_a[j]+k[i]*prev_a[i-j];
+ };
+ err=(1-k[i]*k[i])*err;
+ exch=prev_a;
+ prev_a=a;
+ a=exch;
+ };
}
void comp_lpc(double *buf_x,double *corr,double *lpc_coef,int n)
{
- double buffer[n*3];
- double acc,max=0;
- int i,j;
- /* computes LPC analysis for one subframe */
- /* hamming windowing*/
- acc=0;
- for(i=0;i<2*n;i++)
- {
- acc+=buf_x[i]*buf_x[i];
- };
- if (acc>THRES)
- {
- for(i=0;i<3*n;i++)
- {
- buffer[i]=buf_x[i-n]*HammingWindowTable[i];
- };
- /* autocorrelation computation*/
- for(i=0;i<11;i++)
- {
- acc=0;
- for(j=i;j<n*3;j++)
- {
- acc=acc+buffer[j]*buffer[j-i];
- };
- /* correction with binomial coeffs */
- corr[i]=acc;//*BinomialWindowTable[i];
- };
- corr[0]=corr[0]*(1.0+1.0/1024.0);
- lev_durb(corr,lpc_coef);
- }
- else
- {
- for(i=0;i<11;i++)
- {
- lpc_coef[i]=0;
- };
- }
+ double buffer[n*3];
+ double acc,max=0;
+ int i,j;
+ /* computes LPC analysis for one subframe */
+ /* hamming windowing*/
+ acc=0;
+ for(i=0; i<2*n; i++)
+ {
+ acc+=buf_x[i]*buf_x[i];
+ };
+ if (acc>THRES)
+ {
+ for(i=0; i<3*n; i++)
+ {
+ buffer[i]=buf_x[i-n]*HammingWindowTable[i];
+ };
+ /* autocorrelation computation*/
+ for(i=0; i<11; i++)
+ {
+ acc=0;
+ for(j=i; j<n*3; j++)
+ {
+ acc=acc+buffer[j]*buffer[j-i];
+ };
+ /* correction with binomial coeffs */
+ corr[i]=acc;//*BinomialWindowTable[i];
+ };
+ corr[0]=corr[0]*(1.0+1.0/1024.0);
+ lev_durb(corr,lpc_coef);
+ }
+ else
+ {
+ for(i=0; i<11; i++)
+ {
+ lpc_coef[i]=0;
+ };
+ }
}
-
+
/* LPC to LSP coefficients conversion */
@@ -110,19 +110,19 @@ void comp_lpc(double *buf_x,double *corr,double *lpc_coef,int n)
double evalc(double cw,double *fonc)
{
- double b[7];
- double x,res;
- int k;
-
- x=cw;
- b[5]=1;
- b[6]=0;
- for(k=4;k>0;k--)
- {
- b[k]=2*x*b[k+1]-b[k+2]+fonc[5-k];
- };
- res=x*b[1]-b[2]+fonc[5]/2;
- return(res);
+ double b[7];
+ double x,res;
+ int k;
+
+ x=cw;
+ b[5]=1;
+ b[6]=0;
+ for(k=4; k>0; k--)
+ {
+ b[k]=2*x*b[k+1]-b[k+2]+fonc[5-k];
+ };
+ res=x*b[1]-b[2]+fonc[5]/2;
+ return(res);
}
@@ -131,62 +131,62 @@ double evalc(double cw,double *fonc)
/* all LSP frenquencies are in [0;PI] but are normalized to be in [0;1] */
void lpc2lsp(double lpc_coef[],double *f1,double *f2,double lsp_coef[])
{
-
- int i,k=1;
- double *fonc,*prev_f,*f_exch;
- double prev_sign1,sign,prev_sign2;
- double *s, *prev_s,*s_exch;
- double lpc_exp[11];
-
- /* first computes an additional bandwidth expansion on LPC coeffs*/
- for(i=1;i<11;i++)
- {
- lpc_exp[i]=lpc_coef[i]*BandExpTable[i];
- };
- /* computes the F1 and F2 coeffs*/
- f1[0]=f2[0]=1;
- for(i=0;i<5;i++)
- {
- f1[i+1]=lpc_exp[i+1]+lpc_exp[10-i]-f1[i];
- f2[i+1]=lpc_exp[i+1]-lpc_exp[10-i]+f2[i];
- };
-
- /*find the roots of C(x) alternatively for F1 and F2*/
- fonc=f1;
- prev_f=f2;
- prev_sign1=evalc(1.0,f1);
- prev_sign2=evalc(1.0,f2);
- s=&prev_sign1;
- prev_s=&prev_sign2;
- for(i=1;i<256;i++)
- {
- sign=evalc(CosineTable[i],fonc);
- if ((sign)*(*s)<0)
- {
- /* interpolate to find root*/
- lsp_coef[k]=((double)i-(*s)/(sign-(*s)))/256.0;
- k++;
- /* chek if all roots are found */
- if (k==11) i=257;
- (*s)=sign;
- /* pointers exchange */
- s_exch=s;
- s=prev_s;
- prev_s=s_exch;
- f_exch=fonc;
- fonc=prev_f;
- prev_f=f_exch;
- }
- else (*s)=sign;
- }
- /* if here all roots are not found , use lspDC vector */
- if (k!=11)
- {
- for(i=1;i<11;i++)
- {
- lsp_coef[i]=LspDcTable[i];
- };
- };
+
+ int i,k=1;
+ double *fonc,*prev_f,*f_exch;
+ double prev_sign1,sign,prev_sign2;
+ double *s, *prev_s,*s_exch;
+ double lpc_exp[11];
+
+ /* first computes an additional bandwidth expansion on LPC coeffs*/
+ for(i=1; i<11; i++)
+ {
+ lpc_exp[i]=lpc_coef[i]*BandExpTable[i];
+ };
+ /* computes the F1 and F2 coeffs*/
+ f1[0]=f2[0]=1;
+ for(i=0; i<5; i++)
+ {
+ f1[i+1]=lpc_exp[i+1]+lpc_exp[10-i]-f1[i];
+ f2[i+1]=lpc_exp[i+1]-lpc_exp[10-i]+f2[i];
+ };
+
+ /*find the roots of C(x) alternatively for F1 and F2*/
+ fonc=f1;
+ prev_f=f2;
+ prev_sign1=evalc(1.0,f1);
+ prev_sign2=evalc(1.0,f2);
+ s=&prev_sign1;
+ prev_s=&prev_sign2;
+ for(i=1; i<256; i++)
+ {
+ sign=evalc(CosineTable[i],fonc);
+ if ((sign)*(*s)<0)
+ {
+ /* interpolate to find root*/
+ lsp_coef[k]=((double)i-(*s)/(sign-(*s)))/256.0;
+ k++;
+ /* chek if all roots are found */
+ if (k==11) i=257;
+ (*s)=sign;
+ /* pointers exchange */
+ s_exch=s;
+ s=prev_s;
+ prev_s=s_exch;
+ f_exch=fonc;
+ fonc=prev_f;
+ prev_f=f_exch;
+ }
+ else (*s)=sign;
+ }
+ /* if here all roots are not found , use lspDC vector */
+ if (k!=11)
+ {
+ for(i=1; i<11; i++)
+ {
+ lsp_coef[i]=LspDcTable[i];
+ };
+ };
}
@@ -194,59 +194,61 @@ void lpc2lsp(double lpc_coef[],double *f1,double *f2,double lsp_coef[])
void lsp2lpc(double *lsp_coef,double *lpc_coef)
{
- int i,j=0,index,ok=1;
- double lspcos[11],delta,tmp,p_avg;
- double F1[12],F2[12]; /* begin at indice two*/
-
- F1[0]=0;F1[1]=1;
- F2[0]=0;F2[1]=1;
- /* stability check */
- while(ok && (j<11))
- {
- ok=0;
- for(i=1;i<10;i++)
- {
- if( (lsp_coef[i+1]-lsp_coef[i]) < Dmin)
- {
- ok=1;
- p_avg=(lsp_coef[i]+lsp_coef[i+1])/2.0;
- lsp_coef[i]=p_avg-Dmin/2.0;
- lsp_coef[i+1]=p_avg+Dmin/2.0;
- };
- };
- j++;
- }
-
- /* first converts lsp frequencies to lsp coefficients */
- for (i=1;i<11;i++)
- {
- /* interpolation */
- tmp=lsp_coef[i]*255.0;
- index=(int)tmp;
- delta=CosineTable[index+1]-CosineTable[index];
- lspcos[i]=CosineTable[index]+delta*(tmp-index);
- };
-
- for(i=2;i<7;i++)
- {
- F1[i]=-2*lspcos[2*i-3]*F1[i-1]+2*F1[i-2];
- F2[i]=-2*lspcos[2*i-2]*F2[i-1]+2*F2[i-2];
- for(j=i-1;j>1;j--)
- {
- F1[j]=F1[j]-2*lspcos[2*i-3]*F1[j-1]+F1[j-2];
- F2[j]=F2[j]-2*lspcos[2*i-2]*F2[j-1]+F2[j-2];
- };
- };
- for(i=6;i>1;i--)
- {
- F1[i]=F1[i]+F1[i-1];
- F2[i]=F2[i]-F2[i-1];
- };
- for(i=2;i<7;i++)
- {
- lpc_coef[i-1]=(F1[i]+F2[i])*0.5;
- lpc_coef[i+4]=(F1[8-i]-F2[8-i])*0.5;
- };
- lpc_coef[0]=1;
+ int i,j=0,index,ok=1;
+ double lspcos[11],delta,tmp,p_avg;
+ double F1[12],F2[12]; /* begin at indice two*/
+
+ F1[0]=0;
+ F1[1]=1;
+ F2[0]=0;
+ F2[1]=1;
+ /* stability check */
+ while(ok && (j<11))
+ {
+ ok=0;
+ for(i=1; i<10; i++)
+ {
+ if( (lsp_coef[i+1]-lsp_coef[i]) < Dmin)
+ {
+ ok=1;
+ p_avg=(lsp_coef[i]+lsp_coef[i+1])/2.0;
+ lsp_coef[i]=p_avg-Dmin/2.0;
+ lsp_coef[i+1]=p_avg+Dmin/2.0;
+ };
+ };
+ j++;
+ }
+
+ /* first converts lsp frequencies to lsp coefficients */
+ for (i=1; i<11; i++)
+ {
+ /* interpolation */
+ tmp=lsp_coef[i]*255.0;
+ index=(int)tmp;
+ delta=CosineTable[index+1]-CosineTable[index];
+ lspcos[i]=CosineTable[index]+delta*(tmp-index);
+ };
+
+ for(i=2; i<7; i++)
+ {
+ F1[i]=-2*lspcos[2*i-3]*F1[i-1]+2*F1[i-2];
+ F2[i]=-2*lspcos[2*i-2]*F2[i-1]+2*F2[i-2];
+ for(j=i-1; j>1; j--)
+ {
+ F1[j]=F1[j]-2*lspcos[2*i-3]*F1[j-1]+F1[j-2];
+ F2[j]=F2[j]-2*lspcos[2*i-2]*F2[j-1]+F2[j-2];
+ };
+ };
+ for(i=6; i>1; i--)
+ {
+ F1[i]=F1[i]+F1[i-1];
+ F2[i]=F2[i]-F2[i-1];
+ };
+ for(i=2; i<7; i++)
+ {
+ lpc_coef[i-1]=(F1[i]+F2[i])*0.5;
+ lpc_coef[i+4]=(F1[8-i]-F2[8-i])*0.5;
+ };
+ lpc_coef[0]=1;
}
diff --git a/mp3amp~.c b/mp3amp~.c
index 948c4ca..165ef36 100644
--- a/mp3amp~.c
+++ b/mp3amp~.c
@@ -38,7 +38,7 @@
#include <fcntl.h>
#include "mpg123.h" /* mpg123 decoding library from lame 3.92 */
#include "mpglib.h" /* mpglib decoding library from lame 3.92 */
-#include "interface.h" /* mpglib decoding library from lame 3.92 */
+#include "interface.h" /* mpglib decoding library from lame 3.92 */
#ifdef _WIN32
#if !defined(__OBJC__) && !defined(__GNU_LIBOBJC__) && !defined(__objc_INCLUDE_GNU)
#define BOOL WINBOOL
@@ -72,12 +72,12 @@
#define LAME_AUDIO_CHUNK_SIZE 1152
#define MIN_AUDIO_INPUT 2*LAME_AUDIO_CHUNK_SIZE /* we must have at least n chunks to play a steady sound */
-#define INPUT_BUFFER_SIZE 131072 /* data received on the socket : 128k */
+#define INPUT_BUFFER_SIZE 131072 /* data received on the socket : 128k */
#define OUTPUT_BUFFER_SIZE 131072 /* audio output buffer : 128k */
#define DECODE_PACKET_SIZE 131072 /* size of the data returned by mpglib : 128k */
#define STRBUF_SIZE 4096 /* char received from server on startup */
#define MAX_DECODERS 50
-#define BARHEIGHT 10
+#define BARHEIGHT 10
static int guidebug=0;
@@ -114,7 +114,7 @@ static int guidebug=0;
sys_vgui(a,b,c,d,e,f,g,h,i)
- /* useful debugging functions from mpglib */
+/* useful debugging functions from mpglib */
extern int decode_header( struct frame* fr, unsigned long newhead );
extern void print_header_compact( struct frame* fr );
extern int head_check( unsigned long head, int check_layer );
@@ -128,64 +128,64 @@ static t_class *mp3amp_class;
/* too bad, this needs to be static,
handling an array to enable several decoders in pd */
static MPSTR mps[MAX_DECODERS]; /* decoder buffer */
-static int nbinstances = 0;
+static int nbinstances = 0;
extern const long freqs[9];
-
+
/* time-out used for select() call */
-static struct timeval ztout;
+static struct timeval ztout;
typedef struct _mp3amp
{
- t_object x_obj;
- t_int x_instance; /* instance of the object */
- t_outlet *x_connection;
- t_int x_fd; /* the socket number */
- t_int x_inframes; /* number of waiting frames */
- t_int x_dframes; /* displayed frames in status bar */
- t_int x_packetsize; /* size of the packets */
- t_int x_pblocks; /* processed blocks */
- t_int x_graphic; /* indicates if we show a graphic bar */
- t_canvas *x_canvas; /* remember canvas */
- t_int x_nbwaitloops; /* number of loops to wait */
- t_int x_nbloops; /* number of loops processed */
- t_int x_blocksize; /* size of a dsp block */
- t_int x_resample; /* resampling factor (pd's sr / stream sr) */
- t_int x_dsp; /* number of dsp calls, used to measure time */
- t_int x_standby; /* flag to freeze decoding */
- t_int x_nooutput; /* flag to avoid output of connection state */
+ t_object x_obj;
+ t_int x_instance; /* instance of the object */
+ t_outlet *x_connection;
+ t_int x_fd; /* the socket number */
+ t_int x_inframes; /* number of waiting frames */
+ t_int x_dframes; /* displayed frames in status bar */
+ t_int x_packetsize; /* size of the packets */
+ t_int x_pblocks; /* processed blocks */
+ t_int x_graphic; /* indicates if we show a graphic bar */
+ t_canvas *x_canvas; /* remember canvas */
+ t_int x_nbwaitloops; /* number of loops to wait */
+ t_int x_nbloops; /* number of loops processed */
+ t_int x_blocksize; /* size of a dsp block */
+ t_int x_resample; /* resampling factor (pd's sr / stream sr) */
+ t_int x_dsp; /* number of dsp calls, used to measure time */
+ t_int x_standby; /* flag to freeze decoding */
+ t_int x_nooutput; /* flag to avoid output of connection state */
#ifdef _WIN32
- char *x_inbuffer; /* accumulation buffer for incoming mp3 frames */
+ char *x_inbuffer; /* accumulation buffer for incoming mp3 frames */
#else
- unsigned char *x_inbuffer; /* accumulation buffer for incoming mp3 frames */
+ unsigned char *x_inbuffer; /* accumulation buffer for incoming mp3 frames */
#endif
- t_int x_inwriteposition;
- t_int x_inbuffersize;
- t_int x_offset; /* offset used for start of decoding */
-
- t_float *x_outbuffer; /* buffer to store audio decoded data */
- t_int x_outwriteposition;
- t_int x_outreadposition;
- t_int x_outunread;
- t_int x_outbuffersize;
- char x_out[DECODE_PACKET_SIZE];
-
- /* mp3 stuff */
- t_int x_samplerate;
- t_int x_bitrate; /* bitrate of mp3 stream read at connection time */
- t_int x_bitrateindex; /* bitrate index for each frame, might change dynamically */
- t_int x_mp3mode; /* mode (mono, joint stereo, stereo, dual mono) */
- char* x_bcname; /* name of broadcast */
- char* x_bcurl; /* url of broadcast */
- char* x_bcgenre; /* genre of broadcast */
- char* x_bcaim; /* aim of broadcast */
- char* x_mountpoint; /* mountpoint for IceCast server */
- char* x_hostname; /* hostname to connect to */
- t_int x_port; /* port number to connect to */
-
- t_int x_stream; /* indicates if a stream is connected ( meaning correct input flow ) */
+ t_int x_inwriteposition;
+ t_int x_inbuffersize;
+ t_int x_offset; /* offset used for start of decoding */
+
+ t_float *x_outbuffer; /* buffer to store audio decoded data */
+ t_int x_outwriteposition;
+ t_int x_outreadposition;
+ t_int x_outunread;
+ t_int x_outbuffersize;
+ char x_out[DECODE_PACKET_SIZE];
+
+ /* mp3 stuff */
+ t_int x_samplerate;
+ t_int x_bitrate; /* bitrate of mp3 stream read at connection time */
+ t_int x_bitrateindex; /* bitrate index for each frame, might change dynamically */
+ t_int x_mp3mode; /* mode (mono, joint stereo, stereo, dual mono) */
+ char* x_bcname; /* name of broadcast */
+ char* x_bcurl; /* url of broadcast */
+ char* x_bcgenre; /* genre of broadcast */
+ char* x_bcaim; /* aim of broadcast */
+ char* x_mountpoint; /* mountpoint for IceCast server */
+ char* x_hostname; /* hostname to connect to */
+ t_int x_port; /* port number to connect to */
+
+ t_int x_stream; /* indicates if a stream is connected ( meaning correct input flow ) */
} t_mp3amp;
static void mp3amp_recv(t_mp3amp *x);
@@ -220,76 +220,77 @@ static int strip_ice_header(char *head, int n)
static void mp3amp_tilde_mpglib_init(t_mp3amp *x)
{
- int ret;
-
- InitMP3(&mps[x->x_instance]);
+ int ret;
+
+ InitMP3(&mps[x->x_instance]);
}
static int mp3amp_decode_input(t_mp3amp *x)
{
- t_int i;
- t_int alength = 0;
- float resample = 0;
- struct frame hframe;
- unsigned int a,b,c,d;
- unsigned long cheader;
- signed short int *p = (signed short int *) x->x_out;
- t_int pbytes;
- t_int ret, totlength=0;
- t_int pframes = 0;
-
- x->x_offset=0;
- // search for an header to check dynamic bitrate
- while ( x->x_offset < x->x_inwriteposition )
- {
+ t_int i;
+ t_int alength = 0;
+ float resample = 0;
+ struct frame hframe;
+ unsigned int a,b,c,d;
+ unsigned long cheader;
+ signed short int *p = (signed short int *) x->x_out;
+ t_int pbytes;
+ t_int ret, totlength=0;
+ t_int pframes = 0;
+
+ x->x_offset=0;
+ // search for an header to check dynamic bitrate
+ while ( x->x_offset < x->x_inwriteposition )
+ {
/* decode first 4 bytes as the header */
a = *((unsigned char*)x->x_inbuffer+x->x_offset);
b = *((unsigned char*)x->x_inbuffer+x->x_offset+1);
c = *((unsigned char*)x->x_inbuffer+x->x_offset+2);
d = *((unsigned char*)x->x_inbuffer+x->x_offset+3);
-
+
cheader = 0;
cheader = a;
cheader <<= 8;
cheader |= b;
cheader <<= 8;
- cheader |= c;
+ cheader |= c;
cheader <<= 8;
cheader |= d;
if ( head_check( cheader, 0 ) )
- {
- decode_header( &hframe, cheader );
- if ( hframe.framesize == 0 )
- {
- post( "mp3amp~: weird header ( frame size = 0 ) .... ignored" );
- x->x_offset++;
- continue;
- }
- x->x_packetsize = hframe.framesize;
- // print_header_compact( &hframe );
- // when the bitrate change, reinit decoder
- if ( x->x_bitrateindex != hframe.bitrate_index )
- {
- post( "mp3amp~: bitrate has changed, reinitialize decoder" );
- ExitMP3(&mps[x->x_instance]);
- InitMP3(&mps[x->x_instance]);
- x->x_bitrateindex = hframe.bitrate_index;
- }
- break;
+ {
+ decode_header( &hframe, cheader );
+ if ( hframe.framesize == 0 )
+ {
+ post( "mp3amp~: weird header ( frame size = 0 ) .... ignored" );
+ x->x_offset++;
+ continue;
+ }
+ x->x_packetsize = hframe.framesize;
+ // print_header_compact( &hframe );
+ // when the bitrate change, reinit decoder
+ if ( x->x_bitrateindex != hframe.bitrate_index )
+ {
+ post( "mp3amp~: bitrate has changed, reinitialize decoder" );
+ ExitMP3(&mps[x->x_instance]);
+ InitMP3(&mps[x->x_instance]);
+ x->x_bitrateindex = hframe.bitrate_index;
+ }
+ break;
}
x->x_offset++;
- }
-
- if ( x->x_inframes > 0 )
- {
-
- ret = decodeMP3(&mps[x->x_instance], (unsigned char*)(x->x_inbuffer+x->x_offset),
- hframe.framesize+sizeof( unsigned long), (char *) p, sizeof(x->x_out), &pbytes);
-
- switch (ret)
- {
- case MP3_OK:
- switch (mps[x->x_instance].fr.stereo) {
+ }
+
+ if ( x->x_inframes > 0 )
+ {
+
+ ret = decodeMP3(&mps[x->x_instance], (unsigned char*)(x->x_inbuffer+x->x_offset),
+ hframe.framesize+sizeof( unsigned long), (char *) p, sizeof(x->x_out), &pbytes);
+
+ switch (ret)
+ {
+ case MP3_OK:
+ switch (mps[x->x_instance].fr.stereo)
+ {
case 1:
case 2:
alength = ((mps[x->x_instance].fr.stereo==1)?pbytes >> 1 : pbytes >> 2);
@@ -297,27 +298,27 @@ static int mp3amp_decode_input(t_mp3amp *x)
// update outbuffer contents
for ( i=0; i<alength; i++ )
{
- if ( x->x_outunread >= x->x_outbuffersize-2 )
- {
- // post( "mp3amp~: decode : too much input ... ignored" );
- continue;
- }
- *(x->x_outbuffer+x->x_outwriteposition) = ((t_float)(*p++))/32767.0;
- x->x_outwriteposition = (x->x_outwriteposition + 1)%x->x_outbuffersize;
- *(x->x_outbuffer+x->x_outwriteposition) =
- ((mps[x->x_instance].fr.stereo==2)?((t_float)(*p++))/32767.0 : 0.0);
- x->x_outwriteposition = (x->x_outwriteposition + 1)%x->x_outbuffersize;
- x->x_outunread+=2;
-
- if ( x->x_outunread >= MIN_AUDIO_INPUT && !x->x_stream )
- {
- post("mp3amp~: stream connected" );
- x->x_resample = x->x_samplerate / freqs[hframe.sampling_frequency];
- if ( x->x_resample == 0 ) x->x_resample=1;
- post("mp3amp~: resampling stream from %d to %d Hz (r=%d)",
- freqs[hframe.sampling_frequency], x->x_samplerate, x->x_resample );
- x->x_stream = 1;
- }
+ if ( x->x_outunread >= x->x_outbuffersize-2 )
+ {
+ // post( "mp3amp~: decode : too much input ... ignored" );
+ continue;
+ }
+ *(x->x_outbuffer+x->x_outwriteposition) = ((t_float)(*p++))/32767.0;
+ x->x_outwriteposition = (x->x_outwriteposition + 1)%x->x_outbuffersize;
+ *(x->x_outbuffer+x->x_outwriteposition) =
+ ((mps[x->x_instance].fr.stereo==2)?((t_float)(*p++))/32767.0 : 0.0);
+ x->x_outwriteposition = (x->x_outwriteposition + 1)%x->x_outbuffersize;
+ x->x_outunread+=2;
+
+ if ( x->x_outunread >= MIN_AUDIO_INPUT && !x->x_stream )
+ {
+ post("mp3amp~: stream connected" );
+ x->x_resample = x->x_samplerate / freqs[hframe.sampling_frequency];
+ if ( x->x_resample == 0 ) x->x_resample=1;
+ post("mp3amp~: resampling stream from %d to %d Hz (r=%d)",
+ freqs[hframe.sampling_frequency], x->x_samplerate, x->x_resample );
+ x->x_stream = 1;
+ }
}
break;
default:
@@ -325,104 +326,104 @@ static int mp3amp_decode_input(t_mp3amp *x)
break;
}
// roll buffer
- if ( x->x_inwriteposition > hframe.framesize+ (int) sizeof( unsigned long ) + x->x_offset )
- // ^----- maybe the frame is not complete
+ if ( x->x_inwriteposition > hframe.framesize+ (int) sizeof( unsigned long ) + x->x_offset )
+ // ^----- maybe the frame is not complete
{
- x->x_inwriteposition -= hframe.framesize+sizeof( unsigned long )+x->x_offset;
- memcpy( (void *)(x->x_inbuffer),
- (void *)(x->x_inbuffer+x->x_offset+hframe.framesize+sizeof( unsigned long )),
- x->x_inwriteposition);
- x->x_offset = 0;
- // post ( "mp3amp~: decoded frame %d", x->x_inframes );
- x->x_inframes--;
- pframes++;
+ x->x_inwriteposition -= hframe.framesize+sizeof( unsigned long )+x->x_offset;
+ memcpy( (void *)(x->x_inbuffer),
+ (void *)(x->x_inbuffer+x->x_offset+hframe.framesize+sizeof( unsigned long )),
+ x->x_inwriteposition);
+ x->x_offset = 0;
+ // post ( "mp3amp~: decoded frame %d", x->x_inframes );
+ x->x_inframes--;
+ pframes++;
}
else // sorry, it will be ignored
{
- // error( "mp3amp~: incomplete frame...ignored");
- // x->x_offset = 0;
- // x->x_inwriteposition = 0;
- // x->x_inframes = 0;
+ // error( "mp3amp~: incomplete frame...ignored");
+ // x->x_offset = 0;
+ // x->x_inwriteposition = 0;
+ // x->x_inframes = 0;
}
-
+
totlength += alength;
break;
-
- case MP3_NEED_MORE:
- if ( mps[x->x_instance].framesize == 0 && mps[x->x_instance].fsizeold != 0 )
+
+ case MP3_NEED_MORE:
+ if ( mps[x->x_instance].framesize == 0 && mps[x->x_instance].fsizeold != 0 )
{
- post( "mp3amp~: decoding done (totlength=%d).", totlength );
+ post( "mp3amp~: decoding done (totlength=%d).", totlength );
}
else
{
- post( "mp3amp~: retry lame decoding (more data needed)." );
- return -1;
+ post( "mp3amp~: retry lame decoding (more data needed)." );
+ return -1;
}
break;
-
- case MP3_ERR:
+
+ case MP3_ERR:
post( "mp3amp~: lame decoding failed." );
return ret;
break;
-
- }
-
- }
-
- if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
- {
- /* update graphical read status */
- if ( x->x_inframes != x->x_dframes )
- {
- char color[32];
- t_int width;
+
+ }
+
+ }
+
+ if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
+ {
+ /* update graphical read status */
+ if ( x->x_inframes != x->x_dframes )
+ {
+ char color[32];
+ t_int width;
width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
SYS_VGUI3(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x );
if ( x->x_inframes < (MIN_AUDIO_INPUT/LAME_AUDIO_CHUNK_SIZE) )
{
- strcpy( color, "red" );
+ strcpy( color, "red" );
}
else
{
- strcpy( color, "lightgreen" );
+ strcpy( color, "lightgreen" );
}
SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xSTATUS\n",
- x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
- x->x_obj.te_xpix+(x->x_inwriteposition*width)/INPUT_BUFFER_SIZE,
- x->x_obj.te_ypix - 1, color, x );
+ x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
+ x->x_obj.te_xpix+(x->x_inwriteposition*width)/INPUT_BUFFER_SIZE,
+ x->x_obj.te_ypix - 1, color, x );
x->x_dframes = x->x_inframes;
- }
- }
- return totlength;
+ }
+ }
+ return totlength;
}
-
+
static void mp3amp_recv(t_mp3amp *x)
{
- int ret, i;
- float resample = 0;
- struct frame hframe;
- unsigned int a,b,c,d;
- unsigned long cheader;
-
+ int ret, i;
+ float resample = 0;
+ struct frame hframe;
+ unsigned int a,b,c,d;
+ unsigned long cheader;
+
#ifdef _WIN32
- if(( ret = recv(x->x_fd, (char*)x->x_inbuffer + x->x_inwriteposition,
- (x->x_inbuffersize-x->x_inwriteposition), 0)) < 0)
+ if(( ret = recv(x->x_fd, (char*)x->x_inbuffer + x->x_inwriteposition,
+ (x->x_inbuffersize-x->x_inwriteposition), 0)) < 0)
#else
- if ( ( ret = recv(x->x_fd, (void*) (x->x_inbuffer + x->x_inwriteposition),
- (size_t)((x->x_inbuffersize-x->x_inwriteposition)),
- MSG_NOSIGNAL) ) < 0 )
+ if ( ( ret = recv(x->x_fd, (void*) (x->x_inbuffer + x->x_inwriteposition),
+ (size_t)((x->x_inbuffersize-x->x_inwriteposition)),
+ MSG_NOSIGNAL) ) < 0 )
#endif
- {
+ {
post( "mp3amp~: receive error" );
#ifndef _MSC_VER
perror( "recv" );
#endif
mp3amp_disconnect(x);
return;
- }
- else
- {
+ }
+ else
+ {
// post( "mp3amp~: received %d bytes at %d on %d ( up to %d)",
// ret, x->x_inwriteposition, x->x_fd,
@@ -435,144 +436,145 @@ static void mp3amp_recv(t_mp3amp *x)
}
else
{
- // check if we should decode those packets
- if ( x->x_standby )
- {
- return;
- }
- // check we don't overflow input buffer
- if ( ( x->x_inwriteposition + ret ) > x->x_inbuffersize*0.9 )
- {
- post( "mp3streamin~ : too much input...resetting" );
- x->x_inwriteposition=0;
- x->x_offset = 0;
- x->x_inframes = 0;
- return;
- }
- x->x_inwriteposition += ret;
- x->x_offset = 0;
- // check some parameters in the stream
- while ( x->x_offset < x->x_inwriteposition )
- {
- /* decode first 4 bytes as the header */
- a = *((unsigned char*)x->x_inbuffer+x->x_offset);
- b = *((unsigned char*)x->x_inbuffer+x->x_offset+1);
- c = *((unsigned char*)x->x_inbuffer+x->x_offset+2);
- d = *((unsigned char*)x->x_inbuffer+x->x_offset+3);
-
- cheader = 0;
- cheader = a;
- cheader <<= 8;
- cheader |= b;
- cheader <<= 8;
- cheader |= c;
- cheader <<= 8;
- cheader |= d;
- if ( head_check( cheader, 0 ) )
- {
- decode_header( &hframe, cheader );
- // print_header_compact( &hframe );
- x->x_packetsize = hframe.framesize;
- if ( hframe.framesize == 0 )
- {
- post( "mp3amp~: weird header ( frame size = 0 ) .... ignored" );
- x->x_inwriteposition -= ret;
- return;
- }
- x->x_inframes += ret/x->x_packetsize;
- // post( "mp3amp~: nb frames %d", x->x_inframes );
- break;
- }
- x->x_offset++;
+ // check if we should decode those packets
+ if ( x->x_standby )
+ {
+ return;
+ }
+ // check we don't overflow input buffer
+ if ( ( x->x_inwriteposition + ret ) > x->x_inbuffersize*0.9 )
+ {
+ post( "mp3streamin~ : too much input...resetting" );
+ x->x_inwriteposition=0;
+ x->x_offset = 0;
+ x->x_inframes = 0;
+ return;
+ }
+ x->x_inwriteposition += ret;
+ x->x_offset = 0;
+ // check some parameters in the stream
+ while ( x->x_offset < x->x_inwriteposition )
+ {
+ /* decode first 4 bytes as the header */
+ a = *((unsigned char*)x->x_inbuffer+x->x_offset);
+ b = *((unsigned char*)x->x_inbuffer+x->x_offset+1);
+ c = *((unsigned char*)x->x_inbuffer+x->x_offset+2);
+ d = *((unsigned char*)x->x_inbuffer+x->x_offset+3);
+
+ cheader = 0;
+ cheader = a;
+ cheader <<= 8;
+ cheader |= b;
+ cheader <<= 8;
+ cheader |= c;
+ cheader <<= 8;
+ cheader |= d;
+ if ( head_check( cheader, 0 ) )
+ {
+ decode_header( &hframe, cheader );
+ // print_header_compact( &hframe );
+ x->x_packetsize = hframe.framesize;
+ if ( hframe.framesize == 0 )
+ {
+ post( "mp3amp~: weird header ( frame size = 0 ) .... ignored" );
+ x->x_inwriteposition -= ret;
+ return;
+ }
+ x->x_inframes += ret/x->x_packetsize;
+ // post( "mp3amp~: nb frames %d", x->x_inframes );
+ break;
+ }
+ x->x_offset++;
}
}
- }
-}
+ }
+}
static t_int *mp3amp_perform(t_int *w)
{
- t_mp3amp *x = (t_mp3amp*) (w[1]);
- t_float *out1 = (t_float *)(w[2]);
- t_float *out2 = (t_float *)(w[3]);
- int n = (int)(w[4]);
- int ret;
- int i = 0;
-
- x->x_blocksize = n;
- x->x_nbwaitloops = LAME_AUDIO_CHUNK_SIZE/x->x_blocksize;
- // post( "mp3mp3amp~ : will wait %d loops", x->x_nbwaitloops );
- x->x_dsp++;
-
- while( n-- )
- {
- if(x->x_stream && !x->x_standby ) // check that the stream provides enough data
- {
+ t_mp3amp *x = (t_mp3amp*) (w[1]);
+ t_float *out1 = (t_float *)(w[2]);
+ t_float *out2 = (t_float *)(w[3]);
+ int n = (int)(w[4]);
+ int ret;
+ int i = 0;
+
+ x->x_blocksize = n;
+ x->x_nbwaitloops = LAME_AUDIO_CHUNK_SIZE/x->x_blocksize;
+ // post( "mp3mp3amp~ : will wait %d loops", x->x_nbwaitloops );
+ x->x_dsp++;
+
+ while( n-- )
+ {
+ if(x->x_stream && !x->x_standby ) // check that the stream provides enough data
+ {
if(x->x_resample == 1) /* don't need to resample */
{
- *out1++=*(x->x_outbuffer+x->x_outreadposition);
+ *out1++=*(x->x_outbuffer+x->x_outreadposition);
x->x_outreadposition = (x->x_outreadposition + 1)%x->x_outbuffersize;
*out2++=*(x->x_outbuffer+x->x_outreadposition);
x->x_outreadposition = (x->x_outreadposition + 1)%x->x_outbuffersize;
x->x_outunread-=2;
- }
- else
- { /* we just use the same sample x->x_resample times */
- *out1++=*(x->x_outbuffer+x->x_outreadposition);
+ }
+ else
+ {
+ /* we just use the same sample x->x_resample times */
+ *out1++=*(x->x_outbuffer+x->x_outreadposition);
*out2++=*(x->x_outbuffer+((x->x_outreadposition + 1)%x->x_outbuffersize));
if((n%x->x_resample)== 0)
{
- x->x_outreadposition = (x->x_outreadposition + 2)%x->x_outbuffersize;
- x->x_outunread-=2;
+ x->x_outreadposition = (x->x_outreadposition + 2)%x->x_outbuffersize;
+ x->x_outunread-=2;
}
- }
- if ( n == 1 ) x->x_pblocks++;
- }
- else
- {
+ }
+ if ( n == 1 ) x->x_pblocks++;
+ }
+ else
+ {
*out1++=0.0;
*out2++=0.0;
- }
- }
-
- if ( x->x_pblocks == LAME_AUDIO_CHUNK_SIZE/x->x_blocksize )
- {
+ }
+ }
+
+ if ( x->x_pblocks == LAME_AUDIO_CHUNK_SIZE/x->x_blocksize )
+ {
x->x_pblocks = 0;
- }
-
- /* check for readability, then fill the input buffer */
- if(( x->x_fd > 0 )&&(x->x_dsp >= 16)) /* determine how often we try to read */
- {
- fd_set readset;
- fd_set exceptset;
-
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- FD_SET(x->x_fd, &readset );
- FD_SET(x->x_fd, &exceptset );
-
- x->x_dsp = 0;
-
- if ( select( x->x_fd+1, &readset, NULL, &exceptset, &ztout ) >0 )
- {
- if ( FD_ISSET( x->x_fd, &readset) || FD_ISSET( x->x_fd, &exceptset ) )
- {
+ }
+
+ /* check for readability, then fill the input buffer */
+ if(( x->x_fd > 0 )&&(x->x_dsp >= 16)) /* determine how often we try to read */
+ {
+ fd_set readset;
+ fd_set exceptset;
+
+ FD_ZERO(&readset);
+ FD_ZERO(&exceptset);
+ FD_SET(x->x_fd, &readset );
+ FD_SET(x->x_fd, &exceptset );
+
+ x->x_dsp = 0;
+
+ if ( select( x->x_fd+1, &readset, NULL, &exceptset, &ztout ) >0 )
+ {
+ if ( FD_ISSET( x->x_fd, &readset) || FD_ISSET( x->x_fd, &exceptset ) )
+ {
/* receive data or error */
- mp3amp_recv(x);
- }
- }
- }
-
- // check new incoming data
- if ( x->x_fd > 0 && ( x->x_nbloops == 0 ) && ( x->x_inframes > 0 ) && ( !x->x_standby ) )
- {
- mp3amp_decode_input(x);
- }
- if ( x->x_nbwaitloops != 0 )
- {
- x->x_nbloops = (x->x_nbloops+1 ) % x->x_nbwaitloops;
- }
- return (w+5);
-}
+ mp3amp_recv(x);
+ }
+ }
+ }
+
+ // check new incoming data
+ if ( x->x_fd > 0 && ( x->x_nbloops == 0 ) && ( x->x_inframes > 0 ) && ( !x->x_standby ) )
+ {
+ mp3amp_decode_input(x);
+ }
+ if ( x->x_nbwaitloops != 0 )
+ {
+ x->x_nbloops = (x->x_nbloops+1 ) % x->x_nbwaitloops;
+ }
+ return (w+5);
+}
static void mp3amp_dsp(t_mp3amp *x, t_signal **sp)
{
@@ -580,20 +582,20 @@ static void mp3amp_dsp(t_mp3amp *x, t_signal **sp)
}
- /* freeze decoding */
+/* freeze decoding */
static void mp3amp_standby(t_mp3amp *x, t_floatarg fstandby )
{
- if ( fstandby == 0. )
- {
- x->x_standby = 0;
- }
- else
- {
- x->x_standby = 1;
- }
+ if ( fstandby == 0. )
+ {
+ x->x_standby = 0;
+ }
+ else
+ {
+ x->x_standby = 1;
+ }
}
- /* connection main procedure executed by a thread */
+/* connection main procedure executed by a thread */
static void *mp3amp_do_connect(void *tdata )
{
t_mp3amp *x = (t_mp3amp*) tdata;
@@ -601,7 +603,7 @@ static void *mp3amp_do_connect(void *tdata )
struct hostent *hp;
t_int portno = x->x_port; /* get port from message box */
- /* variables used for communication with server */
+ /* variables used for communication with server */
char *sptr = NULL;
char request[STRBUF_SIZE]; /* string to be send to server */
char *url; /* used for relocation */
@@ -626,7 +628,7 @@ static void *mp3amp_do_connect(void *tdata )
return NULL;
}
- /* connect socket using hostname provided in command line */
+ /* connect socket using hostname provided in command line */
server.sin_family = AF_INET;
hp = gethostbyname(x->x_hostname);
if (hp == 0)
@@ -637,10 +639,10 @@ static void *mp3amp_do_connect(void *tdata )
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
- /* assign client port number */
+ /* assign client port number */
server.sin_port = htons((unsigned short)portno);
- /* try to connect. */
+ /* try to connect. */
post("mp3amp~: connecting to http:/%s:%d/%s", x->x_hostname, x->x_port, x->x_mountpoint );
if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
{
@@ -650,7 +652,7 @@ static void *mp3amp_do_connect(void *tdata )
}
post("mp3amp~: connected : socket opened" );
- /* sheck if we can read/write from/to the socket */
+ /* sheck if we can read/write from/to the socket */
FD_ZERO( &fdset);
FD_SET( sockfd, &fdset);
tv.tv_sec = 0; /* seconds */
@@ -665,23 +667,24 @@ static void *mp3amp_do_connect(void *tdata )
}
post("mp3amp~: select done" );
- /* check mountpoint */
+ /* check mountpoint */
if( strstr(x->x_mountpoint, "listen.pls") )
- { /* SHOUTcast playlist -> get / */
- x->x_mountpoint = "";
+ {
+ /* SHOUTcast playlist -> get / */
+ x->x_mountpoint = "";
}
- /* build up stuff we need to send to server */
- sprintf(request, "GET /%s HTTP/1.0 \r\nHost: %s\r\nUser-Agent: mp3amp~ 0.11\r\nAccept: */*\r\n\r\n",
+ /* build up stuff we need to send to server */
+ sprintf(request, "GET /%s HTTP/1.0 \r\nHost: %s\r\nUser-Agent: mp3amp~ 0.11\r\nAccept: */*\r\n\r\n",
x->x_mountpoint, x->x_hostname);
if ( send(sockfd, request, strlen(request), 0) < 0 ) /* say hello to server */
{
- post( "mp3amp~: could not contact server... " );
+ post( "mp3amp~: could not contact server... " );
#ifndef _MSC_VER
- perror( "send" );
+ perror( "send" );
#endif
- return NULL;
+ return NULL;
}
post("mp3amp~: send done" );
@@ -692,46 +695,46 @@ static void *mp3amp_do_connect(void *tdata )
endofheaders=0;
while ( !endofheaders )
{
- if( ( ret = recv(sockfd, request+offset, STRBUF_SIZE, MSG_NOSIGNAL) ) <0)
- {
- error("mp3amp~: no response from server");
+ if( ( ret = recv(sockfd, request+offset, STRBUF_SIZE, MSG_NOSIGNAL) ) <0)
+ {
+ error("mp3amp~: no response from server");
#ifndef _MSC_VER
- perror( "recv" );
+ perror( "recv" );
#endif
- return NULL;
- }
- post ( "mp3amp~ : received %d bytes at %d", ret, offset );
- for ( i=offset; i<offset+ret-1; i++ )
- {
- if ( ( request[i] == '\n' && request[i+1] == '\n' ) ||
- ( request[i] == 10 && request[i+1] == 13 ) )
- {
- endofheaders=1;
- }
- }
- offset+=ret;
+ return NULL;
+ }
+ post ( "mp3amp~ : received %d bytes at %d", ret, offset );
+ for ( i=offset; i<offset+ret-1; i++ )
+ {
+ if ( ( request[i] == '\n' && request[i+1] == '\n' ) ||
+ ( request[i] == 10 && request[i+1] == 13 ) )
+ {
+ endofheaders=1;
+ }
+ }
+ offset+=ret;
}
-
- // time to parse content of the response...
+
+ // time to parse content of the response...
if ( strstr(request, "audio/x-scpls") ) /* SHOUTcast playlist */
{
- /* playlist playing not supported */
- post("mp3amp~: SHOUTcast server returned a playlist, quitting");
- sys_closesocket(sockfd);
- return NULL;
- }
+ /* playlist playing not supported */
+ post("mp3amp~: SHOUTcast server returned a playlist, quitting");
+ sys_closesocket(sockfd);
+ return NULL;
+ }
if ( strstr(request, "HTTP") ) /* seems to be IceCast server */
{
- strip_ice_header(request, STRBUF_SIZE);
- if(sptr = strstr(request, "302"))
+ strip_ice_header(request, STRBUF_SIZE);
+ if(sptr = strstr(request, "302"))
{
cpoint = NULL;
cpoint = strstr(request, "Location:");
- if ( cpoint == NULL )
+ if ( cpoint == NULL )
{
- post( "mp3amp~ : stream has moved but couldn't find new location out of this :" );
- post("mp3amp~: %s", request );
- return NULL;
+ post( "mp3amp~ : stream has moved but couldn't find new location out of this :" );
+ post("mp3amp~: %s", request );
+ return NULL;
}
url = strdup(cpoint + 10);
post("mp3amp~: relocating to %s", url);
@@ -742,7 +745,7 @@ static void *mp3amp_do_connect(void *tdata )
return NULL;
// relocate = TRUE;
}
- if( !(sptr = strstr(request, "200")) && !relocate )
+ if( !(sptr = strstr(request, "200")) && !relocate )
{
error("mp3amp~: cannot connect to the (default) stream");
return NULL;
@@ -752,147 +755,147 @@ static void *mp3amp_do_connect(void *tdata )
// post("mp3amp~: server's header : %s", request );
- // check what we got
+ // check what we got
if( cpoint = strstr(request, "x-audiocast-mount:"))
{
- x->x_mountpoint = strdup(cpoint + 18);
- for ( i=0; i<(int)strlen(x->x_mountpoint); i++ )
- {
+ x->x_mountpoint = strdup(cpoint + 18);
+ for ( i=0; i<(int)strlen(x->x_mountpoint); i++ )
+ {
if ( x->x_mountpoint[i] == '\n' )
{
- x->x_mountpoint[i] = '\0';
- break;
- }
- }
- post(" mountpoint: %s", x->x_mountpoint);
+ x->x_mountpoint[i] = '\0';
+ break;
+ }
+ }
+ post(" mountpoint: %s", x->x_mountpoint);
}
if( cpoint = strstr(request, "x-audiocast-server-url:"))
{
- sptr = strdup( cpoint + 24);
- for ( i=0; i<(int)strlen(sptr); i++ )
- {
+ sptr = strdup( cpoint + 24);
+ for ( i=0; i<(int)strlen(sptr); i++ )
+ {
if ( sptr[i] == '\n' )
{
- sptr[i] = '\0';
- break;
- }
- }
- post(" server-url: %s", sptr);
- }
- if( cpoint = strstr(request, "x-audiocast-location:"))
- {
- sptr = strdup( cpoint + 22);
- for ( i=0; i<(int)strlen(sptr); i++ )
- {
+ sptr[i] = '\0';
+ break;
+ }
+ }
+ post(" server-url: %s", sptr);
+ }
+ if( cpoint = strstr(request, "x-audiocast-location:"))
+ {
+ sptr = strdup( cpoint + 22);
+ for ( i=0; i<(int)strlen(sptr); i++ )
+ {
if ( sptr[i] == '\n' )
{
- sptr[i] = '\0';
- break;
- }
- }
- post(" location: %s", sptr);
- }
- if( cpoint = strstr(request, "x-audiocast-admin:"))
- {
- sptr = strdup( cpoint + 19);
- for ( i=0; i<(int)strlen(sptr); i++ )
- {
+ sptr[i] = '\0';
+ break;
+ }
+ }
+ post(" location: %s", sptr);
+ }
+ if( cpoint = strstr(request, "x-audiocast-admin:"))
+ {
+ sptr = strdup( cpoint + 19);
+ for ( i=0; i<(int)strlen(sptr); i++ )
+ {
if ( sptr[i] == '\n' )
{
- sptr[i] = '\0';
- break;
- }
- }
- post(" admin: %s", sptr);
- }
- if( cpoint = strstr(request, "x-audiocast-name:"))
- {
- x->x_bcname = strdup( cpoint + 17);
- for ( i=0; i<(int)strlen(x->x_bcname); i++ )
- {
+ sptr[i] = '\0';
+ break;
+ }
+ }
+ post(" admin: %s", sptr);
+ }
+ if( cpoint = strstr(request, "x-audiocast-name:"))
+ {
+ x->x_bcname = strdup( cpoint + 17);
+ for ( i=0; i<(int)strlen(x->x_bcname); i++ )
+ {
if ( x->x_bcname[i] == '\n' )
{
- x->x_bcname[i] = '\0';
- break;
- }
- }
- post(" name: %s", x->x_bcname);
- }
- if( cpoint = strstr(request, "x-audiocast-genre:"))
- {
- x->x_bcgenre = strdup( cpoint + 18);
- for ( i=0; i<(int)strlen(x->x_bcgenre); i++ )
- {
+ x->x_bcname[i] = '\0';
+ break;
+ }
+ }
+ post(" name: %s", x->x_bcname);
+ }
+ if( cpoint = strstr(request, "x-audiocast-genre:"))
+ {
+ x->x_bcgenre = strdup( cpoint + 18);
+ for ( i=0; i<(int)strlen(x->x_bcgenre); i++ )
+ {
if ( x->x_bcgenre[i] == '\n' )
{
- x->x_bcgenre[i] = '\0';
- break;
- }
- }
- post(" genre: %s", x->x_bcgenre);
- }
- if( cpoint = strstr(request, "x-audiocast-url:"))
- {
- x->x_bcurl = strdup( cpoint + 16);
- for ( i=0; i<(int)strlen(x->x_bcurl); i++ )
- {
+ x->x_bcgenre[i] = '\0';
+ break;
+ }
+ }
+ post(" genre: %s", x->x_bcgenre);
+ }
+ if( cpoint = strstr(request, "x-audiocast-url:"))
+ {
+ x->x_bcurl = strdup( cpoint + 16);
+ for ( i=0; i<(int)strlen(x->x_bcurl); i++ )
+ {
if ( x->x_bcurl[i] == '\n' )
{
- x->x_bcurl[i] = '\0';
- break;
- }
- }
- post(" url: %s", x->x_bcurl);
- }
- if( cpoint = strstr(request, "x-audiocast-public:1"))
- {
- post(" broadcast is public");
- }
- else if( cpoint = strstr(request, "x-audiocast-public:0"))
- {
- post(" broadcast is NOT public");
- }
- if( cpoint = strstr(request, "x-audiocast-bitrate:"))
- {
- sptr = strdup( cpoint + 20);
- for ( i=0; i<(int)strlen(sptr); i++ )
- {
+ x->x_bcurl[i] = '\0';
+ break;
+ }
+ }
+ post(" url: %s", x->x_bcurl);
+ }
+ if( cpoint = strstr(request, "x-audiocast-public:1"))
+ {
+ post(" broadcast is public");
+ }
+ else if( cpoint = strstr(request, "x-audiocast-public:0"))
+ {
+ post(" broadcast is NOT public");
+ }
+ if( cpoint = strstr(request, "x-audiocast-bitrate:"))
+ {
+ sptr = strdup( cpoint + 20);
+ for ( i=0; i<(int)strlen(sptr); i++ )
+ {
if ( sptr[i] == '\n' )
{
- sptr[i] = '\0';
- break;
- }
- }
- if(!strncmp(sptr, "320", 3))x->x_bitrate = 320;
- else if(!strncmp(sptr, "256", 3))x->x_bitrate = 256;
- else if(!strncmp(sptr, "224", 3))x->x_bitrate = 224;
- else if(!strncmp(sptr, "192", 3))x->x_bitrate = 192;
- else if(!strncmp(sptr, "160", 3))x->x_bitrate = 160;
- else if(!strncmp(sptr, "144", 3))x->x_bitrate = 144;
- else if(!strncmp(sptr, "128", 3))x->x_bitrate = 128;
- else if(!strncmp(sptr, "112", 3))x->x_bitrate = 112;
- else if(!strncmp(sptr, "96", 2))x->x_bitrate = 96;
- else if(!strncmp(sptr, "80", 2))x->x_bitrate = 80;
- else if(!strncmp(sptr, "64", 2))x->x_bitrate = 64;
- else if(!strncmp(sptr, "56", 2))x->x_bitrate = 56;
- else if(!strncmp(sptr, "48", 2))x->x_bitrate = 48;
- else if(!strncmp(sptr, "40", 2))x->x_bitrate = 40;
- else if(!strncmp(sptr, "32", 2))x->x_bitrate = 32;
- else if(!strncmp(sptr, "24", 2))x->x_bitrate = 24;
- else if(!strncmp(sptr, "16", 2))x->x_bitrate = 16;
- else if(!strncmp(sptr, "8", 1))x->x_bitrate = 8;
- else
- {
+ sptr[i] = '\0';
+ break;
+ }
+ }
+ if(!strncmp(sptr, "320", 3))x->x_bitrate = 320;
+ else if(!strncmp(sptr, "256", 3))x->x_bitrate = 256;
+ else if(!strncmp(sptr, "224", 3))x->x_bitrate = 224;
+ else if(!strncmp(sptr, "192", 3))x->x_bitrate = 192;
+ else if(!strncmp(sptr, "160", 3))x->x_bitrate = 160;
+ else if(!strncmp(sptr, "144", 3))x->x_bitrate = 144;
+ else if(!strncmp(sptr, "128", 3))x->x_bitrate = 128;
+ else if(!strncmp(sptr, "112", 3))x->x_bitrate = 112;
+ else if(!strncmp(sptr, "96", 2))x->x_bitrate = 96;
+ else if(!strncmp(sptr, "80", 2))x->x_bitrate = 80;
+ else if(!strncmp(sptr, "64", 2))x->x_bitrate = 64;
+ else if(!strncmp(sptr, "56", 2))x->x_bitrate = 56;
+ else if(!strncmp(sptr, "48", 2))x->x_bitrate = 48;
+ else if(!strncmp(sptr, "40", 2))x->x_bitrate = 40;
+ else if(!strncmp(sptr, "32", 2))x->x_bitrate = 32;
+ else if(!strncmp(sptr, "24", 2))x->x_bitrate = 24;
+ else if(!strncmp(sptr, "16", 2))x->x_bitrate = 16;
+ else if(!strncmp(sptr, "8", 1))x->x_bitrate = 8;
+ else
+ {
post("mp3amp~: unsupported bitrate! : %s", sptr);
return NULL;
- }
- post(" bitrate: %d", x->x_bitrate);
- }
- if( cpoint = strstr(request, "x-audiocast-udpport:"))
- {
- post("mp3amp~: sorry, server wants UDP connection!");
- return NULL;
- }
+ }
+ post(" bitrate: %d", x->x_bitrate);
+ }
+ if( cpoint = strstr(request, "x-audiocast-udpport:"))
+ {
+ post("mp3amp~: sorry, server wants UDP connection!");
+ return NULL;
+ }
}
else /* it is a SHOUTcast server */
{
@@ -905,126 +908,127 @@ static void *mp3amp_do_connect(void *tdata )
}
if (strstr(request, "ICY 200 OK"))
{
- /* recv and decode info about broadcast line by line */
+ /* recv and decode info about broadcast line by line */
post("mp3amp~: connecting to stream...");
i = ret;
/* check what we got */
if( cpoint = strstr(request, "icy-name:"))
{
- x->x_bcname = strdup( cpoint + 10);
- for ( i=0; i<(int)strlen(x->x_bcname); i++ )
- {
- if ( x->x_bcname[i] == '\n' )
+ x->x_bcname = strdup( cpoint + 10);
+ for ( i=0; i<(int)strlen(x->x_bcname); i++ )
{
- x->x_bcname[i] = '\0';
- break;
- }
- }
- post(" name: %s", x->x_bcname);
+ if ( x->x_bcname[i] == '\n' )
+ {
+ x->x_bcname[i] = '\0';
+ break;
+ }
+ }
+ post(" name: %s", x->x_bcname);
}
if( cpoint = strstr(request, "x-audiocast-name:"))
{
- x->x_bcname = strdup( cpoint + 18);
- for ( i=0; i<(int)strlen(x->x_bcname); i++ )
- {
- if ( x->x_bcname[i] == '\n' )
+ x->x_bcname = strdup( cpoint + 18);
+ for ( i=0; i<(int)strlen(x->x_bcname); i++ )
{
- x->x_bcname[i] = '\0';
- break;
- }
- }
- post(" name: %s", x->x_bcname);
+ if ( x->x_bcname[i] == '\n' )
+ {
+ x->x_bcname[i] = '\0';
+ break;
+ }
+ }
+ post(" name: %s", x->x_bcname);
}
if( cpoint = strstr(request, "icy-genre:"))
{
- x->x_bcgenre = strdup( cpoint + 10);
- for ( i=0; i<(int)strlen(x->x_bcgenre); i++ )
- {
- if ( x->x_bcgenre[i] == '\n' )
+ x->x_bcgenre = strdup( cpoint + 10);
+ for ( i=0; i<(int)strlen(x->x_bcgenre); i++ )
{
- x->x_bcgenre[i] = '\0';
- break;
- }
- }
- post(" name: %s", x->x_bcname);
+ if ( x->x_bcgenre[i] == '\n' )
+ {
+ x->x_bcgenre[i] = '\0';
+ break;
+ }
+ }
+ post(" name: %s", x->x_bcname);
}
if( cpoint = strstr(request, "icy-aim:"))
{
- x->x_bcaim = strdup( cpoint + 8);
- for ( i=0; i<(int)strlen(x->x_bcaim); i++ )
- {
- if ( x->x_bcaim[i] == '\n' )
+ x->x_bcaim = strdup( cpoint + 8);
+ for ( i=0; i<(int)strlen(x->x_bcaim); i++ )
{
- x->x_bcaim[i] = '\0';
- break;
- }
- }
- post(" name: %s", x->x_bcname);
+ if ( x->x_bcaim[i] == '\n' )
+ {
+ x->x_bcaim[i] = '\0';
+ break;
+ }
+ }
+ post(" name: %s", x->x_bcname);
}
if( cpoint = strstr(request, "icy-url:"))
{
- x->x_bcurl = strdup( cpoint + 8);
- for ( i=0; i<(int)strlen(x->x_bcurl); i++ )
- {
- if ( x->x_bcurl[i] == '\n' )
+ x->x_bcurl = strdup( cpoint + 8);
+ for ( i=0; i<(int)strlen(x->x_bcurl); i++ )
{
- x->x_bcurl[i] = '\0';
- break;
- }
- }
- post(" name: %s", x->x_bcname);
+ if ( x->x_bcurl[i] == '\n' )
+ {
+ x->x_bcurl[i] = '\0';
+ break;
+ }
+ }
+ post(" name: %s", x->x_bcname);
}
if(strstr(request, "icy-pub:1"))
{
- post(" broadcast is public");
+ post(" broadcast is public");
}
else if(strstr(request, "icy-pub:0"))
{
- post(" broadcast is NOT public");
+ post(" broadcast is NOT public");
}
if( cpoint = strstr(request, "icy-br:"))
{
- sptr = strdup( cpoint + 7);
- if(!strncmp(sptr, "320", 3))x->x_bitrate = 320;
- else if(!strncmp(sptr, "256", 3))x->x_bitrate = 256;
- else if(!strncmp(sptr, "224", 3))x->x_bitrate = 224;
- else if(!strncmp(sptr, "192", 3))x->x_bitrate = 192;
- else if(!strncmp(sptr, "160", 3))x->x_bitrate = 160;
- else if(!strncmp(sptr, "144", 3))x->x_bitrate = 144;
- else if(!strncmp(sptr, "128", 3))x->x_bitrate = 128;
- else if(!strncmp(sptr, "112", 3))x->x_bitrate = 112;
- else if(!strncmp(sptr, "96", 2))x->x_bitrate = 96;
- else if(!strncmp(sptr, "80", 2))x->x_bitrate = 80;
- else if(!strncmp(sptr, "64", 2))x->x_bitrate = 64;
- else if(!strncmp(sptr, "56", 2))x->x_bitrate = 56;
- else if(!strncmp(sptr, "48", 2))x->x_bitrate = 48;
- else if(!strncmp(sptr, "40", 2))x->x_bitrate = 40;
- else if(!strncmp(sptr, "32", 2))x->x_bitrate = 32;
- else if(!strncmp(sptr, "24", 2))x->x_bitrate = 24;
- else if(!strncmp(sptr, "16", 2))x->x_bitrate = 16;
- else if(!strncmp(sptr, "8", 2))x->x_bitrate = 8;
- else
- {
+ sptr = strdup( cpoint + 7);
+ if(!strncmp(sptr, "320", 3))x->x_bitrate = 320;
+ else if(!strncmp(sptr, "256", 3))x->x_bitrate = 256;
+ else if(!strncmp(sptr, "224", 3))x->x_bitrate = 224;
+ else if(!strncmp(sptr, "192", 3))x->x_bitrate = 192;
+ else if(!strncmp(sptr, "160", 3))x->x_bitrate = 160;
+ else if(!strncmp(sptr, "144", 3))x->x_bitrate = 144;
+ else if(!strncmp(sptr, "128", 3))x->x_bitrate = 128;
+ else if(!strncmp(sptr, "112", 3))x->x_bitrate = 112;
+ else if(!strncmp(sptr, "96", 2))x->x_bitrate = 96;
+ else if(!strncmp(sptr, "80", 2))x->x_bitrate = 80;
+ else if(!strncmp(sptr, "64", 2))x->x_bitrate = 64;
+ else if(!strncmp(sptr, "56", 2))x->x_bitrate = 56;
+ else if(!strncmp(sptr, "48", 2))x->x_bitrate = 48;
+ else if(!strncmp(sptr, "40", 2))x->x_bitrate = 40;
+ else if(!strncmp(sptr, "32", 2))x->x_bitrate = 32;
+ else if(!strncmp(sptr, "24", 2))x->x_bitrate = 24;
+ else if(!strncmp(sptr, "16", 2))x->x_bitrate = 16;
+ else if(!strncmp(sptr, "8", 2))x->x_bitrate = 8;
+ else
+ {
post("mp3amp~: unsupported bitrate! (%s)", sptr);
- return NULL;
- }
- post(" bitrate: %d", x->x_bitrate);
- }
- if(strstr(request, "x-audiocast-udpport:"))
- {
+ return NULL;
+ }
+ post(" bitrate: %d", x->x_bitrate);
+ }
+ if(strstr(request, "x-audiocast-udpport:"))
+ {
post("mp3amp~: sorry, server wants UDP connection!");
return NULL;
- }
+ }
}
- else
+ else
{
post("mp3amp~: unknown response from server");
return NULL;
}
- relocate = FALSE;
+ relocate = FALSE;
}
- if (relocate) {
+ if (relocate)
+ {
error("mp3amp~: too many HTTP relocations");
return NULL;
}
@@ -1032,11 +1036,11 @@ static void *mp3amp_do_connect(void *tdata )
x->x_fd = sockfd;
if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
{
- t_int width;
+ t_int width;
- width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
- SYS_VGUI3(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill lightblue -tags %xPBAR\n",
+ width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
+ SYS_VGUI3(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill lightblue -tags %xPBAR\n",
x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
x->x_obj.te_xpix + width, x->x_obj.te_ypix - 1, x );
}
@@ -1044,11 +1048,11 @@ static void *mp3amp_do_connect(void *tdata )
return NULL;
}
- /* launch the connection thread */
+/* launch the connection thread */
static void mp3amp_connect(t_mp3amp *x, t_symbol *hostname, t_symbol *mountpoint, t_floatarg fportno )
{
- pthread_attr_t update_child_attr;
- pthread_t connectchild;
+ pthread_attr_t update_child_attr;
+ pthread_t connectchild;
// store data
x->x_hostname = (char*) getbytes( strlen( hostname->s_name ) + 1 ); // there's a memory leak here
@@ -1060,30 +1064,33 @@ static void mp3amp_connect(t_mp3amp *x, t_symbol *hostname, t_symbol *mountpoint
x->x_port = fportno;
// launch connection thread
- if ( pthread_attr_init( &update_child_attr ) < 0 ) {
- post( "mp3amp~ : could not launch connection thread" );
- perror( "pthread_attr_init" );
- return;
+ if ( pthread_attr_init( &update_child_attr ) < 0 )
+ {
+ post( "mp3amp~ : could not launch connection thread" );
+ perror( "pthread_attr_init" );
+ return;
}
- if ( pthread_attr_setdetachstate( &update_child_attr, PTHREAD_CREATE_DETACHED ) < 0 ) {
- post( "mp3amp~ : could not launch connection thread" );
- perror( "pthread_attr_setdetachstate" );
- return;
+ if ( pthread_attr_setdetachstate( &update_child_attr, PTHREAD_CREATE_DETACHED ) < 0 )
+ {
+ post( "mp3amp~ : could not launch connection thread" );
+ perror( "pthread_attr_setdetachstate" );
+ return;
}
- if ( pthread_create( &connectchild, &update_child_attr, mp3amp_do_connect, x ) < 0 ) {
- post( "mp3amp~ : could not launch connection thread" );
- perror( "pthread_create" );
- return;
+ if ( pthread_create( &connectchild, &update_child_attr, mp3amp_do_connect, x ) < 0 )
+ {
+ post( "mp3amp~ : could not launch connection thread" );
+ perror( "pthread_create" );
+ return;
}
else
{
- // post( "cooled~ : drawing thread %d launched", (int)x->x_updatechild );
+ // post( "cooled~ : drawing thread %d launched", (int)x->x_updatechild );
}
if ( !x->x_nooutput ) outlet_float(x->x_connection, 1);
}
- /* connect using url like "http://localhost:8000/mountpoint" */
+/* connect using url like "http://localhost:8000/mountpoint" */
static void mp3amp_connect_url(t_mp3amp *x, t_symbol *url)
{
char *hostptr = NULL, *p, *endhost = NULL, *hostname = NULL;
@@ -1092,7 +1099,7 @@ static void mp3amp_connect_url(t_mp3amp *x, t_symbol *url)
post( "mp3amp~ : connect url : %s", url->s_name );
- /* strip http:// or ftp:// */
+ /* strip http:// or ftp:// */
p = url->s_name;
if (strncmp(p, "http://", 7) == 0)
p += 7;
@@ -1105,25 +1112,25 @@ static void mp3amp_connect_url(t_mp3amp *x, t_symbol *url)
p++;
endhost = p;
- switch ( *p )
+ switch ( *p )
{
- case ':' :
- portno = atoi( p+1 );
- while (*p && *p != '/') p++;
- pathptr = p+1;
- break;
- case '/' :
- portno = 8000;
- pathptr = p+1;
- break;
- default :
- if ( ( p - url->s_name ) != (int)strlen( url->s_name ) )
- {
+ case ':' :
+ portno = atoi( p+1 );
+ while (*p && *p != '/') p++;
+ pathptr = p+1;
+ break;
+ case '/' :
+ portno = 8000;
+ pathptr = p+1;
+ break;
+ default :
+ if ( ( p - url->s_name ) != (int)strlen( url->s_name ) )
+ {
post( "mp3amp~ : wrong url : %s", hostptr );
return;
- }
- pathptr = "";
- break;
+ }
+ pathptr = "";
+ break;
}
hostname=(char*)getbytes( (int)(endhost - hostptr) + 1);
@@ -1132,11 +1139,11 @@ static void mp3amp_connect_url(t_mp3amp *x, t_symbol *url)
post ("mp3amp~ : connecting to host=%s port=%d path=%s", hostname, portno, pathptr );
- /* call the 'normal' connection routine */
+ /* call the 'normal' connection routine */
mp3amp_connect(x, gensym(hostname), gensym(pathptr), portno);
}
- /* close connection to SHOUTcast server */
+/* close connection to SHOUTcast server */
static void mp3amp_disconnect(t_mp3amp *x)
{
x->x_stream = 0;
@@ -1153,8 +1160,8 @@ static void mp3amp_disconnect(t_mp3amp *x)
InitMP3(&mps[x->x_instance]);
if ( x->x_graphic )
{
- SYS_VGUI3(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
- SYS_VGUI3(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x );
+ SYS_VGUI3(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
+ SYS_VGUI3(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x );
}
post("mp3amp~: connection closed");
outlet_float(x->x_connection, 0);
@@ -1162,7 +1169,8 @@ static void mp3amp_disconnect(t_mp3amp *x)
static void mp3amp_free(t_mp3amp *x)
{
- if (x->x_fd > 0) {
+ if (x->x_fd > 0)
+ {
post( "mp3amp~: closing socket" );
sys_closesocket(x->x_fd);
x->x_fd = -1;
@@ -1174,27 +1182,27 @@ static void mp3amp_free(t_mp3amp *x)
static void *mp3amp_new(t_floatarg fdographics)
{
t_mp3amp *x = NULL;
-
+
if ( ((int)fdographics != 0) && ((int)fdographics != 1.) )
{
- post( "mp3amp~: error : constructor : mp3amp~ [graphic flag = 0 | 1 ] ( got = %f)", fdographics );
- return NULL;
- }
-
+ post( "mp3amp~: error : constructor : mp3amp~ [graphic flag = 0 | 1 ] ( got = %f)", fdographics );
+ return NULL;
+ }
+
x = (t_mp3amp *)pd_new(mp3amp_class);
outlet_new(&x->x_obj, gensym("signal"));
outlet_new(&x->x_obj, gensym("signal"));
x->x_connection = outlet_new(&x->x_obj, gensym("float"));
-
+
if ( nbinstances < MAX_DECODERS )
{
- x->x_instance = nbinstances++;
+ x->x_instance = nbinstances++;
}
else
{
- post( "mp3amp~: cannot create more decoders (memory issues), sorry" );
- return NULL;
- }
+ post( "mp3amp~: cannot create more decoders (memory issues), sorry" );
+ return NULL;
+ }
x->x_fd = -1;
x->x_stream = 0;
@@ -1205,15 +1213,15 @@ static void *mp3amp_new(t_floatarg fdographics)
x->x_dsp = 0;
x->x_inbuffersize = INPUT_BUFFER_SIZE;
- x->x_outbuffersize = OUTPUT_BUFFER_SIZE;
+ x->x_outbuffersize = OUTPUT_BUFFER_SIZE;
x->x_inbuffer = (unsigned char*) getbytes(INPUT_BUFFER_SIZE);
x->x_offset = 0;
x->x_outbuffer = (t_float*) getbytes(OUTPUT_BUFFER_SIZE*sizeof(t_float));
if ( !x->x_inbuffer || !x->x_outbuffer )
{
- post( "mp3amp~: could not allocate buffers" );
- return NULL;
+ post( "mp3amp~: could not allocate buffers" );
+ return NULL;
}
memset( x->x_inbuffer, 0x0, INPUT_BUFFER_SIZE );
memset( x->x_outbuffer, 0x0, OUTPUT_BUFFER_SIZE );
@@ -1228,13 +1236,13 @@ static void *mp3amp_new(t_floatarg fdographics)
ztout.tv_sec = 0;
ztout.tv_usec = 0;
-
+
x->x_graphic = (int)fdographics;
post( "mp3amp~: getting canvas" );
- x->x_canvas = canvas_getcurrent();
-
+ x->x_canvas = canvas_getcurrent();
+
post( "mp3amp~: initializing decoder..." );
- /* init mpg123 decoder */
+ /* init mpg123 decoder */
mp3amp_tilde_mpglib_init(x);
verbose(0, mp3amp_version);
@@ -1245,9 +1253,9 @@ static void *mp3amp_new(t_floatarg fdographics)
void mp3amp_tilde_setup(void)
{
- mp3amp_class = class_new(gensym("mp3amp~"),
- (t_newmethod) mp3amp_new, (t_method) mp3amp_free,
- sizeof(t_mp3amp), 0, A_DEFFLOAT, A_NULL);
+ mp3amp_class = class_new(gensym("mp3amp~"),
+ (t_newmethod) mp3amp_new, (t_method) mp3amp_free,
+ sizeof(t_mp3amp), 0, A_DEFFLOAT, A_NULL);
class_addmethod(mp3amp_class, nullfn, gensym("signal"), 0);
class_addmethod(mp3amp_class, (t_method)mp3amp_dsp, gensym("dsp"), 0);
diff --git a/mp3cast~.c b/mp3cast~.c
index beb4c53..d015da8 100644
--- a/mp3cast~.c
+++ b/mp3cast~.c
@@ -25,9 +25,9 @@
/* be found at http://www.cdex.n3.net. */
/* */
/* ---------------------------------------------------------------------------- */
-
-
-
+
+
+
#ifdef _MSC_VER
#pragma warning( disable : 4244 )
#pragma warning( disable : 4305 )
@@ -53,7 +53,7 @@
#include <windows.h>
#include <winsock.h>
#include <windef.h>
-#else
+#else
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -64,19 +64,20 @@
#endif
#include <lame/lame.h> /* lame encoder stuff */
-#include "mpg123.h"
+#include "mpg123.h"
#define MY_MP3_MALLOC_IN_SIZE 65536
- /* max size taken from lame readme */
-#define MY_MP3_MALLOC_OUT_SIZE 1.25*MY_MP3_MALLOC_IN_SIZE+7200
+/* max size taken from lame readme */
+#define MY_MP3_MALLOC_OUT_SIZE 1.25*MY_MP3_MALLOC_IN_SIZE+7200
#define MAXDATARATE 320 /* maximum mp3 data rate is 320kbit/s */
#define STRBUF_SIZE 1024
static char *mp3cast_version = "mp3cast~: mp3 streamer version 0.5, written by Yves Degoyon";
-static char base64table[65] = {
+static char base64table[65] =
+{
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
@@ -89,12 +90,12 @@ typedef struct _mp3cast
{
t_object x_obj;
- /* LAME stuff */
+ /* LAME stuff */
int x_lame; /* info about encoder status */
int x_lamechunk; /* chunk size for LAME encoder */
int x_mp3size; /* number of returned mp3 samples */
- /* buffer stuff */
+ /* buffer stuff */
unsigned short x_inp; /* in position for buffer */
unsigned short x_outp; /* out position for buffer*/
short *x_mp3inbuf; /* data to be sent to LAME */
@@ -103,17 +104,17 @@ typedef struct _mp3cast
int x_bytesbuffered; /* number of unprocessed bytes in buffer */
int x_start;
- /* mp3 format stuff */
+ /* mp3 format stuff */
int x_samplerate;
int x_bitrate; /* bitrate of mp3 stream */
int x_mp3mode; /* mode (mono, joint stereo, stereo, dual mono) */
int x_mp3quality; /* quality of encoding */
- /* SHOUTcast server stuff */
+ /* SHOUTcast server stuff */
int x_fd; /* info about connection status */
char* x_passwd; /* password for server */
int x_icecast; /* tells if we use a IceCast server or SHOUTcast */
- /* special IceCast server stuff */
+ /* special IceCast server stuff */
char* x_mountpoint;
char* x_name;
char* x_url;
@@ -128,7 +129,7 @@ typedef struct _mp3cast
} t_mp3cast;
- /* encode PCM data to mp3 stream */
+/* encode PCM data to mp3 stream */
static void mp3cast_encode(t_mp3cast *x)
{
unsigned short i, wp;
@@ -145,11 +146,11 @@ static void mp3cast_encode(t_mp3cast *x)
return;
}
- /* on start/reconnect set outpoint that it not interferes with inpoint */
+ /* on start/reconnect set outpoint that it not interferes with inpoint */
if(x->x_start == -1)
{
post("mp3cast~: initialising buffers");
- /* we try to keep 2.5 times the data the encoder needs in the buffer */
+ /* we try to keep 2.5 times the data the encoder needs in the buffer */
if(x->x_inp > (2 * x->x_lamechunk))
{
x->x_outp = (short) x->x_inp - (2.5 * x->x_lamechunk);
@@ -164,10 +165,10 @@ static void mp3cast_encode(t_mp3cast *x)
i = MY_MP3_MALLOC_IN_SIZE - x->x_outp;
- /* read from buffer */
- if(x->x_lamechunk <= i)
+ /* read from buffer */
+ if(x->x_lamechunk <= i)
{
- /* enough data until end of buffer */
+ /* enough data until end of buffer */
for(n = 0; n < x->x_lamechunk; n++) /* fill encode buffer */
{
x->x_mp3inbuf[n] = x->x_buffer[n + x->x_outp];
@@ -188,13 +189,13 @@ static void mp3cast_encode(t_mp3cast *x)
x->x_outp = x->x_lamechunk - i;
}
- /* encode mp3 data */
- x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf,
- x->x_lamechunk/lame_get_num_channels(x->lgfp),
+ /* encode mp3 data */
+ x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf,
+ x->x_lamechunk/lame_get_num_channels(x->lgfp),
x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE);
// post( "mp3cast~ : encoding returned %d frames", x->x_mp3size );
- /* check result */
+ /* check result */
if(x->x_mp3size<0)
{
lame_close( x->lgfp );
@@ -204,7 +205,7 @@ static void mp3cast_encode(t_mp3cast *x)
}
- /* stream mp3 to SHOUTcast server */
+/* stream mp3 to SHOUTcast server */
static void mp3cast_stream(t_mp3cast *x)
{
int err = -1, i; /* error return code */
@@ -223,12 +224,12 @@ static void mp3cast_stream(t_mp3cast *x)
#endif /* _WIN32 */
x->x_fd = -1;
outlet_float(x->x_obj.ob_outlet, 0);
- }
+ }
if((err > 0)&&(err != x->x_mp3size))error("mp3cast~: %d bytes skipped", x->x_mp3size - err);
}
-
- /* buffer data as channel interleaved PCM */
+
+/* buffer data as channel interleaved PCM */
static t_int *mp3cast_perform(t_int *w)
{
t_float *in1 = (t_float *)(w[1]); /* left audio inlet */
@@ -238,76 +239,94 @@ static t_int *mp3cast_perform(t_int *w)
unsigned short i,wp;
float in;
- /* copy the data into the buffer */
+ /* copy the data into the buffer */
i = MY_MP3_MALLOC_IN_SIZE - x->x_inp; /* space left at the end of buffer */
-
+
n *= 2; /* two channels go into one buffer */
- if( n <= i )
+ if( n <= i )
{
/* the place between inp and MY_MP3_MALLOC_IN_SIZE */
/* is big enough to hold the data */
- for(wp = 0; wp < n; wp++)
+ for(wp = 0; wp < n; wp++)
+ {
+ if(wp%2)
+ {
+ in = *(in2++); /* right channel / inlet */
+ }
+ else
+ {
+ in = *(in1++); /* left channel / inlet */
+ }
+ if (in > 1.0)
+ {
+ in = 1.0;
+ }
+ if (in < -1.0)
{
- if(wp%2)
- {
- in = *(in2++); /* right channel / inlet */
- }
- else
- {
- in = *(in1++); /* left channel / inlet */
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ in = -1.0;
}
- x->x_inp += n; /* n more samples written to buffer */
- }
- else
+ x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ }
+ x->x_inp += n; /* n more samples written to buffer */
+ }
+ else
{
- /* the place between inp and MY_MP3_MALLOC_IN_SIZE is not */
- /* big enough to hold the data */
- /* writing will take place in two turns, one from */
- /* x->x_inp -> MY_MP3_MALLOC_IN_SIZE, then from 0 on */
+ /* the place between inp and MY_MP3_MALLOC_IN_SIZE is not */
+ /* big enough to hold the data */
+ /* writing will take place in two turns, one from */
+ /* x->x_inp -> MY_MP3_MALLOC_IN_SIZE, then from 0 on */
- for(wp = 0; wp < i; wp++) /* fill up to end of buffer */
+ for(wp = 0; wp < i; wp++) /* fill up to end of buffer */
+ {
+ if(wp%2)
+ {
+ in = *(in2++);
+ }
+ else
+ {
+ in = *(in1++);
+ }
+ if (in > 1.0)
+ {
+ in = 1.0;
+ }
+ if (in < -1.0)
+ {
+ in = -1.0;
+ }
+ x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ }
+ for(wp = i; wp < n; wp++) /* write rest at start of buffer */
+ {
+ if(wp%2)
+ {
+ in = *(in2++);
+ }
+ else
{
- if(wp%2)
- {
- in = *(in2++);
- }
- else
- {
- in = *(in1++);
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ in = *(in1++);
}
- for(wp = i; wp < n; wp++) /* write rest at start of buffer */
+ if (in > 1.0)
{
- if(wp%2)
- {
- in = *(in2++);
- }
- else
- {
- in = *(in1++);
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp - i] = (short) (32767.0 * in);
+ in = 1.0;
}
- x->x_inp = n - i; /* new writeposition in buffer */
+ if (in < -1.0)
+ {
+ in = -1.0;
+ }
+ x->x_buffer[wp - i] = (short) (32767.0 * in);
+ }
+ x->x_inp = n - i; /* new writeposition in buffer */
}
if((x->x_fd >= 0)&&(x->x_lame >= 0))
- {
- /* count buffered samples when things are running */
+ {
+ /* count buffered samples when things are running */
x->x_bytesbuffered += n;
- /* encode and send to server */
+ /* encode and send to server */
if(x->x_bytesbuffered > x->x_lamechunk)
{
mp3cast_encode(x); /* encode to mp3 */
@@ -327,7 +346,7 @@ static void mp3cast_dsp(t_mp3cast *x, t_signal **sp)
dsp_add(mp3cast_perform, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n);
}
- /* initialize the lame library */
+/* initialize the lame library */
static void mp3cast_tilde_lame_init(t_mp3cast *x)
{
int ret;
@@ -335,8 +354,8 @@ static void mp3cast_tilde_lame_init(t_mp3cast *x)
#ifdef _WIN32
/* load lame_enc.dll library */
- HINSTANCE dll;
- dll=LoadLibrary("lame_enc.dll");
+ HINSTANCE dll;
+ dll=LoadLibrary("lame_enc.dll");
if(!dll)
{
error("mp3cast~: error loading lame_enc.dll");
@@ -348,12 +367,12 @@ static void mp3cast_tilde_lame_init(t_mp3cast *x)
}
#endif /* _WIN32 */
{
- const char *lameVersion = get_lame_version();
- verbose(0, "mp3cast~ : using lame version : %s", lameVersion );
+ const char *lameVersion = get_lame_version();
+ verbose(0, "mp3cast~ : using lame version : %s", lameVersion );
}
- /* setting lame parameters */
+ /* setting lame parameters */
lame_set_num_channels( x->lgfp, 2);
lame_set_in_samplerate( x->lgfp, sys_getsr() );
lame_set_out_samplerate( x->lgfp, x->x_samplerate );
@@ -366,60 +385,65 @@ static void mp3cast_tilde_lame_init(t_mp3cast *x)
lame_set_disable_reservoir( x->lgfp, 0 );
lame_set_padding_type( x->lgfp, PAD_NO );
ret = lame_init_params( x->lgfp );
- if ( ret<0 ) {
- post( "mp3cast~ : error : lame params initialization returned : %d", ret );
- } else {
- x->x_lame=1;
- /* magic formula copied from windows dll for MPEG-I */
- x->x_lamechunk = 2*1152;
+ if ( ret<0 )
+ {
+ post( "mp3cast~ : error : lame params initialization returned : %d", ret );
+ }
+ else
+ {
+ x->x_lame=1;
+ /* magic formula copied from windows dll for MPEG-I */
+ x->x_lamechunk = 2*1152;
- post( "mp3cast~ : lame initialization done. (%d)", x->x_lame );
+ post( "mp3cast~ : lame initialization done. (%d)", x->x_lame );
}
lame_init_bitstream( x->lgfp );
}
char *mp3cast_base64_encode(char *data)
{
- int len = strlen(data);
- char *out = t_getbytes(len*4/3 + 4);
- char *result = out;
- int chunk;
-
- while(len > 0) {
- chunk = (len >3)?3:len;
- *out++ = base64table[(*data & 0xFC)>>2];
- *out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
-
- switch(chunk) {
- case 3:
- *out++ = base64table[((*(data+1) & 0x0F)<<2) | ((*(data+2) & 0xC0)>>6)];
- *out++ = base64table[(*(data+2)) & 0x3F];
- break;
- case 2:
- *out++ = base64table[((*(data+1) & 0x0F)<<2)];
- *out++ = '=';
- break;
- case 1:
- *out++ = '=';
- *out++ = '=';
- break;
- }
- data += chunk;
- len -= chunk;
- }
- *out = 0;
+ int len = strlen(data);
+ char *out = t_getbytes(len*4/3 + 4);
+ char *result = out;
+ int chunk;
+
+ while(len > 0)
+ {
+ chunk = (len >3)?3:len;
+ *out++ = base64table[(*data & 0xFC)>>2];
+ *out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
- return result;
+ switch(chunk)
+ {
+ case 3:
+ *out++ = base64table[((*(data+1) & 0x0F)<<2) | ((*(data+2) & 0xC0)>>6)];
+ *out++ = base64table[(*(data+2)) & 0x3F];
+ break;
+ case 2:
+ *out++ = base64table[((*(data+1) & 0x0F)<<2)];
+ *out++ = '=';
+ break;
+ case 1:
+ *out++ = '=';
+ *out++ = '=';
+ break;
+ }
+ data += chunk;
+ len -= chunk;
+ }
+ *out = 0;
+
+ return result;
}
- /* connect to server */
+/* connect to server */
static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno)
{
struct sockaddr_in server;
struct hostent *hp;
int portno = fportno; /* get port from message box */
- /* information about this broadcast to be send to the server */
+ /* information about this broadcast to be send to the server */
const char *name = x->x_name; /* name of broadcast */
const char *url = x->x_url; /* url of broadcast */
const char *genre = x->x_genre; /* genre of broadcast */
@@ -430,7 +454,7 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
const char *mountpoint = x->x_mountpoint; /* mountpoint for IceCast server */
int isPublic = x->x_isPublic; /* don't publish broadcast on www.shoutcast.com */
- /* variables used for communication with server */
+ /* variables used for communication with server */
const char * buf = 0;
char resp[STRBUF_SIZE];
unsigned int len;
@@ -454,7 +478,7 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
return;
}
- /* connect socket using hostname provided in command line */
+ /* connect socket using hostname provided in command line */
server.sin_family = AF_INET;
hp = gethostbyname(hostname->s_name);
if (hp == 0)
@@ -465,10 +489,10 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
}
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
- /* assign client port number */
+ /* assign client port number */
server.sin_port = htons((unsigned short)portno);
- /* try to connect. */
+ /* try to connect. */
post("mp3cast~: connecting to port %d", portno);
if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0)
{
@@ -481,7 +505,7 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
return;
}
- /* sheck if we can read/write from/to the socket */
+ /* sheck if we can read/write from/to the socket */
FD_ZERO( &fdset);
FD_SET( sockfd, &fdset);
tv.tv_sec = 0; /* seconds */
@@ -510,16 +534,16 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
if(x->x_icecast == 0) /* SHOUTCAST */
{
- /* now try to log in at SHOUTcast server */
+ /* now try to log in at SHOUTcast server */
post("mp3cast~: logging in to SHOUTcast server...");
- /* first line is the passwd */
+ /* first line is the passwd */
buf = x->x_passwd;
send(sockfd, buf, strlen(buf), 0);
buf = "\n";
send(sockfd, buf, strlen(buf), 0);
- /* header for SHOUTcast server */
+ /* header for SHOUTcast server */
buf = "icy-name:"; /* name of broadcast */
send(sockfd, buf, strlen(buf), 0);
buf = name;
@@ -528,18 +552,18 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
send(sockfd, buf, strlen(buf), 0);
buf = url;
send(sockfd, buf, strlen(buf), 0);
-
- buf = "\nicy-genre:"; /* genre of broadcast */
+
+ buf = "\nicy-genre:"; /* genre of broadcast */
send(sockfd, buf, strlen(buf), 0);
buf = genre;
send(sockfd, buf, strlen(buf), 0);
-
- buf = "\nicy-description:"; /* description of broadcast */
+
+ buf = "\nicy-description:"; /* description of broadcast */
send(sockfd, buf, strlen(buf), 0);
buf = description;
send(sockfd, buf, strlen(buf), 0);
-
- buf = "\nicy-irc:";
+
+ buf = "\nicy-irc:";
send(sockfd, buf, strlen(buf), 0);
buf = irc;
send(sockfd, buf, strlen(buf), 0);
@@ -574,11 +598,11 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
}
else if ( x->x_icecast == 1 ) /* IceCast */
{
- /* now try to log in at IceCast server */
+ /* now try to log in at IceCast server */
post("mp3cast~: logging in to IceCast server...");
- /* send the request, a string like:
- * "SOURCE <password> /<mountpoint>\n" */
+ /* send the request, a string like:
+ * "SOURCE <password> /<mountpoint>\n" */
buf = "SOURCE ";
send(sockfd, buf, strlen(buf), 0);
buf = x->x_passwd;
@@ -631,51 +655,51 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
buf = "\n\n";
send(sockfd, buf, strlen(buf), 0);
- /* end login for IceCast */
+ /* end login for IceCast */
}
else if ( x->x_icecast == 2 ) /* Icecast 2 */
{
char *base64; /* buffer to hold 64bit encoded strings */
- /* send the request, a string like: "SOURCE /<mountpoint> HTTP/1.0\r\n" */
+ /* send the request, a string like: "SOURCE /<mountpoint> HTTP/1.0\r\n" */
buf = "SOURCE /";
send(sockfd, buf, strlen(buf), 0);
buf = x->x_mountpoint;
send(sockfd, buf, strlen(buf), 0);
buf = " HTTP/1.0\r\n";
send(sockfd, buf, strlen(buf), 0);
- /* send basic authorization as base64 encoded string */
+ /* send basic authorization as base64 encoded string */
sprintf(resp, "source:%s", x->x_passwd);
len = strlen(resp);
base64 = mp3cast_base64_encode(resp);
sprintf(resp, "Authorization: Basic %s\r\n", base64);
send(sockfd, resp, strlen(resp), 0);
t_freebytes(base64, len*4/3 + 4);
- /* send application name */
+ /* send application name */
buf = "User-Agent: mp3cast~";
send(sockfd, buf, strlen(buf), 0);
- /* send content type: mpeg */
+ /* send content type: mpeg */
buf = "\r\nContent-Type: audio/mpeg";
send(sockfd, buf, strlen(buf), 0);
- /* send the ice headers */
- /* name */
+ /* send the ice headers */
+ /* name */
buf = "\r\nice-name: ";
send(sockfd, buf, strlen(buf), 0);
buf = x->x_name;
send(sockfd, buf, strlen(buf), 0);
- /* url */
+ /* url */
buf = "\r\nice-url: ";
send(sockfd, buf, strlen(buf), 0);
buf = x->x_url;
send(sockfd, buf, strlen(buf), 0);
- /* genre */
+ /* genre */
buf = "\r\nice-genre: ";
send(sockfd, buf, strlen(buf), 0);
buf = genre;
send(sockfd, buf, strlen(buf), 0);
- /* public */
+ /* public */
buf = "\r\nice-public: ";
send(sockfd, buf, strlen(buf), 0);
- if(isPublic==0)
+ if(isPublic==0)
{
buf = "0";
}
@@ -684,25 +708,25 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
buf = "1";
}
send(sockfd, buf, strlen(buf), 0);
- /* bitrate */
+ /* bitrate */
if(sprintf(resp, "\r\nice-audio-info: bitrate=%d", x->x_bitrate) == -1)
{
error("shoutcast~: could not create audio-info");
}
send(sockfd, resp, strlen(resp), 0);
- /* description */
+ /* description */
buf = "\r\nice-description: ";
send(sockfd, buf, strlen(buf), 0);
buf = description;
send(sockfd, buf, strlen(buf), 0);
- /* end of header: write an empty line */
+ /* end of header: write an empty line */
buf = "\r\n\r\n";
send(sockfd, buf, strlen(buf), 0);
}
- /* read the anticipated response: "OK" */
+ /* read the anticipated response: "OK" */
len = recv(sockfd, resp, STRBUF_SIZE, 0);
- if ( strstr( resp, "OK" ) == NULL )
+ if ( strstr( resp, "OK" ) == NULL )
{
post("mp3cast~: login failed!");
if ( len>0 ) post("mp3cast~: server answered : %s", resp);
@@ -714,8 +738,8 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
return;
}
- /* suck anything that the other side has to say */
- // while (len = recv(sockfd, resp, STRBUF_SIZE,0))
+ /* suck anything that the other side has to say */
+ // while (len = recv(sockfd, resp, STRBUF_SIZE,0))
// {
// post("mp3cast~: server answered : %s", resp);
// }
@@ -728,14 +752,15 @@ static void mp3cast_connect(t_mp3cast *x, t_symbol *hostname, t_floatarg fportno
}
- /* close connection to SHOUTcast server */
+/* close connection to SHOUTcast server */
static void mp3cast_disconnect(t_mp3cast *x)
{
int err = -1;
if(x->x_lame >= 0)
{
- /* ignore remaining bytes */
- if ( x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, 0) < 0 ) {
+ /* ignore remaining bytes */
+ if ( x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, 0) < 0 )
+ {
post( "mp3cast~ : warning : remaining encoded bytes" );
}
lame_close( x->lgfp );
@@ -757,16 +782,16 @@ static void mp3cast_disconnect(t_mp3cast *x)
}
}
- /* set password for SHOUTcast server */
+/* set password for SHOUTcast server */
static void mp3cast_password(t_mp3cast *x, t_symbol *password)
{
post("mp3cast~ : setting password to %s", password->s_name );
x->x_passwd = password->s_name;
}
- /* settings for mp3 encoding */
+/* settings for mp3 encoding */
static void mp3cast_mpeg(t_mp3cast *x, t_floatarg fsamplerate, t_floatarg fbitrate,
- t_floatarg fmode, t_floatarg fquality)
+ t_floatarg fmode, t_floatarg fquality)
{
x->x_samplerate = fsamplerate;
if(fbitrate > MAXDATARATE)
@@ -777,11 +802,11 @@ static void mp3cast_mpeg(t_mp3cast *x, t_floatarg fsamplerate, t_floatarg fbitra
x->x_mp3mode = fmode;
x->x_mp3quality = fquality;
post("mp3cast~: setting mp3 stream to %dHz, %dkbit/s, mode %d, quality %d",
- x->x_samplerate, x->x_bitrate, x->x_mp3mode, x->x_mp3quality);
+ x->x_samplerate, x->x_bitrate, x->x_mp3mode, x->x_mp3quality);
if(x->x_fd>=0)post("mp3cast~ : reconnect to make changes take effect! ");
}
- /* print settings */
+/* print settings */
static void mp3cast_print(t_mp3cast *x)
{
const char * buf = 0;
@@ -791,18 +816,18 @@ static void mp3cast_print(t_mp3cast *x)
" bitrate: %d kbit/s", x->x_samplerate, x->x_bitrate);
switch(x->x_mp3mode)
{
- case 0 :
- buf = "stereo";
- break;
- case 1 :
- buf = "joint stereo";
- break;
- case 2 :
- buf = "dual channel";
- break;
- case 3 :
- buf = "mono";
- break;
+ case 0 :
+ buf = "stereo";
+ break;
+ case 1 :
+ buf = "joint stereo";
+ break;
+ case 2 :
+ buf = "dual channel";
+ break;
+ case 3 :
+ buf = "mono";
+ break;
}
post(" mode: %s\n"
" quality: %d", buf, x->x_mp3quality);
@@ -844,40 +869,40 @@ static void mp3cast_shoutcast(t_mp3cast *x)
post("mp3cast~: set server type to SHOUTcast");
}
- /* set mountpoint for IceCast server */
+/* set mountpoint for IceCast server */
static void mp3cast_mountpoint(t_mp3cast *x, t_symbol *mount)
{
x->x_mountpoint = mount->s_name;
post("mp3cast~: mountpoint set to %s", x->x_mountpoint);
}
- /* set namle for IceCast server */
+/* set namle for IceCast server */
static void mp3cast_name(t_mp3cast *x, t_symbol *name)
{
x->x_name = name->s_name;
post("mp3cast~: name set to %s", x->x_name);
}
- /* set url for IceCast server */
+/* set url for IceCast server */
static void mp3cast_url(t_mp3cast *x, t_symbol *url)
{
x->x_url = url->s_name;
post("mp3cast~: url set to %s", x->x_url);
}
- /* set genre for IceCast server */
+/* set genre for IceCast server */
static void mp3cast_genre(t_mp3cast *x, t_symbol *genre)
{
x->x_genre = genre->s_name;
post("mp3cast~: genre set to %s", x->x_genre);
}
- /* set isPublic for IceCast server */
+/* set isPublic for IceCast server */
static void mp3cast_isPublic(t_mp3cast *x, t_floatarg isPublic)
{
x->x_isPublic = isPublic;
char* isPublicStr;
- if(isPublic==0)
+ if(isPublic==0)
{
isPublicStr = "no";
}
@@ -888,15 +913,15 @@ static void mp3cast_isPublic(t_mp3cast *x, t_floatarg isPublic)
post("mp3cast~: isPublic set to %s", isPublicStr);
}
- /* set description for IceCast server */
+/* set description for IceCast server */
static void mp3cast_description(t_mp3cast *x, t_symbol *description)
{
x->x_description = description->s_name;
post("mp3cast~: description set to %s", x->x_description);
}
- /* clean up */
-static void mp3cast_free(t_mp3cast *x)
+/* clean up */
+static void mp3cast_free(t_mp3cast *x)
{
if(x->x_lame >= 0)
lame_close( x->lgfp );
@@ -949,7 +974,7 @@ void mp3cast_tilde_setup(void)
{
verbose(0, mp3cast_version);
mp3cast_class = class_new(gensym("mp3cast~"), (t_newmethod)mp3cast_new, (t_method)mp3cast_free,
- sizeof(t_mp3cast), 0, 0);
+ sizeof(t_mp3cast), 0, 0);
CLASS_MAINSIGNALIN(mp3cast_class, t_mp3cast, x_f );
class_addmethod(mp3cast_class, (t_method)mp3cast_dsp, gensym("dsp"), 0);
class_addmethod(mp3cast_class, (t_method)mp3cast_connect, gensym("connect"), A_SYMBOL, A_FLOAT, 0);
diff --git a/mp3fileout~.c b/mp3fileout~.c
index bacb4ac..65c4ae4 100644
--- a/mp3fileout~.c
+++ b/mp3fileout~.c
@@ -28,7 +28,7 @@
/* "And all the one who tried hard to succeed" */
/* You know who, don't you ??? */
/* ---------------------------------------------------------------------------- */
-
+
#include <m_pd.h>
#include <m_imp.h>
@@ -84,11 +84,11 @@ void mp3fileout_closesocket(int fd)
#ifndef _MSC_VER
if ( close(fd) < 0 )
{
- perror( "close" );
+ perror( "close" );
}
else
{
- post( "mp3fileout~ : closed socket : %d", fd );
+ post( "mp3fileout~ : closed socket : %d", fd );
}
#endif
#ifdef _WIN32
@@ -104,223 +104,224 @@ static t_class *mp3fileout_class;
typedef struct _mp3fileout
{
- t_object x_obj;
- t_int x_socket;
- t_int x_fd; /* file descriptor for the mp3 file */
- t_int x_eof; /* end of file is reached */
- t_int x_emit; /* indicates the ability to emit */
- t_int x_nbwaitloops;/* synchronization cycles count */
- t_int x_blocksize; /* actual blocksize */
-
- void *x_inbuffer; /* accumulation buffer for read mp3 frames */
- t_int x_inwriteposition;
- t_int x_inbuffersize;
- t_int x_framesize;
- t_int x_offset; /* offset used for decoding */
- t_int x_nbloops; /* number of perform loops */
-
- void *x_outbuffer; /* buffer to be emitted */
- t_int x_outframes; /* number of frames emitted */
- t_int x_outbuffersize;
- t_int x_outavable; /* number of available bytes to emit */
-
- t_canvas *x_canvas;
-
- t_outlet *x_connected; /* indicates state of the connection */
- t_outlet *x_endreached;/* indicates the end of file */
- t_outlet *x_frames; /* indicates the number of frames emitted */
+ t_object x_obj;
+ t_int x_socket;
+ t_int x_fd; /* file descriptor for the mp3 file */
+ t_int x_eof; /* end of file is reached */
+ t_int x_emit; /* indicates the ability to emit */
+ t_int x_nbwaitloops;/* synchronization cycles count */
+ t_int x_blocksize; /* actual blocksize */
+
+ void *x_inbuffer; /* accumulation buffer for read mp3 frames */
+ t_int x_inwriteposition;
+ t_int x_inbuffersize;
+ t_int x_framesize;
+ t_int x_offset; /* offset used for decoding */
+ t_int x_nbloops; /* number of perform loops */
+
+ void *x_outbuffer; /* buffer to be emitted */
+ t_int x_outframes; /* number of frames emitted */
+ t_int x_outbuffersize;
+ t_int x_outavable; /* number of available bytes to emit */
+
+ t_canvas *x_canvas;
+
+ t_outlet *x_connected; /* indicates state of the connection */
+ t_outlet *x_endreached;/* indicates the end of file */
+ t_outlet *x_frames; /* indicates the number of frames emitted */
} t_mp3fileout;
static int mp3fileout_search_header(t_mp3fileout *x)
{
- t_int i;
- t_int length = 0;
- struct frame hframe;
- unsigned long cheader;
- t_int ret = sizeof( unsigned long);
- t_int foffset = 0;
- unsigned int a,b,c,d;
- unsigned char buf[sizeof(unsigned long)];
- t_float nbsamplesframe = 0;
-
- while( ret>0 )
- {
- ret = read( x->x_fd, (void *)buf, sizeof( unsigned long ) );
-
- foffset+=ret;
-
- if ( ret>0 )
+ t_int i;
+ t_int length = 0;
+ struct frame hframe;
+ unsigned long cheader;
+ t_int ret = sizeof( unsigned long);
+ t_int foffset = 0;
+ unsigned int a,b,c,d;
+ unsigned char buf[sizeof(unsigned long)];
+ t_float nbsamplesframe = 0;
+
+ while( ret>0 )
{
- /* check for a valid header */
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- cheader = 0;
- cheader = a;
- cheader <<= 8;
- cheader |= b;
- cheader <<= 8;
- cheader |= c;
- cheader <<= 8;
- cheader |= d;
- if ( head_check( cheader, 0 ) )
- {
- decode_header( &hframe, cheader );
- // print_header_compact( &hframe );
- x->x_framesize = hframe.framesize;
- nbsamplesframe = ( hframe.mpeg25 ? 576 : 1152 );
- x->x_nbwaitloops = (int)(nbsamplesframe/x->x_blocksize);
- if ( x->x_nbwaitloops == 0 ) x->x_nbwaitloops = 1;
- // post ( "mp3fileout~ : will wait %d loops", x->x_nbwaitloops );
-
- // rewind file to the start of the frame
- if ( lseek( x->x_fd, -sizeof(unsigned long), SEEK_CUR ) < 0 )
+ ret = read( x->x_fd, (void *)buf, sizeof( unsigned long ) );
+
+ foffset+=ret;
+
+ if ( ret>0 )
{
- post( "mp3fileout~ : could not rewind file." );
+ /* check for a valid header */
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ cheader = 0;
+ cheader = a;
+ cheader <<= 8;
+ cheader |= b;
+ cheader <<= 8;
+ cheader |= c;
+ cheader <<= 8;
+ cheader |= d;
+ if ( head_check( cheader, 0 ) )
+ {
+ decode_header( &hframe, cheader );
+ // print_header_compact( &hframe );
+ x->x_framesize = hframe.framesize;
+ nbsamplesframe = ( hframe.mpeg25 ? 576 : 1152 );
+ x->x_nbwaitloops = (int)(nbsamplesframe/x->x_blocksize);
+ if ( x->x_nbwaitloops == 0 ) x->x_nbwaitloops = 1;
+ // post ( "mp3fileout~ : will wait %d loops", x->x_nbwaitloops );
+
+ // rewind file to the start of the frame
+ if ( lseek( x->x_fd, -sizeof(unsigned long), SEEK_CUR ) < 0 )
+ {
+ post( "mp3fileout~ : could not rewind file." );
+ }
+ if ( x->x_outframes == 0 )
+ {
+ post( "mp3fileout~ : found firstframe @ %d", foffset );
+ }
+ break;
+ }
+ // post( "mp3fileout~ : read %d bytes.", ret );
}
- if ( x->x_outframes == 0 )
+ else
{
- post( "mp3fileout~ : found firstframe @ %d", foffset );
+ if ( ret < 0 )
+ {
+ post( "mp3fileout~ : error encountered ( ret=%d )...file reading done.", ret );
+ perror( "read" );
+ x->x_eof = 1;
+ }
+ else
+ {
+ post( "mp3fileout~ : file reading done.", ret );
+ x->x_eof = 1;
+ outlet_bang( x->x_endreached );
+ }
+ return -1;
}
- break;
- }
- // post( "mp3fileout~ : read %d bytes.", ret );
- }
- else
- {
- if ( ret < 0 )
- {
- post( "mp3fileout~ : error encountered ( ret=%d )...file reading done.", ret );
- perror( "read" );
- x->x_eof = 1;
- }
- else
- {
- post( "mp3fileout~ : file reading done.", ret );
- x->x_eof = 1;
- outlet_bang( x->x_endreached );
- }
- return -1;
- }
- }
+ }
- return x->x_framesize;
+ return x->x_framesize;
}
static int mp3fileout_read_frame(t_mp3fileout *x)
{
- int size, ret;
-
- if ( x->x_fd > 0 && !x->x_eof)
- {
- if ( ( size = mp3fileout_search_header( x ) ) > 0 )
- {
- if ( size+sizeof(unsigned long) > INPUT_BUFFER_SIZE )
- {
- post( "mp3fileout~ : cannot read frame : size too big : %d", size );
- return -1;
- }
- // post( "mp3fileout~ : reading a frame : size : %d", size );
- ret = read( x->x_fd, x->x_inbuffer, size+sizeof(unsigned long) );
-
- if ( ret>0 )
- {
- memcpy( x->x_outbuffer, x->x_inbuffer, ret );
- x->x_outavable += ret;
- return ret;
- }
- else
- {
+ int size, ret;
+
+ if ( x->x_fd > 0 && !x->x_eof)
+ {
+ if ( ( size = mp3fileout_search_header( x ) ) > 0 )
+ {
+ if ( size+sizeof(unsigned long) > INPUT_BUFFER_SIZE )
+ {
+ post( "mp3fileout~ : cannot read frame : size too big : %d", size );
+ return -1;
+ }
+ // post( "mp3fileout~ : reading a frame : size : %d", size );
+ ret = read( x->x_fd, x->x_inbuffer, size+sizeof(unsigned long) );
+
+ if ( ret>0 )
+ {
+ memcpy( x->x_outbuffer, x->x_inbuffer, ret );
+ x->x_outavable += ret;
+ return ret;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ else
+ {
return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
+ }
+ }
+ else
+ {
+ return -1;
+ }
}
static int mp3fileout_send_frame(t_mp3fileout *x)
{
- int ret=0;
+ int ret=0;
if ( x->x_socket > 0 && x->x_emit )
{
- if ( ( ret = send( x->x_socket, x->x_outbuffer, x->x_outavable, MSG_NOSIGNAL ) ) < 0 )
- {
- post( "mp3fileout~ : connection lost." );
- perror( "send" );
- x->x_socket = -1;
- x->x_emit = 0;
- return -1;
- }
- else
- {
- memcpy( x->x_outbuffer, x->x_outbuffer+ret, x->x_outbuffersize-ret );
- x->x_outavable -= ret;
- x->x_outframes++;
- outlet_float( x->x_frames, x->x_outframes );
- // post( "mp3fileout~ : sent %d bytes, x->x_outavable : %d", ret, x->x_outavable );
- }
-
- }
+ if ( ( ret = send( x->x_socket, x->x_outbuffer, x->x_outavable, MSG_NOSIGNAL ) ) < 0 )
+ {
+ post( "mp3fileout~ : connection lost." );
+ perror( "send" );
+ x->x_socket = -1;
+ x->x_emit = 0;
+ return -1;
+ }
+ else
+ {
+ memcpy( x->x_outbuffer, x->x_outbuffer+ret, x->x_outbuffersize-ret );
+ x->x_outavable -= ret;
+ x->x_outframes++;
+ outlet_float( x->x_frames, x->x_outframes );
+ // post( "mp3fileout~ : sent %d bytes, x->x_outavable : %d", ret, x->x_outavable );
+ }
+
+ }
else
{
- // artificially empty buffer
- x->x_outavable = 0;
+ // artificially empty buffer
+ x->x_outavable = 0;
}
return ret;
}
static void mp3fileout_free(t_mp3fileout *x)
{
- if (x->x_socket > 0) {
+ if (x->x_socket > 0)
+ {
post( "mp3fileout~ : closing socket" );
mp3fileout_closesocket(x->x_socket);
x->x_socket = -1;
- }
- if ( x->x_fd > 0 )
- {
- if ( close( x->x_fd ) < 0 )
- {
- post( "mp3fileout~ : could not close file." );
- perror( "close" );
- }
- }
- if ( x->x_inbuffer ) freebytes( x->x_inbuffer, x->x_inbuffersize );
+ }
+ if ( x->x_fd > 0 )
+ {
+ if ( close( x->x_fd ) < 0 )
+ {
+ post( "mp3fileout~ : could not close file." );
+ perror( "close" );
+ }
+ }
+ if ( x->x_inbuffer ) freebytes( x->x_inbuffer, x->x_inbuffersize );
}
static t_int *mp3fileout_perform(t_int *w)
{
- t_mp3fileout *x = (t_mp3fileout*) (w[1]);
- int ret;
- int i = 0;
-
- x->x_blocksize = (t_int)(w[2]);
- // check new incoming data
- if ( x->x_socket > 0 )
- {
+ t_mp3fileout *x = (t_mp3fileout*) (w[1]);
+ int ret;
+ int i = 0;
+
+ x->x_blocksize = (t_int)(w[2]);
+ // check new incoming data
+ if ( x->x_socket > 0 )
+ {
if ( x->x_nbloops % x->x_nbwaitloops == 0 )
{
- /* read a frame in the file */
- if ( mp3fileout_read_frame(x) > 0 )
- {
- /* send the frame to the peer */
- mp3fileout_send_frame(x);
- }
+ /* read a frame in the file */
+ if ( mp3fileout_read_frame(x) > 0 )
+ {
+ /* send the frame to the peer */
+ mp3fileout_send_frame(x);
+ }
}
x->x_nbloops = ( x->x_nbloops+1 ) % x->x_nbwaitloops;
- }
- return (w+3);
+ }
+ return (w+3);
}
static void mp3fileout_dsp(t_mp3fileout *x, t_signal **sp)
@@ -328,117 +329,117 @@ static void mp3fileout_dsp(t_mp3fileout *x, t_signal **sp)
dsp_add(mp3fileout_perform, 2, x, sp[0]->s_n);
}
- /* start streaming */
+/* start streaming */
static void mp3fileout_start(t_mp3fileout *x)
{
x->x_emit = 1;
if ( x->x_fd > 0 )
{
- // reset file pointer
- if ( lseek( x->x_fd, 0, SEEK_SET ) < 0 )
- {
- post ( "mp3fileout~ : could not reset file pointer.");
- x->x_eof = 1;
- return;
- }
- x->x_eof = 0;
- x->x_outframes = 0;
- outlet_float( x->x_frames, x->x_outframes );
+ // reset file pointer
+ if ( lseek( x->x_fd, 0, SEEK_SET ) < 0 )
+ {
+ post ( "mp3fileout~ : could not reset file pointer.");
+ x->x_eof = 1;
+ return;
+ }
+ x->x_eof = 0;
+ x->x_outframes = 0;
+ outlet_float( x->x_frames, x->x_outframes );
}
}
- /* resume file reading */
+/* resume file reading */
static void mp3fileout_resume(t_mp3fileout *x)
{
x->x_emit = 1;
}
- /* seek in file */
+/* seek in file */
static void mp3fileout_seek(t_mp3fileout *x, t_floatarg foffset)
{
if ( foffset < 0 )
{
- post( "mp3fileout~ : wrong offset.");
- return;
+ post( "mp3fileout~ : wrong offset.");
+ return;
}
if ( x->x_fd > 0 )
{
- // reset file pointer
- if ( lseek( x->x_fd, (int)foffset, SEEK_SET ) < 0 )
- {
- post ( "mp3fileout~ : could not reset file pointer.");
- x->x_eof = 1;
- return;
- }
- x->x_eof = 0;
+ // reset file pointer
+ if ( lseek( x->x_fd, (int)foffset, SEEK_SET ) < 0 )
+ {
+ post ( "mp3fileout~ : could not reset file pointer.");
+ x->x_eof = 1;
+ return;
+ }
+ x->x_eof = 0;
}
}
- /* stop streaming */
+/* stop streaming */
static void mp3fileout_stop(t_mp3fileout *x)
{
x->x_emit = 0;
}
- /* open mp3 file */
+/* open mp3 file */
static void mp3fileout_open(t_mp3fileout *x, t_symbol *filename)
{
- // first close previous file
+ // first close previous file
if ( x->x_fd > 0 )
{
- if ( close( x->x_fd ) < 0 )
- {
- post( "mp3fileout~ : could not close file." );
- perror( "close" );
- }
- x->x_outframes = 0;
- outlet_float( x->x_frames, x->x_outframes );
+ if ( close( x->x_fd ) < 0 )
+ {
+ post( "mp3fileout~ : could not close file." );
+ perror( "close" );
+ }
+ x->x_outframes = 0;
+ outlet_float( x->x_frames, x->x_outframes );
}
if ( ( x->x_fd = open( filename->s_name, O_RDONLY ) ) < 0 )
{
- post( "mp3fileout~ : could not open file : %s", filename->s_name );
- perror( "open" );
- x->x_eof = 1;
+ post( "mp3fileout~ : could not open file : %s", filename->s_name );
+ perror( "open" );
+ x->x_eof = 1;
}
else
{
- x->x_eof = 0;
- post( "mp3fileout~ : opened file : %s ( fd = %d )", filename->s_name, x->x_fd );
+ x->x_eof = 0;
+ post( "mp3fileout~ : opened file : %s ( fd = %d )", filename->s_name, x->x_fd );
}
}
- /* connect to the peer */
+/* connect to the peer */
static void mp3fileout_connect(t_mp3fileout *x, t_symbol *hostname, t_floatarg fportno)
{
struct sockaddr_in csocket;
struct hostent *hp;
int portno = fportno; /* get port from message box */
-
- /* variables used for communication with the peer */
+
+ /* variables used for communication with the peer */
unsigned int len;
int sockfd;
-
+
#ifdef _WIN32
unsigned int ret;
#else
int ret;
#endif
-
+
if (x->x_socket >= 0)
{
error("mp3fileout~: already connected");
return;
}
-
+
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd < 0)
{
error("mp3fileout~: internal error while attempting to open socket");
return;
}
-
- /* connect socket using hostname provided in command line */
+
+ /* connect socket using hostname provided in command line */
csocket.sin_family = AF_INET;
hp = gethostbyname(hostname->s_name);
if (hp == 0)
@@ -452,11 +453,11 @@ static void mp3fileout_connect(t_mp3fileout *x, t_symbol *hostname, t_floatarg f
return;
}
memcpy((char *)&csocket.sin_addr, (char *)hp->h_addr, hp->h_length);
-
- /* assign client port number */
+
+ /* assign client port number */
csocket.sin_port = htons((unsigned short)portno);
-
- /* try to connect. */
+
+ /* try to connect. */
post("mp3fileout~: connecting to port %d", portno);
if (connect(sockfd, (struct sockaddr *) &csocket, sizeof (csocket)) < 0)
{
@@ -468,19 +469,19 @@ static void mp3fileout_connect(t_mp3fileout *x, t_symbol *hostname, t_floatarg f
#endif
return;
}
-
+
x->x_socket = sockfd;
x->x_outframes = 0;
outlet_float( x->x_frames, x->x_outframes );
- outlet_float( x->x_connected, 1 );
+ outlet_float( x->x_connected, 1 );
post( "mp3fileout~ : connected to peer" );
-
-}
- /* close connection to the peer */
+}
+
+/* close connection to the peer */
static void mp3fileout_disconnect(t_mp3fileout *x)
{
-
+
int err = -1;
if(x->x_socket >= 0) /* close socket */
{
@@ -501,12 +502,12 @@ static void *mp3fileout_new(void)
{
t_mp3fileout *x;
int i;
-
+
x = (t_mp3fileout *)pd_new(mp3fileout_class);
- x->x_connected = outlet_new( &x->x_obj, &s_float );
- x->x_frames = outlet_new( &x->x_obj, &s_float );
- x->x_endreached = outlet_new( &x->x_obj, &s_bang );
-
+ x->x_connected = outlet_new( &x->x_obj, &s_float );
+ x->x_frames = outlet_new( &x->x_obj, &s_float );
+ x->x_endreached = outlet_new( &x->x_obj, &s_bang );
+
x->x_socket = -1;
x->x_fd = -1;
x->x_eof = 0;
@@ -517,8 +518,8 @@ static void *mp3fileout_new(void)
x->x_inbuffer = (char*) getbytes( x->x_inbuffersize );
if ( !x->x_inbuffer )
{
- post( "mp3fileout~ : could not allocate buffers." );
- return NULL;
+ post( "mp3fileout~ : could not allocate buffers." );
+ return NULL;
}
memset( x->x_inbuffer, 0x0, INPUT_BUFFER_SIZE );
@@ -526,8 +527,8 @@ static void *mp3fileout_new(void)
x->x_outbuffer = (char*) getbytes( x->x_outbuffersize );
if ( !x->x_outbuffer )
{
- post( "mp3fileout~ : could not allocate buffers." );
- return NULL;
+ post( "mp3fileout~ : could not allocate buffers." );
+ return NULL;
}
memset( x->x_outbuffer, 0x0, OUTPUT_BUFFER_SIZE );
x->x_outavable = 0;
@@ -542,9 +543,9 @@ static void *mp3fileout_new(void)
void mp3fileout_tilde_setup(void)
{
verbose(0, mp3fileout_version );
- mp3fileout_class = class_new(gensym("mp3fileout~"),
- (t_newmethod) mp3fileout_new, (t_method) mp3fileout_free,
- sizeof(t_mp3fileout), 0, A_NULL);
+ mp3fileout_class = class_new(gensym("mp3fileout~"),
+ (t_newmethod) mp3fileout_new, (t_method) mp3fileout_free,
+ sizeof(t_mp3fileout), 0, A_NULL);
class_addmethod(mp3fileout_class, nullfn, gensym("signal"), 0);
class_addmethod(mp3fileout_class, (t_method) mp3fileout_dsp, gensym("dsp"), 0);
diff --git a/mp3streamin~.c b/mp3streamin~.c
index 477f11a..cacdb1b 100644
--- a/mp3streamin~.c
+++ b/mp3streamin~.c
@@ -28,7 +28,7 @@
/* "Somehow, maintain the interest." */
/* Gang Of Four -- Natural's Not In It */
/* ---------------------------------------------------------------------------- */
-
+
#include <m_pd.h>
#include <m_imp.h>
@@ -71,7 +71,7 @@
#define OUTPUT_BUFFER_SIZE 131072 /* 128k*/
#define LAME_AUDIO_CHUNK_SIZE 1152
#define BARHEIGHT 10
-#define MAX_DECODERS 10
+#define MAX_DECODERS 10
/* useful debugging functions from mpglib */
extern int decode_header( struct frame* fr, unsigned long newhead );
@@ -90,11 +90,11 @@ void mp3streamin_closesocket(int fd)
#ifndef _MSC_VER
if ( close(fd) < 0 )
{
- perror( "close" );
+ perror( "close" );
}
else
{
- post( "mp3streamin~ : closed socket : %d", fd );
+ post( "mp3streamin~ : closed socket : %d", fd );
}
#endif
#ifdef _WIN32
@@ -104,33 +104,33 @@ void mp3streamin_closesocket(int fd)
}
int setsocketoptions(int sockfd)
-{
- int sockopt = 1;
- if (setsockopt(sockfd, SOL_TCP, TCP_NODELAY, (const char*) &sockopt, sizeof(int)) < 0)
- {
- post("mp3streamin~ : setsockopt TCP_NODELAY failed");
- perror( "setsockopt" );
- return -1;
- }
- else
- {
- post("mp3streamin~ : TCP_NODELAY set");
- }
-
+{
+ int sockopt = 1;
+ if (setsockopt(sockfd, SOL_TCP, TCP_NODELAY, (const char*) &sockopt, sizeof(int)) < 0)
+ {
+ post("mp3streamin~ : setsockopt TCP_NODELAY failed");
+ perror( "setsockopt" );
+ return -1;
+ }
+ else
+ {
+ post("mp3streamin~ : TCP_NODELAY set");
+ }
+
#ifndef _MSC_VER
- sockopt = 1;
- if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(int)) < 0)
- {
- post("mp3streamin~ : setsockopt SO_REUSEADDR failed");
- perror( "setsockopt" );
- return -1;
- }
- else
- {
- post("mp3streamin~ : setsockopt SO_REUSEADDR done.");
- }
+ sockopt = 1;
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(int)) < 0)
+ {
+ post("mp3streamin~ : setsockopt SO_REUSEADDR failed");
+ perror( "setsockopt" );
+ return -1;
+ }
+ else
+ {
+ post("mp3streamin~ : setsockopt SO_REUSEADDR done.");
+ }
#endif
- return 0;
+ return 0;
}
@@ -140,33 +140,33 @@ static t_class *mp3streamin_class;
typedef struct _mp3streamin
{
- t_object x_obj;
- t_int x_instance;
- t_int x_socket;
- t_int x_shutdown;
- t_outlet *x_connectionip;
- t_int x_serversocket;
- t_int x_inpackets; /* number of packets received */
- t_int x_dpacket; /* displayed packet in status bar */
- t_int x_packetsize; /* size of the packets */
- t_int x_pblocks; /* processed blocks */
- t_int x_graphic; /* indicates if we show a graphic bar */
-
- void *x_inbuffer; /* accumulation buffer for incoming mp3 frames */
- t_int x_inwriteposition;
- t_int x_inbuffersize;
-
- t_float *x_outbuffer; /* buffer to store audio decoded data */
- t_int x_outwriteposition;
- t_int x_outreadposition;
- t_int x_outunread;
- t_int x_outbuffersize;
-
- t_canvas *x_canvas;
-
- t_int x_stream; /* indicates if a stream is connected ( meaning correct input flow ) */
- t_int x_newstream; /* at first, the stream must provide enough data to start */
- t_int x_bitrateindex; /* remember the bitrate index */
+ t_object x_obj;
+ t_int x_instance;
+ t_int x_socket;
+ t_int x_shutdown;
+ t_outlet *x_connectionip;
+ t_int x_serversocket;
+ t_int x_inpackets; /* number of packets received */
+ t_int x_dpacket; /* displayed packet in status bar */
+ t_int x_packetsize; /* size of the packets */
+ t_int x_pblocks; /* processed blocks */
+ t_int x_graphic; /* indicates if we show a graphic bar */
+
+ void *x_inbuffer; /* accumulation buffer for incoming mp3 frames */
+ t_int x_inwriteposition;
+ t_int x_inbuffersize;
+
+ t_float *x_outbuffer; /* buffer to store audio decoded data */
+ t_int x_outwriteposition;
+ t_int x_outreadposition;
+ t_int x_outunread;
+ t_int x_outbuffersize;
+
+ t_canvas *x_canvas;
+
+ t_int x_stream; /* indicates if a stream is connected ( meaning correct input flow ) */
+ t_int x_newstream; /* at first, the stream must provide enough data to start */
+ t_int x_bitrateindex; /* remember the bitrate index */
} t_mp3streamin;
@@ -177,225 +177,227 @@ int nbinstances = 0;
void mp3streamin_tilde_mpglib_init(t_mp3streamin *x)
{
- int ret;
+ int ret;
- InitMP3(&mp[x->x_instance]);
+ InitMP3(&mp[x->x_instance]);
}
static int mp3streamin_decode_input(t_mp3streamin *x)
{
- int i;
- int alength = 0;
- struct frame hframe;
- unsigned int a,b,c,d;
- unsigned long cheader;
- static char out[8192];
- signed short int *p = (signed short int *) out;
- int pbytes;
- int ret;
-
- if ( !x->x_shutdown )
- {
- /* decode first 4 bytes as the header */
- a = *((unsigned char*)x->x_inbuffer);
- b = *((unsigned char*)x->x_inbuffer+1);
- c = *((unsigned char*)x->x_inbuffer+2);
- d = *((unsigned char*)x->x_inbuffer+3);
-
- cheader = 0;
- cheader = a;
- cheader <<= 8;
- cheader |= b;
- cheader <<= 8;
- cheader |= c;
- cheader <<= 8;
- cheader |= d;
- if ( head_check( cheader, 0 ) )
- {
- // post( "mp3streamin~ : valid header ( packet=%d)", x->x_inpackets );
- decode_header( &hframe, cheader );
- // print_header_compact( &hframe );
- // when the bitrate change, reinit decoder
- if ( x->x_bitrateindex != hframe.bitrate_index )
- {
- ExitMP3(&mp[x->x_instance]);
- InitMP3(&mp[x->x_instance]);
- x->x_bitrateindex = hframe.bitrate_index;
- }
- }
- else
+ int i;
+ int alength = 0;
+ struct frame hframe;
+ unsigned int a,b,c,d;
+ unsigned long cheader;
+ static char out[8192];
+ signed short int *p = (signed short int *) out;
+ int pbytes;
+ int ret;
+
+ if ( !x->x_shutdown )
{
- post( "mp3streamin~ : error : mp3 packet received without header" );
- // ignore data
- x->x_inwriteposition = 0;
- x->x_inpackets--;
- return( -1 );
- }
+ /* decode first 4 bytes as the header */
+ a = *((unsigned char*)x->x_inbuffer);
+ b = *((unsigned char*)x->x_inbuffer+1);
+ c = *((unsigned char*)x->x_inbuffer+2);
+ d = *((unsigned char*)x->x_inbuffer+3);
+
+ cheader = 0;
+ cheader = a;
+ cheader <<= 8;
+ cheader |= b;
+ cheader <<= 8;
+ cheader |= c;
+ cheader <<= 8;
+ cheader |= d;
+ if ( head_check( cheader, 0 ) )
+ {
+ // post( "mp3streamin~ : valid header ( packet=%d)", x->x_inpackets );
+ decode_header( &hframe, cheader );
+ // print_header_compact( &hframe );
+ // when the bitrate change, reinit decoder
+ if ( x->x_bitrateindex != hframe.bitrate_index )
+ {
+ ExitMP3(&mp[x->x_instance]);
+ InitMP3(&mp[x->x_instance]);
+ x->x_bitrateindex = hframe.bitrate_index;
+ }
+ }
+ else
+ {
+ post( "mp3streamin~ : error : mp3 packet received without header" );
+ // ignore data
+ x->x_inwriteposition = 0;
+ x->x_inpackets--;
+ return( -1 );
+ }
+
+ // post( "mp3streamin~ : decoding %d bytes framesize=%d", x->x_inwriteposition, hframe.framesize );
+ ret =
+ decodeMP3(&mp[x->x_instance], (unsigned char*)x->x_inbuffer,
+ x->x_inwriteposition, (char *) p, sizeof(out), &pbytes);
- // post( "mp3streamin~ : decoding %d bytes framesize=%d", x->x_inwriteposition, hframe.framesize );
- ret =
- decodeMP3(&mp[x->x_instance], (unsigned char*)x->x_inbuffer,
- x->x_inwriteposition, (char *) p, sizeof(out), &pbytes);
-
- switch (ret) {
- case MP3_OK:
- switch (mp[x->x_instance].fr.stereo) {
- case 1:
- case 2:
- alength = ((mp[x->x_instance].fr.stereo==1)?pbytes >> 1 : pbytes >> 2);
- // post( "mp3streamin~ : processed %d samples", alength );
- // update outbuffer contents
- for ( i=0; i<alength; i++ )
+ switch (ret)
+ {
+ case MP3_OK:
+ switch (mp[x->x_instance].fr.stereo)
{
- if ( x->x_outunread >= x->x_outbuffersize-2 )
- {
- post( "mp3streamin~ : too much input ... ignored" );
- continue;
- }
- *(x->x_outbuffer+x->x_outwriteposition) = ((t_float)(*p++))/32767.0;
- x->x_outwriteposition = (x->x_outwriteposition + 1)%x->x_outbuffersize;
- *(x->x_outbuffer+x->x_outwriteposition) =
- ((mp[x->x_instance].fr.stereo==2)?((t_float)(*p++))/32767.0 : 0.0);
- x->x_outwriteposition = (x->x_outwriteposition + 1)%x->x_outbuffersize;
- x->x_outunread+=2;
-
- if ( x->x_outunread > MIN_AUDIO_INPUT && !x->x_stream )
- {
- post( "mp3streamin~ : stream connected." );
- x->x_stream = 1;
- }
+ case 1:
+ case 2:
+ alength = ((mp[x->x_instance].fr.stereo==1)?pbytes >> 1 : pbytes >> 2);
+ // post( "mp3streamin~ : processed %d samples", alength );
+ // update outbuffer contents
+ for ( i=0; i<alength; i++ )
+ {
+ if ( x->x_outunread >= x->x_outbuffersize-2 )
+ {
+ post( "mp3streamin~ : too much input ... ignored" );
+ continue;
+ }
+ *(x->x_outbuffer+x->x_outwriteposition) = ((t_float)(*p++))/32767.0;
+ x->x_outwriteposition = (x->x_outwriteposition + 1)%x->x_outbuffersize;
+ *(x->x_outbuffer+x->x_outwriteposition) =
+ ((mp[x->x_instance].fr.stereo==2)?((t_float)(*p++))/32767.0 : 0.0);
+ x->x_outwriteposition = (x->x_outwriteposition + 1)%x->x_outbuffersize;
+ x->x_outunread+=2;
+
+ if ( x->x_outunread > MIN_AUDIO_INPUT && !x->x_stream )
+ {
+ post( "mp3streamin~ : stream connected." );
+ x->x_stream = 1;
+ }
+ }
+
+ break;
+ default:
+ alength = -1;
+ break;
}
+ break;
+ case MP3_NEED_MORE:
+ post( "mp3streamin~ : retry lame decoding (more data needed)." );
+ alength = 0;
break;
- default:
+
+ case MP3_ERR:
+ post( "mp3streamin~ : lame decoding failed." );
alength = -1;
break;
- }
- break;
- case MP3_NEED_MORE:
- post( "mp3streamin~ : retry lame decoding (more data needed)." );
- alength = 0;
- break;
-
- case MP3_ERR:
- post( "mp3streamin~ : lame decoding failed." );
- alength = -1;
- break;
+ }
+ x->x_inwriteposition = 0;
+ }
+ else
+ {
+ if ( x->x_outunread == 0 )
+ {
+ post( "mp3streamin~ : connection closed" );
+ mp3streamin_closesocket(x->x_socket);
+ x->x_stream = 0;
+ x->x_newstream = 0;
+ x->x_inpackets = 0;
+ x->x_inwriteposition = 0;
+ x->x_bitrateindex = -1;
+ x->x_socket=-1;
+ outlet_symbol( x->x_connectionip, gensym("") );
+ }
}
- x->x_inwriteposition = 0;
- }
- else
- {
- if ( x->x_outunread == 0 )
- {
- post( "mp3streamin~ : connection closed" );
- mp3streamin_closesocket(x->x_socket);
- x->x_stream = 0;
- x->x_newstream = 0;
- x->x_inpackets = 0;
- x->x_inwriteposition = 0;
- x->x_bitrateindex = -1;
- x->x_socket=-1;
- outlet_symbol( x->x_connectionip, gensym("") );
- }
- }
-
- if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
- {
- /* update graphical read status */
- if ( x->x_inpackets != x->x_dpacket )
- {
- char color[32];
- int minpackets = ( MIN_AUDIO_INPUT/LAME_AUDIO_CHUNK_SIZE )-2; // audio loop has eaten some already
+ if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
+ {
+ /* update graphical read status */
+ if ( x->x_inpackets != x->x_dpacket )
+ {
+ char color[32];
+ int minpackets = ( MIN_AUDIO_INPUT/LAME_AUDIO_CHUNK_SIZE )-2; // audio loop has eaten some already
sys_vgui(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x );
sys_vgui(".x%lx.c delete line %xTHRESHOLD\n", x->x_canvas, x );
if ( x->x_outunread > 0 )
{
- t_int width;
-
- if ( x->x_inpackets < (MIN_AUDIO_INPUT/LAME_AUDIO_CHUNK_SIZE)/2 )
- {
- strcpy( color, "red" );
- }
- else
- {
- strcpy( color, "lightgreen" );
- }
- width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
- sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xSTATUS\n",
- x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
- x->x_obj.te_xpix+(x->x_inpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
- x->x_obj.te_ypix - 1, color, x );
- sys_vgui(".x%lx.c create line %d %d %d %d -fill red -tags %xTHRESHOLD\n",
- x->x_canvas, x->x_obj.te_xpix+(minpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
- x->x_obj.te_ypix-BARHEIGHT-1,
- x->x_obj.te_xpix+(minpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
- x->x_obj.te_ypix-1, x );
- x->x_dpacket = x->x_inpackets;
+ t_int width;
+
+ if ( x->x_inpackets < (MIN_AUDIO_INPUT/LAME_AUDIO_CHUNK_SIZE)/2 )
+ {
+ strcpy( color, "red" );
+ }
+ else
+ {
+ strcpy( color, "lightgreen" );
+ }
+ width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xSTATUS\n",
+ x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
+ x->x_obj.te_xpix+(x->x_inpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
+ x->x_obj.te_ypix - 1, color, x );
+ sys_vgui(".x%lx.c create line %d %d %d %d -fill red -tags %xTHRESHOLD\n",
+ x->x_canvas, x->x_obj.te_xpix+(minpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
+ x->x_obj.te_ypix-BARHEIGHT-1,
+ x->x_obj.te_xpix+(minpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
+ x->x_obj.te_ypix-1, x );
+ x->x_dpacket = x->x_inpackets;
}
else
{
- if ( x->x_shutdown )
- {
- x->x_shutdown=0;
- sys_vgui(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
- sys_vgui(".x%lx.c delete line %xTHRESHOLD\n", x->x_canvas, x );
- }
+ if ( x->x_shutdown )
+ {
+ x->x_shutdown=0;
+ sys_vgui(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
+ sys_vgui(".x%lx.c delete line %xTHRESHOLD\n", x->x_canvas, x );
+ }
}
- }
- }
- return alength;
+ }
+ }
+ return alength;
}
static void mp3streamin_recv(t_mp3streamin *x)
{
- int ret;
+ int ret;
- if ( ( ret = recv(x->x_socket, (void*) (x->x_inbuffer + x->x_inwriteposition),
- (size_t)((x->x_inbuffersize-x->x_inwriteposition)),
- MSG_NOSIGNAL) ) < 0 )
- {
+ if ( ( ret = recv(x->x_socket, (void*) (x->x_inbuffer + x->x_inwriteposition),
+ (size_t)((x->x_inbuffersize-x->x_inwriteposition)),
+ MSG_NOSIGNAL) ) < 0 )
+ {
post( "mp3_streamin~ : receive error" );
perror( "recv" );
- return;
- }
- else
- {
- // post( "streamin~ : received %d bytes at %d on %d ( up to %d)",
+ return;
+ }
+ else
+ {
+ // post( "streamin~ : received %d bytes at %d on %d ( up to %d)",
// ret, x->x_inwriteposition, x->x_socket,
// x->x_inbuffersize-x->x_inwriteposition*sizeof( unsigned long) );
- if ( ret == 0 )
+ if ( ret == 0 )
{
- /* initiate the shutdown phase */
- x->x_shutdown=1;
+ /* initiate the shutdown phase */
+ x->x_shutdown=1;
}
else
- {
- // check we don't overflow input buffer
- if ( (x->x_inpackets+1)*x->x_packetsize > x->x_inbuffersize )
- {
- post( "mp3streamin~ : too much input...resetting" );
- x->x_inpackets=0;
- x->x_inwriteposition=0;
- return;
- }
- x->x_inpackets++;
- x->x_packetsize=ret;
- if ( x->x_inpackets % 100 == 0 )
- {
- // post( "mp3streamin~ : received %d packets", x->x_inpackets );
- }
- x->x_inwriteposition += ret;
+ {
+ // check we don't overflow input buffer
+ if ( (x->x_inpackets+1)*x->x_packetsize > x->x_inbuffersize )
+ {
+ post( "mp3streamin~ : too much input...resetting" );
+ x->x_inpackets=0;
+ x->x_inwriteposition=0;
+ return;
+ }
+ x->x_inpackets++;
+ x->x_packetsize=ret;
+ if ( x->x_inpackets % 100 == 0 )
+ {
+ // post( "mp3streamin~ : received %d packets", x->x_inpackets );
+ }
+ x->x_inwriteposition += ret;
}
-
+
mp3streamin_decode_input(x);
- }
+ }
}
static void mp3streamin_acceptconnection(t_mp3streamin *x)
@@ -405,23 +407,25 @@ static void mp3streamin_acceptconnection(t_mp3streamin *x)
int fd = accept(x->x_serversocket, (struct sockaddr*)&incomer_address, &sockaddrl );
- if (fd < 0) {
- post("mp3streamin~: accept failed");
- return;
+ if (fd < 0)
+ {
+ post("mp3streamin~: accept failed");
+ return;
}
- if (x->x_socket > 0) {
- sys_addpollfn(fd, (t_fdpollfn)mp3streamin_recv, x);
- if ( x->x_outunread != 0 )
- {
- post("mp3streamin~: still have some data to decode, retry later you %s.",
+ if (x->x_socket > 0)
+ {
+ sys_addpollfn(fd, (t_fdpollfn)mp3streamin_recv, x);
+ if ( x->x_outunread != 0 )
+ {
+ post("mp3streamin~: still have some data to decode, retry later you %s.",
inet_ntoa( incomer_address.sin_addr ));
- mp3streamin_closesocket( fd );
- return;
- }
- post("mp3streamin~: the source has changed to %s.",
- inet_ntoa( incomer_address.sin_addr ));
- mp3streamin_closesocket(x->x_socket);
+ mp3streamin_closesocket( fd );
+ return;
+ }
+ post("mp3streamin~: the source has changed to %s.",
+ inet_ntoa( incomer_address.sin_addr ));
+ mp3streamin_closesocket(x->x_socket);
}
x->x_socket = fd;
@@ -430,12 +434,12 @@ static void mp3streamin_acceptconnection(t_mp3streamin *x)
if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
{
- t_int width;
-
- width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
- sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill lightblue -tags %xPBAR\n",
- x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
- x->x_obj.te_xpix + width, x->x_obj.te_ypix - 1, x );
+ t_int width;
+
+ width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill lightblue -tags %xPBAR\n",
+ x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
+ x->x_obj.te_xpix + width, x->x_obj.te_ypix - 1, x );
}
x->x_stream = 0;
x->x_newstream = 1;
@@ -453,8 +457,8 @@ static int mp3streamin_startservice(t_mp3streamin* x, int portno)
if (sockfd < 0)
{
- sys_sockerror("socket");
- return (0);
+ sys_sockerror("socket");
+ return (0);
}
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
@@ -466,67 +470,71 @@ static int mp3streamin_startservice(t_mp3streamin* x, int portno)
setsocketoptions(sockfd);
/* name the socket */
- if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) {
- sys_sockerror("bind");
- mp3streamin_closesocket(sockfd);
- return (0);
+ if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
+ {
+ sys_sockerror("bind");
+ mp3streamin_closesocket(sockfd);
+ return (0);
}
- if (listen(sockfd, 5) < 0) {
- sys_sockerror("listen");
- mp3streamin_closesocket(sockfd);
+ if (listen(sockfd, 5) < 0)
+ {
+ sys_sockerror("listen");
+ mp3streamin_closesocket(sockfd);
}
- else
+ else
{
- x->x_serversocket = sockfd;
- sys_addpollfn(x->x_serversocket, (t_fdpollfn)mp3streamin_acceptconnection, x);
+ x->x_serversocket = sockfd;
+ sys_addpollfn(x->x_serversocket, (t_fdpollfn)mp3streamin_acceptconnection, x);
}
-
+
return 1;
}
static void mp3streamin_free(t_mp3streamin *x)
{
- post( "mp3streamin~ : free %x", x );
- if (x->x_serversocket > 0) {
+ post( "mp3streamin~ : free %x", x );
+ if (x->x_serversocket > 0)
+ {
post( "mp3streamin~ : closing server socket" );
- mp3streamin_closesocket(x->x_serversocket);
+ mp3streamin_closesocket(x->x_serversocket);
x->x_serversocket = -1;
- }
- if (x->x_socket > 0) {
+ }
+ if (x->x_socket > 0)
+ {
post( "mp3streamin~ : closing socket" );
mp3streamin_closesocket(x->x_socket);
x->x_socket = -1;
- }
- if ( x->x_inbuffer ) freebytes( x->x_inbuffer, x->x_inbuffersize );
- if ( x->x_outbuffer ) freebytes( x->x_outbuffer, x->x_outbuffersize*sizeof(t_float) );
- if ( x->x_instance == nbinstances-1 )
- {
+ }
+ if ( x->x_inbuffer ) freebytes( x->x_inbuffer, x->x_inbuffersize );
+ if ( x->x_outbuffer ) freebytes( x->x_outbuffer, x->x_outbuffersize*sizeof(t_float) );
+ if ( x->x_instance == nbinstances-1 )
+ {
nbinstances--;
- }
+ }
}
static t_int *mp3streamin_perform(t_int *w)
{
- t_mp3streamin *x = (t_mp3streamin*) (w[1]);
- t_float *out1 = (t_float *)(w[2]);
- t_float *out2 = (t_float *)(w[3]);
- int n = (int)(w[4]);
- int bsize = n;
- int ret;
- int i = 0;
-
- while( n-- )
- {
- if ( ( ( x->x_outunread > MIN_AUDIO_INPUT ) && x->x_newstream ) || // wait the buffer to load
- ( ( x->x_shutdown ) && ( x->x_outunread >= 2 ) ) || // clean disconnection
- ( x->x_stream ) // check that the stream provides enough data
- )
- {
+ t_mp3streamin *x = (t_mp3streamin*) (w[1]);
+ t_float *out1 = (t_float *)(w[2]);
+ t_float *out2 = (t_float *)(w[3]);
+ int n = (int)(w[4]);
+ int bsize = n;
+ int ret;
+ int i = 0;
+
+ while( n-- )
+ {
+ if ( ( ( x->x_outunread > MIN_AUDIO_INPUT ) && x->x_newstream ) || // wait the buffer to load
+ ( ( x->x_shutdown ) && ( x->x_outunread >= 2 ) ) || // clean disconnection
+ ( x->x_stream ) // check that the stream provides enough data
+ )
+ {
if ( x->x_newstream && !x->x_shutdown )
{
- x->x_newstream = 0;
- x->x_stream = 1;
+ x->x_newstream = 0;
+ x->x_stream = 1;
}
*out1++=*(x->x_outbuffer+x->x_outreadposition);
x->x_outreadposition = (x->x_outreadposition + 1)%x->x_outbuffersize;
@@ -534,50 +542,50 @@ static t_int *mp3streamin_perform(t_int *w)
x->x_outreadposition = (x->x_outreadposition + 1)%x->x_outbuffersize;
x->x_outunread-=2;
if ( n == 1 ) x->x_pblocks++;
- }
- else
- {
+ }
+ else
+ {
*out1++=0.0;
*out2++=0.0;
- }
- }
-
- if ( ( x->x_outunread <= MIN_AUDIO_INPUT/10 ) && ( x->x_stream ) )
- {
- post( "mp3streamin~ : stream lost (too little input)" );
- x->x_stream = 0;
- x->x_newstream = 1; // waiting for a new stream
- }
-
- if ( x->x_pblocks == LAME_AUDIO_CHUNK_SIZE/bsize )
- {
+ }
+ }
+
+ if ( ( x->x_outunread <= MIN_AUDIO_INPUT/10 ) && ( x->x_stream ) )
+ {
+ post( "mp3streamin~ : stream lost (too little input)" );
+ x->x_stream = 0;
+ x->x_newstream = 1; // waiting for a new stream
+ }
+
+ if ( x->x_pblocks == LAME_AUDIO_CHUNK_SIZE/bsize )
+ {
x->x_inpackets--;
x->x_pblocks = 0;
- }
+ }
#ifdef DO_MY_OWN_SELECT
- // check new incoming data
- if ( x->x_socket > 0 )
- {
- fd_set readset;
- fd_set exceptset;
-
- FD_ZERO(&readset);
- FD_ZERO(&exceptset);
- FD_SET(x->x_socket, &readset );
- FD_SET(x->x_socket, &exceptset );
-
- if ( select( maxfd+1, &readset, NULL, &exceptset, &ztout ) >0 )
- {
- if ( FD_ISSET( x->x_socket, &readset) || FD_ISSET( x->x_socket, &exceptset ) )
- {
- /* receive data or error and decode it */
- mp3streamin_recv(x);
- }
- }
- }
+ // check new incoming data
+ if ( x->x_socket > 0 )
+ {
+ fd_set readset;
+ fd_set exceptset;
+
+ FD_ZERO(&readset);
+ FD_ZERO(&exceptset);
+ FD_SET(x->x_socket, &readset );
+ FD_SET(x->x_socket, &exceptset );
+
+ if ( select( maxfd+1, &readset, NULL, &exceptset, &ztout ) >0 )
+ {
+ if ( FD_ISSET( x->x_socket, &readset) || FD_ISSET( x->x_socket, &exceptset ) )
+ {
+ /* receive data or error and decode it */
+ mp3streamin_recv(x);
+ }
+ }
+ }
#endif
- return (w+5);
+ return (w+5);
}
static void mp3streamin_dsp(t_mp3streamin *x, t_signal **sp)
@@ -590,16 +598,16 @@ static void *mp3streamin_new(t_floatarg fportno, t_floatarg fdographics)
{
t_mp3streamin *x;
int i;
-
+
if ( fportno < 0 || fportno > 65535 )
{
- post( "mp3streamin~ : error : wrong portnumber : %d", (int)fportno );
- return NULL;
+ post( "mp3streamin~ : error : wrong portnumber : %d", (int)fportno );
+ return NULL;
}
if ( ((int)fdographics != 0) && ((int)fdographics != 1.) )
{
- post( "mp3streamin~ : error : constructor : mp3streamin~ <portnumber> [graphic flag = 0 | 1 ] ( got = %f)", fdographics );
- return NULL;
+ post( "mp3streamin~ : error : constructor : mp3streamin~ <portnumber> [graphic flag = 0 | 1 ] ( got = %f)", fdographics );
+ return NULL;
}
x = (t_mp3streamin *)pd_new(mp3streamin_class);
@@ -607,7 +615,7 @@ static void *mp3streamin_new(t_floatarg fportno, t_floatarg fdographics)
outlet_new(&x->x_obj, &s_signal);
outlet_new(&x->x_obj, &s_signal);
x->x_connectionip = outlet_new(&x->x_obj, &s_symbol);
-
+
x->x_serversocket = -1;
x->x_socket = -1;
x->x_shutdown = 0;
@@ -617,7 +625,7 @@ static void *mp3streamin_new(t_floatarg fportno, t_floatarg fdographics)
x->x_canvas = canvas_getcurrent();
x->x_inbuffersize = INPUT_BUFFER_SIZE;
- x->x_outbuffersize = OUTPUT_BUFFER_SIZE;
+ x->x_outbuffersize = OUTPUT_BUFFER_SIZE;
x->x_inbuffer = (char*) getbytes( x->x_inbuffersize );
memset( x->x_inbuffer, 0x0, INPUT_BUFFER_SIZE );
x->x_outbuffer = (t_float*) getbytes( x->x_outbuffersize*sizeof(t_float) );
@@ -625,25 +633,25 @@ static void *mp3streamin_new(t_floatarg fportno, t_floatarg fdographics)
if ( !x->x_inbuffer || !x->x_outbuffer )
{
- post( "mp3streamin~ : could not allocate buffers." );
- return NULL;
+ post( "mp3streamin~ : could not allocate buffers." );
+ return NULL;
}
- if ( nbinstances < MAX_DECODERS )
+ if ( nbinstances < MAX_DECODERS )
{
- x->x_instance = nbinstances++;
+ x->x_instance = nbinstances++;
}
else
{
- post( "mp3streamin~ : cannot create more decoders (memory issues), sorry" );
- return NULL;
+ post( "mp3streamin~ : cannot create more decoders (memory issues), sorry" );
+ return NULL;
}
x->x_inwriteposition = 0;
x->x_outreadposition = 0;
x->x_outwriteposition = 0;
x->x_outunread = 0;
-
+
ztout.tv_sec = 0;
ztout.tv_usec = 0;
@@ -662,9 +670,9 @@ static void *mp3streamin_new(t_floatarg fportno, t_floatarg fdographics)
void mp3streamin_tilde_setup(void)
{
verbose(0, mp3streamin_version );
- mp3streamin_class = class_new(gensym("mp3streamin~"),
- (t_newmethod) mp3streamin_new, (t_method) mp3streamin_free,
- sizeof(t_mp3streamin), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT, A_NULL);
+ mp3streamin_class = class_new(gensym("mp3streamin~"),
+ (t_newmethod) mp3streamin_new, (t_method) mp3streamin_free,
+ sizeof(t_mp3streamin), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT, A_NULL);
class_addmethod(mp3streamin_class, nullfn, gensym("signal"), 0);
class_addmethod(mp3streamin_class, (t_method) mp3streamin_dsp, gensym("dsp"), 0);
diff --git a/mp3streamout~.c b/mp3streamout~.c
index 88fec11..5f089dc 100644
--- a/mp3streamout~.c
+++ b/mp3streamout~.c
@@ -70,8 +70,8 @@ extern void print_header_compact( struct frame* fr );
extern int head_check( unsigned long head, int check_layer );
#define MY_MP3_MALLOC_IN_SIZE 65536
- /* max size taken from lame readme */
-#define MY_MP3_MALLOC_OUT_SIZE 1.25*MY_MP3_MALLOC_IN_SIZE+7200
+/* max size taken from lame readme */
+#define MY_MP3_MALLOC_OUT_SIZE 1.25*MY_MP3_MALLOC_IN_SIZE+7200
#define MAXDATARATE 320 /* maximum mp3 data rate is 320kbit/s */
#define STRBUF_SIZE 32
@@ -84,12 +84,12 @@ typedef struct _mp3streamout
{
t_object x_obj;
- /* LAME stuff */
+ /* LAME stuff */
int x_lame; /* info about encoder status */
int x_lamechunk; /* chunk size for LAME encoder */
int x_mp3size; /* number of returned mp3 samples */
- /* buffer stuff */
+ /* buffer stuff */
unsigned short x_inp; /* in position for buffer */
unsigned short x_outp; /* out position for buffer*/
short *x_mp3inbuf; /* data to be sent to LAME */
@@ -98,13 +98,13 @@ typedef struct _mp3streamout
int x_bytesbuffered; /* number of unprocessed bytes in buffer */
int x_start;
- /* mp3 format stuff */
+ /* mp3 format stuff */
int x_samplerate;
int x_bitrate; /* bitrate of mp3 stream */
int x_mp3mode; /* mode (mono, joint stereo, stereo, dual mono) */
int x_mp3quality; /* quality of encoding */
- /* connection data */
+ /* connection data */
int x_fd; /* info about connection status */
int x_outpackets; /* mp3 packets sent */
@@ -114,7 +114,7 @@ typedef struct _mp3streamout
} t_mp3streamout;
- /* encode PCM data to mp3 stream */
+/* encode PCM data to mp3 stream */
static void mp3streamout_encode(t_mp3streamout *x)
{
unsigned short i, wp;
@@ -131,11 +131,11 @@ static void mp3streamout_encode(t_mp3streamout *x)
return;
}
- /* on start/reconnect set outpoint that it not interferes with inpoint */
+ /* on start/reconnect set outpoint that it not interferes with inpoint */
if(x->x_start == -1)
{
post("mp3streamout~: initializing buffers");
- /* we try to keep 2.5 times the data the encoder needs in the buffer */
+ /* we try to keep 2.5 times the data the encoder needs in the buffer */
if(x->x_inp > (2 * x->x_lamechunk))
{
x->x_outp = (short) x->x_inp - (2.5 * x->x_lamechunk);
@@ -150,10 +150,10 @@ static void mp3streamout_encode(t_mp3streamout *x)
i = MY_MP3_MALLOC_IN_SIZE - x->x_outp;
- /* read from buffer */
- if(x->x_lamechunk <= i)
+ /* read from buffer */
+ if(x->x_lamechunk <= i)
{
- /* enough data until end of buffer */
+ /* enough data until end of buffer */
for(n = 0; n < x->x_lamechunk; n++) /* fill encode buffer */
{
x->x_mp3inbuf[n] = x->x_buffer[n + x->x_outp];
@@ -174,15 +174,15 @@ static void mp3streamout_encode(t_mp3streamout *x)
x->x_outp = x->x_lamechunk - i;
}
- /* encode mp3 data */
+ /* encode mp3 data */
- x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf,
- x->x_lamechunk/lame_get_num_channels(x->lgfp),
+ x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf,
+ x->x_lamechunk/lame_get_num_channels(x->lgfp),
x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE);
x->x_mp3size+=lame_encode_flush( x->lgfp, x->x_mp3outbuf+x->x_mp3size, MY_MP3_MALLOC_OUT_SIZE-x->x_mp3size );
// post( "mp3streamout~ : encoding returned %d frames", x->x_mp3size );
- /* check result */
+ /* check result */
if(x->x_mp3size<0)
{
lame_close( x->lgfp );
@@ -191,21 +191,21 @@ static void mp3streamout_encode(t_mp3streamout *x)
}
}
- /* stream mp3 to the peer */
+/* stream mp3 to the peer */
static void mp3streamout_stream(t_mp3streamout *x)
{
- int count = -1, i;
+ int count = -1, i;
struct frame hframe;
/* header needs to be included in each packet */
for( i=0; i<x->x_mp3size; i++ )
{
- // track valid data
- if ( head_check( *((unsigned long*)x->x_mp3outbuf+i), 3 ) )
- {
- // post( "valid header emitted @ %d (byte %d)", i, i*sizeof(unsigned long) );
- }
+ // track valid data
+ if ( head_check( *((unsigned long*)x->x_mp3outbuf+i), 3 ) )
+ {
+ // post( "valid header emitted @ %d (byte %d)", i, i*sizeof(unsigned long) );
+ }
}
count = send(x->x_fd, x->x_mp3outbuf, x->x_mp3size, MSG_NOSIGNAL);
@@ -221,23 +221,23 @@ static void mp3streamout_stream(t_mp3streamout *x)
#endif
x->x_fd = -1;
outlet_float(x->x_obj.ob_outlet, 0);
- }
+ }
else
{
x->x_outpackets++;
if ( x->x_outpackets%100 == 0 )
{
- // post( "mp3streamout~ : emitted %d bytes (packets = %d)", count, x->x_outpackets );
+ // post( "mp3streamout~ : emitted %d bytes (packets = %d)", count, x->x_outpackets );
}
}
if((count > 0)&&(count != x->x_mp3size))
{
- error("mp3streamout~: %d bytes skipped", x->x_mp3size - count);
+ error("mp3streamout~: %d bytes skipped", x->x_mp3size - count);
}
}
-
- /* buffer data as channel interleaved PCM */
+
+/* buffer data as channel interleaved PCM */
static t_int *mp3streamout_perform(t_int *w)
{
t_float *in1 = (t_float *)(w[1]); /* left audio inlet */
@@ -247,76 +247,94 @@ static t_int *mp3streamout_perform(t_int *w)
unsigned short i,wp;
float in;
- /* copy the data into the buffer */
+ /* copy the data into the buffer */
i = MY_MP3_MALLOC_IN_SIZE - x->x_inp; /* space left at the end of buffer */
-
+
n *= 2; /* two channels go into one buffer */
- if( n <= i )
+ if( n <= i )
{
/* the place between inp and MY_MP3_MALLOC_IN_SIZE */
/* is big enough to hold the data */
- for(wp = 0; wp < n; wp++)
+ for(wp = 0; wp < n; wp++)
+ {
+ if(wp%2)
+ {
+ in = *(in2++); /* right channel / inlet */
+ }
+ else
+ {
+ in = *(in1++); /* left channel / inlet */
+ }
+ if (in > 1.0)
+ {
+ in = 1.0;
+ }
+ if (in < -1.0)
{
- if(wp%2)
- {
- in = *(in2++); /* right channel / inlet */
- }
- else
- {
- in = *(in1++); /* left channel / inlet */
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ in = -1.0;
}
- x->x_inp += n; /* n more samples written to buffer */
- }
- else
+ x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ }
+ x->x_inp += n; /* n more samples written to buffer */
+ }
+ else
{
- /* the place between inp and MY_MP3_MALLOC_IN_SIZE is not */
- /* big enough to hold the data */
- /* writing will take place in two turns, one from */
- /* x->x_inp -> MY_MP3_MALLOC_IN_SIZE, then from 0 on */
+ /* the place between inp and MY_MP3_MALLOC_IN_SIZE is not */
+ /* big enough to hold the data */
+ /* writing will take place in two turns, one from */
+ /* x->x_inp -> MY_MP3_MALLOC_IN_SIZE, then from 0 on */
- for(wp = 0; wp < i; wp++) /* fill up to end of buffer */
+ for(wp = 0; wp < i; wp++) /* fill up to end of buffer */
+ {
+ if(wp%2)
+ {
+ in = *(in2++);
+ }
+ else
+ {
+ in = *(in1++);
+ }
+ if (in > 1.0)
+ {
+ in = 1.0;
+ }
+ if (in < -1.0)
+ {
+ in = -1.0;
+ }
+ x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ }
+ for(wp = i; wp < n; wp++) /* write rest at start of buffer */
+ {
+ if(wp%2)
+ {
+ in = *(in2++);
+ }
+ else
+ {
+ in = *(in1++);
+ }
+ if (in > 1.0)
{
- if(wp%2)
- {
- in = *(in2++);
- }
- else
- {
- in = *(in1++);
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ in = 1.0;
}
- for(wp = i; wp < n; wp++) /* write rest at start of buffer */
+ if (in < -1.0)
{
- if(wp%2)
- {
- in = *(in2++);
- }
- else
- {
- in = *(in1++);
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp - i] = (short) (32767.0 * in);
+ in = -1.0;
}
- x->x_inp = n - i; /* new writeposition in buffer */
+ x->x_buffer[wp - i] = (short) (32767.0 * in);
+ }
+ x->x_inp = n - i; /* new writeposition in buffer */
}
if((x->x_fd >= 0)&&(x->x_lame >= 0))
- {
- /* count buffered samples when things are running */
+ {
+ /* count buffered samples when things are running */
x->x_bytesbuffered += n;
- /* encode and send to the peer */
+ /* encode and send to the peer */
if(x->x_bytesbuffered > x->x_lamechunk)
{
mp3streamout_encode(x); /* encode to mp3 */
@@ -336,7 +354,7 @@ static void mp3streamout_dsp(t_mp3streamout *x, t_signal **sp)
dsp_add(mp3streamout_perform, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n);
}
- /* initialize the lame library */
+/* initialize the lame library */
static void mp3streamout_tilde_lame_init(t_mp3streamout *x)
{
int ret;
@@ -357,11 +375,11 @@ static void mp3streamout_tilde_lame_init(t_mp3streamout *x)
}
#endif
{
- const char *lameVersion = get_lame_version();
- verbose(0, "mp3streamout~ : using lame version : %s", lameVersion );
+ const char *lameVersion = get_lame_version();
+ verbose(0, "mp3streamout~ : using lame version : %s", lameVersion );
}
- /* setting lame parameters */
+ /* setting lame parameters */
lame_set_num_channels( x->lgfp, 2);
lame_set_in_samplerate( x->lgfp, sys_getsr() );
lame_set_out_samplerate( x->lgfp, x->x_samplerate );
@@ -374,26 +392,29 @@ static void mp3streamout_tilde_lame_init(t_mp3streamout *x)
lame_set_disable_reservoir( x->lgfp, 0 );
lame_set_padding_type( x->lgfp, PAD_NO );
ret = lame_init_params( x->lgfp );
- if ( ret<0 ) {
- post( "mp3streamout~ : error : lame params initialization returned : %d", ret );
- } else {
- x->x_lame=1;
- /* magic formula copied from windows dll for MPEG-I */
- x->x_lamechunk = 2*1152;
-
- post( "mp3streamout~ : lame initialization done. (%d)", x->x_lame );
+ if ( ret<0 )
+ {
+ post( "mp3streamout~ : error : lame params initialization returned : %d", ret );
+ }
+ else
+ {
+ x->x_lame=1;
+ /* magic formula copied from windows dll for MPEG-I */
+ x->x_lamechunk = 2*1152;
+
+ post( "mp3streamout~ : lame initialization done. (%d)", x->x_lame );
}
lame_init_bitstream( x->lgfp );
}
- /* connect to the peer */
+/* connect to the peer */
static void mp3streamout_connect(t_mp3streamout *x, t_symbol *hostname, t_floatarg fportno)
{
struct sockaddr_in csocket;
struct hostent *hp;
int portno = fportno; /* get port from message box */
- /* variables used for communication with the peer */
+ /* variables used for communication with the peer */
const char *buf = 0;
char resp[STRBUF_SIZE];
unsigned int len;
@@ -418,7 +439,7 @@ static void mp3streamout_connect(t_mp3streamout *x, t_symbol *hostname, t_floata
return;
}
- /* connect socket using hostname provided in command line */
+ /* connect socket using hostname provided in command line */
csocket.sin_family = AF_INET;
hp = gethostbyname(hostname->s_name);
if (hp == 0)
@@ -433,10 +454,10 @@ static void mp3streamout_connect(t_mp3streamout *x, t_symbol *hostname, t_floata
}
memcpy((char *)&csocket.sin_addr, (char *)hp->h_addr, hp->h_length);
- /* assign client port number */
+ /* assign client port number */
csocket.sin_port = htons((unsigned short)portno);
- /* try to connect. */
+ /* try to connect. */
post("mp3streamout~: connecting to port %d", portno);
if (connect(sockfd, (struct sockaddr *) &csocket, sizeof (csocket)) < 0)
{
@@ -458,15 +479,16 @@ static void mp3streamout_connect(t_mp3streamout *x, t_symbol *hostname, t_floata
}
- /* close connection to the peer */
+/* close connection to the peer */
static void mp3streamout_disconnect(t_mp3streamout *x)
{
int err = -1;
if(x->x_lame >= 0)
{
- /* ignore remaining bytes */
- if ( x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, 0) < 0 ) {
+ /* ignore remaining bytes */
+ if ( x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, 0) < 0 )
+ {
post( "mp3streamout~ : warning : remaining encoded bytes" );
}
lame_close( x->lgfp );
@@ -487,43 +509,46 @@ static void mp3streamout_disconnect(t_mp3streamout *x)
}
}
- /* settings for mp3 encoding */
+/* settings for mp3 encoding */
static void mp3streamout_mpeg(t_mp3streamout *x, t_floatarg fbitrate,
- t_floatarg fmode, t_floatarg fquality)
+ t_floatarg fmode, t_floatarg fquality)
{
if ( fbitrate != 32 && fbitrate != 40 && fbitrate != 48 && fbitrate != 56 &&
- fbitrate != 64 && fbitrate != 80 && fbitrate != 96 && fbitrate != 112 &&
- fbitrate != 128 && fbitrate != 160 && fbitrate != 192 && fbitrate != 224 &&
- fbitrate != 256 && fbitrate != 320 ) {
- post( "mp3streamout~ : wrong bitrate." );
- return;
+ fbitrate != 64 && fbitrate != 80 && fbitrate != 96 && fbitrate != 112 &&
+ fbitrate != 128 && fbitrate != 160 && fbitrate != 192 && fbitrate != 224 &&
+ fbitrate != 256 && fbitrate != 320 )
+ {
+ post( "mp3streamout~ : wrong bitrate." );
+ return;
}
- if ( fmode <0 || fmode>2 ) {
- post( "mp3streamout~ : wrong mp3 mode." );
- if ( fmode == 3 )
- {
- post( "mp3streamout~ : mone is not supported by streamout~ for now." );
- }
- return;
+ if ( fmode <0 || fmode>2 )
+ {
+ post( "mp3streamout~ : wrong mp3 mode." );
+ if ( fmode == 3 )
+ {
+ post( "mp3streamout~ : mone is not supported by streamout~ for now." );
+ }
+ return;
}
/* there is a bug in lame 3.92 and quality below 5 will not work */
/* WAIT FOR A FIX */
- if ( fquality <5 || fquality>9 ) {
- post( "mp3streamout~ : wrong quality." );
- return;
+ if ( fquality <5 || fquality>9 )
+ {
+ post( "mp3streamout~ : wrong quality." );
+ return;
}
x->x_bitrate = fbitrate;
x->x_mp3mode = fmode;
x->x_mp3quality = (int)fquality;
post("mp3streamout~: setting mp3 stream to %dHz, %dkbit/s, mode %d, quality %d",
- x->x_samplerate, x->x_bitrate, x->x_mp3mode, x->x_mp3quality);
+ x->x_samplerate, x->x_bitrate, x->x_mp3mode, x->x_mp3quality);
mp3streamout_tilde_lame_init(x);
}
- /* print settings */
+/* print settings */
static void mp3streamout_print(t_mp3streamout *x)
{
- const char * buf = 0;
+ const char * buf = 0;
verbose(0, mp3streamout_version);
post(" LAME mp3 settings:\n"
@@ -531,18 +556,18 @@ static void mp3streamout_print(t_mp3streamout *x)
" bitrate: %d kbit/s", x->x_samplerate, x->x_bitrate);
switch(x->x_mp3mode)
{
- case 0 :
- buf = "stereo";
- break;
- case 1 :
- buf = "joint stereo";
- break;
- case 2 :
- buf = "dual channel";
- break;
- case 3 :
- buf = "mono";
- break;
+ case 0 :
+ buf = "stereo";
+ break;
+ case 1 :
+ buf = "joint stereo";
+ break;
+ case 2 :
+ buf = "dual channel";
+ break;
+ case 3 :
+ buf = "mono";
+ break;
}
post(" mode: %s\n"
" quality: %d", buf, x->x_mp3quality);
@@ -557,8 +582,8 @@ static void mp3streamout_print(t_mp3streamout *x)
}
}
- /* clean up */
-static void mp3streamout_free(t_mp3streamout *x)
+/* clean up */
+static void mp3streamout_free(t_mp3streamout *x)
{
if(x->x_lame >= 0)
@@ -606,7 +631,7 @@ void mp3streamout_tilde_setup(void)
{
verbose(0, mp3streamout_version);
mp3streamout_class = class_new(gensym("mp3streamout~"), (t_newmethod)mp3streamout_new, (t_method)mp3streamout_free,
- sizeof(t_mp3streamout), 0, 0);
+ sizeof(t_mp3streamout), 0, 0);
CLASS_MAINSIGNALIN(mp3streamout_class, t_mp3streamout, x_f );
class_addmethod(mp3streamout_class, (t_method)mp3streamout_dsp, gensym("dsp"), 0);
class_addmethod(mp3streamout_class, (t_method)mp3streamout_connect, gensym("connect"), A_SYMBOL, A_FLOAT, 0);
diff --git a/mp3write~.c b/mp3write~.c
index 234110e..6cae3e9 100644
--- a/mp3write~.c
+++ b/mp3write~.c
@@ -58,8 +58,8 @@
#include "m_pd.h" /* standard pd stuff */
#define MY_MP3_MALLOC_IN_SIZE 65536
- /* max size taken from lame readme */
-#define MY_MP3_MALLOC_OUT_SIZE 1.25*MY_MP3_MALLOC_IN_SIZE+7200
+/* max size taken from lame readme */
+#define MY_MP3_MALLOC_OUT_SIZE 1.25*MY_MP3_MALLOC_IN_SIZE+7200
#define MAXDATARATE 320 /* maximum mp3 data rate is 320kbit/s */
#define STRBUF_SIZE 32
@@ -73,11 +73,11 @@ typedef struct _mp3write
{
t_object x_obj;
- /* LAME stuff */
+ /* LAME stuff */
int x_lame; /* info about encoder status */
int x_lamechunk; /* chunk size for LAME encoder */
- /* buffer stuff */
+ /* buffer stuff */
unsigned short x_inp; /* in position for buffer */
unsigned short x_outp; /* out position for buffer*/
short *x_mp3inbuf; /* data to be sent to LAME */
@@ -87,13 +87,13 @@ typedef struct _mp3write
int x_bytesbuffered; /* number of unprocessed bytes in buffer */
int x_start;
- /* mp3 format stuff */
+ /* mp3 format stuff */
int x_samplerate;
int x_bitrate; /* bitrate of mp3 stream */
int x_mp3mode; /* mode (mono, joint stereo, stereo, dual mono) */
int x_mp3quality; /* quality of encoding */
- /* recording stuff */
+ /* recording stuff */
int x_fd; /* file descriptor of the mp3 output */
int x_file_open_mode; /* file opening mode */
int x_byteswritten; /* number of bytes written */
@@ -106,7 +106,7 @@ typedef struct _mp3write
} t_mp3write;
- /* encode PCM data to mp3 stream */
+/* encode PCM data to mp3 stream */
static void mp3write_encode(t_mp3write *x)
{
unsigned short i, wp;
@@ -123,11 +123,11 @@ static void mp3write_encode(t_mp3write *x)
return;
}
- /* on start/reconnect set outpoint so that it won't interfere with inpoint */
+ /* on start/reconnect set outpoint so that it won't interfere with inpoint */
if(x->x_start == -1)
{
post("mp3write~: reseting buffer positions");
- /* we try to keep 2.5 times the data the encoder needs in the buffer */
+ /* we try to keep 2.5 times the data the encoder needs in the buffer */
if(x->x_inp > (2 * x->x_lamechunk))
{
x->x_outp = (short) x->x_inp - (2.5 * x->x_lamechunk);
@@ -142,10 +142,10 @@ static void mp3write_encode(t_mp3write *x)
i = MY_MP3_MALLOC_IN_SIZE - x->x_outp;
- /* read from buffer */
- if(x->x_lamechunk <= i)
+ /* read from buffer */
+ if(x->x_lamechunk <= i)
{
- /* enough data until end of buffer */
+ /* enough data until end of buffer */
for(n = 0; n < x->x_lamechunk; n++) /* fill encode buffer */
{
x->x_mp3inbuf[n] = x->x_buffer[n + x->x_outp];
@@ -166,14 +166,14 @@ static void mp3write_encode(t_mp3write *x)
x->x_outp = x->x_lamechunk - i;
}
- /* encode mp3 data */
+ /* encode mp3 data */
- x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf,
- x->x_lamechunk/lame_get_num_channels(x->lgfp),
+ x->x_mp3size = lame_encode_buffer_interleaved(x->lgfp, x->x_mp3inbuf,
+ x->x_lamechunk/lame_get_num_channels(x->lgfp),
x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE);
// post( "mp3write~ : encoding returned %d frames", x->x_mp3size );
- /* check result */
+ /* check result */
if(x->x_mp3size<0)
{
lame_close( x->lgfp );
@@ -182,21 +182,22 @@ static void mp3write_encode(t_mp3write *x)
}
}
- /* store mp3 frames in the file */
+/* store mp3 frames in the file */
static void mp3write_writeframes(t_mp3write *x)
{
int err = -1; /* error return code */
- if ( x->x_fd < 0 ) {
- post( "mp3write~ : error : trying to write frames but no valid file is opened" );
- return;
+ if ( x->x_fd < 0 )
+ {
+ post( "mp3write~ : error : trying to write frames but no valid file is opened" );
+ return;
}
#ifdef _WIN32
err = _write(x->x_fd, x->x_mp3outbuf, x->x_mp3size);
#else
err = write(x->x_fd, x->x_mp3outbuf, x->x_mp3size);
-#endif
+#endif
if(err < 0)
{
@@ -211,17 +212,17 @@ static void mp3write_writeframes(t_mp3write *x)
close(x->x_fd);
#endif
x->x_fd = -1;
- }
- else
- {
+ }
+ else
+ {
x->x_byteswritten += err;
outlet_float( x->x_obj.ob_outlet, x->x_byteswritten );
- }
+ }
if((err > 0)&&(err != x->x_mp3size))error("mp3write~: %d bytes skipped", x->x_mp3size - err);
}
-
- /* buffer data as channel interleaved PCM */
+
+/* buffer data as channel interleaved PCM */
static t_int *mp3write_perform(t_int *w)
{
t_float *in1 = (t_float *)(w[1]); /* left audio inlet */
@@ -231,76 +232,94 @@ static t_int *mp3write_perform(t_int *w)
unsigned short i,wp;
float in;
- /* copy the data into the buffer */
+ /* copy the data into the buffer */
i = MY_MP3_MALLOC_IN_SIZE - x->x_inp; /* space left at the end of buffer */
-
+
n *= 2; /* two channels go into one buffer */
- if( n <= i )
+ if( n <= i )
{
/* the place between inp and MY_MP3_MALLOC_IN_SIZE */
/* is big enough to hold the data */
- for(wp = 0; wp < n; wp++)
+ for(wp = 0; wp < n; wp++)
+ {
+ if(wp%2)
+ {
+ in = *(in2++); /* right channel / inlet */
+ }
+ else
+ {
+ in = *(in1++); /* left channel / inlet */
+ }
+ if (in > 1.0)
+ {
+ in = 1.0;
+ }
+ if (in < -1.0)
{
- if(wp%2)
- {
- in = *(in2++); /* right channel / inlet */
- }
- else
- {
- in = *(in1++); /* left channel / inlet */
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ in = -1.0;
}
- x->x_inp += n; /* n more samples written to buffer */
- }
- else
+ x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ }
+ x->x_inp += n; /* n more samples written to buffer */
+ }
+ else
{
- /* the place between inp and MY_MP3_MALLOC_IN_SIZE is not */
- /* big enough to hold the data */
- /* writing will take place in two turns, one from */
- /* x->x_inp -> MY_MP3_MALLOC_IN_SIZE, then from 0 on */
+ /* the place between inp and MY_MP3_MALLOC_IN_SIZE is not */
+ /* big enough to hold the data */
+ /* writing will take place in two turns, one from */
+ /* x->x_inp -> MY_MP3_MALLOC_IN_SIZE, then from 0 on */
- for(wp = 0; wp < i; wp++) /* fill up to end of buffer */
+ for(wp = 0; wp < i; wp++) /* fill up to end of buffer */
+ {
+ if(wp%2)
+ {
+ in = *(in2++);
+ }
+ else
+ {
+ in = *(in1++);
+ }
+ if (in > 1.0)
+ {
+ in = 1.0;
+ }
+ if (in < -1.0)
+ {
+ in = -1.0;
+ }
+ x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ }
+ for(wp = i; wp < n; wp++) /* write rest at start of buffer */
+ {
+ if(wp%2)
+ {
+ in = *(in2++);
+ }
+ else
{
- if(wp%2)
- {
- in = *(in2++);
- }
- else
- {
- in = *(in1++);
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp + x->x_inp] = (short) (32767.0 * in);
+ in = *(in1++);
}
- for(wp = i; wp < n; wp++) /* write rest at start of buffer */
+ if (in > 1.0)
{
- if(wp%2)
- {
- in = *(in2++);
- }
- else
- {
- in = *(in1++);
- }
- if (in > 1.0) { in = 1.0; }
- if (in < -1.0) { in = -1.0; }
- x->x_buffer[wp - i] = (short) (32767.0 * in);
+ in = 1.0;
}
- x->x_inp = n - i; /* new writeposition in buffer */
+ if (in < -1.0)
+ {
+ in = -1.0;
+ }
+ x->x_buffer[wp - i] = (short) (32767.0 * in);
+ }
+ x->x_inp = n - i; /* new writeposition in buffer */
}
if((x->x_fd >= 0)&&(x->x_lame >= 0)&&(x->x_recflag))
- {
- /* count buffered samples when things are running */
+ {
+ /* count buffered samples when things are running */
x->x_bytesbuffered += n;
- /* encode and send to server */
+ /* encode and send to server */
if(x->x_bytesbuffered > x->x_lamechunk)
{
mp3write_encode(x); /* encode to mp3 */
@@ -320,10 +339,10 @@ static void mp3write_dsp(t_mp3write *x, t_signal **sp)
dsp_add(mp3write_perform, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n);
}
- /* initialize the lame library */
+/* initialize the lame library */
static int mp3write_tilde_lame_init(t_mp3write *x)
{
- time_t now;
+ time_t now;
int ret;
x->lgfp = lame_init(); /* set default parameters for now */
@@ -342,11 +361,11 @@ static int mp3write_tilde_lame_init(t_mp3write *x)
}
#endif
{
- const char *lameVersion = get_lame_version();
- verbose(0, "mp3write~ : using lame version : %s", lameVersion );
+ const char *lameVersion = get_lame_version();
+ verbose(0, "mp3write~ : using lame version : %s", lameVersion );
}
- /* setting lame parameters */
+ /* setting lame parameters */
lame_set_num_channels( x->lgfp, 2);
lame_set_in_samplerate( x->lgfp, sys_getsr() );
lame_set_out_samplerate( x->lgfp, x->x_samplerate );
@@ -359,15 +378,18 @@ static int mp3write_tilde_lame_init(t_mp3write *x)
lame_set_disable_reservoir( x->lgfp, 0 );
lame_set_padding_type( x->lgfp, PAD_NO );
ret = lame_init_params( x->lgfp );
- if ( ret<0 ) {
- post( "mp3write~ : error : lame params initialization returned : %d", ret );
- return -1;
- } else {
- x->x_lame=1;
- /* magic formula copied from windows dll for MPEG-I */
- x->x_lamechunk = 2*1152;
-
- post( "mp3write~ : lame initialization done. (%d)", x->x_lame );
+ if ( ret<0 )
+ {
+ post( "mp3write~ : error : lame params initialization returned : %d", ret );
+ return -1;
+ }
+ else
+ {
+ x->x_lame=1;
+ /* magic formula copied from windows dll for MPEG-I */
+ x->x_lamechunk = 2*1152;
+
+ post( "mp3write~ : lame initialization done. (%d)", x->x_lame );
}
lame_init_bitstream( x->lgfp );
@@ -379,33 +401,36 @@ static int mp3write_tilde_lame_init(t_mp3write *x)
now=time(NULL);
sprintf( x->x_title, "Started at %s", ctime(&now) );
id3tag_set_title(x->lgfp, x->x_title );
-
+
return 0;
}
- /* open file and initialize lame */
+/* open file and initialize lame */
static void mp3write_open(t_mp3write *x, t_symbol *sfile)
{
- if ( mp3write_tilde_lame_init(x) < 0 ) {
- error( "mp3write~ : lame initialization failed ... check parameters.");
- return;
+ if ( mp3write_tilde_lame_init(x) < 0 )
+ {
+ error( "mp3write~ : lame initialization failed ... check parameters.");
+ return;
}
/* closing previous file descriptor */
- if ( x->x_fd > 0 ) {
+ if ( x->x_fd > 0 )
+ {
#ifdef _WIN32
- if(_close(x->x_fd) < 0 )
+ if(_close(x->x_fd) < 0 )
#else
- if(close(x->x_fd) < 0)
+ if(close(x->x_fd) < 0)
#endif
- {
- perror( "mp3write~ : closing file" );
- }
+ {
+ perror( "mp3write~ : closing file" );
+ }
}
- if ( x->x_recflag ) {
- x->x_recflag = 0;
+ if ( x->x_recflag )
+ {
+ x->x_recflag = 0;
}
#ifdef _WIN32
@@ -414,15 +439,15 @@ static void mp3write_open(t_mp3write *x, t_symbol *sfile)
if ( ( x->x_fd = open( sfile->s_name, x->x_file_open_mode, S_IRWXU|S_IRWXG|S_IRWXO ) ) < 0 )
#endif
{
- error( "mp3write~ : cannot open >%s<", sfile->s_name);
- x->x_fd=-1;
- return;
+ error( "mp3write~ : cannot open >%s<", sfile->s_name);
+ x->x_fd=-1;
+ return;
}
x->x_byteswritten = 0;
- post( "mp3write~ : opened >%s< fd=%d", sfile->s_name, x->x_fd);
-}
+ post( "mp3write~ : opened >%s< fd=%d", sfile->s_name, x->x_fd);
+}
- /* setting file write mode to append */
+/* setting file write mode to append */
static void mp3write_append(t_mp3write *x)
{
#ifdef _WIN32
@@ -433,7 +458,7 @@ static void mp3write_append(t_mp3write *x)
if(x->x_fd>=0)post("mp3write~ : mode set to append : open a new file to make changes take effect! ");
}
- /* setting file write mode to truncate */
+/* setting file write mode to truncate */
static void mp3write_truncate(t_mp3write *x)
{
#ifdef _WIN32
@@ -444,9 +469,9 @@ static void mp3write_truncate(t_mp3write *x)
if(x->x_fd>=0)post("mp3write~ : mode set to truncate : open a new file to make changes take effect! ");
}
- /* settings for mp3 encoding */
+/* settings for mp3 encoding */
static void mp3write_mpeg(t_mp3write *x, t_floatarg fsamplerate, t_floatarg fbitrate,
- t_floatarg fmode, t_floatarg fquality)
+ t_floatarg fmode, t_floatarg fquality)
{
x->x_samplerate = fsamplerate;
if(fbitrate > MAXDATARATE)
@@ -457,11 +482,11 @@ static void mp3write_mpeg(t_mp3write *x, t_floatarg fsamplerate, t_floatarg fbit
x->x_mp3mode = fmode;
x->x_mp3quality = fquality;
post("mp3write~: setting mp3 stream to %dHz, %dkbit/s, mode %d, quality %d",
- x->x_samplerate, x->x_bitrate, x->x_mp3mode, x->x_mp3quality);
+ x->x_samplerate, x->x_bitrate, x->x_mp3mode, x->x_mp3quality);
if(x->x_fd>=0)post("mp3write~ : restart recording to make changes take effect! ");
}
- /* print settings */
+/* print settings */
static void mp3write_print(t_mp3write *x)
{
const char * buf = 0;
@@ -471,18 +496,18 @@ static void mp3write_print(t_mp3write *x)
" bitrate: %d kbit/s", x->x_samplerate, x->x_bitrate);
switch(x->x_mp3mode)
{
- case 0 :
- buf = "stereo";
- break;
- case 1 :
- buf = "joint stereo";
- break;
- case 2 :
- buf = "dual channel";
- break;
- case 3 :
- buf = "mono";
- break;
+ case 0 :
+ buf = "stereo";
+ break;
+ case 1 :
+ buf = "joint stereo";
+ break;
+ case 2 :
+ buf = "dual channel";
+ break;
+ case 3 :
+ buf = "mono";
+ break;
}
post(" mode: %s\n"
" quality: %d", buf, x->x_mp3quality);
@@ -497,51 +522,55 @@ static void mp3write_print(t_mp3write *x)
}
}
- /* start recording */
+/* start recording */
static void mp3write_start(t_mp3write *x)
{
- if ( x->x_fd < 0 ) {
- post("mp3write~: start received but no file has been set ... ignored.");
- return;
+ if ( x->x_fd < 0 )
+ {
+ post("mp3write~: start received but no file has been set ... ignored.");
+ return;
}
-
- if ( x->x_recflag == 1 ) {
- post("mp3write~: start received but recording is started ... ignored.");
- return;
+
+ if ( x->x_recflag == 1 )
+ {
+ post("mp3write~: start received but recording is started ... ignored.");
+ return;
}
-
+
x->x_recflag = 1;
post("mp3write~: start recording");
}
- /* stop recording */
+/* stop recording */
static void mp3write_stop(t_mp3write *x)
{
int err = -1;
- if ( x->x_fd < 0 ) {
- post("mp3write~: stop received but no file has been set ... ignored.");
- return;
+ if ( x->x_fd < 0 )
+ {
+ post("mp3write~: stop received but no file has been set ... ignored.");
+ return;
}
-
- if ( x->x_recflag == 0 ) {
- post("mp3write~: stop received but recording is stopped ... ignored.");
- return;
+
+ if ( x->x_recflag == 0 )
+ {
+ post("mp3write~: stop received but recording is stopped ... ignored.");
+ return;
}
- /* first stop recording / buffering and so on, than do the rest */
+ /* first stop recording / buffering and so on, than do the rest */
x->x_recflag = 0;
/* flushing remaining frames and tag */
- x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE );
-
+ x->x_mp3size = lame_encode_flush( x->lgfp, x->x_mp3outbuf, MY_MP3_MALLOC_OUT_SIZE );
+
mp3write_writeframes(x); /* write mp3 to file */
x->x_recflag = 0;
post("mp3write~: stop recording, flushed %d bytes", x->x_mp3size);
}
- /* clean up */
-static void mp3write_free(t_mp3write *x)
+/* clean up */
+static void mp3write_free(t_mp3write *x)
{
if(x->x_lame >= 0)
lame_close( x->lgfp );
@@ -595,7 +624,7 @@ void mp3write_tilde_setup(void)
{
verbose(0, mp3write_version);
mp3write_class = class_new(gensym("mp3write~"), (t_newmethod)mp3write_new, (t_method)mp3write_free,
- sizeof(t_mp3write), 0, 0);
+ sizeof(t_mp3write), 0, 0);
CLASS_MAINSIGNALIN(mp3write_class, t_mp3write, x_f );
class_addmethod(mp3write_class, (t_method)mp3write_dsp, gensym("dsp"), 0);
class_addmethod(mp3write_class, (t_method)mp3write_open, gensym("open"), A_SYMBOL, 0);
diff --git a/pianoroll.c b/pianoroll.c
index e7667fe..ceda733 100644
--- a/pianoroll.c
+++ b/pianoroll.c
@@ -60,7 +60,7 @@ void canvas_startmotion(t_canvas *x);
#define DEFAULT_SEQUENCER_PITCH_MIN -15
#define DEFAULT_SEQUENCER_PITCH_MAX 15
-static char *pianoroll_version = "pianoroll: a graphical sequencer controller, version 0.10 (ydegoyon@free.fr)";
+static char *pianoroll_version = "pianoroll: a graphical sequencer controller, version 0.10 (ydegoyon@free.fr)";
t_widgetbehavior pianoroll_widgetbehavior;
static t_class *pianoroll_class;
@@ -96,149 +96,149 @@ static int pointsize = 5;
/* drawing functions */
static void pianoroll_draw_update(t_pianoroll *x, t_glist *glist)
{
- t_int si;
- t_canvas *canvas=glist_getcanvas(glist);
+ t_int si;
+ t_canvas *canvas=glist_getcanvas(glist);
for ( si=0; si<x->x_nbsteps; si++ )
{
- int vi = (int)((1.0-x->x_volumes[si])*(x->x_nbgrades-1));
- int pi = (int)((x->x_pmax-x->x_peaches[si])/(x->x_pmax-x->x_pmin)*(x->x_nbgrades-1));
+ int vi = (int)((1.0-x->x_volumes[si])*(x->x_nbgrades-1));
+ int pi = (int)((x->x_pmax-x->x_peaches[si])/(x->x_pmax-x->x_pmin)*(x->x_nbgrades-1));
- x->x_ivolumes[ si ] = vi;
- x->x_ipeaches[ si ] = pi;
- SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #FFFF00\n", canvas, x, si, pi);
- SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #FF0000\n", canvas, x, si, vi);
+ x->x_ivolumes[ si ] = vi;
+ x->x_ipeaches[ si ] = pi;
+ SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #FFFF00\n", canvas, x, si, pi);
+ SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #FF0000\n", canvas, x, si, vi);
}
}
static void pianoroll_draw_new(t_pianoroll *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
// draw the grid
{
- int gi, gj;
- t_float xgstep = x->x_width/x->x_nbsteps;
- t_float ygstep = x->x_height/x->x_nbgrades;
- for ( gi=0; gi<x->x_nbsteps; gi++ )
- {
- for ( gj=0; gj<x->x_nbgrades; gj++ )
- {
- SYS_VGUI9(".x%lx.c create rectangle %d %d %d %d -fill #771623 -outline #998121 -tags %xPITCH%.4d%.4d\n",
- canvas,
- text_xpix(&x->x_obj, glist)+(int)(gi*xgstep),
- text_ypix(&x->x_obj, glist)+(int)(gj*ygstep),
- text_xpix(&x->x_obj, glist)+(int)(gi*xgstep)+(int)(2*xgstep/3),
- text_ypix(&x->x_obj, glist)+(int)((gj+1)*ygstep),
- x, gi, gj );
- SYS_VGUI9(".x%lx.c create rectangle %d %d %d %d -fill #562663 -outline #998121 -tags %xVOLUME%.4d%.4d\n",
- canvas,
- text_xpix(&x->x_obj, glist)+(int)(gi*xgstep)+(int)(2*xgstep/3),
- text_ypix(&x->x_obj, glist)+(int)(gj*ygstep),
- text_xpix(&x->x_obj, glist)+(int)((gi+1)*xgstep),
- text_ypix(&x->x_obj, glist)+(int)((gj+1)*ygstep),
- x, gi, gj );
- }
- }
- // adjust height and width
- x->x_width = (int)((x->x_nbsteps)*xgstep);
- x->x_height = (int)((x->x_nbgrades)*ygstep);
+ int gi, gj;
+ t_float xgstep = x->x_width/x->x_nbsteps;
+ t_float ygstep = x->x_height/x->x_nbgrades;
+ for ( gi=0; gi<x->x_nbsteps; gi++ )
+ {
+ for ( gj=0; gj<x->x_nbgrades; gj++ )
+ {
+ SYS_VGUI9(".x%lx.c create rectangle %d %d %d %d -fill #771623 -outline #998121 -tags %xPITCH%.4d%.4d\n",
+ canvas,
+ text_xpix(&x->x_obj, glist)+(int)(gi*xgstep),
+ text_ypix(&x->x_obj, glist)+(int)(gj*ygstep),
+ text_xpix(&x->x_obj, glist)+(int)(gi*xgstep)+(int)(2*xgstep/3),
+ text_ypix(&x->x_obj, glist)+(int)((gj+1)*ygstep),
+ x, gi, gj );
+ SYS_VGUI9(".x%lx.c create rectangle %d %d %d %d -fill #562663 -outline #998121 -tags %xVOLUME%.4d%.4d\n",
+ canvas,
+ text_xpix(&x->x_obj, glist)+(int)(gi*xgstep)+(int)(2*xgstep/3),
+ text_ypix(&x->x_obj, glist)+(int)(gj*ygstep),
+ text_xpix(&x->x_obj, glist)+(int)((gi+1)*xgstep),
+ text_ypix(&x->x_obj, glist)+(int)((gj+1)*ygstep),
+ x, gi, gj );
+ }
+ }
+ // adjust height and width
+ x->x_width = (int)((x->x_nbsteps)*xgstep);
+ x->x_height = (int)((x->x_nbgrades)*ygstep);
}
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -tags %xIN\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) - 1,
- text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist),
- x);
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) - 1,
+ text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist),
+ x);
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -tags %xOUTL\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height+1,
- text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist) + x->x_height+2,
- x);
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height+1,
+ text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist) + x->x_height+2,
+ x);
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -tags %xOUTR\n",
- canvas, text_xpix(&x->x_obj, glist)+x->x_width-7, text_ypix(&x->x_obj, glist) + x->x_height+1,
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist) + x->x_height+2,
- x);
+ canvas, text_xpix(&x->x_obj, glist)+x->x_width-7, text_ypix(&x->x_obj, glist) + x->x_height+1,
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist) + x->x_height+2,
+ x);
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void pianoroll_draw_move(t_pianoroll *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
// move the grid
{
- int gi, gj;
- t_float xgstep = x->x_width/x->x_nbsteps;
- t_float ygstep = x->x_height/x->x_nbgrades;
- for ( gi=0; gi<x->x_nbsteps; gi++ )
- {
- for ( gj=0; gj<x->x_nbgrades; gj++ )
- {
- SYS_VGUI9(".x%lx.c coords %xPITCH%.4d%.4d %d %d %d %d\n",
- canvas, x, gi, gj,
- text_xpix(&x->x_obj, glist)+(int)(gi*xgstep),
- text_ypix(&x->x_obj, glist)+(int)(gj*ygstep),
- text_xpix(&x->x_obj, glist)+(int)(gi*xgstep)+(int)(2*xgstep/3),
- text_ypix(&x->x_obj, glist)+(int)((gj+1)*ygstep)
- );
- SYS_VGUI9(".x%lx.c coords %xVOLUME%.4d%.4d %d %d %d %d\n",
- canvas, x, gi, gj,
- text_xpix(&x->x_obj, glist)+(int)(gi*xgstep)+(int)(2*xgstep/3),
- text_ypix(&x->x_obj, glist)+(int)(gj*ygstep),
- text_xpix(&x->x_obj, glist)+(int)((gi+1)*xgstep),
- text_ypix(&x->x_obj, glist)+(int)((gj+1)*ygstep)
- );
- }
- }
+ int gi, gj;
+ t_float xgstep = x->x_width/x->x_nbsteps;
+ t_float ygstep = x->x_height/x->x_nbgrades;
+ for ( gi=0; gi<x->x_nbsteps; gi++ )
+ {
+ for ( gj=0; gj<x->x_nbgrades; gj++ )
+ {
+ SYS_VGUI9(".x%lx.c coords %xPITCH%.4d%.4d %d %d %d %d\n",
+ canvas, x, gi, gj,
+ text_xpix(&x->x_obj, glist)+(int)(gi*xgstep),
+ text_ypix(&x->x_obj, glist)+(int)(gj*ygstep),
+ text_xpix(&x->x_obj, glist)+(int)(gi*xgstep)+(int)(2*xgstep/3),
+ text_ypix(&x->x_obj, glist)+(int)((gj+1)*ygstep)
+ );
+ SYS_VGUI9(".x%lx.c coords %xVOLUME%.4d%.4d %d %d %d %d\n",
+ canvas, x, gi, gj,
+ text_xpix(&x->x_obj, glist)+(int)(gi*xgstep)+(int)(2*xgstep/3),
+ text_ypix(&x->x_obj, glist)+(int)(gj*ygstep),
+ text_xpix(&x->x_obj, glist)+(int)((gi+1)*xgstep),
+ text_ypix(&x->x_obj, glist)+(int)((gj+1)*ygstep)
+ );
+ }
+ }
}
SYS_VGUI7(".x%lx.c coords %xIN %d %d %d %d \n",
- canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) - 1,
- text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist)
- );
+ canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) - 1,
+ text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist)
+ );
SYS_VGUI7(".x%lx.c coords %xOUTL %d %d %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height+1,
- text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist) + x->x_height+2
- );
+ canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist) + x->x_height+1,
+ text_xpix(&x->x_obj, glist)+7, text_ypix(&x->x_obj, glist) + x->x_height+2
+ );
SYS_VGUI7(".x%lx.c coords %xOUTR %d %d %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist)+x->x_width-7, text_ypix(&x->x_obj, glist) + x->x_height+1,
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist) + x->x_height+2
- );
+ canvas, x, text_xpix(&x->x_obj, glist)+x->x_width-7, text_ypix(&x->x_obj, glist) + x->x_height+1,
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist) + x->x_height+2
+ );
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void pianoroll_draw_erase(t_pianoroll* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int i;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int i;
SYS_VGUI3(".x%lx.c delete %xIN\n", canvas, x);
SYS_VGUI3(".x%lx.c delete %xOUTL\n", canvas, x);
SYS_VGUI3(".x%lx.c delete %xOUTR\n", canvas, x);
// delete the grid
{
- int gi, gj;
- for ( gi=0; gi<x->x_nbsteps; gi++ )
- {
- for ( gj=0; gj<x->x_nbgrades; gj++ )
- {
- SYS_VGUI5(".x%lx.c delete %xPITCH%.4d%.4d\n", canvas, x, gi, gj);
- SYS_VGUI5(".x%lx.c delete %xVOLUME%.4d%.4d\n", canvas, x, gi, gj);
- }
- }
+ int gi, gj;
+ for ( gi=0; gi<x->x_nbsteps; gi++ )
+ {
+ for ( gj=0; gj<x->x_nbgrades; gj++ )
+ {
+ SYS_VGUI5(".x%lx.c delete %xPITCH%.4d%.4d\n", canvas, x, gi, gj);
+ SYS_VGUI5(".x%lx.c delete %xVOLUME%.4d%.4d\n", canvas, x, gi, gj);
+ }
+ }
}
}
static void pianoroll_draw_select(t_pianoroll* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
if(x->x_selected)
{
- pd_bind(&x->x_obj.ob_pd, x->x_name);
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
/* sets the item in blue */
}
else
{
- pd_unbind(&x->x_obj.ob_pd, x->x_name);
+ pd_unbind(&x->x_obj.ob_pd, x->x_name);
}
}
@@ -246,146 +246,150 @@ static void pianoroll_draw_select(t_pianoroll* x,t_glist* glist)
static void pianoroll_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_pianoroll* x = (t_pianoroll*)z;
+ t_pianoroll* x = (t_pianoroll*)z;
- *xp1 = text_xpix(&x->x_obj, owner);
- *yp1 = text_ypix(&x->x_obj, owner);
- *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, owner);
+ *yp1 = text_ypix(&x->x_obj, owner);
+ *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
}
static void pianoroll_save(t_gobj *z, t_binbuf *b)
{
- t_pianoroll *x = (t_pianoroll *)z;
- t_int i;
-
- // post( "saving pianoroll : %s", x->x_name->s_name );
- binbuf_addv(b, "ssiissiiffiiifi", gensym("#X"),gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_name, x->x_width, x->x_height,
- x->x_pmin, x->x_pmax,
+ t_pianoroll *x = (t_pianoroll *)z;
+ t_int i;
+
+ // post( "saving pianoroll : %s", x->x_name->s_name );
+ binbuf_addv(b, "ssiissiiffiiifi", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_name, x->x_width, x->x_height,
+ x->x_pmin, x->x_pmax,
x->x_nbgrades, x->x_nbsteps,
- x->x_defvalue, x->x_transpose, x->x_save
- );
- if ( x->x_save )
- {
- for ( i=0; i<x->x_nbsteps; i++ )
- {
- binbuf_addv(b, "ff", x->x_peaches[i], x->x_volumes[i] );
- }
- }
- binbuf_addv(b, ";");
+ x->x_defvalue, x->x_transpose, x->x_save
+ );
+ if ( x->x_save )
+ {
+ for ( i=0; i<x->x_nbsteps; i++ )
+ {
+ binbuf_addv(b, "ff", x->x_peaches[i], x->x_volumes[i] );
+ }
+ }
+ binbuf_addv(b, ";");
}
static void pianoroll_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_pianoroll *x=(t_pianoroll *)z;
+ char buf[800];
+ t_pianoroll *x=(t_pianoroll *)z;
- sprintf(buf, "pdtk_pianoroll_dialog %%s %s %d %d %.2f %.2f %d %d %d %d\n",
- x->x_name->s_name, x->x_width, x->x_height, x->x_pmin, x->x_pmax,
+ sprintf(buf, "pdtk_pianoroll_dialog %%s %s %d %d %.2f %.2f %d %d %d %d\n",
+ x->x_name->s_name, x->x_width, x->x_height, x->x_pmin, x->x_pmax,
x->x_nbgrades, x->x_nbsteps, x->x_defvalue, x->x_save );
- // post("pianoroll_properties : %s", buf );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ // post("pianoroll_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
static void pianoroll_select(t_gobj *z, t_glist *glist, int selected)
{
- t_pianoroll *x = (t_pianoroll *)z;
+ t_pianoroll *x = (t_pianoroll *)z;
- x->x_selected = selected;
- pianoroll_draw_select( x, glist );
+ x->x_selected = selected;
+ pianoroll_draw_select( x, glist );
}
static void pianoroll_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_pianoroll *x = (t_pianoroll *)z;
- t_rtext *y;
-
- // post("pianoroll_vis : %d", vis );
- if (vis)
- {
- pianoroll_draw_new( x, glist );
- pianoroll_draw_update( x, glist );
- }
- else
- {
- pianoroll_draw_erase( x, glist );
- }
+ t_pianoroll *x = (t_pianoroll *)z;
+ t_rtext *y;
+
+ // post("pianoroll_vis : %d", vis );
+ if (vis)
+ {
+ pianoroll_draw_new( x, glist );
+ pianoroll_draw_update( x, glist );
+ }
+ else
+ {
+ pianoroll_draw_erase( x, glist );
+ }
}
static void pianoroll_dialog(t_pianoroll *x, t_symbol *s, int argc, t_atom *argv)
{
- int si, onbsteps;
- t_float *newpeaches, *newvolumes;
-
- if ( !x ) {
- post( "pianoroll : error :tried to set properties on an unexisting object" );
- }
- if ( ( argv[5].a_w.w_float <= 0 ) || ( argv[5].a_w.w_float <= 0 ) ) {
- post( "pianoroll : error : wrong number of steps or grades" );
- return;
- }
- if ( ( argv[3].a_w.w_float >= argv[4].a_w.w_float ) ) {
- post( "pianoroll : error : min pitch is >= to max pitch" );
- return;
- }
- if ( argc != 9 )
- {
- post( "pianoroll : error in the number of arguments ( %d )", argc );
- return;
- }
- if ( argv[0].a_type != A_SYMBOL || 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 ||
- argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
- argv[8].a_type != A_FLOAT
- ) {
- post( "pianoroll : wrong arguments" );
- return;
- }
- pianoroll_draw_erase(x, x->x_glist);
- x->x_name = argv[0].a_w.w_symbol;
- x->x_width = (int)argv[1].a_w.w_float;
- x->x_height = (int)argv[2].a_w.w_float;
- x->x_pmin = argv[3].a_w.w_float;
- x->x_pmax = argv[4].a_w.w_float;
- x->x_nbgrades = argv[5].a_w.w_float;
- onbsteps = x->x_nbsteps;
- x->x_nbsteps = argv[6].a_w.w_float;
- x->x_defvalue = argv[7].a_w.w_float;
- x->x_save = argv[8].a_w.w_float;
-
- if ( onbsteps != x->x_nbsteps )
- {
- int cmindex = ( onbsteps > x->x_nbsteps ) ? x->x_nbsteps : onbsteps;
-
- newpeaches = ( t_float* ) getbytes( x->x_nbsteps*sizeof(t_float) );
- newvolumes = ( t_float* ) getbytes( x->x_nbsteps*sizeof(t_float) );
- for ( si=0; si<cmindex ; si++ )
- {
- newpeaches[si] = x->x_peaches[si];
- newvolumes[si] = x->x_volumes[si];
- }
- freebytes( x->x_peaches, onbsteps*sizeof( t_float ) );
- freebytes( x->x_volumes, onbsteps*sizeof( t_float ) );
- x->x_peaches = newpeaches;
- x->x_volumes = newvolumes;
- for ( si=onbsteps; si<x->x_nbsteps; si++ )
- {
- x->x_peaches[si] = x->x_defvalue;
- x->x_volumes[si] = 1.0;
- }
- freebytes( x->x_ipeaches, onbsteps*sizeof( t_int ) );
- freebytes( x->x_ivolumes, onbsteps*sizeof( t_int ) );
- x->x_ipeaches = ( t_int* ) getbytes( x->x_nbsteps*sizeof(t_int) );
- x->x_ivolumes = ( t_int* ) getbytes( x->x_nbsteps*sizeof(t_int) );
- }
- pianoroll_draw_new(x, x->x_glist);
- pianoroll_draw_update(x, x->x_glist);
+ int si, onbsteps;
+ t_float *newpeaches, *newvolumes;
+
+ if ( !x )
+ {
+ post( "pianoroll : error :tried to set properties on an unexisting object" );
+ }
+ if ( ( argv[5].a_w.w_float <= 0 ) || ( argv[5].a_w.w_float <= 0 ) )
+ {
+ post( "pianoroll : error : wrong number of steps or grades" );
+ return;
+ }
+ if ( ( argv[3].a_w.w_float >= argv[4].a_w.w_float ) )
+ {
+ post( "pianoroll : error : min pitch is >= to max pitch" );
+ return;
+ }
+ if ( argc != 9 )
+ {
+ post( "pianoroll : error in the number of arguments ( %d )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_SYMBOL || 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 ||
+ argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
+ argv[8].a_type != A_FLOAT
+ )
+ {
+ post( "pianoroll : wrong arguments" );
+ return;
+ }
+ pianoroll_draw_erase(x, x->x_glist);
+ x->x_name = argv[0].a_w.w_symbol;
+ x->x_width = (int)argv[1].a_w.w_float;
+ x->x_height = (int)argv[2].a_w.w_float;
+ x->x_pmin = argv[3].a_w.w_float;
+ x->x_pmax = argv[4].a_w.w_float;
+ x->x_nbgrades = argv[5].a_w.w_float;
+ onbsteps = x->x_nbsteps;
+ x->x_nbsteps = argv[6].a_w.w_float;
+ x->x_defvalue = argv[7].a_w.w_float;
+ x->x_save = argv[8].a_w.w_float;
+
+ if ( onbsteps != x->x_nbsteps )
+ {
+ int cmindex = ( onbsteps > x->x_nbsteps ) ? x->x_nbsteps : onbsteps;
+
+ newpeaches = ( t_float* ) getbytes( x->x_nbsteps*sizeof(t_float) );
+ newvolumes = ( t_float* ) getbytes( x->x_nbsteps*sizeof(t_float) );
+ for ( si=0; si<cmindex ; si++ )
+ {
+ newpeaches[si] = x->x_peaches[si];
+ newvolumes[si] = x->x_volumes[si];
+ }
+ freebytes( x->x_peaches, onbsteps*sizeof( t_float ) );
+ freebytes( x->x_volumes, onbsteps*sizeof( t_float ) );
+ x->x_peaches = newpeaches;
+ x->x_volumes = newvolumes;
+ for ( si=onbsteps; si<x->x_nbsteps; si++ )
+ {
+ x->x_peaches[si] = x->x_defvalue;
+ x->x_volumes[si] = 1.0;
+ }
+ freebytes( x->x_ipeaches, onbsteps*sizeof( t_int ) );
+ freebytes( x->x_ivolumes, onbsteps*sizeof( t_int ) );
+ x->x_ipeaches = ( t_int* ) getbytes( x->x_nbsteps*sizeof(t_int) );
+ x->x_ivolumes = ( t_int* ) getbytes( x->x_nbsteps*sizeof(t_int) );
+ }
+ pianoroll_draw_new(x, x->x_glist);
+ pianoroll_draw_update(x, x->x_glist);
}
static void pianoroll_delete(t_gobj *z, t_glist *glist)
@@ -405,208 +409,208 @@ static void pianoroll_displace(t_gobj *z, t_glist *glist, int dx, int dy)
x->x_obj.te_ypix += dy;
if(xold != x->x_obj.te_xpix || yold != x->x_obj.te_ypix)
{
- pianoroll_draw_move(x, x->x_glist);
+ pianoroll_draw_move(x, x->x_glist);
}
}
static int pianoroll_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
- t_pianoroll* x = (t_pianoroll *)z;
- t_canvas *canvas=glist_getcanvas(glist);
+ t_pianoroll* x = (t_pianoroll *)z;
+ t_canvas *canvas=glist_getcanvas(glist);
- if ( doit)
+ if ( doit)
{
- // calculate position to update
- {
- int si, gi;
- t_float xgstep = x->x_width/x->x_nbsteps;
- t_float ygstep = x->x_height/x->x_nbgrades;
+ // calculate position to update
+ {
+ int si, gi;
+ t_float xgstep = x->x_width/x->x_nbsteps;
+ t_float ygstep = x->x_height/x->x_nbgrades;
- si = ( xpix - text_xpix(&x->x_obj, glist) ) / xgstep;
- gi = ( ypix - text_ypix(&x->x_obj, glist) ) / ygstep;
+ si = ( xpix - text_xpix(&x->x_obj, glist) ) / xgstep;
+ gi = ( ypix - text_ypix(&x->x_obj, glist) ) / ygstep;
- // post( "pianoroll : step : %d : grade : %d", si, gi );
+ // post( "pianoroll : step : %d : grade : %d", si, gi );
- if ( ( xpix - text_xpix(&x->x_obj, glist) ) > ( si*xgstep+2*xgstep/3 ) )
- {
+ if ( ( xpix - text_xpix(&x->x_obj, glist) ) > ( si*xgstep+2*xgstep/3 ) )
{
- SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #562663\n", canvas, x, si, x->x_ivolumes[ si ] );
- }
+ {
+ SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #562663\n", canvas, x, si, x->x_ivolumes[ si ] );
+ }
- x->x_volumes[ si ] = (((float)x->x_nbgrades-1-(float)gi))/(float)(x->x_nbgrades-1);
- SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #FF0000\n", canvas, x, si, gi);
- x->x_ivolumes[ si ] = gi;
- }
- else
- {
- {
- SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #761623\n", canvas, x, si, x->x_ipeaches[ si ]);
+ x->x_volumes[ si ] = (((float)x->x_nbgrades-1-(float)gi))/(float)(x->x_nbgrades-1);
+ SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #FF0000\n", canvas, x, si, gi);
+ x->x_ivolumes[ si ] = gi;
}
+ else
+ {
+ {
+ SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #761623\n", canvas, x, si, x->x_ipeaches[ si ]);
+ }
- x->x_peaches[ si ] = x->x_pmin+(float)(x->x_nbgrades-1-gi)/(float)(x->x_nbgrades-1)*(float)(x->x_pmax-x->x_pmin);
- SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #FFFF00\n", canvas, x, si, gi);
- x->x_ipeaches[ si ] = gi;
- }
- }
+ x->x_peaches[ si ] = x->x_pmin+(float)(x->x_nbgrades-1-gi)/(float)(x->x_nbgrades-1)*(float)(x->x_pmax-x->x_pmin);
+ SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #FFFF00\n", canvas, x, si, gi);
+ x->x_ipeaches[ si ] = gi;
+ }
+ }
}
return (1);
}
-static void pianoroll_transpose(t_pianoroll *x, t_floatarg ftranspose)
+static void pianoroll_transpose(t_pianoroll *x, t_floatarg ftranspose)
{
x->x_transpose = ftranspose;
}
-static void pianoroll_save_file(t_pianoroll *x, t_symbol *ffile)
+static void pianoroll_save_file(t_pianoroll *x, t_symbol *ffile)
{
- FILE *tmph;
- t_int si;
-
- if ( ( tmph = fopen( ffile->s_name, "w" ) ) == NULL )
- {
- post( "pianoroll : could not open file : %s for writing", ffile->s_name );
- return;
- }
-
- // post( "saving pianoroll : %s", x->x_name->s_name );
- fprintf(tmph, "%d %d %f %f %d %d %d %f %d ",
- x->x_width, x->x_height,
- x->x_pmin, x->x_pmax,
- x->x_nbgrades, x->x_nbsteps,
- x->x_defvalue, x->x_transpose, x->x_save );
- for ( si=0; si<x->x_nbsteps; si++ )
- {
- fprintf(tmph, "%f %f ", x->x_peaches[si], x->x_volumes[si] );
- }
-
- if ( fclose( tmph ) == -1 )
- {
- post( "pianoroll : could not close file : %s ", ffile->s_name );
- return;
- }
+ FILE *tmph;
+ t_int si;
+
+ if ( ( tmph = fopen( ffile->s_name, "w" ) ) == NULL )
+ {
+ post( "pianoroll : could not open file : %s for writing", ffile->s_name );
+ return;
+ }
+
+ // post( "saving pianoroll : %s", x->x_name->s_name );
+ fprintf(tmph, "%d %d %f %f %d %d %d %f %d ",
+ x->x_width, x->x_height,
+ x->x_pmin, x->x_pmax,
+ x->x_nbgrades, x->x_nbsteps,
+ x->x_defvalue, x->x_transpose, x->x_save );
+ for ( si=0; si<x->x_nbsteps; si++ )
+ {
+ fprintf(tmph, "%f %f ", x->x_peaches[si], x->x_volumes[si] );
+ }
+
+ if ( fclose( tmph ) == -1 )
+ {
+ post( "pianoroll : could not close file : %s ", ffile->s_name );
+ return;
+ }
}
-static void pianoroll_load(t_pianoroll *x, t_symbol *ffile)
+static void pianoroll_load(t_pianoroll *x, t_symbol *ffile)
{
- FILE *tmph;
- t_int si;
-
- if ( ( tmph = fopen( ffile->s_name, "r" ) ) == NULL )
- {
- post( "pianoroll : could not open file : %s for reading", ffile->s_name );
- return;
- }
-
- pianoroll_draw_erase(x, x->x_glist);
- freebytes( x->x_peaches, x->x_nbsteps*sizeof( t_float ) );
- freebytes( x->x_volumes, x->x_nbsteps*sizeof( t_float ) );
- freebytes( x->x_ipeaches, x->x_nbsteps*sizeof( t_int ) );
- freebytes( x->x_ivolumes, x->x_nbsteps*sizeof( t_int ) );
-
- if ( fscanf(tmph, "%d %d %f %f %d %d %d %f %d",
- &x->x_width, &x->x_height,
- &x->x_pmin, &x->x_pmax,
+ FILE *tmph;
+ t_int si;
+
+ if ( ( tmph = fopen( ffile->s_name, "r" ) ) == NULL )
+ {
+ post( "pianoroll : could not open file : %s for reading", ffile->s_name );
+ return;
+ }
+
+ pianoroll_draw_erase(x, x->x_glist);
+ freebytes( x->x_peaches, x->x_nbsteps*sizeof( t_float ) );
+ freebytes( x->x_volumes, x->x_nbsteps*sizeof( t_float ) );
+ freebytes( x->x_ipeaches, x->x_nbsteps*sizeof( t_int ) );
+ freebytes( x->x_ivolumes, x->x_nbsteps*sizeof( t_int ) );
+
+ if ( fscanf(tmph, "%d %d %f %f %d %d %d %f %d",
+ &x->x_width, &x->x_height,
+ &x->x_pmin, &x->x_pmax,
&x->x_nbgrades, &x->x_nbsteps,
&x->x_defvalue, &x->x_transpose, &x->x_save ) != 9 )
- {
- post( "pianoroll : could not restore data from file : %s", ffile->s_name );
- return;
- }
-
- x->x_peaches = ( t_float* ) getbytes( x->x_nbsteps*sizeof(t_float) );
- x->x_volumes = ( t_float* ) getbytes( x->x_nbsteps*sizeof(t_float) );
- x->x_ipeaches = ( t_int* ) getbytes( x->x_nbsteps*sizeof(t_int) );
- x->x_ivolumes = ( t_int* ) getbytes( x->x_nbsteps*sizeof(t_int) );
- for ( si=0; si<x->x_nbsteps ; si++ )
- {
- fscanf( tmph, "%f", &x->x_peaches[si] );
- fscanf( tmph, "%f", &x->x_volumes[si] );
- }
-
- pianoroll_draw_new(x, x->x_glist);
- pianoroll_draw_update(x, x->x_glist);
-
- if ( fclose( tmph ) == -1 )
- {
- post( "pianoroll : could not close file : %s ", ffile->s_name );
- return;
- }
+ {
+ post( "pianoroll : could not restore data from file : %s", ffile->s_name );
+ return;
+ }
+
+ x->x_peaches = ( t_float* ) getbytes( x->x_nbsteps*sizeof(t_float) );
+ x->x_volumes = ( t_float* ) getbytes( x->x_nbsteps*sizeof(t_float) );
+ x->x_ipeaches = ( t_int* ) getbytes( x->x_nbsteps*sizeof(t_int) );
+ x->x_ivolumes = ( t_int* ) getbytes( x->x_nbsteps*sizeof(t_int) );
+ for ( si=0; si<x->x_nbsteps ; si++ )
+ {
+ fscanf( tmph, "%f", &x->x_peaches[si] );
+ fscanf( tmph, "%f", &x->x_volumes[si] );
+ }
+
+ pianoroll_draw_new(x, x->x_glist);
+ pianoroll_draw_update(x, x->x_glist);
+
+ if ( fclose( tmph ) == -1 )
+ {
+ post( "pianoroll : could not close file : %s ", ffile->s_name );
+ return;
+ }
}
-static void pianoroll_init(t_pianoroll *x)
+static void pianoroll_init(t_pianoroll *x)
{
- t_int si;
+ t_int si;
for ( si=0; si<x->x_nbsteps; si++ )
{
- x->x_peaches[si] = x->x_defvalue;
- x->x_volumes[si] = 1.0;
+ x->x_peaches[si] = x->x_defvalue;
+ x->x_volumes[si] = 1.0;
}
pianoroll_draw_erase(x, x->x_glist );
pianoroll_draw_new(x, x->x_glist );
pianoroll_draw_update(x, x->x_glist );
}
-static void pianoroll_pitch(t_pianoroll *x, t_floatarg fpos, t_floatarg fpitch)
+static void pianoroll_pitch(t_pianoroll *x, t_floatarg fpos, t_floatarg fpitch)
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
- t_int ipos;
-
- if ( ( ( (t_int) fpos ) < 0 ) || ( ( (t_int) fpos ) >= x->x_nbsteps ) )
- {
- post( "pianoroll : wrong pitch position : %d", fpos );
- return;
- }
- ipos = (t_int) fpos;
- if ( ( ( (t_int) fpitch ) < x->x_pmin ) || ( ( (t_int) fpitch ) > x->x_pmax ) )
- {
- post( "pianoroll : wrong pitch value : %d", fpitch );
- return;
- }
-
- {
- SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #761623\n", canvas, x, ipos, x->x_ipeaches[ ipos ]);
-
- x->x_ipeaches[ ipos ] = (t_int) ( ( ( x->x_pmax - fpitch ) / ( x->x_pmax - x->x_pmin ) ) * ( x->x_nbgrades - 1 ) );
- x->x_peaches[ ipos ] = x->x_pmin+(float)(x->x_nbgrades-1-x->x_ipeaches[ ipos ])/(float)(x->x_nbgrades-1)*(float)(x->x_pmax-x->x_pmin);
- SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #FFFF00\n", canvas, x, ipos, x->x_ipeaches[ ipos ]);
- }
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_int ipos;
+
+ if ( ( ( (t_int) fpos ) < 0 ) || ( ( (t_int) fpos ) >= x->x_nbsteps ) )
+ {
+ post( "pianoroll : wrong pitch position : %d", fpos );
+ return;
+ }
+ ipos = (t_int) fpos;
+ if ( ( ( (t_int) fpitch ) < x->x_pmin ) || ( ( (t_int) fpitch ) > x->x_pmax ) )
+ {
+ post( "pianoroll : wrong pitch value : %d", fpitch );
+ return;
+ }
+
+ {
+ SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #761623\n", canvas, x, ipos, x->x_ipeaches[ ipos ]);
+
+ x->x_ipeaches[ ipos ] = (t_int) ( ( ( x->x_pmax - fpitch ) / ( x->x_pmax - x->x_pmin ) ) * ( x->x_nbgrades - 1 ) );
+ x->x_peaches[ ipos ] = x->x_pmin+(float)(x->x_nbgrades-1-x->x_ipeaches[ ipos ])/(float)(x->x_nbgrades-1)*(float)(x->x_pmax-x->x_pmin);
+ SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #FFFF00\n", canvas, x, ipos, x->x_ipeaches[ ipos ]);
+ }
}
-
-static void pianoroll_volume(t_pianoroll *x, t_floatarg fpos, t_floatarg fvol)
+
+static void pianoroll_volume(t_pianoroll *x, t_floatarg fpos, t_floatarg fvol)
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
- t_int ipos;
-
- if ( ( ( (t_int) fpos ) < 0 ) || ( ( (t_int) fpos ) >= x->x_nbsteps ) )
- {
- post( "pianoroll : wrong volume position : %d", fpos );
- return;
- }
- ipos = (t_int) fpos;
- if ( ( ( (t_int) fvol ) < 0.0 ) || ( ( (t_int) fvol ) > 1.0 ) )
- {
- post( "pianoroll : wrong volume value : %d", fvol );
- return;
- }
-
- {
- SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #562663\n", canvas, x, ipos, x->x_ivolumes[ ipos ] );
-
- x->x_ivolumes[ ipos ] = (t_int) ( ( 1 - fvol ) * (x->x_nbgrades-1) );
- x->x_volumes[ ipos ] = (((float)x->x_nbgrades-1-(float)x->x_ivolumes[ ipos ]))/(float)(x->x_nbgrades-1);
- SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #FF0000\n", canvas, x, ipos, x->x_ivolumes[ ipos ] );
- }
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_int ipos;
+
+ if ( ( ( (t_int) fpos ) < 0 ) || ( ( (t_int) fpos ) >= x->x_nbsteps ) )
+ {
+ post( "pianoroll : wrong volume position : %d", fpos );
+ return;
+ }
+ ipos = (t_int) fpos;
+ if ( ( ( (t_int) fvol ) < 0.0 ) || ( ( (t_int) fvol ) > 1.0 ) )
+ {
+ post( "pianoroll : wrong volume value : %d", fvol );
+ return;
+ }
+
+ {
+ SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #562663\n", canvas, x, ipos, x->x_ivolumes[ ipos ] );
+
+ x->x_ivolumes[ ipos ] = (t_int) ( ( 1 - fvol ) * (x->x_nbgrades-1) );
+ x->x_volumes[ ipos ] = (((float)x->x_nbgrades-1-(float)x->x_ivolumes[ ipos ]))/(float)(x->x_nbgrades-1);
+ SYS_VGUI5(".x%lx.c itemconfigure %xVOLUME%.4d%.4d -fill #FF0000\n", canvas, x, ipos, x->x_ivolumes[ ipos ] );
+ }
}
-static void pianoroll_float(t_pianoroll *x, t_floatarg fposition)
+static void pianoroll_float(t_pianoroll *x, t_floatarg fposition)
{
- t_int pposition, rposition, rrposition;
- t_float fpart;
- t_int pi;
- t_canvas *canvas;
+ t_int pposition, rposition, rrposition;
+ t_float fpart;
+ t_int pi;
+ t_canvas *canvas;
pposition = ( (int)fposition - 1 ) % x->x_nbsteps;
if ( pposition < 0 ) pposition += x->x_nbsteps;
@@ -620,21 +624,21 @@ static void pianoroll_float(t_pianoroll *x, t_floatarg fposition)
pi=-1;
canvas=glist_getcanvas(x->x_glist);
- outlet_float( x->x_pitch, x->x_peaches[ rposition ] +
- fpart*(x->x_peaches[ rrposition ] - x->x_peaches[ rposition ] ) +
+ outlet_float( x->x_pitch, x->x_peaches[ rposition ] +
+ fpart*(x->x_peaches[ rrposition ] - x->x_peaches[ rposition ] ) +
x->x_transpose );
- outlet_float( x->x_volume, x->x_volumes[ rposition ] +
+ outlet_float( x->x_volume, x->x_volumes[ rposition ] +
fpart*(x->x_volumes[ rrposition ] - x->x_volumes[ rposition ] ) );
// graphical update
{
- if ( x->x_scurrent != -1 )
- {
- SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #FFFF00\n", canvas, x,
- x->x_scurrent, x->x_ipeaches[ x->x_scurrent ]);
- }
- x->x_scurrent = rposition;
- SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #00FF00\n", canvas, x,
+ if ( x->x_scurrent != -1 )
+ {
+ SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #FFFF00\n", canvas, x,
+ x->x_scurrent, x->x_ipeaches[ x->x_scurrent ]);
+ }
+ x->x_scurrent = rposition;
+ SYS_VGUI5(".x%lx.c itemconfigure %xPITCH%.4d%.4d -fill #00FF00\n", canvas, x,
x->x_scurrent, x->x_ipeaches[ x->x_scurrent ]);
}
}
@@ -645,110 +649,113 @@ static t_pianoroll *pianoroll_new(t_symbol *s, int argc, t_atom *argv)
t_pianoroll *x;
t_pd *x2;
char *str;
-
+
// post( "pianoroll_new : create : %s argc =%d", s->s_name, argc );
x = (t_pianoroll *)pd_new(pianoroll_class);
- // new pianoroll created from the gui
+ // new pianoroll created from the gui
if ( argc != 0 )
{
- if ( argc < 10 )
- {
- post( "pianoroll : error in the number of arguments ( %d )", argc );
- return NULL;
- }
- if ( ( argv[5].a_w.w_float <= 0 ) || ( argv[5].a_w.w_float <= 0 ) ) {
- post( "pianoroll : error : wrong number of steps or grades" );
- return NULL;
- }
- if ( ( argv[3].a_w.w_float >= argv[4].a_w.w_float ) ) {
- post( "pianoroll : error : min pitch is > to max pitch" );
- return NULL;
- }
- if ( argv[0].a_type != A_SYMBOL || 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 ||
- argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
- argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT ) {
- post( "pianoroll : wrong arguments" );
- return NULL;
- }
-
- // update pianoroll count
- if (!strncmp((str = argv[0].a_w.w_symbol->s_name), "pianoroll", 9)
- && (zz = atoi(str + 9)) > pianorollcount)
- {
- // post( "pianoroll : already %d objects", pianorollcount );
- pianorollcount = zz;
- }
- x->x_name = argv[0].a_w.w_symbol;
- pd_bind(&x->x_obj.ob_pd, x->x_name);
- x->x_width = argv[1].a_w.w_float;
- x->x_height = argv[2].a_w.w_float;
- x->x_pmin = argv[3].a_w.w_float;
- x->x_pmax = argv[4].a_w.w_float;
- x->x_nbgrades = argv[5].a_w.w_float;
- x->x_nbsteps = argv[6].a_w.w_float;
- x->x_peaches = (t_float*) getbytes( x->x_nbsteps*sizeof(t_float) );
- x->x_ipeaches = (t_int*) getbytes( x->x_nbsteps*sizeof(t_int) );
- x->x_volumes = (t_float*) getbytes( x->x_nbsteps*sizeof(t_float) );
- x->x_ivolumes = (t_int*) getbytes( x->x_nbsteps*sizeof(t_int) );
- x->x_defvalue = argv[7].a_w.w_float;
- x->x_transpose = argv[8].a_w.w_float;
- x->x_save = argv[9].a_w.w_float;
+ if ( argc < 10 )
+ {
+ post( "pianoroll : error in the number of arguments ( %d )", argc );
+ return NULL;
+ }
+ if ( ( argv[5].a_w.w_float <= 0 ) || ( argv[5].a_w.w_float <= 0 ) )
+ {
+ post( "pianoroll : error : wrong number of steps or grades" );
+ return NULL;
+ }
+ if ( ( argv[3].a_w.w_float >= argv[4].a_w.w_float ) )
+ {
+ post( "pianoroll : error : min pitch is > to max pitch" );
+ return NULL;
+ }
+ if ( argv[0].a_type != A_SYMBOL || 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 ||
+ argv[6].a_type != A_FLOAT || argv[7].a_type != A_FLOAT ||
+ argv[8].a_type != A_FLOAT || argv[9].a_type != A_FLOAT )
+ {
+ post( "pianoroll : wrong arguments" );
+ return NULL;
+ }
+
+ // update pianoroll count
+ if (!strncmp((str = argv[0].a_w.w_symbol->s_name), "pianoroll", 9)
+ && (zz = atoi(str + 9)) > pianorollcount)
+ {
+ // post( "pianoroll : already %d objects", pianorollcount );
+ pianorollcount = zz;
+ }
+ x->x_name = argv[0].a_w.w_symbol;
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+ x->x_width = argv[1].a_w.w_float;
+ x->x_height = argv[2].a_w.w_float;
+ x->x_pmin = argv[3].a_w.w_float;
+ x->x_pmax = argv[4].a_w.w_float;
+ x->x_nbgrades = argv[5].a_w.w_float;
+ x->x_nbsteps = argv[6].a_w.w_float;
+ x->x_peaches = (t_float*) getbytes( x->x_nbsteps*sizeof(t_float) );
+ x->x_ipeaches = (t_int*) getbytes( x->x_nbsteps*sizeof(t_int) );
+ x->x_volumes = (t_float*) getbytes( x->x_nbsteps*sizeof(t_float) );
+ x->x_ivolumes = (t_int*) getbytes( x->x_nbsteps*sizeof(t_int) );
+ x->x_defvalue = argv[7].a_w.w_float;
+ x->x_transpose = argv[8].a_w.w_float;
+ x->x_save = argv[9].a_w.w_float;
}
else
{
- char buf[40];
-
- sprintf(buf, "pianoroll%d", ++pianorollcount);
- s = gensym(buf);
-
- x->x_name = s;
- pd_bind(&x->x_obj.ob_pd, x->x_name);
-
- x->x_width = DEFAULT_SEQUENCER_WIDTH;
- x->x_height = DEFAULT_SEQUENCER_HEIGHT;
- x->x_pmin = DEFAULT_SEQUENCER_PITCH_MIN;
- x->x_pmax = DEFAULT_SEQUENCER_PITCH_MAX;
- x->x_nbgrades = DEFAULT_SEQUENCER_NBGRADES;
- x->x_nbsteps = DEFAULT_SEQUENCER_STEPS;
- x->x_peaches = (t_float*) getbytes( x->x_nbsteps*sizeof(t_float) );
- x->x_ipeaches = (t_int*) getbytes( x->x_nbsteps*sizeof(t_int) );
- x->x_volumes = (t_float*) getbytes( x->x_nbsteps*sizeof(t_float) );
- x->x_ivolumes = (t_int*) getbytes( x->x_nbsteps*sizeof(t_int) );
- x->x_defvalue = 0;
- x->x_transpose = 0;
- x->x_save = 1;
+ char buf[40];
+
+ sprintf(buf, "pianoroll%d", ++pianorollcount);
+ s = gensym(buf);
+
+ x->x_name = s;
+ pd_bind(&x->x_obj.ob_pd, x->x_name);
+
+ x->x_width = DEFAULT_SEQUENCER_WIDTH;
+ x->x_height = DEFAULT_SEQUENCER_HEIGHT;
+ x->x_pmin = DEFAULT_SEQUENCER_PITCH_MIN;
+ x->x_pmax = DEFAULT_SEQUENCER_PITCH_MAX;
+ x->x_nbgrades = DEFAULT_SEQUENCER_NBGRADES;
+ x->x_nbsteps = DEFAULT_SEQUENCER_STEPS;
+ x->x_peaches = (t_float*) getbytes( x->x_nbsteps*sizeof(t_float) );
+ x->x_ipeaches = (t_int*) getbytes( x->x_nbsteps*sizeof(t_int) );
+ x->x_volumes = (t_float*) getbytes( x->x_nbsteps*sizeof(t_float) );
+ x->x_ivolumes = (t_int*) getbytes( x->x_nbsteps*sizeof(t_int) );
+ x->x_defvalue = 0;
+ x->x_transpose = 0;
+ x->x_save = 1;
}
// common fields for new and restored pianorolls
- x->x_selected = 0;
- x->x_scurrent = -1;
+ x->x_selected = 0;
+ x->x_scurrent = -1;
x->x_glist = (t_glist *) canvas_getcurrent();
- x->x_pitch = outlet_new(&x->x_obj, &s_float );
- x->x_volume = outlet_new(&x->x_obj, &s_float );
+ x->x_pitch = outlet_new(&x->x_obj, &s_float );
+ x->x_volume = outlet_new(&x->x_obj, &s_float );
// post( "pianoroll : argc : %d", argc );
if ( ( argc != 0 ) && ( x->x_save ) )
{
- int ai = 10;
- int si = 0;
-
- while ( ai < argc )
- {
- x->x_peaches[si] = argv[ai++].a_w.w_float;
- if ( ai >= argc ) break;
- x->x_volumes[si++] = argv[ai++].a_w.w_float;
- }
+ int ai = 10;
+ int si = 0;
+
+ while ( ai < argc )
+ {
+ x->x_peaches[si] = argv[ai++].a_w.w_float;
+ if ( ai >= argc ) break;
+ x->x_volumes[si++] = argv[ai++].a_w.w_float;
+ }
}
else // following arguments are the values of pitch, volumes
{
- for ( si=0; si<x->x_nbsteps; si++ )
- {
- x->x_peaches[si] = x->x_defvalue;
- x->x_volumes[si] = 1.0;
- }
+ for ( si=0; si<x->x_nbsteps; si++ )
+ {
+ x->x_peaches[si] = x->x_defvalue;
+ x->x_volumes[si] = 1.0;
+ }
}
// post( "pianoroll_new name : %s width: %d height : %d", x->x_name->s_name, x->x_width, x->x_height );
@@ -758,33 +765,33 @@ static t_pianoroll *pianoroll_new(t_symbol *s, int argc, t_atom *argv)
static void pianoroll_free(t_pianoroll *x)
{
- // post( "pianoroll~: pianoroll_free" );
- if ( x->x_peaches )
- {
- freebytes( x->x_peaches, x->x_nbsteps*sizeof(t_float) );
- }
- if ( x->x_ipeaches )
- {
- freebytes( x->x_ipeaches, x->x_nbsteps*sizeof(t_int) );
- }
- if ( x->x_volumes )
- {
- freebytes( x->x_volumes, x->x_nbsteps*sizeof(t_float) );
- }
- if ( x->x_ivolumes )
- {
- freebytes( x->x_ivolumes, x->x_nbsteps*sizeof(t_int) );
- }
+ // post( "pianoroll~: pianoroll_free" );
+ if ( x->x_peaches )
+ {
+ freebytes( x->x_peaches, x->x_nbsteps*sizeof(t_float) );
+ }
+ if ( x->x_ipeaches )
+ {
+ freebytes( x->x_ipeaches, x->x_nbsteps*sizeof(t_int) );
+ }
+ if ( x->x_volumes )
+ {
+ freebytes( x->x_volumes, x->x_nbsteps*sizeof(t_float) );
+ }
+ if ( x->x_ivolumes )
+ {
+ freebytes( x->x_ivolumes, x->x_nbsteps*sizeof(t_int) );
+ }
}
void pianoroll_setup(void)
{
verbose(0, pianoroll_version );
pianoroll_class = class_new(gensym("pianoroll"), (t_newmethod)pianoroll_new,
- (t_method)pianoroll_free, sizeof(t_pianoroll), 0, A_GIMME, 0);
+ (t_method)pianoroll_free, sizeof(t_pianoroll), 0, A_GIMME, 0);
class_addmethod(pianoroll_class, (t_method)pianoroll_float, &s_float, A_FLOAT, 0);
class_addmethod(pianoroll_class, (t_method)pianoroll_transpose, gensym("transpose"),
- A_FLOAT, 0);
+ A_FLOAT, 0);
class_addmethod(pianoroll_class, (t_method)pianoroll_init, gensym("init"), 0);
class_addmethod(pianoroll_class, (t_method)pianoroll_dialog, gensym("dialog"), A_GIMME, 0);
class_addmethod(pianoroll_class, (t_method)pianoroll_save_file, gensym("save"), A_SYMBOL, 0);
@@ -812,6 +819,6 @@ void pianoroll_setup(void)
class_setwidget(pianoroll_class, &pianoroll_widgetbehavior);
sys_vgui("eval [read [open {%s/%s.tcl}]]\n",
- pianoroll_class->c_externdir->s_name,
+ pianoroll_class->c_externdir->s_name,
pianoroll_class->c_name->s_name);
}
diff --git a/playlist.c b/playlist.c
index 900f80e..1566634 100644
--- a/playlist.c
+++ b/playlist.c
@@ -27,7 +27,7 @@
/* "If a man's made of blood and iron" */
/* "Doctor, doctor, what's in my chest ????" */
/* Gang Of Four -- Guns Before Butter */
-/* ---------------------------------------------------------------------------- */
+/* ---------------------------------------------------------------------------- */
#include <stdlib.h>
#include <string.h>
@@ -50,41 +50,43 @@
int scandir(const char *dir, struct dirent ***namelist,
int (*select)(const struct dirent *),
- int (*compar)(const struct dirent **, const struct dirent **)) {
- DIR *d;
- struct dirent *entry;
- register int i=0;
- size_t entrysize;
-
- if ((d=opendir(dir)) == NULL)
- return(-1);
-
- *namelist=NULL;
- while ((entry=readdir(d)) != NULL)
- {
- if (select == NULL || (select != NULL && (*select)(entry)))
+ int (*compar)(const struct dirent **, const struct dirent **))
+{
+ DIR *d;
+ struct dirent *entry;
+ register int i=0;
+ size_t entrysize;
+
+ if ((d=opendir(dir)) == NULL)
+ return(-1);
+
+ *namelist=NULL;
+ while ((entry=readdir(d)) != NULL)
{
- *namelist=(struct dirent **)realloc((void *)(*namelist),
- (size_t)((i+1)*sizeof(struct dirent *)));
- if (*namelist == NULL) return(-1);
- entrysize=sizeof(struct dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1;
- (*namelist)[i]=(struct dirent *)malloc(entrysize);
- if ((*namelist)[i] == NULL) return(-1);
- memcpy((*namelist)[i], entry, entrysize);
- i++;
+ if (select == NULL || (select != NULL && (*select)(entry)))
+ {
+ *namelist=(struct dirent **)realloc((void *)(*namelist),
+ (size_t)((i+1)*sizeof(struct dirent *)));
+ if (*namelist == NULL) return(-1);
+ entrysize=sizeof(struct dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1;
+ (*namelist)[i]=(struct dirent *)malloc(entrysize);
+ if ((*namelist)[i] == NULL) return(-1);
+ memcpy((*namelist)[i], entry, entrysize);
+ i++;
+ }
}
- }
- if (closedir(d)) return(-1);
- if (i == 0) return(-1);
- if (compar != NULL)
- qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), compar);
-
- return(i);
+ if (closedir(d)) return(-1);
+ if (i == 0) return(-1);
+ if (compar != NULL)
+ qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), compar);
+
+ return(i);
}
-int alphasort(const struct dirent **a, const struct dirent **b) {
- return(strcmp((*a)->d_name, (*b)->d_name));
- }
+int alphasort(const struct dirent **a, const struct dirent **b)
+{
+ return(strcmp((*a)->d_name, (*b)->d_name));
+}
int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **));
int alphasort(const struct dirent **, const struct dirent **);
@@ -173,149 +175,149 @@ typedef struct _playlist
char *x_sbcolor; /* scrollbar color */
char *x_fgcolor; /* foreground color */
char *x_secolor; /* selection color */
-} t_playlist;
+} t_playlist;
static void playlist_update_dir(t_playlist *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int i;
- char wrappedname[ MAX_DIR_LENGTH ];
- struct timespec tv;
-
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int i;
+ char wrappedname[ MAX_DIR_LENGTH ];
+ struct timespec tv;
+
tv.tv_sec = 0;
tv.tv_nsec = 10000000;
// set title
- SYS_VGUI3(".x%lx.c delete %xTITLE\n", canvas, x);
+ SYS_VGUI3(".x%lx.c delete %xTITLE\n", canvas, x);
if ( x->x_graphics )
{
- SYS_VGUI8(".x%lx.c create text %d %d -width %d -text \"%s\" -anchor w -font %s -tags %xTITLE\n",
- canvas,
- text_xpix(&x->x_obj, glist)+5,
- text_ypix(&x->x_obj, glist)-10,
- x->x_width,
- x->x_curdir,
- x->x_font,
- x );
+ SYS_VGUI8(".x%lx.c create text %d %d -width %d -text \"%s\" -anchor w -font %s -tags %xTITLE\n",
+ canvas,
+ text_xpix(&x->x_obj, glist)+5,
+ text_ypix(&x->x_obj, glist)-10,
+ x->x_width,
+ x->x_curdir,
+ x->x_font,
+ x );
}
// delete previous entries
for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
{
- SYS_VGUI4(".x%lx.c delete %xENTRY%d\n", canvas, x, i);
+ SYS_VGUI4(".x%lx.c delete %xENTRY%d\n", canvas, x, i);
}
// display the content of current directory
{
- t_int nentries, i;
- struct dirent** dentries; /* all directory entries */
-
- // post( "playlist : scandir : %s", x->x_curdir );
- if ( ( nentries = scandir(x->x_curdir, &dentries, NULL, (x->x_sort==1)?alphasort:NULL ) ) == -1 )
- {
- post( "playlist : could not scan current directory ( where the hell are you ??? )" );
- perror( "scandir" );
- return;
- }
-
- x->x_firstseen = 0;
- if ( x->x_dentries )
- {
- for ( i=0; i<x->x_nentries; i++ )
- {
- // post( "playlist : freeing entry %d size=%d : %s", i, strlen( x->x_dentries[i] ) + 1, x->x_dentries[i] );
- freebytes( x->x_dentries[i], strlen( x->x_dentries[i] ) + 1 );
- }
- }
- if ( x->x_pnentries != -1 )
- {
- freebytes( x->x_dentries, x->x_pnentries*sizeof(char**) );
- }
-
- x->x_nentries = 0;
- // post( "playlist : allocating dentries %d", nentries );
- x->x_dentries = (char **) getbytes( nentries*sizeof(char**) ) ;
- x->x_pnentries = nentries;
- for ( i=0; i<nentries; i++ )
- {
- size_t nmatches = 0;
- regmatch_t matchinfos[1];
- DIR* tmpdir;
-
- // ckeck if that entry should be displayed
- if ( ( ( ( tmpdir = opendir( dentries[i]->d_name ) ) != NULL ) ) ||
- ( strstr( dentries[i]->d_name, x->x_extension ) ) ||
- ( !strcmp( x->x_extension, "all" ) )
- )
- {
- // close temporarily opened dir
- if ( tmpdir )
+ t_int nentries, i;
+ struct dirent** dentries; /* all directory entries */
+
+ // post( "playlist : scandir : %s", x->x_curdir );
+ if ( ( nentries = scandir(x->x_curdir, &dentries, NULL, (x->x_sort==1)?alphasort:NULL ) ) == -1 )
+ {
+ post( "playlist : could not scan current directory ( where the hell are you ??? )" );
+ perror( "scandir" );
+ return;
+ }
+
+ x->x_firstseen = 0;
+ if ( x->x_dentries )
+ {
+ for ( i=0; i<x->x_nentries; i++ )
{
- if ( closedir( tmpdir ) < 0 )
- {
- post( "playlist : could not close directory %s", dentries[i]->d_name );
- }
+ // post( "playlist : freeing entry %d size=%d : %s", i, strlen( x->x_dentries[i] ) + 1, x->x_dentries[i] );
+ freebytes( x->x_dentries[i], strlen( x->x_dentries[i] ) + 1 );
}
+ }
+ if ( x->x_pnentries != -1 )
+ {
+ freebytes( x->x_dentries, x->x_pnentries*sizeof(char**) );
+ }
- // post( "playlist : allocating entry %d %d : %s", x->x_nentries, strlen( dentries[i]->d_name ) + 1, dentries[i]->d_name );
- x->x_dentries[x->x_nentries] = ( char * ) getbytes( strlen( dentries[i]->d_name ) + 1 );
- strcpy( x->x_dentries[x->x_nentries], dentries[i]->d_name );
-
- // display the entry if displayable
- if ( x->x_nentries*x->x_charheight+5 < x->x_height )
+ x->x_nentries = 0;
+ // post( "playlist : allocating dentries %d", nentries );
+ x->x_dentries = (char **) getbytes( nentries*sizeof(char**) ) ;
+ x->x_pnentries = nentries;
+ for ( i=0; i<nentries; i++ )
+ {
+ size_t nmatches = 0;
+ regmatch_t matchinfos[1];
+ DIR* tmpdir;
+
+ // ckeck if that entry should be displayed
+ if ( ( ( ( tmpdir = opendir( dentries[i]->d_name ) ) != NULL ) ) ||
+ ( strstr( dentries[i]->d_name, x->x_extension ) ) ||
+ ( !strcmp( x->x_extension, "all" ) )
+ )
{
- // nanosleep( &tv, NULL );
- x->x_lastseen = x->x_nentries;
- strncpy( wrappedname, x->x_dentries[x->x_nentries], MIN(x->x_width/x->x_charwidth, MAX_DIR_LENGTH) );
- wrappedname[ x->x_width/x->x_charwidth ] = '\0';
- SYS_VGUI11(".x%lx.c create text %d %d -fill %s -activefill %s -width %d -text \"%s\" -anchor w -font %s -tags %xENTRY%d\n",
- canvas,
- text_xpix(&x->x_obj, glist)+5,
- text_ypix(&x->x_obj, glist)+5+(x->x_nentries-x->x_firstseen)*x->x_charheight,
- x->x_fgcolor,
- x->x_secolor,
- x->x_width,
- wrappedname,
- x->x_font,
- x, x->x_nentries );
+ // close temporarily opened dir
+ if ( tmpdir )
+ {
+ if ( closedir( tmpdir ) < 0 )
+ {
+ post( "playlist : could not close directory %s", dentries[i]->d_name );
+ }
+ }
+
+ // post( "playlist : allocating entry %d %d : %s", x->x_nentries, strlen( dentries[i]->d_name ) + 1, dentries[i]->d_name );
+ x->x_dentries[x->x_nentries] = ( char * ) getbytes( strlen( dentries[i]->d_name ) + 1 );
+ strcpy( x->x_dentries[x->x_nentries], dentries[i]->d_name );
+
+ // display the entry if displayable
+ if ( x->x_nentries*x->x_charheight+5 < x->x_height )
+ {
+ // nanosleep( &tv, NULL );
+ x->x_lastseen = x->x_nentries;
+ strncpy( wrappedname, x->x_dentries[x->x_nentries], MIN(x->x_width/x->x_charwidth, MAX_DIR_LENGTH) );
+ wrappedname[ x->x_width/x->x_charwidth ] = '\0';
+ SYS_VGUI11(".x%lx.c create text %d %d -fill %s -activefill %s -width %d -text \"%s\" -anchor w -font %s -tags %xENTRY%d\n",
+ canvas,
+ text_xpix(&x->x_obj, glist)+5,
+ text_ypix(&x->x_obj, glist)+5+(x->x_nentries-x->x_firstseen)*x->x_charheight,
+ x->x_fgcolor,
+ x->x_secolor,
+ x->x_width,
+ wrappedname,
+ x->x_font,
+ x, x->x_nentries );
+ }
+ x->x_nentries++;
}
- x->x_nentries++;
- }
- }
-
+ }
+
}
}
static void playlist_output_current(t_playlist* x)
{
// output the selected dir+file
- // check that it's not a directory
+ // check that it's not a directory
if ( chdir( x->x_dentries[x->x_itemselected] ) == 0 )
{
- chdir( x->x_curdir );
- return;
+ chdir( x->x_curdir );
+ return;
}
if ( x->x_dentries && x->x_itemselected < x->x_nentries && x->x_itemselected >= 0 )
{
- char* tmpstring = (char*) getbytes( strlen( x->x_curdir ) + strlen( x->x_dentries[x->x_itemselected]) + 2 );
+ char* tmpstring = (char*) getbytes( strlen( x->x_curdir ) + strlen( x->x_dentries[x->x_itemselected]) + 2 );
- sprintf( tmpstring, "%s/%s", x->x_curdir, x->x_dentries[x->x_itemselected] );
- outlet_symbol( x->x_dir, gensym( x->x_curdir ) );
- outlet_symbol( x->x_file, gensym( x->x_dentries[x->x_itemselected] ) );
- outlet_symbol( x->x_fullpath, gensym( tmpstring ) );
- freebytes( tmpstring, strlen( x->x_curdir ) + strlen( x->x_dentries[x->x_itemselected]) + 2 );
+ sprintf( tmpstring, "%s/%s", x->x_curdir, x->x_dentries[x->x_itemselected] );
+ outlet_symbol( x->x_dir, gensym( x->x_curdir ) );
+ outlet_symbol( x->x_file, gensym( x->x_dentries[x->x_itemselected] ) );
+ outlet_symbol( x->x_fullpath, gensym( tmpstring ) );
+ freebytes( tmpstring, strlen( x->x_curdir ) + strlen( x->x_dentries[x->x_itemselected]) + 2 );
}
-}
+}
static void playlist_sort(t_playlist* x, t_floatarg fsort)
{
if ( ( (t_int)fsort != 0 ) && ( (t_int)fsort != 1 ) )
{
- post( "playlist : wrong argument to playlist message : %d", (t_int)fsort );
- return;
+ post( "playlist : wrong argument to playlist message : %d", (t_int)fsort );
+ return;
}
x->x_sort = (t_int) fsort;
@@ -326,8 +328,8 @@ static void playlist_font(t_playlist* x, t_symbol *fname, t_symbol *fcase, t_flo
{
if ( (t_int)fsize <= 4 )
{
- post( "playlist : wrong font size in font message : %d", (t_int)fsize );
- return;
+ post( "playlist : wrong font size in font message : %d", (t_int)fsize );
+ return;
}
sprintf( x->x_font, "{%s %d %s}", fname->s_name, (int)fsize, fcase->s_name );
x->x_charheight = (t_int)fsize;
@@ -337,57 +339,57 @@ static void playlist_font(t_playlist* x, t_symbol *fname, t_symbol *fcase, t_flo
}
static void playlist_draw_new(t_playlist *x, t_glist *glist)
-{
- t_canvas *canvas=glist_getcanvas(glist);
+{
+ t_canvas *canvas=glist_getcanvas(glist);
x->x_glist = glist;
if ( x->x_graphics )
{
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xPLAYLIST\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
- x->x_bgcolor, x);
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xSCROLLLIST\n",
- canvas, text_xpix(&x->x_obj, glist)+4*x->x_width/5, text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
- x->x_sbcolor, x);
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xPLAYLIST\n",
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
+ x->x_bgcolor, x);
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xSCROLLLIST\n",
+ canvas, text_xpix(&x->x_obj, glist)+4*x->x_width/5, text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
+ x->x_sbcolor, x);
}
playlist_update_dir( x, glist );
}
static void playlist_draw_move(t_playlist *x, t_glist *glist)
-{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int i;
- struct timespec tv;
-
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int i;
+ struct timespec tv;
+
tv.tv_sec = 0;
tv.tv_nsec = 10000000;
if ( x->x_graphics )
{
- SYS_VGUI7(".x%lx.c coords %xPLAYLIST %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width,
- text_ypix(&x->x_obj, glist)+x->x_height);
- SYS_VGUI7(".x%lx.c coords %xSCROLLLIST %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist)+4*x->x_width/5, text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width,
- text_ypix(&x->x_obj, glist)+x->x_height);
- SYS_VGUI5(".x%lx.c coords %xTITLE %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist)+5, text_ypix(&x->x_obj, glist)-10 );
+ SYS_VGUI7(".x%lx.c coords %xPLAYLIST %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width,
+ text_ypix(&x->x_obj, glist)+x->x_height);
+ SYS_VGUI7(".x%lx.c coords %xSCROLLLIST %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist)+4*x->x_width/5, text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width,
+ text_ypix(&x->x_obj, glist)+x->x_height);
+ SYS_VGUI5(".x%lx.c coords %xTITLE %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist)+5, text_ypix(&x->x_obj, glist)-10 );
}
for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
{
- // nanosleep( &tv, NULL );
- SYS_VGUI6(".x%lx.c coords %xENTRY%d %d %d\n",
- canvas, x, i,
- text_xpix(&x->x_obj, glist)+5,
- text_ypix(&x->x_obj, glist)+5+(i-x->x_firstseen)*x->x_charheight);
+ // nanosleep( &tv, NULL );
+ SYS_VGUI6(".x%lx.c coords %xENTRY%d %d %d\n",
+ canvas, x, i,
+ text_xpix(&x->x_obj, glist)+5,
+ text_ypix(&x->x_obj, glist)+5+(i-x->x_firstseen)*x->x_charheight);
}
canvas_fixlinesfor( canvas, (t_text*)x );
@@ -395,25 +397,25 @@ static void playlist_draw_move(t_playlist *x, t_glist *glist)
static void playlist_draw_erase(t_playlist* x, t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int i;
-
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int i;
+
if ( x->x_graphics )
{
- SYS_VGUI3(".x%lx.c delete %xPLAYLIST\n", canvas, x);
- SYS_VGUI3(".x%lx.c delete %xSCROLLLIST\n", canvas, x);
- SYS_VGUI3(".x%lx.c delete %xTITLE\n", canvas, x);
+ SYS_VGUI3(".x%lx.c delete %xPLAYLIST\n", canvas, x);
+ SYS_VGUI3(".x%lx.c delete %xSCROLLLIST\n", canvas, x);
+ SYS_VGUI3(".x%lx.c delete %xTITLE\n", canvas, x);
}
for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
{
- SYS_VGUI4(".x%lx.c delete %xENTRY%d\n", canvas, x, i);
+ SYS_VGUI4(".x%lx.c delete %xENTRY%d\n", canvas, x, i);
}
-}
+}
static void playlist_draw_select(t_playlist* x, t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
-
+ t_canvas *canvas=glist_getcanvas(glist);
+
// post( "playlist : select" );
if(x->x_selected)
{
@@ -424,57 +426,57 @@ static void playlist_draw_select(t_playlist* x, t_glist* glist)
{
if (x->x_graphics) SYS_VGUI3(".x%lx.c itemconfigure %xPLAYLIST -outline #000000\n", canvas, x);
}
-}
+}
/* ------------------------ playlist widgetbehaviour----------------------------- */
static void playlist_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_playlist* x = (t_playlist*)z;
+ t_playlist* x = (t_playlist*)z;
- *xp1 = text_xpix(&x->x_obj, owner);
- *yp1 = text_ypix(&x->x_obj, owner);
- *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, owner);
+ *yp1 = text_ypix(&x->x_obj, owner);
+ *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
}
static void playlist_save(t_gobj *z, t_binbuf *b)
{
- t_playlist *x = (t_playlist *)z;
+ t_playlist *x = (t_playlist *)z;
- // post( "saving playlist : %s", x->x_extension );
- binbuf_addv(b, "ssiissiisssss", gensym("#X"), gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- gensym("playlist"), gensym(x->x_extension), x->x_width, x->x_height,
- gensym(x->x_font), gensym(x->x_bgcolor), gensym(x->x_sbcolor),
+ // post( "saving playlist : %s", x->x_extension );
+ binbuf_addv(b, "ssiissiisssss", gensym("#X"), gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ gensym("playlist"), gensym(x->x_extension), x->x_width, x->x_height,
+ gensym(x->x_font), gensym(x->x_bgcolor), gensym(x->x_sbcolor),
gensym(x->x_fgcolor), gensym(x->x_secolor) );
- binbuf_addv(b, ";");
+ binbuf_addv(b, ";");
}
static void playlist_select(t_gobj *z, t_glist *glist, int selected)
{
- t_playlist *x = (t_playlist *)z;
+ t_playlist *x = (t_playlist *)z;
- x->x_selected = selected;
+ x->x_selected = selected;
- playlist_draw_select( x, glist );
+ playlist_draw_select( x, glist );
}
static void playlist_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_playlist *x = (t_playlist *)z;
-
- x->x_glist = glist;
- if (vis)
- {
- playlist_draw_new( x, glist );
- }
- else
- {
- playlist_draw_erase( x, glist );
- }
+ t_playlist *x = (t_playlist *)z;
+
+ x->x_glist = glist;
+ if (vis)
+ {
+ playlist_draw_new( x, glist );
+ }
+ else
+ {
+ playlist_draw_erase( x, glist );
+ }
}
static void playlist_delete(t_gobj *z, t_glist *glist)
@@ -484,9 +486,9 @@ static void playlist_delete(t_gobj *z, t_glist *glist)
static void playlist_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
- t_playlist *x = (t_playlist *)z;
- t_int xold = text_xpix(&x->x_obj, glist);
- t_int yold = text_ypix(&x->x_obj, glist);
+ t_playlist *x = (t_playlist *)z;
+ t_int xold = text_xpix(&x->x_obj, glist);
+ t_int yold = text_ypix(&x->x_obj, glist);
// post( "playlist_displace dx=%d dy=%d", dx, dy );
@@ -494,413 +496,414 @@ static void playlist_displace(t_gobj *z, t_glist *glist, int dx, int dy)
x->x_obj.te_ypix += dy;
if(xold != text_xpix(&x->x_obj, glist) || yold != text_ypix(&x->x_obj, glist))
{
- playlist_draw_move(x, glist);
+ playlist_draw_move(x, glist);
}
}
static void playlist_motion(t_playlist *x, t_floatarg dx, t_floatarg dy)
{
- t_int i;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- x->x_cdy+=dy;
-
- // check if we need to scroll
- if ( ( x->x_lastseen < x->x_nentries ) )
- {
- // eventually, move down
- if ( x->x_cdy >= x->x_charheight )
- {
- x->x_cdy = 0;
- if ( x->x_firstseen < x->x_nentries - ( x->x_height/x->x_charheight ) )
- {
- if ( x->x_firstseen + 1 < x->x_nentries )
- {
- for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
- {
- SYS_VGUI4(".x%lx.c delete %xENTRY%d\n", canvas, x, i);
- }
- x->x_firstseen++;
- for ( i=x->x_firstseen; i< x->x_nentries; i++ )
- {
- char *wrappedname = (char *) getbytes( x->x_width );
-
- if ( (i-x->x_firstseen)*x->x_charheight < x->x_height )
- {
- x->x_lastseen = i;
- strncpy( wrappedname, x->x_dentries[i], x->x_width/x->x_charwidth );
- wrappedname[ x->x_width/x->x_charwidth ] = '\0';
- SYS_VGUI11(".x%lx.c create text %d %d -fill %s -activefill %s -width %d -text \"%s\" -anchor w -font %s -tags %xENTRY%d\n",
- canvas,
- text_xpix(&x->x_obj, x->x_glist)+5,
- text_ypix(&x->x_obj, x->x_glist)+5+(i-x->x_firstseen)*x->x_charheight,
- x->x_fgcolor,
- x->x_secolor,
- x->x_width,
- wrappedname,
- x->x_font,
- x, i );
- }
- else break;
- }
- SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n",
- canvas, x, x->x_itemselected, x->x_secolor);
- // post( "playlist : moved down first=%d last=%d", x->x_firstseen, x->x_lastseen );
- }
- }
- }
- // eventually, move up
- if ( x->x_cdy <= -x->x_charheight )
+ t_int i;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ x->x_cdy+=dy;
+
+ // check if we need to scroll
+ if ( ( x->x_lastseen < x->x_nentries ) )
{
- x->x_cdy = 0;
- if ( x->x_lastseen >= ( x->x_height/x->x_charheight ) )
- {
- if ( x->x_firstseen - 1 >= 0 )
- {
- for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
+ // eventually, move down
+ if ( x->x_cdy >= x->x_charheight )
+ {
+ x->x_cdy = 0;
+ if ( x->x_firstseen < x->x_nentries - ( x->x_height/x->x_charheight ) )
{
- SYS_VGUI4(".x%lx.c delete %xENTRY%d\n", canvas, x, i);
+ if ( x->x_firstseen + 1 < x->x_nentries )
+ {
+ for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
+ {
+ SYS_VGUI4(".x%lx.c delete %xENTRY%d\n", canvas, x, i);
+ }
+ x->x_firstseen++;
+ for ( i=x->x_firstseen; i< x->x_nentries; i++ )
+ {
+ char *wrappedname = (char *) getbytes( x->x_width );
+
+ if ( (i-x->x_firstseen)*x->x_charheight < x->x_height )
+ {
+ x->x_lastseen = i;
+ strncpy( wrappedname, x->x_dentries[i], x->x_width/x->x_charwidth );
+ wrappedname[ x->x_width/x->x_charwidth ] = '\0';
+ SYS_VGUI11(".x%lx.c create text %d %d -fill %s -activefill %s -width %d -text \"%s\" -anchor w -font %s -tags %xENTRY%d\n",
+ canvas,
+ text_xpix(&x->x_obj, x->x_glist)+5,
+ text_ypix(&x->x_obj, x->x_glist)+5+(i-x->x_firstseen)*x->x_charheight,
+ x->x_fgcolor,
+ x->x_secolor,
+ x->x_width,
+ wrappedname,
+ x->x_font,
+ x, i );
+ }
+ else break;
+ }
+ SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n",
+ canvas, x, x->x_itemselected, x->x_secolor);
+ // post( "playlist : moved down first=%d last=%d", x->x_firstseen, x->x_lastseen );
+ }
}
- x->x_firstseen--;
- for ( i=x->x_firstseen; i< x->x_nentries; i++ )
+ }
+ // eventually, move up
+ if ( x->x_cdy <= -x->x_charheight )
+ {
+ x->x_cdy = 0;
+ if ( x->x_lastseen >= ( x->x_height/x->x_charheight ) )
{
- char *wrappedname = (char *) getbytes( x->x_width );
-
- if ( (i-x->x_firstseen)*x->x_charheight < x->x_height )
- {
- x->x_lastseen = i;
- strncpy( wrappedname, x->x_dentries[i], x->x_width/x->x_charwidth );
- wrappedname[ x->x_width/x->x_charwidth ] = '\0';
- SYS_VGUI11(".x%lx.c create text %d %d -fill %s -activefill %s -width %d -text \"%s\" \
+ if ( x->x_firstseen - 1 >= 0 )
+ {
+ for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
+ {
+ SYS_VGUI4(".x%lx.c delete %xENTRY%d\n", canvas, x, i);
+ }
+ x->x_firstseen--;
+ for ( i=x->x_firstseen; i< x->x_nentries; i++ )
+ {
+ char *wrappedname = (char *) getbytes( x->x_width );
+
+ if ( (i-x->x_firstseen)*x->x_charheight < x->x_height )
+ {
+ x->x_lastseen = i;
+ strncpy( wrappedname, x->x_dentries[i], x->x_width/x->x_charwidth );
+ wrappedname[ x->x_width/x->x_charwidth ] = '\0';
+ SYS_VGUI11(".x%lx.c create text %d %d -fill %s -activefill %s -width %d -text \"%s\" \
-anchor w -font %s -tags %xENTRY%d\n",
- canvas,
- text_xpix(&x->x_obj, x->x_glist)+5,
- text_ypix(&x->x_obj, x->x_glist)+5+(i-x->x_firstseen)*x->x_charheight,
- x->x_fgcolor,
- x->x_secolor,
- x->x_width,
- wrappedname,
- x->x_font,
- x, i );
+ canvas,
+ text_xpix(&x->x_obj, x->x_glist)+5,
+ text_ypix(&x->x_obj, x->x_glist)+5+(i-x->x_firstseen)*x->x_charheight,
+ x->x_fgcolor,
+ x->x_secolor,
+ x->x_width,
+ wrappedname,
+ x->x_font,
+ x, i );
+ }
+ else break;
+ }
+ SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n",
+ canvas, x, x->x_itemselected, x->x_secolor);
+ // post( "playlist : moved up first=%d last=%d", x->x_firstseen, x->x_lastseen );
}
- else break;
}
- SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n",
- canvas, x, x->x_itemselected, x->x_secolor);
- // post( "playlist : moved up first=%d last=%d", x->x_firstseen, x->x_lastseen );
- }
- }
- }
- } // scroll test
-}
-
+ }
+ } // scroll test
+}
+
static void playlist_scroll(t_playlist *x, t_floatarg fdy)
{
- t_int nbsteps, si;
+ t_int nbsteps, si;
nbsteps = (t_int)abs(fdy/x->x_charheight);
// post( "playlist : iterations %d", nbsteps );
for (si=0; si<nbsteps; si++ )
{
- playlist_motion(x, 0, (fdy/abs(fdy))*x->x_charheight);
+ playlist_motion(x, 0, (fdy/abs(fdy))*x->x_charheight);
}
}
static void playlist_graphics(t_playlist *x, t_floatarg fgraphics)
{
- if ( ( (t_int)fgraphics == 0 ) || ( (t_int)fgraphics == 1 ) )
- {
- playlist_draw_erase(x, x->x_glist);
- x->x_graphics = (t_int) fgraphics;
- playlist_draw_new(x, x->x_glist);
- }
+ if ( ( (t_int)fgraphics == 0 ) || ( (t_int)fgraphics == 1 ) )
+ {
+ playlist_draw_erase(x, x->x_glist);
+ x->x_graphics = (t_int) fgraphics;
+ playlist_draw_new(x, x->x_glist);
+ }
}
static int playlist_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
- t_playlist* x = (t_playlist *)z;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_playlist* x = (t_playlist *)z;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
- if (doit)
+ if (doit)
{
- // leave a margin for scrolling without selection
- if ( (xpix-text_xpix(&x->x_obj, glist)) < 4*x->x_width/5 )
- {
- // deselect previously selected item
- SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n",
- canvas, x, x->x_itemselected, x->x_fgcolor);
- x->x_itemselected = x->x_firstseen + (ypix-text_ypix(&x->x_obj, glist))/x->x_charheight;
- SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n",
- canvas, x, x->x_itemselected, x->x_secolor);
- // post( "playlist : selected item : %d", x->x_itemselected );
- if ( x->x_dentries && ( x->x_itemselected < x->x_nentries ) )
+ // leave a margin for scrolling without selection
+ if ( (xpix-text_xpix(&x->x_obj, glist)) < 4*x->x_width/5 )
{
- char *tmpstring = (char *) getbytes( strlen( x->x_curdir ) + strlen( x->x_dentries[x->x_itemselected] ) + 2 );
- sprintf( tmpstring, "%s/%s", x->x_curdir, x->x_dentries[x->x_itemselected] );
- // post( "playlist : chdir : %s", tmpstring );
- if ( chdir( tmpstring ) < 0 )
- {
- playlist_output_current(x);
- }
- else
- {
- if ( !strcmp( x->x_dentries[ x->x_itemselected ], ".." ) )
- {
- char *iamthelastslash;
-
- iamthelastslash = strrchr( x->x_curdir, '/' );
- *iamthelastslash = '\0';
-
- if ( !strcmp( x->x_curdir, "" ) )
- {
- strcpy( x->x_curdir, "/" );
- }
- }
- else
- if ( !strcmp( x->x_dentries[ x->x_itemselected ], "." ) )
- {
- // nothing
- }
- else
- {
- if ( strlen( x->x_curdir ) + strlen( x->x_dentries[x->x_itemselected] ) + 2 > MAX_DIR_LENGTH )
- {
- post( "playlist : maximum dir length reached : cannot change directory" );
- return -1;
- }
- if ( strcmp( x->x_curdir, "/" ) )
- {
- sprintf( x->x_curdir, "%s/%s", x->x_curdir, x->x_dentries[x->x_itemselected] );
- }
- else
- {
- sprintf( x->x_curdir, "/%s", x->x_dentries[x->x_itemselected] );
- }
- }
-
- playlist_update_dir( x, glist );
- }
+ // deselect previously selected item
+ SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n",
+ canvas, x, x->x_itemselected, x->x_fgcolor);
+ x->x_itemselected = x->x_firstseen + (ypix-text_ypix(&x->x_obj, glist))/x->x_charheight;
+ SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n",
+ canvas, x, x->x_itemselected, x->x_secolor);
+ // post( "playlist : selected item : %d", x->x_itemselected );
+ if ( x->x_dentries && ( x->x_itemselected < x->x_nentries ) )
+ {
+ char *tmpstring = (char *) getbytes( strlen( x->x_curdir ) + strlen( x->x_dentries[x->x_itemselected] ) + 2 );
+ sprintf( tmpstring, "%s/%s", x->x_curdir, x->x_dentries[x->x_itemselected] );
+ // post( "playlist : chdir : %s", tmpstring );
+ if ( chdir( tmpstring ) < 0 )
+ {
+ playlist_output_current(x);
+ }
+ else
+ {
+ if ( !strcmp( x->x_dentries[ x->x_itemselected ], ".." ) )
+ {
+ char *iamthelastslash;
+
+ iamthelastslash = strrchr( x->x_curdir, '/' );
+ *iamthelastslash = '\0';
+
+ if ( !strcmp( x->x_curdir, "" ) )
+ {
+ strcpy( x->x_curdir, "/" );
+ }
+ }
+ else if ( !strcmp( x->x_dentries[ x->x_itemselected ], "." ) )
+ {
+ // nothing
+ }
+ else
+ {
+ if ( strlen( x->x_curdir ) + strlen( x->x_dentries[x->x_itemselected] ) + 2 > MAX_DIR_LENGTH )
+ {
+ post( "playlist : maximum dir length reached : cannot change directory" );
+ return -1;
+ }
+ if ( strcmp( x->x_curdir, "/" ) )
+ {
+ sprintf( x->x_curdir, "%s/%s", x->x_curdir, x->x_dentries[x->x_itemselected] );
+ }
+ else
+ {
+ sprintf( x->x_curdir, "/%s", x->x_dentries[x->x_itemselected] );
+ }
+ }
+
+ playlist_update_dir( x, glist );
+ }
+ }
}
- }
- x->x_glist = glist;
- glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)playlist_motion,
- NULL, xpix, ypix );
+ x->x_glist = glist;
+ glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)playlist_motion,
+ NULL, xpix, ypix );
}
return (1);
}
static void playlist_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_playlist *x=(t_playlist *)z;
+ char buf[800];
+ t_playlist *x=(t_playlist *)z;
- sprintf(buf, "pdtk_playlist_dialog %%s %s %d %d %s %s %s %s %s\n",
- x->x_extension, (int)x->x_width, (int)x->x_height,
+ sprintf(buf, "pdtk_playlist_dialog %%s %s %d %d %s %s %s %s %s\n",
+ x->x_extension, (int)x->x_width, (int)x->x_height,
x->x_font, x->x_bgcolor, x->x_sbcolor,
x->x_fgcolor, x->x_secolor );
- // post("playlist_properties : %s", buf );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ // post("playlist_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
static void playlist_dialog(t_playlist *x, t_symbol *s, int argc, t_atom *argv)
{
- if ( !x ) {
- post( "playlist : error :tried to set properties on an unexisting object" );
- }
- if ( argc != 10 )
- {
- post( "playlist : error in the number of arguments ( %d instead of 10 )", argc );
- return;
- }
- if ( argv[0].a_type != A_SYMBOL || argv[1].a_type != A_FLOAT ||
- argv[2].a_type != A_FLOAT || argv[3].a_type != A_SYMBOL ||
- argv[4].a_type != A_FLOAT || argv[5].a_type != A_SYMBOL ||
- argv[6].a_type != A_SYMBOL || argv[7].a_type != A_SYMBOL ||
- argv[8].a_type != A_SYMBOL || argv[9].a_type != A_SYMBOL ) {
- post( "playlist : wrong arguments" );
- return;
- }
- x->x_extension = argv[0].a_w.w_symbol->s_name;
- x->x_width = (int)argv[1].a_w.w_float;
- x->x_height = (int)argv[2].a_w.w_float;
- sprintf( x->x_font, "{%s %d %s}", argv[3].a_w.w_symbol->s_name,
- (int)argv[4].a_w.w_float, argv[5].a_w.w_symbol->s_name );
- x->x_charheight = (t_int)argv[4].a_w.w_float;
- strcpy( x->x_bgcolor, argv[6].a_w.w_symbol->s_name );
- strcpy( x->x_sbcolor, argv[7].a_w.w_symbol->s_name );
- strcpy( x->x_fgcolor, argv[8].a_w.w_symbol->s_name );
- strcpy( x->x_secolor, argv[9].a_w.w_symbol->s_name );
-
- playlist_draw_erase(x, x->x_glist);
- playlist_draw_new(x, x->x_glist);
+ if ( !x )
+ {
+ post( "playlist : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 10 )
+ {
+ post( "playlist : error in the number of arguments ( %d instead of 10 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_SYMBOL || argv[1].a_type != A_FLOAT ||
+ argv[2].a_type != A_FLOAT || argv[3].a_type != A_SYMBOL ||
+ argv[4].a_type != A_FLOAT || argv[5].a_type != A_SYMBOL ||
+ argv[6].a_type != A_SYMBOL || argv[7].a_type != A_SYMBOL ||
+ argv[8].a_type != A_SYMBOL || argv[9].a_type != A_SYMBOL )
+ {
+ post( "playlist : wrong arguments" );
+ return;
+ }
+ x->x_extension = argv[0].a_w.w_symbol->s_name;
+ x->x_width = (int)argv[1].a_w.w_float;
+ x->x_height = (int)argv[2].a_w.w_float;
+ sprintf( x->x_font, "{%s %d %s}", argv[3].a_w.w_symbol->s_name,
+ (int)argv[4].a_w.w_float, argv[5].a_w.w_symbol->s_name );
+ x->x_charheight = (t_int)argv[4].a_w.w_float;
+ strcpy( x->x_bgcolor, argv[6].a_w.w_symbol->s_name );
+ strcpy( x->x_sbcolor, argv[7].a_w.w_symbol->s_name );
+ strcpy( x->x_fgcolor, argv[8].a_w.w_symbol->s_name );
+ strcpy( x->x_secolor, argv[9].a_w.w_symbol->s_name );
+
+ playlist_draw_erase(x, x->x_glist);
+ playlist_draw_new(x, x->x_glist);
}
static t_playlist *playlist_new(t_symbol *s, int argc, t_atom *argv )
{
- t_int i, argoffset=0;
- t_playlist *x;
- char *tmpcurdir;
-
- x = (t_playlist *)pd_new(playlist_class);
-
- x->x_extension = ( char * ) getbytes( MAX_DIR_LENGTH );
- sprintf( x->x_extension, "all" );
- x->x_width = 400;
- x->x_height = 300;
- x->x_font = ( char * ) getbytes( MAX_DIR_LENGTH );
- sprintf( x->x_font, "{Helvetica 10 bold}" );
- x->x_charheight = 10;
- x->x_charwidth = (2*10)/3;
- x->x_bgcolor = ( char * ) getbytes( MAX_DIR_LENGTH );
- sprintf( x->x_bgcolor, "#457782" );
- x->x_sbcolor = ( char * ) getbytes( MAX_DIR_LENGTH );
- sprintf( x->x_sbcolor, "yellow" );
- x->x_fgcolor = ( char * ) getbytes( MAX_DIR_LENGTH );
- sprintf( x->x_fgcolor, "black" );
- x->x_secolor = ( char * ) getbytes( MAX_DIR_LENGTH );
- sprintf( x->x_secolor, "red" );
-
- if ( argc >= 1 )
- {
- if ( argv[0].a_type != A_SYMBOL )
- {
- error( "playlist : wrong argument (extension : 1)" );
- return NULL;
- }
- if ( !strcmp( argv[0].a_w.w_symbol->s_name, "" ) )
- {
- error( "playlist : no extension specified" );
- error( "playlist : usage : playlist <extension> <width> <height>" );
- return NULL;
- }
- strcpy( x->x_extension, argv[0].a_w.w_symbol->s_name );
- }
- if ( argc >= 2 )
- {
- if ( argv[1].a_type != A_FLOAT )
- {
- error( "playlist : wrong argument (width : 2)" );
- return NULL;
- }
- if ( (int)argv[1].a_w.w_float <= 0 )
- {
- error( "playlist : wrong width (%d)", (t_int)(int)argv[1].a_w.w_float );
- error( "playlist : usage : playlist <extension> <width> <height>" );
- return NULL;
- }
- x->x_width = (int)argv[1].a_w.w_float;
- }
- if ( argc >= 3 )
- {
- if ( argv[2].a_type != A_FLOAT )
- {
- error( "playlist : wrong argument (height : 3)" );
- return NULL;
- }
- if ( (int)argv[2].a_w.w_float <= 0 )
- {
- error( "playlist : wrong height (%d)", (t_int)(int)argv[2].a_w.w_float );
- error( "playlist : usage : playlist <extension> <width> <height>" );
- return NULL;
- }
- x->x_height = (int)argv[2].a_w.w_float;
- }
- if ( argc >= 6 )
- {
- if ( argv[3].a_type != A_SYMBOL ||
- argv[5].a_type != A_SYMBOL )
- {
- error( "playlist : wrong arguments (font : 4,6)" );
- error( "argument types : %d %d", argv[3].a_type, argv[5].a_type );
- return NULL;
- }
- if ( argv[4].a_type != A_SYMBOL &&
- argv[4].a_type != A_FLOAT )
- {
- error( "playlist : wrong arguments (font size : 5)" );
- error( "argument types : %d", argv[4].a_type );
- return NULL;
- }
- if ( argv[4].a_type == A_SYMBOL )
- {
- sprintf( x->x_font, "%s", argv[3].a_w.w_symbol->s_name );
- x->x_charheight = (t_int)atoi( strstr( argv[3].a_w.w_symbol->s_name, " ") );
- argoffset=2;
- }
- if ( argv[4].a_type == A_FLOAT )
- {
- x->x_charheight = (t_int)argv[4].a_w.w_float;
- sprintf( x->x_font, "%s %d %s", argv[3].a_w.w_symbol->s_name,
- (int)x->x_charheight, argv[5].a_w.w_symbol->s_name );
- argoffset=0;
- }
- post( "playlist : font : %s, size : %d", x->x_font, x->x_charheight );
- }
- if ( argc >= 7-argoffset )
- {
- if ( argv[6-argoffset].a_type != A_SYMBOL )
- {
- error( "playlist : wrong arguments (background color : %d)", 7-argoffset );
- return NULL;
- }
- strcpy( x->x_bgcolor, argv[6-argoffset].a_w.w_symbol->s_name );
- }
- if ( argc >= 8-argoffset )
- {
- if ( argv[7-argoffset].a_type != A_SYMBOL )
- {
- error( "playlist : wrong arguments (scrollbar color : %d)", 8-argoffset );
- return NULL;
- }
- strcpy( x->x_sbcolor, argv[7-argoffset].a_w.w_symbol->s_name );
- }
- if ( argc >= 9-argoffset )
- {
- if ( argv[8-argoffset].a_type != A_SYMBOL )
- {
- error( "playlist : wrong arguments (foreground color : %d)", 9-argoffset );
- return NULL;
- }
- strcpy( x->x_fgcolor, argv[8-argoffset].a_w.w_symbol->s_name );
- }
- if ( argc >= 10-argoffset )
- {
- if ( argv[9-argoffset].a_type != A_SYMBOL )
- {
- error( "playlist : wrong arguments (selection color : %d)", 10-argoffset );
- return NULL;
- }
- strcpy( x->x_secolor, argv[9-argoffset].a_w.w_symbol->s_name );
- }
-
- x->x_fullpath = outlet_new(&x->x_obj, &s_symbol );
- x->x_file = outlet_new(&x->x_obj, &s_symbol );
- x->x_dir = outlet_new(&x->x_obj, &s_symbol );
-
- x->x_glist = (t_glist *) canvas_getcurrent();
- x->x_nentries = 0;
- x->x_pnentries = 0;
- x->x_dentries = NULL;
-
- // get current directory full path
- t_symbol *cwd = canvas_getdir(canvas_getcurrent());
- int cwdlen = strlen(cwd->s_name);
- x->x_curdir = ( char * ) getbytes( cwdlen );
- strncpy( x->x_curdir, cwd->s_name, cwdlen );
- x->x_curdir[ cwdlen ] = '\0';
-
- x->x_selected = 0;
- x->x_itemselected = -1;
-
- x->x_sort = 1;
- x->x_graphics = 1;
-
- // post( "playlist : built extension=%s width=%d height=%d", x->x_extension, x->x_width, x->x_height );
-
- return (x);
+ t_int i, argoffset=0;
+ t_playlist *x;
+ char *tmpcurdir;
+
+ x = (t_playlist *)pd_new(playlist_class);
+
+ x->x_extension = ( char * ) getbytes( MAX_DIR_LENGTH );
+ sprintf( x->x_extension, "all" );
+ x->x_width = 400;
+ x->x_height = 300;
+ x->x_font = ( char * ) getbytes( MAX_DIR_LENGTH );
+ sprintf( x->x_font, "{Helvetica 10 bold}" );
+ x->x_charheight = 10;
+ x->x_charwidth = (2*10)/3;
+ x->x_bgcolor = ( char * ) getbytes( MAX_DIR_LENGTH );
+ sprintf( x->x_bgcolor, "#457782" );
+ x->x_sbcolor = ( char * ) getbytes( MAX_DIR_LENGTH );
+ sprintf( x->x_sbcolor, "yellow" );
+ x->x_fgcolor = ( char * ) getbytes( MAX_DIR_LENGTH );
+ sprintf( x->x_fgcolor, "black" );
+ x->x_secolor = ( char * ) getbytes( MAX_DIR_LENGTH );
+ sprintf( x->x_secolor, "red" );
+
+ if ( argc >= 1 )
+ {
+ if ( argv[0].a_type != A_SYMBOL )
+ {
+ error( "playlist : wrong argument (extension : 1)" );
+ return NULL;
+ }
+ if ( !strcmp( argv[0].a_w.w_symbol->s_name, "" ) )
+ {
+ error( "playlist : no extension specified" );
+ error( "playlist : usage : playlist <extension> <width> <height>" );
+ return NULL;
+ }
+ strcpy( x->x_extension, argv[0].a_w.w_symbol->s_name );
+ }
+ if ( argc >= 2 )
+ {
+ if ( argv[1].a_type != A_FLOAT )
+ {
+ error( "playlist : wrong argument (width : 2)" );
+ return NULL;
+ }
+ if ( (int)argv[1].a_w.w_float <= 0 )
+ {
+ error( "playlist : wrong width (%d)", (t_int)(int)argv[1].a_w.w_float );
+ error( "playlist : usage : playlist <extension> <width> <height>" );
+ return NULL;
+ }
+ x->x_width = (int)argv[1].a_w.w_float;
+ }
+ if ( argc >= 3 )
+ {
+ if ( argv[2].a_type != A_FLOAT )
+ {
+ error( "playlist : wrong argument (height : 3)" );
+ return NULL;
+ }
+ if ( (int)argv[2].a_w.w_float <= 0 )
+ {
+ error( "playlist : wrong height (%d)", (t_int)(int)argv[2].a_w.w_float );
+ error( "playlist : usage : playlist <extension> <width> <height>" );
+ return NULL;
+ }
+ x->x_height = (int)argv[2].a_w.w_float;
+ }
+ if ( argc >= 6 )
+ {
+ if ( argv[3].a_type != A_SYMBOL ||
+ argv[5].a_type != A_SYMBOL )
+ {
+ error( "playlist : wrong arguments (font : 4,6)" );
+ error( "argument types : %d %d", argv[3].a_type, argv[5].a_type );
+ return NULL;
+ }
+ if ( argv[4].a_type != A_SYMBOL &&
+ argv[4].a_type != A_FLOAT )
+ {
+ error( "playlist : wrong arguments (font size : 5)" );
+ error( "argument types : %d", argv[4].a_type );
+ return NULL;
+ }
+ if ( argv[4].a_type == A_SYMBOL )
+ {
+ sprintf( x->x_font, "%s", argv[3].a_w.w_symbol->s_name );
+ x->x_charheight = (t_int)atoi( strstr( argv[3].a_w.w_symbol->s_name, " ") );
+ argoffset=2;
+ }
+ if ( argv[4].a_type == A_FLOAT )
+ {
+ x->x_charheight = (t_int)argv[4].a_w.w_float;
+ sprintf( x->x_font, "%s %d %s", argv[3].a_w.w_symbol->s_name,
+ (int)x->x_charheight, argv[5].a_w.w_symbol->s_name );
+ argoffset=0;
+ }
+ post( "playlist : font : %s, size : %d", x->x_font, x->x_charheight );
+ }
+ if ( argc >= 7-argoffset )
+ {
+ if ( argv[6-argoffset].a_type != A_SYMBOL )
+ {
+ error( "playlist : wrong arguments (background color : %d)", 7-argoffset );
+ return NULL;
+ }
+ strcpy( x->x_bgcolor, argv[6-argoffset].a_w.w_symbol->s_name );
+ }
+ if ( argc >= 8-argoffset )
+ {
+ if ( argv[7-argoffset].a_type != A_SYMBOL )
+ {
+ error( "playlist : wrong arguments (scrollbar color : %d)", 8-argoffset );
+ return NULL;
+ }
+ strcpy( x->x_sbcolor, argv[7-argoffset].a_w.w_symbol->s_name );
+ }
+ if ( argc >= 9-argoffset )
+ {
+ if ( argv[8-argoffset].a_type != A_SYMBOL )
+ {
+ error( "playlist : wrong arguments (foreground color : %d)", 9-argoffset );
+ return NULL;
+ }
+ strcpy( x->x_fgcolor, argv[8-argoffset].a_w.w_symbol->s_name );
+ }
+ if ( argc >= 10-argoffset )
+ {
+ if ( argv[9-argoffset].a_type != A_SYMBOL )
+ {
+ error( "playlist : wrong arguments (selection color : %d)", 10-argoffset );
+ return NULL;
+ }
+ strcpy( x->x_secolor, argv[9-argoffset].a_w.w_symbol->s_name );
+ }
+
+ x->x_fullpath = outlet_new(&x->x_obj, &s_symbol );
+ x->x_file = outlet_new(&x->x_obj, &s_symbol );
+ x->x_dir = outlet_new(&x->x_obj, &s_symbol );
+
+ x->x_glist = (t_glist *) canvas_getcurrent();
+ x->x_nentries = 0;
+ x->x_pnentries = 0;
+ x->x_dentries = NULL;
+
+ // get current directory full path
+ t_symbol *cwd = canvas_getdir(canvas_getcurrent());
+ int cwdlen = strlen(cwd->s_name);
+ x->x_curdir = ( char * ) getbytes( cwdlen );
+ strncpy( x->x_curdir, cwd->s_name, cwdlen );
+ x->x_curdir[ cwdlen ] = '\0';
+
+ x->x_selected = 0;
+ x->x_itemselected = -1;
+
+ x->x_sort = 1;
+ x->x_graphics = 1;
+
+ // post( "playlist : built extension=%s width=%d height=%d", x->x_extension, x->x_width, x->x_height );
+
+ return (x);
}
static void playlist_free(t_playlist *x)
@@ -908,132 +911,131 @@ static void playlist_free(t_playlist *x)
// post( "playlist : playlist_free" );
if ( x->x_extension )
{
- freebytes( x->x_extension, MAX_DIR_LENGTH );
+ freebytes( x->x_extension, MAX_DIR_LENGTH );
}
if ( x->x_curdir )
{
- freebytes( x->x_curdir, MAX_DIR_LENGTH );
+ freebytes( x->x_curdir, MAX_DIR_LENGTH );
}
if ( x->x_font )
{
- freebytes( x->x_font, MAX_DIR_LENGTH );
+ freebytes( x->x_font, MAX_DIR_LENGTH );
}
if ( x->x_bgcolor )
{
- freebytes( x->x_bgcolor, MAX_DIR_LENGTH );
+ freebytes( x->x_bgcolor, MAX_DIR_LENGTH );
}
if ( x->x_sbcolor )
{
- freebytes( x->x_sbcolor, MAX_DIR_LENGTH );
+ freebytes( x->x_sbcolor, MAX_DIR_LENGTH );
}
if ( x->x_fgcolor )
{
- freebytes( x->x_fgcolor, MAX_DIR_LENGTH );
+ freebytes( x->x_fgcolor, MAX_DIR_LENGTH );
}
if ( x->x_secolor )
{
- freebytes( x->x_secolor, MAX_DIR_LENGTH );
+ freebytes( x->x_secolor, MAX_DIR_LENGTH );
}
}
static void playlist_seek(t_playlist *x, t_floatarg fseeked)
{
- t_int iout=0;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- if ( fseeked < 0 )
- {
- post( "playlist : wrong searched file : %f", fseeked );
- return;
- }
-
- if ( x->x_nentries > 2 )
- {
- // do not select . or ..
- iout = (int)fseeked % (x->x_nentries-2) + 2;
- }
- else
- {
- return;
- }
- SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n", canvas, x, x->x_itemselected, x->x_fgcolor);
- x->x_itemselected = iout;
- SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n", canvas, x, x->x_itemselected, x->x_secolor);
- playlist_output_current(x);
+ t_int iout=0;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ if ( fseeked < 0 )
+ {
+ post( "playlist : wrong searched file : %f", fseeked );
+ return;
+ }
+
+ if ( x->x_nentries > 2 )
+ {
+ // do not select . or ..
+ iout = (int)fseeked % (x->x_nentries-2) + 2;
+ }
+ else
+ {
+ return;
+ }
+ SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n", canvas, x, x->x_itemselected, x->x_fgcolor);
+ x->x_itemselected = iout;
+ SYS_VGUI5(".x%lx.c itemconfigure %xENTRY%d -fill %s\n", canvas, x, x->x_itemselected, x->x_secolor);
+ playlist_output_current(x);
}
static void playlist_location(t_playlist *x, t_symbol *flocation)
{
- int iout=0;
- char olddir[ MAX_DIR_LENGTH ]; /* remember old location */
-
- strcpy( olddir, x->x_curdir );
-
- if ( !strcmp( flocation->s_name, ".." ) )
- {
- char *iamthelastslash;
-
- iamthelastslash = strrchr( x->x_curdir, '/' );
- *iamthelastslash = '\0';
-
- if ( !strcmp( x->x_curdir, "" ) )
- {
- strcpy( x->x_curdir, "/" );
- }
- }
- else
- if ( !strncmp( flocation->s_name, "/", 1 ) )
- {
+ int iout=0;
+ char olddir[ MAX_DIR_LENGTH ]; /* remember old location */
+
+ strcpy( olddir, x->x_curdir );
+
+ if ( !strcmp( flocation->s_name, ".." ) )
+ {
+ char *iamthelastslash;
+
+ iamthelastslash = strrchr( x->x_curdir, '/' );
+ *iamthelastslash = '\0';
+
+ if ( !strcmp( x->x_curdir, "" ) )
+ {
+ strcpy( x->x_curdir, "/" );
+ }
+ }
+ else if ( !strncmp( flocation->s_name, "/", 1 ) )
+ {
// absolute path required
if ( strlen( flocation->s_name ) >= MAX_DIR_LENGTH )
{
- error( "playlist : maximum dir length reached : cannot change directory" );
- return;
+ error( "playlist : maximum dir length reached : cannot change directory" );
+ return;
}
strncpy( x->x_curdir, flocation->s_name, MAX_DIR_LENGTH );
- }
- else
- {
- // relative path
- if ( strlen( x->x_curdir ) + strlen( flocation->s_name ) + 2 > MAX_DIR_LENGTH )
- {
- post( "playlist : maximum dir length reached : cannot change directory" );
- return;
- }
- if ( strcmp( x->x_curdir, "/" ) )
- {
- sprintf( x->x_curdir, "%s/%s", x->x_curdir, flocation->s_name );
- }
- else
- {
- sprintf( x->x_curdir, "/%s", flocation->s_name );
- }
- }
-
- if ( chdir( x->x_curdir ) < 0 )
- {
- error( "playlist : requested location >%s< is not a directory", x->x_curdir );
- strcpy( x->x_curdir, olddir );
- return;
- }
-
- playlist_update_dir( x, x->x_glist );
+ }
+ else
+ {
+ // relative path
+ if ( strlen( x->x_curdir ) + strlen( flocation->s_name ) + 2 > MAX_DIR_LENGTH )
+ {
+ post( "playlist : maximum dir length reached : cannot change directory" );
+ return;
+ }
+ if ( strcmp( x->x_curdir, "/" ) )
+ {
+ sprintf( x->x_curdir, "%s/%s", x->x_curdir, flocation->s_name );
+ }
+ else
+ {
+ sprintf( x->x_curdir, "/%s", flocation->s_name );
+ }
+ }
+
+ if ( chdir( x->x_curdir ) < 0 )
+ {
+ error( "playlist : requested location >%s< is not a directory", x->x_curdir );
+ strcpy( x->x_curdir, olddir );
+ return;
+ }
+
+ playlist_update_dir( x, x->x_glist );
}
void playlist_setup(void)
{
verbose(0, playlist_version );
playlist_class = class_new(gensym("playlist"), (t_newmethod)playlist_new,
- (t_method)playlist_free, sizeof(t_playlist),
- CLASS_DEFAULT, A_GIMME, 0);
+ (t_method)playlist_free, sizeof(t_playlist),
+ CLASS_DEFAULT, A_GIMME, 0);
class_addmethod(playlist_class, (t_method)playlist_seek, gensym("seek"), A_DEFFLOAT, A_NULL );
class_addmethod(playlist_class, (t_method)playlist_location, gensym("location"), A_SYMBOL, A_NULL );
class_addmethod(playlist_class, (t_method)playlist_dialog, gensym("dialog"), A_GIMME, A_NULL );
class_addmethod(playlist_class, (t_method)playlist_sort, gensym("sort"), A_DEFFLOAT, A_NULL );
class_addmethod(playlist_class, (t_method)playlist_graphics, gensym("graphics"), A_DEFFLOAT, A_NULL );
class_addmethod(playlist_class, (t_method)playlist_scroll, gensym("scroll"), A_DEFFLOAT, A_NULL );
- class_addmethod(playlist_class, (t_method)playlist_font, gensym("font"), A_SYMBOL,
- A_SYMBOL, A_DEFFLOAT, A_NULL );
+ class_addmethod(playlist_class, (t_method)playlist_font, gensym("font"), A_SYMBOL,
+ A_SYMBOL, A_DEFFLOAT, A_NULL );
playlist_widgetbehavior.w_getrectfn = playlist_getrect;
playlist_widgetbehavior.w_displacefn = playlist_displace;
@@ -1054,6 +1056,6 @@ void playlist_setup(void)
class_setwidget(playlist_class, &playlist_widgetbehavior);
sys_vgui("eval [read [open {%s/%s.tcl}]]\n",
- playlist_class->c_externdir->s_name,
+ playlist_class->c_externdir->s_name,
playlist_class->c_name->s_name);
}
diff --git a/probalizer.c b/probalizer.c
index 66cb5e8..9b1ee99 100644
--- a/probalizer.c
+++ b/probalizer.c
@@ -57,7 +57,7 @@
#define DEFAULT_PROBALIZER_NBOCCURRENCES 100
#define DEFAULT_PROB_VALUE 10
-static char *probalizer_version = "probalizer : outputs integer values according to a drawn probability curve , version 0.4 (ydegoyon@free.fr)";
+static char *probalizer_version = "probalizer : outputs integer values according to a drawn probability curve , version 0.4 (ydegoyon@free.fr)";
t_widgetbehavior probalizer_widgetbehavior;
static t_class *probalizer_class;
@@ -104,128 +104,128 @@ static int pointsize = 5;
/* drawing functions */
static void probalizer_draw_new(t_probalizer *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int ei;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int ei;
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #6790E2 -tags %xPROBALIZER\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height,
- x);
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height,
+ x);
SYS_VGUI5(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"0\" -tags %xLTCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist)-15, text_ypix(&x->x_obj, glist) + x->x_height, x );
+ canvas, text_xpix(&x->x_obj, glist)-15, text_ypix(&x->x_obj, glist) + x->x_height, x );
SYS_VGUI6(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"%d\" -tags %xLBCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist)-15, text_ypix(&x->x_obj, glist), x->x_noccurrences, x );
+ canvas, text_xpix(&x->x_obj, glist)-15, text_ypix(&x->x_obj, glist), x->x_noccurrences, x );
SYS_VGUI5(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"1\" -tags %xBLCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist)+2, text_ypix(&x->x_obj, glist) + x->x_height + 10, x );
+ canvas, text_xpix(&x->x_obj, glist)+2, text_ypix(&x->x_obj, glist) + x->x_height + 10, x );
SYS_VGUI6(".x%lx.c create text %d %d -font -*-courier-bold--normal--10-* -text \"%d\" -tags %xBRCAPTION\n",
- canvas, text_xpix(&x->x_obj, glist) + x->x_width-5, text_ypix(&x->x_obj, glist) + x->x_height + 10, x->x_nvalues, x );
+ canvas, text_xpix(&x->x_obj, glist) + x->x_width-5, text_ypix(&x->x_obj, glist) + x->x_height + 10, x->x_nvalues, x );
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xIN\n",
- canvas, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) - 2,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist) ,
- x);
+ canvas, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) - 2,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist) ,
+ x);
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT\n",
- canvas, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2,
- x);
+ canvas, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2,
+ x);
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #000000 -tags %xOUT2\n",
- canvas, text_xpix(&x->x_obj, glist) + x->x_width -5,
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + x->x_width,
- text_ypix(&x->x_obj, glist) + x->x_height + 2,
- x);
+ canvas, text_xpix(&x->x_obj, glist) + x->x_width -5,
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + x->x_width,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2,
+ x);
for ( ei=0; ei<x->x_nvalues; ei++ )
{
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #118373 -tags %xPROB%d\n",
- canvas,
- text_xpix(&x->x_obj, glist) + ei * x->x_width/x->x_nvalues,
- text_ypix(&x->x_obj, glist) + x->x_height - ( *(x->x_probs+ei) * x->x_height / x->x_noccurrences ),
- text_xpix(&x->x_obj, glist) + (ei+1) * x->x_width/x->x_nvalues,
- text_ypix(&x->x_obj, glist) + x->x_height,
- x, ei);
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -outline #000000 -fill #118373 -tags %xPROB%d\n",
+ canvas,
+ text_xpix(&x->x_obj, glist) + ei * x->x_width/x->x_nvalues,
+ text_ypix(&x->x_obj, glist) + x->x_height - ( *(x->x_probs+ei) * x->x_height / x->x_noccurrences ),
+ text_xpix(&x->x_obj, glist) + (ei+1) * x->x_width/x->x_nvalues,
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ x, ei);
}
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void probalizer_draw_update(t_probalizer *x)
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
- t_int ei;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_int ei;
for ( ei=0; ei<x->x_nvalues; ei++ )
{
- SYS_VGUI8(".x%lx.c coords %xPROB%d %d %d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, x->x_glist) + ei * x->x_width / x->x_nvalues,
- text_ypix(&x->x_obj, x->x_glist) + x->x_height - ( *(x->x_probs+ei) * x->x_height / x->x_noccurrences ),
- text_xpix(&x->x_obj, x->x_glist) + (ei+1) * x->x_width / x->x_nvalues,
- text_ypix(&x->x_obj, x->x_glist) + x->x_height );
+ SYS_VGUI8(".x%lx.c coords %xPROB%d %d %d %d %d\n",
+ canvas, x, ei,
+ text_xpix(&x->x_obj, x->x_glist) + ei * x->x_width / x->x_nvalues,
+ text_ypix(&x->x_obj, x->x_glist) + x->x_height - ( *(x->x_probs+ei) * x->x_height / x->x_noccurrences ),
+ text_xpix(&x->x_obj, x->x_glist) + (ei+1) * x->x_width / x->x_nvalues,
+ text_ypix(&x->x_obj, x->x_glist) + x->x_height );
}
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void probalizer_draw_move(t_probalizer *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int ei;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int ei;
SYS_VGUI7(".x%lx.c coords %xPROBALIZER %d %d %d %d \n",
- canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height
- );
+ canvas, x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width, text_ypix(&x->x_obj, glist)+x->x_height
+ );
SYS_VGUI7(".x%lx.c coords %xIN %d %d %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) - 2,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist)
- );
+ canvas, x, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) - 2,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist)
+ );
SYS_VGUI7(".x%lx.c coords %xOUT %d %d %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist),
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 2
- );
+ canvas, x, text_xpix(&x->x_obj, glist),
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2
+ );
SYS_VGUI7(".x%lx.c coords %xOUT2 %d %d %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist) + x->x_width - 5,
- text_ypix(&x->x_obj, glist) + x->x_height,
- text_xpix(&x->x_obj, glist) + x->x_width,
- text_ypix(&x->x_obj, glist) + x->x_height + 2
- );
+ canvas, x, text_xpix(&x->x_obj, glist) + x->x_width - 5,
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ text_xpix(&x->x_obj, glist) + x->x_width,
+ text_ypix(&x->x_obj, glist) + x->x_height + 2
+ );
SYS_VGUI5(".x%lx.c coords %xLTCAPTION %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist)-15,
- text_ypix(&x->x_obj, glist) + x->x_height
- );
+ canvas, x, text_xpix(&x->x_obj, glist)-15,
+ text_ypix(&x->x_obj, glist) + x->x_height
+ );
SYS_VGUI5(".x%lx.c coords %xLBCAPTION %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist)-15,
- text_ypix(&x->x_obj, glist)
- );
+ canvas, x, text_xpix(&x->x_obj, glist)-15,
+ text_ypix(&x->x_obj, glist)
+ );
SYS_VGUI5(".x%lx.c coords %xBLCAPTION %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist)+2,
- text_ypix(&x->x_obj, glist) + x->x_height + 10
- );
+ canvas, x, text_xpix(&x->x_obj, glist)+2,
+ text_ypix(&x->x_obj, glist) + x->x_height + 10
+ );
SYS_VGUI5(".x%lx.c coords %xBRCAPTION %d %d\n",
- canvas, x, text_xpix(&x->x_obj, glist) + x->x_width - 5,
- text_ypix(&x->x_obj, glist) + x->x_height + 10
- );
+ canvas, x, text_xpix(&x->x_obj, glist) + x->x_width - 5,
+ text_ypix(&x->x_obj, glist) + x->x_height + 10
+ );
for ( ei=0; ei<x->x_nvalues; ei++ )
{
- SYS_VGUI8(".x%lx.c coords %xPROB%d %d %d %d %d\n",
- canvas, x, ei,
- text_xpix(&x->x_obj, glist) + ei * x->x_width / x->x_nvalues,
- text_ypix(&x->x_obj, glist) + x->x_height - ( *(x->x_probs+ei) * x->x_height / x->x_noccurrences ),
- text_xpix(&x->x_obj, glist) + (ei+1) * x->x_width / x->x_nvalues,
- text_ypix(&x->x_obj, glist) + x->x_height );
+ SYS_VGUI8(".x%lx.c coords %xPROB%d %d %d %d %d\n",
+ canvas, x, ei,
+ text_xpix(&x->x_obj, glist) + ei * x->x_width / x->x_nvalues,
+ text_ypix(&x->x_obj, glist) + x->x_height - ( *(x->x_probs+ei) * x->x_height / x->x_noccurrences ),
+ text_xpix(&x->x_obj, glist) + (ei+1) * x->x_width / x->x_nvalues,
+ text_ypix(&x->x_obj, glist) + x->x_height );
}
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void probalizer_draw_erase(t_probalizer* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- int i, ei, gi;
+ t_canvas *canvas=glist_getcanvas(glist);
+ int i, ei, gi;
SYS_VGUI3(".x%lx.c delete %xPROBALIZER\n", canvas, x );
SYS_VGUI3(".x%lx.c delete %xIN\n", canvas, x );
@@ -237,24 +237,24 @@ static void probalizer_draw_erase(t_probalizer* x,t_glist* glist)
SYS_VGUI3(".x%lx.c delete %xBRCAPTION\n", canvas, x );
for ( ei=0; ei<x->x_nvalues; ei++ )
{
- SYS_VGUI4(".x%lx.c delete %xPROB%d\n", canvas, x, ei );
+ SYS_VGUI4(".x%lx.c delete %xPROB%d\n", canvas, x, ei );
}
}
static void probalizer_draw_select(t_probalizer* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
if(x->x_selected)
{
/* sets the main item in blue */
- SYS_VGUI3(".x%lx.c itemconfigure %xPROBALIZER -outline #0000FF\n", glist_getcanvas(glist), x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xPROBALIZER -outline #0000FF\n", glist_getcanvas(glist), x);
}
else
{
/* sets the main item in black */
- SYS_VGUI3(".x%lx.c itemconfigure %xPROBALIZER -outline #000000\n", glist_getcanvas(glist), x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xPROBALIZER -outline #000000\n", glist_getcanvas(glist), x);
}
}
@@ -262,119 +262,120 @@ static void probalizer_draw_select(t_probalizer* x,t_glist* glist)
static void probalizer_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_probalizer* x = (t_probalizer*)z;
+ t_probalizer* x = (t_probalizer*)z;
- *xp1 = text_xpix(&x->x_obj, owner);
- *yp1 = text_ypix(&x->x_obj, owner);
- *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, owner);
+ *yp1 = text_ypix(&x->x_obj, owner);
+ *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
}
static void probalizer_save(t_gobj *z, t_binbuf *b)
{
- t_probalizer *x = (t_probalizer *)z;
- int ei,gi;
-
- binbuf_addv(b, "ssiisiiiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_width, x->x_height,
- x->x_nvalues, x->x_noccurrences, x->x_save );
- if ( x->x_save )
- {
- for ( ei=0; ei<x->x_nvalues; ei++ )
- {
- // post( "probalizer : saving ( %d, %d )", ei, gi );
- binbuf_addv(b, "ii", ei, *(x->x_probs+ei) );
- }
- }
- binbuf_addv(b, ";");
+ t_probalizer *x = (t_probalizer *)z;
+ int ei,gi;
+
+ binbuf_addv(b, "ssiisiiiii", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_width, x->x_height,
+ x->x_nvalues, x->x_noccurrences, x->x_save );
+ if ( x->x_save )
+ {
+ for ( ei=0; ei<x->x_nvalues; ei++ )
+ {
+ // post( "probalizer : saving ( %d, %d )", ei, gi );
+ binbuf_addv(b, "ii", ei, *(x->x_probs+ei) );
+ }
+ }
+ binbuf_addv(b, ";");
}
static void probalizer_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_probalizer *x=(t_probalizer *)z;
+ char buf[800];
+ t_probalizer *x=(t_probalizer *)z;
- sprintf(buf, "pdtk_probalizer_dialog %%s %d %d %d %d %d\n",
+ sprintf(buf, "pdtk_probalizer_dialog %%s %d %d %d %d %d\n",
x->x_width, x->x_height, x->x_nvalues, x->x_noccurrences, x->x_save );
- // post("probalizer_properties : %s", buf );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ // post("probalizer_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
static void probalizer_select(t_gobj *z, t_glist *glist, int selected)
{
- t_probalizer *x = (t_probalizer *)z;
+ t_probalizer *x = (t_probalizer *)z;
- x->x_selected = selected;
- probalizer_draw_select( x, glist );
+ x->x_selected = selected;
+ probalizer_draw_select( x, glist );
}
static void probalizer_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_probalizer *x = (t_probalizer *)z;
- t_rtext *y;
-
- // post("probalizer_vis : %d", vis );
- if (vis)
- {
- probalizer_draw_new( x, glist );
- }
- else
- {
- probalizer_draw_erase( x, glist );
- }
+ t_probalizer *x = (t_probalizer *)z;
+ t_rtext *y;
+
+ // post("probalizer_vis : %d", vis );
+ if (vis)
+ {
+ probalizer_draw_new( x, glist );
+ }
+ else
+ {
+ probalizer_draw_erase( x, glist );
+ }
}
- /* handle parameters sent by the property dialog */
+/* handle parameters sent by the property dialog */
static void probalizer_dialog(t_probalizer *x, t_symbol *s, int argc, t_atom *argv)
{
- t_int onvalues, owidth, ei, gi, bi;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- if ( !x ) {
- post( "probalizer : error :tried to set properties on an unexisting object" );
- }
- onvalues = x->x_nvalues;
- owidth = x->x_width;
- probalizer_draw_erase(x, x->x_glist);
- if ( argc < 5 )
- {
- post( "probalizer : 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 )
- {
- post( "probalizer : wrong arguments" );
- return;
- }
-
- 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_nvalues = argv[2].a_w.w_float;
- if ( x->x_nvalues < 1 ) x->x_nvalues = 1;
- x->x_noccurrences = argv[3].a_w.w_float;
- if ( x->x_noccurrences < 1 ) x->x_noccurrences = 1;
- x->x_save = argv[4].a_w.w_float;
-
- // re-allocate arrays of values
- post( "probalizer : re-allocate values" );
- if ( onvalues != x->x_nvalues )
- {
- t_int mvalues = ( onvalues > x->x_nvalues ) ? x->x_nvalues : onvalues;
- t_int *newprobs, *newovalues;
+ t_int onvalues, owidth, ei, gi, bi;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ if ( !x )
+ {
+ post( "probalizer : error :tried to set properties on an unexisting object" );
+ }
+ onvalues = x->x_nvalues;
+ owidth = x->x_width;
+ probalizer_draw_erase(x, x->x_glist);
+ if ( argc < 5 )
+ {
+ post( "probalizer : 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 )
+ {
+ post( "probalizer : wrong arguments" );
+ return;
+ }
+
+ 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_nvalues = argv[2].a_w.w_float;
+ if ( x->x_nvalues < 1 ) x->x_nvalues = 1;
+ x->x_noccurrences = argv[3].a_w.w_float;
+ if ( x->x_noccurrences < 1 ) x->x_noccurrences = 1;
+ x->x_save = argv[4].a_w.w_float;
+
+ // re-allocate arrays of values
+ post( "probalizer : re-allocate values" );
+ if ( onvalues != x->x_nvalues )
+ {
+ t_int mvalues = ( onvalues > x->x_nvalues ) ? x->x_nvalues : onvalues;
+ t_int *newprobs, *newovalues;
newprobs = (t_int*) getbytes( x->x_nvalues*sizeof(t_int) );
newovalues = (t_int*) getbytes( x->x_nvalues*sizeof(t_int) );
for ( ei=0; ei<x->x_nvalues; ei++ )
{
- *(newprobs+ei)=DEFAULT_PROB_VALUE;
+ *(newprobs+ei)=DEFAULT_PROB_VALUE;
}
memset( newovalues, 0x0, x->x_nvalues*sizeof(t_int) );
for ( ei=0; ei<mvalues; ei++ )
@@ -382,15 +383,15 @@ static void probalizer_dialog(t_probalizer *x, t_symbol *s, int argc, t_atom *ar
*(newprobs+ei ) = *(x->x_probs+ei);
}
if ( x->x_probs )
- freebytes( x->x_probs, onvalues*sizeof(t_int) );
+ freebytes( x->x_probs, onvalues*sizeof(t_int) );
x->x_probs = newprobs;
if ( x->x_ovalues )
- freebytes( x->x_ovalues, onvalues*sizeof(t_int) );
+ freebytes( x->x_ovalues, onvalues*sizeof(t_int) );
x->x_ovalues = newovalues;
- }
+ }
- probalizer_draw_new(x, x->x_glist);
- canvas_fixlinesfor( canvas, (t_text*)x );
+ probalizer_draw_new(x, x->x_glist);
+ canvas_fixlinesfor( canvas, (t_text*)x );
}
static void probalizer_delete(t_gobj *z, t_glist *glist)
@@ -410,53 +411,53 @@ static void probalizer_displace(t_gobj *z, t_glist *glist, int dx, int dy)
x->x_obj.te_ypix += dy;
if(xold != x->x_obj.te_xpix || yold != x->x_obj.te_ypix)
{
- probalizer_draw_move(x, x->x_glist);
+ probalizer_draw_move(x, x->x_glist);
}
}
static int probalizer_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
- t_probalizer* x = (t_probalizer *)z;
- t_canvas *canvas=glist_getcanvas(glist);
- t_int nevent, npix;
+ t_probalizer* x = (t_probalizer *)z;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int nevent, npix;
- if ( doit)
+ if ( doit)
{
- int nevent;
- int newvalue;
+ int nevent;
+ int newvalue;
- nevent = ((float)( xpix - text_xpix(&x->x_obj, glist) ))/((float)x->x_width/(float)x->x_nvalues);
- newvalue = ((float)(text_ypix(&x->x_obj, glist) + x->x_height - ypix))/( (float)x->x_height/(float)x->x_noccurrences);
+ nevent = ((float)( xpix - text_xpix(&x->x_obj, glist) ))/((float)x->x_width/(float)x->x_nvalues);
+ newvalue = ((float)(text_ypix(&x->x_obj, glist) + x->x_height - ypix))/( (float)x->x_height/(float)x->x_noccurrences);
- // post( "changed %d to %d", nevent, newvalue );
+ // post( "changed %d to %d", nevent, newvalue );
- // consistency check
- if ( nevent < 0 )
- {
+ // consistency check
+ if ( nevent < 0 )
+ {
post( "probalizer : warning : negative event : %d", nevent );
nevent = 0;
- }
- if ( nevent > x->x_nvalues - 1 )
- {
+ }
+ if ( nevent > x->x_nvalues - 1 )
+ {
post( "probalizer : warning : event bigger than number of values: %d", nevent );
nevent = x->x_nvalues - 1 ;
- }
- if ( newvalue < 0 )
- {
+ }
+ if ( newvalue < 0 )
+ {
post( "probalizer : warning : negative value : %d", newvalue );
newvalue = 0;
- }
- if ( newvalue > x->x_noccurrences )
- {
+ }
+ if ( newvalue > x->x_noccurrences )
+ {
post( "probalizer : warning : value bigger than max occurrences : %d", newvalue );
newvalue = x->x_noccurrences ;
- }
+ }
- *( x->x_probs + nevent ) = newvalue;
- // reset all counters
- memset( x->x_ovalues, 0x0, x->x_nvalues*sizeof(t_int) );
- probalizer_draw_update( x );
+ *( x->x_probs + nevent ) = newvalue;
+ // reset all counters
+ memset( x->x_ovalues, 0x0, x->x_nvalues*sizeof(t_int) );
+ probalizer_draw_update( x );
}
return (1);
}
@@ -466,7 +467,7 @@ static t_probalizer *probalizer_new(t_symbol *s, int argc, t_atom *argv)
int bi, i, ei;
t_probalizer *x;
t_pd *x2;
-
+
// post( "probalizer_new : create : %s argc =%d", s->s_name, argc );
x = (t_probalizer *)pd_new(probalizer_class);
@@ -475,70 +476,70 @@ static t_probalizer *probalizer_new(t_symbol *s, int argc, t_atom *argv)
// create bang output
x->x_endoutlet = outlet_new(&x->x_obj, &s_bang);
- // new probalizer created from the gui
+ // new probalizer created from the gui
if ( argc != 0 )
{
- if ( argc < 5 )
- {
- post( "probalizer : 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 )
- {
- post( "probalizer : wrong arguments" );
- return NULL;
- }
+ if ( argc < 5 )
+ {
+ post( "probalizer : 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 )
+ {
+ post( "probalizer : wrong arguments" );
+ return NULL;
+ }
- x->x_width = argv[0].a_w.w_float;
- x->x_height = argv[1].a_w.w_float;
- x->x_nvalues = argv[2].a_w.w_float;
- if ( x->x_nvalues < 1 ) x->x_nvalues = 1;
- x->x_noccurrences = argv[3].a_w.w_float;
- if ( x->x_noccurrences < 1 ) x->x_noccurrences = 1;
- x->x_save = argv[4].a_w.w_float;
+ x->x_width = argv[0].a_w.w_float;
+ x->x_height = argv[1].a_w.w_float;
+ x->x_nvalues = argv[2].a_w.w_float;
+ if ( x->x_nvalues < 1 ) x->x_nvalues = 1;
+ x->x_noccurrences = argv[3].a_w.w_float;
+ if ( x->x_noccurrences < 1 ) x->x_noccurrences = 1;
+ x->x_save = argv[4].a_w.w_float;
}
else
{
- x->x_width = DEFAULT_PROBALIZER_WIDTH;
- x->x_height = DEFAULT_PROBALIZER_HEIGHT;
- x->x_nvalues = DEFAULT_PROBALIZER_NBVALUES;
- x->x_noccurrences = DEFAULT_PROBALIZER_NBOCCURRENCES;
- x->x_save = 1;
+ x->x_width = DEFAULT_PROBALIZER_WIDTH;
+ x->x_height = DEFAULT_PROBALIZER_HEIGHT;
+ x->x_nvalues = DEFAULT_PROBALIZER_NBVALUES;
+ x->x_noccurrences = DEFAULT_PROBALIZER_NBOCCURRENCES;
+ x->x_save = 1;
}
// common fields for new and restored probalizers
x->x_probs = (t_int*) getbytes( x->x_nvalues*sizeof(t_int) );
if ( !x->x_probs )
{
- error( "probalizer : could not allocate buffer" );
- return NULL;
+ error( "probalizer : could not allocate buffer" );
+ return NULL;
}
x->x_ovalues = (t_int*) getbytes( x->x_nvalues*sizeof(t_int) );
if ( !x->x_ovalues )
{
- error( "probalizer : could not allocate buffer" );
- return NULL;
+ error( "probalizer : could not allocate buffer" );
+ return NULL;
}
for ( ei=0; ei<x->x_nvalues; ei++ )
{
*(x->x_probs+ei)=DEFAULT_PROB_VALUE;
}
memset( x->x_ovalues, 0x0, x->x_nvalues*sizeof(t_int) );
- x->x_selected = 0;
+ x->x_selected = 0;
x->x_glist = (t_glist *) canvas_getcurrent();
// post( "probalizer : argc : %d", argc );
if ( ( argc != 0 ) && ( x->x_save ) )
{
- int ai = 5;
- int si = 0;
+ int ai = 5;
+ int si = 0;
- while ( ai < argc - 1 )
- {
- *(x->x_probs + (int)argv[ai].a_w.w_float) = (int)argv[ai+1].a_w.w_float;
- ai += 2;
- }
+ while ( ai < argc - 1 )
+ {
+ *(x->x_probs + (int)argv[ai].a_w.w_float) = (int)argv[ai+1].a_w.w_float;
+ ai += 2;
+ }
}
// post( "probalizer_new width: %d height : %d", x->x_width, x->x_height );
@@ -548,7 +549,7 @@ static t_probalizer *probalizer_new(t_symbol *s, int argc, t_atom *argv)
/* zero counters */
static void probalizer_zero(t_probalizer *x)
{
- t_int ei;
+ t_int ei;
for ( ei=0; ei<x->x_nvalues; ei++ )
{
@@ -561,10 +562,10 @@ static void probalizer_zero(t_probalizer *x)
/* the core of it, output an integer value out of the serial */
static void probalizer_bang(t_probalizer *x)
{
- t_int ei, ci;
- t_int *candidates;
- t_int nbcandidates = 0;
- t_int nevalues=0;
+ t_int ei, ci;
+ t_int *candidates;
+ t_int nbcandidates = 0;
+ t_int nevalues=0;
// calculate number of eligible values
for ( ei=0; ei<x->x_nvalues; ei++ )
@@ -574,54 +575,54 @@ static void probalizer_bang(t_probalizer *x)
if ( nevalues == 0 )
{
- error( "probalizer : probabilities are null, sorry" );
- return;
+ error( "probalizer : probabilities are null, sorry" );
+ return;
}
candidates = ( t_int* ) getbytes( nevalues*sizeof( t_int ) );
if ( !candidates )
{
- error( "probalizer : could not allocate buffer for internal computation" );
- return;
+ error( "probalizer : could not allocate buffer for internal computation" );
+ return;
}
// select eligible values
for ( ei=0; ei<x->x_nvalues; ei++ )
{
- if( *(x->x_ovalues+ei) < *(x->x_probs+ei) )
- {
- for ( ci=0; ci<*(x->x_probs+ei) - *(x->x_ovalues+ei); ci++)
- {
- *(candidates+nbcandidates) = ei;
- nbcandidates++;
- }
- }
+ if( *(x->x_ovalues+ei) < *(x->x_probs+ei) )
+ {
+ for ( ci=0; ci<*(x->x_probs+ei) - *(x->x_ovalues+ei); ci++)
+ {
+ *(candidates+nbcandidates) = ei;
+ nbcandidates++;
+ }
+ }
}
// output one of the values
{
- int chosen = random() % nbcandidates;
- int volue = *(candidates+chosen);
-
- outlet_float( x->x_obj.ob_outlet, volue+1 );
- *(x->x_ovalues+volue) = *(x->x_ovalues+volue) + 1;
- // for ( ei=0; ei<nbcandidates; ei++ )
- // {
- // post( "probalizer : output : %d", *(x->x_ovalues+*(candidates+ei)) );
- // }
-
- // test end of the serial
- if (nbcandidates == 1 )
- {
- // post( "probalizer : end of the serial" );
- outlet_bang( x->x_endoutlet );
- memset( x->x_ovalues, 0x0, x->x_nvalues*sizeof(t_int) );
- }
+ int chosen = random() % nbcandidates;
+ int volue = *(candidates+chosen);
+
+ outlet_float( x->x_obj.ob_outlet, volue+1 );
+ *(x->x_ovalues+volue) = *(x->x_ovalues+volue) + 1;
+ // for ( ei=0; ei<nbcandidates; ei++ )
+ // {
+ // post( "probalizer : output : %d", *(x->x_ovalues+*(candidates+ei)) );
+ // }
+
+ // test end of the serial
+ if (nbcandidates == 1 )
+ {
+ // post( "probalizer : end of the serial" );
+ outlet_bang( x->x_endoutlet );
+ memset( x->x_ovalues, 0x0, x->x_nvalues*sizeof(t_int) );
+ }
}
if ( candidates )
{
- freebytes( candidates, nevalues*sizeof( t_int ) );
+ freebytes( candidates, nevalues*sizeof( t_int ) );
}
}
@@ -630,14 +631,14 @@ static void probalizer_float(t_probalizer *x, t_float fvalue)
{
if ( ( (fvalue-1 ) < 0 ) || ( (fvalue-1 ) >= x->x_nvalues ) )
{
- post( "probalizer : wrong float value : %d", (int)fvalue );
- return;
- }
+ post( "probalizer : wrong float value : %d", (int)fvalue );
+ return;
+ }
if ( ( *(x->x_probs+(int)(fvalue-1))+1 ) <= x->x_noccurrences )
{
- *(x->x_probs+(int)(fvalue-1))+=1;
- probalizer_draw_update( x );
- }
+ *(x->x_probs+(int)(fvalue-1))+=1;
+ probalizer_draw_update( x );
+ }
}
/* reset output */
@@ -649,7 +650,7 @@ static void probalizer_reset(t_probalizer *x)
/* equi probability */
static void probalizer_equi(t_probalizer *x)
{
- t_int ei;
+ t_int ei;
for ( ei=0; ei<x->x_nvalues; ei++ )
{
@@ -661,23 +662,23 @@ static void probalizer_equi(t_probalizer *x)
static void probalizer_free(t_probalizer *x)
{
- t_int ei;
-
- if ( x->x_probs )
- {
- freebytes( x->x_probs, x->x_nvalues*sizeof(int) );
- }
- if ( x->x_ovalues )
- {
- freebytes( x->x_ovalues, x->x_nvalues*sizeof(int) );
- }
+ t_int ei;
+
+ if ( x->x_probs )
+ {
+ freebytes( x->x_probs, x->x_nvalues*sizeof(int) );
+ }
+ if ( x->x_ovalues )
+ {
+ freebytes( x->x_ovalues, x->x_nvalues*sizeof(int) );
+ }
}
void probalizer_setup(void)
{
verbose(0, probalizer_version );
probalizer_class = class_new(gensym("probalizer"), (t_newmethod)probalizer_new,
- (t_method)probalizer_free, sizeof(t_probalizer), 0, A_GIMME, 0);
+ (t_method)probalizer_free, sizeof(t_probalizer), 0, A_GIMME, 0);
class_addmethod(probalizer_class, (t_method)probalizer_dialog, gensym("dialog"), A_GIMME, 0);
class_addmethod(probalizer_class, (t_method)probalizer_float, &s_float, A_FLOAT, 0);
class_addmethod(probalizer_class, (t_method)probalizer_bang, &s_bang, 0);
@@ -704,6 +705,6 @@ void probalizer_setup(void)
sys_vgui("eval [read [open {%s/%s.tcl}]]\n",
- probalizer_class->c_externdir->s_name,
+ probalizer_class->c_externdir->s_name,
probalizer_class->c_name->s_name);
}
diff --git a/randomblock~.c b/randomblock~.c
index dca780d..d9e2fe0 100644
--- a/randomblock~.c
+++ b/randomblock~.c
@@ -52,64 +52,69 @@ typedef struct _randomblock
t_int x_limit;
} t_randomblock;
- /* clean up */
-static void randomblock_free(t_randomblock *x)
+/* clean up */
+static void randomblock_free(t_randomblock *x)
{
}
static void *randomblock_new(t_float flimit)
{
- t_randomblock *x = (t_randomblock *)pd_new(randomblock_class);
- outlet_new(&x->x_obj, &s_signal);
- inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("limit"));
- if ( flimit <= 0 || flimit > RAND_MAX ) {
- post( "randomblock~: wrong creation argument" );
- return NULL;
- }
- x->x_limit = (int) flimit;
- return(x);
+ t_randomblock *x = (t_randomblock *)pd_new(randomblock_class);
+ outlet_new(&x->x_obj, &s_signal);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("limit"));
+ if ( flimit <= 0 || flimit > RAND_MAX )
+ {
+ post( "randomblock~: wrong creation argument" );
+ return NULL;
+ }
+ x->x_limit = (int) flimit;
+ return(x);
}
static void *randomblock_limit(t_randomblock* x, t_float flimit)
{
- if ( flimit < 0 || flimit > RAND_MAX ) {
- post( "randomblock~: wrong random limit" );
- return;
- } else {
- x->x_limit=(int)flimit;
- }
+ if ( flimit < 0 || flimit > RAND_MAX )
+ {
+ post( "randomblock~: wrong random limit" );
+ return;
+ }
+ else
+ {
+ x->x_limit=(int)flimit;
+ }
}
static t_int *randomblock_perform(t_int *w)
{
- t_float *out = (t_float*) w[1];
- int n = (int)(w[2]);
- t_randomblock *x = (t_randomblock*) w[3];
-
- int rvalue = rand();
- // post("random value : %d", rvalue );
- rvalue = rvalue%(x->x_limit-n);
- // post("modulated by %d : %d", (x->x_limit-n), rvalue );
- if ( rvalue < 0 ) rvalue=0;
-
- while (n--) {
- *(out)++=(float)rvalue++;
- }
-
- return (w+4);
+ t_float *out = (t_float*) w[1];
+ int n = (int)(w[2]);
+ t_randomblock *x = (t_randomblock*) w[3];
+
+ int rvalue = rand();
+ // post("random value : %d", rvalue );
+ rvalue = rvalue%(x->x_limit-n);
+ // post("modulated by %d : %d", (x->x_limit-n), rvalue );
+ if ( rvalue < 0 ) rvalue=0;
+
+ while (n--)
+ {
+ *(out)++=(float)rvalue++;
+ }
+
+ return (w+4);
}
static void randomblock_dsp(t_randomblock *x, t_signal **sp)
{
- dsp_add( randomblock_perform, 3, sp[0]->s_vec, sp[0]->s_n, x ) ;
+ dsp_add( randomblock_perform, 3, sp[0]->s_vec, sp[0]->s_n, x ) ;
}
void randomblock_tilde_setup(void)
{
- verbose(0, randomblock_version);
- randomblock_class = class_new(gensym("randomblock~"), (t_newmethod)randomblock_new,
- (t_method)randomblock_free,
- sizeof(t_randomblock), 0, A_DEFFLOAT, 0);
- class_addmethod( randomblock_class, (t_method)randomblock_dsp, gensym("dsp"), 0);
- class_addmethod( randomblock_class, (t_method)randomblock_limit, gensym("limit"), A_FLOAT, 0);
+ verbose(0, randomblock_version);
+ randomblock_class = class_new(gensym("randomblock~"), (t_newmethod)randomblock_new,
+ (t_method)randomblock_free,
+ sizeof(t_randomblock), 0, A_DEFFLOAT, 0);
+ class_addmethod( randomblock_class, (t_method)randomblock_dsp, gensym("dsp"), 0);
+ class_addmethod( randomblock_class, (t_method)randomblock_limit, gensym("limit"), A_FLOAT, 0);
}
diff --git a/samplebox~.c b/samplebox~.c
index f937faf..ea8bb65 100644
--- a/samplebox~.c
+++ b/samplebox~.c
@@ -82,83 +82,107 @@ typedef struct _samplebox
} t_samplebox;
- /* clean up */
-static void samplebox_free(t_samplebox *x)
+/* clean up */
+static void samplebox_free(t_samplebox *x)
{
- if ( x->x_rdata != NULL ) {
- freebytes(x->x_rdata, x->x_size*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- x->x_rdata = NULL;
+ if ( x->x_rdata != NULL )
+ {
+ freebytes(x->x_rdata, x->x_size*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ x->x_rdata = NULL;
}
- if ( x->x_idata != NULL ) {
- freebytes(x->x_idata, x->x_size*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- x->x_idata = NULL;
+ if ( x->x_idata != NULL )
+ {
+ freebytes(x->x_idata, x->x_size*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ x->x_idata = NULL;
}
- if ( x->x_rootsquares != NULL ) {
- freebytes(x->x_rootsquares, x->x_size*sizeof(float) );
- post( "Freed %d bytes", x->x_size*sizeof(float) );
- x->x_rootsquares = NULL;
+ if ( x->x_rootsquares != NULL )
+ {
+ freebytes(x->x_rootsquares, x->x_size*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*sizeof(float) );
+ x->x_rootsquares = NULL;
}
}
- /* allocate tables for storing sound */
+/* allocate tables for storing sound */
static t_int samplebox_allocate(t_samplebox *x)
{
- if ( !(x->x_rdata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) ) {
- return -1;
- } else {
- post( "samplebox~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ if ( !(x->x_rdata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) )
+ {
+ return -1;
}
- if ( !(x->x_idata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) ) {
- return -1;
- } else {
- post( "samplebox~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ else
+ {
+ post( "samplebox~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
}
- if ( !(x->x_rootsquares = getbytes( x->x_size*sizeof(float) ) ) ) {
- return -1;
- } else {
- post( "samplebox~ : allocated %d bytes", x->x_size*sizeof(float) );
+ if ( !(x->x_idata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) )
+ {
+ return -1;
+ }
+ else
+ {
+ post( "samplebox~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ }
+ if ( !(x->x_rootsquares = getbytes( x->x_size*sizeof(float) ) ) )
+ {
+ return -1;
+ }
+ else
+ {
+ post( "samplebox~ : allocated %d bytes", x->x_size*sizeof(float) );
}
return 0;
}
- /* reallocate tables for storing sound */
+/* reallocate tables for storing sound */
static t_int samplebox_reallocate(t_samplebox *x, t_int ioldsize, t_int inewsize)
{
- t_float *prdata=x->x_rdata, *pidata=x->x_idata, *prootsquares=x->x_rootsquares;
+ t_float *prdata=x->x_rdata, *pidata=x->x_idata, *prootsquares=x->x_rootsquares;
- if ( !(x->x_rdata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) ) {
- return -1;
- } else {
- post( "samplebox~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
+ if ( !(x->x_rdata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) )
+ {
+ return -1;
+ }
+ else
+ {
+ post( "samplebox~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
}
- if ( !(x->x_idata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) ) {
- return -1;
- } else {
- post( "samplebox~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
+ if ( !(x->x_idata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) )
+ {
+ return -1;
}
- if ( !(x->x_rootsquares = getbytes( inewsize*sizeof(float) ) ) ) {
- return -1;
- } else {
- post( "samplebox~ : allocated %d bytes", inewsize*sizeof(float) );
+ else
+ {
+ post( "samplebox~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
}
- if ( prdata != NULL ) {
- freebytes(prdata, ioldsize*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
+ if ( !(x->x_rootsquares = getbytes( inewsize*sizeof(float) ) ) )
+ {
+ return -1;
}
- if ( pidata != NULL ) {
- freebytes(pidata, ioldsize*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
+ else
+ {
+ post( "samplebox~ : allocated %d bytes", inewsize*sizeof(float) );
}
- if ( prootsquares != NULL ) {
- freebytes(prootsquares, ioldsize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*sizeof(float) );
+ if ( prdata != NULL )
+ {
+ freebytes(prdata, ioldsize*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
+ }
+ if ( pidata != NULL )
+ {
+ freebytes(pidata, ioldsize*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
+ }
+ if ( prootsquares != NULL )
+ {
+ freebytes(prootsquares, ioldsize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*sizeof(float) );
}
return 0;
}
- /* records or playback the sonogram */
+/* records or playback the sonogram */
static t_int *samplebox_perform(t_int *w)
{
t_float *rin = (t_float *)(w[1]);
@@ -175,13 +199,14 @@ static t_int *samplebox_perform(t_int *w)
t_float z[4];
// reallocate tables if blocksize has been changed
- if ( n != x->x_blocksize ) {
- post( "samplebox~ : reallocating tables" );
- x->x_allocate = 1;
- samplebox_free(x);
- x->x_blocksize = n;
- samplebox_allocate(x);
- x->x_allocate = 0;
+ if ( n != x->x_blocksize )
+ {
+ post( "samplebox~ : reallocating tables" );
+ x->x_allocate = 1;
+ samplebox_free(x);
+ x->x_blocksize = n;
+ samplebox_allocate(x);
+ x->x_allocate = 0;
}
// new block : energy is set to zero
@@ -189,103 +214,122 @@ static t_int *samplebox_perform(t_int *w)
// *(x->x_rootsquares+x->x_writepos) = 0.0;
// }
- if ( x->x_play || x->x_record ) {
- bi = 0;
- while (bi<n) {
- // eventually records input
- if ( !x->x_allocate && x->x_record) {
- *(x->x_rdata+(x->x_writepos*x->x_blocksize)+bi)=*rin;
- *(x->x_idata+(x->x_writepos*x->x_blocksize)+bi)=*iin;
- // *(x->x_rootsquares+x->x_writepos) += sqrt( pow((*rin),2) + pow((*iin),2) );
+ if ( x->x_play || x->x_record )
+ {
+ bi = 0;
+ while (bi<n)
+ {
+ // eventually records input
+ if ( !x->x_allocate && x->x_record)
+ {
+ *(x->x_rdata+(x->x_writepos*x->x_blocksize)+bi)=*rin;
+ *(x->x_idata+(x->x_writepos*x->x_blocksize)+bi)=*iin;
+ // *(x->x_rootsquares+x->x_writepos) += sqrt( pow((*rin),2) + pow((*iin),2) );
+ }
+ // set outputs
+ if ( !x->x_allocate && x->x_play)
+ {
+ *rout = 0.;
+ *iout = 0.;
+ // interpolates 4 points like tabread4
+ rpoint = ((int)x->x_readpos*x->x_blocksize)+bi;
+
+ if ( rpoint == 0 )
+ {
+ v[0]=0.0;
+ v[1]=*(x->x_rdata+rpoint);
+ v[2]=*(x->x_rdata+rpoint+1);
+ v[3]=*(x->x_rdata+rpoint+2);
+ z[0]=0.0;
+ z[1]=*(x->x_idata+rpoint);
+ z[2]=*(x->x_idata+rpoint+1);
+ z[3]=*(x->x_idata+rpoint+2);
+ }
+ else if ( rpoint == (x->x_size*x->x_blocksize-1) )
+ {
+ v[0]=*(x->x_rdata+rpoint-1);
+ v[1]=*(x->x_rdata+rpoint);
+ v[2]=*(x->x_rdata+rpoint+1);
+ v[3]=0.0;
+ z[0]=*(x->x_idata+rpoint-1);
+ z[1]=*(x->x_idata+rpoint);
+ z[2]=*(x->x_idata+rpoint+1);
+ z[3]=0.0;
+ }
+ else if ( rpoint == (x->x_size*x->x_blocksize) )
+ {
+ v[0]=*(x->x_rdata+rpoint-1);
+ v[1]=*(x->x_rdata+rpoint);
+ v[2]=0.0;
+ v[3]=0.0;
+ z[0]=*(x->x_idata+rpoint-1);
+ z[1]=*(x->x_idata+rpoint);
+ z[2]=0.0;
+ z[3]=0.0;
+ }
+ else
+ {
+ v[0]=*(x->x_rdata+rpoint-1);
+ v[1]=*(x->x_rdata+rpoint);
+ v[2]=*(x->x_rdata+rpoint+1);
+ v[3]=*(x->x_rdata+rpoint+2);
+ z[0]=*(x->x_idata+rpoint-1);
+ z[1]=*(x->x_idata+rpoint);
+ z[2]=*(x->x_idata+rpoint+1);
+ z[3]=*(x->x_idata+rpoint+2);
+ }
+
+ {
+ t_float frac = rpoint-(int)rpoint;
+
+ // taken from tabread4_tilde
+ *rout = v[1]+frac*((v[2]-v[1])-0.5f*(frac-1.)*((v[0]-v[3]+3.0f*(v[2]-v[1]))*frac+(2.0f*v[1]-v[0]-v[2])));
+ *iout = z[1]+frac*((z[2]-z[1])-0.5f*(frac-1.)*((z[0]-z[3]+3.0f*(z[2]-z[1]))*frac+(2.0f*z[1]-z[0]-z[2])));
+ }
+
+ // add phase argument
+ fspectrum = sqrt( pow( *rout, 2) + pow( *iout, 2) );
+ fphase = atan2( *iout, *rout );
+ fphase += (x->x_phase/180.0)*(M_PI);
+ *rout = fspectrum*cos( fphase );
+ *iout = fspectrum*sin( fphase );
+ }
+ else
+ {
+ *rout=0.0;
+ *iout=0.0;
+ }
+ rout++;
+ iout++;
+ rin++;
+ iin++;
+ bi++;
}
- // set outputs
- if ( !x->x_allocate && x->x_play) {
- *rout = 0.;
- *iout = 0.;
- // interpolates 4 points like tabread4
- rpoint = ((int)x->x_readpos*x->x_blocksize)+bi;
-
- if ( rpoint == 0 ) {
- v[0]=0.0;
- v[1]=*(x->x_rdata+rpoint);
- v[2]=*(x->x_rdata+rpoint+1);
- v[3]=*(x->x_rdata+rpoint+2);
- z[0]=0.0;
- z[1]=*(x->x_idata+rpoint);
- z[2]=*(x->x_idata+rpoint+1);
- z[3]=*(x->x_idata+rpoint+2);
- } else if ( rpoint == (x->x_size*x->x_blocksize-1) ) {
- v[0]=*(x->x_rdata+rpoint-1);
- v[1]=*(x->x_rdata+rpoint);
- v[2]=*(x->x_rdata+rpoint+1);
- v[3]=0.0;
- z[0]=*(x->x_idata+rpoint-1);
- z[1]=*(x->x_idata+rpoint);
- z[2]=*(x->x_idata+rpoint+1);
- z[3]=0.0;
- } else if ( rpoint == (x->x_size*x->x_blocksize) ) {
- v[0]=*(x->x_rdata+rpoint-1);
- v[1]=*(x->x_rdata+rpoint);
- v[2]=0.0;
- v[3]=0.0;
- z[0]=*(x->x_idata+rpoint-1);
- z[1]=*(x->x_idata+rpoint);
- z[2]=0.0;
- z[3]=0.0;
- } else {
- v[0]=*(x->x_rdata+rpoint-1);
- v[1]=*(x->x_rdata+rpoint);
- v[2]=*(x->x_rdata+rpoint+1);
- v[3]=*(x->x_rdata+rpoint+2);
- z[0]=*(x->x_idata+rpoint-1);
- z[1]=*(x->x_idata+rpoint);
- z[2]=*(x->x_idata+rpoint+1);
- z[3]=*(x->x_idata+rpoint+2);
+ // reset playing position until next play
+ if ( x->x_play )
+ {
+ x->x_readpos+=x->x_readspeed;
+ // post( "xreadpos : %f (added %f)", x->x_readpos, x->x_readspeed );
+ if ( x->x_readpos >= (x->x_readend*x->x_size)/100 )
+ {
+ x->x_play=0;
+ x->x_readpos=(x->x_readstart*x->x_size)/100;
+ // post( "samplebox~ : stopped playing (readpos=%d)", x->x_readpos );
+ outlet_bang(x->x_playend);
}
-
+ }
+ // reset recording position until next record
+ if ( x->x_record )
+ {
+ x->x_writepos++;
+ if ( x->x_writepos >= x->x_size )
{
- t_float frac = rpoint-(int)rpoint;
-
- // taken from tabread4_tilde
- *rout = v[1]+frac*((v[2]-v[1])-0.5f*(frac-1.)*((v[0]-v[3]+3.0f*(v[2]-v[1]))*frac+(2.0f*v[1]-v[0]-v[2])));
- *iout = z[1]+frac*((z[2]-z[1])-0.5f*(frac-1.)*((z[0]-z[3]+3.0f*(z[2]-z[1]))*frac+(2.0f*z[1]-z[0]-z[2])));
+ x->x_record=0;
+ x->x_writepos=0;
+ outlet_bang(x->x_recordend);
+ // post( "samplebox~ : stopped recording" );
}
-
- // add phase argument
- fspectrum = sqrt( pow( *rout, 2) + pow( *iout, 2) );
- fphase = atan2( *iout, *rout );
- fphase += (x->x_phase/180.0)*(M_PI);
- *rout = fspectrum*cos( fphase );
- *iout = fspectrum*sin( fphase );
- } else {
- *rout=0.0;
- *iout=0.0;
}
- rout++;iout++;
- rin++;iin++;
- bi++;
- }
- // reset playing position until next play
- if ( x->x_play ) {
- x->x_readpos+=x->x_readspeed;
- // post( "xreadpos : %f (added %f)", x->x_readpos, x->x_readspeed );
- if ( x->x_readpos >= (x->x_readend*x->x_size)/100 ) {
- x->x_play=0;
- x->x_readpos=(x->x_readstart*x->x_size)/100;
- // post( "samplebox~ : stopped playing (readpos=%d)", x->x_readpos );
- outlet_bang(x->x_playend);
- }
- }
- // reset recording position until next record
- if ( x->x_record ) {
- x->x_writepos++;
- if ( x->x_writepos >= x->x_size ) {
- x->x_record=0;
- x->x_writepos=0;
- outlet_bang(x->x_recordend);
- // post( "samplebox~ : stopped recording" );
- }
- }
}
return (w+7);
}
@@ -295,14 +339,14 @@ static void samplebox_dsp(t_samplebox *x, t_signal **sp)
dsp_add(samplebox_perform, 6, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[0]->s_n, x);
}
- /* record the sonogram */
+/* record the sonogram */
static void samplebox_record(t_samplebox *x)
{
x->x_record=1;
x->x_writepos=0;
}
- /* play the sonogram */
+/* play the sonogram */
static void samplebox_play(t_samplebox *x)
{
x->x_play=1;
@@ -310,79 +354,93 @@ static void samplebox_play(t_samplebox *x)
x->x_readpos=(x->x_readstart*x->x_size)/100;
}
- /* setting the starting point for reading ( in percent ) */
+/* setting the starting point for reading ( in percent ) */
static void samplebox_readstart(t_samplebox *x, t_floatarg fstart)
{
- t_float startpoint = fstart;
+ t_float startpoint = fstart;
if (startpoint < 0) startpoint = 0;
if (startpoint > 100) startpoint = 100;
- if ( startpoint > x->x_readend ) {
- x->x_readstart = x->x_readend;
- post( "samplebox~ : warning : range for reading is null" );
- } else {
- x->x_readstart=startpoint;
+ if ( startpoint > x->x_readend )
+ {
+ x->x_readstart = x->x_readend;
+ post( "samplebox~ : warning : range for reading is null" );
+ }
+ else
+ {
+ x->x_readstart=startpoint;
}
}
- /* setting the starting point for modification ( in percent ) */
+/* setting the starting point for modification ( in percent ) */
static void samplebox_modstart(t_samplebox *x, t_floatarg fstart)
{
- t_float startpoint = fstart;
+ t_float startpoint = fstart;
if (startpoint < 0) startpoint = 0;
if (startpoint > 100) startpoint = 100;
- if ( startpoint > x->x_modend ) {
- x->x_modstart = x->x_modend;
- post( "samplebox~ : warning : range for modifications is null" );
- } else {
- x->x_modstart=startpoint;
+ if ( startpoint > x->x_modend )
+ {
+ x->x_modstart = x->x_modend;
+ post( "samplebox~ : warning : range for modifications is null" );
+ }
+ else
+ {
+ x->x_modstart=startpoint;
}
}
- /* setting the ending point for reading ( in percent ) */
+/* setting the ending point for reading ( in percent ) */
static void samplebox_readend(t_samplebox *x, t_floatarg fend)
{
- t_float endpoint = fend;
+ t_float endpoint = fend;
if (endpoint < 0) endpoint = 0;
if (endpoint > 100) endpoint = 100;
- if ( endpoint < x->x_readstart ) {
- x->x_readend = x->x_readstart;
- post( "samplebox~ : warning : range for reading is null" );
- } else {
- x->x_readend=endpoint;
+ if ( endpoint < x->x_readstart )
+ {
+ x->x_readend = x->x_readstart;
+ post( "samplebox~ : warning : range for reading is null" );
+ }
+ else
+ {
+ x->x_readend=endpoint;
}
}
- /* setting the ending point for modification ( in percent ) */
+/* setting the ending point for modification ( in percent ) */
static void samplebox_modend(t_samplebox *x, t_floatarg fend)
{
- t_float endpoint = fend;
+ t_float endpoint = fend;
if (endpoint < 0) endpoint = 0;
if (endpoint > 100) endpoint = 100;
- if ( endpoint < x->x_modstart ) {
- x->x_modend = x->x_modstart;
- post( "samplebox~ : warning : range for modifications is null" );
- } else {
- x->x_modend=endpoint;
+ if ( endpoint < x->x_modstart )
+ {
+ x->x_modend = x->x_modstart;
+ post( "samplebox~ : warning : range for modifications is null" );
+ }
+ else
+ {
+ x->x_modend=endpoint;
}
}
- /* sets the reading speed */
+/* sets the reading speed */
static void samplebox_readspeed(t_samplebox *x, t_floatarg freadspeed)
{
- if ((int)freadspeed < 0 ) {
- post( "samplebox~ : wrong readspeed argument" );
+ if ((int)freadspeed < 0 )
+ {
+ post( "samplebox~ : wrong readspeed argument" );
}
x->x_readspeed=freadspeed;
}
- /* resize sonogram */
+/* resize sonogram */
static void samplebox_resize(t_samplebox *x, t_floatarg fnewsize )
{
- if (fnewsize <= 0) {
+ if (fnewsize <= 0)
+ {
post( "samplebox~ : error : wrong size" );
return;
}
@@ -395,56 +453,60 @@ static void samplebox_resize(t_samplebox *x, t_floatarg fnewsize )
x->x_allocate = 0;
}
- /* flip blocks */
+/* flip blocks */
static void samplebox_flipblocks(t_samplebox *x)
{
- t_int samplestart, sampleend, middlesample, fi, si;
- t_float fvalue;
+ t_int samplestart, sampleend, middlesample, fi, si;
+ t_float fvalue;
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
middlesample = ( sampleend+samplestart+1 ) / 2;
post( "flip blocks [%d,%d] and [%d,%d]", samplestart, middlesample, middlesample, sampleend );
- for ( si=samplestart; si<=middlesample; si++ ) {
- for ( fi=0; fi<x->x_blocksize; fi++ ) {
- fvalue = *(x->x_rdata+((si)*x->x_blocksize)+fi);
- *(x->x_rdata+((si)*x->x_blocksize)+fi) = *(x->x_rdata+((sampleend+samplestart-si)*x->x_blocksize)+fi);
- *(x->x_rdata+((sampleend+samplestart-si)*x->x_blocksize)+fi) = fvalue;
- fvalue = *(x->x_idata+((si)*x->x_blocksize)+fi);
- *(x->x_idata+((si)*x->x_blocksize)+fi) = *(x->x_idata+((sampleend+samplestart-si)*x->x_blocksize)+fi);
- *(x->x_idata+((sampleend+samplestart-si)*x->x_blocksize)+fi) = fvalue;
- }
+ for ( si=samplestart; si<=middlesample; si++ )
+ {
+ for ( fi=0; fi<x->x_blocksize; fi++ )
+ {
+ fvalue = *(x->x_rdata+((si)*x->x_blocksize)+fi);
+ *(x->x_rdata+((si)*x->x_blocksize)+fi) = *(x->x_rdata+((sampleend+samplestart-si)*x->x_blocksize)+fi);
+ *(x->x_rdata+((sampleend+samplestart-si)*x->x_blocksize)+fi) = fvalue;
+ fvalue = *(x->x_idata+((si)*x->x_blocksize)+fi);
+ *(x->x_idata+((si)*x->x_blocksize)+fi) = *(x->x_idata+((sampleend+samplestart-si)*x->x_blocksize)+fi);
+ *(x->x_idata+((sampleend+samplestart-si)*x->x_blocksize)+fi) = fvalue;
+ }
}
}
- /* change the phase */
+/* change the phase */
static void samplebox_phase(t_samplebox *x, t_floatarg fincphase)
{
- if (fincphase < 0 || fincphase > 90) {
+ if (fincphase < 0 || fincphase > 90)
+ {
post( "samplebox~ : error : wrong phase in phase function : out of [0,90]" );
return;
}
x->x_phase = fincphase;
}
- /* swap blocks */
+/* swap blocks */
static void samplebox_swapblocks(t_samplebox *x, t_floatarg fperstart, t_floatarg fperend, t_floatarg fpersize)
{
- t_int samplestart, samplestartb, samplesize, sp, sf;
- t_int iperstart, iperend, ipersize;
- t_float s1, s2;
- t_float fvalue;
+ t_int samplestart, samplestartb, samplesize, sp, sf;
+ t_int iperstart, iperend, ipersize;
+ t_float s1, s2;
+ t_float fvalue;
iperstart = fperstart;
iperend = fperend;
ipersize = fpersize;
if (iperstart < 0 || iperstart > iperend ||
- iperend <= 0 || iperend+ipersize > 100 ||
- ipersize < 0 || fpersize > 100 ) {
+ iperend <= 0 || iperend+ipersize > 100 ||
+ ipersize < 0 || fpersize > 100 )
+ {
post( "samplebox~ : error : wrong interval [%d%%, %d%%] <-> [%d%%, %d%%]",
- iperstart, iperstart+ipersize, iperend, iperend+ipersize );
+ iperstart, iperstart+ipersize, iperend, iperend+ipersize );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
@@ -454,15 +516,17 @@ static void samplebox_swapblocks(t_samplebox *x, t_floatarg fperstart, t_floatar
samplestartb=samplestart+((samplestartb-samplestart)*iperend)/100;
// post( "swap blocks [%d,%d] and [%d,%d]", samplestart, samplestart+samplesize, samplestartb, samplestartb+samplesize );
-
- for ( sp=samplesize; sp>=0; sp-- ) {
- for ( sf=0; sf<x->x_blocksize; sf++) {
- fvalue = *(x->x_rdata+((int)(samplestart+sp)*x->x_blocksize)+sf);
- *(x->x_rdata+((int)(samplestart+sp)*x->x_blocksize)+sf) = *(x->x_rdata+((int)(samplestartb+sp)*x->x_blocksize)+sf);
- *(x->x_rdata+((int)(samplestartb+sp)*x->x_blocksize)+sf) = fvalue;
- fvalue = *(x->x_idata+((int)(samplestart+sp)*x->x_blocksize)+sf);
- *(x->x_idata+((int)(samplestart+sp)*x->x_blocksize)+sf) = *(x->x_idata+((int)(samplestartb+sp)*x->x_blocksize)+sf);
- *(x->x_idata+((int)(samplestartb+sp)*x->x_blocksize)+sf) = fvalue;
+
+ for ( sp=samplesize; sp>=0; sp-- )
+ {
+ for ( sf=0; sf<x->x_blocksize; sf++)
+ {
+ fvalue = *(x->x_rdata+((int)(samplestart+sp)*x->x_blocksize)+sf);
+ *(x->x_rdata+((int)(samplestart+sp)*x->x_blocksize)+sf) = *(x->x_rdata+((int)(samplestartb+sp)*x->x_blocksize)+sf);
+ *(x->x_rdata+((int)(samplestartb+sp)*x->x_blocksize)+sf) = fvalue;
+ fvalue = *(x->x_idata+((int)(samplestart+sp)*x->x_blocksize)+sf);
+ *(x->x_idata+((int)(samplestart+sp)*x->x_blocksize)+sf) = *(x->x_idata+((int)(samplestartb+sp)*x->x_blocksize)+sf);
+ *(x->x_idata+((int)(samplestartb+sp)*x->x_blocksize)+sf) = fvalue;
}
}
}
@@ -479,12 +543,13 @@ static void *samplebox_new(t_floatarg fsize)
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("readend"));
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("modstart"));
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("modend"));
-
- if ( fsize <= 0 ) {
- error( "samplebox~ : missing or negative creation arguments" );
- return NULL;
+
+ if ( fsize <= 0 )
+ {
+ error( "samplebox~ : missing or negative creation arguments" );
+ return NULL;
}
-
+
x->x_size = fsize;
x->x_blocksize = sys_getblksize();
x->x_play = 0;
@@ -502,10 +567,13 @@ static void *samplebox_new(t_floatarg fsize)
x->x_rootsquares = NULL;
x->x_phase = 0.0;
x->x_samplerate = sys_getsr();
- if ( samplebox_allocate(x) <0 ) {
- return NULL;
- } else {
- return(x);
+ if ( samplebox_allocate(x) <0 )
+ {
+ return NULL;
+ }
+ else
+ {
+ return(x);
}
}
@@ -513,7 +581,7 @@ void samplebox_tilde_setup(void)
{
verbose(0, samplebox_version);
samplebox_class = class_new(gensym("samplebox~"), (t_newmethod)samplebox_new, (t_method)samplebox_free,
- sizeof(t_samplebox), 0, A_DEFFLOAT, 0);
+ sizeof(t_samplebox), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN( samplebox_class, t_samplebox, x_f );
class_addmethod(samplebox_class, (t_method)samplebox_dsp, gensym("dsp"), 0);
class_addmethod(samplebox_class, (t_method)samplebox_record, gensym("record"), 0);
diff --git a/scratcher~.c b/scratcher~.c
index b34e1b4..81d7868 100644
--- a/scratcher~.c
+++ b/scratcher~.c
@@ -37,8 +37,8 @@
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
-#ifdef __APPLE__
-#include <sys/malloc.h>
+#ifdef __APPLE__
+#include <sys/malloc.h>
#else
#include <malloc.h>
#endif
@@ -50,7 +50,7 @@
#ifdef _WIN32
#define M_PI 3.14159265358979323846
-#else
+#else
#include <unistd.h>
#endif
@@ -61,8 +61,8 @@
static int guidebug=0;
static int ignorevisible=1; // ignore visible test
- // because this seems to lead to bad refresh
- // wait for a fix
+// because this seems to lead to bad refresh
+// wait for a fix
#define SYS_VGUI2(a,b) if (guidebug) \
post(a,b);\
@@ -105,13 +105,13 @@ static int ignorevisible=1; // ignore visible test
sys_vgui(a,b,c,d,e,f,g,h,i,j,k)
#define DEFAULT_SCRATCHER_SIZE 88200 // 2 seconds at 44100 hertz
-#define DEFAULT_SCRATCHER_WIDTH 200
-#define DEFAULT_SCRATCHER_HEIGHT 200
-#define DEFAULT_SCRATCHER_SENSIBILITY 25
+#define DEFAULT_SCRATCHER_WIDTH 200
+#define DEFAULT_SCRATCHER_HEIGHT 200
+#define DEFAULT_SCRATCHER_SENSIBILITY 25
#define DEFAULT_SCRATCHER_MAX_SPEED 2.0
-#define DEFAULT_TURNTABLE_INERTIA 0.01
+#define DEFAULT_TURNTABLE_INERTIA 0.01
-#define SCRATCHER_NB_GROOVES 20
+#define SCRATCHER_NB_GROOVES 20
#define SCRATCHER_MOVE_TIMEOUT 20
static char *scratcher_version = "scratcher~: version 0.10, written by Yves Degoyon (ydegoyon@free.fr)";
@@ -141,7 +141,7 @@ typedef struct _scratcher
t_int x_mousemoved; /* flag to indicate the mouse movement */
t_float x_inertia; /* turntable inertia */
- /* graphical data block */
+ /* graphical data block */
t_int x_selected; /* flag to remember if we are seleted or not */
t_int x_width; /* width of the graphical object */
t_int x_height; /* height of the graphical object */
@@ -156,160 +156,160 @@ typedef struct _scratcher
static void scratcher_draw_new(t_scratcher *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int ci;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int ci;
SYS_VGUI7(".x%lx.c create oval %d %d %d %d -fill #000000 -tags %xSCRATCHER\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width,
- text_ypix(&x->x_obj, glist) + x->x_height,
- x);
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width,
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ x);
for ( ci=0; ci<SCRATCHER_NB_GROOVES; ci ++)
{
- SYS_VGUI8(".x%lx.c create oval %d %d %d %d -outline #FFFFFF -tags %xGROOVE%d\n",
- canvas, text_xpix(&x->x_obj, glist) + ci*x->x_width/(2*SCRATCHER_NB_GROOVES),
- text_ypix(&x->x_obj, glist) + ci*x->x_height/(2*SCRATCHER_NB_GROOVES),
- text_xpix(&x->x_obj, glist) + x->x_width - ci*x->x_width/(2*SCRATCHER_NB_GROOVES),
- text_ypix(&x->x_obj, glist) + x->x_height - ci*x->x_height/(2*SCRATCHER_NB_GROOVES),
- x, ci);
+ SYS_VGUI8(".x%lx.c create oval %d %d %d %d -outline #FFFFFF -tags %xGROOVE%d\n",
+ canvas, text_xpix(&x->x_obj, glist) + ci*x->x_width/(2*SCRATCHER_NB_GROOVES),
+ text_ypix(&x->x_obj, glist) + ci*x->x_height/(2*SCRATCHER_NB_GROOVES),
+ text_xpix(&x->x_obj, glist) + x->x_width - ci*x->x_width/(2*SCRATCHER_NB_GROOVES),
+ text_ypix(&x->x_obj, glist) + x->x_height - ci*x->x_height/(2*SCRATCHER_NB_GROOVES),
+ x, ci);
}
if ( x->x_showspeed )
{
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xSPEEDBAR -width 3\n",
- canvas, text_xpix(&x->x_obj, glist)+x->x_width/2,
- text_ypix(&x->x_obj, glist)+x->x_height/2,
- text_xpix(&x->x_obj, glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1. )),
- text_ypix(&x->x_obj, glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1. )),
- x );
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xSPEEDBAR -width 3\n",
+ canvas, text_xpix(&x->x_obj, glist)+x->x_width/2,
+ text_ypix(&x->x_obj, glist)+x->x_height/2,
+ text_xpix(&x->x_obj, glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1. )),
+ text_ypix(&x->x_obj, glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1. )),
+ x );
}
SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -tags %xFSCRATCHER\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width,
- text_ypix(&x->x_obj, glist) + x->x_height,
- x);
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width,
+ text_ypix(&x->x_obj, glist) + x->x_height,
+ x);
canvas_fixlinesfor( canvas, (t_text*)x );
}
static void scratcher_draw_delete(t_scratcher *x, t_glist *glist)
{
- t_int ci;
- t_canvas *canvas=glist_getcanvas(glist);
+ t_int ci;
+ t_canvas *canvas=glist_getcanvas(glist);
if ( glist_isvisible( glist ) )
{
- SYS_VGUI3( ".x%lx.c delete %xSCRATCHER\n", canvas, x );
- SYS_VGUI3( ".x%lx.c delete %xFSCRATCHER\n", canvas, x );
- SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
- for ( ci=0; ci<SCRATCHER_NB_GROOVES; ci ++)
- {
- SYS_VGUI4( ".x%lx.c delete %xGROOVE%d\n", canvas, x, ci );
- }
+ SYS_VGUI3( ".x%lx.c delete %xSCRATCHER\n", canvas, x );
+ SYS_VGUI3( ".x%lx.c delete %xFSCRATCHER\n", canvas, x );
+ SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
+ for ( ci=0; ci<SCRATCHER_NB_GROOVES; ci ++)
+ {
+ SYS_VGUI4( ".x%lx.c delete %xGROOVE%d\n", canvas, x, ci );
+ }
}
}
static void scratcher_draw_move(t_scratcher *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int ci;
-
- if ( glist_isvisible( x->x_glist ) )
- {
- SYS_VGUI7(".x%lx.c coords %xSCRATCHER %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist)-1, text_ypix(&x->x_obj, glist)-1,
- text_xpix(&x->x_obj, glist)+x->x_width+1,
- text_ypix(&x->x_obj, glist)+x->x_height+1);
- SYS_VGUI7(".x%lx.c coords %xFSCRATCHER %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist)-1, text_ypix(&x->x_obj, glist)-1,
- text_xpix(&x->x_obj, glist)+x->x_width+1,
- text_ypix(&x->x_obj, glist)+x->x_height+1);
- if ( x->x_showspeed )
- {
- SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist)+x->x_width/2,
- text_ypix(&x->x_obj, glist)+x->x_height/2,
- text_xpix(&x->x_obj, glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
- text_ypix(&x->x_obj, glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
- );
- }
- for ( ci=0; ci<SCRATCHER_NB_GROOVES; ci ++)
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int ci;
+
+ if ( glist_isvisible( x->x_glist ) )
{
- SYS_VGUI8(".x%lx.c coords %xGROOVE%d %d %d %d %d\n",
- canvas, x, ci,
- text_xpix(&x->x_obj, glist) + ci*x->x_width/(2*SCRATCHER_NB_GROOVES),
- text_ypix(&x->x_obj, glist) + ci*x->x_height/(2*SCRATCHER_NB_GROOVES),
- text_xpix(&x->x_obj, glist) + x->x_width - ci*x->x_width/(2*SCRATCHER_NB_GROOVES),
- text_ypix(&x->x_obj, glist) + x->x_height - ci*x->x_height/(2*SCRATCHER_NB_GROOVES)
- );
+ SYS_VGUI7(".x%lx.c coords %xSCRATCHER %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist)-1, text_ypix(&x->x_obj, glist)-1,
+ text_xpix(&x->x_obj, glist)+x->x_width+1,
+ text_ypix(&x->x_obj, glist)+x->x_height+1);
+ SYS_VGUI7(".x%lx.c coords %xFSCRATCHER %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist)-1, text_ypix(&x->x_obj, glist)-1,
+ text_xpix(&x->x_obj, glist)+x->x_width+1,
+ text_ypix(&x->x_obj, glist)+x->x_height+1);
+ if ( x->x_showspeed )
+ {
+ SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist)+x->x_width/2,
+ text_ypix(&x->x_obj, glist)+x->x_height/2,
+ text_xpix(&x->x_obj, glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
+ text_ypix(&x->x_obj, glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
+ );
+ }
+ for ( ci=0; ci<SCRATCHER_NB_GROOVES; ci ++)
+ {
+ SYS_VGUI8(".x%lx.c coords %xGROOVE%d %d %d %d %d\n",
+ canvas, x, ci,
+ text_xpix(&x->x_obj, glist) + ci*x->x_width/(2*SCRATCHER_NB_GROOVES),
+ text_ypix(&x->x_obj, glist) + ci*x->x_height/(2*SCRATCHER_NB_GROOVES),
+ text_xpix(&x->x_obj, glist) + x->x_width - ci*x->x_width/(2*SCRATCHER_NB_GROOVES),
+ text_ypix(&x->x_obj, glist) + x->x_height - ci*x->x_height/(2*SCRATCHER_NB_GROOVES)
+ );
+ }
+ canvas_fixlinesfor( canvas, (t_text*)x );
}
- canvas_fixlinesfor( canvas, (t_text*)x );
- }
}
static void scratcher_draw_select(t_scratcher* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
- if ( glist_isvisible( x->x_glist ) )
- {
- if(x->x_selected)
- {
- }
- else
+ if ( glist_isvisible( x->x_glist ) )
{
+ if(x->x_selected)
+ {
+ }
+ else
+ {
+ }
}
- }
}
/* ------------------------ widget callbacks ----------------------------- */
static void scratcher_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_scratcher* x = (t_scratcher*)z;
+ t_scratcher* x = (t_scratcher*)z;
- *xp1 = text_xpix(&x->x_obj, owner);
- *yp1 = text_ypix(&x->x_obj, owner);
- *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, owner);
+ *yp1 = text_ypix(&x->x_obj, owner);
+ *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
}
static void scratcher_save(t_gobj *z, t_binbuf *b)
{
- t_scratcher *x = (t_scratcher *)z;
+ t_scratcher *x = (t_scratcher *)z;
- binbuf_addv(b, "ssiisiiiiff", gensym("#X"),gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_size, x->x_width, x->x_height,
+ binbuf_addv(b, "ssiisiiiiff", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_size, x->x_width, x->x_height,
x->x_sensibility, x->x_maxspeed, x->x_inertia );
- binbuf_addv(b, ";");
+ binbuf_addv(b, ";");
}
static void scratcher_select(t_gobj *z, t_glist *glist, int selected)
{
- t_scratcher *x = (t_scratcher *)z;
+ t_scratcher *x = (t_scratcher *)z;
- x->x_selected = selected;
- scratcher_draw_select( x, glist );
+ x->x_selected = selected;
+ scratcher_draw_select( x, glist );
}
static void scratcher_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_scratcher *x = (t_scratcher *)z;
- t_rtext *y;
-
- if (vis)
- {
- scratcher_draw_new( x, glist );
- }
- else
- {
- scratcher_draw_delete( x, glist );
- }
+ t_scratcher *x = (t_scratcher *)z;
+ t_rtext *y;
+
+ if (vis)
+ {
+ scratcher_draw_new( x, glist );
+ }
+ else
+ {
+ scratcher_draw_delete( x, glist );
+ }
}
static void scratcher_delete(t_gobj *z, t_glist *glist)
@@ -319,7 +319,7 @@ static void scratcher_delete(t_gobj *z, t_glist *glist)
static void scratcher_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
- t_scratcher *x = (t_scratcher *)z;
+ t_scratcher *x = (t_scratcher *)z;
x->x_obj.te_xpix += dx;
x->x_obj.te_ypix += dy;
@@ -329,175 +329,185 @@ static void scratcher_displace(t_gobj *z, t_glist *glist, int dx, int dy)
static void scratcher_motion(t_scratcher *x, t_floatarg dx, t_floatarg dy)
{
- struct timeval tv;
- struct timezone tz;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- // post( "scratcher_motion dx=%f dy=%f", dx, dy );
-
- x->x_speedinc += dy / x->x_sensibility;
-
- x->x_mousemoved = 1;
- // get current time in ms
- gettimeofday( &tv, &tz );
- x->x_lastmovetime = tv.tv_sec*1000 + tv.tv_usec/1000;
- // post( "scratcher~ : move time : %ld", x->x_lastmovetime );
-
- if ( x->x_showspeed )
- {
- SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
- );
- }
+ struct timeval tv;
+ struct timezone tz;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ // post( "scratcher_motion dx=%f dy=%f", dx, dy );
+
+ x->x_speedinc += dy / x->x_sensibility;
+
+ x->x_mousemoved = 1;
+ // get current time in ms
+ gettimeofday( &tv, &tz );
+ x->x_lastmovetime = tv.tv_sec*1000 + tv.tv_usec/1000;
+ // post( "scratcher~ : move time : %ld", x->x_lastmovetime );
+
+ if ( x->x_showspeed )
+ {
+ SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
+ );
+ }
}
static void scratcher_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_scratcher *x=(t_scratcher *)z;
+ char buf[800];
+ t_scratcher *x=(t_scratcher *)z;
- sprintf(buf, "pdtk_scratcher_dialog %%s %d %d\n",
+ sprintf(buf, "pdtk_scratcher_dialog %%s %d %d\n",
x->x_width, x->x_height );
- // post("scratcher_properties : %s", buf );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ // post("scratcher_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
static void scratcher_dialog(t_scratcher *x, t_symbol *s, int argc, t_atom *argv)
{
- if ( !x ) {
- post( "scratcher : error :tried to set properties on an unexisting object" );
- }
- if ( argc != 2 )
- {
- post( "scratcher : error in the number of arguments ( %d instead of 2 )", argc );
- return;
- }
- if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT ) {
- post( "scratcher : wrong arguments" );
- return;
- }
- x->x_width = (int)argv[0].a_w.w_float;
- x->x_height = (int)argv[1].a_w.w_float;
- scratcher_draw_delete(x, x->x_glist);
- scratcher_draw_new(x, x->x_glist);
+ if ( !x )
+ {
+ post( "scratcher : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 2 )
+ {
+ post( "scratcher : error in the number of arguments ( %d instead of 2 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_FLOAT || argv[1].a_type != A_FLOAT )
+ {
+ post( "scratcher : wrong arguments" );
+ return;
+ }
+ x->x_width = (int)argv[0].a_w.w_float;
+ x->x_height = (int)argv[1].a_w.w_float;
+ scratcher_draw_delete(x, x->x_glist);
+ scratcher_draw_new(x, x->x_glist);
}
- /* reset reading speed */
+/* reset reading speed */
static void scratcher_reset(t_scratcher *x)
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- x->x_readspeed=1.;
- if ( x->x_showspeed )
- {
- SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
- );
- }
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ x->x_readspeed=1.;
+ if ( x->x_showspeed )
+ {
+ SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
+ );
+ }
}
static int scratcher_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
- t_scratcher* x = (t_scratcher *)z;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_scratcher* x = (t_scratcher *)z;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
// post( "scratcher_click : x=%d y=%d doit=%d alt=%d, shift=%d", xpix, ypix, doit, alt, shift );
if ( doit )
{
- // activate motion callback
- glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)scratcher_motion,
- 0, xpix, ypix );
- x->x_readspeed=0.;
- x->x_motioned = 1;
- if ( x->x_showspeed )
- {
- SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist)+x->x_width/2,
- text_ypix(&x->x_obj, glist)+x->x_height/2,
- text_xpix(&x->x_obj, glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
- text_ypix(&x->x_obj, glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
- );
- }
+ // activate motion callback
+ glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)scratcher_motion,
+ 0, xpix, ypix );
+ x->x_readspeed=0.;
+ x->x_motioned = 1;
+ if ( x->x_showspeed )
+ {
+ SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, glist)+x->x_width/2,
+ text_ypix(&x->x_obj, glist)+x->x_height/2,
+ text_xpix(&x->x_obj, glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
+ text_ypix(&x->x_obj, glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
+ );
+ }
}
else
{
- if ( x->x_play ) scratcher_reset(x);
- x->x_motioned = 0;
+ if ( x->x_play ) scratcher_reset(x);
+ x->x_motioned = 0;
}
return (1);
}
- /* clean up */
-static void scratcher_free(t_scratcher *x)
+/* clean up */
+static void scratcher_free(t_scratcher *x)
{
- if ( x->x_sdata != NULL ) {
- freebytes(x->x_sdata, x->x_size*sizeof(t_float) );
- post( "scratcher~ : freed %d bytes", x->x_size*sizeof(t_float) );
- x->x_sdata = NULL;
+ if ( x->x_sdata != NULL )
+ {
+ freebytes(x->x_sdata, x->x_size*sizeof(t_float) );
+ post( "scratcher~ : freed %d bytes", x->x_size*sizeof(t_float) );
+ x->x_sdata = NULL;
}
}
- /* allocate tables for storing sample data */
+/* allocate tables for storing sample data */
static t_int scratcher_allocate(t_scratcher *x)
{
- if ( !(x->x_sdata = getbytes( x->x_size*sizeof(float) ) ) ) {
- post( "scratcher~ : could not allocate %d bytes", x->x_size*sizeof(t_float) );
- return -1;
- } else {
- post( "scratcher~ : allocated %d bytes", x->x_size*sizeof(t_float) );
+ if ( !(x->x_sdata = getbytes( x->x_size*sizeof(float) ) ) )
+ {
+ post( "scratcher~ : could not allocate %d bytes", x->x_size*sizeof(t_float) );
+ return -1;
+ }
+ else
+ {
+ post( "scratcher~ : allocated %d bytes", x->x_size*sizeof(t_float) );
}
return 0;
}
- /* reallocate tables for storing sample data */
+/* reallocate tables for storing sample data */
static t_int scratcher_reallocate(t_scratcher *x, t_int ioldsize, t_int inewsize)
{
- t_float *pdata;
+ t_float *pdata;
pdata = x->x_sdata;
- if ( !(x->x_sdata = getbytes( inewsize*sizeof(float) ) ) ) {
- post( "scratcher~ : could not allocate %d bytes", inewsize*sizeof(t_float) );
- return -1;
- } else {
- post( "scratcher~ : allocated %d bytes", inewsize*sizeof(t_float) );
+ if ( !(x->x_sdata = getbytes( inewsize*sizeof(float) ) ) )
+ {
+ post( "scratcher~ : could not allocate %d bytes", inewsize*sizeof(t_float) );
+ return -1;
}
- if ( pdata != NULL ) {
- freebytes(pdata, ioldsize*sizeof(t_float) );
- post( "scratcher~ : freed %d bytes", ioldsize*sizeof(t_float) );
+ else
+ {
+ post( "scratcher~ : allocated %d bytes", inewsize*sizeof(t_float) );
+ }
+ if ( pdata != NULL )
+ {
+ freebytes(pdata, ioldsize*sizeof(t_float) );
+ post( "scratcher~ : freed %d bytes", ioldsize*sizeof(t_float) );
}
return 0;
}
- /* records or playback the scratcher */
+/* records or playback the scratcher */
static t_int *scratcher_perform(t_int *w)
{
- t_float *in = (t_float *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- t_int n = (int)(w[3]); /* number of samples */
- t_scratcher *x = (t_scratcher *)(w[4]);
- struct timeval tv;
- struct timezone tz;
- long long perftime = 0L;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_float *in = (t_float *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ t_int n = (int)(w[3]); /* number of samples */
+ t_scratcher *x = (t_scratcher *)(w[4]);
+ struct timeval tv;
+ struct timezone tz;
+ long long perftime = 0L;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
x->x_readspeed += x->x_speedinc;
if ( x->x_readspeed > x->x_maxspeed )
{
- x->x_readspeed = x->x_maxspeed;
+ x->x_readspeed = x->x_maxspeed;
}
if ( x->x_readspeed < -x->x_maxspeed )
{
- x->x_readspeed = -x->x_maxspeed;
+ x->x_readspeed = -x->x_maxspeed;
}
x->x_speedinc = 0;
@@ -505,65 +515,72 @@ static t_int *scratcher_perform(t_int *w)
if ( x->x_mousemoved )
{
- // get current time in ms
- gettimeofday( &tv, &tz );
- perftime = tv.tv_sec*1000 + tv.tv_usec/1000;
- if ( perftime - x->x_lastmovetime > SCRATCHER_MOVE_TIMEOUT )
- {
- // post( "scratcher~ : mouse timeout (m=%ld)", perftime );
- // post( "scratcher~ : (m=%ld)", x->x_lastmovetime );
- if ( x->x_readspeed > 0. )
- {
- x->x_readspeed -= x->x_inertia;
- // post( "scratcher~ : dec speed" );
- }
- if ( x->x_readspeed < 0. )
- {
- x->x_readspeed += x->x_inertia;
- // post( "scratcher~ : inc speed" );
- }
- if ( ( x->x_readspeed <= x->x_inertia && x->x_readspeed > 0 ) ||
- ( x->x_readspeed >= -x->x_inertia && x->x_readspeed < 0 ) )
- {
- x->x_mousemoved = 0;
- x->x_readspeed = 0.;
- }
- if ( x->x_showspeed )
- {
- SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
- );
- }
+ // get current time in ms
+ gettimeofday( &tv, &tz );
+ perftime = tv.tv_sec*1000 + tv.tv_usec/1000;
+ if ( perftime - x->x_lastmovetime > SCRATCHER_MOVE_TIMEOUT )
+ {
+ // post( "scratcher~ : mouse timeout (m=%ld)", perftime );
+ // post( "scratcher~ : (m=%ld)", x->x_lastmovetime );
+ if ( x->x_readspeed > 0. )
+ {
+ x->x_readspeed -= x->x_inertia;
+ // post( "scratcher~ : dec speed" );
+ }
+ if ( x->x_readspeed < 0. )
+ {
+ x->x_readspeed += x->x_inertia;
+ // post( "scratcher~ : inc speed" );
+ }
+ if ( ( x->x_readspeed <= x->x_inertia && x->x_readspeed > 0 ) ||
+ ( x->x_readspeed >= -x->x_inertia && x->x_readspeed < 0 ) )
+ {
+ x->x_mousemoved = 0;
+ x->x_readspeed = 0.;
+ }
+ if ( x->x_showspeed )
+ {
+ SYS_VGUI7( ".x%lx.c coords %xSPEEDBAR %d %d %d %d\n",
+ canvas, x,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1 )),
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1 ))
+ );
+ }
}
}
- while (n--) {
+ while (n--)
+ {
// eventually records input
- if ( x->x_record) {
- *(x->x_sdata+x->x_writepos)=*in;
- x->x_writepos++;
- if ( x->x_writepos >= x->x_size ) {
- x->x_record=0;
- x->x_writepos=0;
- if ( x->x_empty ) x->x_empty = 0;
- // post( "scratcher~ : stopped recording" );
- }
+ if ( x->x_record)
+ {
+ *(x->x_sdata+x->x_writepos)=*in;
+ x->x_writepos++;
+ if ( x->x_writepos >= x->x_size )
+ {
+ x->x_record=0;
+ x->x_writepos=0;
+ if ( x->x_empty ) x->x_empty = 0;
+ // post( "scratcher~ : stopped recording" );
+ }
}
// set outputs
- if ( x->x_play) {
+ if ( x->x_play)
+ {
*out = *(x->x_sdata+(int)x->x_readpos);
x->x_readpos+=x->x_readspeed;
if ( x->x_readpos < 0 ) x->x_readpos = x->x_size-1;
if ( x->x_readpos >= x->x_size ) x->x_readpos = 0;
- } else {
+ }
+ else
+ {
*out=0.0;
}
- in++;out++;
+ in++;
+ out++;
}
return (w+5);
@@ -571,66 +588,67 @@ static t_int *scratcher_perform(t_int *w)
static void scratcher_dsp(t_scratcher *x, t_signal **sp)
{
- dsp_add(scratcher_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x);
+ dsp_add(scratcher_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x);
}
- /* play the sound */
+/* play the sound */
static void scratcher_play(t_scratcher *x)
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- x->x_play=1;
- // reset read position
- x->x_readpos=0;
- x->x_readspeed=1.;
- if ( x->x_showspeed )
- {
- SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xSPEEDBAR -width 3\n",
- canvas, text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1. )),
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1. )),
- x );
- }
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ x->x_play=1;
+ // reset read position
+ x->x_readpos=0;
+ x->x_readspeed=1.;
+ if ( x->x_showspeed )
+ {
+ SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xSPEEDBAR -width 3\n",
+ canvas, text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1. )),
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1. )),
+ x );
+ }
}
- /* stop playing */
+/* stop playing */
static void scratcher_stop(t_scratcher *x)
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- x->x_play=0;
- // reset read position
- x->x_readpos=0;
- x->x_readspeed=0.;
- if ( x->x_showspeed )
- {
- SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xSPEEDBAR -width 3\n",
- canvas, text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1. )),
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1. )),
- x );
- }
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ x->x_play=0;
+ // reset read position
+ x->x_readpos=0;
+ x->x_readspeed=0.;
+ if ( x->x_showspeed )
+ {
+ SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xSPEEDBAR -width 3\n",
+ canvas, text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1. )),
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1. )),
+ x );
+ }
}
- /* record the sound */
+/* record the sound */
static void scratcher_record(t_scratcher *x)
{
- scratcher_stop(x);
- x->x_record=1;
- x->x_writepos=0;
+ scratcher_stop(x);
+ x->x_record=1;
+ x->x_writepos=0;
}
- /* resize sound */
+/* resize sound */
static void scratcher_resize(t_scratcher *x, t_floatarg fnewsize )
{
- t_int dspstate;
- struct timespec ts;
+ t_int dspstate;
+ struct timespec ts;
- if (fnewsize <= 0) {
+ if (fnewsize <= 0)
+ {
post( "scratcher~ : error : wrong size" );
return;
}
@@ -642,55 +660,59 @@ static void scratcher_resize(t_scratcher *x, t_floatarg fnewsize )
x->x_size = fnewsize;
}
- /* set sensibility */
+/* set sensibility */
static void scratcher_sensibility(t_scratcher *x, t_floatarg fsensibility )
{
- if (fsensibility <= 0) {
+ if (fsensibility <= 0)
+ {
post( "scratcher~ : error : wrong sensibility" );
return;
}
x->x_sensibility = fsensibility;
}
- /* set maximum speed */
+/* set maximum speed */
static void scratcher_maxspeed(t_scratcher *x, t_floatarg fmaxspeed )
{
- if (fmaxspeed < 0) {
+ if (fmaxspeed < 0)
+ {
post( "scratcher~ : error : wrong maximum speed" );
return;
}
x->x_maxspeed = fmaxspeed;
}
- /* set turntable inertia */
+/* set turntable inertia */
static void scratcher_inertia(t_scratcher *x, t_floatarg finertia )
{
- if (finertia < 0) {
+ if (finertia < 0)
+ {
post( "scratcher~ : error : wrong inertia" );
return;
}
x->x_inertia = finertia;
}
- /* toggle speed line */
+/* toggle speed line */
static void scratcher_showspeed(t_scratcher *x, t_floatarg fshowspeed )
{
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
- if (fshowspeed == 0) {
- x->x_showspeed = 0;
- SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
+ if (fshowspeed == 0)
+ {
+ x->x_showspeed = 0;
+ SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
}
else
{
- x->x_showspeed = 1;
- SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xSPEEDBAR -width 3\n",
- canvas, text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
- text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1. )),
- text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1. )),
- x );
+ x->x_showspeed = 1;
+ SYS_VGUI3( ".x%lx.c delete %xSPEEDBAR\n", canvas, x );
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xSPEEDBAR -width 3\n",
+ canvas, text_xpix(&x->x_obj, x->x_glist)+x->x_width/2,
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2,
+ text_xpix(&x->x_obj, x->x_glist)+x->x_width/2 + (int)(x->x_width/2*cos( x->x_readspeed - 1. )),
+ text_ypix(&x->x_obj, x->x_glist)+x->x_height/2 - (int)(x->x_width/2*sin( x->x_readspeed - 1. )),
+ x );
}
}
@@ -698,57 +720,58 @@ static void *scratcher_new(t_symbol *s, int argc, t_atom *argv)
{
t_scratcher *x = (t_scratcher *)pd_new(scratcher_class);
outlet_new(&x->x_obj, &s_signal);
-
+
// new scratcher created from the gui
if ( argc != 0 )
{
- if ( argc < 3 )
- {
- post( "scratcher~ : error in the number of arguments ( < 3 )", argc );
- return NULL;
- }
- if ( argv[0].a_type != A_FLOAT ||
- argv[1].a_type != A_FLOAT ||
- argv[2].a_type != A_FLOAT ) {
- post( "scratcher~ : wrong arguments" );
- return NULL;
- }
- x->x_size = argv[0].a_w.w_float;
- x->x_width = argv[1].a_w.w_float;
- x->x_height = argv[2].a_w.w_float;
- if ( argc >= 4 )
- {
- x->x_sensibility = argv[3].a_w.w_float;
- }
- else
- {
- x->x_sensibility = DEFAULT_SCRATCHER_SENSIBILITY;
- }
- if ( argc >= 5 )
- {
- x->x_maxspeed = argv[4].a_w.w_float;
- }
- else
- {
- x->x_maxspeed = DEFAULT_SCRATCHER_MAX_SPEED;
- }
- if ( argc >= 6 )
- {
- x->x_inertia = argv[5].a_w.w_float;
- }
- else
- {
- x->x_inertia = DEFAULT_TURNTABLE_INERTIA;
- }
+ if ( argc < 3 )
+ {
+ post( "scratcher~ : error in the number of arguments ( < 3 )", argc );
+ return NULL;
+ }
+ if ( argv[0].a_type != A_FLOAT ||
+ argv[1].a_type != A_FLOAT ||
+ argv[2].a_type != A_FLOAT )
+ {
+ post( "scratcher~ : wrong arguments" );
+ return NULL;
+ }
+ x->x_size = argv[0].a_w.w_float;
+ x->x_width = argv[1].a_w.w_float;
+ x->x_height = argv[2].a_w.w_float;
+ if ( argc >= 4 )
+ {
+ x->x_sensibility = argv[3].a_w.w_float;
+ }
+ else
+ {
+ x->x_sensibility = DEFAULT_SCRATCHER_SENSIBILITY;
+ }
+ if ( argc >= 5 )
+ {
+ x->x_maxspeed = argv[4].a_w.w_float;
+ }
+ else
+ {
+ x->x_maxspeed = DEFAULT_SCRATCHER_MAX_SPEED;
+ }
+ if ( argc >= 6 )
+ {
+ x->x_inertia = argv[5].a_w.w_float;
+ }
+ else
+ {
+ x->x_inertia = DEFAULT_TURNTABLE_INERTIA;
+ }
}
else
{
- x->x_size = DEFAULT_SCRATCHER_SIZE;
- x->x_width = DEFAULT_SCRATCHER_WIDTH;
- x->x_height = DEFAULT_SCRATCHER_HEIGHT;
- x->x_sensibility = DEFAULT_SCRATCHER_SENSIBILITY;
- x->x_maxspeed = DEFAULT_SCRATCHER_MAX_SPEED;
- x->x_inertia = DEFAULT_TURNTABLE_INERTIA;
+ x->x_size = DEFAULT_SCRATCHER_SIZE;
+ x->x_width = DEFAULT_SCRATCHER_WIDTH;
+ x->x_height = DEFAULT_SCRATCHER_HEIGHT;
+ x->x_sensibility = DEFAULT_SCRATCHER_SENSIBILITY;
+ x->x_maxspeed = DEFAULT_SCRATCHER_MAX_SPEED;
+ x->x_inertia = DEFAULT_TURNTABLE_INERTIA;
}
x->x_play = 0;
@@ -767,12 +790,15 @@ static void *scratcher_new(t_symbol *s, int argc, t_atom *argv)
// activate graphical callbacks
class_setwidget(scratcher_class, &scratcher_widgetbehavior);
-
+
// post( "scratcher~ : new scratcher : size = %d", x->x_size );
- if ( scratcher_allocate(x) <0 ) {
- return NULL;
- } else {
- return(x);
+ if ( scratcher_allocate(x) <0 )
+ {
+ return NULL;
+ }
+ else
+ {
+ return(x);
}
}
@@ -781,7 +807,7 @@ void scratcher_tilde_setup(void)
{
verbose(0, scratcher_version);
scratcher_class = class_new(gensym("scratcher~"), (t_newmethod)scratcher_new, (t_method)scratcher_free,
- sizeof(t_scratcher), 0, A_GIMME, 0);
+ sizeof(t_scratcher), 0, A_GIMME, 0);
// set callbacks
@@ -815,6 +841,6 @@ void scratcher_tilde_setup(void)
class_addmethod(scratcher_class, (t_method)scratcher_dialog, gensym("dialog"), A_GIMME, A_NULL);
sys_vgui("eval [read [open {%s/%s.tcl}]]\n",
- scratcher_class->c_externdir->s_name,
+ scratcher_class->c_externdir->s_name,
scratcher_class->c_name->s_name);
}
diff --git a/scrolllist.c b/scrolllist.c
index bbbbf73..e10846b 100644
--- a/scrolllist.c
+++ b/scrolllist.c
@@ -26,7 +26,7 @@
/* "I tried your cat's name, it tried your favorite band" */
/* "I have the password to your ... shell account" */
/* Barcelona - Shell Account */
-/* ---------------------------------------------------------------------------- */
+/* ---------------------------------------------------------------------------- */
#include <stdlib.h>
#include <string.h>
@@ -124,12 +124,12 @@ typedef struct _scrolllist
char *x_bgcolor; /* background color */
char *x_fgcolor; /* foreground color */
char *x_secolor; /* selection color */
-} t_scrolllist;
+} t_scrolllist;
static void scrolllist_erase(t_scrolllist *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int i;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int i;
// just in case we got confused
if ( x->x_firstseen < 0 ) x->x_firstseen=0;
@@ -144,8 +144,8 @@ static void scrolllist_erase(t_scrolllist *x, t_glist *glist)
static void scrolllist_update(t_scrolllist *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int i;
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int i;
// just in case we got confused
if ( x->x_firstseen < 0 ) x->x_firstseen=0;
@@ -154,24 +154,24 @@ static void scrolllist_update(t_scrolllist *x, t_glist *glist)
// display the content of text items
for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
{
- // display the entry if displayable
- if ( ( (i-x->x_firstseen)*x->x_charheight < x->x_height ) && ( x->x_items[i] != NULL ) )
- {
- SYS_VGUI11(".x%lx.c create text %d %d -fill %s -activefill %s -width %d -text \"%s\" -anchor w -font %s -tags %xITEM%d\n",
- canvas,
- text_xpix(&x->x_obj, glist)+5,
- text_ypix(&x->x_obj, glist)+5+(i-x->x_firstseen)*x->x_charheight,
- x->x_fgcolor,
- x->x_secolor,
- x->x_width,
- x->x_items[i],
- x->x_font,
- x, i );
+ // display the entry if displayable
+ if ( ( (i-x->x_firstseen)*x->x_charheight < x->x_height ) && ( x->x_items[i] != NULL ) )
+ {
+ SYS_VGUI11(".x%lx.c create text %d %d -fill %s -activefill %s -width %d -text \"%s\" -anchor w -font %s -tags %xITEM%d\n",
+ canvas,
+ text_xpix(&x->x_obj, glist)+5,
+ text_ypix(&x->x_obj, glist)+5+(i-x->x_firstseen)*x->x_charheight,
+ x->x_fgcolor,
+ x->x_secolor,
+ x->x_width,
+ x->x_items[i],
+ x->x_font,
+ x, i );
}
if ( ( x->x_itemselected >= x->x_firstseen ) && ( x->x_itemselected <= x->x_lastseen ) )
{
- SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n",
- canvas, x, x->x_itemselected, x->x_secolor);
+ SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n",
+ canvas, x, x->x_itemselected, x->x_secolor);
}
}
}
@@ -180,53 +180,53 @@ static void scrolllist_output_current(t_scrolllist* x)
{
if ( x->x_items && x->x_itemselected < x->x_nitems && x->x_itemselected >= 0 )
{
- outlet_symbol( x->x_item, gensym( x->x_items[x->x_itemselected] ) );
+ outlet_symbol( x->x_item, gensym( x->x_items[x->x_itemselected] ) );
}
}
static void scrolllist_draw_new(t_scrolllist *x, t_glist *glist)
-{
- t_canvas *canvas=glist_getcanvas(glist);
+{
+ t_canvas *canvas=glist_getcanvas(glist);
x->x_glist = glist;
if ( x->x_graphics )
{
- SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xTEXTLIST\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
- x->x_bgcolor, x);
+ SYS_VGUI8(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xTEXTLIST\n",
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height,
+ x->x_bgcolor, x);
}
else
{
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -outline white -fill white -tags %xTEXTLIST\n",
- canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height, x);
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -outline white -fill white -tags %xTEXTLIST\n",
+ canvas, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist) + x->x_width, text_ypix(&x->x_obj, glist) + x->x_height, x);
}
scrolllist_erase( x, glist );
scrolllist_update( x, glist );
}
static void scrolllist_draw_move(t_scrolllist *x, t_glist *glist)
-{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int i;
- struct timespec tv;
-
+{
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int i;
+ struct timespec tv;
+
tv.tv_sec = 0;
tv.tv_nsec = 10000000;
SYS_VGUI7(".x%lx.c coords %xTEXTLIST %d %d %d %d\n",
- canvas, x,
- text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
- text_xpix(&x->x_obj, glist)+x->x_width,
- text_ypix(&x->x_obj, glist)+x->x_height);
+ canvas, x,
+ text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),
+ text_xpix(&x->x_obj, glist)+x->x_width,
+ text_ypix(&x->x_obj, glist)+x->x_height);
for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
{
- // nanosleep( &tv, NULL );
- SYS_VGUI6(".x%lx.c coords %xITEM%d %d %d\n",
- canvas, x, i,
- text_xpix(&x->x_obj, glist)+5,
- text_ypix(&x->x_obj, glist)+5+(i-x->x_firstseen)*x->x_charheight);
+ // nanosleep( &tv, NULL );
+ SYS_VGUI6(".x%lx.c coords %xITEM%d %d %d\n",
+ canvas, x, i,
+ text_xpix(&x->x_obj, glist)+5,
+ text_ypix(&x->x_obj, glist)+5+(i-x->x_firstseen)*x->x_charheight);
}
canvas_fixlinesfor( canvas, (t_text*)x );
@@ -234,20 +234,20 @@ static void scrolllist_draw_move(t_scrolllist *x, t_glist *glist)
static void scrolllist_draw_erase(t_scrolllist* x, t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_int i;
-
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_int i;
+
SYS_VGUI3(".x%lx.c delete %xTEXTLIST\n", canvas, x);
for ( i=x->x_firstseen; i<=x->x_lastseen; i++ )
{
- SYS_VGUI4(".x%lx.c delete %xITEM%d\n", canvas, x, i);
+ SYS_VGUI4(".x%lx.c delete %xITEM%d\n", canvas, x, i);
}
-}
+}
static void scrolllist_draw_select(t_scrolllist* x, t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
-
+ t_canvas *canvas=glist_getcanvas(glist);
+
// post( "scrolllist : select" );
if(x->x_selected)
{
@@ -258,75 +258,75 @@ static void scrolllist_draw_select(t_scrolllist* x, t_glist* glist)
{
SYS_VGUI3(".x%lx.c itemconfigure %xTEXTLIST -outline #000000\n", canvas, x);
}
-}
+}
/* ------------------------ scrolllist widgetbehaviour----------------------------- */
static void scrolllist_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_scrolllist* x = (t_scrolllist*)z;
+ t_scrolllist* x = (t_scrolllist*)z;
- *xp1 = text_xpix(&x->x_obj, owner);
- *yp1 = text_ypix(&x->x_obj, owner);
- *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
- *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
+ *xp1 = text_xpix(&x->x_obj, owner);
+ *yp1 = text_ypix(&x->x_obj, owner);
+ *xp2 = text_xpix(&x->x_obj, owner)+x->x_width;
+ *yp2 = text_ypix(&x->x_obj, owner)+x->x_height;
}
static void scrolllist_save(t_gobj *z, t_binbuf *b)
{
- t_scrolllist *x = (t_scrolllist *)z;
-
- // post( "saving scrolllist : %d", x->x_capacity );
- binbuf_addv(b, "ssiisiiissss", gensym("#X"), gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_capacity, x->x_width, x->x_height,
- gensym(x->x_font), gensym(x->x_bgcolor),
+ t_scrolllist *x = (t_scrolllist *)z;
+
+ // post( "saving scrolllist : %d", x->x_capacity );
+ binbuf_addv(b, "ssiisiiissss", gensym("#X"), gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_capacity, x->x_width, x->x_height,
+ gensym(x->x_font), gensym(x->x_bgcolor),
gensym(x->x_fgcolor), gensym(x->x_secolor) );
- binbuf_addv(b, ";");
+ binbuf_addv(b, ";");
}
static void scrolllist_select(t_gobj *z, t_glist *glist, int selected)
{
- t_scrolllist *x = (t_scrolllist *)z;
+ t_scrolllist *x = (t_scrolllist *)z;
- x->x_selected = selected;
+ x->x_selected = selected;
- scrolllist_draw_select( x, glist );
+ scrolllist_draw_select( x, glist );
}
static void scrolllist_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_scrolllist *x = (t_scrolllist *)z;
- t_rtext *y;
-
- // post( "scrolllist : vis (%d)", vis );
- x->x_glist = glist;
- if (vis)
- {
- scrolllist_draw_erase(x, x->x_glist);
- scrolllist_draw_new( x, glist );
- }
- else
- {
- scrolllist_draw_erase( x, glist );
- }
+ t_scrolllist *x = (t_scrolllist *)z;
+ t_rtext *y;
+
+ // post( "scrolllist : vis (%d)", vis );
+ x->x_glist = glist;
+ if (vis)
+ {
+ scrolllist_draw_erase(x, x->x_glist);
+ scrolllist_draw_new( x, glist );
+ }
+ else
+ {
+ scrolllist_draw_erase( x, glist );
+ }
}
static void scrolllist_deleteobj(t_gobj *z, t_glist *glist)
{
- t_scrolllist *x = (t_scrolllist *)z;
+ t_scrolllist *x = (t_scrolllist *)z;
canvas_deletelinesfor(glist, (t_text *)z);
}
static void scrolllist_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
- t_scrolllist *x = (t_scrolllist *)z;
- t_int xold = text_xpix(&x->x_obj, glist);
- t_int yold = text_ypix(&x->x_obj, glist);
+ t_scrolllist *x = (t_scrolllist *)z;
+ t_int xold = text_xpix(&x->x_obj, glist);
+ t_int yold = text_ypix(&x->x_obj, glist);
// post( "scrolllist_displace dx=%d dy=%d", dx, dy );
@@ -334,234 +334,236 @@ static void scrolllist_displace(t_gobj *z, t_glist *glist, int dx, int dy)
x->x_obj.te_ypix += dy;
if(xold != text_xpix(&x->x_obj, glist) || yold != text_ypix(&x->x_obj, glist))
{
- scrolllist_draw_move(x, glist);
+ scrolllist_draw_move(x, glist);
}
}
static void scrolllist_motion(t_scrolllist *x, t_floatarg dx, t_floatarg dy)
{
- t_int i;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- x->x_cdy+=dy;
- scrolllist_erase( x, x->x_glist );
-
- // check if we need to scroll
- // eventually, move down
- if ( x->x_cdy >= x->x_charheight )
- {
- if ( x->x_firstseen < x->x_nitems - x->x_ndisplayed )
- {
- x->x_firstseen++;
- x->x_lastseen++;
- // post( "scrolllist : moved down first=%d last=%d", x->x_firstseen, x->x_lastseen );
- }
- }
- // eventually, move up
- if ( x->x_cdy <= -x->x_charheight )
- {
- if ( x->x_firstseen-1 >= 0 )
- {
- x->x_firstseen--;
- x->x_lastseen--;
- // post( "scrolllist : moved up first=%d last=%d", x->x_firstseen, x->x_lastseen );
- }
- }
- scrolllist_update(x, x->x_glist);
- if ( ( x->x_cdy >= x->x_charheight ) || ( x->x_cdy <= -x->x_charheight ) ) x->x_cdy = 0;
-}
-
+ t_int i;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ x->x_cdy+=dy;
+ scrolllist_erase( x, x->x_glist );
+
+ // check if we need to scroll
+ // eventually, move down
+ if ( x->x_cdy >= x->x_charheight )
+ {
+ if ( x->x_firstseen < x->x_nitems - x->x_ndisplayed )
+ {
+ x->x_firstseen++;
+ x->x_lastseen++;
+ // post( "scrolllist : moved down first=%d last=%d", x->x_firstseen, x->x_lastseen );
+ }
+ }
+ // eventually, move up
+ if ( x->x_cdy <= -x->x_charheight )
+ {
+ if ( x->x_firstseen-1 >= 0 )
+ {
+ x->x_firstseen--;
+ x->x_lastseen--;
+ // post( "scrolllist : moved up first=%d last=%d", x->x_firstseen, x->x_lastseen );
+ }
+ }
+ scrolllist_update(x, x->x_glist);
+ if ( ( x->x_cdy >= x->x_charheight ) || ( x->x_cdy <= -x->x_charheight ) ) x->x_cdy = 0;
+}
+
static void scrolllist_scroll(t_scrolllist *x, t_floatarg fdy)
{
- t_int nbsteps, si;
+ t_int nbsteps, si;
x->x_cdy += (t_int)fdy;
nbsteps = (t_int)abs(x->x_cdy/x->x_charheight);
// post( "scrolllist : iterations %d", nbsteps );
for (si=0; si<nbsteps; si++ )
{
- scrolllist_motion(x, 0, (fdy/abs(fdy))*x->x_charheight);
+ scrolllist_motion(x, 0, (fdy/abs(fdy))*x->x_charheight);
}
}
static void scrolllist_graphics(t_scrolllist *x, t_floatarg fgraphics)
{
- if ( ( (t_int)fgraphics == 0 ) || ( (t_int)fgraphics == 1 ) )
- {
- scrolllist_draw_erase(x, x->x_glist);
- x->x_graphics = (t_int) fgraphics;
- scrolllist_draw_new(x, x->x_glist);
- }
+ if ( ( (t_int)fgraphics == 0 ) || ( (t_int)fgraphics == 1 ) )
+ {
+ scrolllist_draw_erase(x, x->x_glist);
+ x->x_graphics = (t_int) fgraphics;
+ scrolllist_draw_new(x, x->x_glist);
+ }
}
static int scrolllist_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
- t_scrolllist* x = (t_scrolllist *)z;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
- t_int xoffset;
+ t_scrolllist* x = (t_scrolllist *)z;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_int xoffset;
- if (doit)
+ if (doit)
{
- // deselect previously selected item
- SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n",
- canvas, x, x->x_itemselected, x->x_fgcolor);
- x->x_itemselected = x->x_firstseen + (ypix-text_ypix(&x->x_obj, glist))/x->x_charheight;
- SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n",
- canvas, x, x->x_itemselected, x->x_secolor);
- // post( "scrolllist : selected item : %d", x->x_itemselected );
- if ( x->x_items && ( x->x_itemselected < x->x_nitems ) )
- {
- xoffset=(xpix-text_xpix(&x->x_obj, glist));
- if ( xoffset <= (t_int)( x->x_width*4/5 ) )
- {
- scrolllist_output_current(x);
- scrolllist_erase( x, x->x_glist );
- scrolllist_update( x, glist );
- }
- else
- {
- x->x_itemselected=-1;
- }
- }
- x->x_glist = glist;
- glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)scrolllist_motion,
- NULL, xpix, ypix );
+ // deselect previously selected item
+ SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n",
+ canvas, x, x->x_itemselected, x->x_fgcolor);
+ x->x_itemselected = x->x_firstseen + (ypix-text_ypix(&x->x_obj, glist))/x->x_charheight;
+ SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n",
+ canvas, x, x->x_itemselected, x->x_secolor);
+ // post( "scrolllist : selected item : %d", x->x_itemselected );
+ if ( x->x_items && ( x->x_itemselected < x->x_nitems ) )
+ {
+ xoffset=(xpix-text_xpix(&x->x_obj, glist));
+ if ( xoffset <= (t_int)( x->x_width*4/5 ) )
+ {
+ scrolllist_output_current(x);
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_update( x, glist );
+ }
+ else
+ {
+ x->x_itemselected=-1;
+ }
+ }
+ x->x_glist = glist;
+ glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)scrolllist_motion,
+ NULL, xpix, ypix );
}
return (1);
}
static void scrolllist_properties(t_gobj *z, t_glist *owner)
{
- char buf[800];
- t_scrolllist *x=(t_scrolllist *)z;
+ char buf[800];
+ t_scrolllist *x=(t_scrolllist *)z;
- sprintf(buf, "pdtk_scrolllist_dialog %%s %d %d %d %s %s %s %s\n",
- (int)x->x_capacity, (int)x->x_width, (int)x->x_height,
+ sprintf(buf, "pdtk_scrolllist_dialog %%s %d %d %d %s %s %s %s\n",
+ (int)x->x_capacity, (int)x->x_width, (int)x->x_height,
x->x_font, x->x_bgcolor,
x->x_fgcolor, x->x_secolor );
- // post("scrolllist_properties : %s", buf );
- gfxstub_new(&x->x_obj.ob_pd, x, buf);
+ // post("scrolllist_properties : %s", buf );
+ gfxstub_new(&x->x_obj.ob_pd, x, buf);
}
static void scrolllist_dialog(t_scrolllist *x, t_symbol *s, int argc, t_atom *argv)
{
- char **titems;
- t_int ncapacity, i, ccapacity;
-
- scrolllist_erase( x, x->x_glist );
- scrolllist_draw_erase(x, x->x_glist);
-
- if ( !x ) {
- post( "scrolllist : error :tried to set properties on an unexisting object" );
- }
- if ( argc != 9 )
- {
- post( "scrolllist : error in the number of arguments ( %d instead of 10 )", 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_SYMBOL ||
- argv[4].a_type != A_FLOAT || argv[5].a_type != A_SYMBOL ||
- argv[6].a_type != A_SYMBOL || argv[7].a_type != A_SYMBOL ||
- argv[8].a_type != A_SYMBOL ) {
- post( "scrolllist : wrong arguments" );
- return;
- }
-
- ncapacity = (t_int)argv[0].a_w.w_float;
- titems = (char**) malloc( ncapacity*sizeof(char*) );
-
- if ( ncapacity < x->x_nitems )
- {
- post( "scrolllist : new size is too small : texts lost !!" );
- ccapacity = ncapacity;
- }
- else
- {
- ccapacity = x->x_nitems;
- }
- for ( i=0; i<ccapacity; i++ )
- {
- if ( x->x_items[i] != NULL )
- {
- titems[i] = (char*) malloc( strlen( x->x_items[i] ) + 1 );
- memcpy( titems[i], x->x_items[i], strlen( x->x_items[i] ) );
- titems[i][strlen( x->x_items[i] )]='\0';
- free( x->x_items[i] );
- x->x_items[i] = NULL;
- }
- }
- if ( x->x_items )
- {
- free( x->x_items );
- x->x_items = NULL;
- }
- x->x_items = titems;
- x->x_nitems = ccapacity;
- x->x_capacity = ncapacity;
-
- x->x_width = (int)argv[1].a_w.w_float;
- x->x_height = (int)argv[2].a_w.w_float;
- sprintf( x->x_font, "{%s %d %s}", argv[3].a_w.w_symbol->s_name,
- (int)argv[4].a_w.w_float, argv[5].a_w.w_symbol->s_name );
- x->x_charheight = (t_int)argv[4].a_w.w_float;
- strcpy( x->x_bgcolor, argv[6].a_w.w_symbol->s_name );
- strcpy( x->x_fgcolor, argv[7].a_w.w_symbol->s_name );
- strcpy( x->x_secolor, argv[8].a_w.w_symbol->s_name );
-
- x->x_firstseen = 0;
- x->x_ndisplayed = (t_int)(x->x_height/x->x_charheight );
- if ( x->x_nitems >= x->x_ndisplayed )
- {
- x->x_lastseen = x->x_ndisplayed-1;
- }
- else
- {
- x->x_lastseen = x->x_nitems-1;
- }
-
- scrolllist_draw_new(x, x->x_glist);
- scrolllist_update(x, x->x_glist);
+ char **titems;
+ t_int ncapacity, i, ccapacity;
+
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_draw_erase(x, x->x_glist);
+
+ if ( !x )
+ {
+ post( "scrolllist : error :tried to set properties on an unexisting object" );
+ }
+ if ( argc != 9 )
+ {
+ post( "scrolllist : error in the number of arguments ( %d instead of 10 )", 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_SYMBOL ||
+ argv[4].a_type != A_FLOAT || argv[5].a_type != A_SYMBOL ||
+ argv[6].a_type != A_SYMBOL || argv[7].a_type != A_SYMBOL ||
+ argv[8].a_type != A_SYMBOL )
+ {
+ post( "scrolllist : wrong arguments" );
+ return;
+ }
+
+ ncapacity = (t_int)argv[0].a_w.w_float;
+ titems = (char**) malloc( ncapacity*sizeof(char*) );
+
+ if ( ncapacity < x->x_nitems )
+ {
+ post( "scrolllist : new size is too small : texts lost !!" );
+ ccapacity = ncapacity;
+ }
+ else
+ {
+ ccapacity = x->x_nitems;
+ }
+ for ( i=0; i<ccapacity; i++ )
+ {
+ if ( x->x_items[i] != NULL )
+ {
+ titems[i] = (char*) malloc( strlen( x->x_items[i] ) + 1 );
+ memcpy( titems[i], x->x_items[i], strlen( x->x_items[i] ) );
+ titems[i][strlen( x->x_items[i] )]='\0';
+ free( x->x_items[i] );
+ x->x_items[i] = NULL;
+ }
+ }
+ if ( x->x_items )
+ {
+ free( x->x_items );
+ x->x_items = NULL;
+ }
+ x->x_items = titems;
+ x->x_nitems = ccapacity;
+ x->x_capacity = ncapacity;
+
+ x->x_width = (int)argv[1].a_w.w_float;
+ x->x_height = (int)argv[2].a_w.w_float;
+ sprintf( x->x_font, "{%s %d %s}", argv[3].a_w.w_symbol->s_name,
+ (int)argv[4].a_w.w_float, argv[5].a_w.w_symbol->s_name );
+ x->x_charheight = (t_int)argv[4].a_w.w_float;
+ strcpy( x->x_bgcolor, argv[6].a_w.w_symbol->s_name );
+ strcpy( x->x_fgcolor, argv[7].a_w.w_symbol->s_name );
+ strcpy( x->x_secolor, argv[8].a_w.w_symbol->s_name );
+
+ x->x_firstseen = 0;
+ x->x_ndisplayed = (t_int)(x->x_height/x->x_charheight );
+ if ( x->x_nitems >= x->x_ndisplayed )
+ {
+ x->x_lastseen = x->x_ndisplayed-1;
+ }
+ else
+ {
+ x->x_lastseen = x->x_nitems-1;
+ }
+
+ scrolllist_draw_new(x, x->x_glist);
+ scrolllist_update(x, x->x_glist);
}
static void scrolllist_bgcolor(t_scrolllist *x, t_symbol *s)
{
- scrolllist_erase( x, x->x_glist );
- scrolllist_draw_erase(x, x->x_glist);
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_draw_erase(x, x->x_glist);
- strcpy( x->x_bgcolor, s->s_name );
+ strcpy( x->x_bgcolor, s->s_name );
- scrolllist_draw_new(x, x->x_glist);
- scrolllist_update(x, x->x_glist);
+ scrolllist_draw_new(x, x->x_glist);
+ scrolllist_update(x, x->x_glist);
}
static void scrolllist_fgcolor(t_scrolllist *x, t_symbol *s)
{
- scrolllist_erase( x, x->x_glist );
- scrolllist_draw_erase(x, x->x_glist);
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_draw_erase(x, x->x_glist);
- strcpy( x->x_fgcolor, s->s_name );
+ strcpy( x->x_fgcolor, s->s_name );
- scrolllist_draw_new(x, x->x_glist);
- scrolllist_update(x, x->x_glist);
+ scrolllist_draw_new(x, x->x_glist);
+ scrolllist_update(x, x->x_glist);
}
static void scrolllist_secolor(t_scrolllist *x, t_symbol *s)
{
- scrolllist_erase( x, x->x_glist );
- scrolllist_draw_erase(x, x->x_glist);
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_draw_erase(x, x->x_glist);
- strcpy( x->x_secolor, s->s_name );
+ strcpy( x->x_secolor, s->s_name );
- scrolllist_draw_new(x, x->x_glist);
- scrolllist_update(x, x->x_glist);
+ scrolllist_draw_new(x, x->x_glist);
+ scrolllist_update(x, x->x_glist);
}
static void scrolllist_sort(t_scrolllist* x)
{
- char **titems;
- t_int i, j, k, irank, indest;
+ char **titems;
+ t_int i, j, k, irank, indest;
scrolllist_erase( x, x->x_glist );
@@ -569,59 +571,59 @@ static void scrolllist_sort(t_scrolllist* x)
titems = (char**) malloc( x->x_capacity*sizeof(char*) );
for ( i=0; i<x->x_capacity; i++ )
{
- titems[i]=NULL;
+ titems[i]=NULL;
}
indest=0;
for ( i=0; i<x->x_nitems; i++ )
{
- if ( x->x_items[i] != NULL )
- {
- irank=0;
- for ( j=0; j<x->x_capacity; j++ )
+ if ( x->x_items[i] != NULL )
{
- if ( titems[j] != NULL )
- {
- // post( "scrollist : comparing >%s< to >%s<", titems[j], x->x_items[i] );
- if ( strcasecmp( titems[j], x->x_items[i] ) > 0 )
- {
- irank=j;
- break;
- }
- irank=j+1;
- }
+ irank=0;
+ for ( j=0; j<x->x_capacity; j++ )
+ {
+ if ( titems[j] != NULL )
+ {
+ // post( "scrollist : comparing >%s< to >%s<", titems[j], x->x_items[i] );
+ if ( strcasecmp( titems[j], x->x_items[i] ) > 0 )
+ {
+ irank=j;
+ break;
+ }
+ irank=j+1;
+ }
+ }
+ // insert in irank
+ // post( "scrollist : inserting %s at %d", x->x_items[i], irank );
+ for ( k=indest-1; k>=irank; k-- )
+ {
+ if ( (k+1) < x->x_capacity )
+ {
+ if ( titems[k+1] != NULL )
+ {
+ free( titems[k+1] );
+ titems[k+1] = NULL;
+ }
+ titems[k+1] = (char*) malloc( strlen( titems[k] ) + 1 );
+ memcpy( titems[k+1], titems[k], strlen( titems[k] ) );
+ titems[k+1][strlen( titems[k] )]='\0';
+ // post( "scrollist : copying %d to %d", k, k+1 );
+ }
+ }
+ titems[irank] = (char*) malloc( strlen( x->x_items[i] ) + 1 );
+ memcpy( titems[irank], x->x_items[i], strlen( x->x_items[i] ) );
+ titems[irank][strlen( x->x_items[i] )]='\0';
+ free( x->x_items[i] );
+ x->x_items[i]=NULL;
+ indest++;
}
- // insert in irank
- // post( "scrollist : inserting %s at %d", x->x_items[i], irank );
- for ( k=indest-1; k>=irank; k-- )
- {
- if ( (k+1) < x->x_capacity )
- {
- if ( titems[k+1] != NULL )
- {
- free( titems[k+1] );
- titems[k+1] = NULL;
- }
- titems[k+1] = (char*) malloc( strlen( titems[k] ) + 1 );
- memcpy( titems[k+1], titems[k], strlen( titems[k] ) );
- titems[k+1][strlen( titems[k] )]='\0';
- // post( "scrollist : copying %d to %d", k, k+1 );
- }
- }
- titems[irank] = (char*) malloc( strlen( x->x_items[i] ) + 1 );
- memcpy( titems[irank], x->x_items[i], strlen( x->x_items[i] ) );
- titems[irank][strlen( x->x_items[i] )]='\0';
- free( x->x_items[i] );
- x->x_items[i]=NULL;
- indest++;
- }
}
- if ( x->x_items )
+ if ( x->x_items )
{
- free( x->x_items );
- x->x_items = NULL;
+ free( x->x_items );
+ x->x_items = NULL;
}
x->x_items = titems;
-
+
scrolllist_update( x, x->x_glist );
}
@@ -629,8 +631,8 @@ static void scrolllist_font(t_scrolllist* x, t_symbol *fname, t_symbol *fcase, t
{
if ( (t_int)fsize <= 4 )
{
- post( "scrolllist : wrong font size in font message : %d", (t_int)fsize );
- return;
+ post( "scrolllist : wrong font size in font message : %d", (t_int)fsize );
+ return;
}
sprintf( x->x_font, "{%s %d %s}", fname->s_name, (int)fsize, fcase->s_name );
x->x_charheight = (t_int)fsize;
@@ -642,357 +644,357 @@ static void scrolllist_font(t_scrolllist* x, t_symbol *fname, t_symbol *fcase, t
static void scrolllist_add(t_scrolllist* x, t_symbol *fnewtext)
{
- t_int i;
-
- // post( "scrollist : add : nitems = %d", x->x_nitems );
- if ( x->x_nitems >= x->x_capacity )
- {
- // post( "scrolllist : warning : list is full, erasing first line" );
- for ( i=0; i<(x->x_nitems-1); i++ )
- {
- if ( x->x_items[i] != NULL )
- {
- free( x->x_items[i] );
- x->x_items[i] = NULL;
- }
- x->x_items[i] = (char*) malloc( strlen( x->x_items[i+1] ) + 1 );
- memcpy( x->x_items[i], x->x_items[i+1], strlen( x->x_items[i+1] ) );
- x->x_items[i][strlen( x->x_items[i+1] )]='\0';
- // post( "scrollist : copying %d to %d", i+1, i );
- }
- x->x_items[x->x_nitems-1] = (char*) malloc( strlen( fnewtext->s_name ) + 1 );
- memcpy( x->x_items[x->x_nitems-1], fnewtext->s_name, strlen( fnewtext->s_name ) );
- x->x_items[x->x_nitems-1][strlen( fnewtext->s_name )]='\0';
- }
- else
- {
- // post( "scrolllist : item #%d : %x", x->x_nitems, &x->x_items[x->x_nitems] );
- // post( "scrolllist : allocating : %d", strlen( fnewtext->s_name ) + 1 );
- x->x_items[x->x_nitems] = (char*) malloc( strlen( fnewtext->s_name ) + 1 );
- memcpy( x->x_items[x->x_nitems], fnewtext->s_name, strlen( fnewtext->s_name ) );
- x->x_items[x->x_nitems][strlen( fnewtext->s_name )]='\0';
- x->x_nitems++;
- if ( (x->x_nitems-x->x_firstseen)*x->x_charheight+5 < x->x_height )
- {
- x->x_lastseen = x->x_nitems-1;
- }
- }
- scrolllist_erase( x, x->x_glist );
- scrolllist_update( x, x->x_glist );
+ t_int i;
+
+ // post( "scrollist : add : nitems = %d", x->x_nitems );
+ if ( x->x_nitems >= x->x_capacity )
+ {
+ // post( "scrolllist : warning : list is full, erasing first line" );
+ for ( i=0; i<(x->x_nitems-1); i++ )
+ {
+ if ( x->x_items[i] != NULL )
+ {
+ free( x->x_items[i] );
+ x->x_items[i] = NULL;
+ }
+ x->x_items[i] = (char*) malloc( strlen( x->x_items[i+1] ) + 1 );
+ memcpy( x->x_items[i], x->x_items[i+1], strlen( x->x_items[i+1] ) );
+ x->x_items[i][strlen( x->x_items[i+1] )]='\0';
+ // post( "scrollist : copying %d to %d", i+1, i );
+ }
+ x->x_items[x->x_nitems-1] = (char*) malloc( strlen( fnewtext->s_name ) + 1 );
+ memcpy( x->x_items[x->x_nitems-1], fnewtext->s_name, strlen( fnewtext->s_name ) );
+ x->x_items[x->x_nitems-1][strlen( fnewtext->s_name )]='\0';
+ }
+ else
+ {
+ // post( "scrolllist : item #%d : %x", x->x_nitems, &x->x_items[x->x_nitems] );
+ // post( "scrolllist : allocating : %d", strlen( fnewtext->s_name ) + 1 );
+ x->x_items[x->x_nitems] = (char*) malloc( strlen( fnewtext->s_name ) + 1 );
+ memcpy( x->x_items[x->x_nitems], fnewtext->s_name, strlen( fnewtext->s_name ) );
+ x->x_items[x->x_nitems][strlen( fnewtext->s_name )]='\0';
+ x->x_nitems++;
+ if ( (x->x_nitems-x->x_firstseen)*x->x_charheight+5 < x->x_height )
+ {
+ x->x_lastseen = x->x_nitems-1;
+ }
+ }
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_update( x, x->x_glist );
}
static void scrolllist_insert(t_scrolllist* x, t_symbol *ftext, t_floatarg frank)
{
- t_int rank, i;
-
- if ( (t_int)frank > x->x_capacity )
- {
- post( "scrolllist : error : incorrect rank in insert message (%d), over capacity", (t_int)frank );
- return;
- }
- rank = (t_int)frank-1;
- if ( rank < 0 )
- {
- rank=0;
- }
- if ( rank > x->x_nitems-1 )
- {
- rank=x->x_nitems-1;
- }
- for ( i=x->x_nitems-1; i>=rank; i-- )
- {
- if ( (i+1) < x->x_capacity )
- {
- if ( x->x_items[i+1] != NULL )
- {
- free( x->x_items[i+1] );
- x->x_items[i+1] = NULL;
- }
- x->x_items[i+1] = (char*) malloc( strlen( x->x_items[i] ) + 1 );
- memcpy( x->x_items[i+1], x->x_items[i], strlen( x->x_items[i] ) );
- x->x_items[i+1][strlen( x->x_items[i] )]='\0';
- // post( "scrollist : copying %d to %d", i, i+1 );
- }
- }
- // post( "scrollist : inserting at %d", rank );
- x->x_items[rank] = (char*) malloc( strlen( ftext->s_name ) + 1 );
- memcpy( x->x_items[rank], ftext->s_name, strlen( ftext->s_name ) );
- x->x_items[rank][strlen( ftext->s_name )]='\0';
- if ( x->x_nitems < x->x_capacity ) x->x_nitems++;
- if ( (x->x_nitems-x->x_firstseen)*x->x_charheight+5 < x->x_height )
- {
- x->x_lastseen = x->x_nitems-1;
- }
- scrolllist_erase( x, x->x_glist );
- scrolllist_update( x, x->x_glist );
+ t_int rank, i;
+
+ if ( (t_int)frank > x->x_capacity )
+ {
+ post( "scrolllist : error : incorrect rank in insert message (%d), over capacity", (t_int)frank );
+ return;
+ }
+ rank = (t_int)frank-1;
+ if ( rank < 0 )
+ {
+ rank=0;
+ }
+ if ( rank > x->x_nitems-1 )
+ {
+ rank=x->x_nitems-1;
+ }
+ for ( i=x->x_nitems-1; i>=rank; i-- )
+ {
+ if ( (i+1) < x->x_capacity )
+ {
+ if ( x->x_items[i+1] != NULL )
+ {
+ free( x->x_items[i+1] );
+ x->x_items[i+1] = NULL;
+ }
+ x->x_items[i+1] = (char*) malloc( strlen( x->x_items[i] ) + 1 );
+ memcpy( x->x_items[i+1], x->x_items[i], strlen( x->x_items[i] ) );
+ x->x_items[i+1][strlen( x->x_items[i] )]='\0';
+ // post( "scrollist : copying %d to %d", i, i+1 );
+ }
+ }
+ // post( "scrollist : inserting at %d", rank );
+ x->x_items[rank] = (char*) malloc( strlen( ftext->s_name ) + 1 );
+ memcpy( x->x_items[rank], ftext->s_name, strlen( ftext->s_name ) );
+ x->x_items[rank][strlen( ftext->s_name )]='\0';
+ if ( x->x_nitems < x->x_capacity ) x->x_nitems++;
+ if ( (x->x_nitems-x->x_firstseen)*x->x_charheight+5 < x->x_height )
+ {
+ x->x_lastseen = x->x_nitems-1;
+ }
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_update( x, x->x_glist );
}
static void scrolllist_replace(t_scrolllist* x, t_symbol *ftext, t_floatarg frank)
{
- t_int rank;
-
- if ( ( (t_int)frank <= 0 ) || ( (t_int)frank > x->x_nitems ) )
- {
- post( "scrolllist : error : incorrect rank in replace message (%d), no such text", (t_int)frank );
- return;
- }
-
- rank = (t_int) frank-1;
- if ( x->x_items[rank] != NULL )
- {
- free( x->x_items[rank] );
- x->x_items[rank] = NULL;
- }
- x->x_items[rank] = (char*) malloc( strlen( ftext->s_name ) + 1 );
- memcpy( x->x_items[rank], ftext->s_name, strlen( ftext->s_name ) );
- x->x_items[rank][strlen( ftext->s_name )]='\0';
- scrolllist_erase( x, x->x_glist );
- scrolllist_update( x, x->x_glist );
+ t_int rank;
+
+ if ( ( (t_int)frank <= 0 ) || ( (t_int)frank > x->x_nitems ) )
+ {
+ post( "scrolllist : error : incorrect rank in replace message (%d), no such text", (t_int)frank );
+ return;
+ }
+
+ rank = (t_int) frank-1;
+ if ( x->x_items[rank] != NULL )
+ {
+ free( x->x_items[rank] );
+ x->x_items[rank] = NULL;
+ }
+ x->x_items[rank] = (char*) malloc( strlen( ftext->s_name ) + 1 );
+ memcpy( x->x_items[rank], ftext->s_name, strlen( ftext->s_name ) );
+ x->x_items[rank][strlen( ftext->s_name )]='\0';
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_update( x, x->x_glist );
}
static void scrolllist_delete(t_scrolllist* x, t_floatarg frank)
{
- t_int rank, i;
-
- if ( ( (t_int)frank <= 0 ) || ( (t_int)frank > x->x_nitems ) )
- {
- post( "scrolllist : error : incorrect rank in delete message (%d), no such text (%d)", (t_int)frank, x->x_nitems );
- return;
- }
-
- rank = (t_int) frank-1;
- for ( i=rank; i<x->x_nitems-1; i++ )
- {
- if ( x->x_items[i] != NULL )
- {
- free( x->x_items[i] );
- x->x_items[i] = NULL;
- }
- x->x_items[i] = (char*) malloc( strlen( x->x_items[i+1] ) + 1 );
- memcpy( x->x_items[i], x->x_items[i+1], strlen( x->x_items[i+1] ) );
- x->x_items[i][strlen( x->x_items[i+1] )]='\0';
- // post( "scrollist : copying %d to %d", i+1, i );
- }
- free( x->x_items[x->x_nitems-1] );
- x->x_items[x->x_nitems-1] = NULL;
- if ( x->x_lastseen == x->x_nitems-2 ) x->x_lastseen--;
- x->x_nitems--;
- scrolllist_erase( x, x->x_glist );
- scrolllist_update( x, x->x_glist );
+ t_int rank, i;
+
+ if ( ( (t_int)frank <= 0 ) || ( (t_int)frank > x->x_nitems ) )
+ {
+ post( "scrolllist : error : incorrect rank in delete message (%d), no such text (%d)", (t_int)frank, x->x_nitems );
+ return;
+ }
+
+ rank = (t_int) frank-1;
+ for ( i=rank; i<x->x_nitems-1; i++ )
+ {
+ if ( x->x_items[i] != NULL )
+ {
+ free( x->x_items[i] );
+ x->x_items[i] = NULL;
+ }
+ x->x_items[i] = (char*) malloc( strlen( x->x_items[i+1] ) + 1 );
+ memcpy( x->x_items[i], x->x_items[i+1], strlen( x->x_items[i+1] ) );
+ x->x_items[i][strlen( x->x_items[i+1] )]='\0';
+ // post( "scrollist : copying %d to %d", i+1, i );
+ }
+ free( x->x_items[x->x_nitems-1] );
+ x->x_items[x->x_nitems-1] = NULL;
+ if ( x->x_lastseen == x->x_nitems-2 ) x->x_lastseen--;
+ x->x_nitems--;
+ scrolllist_erase( x, x->x_glist );
+ scrolllist_update( x, x->x_glist );
}
static void scrolllist_clear(t_scrolllist* x)
{
- t_int i;
-
- scrolllist_erase( x, x->x_glist );
- for ( i=0; i<x->x_capacity; i++ )
- {
- x->x_items[i]=NULL;
- }
- x->x_nitems = 0;
- x->x_selected = 0;
- x->x_itemselected = -1;
- x->x_firstseen = 0;
- x->x_lastseen = -1;
- scrolllist_update( x, x->x_glist );
+ t_int i;
+
+ scrolllist_erase( x, x->x_glist );
+ for ( i=0; i<x->x_capacity; i++ )
+ {
+ x->x_items[i]=NULL;
+ }
+ x->x_nitems = 0;
+ x->x_selected = 0;
+ x->x_itemselected = -1;
+ x->x_firstseen = 0;
+ x->x_lastseen = -1;
+ scrolllist_update( x, x->x_glist );
}
static void scrolllist_seek(t_scrolllist *x, t_floatarg fseeked)
{
- t_int iout=0;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- if ( fseeked < 0 )
- {
- post( "scrolllist : wrong searched file : %f", fseeked );
- return;
- }
- if ( x->x_nitems == 0 ) return;
-
- iout = (t_int)fseeked % (x->x_nitems);
- SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n", canvas, x, x->x_itemselected, x->x_fgcolor);
- x->x_itemselected = iout;
- SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n", canvas, x, x->x_itemselected, x->x_secolor);
- scrolllist_output_current(x);
+ t_int iout=0;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ if ( fseeked < 0 )
+ {
+ post( "scrolllist : wrong searched file : %f", fseeked );
+ return;
+ }
+ if ( x->x_nitems == 0 ) return;
+
+ iout = (t_int)fseeked % (x->x_nitems);
+ SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n", canvas, x, x->x_itemselected, x->x_fgcolor);
+ x->x_itemselected = iout;
+ SYS_VGUI5(".x%lx.c itemconfigure %xITEM%d -fill %s\n", canvas, x, x->x_itemselected, x->x_secolor);
+ scrolllist_output_current(x);
}
static t_scrolllist *scrolllist_new(t_symbol *s, int argc, t_atom *argv )
{
- t_int i, argoffset=0;
- t_scrolllist *x;
-
- x = (t_scrolllist *)pd_new(scrolllist_class);
-
- x->x_capacity = 100;
- x->x_width = 400;
- x->x_height = 200;
- x->x_font = ( char * ) malloc( MAX_STRING_LENGTH );
- sprintf( x->x_font, "{Helvetica 10 bold}" );
- x->x_charheight = 10;
- x->x_charwidth = (2*10)/3;
- x->x_bgcolor = ( char * ) malloc( MAX_STRING_LENGTH );
- sprintf( x->x_bgcolor, "#457782" );
- x->x_fgcolor = ( char * ) malloc( MAX_STRING_LENGTH );
- sprintf( x->x_fgcolor, "black" );
- x->x_secolor = ( char * ) malloc( MAX_STRING_LENGTH );
- sprintf( x->x_secolor, "red" );
-
- if ( argc >= 1 )
- {
- if ( argv[0].a_type != A_FLOAT )
- {
- error( "scrolllist : wrong argument (capacity : 1)" );
- return NULL;
- }
- x->x_capacity = (int)argv[0].a_w.w_float;
- }
- if ( argc >= 2 )
- {
- if ( argv[1].a_type != A_FLOAT )
- {
- error( "scrolllist : wrong argument (width : 2)" );
- return NULL;
- }
- if ( (int)argv[1].a_w.w_float <= 0 )
- {
- error( "scrolllist : wrong width (%d)", (t_int)(int)argv[1].a_w.w_float );
- error( "scrolllist : usage : scrolllist <capacity> <width> <height>" );
- return NULL;
- }
- x->x_width = (int)argv[1].a_w.w_float;
- }
- if ( argc >= 3 )
- {
- if ( argv[2].a_type != A_FLOAT )
- {
- error( "scrolllist : wrong argument (height : 3)" );
- return NULL;
- }
- if ( (int)argv[2].a_w.w_float <= 0 )
- {
- error( "scrolllist : wrong height (%d)", (t_int)(int)argv[2].a_w.w_float );
- error( "scrolllist : usage : scrolllist <capacity> <width> <height>" );
- return NULL;
- }
- x->x_height = (int)argv[2].a_w.w_float;
- }
- if ( argc >= 6 )
- {
- if ( argv[3].a_type != A_SYMBOL ||
- argv[5].a_type != A_SYMBOL )
- {
- error( "scrolllist : wrong arguments (font : 4,6)" );
- error( "argument types : %d %d", argv[3].a_type, argv[5].a_type );
- return NULL;
- }
- if ( argv[4].a_type != A_SYMBOL &&
- argv[4].a_type != A_FLOAT )
- {
- error( "scrolllist : wrong arguments (font size : 5)" );
- error( "argument types : %d", argv[4].a_type );
- return NULL;
- }
- if ( argv[4].a_type == A_SYMBOL )
- {
- sprintf( x->x_font, "%s", argv[3].a_w.w_symbol->s_name );
- x->x_charheight = (t_int)atoi( strstr( argv[3].a_w.w_symbol->s_name, " ") );
- argoffset=2;
- }
- if ( argv[4].a_type == A_FLOAT )
- {
- x->x_charheight = (t_int)argv[4].a_w.w_float;
- sprintf( x->x_font, "%s %d %s", argv[3].a_w.w_symbol->s_name,
- (int)x->x_charheight, argv[5].a_w.w_symbol->s_name );
- argoffset=0;
- }
- post( "scrolllist : font : %s, size : %d", x->x_font, x->x_charheight );
- }
- if ( argc >= 7-argoffset )
- {
- if ( argv[6-argoffset].a_type != A_SYMBOL )
- {
- error( "scrolllist : wrong arguments (background color : %d)", 7-argoffset );
- return NULL;
- }
- strcpy( x->x_bgcolor, argv[6-argoffset].a_w.w_symbol->s_name );
- }
- if ( argc >= 8-argoffset )
- {
- if ( argv[7-argoffset].a_type != A_SYMBOL )
- {
- error( "scrolllist : wrong arguments (foreground color : %d)", 8-argoffset );
- return NULL;
- }
- strcpy( x->x_fgcolor, argv[7-argoffset].a_w.w_symbol->s_name );
- }
- if ( argc >= 9-argoffset )
- {
- if ( argv[8-argoffset].a_type != A_SYMBOL )
- {
- error( "scrolllist : wrong arguments (selection color : %d)", 9-argoffset );
- return NULL;
- }
- strcpy( x->x_secolor, argv[8-argoffset].a_w.w_symbol->s_name );
- }
-
- x->x_item = outlet_new(&x->x_obj, &s_symbol );
-
- x->x_glist = (t_glist *) canvas_getcurrent();
- x->x_nitems = 0;
- x->x_items = (char **) malloc( x->x_capacity*sizeof(char*) );
- for ( i=0; i<x->x_capacity; i++ )
- {
- x->x_items[i]=NULL;
- }
-
- x->x_selected = 0;
- x->x_itemselected = -1;
- x->x_firstseen = 0;
- x->x_lastseen = -1;
- x->x_ndisplayed = (t_int)(x->x_height/x->x_charheight );
-
- x->x_graphics = 1;
-
- post( "scrolllist : capacity=%d width=%d height=%d", x->x_capacity, x->x_width, x->x_height );
-
- return (x);
+ t_int i, argoffset=0;
+ t_scrolllist *x;
+
+ x = (t_scrolllist *)pd_new(scrolllist_class);
+
+ x->x_capacity = 100;
+ x->x_width = 400;
+ x->x_height = 200;
+ x->x_font = ( char * ) malloc( MAX_STRING_LENGTH );
+ sprintf( x->x_font, "{Helvetica 10 bold}" );
+ x->x_charheight = 10;
+ x->x_charwidth = (2*10)/3;
+ x->x_bgcolor = ( char * ) malloc( MAX_STRING_LENGTH );
+ sprintf( x->x_bgcolor, "#457782" );
+ x->x_fgcolor = ( char * ) malloc( MAX_STRING_LENGTH );
+ sprintf( x->x_fgcolor, "black" );
+ x->x_secolor = ( char * ) malloc( MAX_STRING_LENGTH );
+ sprintf( x->x_secolor, "red" );
+
+ if ( argc >= 1 )
+ {
+ if ( argv[0].a_type != A_FLOAT )
+ {
+ error( "scrolllist : wrong argument (capacity : 1)" );
+ return NULL;
+ }
+ x->x_capacity = (int)argv[0].a_w.w_float;
+ }
+ if ( argc >= 2 )
+ {
+ if ( argv[1].a_type != A_FLOAT )
+ {
+ error( "scrolllist : wrong argument (width : 2)" );
+ return NULL;
+ }
+ if ( (int)argv[1].a_w.w_float <= 0 )
+ {
+ error( "scrolllist : wrong width (%d)", (t_int)(int)argv[1].a_w.w_float );
+ error( "scrolllist : usage : scrolllist <capacity> <width> <height>" );
+ return NULL;
+ }
+ x->x_width = (int)argv[1].a_w.w_float;
+ }
+ if ( argc >= 3 )
+ {
+ if ( argv[2].a_type != A_FLOAT )
+ {
+ error( "scrolllist : wrong argument (height : 3)" );
+ return NULL;
+ }
+ if ( (int)argv[2].a_w.w_float <= 0 )
+ {
+ error( "scrolllist : wrong height (%d)", (t_int)(int)argv[2].a_w.w_float );
+ error( "scrolllist : usage : scrolllist <capacity> <width> <height>" );
+ return NULL;
+ }
+ x->x_height = (int)argv[2].a_w.w_float;
+ }
+ if ( argc >= 6 )
+ {
+ if ( argv[3].a_type != A_SYMBOL ||
+ argv[5].a_type != A_SYMBOL )
+ {
+ error( "scrolllist : wrong arguments (font : 4,6)" );
+ error( "argument types : %d %d", argv[3].a_type, argv[5].a_type );
+ return NULL;
+ }
+ if ( argv[4].a_type != A_SYMBOL &&
+ argv[4].a_type != A_FLOAT )
+ {
+ error( "scrolllist : wrong arguments (font size : 5)" );
+ error( "argument types : %d", argv[4].a_type );
+ return NULL;
+ }
+ if ( argv[4].a_type == A_SYMBOL )
+ {
+ sprintf( x->x_font, "%s", argv[3].a_w.w_symbol->s_name );
+ x->x_charheight = (t_int)atoi( strstr( argv[3].a_w.w_symbol->s_name, " ") );
+ argoffset=2;
+ }
+ if ( argv[4].a_type == A_FLOAT )
+ {
+ x->x_charheight = (t_int)argv[4].a_w.w_float;
+ sprintf( x->x_font, "%s %d %s", argv[3].a_w.w_symbol->s_name,
+ (int)x->x_charheight, argv[5].a_w.w_symbol->s_name );
+ argoffset=0;
+ }
+ post( "scrolllist : font : %s, size : %d", x->x_font, x->x_charheight );
+ }
+ if ( argc >= 7-argoffset )
+ {
+ if ( argv[6-argoffset].a_type != A_SYMBOL )
+ {
+ error( "scrolllist : wrong arguments (background color : %d)", 7-argoffset );
+ return NULL;
+ }
+ strcpy( x->x_bgcolor, argv[6-argoffset].a_w.w_symbol->s_name );
+ }
+ if ( argc >= 8-argoffset )
+ {
+ if ( argv[7-argoffset].a_type != A_SYMBOL )
+ {
+ error( "scrolllist : wrong arguments (foreground color : %d)", 8-argoffset );
+ return NULL;
+ }
+ strcpy( x->x_fgcolor, argv[7-argoffset].a_w.w_symbol->s_name );
+ }
+ if ( argc >= 9-argoffset )
+ {
+ if ( argv[8-argoffset].a_type != A_SYMBOL )
+ {
+ error( "scrolllist : wrong arguments (selection color : %d)", 9-argoffset );
+ return NULL;
+ }
+ strcpy( x->x_secolor, argv[8-argoffset].a_w.w_symbol->s_name );
+ }
+
+ x->x_item = outlet_new(&x->x_obj, &s_symbol );
+
+ x->x_glist = (t_glist *) canvas_getcurrent();
+ x->x_nitems = 0;
+ x->x_items = (char **) malloc( x->x_capacity*sizeof(char*) );
+ for ( i=0; i<x->x_capacity; i++ )
+ {
+ x->x_items[i]=NULL;
+ }
+
+ x->x_selected = 0;
+ x->x_itemselected = -1;
+ x->x_firstseen = 0;
+ x->x_lastseen = -1;
+ x->x_ndisplayed = (t_int)(x->x_height/x->x_charheight );
+
+ x->x_graphics = 1;
+
+ post( "scrolllist : capacity=%d width=%d height=%d", x->x_capacity, x->x_width, x->x_height );
+
+ return (x);
}
static void scrolllist_free(t_scrolllist *x)
{
- t_int i;
+ t_int i;
// post( "scrolllist : scrolllist_free" );
// free text items list
if ( x->x_nitems )
{
- for ( i=0; i<x->x_nitems; i++ )
- {
- if ( x->x_items[i] != NULL )
+ for ( i=0; i<x->x_nitems; i++ )
{
- // post( "scrolllist : freeing entry %d size=%d : %s", i, strlen( x->x_items[i] ) + 1, x->x_items[i] );
- free( x->x_items[i] );
+ if ( x->x_items[i] != NULL )
+ {
+ // post( "scrolllist : freeing entry %d size=%d : %s", i, strlen( x->x_items[i] ) + 1, x->x_items[i] );
+ free( x->x_items[i] );
+ }
}
- }
}
free( x->x_items );
if ( x->x_font )
{
- free( x->x_font );
+ free( x->x_font );
}
if ( x->x_bgcolor )
{
- free( x->x_bgcolor );
+ free( x->x_bgcolor );
}
if ( x->x_fgcolor )
{
- free( x->x_fgcolor );
+ free( x->x_fgcolor );
}
if ( x->x_secolor )
{
- free( x->x_secolor );
+ free( x->x_secolor );
}
}
@@ -1000,8 +1002,8 @@ void scrolllist_setup(void)
{
verbose(0, scrolllist_version );
scrolllist_class = class_new(gensym("scrolllist"), (t_newmethod)scrolllist_new,
- (t_method)scrolllist_free, sizeof(t_scrolllist),
- CLASS_DEFAULT, A_GIMME, 0);
+ (t_method)scrolllist_free, sizeof(t_scrolllist),
+ CLASS_DEFAULT, A_GIMME, 0);
class_addmethod(scrolllist_class, (t_method)scrolllist_seek, gensym("seek"), A_DEFFLOAT, A_NULL );
class_addmethod(scrolllist_class, (t_method)scrolllist_dialog, gensym("dialog"), A_GIMME, A_NULL );
class_addmethod(scrolllist_class, (t_method)scrolllist_sort, gensym("sort"), A_NULL );
@@ -1036,6 +1038,6 @@ void scrolllist_setup(void)
class_setwidget(scrolllist_class, &scrolllist_widgetbehavior);
sys_vgui("eval [read [open {%s/%s.tcl}]]\n",
- scrolllist_class->c_externdir->s_name,
+ scrolllist_class->c_externdir->s_name,
scrolllist_class->c_name->s_name);
}
diff --git a/sonogram~.c b/sonogram~.c
index 78df47d..90168de 100644
--- a/sonogram~.c
+++ b/sonogram~.c
@@ -37,8 +37,8 @@
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
-#ifdef __APPLE__
-#include <sys/malloc.h>
+#ifdef __APPLE__
+#include <sys/malloc.h>
#else
#include <malloc.h>
#endif
@@ -62,8 +62,8 @@
static int guidebug=0;
static int ignorevisible=1; // ignore visible test
- // because this seems to lead to bad refresh
- // wait for a fix
+// because this seems to lead to bad refresh
+// wait for a fix
#define SYS_VGUI2(a,b) if (guidebug) \
post(a,b);\
@@ -141,7 +141,7 @@ typedef struct _sonogram
t_int x_uys; /* starting y position for undo */
t_int x_uye; /* ending y position for undo */
- /* graphical data block */
+ /* graphical data block */
t_int x_enhancemode; /* flag to set enhance mode */
t_int x_graphic; /* flag to set graphic mode */
t_int x_phaso; /* flag to indicate if phasogram is shown */
@@ -151,11 +151,11 @@ typedef struct _sonogram
t_int x_nbupdated; /* number of points updated */
t_glist *x_glist; /* keep graphic context for various operations */
t_int x_zoom; /* zoom factor */
- #ifndef _WIN32
+#ifndef _WIN32
pthread_t x_updatechild; /* thread id for the update child */
- #else
- int x_updatechild;
- #endif
+#else
+ int x_updatechild;
+#endif
t_int x_updatestart; /* starting position for update */
t_int x_updateend; /* ending position for update */
t_int x_xpos; /* stuck x position */
@@ -178,136 +178,201 @@ typedef struct _sonogram
/* ------------------------ drawing functions ---------------------------- */
static char* sonogram_get_fill_color( t_float fspectrum )
{
- if ( fspectrum < 0.01 ) {
- return "#EEEEEE ";
- } else if ( fspectrum < 0.1 ) {
- return "#DDDDDD ";
- } else if ( fspectrum < 0.5 ) {
- return "#CCCCCC ";
- } else if ( fspectrum < 1 ) {
- return "#BBBBBB ";
- } else if ( fspectrum < 2 ) {
- return "#AAAAAA ";
- } else if ( fspectrum < 5 ) {
- return "#999999 ";
- } else if ( fspectrum < 10 ) {
- return "#888888 ";
- } else if ( fspectrum < 20 ) {
- return "#777777 ";
- } else if ( fspectrum < 30 ) {
- return "#666666 ";
- } else if ( fspectrum < 40 ) {
- return "#555555 ";
- } else if ( fspectrum < 50 ) {
- return "#444444 ";
- } else if ( fspectrum < 60 ) {
- return "#333333 ";
- } else if ( fspectrum < 80 ) {
- return "#222222 ";
- } else if ( fspectrum < 100 ) {
- return "#111111 ";
- } else {
- return "#000000 ";
- }
+ if ( fspectrum < 0.01 )
+ {
+ return "#EEEEEE ";
+ }
+ else if ( fspectrum < 0.1 )
+ {
+ return "#DDDDDD ";
+ }
+ else if ( fspectrum < 0.5 )
+ {
+ return "#CCCCCC ";
+ }
+ else if ( fspectrum < 1 )
+ {
+ return "#BBBBBB ";
+ }
+ else if ( fspectrum < 2 )
+ {
+ return "#AAAAAA ";
+ }
+ else if ( fspectrum < 5 )
+ {
+ return "#999999 ";
+ }
+ else if ( fspectrum < 10 )
+ {
+ return "#888888 ";
+ }
+ else if ( fspectrum < 20 )
+ {
+ return "#777777 ";
+ }
+ else if ( fspectrum < 30 )
+ {
+ return "#666666 ";
+ }
+ else if ( fspectrum < 40 )
+ {
+ return "#555555 ";
+ }
+ else if ( fspectrum < 50 )
+ {
+ return "#444444 ";
+ }
+ else if ( fspectrum < 60 )
+ {
+ return "#333333 ";
+ }
+ else if ( fspectrum < 80 )
+ {
+ return "#222222 ";
+ }
+ else if ( fspectrum < 100 )
+ {
+ return "#111111 ";
+ }
+ else
+ {
+ return "#000000 ";
+ }
}
static char* phasogram_get_fill_color( t_int phase )
{
- if ( phase < 0 )
- {
- if ( phase > -10 ) {
- return "#111111 ";
- } else if ( phase > -20 ) {
- return "#222222 ";
- } else if ( phase > -30 ) {
- return "#333333 ";
- } else if ( phase > -40 ) {
- return "#444444 ";
- } else if ( phase > -50 ) {
- return "#555555 ";
- } else if ( phase > -60 ) {
- return "#666666 ";
- } else if ( phase > -70 ) {
- return "#777777 ";
- } else if ( phase > -80 ) {
- return "#888888 ";
- } else {
- return "#999999 ";
- }
- }
- else
- {
- if ( phase == 0 ) {
- return "#FFFFFF ";
- } else if ( phase < 10 ) {
- return "#111111 ";
- } else if ( phase < 20 ) {
- return "#222222 ";
- } else if ( phase < 30 ) {
- return "#333333 ";
- } else if ( phase < 40 ) {
- return "#444444 ";
- } else if ( phase < 50 ) {
- return "#555555 ";
- } else if ( phase < 60 ) {
- return "#666666 ";
- } else if ( phase < 70 ) {
- return "#777777 ";
- } else if ( phase < 80 ) {
- return "#888888 ";
- } else {
- return "#999999 ";
- }
- }
- // normally never reached
- return "";
+ if ( phase < 0 )
+ {
+ if ( phase > -10 )
+ {
+ return "#111111 ";
+ }
+ else if ( phase > -20 )
+ {
+ return "#222222 ";
+ }
+ else if ( phase > -30 )
+ {
+ return "#333333 ";
+ }
+ else if ( phase > -40 )
+ {
+ return "#444444 ";
+ }
+ else if ( phase > -50 )
+ {
+ return "#555555 ";
+ }
+ else if ( phase > -60 )
+ {
+ return "#666666 ";
+ }
+ else if ( phase > -70 )
+ {
+ return "#777777 ";
+ }
+ else if ( phase > -80 )
+ {
+ return "#888888 ";
+ }
+ else
+ {
+ return "#999999 ";
+ }
+ }
+ else
+ {
+ if ( phase == 0 )
+ {
+ return "#FFFFFF ";
+ }
+ else if ( phase < 10 )
+ {
+ return "#111111 ";
+ }
+ else if ( phase < 20 )
+ {
+ return "#222222 ";
+ }
+ else if ( phase < 30 )
+ {
+ return "#333333 ";
+ }
+ else if ( phase < 40 )
+ {
+ return "#444444 ";
+ }
+ else if ( phase < 50 )
+ {
+ return "#555555 ";
+ }
+ else if ( phase < 60 )
+ {
+ return "#666666 ";
+ }
+ else if ( phase < 70 )
+ {
+ return "#777777 ";
+ }
+ else if ( phase < 80 )
+ {
+ return "#888888 ";
+ }
+ else
+ {
+ return "#999999 ";
+ }
+ }
+ // normally never reached
+ return "";
}
static void sonogram_update_point(t_sonogram *x, t_glist *glist, t_int sample, t_int frequency)
{
- t_canvas *canvas=glist_getcanvas(glist);
- t_float fspectrum=0.0;
- t_int phase=0.0;
- char newColor[ 8 ], olColor[8];
- int i;
-
- fspectrum =
- sqrt( pow( *(x->x_rdata+sample*x->x_blocksize+frequency), 2) +
- pow( *(x->x_idata+sample*x->x_blocksize+frequency), 2) );
- phase = (int) ( atan2( *(x->x_idata+(sample*x->x_blocksize)+frequency),
- *(x->x_rdata+(sample*x->x_blocksize)+frequency) )*180/M_PI );
- if ( x->x_empty && ( fspectrum != 0 ))
- {
- x->x_empty = 0;
- }
- strncpy( newColor, sonogram_get_fill_color( fspectrum ), 8 );
-
- for ( i=0; i<x->x_zoom; i++ )
- {
- sprintf( x->x_gifdata, "%s", newColor );
- }
- for ( i=0; i<x->x_zoom; i++ )
- {
- SYS_VGUI5("SONIMAGE%x put {%s} -to %d %d\n", x, x->x_gifdata,
+ t_canvas *canvas=glist_getcanvas(glist);
+ t_float fspectrum=0.0;
+ t_int phase=0.0;
+ char newColor[ 8 ], olColor[8];
+ int i;
+
+ fspectrum =
+ sqrt( pow( *(x->x_rdata+sample*x->x_blocksize+frequency), 2) +
+ pow( *(x->x_idata+sample*x->x_blocksize+frequency), 2) );
+ phase = (int) ( atan2( *(x->x_idata+(sample*x->x_blocksize)+frequency),
+ *(x->x_rdata+(sample*x->x_blocksize)+frequency) )*180/M_PI );
+ if ( x->x_empty && ( fspectrum != 0 ))
+ {
+ x->x_empty = 0;
+ }
+ strncpy( newColor, sonogram_get_fill_color( fspectrum ), 8 );
+
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ sprintf( x->x_gifdata, "%s", newColor );
+ }
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ SYS_VGUI5("SONIMAGE%x put {%s} -to %d %d\n", x, x->x_gifdata,
+ sample*x->x_zoom+i, (x->x_blocksize/2-frequency)*x->x_zoom );
+ }
+
+ if ( x->x_phaso )
+ {
+ strncpy( newColor, phasogram_get_fill_color( phase ), 8 );
+ strcpy( x->x_gifdata, "" );
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ sprintf( x->x_gifdata, "%s", newColor );
+ }
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ SYS_VGUI5("FAZIMAGE%x put {%s} -to %d %d\n", x, x->x_gifdata,
sample*x->x_zoom+i, (x->x_blocksize/2-frequency)*x->x_zoom );
- }
-
- if ( x->x_phaso )
- {
- strncpy( newColor, phasogram_get_fill_color( phase ), 8 );
- strcpy( x->x_gifdata, "" );
- for ( i=0; i<x->x_zoom; i++ )
- {
- sprintf( x->x_gifdata, "%s", newColor );
- }
- for ( i=0; i<x->x_zoom; i++ )
- {
- SYS_VGUI5("FAZIMAGE%x put {%s} -to %d %d\n", x, x->x_gifdata,
- sample*x->x_zoom+i, (x->x_blocksize/2-frequency)*x->x_zoom );
- }
- }
-
- x->x_nbupdated++;
+ }
+ }
+
+ x->x_nbupdated++;
}
static void sonogram_update_block(t_sonogram *x, t_glist *glist, t_int bnumber)
@@ -320,14 +385,14 @@ static void sonogram_update_block(t_sonogram *x, t_glist *glist, t_int bnumber)
// update sonogram
for ( fi=x->x_blocksize/2-1; fi>=0; fi-- )
{
- fspectrum =
- sqrt( pow( *(x->x_rdata+bnumber*x->x_blocksize+fi), 2) +
- pow( *(x->x_idata+bnumber*x->x_blocksize+fi), 2) );
- strncpy( color, sonogram_get_fill_color( fspectrum ), 8 );
- for ( i=0; i<x->x_zoom; i++ )
- {
- strncpy( x->x_gifdata+((x->x_blocksize/2-fi-1)*x->x_zoom+i)*8, color, 8 );
- }
+ fspectrum =
+ sqrt( pow( *(x->x_rdata+bnumber*x->x_blocksize+fi), 2) +
+ pow( *(x->x_idata+bnumber*x->x_blocksize+fi), 2) );
+ strncpy( color, sonogram_get_fill_color( fspectrum ), 8 );
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ strncpy( x->x_gifdata+((x->x_blocksize/2-fi-1)*x->x_zoom+i)*8, color, 8 );
+ }
}
for ( i=0; i<x->x_zoom; i++ )
{
@@ -336,24 +401,24 @@ static void sonogram_update_block(t_sonogram *x, t_glist *glist, t_int bnumber)
}
// update phasogram
- if ( x->x_phaso )
- {
- strcpy( x->x_gifdata, "" );
- for ( fi=x->x_blocksize/2-1; fi>=0; fi-- )
- {
- phase = (int) ( atan2( *(x->x_idata+bnumber*x->x_blocksize+fi),
- *(x->x_rdata+bnumber*x->x_blocksize+fi) )*180/M_PI );
- strncpy( color, phasogram_get_fill_color( phase ), 8 );
+ if ( x->x_phaso )
+ {
+ strcpy( x->x_gifdata, "" );
+ for ( fi=x->x_blocksize/2-1; fi>=0; fi-- )
+ {
+ phase = (int) ( atan2( *(x->x_idata+bnumber*x->x_blocksize+fi),
+ *(x->x_rdata+bnumber*x->x_blocksize+fi) )*180/M_PI );
+ strncpy( color, phasogram_get_fill_color( phase ), 8 );
+ for ( i=0; i<x->x_zoom; i++ )
+ {
+ strncpy( x->x_gifdata+((x->x_blocksize/2-fi-1)*x->x_zoom+i)*8, color, 8 );
+ }
+ }
for ( i=0; i<x->x_zoom; i++ )
{
- strncpy( x->x_gifdata+((x->x_blocksize/2-fi-1)*x->x_zoom+i)*8, color, 8 );
+ sprintf( x->x_guicommand, "FAZIMAGE%x put {%s} -to %d 0\n", (unsigned int)x, x->x_gifdata, (bnumber*x->x_zoom)+i );
+ sys_gui( x->x_guicommand );
}
- }
- for ( i=0; i<x->x_zoom; i++ )
- {
- sprintf( x->x_guicommand, "FAZIMAGE%x put {%s} -to %d 0\n", (unsigned int)x, x->x_gifdata, (bnumber*x->x_zoom)+i );
- sys_gui( x->x_guicommand );
- }
}
}
@@ -365,199 +430,204 @@ static void sonogram_erase_block(t_sonogram *x, t_glist *glist, t_int bnumber )
t_float fspectrum=0.0;
char fillColor[ 16 ];
- for ( fi=0; fi<x->x_blocksize/2; fi++)
- {
+ for ( fi=0; fi<x->x_blocksize/2; fi++)
+ {
{
- int i;
+ int i;
- for ( i=0; i<x->x_zoom; i++ )
- {
+ for ( i=0; i<x->x_zoom; i++ )
+ {
strncpy( x->x_gifdata+i*sizeof("#FFFFFF "), "#FFFFFF ", 8 );
- }
- SYS_VGUI5("SONIMAGE%x put {%s} -to %d %d\n", x, x->x_gifdata,
- bnumber*x->x_zoom, (x->x_blocksize/2-fi)*x->x_zoom );
+ }
+ SYS_VGUI5("SONIMAGE%x put {%s} -to %d %d\n", x, x->x_gifdata,
+ bnumber*x->x_zoom, (x->x_blocksize/2-fi)*x->x_zoom );
}
- }
+ }
}
static void *sonogram_do_update_part(void *tdata)
{
- t_sonogram *x = (t_sonogram*) tdata;
- t_int si;
- t_int nbpoints = 0;
- t_float percentage = 0, opercentage = 0;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
-
- // loose synchro
- usleep( THREAD_SLEEP_TIME );
-
- // check boundaries
- if ( x->x_updateend > x->x_size-1 ) x->x_updateend = x->x_size-1;
- if ( x->x_updatestart < 0 ) x->x_updatestart = 0;
-
- // post("sonogram~ : ok, let's go [updating %d, %d]", x->x_updatestart, x->x_updateend );
-
- if ( x->x_erase )
- {
- for ( si=x->x_updatestart; si<=x->x_updateend; si++ )
- {
- sonogram_erase_block(x, x->x_glist, si);
- nbpoints++;
- percentage = (nbpoints*100/(x->x_updateend-x->x_updatestart+1));
- if ( (percentage == (int) percentage) && ((int)percentage%5 == 0) && ( percentage != opercentage ) )
- {
- // post( "sonogram~ : erase part : %d %% completed", (int)percentage );
- opercentage = percentage;
- }
- }
- }
-
- percentage = opercentage = nbpoints = 0;
-
- if ( x->x_redraw )
- {
- for ( si=x->x_updatestart; si<=x->x_updateend; si++ )
- {
- sonogram_update_block(x, x->x_glist, si);
- nbpoints++;
- percentage = (nbpoints*100/(x->x_updateend-x->x_updatestart+1));
- if ( (percentage == (int) percentage) && ((int)percentage%5 == 0) && ( percentage != opercentage ) )
- {
- // post( "sonogram~ : update part : %d %% completed", (int)percentage );
- opercentage = percentage;
- }
- }
- }
-
- // set borders in black
- SYS_VGUI3(".x%lx.c itemconfigure %xSONOGRAM -outline #000000\n", canvas, x);
- if ( x->x_phaso )
- {
- SYS_VGUI3(".x%lx.c itemconfigure %xPHASOGRAM -outline #000000\n", canvas, x);
- }
-
- // post("sonogram~ : child thread %d ended (nb_updated=%d)", (int)x->x_updatechild, x->x_nbupdated );
- x->x_updatechild = 0;
- return NULL;
-}
+ t_sonogram *x = (t_sonogram*) tdata;
+ t_int si;
+ t_int nbpoints = 0;
+ t_float percentage = 0, opercentage = 0;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
-static void sonogram_update_part(t_sonogram *x, t_glist *glist, t_int bstart, t_int bend,
- t_int erase, t_int redraw, t_int keepframe)
-{
- pthread_attr_t update_child_attr;
- pthread_t update_child;
- t_canvas *canvas=glist_getcanvas(glist);
- if ( x->x_graphic )
- {
- if ( x->x_updatechild != 0 )
- {
- // post( "sonogram~ : error : no update is possible for now" );
- return;
- }
- x->x_updatestart = bstart;
- x->x_updateend = bend;
- if ( !keepframe )
+ // loose synchro
+ usleep( THREAD_SLEEP_TIME );
+
+ // check boundaries
+ if ( x->x_updateend > x->x_size-1 ) x->x_updateend = x->x_size-1;
+ if ( x->x_updatestart < 0 ) x->x_updatestart = 0;
+
+ // post("sonogram~ : ok, let's go [updating %d, %d]", x->x_updatestart, x->x_updateend );
+
+ if ( x->x_erase )
{
- x->x_erase = 0;
+ for ( si=x->x_updatestart; si<=x->x_updateend; si++ )
+ {
+ sonogram_erase_block(x, x->x_glist, si);
+ nbpoints++;
+ percentage = (nbpoints*100/(x->x_updateend-x->x_updatestart+1));
+ if ( (percentage == (int) percentage) && ((int)percentage%5 == 0) && ( percentage != opercentage ) )
+ {
+ // post( "sonogram~ : erase part : %d %% completed", (int)percentage );
+ opercentage = percentage;
+ }
+ }
}
- else
+
+ percentage = opercentage = nbpoints = 0;
+
+ if ( x->x_redraw )
{
- x->x_erase = erase;
- }
- x->x_redraw = redraw;
- x->x_nbupdated = 0;
- // recreate the square if needed
- if ( ( bstart == 0 ) && ( bend == x->x_size-1 ) && !keepframe )
- {
- SYS_VGUI3(".x%lx.c delete %xSONOGRAM\n", canvas, x );
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xSONOGRAM\n",
- glist_getcanvas(glist), x->x_xpos-1, x->x_ypos-1,
- x->x_xpos + x->x_size*x->x_zoom+1,
- x->x_ypos + x->x_blocksize/2*x->x_zoom+1,
- x);
- SYS_VGUI2("image delete SONIMAGE%x\n", x );
- SYS_VGUI3(".x%lx.c delete ISONIMAGE%x\n", canvas, x );
- SYS_VGUI4("image create photo SONIMAGE%x -format gif -width %d -height %d\n",
- x, x->x_size*x->x_zoom, x->x_blocksize/2*x->x_zoom );
- SYS_VGUI2("SONIMAGE%x blank\n", x);
- SYS_VGUI6(".x%lx.c create image %d %d -image SONIMAGE%x -tags ISONIMAGE%x\n",
- canvas, x->x_xpos+((x->x_size*x->x_zoom)/2),
- (x->x_ypos+((x->x_blocksize/2*x->x_zoom)/2)), x, x );
- if ( x->x_phaso )
- {
- SYS_VGUI3(".x%lx.c delete %xPHASOGRAM\n", canvas, x );
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xPHASOGRAM\n",
- canvas, x->x_xpos-1, x->x_ypos+x->x_blocksize/2*x->x_zoom+2,
- x->x_xpos + x->x_size*x->x_zoom +1,
- x->x_ypos + x->x_blocksize*x->x_zoom + 3,
- x);
- SYS_VGUI2("image delete FAZIMAGE%x\n", x );
- SYS_VGUI3(".x%lx.c delete IFAZIMAGE%x\n", canvas, x );
- SYS_VGUI4("image create photo FAZIMAGE%x -format gif -width %d -height %d\n",
- x, x->x_size*x->x_zoom, x->x_blocksize/2*x->x_zoom );
- SYS_VGUI2("FAZIMAGE%x blank\n", x);
- SYS_VGUI6(".x%lx.c create image %d %d -image FAZIMAGE%x -tags IFAZIMAGE%x\n",
- canvas, x->x_xpos+((x->x_size*x->x_zoom)/2),
- x->x_ypos+3*((x->x_blocksize/2*x->x_zoom)/2)+2, x, x );
- }
- canvas_fixlinesfor( canvas, (t_text*)x );
+ for ( si=x->x_updatestart; si<=x->x_updateend; si++ )
+ {
+ sonogram_update_block(x, x->x_glist, si);
+ nbpoints++;
+ percentage = (nbpoints*100/(x->x_updateend-x->x_updatestart+1));
+ if ( (percentage == (int) percentage) && ((int)percentage%5 == 0) && ( percentage != opercentage ) )
+ {
+ // post( "sonogram~ : update part : %d %% completed", (int)percentage );
+ opercentage = percentage;
+ }
+ }
}
- // set borders in red
- SYS_VGUI3(".x%lx.c itemconfigure %xSONOGRAM -outline #FF0000\n", canvas, x);
+
+ // set borders in black
+ SYS_VGUI3(".x%lx.c itemconfigure %xSONOGRAM -outline #000000\n", canvas, x);
if ( x->x_phaso )
{
- SYS_VGUI3(".x%lx.c itemconfigure %xPHASOGRAM -outline #FF0000\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xPHASOGRAM -outline #000000\n", canvas, x);
}
- // launch update thread
- if ( pthread_attr_init( &update_child_attr ) < 0 ) {
- post( "sonogram~ : could not launch update thread" );
- perror( "pthread_attr_init" );
- return;
- }
- if ( pthread_attr_setdetachstate( &update_child_attr, PTHREAD_CREATE_DETACHED ) < 0 ) {
- post( "sonogram~ : could not launch update thread" );
- perror( "pthread_attr_setdetachstate" );
- return;
- }
- if ( pthread_create( &x->x_updatechild, &update_child_attr, sonogram_do_update_part, x ) < 0 ) {
- post( "sonogram~ : could not launch update thread" );
- perror( "pthread_create" );
- return;
- }
- else
+ // post("sonogram~ : child thread %d ended (nb_updated=%d)", (int)x->x_updatechild, x->x_nbupdated );
+ x->x_updatechild = 0;
+ return NULL;
+}
+
+static void sonogram_update_part(t_sonogram *x, t_glist *glist, t_int bstart, t_int bend,
+ t_int erase, t_int redraw, t_int keepframe)
+{
+ pthread_attr_t update_child_attr;
+ pthread_t update_child;
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ if ( x->x_graphic )
{
- // post( "sonogram~ : drawing thread %d launched", (int)x->x_updatechild );
+ if ( x->x_updatechild != 0 )
+ {
+ // post( "sonogram~ : error : no update is possible for now" );
+ return;
+ }
+ x->x_updatestart = bstart;
+ x->x_updateend = bend;
+ if ( !keepframe )
+ {
+ x->x_erase = 0;
+ }
+ else
+ {
+ x->x_erase = erase;
+ }
+ x->x_redraw = redraw;
+ x->x_nbupdated = 0;
+ // recreate the square if needed
+ if ( ( bstart == 0 ) && ( bend == x->x_size-1 ) && !keepframe )
+ {
+ SYS_VGUI3(".x%lx.c delete %xSONOGRAM\n", canvas, x );
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xSONOGRAM\n",
+ glist_getcanvas(glist), x->x_xpos-1, x->x_ypos-1,
+ x->x_xpos + x->x_size*x->x_zoom+1,
+ x->x_ypos + x->x_blocksize/2*x->x_zoom+1,
+ x);
+ SYS_VGUI2("image delete SONIMAGE%x\n", x );
+ SYS_VGUI3(".x%lx.c delete ISONIMAGE%x\n", canvas, x );
+ SYS_VGUI4("image create photo SONIMAGE%x -format gif -width %d -height %d\n",
+ x, x->x_size*x->x_zoom, x->x_blocksize/2*x->x_zoom );
+ SYS_VGUI2("SONIMAGE%x blank\n", x);
+ SYS_VGUI6(".x%lx.c create image %d %d -image SONIMAGE%x -tags ISONIMAGE%x\n",
+ canvas, x->x_xpos+((x->x_size*x->x_zoom)/2),
+ (x->x_ypos+((x->x_blocksize/2*x->x_zoom)/2)), x, x );
+ if ( x->x_phaso )
+ {
+ SYS_VGUI3(".x%lx.c delete %xPHASOGRAM\n", canvas, x );
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xPHASOGRAM\n",
+ canvas, x->x_xpos-1, x->x_ypos+x->x_blocksize/2*x->x_zoom+2,
+ x->x_xpos + x->x_size*x->x_zoom +1,
+ x->x_ypos + x->x_blocksize*x->x_zoom + 3,
+ x);
+ SYS_VGUI2("image delete FAZIMAGE%x\n", x );
+ SYS_VGUI3(".x%lx.c delete IFAZIMAGE%x\n", canvas, x );
+ SYS_VGUI4("image create photo FAZIMAGE%x -format gif -width %d -height %d\n",
+ x, x->x_size*x->x_zoom, x->x_blocksize/2*x->x_zoom );
+ SYS_VGUI2("FAZIMAGE%x blank\n", x);
+ SYS_VGUI6(".x%lx.c create image %d %d -image FAZIMAGE%x -tags IFAZIMAGE%x\n",
+ canvas, x->x_xpos+((x->x_size*x->x_zoom)/2),
+ x->x_ypos+3*((x->x_blocksize/2*x->x_zoom)/2)+2, x, x );
+ }
+ canvas_fixlinesfor( canvas, (t_text*)x );
+ }
+ // set borders in red
+ SYS_VGUI3(".x%lx.c itemconfigure %xSONOGRAM -outline #FF0000\n", canvas, x);
+ if ( x->x_phaso )
+ {
+ SYS_VGUI3(".x%lx.c itemconfigure %xPHASOGRAM -outline #FF0000\n", canvas, x);
+ }
+
+ // launch update thread
+ if ( pthread_attr_init( &update_child_attr ) < 0 )
+ {
+ post( "sonogram~ : could not launch update thread" );
+ perror( "pthread_attr_init" );
+ return;
+ }
+ if ( pthread_attr_setdetachstate( &update_child_attr, PTHREAD_CREATE_DETACHED ) < 0 )
+ {
+ post( "sonogram~ : could not launch update thread" );
+ perror( "pthread_attr_setdetachstate" );
+ return;
+ }
+ if ( pthread_create( &x->x_updatechild, &update_child_attr, sonogram_do_update_part, x ) < 0 )
+ {
+ post( "sonogram~ : could not launch update thread" );
+ perror( "pthread_create" );
+ return;
+ }
+ else
+ {
+ // post( "sonogram~ : drawing thread %d launched", (int)x->x_updatechild );
+ }
}
- }
}
- /* paste selection at the drawing point */
+/* paste selection at the drawing point */
static void sonogram_paste( t_sonogram* x)
{
- t_int pxstart = (x->x_xdraw-x->x_xpos)/x->x_zoom;
- t_int pystart = (x->x_ypos-x->x_ydraw)/x->x_zoom+x->x_blocksize/2;
+ t_int pxstart = (x->x_xdraw-x->x_xpos)/x->x_zoom;
+ t_int pystart = (x->x_ypos-x->x_ydraw)/x->x_zoom+x->x_blocksize/2;
t_int cxs,cxe,cys,cye,si=0,fi=0;
t_float *icopy;
t_float *rcopy;
t_int copynd;
- if ( x->x_xstartcapture > x->x_xendcapture ) {
- fi = x->x_xstartcapture;
- x->x_xstartcapture = x->x_xendcapture;
- x->x_xendcapture = fi;
- }
- if ( x->x_ystartcapture > x->x_yendcapture ) {
- fi = x->x_ystartcapture;
- x->x_ystartcapture = x->x_yendcapture;
- x->x_yendcapture = fi;
+ if ( x->x_xstartcapture > x->x_xendcapture )
+ {
+ fi = x->x_xstartcapture;
+ x->x_xstartcapture = x->x_xendcapture;
+ x->x_xendcapture = fi;
}
- cxs=(x->x_xstartcapture-x->x_xpos)/x->x_zoom;
- cxe=(x->x_xendcapture-x->x_xpos)/x->x_zoom;
- cys=(x->x_ypos-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
- cye=(x->x_ypos-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2;
+ if ( x->x_ystartcapture > x->x_yendcapture )
+ {
+ fi = x->x_ystartcapture;
+ x->x_ystartcapture = x->x_yendcapture;
+ x->x_yendcapture = fi;
+ }
+ cxs=(x->x_xstartcapture-x->x_xpos)/x->x_zoom;
+ cxe=(x->x_xendcapture-x->x_xpos)/x->x_zoom;
+ cys=(x->x_ypos-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
+ cye=(x->x_ypos-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2;
if ( cye < 0 ) cye=0;
if ( cys < 0 ) cys=0;
if ( cye >= x->x_blocksize/2 ) cye=x->x_blocksize/2-1;
@@ -570,81 +640,87 @@ static void sonogram_paste( t_sonogram* x)
rcopy = ( t_float* ) getbytes( ( cxe-cxs+1 )*( cye-cys+1 )*sizeof( t_float ) );
if ( !icopy || !rcopy )
{
- post( "sonogram~ : cannot allocate buffers for pasting" );
- return;
+ post( "sonogram~ : cannot allocate buffers for pasting" );
+ return;
}
// copy initial data
copynd = 0;
- for ( si=cxs; si<=cxe; si++) {
- for ( fi=cys; fi<=cye; fi++) {
- *(rcopy+copynd) = *(x->x_rdata+(si)*x->x_blocksize+fi);
- *(icopy+copynd) = *(x->x_idata+(si)*x->x_blocksize+fi);
- copynd++;
- }
+ for ( si=cxs; si<=cxe; si++)
+ {
+ for ( fi=cys; fi<=cye; fi++)
+ {
+ *(rcopy+copynd) = *(x->x_rdata+(si)*x->x_blocksize+fi);
+ *(icopy+copynd) = *(x->x_idata+(si)*x->x_blocksize+fi);
+ copynd++;
+ }
}
post( "sonogram~ : paste from [%d,%d,%d,%d] to [%d,%d]", cxs, cys, cxe, cye, pxstart, pystart );
- for ( si=cxs; si<=cxe; si++) {
- if ( pxstart+si-cxs >= x->x_size ) break;
- copynd = (si-cxs)*(cye-cys+1);
- for ( fi=cys; fi<=cye; fi++) {
- // post ( "sonogram~ : si : %d : fi : %d : copynd : %d", si, fi, copynd );
- if ( pystart+fi-cys >= x->x_blocksize/2 ) break;
- *(x->x_rudata+((si-cxs)*x->x_blocksize)+(fi-cys)) = *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys));
- *(x->x_iudata+((si-cxs)*x->x_blocksize)+(fi-cys)) = *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys));
- if ( x->x_enhancemode )
- {
- // save data for undo
- *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) += *(rcopy+copynd);
- *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) += *(icopy+copynd);
- }
- else
- {
- *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) = *(rcopy+copynd);
- *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) = *(icopy+copynd);
- }
- copynd++;
- }
- }
-
- x->x_uxs = pxstart;
- x->x_uxe = pxstart+(si-1)-cxs;
- x->x_uys = pystart;
- x->x_uye = pystart+(fi-1)-cys;;
+ for ( si=cxs; si<=cxe; si++)
+ {
+ if ( pxstart+si-cxs >= x->x_size ) break;
+ copynd = (si-cxs)*(cye-cys+1);
+ for ( fi=cys; fi<=cye; fi++)
+ {
+ // post ( "sonogram~ : si : %d : fi : %d : copynd : %d", si, fi, copynd );
+ if ( pystart+fi-cys >= x->x_blocksize/2 ) break;
+ *(x->x_rudata+((si-cxs)*x->x_blocksize)+(fi-cys)) = *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys));
+ *(x->x_iudata+((si-cxs)*x->x_blocksize)+(fi-cys)) = *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys));
+ if ( x->x_enhancemode )
+ {
+ // save data for undo
+ *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) += *(rcopy+copynd);
+ *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) += *(icopy+copynd);
+ }
+ else
+ {
+ *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) = *(rcopy+copynd);
+ *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) = *(icopy+copynd);
+ }
+ copynd++;
+ }
+ }
+
+ x->x_uxs = pxstart;
+ x->x_uxe = pxstart+(si-1)-cxs;
+ x->x_uys = pystart;
+ x->x_uye = pystart+(fi-1)-cys;;
freebytes( rcopy, ( cxe-cxs+1 )*( cye-cys+1 )*sizeof( t_float ) );
freebytes( icopy, ( cxe-cxs+1 )*( cye-cys+1 )*sizeof( t_float ) );
}
- /* paste phase at the drawing point */
+/* paste phase at the drawing point */
static void sonogram_paste_phase( t_sonogram* x)
{
- t_int pxstart = (x->x_xdraw-x->x_xpos)/x->x_zoom;
- t_int pystart = (x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_ydraw)/x->x_zoom+x->x_blocksize/2;
- t_int cxs,cxe,cys,cye,si,fi;
- t_float fspectrum, fdestspectrum;
- t_float fphase, fdestphase;
- t_float *icopy;
- t_float *rcopy;
- t_int copynd;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
-
- if ( x->x_xstartcapture > x->x_xendcapture ) {
- fi = x->x_xstartcapture;
- x->x_xstartcapture = x->x_xendcapture;
- x->x_xendcapture = fi;
- }
- if ( x->x_ystartcapture > x->x_yendcapture ) {
- fi = x->x_ystartcapture;
- x->x_ystartcapture = x->x_yendcapture;
- x->x_yendcapture = fi;
- }
- cxs=(x->x_xstartcapture-x->x_xpos)/x->x_zoom;
- cxe=(x->x_xendcapture-x->x_xpos)/x->x_zoom;
- cys=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
- cye=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2;
+ t_int pxstart = (x->x_xdraw-x->x_xpos)/x->x_zoom;
+ t_int pystart = (x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_ydraw)/x->x_zoom+x->x_blocksize/2;
+ t_int cxs,cxe,cys,cye,si,fi;
+ t_float fspectrum, fdestspectrum;
+ t_float fphase, fdestphase;
+ t_float *icopy;
+ t_float *rcopy;
+ t_int copynd;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+
+ if ( x->x_xstartcapture > x->x_xendcapture )
+ {
+ fi = x->x_xstartcapture;
+ x->x_xstartcapture = x->x_xendcapture;
+ x->x_xendcapture = fi;
+ }
+ if ( x->x_ystartcapture > x->x_yendcapture )
+ {
+ fi = x->x_ystartcapture;
+ x->x_ystartcapture = x->x_yendcapture;
+ x->x_yendcapture = fi;
+ }
+ cxs=(x->x_xstartcapture-x->x_xpos)/x->x_zoom;
+ cxe=(x->x_xendcapture-x->x_xpos)/x->x_zoom;
+ cys=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
+ cye=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2;
if ( cye < 0 ) cye=0;
if ( cys < 0 ) cys=0;
if ( cye >= x->x_blocksize/2 ) cye=x->x_blocksize/2-1;
@@ -657,48 +733,52 @@ static void sonogram_paste_phase( t_sonogram* x)
rcopy = ( t_float* ) getbytes( ( cxe-cxs+1 )*( cye-cys+1 )*sizeof( t_float ) );
if ( !icopy || !rcopy )
{
- post( "sonogram~ : cannot allocate buffers for pasting" );
- return;
+ post( "sonogram~ : cannot allocate buffers for pasting" );
+ return;
}
// copy initial data
copynd = 0;
- for ( si=cxs; si<=cxe; si++) {
- for ( fi=cys; fi<=cye; fi++) {
- *(rcopy+copynd) = *(x->x_rdata+(si)*x->x_blocksize+fi);
- *(icopy+copynd) = *(x->x_idata+(si)*x->x_blocksize+fi);
- copynd++;
- }
+ for ( si=cxs; si<=cxe; si++)
+ {
+ for ( fi=cys; fi<=cye; fi++)
+ {
+ *(rcopy+copynd) = *(x->x_rdata+(si)*x->x_blocksize+fi);
+ *(icopy+copynd) = *(x->x_idata+(si)*x->x_blocksize+fi);
+ copynd++;
+ }
}
post( "sonogram~ : paste phase from [%d,%d,%d,%d] to [%d,%d]", cxs, cys, cxe, cye, pxstart, pystart );
- for ( si=cxs; si<=cxe; si++) {
- if ( pxstart+si-cxs >= x->x_size ) break;
- copynd = (si-cxs)*(cye-cys+1);
- for ( fi=cys; fi<=cye; fi++) {
- if ( pystart+fi-cys > x->x_blocksize+1 ) break;
- fphase = atan2( *(icopy+copynd), *(rcopy+copynd) );
- fdestspectrum =
+ for ( si=cxs; si<=cxe; si++)
+ {
+ if ( pxstart+si-cxs >= x->x_size ) break;
+ copynd = (si-cxs)*(cye-cys+1);
+ for ( fi=cys; fi<=cye; fi++)
+ {
+ if ( pystart+fi-cys > x->x_blocksize+1 ) break;
+ fphase = atan2( *(icopy+copynd), *(rcopy+copynd) );
+ fdestspectrum =
sqrt( pow( *(x->x_rdata+(pxstart+si-cxs)*x->x_blocksize+(pystart+fi-cys)), 2) +
- pow( *(x->x_idata+(pxstart+si-cxs)*x->x_blocksize+(pystart+fi-cys)), 2) );
- fdestphase = atan2( *(x->x_idata+(pxstart+si-cxs)*x->x_blocksize+(pystart+fi-cys)),
- *(x->x_rdata+(pxstart+si-cxs)*x->x_blocksize+(pystart+fi-cys)) );
- if ( x->x_enhancemode )
- {
- *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) +=
- fdestspectrum*cos( fdestphase + fphase );
- *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) +=
- fdestspectrum*sin( fdestphase + fphase );
- }
- else
- {
- *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) =
- fdestspectrum*cos( fphase );
- *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) =
- fdestspectrum*sin( fphase );
- }
- copynd++;
- }
+ pow( *(x->x_idata+(pxstart+si-cxs)*x->x_blocksize+(pystart+fi-cys)), 2) );
+ fdestphase = atan2( *(x->x_idata+(pxstart+si-cxs)*x->x_blocksize+(pystart+fi-cys)),
+ *(x->x_rdata+(pxstart+si-cxs)*x->x_blocksize+(pystart+fi-cys)) );
+ if ( x->x_enhancemode )
+ {
+ *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) +=
+ fdestspectrum*cos( fdestphase + fphase );
+ *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) +=
+ fdestspectrum*sin( fdestphase + fphase );
+ }
+ else
+ {
+ *(x->x_rdata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) =
+ fdestspectrum*cos( fphase );
+ *(x->x_idata+((pxstart+si-cxs)*x->x_blocksize)+(pystart+fi-cys)) =
+ fdestspectrum*sin( fphase );
+ }
+ copynd++;
+ }
}
freebytes( rcopy, ( cxe-cxs+1 )*( cye-cys+1 )*sizeof( t_float ) );
@@ -707,185 +787,185 @@ static void sonogram_paste_phase( t_sonogram* x)
sonogram_update_part(x, x->x_glist, pxstart, pxstart+(si-1)-cxs, 0, 1, 1);
// start a new capture
SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
- x->x_xstartcapture = x->x_xdraw;
- x->x_ystartcapture = x->x_ydraw;
- x->x_xendcapture = x->x_xdraw;
- x->x_yendcapture = x->x_ydraw;
-
+ x->x_xstartcapture = x->x_xdraw;
+ x->x_ystartcapture = x->x_ydraw;
+ x->x_xendcapture = x->x_xdraw;
+ x->x_yendcapture = x->x_ydraw;
+
}
static void sonogram_draw_new(t_sonogram *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
-
- x->x_xpos=text_xpix(&x->x_obj, glist);
- x->x_ypos=text_ypix(&x->x_obj, glist);
- if ( x->x_graphic )
- {
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xSONOGRAM\n",
- canvas, x->x_xpos-1, x->x_ypos-1,
- x->x_xpos + x->x_size*x->x_zoom+1,
- x->x_ypos + x->x_blocksize/2*x->x_zoom+1,
- x);
- SYS_VGUI4("image create photo SONIMAGE%x -format gif -width %d -height %d\n",
- x, x->x_size*x->x_zoom, x->x_blocksize/2*x->x_zoom );
- SYS_VGUI2("SONIMAGE%x blank\n", x);
- SYS_VGUI6(".x%lx.c create image %d %d -image SONIMAGE%x -tags ISONIMAGE%x\n",
- canvas, x->x_xpos+((x->x_size*x->x_zoom)/2),
- (x->x_ypos+((x->x_blocksize/2*x->x_zoom)/2)), x, x );
- if ( x->x_phaso )
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ x->x_xpos=text_xpix(&x->x_obj, glist);
+ x->x_ypos=text_ypix(&x->x_obj, glist);
+ if ( x->x_graphic )
{
- SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xPHASOGRAM\n",
- canvas, x->x_xpos-1, x->x_ypos+x->x_blocksize/2*x->x_zoom+2,
- x->x_xpos + x->x_size*x->x_zoom +1,
- x->x_ypos + x->x_blocksize*x->x_zoom + 3,
- x);
- SYS_VGUI4("image create photo FAZIMAGE%x -format gif -width %d -height %d\n",
- x, x->x_size*x->x_zoom, x->x_blocksize/2*x->x_zoom );
- SYS_VGUI2("FAZIMAGE%x blank\n", x);
- SYS_VGUI6(".x%lx.c create image %d %d -image FAZIMAGE%x -tags IFAZIMAGE%x\n",
- canvas, x->x_xpos+((x->x_size*x->x_zoom)/2),
- x->x_ypos+3*((x->x_blocksize/2*x->x_zoom)/2)+2, x, x );
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xSONOGRAM\n",
+ canvas, x->x_xpos-1, x->x_ypos-1,
+ x->x_xpos + x->x_size*x->x_zoom+1,
+ x->x_ypos + x->x_blocksize/2*x->x_zoom+1,
+ x);
+ SYS_VGUI4("image create photo SONIMAGE%x -format gif -width %d -height %d\n",
+ x, x->x_size*x->x_zoom, x->x_blocksize/2*x->x_zoom );
+ SYS_VGUI2("SONIMAGE%x blank\n", x);
+ SYS_VGUI6(".x%lx.c create image %d %d -image SONIMAGE%x -tags ISONIMAGE%x\n",
+ canvas, x->x_xpos+((x->x_size*x->x_zoom)/2),
+ (x->x_ypos+((x->x_blocksize/2*x->x_zoom)/2)), x, x );
+ if ( x->x_phaso )
+ {
+ SYS_VGUI7(".x%lx.c create rectangle %d %d %d %d -fill #FFFFFF -tags %xPHASOGRAM\n",
+ canvas, x->x_xpos-1, x->x_ypos+x->x_blocksize/2*x->x_zoom+2,
+ x->x_xpos + x->x_size*x->x_zoom +1,
+ x->x_ypos + x->x_blocksize*x->x_zoom + 3,
+ x);
+ SYS_VGUI4("image create photo FAZIMAGE%x -format gif -width %d -height %d\n",
+ x, x->x_size*x->x_zoom, x->x_blocksize/2*x->x_zoom );
+ SYS_VGUI2("FAZIMAGE%x blank\n", x);
+ SYS_VGUI6(".x%lx.c create image %d %d -image FAZIMAGE%x -tags IFAZIMAGE%x\n",
+ canvas, x->x_xpos+((x->x_size*x->x_zoom)/2),
+ x->x_ypos+3*((x->x_blocksize/2*x->x_zoom)/2)+2, x, x );
+ }
+ canvas_fixlinesfor( canvas, (t_text*)x );
}
- canvas_fixlinesfor( canvas, (t_text*)x );
- }
}
static void sonogram_draw_delete(t_sonogram *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
if ( x->x_graphic && glist_isvisible( glist ) )
{
- SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
- SYS_VGUI3( ".x%lx.c delete line %xREADSTART\n", canvas, x);
- SYS_VGUI3( ".x%lx.c delete line %xREADEND\n", canvas, x);
- SYS_VGUI3( ".x%lx.c delete line %xMODSTART\n", canvas, x);
- SYS_VGUI3( ".x%lx.c delete line %xMODEND\n", canvas, x);
- SYS_VGUI3(".x%lx.c delete %xSONOGRAM\n", canvas, x );
- SYS_VGUI3(".x%lx.c delete %xPHASOGRAM\n", canvas, x );
- SYS_VGUI3(".x%lx.c delete %xISONIMAGE\n", canvas, x );
- SYS_VGUI2("image delete SONIMAGE%x\n", x );
- if ( x->x_phaso )
- {
- SYS_VGUI3(".x%lx.c delete %xIFAZIMAGE\n", canvas, x );
- SYS_VGUI2("image delete FAZIMAGE%x\n", x );
- }
+ SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
+ SYS_VGUI3( ".x%lx.c delete line %xREADSTART\n", canvas, x);
+ SYS_VGUI3( ".x%lx.c delete line %xREADEND\n", canvas, x);
+ SYS_VGUI3( ".x%lx.c delete line %xMODSTART\n", canvas, x);
+ SYS_VGUI3( ".x%lx.c delete line %xMODEND\n", canvas, x);
+ SYS_VGUI3(".x%lx.c delete %xSONOGRAM\n", canvas, x );
+ SYS_VGUI3(".x%lx.c delete %xPHASOGRAM\n", canvas, x );
+ SYS_VGUI3(".x%lx.c delete %xISONIMAGE\n", canvas, x );
+ SYS_VGUI2("image delete SONIMAGE%x\n", x );
+ if ( x->x_phaso )
+ {
+ SYS_VGUI3(".x%lx.c delete %xIFAZIMAGE\n", canvas, x );
+ SYS_VGUI2("image delete FAZIMAGE%x\n", x );
+ }
}
}
static void sonogram_draw_move(t_sonogram *x, t_glist *glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
-
- if ( x->x_graphic && glist_isvisible( x->x_glist ) )
- {
- SYS_VGUI7(".x%lx.c coords %xSONOGRAM %d %d %d %d\n",
- canvas, x,
- x->x_xpos-1, x->x_ypos-1,
- x->x_xpos+x->x_size*x->x_zoom+1,
- x->x_ypos+x->x_blocksize/2*x->x_zoom+1);
- SYS_VGUI5(".x%lx.c coords ISONIMAGE%x %d %d\n",
- canvas, x,
- x->x_xpos+((x->x_size*x->x_zoom)/2),
- (x->x_ypos+((x->x_blocksize/2*x->x_zoom)/2)) );
- if ( x->x_phaso )
+ t_canvas *canvas=glist_getcanvas(glist);
+
+ if ( x->x_graphic && glist_isvisible( x->x_glist ) )
{
- SYS_VGUI7(".x%lx.c coords %xPHASOGRAM %d %d %d %d\n",
- canvas, x,
- x->x_xpos-1, x->x_ypos+(x->x_blocksize/2*x->x_zoom)+1,
- x->x_xpos+x->x_size*x->x_zoom+1,
- x->x_ypos+x->x_blocksize*x->x_zoom+3);
- SYS_VGUI5(".x%lx.c coords IFAZIMAGE%x %d %d\n",
- canvas, x,
- x->x_xpos+((x->x_size*x->x_zoom)/2),
- x->x_ypos+3*((x->x_blocksize/2*x->x_zoom)/2)+2 );
- }
- canvas_fixlinesfor( canvas, (t_text*)x );
- }
+ SYS_VGUI7(".x%lx.c coords %xSONOGRAM %d %d %d %d\n",
+ canvas, x,
+ x->x_xpos-1, x->x_ypos-1,
+ x->x_xpos+x->x_size*x->x_zoom+1,
+ x->x_ypos+x->x_blocksize/2*x->x_zoom+1);
+ SYS_VGUI5(".x%lx.c coords ISONIMAGE%x %d %d\n",
+ canvas, x,
+ x->x_xpos+((x->x_size*x->x_zoom)/2),
+ (x->x_ypos+((x->x_blocksize/2*x->x_zoom)/2)) );
+ if ( x->x_phaso )
+ {
+ SYS_VGUI7(".x%lx.c coords %xPHASOGRAM %d %d %d %d\n",
+ canvas, x,
+ x->x_xpos-1, x->x_ypos+(x->x_blocksize/2*x->x_zoom)+1,
+ x->x_xpos+x->x_size*x->x_zoom+1,
+ x->x_ypos+x->x_blocksize*x->x_zoom+3);
+ SYS_VGUI5(".x%lx.c coords IFAZIMAGE%x %d %d\n",
+ canvas, x,
+ x->x_xpos+((x->x_size*x->x_zoom)/2),
+ x->x_ypos+3*((x->x_blocksize/2*x->x_zoom)/2)+2 );
+ }
+ canvas_fixlinesfor( canvas, (t_text*)x );
+ }
}
static void sonogram_draw_select(t_sonogram* x,t_glist* glist)
{
- t_canvas *canvas=glist_getcanvas(glist);
+ t_canvas *canvas=glist_getcanvas(glist);
- if ( x->x_graphic && glist_isvisible( x->x_glist ) )
- {
- if(x->x_selected)
+ if ( x->x_graphic && glist_isvisible( x->x_glist ) )
{
- /* sets the item in blue */
- SYS_VGUI3(".x%lx.c itemconfigure %xSONOGRAM -outline #0000FF\n", canvas, x);
- if ( x->x_phaso )
+ if(x->x_selected)
{
- SYS_VGUI3(".x%lx.c itemconfigure %xPHASOGRAM -outline #0000FF\n", canvas, x);
+ /* sets the item in blue */
+ SYS_VGUI3(".x%lx.c itemconfigure %xSONOGRAM -outline #0000FF\n", canvas, x);
+ if ( x->x_phaso )
+ {
+ SYS_VGUI3(".x%lx.c itemconfigure %xPHASOGRAM -outline #0000FF\n", canvas, x);
+ }
}
- }
- else
- {
- SYS_VGUI3(".x%lx.c itemconfigure %xSONOGRAM -outline #000000\n", canvas, x);
- if ( x->x_phaso )
+ else
{
- SYS_VGUI3(".x%lx.c itemconfigure %xPHASOGRAM -outline #000000\n", canvas, x);
+ SYS_VGUI3(".x%lx.c itemconfigure %xSONOGRAM -outline #000000\n", canvas, x);
+ if ( x->x_phaso )
+ {
+ SYS_VGUI3(".x%lx.c itemconfigure %xPHASOGRAM -outline #000000\n", canvas, x);
+ }
}
}
- }
}
/* ------------------------ widget callbacks ----------------------------- */
static void sonogram_getrect(t_gobj *z, t_glist *owner,
- int *xp1, int *yp1, int *xp2, int *yp2)
+ int *xp1, int *yp1, int *xp2, int *yp2)
{
- t_sonogram* x = (t_sonogram*)z;
-
- *xp1 = x->x_xpos;
- *yp1 = x->x_ypos;
- if ( !x->x_phaso )
- {
- *xp2 = x->x_xpos+x->x_size*x->x_zoom;
- *yp2 = x->x_ypos+x->x_blocksize/2*x->x_zoom+1;
- }
- else
- {
- *xp2 = x->x_xpos+x->x_size*x->x_zoom;
- *yp2 = x->x_ypos+x->x_blocksize*x->x_zoom+3;
- }
+ t_sonogram* x = (t_sonogram*)z;
+
+ *xp1 = x->x_xpos;
+ *yp1 = x->x_ypos;
+ if ( !x->x_phaso )
+ {
+ *xp2 = x->x_xpos+x->x_size*x->x_zoom;
+ *yp2 = x->x_ypos+x->x_blocksize/2*x->x_zoom+1;
+ }
+ else
+ {
+ *xp2 = x->x_xpos+x->x_size*x->x_zoom;
+ *yp2 = x->x_ypos+x->x_blocksize*x->x_zoom+3;
+ }
}
static void sonogram_save(t_gobj *z, t_binbuf *b)
{
- t_sonogram *x = (t_sonogram *)z;
+ t_sonogram *x = (t_sonogram *)z;
- binbuf_addv(b, "ssiisiii", gensym("#X"),gensym("obj"),
- (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
- atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
- x->x_size, x->x_graphic, x->x_phaso );
- binbuf_addv(b, ";");
+ binbuf_addv(b, "ssiisiii", gensym("#X"),gensym("obj"),
+ (t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
+ atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
+ x->x_size, x->x_graphic, x->x_phaso );
+ binbuf_addv(b, ";");
}
static void sonogram_select(t_gobj *z, t_glist *glist, int selected)
{
- t_sonogram *x = (t_sonogram *)z;
+ t_sonogram *x = (t_sonogram *)z;
- x->x_selected = selected;
- sonogram_draw_select( x, glist );
+ x->x_selected = selected;
+ sonogram_draw_select( x, glist );
}
static void sonogram_vis(t_gobj *z, t_glist *glist, int vis)
{
- t_sonogram *x = (t_sonogram *)z;
- t_rtext *y;
-
- if (vis)
- {
- sonogram_draw_new( x, glist );
- }
- else
- {
- // erase all points
- sonogram_draw_delete( x, glist );
- }
+ t_sonogram *x = (t_sonogram *)z;
+ t_rtext *y;
+
+ if (vis)
+ {
+ sonogram_draw_new( x, glist );
+ }
+ else
+ {
+ // erase all points
+ sonogram_draw_delete( x, glist );
+ }
}
static void sonogram_delete(t_gobj *z, t_glist *glist)
@@ -904,359 +984,416 @@ static void sonogram_displace(t_gobj *z, t_glist *glist, int dx, int dy)
if ( ( x->x_xpos != xold ) || ( x->x_ypos != yold ) )
{
- sonogram_draw_move( x, glist );
+ sonogram_draw_move( x, glist );
}
}
static void sonogram_modify_point( t_sonogram* x, t_int sample, t_int frequency, t_int alted )
{
- if ( alted )
- {
- *(x->x_rdata+(sample*x->x_blocksize)+frequency) = 0;
- *(x->x_idata+(sample*x->x_blocksize)+frequency) = 0;
- }
- else
- {
- if ( x->x_enhancemode )
- {
- *(x->x_rdata+(sample*x->x_blocksize)+frequency) *= x->x_modstep;
- *(x->x_idata+(sample*x->x_blocksize)+frequency) *= x->x_modstep;
- }
- else
- {
- *(x->x_rdata+(sample*x->x_blocksize)+frequency) += x->x_modstep;
- *(x->x_idata+(sample*x->x_blocksize)+frequency) += x->x_modstep;
- }
- }
+ if ( alted )
+ {
+ *(x->x_rdata+(sample*x->x_blocksize)+frequency) = 0;
+ *(x->x_idata+(sample*x->x_blocksize)+frequency) = 0;
+ }
+ else
+ {
+ if ( x->x_enhancemode )
+ {
+ *(x->x_rdata+(sample*x->x_blocksize)+frequency) *= x->x_modstep;
+ *(x->x_idata+(sample*x->x_blocksize)+frequency) *= x->x_modstep;
+ }
+ else
+ {
+ *(x->x_rdata+(sample*x->x_blocksize)+frequency) += x->x_modstep;
+ *(x->x_idata+(sample*x->x_blocksize)+frequency) += x->x_modstep;
+ }
+ }
}
static void sonogram_modify_point_phase( t_sonogram* x, t_int sample, t_int frequency, t_int alted )
{
- t_float fspectrum;
- t_float fphase;
-
- fspectrum =
- sqrt( pow( *(x->x_rdata+sample*x->x_blocksize+frequency), 2) +
- pow( *(x->x_idata+sample*x->x_blocksize+frequency), 2) );
- fphase = atan2( *(x->x_idata+sample*x->x_blocksize+frequency),
- *(x->x_rdata+sample*x->x_blocksize+frequency) );
- if ( alted==4 )
- {
- // setting phase to 0
- *(x->x_rdata+(sample*x->x_blocksize)+frequency) = fspectrum;
- *(x->x_idata+(sample*x->x_blocksize)+frequency) = 0;
- }
- else
- {
- if ( x->x_enhancemode )
- {
- *(x->x_rdata+(sample*x->x_blocksize)+frequency) = fspectrum*cos( fphase*x->x_modstep );
- *(x->x_idata+(sample*x->x_blocksize)+frequency) = fspectrum*sin( fphase*x->x_modstep );
- }
- else
- {
- *(x->x_rdata+(sample*x->x_blocksize)+frequency) = fspectrum*cos( fphase+x->x_modstep );
- *(x->x_idata+(sample*x->x_blocksize)+frequency) = fspectrum*sin( fphase+x->x_modstep );
- }
- }
+ t_float fspectrum;
+ t_float fphase;
+
+ fspectrum =
+ sqrt( pow( *(x->x_rdata+sample*x->x_blocksize+frequency), 2) +
+ pow( *(x->x_idata+sample*x->x_blocksize+frequency), 2) );
+ fphase = atan2( *(x->x_idata+sample*x->x_blocksize+frequency),
+ *(x->x_rdata+sample*x->x_blocksize+frequency) );
+ if ( alted==4 )
+ {
+ // setting phase to 0
+ *(x->x_rdata+(sample*x->x_blocksize)+frequency) = fspectrum;
+ *(x->x_idata+(sample*x->x_blocksize)+frequency) = 0;
+ }
+ else
+ {
+ if ( x->x_enhancemode )
+ {
+ *(x->x_rdata+(sample*x->x_blocksize)+frequency) = fspectrum*cos( fphase*x->x_modstep );
+ *(x->x_idata+(sample*x->x_blocksize)+frequency) = fspectrum*sin( fphase*x->x_modstep );
+ }
+ else
+ {
+ *(x->x_rdata+(sample*x->x_blocksize)+frequency) = fspectrum*cos( fphase+x->x_modstep );
+ *(x->x_idata+(sample*x->x_blocksize)+frequency) = fspectrum*sin( fphase+x->x_modstep );
+ }
+ }
}
static void sonogram_motion(t_sonogram *x, t_floatarg dx, t_floatarg dy)
{
- t_int fdraw=0, sdraw=0;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
-
- // post( "sonogram_motion @ [%d,%d] dx=%f dy=%f alt=%d", x->x_xdraw, x->x_ydraw, dx, dy, x->x_alted );
- if ( ( x->x_shifted || (x->x_alted==4) ) )
- {
- if ( (x->x_xdraw+dx) >= x->x_xpos &&
- (x->x_xdraw+dx) <= x->x_xpos+x->x_size*x->x_zoom ) {
- x->x_xdraw += dx;
- }
- if ( (x->x_ydraw+dy) >= x->x_ypos &&
- (x->x_ydraw+dy) <= x->x_ypos+x->x_blocksize*x->x_zoom ) {
- x->x_ydraw += dy;
- }
- sdraw=(x->x_xdraw-x->x_xpos)/x->x_zoom;
- if ( x->x_ydraw <= x->x_ypos+x->x_blocksize/2*x->x_zoom )
- {
- fdraw=(x->x_ypos-x->x_ydraw)/x->x_zoom+x->x_blocksize/2;
- // post( "modify point @ [%d, %d] alted=%d", sdraw, fdraw, x->x_alted );
- sonogram_modify_point( x, sdraw, fdraw, x->x_alted );
- }
- if ( x->x_ydraw >= x->x_ypos+x->x_blocksize/2*x->x_zoom+1 )
- {
- fdraw=(x->x_ypos+x->x_blocksize*x->x_zoom/2+1-x->x_ydraw)/x->x_zoom+x->x_blocksize/2;
- // post( "modify phase @ [%d, %d]", sdraw, fdraw );
- sonogram_modify_point_phase( x, sdraw, fdraw, x->x_alted );
- }
- sonogram_update_point( x, x->x_glist, sdraw, fdraw );
- }
- else
- {
- if ( (x->x_xendcapture+dx) >= x->x_xpos &&
- (x->x_xendcapture+dx) <= x->x_xpos+x->x_size*x->x_zoom ) {
- x->x_xendcapture += dx;
- }
- if ( (x->x_yendcapture+dy) >= x->x_ypos &&
- (x->x_yendcapture+dy) <= x->x_ypos+x->x_blocksize*x->x_zoom ) {
- x->x_yendcapture += dy;
- }
- SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
- SYS_VGUI7( ".x%lx.c create rectangle %d %d %d %d -outline #0000FF -tags %xCAPTURE\n",
+ t_int fdraw=0, sdraw=0;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
+
+ // post( "sonogram_motion @ [%d,%d] dx=%f dy=%f alt=%d", x->x_xdraw, x->x_ydraw, dx, dy, x->x_alted );
+ if ( ( x->x_shifted || (x->x_alted==4) ) )
+ {
+ if ( (x->x_xdraw+dx) >= x->x_xpos &&
+ (x->x_xdraw+dx) <= x->x_xpos+x->x_size*x->x_zoom )
+ {
+ x->x_xdraw += dx;
+ }
+ if ( (x->x_ydraw+dy) >= x->x_ypos &&
+ (x->x_ydraw+dy) <= x->x_ypos+x->x_blocksize*x->x_zoom )
+ {
+ x->x_ydraw += dy;
+ }
+ sdraw=(x->x_xdraw-x->x_xpos)/x->x_zoom;
+ if ( x->x_ydraw <= x->x_ypos+x->x_blocksize/2*x->x_zoom )
+ {
+ fdraw=(x->x_ypos-x->x_ydraw)/x->x_zoom+x->x_blocksize/2;
+ // post( "modify point @ [%d, %d] alted=%d", sdraw, fdraw, x->x_alted );
+ sonogram_modify_point( x, sdraw, fdraw, x->x_alted );
+ }
+ if ( x->x_ydraw >= x->x_ypos+x->x_blocksize/2*x->x_zoom+1 )
+ {
+ fdraw=(x->x_ypos+x->x_blocksize*x->x_zoom/2+1-x->x_ydraw)/x->x_zoom+x->x_blocksize/2;
+ // post( "modify phase @ [%d, %d]", sdraw, fdraw );
+ sonogram_modify_point_phase( x, sdraw, fdraw, x->x_alted );
+ }
+ sonogram_update_point( x, x->x_glist, sdraw, fdraw );
+ }
+ else
+ {
+ if ( (x->x_xendcapture+dx) >= x->x_xpos &&
+ (x->x_xendcapture+dx) <= x->x_xpos+x->x_size*x->x_zoom )
+ {
+ x->x_xendcapture += dx;
+ }
+ if ( (x->x_yendcapture+dy) >= x->x_ypos &&
+ (x->x_yendcapture+dy) <= x->x_ypos+x->x_blocksize*x->x_zoom )
+ {
+ x->x_yendcapture += dy;
+ }
+ SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
+ SYS_VGUI7( ".x%lx.c create rectangle %d %d %d %d -outline #0000FF -tags %xCAPTURE\n",
canvas, x->x_xstartcapture, x->x_ystartcapture, x->x_xendcapture, x->x_yendcapture, x );
- }
+ }
}
static int sonogram_click(t_gobj *z, struct _glist *glist,
- int xpix, int ypix, int shift, int alt, int dbl, int doit)
+ int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
- t_sonogram* x = (t_sonogram *)z;
- t_int si,fi;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_sonogram* x = (t_sonogram *)z;
+ t_int si,fi;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
// post( "sonogram_click : x=%d y=%d doit=%d alt=%d, shift=%d", xpix, ypix, doit, alt, shift );
- if ( x->x_aftermousedown == 1 && doit == 0)
- {
- x->x_aftermousedown = 1;
- }
+ if ( x->x_aftermousedown == 1 && doit == 0)
+ {
+ x->x_aftermousedown = 1;
+ }
else
{
- x->x_aftermousedown = 0;
+ x->x_aftermousedown = 0;
}
if ( doit )
{
- x->x_xdraw = xpix;
- x->x_ydraw = ypix;
- x->x_shifted = shift;
- x->x_alted = alt;
- // activate motion callback
- glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)sonogram_motion,
- 0, xpix, ypix );
-
- if ( shift && alt && (x->x_xstartcapture != x->x_xendcapture ) )
- {
- sonogram_paste(x);
- sonogram_paste_phase(x);
- }
- else if ( shift && (x->x_xstartcapture != x->x_xendcapture ) )
- {
- // add or multiply modstep
- if ( x->x_xstartcapture > x->x_xendcapture ) {
- fi = x->x_xstartcapture;
- x->x_xstartcapture = x->x_xendcapture;
- x->x_xendcapture = fi;
- }
- if ( x->x_ystartcapture > x->x_yendcapture ) {
- fi = x->x_ystartcapture;
- x->x_ystartcapture = x->x_yendcapture;
- x->x_yendcapture = fi;
- }
- for ( si=(x->x_xstartcapture-x->x_xpos)/x->x_zoom;
- si<=(x->x_xendcapture-x->x_xpos)/x->x_zoom; si++) {
- for ( fi=(x->x_ypos-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
- fi<=(x->x_ypos-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2; fi++) {
- sonogram_modify_point( x, si, fi, alt );
- }
- for ( fi=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
- fi<=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2; fi++) {
- sonogram_modify_point_phase( x, si, fi, alt );
- }
- }
- // post( "modified y from %d to %d", (x->x_ypos-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2,
- // (x->x_ypos-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2 );
- sonogram_update_part(x, x->x_glist, (x->x_xstartcapture-x->x_xpos)/x->x_zoom,
- (x->x_xendcapture-x->x_xpos)/x->x_zoom, 0, 1, 1);
- }
- else if ( (alt==4) && (x->x_xstartcapture != x->x_xendcapture ) )
- {
- // clean up area
- if ( x->x_xstartcapture > x->x_xendcapture ) {
- fi = x->x_xstartcapture;
- x->x_xstartcapture = x->x_xendcapture;
- x->x_xendcapture = fi;
- }
- if ( x->x_ystartcapture > x->x_yendcapture ) {
- fi = x->x_ystartcapture;
- x->x_ystartcapture = x->x_yendcapture;
- x->x_yendcapture = fi;
- }
- for ( si=(x->x_xstartcapture-x->x_xpos)/x->x_zoom;
- si<=(x->x_xendcapture-x->x_xpos)/x->x_zoom; si++) {
- for ( fi=(x->x_ypos-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
- fi<=(x->x_ypos-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2; fi++) {
- sonogram_modify_point( x, si, fi, alt );
- }
- for ( fi=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
- fi<=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2; fi++) {
- sonogram_modify_point_phase( x, si, fi, alt );
- }
- }
- sonogram_update_part(x, x->x_glist, (x->x_xstartcapture-x->x_xpos)/x->x_zoom,
- (x->x_xendcapture-x->x_xpos)/x->x_zoom, 0, 1, 1);
- }
- // start a new capture
- SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
- x->x_xstartcapture = xpix;
- x->x_ystartcapture = ypix;
- x->x_xendcapture = xpix;
- x->x_yendcapture = ypix;
+ x->x_xdraw = xpix;
+ x->x_ydraw = ypix;
+ x->x_shifted = shift;
+ x->x_alted = alt;
+ // activate motion callback
+ glist_grab( glist, &x->x_obj.te_g, (t_glistmotionfn)sonogram_motion,
+ 0, xpix, ypix );
+
+ if ( shift && alt && (x->x_xstartcapture != x->x_xendcapture ) )
+ {
+ sonogram_paste(x);
+ sonogram_paste_phase(x);
+ }
+ else if ( shift && (x->x_xstartcapture != x->x_xendcapture ) )
+ {
+ // add or multiply modstep
+ if ( x->x_xstartcapture > x->x_xendcapture )
+ {
+ fi = x->x_xstartcapture;
+ x->x_xstartcapture = x->x_xendcapture;
+ x->x_xendcapture = fi;
+ }
+ if ( x->x_ystartcapture > x->x_yendcapture )
+ {
+ fi = x->x_ystartcapture;
+ x->x_ystartcapture = x->x_yendcapture;
+ x->x_yendcapture = fi;
+ }
+ for ( si=(x->x_xstartcapture-x->x_xpos)/x->x_zoom;
+ si<=(x->x_xendcapture-x->x_xpos)/x->x_zoom; si++)
+ {
+ for ( fi=(x->x_ypos-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
+ fi<=(x->x_ypos-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2; fi++)
+ {
+ sonogram_modify_point( x, si, fi, alt );
+ }
+ for ( fi=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
+ fi<=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2; fi++)
+ {
+ sonogram_modify_point_phase( x, si, fi, alt );
+ }
+ }
+ // post( "modified y from %d to %d", (x->x_ypos-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2,
+ // (x->x_ypos-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2 );
+ sonogram_update_part(x, x->x_glist, (x->x_xstartcapture-x->x_xpos)/x->x_zoom,
+ (x->x_xendcapture-x->x_xpos)/x->x_zoom, 0, 1, 1);
+ }
+ else if ( (alt==4) && (x->x_xstartcapture != x->x_xendcapture ) )
+ {
+ // clean up area
+ if ( x->x_xstartcapture > x->x_xendcapture )
+ {
+ fi = x->x_xstartcapture;
+ x->x_xstartcapture = x->x_xendcapture;
+ x->x_xendcapture = fi;
+ }
+ if ( x->x_ystartcapture > x->x_yendcapture )
+ {
+ fi = x->x_ystartcapture;
+ x->x_ystartcapture = x->x_yendcapture;
+ x->x_yendcapture = fi;
+ }
+ for ( si=(x->x_xstartcapture-x->x_xpos)/x->x_zoom;
+ si<=(x->x_xendcapture-x->x_xpos)/x->x_zoom; si++)
+ {
+ for ( fi=(x->x_ypos-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
+ fi<=(x->x_ypos-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2; fi++)
+ {
+ sonogram_modify_point( x, si, fi, alt );
+ }
+ for ( fi=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_yendcapture)/x->x_zoom+x->x_blocksize/2;
+ fi<=(x->x_ypos+x->x_blocksize/2*x->x_zoom+1-x->x_ystartcapture)/x->x_zoom+x->x_blocksize/2; fi++)
+ {
+ sonogram_modify_point_phase( x, si, fi, alt );
+ }
+ }
+ sonogram_update_part(x, x->x_glist, (x->x_xstartcapture-x->x_xpos)/x->x_zoom,
+ (x->x_xendcapture-x->x_xpos)/x->x_zoom, 0, 1, 1);
+ }
+ // start a new capture
+ SYS_VGUI3( ".x%lx.c delete %xCAPTURE\n", canvas, x );
+ x->x_xstartcapture = xpix;
+ x->x_ystartcapture = ypix;
+ x->x_xendcapture = xpix;
+ x->x_yendcapture = ypix;
}
else
{
- // nothing
+ // nothing
}
x->x_aftermousedown = doit;
return (1);
}
- /* clean up */
-static void sonogram_free(t_sonogram *x)
+/* clean up */
+static void sonogram_free(t_sonogram *x)
{
- if ( x->x_rdata != NULL ) {
- freebytes(x->x_rdata, x->x_size*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- x->x_rdata = NULL;
- }
- if ( x->x_idata != NULL ) {
- freebytes(x->x_idata, x->x_size*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- x->x_idata = NULL;
- }
- if ( x->x_rudata != NULL ) {
- freebytes(x->x_rudata, x->x_size*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- x->x_rdata = NULL;
- }
- if ( x->x_iudata != NULL ) {
- freebytes(x->x_iudata, x->x_size*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- x->x_idata = NULL;
- }
- if ( x->x_gifdata != NULL ) {
- freebytes(x->x_gifdata, (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_gifdata = NULL;
- }
- if ( x->x_guicommand != NULL ) {
- freebytes(x->x_guicommand, 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_guicommand = NULL;
+ if ( x->x_rdata != NULL )
+ {
+ freebytes(x->x_rdata, x->x_size*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ x->x_rdata = NULL;
+ }
+ if ( x->x_idata != NULL )
+ {
+ freebytes(x->x_idata, x->x_size*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ x->x_idata = NULL;
+ }
+ if ( x->x_rudata != NULL )
+ {
+ freebytes(x->x_rudata, x->x_size*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ x->x_rdata = NULL;
+ }
+ if ( x->x_iudata != NULL )
+ {
+ freebytes(x->x_iudata, x->x_size*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ x->x_idata = NULL;
+ }
+ if ( x->x_gifdata != NULL )
+ {
+ freebytes(x->x_gifdata, (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_gifdata = NULL;
+ }
+ if ( x->x_guicommand != NULL )
+ {
+ freebytes(x->x_guicommand, 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_guicommand = NULL;
}
}
- /* allocate tables for storing ffts */
+/* allocate tables for storing ffts */
static t_int sonogram_allocate(t_sonogram *x)
{
- t_int fi;
-
- if ( !(x->x_rdata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- }
- if ( !(x->x_idata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- }
- if ( !(x->x_multfreq = getbytes( x->x_blocksize*sizeof(t_int) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", x->x_blocksize*sizeof(t_int) );
+ t_int fi;
+
+ if ( !(x->x_rdata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ }
+ if ( !(x->x_idata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ }
+ if ( !(x->x_multfreq = getbytes( x->x_blocksize*sizeof(t_int) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", x->x_blocksize*sizeof(t_int) );
}
for ( fi=0; fi<x->x_blocksize; fi++ )
{
- *(x->x_multfreq+fi)=1;
+ *(x->x_multfreq+fi)=1;
}
// no undo is available
x->x_uxs = x->x_uxe = x->x_uys = x->x_uye = -1;
- if ( !(x->x_rudata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- }
- if ( !(x->x_iudata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
- }
- if ( !( x->x_gifdata = ( char* ) getbytes( (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- }
- if ( !( x->x_guicommand = ( char* ) getbytes( 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- }
-
+ if ( !(x->x_rudata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ }
+ if ( !(x->x_iudata = getbytes( x->x_size*x->x_blocksize*sizeof(float) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", x->x_size*x->x_blocksize*sizeof(float) );
+ }
+ if ( !( x->x_gifdata = ( char* ) getbytes( (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ }
+ if ( !( x->x_guicommand = ( char* ) getbytes( 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ }
+
return 0;
}
- /* reallocate tables for storing ffts */
+/* reallocate tables for storing ffts */
static t_int sonogram_reallocate(t_sonogram *x, t_int ioldsize, t_int inewsize)
{
- t_int fi;
- t_float *prdata=x->x_rdata, *pidata=x->x_idata;
- t_float *prudata=x->x_rudata, *piudata=x->x_iudata;
-
- if ( !(x->x_rdata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
- }
- if ( !(x->x_idata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
+ t_int fi;
+ t_float *prdata=x->x_rdata, *pidata=x->x_idata;
+ t_float *prudata=x->x_rudata, *piudata=x->x_iudata;
+
+ if ( !(x->x_rdata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
+ }
+ if ( !(x->x_idata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
}
// no undo is available
x->x_uxs = x->x_uxe = x->x_uys = x->x_uye = -1;
- if ( !(x->x_rudata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
- }
- if ( !(x->x_iudata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return -1;
- } else {
- post( "sonogram~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
- }
- if ( prdata != NULL ) {
- freebytes(prdata, ioldsize*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
- }
- if ( pidata != NULL ) {
- freebytes(pidata, ioldsize*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
- }
- if ( prudata != NULL ) {
- freebytes(prudata, ioldsize*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
- }
- if ( piudata != NULL ) {
- freebytes(piudata, ioldsize*x->x_blocksize*sizeof(float) );
- post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
- }
-
+ if ( !(x->x_rudata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
+ }
+ if ( !(x->x_iudata = getbytes( inewsize*x->x_blocksize*sizeof(float) ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return -1;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", inewsize*x->x_blocksize*sizeof(float) );
+ }
+ if ( prdata != NULL )
+ {
+ freebytes(prdata, ioldsize*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
+ }
+ if ( pidata != NULL )
+ {
+ freebytes(pidata, ioldsize*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
+ }
+ if ( prudata != NULL )
+ {
+ freebytes(prudata, ioldsize*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
+ }
+ if ( piudata != NULL )
+ {
+ freebytes(piudata, ioldsize*x->x_blocksize*sizeof(float) );
+ post( "Freed %d bytes", ioldsize*x->x_blocksize*sizeof(float) );
+ }
+
return 0;
}
- /* records or playback the sonogram */
+/* records or playback the sonogram */
static t_int *sonogram_perform(t_int *w)
{
t_float *rin = (t_float *)(w[1]);
@@ -1273,81 +1410,91 @@ static t_int *sonogram_perform(t_int *w)
if ( x->x_readstart <= x->x_readend )
{
- startsamp = (x->x_readstart*x->x_size)/100;
- endsamp = (x->x_readend*x->x_size)/100;
+ startsamp = (x->x_readstart*x->x_size)/100;
+ endsamp = (x->x_readend*x->x_size)/100;
}
else
{
- startsamp = (x->x_readend*x->x_size)/100;
- endsamp = (x->x_readstart*x->x_size)/100;
+ startsamp = (x->x_readend*x->x_size)/100;
+ endsamp = (x->x_readstart*x->x_size)/100;
}
// reallocate tables if blocksize has been changed
- if ( n != x->x_blocksize && x->x_updatechild == 0 ) {
- post( "sonogram~ : reallocating tables" );
- // erase all points
- sonogram_free(x);
- x->x_blocksize = n;
- sonogram_allocate(x);
- sonogram_update_part(x, x->x_glist, 0, x->x_size-1, !x->x_empty, 0, 0);
- canvas_fixlinesfor(x->x_glist, (t_text*)x );
+ if ( n != x->x_blocksize && x->x_updatechild == 0 )
+ {
+ post( "sonogram~ : reallocating tables" );
+ // erase all points
+ sonogram_free(x);
+ x->x_blocksize = n;
+ sonogram_allocate(x);
+ sonogram_update_part(x, x->x_glist, 0, x->x_size-1, !x->x_empty, 0, 0);
+ canvas_fixlinesfor(x->x_glist, (t_text*)x );
}
bi = 0;
- while (bi<n)
+ while (bi<n)
{
// eventually records input
- if ( x->x_record) {
- *(x->x_rdata+(x->x_writepos*x->x_blocksize)+bi)=(*(rin))*(*(x->x_multfreq+bi));
- *(x->x_idata+(x->x_writepos*x->x_blocksize)+bi)=(*(iin))*(*(x->x_multfreq+bi));
+ if ( x->x_record)
+ {
+ *(x->x_rdata+(x->x_writepos*x->x_blocksize)+bi)=(*(rin))*(*(x->x_multfreq+bi));
+ *(x->x_idata+(x->x_writepos*x->x_blocksize)+bi)=(*(iin))*(*(x->x_multfreq+bi));
}
// set outputs
*rout = 0.0;
*iout = 0.0;
- if ( x->x_play) {
+ if ( x->x_play)
+ {
is=0;
- fspectrum =
- sqrt( pow( *(x->x_rdata+(((int)x->x_readpos+is)*x->x_blocksize)+bi), 2) +
- pow( *(x->x_idata+(((int)x->x_readpos+is)*x->x_blocksize)+bi), 2) );
- fphase = atan2( *(x->x_idata+(((int)x->x_readpos+is)*x->x_blocksize)+bi),
- *(x->x_rdata+(((int)x->x_readpos+is)*x->x_blocksize)+bi) );
+ fspectrum =
+ sqrt( pow( *(x->x_rdata+(((int)x->x_readpos+is)*x->x_blocksize)+bi), 2) +
+ pow( *(x->x_idata+(((int)x->x_readpos+is)*x->x_blocksize)+bi), 2) );
+ fphase = atan2( *(x->x_idata+(((int)x->x_readpos+is)*x->x_blocksize)+bi),
+ *(x->x_rdata+(((int)x->x_readpos+is)*x->x_blocksize)+bi) );
fphase += (x->x_phase/180.0)*(M_PI);
*rout += fspectrum*cos( fphase );
*iout += fspectrum*sin( fphase );
- }
- rout++;iout++;
- rin++;iin++;
+ }
+ rout++;
+ iout++;
+ rin++;
+ iin++;
bi++;
-
+
}
// reset playing position until next play
- if ( x->x_play ) {
- x->x_readpos+=x->x_readspeed;
- // post( "xreadpos : %f (added %f) %d", x->x_readpos, x->x_readspeed, x->x_readend );
- if ( ( x->x_readspeed >= 0 ) && ( x->x_readpos >= endsamp ) ) {
- x->x_play=0;
- x->x_readpos=(float)(startsamp);
- // post( "cooled~ : stopped playing (readpos=%d)", x->x_readpos );
- outlet_bang(x->x_end);
- }
- if ( ( x->x_readspeed < 0 ) && ( x->x_readpos <= startsamp ) ) {
- x->x_play=0;
- x->x_readpos = (float)(endsamp);
- // post( "cooled~ : stopped playing (readpos=%d)", x->x_readpos );
- outlet_bang(x->x_end);
- }
+ if ( x->x_play )
+ {
+ x->x_readpos+=x->x_readspeed;
+ // post( "xreadpos : %f (added %f) %d", x->x_readpos, x->x_readspeed, x->x_readend );
+ if ( ( x->x_readspeed >= 0 ) && ( x->x_readpos >= endsamp ) )
+ {
+ x->x_play=0;
+ x->x_readpos=(float)(startsamp);
+ // post( "cooled~ : stopped playing (readpos=%d)", x->x_readpos );
+ outlet_bang(x->x_end);
+ }
+ if ( ( x->x_readspeed < 0 ) && ( x->x_readpos <= startsamp ) )
+ {
+ x->x_play=0;
+ x->x_readpos = (float)(endsamp);
+ // post( "cooled~ : stopped playing (readpos=%d)", x->x_readpos );
+ outlet_bang(x->x_end);
+ }
}
// reset recording position until next record
- if ( x->x_record ) {
- x->x_writepos++;
- if ( x->x_writepos >= x->x_size ) {
- x->x_record=0;
- x->x_writepos=0;
- sonogram_update_part(x, x->x_glist, 0, x->x_size-1, 0, 1, 0);
- outlet_bang(x->x_recend);
- if ( x->x_empty ) x->x_empty = 0;
- // post( "sonogram~ : stopped recording" );
- }
+ if ( x->x_record )
+ {
+ x->x_writepos++;
+ if ( x->x_writepos >= x->x_size )
+ {
+ x->x_record=0;
+ x->x_writepos=0;
+ sonogram_update_part(x, x->x_glist, 0, x->x_size-1, 0, 1, 0);
+ outlet_bang(x->x_recend);
+ if ( x->x_empty ) x->x_empty = 0;
+ // post( "sonogram~ : stopped recording" );
+ }
}
// post( "sonogram~ : read : %f:%d : write: %d:%d", x->x_readpos, x->x_play, x->x_writepos, x->x_record );
return (w+7);
@@ -1358,7 +1505,7 @@ static void sonogram_dsp(t_sonogram *x, t_signal **sp)
dsp_add(sonogram_perform, 6, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[0]->s_n, x);
}
- /* record the sonogram */
+/* record the sonogram */
static void sonogram_record(t_sonogram *x)
{
x->x_record=1;
@@ -1366,7 +1513,7 @@ static void sonogram_record(t_sonogram *x)
// post( "sonogram~ : recording on" );
}
- /* play the sonogram */
+/* play the sonogram */
static void sonogram_play(t_sonogram *x)
{
x->x_play=1;
@@ -1374,11 +1521,11 @@ static void sonogram_play(t_sonogram *x)
// post( "sonogram~ : playing on" );
}
- /* setting the starting point for reading ( in percent ) */
+/* setting the starting point for reading ( in percent ) */
static void sonogram_readstart(t_sonogram *x, t_floatarg fstart)
{
- t_float startpoint = fstart;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_float startpoint = fstart;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
if (startpoint < 0) startpoint = 0;
if (startpoint > 100) startpoint = 100;
@@ -1388,63 +1535,66 @@ static void sonogram_readstart(t_sonogram *x, t_floatarg fstart)
if ( ( x->x_readstart < x->x_readend ) && ( x->x_readspeed < 0 ) ) x->x_readspeed = -x->x_readspeed;
if ( x->x_graphic && glist_isvisible( x->x_glist ) )
{
- SYS_VGUI3( ".x%lx.c delete line %xREADSTART\n",
+ SYS_VGUI3( ".x%lx.c delete line %xREADSTART\n",
canvas, x);
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xREADSTART -width 3\n",
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xREADSTART -width 3\n",
canvas, x->x_xpos+(x->x_readstart*(x->x_size)/100 ),
- x->x_ypos, x->x_xpos+(x->x_readstart*(x->x_size)/100 ),
- x->x_ypos+x->x_blocksize*x->x_zoom, x );
+ x->x_ypos, x->x_xpos+(x->x_readstart*(x->x_size)/100 ),
+ x->x_ypos+x->x_blocksize*x->x_zoom, x );
}
}
- /* setting the starting point for modification ( in percent ) */
+/* setting the starting point for modification ( in percent ) */
static void sonogram_modstart(t_sonogram *x, t_floatarg fstart)
{
- t_float startpoint = fstart;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_float startpoint = fstart;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
if (startpoint < 0) startpoint = 0;
if (startpoint > 100) startpoint = 100;
- if ( startpoint > x->x_modend ) {
- x->x_modstart = x->x_modend;
- post( "sonogram~ : warning : range for modifications is null" );
- } else {
- x->x_modstart=startpoint;
+ if ( startpoint > x->x_modend )
+ {
+ x->x_modstart = x->x_modend;
+ post( "sonogram~ : warning : range for modifications is null" );
+ }
+ else
+ {
+ x->x_modstart=startpoint;
}
if ( x->x_graphic && glist_isvisible( x->x_glist ) )
{
- SYS_VGUI3( ".x%lx.c delete line %xMODSTART\n",
+ SYS_VGUI3( ".x%lx.c delete line %xMODSTART\n",
canvas, x);
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #11E834 -tags %xMODSTART -width 3\n",
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #11E834 -tags %xMODSTART -width 3\n",
canvas, x->x_xpos+(x->x_modstart*(x->x_size)/100 ),
- x->x_ypos, x->x_xpos+(x->x_modstart*(x->x_size)/100 ),
- x->x_ypos+x->x_blocksize*x->x_zoom, x );
+ x->x_ypos, x->x_xpos+(x->x_modstart*(x->x_size)/100 ),
+ x->x_ypos+x->x_blocksize*x->x_zoom, x );
}
}
- /* setting the modification step for graphical mode */
+/* setting the modification step for graphical mode */
static void sonogram_modstep(t_sonogram *x, t_floatarg fmodstep)
{
- if ( x->x_graphic )
- {
- x->x_modstep = fmodstep;
- }
+ if ( x->x_graphic )
+ {
+ x->x_modstep = fmodstep;
+ }
}
- /* setting enhance mode */
+/* setting enhance mode */
static void sonogram_enhancemode(t_sonogram *x, t_floatarg fenhancemode)
{
- if ( x->x_graphic )
- {
- x->x_enhancemode = fenhancemode;
- }
+ if ( x->x_graphic )
+ {
+ x->x_enhancemode = fenhancemode;
+ }
}
- /* setting the ending point for reading ( in percent ) */
+/* setting the ending point for reading ( in percent ) */
static void sonogram_readend(t_sonogram *x, t_floatarg fend)
{
- t_float endpoint = fend;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_float endpoint = fend;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
if (endpoint < 0) endpoint = 0;
if (endpoint > 100) endpoint = 100;
@@ -1454,120 +1604,133 @@ static void sonogram_readend(t_sonogram *x, t_floatarg fend)
if ( ( x->x_readstart < x->x_readend ) && ( x->x_readspeed < 0 ) ) x->x_readspeed = -x->x_readspeed;
if ( x->x_graphic && glist_isvisible( x->x_glist ) )
{
- SYS_VGUI3( ".x%lx.c delete line %xREADEND\n",
+ SYS_VGUI3( ".x%lx.c delete line %xREADEND\n",
canvas, x);
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xREADEND -width 3\n",
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #FF0000 -tags %xREADEND -width 3\n",
canvas, x->x_xpos+(x->x_readend*(x->x_size)/100 ),
- x->x_ypos, x->x_xpos+(x->x_readend*(x->x_size)/100 ),
- x->x_ypos+x->x_blocksize*x->x_zoom, x );
+ x->x_ypos, x->x_xpos+(x->x_readend*(x->x_size)/100 ),
+ x->x_ypos+x->x_blocksize*x->x_zoom, x );
}
}
- /* setting the ending point for modification ( in percent ) */
+/* setting the ending point for modification ( in percent ) */
static void sonogram_modend(t_sonogram *x, t_floatarg fend)
{
- t_float endpoint = fend;
- t_canvas *canvas=glist_getcanvas(x->x_glist);
+ t_float endpoint = fend;
+ t_canvas *canvas=glist_getcanvas(x->x_glist);
if (endpoint < 0) endpoint = 0;
if (endpoint > 100) endpoint = 100;
- if ( endpoint < x->x_modstart ) {
- x->x_modend = x->x_modstart;
- post( "sonogram~ : warning : range for modifications is null" );
- } else {
- x->x_modend=endpoint;
+ if ( endpoint < x->x_modstart )
+ {
+ x->x_modend = x->x_modstart;
+ post( "sonogram~ : warning : range for modifications is null" );
+ }
+ else
+ {
+ x->x_modend=endpoint;
}
if ( x->x_graphic && glist_isvisible( x->x_glist ) )
{
- SYS_VGUI3( ".x%lx.c delete line %xMODEND\n",
+ SYS_VGUI3( ".x%lx.c delete line %xMODEND\n",
canvas, x);
- SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #11E834 -tags %xMODEND -width 3\n",
+ SYS_VGUI7( ".x%lx.c create line %d %d %d %d -fill #11E834 -tags %xMODEND -width 3\n",
canvas, x->x_xpos+(x->x_modend*(x->x_size)/100 ),
- x->x_ypos, x->x_xpos+(x->x_modend*(x->x_size)/100 ),
- x->x_ypos+x->x_blocksize*x->x_zoom, x );
+ x->x_ypos, x->x_xpos+(x->x_modend*(x->x_size)/100 ),
+ x->x_ypos+x->x_blocksize*x->x_zoom, x );
}
}
- /* sets the reading speed */
+/* sets the reading speed */
static void sonogram_readspeed(t_sonogram *x, t_floatarg freadspeed)
{
- if (freadspeed <= 0 ) {
- post( "sonogram~ : wrong readspeed argument" );
- return;
+ if (freadspeed <= 0 )
+ {
+ post( "sonogram~ : wrong readspeed argument" );
+ return;
}
x->x_readspeed=freadspeed;
}
- /* enhance frequencies */
+/* enhance frequencies */
static void sonogram_enhance(t_sonogram *x, t_floatarg fstartfreq, t_floatarg fendfreq, t_floatarg fenhance, t_floatarg fnoupdate )
{
- t_int samplestart, sampleend, si, fi=0, ffi=0;
- t_float oldenergy;
+ t_int samplestart, sampleend, si, fi=0, ffi=0;
+ t_float oldenergy;
if (fstartfreq < 0 || fendfreq < 0 ||
- fstartfreq > x->x_blocksize || fendfreq > x->x_blocksize ||
- fstartfreq > fendfreq ) {
+ fstartfreq > x->x_blocksize || fendfreq > x->x_blocksize ||
+ fstartfreq > fendfreq )
+ {
post( "sonogram~ : error : wrong frequencies range" );
return;
}
- if ( fenhance < 0 ) {
+ if ( fenhance < 0 )
+ {
post( "sonogram~ : error : wrong multiplicating factor" );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
// post("enhancing portion [%d,%d]", samplestart, sampleend );
- for ( si=samplestart; si<=sampleend; si++ ) {
- for ( fi=(int)fstartfreq; fi<=(int)fendfreq; fi++ ) {
- *(x->x_multfreq+fi) = fenhance;
- if ( (fi != 0) && (fi != x->x_blocksize/2-1) )
- {
- /* multiply both r*sin(a) and r*cos(a) to mutiply r */
- *(x->x_rdata+(si*x->x_blocksize)+fi) *= fenhance;
- *(x->x_idata+(si*x->x_blocksize)+fi) *= fenhance;
- }
- }
+ for ( si=samplestart; si<=sampleend; si++ )
+ {
+ for ( fi=(int)fstartfreq; fi<=(int)fendfreq; fi++ )
+ {
+ *(x->x_multfreq+fi) = fenhance;
+ if ( (fi != 0) && (fi != x->x_blocksize/2-1) )
+ {
+ /* multiply both r*sin(a) and r*cos(a) to mutiply r */
+ *(x->x_rdata+(si*x->x_blocksize)+fi) *= fenhance;
+ *(x->x_idata+(si*x->x_blocksize)+fi) *= fenhance;
+ }
+ }
}
// post( "sonogram~ : enhanced %d,%d", fi, ffi );
if ( !(int)fnoupdate )
{
- sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
+ sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
}
- /* add a constant to frequencies */
+/* add a constant to frequencies */
static void sonogram_add(t_sonogram *x, t_floatarg fstartfreq, t_floatarg fendfreq, t_floatarg fadd)
{
- t_int samplestart, sampleend, si, fi;
- t_float oldenergy;
+ t_int samplestart, sampleend, si, fi;
+ t_float oldenergy;
if (fstartfreq < 0 || fendfreq < 0 ||
- fstartfreq > x->x_blocksize || fendfreq > x->x_blocksize ||
- fstartfreq > fendfreq ) {
+ fstartfreq > x->x_blocksize || fendfreq > x->x_blocksize ||
+ fstartfreq > fendfreq )
+ {
post( "sonogram~ : error : wrong frequencies range" );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
// post("enhancing portion [%d,%d]", samplestart, sampleend );
- for ( si=samplestart; si<=sampleend; si++ ) {
- for ( fi=(int)fstartfreq; fi<=(int)fendfreq; fi++ ) {
- /* multiply both r*sin(a) and r*cos(a) to mutiply r */
- *(x->x_rdata+(si*x->x_blocksize)+fi) += fadd;
- *(x->x_idata+(si*x->x_blocksize)+fi) += fadd;
- }
+ for ( si=samplestart; si<=sampleend; si++ )
+ {
+ for ( fi=(int)fstartfreq; fi<=(int)fendfreq; fi++ )
+ {
+ /* multiply both r*sin(a) and r*cos(a) to mutiply r */
+ *(x->x_rdata+(si*x->x_blocksize)+fi) += fadd;
+ *(x->x_idata+(si*x->x_blocksize)+fi) += fadd;
+ }
}
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* resize sonogram */
+/* resize sonogram */
static void sonogram_resize(t_sonogram *x, t_floatarg fnewsize )
{
- if (fnewsize <= 0) {
+ if (fnewsize <= 0)
+ {
post( "sonogram~ : error : wrong size" );
return;
}
- if (x->x_updatechild > 0) {
+ if (x->x_updatechild > 0)
+ {
post( "sonogram~ : can't resize now, an update is pending." );
return;
}
@@ -1580,145 +1743,164 @@ static void sonogram_resize(t_sonogram *x, t_floatarg fnewsize )
sonogram_update_part(x, x->x_glist, 0, x->x_size-1, 0, 0, 0);
}
- /* set zoom factor */
+/* set zoom factor */
static void sonogram_zoom(t_sonogram *x, t_floatarg fzoom )
{
post( "sonogram~: warning : zoom and big block factors might lead to a crash" );
- if (fzoom < 1) {
+ if (fzoom < 1)
+ {
post( "sonogram~ : error : wrong zoom factor" );
return;
}
- if ( x->x_gifdata != NULL ) {
- freebytes(x->x_gifdata, (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_gifdata = NULL;
+ if ( x->x_gifdata != NULL )
+ {
+ freebytes(x->x_gifdata, (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_gifdata = NULL;
}
- if ( x->x_guicommand != NULL ) {
- freebytes(x->x_guicommand, 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- post( "Freed %d bytes", 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- x->x_guicommand = NULL;
+ if ( x->x_guicommand != NULL )
+ {
+ freebytes(x->x_guicommand, 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ post( "Freed %d bytes", 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ x->x_guicommand = NULL;
}
x->x_zoom = (int)fzoom;
- if ( !( x->x_gifdata = ( char* ) getbytes( (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return;
- } else {
- post( "sonogram~ : allocated %d bytes", (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
- }
- if ( !( x->x_guicommand = ( char* ) getbytes( 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") ) ) ) {
- post( "sonogram~ : error : could not allocate buffers" );
- return;
- } else {
- post( "sonogram~ : allocated %d bytes", 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ if ( !( x->x_gifdata = ( char* ) getbytes( (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", (x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
+ }
+ if ( !( x->x_guicommand = ( char* ) getbytes( 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") ) ) )
+ {
+ post( "sonogram~ : error : could not allocate buffers" );
+ return;
+ }
+ else
+ {
+ post( "sonogram~ : allocated %d bytes", 128+(x->x_blocksize/2)*x->x_zoom*sizeof("#FFFFFF ") );
}
sonogram_update_part(x, x->x_glist, 0, x->x_size-1, !x->x_empty, !x->x_empty, 0);
canvas_fixlinesfor(x->x_glist, (t_text*)x );
}
- /* refresh data */
+/* refresh data */
static void sonogram_refresh(t_sonogram *x)
{
sonogram_update_part(x, x->x_glist, 0, x->x_size-1, 0, 1, 1);
}
- /* flip frequencies */
+/* flip frequencies */
static void sonogram_flipfreqs(t_sonogram *x)
{
- t_int samplestart, sampleend, si, fi;
- t_float fvalue;
- t_int ioperon;
+ t_int samplestart, sampleend, si, fi;
+ t_float fvalue;
+ t_int ioperon;
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
ioperon=x->x_blocksize/2;
- for ( si=samplestart; si<=sampleend; si++ ) {
- for ( fi=0; fi<=ioperon/2; fi++ ) {
- fvalue = *(x->x_rdata+(si*x->x_blocksize)+fi);
- *(x->x_rdata+(si*x->x_blocksize)+fi) = *(x->x_rdata+(si*x->x_blocksize)+(ioperon-fi-1));
- *(x->x_rdata+(si*x->x_blocksize)+(ioperon-fi-1)) = fvalue;
- fvalue = *(x->x_idata+(si*x->x_blocksize)+fi);
- *(x->x_idata+(si*x->x_blocksize)+fi) = *(x->x_idata+(si*x->x_blocksize)+(ioperon-fi-1));
- *(x->x_idata+(si*x->x_blocksize)+(ioperon-fi-1)) = fvalue;
- }
+ for ( si=samplestart; si<=sampleend; si++ )
+ {
+ for ( fi=0; fi<=ioperon/2; fi++ )
+ {
+ fvalue = *(x->x_rdata+(si*x->x_blocksize)+fi);
+ *(x->x_rdata+(si*x->x_blocksize)+fi) = *(x->x_rdata+(si*x->x_blocksize)+(ioperon-fi-1));
+ *(x->x_rdata+(si*x->x_blocksize)+(ioperon-fi-1)) = fvalue;
+ fvalue = *(x->x_idata+(si*x->x_blocksize)+fi);
+ *(x->x_idata+(si*x->x_blocksize)+fi) = *(x->x_idata+(si*x->x_blocksize)+(ioperon-fi-1));
+ *(x->x_idata+(si*x->x_blocksize)+(ioperon-fi-1)) = fvalue;
+ }
}
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* flip blocks */
+/* flip blocks */
static void sonogram_flipblocks(t_sonogram *x)
{
- t_int samplestart, sampleend, middlesample, fi, si;
- t_float fvalue;
+ t_int samplestart, sampleend, middlesample, fi, si;
+ t_float fvalue;
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
middlesample = ( sampleend+samplestart+1 ) / 2;
- for ( si=samplestart; si<=middlesample; si++ ) {
- for ( fi=0; fi<x->x_blocksize; fi++ ) {
- fvalue = *(x->x_rdata+((si)*x->x_blocksize)+fi);
- *(x->x_rdata+((si)*x->x_blocksize)+fi) = *(x->x_rdata+((sampleend+samplestart-si)*x->x_blocksize)+fi);
- *(x->x_rdata+((sampleend+samplestart-si)*x->x_blocksize)+fi) = fvalue;
- fvalue = *(x->x_idata+((si)*x->x_blocksize)+fi);
- *(x->x_idata+((si)*x->x_blocksize)+fi) = *(x->x_idata+((sampleend+samplestart-si)*x->x_blocksize)+fi);
- *(x->x_idata+((sampleend+samplestart-si)*x->x_blocksize)+fi) = fvalue;
- }
+ for ( si=samplestart; si<=middlesample; si++ )
+ {
+ for ( fi=0; fi<x->x_blocksize; fi++ )
+ {
+ fvalue = *(x->x_rdata+((si)*x->x_blocksize)+fi);
+ *(x->x_rdata+((si)*x->x_blocksize)+fi) = *(x->x_rdata+((sampleend+samplestart-si)*x->x_blocksize)+fi);
+ *(x->x_rdata+((sampleend+samplestart-si)*x->x_blocksize)+fi) = fvalue;
+ fvalue = *(x->x_idata+((si)*x->x_blocksize)+fi);
+ *(x->x_idata+((si)*x->x_blocksize)+fi) = *(x->x_idata+((sampleend+samplestart-si)*x->x_blocksize)+fi);
+ *(x->x_idata+((sampleend+samplestart-si)*x->x_blocksize)+fi) = fvalue;
+ }
}
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* undo if available */
+/* undo if available */
static void sonogram_undo(t_sonogram *x)
{
- t_int si,fi;
+ t_int si,fi;
if ( x->x_uxs == -1 )
{
- post( "sonogram~ : nothing to undo, man" );
- return;
+ post( "sonogram~ : nothing to undo, man" );
+ return;
}
post( "sonogram~ : restoring region [%d,%d,%d,%d]", x->x_uxs, x->x_uys, x->x_uxe, x->x_uye );
- for ( si=x->x_uxs; si<=x->x_uxe; si++ ) {
- for ( fi=x->x_uys; fi<=x->x_uye; fi++ ) {
- *(x->x_rdata+((si)*x->x_blocksize)+fi) = *(x->x_rudata+(si-x->x_uxs)*x->x_blocksize+(fi-x->x_uys));
- *(x->x_idata+((si)*x->x_blocksize)+fi) = *(x->x_iudata+(si-x->x_uxs)*x->x_blocksize+(fi-x->x_uys));
- }
+ for ( si=x->x_uxs; si<=x->x_uxe; si++ )
+ {
+ for ( fi=x->x_uys; fi<=x->x_uye; fi++ )
+ {
+ *(x->x_rdata+((si)*x->x_blocksize)+fi) = *(x->x_rudata+(si-x->x_uxs)*x->x_blocksize+(fi-x->x_uys));
+ *(x->x_idata+((si)*x->x_blocksize)+fi) = *(x->x_iudata+(si-x->x_uxs)*x->x_blocksize+(fi-x->x_uys));
+ }
}
sonogram_update_part(x, x->x_glist, x->x_uxs, x->x_uxe, 0, 1, 1);
}
- /* zswap exchanges real and imaginery part */
+/* zswap exchanges real and imaginery part */
static void sonogram_zswap(t_sonogram *x)
{
- t_int samplestart, sampleend, fi, si;
- t_float fvalue;
+ t_int samplestart, sampleend, fi, si;
+ t_float fvalue;
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
- for ( si=samplestart; si<=sampleend; si++ ) {
- for ( fi=0; fi<x->x_blocksize; fi++ ) {
- fvalue = *(x->x_rdata+(si*x->x_blocksize)+fi);
- *(x->x_rdata+(si*x->x_blocksize)+fi) = *(x->x_idata+(si*x->x_blocksize)+fi);
- *(x->x_idata+(si*x->x_blocksize)+fi) = fvalue;
- }
+ for ( si=samplestart; si<=sampleend; si++ )
+ {
+ for ( fi=0; fi<x->x_blocksize; fi++ )
+ {
+ fvalue = *(x->x_rdata+(si*x->x_blocksize)+fi);
+ *(x->x_rdata+(si*x->x_blocksize)+fi) = *(x->x_idata+(si*x->x_blocksize)+fi);
+ *(x->x_idata+(si*x->x_blocksize)+fi) = fvalue;
+ }
}
}
- /* swap points */
+/* swap points */
static void sonogram_swappoints(t_sonogram *x, t_floatarg fnbpoints)
{
- t_int samplestart, sampleend, sp;
- t_float s1, s2, f1, f2;
- t_float fvalue;
+ t_int samplestart, sampleend, sp;
+ t_float s1, s2, f1, f2;
+ t_float fvalue;
- if (fnbpoints <= 0) {
+ if (fnbpoints <= 0)
+ {
post( "sonogram~ : error : bad number of points" );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
-
- for ( sp=0; sp<fnbpoints; sp++ ) {
+
+ for ( sp=0; sp<fnbpoints; sp++ )
+ {
s1 = samplestart + (random()%(sampleend-samplestart));
s2 = samplestart + (random()%(sampleend-samplestart));
f1 = random()%( x->x_blocksize/2-1 );
@@ -1733,59 +1915,68 @@ static void sonogram_swappoints(t_sonogram *x, t_floatarg fnbpoints)
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* average blocks according to a factor */
+/* average blocks according to a factor */
static void sonogram_average(t_sonogram *x, t_floatarg fnbblocks)
{
- t_int samplestart, sampleend, fi, si, ssi;
- t_float fraverage, fiaverage;
+ t_int samplestart, sampleend, fi, si, ssi;
+ t_float fraverage, fiaverage;
- if (fnbblocks < 1) {
+ if (fnbblocks < 1)
+ {
post( "sonogram~ : error : bad average factor" );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
-
+
fraverage=fiaverage=0.0;
- for ( fi=0; fi<x->x_blocksize; fi++ ) {
- for ( si=samplestart; si<=sampleend-fnbblocks; si+=fnbblocks ) {
- fraverage=fiaverage=0.0;
- for ( ssi=0; ssi<fnbblocks; ssi++ ) {
- fraverage += *(x->x_rdata+((int)(si+ssi)*x->x_blocksize)+fi);
- fiaverage += *(x->x_idata+((int)(si+ssi)*x->x_blocksize)+fi);
- }
- fraverage /= fnbblocks;
- fiaverage /= fnbblocks;
- for ( ssi=0; ssi<fnbblocks; ssi++ ) {
- *(x->x_rdata+((int)(si+ssi)*x->x_blocksize)+fi)=fraverage;
- *(x->x_idata+((int)(si+ssi)*x->x_blocksize)+fi)=fiaverage;
- }
+ for ( fi=0; fi<x->x_blocksize; fi++ )
+ {
+ for ( si=samplestart; si<=sampleend-fnbblocks; si+=fnbblocks )
+ {
+ fraverage=fiaverage=0.0;
+ for ( ssi=0; ssi<fnbblocks; ssi++ )
+ {
+ fraverage += *(x->x_rdata+((int)(si+ssi)*x->x_blocksize)+fi);
+ fiaverage += *(x->x_idata+((int)(si+ssi)*x->x_blocksize)+fi);
+ }
+ fraverage /= fnbblocks;
+ fiaverage /= fnbblocks;
+ for ( ssi=0; ssi<fnbblocks; ssi++ )
+ {
+ *(x->x_rdata+((int)(si+ssi)*x->x_blocksize)+fi)=fraverage;
+ *(x->x_idata+((int)(si+ssi)*x->x_blocksize)+fi)=fiaverage;
+ }
}
}
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* go up by the given number */
+/* go up by the given number */
static void sonogram_goup(t_sonogram *x, t_floatarg fgoup)
{
- t_int samplestart, sampleend, sp, sf;
+ t_int samplestart, sampleend, sp, sf;
- if (fgoup <= 0 || fgoup > x->x_blocksize/2) {
+ if (fgoup <= 0 || fgoup > x->x_blocksize/2)
+ {
post( "sonogram~ : error : wrong offset in goup function" );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
-
- for ( sp=samplestart; sp<=sampleend; sp++ ) {
- for (sf=(x->x_blocksize/2)-fgoup-1; sf>=0; sf-- ) {
- *(x->x_rdata+((int)sp*x->x_blocksize)+(sf+(int)fgoup)) =
- *(x->x_rdata+((int)sp*x->x_blocksize)+sf);
- *(x->x_idata+((int)sp*x->x_blocksize)+(sf+(int)fgoup)) =
- *(x->x_idata+((int)sp*x->x_blocksize)+sf);
-
- }
- for (sf=0; sf<fgoup; sf++ ) {
+
+ for ( sp=samplestart; sp<=sampleend; sp++ )
+ {
+ for (sf=(x->x_blocksize/2)-fgoup-1; sf>=0; sf-- )
+ {
+ *(x->x_rdata+((int)sp*x->x_blocksize)+(sf+(int)fgoup)) =
+ *(x->x_rdata+((int)sp*x->x_blocksize)+sf);
+ *(x->x_idata+((int)sp*x->x_blocksize)+(sf+(int)fgoup)) =
+ *(x->x_idata+((int)sp*x->x_blocksize)+sf);
+
+ }
+ for (sf=0; sf<fgoup; sf++ )
+ {
*(x->x_rdata+((int)sp*x->x_blocksize)+(int)sf) = 0.0;
*(x->x_idata+((int)sp*x->x_blocksize)+(int)sf) = 0.0;
}
@@ -1793,47 +1984,54 @@ static void sonogram_goup(t_sonogram *x, t_floatarg fgoup)
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* roll up by the given number */
+/* roll up by the given number */
static void sonogram_roll(t_sonogram *x, t_floatarg froll)
{
- t_int samplestart, sampleend, sp, sf;
- t_float *fprvalues;
- t_float *fpivalues;
+ t_int samplestart, sampleend, sp, sf;
+ t_float *fprvalues;
+ t_float *fpivalues;
- if (froll <= 0 || froll > x->x_blocksize/2) {
+ if (froll <= 0 || froll > x->x_blocksize/2)
+ {
post( "sonogram~ : error : wrong offset in roll function" );
return;
}
fprvalues = (t_float*)getbytes( ((int)froll)*sizeof( float ) );
- if ( !fprvalues ) {
+ if ( !fprvalues )
+ {
post( "sonogram~ : error : could not allocate %d bytes", ((int)froll)*sizeof(float) );
return;
}
fpivalues = (t_float*)getbytes( ((int)froll)*sizeof( float ) );
- if ( !fpivalues ) {
+ if ( !fpivalues )
+ {
post( "sonogram~ : error : could not allocate %d bytes", ((int)froll)*sizeof(float) );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
-
- for ( sp=samplestart; sp<=sampleend; sp++ ) {
-
+
+ for ( sp=samplestart; sp<=sampleend; sp++ )
+ {
+
// saving values
- for (sf=0; sf<froll; sf++ ) {
- *(fprvalues+sf) =
- *(x->x_rdata+((int)sp*x->x_blocksize)+(x->x_blocksize/2-(int)froll+sf));
- *(fpivalues+sf) =
- *(x->x_idata+((int)sp*x->x_blocksize)+(x->x_blocksize/2-(int)froll+sf));
- }
- for (sf=(x->x_blocksize/2)-froll-1; sf>=0; sf-- ) {
- *(x->x_rdata+((int)sp*x->x_blocksize)+(sf+(int)froll)) =
- *(x->x_rdata+((int)sp*x->x_blocksize)+sf);
- *(x->x_idata+((int)sp*x->x_blocksize)+(sf+(int)froll)) =
- *(x->x_idata+((int)sp*x->x_blocksize)+sf);
- }
- for (sf=0; sf<froll; sf++ ) {
+ for (sf=0; sf<froll; sf++ )
+ {
+ *(fprvalues+sf) =
+ *(x->x_rdata+((int)sp*x->x_blocksize)+(x->x_blocksize/2-(int)froll+sf));
+ *(fpivalues+sf) =
+ *(x->x_idata+((int)sp*x->x_blocksize)+(x->x_blocksize/2-(int)froll+sf));
+ }
+ for (sf=(x->x_blocksize/2)-froll-1; sf>=0; sf-- )
+ {
+ *(x->x_rdata+((int)sp*x->x_blocksize)+(sf+(int)froll)) =
+ *(x->x_rdata+((int)sp*x->x_blocksize)+sf);
+ *(x->x_idata+((int)sp*x->x_blocksize)+(sf+(int)froll)) =
+ *(x->x_idata+((int)sp*x->x_blocksize)+sf);
+ }
+ for (sf=0; sf<froll; sf++ )
+ {
*(x->x_rdata+((int)sp*x->x_blocksize)+(int)sf) = *(fprvalues+sf);
*(x->x_idata+((int)sp*x->x_blocksize)+(int)sf) = *(fpivalues+sf);
}
@@ -1843,63 +2041,71 @@ static void sonogram_roll(t_sonogram *x, t_floatarg froll)
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* suppress point below the threshold */
+/* suppress point below the threshold */
static void sonogram_threshold(t_sonogram *x, t_floatarg fthreshold)
{
- t_int samplestart, sampleend, sp, sf;
- t_float fspectrum;
+ t_int samplestart, sampleend, sp, sf;
+ t_float fspectrum;
- if (fthreshold <= 0) {
+ if (fthreshold <= 0)
+ {
post( "sonogram~ : error : wrong threshold" );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
-
- for ( sp=samplestart; sp<=sampleend; sp++ ) {
- for (sf=0; sf<=(x->x_blocksize/2)-1; sf++ ) {
- fspectrum = sqrt( pow( *(x->x_rdata+sp*x->x_blocksize+sf), 2) +
- pow( *(x->x_idata+sp*x->x_blocksize+sf), 2) );
- if ( fspectrum < fthreshold )
- {
- *(x->x_rdata+sp*x->x_blocksize+sf) = 0.0;
- *(x->x_idata+sp*x->x_blocksize+sf) = 0.0;
- }
- }
+
+ for ( sp=samplestart; sp<=sampleend; sp++ )
+ {
+ for (sf=0; sf<=(x->x_blocksize/2)-1; sf++ )
+ {
+ fspectrum = sqrt( pow( *(x->x_rdata+sp*x->x_blocksize+sf), 2) +
+ pow( *(x->x_idata+sp*x->x_blocksize+sf), 2) );
+ if ( fspectrum < fthreshold )
+ {
+ *(x->x_rdata+sp*x->x_blocksize+sf) = 0.0;
+ *(x->x_idata+sp*x->x_blocksize+sf) = 0.0;
+ }
+ }
}
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* change the phase */
+/* change the phase */
static void sonogram_phase(t_sonogram *x, t_floatarg fincphase)
{
- if (fincphase < 0 || fincphase > 90) {
+ if (fincphase < 0 || fincphase > 90)
+ {
post( "sonogram~ : error : wrong phase in phase function : out of [0,90]" );
return;
}
x->x_phase = fincphase;
}
- /* go down by the given number */
+/* go down by the given number */
static void sonogram_godown(t_sonogram *x, t_floatarg fgodown)
{
- t_int samplestart, sampleend, sp, sf;
+ t_int samplestart, sampleend, sp, sf;
- if (fgodown <= 0 || fgodown > x->x_blocksize/2) {
+ if (fgodown <= 0 || fgodown > x->x_blocksize/2)
+ {
post( "sonogram~ : error : wrong offset in godown function" );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
-
- for ( sp=samplestart; sp<=sampleend; sp++ ) {
- for (sf=0; sf<=(x->x_blocksize/2)-fgodown-1; sf++ ) {
- *(x->x_rdata+((int)sp*x->x_blocksize)+sf) =
- *(x->x_rdata+((int)sp*x->x_blocksize)+(sf+(int)fgodown));
- *(x->x_idata+((int)sp*x->x_blocksize)+sf) =
- *(x->x_idata+((int)sp*x->x_blocksize)+(sf+(int)fgodown));
- }
- for (sf=(x->x_blocksize/2)-fgodown; sf<(x->x_blocksize/2); sf++ ) {
+
+ for ( sp=samplestart; sp<=sampleend; sp++ )
+ {
+ for (sf=0; sf<=(x->x_blocksize/2)-fgodown-1; sf++ )
+ {
+ *(x->x_rdata+((int)sp*x->x_blocksize)+sf) =
+ *(x->x_rdata+((int)sp*x->x_blocksize)+(sf+(int)fgodown));
+ *(x->x_idata+((int)sp*x->x_blocksize)+sf) =
+ *(x->x_idata+((int)sp*x->x_blocksize)+(sf+(int)fgodown));
+ }
+ for (sf=(x->x_blocksize/2)-fgodown; sf<(x->x_blocksize/2); sf++ )
+ {
*(x->x_rdata+((int)sp*x->x_blocksize)+(int)sf) = 0.0;
*(x->x_idata+((int)sp*x->x_blocksize)+(int)sf) = 0.0;
}
@@ -1907,23 +2113,24 @@ static void sonogram_godown(t_sonogram *x, t_floatarg fgodown)
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
}
- /* swap blocks */
+/* swap blocks */
static void sonogram_swapblocks(t_sonogram *x, t_floatarg fperstart, t_floatarg fperend, t_floatarg fpersize)
{
- t_int samplestart, samplestartb, samplesize, sp, sf;
- t_int iperstart, iperend, ipersize;
- t_float s1, s2;
- t_float fvalue;
+ t_int samplestart, samplestartb, samplesize, sp, sf;
+ t_int iperstart, iperend, ipersize;
+ t_float s1, s2;
+ t_float fvalue;
iperstart = fperstart;
iperend = fperend;
ipersize = fpersize;
if (iperstart < 0 || iperstart > iperend ||
- iperend <= 0 || iperend+ipersize > 100 ||
- ipersize < 0 || fpersize > 100 ) {
+ iperend <= 0 || iperend+ipersize > 100 ||
+ ipersize < 0 || fpersize > 100 )
+ {
post( "sonogram~ : error : wrong interval [%d%%, %d%%] <-> [%d%%, %d%%]",
- iperstart, iperstart+ipersize, iperend, iperend+ipersize );
+ iperstart, iperstart+ipersize, iperend, iperend+ipersize );
return;
}
@@ -1934,41 +2141,45 @@ static void sonogram_swapblocks(t_sonogram *x, t_floatarg fperstart, t_floatarg
samplestartb=samplestart+((samplestartb-samplestart)*iperend)/100;
post( "swap blocks [%d,%d] and [%d,%d]", samplestart, samplestart+samplesize, samplestartb, samplestartb+samplesize );
-
- for ( sp=samplesize; sp>=0; sp-- ) {
- for ( sf=0; sf<x->x_blocksize; sf++) {
- fvalue = *(x->x_rdata+((int)(samplestart+sp)*x->x_blocksize)+sf);
- *(x->x_rdata+((int)(samplestart+sp)*x->x_blocksize)+sf) = *(x->x_rdata+((int)(samplestartb+sp)*x->x_blocksize)+sf);
- *(x->x_rdata+((int)(samplestartb+sp)*x->x_blocksize)+sf) = fvalue;
- fvalue = *(x->x_idata+((int)(samplestart+sp)*x->x_blocksize)+sf);
- *(x->x_idata+((int)(samplestart+sp)*x->x_blocksize)+sf) = *(x->x_idata+((int)(samplestartb+sp)*x->x_blocksize)+sf);
- *(x->x_idata+((int)(samplestartb+sp)*x->x_blocksize)+sf) = fvalue;
+
+ for ( sp=samplesize; sp>=0; sp-- )
+ {
+ for ( sf=0; sf<x->x_blocksize; sf++)
+ {
+ fvalue = *(x->x_rdata+((int)(samplestart+sp)*x->x_blocksize)+sf);
+ *(x->x_rdata+((int)(samplestart+sp)*x->x_blocksize)+sf) = *(x->x_rdata+((int)(samplestartb+sp)*x->x_blocksize)+sf);
+ *(x->x_rdata+((int)(samplestartb+sp)*x->x_blocksize)+sf) = fvalue;
+ fvalue = *(x->x_idata+((int)(samplestart+sp)*x->x_blocksize)+sf);
+ *(x->x_idata+((int)(samplestart+sp)*x->x_blocksize)+sf) = *(x->x_idata+((int)(samplestartb+sp)*x->x_blocksize)+sf);
+ *(x->x_idata+((int)(samplestartb+sp)*x->x_blocksize)+sf) = fvalue;
}
}
sonogram_update_part(x, x->x_glist, 0, x->x_size-1, 0, 1, 1);
}
- /* swap frequencies */
+/* swap frequencies */
static void sonogram_swapfreqs(t_sonogram *x, t_floatarg ffirstfreq, t_floatarg fsecondfreq)
{
- t_int samplestart, sampleend, sp;
- t_float fvalue;
+ t_int samplestart, sampleend, sp;
+ t_float fvalue;
- if (ffirstfreq < 0 || fsecondfreq <0) {
+ if (ffirstfreq < 0 || fsecondfreq <0)
+ {
post( "sonogram~ : error : wrong frequencies" );
return;
}
samplestart=(x->x_modstart*(x->x_size-1))/100;
sampleend=(x->x_modend*(x->x_size-1))/100;
-
- for ( sp=samplestart; sp<=sampleend; sp++ ) {
+
+ for ( sp=samplestart; sp<=sampleend; sp++ )
+ {
fvalue = *(x->x_rdata+((int)sp*x->x_blocksize)+(int)ffirstfreq);
- *(x->x_rdata+((int)sp*x->x_blocksize)+(int)ffirstfreq) =
- *(x->x_rdata+((int)sp*x->x_blocksize)+(int)fsecondfreq);
+ *(x->x_rdata+((int)sp*x->x_blocksize)+(int)ffirstfreq) =
+ *(x->x_rdata+((int)sp*x->x_blocksize)+(int)fsecondfreq);
*(x->x_rdata+((int)sp*x->x_blocksize)+(int)fsecondfreq) = fvalue;
fvalue = *(x->x_idata+((int)sp*x->x_blocksize)+(int)ffirstfreq);
- *(x->x_idata+((int)sp*x->x_blocksize)+(int)ffirstfreq) =
- *(x->x_idata+((int)sp*x->x_blocksize)+(int)fsecondfreq);
+ *(x->x_idata+((int)sp*x->x_blocksize)+(int)ffirstfreq) =
+ *(x->x_idata+((int)sp*x->x_blocksize)+(int)fsecondfreq);
*(x->x_idata+((int)sp*x->x_blocksize)+(int)fsecondfreq) = fvalue;
}
sonogram_update_part(x, x->x_glist, samplestart, sampleend, 0, 1, 1);
@@ -1987,19 +2198,20 @@ static void *sonogram_new(t_floatarg fsize, t_floatarg fgraphic, t_floatarg fpha
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("modstart"));
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("modend"));
- if ( fsize <= 0 || ( fgraphic != 0 && fgraphic != 1 ) || ( fphaso != 0 && fphaso != 1 ) ) {
- error( "sonogram~ : missing or negative creation arguments" );
- return NULL;
+ if ( fsize <= 0 || ( fgraphic != 0 && fgraphic != 1 ) || ( fphaso != 0 && fphaso != 1 ) )
+ {
+ error( "sonogram~ : missing or negative creation arguments" );
+ return NULL;
}
// activate graphical callbacks
- if ( fgraphic != 0 )
+ if ( fgraphic != 0 )
{
- class_setwidget(sonogram_class, &sonogram_widgetbehavior);
+ class_setwidget(sonogram_class, &sonogram_widgetbehavior);
}
x->x_graphic = (int) fgraphic;
x->x_phaso = (int) fphaso;
-
+
x->x_size = fsize;
x->x_blocksize = sys_getblksize();
x->x_play = 0;
@@ -2026,10 +2238,13 @@ static void *sonogram_new(t_floatarg fsize, t_floatarg fgraphic, t_floatarg fpha
x->x_enhancemode = 0;
x->x_glist = (t_glist*)canvas_getcurrent();
- if ( sonogram_allocate(x) <0 ) {
- return NULL;
- } else {
- return(x);
+ if ( sonogram_allocate(x) <0 )
+ {
+ return NULL;
+ }
+ else
+ {
+ return(x);
}
}
@@ -2038,7 +2253,7 @@ void sonogram_tilde_setup(void)
{
verbose(0, sonogram_version);
sonogram_class = class_new(gensym("sonogram~"), (t_newmethod)sonogram_new, (t_method)sonogram_free,
- sizeof(t_sonogram), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ sizeof(t_sonogram), 0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
// set callbacks
diff --git a/speexin~.c b/speexin~.c
index 310e028..60a441f 100644
--- a/speexin~.c
+++ b/speexin~.c
@@ -25,7 +25,7 @@
/* be found at http://speex.sourceforge.net. */
/* */
/* ---------------------------------------------------------------------------- */
-
+
#include <m_pd.h>
#include <g_canvas.h>
@@ -89,11 +89,11 @@ void speexin_closesocket(int fd)
#ifndef _WIN32
if ( close(fd) < 0 )
{
- perror( "close" );
+ perror( "close" );
}
else
{
- post( "speexin~ : closed socket : %d", fd );
+ post( "speexin~ : closed socket : %d", fd );
}
#endif
#ifdef _WIN32
@@ -103,33 +103,33 @@ void speexin_closesocket(int fd)
}
int setsocketoptions(int sockfd)
-{
- int sockopt = 1;
- if (setsockopt(sockfd, SOL_TCP, TCP_NODELAY, (const char*) &sockopt, sizeof(int)) < 0)
- {
- post("speexin~ : setsockopt TCP_NODELAY failed");
- perror( "setsockopt" );
- return -1;
- }
- else
- {
- post("speexin~ : TCP_NODELAY set");
- }
-
+{
+ int sockopt = 1;
+ if (setsockopt(sockfd, SOL_TCP, TCP_NODELAY, (const char*) &sockopt, sizeof(int)) < 0)
+ {
+ post("speexin~ : setsockopt TCP_NODELAY failed");
+ perror( "setsockopt" );
+ return -1;
+ }
+ else
+ {
+ post("speexin~ : TCP_NODELAY set");
+ }
+
#ifdef _WIN32
- sockopt = 1;
- if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(int)) < 0)
- {
- post("speexin~ : setsockopt SO_REUSEADDR failed");
- perror( "setsockopt" );
- return -1;
- }
- else
- {
- post("speexin~ : setsockopt SO_REUSEADDR done.");
- }
+ sockopt = 1;
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(int)) < 0)
+ {
+ post("speexin~ : setsockopt SO_REUSEADDR failed");
+ perror( "setsockopt" );
+ return -1;
+ }
+ else
+ {
+ post("speexin~ : setsockopt SO_REUSEADDR done.");
+ }
#endif
- return 0;
+ return 0;
}
@@ -139,62 +139,62 @@ static t_class *speexin_class;
typedef struct _speexin
{
- t_object x_obj;
- t_int x_socket;
- t_outlet *x_connectionip;
- t_int x_serversocket;
- t_int x_samplerate;
-
- /* Speex stuff */
- SpeexBits x_bits; /* bits packing structure */
- void *x_decstate; /* decoder state */
- t_int x_framesize; /* frame size */
- t_int x_mode; /* Narrow or Wide Band */
- int x_quality; /* encoding quality ( 0 to 10 ) */
-
- t_int x_inpackets; /* number of packets received */
- t_int x_dpacket; /* displayed packet in status bar */
- t_int x_packetsize; /* size of the packets */
- t_int x_pblocks; /* processed blocks */
- t_int x_graphic; /* indicates if we show a graphic bar */
-
- void *x_inbuffer; /* accumulation buffer for incoming speex frames */
- t_int x_inwritepos; /* accumulation buffer for incoming speex frames */
- t_int x_encsize;
- t_int x_inbuffersize;
-
- t_float *x_outbuffer; /* buffer to store audio decoded data */
- t_int x_oinp;
- t_int x_ooutp;
- t_int x_outunread;
- t_int x_outbuffersize;
- t_float *x_decchunk;
-
- t_canvas *x_canvas;
-
- t_int x_stream; /* indicates if a stream is connected ( meaning correct input flow ) */
- t_int x_newstream; /* at first, the stream must provide enough data to start */
+ t_object x_obj;
+ t_int x_socket;
+ t_outlet *x_connectionip;
+ t_int x_serversocket;
+ t_int x_samplerate;
+
+ /* Speex stuff */
+ SpeexBits x_bits; /* bits packing structure */
+ void *x_decstate; /* decoder state */
+ t_int x_framesize; /* frame size */
+ t_int x_mode; /* Narrow or Wide Band */
+ int x_quality; /* encoding quality ( 0 to 10 ) */
+
+ t_int x_inpackets; /* number of packets received */
+ t_int x_dpacket; /* displayed packet in status bar */
+ t_int x_packetsize; /* size of the packets */
+ t_int x_pblocks; /* processed blocks */
+ t_int x_graphic; /* indicates if we show a graphic bar */
+
+ void *x_inbuffer; /* accumulation buffer for incoming speex frames */
+ t_int x_inwritepos; /* accumulation buffer for incoming speex frames */
+ t_int x_encsize;
+ t_int x_inbuffersize;
+
+ t_float *x_outbuffer; /* buffer to store audio decoded data */
+ t_int x_oinp;
+ t_int x_ooutp;
+ t_int x_outunread;
+ t_int x_outbuffersize;
+ t_float *x_decchunk;
+
+ t_canvas *x_canvas;
+
+ t_int x_stream; /* indicates if a stream is connected ( meaning correct input flow ) */
+ t_int x_newstream; /* at first, the stream must provide enough data to start */
} t_speexin;
void speexin_tilde_speex_init(t_speexin *x)
{
- int ret;
- int pf=1;
+ int ret;
+ int pf=1;
speex_bits_init(&x->x_bits);
switch ( x->x_mode )
{
- case SPEEX_NB_MODE :
+ case SPEEX_NB_MODE :
x->x_decstate = speex_decoder_init(&speex_nb_mode);
break;
- case SPEEX_WB_MODE :
+ case SPEEX_WB_MODE :
x->x_decstate = speex_decoder_init(&speex_wb_mode);
break;
-
- default :
+
+ default :
error( "speexin~ : severe error : decoding scheme is unknown" );
break;
}
@@ -209,145 +209,145 @@ void speexin_tilde_speex_init(t_speexin *x)
static void speexin_decode_input(t_speexin *x)
{
- int i;
- int alength = 0;
- static char out[8192];
- signed short int *p = (signed short int *) out;
- int pbytes;
- int ret;
- int flength = 0;
-
- if ( x->x_encsize > 0 )
- {
-
- while ( x->x_encsize > *(char *)(x->x_inbuffer) )
+ int i;
+ int alength = 0;
+ static char out[8192];
+ signed short int *p = (signed short int *) out;
+ int pbytes;
+ int ret;
+ int flength = 0;
+
+ if ( x->x_encsize > 0 )
{
- flength = *(char *)(x->x_inbuffer );
+ while ( x->x_encsize > *(char *)(x->x_inbuffer) )
+ {
+
+ flength = *(char *)(x->x_inbuffer );
- // post( "speexin~ : reading bits from 1 to : %d", flength+1 );
- speex_bits_read_from(&x->x_bits, x->x_inbuffer+1, flength);
+ // post( "speexin~ : reading bits from 1 to : %d", flength+1 );
+ speex_bits_read_from(&x->x_bits, x->x_inbuffer+1, flength);
#ifdef DATADEBUG
- {
- t_int si;
-
- printf( "speexin~ : decoding : " );
- for ( si=0; si<flength; si++ )
- {
- printf( "%d ", *(char *)(x->x_inbuffer+1+si) );
- }
- printf( "\n" );
- }
+ {
+ t_int si;
+
+ printf( "speexin~ : decoding : " );
+ for ( si=0; si<flength; si++ )
+ {
+ printf( "%d ", *(char *)(x->x_inbuffer+1+si) );
+ }
+ printf( "\n" );
+ }
#endif
- {
- t_int sp=0, rp=0;
-
- speex_decode(x->x_decstate, &x->x_bits, x->x_decchunk);
-
- while( sp < x->x_framesize )
- {
- rp=(x->x_oinp+sp)%x->x_outbuffersize;
- // if ( rp == x->x_outbuffersize - 1 ) post( "speexin~ : write at the end of audio buffer" );
- // post( "speexin~ : sp=%d : rp=%d", sp, rp );
- x->x_outbuffer[ rp ] = x->x_decchunk[sp++];
- }
- x->x_oinp = rp+1;
- }
- x->x_outunread += x->x_framesize;
- memcpy( x->x_inbuffer, x->x_inbuffer+flength+1, x->x_inbuffersize-flength-1 );
- x->x_encsize -= flength+1;
- x->x_inwritepos -= flength+1;
+ {
+ t_int sp=0, rp=0;
+
+ speex_decode(x->x_decstate, &x->x_bits, x->x_decchunk);
+
+ while( sp < x->x_framesize )
+ {
+ rp=(x->x_oinp+sp)%x->x_outbuffersize;
+ // if ( rp == x->x_outbuffersize - 1 ) post( "speexin~ : write at the end of audio buffer" );
+ // post( "speexin~ : sp=%d : rp=%d", sp, rp );
+ x->x_outbuffer[ rp ] = x->x_decchunk[sp++];
+ }
+ x->x_oinp = rp+1;
+ }
+ x->x_outunread += x->x_framesize;
+ memcpy( x->x_inbuffer, x->x_inbuffer+flength+1, x->x_inbuffersize-flength-1 );
+ x->x_encsize -= flength+1;
+ x->x_inwritepos -= flength+1;
- }
+ }
- }
+ }
- if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
- {
- /* update graphical read status */
- if ( x->x_inpackets != x->x_dpacket )
- {
- char color[32];
- int minpackets = ( MIN_AUDIO_INPUT/x->x_framesize)-2; // audio loop has eaten some already
+ if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
+ {
+ /* update graphical read status */
+ if ( x->x_inpackets != x->x_dpacket )
+ {
+ char color[32];
+ int minpackets = ( MIN_AUDIO_INPUT/x->x_framesize)-2; // audio loop has eaten some already
sys_vgui(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x );
sys_vgui(".x%lx.c delete line %xTHRESHOLD\n", x->x_canvas, x );
if ( x->x_outunread > 0 )
{
- t_int width;
-
- if ( x->x_inpackets < (MIN_AUDIO_INPUT/x->x_framesize)/2 )
- {
- strcpy( color, "red" );
- }
- else
- {
- strcpy( color, "lightgreen" );
- }
- width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
- sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xSTATUS\n",
- x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
- x->x_obj.te_xpix+(x->x_inpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
- x->x_obj.te_ypix - 1, color, x );
- sys_vgui(".x%lx.c create line %d %d %d %d -fill red -tags %xTHRESHOLD\n",
- x->x_canvas, x->x_obj.te_xpix+(minpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
- x->x_obj.te_ypix-BARHEIGHT-1,
- x->x_obj.te_xpix+(minpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
- x->x_obj.te_ypix-1, x );
- x->x_dpacket = x->x_inpackets;
+ t_int width;
+
+ if ( x->x_inpackets < (MIN_AUDIO_INPUT/x->x_framesize)/2 )
+ {
+ strcpy( color, "red" );
+ }
+ else
+ {
+ strcpy( color, "lightgreen" );
+ }
+ width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill %s -tags %xSTATUS\n",
+ x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
+ x->x_obj.te_xpix+(x->x_inpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
+ x->x_obj.te_ypix - 1, color, x );
+ sys_vgui(".x%lx.c create line %d %d %d %d -fill red -tags %xTHRESHOLD\n",
+ x->x_canvas, x->x_obj.te_xpix+(minpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
+ x->x_obj.te_ypix-BARHEIGHT-1,
+ x->x_obj.te_xpix+(minpackets*x->x_packetsize*width)/INPUT_BUFFER_SIZE,
+ x->x_obj.te_ypix-1, x );
+ x->x_dpacket = x->x_inpackets;
}
- }
+ }
- }
+ }
}
static void speexin_recv(t_speexin *x)
{
- int ret;
+ int ret;
- if ( x->x_inwritepos > x->x_inbuffersize - 1024 )
- {
+ if ( x->x_inwritepos > x->x_inbuffersize - 1024 )
+ {
post( "speexin~ : input buffer is full" );
return;
- }
- if ( ( ret = recv(x->x_socket, (void*) x->x_inbuffer + x->x_inwritepos,
- (size_t)x->x_inbuffersize,
- MSG_NOSIGNAL) ) < 0 )
- {
+ }
+ if ( ( ret = recv(x->x_socket, (void*) x->x_inbuffer + x->x_inwritepos,
+ (size_t)x->x_inbuffersize,
+ MSG_NOSIGNAL) ) < 0 )
+ {
post( "speexin~ : receive error" );
perror( "recv" );
- return;
- }
- else
- {
- // post( "speexin~ : received %d bytes at %d on %d ( up to %d)",
+ return;
+ }
+ else
+ {
+ // post( "speexin~ : received %d bytes at %d on %d ( up to %d)",
// ret, x->x_inwritepos, x->x_socket,
// x->x_inbuffersize );
- if ( ret == 0 )
+ if ( ret == 0 )
{
- post( "speexin~ : closing connection ( s=%d )", x->x_socket );
- speexin_closesocket(x->x_socket);
- x->x_socket = -1;
- sys_vgui(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
- sys_vgui(".x%lx.c delete line %xTHRESHOLD\n", x->x_canvas, x );
- sys_vgui(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x );
- outlet_symbol( x->x_connectionip, gensym("") );
+ post( "speexin~ : closing connection ( s=%d )", x->x_socket );
+ speexin_closesocket(x->x_socket);
+ x->x_socket = -1;
+ sys_vgui(".x%lx.c delete rectangle %xPBAR\n", x->x_canvas, x );
+ sys_vgui(".x%lx.c delete line %xTHRESHOLD\n", x->x_canvas, x );
+ sys_vgui(".x%lx.c delete rectangle %xSTATUS\n", x->x_canvas, x );
+ outlet_symbol( x->x_connectionip, gensym("") );
}
else
- {
- x->x_inpackets++;
+ {
+ x->x_inpackets++;
}
x->x_encsize += ret;
x->x_inwritepos += ret;
-
+
speexin_decode_input(x);
- }
+ }
}
static void speexin_acceptconnection(t_speexin *x)
@@ -358,15 +358,17 @@ static void speexin_acceptconnection(t_speexin *x)
int fd = accept(x->x_serversocket, (struct sockaddr*)&incomer_address, &sockaddrl );
post("speexin~: accepted incomer : %d.", fd );
- if (fd < 0) {
- post("speexin~: accept failed");
- return;
+ if (fd < 0)
+ {
+ post("speexin~: accept failed");
+ return;
}
- if (x->x_socket > 0) {
- post("speexin~: the source has changed to %s ( new socket = %d ).",
- inet_ntoa( incomer_address.sin_addr ), fd );
- speexin_closesocket(x->x_socket);
+ if (x->x_socket > 0)
+ {
+ post("speexin~: the source has changed to %s ( new socket = %d ).",
+ inet_ntoa( incomer_address.sin_addr ), fd );
+ speexin_closesocket(x->x_socket);
}
x->x_socket = fd;
@@ -375,12 +377,12 @@ static void speexin_acceptconnection(t_speexin *x)
if ( x->x_graphic && glist_isvisible( x->x_canvas ) )
{
- t_int width;
-
- width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
- sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill lightblue -tags %xPBAR\n",
- x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
- x->x_obj.te_xpix + width, x->x_obj.te_ypix - 1, x );
+ t_int width;
+
+ width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) );
+ sys_vgui(".x%lx.c create rectangle %d %d %d %d -fill lightblue -tags %xPBAR\n",
+ x->x_canvas, x->x_obj.te_xpix, x->x_obj.te_ypix-BARHEIGHT-1,
+ x->x_obj.te_xpix + width, x->x_obj.te_ypix - 1, x );
}
x->x_stream = 0;
x->x_newstream = 1;
@@ -398,8 +400,8 @@ static int speexin_startservice(t_speexin* x, int portno)
if (sockfd < 0)
{
- sys_sockerror("socket");
- return (0);
+ sys_sockerror("socket");
+ return (0);
}
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
@@ -411,118 +413,122 @@ static int speexin_startservice(t_speexin* x, int portno)
setsocketoptions(sockfd);
/* name the socket */
- if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0) {
- sys_sockerror("bind");
- speexin_closesocket(sockfd);
- return (0);
+ if (bind(sockfd, (struct sockaddr *)&server, sizeof(server)) < 0)
+ {
+ sys_sockerror("bind");
+ speexin_closesocket(sockfd);
+ return (0);
}
- if (listen(sockfd, 5) < 0) {
- sys_sockerror("listen");
- speexin_closesocket(sockfd);
+ if (listen(sockfd, 5) < 0)
+ {
+ sys_sockerror("listen");
+ speexin_closesocket(sockfd);
}
- else
+ else
{
- x->x_serversocket = sockfd;
- sys_addpollfn(x->x_serversocket, (t_fdpollfn)speexin_acceptconnection, x);
+ x->x_serversocket = sockfd;
+ sys_addpollfn(x->x_serversocket, (t_fdpollfn)speexin_acceptconnection, x);
}
-
+
return 1;
}
static void speexin_free(t_speexin *x)
{
- post( "speexin~ : free %x", x );
- if (x->x_serversocket > 0) {
+ post( "speexin~ : free %x", x );
+ if (x->x_serversocket > 0)
+ {
post( "speexin~ : closing server socket" );
- speexin_closesocket(x->x_serversocket);
+ speexin_closesocket(x->x_serversocket);
x->x_serversocket = -1;
- }
- if (x->x_socket > 0) {
+ }
+ if (x->x_socket > 0)
+ {
post( "speexin~ : closing socket" );
speexin_closesocket(x->x_socket);
x->x_socket = -1;
- }
- if ( x->x_inbuffer ) freebytes( x->x_inbuffer, x->x_inbuffersize );
- if ( x->x_outbuffer ) freebytes( x->x_outbuffer, x->x_outbuffersize*sizeof(t_float) );
- if ( x->x_decchunk ) freebytes(x->x_decchunk, x->x_framesize*sizeof(t_float));
+ }
+ if ( x->x_inbuffer ) freebytes( x->x_inbuffer, x->x_inbuffersize );
+ if ( x->x_outbuffer ) freebytes( x->x_outbuffer, x->x_outbuffersize*sizeof(t_float) );
+ if ( x->x_decchunk ) freebytes(x->x_decchunk, x->x_framesize*sizeof(t_float));
}
static t_int *speexin_perform(t_int *w)
{
- t_speexin *x = (t_speexin*) (w[1]);
- t_float *out = (t_float *)(w[2]);
- t_int n = (int)(w[3]);
- t_int bsize = n;
- t_int ret;
- t_int i = 0;
- t_int j = 0;
- t_int sp = 0;
- t_int sratio;
-
- // samplerate is supposed to be above 16kHz, thus sratio>1
- if ( x->x_mode == SPEEX_NB_MODE )
- {
- sratio = x->x_samplerate / 8000;
- }
- else
- {
- sratio = x->x_samplerate / 16000;
- }
- // post( "speexin~ : ratio : %d", sratio );
-
- memset( out, 0x0, n*sizeof(t_float ) );
-
- sp = 0;
- while( sp < n )
- {
- if ( ( ( x->x_outunread > MIN_AUDIO_INPUT ) && x->x_newstream ) || // wait the buffer to load
- ( x->x_stream ) // check that the stream provides enough data
- )
- {
+ t_speexin *x = (t_speexin*) (w[1]);
+ t_float *out = (t_float *)(w[2]);
+ t_int n = (int)(w[3]);
+ t_int bsize = n;
+ t_int ret;
+ t_int i = 0;
+ t_int j = 0;
+ t_int sp = 0;
+ t_int sratio;
+
+ // samplerate is supposed to be above 16kHz, thus sratio>1
+ if ( x->x_mode == SPEEX_NB_MODE )
+ {
+ sratio = x->x_samplerate / 8000;
+ }
+ else
+ {
+ sratio = x->x_samplerate / 16000;
+ }
+ // post( "speexin~ : ratio : %d", sratio );
+
+ memset( out, 0x0, n*sizeof(t_float ) );
+
+ sp = 0;
+ while( sp < n )
+ {
+ if ( ( ( x->x_outunread > MIN_AUDIO_INPUT ) && x->x_newstream ) || // wait the buffer to load
+ ( x->x_stream ) // check that the stream provides enough data
+ )
+ {
if ( x->x_newstream )
{
- x->x_newstream = 0;
- x->x_stream = 1;
+ x->x_newstream = 0;
+ x->x_stream = 1;
}
/* resampling */
for ( j=0; j<sratio; j++ )
- {
- *(out+sp)=*(x->x_outbuffer+x->x_ooutp)/8000; // input has been scaled
- //*(x->x_outbuffer+x->x_ooutp)=0.0; // data read, now zeroed
- sp++;
- if ( sp >= n ) break;
+ {
+ *(out+sp)=*(x->x_outbuffer+x->x_ooutp)/8000; // input has been scaled
+ //*(x->x_outbuffer+x->x_ooutp)=0.0; // data read, now zeroed
+ sp++;
+ if ( sp >= n ) break;
}
x->x_ooutp = (x->x_ooutp + 1)%x->x_outbuffersize;
// if ( x->x_ooutp == x->x_outbuffersize - 1 ) post( "speexin~ : end of audio buffer" );
x->x_outunread-=1;
- }
- else
- {
+ }
+ else
+ {
for ( j=0; j<sratio; j++ )
- {
- *(out+sp)=0.0;
- sp++;
- if ( sp >= n ) break;
+ {
+ *(out+sp)=0.0;
+ sp++;
+ if ( sp >= n ) break;
}
- }
- }
- x->x_pblocks++;
-
- if ( ( x->x_outunread <= MIN_AUDIO_INPUT/10 ) && ( x->x_stream ) )
- {
- // post( "speexin~ : stream lost (too little input)" );
- x->x_stream = 0;
- x->x_newstream = 1; // waiting for a new stream
- }
-
- if ( x->x_pblocks == x->x_framesize/bsize )
- {
+ }
+ }
+ x->x_pblocks++;
+
+ if ( ( x->x_outunread <= MIN_AUDIO_INPUT/10 ) && ( x->x_stream ) )
+ {
+ // post( "speexin~ : stream lost (too little input)" );
+ x->x_stream = 0;
+ x->x_newstream = 1; // waiting for a new stream
+ }
+
+ if ( x->x_pblocks == x->x_framesize/bsize )
+ {
x->x_inpackets--;
x->x_pblocks = 0;
- }
+ }
- return (w+4);
+ return (w+4);
}
static void speexin_dsp(t_speexin *x, t_signal **sp)
@@ -535,22 +541,22 @@ static void *speexin_new(t_floatarg fportno, t_floatarg fdographics)
{
t_speexin *x;
int i;
-
+
if ( fportno < 0 || fportno > 65535 )
{
- post( "speexin~ : error : wrong portnumber : %d", (int)fportno );
- return NULL;
+ post( "speexin~ : error : wrong portnumber : %d", (int)fportno );
+ return NULL;
}
if ( ((int)fdographics != 0) && ((int)fdographics != 1.) )
{
- post( "speexin~ : error : constructor : speexin~ <portnumber> [graphic flag = 0 | 1 ] ( got = %f)", fdographics );
- return NULL;
+ post( "speexin~ : error : constructor : speexin~ <portnumber> [graphic flag = 0 | 1 ] ( got = %f)", fdographics );
+ return NULL;
}
x = (t_speexin *)pd_new(speexin_class);
outlet_new(&x->x_obj, &s_signal);
x->x_connectionip = outlet_new(&x->x_obj, &s_symbol);
-
+
x->x_serversocket = -1;
x->x_socket = -1;
x->x_inpackets = 0;
@@ -562,7 +568,7 @@ static void *speexin_new(t_floatarg fportno, t_floatarg fdographics)
x->x_canvas = canvas_getcurrent();
x->x_inbuffersize = INPUT_BUFFER_SIZE;
- x->x_outbuffersize = OUTPUT_BUFFER_SIZE;
+ x->x_outbuffersize = OUTPUT_BUFFER_SIZE;
x->x_inbuffer = (char*) getbytes( x->x_inbuffersize );
memset( x->x_inbuffer, 0x0, INPUT_BUFFER_SIZE );
x->x_outbuffer = (t_float*) getbytes( x->x_outbuffersize*sizeof(t_float) );
@@ -570,14 +576,14 @@ static void *speexin_new(t_floatarg fportno, t_floatarg fdographics)
if ( !x->x_inbuffer || !x->x_outbuffer )
{
- post( "speexin~ : could not allocate buffers." );
- return NULL;
+ post( "speexin~ : could not allocate buffers." );
+ return NULL;
}
x->x_encsize = 0;
x->x_oinp = 0;
x->x_ooutp = 0;
-
+
ztout.tv_sec = 0;
ztout.tv_usec = 0;
@@ -603,9 +609,9 @@ static void *speexin_new(t_floatarg fportno, t_floatarg fdographics)
void speexin_tilde_setup(void)
{
verbose(0, speexin_version );
- speexin_class = class_new(gensym("speexin~"),
- (t_newmethod) speexin_new, (t_method) speexin_free,
- sizeof(t_speexin), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT, A_NULL);
+ speexin_class = class_new(gensym("speexin~"),
+ (t_newmethod) speexin_new, (t_method) speexin_free,
+ sizeof(t_speexin), CLASS_NOINLET, A_DEFFLOAT, A_DEFFLOAT, A_NULL);
class_addmethod(speexin_class, nullfn, gensym("signal"), 0);
class_addmethod(speexin_class, (t_method) speexin_dsp, gensym("dsp"), 0);
diff --git a/speexout~.c b/speexout~.c
index 10f335b..67752f6 100644
--- a/speexout~.c
+++ b/speexout~.c
@@ -66,8 +66,8 @@
#define MSG_NOSIGNAL 0
#endif
-#include <speex/speex.h> /* speex codec stuff */
-#include <speex/speex_bits.h> /* speex codec stuff */
+#include <speex/speex.h> /* speex codec stuff */
+#include <speex/speex_bits.h> /* speex codec stuff */
#include "m_pd.h" /* standard pd stuff */
@@ -90,14 +90,14 @@ typedef struct _speexout
t_object x_obj;
int x_samplerate; /* pd sampling rate */
- /* Speex stuff */
+ /* Speex stuff */
SpeexBits x_bits; /* bits packing structure */
void *x_encstate; /* encoder state */
t_int x_framesize; /* frame size */
t_int x_mode; /* Narrow or Wide Band */
int x_quality; /* encoding quality ( 0 to 10 ) */
- /* buffer stuff */
+ /* buffer stuff */
unsigned short x_inp; /* in position for buffer */
unsigned short x_outp; /* out position for buffer */
t_int x_encsize; /* size of encoded data */
@@ -108,7 +108,7 @@ typedef struct _speexout
int x_start;
t_float *x_encchunk;
- /* connection data */
+ /* connection data */
int x_fd; /* info about connection status */
int x_outpackets; /* speex packets sent */
@@ -117,132 +117,132 @@ typedef struct _speexout
} t_speexout;
- /* encode PCM data to speex frames */
+/* encode PCM data to speex frames */
static void speexout_encode(t_speexout *x)
{
if ( x->x_bytesbuffered > x->x_framesize )
{
- speex_bits_reset(&x->x_bits);
-
- {
- t_int sp=0, rp=0;
-
- while( sp < x->x_framesize )
- {
- rp=(x->x_outp+sp)%IN_BUFFER_SIZE;
- // post( "speexout~ : sp=%d : rp=%d", sp, rp );
- x->x_encchunk[ sp++ ] = *(x->x_inbuf+rp);
- }
- speex_encode(x->x_encstate, x->x_encchunk, &x->x_bits);
- }
-
- x->x_outp = (x->x_outp+x->x_framesize)%IN_BUFFER_SIZE;
- x->x_bytesbuffered -= x->x_framesize;
- x->x_encsize = speex_bits_write(&x->x_bits, x->x_outbuf+1, OUT_BUFFER_SIZE );
- if ( x->x_encsize < 127 )
- {
- *(x->x_outbuf) = (char)x->x_encsize;
- }
- else
- {
- post( "speexout~ : encoding error : frame is more than 127 bytes" );
- x->x_encsize = -1;
- }
- x->x_bytesemitted += x->x_encsize;
+ speex_bits_reset(&x->x_bits);
+
+ {
+ t_int sp=0, rp=0;
+
+ while( sp < x->x_framesize )
+ {
+ rp=(x->x_outp+sp)%IN_BUFFER_SIZE;
+ // post( "speexout~ : sp=%d : rp=%d", sp, rp );
+ x->x_encchunk[ sp++ ] = *(x->x_inbuf+rp);
+ }
+ speex_encode(x->x_encstate, x->x_encchunk, &x->x_bits);
+ }
+
+ x->x_outp = (x->x_outp+x->x_framesize)%IN_BUFFER_SIZE;
+ x->x_bytesbuffered -= x->x_framesize;
+ x->x_encsize = speex_bits_write(&x->x_bits, x->x_outbuf+1, OUT_BUFFER_SIZE );
+ if ( x->x_encsize < 127 )
+ {
+ *(x->x_outbuf) = (char)x->x_encsize;
+ }
+ else
+ {
+ post( "speexout~ : encoding error : frame is more than 127 bytes" );
+ x->x_encsize = -1;
+ }
+ x->x_bytesemitted += x->x_encsize;
#ifdef DATADEBUG
- {
- t_int si;
-
- printf( "speexout~ : encoded : " );
- for ( si=0; si<x->x_encsize; si++ )
- {
- printf( "%d ", *(x->x_outbuf+si) );
- }
- printf( "\n" );
- }
+ {
+ t_int si;
+
+ printf( "speexout~ : encoded : " );
+ for ( si=0; si<x->x_encsize; si++ )
+ {
+ printf( "%d ", *(x->x_outbuf+si) );
+ }
+ printf( "\n" );
+ }
#endif
}
else
{
- x->x_encsize = -1;
+ x->x_encsize = -1;
}
}
- /* stream data to the peer */
+/* stream data to the peer */
static void speexout_stream(t_speexout *x)
{
- int count = -1, i;
+ int count = -1, i;
- if ( x->x_encsize > 0 )
- {
- count = send(x->x_fd, x->x_outbuf, x->x_encsize+1, MSG_NOSIGNAL);
- if(count < 0)
+ if ( x->x_encsize > 0 )
{
- error("speexout~: could not send encoded data to the peer (%d)", count);
+ count = send(x->x_fd, x->x_outbuf, x->x_encsize+1, MSG_NOSIGNAL);
+ if(count < 0)
+ {
+ error("speexout~: could not send encoded data to the peer (%d)", count);
#ifdef _WIN32
- closesocket(x->x_fd);
+ closesocket(x->x_fd);
#else
- close(x->x_fd);
+ close(x->x_fd);
#endif
- x->x_fd = -1;
- outlet_float(x->x_obj.ob_outlet, 0);
- }
- else
- {
- x->x_outpackets++;
- // post( "speexout~ : emitted %d bytes (packets = %d)", count, x->x_outpackets );
- if ( x->x_outpackets%100 == 0 )
- {
- // post( "speexout~ : emitted %d bytes (packets = %d)", x->x_bytesemitted, x->x_outpackets );
- }
- if(count != x->x_encsize+1)
- {
- error("speexout~: %d bytes skipped", x->x_encsize - count);
- }
+ x->x_fd = -1;
+ outlet_float(x->x_obj.ob_outlet, 0);
+ }
+ else
+ {
+ x->x_outpackets++;
+ // post( "speexout~ : emitted %d bytes (packets = %d)", count, x->x_outpackets );
+ if ( x->x_outpackets%100 == 0 )
+ {
+ // post( "speexout~ : emitted %d bytes (packets = %d)", x->x_bytesemitted, x->x_outpackets );
+ }
+ if(count != x->x_encsize+1)
+ {
+ error("speexout~: %d bytes skipped", x->x_encsize - count);
+ }
+ }
+ x->x_encsize = -1;
}
- x->x_encsize = -1;
- }
}
-
- /* buffer and downsample the data */
+
+/* buffer and downsample the data */
static t_int *speexout_perform(t_int *w)
{
t_float *in = (t_float *)(w[1]); /* audio inlet */
t_speexout *x = (t_speexout *)(w[2]);
int n = (int)(w[3]); /* number of samples */
unsigned short i,wp;
- t_float accum = 0.;
+ t_float accum = 0.;
int sratio;
/* samplerate is supposed to be > 16kHz, thus sratio > 1 */
- if ( x->x_mode == SPEEX_NB_MODE )
+ if ( x->x_mode == SPEEX_NB_MODE )
{
- sratio = x->x_samplerate / 8000;
+ sratio = x->x_samplerate / 8000;
}
else
{
- sratio = x->x_samplerate / 16000;
+ sratio = x->x_samplerate / 16000;
}
/* copy the data into the buffer and resample audio data */
-
+
accum=0;
for(wp = 0; wp < n; wp++)
{
accum += *(in+wp);
if ( wp % sratio == sratio - 1 )
{
- x->x_inbuf[x->x_inp] = ( accum / sratio ) * 8000; // scale the input for speex best efficiency
- // post( "x->x_inp : %d", x->x_inp );
- x->x_inp = (x->x_inp+1)%IN_BUFFER_SIZE;
- x->x_bytesbuffered ++;
- accum = 0;
+ x->x_inbuf[x->x_inp] = ( accum / sratio ) * 8000; // scale the input for speex best efficiency
+ // post( "x->x_inp : %d", x->x_inp );
+ x->x_inp = (x->x_inp+1)%IN_BUFFER_SIZE;
+ x->x_bytesbuffered ++;
+ accum = 0;
}
}
if( ( x->x_fd >= 0 ) && ( x->x_bytesbuffered > x->x_framesize ) )
- {
+ {
/* encode and send to the peer */
speexout_encode(x); /* speex encoding */
speexout_stream(x); /* stream mp3 to the peer */
@@ -259,23 +259,23 @@ static void speexout_dsp(t_speexout *x, t_signal **sp)
dsp_add(speexout_perform, 3, sp[0]->s_vec, x, sp[0]->s_n);
}
- /* initialize the speex library */
+/* initialize the speex library */
static void speexout_tilde_speex_init(t_speexout *x)
{
speex_bits_init(&x->x_bits);
- switch ( x->x_mode )
+ switch ( x->x_mode )
{
- case SPEEX_NB_MODE :
+ case SPEEX_NB_MODE :
x->x_encstate = speex_encoder_init(&speex_nb_mode);
break;
- case SPEEX_WB_MODE :
+ case SPEEX_WB_MODE :
x->x_encstate = speex_encoder_init(&speex_wb_mode);
break;
-
- default :
+
+ default :
error( "speexout~ : severe error : encoding scheme is unknown" );
break;
}
@@ -285,14 +285,14 @@ static void speexout_tilde_speex_init(t_speexout *x)
}
- /* connect to the peer */
+/* connect to the peer */
static void speexout_connect(t_speexout *x, t_symbol *hostname, t_floatarg fportno)
{
struct sockaddr_in csocket;
struct hostent *hp;
int portno = fportno; /* get port from message box */
- /* variables used for communication with the peer */
+ /* variables used for communication with the peer */
const char *buf = 0;
unsigned int len;
int sockfd;
@@ -316,7 +316,7 @@ static void speexout_connect(t_speexout *x, t_symbol *hostname, t_floatarg fport
return;
}
- /* connect socket using hostname provided in command line */
+ /* connect socket using hostname provided in command line */
csocket.sin_family = AF_INET;
hp = gethostbyname(hostname->s_name);
if (hp == 0)
@@ -331,10 +331,10 @@ static void speexout_connect(t_speexout *x, t_symbol *hostname, t_floatarg fport
}
memcpy((char *)&csocket.sin_addr, (char *)hp->h_addr, hp->h_length);
- /* assign client port number */
+ /* assign client port number */
csocket.sin_port = htons((unsigned short)portno);
- /* try to connect. */
+ /* try to connect. */
post("speexout~: connecting to port %d", portno);
if (connect(sockfd, (struct sockaddr *) &csocket, sizeof (csocket)) < 0)
{
@@ -355,11 +355,11 @@ static void speexout_connect(t_speexout *x, t_symbol *hostname, t_floatarg fport
}
- /* close connection to the peer */
+/* close connection to the peer */
static void speexout_disconnect(t_speexout *x)
{
- int err = -1;
+ int err = -1;
if(x->x_fd >= 0) /* close socket */
{
@@ -374,20 +374,21 @@ static void speexout_disconnect(t_speexout *x)
}
}
- /* settings for encoding quality */
+/* settings for encoding quality */
static void speexout_quality(t_speexout *x, t_floatarg fquality )
{
- if ( fquality < 0 || fquality > 10 ) {
- post( "speexout~ : wrong quality." );
- return;
+ if ( fquality < 0 || fquality > 10 )
+ {
+ post( "speexout~ : wrong quality." );
+ return;
}
x->x_quality = fquality;
post("speexout~: setting quality to : %d", x->x_quality);
speex_encoder_ctl(x->x_encstate, SPEEX_SET_QUALITY, &x->x_quality);
}
- /* clean up */
-static void speexout_free(t_speexout *x)
+/* clean up */
+static void speexout_free(t_speexout *x)
{
speex_bits_destroy(&x->x_bits);
@@ -445,7 +446,7 @@ void speexout_tilde_setup(void)
{
verbose(0, speexout_version);
speexout_class = class_new(gensym("speexout~"), (t_newmethod)speexout_new, (t_method)speexout_free,
- sizeof(t_speexout), 0, A_GIMME, 0);
+ sizeof(t_speexout), 0, A_GIMME, 0);
CLASS_MAINSIGNALIN(speexout_class, t_speexout, x_f );
class_addmethod(speexout_class, (t_method)speexout_dsp, gensym("dsp"), 0);
class_addmethod(speexout_class, (t_method)speexout_connect, gensym("connect"), A_SYMBOL, A_FLOAT, 0);
diff --git a/spigot~.c b/spigot~.c
index c11325c..5ab4acc 100644
--- a/spigot~.c
+++ b/spigot~.c
@@ -39,15 +39,21 @@ static t_int *spigot_perform(t_int *w)
t_float *outl = (t_float *)(w[3]);
int n = (int)(w[4]);
t_spigot* x = (t_spigot*)(w[5]);
- while (n--) {
- if ( (x->x_on)==0.0 ) {
- *(outl)=0.0;
- *(outr)=*(in);
- } else {
- *(outl)=*(in);
- *(outr)=0.0;
- }
- in++;outl++;outr++;
+ while (n--)
+ {
+ if ( (x->x_on)==0.0 )
+ {
+ *(outl)=0.0;
+ *(outr)=*(in);
+ }
+ else
+ {
+ *(outl)=*(in);
+ *(outr)=0.0;
+ }
+ in++;
+ outl++;
+ outr++;
}
return (w+6);
}
@@ -67,7 +73,7 @@ void spigot_tilde_setup(void)
{
verbose(0, spigot_version );
spigot_class = class_new(gensym("spigot~"), (t_newmethod)spigot_new, 0,
- sizeof(t_spigot), 0, 0);
+ sizeof(t_spigot), 0, 0);
CLASS_MAINSIGNALIN( spigot_class, t_spigot, x_f );
class_addmethod(spigot_class, (t_method)spigot_dsp, gensym("dsp"), 0);
class_addmethod(spigot_class, (t_method)spigot_set, gensym("seton"), A_FLOAT, 0);
diff --git a/tables.c b/tables.c
index 049a523..df95669 100644
--- a/tables.c
+++ b/tables.c
@@ -17,295 +17,299 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-double LspDcTable[11] = {
- 0,
- 0.0955505 ,
- 0.144073 ,
- 0.23468 ,
- 0.329773 ,
- 0.42334 ,
- 0.503387 ,
- 0.602783 ,
- 0.679321 ,
- 0.77771 ,
- 0.845886
+double LspDcTable[11] =
+{
+ 0,
+ 0.0955505 ,
+ 0.144073 ,
+ 0.23468 ,
+ 0.329773 ,
+ 0.42334 ,
+ 0.503387 ,
+ 0.602783 ,
+ 0.679321 ,
+ 0.77771 ,
+ 0.845886
};
-double CosineTable[257] = {
- 1 ,
- 0.999939 ,
- 0.999695 ,
- 0.999329 ,
- 0.998779 ,
- 0.998108 ,
- 0.997314 ,
- 0.996338 ,
- 0.995178 ,
- 0.993896 ,
- 0.992493 ,
- 0.990906 ,
- 0.989197 ,
- 0.987305 ,
- 0.985291 ,
- 0.983093 ,
- 0.980774 ,
- 0.978333 ,
- 0.975708 ,
- 0.972961 ,
- 0.970032 ,
- 0.96698 ,
- 0.963806 ,
- 0.960449 ,
- 0.95697 ,
- 0.953308 ,
- 0.949524 ,
- 0.945618 ,
- 0.941528 ,
- 0.937317 ,
- 0.932983 ,
- 0.928528 ,
- 0.923889 ,
- 0.919128 ,
- 0.914185 ,
- 0.90918 ,
- 0.903992 ,
- 0.898682 ,
- 0.89325 ,
- 0.887634 ,
- 0.881897 ,
- 0.876099 ,
- 0.870117 ,
- 0.863953 ,
- 0.857727 ,
- 0.851379 ,
- 0.844849 ,
- 0.838196 ,
- 0.831482 ,
- 0.824585 ,
- 0.817566 ,
- 0.810486 ,
- 0.803223 ,
- 0.795837 ,
- 0.78833 ,
- 0.780762 ,
- 0.77301 ,
- 0.765198 ,
- 0.757202 ,
- 0.749146 ,
- 0.740967 ,
- 0.732666 ,
- 0.724243 ,
- 0.715759 ,
- 0.707092 ,
- 0.698364 ,
- 0.689514 ,
- 0.680603 ,
- 0.67157 ,
- 0.662415 ,
- 0.653198 ,
- 0.64386 ,
- 0.634399 ,
- 0.624878 ,
- 0.615234 ,
- 0.60553 ,
- 0.595703 ,
- 0.585815 ,
- 0.575806 ,
- 0.565735 ,
- 0.555542 ,
- 0.545349 ,
- 0.534973 ,
- 0.524597 ,
- 0.514099 ,
- 0.50354 ,
- 0.49292 ,
- 0.482178 ,
- 0.471375 ,
- 0.46051 ,
- 0.449585 ,
- 0.438599 ,
- 0.427551 ,
- 0.416443 ,
- 0.405212 ,
- 0.393982 ,
- 0.38269 ,
- 0.371338 ,
- 0.359924 ,
- 0.348389 ,
- 0.336914 ,
- 0.325317 ,
- 0.31366 ,
- 0.302002 ,
- 0.290283 ,
- 0.278503 ,
- 0.266724 ,
- 0.254883 ,
- 0.242981 ,
- 0.231079 ,
- 0.219116 ,
- 0.207092 ,
- 0.195068 ,
- 0.183044 ,
- 0.170959 ,
- 0.158875 ,
- 0.146729 ,
- 0.134583 ,
- 0.122437 ,
- 0.110229 ,
- 0.0980225 ,
- 0.0858154 ,
- 0.0735474 ,
- 0.0613403 ,
- 0.0490723 ,
- 0.0368042 ,
- 0.0245361 ,
- 0.0122681 ,
- 0 ,
- -0.0122681 ,
- -0.0245361 ,
- -0.0368042 ,
- -0.0490723 ,
- -0.0613403 ,
- -0.0735474 ,
- -0.0858154 ,
- -0.0980225 ,
- -0.110229 ,
- -0.122437 ,
- -0.134583 ,
- -0.146729 ,
- -0.158875 ,
- -0.170959 ,
- -0.183044 ,
- -0.195068 ,
- -0.207092 ,
- -0.219116 ,
- -0.231079 ,
- -0.242981 ,
- -0.254883 ,
- -0.266724 ,
- -0.278503 ,
- -0.290283 ,
- -0.302002 ,
- -0.31366 ,
- -0.325317 ,
- -0.336914 ,
- -0.348389 ,
- -0.359924 ,
- -0.371338 ,
- -0.38269 ,
- -0.393982 ,
- -0.405212 ,
- -0.416443 ,
- -0.427551 ,
- -0.438599 ,
- -0.449585 ,
- -0.46051 ,
- -0.471375 ,
- -0.482178 ,
- -0.49292 ,
- -0.50354 ,
- -0.514099 ,
- -0.524597 ,
- -0.534973 ,
- -0.545349 ,
- -0.555542 ,
- -0.565735 ,
- -0.575806 ,
- -0.585815 ,
- -0.595703 ,
- -0.60553 ,
- -0.615234 ,
- -0.624878 ,
- -0.634399 ,
- -0.64386 ,
- -0.653198 ,
- -0.662415 ,
- -0.67157 ,
- -0.680603 ,
- -0.689514 ,
- -0.698364 ,
- -0.707092 ,
- -0.715759 ,
- -0.724243 ,
- -0.732666 ,
- -0.740967 ,
- -0.749146 ,
- -0.757202 ,
- -0.765198 ,
- -0.77301 ,
- -0.780762 ,
- -0.78833 ,
- -0.795837 ,
- -0.803223 ,
- -0.810486 ,
- -0.817566 ,
- -0.824585 ,
- -0.831482 ,
- -0.838196 ,
- -0.844849 ,
- -0.851379 ,
- -0.857727 ,
- -0.863953 ,
- -0.870117 ,
- -0.876099 ,
- -0.881897 ,
- -0.887634 ,
- -0.89325 ,
- -0.898682 ,
- -0.903992 ,
- -0.90918 ,
- -0.914185 ,
- -0.919128 ,
- -0.923889 ,
- -0.928528 ,
- -0.932983 ,
- -0.937317 ,
- -0.941528 ,
- -0.945618 ,
- -0.949524 ,
- -0.953308 ,
- -0.95697 ,
- -0.960449 ,
- -0.963806 ,
- -0.96698 ,
- -0.970032 ,
- -0.972961 ,
- -0.975708 ,
- -0.978333 ,
- -0.980774 ,
- -0.983093 ,
- -0.985291 ,
- -0.987305 ,
- -0.989197 ,
- -0.990906 ,
- -0.992493 ,
- -0.993896 ,
- -0.995178 ,
- -0.996338 ,
- -0.997314 ,
- -0.998108 ,
- -0.998779 ,
- -0.999329 ,
- -0.999695 ,
- -0.999939 ,
- -1
+double CosineTable[257] =
+{
+ 1 ,
+ 0.999939 ,
+ 0.999695 ,
+ 0.999329 ,
+ 0.998779 ,
+ 0.998108 ,
+ 0.997314 ,
+ 0.996338 ,
+ 0.995178 ,
+ 0.993896 ,
+ 0.992493 ,
+ 0.990906 ,
+ 0.989197 ,
+ 0.987305 ,
+ 0.985291 ,
+ 0.983093 ,
+ 0.980774 ,
+ 0.978333 ,
+ 0.975708 ,
+ 0.972961 ,
+ 0.970032 ,
+ 0.96698 ,
+ 0.963806 ,
+ 0.960449 ,
+ 0.95697 ,
+ 0.953308 ,
+ 0.949524 ,
+ 0.945618 ,
+ 0.941528 ,
+ 0.937317 ,
+ 0.932983 ,
+ 0.928528 ,
+ 0.923889 ,
+ 0.919128 ,
+ 0.914185 ,
+ 0.90918 ,
+ 0.903992 ,
+ 0.898682 ,
+ 0.89325 ,
+ 0.887634 ,
+ 0.881897 ,
+ 0.876099 ,
+ 0.870117 ,
+ 0.863953 ,
+ 0.857727 ,
+ 0.851379 ,
+ 0.844849 ,
+ 0.838196 ,
+ 0.831482 ,
+ 0.824585 ,
+ 0.817566 ,
+ 0.810486 ,
+ 0.803223 ,
+ 0.795837 ,
+ 0.78833 ,
+ 0.780762 ,
+ 0.77301 ,
+ 0.765198 ,
+ 0.757202 ,
+ 0.749146 ,
+ 0.740967 ,
+ 0.732666 ,
+ 0.724243 ,
+ 0.715759 ,
+ 0.707092 ,
+ 0.698364 ,
+ 0.689514 ,
+ 0.680603 ,
+ 0.67157 ,
+ 0.662415 ,
+ 0.653198 ,
+ 0.64386 ,
+ 0.634399 ,
+ 0.624878 ,
+ 0.615234 ,
+ 0.60553 ,
+ 0.595703 ,
+ 0.585815 ,
+ 0.575806 ,
+ 0.565735 ,
+ 0.555542 ,
+ 0.545349 ,
+ 0.534973 ,
+ 0.524597 ,
+ 0.514099 ,
+ 0.50354 ,
+ 0.49292 ,
+ 0.482178 ,
+ 0.471375 ,
+ 0.46051 ,
+ 0.449585 ,
+ 0.438599 ,
+ 0.427551 ,
+ 0.416443 ,
+ 0.405212 ,
+ 0.393982 ,
+ 0.38269 ,
+ 0.371338 ,
+ 0.359924 ,
+ 0.348389 ,
+ 0.336914 ,
+ 0.325317 ,
+ 0.31366 ,
+ 0.302002 ,
+ 0.290283 ,
+ 0.278503 ,
+ 0.266724 ,
+ 0.254883 ,
+ 0.242981 ,
+ 0.231079 ,
+ 0.219116 ,
+ 0.207092 ,
+ 0.195068 ,
+ 0.183044 ,
+ 0.170959 ,
+ 0.158875 ,
+ 0.146729 ,
+ 0.134583 ,
+ 0.122437 ,
+ 0.110229 ,
+ 0.0980225 ,
+ 0.0858154 ,
+ 0.0735474 ,
+ 0.0613403 ,
+ 0.0490723 ,
+ 0.0368042 ,
+ 0.0245361 ,
+ 0.0122681 ,
+ 0 ,
+ -0.0122681 ,
+ -0.0245361 ,
+ -0.0368042 ,
+ -0.0490723 ,
+ -0.0613403 ,
+ -0.0735474 ,
+ -0.0858154 ,
+ -0.0980225 ,
+ -0.110229 ,
+ -0.122437 ,
+ -0.134583 ,
+ -0.146729 ,
+ -0.158875 ,
+ -0.170959 ,
+ -0.183044 ,
+ -0.195068 ,
+ -0.207092 ,
+ -0.219116 ,
+ -0.231079 ,
+ -0.242981 ,
+ -0.254883 ,
+ -0.266724 ,
+ -0.278503 ,
+ -0.290283 ,
+ -0.302002 ,
+ -0.31366 ,
+ -0.325317 ,
+ -0.336914 ,
+ -0.348389 ,
+ -0.359924 ,
+ -0.371338 ,
+ -0.38269 ,
+ -0.393982 ,
+ -0.405212 ,
+ -0.416443 ,
+ -0.427551 ,
+ -0.438599 ,
+ -0.449585 ,
+ -0.46051 ,
+ -0.471375 ,
+ -0.482178 ,
+ -0.49292 ,
+ -0.50354 ,
+ -0.514099 ,
+ -0.524597 ,
+ -0.534973 ,
+ -0.545349 ,
+ -0.555542 ,
+ -0.565735 ,
+ -0.575806 ,
+ -0.585815 ,
+ -0.595703 ,
+ -0.60553 ,
+ -0.615234 ,
+ -0.624878 ,
+ -0.634399 ,
+ -0.64386 ,
+ -0.653198 ,
+ -0.662415 ,
+ -0.67157 ,
+ -0.680603 ,
+ -0.689514 ,
+ -0.698364 ,
+ -0.707092 ,
+ -0.715759 ,
+ -0.724243 ,
+ -0.732666 ,
+ -0.740967 ,
+ -0.749146 ,
+ -0.757202 ,
+ -0.765198 ,
+ -0.77301 ,
+ -0.780762 ,
+ -0.78833 ,
+ -0.795837 ,
+ -0.803223 ,
+ -0.810486 ,
+ -0.817566 ,
+ -0.824585 ,
+ -0.831482 ,
+ -0.838196 ,
+ -0.844849 ,
+ -0.851379 ,
+ -0.857727 ,
+ -0.863953 ,
+ -0.870117 ,
+ -0.876099 ,
+ -0.881897 ,
+ -0.887634 ,
+ -0.89325 ,
+ -0.898682 ,
+ -0.903992 ,
+ -0.90918 ,
+ -0.914185 ,
+ -0.919128 ,
+ -0.923889 ,
+ -0.928528 ,
+ -0.932983 ,
+ -0.937317 ,
+ -0.941528 ,
+ -0.945618 ,
+ -0.949524 ,
+ -0.953308 ,
+ -0.95697 ,
+ -0.960449 ,
+ -0.963806 ,
+ -0.96698 ,
+ -0.970032 ,
+ -0.972961 ,
+ -0.975708 ,
+ -0.978333 ,
+ -0.980774 ,
+ -0.983093 ,
+ -0.985291 ,
+ -0.987305 ,
+ -0.989197 ,
+ -0.990906 ,
+ -0.992493 ,
+ -0.993896 ,
+ -0.995178 ,
+ -0.996338 ,
+ -0.997314 ,
+ -0.998108 ,
+ -0.998779 ,
+ -0.999329 ,
+ -0.999695 ,
+ -0.999939 ,
+ -1
};
-double BandExpTable[11] = {
- 1,
- 0.993988 ,
- 0.988037 ,
- 0.982117 ,
- 0.976227 ,
- 0.970367 ,
- 0.964539 ,
- 0.95874 ,
- 0.953003 ,
- 0.947266 ,
- 0.941589
+double BandExpTable[11] =
+{
+ 1,
+ 0.993988 ,
+ 0.988037 ,
+ 0.982117 ,
+ 0.976227 ,
+ 0.970367 ,
+ 0.964539 ,
+ 0.95874 ,
+ 0.953003 ,
+ 0.947266 ,
+ 0.941589
};
-double HammingWindowTable[128*3]={
-5.38469e-16, 6.69307e-05, 0.000267706, 0.000602271, 0.00107054, 0.00167238, 0.00240763, 0.00327611, 0.00427757, 0.00541174, 0.00667833, 0.00807699, 0.00960736, 0.011269, 0.0130615, 0.0149844, 0.0170371, 0.0192191, 0.0215298, 0.0239687, 0.0265349, 0.029228, 0.032047, 0.0349914, 0.0380602, 0.0412527, 0.0445681, 0.0480053, 0.0515636, 0.055242, 0.0590394, 0.0629548, 0.0669873, 0.0711357, 0.0753989, 0.0797758, 0.0842652, 0.0888659, 0.0935766, 0.0983962, 0.103323, 0.108357, 0.113495, 0.118736, 0.12408, 0.129524, 0.135068, 0.140709, 0.146447, 0.152279, 0.158204, 0.164221, 0.170327, 0.176522, 0.182803, 0.18917, 0.195619, 0.20215, 0.208761, 0.21545, 0.222215, 0.229054, 0.235966, 0.242949, 0.25, 0.257118, 0.264302, 0.271548, 0.278856, 0.286222, 0.293646, 0.301126, 0.308658, 0.316242, 0.323875, 0.331555, 0.33928, 0.347048, 0.354858, 0.362706, 0.37059, 0.37851, 0.386462, 0.394444, 0.402455, 0.410492, 0.418552, 0.426635, 0.434737, 0.442857, 0.450991, 0.459139, 0.467298, 0.475466, 0.48364, 0.491819, 0.5, 0.508181, 0.51636, 0.524534, 0.532702, 0.540861, 0.549009, 0.557143, 0.565263, 0.573365, 0.581448, 0.589508, 0.597545, 0.605556, 0.613538, 0.62149, 0.62941, 0.637294, 0.645142, 0.652952, 0.66072, 0.668445, 0.676125, 0.683758, 0.691342, 0.698874, 0.706354, 0.713778, 0.721144, 0.728452, 0.735698, 0.742882, 0.75, 0.757051, 0.764034, 0.770946, 0.777785, 0.78455, 0.791239, 0.79785, 0.804381, 0.81083, 0.817197, 0.823478, 0.829673, 0.835779, 0.841796, 0.847721, 0.853553, 0.859291, 0.864932, 0.870476, 0.87592, 0.881264, 0.886505, 0.891643, 0.896677, 0.901604, 0.906423, 0.911134, 0.915735, 0.920224, 0.924601, 0.928864, 0.933013, 0.937045, 0.940961, 0.944758, 0.948436, 0.951995, 0.955432, 0.958747, 0.96194, 0.965009, 0.967953, 0.970772, 0.973465, 0.976031, 0.97847, 0.980781, 0.982963, 0.985016, 0.986938, 0.988731, 0.990393, 0.991923, 0.993322, 0.994588, 0.995722, 0.996724, 0.997592, 0.998328, 0.998929, 0.999398, 0.999732, 0.999933, 1, 0.999933, 0.999732, 0.999398, 0.998929, 0.998328, 0.997592, 0.996724, 0.995722, 0.994588, 0.993322, 0.991923, 0.990393, 0.988731, 0.986938, 0.985016, 0.982963, 0.980781, 0.97847, 0.976031, 0.973465, 0.970772, 0.967953, 0.965009, 0.96194, 0.958747, 0.955432, 0.951995, 0.948436, 0.944758, 0.940961, 0.937045, 0.933013, 0.928864, 0.924601, 0.920224, 0.915735, 0.911134, 0.906423, 0.901604, 0.896677, 0.891643, 0.886505, 0.881264, 0.87592, 0.870476, 0.864932, 0.859291, 0.853553, 0.847721, 0.841796, 0.835779, 0.829673, 0.823478, 0.817197, 0.81083, 0.804381, 0.79785, 0.791239, 0.78455, 0.777785, 0.770946, 0.764034, 0.757051, 0.75, 0.742882, 0.735698, 0.728452, 0.721144, 0.713778, 0.706354, 0.698874, 0.691342, 0.683758, 0.676125, 0.668445, 0.66072, 0.652952, 0.645142, 0.637294, 0.62941, 0.62149, 0.613538, 0.605556, 0.597545, 0.589508, 0.581448, 0.573365, 0.565263, 0.557143, 0.549009, 0.540861, 0.532702, 0.524534, 0.51636, 0.508181, 0.5, 0.491819, 0.48364, 0.475466, 0.467298, 0.459139, 0.450991, 0.442857, 0.434737, 0.426635, 0.418552, 0.410492, 0.402455, 0.394444, 0.386462, 0.37851, 0.37059, 0.362706, 0.354858, 0.347048, 0.33928, 0.331555, 0.323875, 0.316242, 0.308658, 0.301126, 0.293646, 0.286222, 0.278856, 0.271548, 0.264302, 0.257118, 0.25, 0.242949, 0.235966, 0.229054, 0.222215, 0.21545, 0.208761, 0.20215, 0.195619, 0.18917, 0.182803, 0.176522, 0.170327, 0.164221, 0.158204, 0.152279, 0.146447, 0.140709, 0.135068, 0.129524, 0.12408, 0.118736, 0.113495, 0.108357, 0.103323, 0.0983962, 0.0935766, 0.0888659, 0.0842652, 0.0797758, 0.0753989, 0.0711357, 0.0669873, 0.0629548, 0.0590394, 0.055242, 0.0515636, 0.0480053, 0.0445681, 0.0412527, 0.0380602, 0.0349914, 0.032047, 0.029228, 0.0265349, 0.0239687, 0.0215298, 0.0192191, 0.0170371, 0.0149844, 0.0130615, 0.011269, 0.00960736, 0.00807699, 0.00667833, 0.00541174, 0.00427757, 0.00327611, 0.00240763, 0.00167238, 0.00107054, 0.000602271, 0.000267706, 6.69307e-05,
- };
+double HammingWindowTable[128*3]=
+{
+ 5.38469e-16, 6.69307e-05, 0.000267706, 0.000602271, 0.00107054, 0.00167238, 0.00240763, 0.00327611, 0.00427757, 0.00541174, 0.00667833, 0.00807699, 0.00960736, 0.011269, 0.0130615, 0.0149844, 0.0170371, 0.0192191, 0.0215298, 0.0239687, 0.0265349, 0.029228, 0.032047, 0.0349914, 0.0380602, 0.0412527, 0.0445681, 0.0480053, 0.0515636, 0.055242, 0.0590394, 0.0629548, 0.0669873, 0.0711357, 0.0753989, 0.0797758, 0.0842652, 0.0888659, 0.0935766, 0.0983962, 0.103323, 0.108357, 0.113495, 0.118736, 0.12408, 0.129524, 0.135068, 0.140709, 0.146447, 0.152279, 0.158204, 0.164221, 0.170327, 0.176522, 0.182803, 0.18917, 0.195619, 0.20215, 0.208761, 0.21545, 0.222215, 0.229054, 0.235966, 0.242949, 0.25, 0.257118, 0.264302, 0.271548, 0.278856, 0.286222, 0.293646, 0.301126, 0.308658, 0.316242, 0.323875, 0.331555, 0.33928, 0.347048, 0.354858, 0.362706, 0.37059, 0.37851, 0.386462, 0.394444, 0.402455, 0.410492, 0.418552, 0.426635, 0.434737, 0.442857, 0.450991, 0.459139, 0.467298, 0.475466, 0.48364, 0.491819, 0.5, 0.508181, 0.51636, 0.524534, 0.532702, 0.540861, 0.549009, 0.557143, 0.565263, 0.573365, 0.581448, 0.589508, 0.597545, 0.605556, 0.613538, 0.62149, 0.62941, 0.637294, 0.645142, 0.652952, 0.66072, 0.668445, 0.676125, 0.683758, 0.691342, 0.698874, 0.706354, 0.713778, 0.721144, 0.728452, 0.735698, 0.742882, 0.75, 0.757051, 0.764034, 0.770946, 0.777785, 0.78455, 0.791239, 0.79785, 0.804381, 0.81083, 0.817197, 0.823478, 0.829673, 0.835779, 0.841796, 0.847721, 0.853553, 0.859291, 0.864932, 0.870476, 0.87592, 0.881264, 0.886505, 0.891643, 0.896677, 0.901604, 0.906423, 0.911134, 0.915735, 0.920224, 0.924601, 0.928864, 0.933013, 0.937045, 0.940961, 0.944758, 0.948436, 0.951995, 0.955432, 0.958747, 0.96194, 0.965009, 0.967953, 0.970772, 0.973465, 0.976031, 0.97847, 0.980781, 0.982963, 0.985016, 0.986938, 0.988731, 0.990393, 0.991923, 0.993322, 0.994588, 0.995722, 0.996724, 0.997592, 0.998328, 0.998929, 0.999398, 0.999732, 0.999933, 1, 0.999933, 0.999732, 0.999398, 0.998929, 0.998328, 0.997592, 0.996724, 0.995722, 0.994588, 0.993322, 0.991923, 0.990393, 0.988731, 0.986938, 0.985016, 0.982963, 0.980781, 0.97847, 0.976031, 0.973465, 0.970772, 0.967953, 0.965009, 0.96194, 0.958747, 0.955432, 0.951995, 0.948436, 0.944758, 0.940961, 0.937045, 0.933013, 0.928864, 0.924601, 0.920224, 0.915735, 0.911134, 0.906423, 0.901604, 0.896677, 0.891643, 0.886505, 0.881264, 0.87592, 0.870476, 0.864932, 0.859291, 0.853553, 0.847721, 0.841796, 0.835779, 0.829673, 0.823478, 0.817197, 0.81083, 0.804381, 0.79785, 0.791239, 0.78455, 0.777785, 0.770946, 0.764034, 0.757051, 0.75, 0.742882, 0.735698, 0.728452, 0.721144, 0.713778, 0.706354, 0.698874, 0.691342, 0.683758, 0.676125, 0.668445, 0.66072, 0.652952, 0.645142, 0.637294, 0.62941, 0.62149, 0.613538, 0.605556, 0.597545, 0.589508, 0.581448, 0.573365, 0.565263, 0.557143, 0.549009, 0.540861, 0.532702, 0.524534, 0.51636, 0.508181, 0.5, 0.491819, 0.48364, 0.475466, 0.467298, 0.459139, 0.450991, 0.442857, 0.434737, 0.426635, 0.418552, 0.410492, 0.402455, 0.394444, 0.386462, 0.37851, 0.37059, 0.362706, 0.354858, 0.347048, 0.33928, 0.331555, 0.323875, 0.316242, 0.308658, 0.301126, 0.293646, 0.286222, 0.278856, 0.271548, 0.264302, 0.257118, 0.25, 0.242949, 0.235966, 0.229054, 0.222215, 0.21545, 0.208761, 0.20215, 0.195619, 0.18917, 0.182803, 0.176522, 0.170327, 0.164221, 0.158204, 0.152279, 0.146447, 0.140709, 0.135068, 0.129524, 0.12408, 0.118736, 0.113495, 0.108357, 0.103323, 0.0983962, 0.0935766, 0.0888659, 0.0842652, 0.0797758, 0.0753989, 0.0711357, 0.0669873, 0.0629548, 0.0590394, 0.055242, 0.0515636, 0.0480053, 0.0445681, 0.0412527, 0.0380602, 0.0349914, 0.032047, 0.029228, 0.0265349, 0.0239687, 0.0215298, 0.0192191, 0.0170371, 0.0149844, 0.0130615, 0.011269, 0.00960736, 0.00807699, 0.00667833, 0.00541174, 0.00427757, 0.00327611, 0.00240763, 0.00167238, 0.00107054, 0.000602271, 0.000267706, 6.69307e-05,
+};
diff --git a/vocoder~.c b/vocoder~.c
index c2e624c..60d3e8b 100644
--- a/vocoder~.c
+++ b/vocoder~.c
@@ -1,6 +1,6 @@
-/* vocoder~ -- vocoder effect inspired by xvox
+/* vocoder~ -- vocoder effect inspired by xvox
* written by Simon Morlat ( http://simon.morlat.free.fr )
- *
+ *
* Copyleft 2001 Yves Degoyon.
* Permission is granted to use this software for any purpose provided you
* keep this copyright notice intact.
@@ -37,11 +37,11 @@ static void vocoder_cutoff(t_vocoder *x, t_floatarg fcutoff )
{
if ( fcutoff > 128.0 )
{
- fcutoff = 128.0;
+ fcutoff = 128.0;
}
if ( fcutoff < 0.0 )
{
- fcutoff = 0.0;
+ fcutoff = 0.0;
}
x->x_cutoff = fcutoff;
}
@@ -50,11 +50,11 @@ static void vocoder_vfeedback(t_vocoder *x, t_floatarg fvfeedback )
{
if ( fvfeedback > 100.0 )
{
- fvfeedback = 100.0;
+ fvfeedback = 100.0;
}
if ( fvfeedback < 0.0 )
{
- fvfeedback = 0.0;
+ fvfeedback = 0.0;
}
x->x_vfeedback = fvfeedback;
}
@@ -71,53 +71,53 @@ static t_int *vocoder_perform(t_int *w)
int n = (int)(w[5]), i;
if ( !x->x_process ) return (w+6);
- if ( x->x_blocksize != n )
+ if ( x->x_blocksize != n )
{
- if ( x->x_in1buf ) freebytes( x->x_in1buf, 3*x->x_blocksize/2*sizeof( double ) );
- if ( x->x_in2buf ) freebytes( x->x_in2buf, 3*x->x_blocksize/2*sizeof( double ) );
- if ( x->x_outbuf ) freebytes( x->x_outbuf, (x->x_blocksize+OUTPUT_DELAY)*sizeof( double ) );
- x->x_blocksize = n;
- x->x_in1buf = (double*) getbytes( 3*x->x_blocksize/2*sizeof( double ) );
- x->x_in2buf = (double*) getbytes( 3*x->x_blocksize/2*sizeof( double ) );
- x->x_outbuf = (double*) getbytes( (x->x_blocksize+OUTPUT_DELAY)*sizeof( double ) );
- if ( !x->x_in1buf || !x->x_in2buf || !x->x_outbuf )
- {
- post( "vocoder~ : allocations failed : stop processing" );
- x->x_process = 0;
- }
- }
-
- for(i=0;i<x->x_blocksize/2;i++)
+ if ( x->x_in1buf ) freebytes( x->x_in1buf, 3*x->x_blocksize/2*sizeof( double ) );
+ if ( x->x_in2buf ) freebytes( x->x_in2buf, 3*x->x_blocksize/2*sizeof( double ) );
+ if ( x->x_outbuf ) freebytes( x->x_outbuf, (x->x_blocksize+OUTPUT_DELAY)*sizeof( double ) );
+ x->x_blocksize = n;
+ x->x_in1buf = (double*) getbytes( 3*x->x_blocksize/2*sizeof( double ) );
+ x->x_in2buf = (double*) getbytes( 3*x->x_blocksize/2*sizeof( double ) );
+ x->x_outbuf = (double*) getbytes( (x->x_blocksize+OUTPUT_DELAY)*sizeof( double ) );
+ if ( !x->x_in1buf || !x->x_in2buf || !x->x_outbuf )
+ {
+ post( "vocoder~ : allocations failed : stop processing" );
+ x->x_process = 0;
+ }
+ }
+
+ for(i=0; i<x->x_blocksize/2; i++)
{
- x->x_in1buf[i]=x->x_in1buf[i+x->x_blocksize];
+ x->x_in1buf[i]=x->x_in1buf[i+x->x_blocksize];
};
- for(i=0;i<OUTPUT_DELAY;i++) x->x_outbuf[i]=x->x_outbuf[i+x->x_blocksize];
- for(i=0;i<x->x_blocksize;i++)
+ for(i=0; i<OUTPUT_DELAY; i++) x->x_outbuf[i]=x->x_outbuf[i+x->x_blocksize];
+ for(i=0; i<x->x_blocksize; i++)
{
- x->x_in1buf[x->x_blocksize/2+i]=(double)(*(in1++));
- x->x_in2buf[x->x_blocksize/2+i]=(double)(*(in2++));
+ x->x_in1buf[x->x_blocksize/2+i]=(double)(*(in1++));
+ x->x_in2buf[x->x_blocksize/2+i]=(double)(*(in2++));
}
hp_filter(x->x_in2buf,x->x_cutoff/128.,n);
- for(i=0;i<4;i++)
+ for(i=0; i<4; i++)
{
- comp_lpc(x->x_in1buf+offset,correls,lpc_coef,x->x_blocksize/4);
- if (lpc_coef[0]!=0)
- {
- lpc2lsp(lpc_coef,f1,f2,lsp_coef);
- lsp2lpc(lsp_coef,lpc_coef);
- };
- lpc_filter(x->x_in2buf+offset,lpc_coef,x->x_outbuf+OUTPUT_DELAY+offset,x->x_blocksize/4);
- offset+=x->x_blocksize/4;
+ comp_lpc(x->x_in1buf+offset,correls,lpc_coef,x->x_blocksize/4);
+ if (lpc_coef[0]!=0)
+ {
+ lpc2lsp(lpc_coef,f1,f2,lsp_coef);
+ lsp2lpc(lsp_coef,lpc_coef);
+ };
+ lpc_filter(x->x_in2buf+offset,lpc_coef,x->x_outbuf+OUTPUT_DELAY+offset,x->x_blocksize/4);
+ offset+=x->x_blocksize/4;
};
- for(i=0;i<x->x_blocksize;i++)
+ for(i=0; i<x->x_blocksize; i++)
{
- if ( x->x_outbuf[OUTPUT_DELAY+i] > 1.0 ) x->x_outbuf[OUTPUT_DELAY+i]=1.0;
- if ( x->x_outbuf[OUTPUT_DELAY+i] < -1.0 ) x->x_outbuf[OUTPUT_DELAY+i]=-1.0;
- *(out1++)=(t_float)(((100-x->x_vfeedback)*x->x_outbuf[OUTPUT_DELAY+i]
- + x->x_vfeedback*(*fin1++))/100.0);
+ if ( x->x_outbuf[OUTPUT_DELAY+i] > 1.0 ) x->x_outbuf[OUTPUT_DELAY+i]=1.0;
+ if ( x->x_outbuf[OUTPUT_DELAY+i] < -1.0 ) x->x_outbuf[OUTPUT_DELAY+i]=-1.0;
+ *(out1++)=(t_float)(((100-x->x_vfeedback)*x->x_outbuf[OUTPUT_DELAY+i]
+ + x->x_vfeedback*(*fin1++))/100.0);
};
-
+
return (w+6);
}
@@ -143,7 +143,7 @@ static void *vocoder_new(void)
return (x);
}
- /* clean up */
+/* clean up */
static void vocoder_free(t_vocoder *x)
{
if ( x->x_in1buf ) freebytes( x->x_in1buf, 3*x->x_blocksize/2*sizeof( double ) );
@@ -155,7 +155,7 @@ void vocoder_tilde_setup(void)
{
verbose(0, vocoder_version);
vocoder_class = class_new(gensym("vocoder~"), (t_newmethod)vocoder_new, (t_method)vocoder_free,
- sizeof(t_vocoder), 0, 0);
+ sizeof(t_vocoder), 0, 0);
CLASS_MAINSIGNALIN( vocoder_class, t_vocoder, x_f );
class_addmethod(vocoder_class, (t_method)vocoder_dsp, gensym("dsp"), 0);
class_addmethod(vocoder_class, (t_method)vocoder_cutoff, gensym("cutoff"), A_FLOAT, 0);
diff --git a/wahwah~.c b/wahwah~.c
index 9819f09..322b078 100644
--- a/wahwah~.c
+++ b/wahwah~.c
@@ -79,41 +79,41 @@ static t_class *wahwah_class;
static void wahwah_set_coeffs (t_wahwah *x)
{
- t_int i;
- double omega;
- double sn,cs;
- double alpha = 0.0;
- /* filter coefficients */
- double a0,a1,a2,b0,b1,b2;
- double A;
+ t_int i;
+ double omega;
+ double sn,cs;
+ double alpha = 0.0;
+ /* filter coefficients */
+ double a0,a1,a2,b0,b1,b2;
+ double A;
A = exp(x->x_dbgain/40.0)*log(10.0);
for (i = 0; i < COEFFSIZE; i++)
{
- omega = 2.0*M_PI*(double)i/(double)x->x_samplerate;
- sn = sin(omega);
- cs = cos(omega);
- if (x->x_bandwidth)
- alpha = sn*sin(log(2.0)/2.0*x->x_bandwidth*omega/sn);
- else
- /* if Q is specified instead of bandwidth */
- if (x->x_Q)
- alpha = sn/(2.0*x->x_Q);
-
- /* then compute the coefs for whichever filter type you want */
- b0 = 1.0 + alpha*A;
- b1 = -2.0*cs ;
- b2 = 1.0 - alpha*A;
- a0 = 1.0 + alpha/A;
- a1 = -2.0*cs ;
- a2 = 1.0 - alpha/A;
-
- *(x->x_coeffs+i*NBCOEFFS) = (b0/a0);
- *(x->x_coeffs+i*NBCOEFFS+1) = (b1/a0);
- *(x->x_coeffs+i*NBCOEFFS+2) = (b2/a0);
- *(x->x_coeffs+i*NBCOEFFS+3) = (a1/a0);
- *(x->x_coeffs+i*NBCOEFFS+4) = (a2/a0);
- // post( "wahwah~ : coeff : %f", *(x->x_coeffs+i*NBCOEFFS+4) );
+ omega = 2.0*M_PI*(double)i/(double)x->x_samplerate;
+ sn = sin(omega);
+ cs = cos(omega);
+ if (x->x_bandwidth)
+ alpha = sn*sin(log(2.0)/2.0*x->x_bandwidth*omega/sn);
+ else
+ /* if Q is specified instead of bandwidth */
+ if (x->x_Q)
+ alpha = sn/(2.0*x->x_Q);
+
+ /* then compute the coefs for whichever filter type you want */
+ b0 = 1.0 + alpha*A;
+ b1 = -2.0*cs ;
+ b2 = 1.0 - alpha*A;
+ a0 = 1.0 + alpha/A;
+ a1 = -2.0*cs ;
+ a2 = 1.0 - alpha/A;
+
+ *(x->x_coeffs+i*NBCOEFFS) = (b0/a0);
+ *(x->x_coeffs+i*NBCOEFFS+1) = (b1/a0);
+ *(x->x_coeffs+i*NBCOEFFS+2) = (b2/a0);
+ *(x->x_coeffs+i*NBCOEFFS+3) = (a1/a0);
+ *(x->x_coeffs+i*NBCOEFFS+4) = (a2/a0);
+ // post( "wahwah~ : coeff : %f", *(x->x_coeffs+i*NBCOEFFS+4) );
}
x->min_coef = x->x_minfc;
x->max_coef = x->x_maxfc;
@@ -127,11 +127,11 @@ static void wahwah_bandwidth(t_wahwah *x, t_floatarg fbandwidth )
{
if ( fbandwidth > 10.0 )
{
- fbandwidth = 10.0;
+ fbandwidth = 10.0;
}
if ( fbandwidth < 0.0 )
{
- fbandwidth = 0.0;
+ fbandwidth = 0.0;
}
x->x_bandwidth = fbandwidth;
// post( "wahwah~ : bandwidth: %f", x->x_bandwidth );
@@ -142,11 +142,11 @@ static void wahwah_dbgain(t_wahwah *x, t_floatarg fdbgain )
{
if ( fdbgain > 15.0 )
{
- fdbgain = 15.0;
+ fdbgain = 15.0;
}
if ( fdbgain < -15.0 )
{
- fdbgain = -15.0;
+ fdbgain = -15.0;
}
x->x_dbgain = fdbgain;
// post( "wahwah~ : dbgain: %f", x->x_dbgain );
@@ -157,11 +157,11 @@ static void wahwah_maxstep(t_wahwah *x, t_floatarg fmaxstep )
{
if ( fmaxstep > 100.0 )
{
- fmaxstep = 100.0;
+ fmaxstep = 100.0;
}
if ( fmaxstep < 0.0 )
{
- fmaxstep = 0.0;
+ fmaxstep = 0.0;
}
x->x_maxstep = fmaxstep;
// post( "wahwah~ : maxstep: %f", x->x_maxstep );
@@ -172,11 +172,11 @@ static void wahwah_sensibility(t_wahwah *x, t_floatarg fsensibility )
{
if ( fsensibility > 1000.0 )
{
- fsensibility = 1000.0;
+ fsensibility = 1000.0;
}
if ( fsensibility < 0.0 )
{
- fsensibility = 0.0;
+ fsensibility = 0.0;
}
x->x_sense = fsensibility;
// post( "wahwah~ : sensibility: %f", x->x_sense );
@@ -187,11 +187,11 @@ static void wahwah_maxfreq(t_wahwah *x, t_floatarg fmaxfreq )
{
if ( fmaxfreq > 3000.0 )
{
- fmaxfreq = 3000.0;
+ fmaxfreq = 3000.0;
}
if ( fmaxfreq < 0.0 )
{
- fmaxfreq = 0.0;
+ fmaxfreq = 0.0;
}
x->x_maxfc = fmaxfreq;
// post( "wahwah~ : maxfreq: %f", x->x_maxfc );
@@ -202,11 +202,11 @@ static void wahwah_minfreq(t_wahwah *x, t_floatarg fminfreq )
{
if ( fminfreq > 3000.0 )
{
- fminfreq = 3000.0;
+ fminfreq = 3000.0;
}
if ( fminfreq < 0.0 )
{
- fminfreq = 0.0;
+ fminfreq = 0.0;
}
x->x_minfc = fminfreq;
// post( "wahwah~ : minfreq: %f", x->x_minfc );
@@ -217,22 +217,22 @@ static void wahwah_step(t_wahwah *x, t_floatarg fstep )
{
if ( fstep > x->x_maxstep )
{
- fstep = x->x_maxstep;
+ fstep = x->x_maxstep;
}
if ( fstep < 0 )
{
- fstep = 0;
+ fstep = 0;
}
x->step = fstep*x->x_sense/x->x_samplerate;
}
static t_int *wahwah_perform(t_int *w)
{
- t_float *in = (t_float *)(w[1]);
- t_float *out = (t_float *)(w[2]);
- t_int n = (int)(w[3]);
- t_wahwah *x = (t_wahwah*)(w[4]);
- t_int i;
+ t_float *in = (t_float *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ t_int n = (int)(w[3]);
+ t_wahwah *x = (t_wahwah*)(w[4]);
+ t_int i;
for (i=0; i<n; i++)
{
@@ -240,10 +240,10 @@ static t_int *wahwah_perform(t_int *w)
x->x0 = (int)((*(in+i))*32768);
x->y0 = (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS))*x->x0
- + (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+1))*x->x1
- + (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+2))*x->x2
- - (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+3))*x->y1
- - (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+4))*x->y2;
+ + (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+1))*x->x1
+ + (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+2))*x->x2
+ - (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+3))*x->y1
+ - (*(x->x_coeffs+(int)x->cur_coef*NBCOEFFS+4))*x->y2;
x->y2 = x->y1;
x->y1 = x->y0;
@@ -279,60 +279,60 @@ static void wahwah_preset(t_wahwah *x, t_float pnumber)
{
switch ( (int)pnumber )
{
- /* fast change medium wah wah */
- case 1:
- x->x_minfc = 100.0;
- x->x_maxfc = 1600.0;
- x->x_sense = 100.0;
- x->x_maxstep = 60.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- /* slow change medium wah wah */
- case 2:
- x->x_minfc = 100.0;
- x->x_maxfc = 1600.0;
- x->x_sense = 50.0;
- x->x_maxstep = 36.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- /* fast wah wah */
- case 3:
- x->x_minfc = 100.0;
- x->x_maxfc = 600.0;
- x->x_sense = 100.0;
- x->x_maxstep = 66.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- /* ranged wah wah */
- case 4:
- x->x_minfc = 10.0;
- x->x_maxfc = 2900.0;
- x->x_sense = 100.0;
- x->x_maxstep = 66.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- /* wah wah 400 - 2000 */
- case 5:
- x->x_minfc = 400.0;
- x->x_maxfc = 2000.0;
- x->x_sense = 100.0;
- x->x_maxstep = 66.0;
- x->x_dbgain = 15.0;
- x->x_Q = 1.0;
- break;
-
- default:
- post( "wahwah~ : unknown preset requested : %d", pnumber );
- return;
- break;
+ /* fast change medium wah wah */
+ case 1:
+ x->x_minfc = 100.0;
+ x->x_maxfc = 1600.0;
+ x->x_sense = 100.0;
+ x->x_maxstep = 60.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ /* slow change medium wah wah */
+ case 2:
+ x->x_minfc = 100.0;
+ x->x_maxfc = 1600.0;
+ x->x_sense = 50.0;
+ x->x_maxstep = 36.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ /* fast wah wah */
+ case 3:
+ x->x_minfc = 100.0;
+ x->x_maxfc = 600.0;
+ x->x_sense = 100.0;
+ x->x_maxstep = 66.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ /* ranged wah wah */
+ case 4:
+ x->x_minfc = 10.0;
+ x->x_maxfc = 2900.0;
+ x->x_sense = 100.0;
+ x->x_maxstep = 66.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ /* wah wah 400 - 2000 */
+ case 5:
+ x->x_minfc = 400.0;
+ x->x_maxfc = 2000.0;
+ x->x_sense = 100.0;
+ x->x_maxstep = 66.0;
+ x->x_dbgain = 15.0;
+ x->x_Q = 1.0;
+ break;
+
+ default:
+ post( "wahwah~ : unknown preset requested : %d", pnumber );
+ return;
+ break;
}
wahwah_set_coeffs( x );
}
@@ -342,18 +342,20 @@ static void wahwah_dsp(t_wahwah *x, t_signal **sp)
dsp_add(wahwah_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x );
}
- /* clean up */
+/* clean up */
static void wahwah_free(t_wahwah *x)
{
- if ( x->x_buf != NULL ) {
- freebytes(x->x_buf, BFSZ*sizeof( double ) );
- post( "Freed %d bytes", BFSZ*sizeof( double ) );
- x->x_buf = NULL;
+ if ( x->x_buf != NULL )
+ {
+ freebytes(x->x_buf, BFSZ*sizeof( double ) );
+ post( "Freed %d bytes", BFSZ*sizeof( double ) );
+ x->x_buf = NULL;
}
- if ( x->x_coeffs != NULL ) {
- freebytes(x->x_coeffs, COEFFSIZE*NBCOEFFS*sizeof( t_float ) );
- post( "Freed %d bytes", COEFFSIZE*NBCOEFFS*sizeof( t_float ));
- x->x_coeffs = NULL;
+ if ( x->x_coeffs != NULL )
+ {
+ freebytes(x->x_coeffs, COEFFSIZE*NBCOEFFS*sizeof( t_float ) );
+ post( "Freed %d bytes", COEFFSIZE*NBCOEFFS*sizeof( t_float ));
+ x->x_coeffs = NULL;
}
}
@@ -373,13 +375,13 @@ static void *wahwah_new(void)
if ( !( x->x_buf = ( double* ) getbytes( BFSZ*sizeof( double ) ) ) )
{
- post ("wahwah~ : could not allocate buffer" );
- return NULL;
+ post ("wahwah~ : could not allocate buffer" );
+ return NULL;
}
if ( !( x->x_coeffs = ( t_float* ) getbytes( COEFFSIZE*NBCOEFFS*sizeof( t_float ) ) ) )
{
- post ("wahwah~ : could not allocate coeffs" );
- return NULL;
+ post ("wahwah~ : could not allocate coeffs" );
+ return NULL;
}
// set default parameters
@@ -393,7 +395,7 @@ void wahwah_tilde_setup(void)
{
verbose(0, wahwah_version );
wahwah_class = class_new(gensym("wahwah~"), (t_newmethod)wahwah_new, (t_method)wahwah_free,
- sizeof(t_wahwah), 0, 0);
+ sizeof(t_wahwah), 0, 0);
CLASS_MAINSIGNALIN( wahwah_class, t_wahwah, x_f );
class_addmethod(wahwah_class, (t_method)wahwah_step, gensym("step"), A_FLOAT, 0);