Skip to content

Commit

Permalink
Added a lot more scales and few docs
Browse files Browse the repository at this point in the history
  • Loading branch information
x02210 committed Dec 22, 2014
1 parent 3ad4c41 commit fec0ae1
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 43 deletions.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,39 @@ the formulas). At the moment the following are supported:

## Supported Scales

TODO: When scales are implemented...
Note: Formulas need to be confirmed...

| Name | Interval Structure |
|------|---------|
| Major | W, W, H, W, W, W, H |
| Natural Minor | W, H, W, W, H, W, W |
| Major Pentatonic | W, W, W+H, W, W+H |
| Minor Pentatonic | W+H, W, W, W+H, W |
| Blues | W+H, W, H, H, W+H, W |
| Major Blues | W, H, H, H, H, H, W, H, W |
| Minor Blues | W, H, W, H, H, H, W, W |
| Ionian Mode | W, W, H, W, W, W, H |
| Dorian Mode | W, H, W, W, W, H, W |
| Phrygian Mode | H, W, W, W, H, W, W |
| Lydian Mode | W, W, W, H, W, W, H |
| Mixolydian Mode | W, W, H, W, W, H, W |
| Aeolian Mode | W, H, W, W, H, W, W |
| Locrian Mode | H, W, W, H, W, W, W |
| Harmonic Minor | W, H, W, W, H, W+H, H |
| Phrygian Dominant | H, W+H, H, W, H, W, W |
| Jazz Melodic Minor | W, H, W, W, W, W, H |
| Dorian b2 | H, W, W, W, W, H, W |
| Lydian Augmented | W, W, W, W, H, W, H |
| Lydian b7 | W, W, W, H, W, H, W |
| Mixoydian b13 | W, W, H, W, H, W, W |
| Locrian #2 | W, H, W, H, W, W, W |
| Super Locrian | H, W, H, W, W, W, W |
| Chromatic | H, H, H, H, H, H, H, H, H, H, H, H |
| Whole Tone | W, W, W, W, W, W, W |
| Dimished Whole Half | W, H, W, H, W, H, W, H |
| Dimished Half Whole | H, W, H, W, H, W, H, W |
| Hungarian Minor | W, H, W+H, H, W+H, H |
| Double Harmonic | H, W+H, H, W, H, W+H, H |
| Enigmatic | W, W+H, W, W, W, H, H |
| Japanese | H, W+H, W, H, W, H |

8 changes: 8 additions & 0 deletions css/scale.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#more select {
height:150px;
padding-right: 4px;
}

#more {
padding-left: 50px;
}
18 changes: 18 additions & 0 deletions doc/getScalesMd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

#
# Get the supported chords in markdown format
#

echo "| Name | Interval Structure |"
echo "|------|---------|"
cat ../src/ScaleTypes.js | grep "C.Scale.TYPES\[" | awk -F '[][\"]' '{ \
intervals = $6
gsub(/ .5/, " H", intervals)
gsub(/ 1\.5/, " W+H", intervals)
gsub(/ 1/, " W", intervals)
print "| "$3" | "intervals"|"
}'

exit 0

139 changes: 125 additions & 14 deletions jschords-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ C.Chord = C.Class.extend({
* @private
*/
_formulaToNote: function(f){
var scale = new C.Scale({root: this.options.root,type:"Major"})
var scale = new C.Scale({root: this.options.root,name:"Major"})
return scale.offset(f);
},

Expand Down Expand Up @@ -2297,7 +2297,8 @@ C.IStringInstrument = C.Instrument.extend({

/**
* Create full the fretboard, if applicable. Store
* the HTML elements on idx...
* the HTML elements on this.fretboard to be able to
* clear without redrawing
*
* @param {HTMLElement} el
* @param {Object} opts
Expand All @@ -2308,6 +2309,9 @@ C.IStringInstrument = C.Instrument.extend({
*/
drawInstrument: function(el,opts){

if (this.fretboard!==undefined) return;

C.DomUtil.empty (el);
var numStrings = this.getNumStrings();
var numFrets = this.options.numFrets;

Expand All @@ -2334,7 +2338,7 @@ C.IStringInstrument = C.Instrument.extend({
var clsExtra = "";
if ( C.Util.objValue(opts, "changeSize", false)) clsExtra = " s"+(s+1);

for (var f=1; f<numFrets+1; f++){
for (var f=1; f<numFrets+2; f++){
idx[s][f] = C.DomUtil.create('td',cls+clsExtra,row);
idx[s][f].setAttribute("data-string",s);
idx[s][f].setAttribute("data-fret",f);
Expand All @@ -2344,23 +2348,27 @@ C.IStringInstrument = C.Instrument.extend({

idx[numStrings] = [];
var row = C.DomUtil.create('tr','',t);
for (var f=0; f<numFrets+1; f++){
for (var f=0; f<numFrets+2; f++){
idx[numStrings][f] = C.DomUtil.create('td',"g_fret_num",row);
if ((f!=1 && f%2!=0 && f!=11) || f==12) idx[numStrings][f].innerText=f;
// dot pattern...
if ((f!=1 && f%2!=0 && f!=11 && f!=13) || f==12) idx[numStrings][f].innerText=f;
}

el.appendChild(t);

return idx;
this.fretboard = idx;

return this;
},

/**
* Draw the whole scale on the fretboard. TODO: extend
* with boxes
* Draw the whole scale on the fretboard.
*
* TODO: extend with boxes
*/
drawScale: function(scale,el,opts){
C.DomUtil.empty (el);
var idx = this.drawInstrument(el,opts);
drawScale: function(scale,opts,el){
this.drawInstrument(el,opts);
var idx = this.fretboard;
var notes = scale.getNotes();

for (var n=0; n<notes.length; n++) {
Expand All @@ -2372,7 +2380,7 @@ C.IStringInstrument = C.Instrument.extend({
for (var s=0; s<this.getNumStrings(); s++) {

// Get all positions of this not on this string
var pos = this.getFretsFor(notes[n],s,this.options.numFrets);
var pos = this.getFretsFor(notes[n],s,this.options.numFrets+1);

// Add them
for (var p=0; p<pos.length; p++) {
Expand All @@ -2385,6 +2393,21 @@ C.IStringInstrument = C.Instrument.extend({
return this;
},

/**
* Clear the current scale if any
*/
clearScale: function(){
var f = this.fretboard;

if (!f) return;

for (var i=0; i<f.length; i++){
for (var j=0; j<f[i].length; j++){
C.DomUtil.empty(f[i][j]);
}
}
},

drawChordOnInstrument: function(what,el,opts){
}
});
Expand All @@ -2398,7 +2421,7 @@ C.IStringInstrument = C.Instrument.extend({
C.Scale = C.Class.extend({
options: {
root: "C",
type: "Major"
name: "Major"
},

/**
Expand All @@ -2410,7 +2433,34 @@ C.Scale = C.Class.extend({
initialize: function (options) {
C.setOptions(this, options);
// Cache distances
this.dist = C.Scale.TYPES[this.options.type];
this.dist = C.Scale.TYPES[this.options.name];
},

/**
* Get string representation of this scale
*/
toString: function(){
return this.options.root+" "+this.options.name;
},

/**
* Set the root note of the scale
* @param {String} root
*/
setRoot: function(root){
this.options.root=root;
return this;
},

/**
* Set/Change the scale name/type
*
* @param {String} name
*/
setName: function(name){
this.options.name = name;
this.dist = C.Scale.TYPES[this.options.name];
return this;
},

/**
Expand Down Expand Up @@ -2468,6 +2518,30 @@ C.Scale = C.Class.extend({
}

return notes;
},

/**
* Get scale's name
* @return {String}
*/
getName: function(){
return this.options.name;
},

/**
* Get scale's root (attribute)
* @return {String}
*/
getRoot: function(){
return this.options.root;
},

/**
* Get scale's root (Note)
* @return {C.Note}
*/
getRootNote: function(){
return new C.Note({note: this.options.root});
}
});

Expand All @@ -2486,9 +2560,46 @@ C.Scale.TYPES = new Array();

C.Scale.TYPES["Major"] = [ 1, 1, .5, 1, 1, 1, .5 ];
C.Scale.TYPES["Natural Minor"] = [ 1, .5, 1, 1, .5, 1, 1 ];

C.Scale.TYPES["Major Pentatonic"] = [ 1, 1, 1.5, 1, 1.5 ];
C.Scale.TYPES["Minor Pentatonic"] = [ 1.5, 1, 1, 1.5, 1 ];
C.Scale.TYPES["Blues"] = [ 1.5, 1, .5, .5, 1.5, 1 ];
C.Scale.TYPES["Major Blues"] = [ 1, .5, .5, .5, .5, .5, 1, .5, 1 ];
C.Scale.TYPES["Minor Blues"] = [ 1, .5, 1, .5, .5, .5, 1, 1 ];

// Shifting!
C.Scale.TYPES["Ionian Mode"] = [ 1, 1, .5, 1, 1, 1, .5 ];
C.Scale.TYPES["Dorian Mode"] = [ 1, .5, 1, 1, 1, .5, 1 ];
C.Scale.TYPES["Phrygian Mode"] = [ .5, 1, 1, 1, .5, 1, 1 ];
C.Scale.TYPES["Lydian Mode"] = [ 1, 1, 1, .5, 1, 1, .5 ];
C.Scale.TYPES["Mixolydian Mode"] = [ 1, 1, .5, 1, 1, .5, 1 ];
C.Scale.TYPES["Aeolian Mode"] = [ 1, .5, 1, 1, .5, 1, 1 ];
C.Scale.TYPES["Locrian Mode"] = [ .5, 1, 1, .5, 1, 1, 1 ];


C.Scale.TYPES["Harmonic Minor"] = [ 1, .5, 1, 1, .5, 1.5, .5 ];
C.Scale.TYPES["Phrygian Dominant"] = [ .5, 1.5, .5, 1, .5, 1, 1 ];

C.Scale.TYPES["Jazz Melodic Minor"] = [ 1, .5, 1, 1, 1, 1, .5 ];
C.Scale.TYPES["Dorian b2"] = [ .5, 1, 1, 1, 1, .5, 1 ];
C.Scale.TYPES["Lydian Augmented"] = [ 1, 1, 1, 1, .5, 1, .5 ];
C.Scale.TYPES["Lydian b7"] = [ 1, 1, 1, .5, 1, .5, 1 ];
C.Scale.TYPES["Mixoydian b13"] = [ 1, 1, .5, 1, .5, 1, 1 ];
C.Scale.TYPES["Locrian #2"] = [ 1, .5, 1, .5, 1, 1, 1 ];
C.Scale.TYPES["Super Locrian"] = [ .5, 1, .5, 1, 1, 1, 1 ];



C.Scale.TYPES["Chromatic"] = [ .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5 ];
C.Scale.TYPES["Whole Tone"] = [ 1, 1, 1, 1, 1, 1, 1 ];
C.Scale.TYPES["Dimished Whole Half"] = [ 1, .5, 1, .5, 1, .5, 1, .5 ];
C.Scale.TYPES["Dimished Half Whole"] = [ .5, 1, .5, 1, .5, 1, .5, 1 ];


C.Scale.TYPES["Hungarian Minor"] = [ 1, .5, 1.5, .5, 1.5, .5 ];
C.Scale.TYPES["Double Harmonic"] = [ .5, 1.5, .5, 1, .5, 1.5, .5 ];
C.Scale.TYPES["Enigmatic"] = [ 1, 1.5, 1, 1, 1, .5, .5 ];
C.Scale.TYPES["Japanese"] = [ .5, 1.5, 1, .5, 1, .5 ];
/**
* C.DomUtil contains various utility functions for working with DOM.
* FULL CREDIT TO LEAFLET
Expand Down
Loading

0 comments on commit fec0ae1

Please sign in to comment.