Dear all,<br><br>I just noticed that I accidentally send this to the DEV list instead of the users one. That was of course a mistake. I hope this didn&#39;t bother anyone, I&#39;ll try to pay more attention on the future. <br>
<br>Sorry,<br>Kas.<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Kassen</b> <span dir="ltr">&lt;<a href="mailto:signal.automatique@gmail.com">signal.automatique@gmail.com</a>&gt;</span><br>
Date: 2009/1/21<br>Subject: hotswapping UGens<br>To: ChucK Developer Mailing List &lt;<a href="mailto:chuck-dev@lists.cs.princeton.edu">chuck-dev@lists.cs.princeton.edu</a>&gt;<br><br><br>Fellow ChucKists,<br><br>Inspired by Scott&#39;s explanation of casting I thought I&#39;d try a new trick that may be quite interesting for livecoding.<br>
<br>first run this file;<br>-----------------------------<br>new UGen @=&gt; Foo.instrument;<br>
public class Foo<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; static UGen @instrument;<br>&nbsp;&nbsp;&nbsp; spork ~attach();<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; fun void attach()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while(1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(!instrument.isConnectedTo( dac )) instrument =&gt; dac;<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; second =&gt; now;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>Foo foo;<br>new Sitar @=&gt; foo.instrument;<br><br>//your melody goes here<br>while(second =&gt; now) 1 =&gt; (foo.instrument $ Sitar).noteOn;<br>

--------------------------------------------<br><br>Then run this to hot-swap the UGen while the original code runs;<br><br>--------------<br>new Shakers @=&gt; Foo.instrument;<br>-----------------------<br><br>Sadly this does need that &quot;attach&quot; function as assignment breaks the link to the dac. I&#39;m not sure I feel that&#39;s desirable behaviour but at least we can now hotswap UGens without crashing. I don&#39;t think I succeeded in that before.<br>

<br>Yours,<br>Kas.<br>
</div><br>