Home › Forums › General › Programming › Getting Panel reflect Patch & Program Settings › Reply To: Getting Panel reflect Patch & Program Settings
Hi Baus,
First you would need to determine at the positions of the two 4bit bytes in the incoming MIDI message. Remember to count from F0
as zero.
These two bytes will be converted to a number, for example 0F 01
is converted to 1F
which in decimal is 31
as you know.
Create a function that processes the 148 byte MIDI message. You can filter out other incoming midi strings:
receiveMidiFromDevice = function(--[[ CtrlrMidiMessage --]] midi)
if midi:getSize()==148 then
updateModulators(midi) - only run function if incoming MIDI = 148
end
end
In that updateModulators()
function, create a hash table of all the modulator names you want to assign values to:
The key refers to the modulator name and the value to the position of the leading byte in the MIDI message.
local t={dial1=8,dial2=10,dial3=12}
In the function you pass :
local b1=m:getData():getByte(v)
local b2=m:getData():getByte(v+1)
..as two arguments to the 4 bit denibbilize function:
† It is possible to use getRange(t.dial1,2) and pass one argument to a function but we won’t go there
That function will return the value which you then assign to the modulator.
function combine4n(a, b) -- convert two 4 bit nibbles to a single integer
local m = bit.lshift(a, 4)
return m + b
end
In that updateModulators()
function, loop through the table to assign values to the modulators:
function updateModulators(m)
local t={dial1=8,dial2=10,dial3=12}
for k,v in pairs (t) do
local b1=m:getData():getByte(v)
local b2=m:getData():getByte(v+1)
local value=combine4n(b2,b1)
panel:getModulatorByName(k):getComponent():setValue(value,true)
end
end
*NOTE: it is possible that this may in turn cause the modulator to fire off a send MIDI message, but I haven’t addressed that issue here. Also the code panel:getModulatorByName(k)
can be assigned to a lua variable on start as previously discussed in another post.
See attached panel.
Regards,
JG
- This reply was modified 3 years, 6 months ago by dnaldoog. Reason: removed unnecessary variable
- This reply was modified 3 years, 6 months ago by dnaldoog. Reason: removed another unnecessary variable