From ef9eed1eaa214df28cb65e51f1cdd8c01f33e1f5 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Thu, 15 May 2008 22:58:01 +0000 Subject: seek and border adds + help file renamed + old files deleted svn path=/trunk/externals/pdvjtools/; revision=9816 --- videogrid/videogrid.c | 407 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 281 insertions(+), 126 deletions(-) (limited to 'videogrid/videogrid.c') diff --git a/videogrid/videogrid.c b/videogrid/videogrid.c index d8701ec..65825f5 100644 --- a/videogrid/videogrid.c +++ b/videogrid/videogrid.c @@ -1,3 +1,4 @@ + /* videogrid external for Puredata Copyright (C) 2007 Sergi Lario @@ -43,6 +44,9 @@ along with this program. If not, see . #define W_CELL 60 #define H_CELL 40 +/* definició del gruix en pixels del marc del tauler */ +#define GRUIX 2 + /* crear un apuntador al nou objecte */ static t_class *videogrid_class; /* indica el nombre de videogrid creats - utilitzat per diferenciar el nom d'instàncies d'objectes del mateix tipus */ @@ -80,6 +84,10 @@ typedef struct _videogrid { t_symbol *x_color_marc; /* mutex per evitar concurrencia sobre la cua al accedir diferents threads*/ pthread_mutex_t x_lock; + /* v 0.2 -- posicó de la cel·la seleccionada */ + int x_pos_selected; + /* v 0.2 -- color de seleccio */ + t_symbol *x_color_grasp; } t_videogrid; @@ -87,14 +95,14 @@ typedef struct _videogrid { /* calcula la posició x del tauler a partir de la posició de l'element de la cua (d'esquerra a dreta) */ int getX(t_videogrid* x, int posCua){ int c = x->x_num_col; - int xpos = (posCua % c) * W_CELL; + int xpos = (posCua % c) * W_CELL + ((posCua % c) + 1) * GRUIX; return(xpos + 1); } /* calcula la posició y del tauler a partir de la posició de l'element de la cua (de dalt a baix) */ int getY(t_videogrid* x, int posCua){ int c = x->x_num_col; - int ypos = (posCua / c) * H_CELL; + int ypos = (posCua / c) * H_CELL + ((posCua / c) + 1) * GRUIX; return(ypos + 1); } @@ -116,7 +124,7 @@ void eliminar_imatges_temporals(int maxim){ } contador++; } - post("Videogrid: Imatges temporals eliminades\n",path_total); + /* post("Videogrid: Imatges temporals eliminades\n",path_total); */ } int format_adequat_v(path nomF){ @@ -200,7 +208,7 @@ void videogrid_afegir_imatge(t_videogrid *x, path entrada) } /* printf("SURT de la creacio de la imatge %s ...",ig_path); */ }else{ - post("Videogrid: El format del fitxer %s és incompatible.",entrada); + post("Videogrid: Incompatible file format (%s).\n",entrada); } /* sys_vgui("image create photo img%x -file %s\n",x,entrada); @@ -219,7 +227,7 @@ void videogrid_drawme(t_videogrid *x, t_glist *glist, int firsttime) sys_vgui(".x%x.c create rectangle %d %d %d %d -fill %s -tags %xGRID -outline %s\n", glist_getcanvas(glist), text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), - text_xpix(&x->x_obj, glist) + (x->x_num_col * W_CELL) + 1, text_ypix(&x->x_obj, glist) + (x->x_num_fil * H_CELL) + 1, + text_xpix(&x->x_obj, glist) + (x->x_num_col * W_CELL) + 1 + (x->x_num_col * GRUIX) + GRUIX, text_ypix(&x->x_obj, glist) + (x->x_num_fil * H_CELL) + 1 + (x->x_num_fil * GRUIX) + GRUIX, x->x_color_fons->s_name, x,x->x_color_marc->s_name); canvas_fixlinesfor(glist_getcanvas(glist), (t_text*)x); @@ -249,7 +257,7 @@ void videogrid_drawme(t_videogrid *x, t_glist *glist, int firsttime) } } else { - sys_vgui(".x%x.c coords %xGRID %d %d %d %d\n", glist_getcanvas(glist), x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),text_xpix(&x->x_obj, glist) + (x->x_num_col*W_CELL) + 1, text_ypix(&x->x_obj, glist) + (x->x_num_fil*H_CELL) + 1); + sys_vgui(".x%x.c coords %xGRID %d %d %d %d\n", glist_getcanvas(glist), x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist),text_xpix(&x->x_obj, glist) + (x->x_num_col*W_CELL) + 1 + (x->x_num_col * GRUIX) + GRUIX, text_ypix(&x->x_obj, glist) + (x->x_num_fil*H_CELL) + 1 + (x->x_num_fil * GRUIX) + GRUIX); if(!cuaBuida(&x->x_cua)) { int contador = 0; @@ -265,19 +273,48 @@ void videogrid_drawme(t_videogrid *x, t_glist *glist, int firsttime) sprintf(buf, "pdtk_videogrid_table %%s %s %d %d\n", x->x_name->s_name, x->x_num_fil, x->x_num_col); gfxstub_new(&x->x_obj.ob_pd, x, buf); */ } + if (x->x_pos_selected > -1){ + sys_vgui(".x%x.c coords %xGRASP %d %d %d %d\n", glist_getcanvas(glist), x, + text_xpix(&x->x_obj, x->x_glist) + getX(x,x->x_pos_selected), text_ypix(&x->x_obj, x->x_glist) + getY(x,x->x_pos_selected), + text_xpix(&x->x_obj, x->x_glist) + getX(x,x->x_pos_selected) + W_CELL, text_ypix(&x->x_obj, x->x_glist) + getY(x,x->x_pos_selected) + H_CELL); + } + sys_vgui(".x%x.c delete %xLINIA\n", glist_getcanvas(x->x_glist), x); + } + int xI = text_xpix(&x->x_obj, glist); + int yI = text_ypix(&x->x_obj, glist); + int xF = xI + (x->x_num_col * W_CELL) + ((x->x_num_col + 1) * GRUIX); + int yF = yI + (x->x_num_fil * H_CELL) + ((x->x_num_fil + 1) * GRUIX); + int vlines = 0; + int xi = 0; + while(vlines < x->x_num_col){ + xi = xI + getX(x,vlines) - GRUIX + 1; + sys_vgui(".x%x.c create line %d %d %d %d -fill %s -width %d -tag %xLINIA\n", glist_getcanvas(x->x_glist), xi, yI, xi, yF, x->x_color_marc->s_name,GRUIX,x); + vlines++; + } + xi = xi + W_CELL + GRUIX; + sys_vgui(".x%x.c create line %d %d %d %d -fill %s -width %d -tag %xLINIA\n", glist_getcanvas(x->x_glist), xi, yI, xi, yF, x->x_color_marc->s_name,GRUIX,x); + int hlines = 0; + int yi = 0; + while(hlines < x->x_num_fil){ + yi = yI + ((H_CELL + GRUIX) * hlines) + 2; + sys_vgui(".x%x.c create line %d %d %d %d -fill %s -width %d -tag %xLINIA\n", glist_getcanvas(x->x_glist), xI, yi, xF, yi, x->x_color_marc->s_name,GRUIX,x); + hlines++; } + yi = yi + H_CELL + GRUIX; + sys_vgui(".x%x.c create line %d %d %d %d -fill %s -width %d -tag %xLINIA\n", glist_getcanvas(x->x_glist), xI, yi, xF, yi, x->x_color_marc->s_name,GRUIX,x); } -/* borra videogrid */ -void videogrid_erase(t_videogrid* x,t_glist* glist) +/* borra videogrid v 0.2 -- int toclear */ +void videogrid_erase(t_videogrid* x,t_glist* glist, int toclear) { int maxim = x->x_num_fil * x->x_num_col; path path_total; - char contador_str[2]; + char contador_str[BYTES_NUM_TEMP]; /* post("Entra a erase"); */ /* elimina les imatges */ int contador = 0; while(contador < numNodes(&x->x_cua)){ + sys_vgui(".x%x.c delete %xS%d\n", glist_getcanvas(x->x_glist), x, contador); strcpy(path_total,PATH_TEMPORAL); sprintf(contador_str,"%d", contador); @@ -290,8 +327,16 @@ void videogrid_erase(t_videogrid* x,t_glist* glist) contador++; } - /* elimina el grid */ - sys_vgui(".x%x.c delete %xGRID\n", glist_getcanvas(glist), x); + /* elimina el grid v 0.2 -- excepte quan es fa un clear */ + if(toclear == 0){ + sys_vgui(".x%x.c delete %xGRID\n", glist_getcanvas(glist), x); + sys_vgui(".x%x.c delete %xLINIA\n", glist_getcanvas(x->x_glist), x); + } + /* v 0.2 -- elimina el marc de la casella seleccionada */ + if(x->x_pos_selected > -1){ + sys_vgui(".x%x.c delete %xGRASP\n", glist_getcanvas(glist), x); + x->x_pos_selected = -1; + } eliminar_imatges_temporals(maxim); } @@ -313,7 +358,7 @@ void videogrid_putvideo(t_videogrid *x, t_symbol *entrada) fitxer = fopen(e,"r"); if (!fitxer) { - post("Videogrid: Problema amb l'obertura del fitxer %s\n",e); + post("Videogrid: Problem opening file %s.\n",e); } else { /* post("s'encua la imatge %s\n", e); */ @@ -333,14 +378,14 @@ void *videogrid_putvideodir_thread(t_videogrid *x) int maxim; if ((dirp = opendir(x->x_dir_canvi)) == NULL) { - post("Videogrid: No es pot obrir el directori %s\n", x->x_dir_canvi); + post("Videogrid: Can not open folder %s.\n", x->x_dir_canvi); }else{ maxim = x->x_num_fil * x->x_num_col; strcpy(directoriAnterior, x->x_dir_actual); strcpy(x->x_dir_actual, x->x_dir_canvi); /* si es el mateix directori entrat l'ultim busca la ultima imatge afegida per a seguir a encuant a partir d'ella en endavant */ if(strcmp(directoriAnterior, x->x_dir_actual) == 0){ - post("Videogrid: Repeteix directori %s\n", x->x_dir_actual); + /* post("Videogrid: Repeteix directori %s\n", x->x_dir_actual); */ while ( (direntp = readdir( dirp )) != NULL ){ /* es descarta el mateix directori, el directori anterior i tot el que no sigui un fitxer regular */ if((strcmp(direntp->d_name,"..") != 0)&&(strcmp(direntp->d_name,".") != 0)&&(direntp->d_type == DT_REG)){ @@ -369,7 +414,7 @@ void *videogrid_putvideodir_thread(t_videogrid *x) } }else{ /* directori diferent omple la cua començant pel primer fitxer */ - post("Videogrid: Nou directori %s \n", x->x_dir_actual); + /* post("Videogrid: Nou directori %s \n", x->x_dir_actual); */ while ( (direntp = readdir( dirp )) != NULL ){ /* es descarta el mateix directori, el directori anterior i tot el que no sigui un fitxer regular */ if((strcmp(direntp->d_name,"..") != 0)&&(strcmp(direntp->d_name,".") != 0)&&(direntp->d_type == DT_REG)){ @@ -420,44 +465,97 @@ void videogrid_putvideodir(t_videogrid *x, t_symbol *entrada) pthread_mutex_destroy(&x->x_lock); } + +/* v 0.2 -- mètode de la classe que desmarca la cel·la seleccionada */ +static void videogrid_ungrasp_selected(t_videogrid *x) +{ + /* post("Ungrasp selected thumb %d", x->x_pos_selected); */ + if(x->x_pos_selected > -1) { + sys_vgui(".x%x.c delete %xGRASP\n", glist_getcanvas(x->x_glist), x); + x->x_pos_selected = -1; + } +} + +/* v 0.2 -- mètode de la classe que marca la cel·la seleccionada */ +static void videogrid_grasp_selected(t_videogrid *x, int pos) +{ + /*printf("Grasp selected thumb %d", pos);*/ + if(pos != x->x_pos_selected) { + videogrid_ungrasp_selected(x); + /* post("Grasp selected thumb %d", pos); */ + x->x_pos_selected = pos; + /* nem per aqui ---- */ + sys_vgui(".x%x.c create rectangle %d %d %d %d -fill {} -tags %xGRASP -outline %s -width %d\n", + glist_getcanvas(x->x_glist), + text_xpix(&x->x_obj, x->x_glist) + getX(x,x->x_pos_selected), text_ypix(&x->x_obj, x->x_glist) + getY(x,x->x_pos_selected), + text_xpix(&x->x_obj, x->x_glist) + getX(x,x->x_pos_selected) + W_CELL, text_ypix(&x->x_obj, x->x_glist) + getY(x,x->x_pos_selected) + H_CELL, + x,x->x_color_grasp->s_name, GRUIX + 1); + canvas_fixlinesfor(glist_getcanvas(x->x_glist), (t_text*)x); + } +} + +/* v 0.2 -- mètode de la classe que dispara l'element del taules en la posicio N [seek N( */ +void videogrid_seek(t_videogrid *x, t_floatarg postauler) +{ + /* post("seek a %d\n",postauler); */ + path pathSortida; + Node *actual; + int contador = 0; + int maxim = x->x_num_fil * x->x_num_col; + /* obtenir el path per enviar a la sortida */ + if((!cuaBuida(&x->x_cua))&&(postauler < numNodes(&x->x_cua))&&(postauler >= 0 )){ + if(x->x_tauler_primer){ + actual = x->x_tauler_primer; + while(contador <= postauler){ + if(contador == postauler){ + strcpy(pathSortida,actual->pathFitxer); + } + if(actual->seguent == NULL){ + actual = x->x_cua.davanter; + }else{ + actual = actual->seguent; + } + contador++; + } + outlet_symbol(x->x_sortida, gensym(pathSortida)); + /* post("Esta a videogrid_click amb %d %d a la posicio %d\n", x_pos, y_pos, postauler);*/ + /* v 0.2 -- marcar casella */ + videogrid_grasp_selected(x, postauler); + } + } +} + static int videogrid_click(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit) { t_videogrid* x = (t_videogrid *)z; int x_pos = xpix - text_xpix(&x->x_obj, x->x_glist); int y_pos = ypix - text_ypix(&x->x_obj, x->x_glist); - int xa, ya, postauler, contador, maxim; - path pathSortida; - Node *actual; + int xa, ya, postauler; if (doit) { - /* obtenir la posicio en el tauler */ - xa = x_pos / W_CELL; - ya = (y_pos / H_CELL) * x->x_num_col; - postauler = ya + xa; - /* obtenir el path per enviar a la sortida */ - if((!cuaBuida(&x->x_cua))&&(postauler < numNodes(&x->x_cua))){ - contador = 0; - maxim = x->x_num_fil * x->x_num_col; - if(x->x_tauler_primer){ - actual = x->x_tauler_primer; - while(contador <= postauler){ - if(contador == postauler){ - strcpy(pathSortida,actual->pathFitxer); - } - if(actual->seguent == NULL){ - actual = x->x_cua.davanter; - }else{ - actual = actual->seguent; - } - contador++; - } - outlet_symbol(x->x_sortida, gensym(pathSortida)); - } - } + /* obtenir la posicio en el tauler */ + // -- v 0.2 -- midoficacio pel gruix del marc // + xa = ((x_pos) / (W_CELL + GRUIX + 1)); + ya = ((y_pos) / (H_CELL + GRUIX + 1)) * x->x_num_col; + postauler = ya + xa; + // -- v 0.2 -- seleciona la casella disparant el path // + videogrid_seek(x, postauler); } return (1); } +/* v 0.2 -- mètode de la classe que buida el tauler amb el missatge [clear ( */ +void videogrid_clear(t_videogrid *x) +{ + videogrid_erase(x, x->x_glist,1); + eliminarCua(&x->x_cua); + x->x_ultima_img = 0; + x->x_dir_pos = 0; + x->x_tauler_primer = NULL; + videogrid_drawme(x, x->x_glist, 0); +} + + static void videogrid_getrect(t_gobj *z, t_glist *glist,int *xp1, int *yp1, int *xp2, int *yp2) { int cols, fils; @@ -466,8 +564,8 @@ static void videogrid_getrect(t_gobj *z, t_glist *glist,int *xp1, int *yp1, int fils = x->x_num_fil; *xp1 = text_xpix(&x->x_obj, glist); *yp1 = text_ypix(&x->x_obj, glist); - *xp2 = text_xpix(&x->x_obj, glist) + (cols*W_CELL); - *yp2 = text_ypix(&x->x_obj, glist) + (fils*H_CELL); + *xp2 = text_xpix(&x->x_obj, glist) + (cols*W_CELL) + ((cols + 1) * GRUIX); + *yp2 = text_ypix(&x->x_obj, glist) + (fils*H_CELL) + ((fils + 1) * GRUIX); /* post("Esta amb el ratoli en el punt %d %d %d %d o son els vetexs de la caixa... es/bd", xp1, yp1, xp2, yp2); */ } @@ -480,7 +578,7 @@ static void videogrid_displace(t_gobj *z, t_glist *glist,int dx, int dy) sys_vgui(".x%x.c coords %xGRID %d %d %d %d\n", glist_getcanvas(glist), x, text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist), - text_xpix(&x->x_obj, glist) + (x->x_num_col*W_CELL), text_ypix(&x->x_obj, glist) + (x->x_num_fil*H_CELL)); + text_xpix(&x->x_obj, glist) + (x->x_num_col*W_CELL) + 1 + (x->x_num_col * GRUIX) + GRUIX, text_ypix(&x->x_obj, glist) + (x->x_num_fil*H_CELL) + 1 + (x->x_num_fil * GRUIX) + GRUIX); videogrid_drawme(x, glist, 0); canvas_fixlinesfor(glist_getcanvas(glist),(t_text*) x); } @@ -513,7 +611,7 @@ static void videogrid_vis(t_gobj *z, t_glist *glist, int vis) if (vis) videogrid_drawme(s, glist, 1); else - videogrid_erase(s,glist); + videogrid_erase(s,glist,0); } @@ -585,43 +683,73 @@ static void videogrid_save(t_gobj *z, t_binbuf *b) binbuf_addv(b, "ssiissiisss", gensym("#X"),gensym("obj"), x->x_obj.te_xpix, x->x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)), - x->x_name,x->x_num_fil,x->x_num_col,x->x_color_fons,x->x_color_marc,gensym(cadenaPathsInicials)); + x->x_name,x->x_num_fil,x->x_num_col,x->x_color_fons,x->x_color_marc,x->x_color_grasp,gensym(cadenaPathsInicials)); binbuf_addv(b, ";"); } static void videogrid_properties(t_gobj *z, t_glist *owner) { - char buf[800]; + char buf[900]; t_videogrid *x=(t_videogrid *)z; /* post("Es crida a pdtk_videogrid dialog passant nom = %s\n fils = %d \t cols = %d \t color fons = %s \t color marc = %s\n", x->x_name->s_name, x->x_num_fil, x->x_num_col, x->x_color_fons->s_name, x->x_color_marc->s_name); */ - sprintf(buf, "pdtk_videogrid_dialog %%s %s %d %d %s %s\n", - x->x_name->s_name, x->x_num_fil, x->x_num_col, x->x_color_fons->s_name, x->x_color_marc->s_name); + sprintf(buf, "pdtk_videogrid_dialog %%s %s %d %d %s %s %s\n", + x->x_name->s_name, x->x_num_fil, x->x_num_col, x->x_color_fons->s_name, x->x_color_marc->s_name, x->x_color_grasp->s_name); /* post("videogrid_properties : %s", buf ); */ gfxstub_new(&x->x_obj.ob_pd, x, buf); } static void videogrid_dialog(t_videogrid *x, t_symbol *s, int argc, t_atom *argv) { - int maxim, nfil, ncol, maxdigit; + int maxim, maxdigit; + int nfil = 0; + int ncol = 0; if ( !x ) { - post("Videogrid: error_ intent de modificar le propietats d'un objecte inexistent\n"); - } - if ( argc != 5 ) - { - post("Videogrid: error_ sobre el nombre d'arguments ( 5 enlloc de %d )\n",argc); - return; + post("Videogrid: error_ Attempt to alter the properties of an object that does not exist.\n"); } - 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_SYMBOL) - { - post("Videogrid: error_ algun dels arguments no es del tipus adequat\n"); - return; + switch (argc) { + case 3: + /* versio inicial */ + if (argv[0].a_type != A_SYMBOL || argv[1].a_type != A_FLOAT || argv[2].a_type != A_FLOAT) + { + post("Videogrid: error_ Some of the values are inconsistent in its data type.\n"); + return; + } + x->x_name = argv[0].a_w.w_symbol; + nfil = (int)argv[1].a_w.w_float; + ncol = (int)argv[2].a_w.w_float; + break; + case 5: + /* versio 0.1 */ + 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_SYMBOL) + { + post("Videogrid: error_ Some of the values are inconsistent in its data type.\n"); + return; + } + x->x_name = argv[0].a_w.w_symbol; + nfil = (int)argv[1].a_w.w_float; + ncol = (int)argv[2].a_w.w_float; + x->x_color_fons = argv[3].a_w.w_symbol; + x->x_color_marc = argv[4].a_w.w_symbol; + break; + case 6: + /* versio 0.2 */ + 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_SYMBOL || argv[5].a_type != A_SYMBOL) + { + post("Videogrid: error_ Some of the values are inconsistent in its data type.\n"); + return; + } + x->x_name = argv[0].a_w.w_symbol; + nfil = (int)argv[1].a_w.w_float; + ncol = (int)argv[2].a_w.w_float; + x->x_color_fons = argv[3].a_w.w_symbol; + x->x_color_marc = argv[4].a_w.w_symbol; + x->x_color_grasp = argv[5].a_w.w_symbol; + break; + default: + /* no fa res */ + break; } - x->x_name = argv[0].a_w.w_symbol; - nfil = (int)argv[1].a_w.w_float; - ncol = (int)argv[2].a_w.w_float; - x->x_color_fons = argv[3].a_w.w_symbol; - x->x_color_marc = argv[4].a_w.w_symbol; /* el màxim es fixa pel nombre de digits utilitzats pel nom de la imatge temporal */ maxdigit = pow(10,BYTES_NUM_TEMP); if((nfil*ncol) <= maxdigit){ @@ -629,17 +757,16 @@ static void videogrid_dialog(t_videogrid *x, t_symbol *s, int argc, t_atom *argv x->x_num_fil = nfil; x->x_num_col = ncol; }else{ - post("Videogrid: El nombre de files i columnes són inferiors al mímin permès: 1 casella\n",maxdigit); + post("Videogrid: The number of rows and columns is less than the minimum allowed: 1 cell.\n",maxdigit); } }else{ - post("Videogrid: El nombre de files i columnes excedeixen del màxim permès: un total de %d caselles\n",maxdigit); + post("Videogrid: The number of rows and columns exceeds the maximum allowed: a total of %d cells.\n",maxdigit); } - - post("Videogrid: Valors modificats_ nom = %s\n fils = %d \t cols = %d\n", x->x_name->s_name, x->x_num_fil, x->x_num_col); + /* post("Videogrid: Modified values\n name = %s\n rows = %d \t cols = %d.\n", x->x_name->s_name, x->x_num_fil, x->x_num_col); */ /* elimina els nodes no representables amb la nova configuració */ maxim = x->x_num_fil * x->x_num_col; int extret; - videogrid_erase(x, x->x_glist); + videogrid_erase(x, x->x_glist,0); /* si hi ha més nodes a la cua que el maxim */ while((numNodes(&x->x_cua)) > maxim){ /* desencuem */ @@ -682,13 +809,13 @@ static void *videogrid_new(t_symbol* name, int argc, t_atom *argv) x->x_sortida = outlet_new(&x->x_obj,&s_symbol); /* s'obté el canvas de pd */ x->x_glist = (t_glist*) canvas_getcurrent(); - /* posició en el tauler de la última imatge afegida */ x->x_ultima_img = 0; /* posició de l'últim fitxer del directori encuat */ x->x_dir_pos = 0; /* apuntador al primer element en el tauler */ x->x_tauler_primer = NULL; + x->x_pos_selected = -1; /* fixa el nom de l'objecte */ char nom[15]; sprintf(nom, "videogrid%d", ++videogridcount); @@ -698,59 +825,83 @@ static void *videogrid_new(t_symbol* name, int argc, t_atom *argv) pd_bind(&x->x_obj.ob_pd, x->x_name); /* crea la cua de nodes */ crearCua(&x->x_cua); - post("NOU videogrid: s'han entrat %d arguments\n", argc); - - if (argc != 0) - { - post("NOU videogrid: s'obre un objecte existent o amb arguments definits\n"); - /* x->x_name */ - x->x_num_fil = (int)atom_getintarg(1, argc, argv); - x->x_num_col = (int)atom_getintarg(2, argc, argv); - x->x_color_fons = argv[3].a_w.w_symbol; - x->x_color_marc = argv[4].a_w.w_symbol; - post("!!!NOU videogrid: s'han entrat %d arguments\n", argc); - if(argc == 6){ - /* llegir la cadena de paths | afegir els paths a la cua */ - char *cadenaPaths; - cadenaPaths = (char *)malloc(51200*sizeof(char)); - strcpy(cadenaPaths,(char *)argv[5].a_w.w_symbol->s_name); - /* printf("Es carreguen els paths %s --- %s **** %s\n", cadenaPaths, argv[5].a_w.w_symbol->s_name,argv[3].a_w.w_symbol->s_name); */ - /* split */ - - char *token; - t_symbol *tt; - for ( token = strtok(argv[5].a_w.w_symbol->s_name,"|"); - token != NULL; - token = strtok(NULL,"|") ){ - tt = gensym(token); - - /* printf("AFEGINT CARREGANT %s\n",tt->s_name); */ - /* videogrid_putvideo(x,tt); */ - /* DE MOMENT NO AFEGEIX ELS PATHS */ - /* videogrid_afegir_imatge(x,tt->s_name); */ - } - /* - token = strtok(cadenaPaths,"|"); - while(token){ - tt = gensym(token); - printf("AFEGINT CARREGANT %s\n",tt->s_name); - videogrid_putvideo(x,tt); - token = strtok(NULL,"|"); - } - */ - free(cadenaPaths); - } - }else{ - /* crea un objecte nou */ - post("NOU videogrid: es crea un objecte nou\n"); - /* fixa el nombre de files */ - x->x_num_fil = 3; - /* fixa el nombre de columnes */ - x->x_num_col = 5; - - /* colors de fons i de marc*/ - x->x_color_fons = gensym("#F0F0F0"); - x->x_color_marc = gensym("#0F0F0F"); + post("NEW videogrid: created with %d parameters.\n", argc); + + switch (argc) { + case 3: + /* versio inicial */ + x->x_num_fil = (int)atom_getintarg(1, argc, argv); + x->x_num_col = (int)atom_getintarg(2, argc, argv); + x->x_color_fons = gensym("#F0F0F0"); + x->x_color_marc = gensym("#0F0F0F"); + x->x_color_grasp = gensym("#F1882B"); + break; + case 5: + /* versio 0.1 */ + x->x_num_fil = (int)atom_getintarg(1, argc, argv); + x->x_num_col = (int)atom_getintarg(2, argc, argv); + x->x_color_fons = argv[3].a_w.w_symbol; + x->x_color_marc = argv[4].a_w.w_symbol; + x->x_color_grasp = gensym("#F1882B"); + break; + case 6: + /* versio 0.2 */ + x->x_num_fil = (int)atom_getintarg(1, argc, argv); + x->x_num_col = (int)atom_getintarg(2, argc, argv); + x->x_color_fons = argv[3].a_w.w_symbol; + x->x_color_marc = argv[4].a_w.w_symbol; + x->x_color_grasp = argv[5].a_w.w_symbol; + break; + case 7: + /* versio 0.1 - paths dels elsements del tauler */ + x->x_num_fil = (int)atom_getintarg(1, argc, argv); + x->x_num_col = (int)atom_getintarg(2, argc, argv); + x->x_color_fons = argv[3].a_w.w_symbol; + x->x_color_marc = argv[4].a_w.w_symbol; + x->x_color_grasp = argv[5].a_w.w_symbol; + /* + // -- llegir la cadena de paths | afegir els paths a la cua // + // -- ATENCIO! NO AFEGEIX ELS PATHS !!! // + char *cadenaPaths; + cadenaPaths = (char *)malloc(51200*sizeof(char)); + strcpy(cadenaPaths,(char *)argv[6].a_w.w_symbol->s_name); + // -- printf("Es carreguen els paths %s --- %s **** %s\n", cadenaPaths, argv[5].a_w.w_symbol->s_name,argv[3].a_w.w_symbol->s_name); // + // -- split // + char *token; + t_symbol *tt; + for ( token = strtok(argv[6].a_w.w_symbol->s_name,"|"); + token != NULL; + token = strtok(NULL,"|") ){ + tt = gensym(token); + // -- printf("AFEGINT CARREGANT %s\n",tt->s_name); // + // -- imagegrid_putimg(x,tt); // + // -- ATENCIO! NO AFEGEIX ELS PATHS !!! // + // -- imagegrid_afegir_imatge(x,tt->s_name); // + } + + token = strtok(cadenaPaths,"|"); + while(token){ + tt = gensym(token); + printf("AFEGINT CARREGANT %s\n",tt->s_name); + imagegrid_putimg(x,tt); + token = strtok(NULL,"|"); + } + free(cadenaPaths); + */ + break; + + default: + /* crea un objecte nou per defecte */ + /* post("NEW imagegrid created.\n"); */ + /* fixa el nombre de files */ + x->x_num_fil = 3; + /* fixa el nombre de columnes */ + x->x_num_col = 5; + /* colors de fons i de marc*/ + x->x_color_fons = gensym("#F0F0F0"); + x->x_color_marc = gensym("#0F0F0F"); + x->x_color_grasp = gensym("#F1882B"); + break; } /* printf("S'ha instanciat un videogrid anomenat %s amb les caracteristiques seguents:",x->x_name->s_name); printf("Nombre de files %d - Nombre de columnes: %d", x->x_num_fil, x->x_num_col); */ @@ -761,7 +912,7 @@ static void *videogrid_new(t_symbol* name, int argc, t_atom *argv) static void videogrid_destroy(t_videogrid *x){ /* elimina el contingut de la cua */ eliminarCua(&x->x_cua); - post("Videogrid eliminat"); + post("Videogrid destroyed.\n"); } /* generacio d'una nova classe */ @@ -814,6 +965,10 @@ void videogrid_setup(void) class_addmethod(videogrid_class, (t_method)videogrid_dialog, gensym("dialog"), A_GIMME, 0); /* afegeix un metode per l'obtencio de la posicio del clic del ratolí */ class_addmethod(videogrid_class, (t_method)videogrid_click, gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0); + /* v 0.2 -- afegeix un metode netejar el contigut del tauler */ + class_addmethod(videogrid_class, (t_method)videogrid_clear, gensym("clear"), 0); + /* v 0.2 -- afegeix un metode seek #num per disparar */ + class_addmethod(videogrid_class, (t_method)videogrid_seek, gensym("seek"), A_FLOAT, 0); /* inicia el comportament de videogrid */ videogrid_setwidget(); -- cgit v1.2.1