Scripting simplification

This works but it's a bit janky. Can you suggest a more efficient way to do it? Use case is an 'erase' fader: Swipe the fader to activate Erase - but only when a track is armed. I'm sure there's a more elegant way to code this - or perhaps calling a script when the fader is swiped?

Side-issue: Fader 'spring' is normally reliable for me, but with this script it doesn't always 'reset'. Hence the 'manual reset' attempt at the end. Any ideas on this?

Thanks!

if (value >= 120 && @{Looper1ControlsFXrow1Arm}==1024) {
  set("Looper1Controlsaction_rowerase_panelErase", 127)
  set("Looper1Controlsaction_rowerase_panelErase", 0)
  } 
if (value >= 120 && @{Looper2ControlsFXrow1Arm}==1024) {
  set("Looper2Controlsaction_rowerase_panelErase", 127)
  set("Looper2Controlsaction_rowerase_panelErase", 0)
  } 
if (value >= 120 && @{Looper3ControlsFXrow1Arm}==1024) {
  set("Looper3Controlsaction_rowerase_panelErase", 127)
  set("Looper3Controlsaction_rowerase_panelErase", 0)
  } 
if (value >= 120 && @{Looper4ControlsFXrow1Arm}==1024) {
  set("Looper4Controlsaction_rowerase_panelErase", 127)
  set("Looper4Controlsaction_rowerase_panelErase", 0)
  } 
if (value >= 120 && @{Looper5ControlsFXrow1Arm}==1024) {
  set("Looper5Controlsaction_rowerase_panelErase", 127)
  set("Looper5Controlsaction_rowerase_panelErase", 0)
  } 
if (value >= 120 && @{Looper6ControlsFXrow1Arm}==1024) {
  set("Looper6Controlsaction_rowerase_panelErase", 127)
  set("Looper6Controlsaction_rowerase_panelErase", 0)
  } 

if (value >= 121) {
  set("@{this.id}", 0)
}

It's hard to fully understand the use case, but at least I can suggest the following:

  • don't use the @{} syntax in scripts, you can use the get() and getProp() functions instead.
  • set() accepts "this" as first argument.
  • you could use some kind of loop:
if (value >= 120) {
  for (var i = 1; i < 7; i++) {
    if (get("Looper" + i + "ControlsFxrow1Arm") == 1024) {
      var id = "Looper" + i + "Controlsaction_rowerase_panelErase"
      set(id, 127)
      set(id, 0)
    }
  }
} 

On the spring problem, it would help to have a minimal session file to reproduce the issue.

Oh wow - thanks for this - so elegant! Will see if it fixes the spring thing.

Works perfectly and no spring problem anymore too - awesome!