[chuck-users] SndBuf Passing args to running functions
Michael Heuer
heuermh at gmail.com
Sun Feb 23 23:14:13 EST 2020
Hello Herman,
I don't think you need to pass values to the sporked functions.
Scoping rules allow the sporked functions to access variables declared in their enclosing class, e.g.
0 => int centralpos;
spork ~ doSomething();
spork ~ doSomethingElse();
2::second => now;
42 => centralpos;
2::second => now;
0 => centralpos;
<<<"done">>>;
fun void doSomething()
{
while (true)
{
if (centralpos == 42)
{
<<<"hello from doSomething!">>>;
}
250::ms => now;
}
}
fun void doSomethingElse()
{
while (true)
{
if (centralpos == 42)
{
<<<"hello from doSomethingElse!">>>;
}
500::ms => now;
}
}
Do remember to advance time everywhere or things won't work correctly.
Hope this helps!
michael
> On Feb 21, 2020, at 2:11 AM, herman verbaeten <hverb54 at hotmail.com> wrote:
>
> Hi,
>
> I'm in big trouble. I'v been trying for a long time now to change an argument in a running function. As you can see in my script i set a certain central pos ("70000")to buf.pos as a central position in my soundbuffer and i let my function LFOtoPOS circle around it.
>
> Once the "spork" instruction has started the process i can't figure out how to addresss the argument "centralpos" to change it on the fly or by another function or parameter. Some help please ...
>
> Kind regards,
>
> Herman
> ----------------------------------------------------------------------------------------------
>
> me.sourceDir() + "sound.wav" => string filename;
> if( me.args() ) me.arg(0) => filename;
>
> SndBuf buf => dac;
>
> filename => buf.read;
>
> 1 => buf.pos;
> .5 => buf.gain;
>
> spork ~ LFOtoPOS(70000);
>
> fun void LFOtoPOS(int centralpos)
> {
> TriOsc lfo => blackhole;
> 1 => lfo.freq;
> centralpos => buf.pos;
> while (true)
> {
> 1::samp => now;
> (10000*lfo.last())$ int => buf.pos;
> }
> }
>
> // time loop
> while( true )
> {
> 1000::ms => now;
> }
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu <mailto:chuck-users at lists.cs.princeton.edu>
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users <https://lists.cs.princeton.edu/mailman/listinfo/chuck-users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20200223/ff79552e/attachment.html>
More information about the chuck-users
mailing list