Connexion rapide:  

Forum: VirtualDJ Technical Support

Sujet VDJScript: read the current value of a control and reuse it
Could someone please help me understand the VDJScript syntax to read the current value of a control, store it, and then set the control back to the stored value?

Here is the application I am attempting.

When playing some sound FX they are overpowered by the music. Here is a simple and working script that overcomes this, but it is hard coded with the “deck 1 volume” and “deck 2 volume”. This can be problematic.

deck 1 volume 70% & deck 2 volume 70% & sampler 1 play_stop & wait 600 & deck 1 volume 100% & deck 2 volume 100%

I would rather do something like this:

store the value of “deck 1 volume”
store the value of “deck 2 volume”
Reduce “deck 1 volume” by 30%
Reduce “deck 2 volume” by 30%
sampler 1 play_stop & wait 600
restore “deck 1 volume” to the store the value of “deck 1 volume”
restore “deck 2 volume” to the store the value of “deck 2 volume”


Is this doable?

Thanks,
Kevin Weiner
 

Posté Wed 12 Oct 22 @ 11:40 pm
locoDogPRO InfinityModeratorMember since 2013
read the explanation for the set verb.
Use that, to set, then uses get_var and param_cast send it back to a control.
 

Posté Thu 13 Oct 22 @ 7:36 am
LOCODOG,
I reviewed the suggested reading; thank you.

I must be missing fundamental knowledge. Is it possible to show an example of a script that stores the value of “deck 1 volume” in %MyVar and then sets “deck 2 volume” = %MyVar?

An example such as this may help me understand what I am missing.

Thanks,
Kevin
 

Posté Fri 14 Oct 22 @ 4:21 am
locoDogPRO InfinityModeratorMember since 2013
deck 1 level 70% & set Avar `deck 1 level` & wait 500ms & deck 1 level 5% & wait 500ms & deck 1 get_var Avar & param_cast & deck 1 level


expanded so you see it in action, set then get & cast
 

Posté Fri 14 Oct 22 @ 4:28 am
LOCODOG,
Thank you for the example. That has helped me a lot. With the understanding I gained from your example, I am getting close, but I cannot seem to get over the finish line. I am still missing something.

I can get a script to work in that it reduces the volume of each deck independently for the duration of the sampler play, but it is not restoring the volume of each deck properly.

set $tmpDeck1Volume `deck 1 level` & set $tmpDeck2Volume `deck 2 level` & get_var $tmpDeck1Volume & param_multiply 70% & deck 1 level & get_var $tmpDeck2Volume & param_multiply 70% & deck 2 level & sampler 1 play_stop & wait 500ms & get_var $tmpDeck1Volume & param_cast & deck 1 level & get_var $tmpDeck2Volume & param_cast & deck 2 level & var_list

This view is to help me learn what I am doing incorrectly:

set $tmpDeck1Volume `deck 1 level` & | sets global variable $tmpDeck1Volume to value of deck 1 level
set $tmpDeck2Volume `deck 2 level` & | sets global variable $tmpDeck2Volume to value of deck 2 level
get_var $tmpDeck1Volume & param_multiply 70% & deck 1 level & | reduce deck 1 level by 30%
get_var $tmpDeck2Volume & param_multiply 70% & deck 2 level & | reduce deck 2 level by 30%
sampler 1 play_stop & | play a sound FX
wait 500ms & | wait for the sound FX to play
get_var $tmpDeck1Volume & param_cast & deck 1 level & | Restore deck 1 level to original value
get_var $tmpDeck2Volume & param_cast & deck 2 level & | Restore deck 2 level to original value
var_list | for debugging only

What occurs is both the deck 1 level fader and the deck 2 level fader are independently reduced by 30% for the duration of the sampler play. Then, the deck 1 level fader is set equal to the current (reduced) setting of the deck 2 level fader.

Please do not fix this for me; I will not learn that way, but if you would, please help me see what I am missing.

Thanks,
Kevin
 

Posté Sat 15 Oct 22 @ 1:31 am
locoDogPRO InfinityModeratorMember since 2013
you won't see it, it's your method with reducing the level , you're ending up with a fixed implicit. That has priority over the cast value.
wrap the whole level reduction bit in ( ) from before the first get_var to just after deck 2 level.
 

Posté Sat 15 Oct 22 @ 4:32 am
LOCODOG,

Thank you, Sir!

Is there suggested reading material to learn about such things as this scripting language’s fixed implicit and other intricacies? I have not been able to find anything on a Google search; I will pay for documentation. For that matter, I would like to thank you with a PayPal or other such donation, if I may.

With this script working, may I ask…was my methodology for this functionality a good approach? As I am not proficient at VDJScript, sometimes I feel like I am using a “brutal force” and not a smart approach.

Kevin Weiner
 

Posté Sat 15 Oct 22 @ 9:56 pm
locoDogPRO InfinityModeratorMember since 2013
I've got this ScriptSchool It's not everything, but with years of experimenting, sometimes you know things but you can't explain exactly how you know it. But a fixed implicit is one of those that has you tearing hair out the first time and it sticks in your mind how to spot it in future.

I have a link here where you can throw into the beer fund, thanks :)
https://www.virtualdj.com/user/locodog/index.html

your method is fine, there's no prizes for pretty script, I'm seeing little bits of v7 script [sampler 1 play], which still works but isn't as flexible as v8 syntax [sampler_play 1]. [v8 syntax is better for casting values to] The wait for sample to end is an arbitrary value. That could be covered more dynamically with a rs script repeat_start NAME 30ms -1 & sampler_play 1 ? nothing : VOLUME BACK UP & repeat_stop NAME
 

Posté Sun 16 Oct 22 @ 6:24 am
LOCODOG,

Ha! That was where I was heading next. I was already looking at the VERBS to see if I could obtain the sample length, setting that as the WAIT duration. Your solution is brilliant!

Back in the days of outboard processors, I had a compressor triggered by the sidechain input, and that brought the mains down when I spoke or played a sound FX (my favorite is when someone says something out of place, and I hit the hotkey for “That boy’ I say that boy Is about as sharp as a bowling ball” - Foghorn Leghorn

Thank you again for all your help. Beer funds are on the way.

Kevin Weiner
 

Posté Sun 16 Oct 22 @ 10:59 pm
LOCODOG - The PayPal exchange rate system was a bit confusing. Please let me know if the amount you received was insufficient, and I will gladly send more. - K
 

Posté Sun 16 Oct 22 @ 11:03 pm
LOCODOG,

You are a good teacher. At first, the addition of [repeat_start] worked, but the deck level sliders were continuously returned to the original level and could not be changed once the script ran. Wrapping the “ELSE” section of “sampler_play 1 ?” solve this problem.

Here is the working script:

set $tmpDeck1Volume `deck 1 level` & set $tmpDeck2Volume `deck 2 level` & (get_var $tmpDeck1Volume & param_multiply 70% & deck 1 level & get_var $tmpDeck2Volume & param_multiply 70% & deck 2 level) & sampler play_stop 1 & repeat_start MySampleIsPlaying 30ms -1 & sampler_play 1 ? nothing : (get_var $tmpDeck1Volume & param_cast & deck 1 level & get_var $tmpDeck2Volume & param_cast & deck 2 level) & repeat_stop MySampleIsPlaying


I have just one more challenge to try to resolve. If this script is running and the button is pressed a second time (on purpose or an accident), the deck-level sliders wind up at the incorrect level once the script is done running. That makes sense as the [set $tmpDeck1Volume `deck 1 level` & set $tmpDeck2Volume] will populate the reduce levels.

I know I can ask [sampler_play 1 ? ] before doing anything; I believe that will resolve this, but what if any other [sampler_play 2,3,4…32] = TRUE?

Is there a way to ask: [sampler_play ANY] ?

Thanks,
Kevin
 

Posté Mon 17 Oct 22 @ 1:07 am
locoDogPRO InfinityModeratorMember since 2013
sampler_used
is the one you want, cheers for the beer :)
 

Posté Mon 17 Oct 22 @ 5:48 am
For the benefit of anyone following this thread, or reading it for the first time, here is a copy of the current iteration of the script:

sampler_used ? sampler_stop 1 : set $tmpDeck1Volume `deck 1 level` & set $tmpDeck2Volume `deck 2 level` & (get_var $tmpDeck1Volume & param_multiply 70% & deck 1 level & get_var $tmpDeck2Volume & param_multiply 70% & deck 2 level) & sampler play_stop 1 & repeat_start MySampleIsPlaying 30ms -1 & sampler_play 1 ? nothing : (get_var $tmpDeck1Volume & param_cast & deck 1 level & get_var $tmpDeck2Volume & param_cast & deck 2 level) & repeat_stop MySampleIsPlaying


Purpose: This script's purpose is to automatically reduce deck 1 and deck 2 volumes, play a sampler and return the volumes to where they were after the sampler plays.

Example: You may want to play drop during a mix. Perhaps a baby cry or sad horns…

Why: When playing certain sound FX from a sample bank, some sound FXs are overpowered or lost under the music.

On a single hotkey press, deck 1 and deck 2 volumes are reduced by 30%. The sampler plays for its duration, and then the deck 1 and deck 2 volumes are returned to their previous volume.

If the hotkey is pressed while the sample is playing, the sampler stops, and deck 1 and deck 2 volumes are returned to their previous volume.

Here are a few assumptions you need to know if you would like to play with this:

• If you use more than two decks, you may need to modify this to include them.
• While triggered, this script will only allow one sampler to play at a time by use of this script.
• If you use this on more than one hotkey to trigger more than one sampler, please be sure to update the sampler number in all three places.

Kevin
 

Posté Wed 19 Oct 22 @ 2:00 am