xxxxxxxxxx
46
// Click on the canvas to create a random melody
// Uncomment below to play each example
let synth = new Tone.Synth().toMaster();
function setup() {
}
function mousePressed(){
//play 440 Hz for 0.1 seconds
// synth.triggerAttackRelease(440, 0.1);s
//play a random frequency
// let frequency = random(100, 10000);
// synth.triggerAttackRelease(frequency, 0.1);
//play a random frequency within an octave
// let frequency = random(440, 880);
// synth.triggerAttackRelease(frequency, 0.1);
//play a random frequency within a 5-note scale that I made up
// let myScale = [200.32, 350.55, 480, 670, 800];
// let pos = int(random(0, myScale.length));
// let frequency = myScale[pos];
// synth.triggerAttackRelease(frequency, 0.1);
//play a random frequency within an equal-tempered semitone
// let frequency = random(329.63, 349.23);
// synth.triggerAttackRelease(frequency, 0.1);
//play A4 (440 Hz, referred to by its note name + octave)
//see frequencies of different pitches here: http://www.phy.mtu.edu/~suits/notefreqs.html
//https://en.wikipedia.org/wiki/Scientific_pitch_notation
// synth.triggerAttackRelease("A4", 0.1);
//play a random equal-tempered pitch between C3 and C5 (three octaves)
//these are all within the C major scale, or the A minor scale
//pitches range from C0 to B8 (C0, D0, E0, F0, G0, A0, B0; C1, D1, and so on).
// let myScale = ["C3", "D3", "E3", "F3", "G3", "A3", "B3",
// "C4", "D4", "E4", "F4", "G4", "A4", "B4",
// "C5", "D5", "E5", "F5", "G5", "A5", "B5" ];
// let pos = int(random(0, myScale.length));
// let pitch = myScale[pos];
// synth.triggerAttackRelease(pitch, 0.1);
}