Encoder - increment values; XY Pad - extract float values

Hi there,

Couple of newbie questions here.

  1. I am trying to use encoder to scroll through video clips in disguise software, let’s say I have 30 of them. Unfortunately my scripting skills are not that good. Reading through community topics, I understand that I should use script widget to achieve this. Script I currently have looks like this and it works to some extent:

var value = @{encoder_1}
if (value == 1) {
set(‘fader_1’, @{fader_1}+1)
} else if (value == -1) {
set(‘fader_1’, @{fader_1}-1)
}

2 problems here:

  • If I keep rotating encoder clocwise it sends 1 constantly, but my fader value incresed only once and not on every encoder tick.
  • I would like to take fader out of the equation and do it only through encoder and script, or only through encoder if that’s possible.

Also I would like to define the range, for example if I have 30 clips, then it shouldn’t go past that value

  1. I have an XY pad which obviously sends 2 float values from same osc address, but I need to send them separately. I managed to extract them, like this:
    #{@{xy_1}[0]}
    #{@{xy_1}[1]}
    These 2 values I have placed in 2 variable widgets, but when I try to send osc values out of variable widget, it doesn’t do it.

How can I solve these issues?

Thank you in advance!
Kris

  • If I keep rotating encoder clocwise it sends 1 constantly, but my fader value incresed only once and not on every encoder tick.
  • I would like to take fader out of the equation and do it only through encoder and script, or only through encoder if that’s possible.

Using the encoder’s script property would be more appropriate here:

var min = 0,
    max = 30,
    index = locals.index || 0 // load index

// increment index
index = Math.min(max, Math.max(min, index + value))

// save index
locals.index = index

// send index ?
send("127.0.0.1:4444", "/index", index) 

Reference: https://openstagecontrol.ammd.net/docs/widgets/scripting/

I have an XY pad which obviously sends 2 float values from same osc address, but I need to send them separately. I managed to extract them, like this:

Again, using the xy’s script property:

send("127.0.0.1:4444", "/x", value[0])
send("127.0.0.1:4444", "/y", value[1])

Such a short and elegant script. It works perfectly!
Thank you so much!

I have another question if you don’t mind:

Is it possible to constantly increment slider value if I push and hold the button and stop increment on release?
With these lines of code it works just once, so obviously missing something additional:
if (value == 1) return
set(“fader_1”,@{fader_1}+1)

var increment = 1,
    timeBetweenIncrements = 100 // ms

if (value === 1) {
 setInterval(()=>{
  set("fader_1", get("fader_1") + increment)
 }, timeBetweenIncrements)
} else {
 clearInterval()
}

Note: avoid using the @{} syntax in scripts, use get() or getProp() instead.

Amazing!

Thank you very much!

Question - What is the reason not to use @{} syntax in scripts? Does it affect overal performance for session?

The reason is that the code the in script property is compiled twice: once to replace the @/OSC/JS/# blocks (-> aim: making properties dynamic), and once to generate the function that runs when the associated event occurs (value update, keyboard stroke, and possibly more to be added in the future).

Take this code for instance:

@{input_1} + " dB"

A #{} block containing this code would compile to the following code, executed each time the input’s value updates with the new value as argument:

function(VAR_000, /* + other variables */) {
  return VAR_000 + " dB"
}

The #{} block ends up replaced with the returned value and that’s how the property is computed. Now if you write the same code directly in a script property:

@{input_1} + " dB"

If the input’s value is “hello”, the first compilation pass produces the following property value:

hello + " dB"

The @{} block is replaced with the literal value it holds (just like the #{} block is replaced by its execution result). The second compilation pass is likely to fail because hello ends up seen as an undeclared variable here (no quotes around it).


TL;DR: This all happened because the script property was built on top of the preexisting dynamic property logic.

Thanks, this explains why some of the stuff in script property doesn’t work for me.

One thing I can’t wrap my head around though:

If I have a variable which value is changed through buttons, lets say 1, 2 and 3 (cam_variable), how do I pull it into script property without @{} if variable is somewhere in the middle? Because
send(get(“osc_tx”), “/d3/cam_get(“cam_variable”)x", value[0]) <- This doesn’t work
send(get(“osc_tx”), "/d3/cam
@{cam_variable}_z”, value[1]) <- This works

Thanks in advance!

String contatenation in JS is usually done with the + operator:

"/d3/cam_" + get("cam_variable") + "x"

Thank you very much for all the help so far!

I’m sure I will have more questions along the way. So far everything I tried to achieve works very well.

Thank you for making such a cool program! :slight_smile: