# K2 Table editing utility



## kotori (May 29, 2006)

Hi
I've made a utility for editing K2 tables as a list of values. It can extract a table to a value list and it can also export to Kontakt tables. The purpose of the Table Editor is to make it possible to easily setup rescalings with good precision. For example, it can be used to setup rescalings for mod-wheel controlled equal-power crossfading between velocity layers. It's possible to manually enter the table values, paste them from eg. Excel, or write your own formulae - eg. _sin(x/127*pi)+0.5_ - and calculate the table automatically with an optional normalization to make the values span the whole 0-100% range.

The program uses UI automation (when exporting tables to Kontakt it simulates mouse clicks in the table) and image recognition (to import tables from Kontakt it takes a screenshot of the Kontakt window and interpretes that) to do its work. 

How a formula is constructed:
x represents the incoming value and is in the 0-127 range
functions: sin, cos, tan, exp, log, abs
constants: e, pi
It's possible to write a range condition and have it evaluate to 1 or 0 depending on whether it's true or not. Eg. "(10<=x<=20)*sin(x)" will evaluate to 1*sin(x) when x lies between 10 and 20, and 0 otherwise. Summing multiple terms of that format makes it possible to use different formulae for different intervals.

You can download the Table Editor at: http://nilsliberg.se/ksp/K2TableEditor.zip
Unzip it and run K2TableEditor.exe.

Here's a table constructed with a single formula and exported to Kontakt:






Here's an example formula showing how to do cosine crossfades:
(1+cos((x-30)/25*pi+pi))*(30<=x<=55) + 2*(56<=x<=64) + (1+cos((x-65)/25*pi))*(65<=x<=90)
The resulting table looks like this:




As you can see there are three intervals 30-55, 56-64 and 65-90.

Cheers,
Nils


----------



## Dynamitec (May 29, 2006)

Wow, Nils! Thank you! As usual great ideas from you!


----------



## aiit (May 29, 2006)

Unbelievable….. Great idea always got frustrated when trying to do smooth curves.

Thanks for the tool.
Jacob.


----------



## Thonex (May 29, 2006)

Wow Nils!!!!!

I'm just blown away by this... if I understand it... and even if I don't :smile: 

What a creative solution... I'll have to check this out tomorrow.

Again... It's so great to have you here!!!!

Cheers Nils,

T


----------



## kotori (May 30, 2006)

Hi everyone,
glad you like this tool. :smile: 
I decided to polish it a bit. There's now a newer and better version - same http://nilsliberg.se/ksp/K2TableEditor.zip (URL) as before (you can simply replace the earlier program with this). This version adds some assistance in constructing the formula if you want to do linear or cosine crossfadings - you just have to specify some values which control the interval and press either the linear or cos button. There's also a little preview at the bottom. Here's what it looks like:




The '?' button provides some information about how to construct a formula.
So now you have the option to:
* Specify the values manually (possibly pasting them from Excel)
* Writing your own formula, or
* Automatically construct a formula and calculate the values (linear and cosine crossfades)

When you press the Fetch/Set buttons you need to have Kontakt started and a rescaling visible. No part of the rescaling may be outside the screen and the Active button must be pressed.

Cheers,
Nils


----------



## Thonex (May 30, 2006)

Hi Nils,

I DLed your program... but when I extracted it there was a file called Library.zip (14,961 KB) that I was unable to open... and it results in a problem when trying to open your program. I'll try DLing it again to see if maybe there was a corrupt DL.

T


----------



## Thonex (May 30, 2006)

Well.. I got it to work without the sin and linear buttons to show up on the UI... man.... it's like magic!!! :shock:  .... the K2 Table editor just redraws itself.. all by itself... well... with the use of your program. Very ingenious!!!!!

One thing I noticed is that the top value is 100. I thought it was supposed to be 127 in K2... or is that being exported as 127 to K2 and only showing up as 100 in your K2 Table utility?

But wow... pretty amazing stuff!!!!

I'm DLing it again to see if I can get rid of the problem I'm having.

Cheers,

T


----------



## Thonex (May 30, 2006)

OK.. I tried DLing it again on another computer and this time it won't even extract. hmmm.... anyone else having this problem?

Thanks.

T


----------



## kotori (May 30, 2006)

Hi Andrew,
Thanks for letting me know about this. It turned out that the paths to the button images were absolute and not relative, so it only worked on my computer :oops:. I've fixed this now and uploaded a new version which should work better (same URL). If you just downloaded it you may have to clear your browser's cache to get the newest version. Actually the scale of Kontakt rescalings is 0-100% so the range is correct.

Cheers,
Nils


----------



## Thonex (May 30, 2006)

Thanks Nils,

I DLed it and I'll try it later today... in the middle of writing.

Cheers,

T


----------



## Thonex (May 31, 2006)

OK Nils... This is simply amazing!!!! Frankly, I'm surprised more people haven't chimed in... but then again... it is a pretty unique application.

I'm amazed by the "technology" of this little application... the image recognition and the automation of retracing the bars in the table.... amazing!!!

Did you write the Image recognition code yourself or are these types of things available as modules to incorporate into your own code. Whatever the answer, it doesn't take away from this brilliant approach to K2 programming.

It's like a ghost doing it for you.  

Since you opened the door to this kind of application, would it be possible for a similar application to accurately change the master tempo of K2 with midi commands? There are many applications out there that don't follow midi clock in stand alone mode... maybe this could be a commercial solution for you?

Great job Nils... I'm blown away.

T


----------



## kotori (May 31, 2006)

Hi Thonex,
I'm glad you like it! It's the beauty of the Python programming language. It's soo easy to take a couple of existing modules (Image handling and windows automation) and make something useful. It's really quite simple, here's how it works:
 I tell the automation library to find a window with the Kontakt caption, bring it to the front and take a screenshot of it. (~5 lines of code)
 For efficiency I build a list of all coordinates having a pixel with same orange color as the Active button. Among these candidates I than take the difference between the part of the screenshot and a pre-stored image of the Active button. There's a function to sum the pixels of an image, so when the pixel sum of the diff-image is zero I have got a match. 
(~22 lines of code)
 I have manually calculated the distance from the Active button to the rescaling table, so as soon as I know the position of the button it's a simple matter of calculating the height of each bar or automate mouse clicks at certain positions (~25 lines of code).
Then there's some GUI code which comprise the larger part of the program. But as you see, the core is quite small. :smile: 

Cheers,
Nils


----------



## ComposerDude (May 31, 2006)

Very clever, Nils!

-Peter


----------



## Thonex (May 31, 2006)

Interesting stuff Nils... very creative ue of the code.

I'm trying to think of anything else that would be helpful for K2 with this kind of image recognition technology.

I guess remapping samples in order of pitch wouldn't be possible eh? :wink:


----------



## Rodney Glenn (May 31, 2006)

Brilliant stuff...great job as always Nils (mycket snillrikt). :smile: 

R


----------



## Thonex (Jun 2, 2006)

kotori @ Fri Jun 02 said:


> Yes, it should be possible to write a script/program that enters values in the tempo field and presses return repeatedly. I have never written a python app which receives midi I don't think it would be a problem to do so. Do you want me to give it a try?
> 
> Btw. when you use this table editing tool always save your multi first, just in case.
> 
> ...



Don't try it just yet. I'm trying to get an answer out of NI regarding midi clock and tempo changes with both K2 and Kore in stand-alone mode.... if Kore recognizes mò[|   ; Ü[|   ; Ý[|   ; Þ[|   ; ß[|   ; à[|   ; á[|   ; â[|   ; ã[|   ; ä[|   ; å[|   ;


----------



## Rodney Glenn (Jun 2, 2006)

kotori @ Fri Jun 02 said:


> Thanks Rodney! :smile: You know Swedish?



Hehe, I actually live in Sweden. I just realized I didn't activate the flag in my profile (sorry bout that) so it's corrected now. :smile: 

R


----------



## Thonex (Jul 2, 2006)

kotori @ Fri Jun 02 said:


> Thonex @ Wed May 31 said:
> 
> 
> > Since you opened the door to this kind of application, would it be possible for a similar application to accurately change the master tempo of K2 with midi commands? There are many applications out there that don't follow midi clock in stand alone mode... maybe this could be a commercial solution for you?
> ...



Hi Nils,

If you are still open to your offer to see if we can do anything with regards to K2's tempo synch... I'd love for you to give it a try.... especially now that NI seems to not really care too much about it. 

Would you still be interested/available to give it a shot?

On my end, I'm going to try to see if there is a way for me to completely bypass any Tempo info and just have a script use milliseconds and speed based on the DAW's tempo.

Cheers,


T


----------



## Giorgio Tommasini (Jul 29, 2006)

:smile: 

Nils, du är en fantastisk gubbe.

Kann vi inte prata lite grann?


Giorgio


----------



## Thonex (Nov 11, 2006)

This needs to be bumped. I just did some silky smooth x-fades between groups using this utility.... very very helpful.

Thanks Nils.

T


----------



## Nickie Fønshauge (Nov 12, 2006)

Yeah, it is indeed a great tool. It cannot be recommended too much.

Tackar så mycket!


----------



## kotori (Nov 13, 2006)

Thank you guys. It's good to know that you find it useful!


----------



## Big Bob (Nov 13, 2006)

Good to see you back again Nils  . I was just about to put out an SOS asking if anyone had heard from you recently. Glad to see you're still alive and well. Hope you thoroughly enjoyed your holiday.

God Bless,

Bob


----------



## Nickie Fønshauge (Dec 16, 2006)

For some reason the Table Editor doesn't seem to work with K2.2. I get an error message no matter what I do. Or maybe I just can't remember how to do it right :oops: Can somebody confirm, that it doesn't work with K2.2? Or tell me how to use it?


----------



## kotori (Dec 17, 2006)

Nickie Fønshauge @ Sun Dec 17 said:


> For some reason the Table Editor doesn't seem to work with K2.2. I get an error message no matter what I do. Or maybe I just can't remember how to do it right :oops: Can somebody confirm, that it doesn't work with K2.2? Or tell me how to use it?



It seems NI changed the caption of the main window of Kontakt which confused my program (they really should have better things to do, don't you think? ). 
Anyway, I uploaded an http://nilsliberg.se/ksp/K2TableEditor.zip (updated version) (same URL as before) which I hope will work again.

Cheers,
Nils


----------



## Nickie Fønshauge (Dec 17, 2006)

kotori @ 17th December 2006 said:


> It seems NI changed the caption of the main window of Kontakt which confused my program (they really should have better things to do, don't you think? ).


Absolutely! No need to go around and confuse other peoples programs. Now, if they could just learn not to confuse their own programs, maybe they would leave your programs alone too.

Thanks for your concern.


----------



## pocoapoco (Jan 6, 2007)

I realize you've posted this more than six months ago, but I thought of another useful thing you could add to this utility. That would be to create a table based on the changing amplitude of a sample over time which I see would be very useful in producing release samples. I know it would be quite a bit of work to add that function, but man would it ever be useful. So useful that I'd have to get windows program running capability.


----------



## kotori (Jan 7, 2007)

pocoapoco @ Sun Jan 07 said:


> I realize you've posted this more than six months ago, but I thought of another useful thing you could add to this utility. That would be to create a table based on the changing amplitude of a sample over time which I see would be very useful in producing release samples. I know it would be quite a bit of work to add that function, but man would it ever be useful. So useful that I'd have to get windows program running capability.



I'm not sure how you mean this amplitude data would be used. Not in the same way I guess since it's time dependant...
Would it be for modulating the release sample volume to match the main note at any time?


----------



## pocoapoco (Jan 16, 2007)

yes, exactly. Sorry for the delay in my response.


----------



## pocoapoco (Jan 17, 2007)

You might be right. I really don't know what most other people want or see as necessary or desirable as far as this sort of thing goes. And, in fact, the only use for this would be in releases for acoustic samples with a natural decay like piano or guitar. It may even be possible to generate a good level for release volume in most or all cases with a simple mathematical function. But I haven't studied it too much. I can only tell you that I care about it in practice. If I had access to a compiler right now I might even try to address the challenge of coming up with a simple application.


----------



## MozillaUser (Apr 10, 2009)

Sorry if I'm offtopic, but I'm kinda new here.
Since this topic is quite old, and I missed it when it was fresh:
Nils, I browsed the whole site of yours, but I found absolutely no trace of your table editor. The links you provided give me a 404. Can you post a working link for the Table Editor, please? Thanks in advance.
best--
MozillaUser


----------



## Big Bob (Apr 11, 2009)

Thonex @ Sat Apr 11 said:


> Big Bob @ Sat Apr 11 said:
> 
> 
> > Meantime, you might try this link.
> ...



Yes, I saw that Andrew but I don't have the faintest idea of what the associated code does :roll: . Maybe when Nils comes up for air, he will tell us?

Maranatha,

Bob


----------



## MozillaUser (Apr 14, 2009)

Thanks a lot Bob, I've got the thing.
Mahabharata 
Mozil


----------



## Synesthesia (Aug 28, 2009)

Nils - 

You wrote this in Python right?

Just wondering how difficult (ahem) or not it might be to get this incredible tool working on OS X..?

I know there is a Python compiler in the dev toolkit..

As a relatively incompetent programmer, is there anything in there that wouldn't translate to Python on the mac?

Cheers!

Paul :mrgreen:


----------



## nlundberg (Aug 29, 2009)

Hi,

I'll second that! I'd love to be able to use this app in OS X!!

Best.


----------



## Synesthesia (Aug 31, 2009)

Hey Nils!

Bump...

Is there any reason why this should not work? Did you only use items from the 'Standard Library'..?

I'd love to know and if there is no reason why ths shouldn't in theory work I'll have a crack at making it work..

Is the window size etc the same on the os X K3.5?

Cheers,

Paul


----------



## Synesthesia (Sep 3, 2009)

The lone voice cries in the wilderness.

I have finally got the sample start offset utility working - by going back to Kontakt 3 (not 3.5) - I reckon its the same problem with the Window title bar name - so for this I need to reinstall K2.2....?

Nils - is it possible to edit a source file to change the Window title that it looks for? I have tried to see if the uncompiled source code is anywhere in the folder but I cant find it...

Thanks!

Paul


----------



## nlundberg (Sep 4, 2009)

Paul, I am counting on you!


----------



## Nickie Fønshauge (Sep 5, 2009)

What kind of tables do you need? If it is cross-fade tables, have a look at the ones in http://foenshauge.dk/software/kontakt2/tables/Pro_Musica.rar. Might save you the trouble of inventing the wheel again :wink:


----------



## Synesthesia (Sep 6, 2009)

Wow.>!

Thank you so much Nickie - - many many thanks.

You have saved me tearing more chunks of hair from my head.!!!

o-[][]-o o-[][]-o o-[][]-o 

Cheers!!

Paul


----------

