How to change patterns with MIDI?

I was wondering if it is possible to change rhythm patterns with MIDI inputs.
for ex: there are 3 types of rhythmic patterns declared in 3 different variables called ‘patternA’ , ‘patternB’ , ‘patternC’. Is there a way to trigger these variables to MIDI controller to change scenes in real time?

You can use the sync command to respond to MIDI input.
In the “Cues” window you can see the midi messages coming in, so you can check which MIDI messages you can sync to (make sure “Enable incoming MIDI cues” is checked in Preferences => IO).
There should be some examples in this forum if you search for “sync midi”. Hopefully that’s enough to get you started. If you try something and get stuck, it is helpful if you post the code you tried so we can see where it needs fixing.