I've found a really nice pice of code here https://stackoverflow.com/a/45979883/9138729
I have a hard time to make it work in my C# form application
function transposeChord(chord, amount) {
var scale = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];
var normalizeMap = {
"Cb": "B",
"Db": "C#",
"Eb": "D#",
"Fb": "E",
"Gb": "F#",
"Ab": "G#",
"Bb": "A#",
"E#": "F",
"B#": "C"
};
return chord.replace(/[CDEFGAB](b|#)?/g, function(match) {
matchIndex = normalizeMap[match] ? normalizeMap[match] : match;
var i = (scale.indexOf(matchIndex) + amount) % scale.length;
if (i < 0) {
return scale[i + scale.length];
} else {
return scale[i];
}
}
);
}
- The normalizeMap var has 2 options on each line (string[,]?).
- The replace function in C# doesn't work with the "(b|#)?/g" part (i think)
- The function(match) is present in C#?
Or do I need to take a whole new approach to fit C# logic?