From 66303909e5e07e118f50949b5746654877b2b257 Mon Sep 17 00:00:00 2001 From: EdricCantu <136949182+EdricCantu@users.noreply.github.com> Date: Fri, 13 Sep 2024 15:16:24 -0500 Subject: [PATCH] Create noteToFreq,js --- noteToFreq,js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 noteToFreq,js diff --git a/noteToFreq,js b/noteToFreq,js new file mode 100644 index 0000000..151cd75 --- /dev/null +++ b/noteToFreq,js @@ -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)); +}