Are note names supported in Scamp?

I searched in the documentation but could not find out if note names like c4 fs5 bf3 are supported or if there are classes/functions that convert between names and midi notes. I saw note names mentioned in the docs in the performance object only.

It’s not currently implemented, but you’re not the first person to ask about it! I’ll think about adding it to scamp_extensions, or even to scamp itself. Here’s how you might implement it:

pitch_class_displacements = {
    'c': 0,
    'd': 2,
    'e': 4,
    'f': 5,
    'g': 7,
    'a': 9,
    'b': 11
}

accidental_displacements = {
    '#': 1,
    's': 1,
    'f': -1,
    'b': -1,
    'x': 2,
    'bb': -2
}

def note_name_to_number(note_name: str):
    note_name = note_name.lower().replace(' ', '')
    pitch_class_name = note_name[0]
    octave = note_name[-1]
    accidental = note_name[1:-1]
    return (int(octave) + 1) * 12 + \
           pitch_class_displacements[pitch_class_name] + \
           (accidental_displacements[accidental] if accidental in accidental_displacements else 0)


print(note_name_to_number("c4"))
print(note_name_to_number("fs5"))
print(note_name_to_number("bf3"))

Thanks. I might try and implement it myself as a Python exercise.

Another (sort of crazy) implementation using a dictionary comprehension:

In case anyone is looking for this, someone recently asked me about using note names instead of midi pitches, and I wrote this insane dictionary comprehension that works:

named_notes = {
    f"{letter}{alteration}{octave}": [9, 11, 12, 14, 16, 17, 19]["ABCDEFG".index(letter.upper())] + \
    12 * octave + [-1, 0, 1][("b", "", "#").index(alteration)]
    for letter in "ABCDEFGabcdefg"
    for alteration in ("b", "", "#")
    for octave in range(0, 9)
}
print(named_notes["c4"])
print(named_notes["D#5"])
print(named_notes["Eb3"])