Help with code for Midi legato playing and pitchbend

PieterP:
You can only pitch bend an entire channel, you can't do it for individual notes.

I know that , this is for 1 note playing at a time (mono) but that's why i'm thinking there may be a way i can detect whether the note has been turned off or is still pressed after another note off has been sent, for example like i said i play d3 and it sends pitchbend and then i play d#3 after with the d3 still held down and i tell it to pitchbend 0 amount on d3 so everything is fine untill here, its playing only D#3 with pitchbend zero, then when i release D#3 D2 will sound again but a note on is not sent because it was already pressed from before so no pitchbend is sent, im i making sense, so i guess i need something that tells the program that after the release of D#3 go to previous state with pitch bend -2949