What's new

Live Update UI Element Per LFO or Other

Hello everyone,

I'm trying to have a GUI element (in this case an XY pad, but perhaps also a slider) visually change its value per how an LFO (or other mod source) is interacting with with the setting it controls. The effect i'm going for is that the user can set volume and pan using the XY pad, and then an LFO is modulating both of those to some degree. So after they set the initial value and start playing, the LFO triggers and the XY pad visually updates to match the actual volume and pan volumes.

I was testing trying to update the XY position by setting the position of the element to be controlled by another knobs position inside of the 'on note' function (the knob usage is strictly for test, I really want to have this use an LFO to move it around). However this only updates it at each note trigger, not during the note sustain. Also i'm having trouble mapping the value of something to the 0-1 range the XY pad desired.

I had dabbled in some animation before in KSP, and my guess is that I would have to create a user function which gets called at every on-note function. This function would run a while loop that does some math to map the current parameter value (in this case volume or pan), to the 0-1 range the pad wants, and then update the current element location in the XY pad - all at specific time intervals fast enough to look like an animation. This sounds like a massive pain and I imagine there might be an easier way to do it.

So I have a few questions:
-How do I correctly map the 0-1000000 value of the volume parameter of a certain group to the 0-1 float value? int_to_real() seems to only be getting me 0 or 1, and dividing by 1000000 doesn't work either.

-How can I update an XY pad location live either as notes are played, or all the time, to match the volume or pan of a certain group (which is being modified by a modulator)? How can I do the same type of live updating of a knob / slider position?

I'd prefer a solution that is as CPU intensive as possible, but at this time I just want to get it up and running at any cost and deal with the CPU issue later (even by having a version with animation and without animation).

Thanks,
--
Andrew
 
the proper way is not to use animation at all. KSP is running in the audio thread, the audio thread has not to play image-based animation)
For the question about XY assignment:
Code:
var := int_to_real(get_engine_par(<args>))
xy[<0 or 1>] := var/1000000
As far as I know, there's no way to catch the real LFO 'value'. Even with note_on.
For the pretty animations build your own LFO with blackjack and hookers, but it is bad)

You can try to look into the code of CinePianos (Challen Talk and other pianos). For me, it's the guideline of how to build a responsive, cheap and cool interface. No math, no listener, no animations (almost). And realistic arrow potentiometers)
 
the proper way is not to use animation at all. KSP is running in the audio thread, the audio thread has not to play image-based animation)
For the question about XY assignment:
Code:
var := int_to_real(get_engine_par(<args>))
xy[<0 or 1>] := var/1000000
As far as I know, there's no way to catch the real LFO 'value'. Even with note_on.
For the pretty animations build your own LFO with blackjack and hookers, but it is bad)

You can try to look into the code of CinePianos (Challen Talk and other pianos). For me, it's the guideline of how to build a responsive, cheap and cool interface. No math, no listener, no animations (almost). And realistic arrow potentiometers)

You can do animations in KSP, i've made a few simple scripts that trigger an animated sequence when you hit a note. Also i've purchased libraries before (Haunted Spaces) which has an animated XY pad that moves a shape around to control volume sliders.

It may not be the most efficient use of CPU, and it may be kind of gimmicky, but for certain libraries I think it makes sense.
 
You can and you should if the project really demands it, but do watch out that listener is not running too fast.
 
You cannot get current volume of a played sample from KSP.

Maybe not of a sample, but the current volume of the group channel after all modulations have been applied? I seem to be able to access the level the volume knob is turned to, but not the position that it rotates to during playback accounting for envelopes and LFO's.

If this isn't possible the only way I see this type of thing could be done, is if you made an a mathematical function to run off of the same initial conditions as the knobs at the time of trigger. So its not directly using the volume post-LFO to move around, but a sin wave that uses the same frequency value and amplitude as the LFO. Sounds like a PITA though, haha.
 
Top Bottom