Home › Forums › General › Programming › Storing received sysex dump as memoryblock then process › Reply To: Storing received sysex dump as memoryblock then process
June 26, 2020 at 4:35 am
#118901
Hi Damien,
I feel your pain with regards to the edit three times and strike you’re out. If that happens hit the back button on your browser, cut and paste and wait a few hours to re-post. Not familiar with WordPress, but the admins surely could fix that somehow?
The problem with the code above is you are doing a getSize() on the function name. Also you declare a midiMessage=MemoryBlock() – that would zero out the midiMessage passed into the function.
I would initialise total outside the loop just to be safe and also I recommend keeping everything local if possible.
midiMessageReceived = function(midiMessage)
local midiMessageRawSize = midiMessage:getSize()
local MessageType = midiMessage:getData():getByte(5)
if midiMessageRawSize == 334 and MessageType == 0x25 then -- determine if the message is Edit Buffer Type hex25 with size 334bytes
local t,total={},0
--local newMidiMessage = MemoryBlock() don't need this
for i=9,midiMessageRawSize-2,2 do
--assert(i < midiMessage:getSize()) -- For debugging only
local msb = bit.lshift(midiMessage:getData():getByte(i),4)
local lsb = midiMessage:getData():getByte(i+1)
total = msb+lsb -- console(String(string.format("[%d] = %.2X",i,total)))
table.insert(t,total)
end
EditBufferMessage = MemoryBlock()
EditBufferMessage:createFromTable(t)
--console(String(EditBufferMessage:toHexString(1)))
--panel:getLabel("Debug"):setText(EditBufferMessage:toHexString(1))
ActiveUnitDecode(midiMessage)
BufferPstNameDecode(EditBufferMessage)
BypassStatusDecode(EditBufferMessage)
UAAlgoLblDecode(EditBufferMessage)
UBAlgoLblDecode(EditBufferMessage)
UCAlgoLblDecode(EditBufferMessage)
UDAlgoLblDecode(EditBufferMessage)
ConfigSrcTypeDecode(EditBufferMessage)
UAAlgoDecode(EditBufferMessage)
UBAlgoDecode(EditBufferMessage)
UCAlgoDecode(EditBufferMessage)
UDAlgoDecode(EditBufferMessage)
panel:getModulatorByName("ViButComEdit"):getComponent():setValue(1, true)
end
end