Fellow ChucKists, Inspired by Scott's explanation of casting I thought I'd try a new trick that may be quite interesting for livecoding. first run this file; ----------------------------- new UGen @=> Foo.instrument; public class Foo { static UGen @instrument; spork ~attach(); fun void attach() { while(1) { if(!instrument.isConnectedTo( dac )) instrument => dac; second => now; } } } Foo foo; new Sitar @=> foo.instrument; //your melody goes here while(second => now) 1 => (foo.instrument $ Sitar).noteOn; -------------------------------------------- Then run this to hot-swap the UGen while the original code runs; -------------- new Shakers @=> Foo.instrument; ----------------------- 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. Yours, Kas.
2009/1/21 Kassen
Inspired by Scott's explanation of casting I thought I'd try a new trick that may be quite interesting for livecoding.
first run this file; ----------------------------- new UGen @=> Foo.instrument; public class Foo { static UGen @instrument; spork ~attach();
fun void attach() { while(1) { if(!instrument.isConnectedTo( dac )) instrument => dac; second => now; } } }
Foo foo; new Sitar @=> foo.instrument;
//your melody goes here while(second => now) 1 => (foo.instrument $ Sitar).noteOn; --------------------------------------------
Then run this to hot-swap the UGen while the original code runs;
-------------- new Shakers @=> Foo.instrument; -----------------------
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.
It doesn't seem like the melody should keep playing on the Shakers since the noteOn is being called assuming the instrument is a Sitar. :D -- Tom Lieber http://AllTom.com/
Tom; It doesn't seem like the melody should keep playing on the Shakers
since the noteOn is being called assuming the instrument is a Sitar. :D
I feared a crash at that point as well, yes, but apparently only the name of the function needs to match. To put it bluntly; //warning; very perverse code ahead new SinOsc @=> UGen u => dac; second => now; 500 => (u $ LPF).freq; second => now; I'm quite excited by this, It's like a huge new feature without the need for a actual update. If you'd like to do it cleanly you could instantiate StkInstrument instead of UGen and probably cast to that for the noteOn() as well. This should lead to less chance of crashing and more protection by the parser. It's not as exciting though. Yours, Kas.
participants (2)
-
Kassen
-
Tom Lieber