xxxxxxxxxx
// remember to add the sound library : p5.sound
var osc; // this is a variable which we will use for an oscillator
var env; // this is a variable which we wlll use for the envelope
var sequence = [60, 63, 65, 62, 60, 67, 68, 70, 72, 60, 58, 62, 74, 63];
var s = 0;
var speed = 6;
var fg = 255;
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
// take 0.1 seconds to get to level 1, then 0.5 seconds to get to level 0
env = new p5.Envelope(0.01, 1, 0.3, 0);
osc = new p5.Oscillator(); // make an oscillator
osc.setType('sine'); // options are 'sine', 'sawtooth', 'triangle', 'square'
osc.start(); // start it
osc.amp(0);
textSize(60);
}
function draw() {
background(255-fg);
stroke(fg);
fill(fg);
text(frameCount + ": " + s + ": " + sequence[s], width/2, height/2);
if(frameCount%speed==0) {
playit(sequence[s]); // play a note
s = (s+1) % sequence.length; // increment which note
fg = 255-fg; // flip the color
}
}
function mouseClicked()
{
//playit();
}
function playit(f)
{
osc.freq(midiToFreq(f)); // frequency to the argument
env.play(osc);
}