Jelly, 31 30 3029 bytes
FµḢ“¤ı¶“Œ’ḥ;ṪV×12Ʋ;⁾a#i’Ɗ€Sµ$ÞFµḢ“¤ı¶“Œ’ḥ;ṪV×12Ʋ;=”#Ḥ’ƊSµ$Þ
FµḢ“¤ı¶“Œ’ḥ;ṪV×12Ʋ;⁾a#i’Ɗ€Sµ$ÞFµḢ“¤ı¶“Œ’ḥ;ṪV×12Ʋ;=”#Ḥ’ƊSµ$Þ - Link: notes
$Þ - sort by: last two links as a monad:
µ - monadic chain:
F - flatten (this is to get a copy so we don't
alter what we are sorting in place)
µ - monadic chain:
Ḣ - head of note (removes it too)
ḥ - hash with salt & domain:
“¤ı¶“Œ’ - base 250 numbers = [256628,20]
X = CDEFGAB -> 4,6,8,9,11,13,15
Ʋ - last four links as a monad:
Ṫ - tail of note (removes it too)
V - evaluate as Jelly code -> integer
12 - twelve
× - multiply
Y = 12 × octave
; - concatenate -> [X,Y]
Ɗ€Ɗ - for eachlast (ie.three vlinks inas [],a ['#'],monad or- ['b']f(v):
i - first index (orv 0)being one of v[], in:
['#'], or ['b'])
⁾a# =”# - equals '#'? ['a',(vectorises)
'#'] Ḥ - double
’ - decrement
O = accidental offsets [], [1], or [-1]
; - concatenate -> [X,Y]+O
S - sum -> note number