examples\instruments\shredder\modalDemo.ck
if(me.args() == 0)
{
    <<<"This is intended for use by Shredder. Bailing...", me.id()>>>;
    1::second => now;
    me.exit();
}
// we use the first argument to find our Shredder
me.arg(0).toInt() => int shredderId;
Shredder.Shredders[shredderId] @=> Shredder shredder;

// remaining arguments
me.arg(1).toFloat() => float midiNote;
me.arg(2).toFloat() => float velocity;

<<<"modalDemo.ck note", midiNote, "velocity", velocity>>>;

shredder.GetOutlet() @=> UGen outlet;

// we can also get our hands on recent "CC" values via
// shredder.GetCC("CC7") => float channelVolume;
// shredder.GetCC("CC10") => float channelPan;
// etc

// We optionally synchronize to a beat or measure before
// we do our thing.
shredder.Synchronize();

//---------------|
// modal demo
// based off of mand-o-matic ( master plan ) 
// by : philipd 
// by: Ge Wang (gewang@cs.princeton.edu)
//     Perry R. Cook (prc@cs.princeton.edu)
//------------------|
ModalBar modey => JCRev rev => Echo echo => outlet;
.4 => rev.gain;
.1 => rev.mix;
1000::ms => echo.max;
750::ms => echo.delay;
0.6 => echo.mix;

// scale
[ 0, 2, 4, 7, 9, 11 ] @=> int scale[];

// our main loop
int j;
while(j++ < 300)
{
    // presets
    // note: Math.randomf() returns value between 0 and 1
    if( Math.randomf() > 0.9 )
    {
        Math.random2( 0, 8 ) => modey.preset;
        // <<< "preset:", modey.preset() >>>;
    }

    // position
    Math.random2f( 0.2, 0.8 ) => modey.strikePosition;

    // frequency...
    scale[Math.random2(0,scale.size()-1)] => int freq;
    Std.mtof( midiNote + Math.random2(0,4)*12 + freq ) => modey.freq;

    // pluck it!
    Math.min(1, velocity + Math.random2f(-.2, .2)) => modey.strike;

    // randomly select from three hold durations or 'multipick'
    if( Math.randomf() > 0.8 )
    { 500::ms => now; }
    else if( Math.randomf() > .925 )
    { 250::ms => now; }
    else if( Math.randomf() > .05 )
    { .125::second => now; }
    else
    {
        1 => int i => int pick_dir;
        // how many times
        4 * Math.random2( 1, 5 ) => int pick;
        0.0 => float pluck;
        0.65 / pick => float inc;
        // time loop
        for( ; i < pick; i++ )
        {
            75::ms => now;
            Math.random2f(.2, .3) + i*inc => pluck;
            pluck => modey.stickHardness;
            pluck + -.2 * pick_dir => float s;
            // <<<"Strike", s>>>;
            s => modey.strike;
            // simulate pluck direction
            !pick_dir => pick_dir;
        }
        // let time pass for final pluck
        75::ms => now;
    }
}
home .. topics .. interface .. reference .. examples .. tipjar