# Buttonophobia



## dfhagai (Feb 9, 2019)

Hi,

I have a full 128 note piano graphic on my script's GUI.
I want the virtual keys to light up when the player plays.

At first, I've created two arrays with the X & Y coordinates and shifted one button around (using $CONTROL_PAR_PICTURE for the key graphics), but obviously that's not polyphonic... 

I thought of using buttons for all individual graphics carriers .That means, I'll need 128 buttons to be available simultaneously, one for each played key.
Add to the fact that eventually I'm planning of having 8 keyboards on the GUI, and you've got 1024 buttons....yikes. 

Is there a more efficient way you can think of? can I somehow add a graphic to a polyphonic variable in KSP?

Any advice would be much appreciated!
Thanks!
HD


----------



## dfhagai (Feb 10, 2019)

The button approach is useless, because it's too specific....meaning I have to define each key it's own graphic... 
This is far to cumbersome, long and clumsy...


----------



## henrik242 (Feb 10, 2019)

dfhagai said:


> The button approach is useless, because it's too specific....meaning I have to define each key it's own graphic...
> This is far to cumbersome, long and clumsy...


Also, there is a limit of 256 switches in ksp.

The idea with the positioning sounds interesting. Are you sure it won't work with simultaneous notes? Eah note has its own callback, so it might be worth a shot...


----------



## dfhagai (Feb 10, 2019)

> Also, there is a limit of 256 switches in ksp.


Didn't know that... thanks!



> The idea with the positioning sounds interesting. Are you sure it won't work with simultaneous notes? Eah note has its own callback, so it might be worth a shot...



It can't be achieved polyphonically because you can't (as far as I know, and I hope i'm wrong) attach an image to a variable, only to a UI variable (slider, knob, button, etc...), so in order to serve graphically a full keyboard, you'll need 128 UI elements...


----------



## henrik242 (Feb 10, 2019)

dfhagai said:


> It can't be achieved polyphonically because you can't (as far as I know, and I hope i'm wrong) attach an image to a variable, only to a UI variable (slider, knob, button, etc...), so in order to serve graphically a full keyboard, you'll need 128 UI elements...


Correct about the assigning an image to a variable, but you could move the UI-variable around perhaps? The manual warns about it being more CPU-intensive, though. 

Anyways, I'm just guessing. I don't know if it will work polyphonically.


----------



## dfhagai (Feb 10, 2019)

It won't, cause it's one ui element that your moving around, and it cant appear in more then one place at a time.
Quantum physics dont apply in KSP


----------



## polypx (Feb 10, 2019)

You could use 128 labels (they don't need to be switches unless you want to trigger something by clicking on it).

But that's half your labels for one script. If you need 8 keyboards simultaneously you won't be able to do it. You could possibly re-use the same keyboard, perhaps you only need to see one at a time?


----------



## dfhagai (Feb 10, 2019)

Must....have.....eightttt.....


----------



## EvilDragon (Feb 10, 2019)

Why not use ui_table with 128 cells? That should be good enough, and it's just a single control. If you don't need it clickable/editable, you can just cover it with a transparent button that's set to a higher Z-layer...

Also does it need to cover all 128 keys supported by MIDI, or just piano's range?

Here's what I did some time ago with a single ui_table and a single ui_label behind it:


----------



## dfhagai (Feb 10, 2019)

How can I use a single UI table to trigger different graphics, polyphonically, at the same time, one for each of the key?


----------



## EvilDragon (Feb 10, 2019)

You can't trigger different graphics, but you can set the table's cell value to show it as blinking. If you need *eight *of these, this is your only bet, really.







Also, here's a quick calculation for table width so that all the cells of the table have exactly the same width: (num_table_steps * cell_width_px) + 6. Minimum usable cell width is 2 px. And here's the background that I did that goes behind that table:


----------



## dfhagai (Feb 10, 2019)

I see....I'll give it a go then 
How did you manage to put the graphic behind the table? 
I've tried to hide the table original background using $HIDE_PART_BG but it's not working...


----------



## geronimo (Feb 10, 2019)

dfhagai said:


> I see....I'll give it a go then
> How did you manage to put the graphic behind the table?


With "$CONTROL_PAR_Z_LAYER" , perhaps _

0: all controls are assigned to this layer by default
-1: controls in this layer are placed below the default layer
1: controls in this layer are placed on top of the default and back layers.
(extracts from the KSP reference manual )


----------



## EvilDragon (Feb 10, 2019)

Labels go behind the table by default, you don't even need to do the Z-layer thing.

You could also try assigning $CONTROL_PAR_PICTURE for the table (so then you don't need a separate ui_label declared), but it really needs to match dimensions then.


----------



## paoling (Feb 11, 2019)

A table is nice. 

If you want to have skinned controls, consider also using fewer buttons, and reskin them. I did that in TimeDrops and it works nice. There are like 128 available buttons, that you can reskin on the fly (it doesn't take resources) an move around.

Also using the X-Y pad works fine. You can also click on it to do stuff. You can cursor to emulate a state of a key, it obviously needs a quite amount of tweaking but it works nice. (max 32 cursors but you can stack them).


----------



## EvilDragon (Feb 11, 2019)

There's max 16 cursors in XY pad. 2 axes per cursor, so the array max size is 32, but cursor count is 16.


----------



## dfhagai (Feb 13, 2019)

Does anybody knows what's the knobs/Sliders/Buttons limitation on a Multiscript?


----------



## EvilDragon (Feb 13, 2019)

It's all the same. Since Kontakt 5.8.0 the limit is 512 controls per UI control type. Prior to that, it was 256. And don't forget that you have buttons AND switches, so you can have twice the amount of buttonage compared to other control types. Oh, and file selectors, you can only have 3 of them.


----------



## dfhagai (Feb 13, 2019)

Word.


----------

