- New CITP/MSEx menu. Init protocol and make thumbs options

This commit is contained in:
Santi Noreña 2013-02-12 15:07:08 +01:00
parent ef52ae20d8
commit 2d1bbe0e37
12 changed files with 674 additions and 727 deletions

View file

@ -1,11 +1,11 @@
/* --------------------------------------------------------------------------*/
/* */
/* object for getting files */
/* */
/* Based on folderlist by Hans-Christoph Steiner <hans@eds.org> */
/* */
/* Copyright (c) 2013 Santi Noreña <belfegor@gmail.com> */
/* */
/* object for getting files from a source tree
Copyright (c) 2013 Santi Noreña <belfegor@gmail.com>
Based on folderlist by Hans-Christoph Steiner <hans@eds.org> */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation; either version 3 */
@ -30,11 +30,6 @@
#include <stdio.h>
#include <string.h>
//static char *version = "$Revision: 0.01 $";
#define DEBUG(x)
/*------------------------------------------------------------------------------
* CLASS DEF
*/
@ -43,10 +38,10 @@ static t_class *fileselector_class;
typedef struct _fileselector {
t_object x_obj;
t_symbol* x_pattern;
int x_folder;
int x_file;
int x_type;
t_outlet *x_out;
int x_folder;
int x_file;
int x_type;
t_outlet *x_out;
} t_fileselector;
/*------------------------------------------------------------------------------
@ -57,105 +52,140 @@ static void fileselector_output(t_fileselector* x)
{
if (strlen(x->x_pattern->s_name) < 6)
{
post("fileselector: Set path first");
return;
}
char path[FILENAME_MAX] = "";
post("fileselector: Set path first");
return;
}
char path[FILENAME_MAX] = "";
glob_t glob_buffer;
unsigned int i;
unsigned int i;
strncpy(path, x->x_pattern->s_name, FILENAME_MAX);
if(sys_isabsolutepath(path)) {
if(x->x_type < 25) // Make the path video
{
return;
}
if((x->x_type > 24) && (x->x_type<50)) // Make the path video
{
strncat(path,"/video/*",8);
glob_t glob_video;
switch(glob(path, GLOB_TILDE, NULL, &glob_video))
{
case GLOB_NOSPACE:
pd_error(x,"[fileselector] out of memory for \"%s\"",path);
break;
# ifdef GLOB_ABORTED
case GLOB_ABORTED:
pd_error(x,"[fileselector] aborted \"%s\"",path);
break;
# endif
# ifdef GLOB_NOMATCH
case GLOB_NOMATCH:
pd_error(x,"[fileselector] nothing found for %s ",path);
break;
# endif
}
i = x->x_folder;
if (i < glob_video.gl_pathc)
{
strncpy(path, glob_video.gl_pathv[i],strnlen(glob_video.gl_pathv[i],FILENAME_MAX));
strncat(path, "/*", 2);
globfree(&glob_video);
}
else
{
post("fileselector: folder is greater than the number of folders");
globfree(&glob_video);
return;
}
}
if((x->x_type > 49) && (x->x_type<75)) // Make the path image
{
strncat(path,"/image/*",8);
}
if((x->x_type > 74) && (x->x_type<100)) // Make the path image
{
strncat(path,"/fonts/*",8);
}
switch(glob(path, GLOB_TILDE, NULL,&glob_buffer))
{
case GLOB_NOSPACE:
pd_error(x,"[fileselector] out of memory for \"%s\"",path);
break;
# ifdef GLOB_ABORTED
case GLOB_ABORTED:
pd_error(x,"[fileselector] aborted \"%s\"",path);
break;
# endif
# ifdef GLOB_NOMATCH
case GLOB_NOMATCH:
pd_error(x,"[fileselector] nothing found for \"%s\"",path);
break;
# endif
}
i = x->x_file;
if (i < glob_buffer.gl_pathc)
{
outlet_symbol(x->x_out, gensym(glob_buffer.gl_pathv[i]));
}
if(x->x_type < 25) // Make the path video
{
return;
}
if((x->x_type > 24) && (x->x_type<50)) // Make the path video
{
strncat(path,"/video/*",8);
glob_t glob_video;
switch(glob(path, GLOB_TILDE, NULL, &glob_video))
{
case GLOB_NOSPACE:
pd_error(x,"[fileselector] out of memory for \"%s\"",path);
break;
# ifdef GLOB_ABORTED
case GLOB_ABORTED:
pd_error(x,"[fileselector] aborted \"%s\"",path);
break;
# endif
# ifdef GLOB_NOMATCH
case GLOB_NOMATCH:
pd_error(x,"[fileselector] nothing found for %s ",path);
break;
# endif
}
i = x->x_folder;
if (i < glob_video.gl_pathc)
{
strncpy(path, glob_video.gl_pathv[i],strnlen(glob_video.gl_pathv[i],FILENAME_MAX));
strncat(path, "/*", 2);
globfree(&glob_video);
}
else
{
post("fileselector: folder is greater than the number of folders");
globfree(&glob_video);
return;
}
}
if((x->x_type > 49) && (x->x_type<75)) // Make the path image
{
strncat(path,"/image/*",8);
}
if((x->x_type > 74) && (x->x_type<100)) // Make the path image
{
strncat(path,"/fonts/*",8);
}
globfree( &(glob_buffer) );
if(x->x_type > 255) // Make the path sound
{
strncat(path,"/sound/*",8);
glob_t glob_audio;
switch(glob(path, GLOB_TILDE, NULL, &glob_audio))
{
case GLOB_NOSPACE:
pd_error(x,"[fileselector] out of memory for \"%s\"",path);
break;
# ifdef GLOB_ABORTED
case GLOB_ABORTED:
pd_error(x,"[fileselector] aborted \"%s\"",path);
break;
# endif
# ifdef GLOB_NOMATCH
case GLOB_NOMATCH:
pd_error(x,"[fileselector] nothing found for %s ",path);
break;
# endif
}
i = x->x_folder;
if (i < glob_audio.gl_pathc)
{
strncpy(path, glob_audio.gl_pathv[i],strnlen(glob_audio.gl_pathv[i],FILENAME_MAX));
strncat(path, "/*", 2);
globfree(&glob_audio);
}
else
{
post("fileselector: folder is greater than the number of folders");
globfree(&glob_audio);
return;
}
}
// Look for the file
switch(glob(path, GLOB_TILDE, NULL,&glob_buffer))
{
case GLOB_NOSPACE:
pd_error(x,"[fileselector] out of memory for \"%s\"",path);
break;
# ifdef GLOB_ABORTED
case GLOB_ABORTED:
pd_error(x,"[fileselector] aborted \"%s\"",path);
break;
# endif
# ifdef GLOB_NOMATCH
case GLOB_NOMATCH:
pd_error(x,"[fileselector] nothing found for \"%s\"",path);
break;
# endif
}
i = x->x_file;
if (i < glob_buffer.gl_pathc)
{
outlet_symbol(x->x_out, gensym(glob_buffer.gl_pathv[i]));
}
}
globfree( &(glob_buffer) );
}
static void fileselector_set(t_fileselector* x, t_symbol *s)
{
x->x_pattern = s;
x->x_pattern = s;
}
static void fileselector_folder(t_fileselector* x, t_floatarg f)
{
x->x_folder = f;
return;
x->x_folder = f;
return;
}
static void fileselector_file(t_fileselector* x, t_floatarg f)
{
x->x_file = f;
x->x_file = f;
return;
}
static void fileselector_type(t_fileselector* x, t_floatarg f)
{
x->x_type = f;
x->x_type = f;
return;
}
@ -181,8 +211,8 @@ void fileselector_setup(void)
// add inlet folder
class_addmethod(fileselector_class,(t_method)fileselector_folder,gensym("folder"),A_FLOAT, 0);
// add inlet file
class_addmethod(fileselector_class,(t_method)fileselector_file,gensym("file"),A_FLOAT, 0);
class_addmethod(fileselector_class,(t_method)fileselector_file,gensym("file"),A_FLOAT, 0);
// add inlet type
class_addmethod(fileselector_class,(t_method)fileselector_type,gensym("type"),A_FLOAT, 0);
class_addmethod(fileselector_class,(t_method)fileselector_type,gensym("type"),A_FLOAT, 0);
}