Switch press states (release, long press)

Hi, is there any way to implement different actions for different press states on a switch? I'd like to do different things on long press, release, double tap. (another way of asking this, is; is there any way to implement 'onTouch' on switches?)

Hi datalooper,

I couldn't get onTouch events on switches (but maybe I am missing something probably). However I could do a little radio button which returns its index and state, not sure if that helps like a start point?

switchTouch 1.02.json (5.3 KB)

edit: updated (1.02)

Cheers

Hmmm, I remember having some good reason for implementing my logic in switches and not matrix widgets, but good to know this can be done in a matrix of buttons....good to have a backup plan. Jean, any secret hacks to make touch state work on switches?

It looks like I'll be able to make it this work, but I can't figure out how to set the labels via an array received via OSC. If I try using p.label = OSC{"/something"}[$] I just get undefined. Is there some specific syntax?

1 Like

I normally like to have this on separate variables objects in the tree , so I can re-use them if needed over the whole project (like the BtnIdx variable). Just in the oscLabels variable, set your OSC address, haven't checked it myself tho. But if you are sending an array I guess it should. Updated the first reply with the file (1.02) Cheers

Thanks so much!

1 Like

In the spirit of not just taking, here's the script for the different press states:

JS{
  const p = {}
  const buttonsNum = 4
  const colors = Array(buttonsNum).fill("auto")
  const colorOn = "Yellow"
  colors[@{btnIdx}] = colorOn
  p.colorWidget = colors[$]
  p.label = OSC{/switch_drums}[$]
  p.mode = "push"
  p.onValue = `set("btnIdx", getIndex())
  if(value){
    set('tap_counter',get('tap_counter') + 1)
    console.log(get('tap_counter'))
    if(get('tap_counter') == 2){
      console.log("double tap")
    }
    setTimeout(function(){
      set('tap_counter',0)
      setTimeout(function(){
        var newVal = get('drum_select_matrix/'+getIndex())
        if(newVal){
          console.log("long press")
      }
    },500)
    },500)
    
  }
  
  `
  return p
}
2 Likes

cool! thanks for sharing, glad if that helps somehow. I forgot to say, for the buttonsNum variable , i've used 4 just for the example. But can be replaced with @{this.quantity} :+1: