xxxxxxxxxx
44
let synth;
function setup() {
createCanvas(400, 400);
background(220);
synth = new p5.PolySynth();
masterVolume(0.5);
}
function mousePressed() {
// let scale = shiftScale([ 0, 3, 5, 7, 10 ], 60);
// let midiNote = scale[int(random(0, scale.length))];
// let chord = shiftScale([ 0, 3, 7, 10, 14 ], int(random(60, 65)));
// for (let i = 0; i < chord.length; i +=1) {
// let note = midiToFreq(chord[i]);
// synth.play(note, 1, 0, 0.5);
// }
// // let's talk about making a loop
// let scaleLower = shiftScale([ 0, 3, 5, 7, 10 ], 60);
// let scaleHigher = shiftScale([ 0, 3, 5, 7, 10 ], 72);
// let scale = scaleLower.concat(scaleHigher);
let scale = [60, undefined, 62, 64, undefined, 72];
let loopIndex = 0;
let looper = new p5.SoundLoop(function(timeFromNow) {
let midiNote = scale[loopIndex];
if (midiNote) {
let note = midiToFreq(scale[loopIndex]);
synth.play(note, 1, timeFromNow, 0.5);
}
loopIndex = (loopIndex + 1) % scale.length;
}, 0.25);
looper.maxIterations = scale.length;
looper.start();
}
function draw() {
}