aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-06-18 19:11:53 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2010-06-18 19:11:53 +0000
commit1ba8af86e09cd23be8e91522b1716dc477227680 (patch)
tree5a02963e47b2ae4e34a573bb4673bab0a145bca0
parent500dfb45f31824ad159f04372cd27ed4948389bd (diff)
simplified interface as much as possible, left inlet controls which element is shown, right inlet sets the pattern. also added a float method to select the element in the list based on number
svn path=/trunk/externals/ezfile/; revision=13673
-rw-r--r--getfilenames-help.pd79
-rw-r--r--getfilenames.c84
2 files changed, 80 insertions, 83 deletions
diff --git a/getfilenames-help.pd b/getfilenames-help.pd
index 1f063b4..ca2759b 100644
--- a/getfilenames-help.pd
+++ b/getfilenames-help.pd
@@ -1,48 +1,53 @@
-#N canvas 118 89 529 471 10;
+#N canvas 341 57 529 471 10;
#X msg 19 73 bang;
-#X msg 28 364 bang;
-#X obj 170 340 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+#X msg 29 387 bang;
+#X obj 172 363 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
-#X obj 12 429 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+#X obj 12 435 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
-#X msg 176 296 symbol /usr/*;
-#X text 160 278 set pattern without no output;
-#X obj 28 395 getfilenames;
-#X obj 83 318 getfilenames /*;
-#X obj 83 339 print;
-#X obj 29 428 print;
-#X msg 104 185 symbol ~/*.*;
-#X text 200 236 relative paths work;
-#X msg 115 237 symbol ../*;
-#X text 177 163 drive letters work on ReactOS/Windows;
-#X msg 90 162 symbol C:/*;
-#X text 203 187 all files with a dot in your home;
-#X msg 53 137 symbol %USERPROFILE%/*;
-#X text 216 138 ReactOS/Windows environment variables work;
-#X text 275 257 nested wildcards work on UNIX;
-#X msg 132 258 symbol /var/*/*.log;
-#X text 186 212 patterns default to path that Pd launched from;
+#X obj 29 409 getfilenames;
+#X obj 85 341 getfilenames /*;
+#X obj 85 362 print;
+#X obj 29 434 print;
+#X text 234 259 relative paths work;
+#X text 211 186 drive letters work on ReactOS/Windows;
+#X text 237 210 all files with a dot in your home;
+#X text 263 161 ReactOS/Windows environment variables work;
+#X text 309 280 nested wildcards work on UNIX;
+#X text 220 235 patterns default to path that Pd launched from;
#X text 8 5 Get a listing of files based on a wildcard pattern. On
UNIX \, it follows glob rules \, on ReactOS/Windows it follows the
cmd.exe rules.;
-#X text 116 389 With no argument \, it defaults to the contents of
+#X text 117 403 With no argument \, it defaults to the contents of
the folder of the current patch \, i.e. "/path/to/current/patch/*".
;
-#X msg 110 212 symbol *.pd;
#X text 54 73 get next file;
#X msg 34 99 rewind;
#X text 81 98 go back to the beginning of the file list;
-#X connect 0 0 7 0;
-#X connect 1 0 6 0;
-#X connect 4 0 7 1;
-#X connect 6 0 3 0;
-#X connect 6 0 9 0;
-#X connect 7 0 8 0;
-#X connect 7 1 2 0;
-#X connect 10 0 7 0;
-#X connect 12 0 7 0;
-#X connect 14 0 7 0;
-#X connect 16 0 7 0;
-#X connect 19 0 7 0;
-#X connect 23 0 7 0;
-#X connect 25 0 7 0;
+#X obj 51 128 hsl 128 15 0 127 0 0 empty empty empty -2 -8 0 10 -262144
+-1 -1 1000 1;
+#X text 186 128 or choose by position;
+#X floatatom 62 149 5 0 0 0 - - -;
+#X msg 149 260 symbol ../*;
+#X msg 178 319 symbol /usr/*;
+#X msg 166 281 symbol /var/*/*.log;
+#X msg 144 235 symbol *.pd;
+#X msg 138 208 symbol ~/*.*;
+#X msg 124 185 symbol C:/*;
+#X msg 100 160 symbol %USERPROFILE%/*;
+#X connect 0 0 5 0;
+#X connect 1 0 4 0;
+#X connect 4 0 3 0;
+#X connect 4 0 7 0;
+#X connect 5 0 6 0;
+#X connect 5 1 2 0;
+#X connect 17 0 5 0;
+#X connect 19 0 5 0;
+#X connect 19 0 21 0;
+#X connect 22 0 5 1;
+#X connect 23 0 5 1;
+#X connect 24 0 5 1;
+#X connect 25 0 5 1;
+#X connect 26 0 5 1;
+#X connect 27 0 5 1;
+#X connect 28 0 5 1;
diff --git a/getfilenames.c b/getfilenames.c
index 580069c..55c3d29 100644
--- a/getfilenames.c
+++ b/getfilenames.c
@@ -47,9 +47,9 @@ static t_class *getfilenames_class;
typedef struct _getfilenames {
t_object x_obj;
- t_symbol* x_pattern;
t_canvas* x_canvas;
- int isnewpattern;
+ t_symbol* x_pattern;
+ t_symbol* active_pattern;
#ifdef _WIN32
HANDLE hFind;
#else
@@ -71,8 +71,21 @@ static void normalize_path(t_getfilenames* x, char *normalized, const char *orig
char buf[FILENAME_MAX];
t_symbol *cwd = canvas_getdir(x->x_canvas);
#ifdef _WIN32
- sys_unbashfilename(original, buf);
+ char patternBuffer[FILENAME_MAX];
+ char envVarBuffer[FILENAME_MAX];
+ if( (original[0] == '~') && (original[1] == '/'))
+ {
+ strcpy(patternBuffer,"%USERPROFILE%");
+ strncat(patternBuffer, original + 1, FILENAME_MAX - 1);
+ }
+ else
+ {
+ patternBuffer = original;
+ }
+ ExpandEnvironmentStrings(patternBuffer, envVarBuffer, FILENAME_MAX - 2);
+ sys_unbashfilename(envVarBuffer, buf);
#else
+ // TODO translate env vars to a full path using /bin/sh and exec
strncpy(buf, original, FILENAME_MAX);
#endif
if(sys_isabsolutepath(buf)) {
@@ -104,7 +117,7 @@ static void getfilenames_rewind(t_getfilenames* x)
DEBUG(post("getfilenames_rewind"););
char normalized_path[FILENAME_MAX] = "";
- normalize_path(x, normalized_path, x->x_pattern->s_name);
+ normalize_path(x, normalized_path, x->active_pattern->s_name);
#ifdef _WIN32
WIN32_FIND_DATA findData;
HANDLE hFind;
@@ -128,7 +141,8 @@ static void getfilenames_rewind(t_getfilenames* x)
{
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
- pd_error(x,"[getfilenames] nothing found for \"%s\"",x->x_pattern->s_name);
+ pd_error(x,"[getfilenames] nothing found for \"%s\"",
+ x->active_pattern->s_name);
break;
default:
FormatMessage(
@@ -182,45 +196,13 @@ static void getfilenames_rewind(t_getfilenames* x)
#endif /* _WIN32 */
}
-
-static void getfilenames_set(t_getfilenames* x, t_symbol *s)
-{
- DEBUG(post("getfilenames_set"););
-#ifdef _WIN32
- char *patternBuffer;
- char envVarBuffer[FILENAME_MAX];
- if( (s->s_name[0] == '~') && (s->s_name[1] == '/'))
- {
- patternBuffer = getbytes(FILENAME_MAX);
- strcpy(patternBuffer,"%USERPROFILE%");
- strncat(patternBuffer, s->s_name + 1, FILENAME_MAX - 1);
- post("set: %s", patternBuffer);
- }
- else
- {
- patternBuffer = s->s_name;
- }
- ExpandEnvironmentStrings(patternBuffer, envVarBuffer, FILENAME_MAX - 2);
- x->x_pattern = gensym(envVarBuffer);
-#else // UNIX
- // TODO translate env vars to a full path using /bin/sh and exec
- x->x_pattern = s;
-#endif /* _WIN32 */
-}
-
-
-static void getfilenames_symbol(t_getfilenames *x, t_symbol *s)
-{
- getfilenames_set(x,s);
- x->isnewpattern = 1;
-}
-
static void getfilenames_bang(t_getfilenames *x)
{
- if(x->isnewpattern)
+ if(x->x_pattern != x->active_pattern)
{
+ x->active_pattern = x->x_pattern;
+ post("x->active_pattern %s x->x_pattern %s", x->active_pattern->s_name, x->x_pattern->s_name);
getfilenames_rewind(x);
- x->isnewpattern = 0;
}
if(x->current_glob_position < x->glob_buffer.gl_pathc)
{
@@ -232,6 +214,16 @@ static void getfilenames_bang(t_getfilenames *x)
outlet_bang(x->status_outlet);
}
+static void getfilenames_float(t_getfilenames *x, t_float f)
+{
+ unsigned int position = (unsigned int)f;
+ if(x->current_glob_position != position)
+ {
+ x->current_glob_position = position;
+ getfilenames_bang(x);
+ }
+}
+
static void *getfilenames_new(t_symbol *s)
{
DEBUG(post("getfilenames_new"););
@@ -240,7 +232,7 @@ static void *getfilenames_new(t_symbol *s)
t_symbol *currentdir;
char buffer[MAXPDSTRING];
- x->x_canvas = canvas_getcurrent();
+ x->x_canvas = canvas_getcurrent();
symbolinlet_new(&x->x_obj, &x->x_pattern);
x->data_outlet = outlet_new(&x->x_obj, &s_symbol);
@@ -250,6 +242,7 @@ static void *getfilenames_new(t_symbol *s)
if (s != &s_)
{
x->x_pattern = s;
+ verbose(4, "setting pattern to: %s", x->x_pattern->s_name);
}
else
{
@@ -257,9 +250,10 @@ static void *getfilenames_new(t_symbol *s)
strncpy(buffer,currentdir->s_name,MAXPDSTRING);
strncat(buffer,"/*",MAXPDSTRING);
x->x_pattern = gensym(buffer);
- post("setting pattern to default: *");
+ verbose(4, "setting pattern to default: *");
}
- x->isnewpattern = 1;
+ /* this is activated in getfilenames_bang() */
+ x->active_pattern = &s_;
return (x);
}
@@ -281,11 +275,9 @@ void getfilenames_setup(void)
0);
/* add inlet datatype methods */
class_addbang(getfilenames_class, (t_method) getfilenames_bang);
- class_addsymbol(getfilenames_class, (t_method) getfilenames_symbol);
+ class_addfloat(getfilenames_class, (t_method) getfilenames_float);
/* add inlet message methods */
- class_addmethod(getfilenames_class, (t_method) getfilenames_set,
- gensym("set"), A_DEFSYMBOL, 0);
class_addmethod(getfilenames_class, (t_method) getfilenames_rewind,
gensym("rewind"), 0);
}