electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
  host / artist show at your time
today> Modulator ESP Adventures In Sound
 Forum index » DIY Hardware and Software » ChucK programming language
How can I send 'function' as a parameter to a function?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Thu Dec 14, 2006 2:09 pm    Post subject:  How can I send 'function' as a parameter to a function?
Subject description: lol -_-" ..
Reply with quote  Mark this post and the followings unread

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)

Shocked

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Thu Dec 14, 2006 3:20 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Thu Dec 14, 2006 5:02 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Fri Dec 15, 2006 12:20 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Dec 15, 2006 1:20 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Tue Dec 19, 2006 1:22 pm    Post subject: Reply with quote  Mark this post and the followings unread

what about a pointer variable?
would it work?
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
majutsu



Joined: Jun 18, 2006
Posts: 151
Location: New York
Audio files: 1

PostPosted: Mon Jan 01, 2007 12:55 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use