# XY Pad Problem



## Kore G (Jun 30, 2019)

Hello guys! 
I have a 4 layer library and i want to control the volume 
with an XY pad. Here is the code:


```
on init
make_perfview
declare ui_xy ?xy[2]
make_persistent(?xy)

end on

on ui_control (?xy)
set_engine_par($ENGINE_PAR_VOLUME,real_to_int(?xy[1] * 1000000.0),0,-1,-1)
set_engine_par($ENGINE_PAR_VOLUME,real_to_int(?xy[0] * 1000000.0),1,-1,-1)
set_engine_par($ENGINE_PAR_VOLUME,real_to_int(?xy[1] * 1000000.0),2,-1,-1)
set_engine_par($ENGINE_PAR_VOLUME,real_to_int(?xy[0] * 1000000.0),3,-1,-1)

end on
```

I want the volume to be at maximum when the cursor go to each corner
and the others at minimum.

This code not work for me.

I try this one but it saws me 2 cursors instead...


```
on init
make_perfview
declare ui_xy ?xy[4]
make_persistent(?xy)
end on

on ui_control (?xy)
set_engine_par($ENGINE_PAR_VOLUME,real_to_int(?xy[0] * 1000000.0),0,-1,-1)
set_engine_par($ENGINE_PAR_VOLUME,real_to_int(?xy[1] * 1000000.0),1,-1,-1)
set_engine_par($ENGINE_PAR_VOLUME,real_to_int(?xy[2] * 1000000.0),2,-1,-1)
set_engine_par($ENGINE_PAR_VOLUME,real_to_int(?xy[3] * 1000000.0),3,-1,-1)
end on
```


----------



## angeruroth (Jun 30, 2019)

You only need one cursor, so the first declaration is ok.
But XY pad values go from 0 to 1, so you need to change your math to something like this:
a := real_to_int((?xy[0] - 0.5) * 2000000.0)
b := real_to_int((1.0 - (?xy[0] - 0.5)) * 2000000.0)
c := real_to_int((?xy[1] - 0.5) * 2000000.0)
d := real_to_int((1.0 - (?xy[1] - 0.5)) * 2000000.0)

This formulas will return negative values. You may need to change that.


----------



## PaulieDC (Jun 30, 2019)

Whoa, I may be a noob to VI composing but I’m a software developer for the past 20 years and didn’t know Kontakt had an SDK! Is it built in like VBA is in Office, or something I need to download separately?


----------



## EvilDragon (Jun 30, 2019)

angeruroth said:


> This formulas will return negative values. You may need to change that.



Negative values won't work with set_engine_par(), rethink the approach 


OP, do you want to have a vector crossfade like on Korg Wavestation or Prophet VS, where the joystick (in this case XY pad) crossfades between all 4 soundsources, or do you want to have individual mixing for each?


In case you need a vector mix, what you need to use is bilinear interpolation.



PaulieDC said:


> Is it built in like VBA is in Office



It's built in. Check out the manual


----------



## PaulieDC (Jun 30, 2019)

EvilDragon said:


> It's built in. Check out the manual


----------



## Kore G (Jul 1, 2019)

angeruroth said:


> You only need one cursor, so the first declaration is ok.
> But XY pad values go from 0 to 1, so you need to change your math to something like this:
> a := real_to_int((?xy[0] - 0.5) * 2000000.0)
> b := real_to_int((1.0 - (?xy[0] - 0.5)) * 2000000.0)
> ...



Thanks a lot angeruroth!
I test it, this one doesn't work!
Mario is right negative values doesn't work.


----------



## Kore G (Jul 1, 2019)

EvilDragon said:


> Negative values won't work with set_engine_par(), rethink the approach
> 
> 
> OP, do you want to have a vector crossfade like on Korg Wavestation or Prophet VS, where the joystick (in this case XY pad) crossfades between all 4 soundsources, or do you want to have individual mixing for each?
> ...



I think individual mixing for each is what i need.
I search on the manual and i didn't find anything about callback in ui_xy...


----------



## angeruroth (Jul 1, 2019)

EvilDragon said:


> Negative values won't work with set_engine_par(), rethink the approach


Yes, but you only need to set the limit 

This code if you want silence when the pointer in centered:

```
$a := real_to_int((?xy[0] - 0.5) * 2000000.0)
if($a < 0)
    $a := 0
end if
$b := real_to_int((1.0 - (?xy[0] - 0.5)) * 2000000.0)
if($b < 0)
    $b := 0
end if
$c := real_to_int((?xy[1] - 0.5) * 2000000.0)
if($c < 0)
    $c := 0
end if
$d := real_to_int((1.0 - (?xy[1] - 0.5)) * 2000000.0)
if($d < 0)
    $d := 0
end if
```

This easier code if you need a linear-crossfade with no silence:

```
$a := real_to_int(?xy[0] * 2000000.0)
$b := real_to_int((1.0 - ?xy[0]) * 2000000.0)
$c := real_to_int(?xy[1] * 2000000.0)
$d := real_to_int((1.0 - ?xy[1]) * 2000000.0)
```

Of course you can go math hard


----------



## Kore G (Jul 1, 2019)

angeruroth said:


> Yes, but you only need to set the limit
> 
> This code if you want silence when the pointer in centered:
> 
> ...



Thanks a lot Mario the linear-crossfade with no silence
is what i need!


----------



## EvilDragon (Jul 1, 2019)

Of course that's not a linear crossfade because the scaling of $ENGINE_PAR_VOLUME is not linear at all


----------



## angeruroth (Jul 1, 2019)

EvilDragon said:


> Of course that's not a linear crossfade because the scaling of $ENGINE_PAR_VOLUME is not linear at all


Hmm, I'm almost brain dead right now (too much heat in my region) but that's interesting. Could you please elaborate on how the scaling works?


----------



## Kore G (Jul 1, 2019)

angeruroth said:


> Hmm, I'm almost brain dead right now (too much heat in my region) but that's interesting. Could you please elaborate on how the scaling works?


Test this nki


----------



## Robym (Jul 1, 2019)

Hi,
it is possible to have 4 layers that are at 100% volume on each XY PAD corner, at 25% in the center and at "0" on all other 3 corners. We have done it in a library we are developing it, but unfortunately I can't share it at the moment since it's a script for a new product (Sorry).
I just thought i'd mentioned that there is a way (or more than one) as i think this is what KORE G might be asking for.
Roby
In the video below the XY Pad controls the 4 busses volumes.


----------



## Guster83 (Feb 15, 2022)

Hello everyone,
I'm bumping this because recently I've been trying to achieve what this topic originally asked (which I have already been able to do with an xy pad), except I'd like to do this with a single knob.
Meaning, for example, the knob defaulting all the way to the left would mean only group 1's volume is up, then as you move the knob to the right then it crossfades into group 2, and then group 2 crossfades into group 3 (with group 1 no longer being heard) and then group 3 into group 4 etc.
I'm a newbie so any thoughts on how to approach this will be greatly appreciated.
Thanks.
Gus


----------



## Guster83 (Feb 15, 2022)

Tried a few different things but still stuck. One thing is noticed is that I cannot set the value for the [0] slot of the xy array, is this a restriction of ksp? 
With something like this: ?xy[0]:= $controller1
In other words, I'm trying to control the xy pad with 2 knobs.


----------



## EvilDragon (Feb 16, 2022)

You can definitely set any index of ui_xy, but you need to use a real variable (~), not an integer ($), or use int_to_real() function.


----------



## Guster83 (Feb 16, 2022)

Thanks @EvilDragon , that worked 
My main goal with the XY though, I have not been able to accomplish yet. But since it is not really the same issue as this thread, I'll create a separate one later to see if I can get some suggestions. Thanks again.


----------

