Stax, 25 24 bytes
╝─°U┤ƒXz☺=∞♫8åì=Só╢♀↔$è◄╝─°U┤ƒXz☺=≡eA╕δ┴╬\¿☺zt┼§ Run and debug it onlineRun and debug it online
The corresponding ascii representation of the same program is this.
{h9%H_H32/-c2>c4>-c7>c9>-mrE-v12%^^ Effectively, it calculates the keyboard index of each note using a formula, then calculates the resulting interval.
- Start from the base note, A = 02, B = 24, ... G = 1214
- Calculate the accidental offset
2 - code / 32wherecodeis the ascii code of the last character. - Add them together.
- If the result is > 24, subtract 1 to remove B#.
- If the result is > 7, subtract 1 to remove E#.
- Modularly subtract the two resulting note indexes, and add 1.