Forward of a old message for Andrew to illustrate a technique related to his question.<div><br></div><div>Please note that this technique is squarely in the "powertools can maim" category; it's very powerful, getting around some of ChucK's limitations but it runs right next to the edge of where the VM will crash because of the casting. </div>
<div><br></div><div>Kas.<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Kassen</b> <span dir="ltr"><<a href="mailto:signal.automatique@gmail.com">signal.automatique@gmail.com</a>></span><br>
Date: 21 January 2009 16:14<br>Subject: hotswapping UGens<br><br><br>Fellow ChucKists,<br><br>Inspired by Scott's explanation of casting I thought I'd try a new trick that may be quite interesting for livecoding.<br>
<br>first run this file;<br>-----------------------------<br>new UGen @=> Foo.instrument;<br>
public class Foo<br>    {<br>    static UGen @instrument;<br>    spork ~attach();<br>    <br>    fun void attach()<br>        {<br>        while(1)<br>            {<br>            if(!instrument.isConnectedTo( dac )) instrument => dac;<br>

            second => now;<br>            }<br>        }<br>    }<br><br>Foo foo;<br>new Sitar @=> foo.instrument;<br><br>//your melody goes here<br>while(second => now) 1 => (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 @=> Foo.instrument;<br>-----------------------<br><br>Sadly this does need that "attach" function as assignment breaks the link to the dac. I'm not sure I feel that's desirable behaviour but at least we can now hotswap UGens without crashing. I don't think I succeeded in that before.<br>

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