# Crossfade script using Big Bob's math library



## kotori (Jan 9, 2007)

:arrow: _http://nilsliberg.se/ksp/scripts/scripts.html#crossfade (The latest version)._

Hi everyone,

Feel free to try out this http://www.nilsliberg.se/ksp/scripts/NLCrossfade4_compiled.txt (crossfade script) I've written (copy and paste the code directly into Kontakt) . Credit goes to Big Bob for providing his excellent math library which is what powers this script. If I've done everything right this script should provide equal-power crossfade without volume dips.

_Usage instructions_:
This script is under development and uses the change_vol function, so please add a limiter to the output just in case something should go wrong to protect your ears. Move the intensity slider for any velocity->volume modulation of your groups to 0%. 
Specify the number of velocity layers (nlayers) and the top velocity of each layer. layer1 should be the lowest layer, layer2 the next and so on. The intensity knob corresponds loosely to the velocity->volume modulation slider in Kontakt. It's normally at 70-80%, but if you like to listen to a pure xfade between the layers without the lower ones having lower volume you can try to set it to 0%. 

Cheers,
Nils


----------



## Thonex (Jan 9, 2007)

Hi Nils... was going to try it out and....

Line 437:
Error ... ui_update not declared.

But wow.... what a complex looking script.... I'll never complain about my simple looking scripts again :shock: 

T


----------



## Big Bob (Jan 9, 2007)

Thonex @ Tue Jan 09 said:


> Hi Nils... was going to try it out and....
> 
> Line 437:
> Error ... ui_update not declared.
> ...



Andrew, what version of K2 are you running? I haven't studied Nils' script yet but ui_update is a new callback type added by NI with K2.2.

Bob


----------



## Thonex (Jan 9, 2007)

Ahhhhh... that's the problem. I didn't update to 2.2 yet because I'm in the middle of projects... and I'd have to update all 6 of my computers.

So, I'm going to wait until I'm done with my current projects or maybe load K2.2 into one of my lesser used K2 pcs.

Cheers,

T


----------



## kotori (Jan 10, 2007)

Hi everyone,
I deleted the on ui_update part so I think it should be compatible with K2.1 now. In addition I made a number of updates and made the code a little bit clearer for anyone interested in reading it. The link above leads to the updated script.

I also made available the syntax highlighted http://nilsliberg.se/ksp/scripts/NLCrossfadeV04.html (uncompiled source) if anyone's interested. Here's what the script looks like:






Cheers,
Nils


----------



## kotori (Jan 10, 2007)

Thonex @ Wed Jan 10 said:


> oh my.....  I promised my wife that since I finished my deadlines yesterday..I won't step foot into the studio for a few days.... but I may just have to sneak in.....


Congratulations on finishing that deadline Andrew and sorry to tempt you this way. :lol: 
I should point out though that the script is still under development. Although it seems to work quite nicely it still has a couple of problems: the intensity knob is reversed and its range is probably quite different from K2's. Also I have in some cases noticed slight jumps in volume after the first CC movement after a note has been pressed (has anyone else noticed this?). This could be due to the relative flag being set to 0 when calling change_vol, although I didn't think that would cause problems as long as the volume modulation is turned off.


----------



## Thonex (Jan 10, 2007)

kotori @ Wed Jan 10 said:


> Also I have in some cases noticed slight jumps in volume after the first CC movement after a note has been pressed (has anyone else noticed this?). This could be due to the relative flag being set to 0 when calling change_vol, although I didn't think that would cause problems as long as the volume modulation is turned off.



Talking to you from my laptop.... (not in my studio  ) I have had anomalies with the change_vol() command... especially when a loop was involved... but I can't remember if it was in K2.1 or a prior version.

T


----------



## Big Bob (Jan 10, 2007)

kotori @ Wed Jan 10 said:


> Thonex @ Wed Jan 10 said:
> 
> 
> > oh my.....  I promised my wife that since I finished my deadlines yesterday..I won't step foot into the studio for a few days.... but I may just have to sneak in.....
> ...



Hi Nils,

I have confirmed this problem just recently. At first I too thought that if there was no volume modulators in play, that when you first started a note it's level would be 0db but such is apparently not the case. The first change_vol (after a wait) that sets it to 0db always seems to result in a level jump. So, I guess we're stuck with using the change_vol(x,y,1) form (and all the extra stuff that goes with that).

Bob


----------



## lee (Jan 11, 2007)

I just wanna say: WOW Nils! :smile: 

Will try this out for sure. How big volume jumps are we talking about?

Thonex: There´s a big risk making agreements like those with your wife. There´s a big risk spending too much time in the studio too I guess. :lol: 

/Johnny


----------



## kotori (Jan 11, 2007)

Thanks for that note about the change_vol function Bob. I've changed the script and now use the relative flag which made that problem go away. I also made some important changes to the modulation - it's now possible to set the dynamical range of velocity→volume (_velrange_) and modwheel→volume (_modrange_) modulation separately. Raise the knob values to make the bottom velocities/CC values sound quieter. It's also possible to assign a CC which can be used to turn the xfade mode on or off. If the CC is not set (CC=0) the xfade mode is always on. 

I have tested the script during development and everything seems to be working fine now. The one thing I'm not completely sure of is what dynamical range to use for velocity→volume modulation when the xfade mode is off (since the native K2 modulation has been deactivated the script must recreate the effect). Furthermore, after a note has been released one cannot influence its xfading using the mod-wheel, even if it has been sustained using the sustain pedal. Apart from these things I think the script is in a state where it can be used now.

Btw. http://nilsliberg.se/ksp/scripts/help_reset_velocity_modulation.jpg (here's an image) explaining how one turns velocity modulation off, which is needed before using the script.

http://nilsliberg.se/ksp/scripts/NLCrossfadeV05.html (source code).
http://nilsliberg.se/ksp/scripts/NLCrossfade5_compiled.txt (compiled script) (can be pasted into Kontakt)
http://nilsliberg.se/ksp/scripts/NLXFadeV0.5.zip (script preset file)





Cheers,
Nils


----------



## Moonchilde (Jan 11, 2007)

This looks awesome. Nice work, haven't been able to try it out yet.


----------



## kotori (Jan 11, 2007)

I added this crossfade script and instructions to http://nilsliberg.se/ksp/scripts/scripts.html (my scripts page).
I also added a paypal donation link there in case someone would like to contribute to and encourage the development of this script and my script editor. 

Cheers,
Nils


----------



## Big Bob (Jan 12, 2007)

I think the Paypal link is a great idea! Your editor alone is well worth the price of admission  . 

God Bless,

Bob


----------



## Christian Marcussen (Jan 12, 2007)

In simple non-programmer langauge - how is this scrip different fromyour other crossfade script?

Thanks


----------



## kotori (Jan 12, 2007)

Thank you very much Bob!

I have already received three donations. I'm very grateful for this and see this as a great encouragement. In fact, it encouraged me to take the time to make a couple of improvements to the Script Editor today. More about this later. :smile: 
I don't know what's more appropriate - to thank people publicly by mentioning their names or direct my sincere thanks to 'you know who you are'. I'd like to do the former, but at the same time I don't want to put any press on anyone since I like the voluntariness. Any ideas about the best way to go about this? Anyway, thanks again for these generous donations. And please keep in mind that I'm greatful for every donation, however small they are.

Christian, the earlier script had a couple of problems whereas this script is working as far as I have seen (although it hasn't been tested that much since it's pretty new), so this script is meant to replace the earlier one. This script also provides settings for dynamical ranges for volume modulation and CC control with which it can be activated/deactivated.

Cheers,
Nils


----------



## Big Bob (Jan 12, 2007)

Hi Nils,

So glad to hear that the money has started to roll in for you. :wink: 

I would vote for the 'you know who you are' approach for two reasons. Personally, if I were to make a contribution, I wouldn't expect or want any public recognition because of it (and possibly others might feel the same way). Secondly, those who would like to contribute but can't do so at this time might feel a little uncomfortable and perhaps pressured.

But, this is just my 2 cents worth, any way you choose is OK with me  .

God Bless,

Bob


----------



## Fernando Warez (Jan 12, 2007)

Nils, i think Bob is right. But that doesn't mean you shouldn't remind us every chance you get how much work it took to make those script, and that it's in our best interest to see more development etc.. 

BTW, i see nothing in your signature. :wink:


----------



## kotori (Jan 13, 2007)

Hi Bob and Fernando,
Yes I decided not to publish any names. So, thanks again to 'you know who you are'.  

Regarding the status of the crossfade script my plan is to announce it on other forums once I've got some reports that it's working ok for people and that my usage instructions are not too unclear. So all feedback is very welcome.

Cheers,
Nils


----------



## kotori (Jan 13, 2007)

Btw. this script does not yet support release triggers. I forgot to mention this. I plan to add it though.


----------



## lee (Jan 16, 2007)

I cant seem to make the script work in K2.11 Can you confirm this Nils? I´m about to upgrade to 2.2, and certainly will if it´s needed to make your script work.

Another thing, when you say it doesnt work with releasetriggers, that means it doesnt work with the perf leg instruments of opus, right?

I agree with Big Bob about the "you know who you are"-approach. Big Bob is a wise man!

About the velrange, do you think the NI-programmers would be kind enough to give you some hints, if you mailed them?

/Johnny


----------



## kotori (Jan 16, 2007)

Hi Johnny,
You're right, it needed K2.2 to work. This was because of me setting the default value of two knobs (so that one can Ctrl+Click on them to reset the value to the default). Since this isn't very important I removed those lines. I plan some other changes so I only changed the http://nilsliberg.se/ksp/scripts/NLCrossfade5_compiled.txt (compiled source) for now. Please try to install the script this way.

The script seems to work with the perf leg instruments of opus. I haven't tried triggering release samples for these instruments, but my guess is that it'll work since these release samples probably are triggered using their legato script instead of the native Kontakt way.



lee @ Tue Jan 16 said:


> About the velrange, do you think the NI-programmers would be kind enough to give you some hints, if you mailed them?


Unfortunately I don't have their mail address? 
However, even if the dynamical range was set to the same as that of the original instrument the volume response would still differ since I use Bob's audio taper. What this means is that this script should give a more linear volume response to velocity changes, eg. the volume change between velocities 50 and 100 should be approximately double the volume change between velocities 50 and 75 (in dB). Normally in K2 this is not true due to non-linearities.

Cheers,
Nils


----------



## lee (Jan 16, 2007)

I was impatient :oops: , and have already begun upgrading to 2.2. I hope it´s not a bad idea.

Edit: However after reading comments about more crashes in 2.2 than in 2.1 I will try to go back to 2.11. Systemåterställning! <-swedish

Will try it with the perf leg instruments later.

Btw, have you thought about making a Instrument A --xfade--> Instrument B script using the same brilliant math library? Similiar to the one dynamitec wrote (I think).

Another thing. If I remember right I tried an earlier version of your script, and I think I didnt have to turn of the vel->amp modulator in k2, since that control sort of vanished automatically as you turned on the x-fade. Can that be true? Then you were able to use the "native" vel control except when you wanted to xfade. (?)

/Johnny


----------



## kotori (Jan 16, 2007)

Hi again Johnny!



> Btw, have you thought about making a Instrument A --xfade--> Instrument B script using the same brilliant math library? Similiar to the one dynamitec wrote.


I hadn't thought about it until you brought it up, but it might be a good idea. It's much simpler to implement. However, first I'd like to make the current script more efficient.

In my other script I think I had some option to let the script deactivate velocity->volume modulation and also reactivate it. I have not made up my mind if I'm going to implement that in this new version as well. The positive side of it is that it's more user-friendly, the negative side is that if a user unloads the script without restoring these modulations the instrument has been change possibly without his/her knowledge.

/Nils


----------



## lee (Jan 16, 2007)

Nils:I see. Well, I understand if you´re not sure about what do to about the activate/deactivate function. However, isnt it positive to have the same vel->volume response for all your instruments, including from different libraries?

I`ve found the old script here: http://vi-control.net/forum/viewtopic.php?t=4644 I´ll check it out and try and implement that function to your new script myself. (well, at least I can try!)

Oh, and the ability to choose what cc for x-fading might be good to have in the new script too. IMHO.

/Johnny


----------



## kotori (Jan 16, 2007)

lee @ Tue Jan 16 said:


> Nils:I see. Well, I understand if you´re not sure about what do to about the activate/deactivate function. However, isnt it positive to have the same vel->volume response for all your instruments, including from different libraries?


Yes, but that's why I encourage users to manually remove the vel->volume modulation. I just had a look at my earlier script, but I think it will turn off all external modulation of group effects/amplifier and I don't know if it's possible to do anything much better given the limitations of KSP. That's not acceptable so I think the manual approach will have to do. Please send me a PM if you still would be interested in the old script.

Cheers,
Nils


----------



## lee (Jan 16, 2007)

I see. I should have understood that you had good reasons for it! I think I found the old script, but thanx anyway. Considering the opus basic instruments, maybe there´s not too much external modulation anyway?

Maybe NI will fix the volume response in future updates.

/Johnny


----------



## Mr. Anxiety (Jan 16, 2007)

Great Work Nils!

I am about to dig into your new script. I haven't updated to K2.2 yet, so I guess that's next. I was really trying to integrate your older script into my set-up, but the incompatability with the SIPS legato script was frustrating. Does this new script live with the SIPS legato script? Any thoughts how to get them to live together, slot order, etc?

Thanks Again,

Mr. A.


----------



## kotori (Jan 16, 2007)

Hi Mr A.,
Unfortunately this script, like any other script that generates multiple notes from a single incoming, is not compatible with SIPS either. The problem is the same as before, if this script precedes SLS then the monophonic SLS will be confused by the multiple notes generated and won't know how to pair them up, and if this script comes after SLS the connection will be lost between the incoming SLS note and my velocity layer notes so that SLS's modulation won't affect my notes. This might have been easy if there were some way to instruct Kontakt to connect my notes to the incoming one, so that any SLS pitch-bend/volume-change would automatically be mirrored to my notes. Maybe it would be possible to change SLS slightly into actively passing that volume/tuning information on and let my script poll for changes at the same interval at which SLS updates the information (100µs) - some quick tests showed that this approach may be feasible. I'm going to do some real tests when I have time.

Cheers,
Nils


----------



## Mr. Anxiety (Jan 16, 2007)

Thanks Nils,

What a day that will be. Legato and Mod Xfade. Then we'll have quite the expressive solo instrument set-up for K2!!!!

Thanks,

Mr. A.


----------



## Moonchilde (Jan 17, 2007)

Nils! This new Xfade script is FANTASTIC!! It works in conjunction with UTKT too! It has to be first in the chain though. But it all works together finally!

Keep up the great work!


----------



## lee (Jan 17, 2007)

I have reverted to K2.11 from K2.2 and can confirm that the compiled downloadable version in this thread works great with K2.11.

Thanx Nils!
/Johnny


----------



## lee (Jan 19, 2007)

I have an idea about having a wider modrange, so you can make xfades from silence to maximum volume. Since many orchestral instruments have a very wide dynamic range. Just a suggestion!

I understand you probably have more complex things to think about, reading the suggestion from Mr Big Bob. I wish you both good luck, whatever you do or dont!

/Johnny


----------



## kotori (Jan 19, 2007)

Hi Johnny,
I posted an updated version of the crossfade script.

Changes:
* maximum dynamical range increased
* more efficient (no polling)
* support for release samples in K2.2.

Cheers,
Nils


----------



## lee (Jan 19, 2007)

Great!!

Before I download, is the new version K2.11-compatible? <---Nevermind, I now read the text at your homepage!  
 ò¨‹


----------



## gmet (Jan 30, 2007)

Nils, Another great offering - Thanks.

I wonder if the ideas presented here (using EQ): http://www.vi-control.net/forum/viewtopic.php?t=5067 could be incorporated into your script for added realism with wind instruments. As far as I can tell effects can be controlled from within a script but I am not competent enough at scripting to implement it.

Justin


----------



## Thonex (Mar 16, 2007)

Hi Nils,

I think I spotted a little problem with this otherwise perfect script.

There is some volume jumping when new notes are triggered and the CC is just moved slightly. Let me explain.

Say you have a sustained string and it is 3 velocity layers deep. play a note and start riding the CC1 from 0 to say 60. let go of that note. Now play a new note and move the CC1 from 60 (where it just was) to 61... or 59 (it doesn't matter... just a small amount to illustrate the problem) and you hear a jump in volume. It's as if the Script forgot what volume was calculated for the CC position of the previous note.

I hope I'm explaining this ok.

Let me know if you would like some clarification.

Regardless... this script is absolutely amazing!!!!


Cheers,

T


----------



## kotori (Mar 17, 2007)

Hi Andrew,
What Kontakt version are you using and is this with the latest script version (the one available on my web page)?


----------



## Thonex (Mar 17, 2007)

kotori @ Sat Mar 17 said:


> Hi Andrew,
> What Kontakt version are you using and is this with the latest script version (the one available on my web page)?



I'm using K2.1.1 and I got the script from the link on the first post of this thread. Maybe that's not the most recent 1. I'll try to find a more recent 1 and report back later this weekend.

*[EDIT] I just went to your website scripts directory and found that indeed the scrpt I was using was an older version. Sorry about that. I'll try V6 later and see if that problem still remains.*


Cheers,

T


----------



## Fernando Warez (Mar 17, 2007)

I finally had a chance to try the script! Love it! 8) 

Well done Nils and thank you!

o-[][]-o


----------



## kotori (Mar 17, 2007)

This was indeed a problem in earlier versions (because of the change_vol K2 bug), but it is fixed in the latest versions.

/Nils

_Edit: thank you Fernando.  
I hope to get some time to make it compatible with SIPS as well. Bob has been most helpful with this but unfortunately I have had extremely little time since I've had to concentrate my work on some instruments to be presented at Musikmesse, so I haven't yet got a chance to reward his helpfulness. _


----------



## Fernando Warez (Mar 17, 2007)

kotori @ Sat Mar 17 said:


> This was indeed a problem in earlier versions (because of the change_vol K2 bug), but it is fixed in the latest versions.
> 
> /Nils
> 
> ...



Take your time. :wink: 

And thank you Bob! o-[][]-o


----------



## Thonex (Mar 20, 2007)

HI Nils,

I tried loadng the K2.1 version of yur equal x-fade script in to a patch via the scripts preset menu and it crashed K2.

I then launched K2 again with an empty templaye, called up 1 patch and tried to bring your scrpt in again from the presets menu... and it crashed again.

Do you hav any ideas what the problem is?

Thanks,

T


----------



## kotori (Mar 20, 2007)

Hi Andrew,
Maybe the preset file format is not compatible. I'm currently not at home, but I'll try to provide a link to the source code when I return.

Cheers,
Nils


----------



## Thonex (Mar 20, 2007)

THanks Nils!!!


----------



## lee (Mar 21, 2007)

I suspect this could be the same issue as I had, Nils. When you gave me the edited for johnny-file instead of the downloadable one from your site.

Maybe you could test this one, thonex: http://nilsliberg.se/temp/NLXV06_compiled_for_Johnny.txt (http://nilsliberg.se/temp/NLXV06_compil ... Johnny.txt)

I also had crashes when loading the k2.1 version from Libergs homepage. But that one above seemed to work good. (it also has some semi-automatic way of finding releasegroups in kontakt, which works for my vsl opus)

/Johnny


----------



## Thonex (Mar 21, 2007)

lee @ Wed Mar 21 said:


> I suspect this could be the same issue as I had, Nils. When you gave me the edited for johnny-file instead of the downloadable one from your site.
> 
> Maybe you could test this one, thonex: http://nilsliberg.se/temp/NLXV06_compiled_for_Johnny.txt (http://nilsliberg.se/temp/NLXV06_compil ... Johnny.txt)
> 
> ...



Thanks Johnny!!!! :D 

THat did the trick!!!

@ Nils.... man... I've gotta say... this is truly an awesome script. Very smooth.... beautiful to look at.... and all sorts of great ideas in the coding!!!

Thanks for all your hard work Nils... truly inspiring!!!


----------



## lee (Mar 21, 2007)

On Nils behalf: You´re welcome Thonex.

Nils is one truly inspiring guy!
/Johnny


----------



## user002 (Dec 7, 2007)

/\~O 

Joined just to say thanks for this great script, Nils. I'll have to donate something when I start getting paid for this. Just great work!

Thoughts for additional features:
-Crossfade activation thru keyswitches
-Crossfading between different velocities AND groups(might not be possible ?)
I mean for example that you have an instrument with 2 groups, let's say a nonvibrato and vibrato group both with multiple velocity layers. Crossfading between velocitylayers 
with one CC# while crossfading between the two groups with another CC# would be great... Tho as this isn't programmable normally in kontakt like velocity crossfades this probably won't work with the script either...
-Group-specific activation (making it possible to have many articulations with individually activatable xfades within one instrument)


----------



## dr (May 26, 2010)

Hi Nihls/ Big Bob, 

Any updates in getting your 2 brilliant scripts to work together. Would be amazing to have legato and velocity crossfading (assigned to breath or other expression controller) working together. 

Best,

David


----------



## Big Bob (May 26, 2010)

I'm afraid that was a project we never finished :( .

Sorry,

Bob


----------



## dr (May 27, 2010)

Hi Big Bob thanks for your reply!

That's too bad to hear. You guys have both done some great work. 

Is there any way to get some form of volume control (assignable to a midi expression controller) while using your script?

I dont know if you are using Kontakt 4 but I tried to use your script with the included VSL instruments and I often get stuck notes. It seems NI have included a further stripped down version of the VSL library now which has no legato or velocity xfading for expression. There are legacy versions in there with the included VSL legato scripting but still not crossfading. Further, they dont seem compatible with the scripts you guys have worked so hard on. 

Any suggestions for getting the most out of these libraries any older libraries using your scripts?


----------



## Mr. Anxiety (May 27, 2010)

I 2nd this request. I also realize this is something you both have graciously given to our community, and to ask for more seems to be pushing it. Although I have donated a bit throughout the years, I and hopefully many others would be more than happy to give more for a future update if we could organize something.

Mr A.


----------



## dr (May 28, 2010)

It's just amazing how these scripts can really breathe new life into older libraries. Using them together would just take things to a whole new level. 

Currently my workaround when I want to use legato i just assign the group volume to CC#1 or 2. Is there a better way?


----------



## Big Bob (May 28, 2010)

Hi dr,



> Is there any way to get some form of volume control (assignable to a midi expression controller) while using your script?



Maybe I don't understand the question but, what prevents you from assigning CC11 to control volume (either at the group or the instrument level)?



> I dont know if you are using Kontakt 4 but I tried to use your script with the included VSL instruments and I often get stuck notes.



I've had almost zero time with K4 so far, so, I'm afraid I can't provide any insight as to what may have changed (insofar as running SIPS with K4).

Hi Mr A,



> I 2nd this request. I also realize this is something you both have graciously given to our community, and to ask for more seems to be pushing it. Although I have donated a bit throughout the years, I and hopefully many others would be more than happy to give more for a future update if we could organize something.



So much has changed (for the better) since Nils and I had to set aside our integrstion efforts 'temporarily'. If either or both of us were to resume the effort, I'm sure it would be much cleaner to start over completely (rather than to try to build on what we had started so long ago). However, I personally don't know when I would be able to spend any time on this and I think that Nils is probably even busier than I am. But, who knows, maybe some day. :roll: 

God Bless,

Bob


----------



## NOX (May 29, 2010)

SIPS 2 will work pretty good in K3 but
K4 presents some serious obstacle for SIPS to work smoothly.

Too bad cause scripted SIPS legatos are unique, musical, unmatched.

So the SIPS scripts will pull out any old sample library out of obsoleteness
but not in K4, unfortunately...


----------



## NOX (May 29, 2010)

SIPS 2 will work pretty good in K3 but
K4 presents some serious obstacle for SIPS to work smoothly.

Too bad cause scripted SIPS legatos are unique, musical, unmatched.

So the SIPS scripts will pull out any old sample library out of obsoleteness
but not in K4, unfortunately...


----------

