I’ve been using the sendNrpn() method posted by someone else for a long time. The Lua version has been broken for a while. The webUI version does work.
function sendNrpn(port, channel, parameter, value)
local parameterMSB = (parameter >> 7) & 0x7F
local parameterLSB = parameter & 0x7F
local valueMSB = (value >> 7) & 0x7F
local valueLSB = value & 0x7F
local messages = {
{channel = channel, type = CONTROL_CHANGE, controllerNumber = 99, value = parameterMSB},
{channel = channel, type = CONTROL_CHANGE, controllerNumber = 98, value = parameterLSB},
{channel = channel, type = CONTROL_CHANGE, controllerNumber = 6, value = valueMSB},
{channel = channel, type = CONTROL_CHANGE, controllerNumber = 38, value = valueLSB}
}
for i, msg in ipairs(messages) do
midi.sendMessage(port, msg)
end
sendNrpn is fixed in the upcoming release. I have added extra parameters to change order of bytes and including the reset bytes. The documentation will be updated.
Hi, is there a way to override the standard sendNrpn function for a bespoke one?
I tried this at the start of the script, to no avail.
local originalSendNrpn = midi.sendNrpn -- keep original
function mySendNrpn(port, channel, parameter, value)
print("Custom NRPN code")
local parameterMSB = (parameter >> 7) & 0x7F
local parameterLSB = parameter & 0x7F
local valueMSB = (value >> 7) & 0x7F
local valueLSB = value & 0x7F
local messages = {
{channel = channel, type = CONTROL_CHANGE, controllerNumber = 98, value = parameterLSB},
{channel = channel, type = CONTROL_CHANGE, controllerNumber = 99, value = parameterMSB},
{channel = channel, type = CONTROL_CHANGE, controllerNumber = 6, value = valueMSB},
{channel = channel, type = CONTROL_CHANGE, controllerNumber = 38, value = valueLSB}
}
for i, msg in ipairs(messages) do
midi.sendMessage(port, msg)
end
end
_G.midi.sendNrpn = mySendNrpn
I did that before, but it’s a lot of work if first the preset is made and only afterwards you find out the default NRPN for that particalur preset isn’t quite what you need.
I have fixed the sendNrpn function. The fix will be released in the upcoming release. The issue was caused by the optional interface parameter that was not included in your call. The fix covers both calling the function with and without the optional parameter.
regarding the function overriding, you can do that like this:
function midi.sendNrpn(port, channel, parameter, value)
print("sendNrpn")
end
midi.sendNrpn(1, 7, 6, 2)
It works for any function. Any standard function can be overridden by redefining it in the global context.