is there documentation for what binbufs are and how they're used?
I think you just have to read the source code in m_binbuf.c. But here's a general guide: Binbufs are containers for atoms. Unlike Pd lists, it can contain "special" atoms like A_SEMI or A_DOLLSYM. binbuf_text() converts a C string to a list of atoms. bufbuf_gettext() converts the atoms back to a C string. binbuf_add() simply adds any kind of atoms to the binbuf binbuf_getnatom() returns the size binbuf_getvec() returns a pointer to the atoms. binbuf_addbinbuf() adds the content of another binbuf (possible containing "special" atoms) but bashes everything to A_FLOAT and A_SYMBOL binbuf_restore() adds a list of atoms but restores "special" atoms from symbols, e.g. ";" -> A_SEMI, "\$0-foo" -> A_DOLLSYM, etc. binbuf_eval() evaluates the stored binbuf by sending it as a message to the given target. You can also pass an atom list as arguments, e.g. for a dollar symbols like "$1-foo". "$0" is always substituted with the dollar zero of the current canvas (see canvas_getdollarzero, canvas_getcurrent and canvas_setcurrent). Note that a A_SEMI atom will denote the start of a new message and the following atom will be taken as the new message target (must be a symbol). Here's an example (taken from x_text.c):
a) The patch file:
static char text_templatefile[] = "\ canvas 0 0 458 153 10;\n\ #X obj 43 31 struct text float x float y text t;\n\ ";
b) create a binbuf
binbuf_text(b, text_templatefile, strlen(text_templatefile));
c) evaluate
binbuf_eval(b, &pd_canvasmaker, 0, 0);
Here's what happens:
1) "canvas 0 0 458 153 10;" goes to canvas maker -> create a new canvas, push it on the loading stack and bind #X to the canvas. 2) the ";" terminates the messages and begins a new one. "#X" (= our canvas) will be the new target. 3) "obj 43 31 struct text float x float y text t;" asks the canvas to create an object (like in dynamic patching) 4) vmess(s__X.s_thing, gensym("pop"), "i", 0) sends the "pop" messages to the canvas. This effectively pops the canvas from the stack and #X is restored to whatever it has been bound before. Hope that helps. Christof
Gesendet: Montag, 05. August 2019 um 21:55 Uhr Von: "x nor" x37v.alex@gmail.com An: "Christof Ressi" christof.ressi@gmx.at Cc: pd-dev pd-dev@lists.iem.at Betreff: Re: [PD-dev] can externals create data structures/templates?
Great, Thanks Christof! That reminds me, is there documentation for what binbufs are and how they're used? It is something I haven't worked with and `m_pd.h` lacks documentation.
On Mon, Aug 5, 2019 at 12:52 PM Christof Ressi <christof.ressi@gmx.at[mailto:christof.ressi@gmx.at]> wrote:
Hi,
if it is possible to write externals that generate structs/templates?
Yes, actually Pd itself does this for the private templates needed by [array] and [text], have a look at garray_init() in g_array.c or text_template_init() in x_text.c. The patch is just a C string which you put into a binbuf which gets evaluated with pd_canvasmaker as the target. You can also create patches programmatically: 1) create the canvas: https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp#L521%5Bht...] 2) fill it with stuff: https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp#L649%5Bht...] Christof
Gesendet: Montag, 05. August 2019 um 21:10 Uhr Von: "x nor" <x37v.alex@gmail.com[mailto:x37v.alex@gmail.com]> An: pd-dev <pd-dev@lists.iem.at[mailto:pd-dev@lists.iem.at]> Betreff: [PD-dev] can externals create data structures/templates?
I'm starting to work with data structures and I'm curious if it is possible to write externals that generate structs/templates? Are there any examples of this? I guess I can do dynamic patching if not? Thanks!_______________________________________________ Pd-dev mailing list Pd-dev@lists.iem.at[mailto:Pd-dev@lists.iem.at] https://lists.puredata.info/listinfo/pd-dev