Make chords.js a bit more readable.

This commit is contained in:
Tomas Groth 2016-06-05 22:30:22 +02:00
parent e51ffd9759
commit 82d5c6dcb2

View File

@ -39,11 +39,12 @@ function storeTransposeValue(songId,transposeValueToSet) {
} }
function transposeChord(chord, transposeValue, notation) { function transposeChord(chord, transposeValue, notation) {
var chordSplit = chord.replace('♭', 'b').split(/[\/\(\)]/), transposedChord = '', note, notenumber, rest, currentChord, var chordSplit = chord.replace('♭', 'b').split(/[\/\(\)]/);
notesSharp = notesSharpNotation[notation], var transposedChord = '', note, notenumber, rest, currentChord;
notesFlat = notesFlatNotation[notation], var notesSharp = notesSharpNotation[notation];
notesPreferred = ['b','#','#','#','#','#','#','#','#','#','#','#']; var notesFlat = notesFlatNotation[notation];
chordNotes = Array(); var notesPreferred = ['b','#','#','#','#','#','#','#','#','#','#','#'];
var chordNotes = Array();
for (i = 0; i <= chordSplit.length - 1; i++) { for (i = 0; i <= chordSplit.length - 1; i++) {
if (i > 0) { if (i > 0) {
transposedChord += '/'; transposedChord += '/';
@ -72,16 +73,23 @@ function transposeChord(chord, transposeValue, notation) {
} }
notenumber = (notesSharp.indexOf(note) === -1 ? notesFlat.indexOf(note) : notesSharp.indexOf(note)); notenumber = (notesSharp.indexOf(note) === -1 ? notesFlat.indexOf(note) : notesSharp.indexOf(note));
notenumber -= parseInt(transposeValue); notenumber -= parseInt(transposeValue);
while (notenumber > 11) {notenumber -= 12;} while (notenumber > 11) {
while (notenumber < 0) {notenumber += 12;} notenumber -= 12;
}
while (notenumber < 0) {
notenumber += 12;
}
if (i === 0) { if (i === 0) {
currentChord = notesPreferred[notenumber] === '#' ? notesSharp[notenumber] : notesFlat[notenumber]; currentChord = notesPreferred[notenumber] === '#' ? notesSharp[notenumber] : notesFlat[notenumber];
lastChord = currentChord; lastChord = currentChord;
} else { } else {
currentChord = notesSharp.indexOf(lastChord) === -1 ? notesFlat[notenumber] : notesSharp[notenumber]; currentChord = notesSharp.indexOf(lastChord) === -1 ? notesFlat[notenumber] : notesSharp[notenumber];
} }
if(!(notesFlat.indexOf(note)===-1 && notesSharp.indexOf(note)===-1)) transposedChord += currentChord + rest; else transposedChord += note + rest; //note+rest; if (!(notesFlat.indexOf(note) === -1 && notesSharp.indexOf(note) === -1)) {
//transposedChord += currentChord + rest; transposedChord += currentChord + rest;
} else {
transposedChord += note + rest;
}
} }
} }
return transposedChord; return transposedChord;