aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blinkenlights/CHANGES.LOG2
-rw-r--r--blinkenlights/blinkenlights-help.pd166
-rw-r--r--blinkenlights/blinkenlights.c221
3 files changed, 306 insertions, 83 deletions
diff --git a/blinkenlights/CHANGES.LOG b/blinkenlights/CHANGES.LOG
index 6f7036d..bd80f8e 100644
--- a/blinkenlights/CHANGES.LOG
+++ b/blinkenlights/CHANGES.LOG
@@ -1,2 +1,4 @@
+0.2
+ incorporate changes from Chun Lee ( chun@goto10.org ) : scratch, automatic vj mode
0.1
first implementation
diff --git a/blinkenlights/blinkenlights-help.pd b/blinkenlights/blinkenlights-help.pd
index 3fc28a6..32baca0 100644
--- a/blinkenlights/blinkenlights-help.pd
+++ b/blinkenlights/blinkenlights-help.pd
@@ -1,10 +1,9 @@
-#N canvas 80 -6 868 605 10;
-#X text 495 569 Comments and bugs @ ydegoyon@noos.fr;
-#X text 496 555 Part of unauthorized PD;
-#X text 430 493 blinkenlights is a blinkenlights movies player;
-#X text 430 507 but it's also a pixel grid than you can use for ASCII
+#N canvas 484 81 885 735 10;
+#X text 334 640 Part of unauthorized PD;
+#X text 480 570 blinkenlights is a blinkenlights movies player;
+#X text 480 584 but it's also a pixel grid than you can use for ASCII
art...;
-#X text 430 523 Constructor : blinkenlights <width> <height> <x pixel
+#X text 480 600 Constructor : blinkenlights <width> <height> <x pixel
size> <y pixel size>;
#X msg 125 10 create;
#X msg 182 10 destroy;
@@ -16,7 +15,7 @@ size> <y pixel size>;
#X msg 284 222 bang;
#X msg 285 266 bang;
#X msg 122 267 pixoff \$1 \$2;
-#X obj 34 562 blinkenlights 18 8 32 32;
+#X obj 87 618 blinkenlights 18 8 32 32;
#X msg 125 152 foreground 124 78 89;
#X obj 347 277 hsl 32 8 1 32 0 0 empty empty empty -2 -6 0 8 -262144
-1 -1 0 1;
@@ -25,9 +24,9 @@ size> <y pixel size>;
#X text 355 257 Set a pixel off;
#X text 352 213 Set a pixel on;
#X obj 346 232 hsl 32 8 1 32 0 0 empty empty empty -2 -6 0 8 -262144
--1 -1 0 1;
+-1 -1 1600 1;
#X obj 335 205 vsl 8 32 1 32 0 0 empty empty empty 0 -8 0 8 -262144
--1 -1 0 1;
+-1 -1 1400 1;
#X msg 338 309 bang;
#X obj 400 320 hsl 32 8 1 32 0 0 empty empty empty -2 -6 0 8 -262144
-1 -1 0 1;
@@ -55,8 +54,8 @@ size> <y pixel size>;
Functions;
#X text 552 187 ========================================;
#X text 550 -6 ========================================;
-#X text 547 394 ========================================;
-#X text 117 394 =========================================== Movies
+#X text 539 472 ========================================;
+#X text 112 472 =========================================== Movies
Functions;
#X text 122 -6 =========================================== Grid Actions
;
@@ -70,69 +69,88 @@ Functions;
#X msg 125 58 height 24;
#X text 275 37 Set the width ( number of pixels );
#X text 275 56 Set the height ( number of pixels );
-#X msg 120 416 open ./blm/ascii_people.blm;
-#X msg 328 416 play;
-#X msg 370 416 stop;
-#X msg 120 443 open \$1;
-#X msg 411 416 next;
-#X obj 451 415 metro 100;
-#X msg 524 416 bang;
-#X msg 564 415 stop;
-#X obj 195 453 playlist .blm 200 100;
-#X msg 434 472 location /usr/local/pd/externs/blinkenlights/blm;
-#X obj 434 450 loadbang;
-#X connect 5 0 15 0;
-#X connect 6 0 15 0;
-#X connect 8 0 15 0;
-#X connect 11 0 15 0;
+#X msg 127 495 open ./blm/ascii_people.blm;
+#X msg 335 495 play;
+#X msg 377 495 stop;
+#X msg 127 522 open \$1;
+#X msg 418 495 next;
+#X obj 458 494 metro 100;
+#X msg 531 495 bang;
+#X msg 571 494 stop;
+#X obj 188 521 openpanel;
+#X obj 261 522 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X floatatom 615 495 5 0 0 0 - - -;
+#X text 534 401 ========================================;
+#X text 116 400 =============================================== VJ
+function;
+#X msg 132 444 vj \$1;
+#X msg 363 444 goto \$1;
+#X obj 366 423 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144
+-1 -1 5600 1;
+#X obj 132 424 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+1;
+#X text 507 420 <- look! you can also scratch the film!;
+#X text 530 434 be sure the window is created first....;
+#X text 154 420 <- switch to the scratch mode;
+#X text 333 654 Comments and bugs @ ydegoyon@free.fr and chun@goto10.org
+;
+#X connect 4 0 14 0;
+#X connect 5 0 14 0;
+#X connect 7 0 14 0;
+#X connect 10 0 14 0;
+#X connect 11 0 49 0;
#X connect 12 0 50 0;
-#X connect 13 0 51 0;
-#X connect 14 0 15 0;
-#X connect 16 0 15 0;
-#X connect 17 0 51 0;
-#X connect 18 0 13 0;
-#X connect 18 0 51 1;
-#X connect 21 0 50 0;
-#X connect 22 0 12 0;
-#X connect 22 0 50 1;
-#X connect 23 0 52 0;
-#X connect 24 0 52 0;
-#X connect 25 0 23 0;
-#X connect 25 0 52 1;
-#X connect 27 0 15 0;
-#X connect 28 0 34 0;
-#X connect 29 0 34 1;
-#X connect 30 0 34 2;
-#X connect 31 0 34 3;
-#X connect 32 0 34 4;
-#X connect 33 0 15 0;
-#X connect 34 0 33 0;
-#X connect 35 0 40 0;
-#X connect 35 1 41 0;
-#X connect 35 2 30 0;
-#X connect 35 3 31 0;
-#X connect 35 4 32 0;
-#X connect 36 0 39 0;
-#X connect 38 0 39 0;
-#X connect 39 0 35 0;
+#X connect 13 0 14 0;
+#X connect 15 0 14 0;
+#X connect 16 0 50 0;
+#X connect 17 0 12 0;
+#X connect 17 0 50 1;
+#X connect 20 0 49 0;
+#X connect 21 0 11 0;
+#X connect 21 0 49 1;
+#X connect 22 0 51 0;
+#X connect 23 0 51 0;
+#X connect 24 0 22 0;
+#X connect 24 0 51 1;
+#X connect 26 0 14 0;
+#X connect 27 0 33 0;
+#X connect 28 0 33 1;
+#X connect 29 0 33 2;
+#X connect 30 0 33 3;
+#X connect 31 0 33 4;
+#X connect 32 0 14 0;
+#X connect 33 0 32 0;
+#X connect 34 0 39 0;
+#X connect 34 1 40 0;
+#X connect 34 2 29 0;
+#X connect 34 3 30 0;
+#X connect 34 4 31 0;
+#X connect 35 0 38 0;
+#X connect 37 0 38 0;
+#X connect 38 0 34 0;
+#X connect 39 0 27 0;
#X connect 40 0 28 0;
-#X connect 41 0 29 0;
-#X connect 42 0 15 0;
-#X connect 50 0 11 0;
-#X connect 51 0 14 0;
-#X connect 52 0 27 0;
-#X connect 53 0 15 0;
-#X connect 54 0 15 0;
-#X connect 56 0 15 0;
-#X connect 57 0 15 0;
-#X connect 60 0 15 0;
-#X connect 61 0 15 0;
-#X connect 62 0 15 0;
-#X connect 63 0 15 0;
-#X connect 64 0 15 0;
+#X connect 41 0 14 0;
+#X connect 49 0 10 0;
+#X connect 50 0 13 0;
+#X connect 51 0 26 0;
+#X connect 52 0 14 0;
+#X connect 53 0 14 0;
+#X connect 55 0 14 0;
+#X connect 56 0 14 0;
+#X connect 59 0 14 0;
+#X connect 60 0 14 0;
+#X connect 61 0 14 0;
+#X connect 62 0 14 0;
+#X connect 63 0 14 0;
+#X connect 64 0 63 0;
#X connect 65 0 64 0;
-#X connect 66 0 65 0;
-#X connect 67 0 65 0;
-#X connect 68 0 63 0;
-#X connect 69 0 68 0;
-#X connect 70 0 69 0;
+#X connect 66 0 64 0;
+#X connect 67 0 62 0;
+#X connect 68 0 67 0;
+#X connect 69 0 64 1;
+#X connect 72 0 14 0;
+#X connect 73 0 14 0;
+#X connect 74 0 73 0;
+#X connect 75 0 72 0;
diff --git a/blinkenlights/blinkenlights.c b/blinkenlights/blinkenlights.c
index 3aca7cd..902e9ce 100644
--- a/blinkenlights/blinkenlights.c
+++ b/blinkenlights/blinkenlights.c
@@ -26,6 +26,13 @@
/* Culturcide : Bruce */
/* ---------------------------------------------------------------------------- */
+//added functions:
+//"static void blinkenlights_findframes(t_blinkenlights *x)"
+//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
+//range of $1 is 0 to 1
#include <sys/types.h>
@@ -35,7 +42,7 @@
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
-#ifndef __APPLE__
+#ifndef MACOSX
#include <malloc.h>
#endif
#include <ctype.h>
@@ -46,7 +53,7 @@
#include "m_pd.h" /* standard pd stuff */
#include "g_canvas.h" /* some pd's graphical functions */
-static char *blinkenlights_version = "blinkenlights: a blinkenlights movies player version 0.1 ( bugs @ ydegoyon@free.fr )";
+static char *blinkenlights_version = "blinkenlights: a blinkenlights movies player version 0.2 ( bugs @ ydegoyon@free.fr and chun@goto10.org )";
static int guidebug=0;
@@ -107,6 +114,13 @@ typedef struct _blinkenlights
t_int x_timer; /* timer read from bl movie */
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_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);
@@ -125,6 +139,11 @@ static void blinkenlights_free(t_blinkenlights *x)
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" );
}
@@ -162,6 +181,10 @@ static void *blinkenlights_new(t_float fwidth, t_float fheight, t_float fxpixsiz
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);
}
@@ -447,6 +470,8 @@ 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 );
if ( !x->x_ecanvas )
{
@@ -463,12 +488,14 @@ static void blinkenlights_readframe(t_blinkenlights *x)
// skip header and empty lines
while ( lineread[0] == '#' || lineread[0] == '\n' || lineread[0] == '\0' )
- {
- // post( "blinkenlights : skipped line : >%s<", lineread );
+ {
+
+ //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);
}
}
@@ -561,6 +588,132 @@ static void blinkenlights_readframe(t_blinkenlights *x)
if ( lineread ) freebytes( lineread, BL_MAX_LENGTH );
}
+//-------------------------------------------------------------------------
+//--chun's functions begin here...
+//-------------------------------------------------------------------------
+/* 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);
+}
+
+//-------------------------------------------------------------------------
+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;
+ width = 0;
+ while ( 1 )
+ {
+
+ if ( fgets( lineread, BL_MAX_LENGTH, x->x_filed ) == NULL )
+ {
+ 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 )
+ {
+ 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++;
+ }
+ }
+ 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);
+ }
+
+}
+
+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);
+}
+
+static void blinkenlights_timer2(t_blinkenlights* x, t_float timer)
+{
+ x->x_timer2 = timer;
+ //post("frame %d", x->frame_inc);
+}
/* open movie */
static void blinkenlights_open(t_blinkenlights *x, t_symbol *sfile)
@@ -571,7 +724,21 @@ static void blinkenlights_open(t_blinkenlights *x, t_symbol *sfile)
return;
}
- blinkenlights_close(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_frame )
+ {
+ blinkenlights_clear(x);
+ }
+
+ //--------------------------------
if ( ( x->x_filed = fopen( sfile->s_name, "r" ) ) == NULL )
{
@@ -579,8 +746,9 @@ static void blinkenlights_open(t_blinkenlights *x, t_symbol *sfile)
return;
}
post( "blinkenlights : opened >%s<", sfile->s_name);
-
- blinkenlights_readframe(x);
+ // don't read the first frame when open..
+ //blinkenlights_readframe(x);
+ blinkenlights_findframes(x);
}
/* play frames */
@@ -590,6 +758,13 @@ static void blinkenlights_playframes(t_blinkenlights *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 );
+}
+
/* play movie */
static void blinkenlights_play(t_blinkenlights *x)
{
@@ -610,6 +785,33 @@ static void blinkenlights_play(t_blinkenlights *x)
clock_delay( x->x_clock, (double)x->x_timer );
}
+ /* 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 );
+ }
+}
+
/* stop movie */
static void blinkenlights_stop(t_blinkenlights *x)
{
@@ -632,8 +834,6 @@ static void blinkenlights_stop(t_blinkenlights *x)
}
}
-
-
/* jump to next frame */
static void blinkenlights_next(t_blinkenlights *x)
{
@@ -656,6 +856,9 @@ void blinkenlights_setup(void)
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);