Home › Forums › General › Programming › SOLVED: What’s wrong in my function › Reply To: SOLVED: What’s wrong in my function
Hi,
dec2hex is indeed returning a string si it will not work in your first example.
--
-- Returns HEX representation of a DECimal number
--
dec2hex = function(num)
local hexstr = '0123456789ABCDEF'
local s = ''
while num > 0 do
local mod = math.fmod(num, 16)
s = string.sub(hexstr, mod+1, mod+1) .. s
num = math.floor(num / 16)
end
if s == '' then s = '0' end
return s
end
Some remarks on very good dnaldoog’s answer:
– it is a good habit to declare all your modulators at once in some method that you call at panel load then that you refer to the modulators through the variables instead of redoing panel:getModulatorByName() all the time; To identify my modulators, I’m usually using modXXX
So: modProgram = panel:getModulatorByName(“Program”)
– you can directly put the getModulatorValue() in the message like
pnr = CtrlrMidiMessage({0xf0, 0x01, 0x00, modProgram:getModulatorValue(), 0xf7})
So you spare one variable assignment
– Using his second proposal allows you to use the dec2hex function:
local sysexString = “f0 43 10 5c 10 “..dec2hex(modProgram:getModulatorValue())..” f7″
But this is clearly less straightforward that what I wrote in the bullet point just before
Have fun!