Template for midi controller Akai apc40mk2 in Touchdesigner, tested 2022.32120. Requires that you set the midi mapping dialog as device in. The midi codes are set for callback automatically at startup. Tox should work straightforward and merge with different startup functions.
References:
https://derivative.ca/UserGuide/MIDI
https://www.akaipro.com/apc40-mkii
https://derivative.ca/UserGuide/MIDI#Using_MIDI_With_CHOPs