A sustain pedal is a type of on/off switch. When you press the pedal, the keyboard should send an “on” MIDI message to your computer, and when you release the pedal, an “off” message.
Sustain pedals have one of two polarities: normally open and normally closed. Since there’s not a universal standard, some keyboard manufacturers have used one polarity while others use the opposite polarity. Thus, sustain pedals are not always interchangeable.
If your MainStage instruments continue sustaining when you aren’t pressing the sustain pedal but release when you press the pedal, the sustain pedal polarity is probably opposite from that of your keyboard.
Many sustain pedals, like the M-Audio SP-2, include a polarity switch so they can be used with practically any keyboard. If you are experiencing this polarity issue, first try flipping the switch to reverse the pedal’s polarity.
Some keyboards include a feature to reverse the setting on the keyboard itself. This may involve changing a setting in a menu or pressing the pedal while the keyboard is being turned on. Some keyboards are able to automatically detect the pedal’s polarity. Consult your keyboard’s user guide for more information.