<<SOLVED>> Pass Controls Function to Another Controls Function

Hello!
I an trying to pass Control A’ Function to Control B’ so that I may use it to key off of when setting the controllers “Message” CC Value.

01_Button A (list)+ B (fader)
001

02_Button A - Settings (List)

03_Button A - List

04_Button B - Settings (Fader)

  1. LUA Script Function A + Function B
    NOTE - values 0-9 are the outputs of function A
-- Function to get a value and return it
function getValue(valueObject, value)
    -- Debug: Print the inputs to getValue
    print("getValue called with value:", value)
    return value  -- Return the value passed to it
end

-- Function to change a value based on a condition
function changeValue(valueObject, value)
    -- Get the value using getValue
    local valueFromGet = getValue(valueObject, value)

    -- Debug: Print the value obtained from getValue
    print("Value obtained from getValue:", valueFromGet)

    local message = valueObject:getMessage()
    local currentParameter = message:getParameterNumber()

    -- Debug: Print the current parameter number
    print("Current parameter number:", currentParameter)

    -- Determine the new parameter number using if-else
    local newParameter

    if valueFromGet == 0 then
        newParameter = 3
    elseif valueFromGet == 1 then
        newParameter = 9
    elseif valueFromGet == 2 then
        newParameter = 14
    elseif valueFromGet == 3 then
        newParameter = 15
    elseif valueFromGet == 4 then
        newParameter = 20
    elseif valueFromGet == 5 then
        newParameter = 21
    elseif valueFromGet == 6 then
        newParameter = 22
    elseif valueFromGet == 7 then
        newParameter = 23
    elseif valueFromGet == 8 then
        newParameter = 24
    elseif valueFromGet == 9 then
        newParameter = 25
    else
        -- Handle unexpected values
        print("Unexpected valueFromGet:", valueFromGet)
        return  -- Exit the function if the value is not in the expected range
    end

    -- Set the new parameter if valid
    message:setParameterNumber(newParameter)
    -- Debug: Print the parameter number that will be set
    print("Setting parameter number to:", newParameter)
end

NOTE: - Each Function, when not trying to pass A into B - seem to work independently.
However, once I pass A into B – The value of B changes the CC Value and overwrites the A function.

I am very new to lua so this once has me scratching my head a bit.

The Goal:
I will have 4 CC Faders that are there to control my “RealTime Cotrols” on the E-mu Proteus 2
Everything else I have working using SysEx but I want these controls to record the automation into the MPC and also the ability to change up the CC Values within a small range for a little flexability to the E-mu Preset when shared to the public.

Your function getValue does not read a value, it just prints the value you offer to the function, and then returns the very same value. I gues that is not your intention?

I believe you do not need the getValue function at all.

In the changeValue function though, you first needs to retrieve the messageValue of Virtual parameter 3 (so you do not get values 0…9 but you get values 3…25, (youi know how to do this?) add this to the value of the fader, and use that sum to set it as new value on a parameter of your choosing via parameterMap.set(deviceId, parameterType, parameterNumber, midiValue)

1 Like

@NewIgnis - Thank you.
Admittedly, as I am new to any coding and the E1, I was struggling a bit with parameter mapping and also getting at an overlays table of stored values. So, I am just using the getValue function to key off of in my - if/then statement - as that is what makes sense to me currently with very low coding knowledge. I am starting to see the onion peeling back though and will eventually get more advanced.

While, @oldgearguy helped along with my current code to “set a Global” and the feature is now working. I will also give your direction a try out as well and see where I end up. It is always good to learn from those who know!!!

Here is the update script that is now working –
NOTE - I did change Button A “Type” to “None” so it would return 0 instead of -1 at the start of the prest.

myCCvalue = 0 -- set a global value 

-- Function to get a value and return it
function getValue(valueObject, value)
    
    myCCvalue = value
    
    return value  -- Return the value passed to it
end


-- Function to change a value based on a condition
function changeValue(valueObject, value)

    local message = valueObject:getMessage()
    local currentParameter = message:getParameterNumber()

    -- Debug: Print the current parameter number
    print("Current parameter number:", currentParameter)

    -- Determine the new parameter number using if-else
    local newParameter

    if  myCCvalue == 0 then
        newParameter = 3
    elseif  myCCvalue == 1 then
        newParameter = 9
    elseif myCCvalue == 2 then
        newParameter = 14
    elseif  myCCvalue == 3 then
        newParameter = 15
    elseif  myCCvalue == 4 then
        newParameter = 20
    elseif myCCvalue == 5 then
        newParameter = 21
    elseif  myCCvalue == 6 then
        newParameter = 22
    elseif  myCCvalue == 7 then
        newParameter = 23
    elseif myCCvalue == 8 then
        newParameter = 24
    elseif  myCCvalue == 9 then
        newParameter = 25
    else
        -- Handle unexpected values
        print("Unexpected myCCvalue:", myCCvalue)
        return  -- Exit the function if the value is not in the expected range
    end

    -- Set the new parameter if valid
    message:setParameterNumber(newParameter)
    -- Debug: Print the parameter number that will be set
    print("Setting parameter number to:", newParameter)
end
1 Like

Final Script Being Used:

-- Function to get a value and return it
function getValue(valueObject, value)
 -- USE THE REAL CONTROL ID HERE from the B fader not the A LIST control
   local ctl = controls.get(3)
   local msgObj = ctl:getValue("value"):getMessage()

   local newParameter = -1

   if value <= 0 then
      newParameter = 3
   elseif value == 1 then
      newParameter = 9
   elseif value == 2 then
      newParameter = 14
   elseif value == 3 then
      newParameter = 15
   elseif value == 4 then
      newParameter = 20
   elseif value == 5 then
      newParameter = 21
   elseif value == 6 then
      newParameter = 22
   elseif value == 7 then
      newParameter = 23
   elseif value == 8 then
      newParameter = 24
   elseif value == 9 then
      newParameter = 25
   else
      -- Handle unexpected values
      print("Unexpected value:" .. value .. " not changing the CC")
   end

   -- check to make sure we have a legit ID, assign it to the control
   if (newParameter ~= -1) then
      msgObj:setParameterNumber(newParameter)
   end
end

1 Like