Skip to content

Commit

Permalink
Create noteToFreq,js
Browse files Browse the repository at this point in the history
  • Loading branch information
EdricCantu authored Sep 13, 2024
1 parent a7f56d8 commit 6630390
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions noteToFreq,js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function ntf(note, tune = "A4=440"){
tune = tune.split("=");
tune = {note: tune[0].split("="), pitch: parseInt(tune[1])};
tune.note = {letter: tune.note[0]], octave: parseInt(tune.note[1])};
note = note.split("=");
note = {letter: note[0], octave: parseInt(note[1])};
//check if octave is similar
if(note.octave == tune.note.octave){
if(note.letter == tune.note.letter) return tune.pitch;
return;
}

}
function interval(l1,l2){
while(l1 !== l2){
switch(l1[]
}
}
function cmp(l1, l2){



}

function accidentalToStrict(letter){
notesSharp = "C C# D D# E F F# G G# A A# B".split(" ");
notesFlat = "C Db D Eb E F Gb G Ab A Bb B".split(" ");
notes = "CC CD DD DE EE FF FG GG GA AA AB BB".split(" ");
switch(letter[1]){
case undefined:
return letter.repeat(2);
break;
case "#":
return notes[notesSharp.indexOf(letter)];
break;
case "b":
return notes[notesFlat.indexOf(letter)];
break;
}
}
noteMap = [];
octave = -2;
while(octave++ < 9) noteMap.push(...("CC CD DD DE EE FF FG GG GA AA AB BB".split(" ").map(letter=>(letter+octave))));
function noteToMidi(note){
//figure out how to separate letter and octave
return noteMap.indexOf(accidentalToStrict(letter));
}

0 comments on commit 6630390

Please sign in to comment.