View on GitHub

jsChords

A project that aims on creating all possible chords and scales (based on the formulas) for a given string instrument. Number of strings and tuning can change (experimental piano is also supported)

Download this project as a .zip file Download this project as a tar.gz file

DEMOs

Chords

You can see Am demo on guitar or you might as well see it on a bouzouki (traditional 3-String) here. However, you might also like this on a piano or a 4-String bouzouki... Or anything else with strings!

Scales

The scales demo can be found here. Again, you can try various instruments like bouzouki. Enjoy!

NEW: Tuner

In order to experiment with the new JS audio API, a simple tuner has been created here

Code examples

Curious about how the demo works? Well... it is simple, 15 lines of code:

1. Parse parameters


var qString = C.Util.getQueryString();
var pos = (qString.pos!==undefined) ? parseInt(qString.pos)-1 : 0;
var inst = qString.inst;
var cname = qString.chord;

2. Create the correct instrument and chord!

chord = C.Chord.byString(cname)

switch (inst) {
    case "Guitar":
	inst = new C.Guitar();
	break;
    case "Bazooka":
	inst = new C.Bazooka();
	break;
    case "Bazooka4": // Let's change a bit the tuning and strings
	inst = new C.Bazooka({strings:["C","F","A","D"], maxFretSpan: 4});
	break;
    case "Piano":
	inst = new C.Piano();
	break;
    default:
}

3. and finally, plot it:

inst.mapChord(chord);
inst.diagram(pos,C.DomUtil.get('diagram'),{});
updateCount();

Well, few more things may be going on but are all for the GUI and nothing complicated, example:

    function onSelChange(){
	var s1=C.DomUtil.get('allNotes')
	var s2=C.DomUtil.get('allTypes')
	
	s1.disabled=true;
	s2.disabled=true;
	
	window.history.pushState("", "", 
	    window.location.href.replace(/chord=[^&]+/,
			"chord="+escape(s1.value)+escape(s2.value)));
	
	chord.setRoot(s1.value);
	chord.setType(s2.value);
	
	C.DomUtil.empty(C.DomUtil.get('diagram'))
	inst.mapChord(chord);
	inst.diagram(0,C.DomUtil.get('diagram'),{});
	
	s1.disabled=false;
	s2.disabled=false;
	updateCount();
	updateInfo();
    }

How can I add a new instrument?

One can always create a "customized" guitar to experiment with, however, creating a new new instrument is very easy. Looking into jsChords/src/instruments/Guitar.js:


C.Guitar = C.IStringInstrument.extend({
    options: {
	numFrets: 12,
	name: "Guitar",
	description: "This is A guitar!",
	strings: ["E", "A", "D", "G", "B", "e"],
	
	// Playable? parameters
	hasBar: true, 
	ignoreTone0: true,
	maxPlayableTones: 4,
	maxFretSpan: 4 
    }
})

Each instrument supports the following options/attributes:

Starting with the Guitar file as base, copy/paste it, rename and customize. Your new instrument is ready!

Documentation

Documentation is generated with jsduck and can be found online here.

Disclaimer

Many thanks to the Leaflet project, from which we use the classes: C.Class, C.Util and C.DomUtil and we have adopted the same OO model.