Created
February 6, 2013 17:59
-
-
Save mazbox/4724476 to your computer and use it in GitHub Desktop.
Given a midi note index, get a note in the scale.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PENTATONIC 2 | |
#define CHROMATIC 1 | |
#define WHOLE 3 | |
#define MAJOR 4 | |
#define MINOR 0 | |
int getScaled(int noteIndex, int scale) { | |
if(scale==CHROMATIC) return pos; | |
else if(scale==PENTATONIC) { | |
int octave = pos / 5; | |
int note = 0; | |
switch(pos % 5) { | |
case 0: note = 0; break; | |
case 1: note = 3; break; | |
case 2: note = 5; break; | |
case 3: note = 7; break; | |
case 4: note = 10; break; | |
} | |
return octave * 12 + note; | |
} | |
else if(scale==MINOR) { | |
int octave = pos / 7; | |
int note = 0; | |
switch(pos % 7) { | |
case 0: note = 0; break; | |
case 1: note = 2; break; | |
case 2: note = 3; break; | |
case 3: note = 5; break; | |
case 4: note = 7; break; | |
case 5: note = 8; break; | |
case 6: note = 11; break; | |
} | |
return octave * 12 + note; | |
} | |
else if(scale==MAJOR) { | |
int octave = pos / 7; | |
int note = 0; | |
switch(pos % 7) { | |
case 0: note = 0; break; | |
case 1: note = 2; break; | |
case 2: note = 4; break; | |
case 3: note = 5; break; | |
case 4: note = 7; break; | |
case 5: note = 9; break; | |
case 6: note = 11; break; | |
} | |
return octave * 12 + note; | |
} | |
else if(scale==WHOLE) { | |
int octave = pos / 6; | |
int note = 0; | |
switch(pos % 6) { | |
case 0: note = 0; break; | |
case 1: note = 2; break; | |
case 2: note = 4; break; | |
case 3: note = 6; break; | |
case 4: note = 8; break; | |
case 5: note = 10; break; | |
} | |
return octave * 12 + note; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment