In the example below, assume a change of value in bankSelect from 9 to 10. This forces to move from a bank 9 where the range was 1-128 into a bank 10 with a range that runs 129-255. In the 9th bank, MIDI range = 0-127. In the 10th bank, MIDI range = 0-126 !
When working with ctrlValue:setRange this doesn’t refresh the parameter value from parameter 12033 (corresponds with control #4) from let’s say 20 into 147. Instead control 4 shows 128.
function bankSelect(valueObject, value)
value = value + 1
local bankGroup = { -- MSB, LSB and ranges for my XV5080 banks
{87,64,128},{87,65,128},{87,66,128},{87,67,128},{87,68,128},{87,69,128},{87,70,128},{1,0,128}, -- preset A-G + GM
{89,6,128},{89,7,255},{89,10,128},{89,11,255},{89,14,128},{89,15,255},{89,18,128} -- SR-JV 4, 6, 8, 10
}
midi.sendControlChange (devPort, channel, 0, bankGroup[value][1])
midi.sendControlChange (devPort, channel, 32, bankGroup[value][2])
local control = controls.get (4) -- patch number
local valueObjects = control:getValues ()
local ctrlValue = control:getValue ("")
local message = ctrlValue:getMessage ()
if bankGroup[value][3] > 128 then
message:setMax (bankGroup[value][3]-129) -- set max MIDI value
ctrlValue:setRange (129, bankGroup[value][3], 0, false)
else
message:setMax (bankGroup[value][3]-1) -- set max MIDI value
ctrlValue:setRange (1, bankGroup[value][3], 0, false)
end
end
The old trick works: this changes a shown value 20 of control 4 (or parameter 12033) into a refreshed value of 147 when bankGroup changes from 9 to 10
function bankSelect(valueObject, value)
value = value + 1
local bankGroup = { -- MSB, LSB and ranges for my XV5080 banks
{87,64,128},{87,65,128},{87,66,128},{87,67,128},{87,68,128},{87,69,128},{87,70,128},{1,0,128}, -- preset A-G + GM
{89,6,128},{89,7,255},{89,10,128},{89,11,255},{89,14,128},{89,15,255},{89,18,128} -- SR-JV 4, 6, 8, 10
}
midi.sendControlChange (devPort, channel, 0, bankGroup[value][1])
midi.sendControlChange (devPort, channel, 32, bankGroup[value][2])
local control = controls.get (4) -- patch number
local valueObjects = control:getValues ()
local ctrlValue = control:getValue ("")
local message = ctrlValue:getMessage ()
ctrlValue:setRange (0, bankGroup[value][3], 0, true) -- set both display and MIDI min max
if bankGroup[value][3] > 128 then
ctrlValue:setMin (129)
message:setMax (bankGroup[value][3]-129) -- set max MIDI value
else
ctrlValue:setMin (1) -- set min display value
message:setMax (bankGroup[value][3]-1) -- set max MIDI value
end
parameterMap.set (deviceId, PT_VIRTUAL, 12033,parameterMap.get (deviceId, PT_VIRTUAL, 12033)+1) -- refresh the shown value
parameterMap.set (deviceId, PT_VIRTUAL, 12033,parameterMap.get (deviceId, PT_VIRTUAL, 12033)-1)