Reply To: 4 separate on/off switches on same parameter address?

Home Forums General Programming 4 separate on/off switches on same parameter address? Reply To: 4 separate on/off switches on same parameter address?

#73000
dnaldoog
Participant
  • Topics: 4
  • Replies: 480
  • Total: 484
  • ★★

Hi there Human Fly!

I would create an array of the buttons, then multiply by 1,2,4, or 8 through a loop adding each button state on/off. They will add up to anything from 0-15. Then just send that value in the sysex.

fourButtons = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)
    a={"P1","P2","P3","P4"} --array of buttons
    m={1,2,4,8} -- multiplier
    sumOfa=0 --variable to hold multiplied values
    for i,v in ipairs(a) do
        local val=panel:getModulatorByName(v):getModulatorValue()
        sumOfa=sumOfa+val*m[ i ]
        --add up the values 
    end --loop
    console(String(sumOfa))
    --You then don't even need to do an if // else - just include the sum in the sysex message
    cs=myCheckSumFunction(0x12, 0x04, 0x00, 0x0c, sumOfa)
    panel:sendMidiMessageNow(CtrlrMidiMessage({0xf0, 0x41, 0x10, 0x16, 0x12, 0x04, 0x00, 0x0c, sumOfa , cs , 0xf7}))
end --function
---------------------------------------------------------
myCheckSumFunction=function(...)
    local total=0
    local result=0
    for i,v in ipairs(arg) do
        total=total+v --addup all the numbers
        if(total > 127) then
            total=total - 128
        end
    end

    result=128-total
if result== 128 then result = 0 end -- If the result is 128 then substitute a value of 0
    return result

end --function
---------------------------------------------------------

NOTE: the attached panel has a small error “return result,10” in myCheckSumFunction() (but still works – should be just “return result”

Attachments:
You must be logged in to view attached files.
Ctrlr