# Need lua help

**URL:** <https://forum.electra.one/t/need-lua-help/1649>\
**Category:** General discussion\
**Created:** [August 14, 2022, 9:07pm UTC](https://forum.electra.one/t/need-lua-help/1649 "2022-08-14T21:07:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abbes](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/abbes/32/989_2.png) [@Abbes](https://forum.electra.one/u/Abbes)\
**Post date:** [August 14, 2022, 9:07pm UTC](https://forum.electra.one/t/need-lua-help/1649/1 "2022-08-14T21:07:08Z")

</div>

I am struggling and need some help i think.  
First i am struggling with programming logic 😂  
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

```auto
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 😂  
Is someone can help me with a simple example ?  
thanks !

---

<div class="post-metadata">

**Author:** ![Abbes](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/abbes/32/989_2.png) [@Abbes](https://forum.electra.one/u/Abbes)\
**Post date:** [August 14, 2022, 10:05pm UTC](https://forum.electra.one/t/need-lua-help/1649/2 "2022-08-14T22:05:49Z")

</div>

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

```auto
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 ?) 😅

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [August 15, 2022, 7:26am UTC](https://forum.electra.one/t/need-lua-help/1649/3 "2022-08-15T07:26:23Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![Abbes](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/abbes/32/989_2.png) [@Abbes](https://forum.electra.one/u/Abbes)\
**Post date:** [August 15, 2022, 10:04am UTC](https://forum.electra.one/t/need-lua-help/1649/4 "2022-08-15T10:04:08Z")

</div>

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](https://europe1.discourse-cdn.com/flex017/uploads/electraone/original/2X/b/bd12c0fdfe8354e5a94a6c7698bd9be2893fb9d0.png)  
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 🙂

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 🙂

Behavior on E1 :

 ![E1 arp param](https://europe1.discourse-cdn.com/flex017/uploads/electraone/original/2X/8/808104fc1d4e0442713cbd9ba4f600d10715aac5.jpeg)  
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 😉

> [@Abbes](#):
>
> ```auto
> ArpRateTimeQt = controls.get (152)
> function selectIt(ValueObject, value)
> local mes = ValueObject:getMessage ()
> mesValue = mes:getValue ()
> print ("message value: " ..mesValue)
> swap()
> end
> 
> function swap()
> 
> ```

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 🧨 🤯  
😂

---

<div class="post-metadata">

**Author:** ![Abbes](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/abbes/32/989_2.png) [@Abbes](https://forum.electra.one/u/Abbes)\
**Post date:** [August 15, 2022, 10:39am UTC](https://forum.electra.one/t/need-lua-help/1649/5 "2022-08-15T10:39:09Z")

</div>

Ok i discovered the " **:setPot (controlSet, pot)**"  
This E1 is really 💘 😍  
…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 ! 🙂

---

<div class="post-metadata">

**Author:** ![NewIgnis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/newignis/32/767_2.png) [@NewIgnis](https://forum.electra.one/u/NewIgnis)\
**Post date:** [August 15, 2022, 10:48am UTC](https://forum.electra.one/t/need-lua-help/1649/6 "2022-08-15T10:48:24Z")

</div>

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

There are 4 controllers in the lower left corner:  
 ![image](https://europe1.discourse-cdn.com/flex017/uploads/electraone/original/2X/2/2c20177eba32e021f4d5598718bc403516273b67.png)

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+i_36)  
> 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+i_36)  
> control:setSlot (32)  
> control:setVisible (false)  
> control = controls.get (61+i_36)  
> control:setSlot (25)  
> end  
> end  
> end

---

<div class="post-metadata">

**Author:** ![Abbes](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/abbes/32/989_2.png) [@Abbes](https://forum.electra.one/u/Abbes)\
**Post date:** [August 15, 2022, 10:55am UTC](https://forum.electra.one/t/need-lua-help/1649/7 "2022-08-15T10:55:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Abbes](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.electra.one/abbes/32/989_2.png) [@Abbes](https://forum.electra.one/u/Abbes)\
**Post date:** [August 24, 2022, 8:38am UTC](https://forum.electra.one/t/need-lua-help/1649/8 "2022-08-24T08:38:32Z")

</div>

Hellooooo ! 😉  
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 😂 but simplicity  
but that was a good “try to make something with lua”  
here is the code :

```auto
------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 .

```auto
---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 🤯 …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 😂 ! it works natively great even if it’s less elegant 🙂 😊 . It’s totaly enough for me !
