forked from openlp/openlp
Make chords.js a bit more readable.
This commit is contained in:
parent
e51ffd9759
commit
82d5c6dcb2
@ -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 += '/';
|
||||||
@ -70,18 +71,25 @@ function transposeChord(chord, transposeValue, notation) {
|
|||||||
note = currentchord;
|
note = currentchord;
|
||||||
rest = "";
|
rest = "";
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user