From f5737db3d985231b0d918fb2bf44feb67bbbd07c Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 11 Apr 2009 21:35:35 +0000 Subject: an object to get what is currently in the canvas-local path svn path=/trunk/externals/hcs/; revision=11006 --- ce_path-help.pd | 20 ++++++++++++ ce_path.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 ce_path-help.pd create mode 100644 ce_path.c diff --git a/ce_path-help.pd b/ce_path-help.pd new file mode 100644 index 0000000..5a4869b --- /dev/null +++ b/ce_path-help.pd @@ -0,0 +1,20 @@ +#N canvas 121 22 423 338 10; +#X declare -lib cyclone -lib mapping -lib zexy; +#X msg 21 52 bang; +#X symbolatom 32 170 0 0 0 0 - - -; +#X obj 21 246 print; +#X text 80 75 start at the top of the list again; +#X msg 33 76 rewind; +#X obj 21 129 ce_path; +#X obj 61 150 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 +-1; +#X text 81 148 done; +#X text 68 51 get next item in list of canvas-local paths; +#X text 29 269 Sending bangs to [ce_path] makes it output the loaded +paths one at a time.; +#X obj 226 10 import cyclone mapping zexy; +#X connect 0 0 5 0; +#X connect 4 0 5 0; +#X connect 5 0 1 0; +#X connect 5 0 2 0; +#X connect 5 1 6 0; diff --git a/ce_path.c b/ce_path.c new file mode 100644 index 0000000..7d04b0d --- /dev/null +++ b/ce_path.c @@ -0,0 +1,97 @@ +/* + * This object allows you to see what is currently in the canvas-local path. + */ + +#include "m_pd.h" +#include "s_stuff.h" +#include "g_canvas.h" + +#include +#include +#include + +/* WARNING: KLUDGE! */ +/* + * this struct is not publically defined (its in g_canvas.c) so I need to + * include this here. Its from Pd 0.41-test03 2006-11-19. */ +struct _canvasenvironment +{ + t_symbol *ce_dir; /* directory patch lives in */ + int ce_argc; /* number of "$" arguments */ + t_atom *ce_argv; /* array of "$" arguments */ + int ce_dollarzero; /* value of "$0" */ + t_namelist *ce_path; /* search path */ +}; + +//static char *version = "$Revision: 1.2 $"; + +#define DEBUG(x) +//#define DEBUG(x) x + +/*------------------------------------------------------------------------------ + * CLASS DEF + */ +t_class *ce_path_class; + +typedef struct _ce_path +{ + t_object x_obj; + t_canvasenvironment *x_canvasenvironment; + t_namelist *x_current; + t_outlet *x_data_outlet; + t_outlet *x_status_outlet; +} t_ce_path; + +static void ce_path_output(t_ce_path* x) +{ + DEBUG(post("ce_path_output");); + char buffer[FILENAME_MAX]; + +/* TODO: think about using x->x_current->nl_next so that if [ce_path] is at + * the end of its list, and another element gets added to the local + * namespace, [ce_path] will output the new element on the next bang. */ + if(x->x_current) + { + strncpy(buffer, x->x_current->nl_string, FILENAME_MAX); + outlet_symbol( x->x_data_outlet, gensym(buffer)); + x->x_current = x->x_current->nl_next; + } + else + outlet_bang(x->x_status_outlet); +} + + +static void ce_path_rewind(t_ce_path* x) +{ + x->x_current = x->x_canvasenvironment->ce_path; +} + + +static void *ce_path_new(void) +{ + t_ce_path *x = (t_ce_path *)pd_new(ce_path_class); + + x->x_data_outlet = outlet_new(&x->x_obj, &s_symbol); + x->x_status_outlet = outlet_new(&x->x_obj, 0); + + x->x_canvasenvironment = canvas_getenv(canvas_getcurrent()); + ce_path_rewind(x); + + return (x); +} + +void ce_path_setup(void) +{ + ce_path_class = class_new(gensym("ce_path"), (t_newmethod)ce_path_new, + NULL, + sizeof(t_ce_path), + CLASS_DEFAULT, + 0, + 0); + /* add inlet atom methods */ + class_addbang(ce_path_class, (t_method) ce_path_output); + + /* add inlet selector methods */ + class_addmethod(ce_path_class, (t_method) ce_path_rewind, + gensym("rewind"), 0); +} -- cgit v1.2.1