Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function note_number_to_name(number) {
- var pitch_class = ['c','d','e','f','g','a','b'];
- var pitch_d = [0,2,4,5,7,9,11];
- var str = ""
- var octave = Math.trunc((number/12) - 1);
- var pitch = number % 12;
- var index = -1;
- for(var i = 0; i< pitch_class.length;i++) {
- if(pitch_d== pitch) {
- index = i;
- break;
- }
- }
- if(index != -1) {//It means there is no sharp #
- str = str + pitch_class[index];
- str = str + octave;
- } else{
- pitch = (number - 1) % 12;
- for(var i = 0; i< pitch_class.length;i++) {
- if(pitch_d== pitch) {
- index = i;
- break;
- }
- }
- str = str + pitch_class[index];
- str = str + '#';
- str = str + octave;
- }
- str = str.toUpperCase();
- return str;
- }
- function note_name_to_number(note) {
- note = note.toLowerCase();
- var pitch_class = ['c','d','e','f','g','a','b'];
- var pitch_d = [0,2,4,5,7,9,11];
- var octave = parseInt(note[note.length-1]);
- var pitch_index = 0;
- for(pitch_index = 0; pitch_index< pitch_class.length; pitch_index++) {
- if(pitch_class[pitch_index] == note[0]) {
- break;
- }
- }
- var acc_index = 0;
- note = note.toUpperCase();
- if(note.length == 3) {
- return((octave+1)*12+pitch_d[pitch_index]+1)
- } else {
- return((octave+1)*12+pitch_d[pitch_index])
- }
- }
- function major_scale(note){
- note_number = note_name_to_number(note);
- var add_note = [0,2,4,5,7,9,11,12];
- var major = [];
- for(var i=0; i<add_note.length;i++) {
- major = note_number_to_name(note_number+add_note);
- }
- return major;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement