# Simple method to design the GUI



## paoling (Oct 10, 2011)

Hi to all!
I want to share a little and basic trick to design the ui.

When I work at a script I usually declare some knobs and sliders that appears at various positions on the perf_view.

But, if I decide to organize these things in a final view, without using the awesome kb123 GUI Generator, which I recommend, you can find the desired positions with this simple trick.

On the ICP (init callback, the "on init" part), add these lines:

declare ui_knob $x(0,640,1)
set_text($x,"x")
move_control ($x,5,7)
declare ui_knob $y(0,400,1)
set_text($y,"y")
move_control ($y,5,9)
declare $ui_id

The coordinates of move_control can change, depending from the height of the ui, to a
zone that out of the other knob positions.

Then add these callbacks or, if they are already present, add the inner code for every control present in your script. Example for a knob named $my_knob:

on ui_control($my_knob) {add only the inner part if this callback is already here}
$ui_id:=get_ui_id($my_knob)
$x:=get_control_par($ui_id,CONTROL_PAR_POS_X)
$y:=get_control_par($ui_id,CONTROL_PAR_POS_Y)
end on

And add these two callbacks somewhere in the script:

on ui_control($x)
set_control_par($ui_id, $CONTROL_PAR_POS_X, $x)
end on

on ui_control($y)
set_control_par($ui_id, $CONTROL_PAR_POS_Y, $y)
end on
--------------
If you click on a knob, slider or a button, or a control that reacts to the "on ui_control" callback (so not things like labels), then you can change its position with those sliders.
Then look for its coordinates, write them on paper and setting the knob final position to the coordinates found in the ICP with 
move_control_px($my_knob, x, y), where x and y are the found values, for that specific knob.

After having found the right coordinates, simply delete the code that I wrote above.

There can be lots of alternatives, including saving the positions to an array, but this can be the simplest solution, without releating to the make_persistent things that can possibly mess up the position.



Paolo


----------



## polypx (Oct 10, 2011)

Paolo, that's brilliant!

cheers
Dan


----------



## paoling (Oct 10, 2011)

EDIT: I've exchanged 2 values for that were wrong in the first version.

Thanks Dan!


----------



## Mike Greene (Oct 10, 2011)

Very slick! 8)


----------



## polypx (Oct 10, 2011)

I think I'd do it with ui_value_edit instead of knobs too... but the concept is great.

cheers, Dan


----------



## Big Bob (Oct 10, 2011)

Yes, indeed the core idea is clever o-[][]-o This is getting more like the good ol' days with this forum. Thanks Paolo for sharing this idea.

Rejoice,

Bob


----------



## paoling (Oct 10, 2011)

Thank you Bob and Mike.. I was thinking about this today when I was at lunch. I thought: "What a boring thing now to make order for all those knobs.."
And since I'm still in the building phase I had no time to use the GUI Generator; that is definitively the best way to arrange things in very large and multi-page scripts.


----------



## mk282 (Nov 2, 2011)

Whacha say about this? 

http://k.minus.com/iqOWD510U0b5.gif


This is now a slightly older version, I added clear current/all controls to default values, and send current/all. I might add a window for declaring the default values perhaps. This works in conjunction with an Excel spreadsheet which automatically generates the ICB, and optionally adds script locking, empty UICBs, and of course, the NRPN CB that's used for communication between the multiscript and the instrument scripts.

I can save all my settings for all controls (up to 1024 controls per script slot) for all 5 script slots, in one .NKP file (when I save the multiscript as a preset). If I need to edit some positions or control parameters, I just call up that preset, call up the NKI, and add changes. Although I always extract the values to declare a control parameter array in the instrument script, even though it's not absolutely necessary (since the control pars get saved in a persistent array - but that poses a problem if you copy the script in an empty script slot - that erases the persistent array).


----------



## paoling (Nov 2, 2011)

Wow!


----------



## polypx (Nov 2, 2011)

Love it!!!


----------



## jdawg (Nov 2, 2011)

WANT. 
How would the multi support translate to the separate patch though?
If you saved the patch without the multi, and opened it up on another machine would all your controls revert to 0,0 ?


~o)


----------



## mk282 (Nov 2, 2011)

Once you set up the control parameters via multiscript, they stay in the instrument script as a persistent array variable.


----------



## jdawg (Nov 2, 2011)

wow, I guess the only question left is, will this be available open source? for sale? for traded gold  

:mrgreen:


----------



## mk282 (Nov 2, 2011)

For the time being it's only for my personal usage, sorry. 

However, it's not really hard to come up with that code. There's a few tricks needed in order to send values larger than 16385 (you use two NRPN variables instead of one, then multiply them), and another trick for merging RGB color values into one number (there's a formula available for that, too).

I don't have my webpage yet, nor methods of selling/donating available (Paypal really sucks for my country), but sooner or later I'm probably going to release it. I wish for a more drag&drop WYSIWYG oriented scripting IDE, something like kb123's GUI Generator, but something a bit more comprehensive.

We'll see what happens. The good thing with this approach is - it's native to Kontakt, no 3rd party programs are necessary. The bad thing with this approach is - it's not BUILT INTO Kontakt, so you still need to create code for each instrument script to support communication with this multiscript, and then again the init callback needs to be written in a special way for everything to work correctly. So it's not without its caveats...


----------

