#02 Options

You can set options when calling the play method as a second argument and when you create a loop.

dittytoy.net/syntax#synthesizers
dittytoy.net/syntax#options

#dittytoy #tutorial

Log in to post a comment.

// #02 Options. DittyToy 2022.
// The MIT License.
//
// https://dittytoy.net/ditty/e261436551
//
// You can set options when calling the play method as a second argument and when you create a loop. Default 
// options for the play method are:
//
// - name (optional, the name of the synthesizer)
// - amp (volume, default: 1)
// - pan (panning, -1 to 1, default: 0)
// - env (envelope, default: adsr)
//
// You can use the same object to set options for the selected envelope. For the ADSR envelope, the available options are:
//
// - attack (in seconds, default: 0)
// - decay (in seconds, default: 0)
// - sustain (default: 1)
// - release (in seconds, default: 0.5)
// - curve (default: -2, the curvature value for the decay and release phase)
// - duration (in ticks, default: 0)
//
// https://dittytoy.net/syntax#synthesizers
// https://dittytoy.net/syntax#options
//


ditty.bpm = 120;

loop( () => {

    for (let i=0; i<4; i++) {
        sine.play(c4, { attack: 0.01, release: 0.25,  duration: 0.125, pan: Math.random() * 2 - 1, amp: 1.0 });
        sleep( 0.25 );
    }

    sine.play(d4, { attack: 0.01, release: 0.25,  duration: 0.25 }); // attack and release in seconds, duration in ticks
    sleep(0.5); // sleep in ticks

    sine.play(f4, { attack: 0.01, release: 0.75,  duration: 0.25 });
    sleep(0.5);

}, { name: 'my first loop' });