I can&#39;t remember, are questions related to pd&#39;s C API appropriate for pd-list, or are they better asked here?  It seems that everyone who responds to those questions is on this list just as much, anyway.<br><br>I have been mucking around with opening and closing pd patches using API calls instead of pd&#39;s messaging system.  The reason for this is that I would like to be able to manage (open/close) multiple instances of a patch, and be able to send each copy of the patch a unique message via its $0 argument (see <a href="http://www.mail-archive.com/pd-list@iem.at/msg41648.html">http://www.mail-archive.com/pd-list@iem.at/msg41648.html</a>).  So far, the method has been to hack glob_evalfile to look like:<br>
<br><div><div><div>t_canvas *glob_evalfile(t_pd *ignore, t_symbol *name, t_symbol *dir)</div><div>{</div><div>    t_pd *x = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>/* even though binbuf_evalfile appears to take care of dspstate,</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> we have to do it again here, because canvas_startdsp() assumes</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> that all toplevel canvases are visible.  LATER check if this</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> is still necessary -- probably not. */</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>    t_canvas *x_canvas = 0; </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>    int dspstate = canvas_suspend_dsp();</div><div>    binbuf_evalfile(name, dir);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>while ((x != s__X.s_thing) &amp;&amp; (x = s__X.s_thing)) </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>x_canvas = canvas_getcurrent();</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>vmess(x, gensym(&quot;pop&quot;), &quot;i&quot;, 1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>    pd_doloadbang();</div>
<div>    canvas_resume_dsp(dspstate);</div><div>    return x_canvas;</div><div>}</div></div><div><br></div><div>The only addition is that x_canvas is retrieved before x is &#39;popped&#39; off of pd&#39;s global stack, and is then returned, giving me a handle to close that particular patch with something like:</div>
</div><div><br></div><div>canvas_menuclose(x_canvas, 0);</div><div><br></div><div>But I realize that in global_evalfile, t_pd and x_canvas point to the same address space.  This leads me to ask, what is the difference between these two pointers?  Is t_canvas a t_pd along with variables for its graphical nature?</div>
<div><br></div><div>Mathieu also pointed to me (as I was using the first set of these) that canvas_setcurrent() and canvas_unsetcurrent() are aliases of pd_pushsym() and pd_popsym().  Is there a good reason to use one over the other?   </div>
<div><br></div><div>Last question:  Does anyone see a way that I could get the value of x in glob_evalfile above without changing the function?  I don&#39;t think it is a dangerous change (and it looks like I could just hand x.gl_pd to canvas_menuclose, thereby not really needing a t_canvas pointer), but I would of course prefer to not change the API if possible.</div>
<div><br></div><div>Cheers,<br>Rich</div>