Javascript library of functions for creating diagrams of guitar chords and scales.
Here are three examples of this library in use.
- http://myguitarpal.com/guitar-chord-finder/
- http://myguitarpal.com/guitar-scale-finder/
- http://myguitarpal.com/mp3/g-to-d-over-f-sharp/
head
tags.
You should include the stylesheet as well in the head of your document.
There are two main functions you should be aware of at present. buildChord()
and buildScale()
.
buildChord(chord, show)
Returns an HTML chord diagram.
chord
(object)(required) The object for the chord you would like to build.
show
(string)(required)
Currently accepts two options. fingering
or degrees
. fingering
will output the chord fingerings, degrees
will output the chordal degrees.
var elem = document.getElementById('chord');
elem.innerHTML = buildChord(
{
fingering: [0,1,2,0,0,0],
chord: [0,2,2,0,0,0],
degrees: [1,5,1,'b3',5,1],
}, 'fingering'
);
The object needs three properties defined which are fingering
, chord
and degrees
.
chord
= the actual placement of the notes on the guitar fretboard.
fingering
= the fingers used to fret the notes.
degrees
= scale degrees the chord is built from.
Each of these properties values should be an array with six values in the array. There are six values in the array representing six strings on a guitar. So the first value will be the sixth string, second value the fifth string, third value the fourth string and so on.
If you'd like to build a chord where not every string is played, use "x" as the note value for that string. For example:
var elem = document.getElementById('chord');
elem.innerHTML = buildChord(
{
fingering: ['x',0,2,3,2,0],
chord: ['x',0,2,2,1,0],
degrees: ['x',1,5,1,'b3',5],
}, 'fingering'
);
buildScale(scale, show)
Returns an HTML scale diagram.
scale
(object)(required) The object for the scale you would like to build.
show (string)(required) Takes either "fingering" or "degrees" depending upon which you would like to show.
Usage is very similar tobuildChord()
. The structure of the scale object is slightly different in order to accommodate more than one note per string.
To show a C Major guitar scale diagram in the element with the id of "scale" you would do the following.
var elem = document.getElementById('scale');
elem.innerHTML = buildScale(
{
root: [['x'],[3],['x'],['x'],['x'],['x']],
fingering: [[],[3],[0,2,3],[0,2],[0,1],[]],
scale: [[],[3],[0,2,3],[0,2],[0,1],[]],
}, 'fingering'
);
You can see there are now multi-dimensional arrays for root
, fingering
and scale
in order to support multiple fretted notes per string.
This will make the most sense if you copy the example above, change some values then look at the html output of the function.
root
= the starting note of the scale. Fill in the rest of the strings without root notes with "x".
fingering
= the fingering of the scale.
scale
= the actual placement of the notes in the scale on the fretboard.