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
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.
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)
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)
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:
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
I see that as of v1.5.1 * encoder steps , ticks and origin properties are removed. Is there any way how to bring it back, through script or something? Changing sensitivity works to some extent, but it's not really possible to divide encoder equally in "n" ticks.
Regarding this:
Is it possible to define locals.index from external variables? Let's say if I press button_1, it sets encoder locals.index to varaible_1, if I press button_2, it sets encoder locals.index to varaible_2 etc. ? And if I increment index, it sets final index back into selected variable. Basically I'd like to switch between different states.
Hope that makes sense.
I had those removed because they were not working very well, but I just got back to it with a fresh look and managed to make the ticks work just fine, I guess it'll be back in next release then !
Is it possible to define locals.index from external variables? Let’s say if I press button_1, it sets encoder locals.index to varaible_1, if I press button_2, it sets encoder locals.index to varaible_2 etc. ? And if I increment index, it sets final index back into selected variable. Basically I’d like to switch between different states.
Instead of storing the value in locals, you can create a variable widget to store it and call set("variable_id", value) and get("variable_id") to set/get it.
May I ask how to increment xy pad values on button press?
Tried this to increment x value, but no luck:
var increment = 0.01,
timeBetweenIncrements = 2 // ms
if (value === 1) {
setInterval(()=>{
set("xy_1[0]", get("xy_1[0]") + increment)
}, timeBetweenIncrements)
} else {
clearInterval()
}
Managed to do it through 2 fader widgets by adding them in xy_1 value field [@{fader_1}, @{fader_2}]
But this seems like a way too long workaround.