Quick Sign In:  

Forum: VirtualDJ Technical Support

Topic: The value of verbs are incorrect when used on encoders
seanPRO InfinityMember since 2018
I'm just learning about scripting in VirtualDJ and I'm trying to get the size of a loop using the following:
get_loop & param_cast & debug

I noticed if I place this on a button it works fine and returns the correct value but using the same code on a encoder (On a Kontrol X1) it always returns "Int: 1". I've also tried other verbs like "get_clock" and they don't seem to return the correct value when used on an encoder? What am I missing here?

My code, while not complete is trying to replicate Traktors functionality where when you move a loop forward the play head stays inside the loop and seems to be working if not for this issue I'm facing:

loop_move +1 &
param_smaller get_loop_in_time "get_time elapsed" ?
get_loop & param_cast 'relative' & goto
 

geposted Mon 12 Dec 22 @ 8:17 pm
You need to better understand how encoders and implicit parameters work I guess..

Each time you move an encoder it sends a value. This value is a relative movement. Eg. -1 (a step back) or +1 (a step forward) Some encoders may send 0 for back and +1 for forward, or some may send 0 for forward and -1 for back.
Also keep in mind that when you're mapping sliders/encoders their value also becomes a parameter that's often used implicitly.

For encoders that send -1/+1 for movement, you can map actions like this: loop_move
That's because it gets automatically translated as "loop_move -1" and "loop_move +1" and therefore it moves the loop around by one beat.
However for encoders that send 0/+1 or -1/0 the same script becomes: param_bigger 0 ? loop_move +1 : loop_move -1
You can see on this example that we use a param query. We are actually fetching the implicit parameter (value) of the encoder.

PS: An exact copy of the code you're trying to use and have issues with could be helpful.
Unless the last 3 lines are the code you're using which don't make sense (since you always move forward, never backwards, in the first place)
 

geposted Mon 12 Dec 22 @ 8:40 pm
seanPRO InfinityMember since 2018
Thanks so much for explaining this. I hadn't included my full code only a snippet as I was nervous it would have more bugs as this is my first day using vdj scripts:

I just tested this snippet expecting it to work:
param_bigger 0 ?
get_loop & param_cast & debug

But I'm still getting the result 1 and -1. My programming background is telling me I need to do something similar to wrapping code in brackets? I presume my current code is causing param_bigger to be passed to debug instead of get_loop?

My full code which might have other problems is:
param_bigger 0 ?
loop_move +1 &
param_smaller get_loop_in_time "get_time elapsed" ?
get_loop & param_cast 'relative' & goto :
loop_move -1

P.S. what's the process for formatting code on these forums?
 

geposted Mon 12 Dec 22 @ 9:18 pm
I see a few mistakes, but the main question is:
What are you actually trying to achieve ?
If all you want is to move loop and have playing position "jump" (and stay within the loop) then all you have to do is to set the "loopAutoMove" setting to "yes"

As for mistakes:
1) There's no 'relative' cast (param_cast 'relative')
2) The correct way to do the comparison bit is param_smaller get_loop_in_time `get_time 'elapsed'` (Notice the backticks and the quote signs)
3) For "goto" action to accept an implicit parameter, the parameter must be formatted as "+4" / "-4" or similar value.

In order to type scripts in the forum you can use [script] block
In order to type code, you can use [code] block
 

geposted Tue 13 Dec 22 @ 2:30 am
seanPRO InfinityMember since 2018
Thanks, I know it's a strange use case but just replicating something that Traktor does where I can move a loop forward 1 beat and the play head stays inside the loop on the same phrase it was originally on.

There's really only one thing I'm missing, brining it back to absolute basics. If I wanted to output get_loop to the debugger I thought this would work:

param_bigger 0 ? get_loop & param_cast 'text' & debug


But it outputs "Text: 1". If I can figure out why that doesn't output the value of get_loop I think I've learnt why this script isn't working for me.
 

geposted Tue 13 Dec 22 @ 4:16 am
locoDogPRO InfinityModeratorMember since 2013
@phantom there is a relative cast, and 2 looks wrong.
 

geposted Tue 13 Dec 22 @ 4:23 am
2 has a typo (a space) but it absolutely works
 

geposted Tue 13 Dec 22 @ 9:07 am
user18829647 wrote :
Thanks, I know it's a strange use case but just replicating something that Traktor does where I can move a loop forward 1 beat and the play head stays inside the loop on the same phrase it was originally on.

That should already be the case with VirtualDJ as well as soon as the "loopAutoMove" setting is enabled
 

geposted Tue 13 Dec 22 @ 9:17 am
locoDogPRO InfinityModeratorMember since 2013
user18829647 wrote :

param_bigger 0 ?
loop_move +1 &
param_smaller get_loop_in_time "get_time elapsed" ?
get_loop & param_cast 'relative' & goto :
loop_move -1


I think I'd do it the other way, I'd check (position in the loop multiplied by loop size) against 1 , that would tell me if I can just move the loop and nothing else or I need to do stuff after I move the loop.

the implicit is a pain, but it can be nulled, it can be manipulated and it can be worked round.
 

geposted Tue 13 Dec 22 @ 8:26 pm
seanPRO InfinityMember since 2018
Thanks for the help. Unfortunately loopAutoMove doesn't solve my problem, I already have it turned on. When moving a loop forward by 1 bar the play head will stay in the current location but I need the play head to move with the loop. And I can't use beat jump because it moves the the play head forward 1 beat and I want it to continue playing on the current phrase inside the loop.

Thanks for the help because this is almost working now, the only remaining issue I have is with param_cast. In a VDJ script which is on an encoder if I do:
param_bigger 0 ? get_loop & param_cast & debug

I would expect it to output get_loop to the debug window but it outputs the value coming from the encoder. How do I get it to output get_loop?
 

geposted Sat 17 Dec 22 @ 4:55 am
locoDogPRO InfinityModeratorMember since 2013
try something like this
param_bigger 0 ? param_multiply get_loop & param_cast & debug
 

geposted Sat 17 Dec 22 @ 1:38 pm
seanPRO InfinityMember since 2018
Thanks locodog, that works, can't quite comprehend why param_multiply is required but does the job.

Here's my script for anyone else who stumbles across this, probably not perfect but does the job. Would of liked to use loop_position as suggested by locodog but I still need to get my head around how math works in virtualdj scripts:

param_smaller 0 ?
loop_move -1 :
loop_move +1 &
param_smaller get_loop_in_time "get_time elapsed" ?
param_multiply get_loop & param_cast 'relative' & goto
 

geposted Mon 19 Dec 22 @ 3:22 am
locoDogPRO InfinityModeratorMember since 2013
why multiply is needed in this case,
the +1/-1 from the encoder [the implicit] gets placed before any cast values.
An absolute pain, but I've been told that behaviour in super deep in the script engine code base [like pretty much back to the start of vdj] so it's unlikely to change, but that +1/-1 can be manipulated with some of the param_* actions
[_add _multiply _invert _1_x, _pow, all the math ones]
and the manipulate value holds it's value, it becomes the implicit.

so your case +1/-1, you want loop size, just multiply by loop size, other cases you might have to zero it first [multiply by 0] then add whatever var is holding your value.

I can't see why there isn't a set_implicit `action` script to avoid this merry dance, but I'm not a professional developer, I've been told can't be done the implicit is really deep in the code, just bash it into shape with the maths verbs.
 

geposted Mon 19 Dec 22 @ 10:21 am
locoDogPRO InfinityModeratorMember since 2013
param_smaller 0 ?
loop_move -1 :
param_bigger "param_multiply get_loop loop_position" 1 ?
loop_move +1 & goto "loopsize+" :
loop_move +1


try that I think it should work.
 

geposted Mon 19 Dec 22 @ 10:54 am