xxxxxxxxxx
59
let osc;
let index = 0;
let synth;
// scales to try
// minor pentatonic
//[0, 3, 5, 7, 10]
// whole tone
// [0, 2, 4, 6, 8, 10]
let myScale;
function setup() {
createCanvas(400, 400);
osc = new p5.Oscillator();
osc.setType('triangle');
osc.freq(440);
// osc.start();
masterVolume(0.3);
myScale = shiftScale([ 0, 3, 5, 7, 10 ], 60);
synth = new p5.PolySynth();
}
function draw() {
background(220);
text("Press any key to play a random note", width/2, height/2);
}
function keyPressed() {
// any note on the keyboard
//let note = random(60, 72);
// any note within a range of the keyboard
// let note = random(60, 72);
// any random note within Cm pentatonic
// let myScale = [60, 63, 65, 67, 70]
// index = int(random(myScale.length));
// let note = myScale[index];
// ascending notes within Cm pentatonic
// let myScale = [60, 63, 65, 67, 70]
// index = (index + 1) % myScale.length;
// play any scale
// let myScale = shiftScale([ 0, 3, 5, 7, 10 ], 60);
// index = int(random(myScale.length));
// let note = myScale[index];
// play a chord
// let chord = [0, 3, 7, 10, 14];
// let shiftedChord = shiftScale(chord, int(random(60, 65)));
// console.log(shiftedChord);
// for (let i = 0; i < shiftedChord.length; i +=1) {
// console.log(shiftedChord[i]);
// synth.play(midiToFreq(shiftedChord[i]), 0.8, 0, 0.5);
// }
}