Thanks a lot, I will definitely implement as you suggest.
How can I combine several lists?
No I think i create a list in a list for the remainingArrowBytes.
This doesnât work with midi.sendSysex.
I tried al sorts of things and got stuck on this.
â125310 error running function ârunFunctionâ: ctrlv2/p000.lua:82: bad argument #-1 to âsendSysexâ (number expected, got string)
downArrow=66
negativeArrowValue = 4
endCommand=07
if (negativeArrowValue < 5) and (negativeArrowValue > 0) then
print (negativeArrowValue, "Sending remaining bytes")
--remainingArrowBytes { for negativeArrowValue in.... add 1 downArrow }
remainingArrowBytes = {}
for i = 1,negativeArrowValue do table.insert(remainingArrowBytes,tonumber(downArrow))
end
print(table.concat(remainingArrowBytes,", "))
print("negativeArrowValue here we are, should send less then 5")
--125310 error running function 'runFunction': ctrlv2/p000.lua:82: bad argument #-1 to 'sendSysex' (number expected, got string)
--sysexMsg = {15, 1, 1, table.concat(remainingArrowBytes,", "), endCommand }
sysexMsg = {15, 1, 1, table.concat(remainingArrowBytes,", "), endCommand }
--midi.sendSysex(PORT_1, sysexMsg)
print(table.concat(sysexMsg,", "))
print(sysexMsg[4])
end
Still have to update the if, elseif, elseâŚ
With your suggestions and some updates I did I got:
With is I git the error
â125310 error running function ârunFunctionâ: ctrlv2/p000.lua:82: bad argument #-1 to âsendSysexâ (number expected, got string)
I think because I pass a list to a list⌠Any hints on how to do this will be great.
mirageDeviceId = 9
previousParameterNumber = nil
lastValue = {}
maxBytes = 5
upArrow= 14
downArrow = 15
parameterSelect = 12
valueSelect = 13
endCommand = 127
arrowValue = nil
mainWorkerCounterCalls = 0
---try this: lastValue = {}
--then near the top of mainWorker(), you can say:
--lastValue[currentParameterNumber] = message:getValue()
--and
--arrowValue = curValue - lastValue[currentParameterNumber]
--and at the bottom,
--lastValue[currentParameterNumber] = curValue
function mainWorker(ValueObject, Value)
mainWorkerCounterCalls = mainWorkerCounterCalls + 1
print("mainWorkerCounterCalls:" .. mainWorkerCounterCalls)
local message = ValueObject:getMessage()
local currentParameterNumber = message:getParameterNumber ()
local curValue = message:getValue ()
--lastValue[currentParameterNumber] = message:getValue()
--
if ( currentParameterNumber ~= previousParameterNumber ) then
previousParameterNumber = currentParameterNumber
--We store the parameter values as well only once per fresh call
--_G.lastValue = message:getValue ()
lastValue[currentParameterNumber] = message:getValue()
-- this always results in print("nothing to send") ?? FIX
--arrowValue = curValue - _G.lastValue
arrowValue = curValue - lastValue[currentParameterNumber]
print("we have parameterNumber: ", currentParameterNumber)
print("Lets check the lenght: ", string.len(currentParameterNumber))
if ( string.len(currentParameterNumber) < 2 ) then
print("string less the 2 in lenght")
byte1st = 0
byte2nd = string.sub(currentParameterNumber,1,1)
elseif ( string.len(currentParameterNumber) == 2 ) then
byte1st = string.sub(currentParameterNumber,1,1)
byte2nd = string.sub(currentParameterNumber,2,2)
else
print("[ERROR] string lenght out of range, must be between 0-99)")
end
parameterNumberPanel = { (byte1st ), (byte2nd .. ", ") }
print(parameterNumberPanel)
print(table.concat(parameterNumberPanel,", "))
sysexMsg = { 15, 1, 1, parameterSelect, byte1st, byte2nd, valueSelect, endCommand }
--global, used to send parameter select once, they are not the same so we send a parameter select message
--sysexMsg = {headerMsg, parameterSelect, table.concat(parameterNumberPanel,", "), valueSelect, endCommand}
midi.sendSysex(PORT_1, sysexMsg)
end
--
if ( currentParameterNumber == previousParameterNumber ) then
--arrowValue = curValue - _G.lastValue
arrowValue = curValue - lastValue[currentParameterNumber]
print ("arrowValue =", arrowValue)
if ( arrowValue <0 ) then
print ('arrowValue is a negative number, sending message')
-- for loop, for 5 bytes max
negativeArrowValue = (0 - arrowValue)
--arrowByte = _G.downArrow
exp1 = 0
exp2 = negativeArrowValue
print (negativeArrowValue, "Total down arrow bytes to send")
for var = exp1,exp2,maxBytes do
if ( negativeArrowValue < 5 ) and ( negativeArrowValue > 0) then
print (negativeArrowValue, "Sending remaining bytes")
--remainingArrowBytes { for negativeArrowValue in.... add 1 downArrow }
remainingArrowBytes = { }
for i = 1,negativeArrowValue do table.insert(remainingArrowBytes,tonumber(downArrow)) end
print(table.concat(remainingArrowBytes,", "))
print("negativeArrowValue here we are, should send less then 5")
--125310 error running function 'runFunction': ctrlv2/p000.lua:82: bad argument #-1 to 'sendSysex' (number expected, got string)
--sysexMsg = {15, 1, 1, table.concat(remainingArrowBytes,", "), endCommand }
sysexMsg = {15, 1, 1, endCommand }
midi.sendSysex(PORT_1, sysexMsg)
break
end
print("sending 5 arrowBytes,")
--we just send 5 bytes so adjust the counter
negativeArrowValue = arrowValue - 5
print(negativeArrowValue, "negativeArrowValue here we are sending 5")
--sysexMsg = {0x33, 0x00, 0x05, 0x05, 0x05, arrowValue}
-- just sending static 5 bytes
sysexMsg = { 15, 1, 1, downArrow, downArrow, downArrow, downArrow, downArrow, endCommand }
midi.sendSysex(PORT_1, sysexMsg)
end
elseif ( arrowValue >0) then
print ('arrowValue is a postive number, sending message')
--arrowByte = _G.upArrow
exp1 = 0
exp2 = arrowValue
print (arrowValue, "Total bytes to send")
for var = exp1,exp2,maxBytes do
if ( arrowValue < 5 ) and ( arrowValue > 0) then
print (arrowValue, "Sending remaining bytes")
--remainingArrowBytes { for negativeArrowValue in.... add 1 downArrow }
--tonumber()
remainingArrowBytes = { }
for i = 1,arrowValue do table.insert(remainingArrowBytes,tonumber(upArrow)) end
print(table.concat(remainingArrowBytes,", "))
--389482 error running function 'runFunction': ctrlv2/p000.lua:115: bad argument #-1 to 'sendSysex' (number expected, got string)
--sysexMsg = {15, 1, 1, table.concat(remainingArrowBytes,", "), endCommand }
sysexMsg = {15, 1, 1, endCommand }
midi.sendSysex(PORT_1, sysexMsg)
break
end
print("sending 5 arrowBytes,")
--we just send 5 bytes so adjust the counter
_G.arrowValue = arrowValue - 5
--sysexMsg = {0x33, 0x00, 0x05, 0x05, 0x05, arrowValue}
-- just sending static 5 bytes
sysexMsg = { 15, 1, 1, upArrow, upArrow, upArrow, upArrow, upArrow, endCommand }
midi.sendSysex(PORT_1, sysexMsg)
end
else
print("nothing to do")
end
--_G.lastValue = curValue
lastValue[currentParameterNumber] = curValue
end
end