# V403 KSP Math Library



## Big Bob (Sep 22, 2011)

Hi Everyone,

I'm attaching V403, the latest update to the KSP Math Library along with an updated User's Guide Addendum. This version of the library includes several new utility functions that you may find quite useful.

1. A Resetable random number generator.

2. Format converters for all the K4 filters such as LP, BP, HP, etc.

3. Format converters for the new K5 filters such as SV, AR, DAFT, etc.

Rejoice,

Bob


----------



## paoling (Sep 22, 2011)

Thank you so much Big Bob, your contribution to the little scripters' community is invaluable; I will keep you informed about my progresses on my future projects (and for the project you helped me to realize).

Paolo


----------



## ScoringFilm (Sep 22, 2011)

Bob,

Thanks - although you don't get many replies I suspect many people benefit silently from your efforts.

Much appreciated,

Regards,

Justin


----------



## Big Bob (Sep 22, 2011)

Feedback is always welcome, thanks guys.

God Bless,

Bob


----------



## paoling (Sep 23, 2011)

Hi Big Bob, I'm facing the same problems I found with the previous version of Math Library; if I carefully follow your instructions, when I compile the script WriteNKA.txt in NILS' Editor, I get a long script with this line 
15:=15
This is strange... I deleted the line and the script runs, but I'm not sure I'm on the right way. I will be more precise in a couple of hours of experimenting..


----------



## andreasOL (Sep 23, 2011)

Many thanks, Bob!

Your work is very much appreciated!!!

Cheers from Germany,
Andreas


----------



## paoling (Sep 23, 2011)

Oh! I've found where's the problem. I just need to disable "use automatic workaround for call bug" in NILS editor. What is that??


----------



## andreasOL (Sep 23, 2011)

Hi

that's to circumvent a true bug in Kontakt in which Kontakt skips lines if a call statement is directory before an "end if" (or the like...). I have encountered something similar in my scripts. 

KSP inserts a self assignment (something like a := a) between the "call" and the "end if" line. However, KSP takes one of the variables that are declared by the script and sometimes it takes a const variable which you cannot assign something to. So I started declaring a variable nop (for "no operation"...it's an old mnemonic from the era of assembler programming) and put a "nop := 0" before the "end if" line.

Kind of a manual workaround to work around the automatic workaround 


So, in your case KSP mistook the "15" for a variable...

Cheers,
Andreas


----------



## paoling (Sep 23, 2011)

Oh.. Thank you so much Andreas for your accurate explaination


----------



## durk (Sep 23, 2011)

n00b question; what are those filter Format converters? What are they used for/do?


----------



## paoling (Sep 23, 2011)

In Kontakt, filters like lowpass, highpass and so on, follow a particular scale that is not linear as the knob value (knob values range from 0 to 1000000, and the middle is 50000)
The only thing that we were able to do before BB was to link a knob in the performance view with a knob of the kontakt engine, without precisely know the its value in hertz. We were just able to match the display of that knob to the knob in the performance view, just for user reference.

But if you decide to set precisely a filter cutoff by 250 hz how can we do? 
Simple we can use Math Library's function LPFreq_to_ep along with set_engine_par(arguments...) to set the precise hertz value that we wish.


----------



## Big Bob (Sep 23, 2011)

paoling @ Fri Sep 23 said:


> Oh! I've found where's the problem. I just need to disable "use automatic workaround for call bug" in NILS editor. What is that??



I never turn that option on anymore because I thought that bug had been fixed some time ago. Are you guys saying that the current version K4.2.3 (or K5) still exhibit this problem?


----------



## paoling (Sep 23, 2011)

Anyway Bob, you allowed me to design a wonderful instrument, I'm just quick testing it and I'm very excited for the results...


----------



## TuwaSni (Sep 23, 2011)

Bob,

Many thanks for the new filter conversions.

TS


----------



## Big Bob (Sep 24, 2011)

Thanks for the favorable feedback, I'm glad that you are finding the update useful.

You might be interested in knowing what's coming :roll: 

I'm working on Version 450 which will utilize Nils' latest KSE update with return-value functions. In the process I'm reorganizing all the ep conversion routines. This collection of converters was built as a kind of patch-work quilt and it's getting a little disorganized. 

I think I'm going to redo the ep converters with only two routines named something like *ep_to_par(pname,ep) *and *par_to_ep(pname,par) *where pname is the parameter name. There are currently 18 pnames defined such as AtkTime, LPFreq, etc. This approach should be more easily extensible for the future.

Anyway, I'll keep you posted as things progress.

Rejoice,

Bob


----------



## andreasOL (Sep 26, 2011)

Big Bob @ Fri 23 Sep said:


> paoling @ Fri Sep 23 said:
> 
> 
> > Oh! I've found where's the problem. I just need to disable "use automatic workaround for call bug" in NILS editor. What is that??
> ...



Oh, don't know  I just leave it on. Does somebody know the exact scenario for the bug and test it?

Cheers,
Andreas


----------



## kotori (Sep 26, 2011)

andreasOL @ Mon Sep 26 said:


> Oh, don't know  I just leave it on. Does somebody know the exact scenario for the bug and test it?



In previous Kontakt versions the following two code snippets were semantically identical:

```
if ($x = $y)
end if
```


```
exit
```
That is, an if-statement with no statements between if and end if was equivalent to an exit-call.


----------



## ScoringFilm (Sep 26, 2011)

Nils, Bob or any other knowledgable person!

Is there any other way of exiting a part of code (if, while, for) without the call back being exited entirely; i.e. to just exit that part of the script and continue?

Regards,

Justin


----------



## Big Bob (Sep 26, 2011)

Hi Nils,

But has the bug been eliminated? I thought that it had.

For what it's worth, I just tried a simple, empty if-end statement with K4.2.3.4914 and the problem doesn't occur.

However, I should mention that V1.4.8 of the KSE won't let me do this because with the call bug option disabled (as well as code optimization off), the new compiler refuses to compile an empty if-end. If optimization is on, the statement is merely removed.

In order to run the test I had to enter the code directly into the Kontakt Editor.

-----------------------------------------------------------------------------------------------

Hey Paolo,

You do need to enable code optimization when you use the Math Library. You are doing that aren't you? If you don't you will get all kinds of extraneous code!
------------------------------------------------------------------------------------------------



> Is there any other way of exiting a part of code (if, while, for) without the call back being exited entirely; i.e. to just exit that part of the script and continue?



Hi Justin,

If you mean something simple like a 'break' statement there is nothing like that that I'm aware of. Of course there is always a way to accomplish the same thing such as forcing a premature exit from a while loop, etc.

I think in earlier versions of Kontakt, an exit statement in a KN function would simply cause the function to exit (instead of the callback it was imbedded in). However, that no longer seems to be the case. At least the last time I tried it, it caused the callback to exit (like you would expect).

*BTW Guys, I just discovered a bug in V403 of the Math Library that affects the high end of the V3x2Freq_to_ep converter. I'm going to post an update in a separate thread so it doesn't get buried.*
Rejoice,

Bob


----------



## ScoringFilm (Sep 26, 2011)

Thanks Bob for the update and answer to my question. This is where is has confused me; as the 'exit' has changed its behaviour on version increments and I wasn't aware!

Regards,

Justin


----------



## andreasOL (Sep 27, 2011)

Regarding Kontakt bugs...

I checked with Kontakt 4.2.3 yesterday and found:

- The "call bug" is gone, i.e. a "call" before and "end if" works  (see http://www.vi-control.net/forum/viewtopic.php?t=17500)

- Empty "if - end if" works also (as Nils mentioned already) :D 

- Empty functions still act as an exit :!: (edit: this is no real problem)

best,
Andreas


----------



## Big Bob (Sep 27, 2011)

Hi Andreas,

Thanks for the info, I wasn't aware of the empty KN function problem. 

Rejoice,

Bob


----------



## tonewill (Oct 9, 2011)

Bob, or anyone else who knows, when you assign a knob to a group volume say, would that benefit from some sort of audio taper function or are group volumes already okay? I've never been sure. I assume your ATFade function is for use with the sample level volume is it? I.E. for use with change_vol().

Thanks for any help,

Barry


----------



## djdarko (Oct 9, 2011)

Thank you Big Bob, I'll check it out.


----------



## Big Bob (Oct 9, 2011)

tonewill @ Sun Oct 09 said:


> Bob, or anyone else who knows, when you assign a knob to a group volume say, would that benefit from some sort of audio taper function or are group volumes already okay? I've never been sure. I assume your ATFade function is for use with the sample level volume is it? I.E. for use with change_vol().
> 
> Thanks for any help,
> 
> Barry



Kontakt primarily uses a cubic function (rather than an exponential) for volume control just about everywhere I have checked. ATFade can be used for any volume control because it controls volume in mdb. Of course you may have to use one or more of the library's format converters also (for example if you are driving an engine parameter).

You may also want to read this pdf that I whipped up about 3 years ago, I'm sure that most of it still applies.

Rejoice,

Bob


----------



## tonewill (Oct 10, 2011)

Thanks a lot Bob. I've started reading that PDF a couple of times in the past, but never managed to finish it; it's a biggie! I'll take a look again and see what I can find. Nice of you to put this altogether.

EDIT: Just realised you've attached a PDF, I thought you were referring to the one that comes with the library :oops:. I'll download that and have a read, thanks again Bob.

Barry.


----------

