EN16 - Managing a two layer system based on rows

Hi!,

I’m trying to manage a 2 layer system with default preset values for some of the knobs and I’m finding a strange behavior in one of my functions.

Each knob have some self variables called val1 val2 that serve as storage cache for the two layers.

I have two functions in system setup that I reuse extensively. They are as follows:

function UpdateValuesPress(self)
  local base = self:element_index()
  for i = base + 4, base + 12, 4 do
    print("e" .. i .. " - " .. "v2: " .. tostring(element[i].val2))
    element[i].val1 = element[i]:encoder_value()
    if element[i].val2 ~= nil then
      element[i]:encoder_value(element[i].val2)
      print(element[i]:encoder_value())
    end
  end
end
function UpdateValuesRelease(self)
  local base = self:element_index()
  for i = base + 4, base + 12, 4 do
    element[i].val2 = element[i]:encoder_value()
    if element[i].val1 ~= nil then
      element[i]:encoder_value(element[i].val1)
    end
  end
end

The weird behavior is at this chunk in UpdateValuesPress:

if element[i].val2 ~= nil then
      element[i]:encoder_value(element[i].val2)
      print(element[i]:encoder_value())

Even though I’m setting val2 with a preset value to be used at setup of the encoder, it seems that “element[i]:encoder_value(element[i].val2)” is not executed or effective on the first time that I press the button to change layers, only when val2 is stored on the second layer when the encoder is moved and after release.

For some reason even though it is set in the setup val2 seems to be zero the first time the function runs.

Capture of val2 and encoder value after 4 pushes on the encoder controlling the layer switch. (yes val2 for e4 should be nil at start)

image

The curious think is that as soon as I rotate the encoder in the controller layer that is stored in val2, val2 gets the value of the corresponding encoder, and when switching back and forth the encoder is correctly updated with the value stored in val2.

It seems that only the initial state of val2 set in the encoder setup is ignored.

Does anyone know what could I be missing?

I hope that I’m descriptive enough.

Profile shared here: grid-editor://?config-link=EBPm9mLpyle6QVLi3ljj

Thanks in advance.