Many thanks! This kind of example makes learning the script much easier, I’d not have got far without your help! I deleted my post above with a bunch errors and remade it here.
This one works perfectly for the level:
function sendRevLevel(valueObject,value)
ccNum = valueObject:getMessage():getParameterNumber()
midi.sendControlChange(portNum,midiChannel,ccNum,127-value)
end
I switched out this format function’s numbers:
function fmtLevel(valueObject,value)
return(math.floor(127-value))
end
For this:
function fmtLevel(valueObject,value)
return(math.floor(value))
end
So it now just displays a simple 0-127 for OP Level instead of running from 127 to 0 on the display.
I’m using the ADSR display style, so didn’t use the ADSR formatting, but also I actually needed a slightly different function in the end.
The DAFM is a weird device and is converting full MIDI range to the number of values the Megadrive/Genesis could use for audio. So despite it saying value range is 32 for example, this is still sent as as 0-127. In order to achieve this stepping the function the 127-value was altered to 127-(value*4)-1
function sendADLevel(valueObject,value)
ccNum = valueObject:getMessage():getParameterNumber()
midi.sendControlChange(portNum,midiChannel,ccNum,127-(value*4)-1)
end
Where the value min max was set for the control as 1 - 32
the control value range must be 1-32. This is multipled by four, in order to get every fourth value from 1 to 128. One is subtracted after we’ve done our multiplcation, to put us back in the 0-127 range, allowing us to step through every fourth relevant MIDI value up and down in the 0-127 range. This is then subtracted from 127 to obtain the reversed value.
for the controls with a range of 16, it’s set 1-16in the min and max and the multiplier is 8:
function sendSRLevel(valueObject,value)
ccNum = valueObject:getMessage():getParameterNumber()
midi.sendControlChange(portNum,midiChannel,ccNum,127-(value*8)-1)
end
The only downside here is the E1 display doesn’t show sustain quite as zero when it is, and so on, as it thinks it’s 1, so I added a formatter:
function fmtAD(valueObject,value)
return(math.floor(value-1))
end
I’m new to all this so it could be it can be done in a more efficient manner, so of course all criticism and tips are welcome.
I figured it’s worth pasting this in here so future visitors to this thread can see a practical example of reversed values in raw code