Need lua help

I am struggling and need some help i think.
First i am struggling with programming logic :joy:
Then I need 3 controls .
I need a “sync/free” button that will switch position of a “quantized” control(fader) and a “time” control(fader)
“sync/free” = pad 1
“time” = Fader 1 (7bit)
“quantized” = Fader 2 (7bit)

Then pad1 is slot 1 >id 1
fader 1 is slot 2 >id 2
fader 2 is slot 3 >id 3

pad1 is a CC and his value is 0 to 127
when pad1 value is 0 then the fader 1 is shown and the fader 2 is hidden
and the fader 1 position is slot 2 and the fader 2 position is slot 3

when pad 1 value is 127 the fader 2 is shown, the fader 1 is hidden
and the fader 2 position is slot 2 and the fader 1 position is slot 3

How to do that !
i write thing is move other things but i can’t figure out how to writte things correctly
I figured out with the hideshow stuff thanks to blinker script and “:isVisible()”
i figured out how to move with the setBounds() function and some other scripts
i can’t figure out how to get the pad1 value . i tried with

local message = valueObject:getMessage (1)
Sync = message:getValue ()
print (.. "val : ".. Sync)

And it does not print the value…

And i can’t figure out how to make a correct structure of all this :joy:
Is someone can help me with a simple example ?
thanks !

ok . I managed to find out … thanks to @NewIgnis script “selectIt” . that was the last peace…

ArpRateTimeQt = controls.get (152)
function selectIt(ValueObject, value)
local mes = ValueObject:getMessage ()
mesValue = mes:getValue ()
print ("message value: " ..mesValue)
swap()
end

function swap()
   if (mesValue > 100) then
       moveDown()
   else
       moveUp()
   end
end

function moveDown()
ArpRateTimeQt:setBounds ({ 170, 220, 146, 56 })
bounds = ArpRateTimeQt:getBounds ()
end

function moveUp()
ArpRateTimeQt:setBounds ({ 170, 128, 146, 56 })
bounds = ArpRateTimeQt:getBounds ()
end

But…It seems it does not do “really” what i want to . because the switched fader would need to switch their id ? to get the control with the knobs ? the real knobs i mean…and it does not… ? (i suppose ? should i try further ?) :sweat_smile:

Abbes, tell us more about the two faders:

  • what type should they be? Cc? Nrpn? Sysex?…
  • what range do they have?
  • must they have the same parameter number or a different one?
  • should they work in both ways (changing it on the controlled device should or should not be reflected on the Electra One)?

Hello and thanks for your answer NewIgnis !
there is nothing fancy there .
Just two faders that will have a CC controlling 2 knobs on ableton .
Arpeggiator
thoses 2 knobs are for the ‘rate’ knob on the arppegiator
When “Sync” is selected (like in this example) , the rate knob is quantized with the daw clock .
It is the Fader 2 on my E1 template.
When “sync” is deselected the “rate” becomes “free” his value is then ms
and it is the Fader 1 on my E1
the ‘free’ and ‘quantized’ state are two differents parameters.
On Ableton the CC are arbitrary. You assign what you want where you want .
Say then ‘Quantized’ Rate is CC2 and ‘free’ rate is CC3 .
the ‘sync’ button is CC1
All are on ch1.

  • what range do they have?
    all have range value from 0 to 127 (7Bits)
  • must they have the same parameter number or a different one?
    They all are independant and have their own parameters
  • should they work in both ways (changing it on the controlled device should or should not be reflected on the Electra One)?
    Everything should be real time and bidirectionnal. , yes :slight_smile:

Behavior on Ableton :
When sync is ON , the “quantized” ‘rate’ knob is shown
When sync is OFF, the "quantized ‘rate’ knob disappear, The “free” ‘rate’ knob appear on the same place and …that’s all :slight_smile:

Behavior on E1 :


Pad1 is ‘Sync’ and have CC1 , with value from 0 to 127
Fader 2 is ‘Time’ with quantized parameters and have CC3 with value from 0 to 127
Fader 1 is 'Time" with free parameters and have CC2 with value from 0 to 127

When ‘Sync’ is on (Value 127) the fader on his right is quandtized time . It is Fader 2
When ‘Sync’ is off (value 0) the fader on his right should be ‘free’ and have time in ms . It is Fader 1

Then the scipt above/under works for moving Fader 2 behind the “morph >1” one in blue just under when the ‘sync’ is off (yes it hides it ! no need to use hide/show script then !!! …for now. i didn’ experiment enough to see if it works flowesly)
and replace it at the same place as the picture when sync is on
That’s all i think . if i missed something tell me :wink:

My goal is to do the same think with Fader 1 but in opposition to Fader 2 off course.
But i thought “all this thing is cool but… if the ‘fader2’ is controlled by knob 2 on the E1 (physical knob of the device i mean) when ‘sync’ is on …how can i control ‘Fader1’ with the same knob 2 on the E1 when Sync is off…and make that ‘Fader1’ and ‘Fader2’ does not interfer their values…”
“is it possible to switch ID ?..how can i select my fader one and 2 then with dynamics ID???..”…
then :firecracker: :exploding_head:
:joy:

Ok i discovered the " :setPot (controlSet, pot)"
This E1 is really :cupid: :heart_eyes:
…is it possible to have a pot_0 or a null value for the pot ?
then i will be shure that when i move the pot_2 i will not move the Fader 1 and 2 . Just the one i want…
I will experiment it later .
Have a nice day all ! :slight_smile:

as inspiration have a look at the second and third page of my Pulse 2 preset…
https://app.electra.one/preset/4GNY0IWOBbgcUh8ZJeJ5

There are 4 controllers in the lower left corner:
image

The 2 lowest controllers are always hidden, and can have different value ranges, overlay lists and parameter numbers.
Depending on the chosen shape (the first 5 are unsynced lfo shapes, the next 5 are synced ones), one of these speed controls is copied in the upper left slot, and shown. This is done with lua using a function, called ‘moveSpeedCtl’. Notice I’m moving the controls on two different pages at once, as the same control is on both pages simultaneously.
The variable shownSpeed you won’t need it, if the controlling control would be a pad instead of a selection list as in my case.

function moveSpeedCtl(valueObject,value) ---- moves tempo controls to change overlay
if value >4 and shownSpeed==1 then
shownSpeed =4
for i = 0,1 do
control = controls.get (61+i36)
control:setSlot (31)
control:setVisible (false)
control = controls.get (68+i
36)
control:setSlot (25)
end
elseif value <5 and shownSpeed==4 then
shownSpeed =1
for i = 0,1 do
control = controls.get (68+i36)
control:setSlot (32)
control:setVisible (false)
control = controls.get (61+i
36)
control:setSlot (25)
end
end
end

1 Like

Oh !! Thanks !!! I will look at that as soon as i can !
Thank you so mutch for your help !
:grin:

1 Like

Hellooooo ! :wink:
I made something that worked but… it’s making the E1 bug …
then i deleted everything and i just put the the 2 parameters visible as normal parameters and no swap, no hiding . nothing :joy: but simplicity
but that was a good “try to make something with lua”
here is the code :

------function to get midi Value from the Sync button

function selectIt(ValueObject, value)
local mes = ValueObject:getMessage ()
mesValue = mes:getValue ()
print ("message value: " ..mesValue)
swap()
end
---position faders 

ArpRateTimeQt:setBounds ({ 170, 304, 146, 56 })
ArpRateTimeFree:setBounds({ 170, 128, 146, 56 })

---Assigning group and pot (and the E1 bug :) )

controlA = controls.get (152)
controlA:setPot (CONTROL_SET_2, POT_7)
controlB = controls.get (163)
controlB:setPot (CONTROL_SET_1, POT_8)


------Function to swap pos of a fader depending the "sync" button value

function swap()
   if (mesValue > 100) then
       moveDown()
   else
       moveUp()
   end
end

---Hide the button behind the'morph>5' :)

function moveDown()
ArpRateTimeQt:setBounds ({ 170, 304, 146, 56 })
ArpRateTimeFree:setBounds({ 170, 128, 146, 56 })
controlA = controls.get (152)
controlA:setPot (CONTROL_SET_2, POT_7)
controlB = controls.get (163)
controlB:setPot (CONTROL_SET_1, POT_8)
end

function moveUp()
ArpRateTimeQt:setBounds ({ 170, 128, 146, 56 })
ArpRateTimeFree:setBounds ({ 170, 304, 146, 56 })
controlA = controls.get (152)
controlA:setPot (CONTROL_SET_1, POT_8)
controlB = controls.get (163)
controlB:setPot (CONTROL_SET_2, POT_7)
end

This is the part that make the E1 bug when sending the code to it .

---Assigning group and pot (and the E1 bug :) )

controlA = controls.get (152)
controlA:setPot (CONTROL_SET_2, POT_7)
controlB = controls.get (163)
controlB:setPot (CONTROL_SET_1, POT_8)

I suppose that it’s because the control with id 163 is initialy set to SET_2, POT_7
and when i ask to set the control with id 152 to Set_2, POT_7… that is 2 controls on the same pot … and :exploding_head: …then i thought …“and with a not alocated pot on a group?” like a third free slot that can make a buffer for the swap …and i said…“and if i do nothing ?”…that was the solution :joy: ! it works natively great even if it’s less elegant :slight_smile: :blush: . It’s totaly enough for me !