Introducing Composer’s Friend toolset—a JavaScript library for helping you practice playing guitar and piano and composing chord progressions. The library can be tailored to other fretboard and keyboard note visualization applications and has advanced features, such as MIDI connectivity (read: can connect to your favorite DAW).
Permanent link to application: https://atdesign.ee/music/ (you will be redirected to GitHub pages when you follow it).
GitHub: https://github.com/ATdesign/composersfriend/
A brief introduction to the application is provided below. I will also explain how you can use the library in your own projects.
Introduction
The basic idea behind developing the library was to have a quick reference for note relationships between the guitar fret and the keyboard and musical scales and chords. The library was later expanded with the chord relationship diagram and chord player and MIDI output. There are several primary considerations that were used while developing the library:
- The Circle of Fifths is key.The Circle of Fifths is a powerful tool in its own right. See for yourself. The main idea is to make it easier to understand note relationships.
- Notes in the chord are displayed all over the fretboard and do not rely on prescribed chord diagrams. The user chooses how the chord ought to be played.
- All graphics are generated using SVG (scalable vector graphics). Thus PDF files can be easily generated for reference.
The chords can also be played using a simple Web Audio API based synthesizer or transmitted over an available MIDI channel to your DAW. All of this right in the browser (if supported).
Using Composer’s Friend
It all startsHere we are concerned only with natural major and minor scales. when the user selects a scale on the Circle of Fifths. The outer circle (white ring) designates major scales, while the inner circle (black ring) represents the minor scales. Upon clicking on a scale, the corresponding scale notes are visualized on all associated instruments (in our case, the keyboard, guitar and bass frets). In addition, this also fills in the note relationship boxes and the Chord Progressions diagram. Should the user enable the P‑t mode, the pentatonic scale is shown.
What the user can do now is to add chords to the chord player by clicking on the chords available in the chord progression diagram. These will then show up in the Chord Player. The settings for each chord are explained in the figure below.
To edit a chord in the chord player, the user must first make it active by clicking on the chord, and then use the Chord Builder to replace the current chord with a different one by clicking on the available options.
The chord player has a transport implementation due to Tone.js library, that is, it acts like a very simple DAW. The duration of the chords relative to each other is represented by line segments. Once the chords are in place, the user should click on the Play button and repeated playback of the chord sequence will begin. The notes are shown on all instruments and the chord is played back (if this is enabled via options).
Import and export of chord progressions as text is possible. In addition, setting the tuning of the guitar instruments can be done online.
In the OptionsTo make use of the MIDI output option one may choose to use a virtual MIDI port such as LoopBe1., the following choices are currently available. First, the user can choose whether the chords should actually be played back using a simple synthesizer right in the browser. Second is the MIDI output option. At the time of writing (February 2018), it is supported directly only in Google Chrome.
Advanced: Using the Library in Your Own Projects
Include the following references:This library uses d3.js library to draw SVG elements.
<link href="css/style.css" rel="stylesheet"> <script src="js/d3.min.js"></script> <script src="js/d3-simple-slider.min.js"></script> <script src="js/composer-tools.js"></script>
Now, if you need to create a fretboard somewhere in your document, and in this example we’ll create the visualization of the first 1+6 frets of a 5‑string bass guitar in low B standard tuning, first create a placeholder:
<div class="fb-bass" style="width: 420px; height: 150px;"> </div>
Then, add the following script:
var bass_options = {"firstFretWidth": 70, "fretboardClass": "fretboard-bass", "fretboardNutClass": "fretboard-nut-bass", "fretCount": 6}; var fb_bass = new comptoolsFretboard(".fb-bass", "B0E1A1D2G2", bass_options);
The fret will automatically fill the provided placeholder. The results will look like this:
You can click on the strings to highlight notes, but this in itself is not very interesting. Let’s display a scale on the freatboard, e.g., A major. Below we create two buttons—one for showing the scale, and one for hiding it.
(Show the code)
The markup for the buttons:
<button class="show-scale">Show the scale</button> <button class="hide-scale">Hide the scale</button>
Corresponding code:
d3.select('.show-scale').on('click', function(){ fb_bass.updateNotes(get_scale('A','major').notes)}); d3.select('.hide-scale').on('click', function(){ fb_bass.clearNotes()});
Notice that the fretboard is equipped with a range slider which can be used for highlighting the notes in the position of interest.
We can create the keyboard in much the same way.
(Show the code)The markup for the keyboard placeholder
<div class="keyb" style="width: 380px; height: 100px;"> </div>
Code:
var st_keyb = new comptoolsKeyboard(".keyb", "C0-F2");
Suppose you want to discover the relations of the notes on the freatboard to, say, the notes found on the keyboard above. You will need to connect the instruments together by means of some logic. This is called instrument glue and the idea is that it implements a simple event dispatcher. To connect the two instruments, run the following code:
the_glue = new InstrumentGlue(); the_glue.objArray.push(st_keyb); the_glue.objArray.push(fb_bass); st_keyb.selection_callback = the_glue.funCallback; fb_bass.selection_callback = the_glue.funCallback;
The two instruments are now effectively connected and selecting a note on one instrument will trigger the display of the location of the same note on the other. Moreover, now, if you select a note on the fretboard, all notes of the same pitch will also be highlighted.
The use of other available widgets is a bit more involved. Study the code on GitHub to understand how these relations work.
Future Work
The following enhancements are planned, but not yet implemented:
- Option to show scale degrees instead of the actual notes.
- Backport of the parts editor from Saxophone’s Friend application.
- Even more features, bug fixes and code optimization…