Author |
Message |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Thu Dec 14, 2006 2:09 pm Post subject:
How can I send 'function' as a parameter to a function? Subject description: lol -_-" .. |
 |
|
i have this idea today,
but can't get it to work on ChucK.
is there a solution to send a function address to be used in another function?
Code: | SinOsc s11 => SinOsc s12 => LPF f1 => Gain g1 => dac;
fun void diminishing(float var, function assign, float ratio, dur rate) {
while(rate => now) ratio *=> var => assign;
}
600 => float f1freq;
1 => float g1gain;
spork ~ diminishing(f1freq, f1.freq, 0.99, 10::ms);
spork ~ diminishing(g1gain, g1.gain, 0.99, 10::ms);
while(second => now); |
my original intention is:
diminishing can apply exponential falls to the indicated float variables.
and assign the value to another place (in the above, osc's freq or gain)
this is one effect i wanna achive from this..
but i wanna pass those values to the function to perform..
instead of putting all those in one function.
it's not flexible enough for me.
Code: | SinOsc s11 => SinOsc s12 => LPF f1 => Gain g1 => dac;
1100 => s11.freq;
3000 => s11.gain;
220 => s12.freq;
1 => s12.gain;
2 => s12.sync;
3000 => f1.freq;
1.4 => f1.Q;
0.5 => g1.gain;
fun void diminishing(float ratio, dur rate) {
while(rate => now) {
s11.gain() * ratio => s11.gain;
f1.freq() * ratio => f1.freq;
g1.gain() * ratio => g1.gain;
}
}
spork ~ diminishing(0.94, 5::ms);
while(second => now); |
|
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Thu Dec 14, 2006 3:20 pm Post subject:
|
 |
|
hmm.. (just for fun, okay?)
while playing around with the above patch..
this comes out -_-"
hahah just for fun la...
Code: | TriOsc s11 => SinOsc s12 => LPF f1 => Gain g1 => LPF f2 => NRev fx1 => dac;
s11 => SinOsc s2 => g1;
2200 => s11.freq;
3000 => s11.gain;
1 => s12.gain;
2 => s12.sync;
3000 => f1.freq;
1.4 => f1.Q;
0.3 => g1.gain;
8000 => f2.freq;
0.01 => fx1.mix;
1760 => s2.freq;
0.2 => s2.gain;
2 => s2.sync;
fun void diminishing(float ratio, dur rate) {
while(rate => now) {
s11.gain() * ratio => s11.gain;
f1.freq() * ratio => f1.freq;
g1.gain() * ratio => g1.gain;
}
}
spork ~ diminishing(0.99, 1::ms);
for(int i; i < 100; i++) {
55 * Std.rand2(4, 13) => s12.freq;
4000 * maybe + 50 => s11.gain;
3000 * maybe + 300 => f1.freq;
0.3 => g1.gain;
(1 + 3 * maybe) * 80::ms => now;
} |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Dec 14, 2006 5:02 pm Post subject:
|
 |
|
I don't think so because functions aren't objects. They can't be "send" anywhere or asigned, just called. From time to time I myself would like arrays of the type function.
In your case with the gain this could be acomplished by putting the gain in multiply mode and chucking var straight into it but clearly that won't work for the filter .freq()
I do have a tip for you in that instead of "while(second => now);" you can also use "day => now;" which basically acomplishes the same thing (as long as you aren't running a instalation....) and I think it should save a small amount of cpu as well as a few characters.
You can keep shreds alive forever in a somewhat elegant way by going
Event forever;
forever => now;
as long as you don't ever broadcast that event.
...But that doesn't realy answer the question. _________________ Kassen |
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Fri Dec 15, 2006 12:20 am Post subject:
|
 |
|
oh.. thanks. forever's good.
hmm.. sometimes when i prepare a while(second => now) .. i love it ticking every seconds in Audicle Time 'n' Timing , that's all.
i agree with you heeh..
i can see that now printing a function works..
( for example, Gain g; <<< g.gain >>>; <<< g.freq >>>; )
and it prints out a function address..
but i can't do anything more to it. |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Dec 15, 2006 1:20 pm Post subject:
|
 |
|
Yeah, I had seen those function adresses too but you can't get to them yourself.
I think there would be some benefits to having functions behave as objects, both in clarity of written code and in scenarios like yours but to me this sounds like the sort of feature that would have pritty big implications and side effects. Maybe once we get classes that can extend Ugens properly, I think those are on our wish-list. _________________ Kassen |
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Tue Dec 19, 2006 1:22 pm Post subject:
|
 |
|
what about a pointer variable?
would it work? |
|
Back to top
|
|
 |
majutsu

Joined: Jun 18, 2006 Posts: 151 Location: New York
Audio files: 1
|
Posted: Mon Jan 01, 2007 12:55 pm Post subject:
|
 |
|
this would be sweet! Having a pointer to a function to call as an argument . . .
but you could put functions in different modules, pass the string of the module name as an argument into another function . . . maybe that could do the same thing. _________________ All phenomena are atoms in association and dissociation. |
|
Back to top
|
|
 |
|