Le 2011-11-20 à 22:23:00, Jonathan Wilkes a écrit :
----- Original Message -----
From: Mathieu Bouchard <[email protected]>
Le 2011-11-16 à 18:06:00, Jonathan Wilkes a écrit :
From: Mathieu Bouchard <[email protected]>
http://artengine.ca/desiredata/gallery/unpost.gif
But this external would require a modification to pd that has been
circulating on the net since 2003 and rejected by Miller in 2004.
What's the modification? Is it on the tracker?
Actually, I don't find it in the bug tracker nor the patch tracker.
Don't worry, it's somewhere in SourceForget.
What's printhook?
It's the feature that redirects the formatted output of [print] and post()
and error() to a single destination.
[unpost] changes this at runtime while keeping a backup, sends a message,
and when the call returns, it restores the backup. That's all.
Here's the source code of [unpost] :
-----------------8<--------découpez-ici--------8<-----------------
static t_class *unpost_class;
struct t_unpost : t_object {
t_outlet *o0,*o1;
};
struct t_unpost_frame {
t_unpost *self;
std::ostringstream buf;
};
static t_unpost_frame *current_unpost;
void *unpost_new (t_symbol *s) {
t_unpost *x = (t_unpost *)pd_new(unpost_class);
x->o0 = outlet_new(x,&s_symbol);
x->o1 = outlet_new(x,&s_symbol);
return x;
}
extern t_printhook sys_printhook;
void unpost_printhook (const char *s) {
std::ostringstream &b = current_unpost->buf;
b << s;
const char *p;
const char *d=b.str().data(),*dd=d;
for (;;) {
p = strchr(d,'\n');
if (!p) break;
current_unpost->self->o1->send(gensym2(d,p-d));
d=p+1;
}
if (d!=dd) {
char *q = strdup(d); /* well i could use memmove, but i'm not supposed
to use strcpy because of overlap */
current_unpost->buf.clear();
current_unpost->buf << q;
free(q);
}
}
void unpost_anything (t_unpost *x, t_symbol *s, int argc, t_atom *argv) {
t_printhook backup1 = sys_printhook;
t_unpost_frame *backup2 = current_unpost;
sys_printhook = unpost_printhook;
current_unpost = new t_unpost_frame;
current_unpost->self = x;
x->o0->send(s,argc,argv);
sys_printhook = backup1;
current_unpost = backup2;
}
______________________________________________________________________
| Mathieu BOUCHARD ----- téléphone : +1.514.383.3801 ----- Montréal, QC_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management ->
http://lists.puredata.info/listinfo/pd-list