<div class="gmail_quote">On Sun, Sep 13, 2009 at 9:01 PM, <a href="mailto:mescalinum@gmail.com">mescalinum@gmail.com</a> <span dir="ltr">&lt;<a href="mailto:mescalinum@gmail.com">mescalinum@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
if I were writing an external that is somewhat an interface to arrays<br>
(read/write), I have some design choices:<br>
<br>
1) copy/paste the code of array (g_array.c) (or eventually only copy<br>
[tabread]/[tabwrite])<br>
    pros: resulting external is tight &amp; tidy<br>
    cons: code duplication, possible breakage in future releases<br>
<br>
2) provide appropriate inlets and outlets, and require the user to patch<br>
the external among [tabread]/[tabwrite] objects<br>
    pros: modular. is independent from the array implementation.<br>
    cons: tricky to use, the user can patch it incorrectly and won&#39;t work.<br>
<br>
3) is possible to patch the required objects without phisically put them<br>
in the canvas [?]<br>
    pros: all pros mentioned in 1) and 2)<br>
    cons: [?]<br>
<br>
obviously, 1) and 2) are ugly under some point of view; what I am<br>
interested in is 3), hence asking here if possible, and directions on<br>
how to proceed.<br></blockquote><div><br>I would suggest the following two options. Everything used in the examples is declared in the &quot;m_pd.h&quot; header that you have to include in your external anyway. Basically, I will explain the techniques used by the pd objects that operate on arrays and the delay objects, so this is stuff that will most probably not be broken for numerous future releases, or a very large part of pd should drastically change.<br>
 <br></div></div>1.<br>You can get a direct pointer to data stored in a g_array with the following code:<br><br>t_symbol *array_name = gensym( &quot;array-named-foo&quot;);<br>t_pd *the_array = <b>pd_findbyclass</b>(  array_name, garray_class );<br>
int size;<br>t_float *data;<br><b>garray_getfloatarray</b>( (t_garray) the_array, &amp;size, &amp;data );<br><br>You have to pass the name of the array as it was set in the pd patch as the &quot;s&quot; argument of pd_findbyclass function. Therefore you can easily let the user choose the array you will operate on via an argument to your external.<br>
<br>2.<br>You can associate your pd external with a symbol using the function<br><br>void <b>pd_bind</b>(t_pd *x, t_symbol *s)<br><br>...where you pass the struct of your external as the &quot;x&quot; argument (you can easily cast it to t_pd). What this means in effect is that you can get a pointer to that structure from another external with the already introduced <b>pd_findbyclass</b> function, by passing it as arguments the registered symbol and the <b>t_class</b> of the registered external.<br>
Again, it is a good idea to let the user choose the registered symbol via an argument of the external.<br><br>This effectively means that you can separate the functionality you want to achieve into many externals, so that one allocates memory for some data in its struct and the others will be able to operate on that memory by accesing the struct of the registered external, while the &quot;invisible connections&quot; are made via the symbols that the user gives as arguments to the externals (we can say, by the names that the user assigns to the instances of the externals).<br>
<br><br>If you have further questions, please ask!<br><br>Best regards,<br>Jakob Leben<br>