Notes, chords, scales lib

What is the best way to manage notes, chords and scales in midi domain? I’d like to construct chords from midi notes, detect chords from midi input, filter input notes by scale, etc. Is there a library for that?

I wrote an app that detects chords. Do you mean like that?

Wow, cool app!
Yes, like that. Did you use some 3rd party library for chord detection or wrote it yourself?

wrote it myself.