Skip to content

Instantly share code, notes, and snippets.

@code26
Created February 1, 2016 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save code26/e7ca4c3afd925b26dc0e to your computer and use it in GitHub Desktop.
Save code26/e7ca4c3afd925b26dc0e to your computer and use it in GitHub Desktop.
simple transpose
//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