aboutsummaryrefslogtreecommitdiff
path: root/playlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'playlist.c')
-rw-r--r--playlist.c1294
1 files changed, 648 insertions, 646 deletions
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);
}