Maybe this is known to everyone, but then, maybe it isn’t.
A control in my Kronos PolysixEx synth, Drum Track Shift (value ranges from -24 to +24), needs a very special value. The value consists of 3 bytes, and doesn’t follow a very logical pattern. Using Midi Monitor in the Preset Editor, the Kronos generated these values:
Kronos value = SysEx bytes
-24 = 7Fh 7Fh 68h
.
-1 = 7Fh 7Fh 7Fh
0 = 00h 00h 00h
+1 = 00h 00h 01h
.
+24 = 00h 00h 18h
So the first two SysEx value bytes are changed depending on postive or negative Kronos values. Furthermore, the third byte is not a very logical range:
-24 = 104
-1 = 127
0=0
1 = 1
24 = 24
The solution was to create Lua function, leveraging midi.sysexsend, but then I had to concetanate different parts of the complete SysEx message. Online I found a solution called table_fuse and it did the job perfectly:
– Korg Kronos
SysExDeviceHeader = {0x42, 0x30, 0x68, 0x6E}
local table_fuse = function (…)
– This function, created by zero1nx on Stackoverflow.com, concatenates two tables
– or better put in the context of SysEx, two arrays of Hex numbers
local result = {}
local i = 1
for _, obj in next, {...} do
if type(obj) ~= "table" then
result[i] = obj
i = i + 1
else
for k, v in next, obj do
if type(k) ~= "number" then
result[k] = v
else
result[i] = v
i = i + 1
end
end
end
end
return result
end
function DrmPttrnShftValue(valueObject, value)
– this function takes the input of the encoder and recalcules the correct value accepted by the Kronos DrumPattern Shift paramater
– (-24 = 0x7F 0x7F 0x68, -1 = 0x7F 0x7F 0x7F, 0 = 0x00 0x00 0x00, +1 = 0x00 0x00 0x01, +24 = 0x00 0x00 0x18)
– value range from the encoder is -24 to 24
– The Sign Mode needs to be something else than “Unsigned”
local SysExTargetID = {0x00, 0x00, 0x00, 0x09, 0x00}
local NegativeNumberPrefix = {0x7F, 0x7F}
local PositiveNumberPrefix = {0x00, 0x00}
local ValuePrefix = {}
local CalcedValue = {}
print("ReceivedValue: " .. string.format("%i", value))
if value >= 0 then
ValuePrefix = PositiveNumberPrefix
CalcedValue = value
else
ValuePrefix = NegativeNumberPrefix
CalcedValue = (value + 128)
end
print("CalcedValue: " .. string.format("%i", CalcedValue) .. " = " .. string.format("%x", CalcedValue) .. "h")
midi.sendSysex (PORT_1 , table_fuse(SysExDeviceHeader,SysExTargetID, ValuePrefix,CalcedValue) )
end