int start = 60; // middle C
int[] major = {0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24}; // the major pattern
int majorIndex = 0;
int note;
SoundCipher sc = new SoundCipher(this);
void setup(){
size(300, 300);
textSize(50);
textAlign(CENTER,CENTER);
// optional: note-based background with colorMode(HSB)
colorMode(HSB);
}
void draw() {
background((note - 60)*10, 200, 200);
textSize(150);
text(note,width/2, height/2);
textSize(24);
text("Click the canvas and \n press keys to play!", width/2, height-40);
}
void keyPressed(){
// get a random note, or one from the major scale
note = getMajorNote();//getRandomNote();
sc.playNote(note,40,1);
}
void mousePressed() {
note = start + major[majorIndex];
sc.playNote(note,40,1);
// increase majorIndex, but don't let it get too high!
majorIndex++;
majorIndex %= major.length;
}
int getRandomNote(){
//pick an entirely random note!
int rand = (int)random(60,85);
return rand;
}
int getMajorNote(){
//use only the notes in the major scale!
//to find the scale, find a stating place (60) and the follow this pattern ...
// whole, whole, half, whole, whole, whole, half
// where "whole" means a jump of two notes and "half" means a jump of one note
int randIndex = (int)random(0,major.length); // pick an index at random
// return the note instead of the index
return major[randIndex] + start;
}