How to send an on/off midi message

To send a message just once, you can use once:

once $ s "cp"

This works for midi too, as a random example:

once $ cc "40:30" # s "midi"