Created
February 1, 2016 02:43
-
-
Save code26/e7ca4c3afd925b26dc0e to your computer and use it in GitHub Desktop.
simple transpose
This file contains 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
//from http://stackoverflow.com/a/7936999 | |
function transposeChord(chord, amount) { | |
var scale = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]; | |
return chord.replace(/[CDEFGAB]#?/g, | |
function(match) { | |
var i = (scale.indexOf(match) + amount) % scale.length; | |
return scale[ i < 0 ? i + scale.length : i ]; | |
}); | |
} | |
alert(transposeChord("Dm7/G", 2)); // gives "Em7/A" | |
alert(transposeChord("Fmaj9#11", -23)); // gives "F#maj9#11" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment