Some difficulty with accessing messge and value

I’ve been trying to access a control during a midi callback function. I need to find the parameter id number so I can use parameterMap.set (). I tried using the following which didn’t work:

local control = controls.get(targetControlId)
local message = control:getMessage()
local paramID = message:getParameterNumber()

I then used the following which did work but it is confusing.

local control = controls.get(targetControlId)   
local value = control:getValue():getValue()
parameterNumber = control:getValue():getMessage():getParameterNumber()

I then refactored the code to this:

local control = controls.get(targetControlId)
local valueObject = control:getValue() -- I want to better understand this line
local message = valueObject:getMessage()
local paramID = message:getParameterNumber()
parameterMap.set(1, PT_VIRTUAL, paramID, fourteenBitValue)

I think I am misunderstanding how json works and I often get confused by what I need to get and how best to get it. I know a common routine to acces the value of the control is something like this and I feel this all makes sense.

function process_active_fx(valueObject, value)
    local control = valueObject:getControl()
    local onVal = valueObject:getMessage():getValue()
  
   local onVal = 6 - value
   parameterMap.set (deviceId, PT_CC7, 126,onVal );
end

However that changes when you need to use control = controls.get(id) because there is no value object. I feel that the language used on the call to valueObject = control:getValue() should be changed to valueObject = control:getValueObject() The reason I think this makes sense is that there are other calls made to getValue where you are specifically getting a value rather than the object. I’m sorry if I am being confusing. Really all I am looking for is a straightforward way to get and set things and I am simply sharing my challenges in accessing the parameterNumber programmatically in order to use parameterMap.set(). I’ll take any insight. Maybe there is a way to make it easier for users or explain the methods on how to access the various json levels. That’s not to say I am complaining because I really love this device and all the capabilities it offers. I think most of my difficulties come from a lack of understanding how these calls relate to json.

here’s how in a function you find back the parameterNumber:

function waveChange(valueObject, value)
  local parameter = valueObject:getMessage ():getParameterNumber ()
...

but you are talking about a MIDI function call back. Can’t you just number the parameter according to the MIDI CC in the call back? Then no lookups are needed

I understand how to extract the parameter id and it’s definitely good to include that for reference so thanks. I managed to get access to the parameterid value in the midi callback as shown above but I’m just pointing out the challenges in doing so and asking if there is a better way. You suggested to keep the values the same and It definitely makes it easier if the id and parameterid are always kept the same but there are cases where you might not want that to be the case programmatically. I think my question is if using the word value is the best language on on this particular call and if there might be a more pointed descriptor because in this case you need to access the valueObject and then message and then parameterId. Sorry this isn’t a big problem or anything like that rather I’m just sharing that this operation was more challenging than expected and when I read back over the lines of code that actually worked they aren’t totally clear. This is more about readability if that makes sense or it’s probably just my misunderstanding of how value is used to extract many elements and that it’s not just the value of the control. I’m planning to reread over the manual to better understand the hierarchy in the json. Thanks

Probably I,m misreading. Can you state again what it is you trying to solve? I thought it was: giving a MIDI callback, what is its parameter?

Indeed sometimes you can’t relate E1 parameters and MIDI parameters one-to-one, but there is always context (port and channel from MIDI , the exact Lfo, Osc or Timbre from within E1, etc), to make a relationship formula.

So far (on synths at least) that hasn’t been an issue.