Last active
August 29, 2015 14:12
-
-
Save DanielFGray/7023ad2808cc9d53ba6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var globals = { | |
naturals: ['C', 'D', 'E', 'F', 'G', 'A', 'B'], | |
degrees: ['R', 'm2', 'M2', 'm3', 'M3', 'P4', ['A4', 'D5'], 'P5', 'm6', 'M6', 'm7', 'M7'], | |
modeNames: ['Ionian', 'Dorian', 'Phrygian', 'Lydian', 'Mixolydian', 'Aeolian', 'Locrian'], | |
accidentals: {'-1': '♭', 0: '', 1: '♯'}, | |
scales: { | |
'Major': [2, 2, 1, 2, 2, 2, 1], | |
'Minor': [2, 1, 2, 2, 1, 2, 2], | |
'Harmonic Minor': [2, 1, 2, 2, 1, 3, 1], | |
'Diminished Arpeggio': [3, 3, 3, 3] | |
} | |
}; | |
function modulate(arr, offset, alg) { | |
if(! Array.isArray(arr) && ! Array.isArray(alg) && ! Number.isInteger(offset)) { | |
return false; | |
} | |
var count = arr.length, | |
height = arr.length, | |
result = []; | |
if(alg !== undefined) { | |
result.push(arr[offset]); | |
count = alg.length; | |
} | |
for(var i = 0, j = 0; i < count; ++i) { | |
var node = offset + (alg ? j += alg[i] : i); | |
if(node >= height) | |
node %= height; | |
var piece = arr[node]; | |
result.push(piece); | |
} | |
return result; | |
} | |
function addAccidentals(notes, scale) { | |
// ???? | |
} | |
console.log('major degrees:', modulate(globals.degrees, 0, globals.scales.Minor)); | |
var naturals = ['C', 'D', 'E', 'F', 'G', 'A', 'B']; | |
for (var i=0; i < naturals.length; ++i) { | |
var scale = 'Major'; | |
var key = naturals[i]; | |
console.log(key + ' ' +scale, modulate(globals.naturals, globals.naturals.indexOf(key))); | |
} | |
console.log('minor degrees:',modulate(globals.degrees, 0, globals.scales.Minor)); | |
for (var i=0; i < naturals.length; ++i) { | |
var scale = 'Minor'; | |
var key = naturals[i]; | |
console.log(key + ' ' + scale.toLowerCase(), modulate(globals.naturals, globals.naturals.indexOf(key))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment