Last active
August 29, 2015 14:03
-
-
Save allenjprice/1e471344be3744c68ced to your computer and use it in GitHub Desktop.
Nashy Transposition, Take 1
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
var keys = { | |
c: ['C', 'D', 'E', 'F', 'G', 'A', 'B'], | |
cSharp: ['C#', 'D#', 'E#', 'F#', 'G#', 'A#', 'B#'], | |
d: ['D', 'E', 'F#', 'G', 'A', 'B', 'C#'], | |
dSharp: ['D#', 'E#', 'Fx', 'G#', 'A#', 'Bx', 'C#'], | |
eFlat: ['Eb', 'F', 'G', 'Ab', 'Bb', 'C', 'D'], | |
e: ['E', 'F#', 'G#', 'A', 'B', 'C#', 'D#'], | |
f: ['F', 'G', 'A', 'Bb', 'C', 'D', 'E'], | |
fSharp: ['F#', 'G#', 'A#', 'B', 'C#', 'D#', 'E#'], | |
gFlat: ['Gb', 'Ab', 'Bb', 'Cb', 'Db', 'Eb', 'F'], | |
g: ['G', 'A', 'B', 'C', 'D', 'E', 'F#'], | |
gSharp: ['G#', 'A#', 'Bx', 'C#', 'D#', 'E#', 'Fx'], | |
aFlat: ['Ab', 'Bb', 'C', 'Db', 'Eb', 'F'], | |
a: ['A', 'B', 'C#', 'D', 'E', 'F#', 'G#'], | |
aSharp: ['A#', 'B#', 'Cx', 'D#', 'E#', 'F#', 'Gx'], | |
bFlat: ['Bb', 'C', 'D', 'Eb', 'F', 'G', 'A'], | |
b: ['B', 'C#', 'D#', 'E', 'F#', 'G#', 'A#'], | |
numbers: ['1', '2', '3', '4', '5', '6', '7'] | |
} | |
function findNextToken(token, index, text){ | |
return text.indexOf(token, index); | |
} | |
function processText(text, originalKey, destinationKey){ | |
var result = ''; | |
for (var i=0; i<text.length; i++){ | |
var character = text[i]; | |
var reNotes = new RegExp("([A-G])"); | |
if (text[i] == '<'){ | |
var endDiamond = findNextToken('>', i, text); | |
//do something to mark the diamonds | |
} | |
if (text[i] == '_'){ | |
var endUnderscore = findNextToken('_', i, text); | |
//do something to mark the split bars | |
} | |
if (text[i] == '['){ | |
var endBracket = findNextToken(']', i, text); | |
//do something to mark section names and ignore transposition | |
} | |
if (text[i].match(reNotes)){ | |
switch (text[i]){ | |
case keys[originalKey][0]: | |
result += keys[destinationKey][0]; | |
break; | |
case keys[originalKey][1]: | |
result += keys[destinationKey][1]; | |
break; | |
case keys[originalKey][2]: | |
result += keys[destinationKey][2]; | |
break; | |
case keys[originalKey][3]: | |
result += keys[destinationKey][3]; | |
break; | |
case keys[originalKey][4]: | |
result += keys[destinationKey][4]; | |
break; | |
case keys[originalKey][5]: | |
result += keys[destinationKey][5]; | |
break; | |
case keys[originalKey][6]: | |
result += keys[destinationKey][6]; | |
break; | |
case keys[originalKey][7]: | |
result += keys[destinationKey][7]; | |
break; | |
} | |
} | |
else | |
result += text[i]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment