Control: setName(), setColor() bug?

I have code like this:

   window.stop()
   for i=0,6 do
      btnBit = (panelBtns >> i) & 0x01
      toggles[FVAL][i] = (btnBit * 127)
      if (toggles[FVAL][i] == 127) then
         toggleText = toggles[NAME][i] .. " ON"
         btnColor = BRIGHTGREEN
      else
         toggleText = toggles[NAME][i] .. " OFF"
         btnColor = WHITE
      end

      toggles[CNTL][i]:setColor(btnColor)
      toggles[CNTL][i]:setName(toggleText)
   end
   window.resume()

FVAL, NAME, CNTL are #defines used for the 2-dimensional array indexing.
CNTL[n] holds the controlId for various on screen momentary pads.

When this code runs, it always sets the color properly but the name is NEVER set.
This code is in a function being called at the end of patch.onResponse()

I tried to replicate the issue:

local panelBtns = 0xAA
local BRIGHTGREEN = 0x00ff00

local CNTL = 1
local FVAL = 2
local NAME = 3

local toggles = {
    [CNTL] = {
        [0] = controls.get(1),
        [1] = controls.get(2),
        [2] = controls.get(3),
        [3] = controls.get(4),
        [4] = controls.get(5),
        [5] = controls.get(6),
        [6] = controls.get(7),
    },
    [FVAL] = {
        [0] = 0,
        [1] = 0,
        [2] = 0,
        [3] = 0,
        [4] = 0,
        [5] = 0,
        [6] = 0,    
    },
    [NAME] = {
        [0] = "A",
        [1] = "B",
        [2] = "C",
        [3] = "D",
        [4] = "E",
        [5] = "F",
        [6] = "G",
    }
}

function patch.onResponse()
    window.stop()
    for i=0,6 do
        btnBit = (panelBtns >> i) & 0x01
        toggles[FVAL][i] = (btnBit * 127)
        if (toggles[FVAL][i] == 127) then
            toggleText = toggles[NAME][i] .. " ON"
            btnColor = BRIGHTGREEN
        else
            toggleText = toggles[NAME][i] .. " OFF"
            btnColor = WHITE
        end

        toggles[CNTL][i]:setColor(btnColor)
        toggles[CNTL][i]:setName(toggleText)
    end
    window.resume()
end

My pads have their colour and text updated ok.

This is my preset: Electra One App

Can you try to run it? patch response: F0h 00h 10h 20h 30h F7h

Martin - Thanks for the quick check.

Looking over my code, it seems to be some timing conflict between one place where I get some values and the calls to the format() functions for each of the controls.

It appears the format() function is using values from the parameterMap before I have them properly set, so the name gets overwritten with the default.

I am restructuring the sequencing of my operations to clean that up.

BTW - I didn’t at first think it was an OS problem, but you know, my code is always correct, so what other option was there? :slight_smile:

thanks again for the sanity check :grinning:
lol

2 Likes