Project name: Guitar Chord Names
Goal: I want the user to enter the fret numbers for a guitar chord, and after hitting a Submit button, return the name of the chord. I want to more than only that, but that is where I want to start.
Problem: I want to reduce the number of variables to do the job.
I have a variable with the chromatic scale notes for the strings of a guitar: E, A, D, G, B, E. I also have a variable listing the 12 possible notes in Western music called the chromatic scale. If you know music theory, I am only going to use sharps for now.
I do not want to have a variable with the chromatic scale notes for each string. I would like to use use the string note to cycle through the chromatic scale notes. For example, a note on the 4th fret of the 6th tring of a guitar (the E string) is a G sharp (G#). If a user enters the number 4 for the 6th string input, I want to convert that to the note G# and save it.
Here is where I am confused about what to do. After getting the value of the input, I want to cycle through the chromatic scale variable, starting on the string note (E in this case), and count up until I find the chromatic note value that corresponds to the fret number entered. Or is it easier to have an array of chromatic note values for each string? Am I going about this the wrong way?
// Standard tuning open string note values const standardTuning = ["E", "A", "D", "G", "B", "E"]; // The chromatic scale using sharps const chromaticSharps = ["A", "A♯", "B", "C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯"];
How do I loop through the array
chromaticSharps , starting on E and counting up to find G#? E has an index of
7 in the array, but I will need it to be “reset” to
0 so that
G# has an index (in relation to E) of
4. And the 4th fret on the E string is
I’d prefer to do that rather than creating 5 array variables for each unique string, each having 12 values. Right now, the variable
chromaticSharps would be perfect for the A string. I would have to repeat that pattern starting on E for the E strings, D for the D string, etc.
If you do know music theory, then you know that I will have to incorporate the flat notes for flat keys. Right now, I just want to focus on chords that can be built from the major scale.