Author |
Message |
Phloxs
Joined: Jan 24, 2014 Posts: 17 Location: Russia
|
Posted: Thu Oct 01, 2015 5:57 am Post subject:
How to put Ugen object to array? |
|
|
Hello.
I want to make some kind of array with links to objects (or objects) in order for I'll control Ugens by adress to this array's index.
How can I do it?
At example:
Code: | SinOsc sin => dac;
SawOsc saw => dac;
[sin, saw] @=> int instList[];
440 => int instList[0];
220 => int instList[1]; |
Of course I get an error "cannot assign '@=>' on types 'Osc[]' @=> 'int[]'" |
|
Back to top
|
|
|
brkl
Joined: Aug 21, 2015 Posts: 8 Location: Finland
|
Posted: Fri Oct 02, 2015 2:53 am Post subject:
|
|
|
I think you can have an array of a single type of object, not different ones. I mean, you can make an array of UGens and assign SinOsc to it, but it won't work. You won't be able to use any feature of SinOsc apart from the ones that are part of UGen.
Oh, I don't know, maybe you could try the Chubgraph feature and make a class that has a setting that determines what kind of UGen it is. I mean, you could give it a shot.
http://chuck.stanford.edu/extend/#chubgraphs |
|
Back to top
|
|
|
Phloxs
Joined: Jan 24, 2014 Posts: 17 Location: Russia
|
Posted: Fri Jul 08, 2016 5:52 am Post subject:
|
|
|
This solution work with StkInstrument class so I guess it should work with Ugens.
Code: |
Mandolin m;
Sitar s;
Shakers sh;
[m, s, sh]@=> StkInstrument instruments[];
for (int i; i instruments.size(); i++)
{
Math.random2(220, 440) => instruments[i].freq;
1 => instruments[i].noteOn;
.5::second => now;
1 => instruments[i].noteOff;
}
|
|
|
Back to top
|
|
|
95
Joined: Nov 01, 2016 Posts: 1 Location: los angeles
|
Posted: Tue Nov 01, 2016 7:50 pm Post subject:
|
|
|
brkl! your suggestion totally worked for me.
brkl wrote: |
Oh, I don't know, maybe you could try the Chubgraph feature and make a class that has a setting that determines what kind of UGen it is. I mean, you could give it a shot.
http://chuck.stanford.edu/extend/#chubgraphs |
i'm making a synth thing with different kinds of oscillators, and wanted to put them in an array. i had tried with a ugen array, but as mentioned, because ugen is so limited, it won't let you do things like change frequency.
BUT THIS IS GREAT
a little sample i made to test it out:
Code: |
class Oski extends Chubgraph{
ADSR e[4];
SinOsc si => e[0] => dac;
SqrOsc sq => e[1] => dac;
TriOsc tr => e[2] => dac;
SawOsc sa => e[3] => dac;
fun void freq(int voice, int value){
if (voice == 0){value => si.freq;}
if (voice == 1){value => sq.freq;}
if (voice == 2){value => tr.freq;}
if (voice == 3){value => sa.freq;}
}
fun void keyOn(int voice){
e[voice].keyOn();
}
fun void keyOff(int voice){
e[voice].keyOff();
}
fun void releaseTime(int voice, dur d){
e[voice].releaseTime(d);
}
}
Oski o => dac;
o.freq(0, 1000);
o.releaseTime(0, .2::second);
o.keyOn(0);
1::second => now;
o.keyOff(0);
1::second => now;
|
|
|
Back to top
|
|
|
|