<div dir="ltr"><div>great, that is very helpful Christof!</div><div>THANKS!<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 5, 2019 at 1:39 PM Christof Ressi <<a href="mailto:christof.ressi@gmx.at">christof.ressi@gmx.at</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> is there documentation for what binbufs are and how they're used?<br>
 <br>
I think you just have to read the source code in m_binbuf.c. But here's a general guide:<br>
 <br>
Binbufs are containers for atoms. Unlike Pd lists, it can contain "special" atoms like A_SEMI or A_DOLLSYM.<br>
 <br>
binbuf_text() converts a C string to a list of atoms.<br>
bufbuf_gettext() converts the atoms back to a C string.<br>
 <br>
binbuf_add() simply adds any kind of atoms to the binbuf<br>
binbuf_getnatom() returns the size<br>
binbuf_getvec() returns a pointer to the atoms.<br>
 <br>
binbuf_addbinbuf() adds the content of another binbuf (possible containing "special" atoms) but bashes everything to A_FLOAT and A_SYMBOL<br>
binbuf_restore() adds a list of atoms but restores "special" atoms from symbols, e.g. ";" -> A_SEMI, "\\$0-foo" -> A_DOLLSYM, etc.<br>
 <br>
binbuf_eval() evaluates the stored binbuf by sending it as a message to the given target.<br>
You can also pass an atom list as arguments, e.g. for a dollar symbols like "$1-foo".<br>
"$0" is always substituted with the dollar zero of the current canvas (see canvas_getdollarzero, canvas_getcurrent and canvas_setcurrent).<br>
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).<br>
 <br>
Here's an example (taken from x_text.c):<br>
<br>
a) The patch file:<br>
<br>
static char text_templatefile[] = "\<br>
canvas 0 0 458 153 10;\n\<br>
#X obj 43 31 struct text float x float y text t;\n\<br>
";<br>
<br>
b) create a binbuf<br>
<br>
binbuf_text(b, text_templatefile, strlen(text_templatefile));<br>
<br>
c) evaluate<br>
<br>
binbuf_eval(b, &pd_canvasmaker, 0, 0);<br>
<br>
Here's what happens:<br>
<br>
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.<br>
2) the ";" terminates the messages and begins a new one. "#X" (= our canvas) will be the new target.<br>
3) "obj 43 31 struct text float x float y text t;" asks the canvas to create an object (like in dynamic patching)<br>
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.<br>
 <br>
Hope that helps.<br>
 <br>
Christof<br>
 <br>
 <br>
 <br>
<br>
Gesendet: Montag, 05. August 2019 um 21:55 Uhr<br>
Von: "x nor" <<a href="mailto:x37v.alex@gmail.com" target="_blank">x37v.alex@gmail.com</a>><br>
An: "Christof Ressi" <<a href="mailto:christof.ressi@gmx.at" target="_blank">christof.ressi@gmx.at</a>><br>
Cc: pd-dev <<a href="mailto:pd-dev@lists.iem.at" target="_blank">pd-dev@lists.iem.at</a>><br>
Betreff: Re: [PD-dev] can externals create data structures/templates?<br>
<br>
Great, Thanks Christof!<br>
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. <br>
<br>
On Mon, Aug 5, 2019 at 12:52 PM Christof Ressi <<a href="mailto:christof.ressi@gmx.at" target="_blank">christof.ressi@gmx.at</a>[mailto:<a href="mailto:christof.ressi@gmx.at" target="_blank">christof.ressi@gmx.at</a>]> wrote:<br>
<br>
Hi,<br>
 <br>
> if it is possible to write externals that generate structs/templates?<br>
 <br>
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.<br>
 <br>
The patch is just a C string which you put into a binbuf which gets evaluated with pd_canvasmaker as the target.<br>
 <br>
You can also create patches programmatically:<br>
 <br>
1) create the canvas: <a href="https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp#L521[https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp%23L521]" rel="noreferrer" target="_blank">https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp#L521[https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp#L521]</a><br>
 <br>
2) fill it with stuff: <a href="https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp#L649[https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp%23L649]" rel="noreferrer" target="_blank">https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp#L649[https://git.iem.at/pd/vstplugin/blob/develop/pd/src/vstplugin~.cpp#L649]</a><br>
 <br>
Christof<br>
 <br>
<br>
Gesendet: Montag, 05. August 2019 um 21:10 Uhr<br>
Von: "x nor" <<a href="mailto:x37v.alex@gmail.com" target="_blank">x37v.alex@gmail.com</a>[mailto:<a href="mailto:x37v.alex@gmail.com" target="_blank">x37v.alex@gmail.com</a>]><br>
An: pd-dev <<a href="mailto:pd-dev@lists.iem.at" target="_blank">pd-dev@lists.iem.at</a>[mailto:<a href="mailto:pd-dev@lists.iem.at" target="_blank">pd-dev@lists.iem.at</a>]><br>
Betreff: [PD-dev] can externals create data structures/templates?<br>
<br>
I'm starting to work with data structures and I'm curious if it is possible to write externals that generate structs/templates?<br>
Are there any examples of this?<br>
I guess I can do dynamic patching if not?<br>
Thanks!_______________________________________________ Pd-dev mailing list <a href="mailto:Pd-dev@lists.iem.at" target="_blank">Pd-dev@lists.iem.at</a>[mailto:<a href="mailto:Pd-dev@lists.iem.at" target="_blank">Pd-dev@lists.iem.at</a>] <a href="https://lists.puredata.info/listinfo/pd-dev" rel="noreferrer" target="_blank">https://lists.puredata.info/listinfo/pd-dev</a><br>
</blockquote></div>