Batch, 136136 135 bytes
@set/ac=0,d=2,e=4,f=5,g=7,a=9,r=-23r=24 @call:c %2 :c @set s=%1 @set s=%s:b=-1% @set/ar=%s:#=+1%-r @if not "%2"=="" cmd/cset/aa13-r%%12+2r%%12 Explanation: The substitutions in the c subroutine replace # in the note name with +1 and b with -1. As this is case insensitive, Bb becomes -1-1. The variables for C...A (also case insensitive) are therefore chosen to be the appropriate number of semitones away from B=-1. The resulting string is then evaluated, and @xnor's trick of subtracting the result from the value gives the desired effect of subtracting the note values from each other. As Batch's % is not a true moduloEdit: Finally I have to use a bias value of -23 instead@Arnauld's trick of 1subtracting the modulo from 13 to ensureachieve the result is always positivedesired answer, saving 1 byte.