If you’re trying to change rackspaces using CC numbers rather than program changes, here is a much easier approach -
You don’t need to inject messages nor do you need to create program change messages. You can just extract the incoming CC number, do the subtraction as you were doing, and then use a script function called SwitchToProgramNumber to directly switch to the desired rackspace.
Var
LAUNCHKEY : MidiInDeviceAlias
Const
FirstCC : integer = 23 // Naming the first and last CC number makes it easier to change
LastCC : integer = 38 // the range later without having to modify hard-coded numbers all over the place
On ControlChangeEvent(m : ControlChangeMessage) Matching [FirstCC .. LastCC] from LAUNCHKEY
var
desiredPCNumber : integer // This is the program number we want to find
if GetCCValue(m) == 127
then
desiredPCNumber = GetCCNumber(m) - FirstCC // Normalize so that the first CC represents program number ZERO
SwitchToProgramNumber(desiredPCNumber, 0) // Use GPScript function instead of injecting messages
end
End