SuperCollider Forum
May 24, 2013, 05:34:25 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The SuperCollider forum is currently experiencing a rash of spambot registrations. New user requests may not be approved quickly as a result -- and if your email address looks like spam, it might not be approved at all. We are working to improve the security of the registration process, and to provide alternate means to contact the administrators to get a new account. Thanks for your patience.
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: .fork/argument question  (Read 3229 times)
0 Members and 1 Guest are viewing this topic.
Mikelib
Newbie
*

Karma: 0
Posts: 8


View Profile
« on: November 16, 2008, 10:52:34 PM »


Hi guys. I am reasonably new to Supercollider so go easy.Smiley
I created this piece of code earlier (modified from help file) and I can see what it is doing but can not understand why the argument is working as it does.
When the code is played it plays a sine 5 times in the sequence 2000hz, 2200,2400,2600,2800. As you can see the frequency on the Synth is set to 2000 + (a*200). Does this mean that the first time the routine happens 1 gets fed into the argument a? Then 2,3,4,5? Is the argument only working like this as it is part of a .do routine?

Any help appreciated.

(
SynthDef(\test,{arg freq = 10000;
Out.ar(1,SinOsc.ar(freq)) * (EnvGen.kr(Env.perc(0.01,0.04),doneAction:2))}).load(s);
)

(
{5.do{ arg a;
Synth(\test,[\freq, 2000 + (a*200)]);
1.0.wait
};d
}.fork;

)
Logged
joshp
AdminGroup
Full Member
*

Karma: 5
Posts: 121



View Profile WWW
« Reply #1 on: November 16, 2008, 11:15:32 PM »

Here is an easy way to test out what your code is doing (and may be helpful for future explorations):

5.do({arg a;
    "A is now ".post;
    a.postln;
    });

Notice that ONLY the values of 'a' will have the first part of the string printed... there is a '5' that will show up in the post window as well, but this is what the interpreter returns from the expression. .do returns its receiver, in this case, the integer 5.

Hope that helps.

Josh

Logged
Mikelib
Newbie
*

Karma: 0
Posts: 8


View Profile
« Reply #2 on: November 16, 2008, 11:21:15 PM »

Excellent. Much appreciated Josh!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!