# New to Scripting **NEED HELP**



## The Darris (Dec 30, 2012)

I am working on a little free library for everybody that I am calling PAWN SHOP. I am sampling just some random instruments you would find at a pawn shop as well as making some odd FX patches (ie; Pads, Stabs, etc). I am in the process of creating my UI and I am having issues scripting the EQ and Reverb controls to sync properly with the FXs loaded into the InsertEffects section of the instrument. For instance: I have just a simple 3-band EQ loaded and on my GUI I have three Knobs (Low, Mid, Hi) all of which control Gains 1-3, respectively. When I move any of the knobs (default value of 0.00dB) It immediately sets the respective GAIN to -18.0dB and I can only control a total of 0.10dB to increase its value to -17.9dB. So basically, my knobs will only control .1 in all of my parameters. Here is what my script looks like for the EQ's Low Gain:


declare ui_knob $K1(-1800,1800,100)
set_text($K1,"Low")
set_knob_unit($K1,$KNOB_UNIT_DB)
set_knob_defval ($K1,0)
set_control_par (get_ui_id($K1),$CONTROL_PAR_VALUE, 0)
end on
on ui_control($K1)
set_engine_par($ENGINE_PAR_GAIN1,$K1,-1,1,-1)
end on


Anybody have a clue on how to fix this? I have been going through page by page of the KSP manual, of which gave me this scripting setup, and have yet to find a definitive answer on how to sync up these parameters.


----------



## Kralc (Dec 30, 2012)

I'm no expert myself, but messed around a bit with it, does this work?
(albeit the inevtiable possibility of there being some superfluous script in there )

on init
declare ui_knob $K1(0,1000000,1) 
set_text($K1,"Low") 
set_knob_defval($K1,500000) 
set_control_par(get_ui_id($K1),$CONTROL_PAR_VALUE, 0)
make_persistent ($K1)
read_persistent_var ($K1)
end on 

on ui_control($K1)
set_engine_par($ENGINE_PAR_GAIN1,$K1,-1,0,1)
set_knob_label($K1,get_engine_par_disp($ENGINE_PAR_GAIN1,-1,0,1))
end on

And for reverb, (With reverb or convolution in the send effects.)

on init
declare ui_knob $Reverb(0,1000000,1)
make_persistent($Reverb)
read_persistent_var($Reverb)
set_control_par_str(get_ui_id($Reverb),$CONTROL_PAR_TEXT,"")
set_control_par(get_ui_id($Reverb),$CONTROL_PAR_ALLOW_AUTOMATION,1)
end on

on ui_control($Reverb)
set_engine_par($ENGINE_PAR_SENDLEVEL_0,$Reverb,-1,7,0)
end on

And if I'm doing anything wrong please let me know... :oops:


----------



## The Darris (Dec 31, 2012)

Kralc @ Sun Dec 30 said:


> And if I'm doing anything wrong please let me know... :oops:



Honestly I wouldn't know either, I am just starting out on this scripting stuff. Your script didn't have any errors but it didn't fix my issue. I know the added lines: make_persistent and read_persistent_var only effect the knob if I am saving the patch and want the knob's setting stored. My issue is strictly the communication of my GUI knobs/controls to the Instrument Insert Effects. I believe it has something to do with the last lines: 

on ui_control($K1) 
set_engine_par($ENGINE_PAR_GAIN1,$K1,-1,1,-1) 
end on 

I know this is the line that directly sets $K1 to communicate to the corresponding GAIN1 and Insert slot but again, my knob, which has been set to the same min/max values in dBs, is only changing the actual EQ Gain by .1dB. In fact the second I click on my knob that GAIN goes to -18.0dB and I can only change it up to -17.9dB.

See attached pictures of the issue.


----------



## The Darris (Dec 31, 2012)

::Issue Solve::

Under the the "declare" section of the knobs I needed to include the lines: 

$K1 := get_engine_par($ENGINE_PAR_GAIN1,-1,1,1) 
set_knob_label($K1,get_engine_par_disp($ENGINE_PAR_GAIN1,-1,1,1))

I believe this string is what sends/receives the information, I could be wrong though.

Oh well, now I just need to figure out how to set my sliders to dry and wet. This should be interesting.


----------



## Big Bob (Dec 31, 2012)

Hi Darris,

I think you may have missed an important point that Kralc was trying to illustrate.

Your main problem is:

declare ui_knob $K1(-1800,1800,100)

While this very nicely displays gain in db, it does not provide the correct engine parameter control range. All engine parameters are controlled with the range from 0 to 1000000. If you define your knob like this;

declare ui_knob $K1(0,1000000,1)

It will then properly control the eq gain. However, you then have to deal with the fact that your knob will now display 0..1000000 instead of the db value you want it to display. There are two common ways to correct this situation. One is to use the method Kralc indicated:

set_knob_label($K1,get_engine_par_disp($ENGINE_PAR_GAIN1,-1,0,1))

This code overrides the 'natural' displayed value of the knob and replaces it with a text string supplied by the get_engine_par_disp function. This is the easiest way to deal with this issue. 

The problem is that the relationship between the ep and the corresponding db value is non linear. To illustrate the direct numerical method of dealing with this general issue you might want to read the following post.

http://www.vi-control.net/forum/viewtopic.php?t=28510

My Math Library includes format converters for most of the non-linear ep relationships.

Rejoice,

Bob


----------



## The Darris (Dec 31, 2012)

Big Bob,

Thank you so much. I actually realized exactly what you just said after I made that "solved" post. I also continued searching the forums and found a guy with the same issue as me to which you helped him out by posting some scripts. After a few hours of trial by fire I figured that it was all in the values I had, like you said. Thanks for actually describing why it is the way it is. I can copy and paste all day but I like to understand what is what when scripting. Thanks again and happy New Year.
-Chris


----------



## The Darris (Dec 31, 2012)

Also, I am having trouble figuring out how to get my sliders to control the Dry and Wet sliders in the standard Reverb effect. Any idea how to do this as well as label the slider controls approriately?


----------



## Big Bob (Dec 31, 2012)

Hi Chris,

Maybe the following example will steer you in the right direction.

*on init*
``message("")
``*declare* ui_slider $Dry(0, 1000000) 
````make_persistent($Dry)
````move_control($Dry,1,1)
````$Dry := 396851``_{ ep value required for default 0 db setting for first run }_
````read_persistent_var($Dry)
``*declare* ui_slider $Wet(0, 1000000) 
````make_persistent($Wet)
````move_control($Wet,1,3)
````$Wet := $Dry
````read_persistent_var($Wet)
``set_engine_par($ENGINE_PAR_SEND_EFFECT_DRY_LEVEL,$Dry,-1,0,1)
``set_engine_par($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN,$Wet,-1,0,1)
``*declare* ui_label $DryDb(1, 1) 
````move_control($DryDb,1,2)
````set_text($DryDb,"Dry: " & get_engine_par_disp($ENGINE_PAR_SEND_EFFECT_DRY_LEVEL,-1,0,1))
``*declare* ui_label $WetDb(1, 1) 
````move_control($WetDb,1,4)
````set_text($WetDb,"Wet: " & get_engine_par_disp($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN,-1,0,1))
*end* on

*on ui_control*($Dry)
``set_engine_par($ENGINE_PAR_SEND_EFFECT_DRY_LEVEL,$Dry,-1,0,1)
``set_text($DryDb,"Dry: " & get_engine_par_disp($ENGINE_PAR_SEND_EFFECT_DRY_LEVEL,-1,0,1))
*end* on

*on ui_control*($Wet)
``set_engine_par($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN,$Wet,-1,0,1)
``set_text($WetDb,"Wet: " & get_engine_par_disp($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN,-1,0,1))
*end* on



Of course if you want to mimic NI's slider you will have to do some custom graphics and write the necessary code to implement the sliding label that looks like a cartoon balloon. :lol: 

Rejoice, 

Bob


----------



## The Darris (Jan 1, 2013)

Bob,

Thank you so much. You have no idea how much your last post opened my eyes and mind to understanding this scripting mayhem. Haha, I got my GUI up and running and everything seems to be working flawlessly, well besides not getting the ctrl-clicking on the sliders to return them to the starting position of 0.0 but I think I just need to figure out the math there and change the 500000 value accordingly. I think I am working backwards, I have been working on the GUI first and now I am finishing up the recording of the samples to input them in. I can't wait to get this finished. Thanks again for all of your help.

Sincerely,

Chris


----------



## mk282 (Jan 1, 2013)

For setting the default value for ui_knobs, ui_sliders, use this:


```
on init
    declare ui_slider $Test (0,1000000)

    set_control_par(get_ui_id($Test),$CONTROL_PAR_DEFAULT_VALUE,500000)
end on
```


----------



## Big Bob (Jan 1, 2013)

Hi Mario, 

That's the way to set 'a' default (ctl-click) value all right but, since Chris says he wants the default to set the sliders to 0.0 db, I think the value will have to be 396851 instead of 500000, no? :wink: 

Bob


----------



## The Darris (Jan 1, 2013)

Well Bob, I believe you are correct in what I was looking for. I was just about to use your Math library to figure it out but you beat me. Haha. Thanks for all of the mentoring, I really needed it. Also, thanks to the other guys on here for helping to steer me in the right direction. Thanks again and I hope you all have a great New Year.

-Chris


----------



## mk282 (Jan 1, 2013)

Big Bob @ 1.1.2013 said:


> Hi Mario,
> 
> That's the way to set 'a' default (ctl-click) value all right but, since Chris says he wants the default to set the sliders to 0.0 db, I think the value will have to be 396851 instead of 500000, no? :wink:
> 
> Bob




Yes, this depends on the actual engine parameter used. I round that one to 397000.


----------



## Big Bob (Jan 1, 2013)

> Yes, this depends on the actual engine parameter used. I round that one to 397000.



Oh sure, 397000 is 'close enough for jazz' as they say :lol: I just suggested 396851 because it was the calculated value I had used in the illustrative code example. The point I was trying to make however was that it wouldn't be 500000 in this situation.

But Chris, Mario brings up a good point in that the ep for 0.0dB, ep0, will depend not only on the non-linear relationship but on the max dB. But at least so far, the non-linear relationship has been very consistent with Kontakt at 18dB/octave. As long as this remains the case, then the ep0 value will depend only on the max gain/volume for the control. 

Therefore, we can compute the ep0 value using the following:

ep0 = epmax*2^(-max/18 )

where epmax = 1000000, and max is the maximum volume/gain for the control. In this case, max = +24dB so ep0 = 1000000*2^(-1.333) = 396850.263

*Whoops!* I see I rounded this value one higher than I should have, shame on me :oops: 

Of course this value can also be obtained by measurement or by trial and error but, once one has the above formula, why not just calculate it and then round it off to some convenient value. In this case, something like 397000 (which Mario suggested) should be just fine.

Rejoice,

Bob


----------



## mk282 (Jan 1, 2013)

You ceil()'d instead of floor()'d. No biggie, at least in this case! :D


----------



## The Darris (Jan 1, 2013)

Wow, my mind is blown and completely confused by the equations. I am so terrible at math, it is not even funny. Haha. But seriously, I will keep that formula and play around with it when I need to. Also, here is a screen shot of my GUI you guys have helped me with. Thanks again.

http://i1354.photobucket.com/albums/q682/thedarris/GUI_PS_zps9f069980.png


----------



## Big Bob (Jan 1, 2013)

Hey Chris,

That's very artistic wallpaper. I was kind of expecting to see the 'three balls' as a background watermark though. But I guess that would have put too much emphasis on the "Pawn Shop' and not enough on the 'Instrument' part. :lol: 

Anyway, I'm glad to see that you prevailed. Congratulations.

God Bless,

Bob


----------



## The Darris (Jan 1, 2013)

Haha, Thanks Bob. My goal for this is to make some more instruments to incorporate a lot of the standard "B" instruments you would find at a Pawn Shop. I have a 10 year Glockenspeil that I am going to do as well as an Accordion I've picked up a long the way. Some other ideas were finding a really crappy drum set to sample but that will be a huge undertaking vs. the instruments I can record right here at my desk. I've also thought of doing an FX section with it. Anyway, this couldn't have made it this far with out your help so I appreciate it.

Take care,

Chris


----------

