# Tune scope error for C# major chords

There is a fail on C# major chord:

That's because for some reason E# is not able to be played. The way the note names are translated into note numbers is not a very good way. It's just getting the note numbers from a dictionary, which, for some reason, does not include E#.

Yes, I know what I'm talking about, because I modified the library, (and made it better) Snap! Build Your Own Blocks

Thanks for bringing this up! This is a known issue that will be corrected with the next pull request, hopefully within the next day or so. There are actually two issues here. The first is that the Chord block is reporting the wrong note. C# Major chord consists of the notes C#, F, and G#. The chord block is reporting an E# instead of an F. The second problem is that TuneScope didn't originally account for E# or B#, since they come up so rarely in music notation. Both issues are corrected in the latest build.

That's why you use a function to convert a note name to note number instead of using a dictionary. Here's the one I made.

snap

javascript
function noteNum(noteName) {
if (Array.isArray(noteName)) {
return noteName.map((e) => {
return noteNum(e);
})
}

if (typeof noteName == 'string' && isNaN(noteName)) {
function range(start, end) {
if (end == undefined) {
end = start;
start = 0;
}

if (start > end) {
return Array.from(new Array(start - end + 1), (x, i) => i + end).reverse()
} else if (start == end) {
return [start];
} else {
return Array.from(new Array(end - start + 1), (x, i) => i + start);
}
}

function letter(string, list) {
var result = [];
if (typeof list == 'object') {
for (let i = 0; i < list.length; i++) {
result.push(string[list[i]]);
}
} else {
result = string[list];
}
return result;
}

splitNoteName = noteName.split('');
var index = splitNoteName.indexOf(splitNoteName.find(e => !isNaN(e) || e == '-'));
var octiveNum = ((index > 0) ? letter(noteName, range(index, noteName.length)) : ['4']).join('');
console.log(octiveNum);
var octive = parseFloat((!isNaN(octiveNum) ? octiveNum : 4));
var notes = {
'c': 1,
'd': 3,
'e': 5,
'f': 6,
'g': 8,
'a': 10,
'b': 12
};
var note = notes[letter(noteName, 0).toLowerCase()];

var accidentals = letter(noteName, range(0, (index > 0) ? index - 1 : noteName.length));

for (i = 0; i < accidentals.length; i++) {
item = accidentals[i];

if (item == undefined) {
continue;
}

if (item == '#' || item == 's') {
note += 1;
} else if (item == '♭' || item == 'b') {
note -= 1;
}
}

return ((note + ((13 * (octive + 1)) - octive)) - 2);
} else {
return parseFloat(noteName);
}
}


It's better because you can do C##4 and it'll convert it to 62 or D4.

This is the testing project: