Author |
Message |
Plasticman
Joined: Feb 25, 2008 Posts: 11 Location: Ireland
|
Posted: Tue Feb 26, 2008 6:15 am Post subject:
Chucking ugens... |
|
|
After a ugen is chucked to dac, how does one remove its input from the controller? |
|
Back to top
|
|
|
Frostburn
Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Tue Feb 26, 2008 6:31 am Post subject:
|
|
|
Do you mean unchucking ( =< )?
Code: | TriOsc osc => dac;
second => now;
osc =< dac; //Unchuck
second => now;
300.0 => osc.freq;
second => now; //still no sound
osc => dac;
second => now; |
_________________ To boldly go where no man has bothered to go before. |
|
Back to top
|
|
|
Plasticman
Joined: Feb 25, 2008 Posts: 11 Location: Ireland
|
Posted: Tue Feb 26, 2008 7:11 am Post subject:
|
|
|
That's... rather obvious. Thanks. |
|
Back to top
|
|
|
moudi
Joined: Oct 07, 2006 Posts: 63 Location: Bern Switzerland
|
Posted: Wed Feb 27, 2008 3:51 pm Post subject:
|
|
|
an additional possible way which could be useful is to use the op function:
Code: |
//stop - always output 0
osc.op(0);
1::second => now;
//1 : normal operation, add all inputs (default)
osc.op(1);
1::second => now;
|
jassas
/moudi |
|
Back to top
|
|
|
Plasticman
Joined: Feb 25, 2008 Posts: 11 Location: Ireland
|
Posted: Mon Mar 03, 2008 7:01 am Post subject:
|
|
|
Ok, hopefully this is a slightly less stupid question.
I'm trying to write a function that will make a copy of an StkInstrument, change the frequency, and play that note, so that it can be sporked to play multiple notes at once.
However, I can't find a way to make a copy of a UGen in the documentation; using the ChucK operator chucks the output of the instrument into a new UGen rather than copying it, and the explicit chuck operator just makes the new UGen a reference to the original instrument. How do I make a duplicate of the UGen?
Code: |
fun void play(StkInstrument s, int octave, float midi)
{
s @=> StkInstrument tmp => dac;
(octave * 12) + midi => Std.mtof => tmp.freq;
<<<tmp>>>;
1 => tmp.noteOn;
3::second => now;
0 => tmp.noteOff;
}
|
|
|
Back to top
|
|
|
kijjaz
Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Mon Mar 03, 2008 9:57 am Post subject:
|
|
|
Ahhh!! that's one powerful question!!! ..
I can't think of a way to copy any objects or any StkInstrument into a new one right away...
but if it's the same type, it's gonna be a bit easier.. (but still not that comfortable).
I'm thinking of making a new one, and chucking values from the first one to the new one's functions.
Other than that, I still can't think of a way.
there might be some way to hack this. |
|
Back to top
|
|
|
Frostburn
Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Mon Mar 03, 2008 10:52 am Post subject:
|
|
|
I don't know the answer to your question exactly but I here's a workaround using a class that takes the type as a string, not as a StkInstrument object.
Code: | class StkPlayer{
Gain out; //my_stkplayer.out => dac;
"StifKarp" => string type; //Default instrument to use
fun void play(int octave, float midi,dur duration){
play(type,octave,midi,1.0,duration); //Use default instrument and full velocity
}
fun void play(string my_type, int octave, float midi,float velocity,dur duration)
{
StkInstrument @ my_stk;
if(my_type == "StifKarp") new StifKarp @=> my_stk;
else if(my_type == "Mandolin") new Mandolin @=> my_stk;
//else if(my_type == ... etc.
my_stk => out; //Connect to the output of this instance
(octave * 12) + midi => Std.mtof => my_stk.freq;
//<<<my_stk>>>;
1.0 => my_stk.noteOn;
duration => now;
0.0 => my_stk.noteOff;
3::second => now; //allow for the release to decay before exiting this shred
}
}
//Try it:
StkPlayer my_stkplayer;
my_stkplayer.out => dac;
spork~my_stkplayer.play("Mandolin",5,0.0,0.5,second);
0.5::second => now;
spork~my_stkplayer.play("Mandolin",5,8.0,0.5,2::second);
5::second => now;
|
I'm working on classes that implement a general Instrument interface that can be easily controlled with MIDI, Hid or score arrays and UGens chucked to effect controllers. It's still in the alpha phase of non-release but I can post what I've done so far if you're interested and want to extend it to make a proper StkPlayer (the one I just posted is terrible). _________________ To boldly go where no man has bothered to go before. |
|
Back to top
|
|
|
Plasticman
Joined: Feb 25, 2008 Posts: 11 Location: Ireland
|
Posted: Mon Mar 03, 2008 11:42 am Post subject:
|
|
|
Yeah, I'd thought of trying something like that, I was just hoping that there would be an easier way around that.
Your idea sounds very interesting though; myself and a few others are currently working on building a synthesizer through ChucK that interfaces with a custom multi-touch interface, and that might be quite useful...
. |
|
Back to top
|
|
|
kijjaz
Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Mon Mar 03, 2008 11:56 am Post subject:
|
|
|
I'm thinking that a 'general UGen duplicator' is gonna be useful.
We should have the dev team add that to the code ha ha. |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Mon Mar 03, 2008 12:22 pm Post subject:
|
|
|
kijjaz wrote: |
I can't think of a way to copy any objects or any StkInstrument into a new one right away...
|
OUCH!
Yes, that's a hard one.
Here's a proof of concept (it will compile) that copies a known type of StkInstrument, copies one parameter, then uses it once. Not sure how to do it more generally for unknown instrument types.
Code: | class Trigger extends Event
{
int target;
}
fun void copy (Shakers master, int id)
{
Shakers copy => dac;
master.preset() => copy.preset;
while(1)
{
trig => now;
if (trig.target == id)
{
1 => copy.noteOn;
}
}
}
Shakers s => dac;
Trigger trig;
Std.rand2(0, 22) => s.preset;
1 => s.noteOn;
second => now;
spork ~ copy(s, 1);
me.yield();
1 => trig.target;
trig.broadcast();
second => now;
|
There is, BTW, a issue somewhere in that if I define "Trigger" at the bottom of the code I get a error that class trigger doesn't have a member named broadcast. _________________ Kassen |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Mon Mar 03, 2008 12:35 pm Post subject:
|
|
|
Frostburn wrote: |
if(my_type == "StifKarp") new StifKarp @=> my_stk;
else if(my_type == "Mandolin") new Mandolin @=> my_stk;
//else if(my_type == ... etc.
|
OUCH! But yes, that would work (crossing posts between my last and some of the above).
We could also overload my "copy" function which would mean we could point copy directly at a target Ugen, provided it's of a type we overloaded "copy" to deal with. that's probably lighter on the CPU, particularly once we get into copying lots of parameters? Overloading wouldn't result in a single massive function, with all it's consequences. _________________ Kassen |
|
Back to top
|
|
|
Frostburn
Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Mon Mar 03, 2008 1:03 pm Post subject:
|
|
|
Plasticman wrote: | Your idea sounds very interesting though; myself and a few others are currently working on building a synthesizer through ChucK that interfaces with a custom multi-touch interface, and that might be quite useful... |
See a snapshot of my project at:
http://electro-music.com/forum/post-172579.html#172579 _________________ To boldly go where no man has bothered to go before. |
|
Back to top
|
|
|
|