# Knobs and Conversions



## Brendan (Jan 18, 2010)

I have a specific question which leads to a more generalized question. 

I'm writing a simple script where in a knob controls the attack of the instrument. The catch is that I want attack to expressed in quarter notes. I have the knob set up with all the note values labeled (1/4, 1/2, 3/4 etc.) and the value of the attack within the instrument is set to quarter notes. The problem is that the values of the knob don't correspond to the number of quarter notes in a straight forward way. 1 for 1 quarter 2 for 2 or even 10000 for 1 and 20000 for 2 would be nice. Instead it looks like this

680000 for 2 quarter notes
740000 for 3
775000 for 4
810000 for 5

I don't see any immediate pattern (then again my math skills are pretty weak). The work around is to create an array of these values and use it like this

_set_engine_par($ENGINE_PAR_ATTACK,%key[$Attack],0,0,-1)


----------



## polypx (Jan 19, 2010)

Brendan

You don't need to do the calculations if you set the envelopes themselves to be in quarter note mode (or any other note value). You do this by clicking and holding where it defaults to "ms" and changing it to the note value you want to use.

Then you can use the standard engine parameter method to set and get the value for your display, like this:


```
on init
declare ui_knob $Attack (0,1000000,1000000)
set_knob_label($Attack, _get_engine_par_disp($ENGINE_PAR_ATTACK,0,0,-1))
make_persistent ($Attack)
end on

on ui_control($Attack)
 	_set_engine_par($ENGINE_PAR_ATTACK, $Attack,0,0,-1)
	set_knob_label($Attack, _get_engine_par_disp($ENGINE_PAR_ATTACK,0,0,-1))
end on
```

I'll attach an example nki so you can see it too.

cheers
Dan


----------



## Brendan (Jan 19, 2010)

Thanks a bunch Dan,
Your script works great. Though using _get_engine_par_disp doesn't let me set the knob display to 1/4, 1/2, 3/4 etc. While _get_engine_par_disp makes the knob label the same as the attack knob within the instrument, the value of the knob is still 0 to 1,000,000. All Kontakt parameters have values from 0 to 1,000,000 right? But they display all kinds of different values. A pan knob for instance might read 0 but the internal value is actually 500000. This is fine if I just want to have a UI knob mirror a knob within the instrument but what if I want to do calculations based on the display value and not the 0 to 1000000 value of the Kontakt parameter? Is there a way to pull the display value into a variable? Hmmm. If not, than some converting is required. In some cases this is very easy and in others not easy at all. Attack, decay and release for example are non linear in their response. I just noticed that my original post got cut short. My second question was whether there were charts out there or if anybody had any similar resources for figuring out conversions.


----------



## Synesthesia (Jan 20, 2010)

Interesting. I just had this problem when setting knobs to display dB reduction -- the figures were totally weird - I couldn't see any pattern either, just had to trial and error to get the correct values.

I'd be very interested if anyone has figured this out!

Cheers,

Paul


----------



## polypx (Jan 20, 2010)

Brendan

That's an interesting point. I can't think of a way to pull the display value to a variable either, but there might be a way. (There are some very smart people on this forum.)

I think if you search here you'll find there has been some research into what values 0 to 1 million actually mean in Kontakt. For examle, I'm pretty sure Bob discovered the volume scale or formula NI were using. But there are so many parameters, and they all seem to behave differently (attack and decay are different, for example), so finding all of them would be really tough.

cheers
Dan


----------



## Big Bob (Jan 20, 2010)

Hi Brendan,

If you are willing to endure the brain drain :? , you may find the answers to some of your questions regarding the relationships between engine parameters and the parameters they represent by studying my KSP Math Library.

Here's some links for you to explore.

http://vi-control.net/forum/viewtopic.p ... th+library

http://vi-control.net/forum/viewtopic.php?p=144514

God Bless,

Bob


----------



## Brendan (Jan 20, 2010)

Thanks Bob! I have studied and learned a lot from your math library although a good deal of it flies right over my head. I missed your "Envelope Time Functions" thread during my initial search. Thanks for pointing it out to me. It's very frustrating that the number we're after is right there in the display, but we have to go through great lengths just to get that number into a variable. And then there's the whole integer based math thing. Dang, no easy answers on this one.


----------



## polypx (Jan 20, 2010)

Sometimes I wonder if this forum should be re-titled "Kontakt : Reverse Engineering"


----------



## Big Bob (Jan 21, 2010)

polypx @ Wed Jan 20 said:


> Sometimes I wonder if this forum should be re-titled "Kontakt : Reverse Engineering"



Be careful with your terminology Dan :wink: We wouldn't want NI to accuse us of violating our license agreement. :lol: Maybe we should just call it something like 'lending NI a hand with filling in some of their missing documentation' ? Or for short, "Kontakt: De-Mystified" :roll:


----------



## polypx (Jan 21, 2010)

Ooops! What was I thinking? :D


----------



## kotori (Jan 21, 2010)

Hi Bob,

It's good to see you around. You have gotten your studio up and running again now?

Speaking of your math library, I was wondering - have you thought about licensing it under some open source license like GPL (or LGPL), BSD or MIT? Or maybe some kind of custom free-for-noncommercial-use license or something?

Cheers,
Nils


----------



## Dynamitec (Jan 22, 2010)

Hi Nils, hi Bob,

speaking of the Math library: in Kontakt 4 with its array size of 32.768 it's easily possible to cache all important math library functions (including all the the time2ep conversation, etc) without any hassle - and it improves CPU usage a lot 

Cheers,
Benjamin


----------



## Big Bob (Jan 22, 2010)

Hi Nils,



> It's good to see you around. You have gotten your studio up and running again now?



Yes, about 2 days ago, I finally became somewhat operational again. o=< Now, all I have to do is play 'catch up' for a month or so (that is if I can still remember what in the world I was doing when I shut down) :? . 



> Speaking of your math library, I was wondering - have you thought about licensing it under some open source license like GPL (or LGPL), BSD or MIT? Or maybe some kind of custom free-for-noncommercial-use license or something?



I really don't know anything about such things. Why would I want to do that? Would that in some way benefit those that might want to use it? Would it benefit me in some way? For those of you 'in the know', these probably sound like dumb questions but remember I'm just an old geezer and not much 'in touch' with current things :roll: 



> speaking of the Math library: in Kontakt 4 with its array size of 32.768 it's easily possible to cache all important math library functions (including all the the time2ep conversation, etc) without any hassle - and it improves CPU usage a lot



Hi Benjamin,

I guess you mean use the Math Library to automatically build a bunch of 'lookup' tables in the ICB (thereby avoiding all the tedious manual calculations and entry of the needed data :cry: ). That's certainly a good suggestion for anyone having plenty of memory and wanting to avoid a possible execution time crunch. 

BTW Nils and Benjamin,

I just installed K4 but haven't had any time to play with it yet. Do you guys have any 'words of wisdom' about new features or potholes to avoid?

God Bless,

Bob


----------



## Big Bob (Jan 22, 2010)

Hi Nils,



> ....
> Making the conditions clear can be a way of encouraging and facilitating people's use of the library. Introducing restrictions can be a way to force people to contribute back if they make any changes (although they may choose to do that even without such conditions in the license).



Thanks for the lucid discussion. When I get some time I'll try to study the text of some of these license formats and, if it seems appropriate, I may 'tack one on' to some of my stuff. However, keep in mind that everything that I've done has always been offered freely without any strings attached other than common courtesy. So, I've always given my permission to use what I've done essentially without any restriction. But, maybe it would be better to say that explicitly in a formal license agreement rather than relying on the 'honor system'?



> One of the nice things is that it's possible to have indirect references to UI controls. Basically each control is automatically assigned an ID number that you can get access to using "get_ui_id(control)".



That is indeed a marvelous new capability that I will put to very good use. A lot of my scripts have utilized 'panel-building' routines that index through the UI elements. However, with no indirect way to access controls, a lengthy and wasteful set of 'select case' constructs are required and I can't tell you how often I wished I could refer to controls indirectly instead of explicity by name. Looks like K4 now provides the means to do that. Whoopee!! o-[][]-o 

Is there anything in K4 that is working poorer than in K3.5? When I left off, I seem to recall that K3.5 wasn't quite as stable as K2.24 had become. Is that true of K4 also or would you say that it is roughly as stable or better than K2.24?


----------

