# Kontakt scripts for Midi/audio - possible?



## Kranich (May 4, 2015)

Good Day,

Steve Porter kindly directed me to this site (thanks Steve).

Kontakt is my main instrument, however, I regularly run into two problems which, I am guessing, can only be overcome with two different Kontakt scripts.

1.  The first (and most pressing) issue has to do with the MIDI implementations of different keyboards.  At my home studio I use a Roland RD-700SX which works flawlessly.  However, I use a much simpler keyboard for local gigs, a Casio PX-110.  After quite a bit of experimenting I found that the two keyboards handle note-off events differently:  While the Roland sends a proper "note-off" command, the Casio sends a "note at zero volume" command.  The problem with that is, "note at zero volume" makes Kontakt believe it has to play twice as many notes as would be necessary - even "note at zero volume" counts as one voice.  Consequently, the CPU is taxed twice as hard and I need to double, sometimes triple the latency in Kontakt to achieve acceptable performance levels.

I made screenshots in Logic to illustrate the differences:

Roland RD-700SX:  https://farm9.staticflickr.com/8715/172 ... 4222_o.jpg
Casio PX-110:  https://farm8.staticflickr.com/7617/170 ... c848_o.jpg

As one can see, the Roland sends "note-off" whereas the Casio sends "note at zero volume".

So, do you think there might be a way of transforming the "note at zero volume" into a "note-off" command?


2.  My favourite piano is the 8dio 1969 Legacy Piano, and it is lovely.  However, there is a marked difference in tonality with one particular octave (notes #48-60), when compared with the rest of the instrument.  What I have done so far is load three instances of the piano into Kontakt and route notes #21-47 and #61-108 to Kontakt channels 1&2 and notes #48-60 to channels 3&4 so that I can apply an EQ to this particular octave.  This method sort of works but I am having problems with excessive memory usage and dropouts, in particular when using Kontakt inside Logic X.

So, I am looking for a way/script to be able to load only one instance of the instrument, but be able to route one octave (notes #48-60) to a different stereo output in Kontakt.

I would be very happy to pay for any help with these two issues. The first one in particular is troubling since I've tried several different keyboards (including Yamahas) and most displayed the same behaviour.

Many thanks!


----------



## d.healey (May 4, 2015)

Your first problem can be fixed really easily with this script


```
on note
    if ($EVENT_VELOCITY = 0)
        note_off($EVENT_ID)
    end if
end on
```


----------



## Kranich (May 4, 2015)

Hello TotalComposure, thank you for the quick reply!

I tried loading your script, however, I received an error message when I clicked "Apply". I tried the general script editor and the one inside the instrument. Please note screenshots:

https://farm8.staticflickr.com/7717/167 ... dd26_o.jpg

https://farm8.staticflickr.com/7753/171 ... ec48_o.jpg


----------



## Kranich (May 4, 2015)

TotalComposure @ Mon May 04 said:


> Your first problem can be fixed really easily with this script
> 
> 
> ```
> ...



Hello again!

I managed to paste the code into the Instrument editor, click "Apply", and the code was accepted. I also saved the script as a .nkp file.

However, the issue remains: Clicks and pops.

I spent a few more hours trying to figure out what is causing the glitches, and it appears my initial diagnosis was wrong. Not the Midi implementation of the note on/off commands, but of the sustain pedal. While the Roland interpolates between the extremes - 0 and 127 - the Casio appears to simply switch from 0 to 127. Screenshots here:

---------------------------------------------------------------------
Roland RD-700SX:  https://farm8.staticflickr.com/7783/171 ... f5c7_o.jpg

In Kontakt pedal down: https://farm8.staticflickr.com/7702/167 ... 2_o.jpg%22

In Kontakt pedal up: https://farm9.staticflickr.com/8839/173 ... b67e_o.jpg

--------------------------------------------
Casio PX-110: https://farm9.staticflickr.com/8801/167 ... 8534_o.jpg

In Kontakt pedal down: https://farm9.staticflickr.com/8840/167 ... 2679_o.jpg

In Kontakt pedal up: https://farm8.staticflickr.com/7743/171 ... a435_o.jpg

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

I am wondering, though, if my tools for monitoring Midi activity are adequate... However, I am now certain that the sustain command is causing the glitches. I verified that it is not the physical pedal.

BTW, not only the 8dio piano is suffering from the glitches, but also Alicia's Keys and Piano in Blue.

I am very sorry for the confusion and the long posts... Now, what to do..?

Thank you for reading.


----------



## d.healey (May 4, 2015)

My sustain pedal works in the same way 0 = off 127 = on, no in-between values and I don't have any issues, so this is possibly a problem specific to the libraries you are using


----------



## Kranich (May 4, 2015)

TotalComposure @ Mon May 04 said:


> My sustain pedal works in the same way 0 = off 127 = on, no in-between values and I don't have any issues, so this is possibly a problem specific to the libraries you are using



Yes, that is possible. Where can I look for the cause, though..? I am completely at a loss.

Is there a piece of software - either inside or outside Kontakt - that can monitor all Midi activity? I somewhat suspect that the glitches are caused by a command not displayed by the standard Midi Monitors in Kontakt or Logic.

To be sure, a few days ago I went to a couple of music shops to try out different keyboards. Two of the cheaper Yamahas caused glitches, two of the more expensive ones didn't. The Casio in our local jazz club is ok, too...


----------



## Reegs (May 4, 2015)

Kranich @ Mon May 04 said:


> Is there a piece of software - either inside or outside Kontakt - that can monitor all Midi activity? I somewhat suspect that the glitches are caused by a command not displayed by the standard Midi Monitors in Kontakt or Logic.



On PC: Midi-ox. http://www.midiox.com/
On Mac: MidiPipe. http://www.subtlesoft.square7.net/MidiPipe.html (Having never used it since I'm on PC I can't vouch for it but it seems to have the same feature set.)


----------



## willbedford (May 4, 2015)

Note off messages (0x8-) and note on messages (0x9-) with 0 velocity should both be detected by Kontakt as a note off; both are interchangeable. It's strange that you are having this problem. However, you might be able to filter out the extra notes by doing something like this:

```
on init
	declare %keys_down[128]
end on

on note
	if (%keys_down[$EVENT_NOTE]=1) {if this key is currently held, don't send the note-on message again}
		ignore_event($EVENT_ID) 
		note_off($EVENT_NOTE) {this line is only needed if the notes hang when you release them}
	else
		%keys_down[$EVENT_NOTE] := 1
	end if
end on

on release
	%keys_down[$EVENT_NOTE] := 0
end on
```


----------



## FriFlo (May 5, 2015)

Actually, with dense midi activity maybe polyphonoc aftertouch and verbose mode activated, the midi monitor itself can cause glitches in audio. Have you tried deactivating it?


----------



## Kranich (May 5, 2015)

Thank you all very much for your combined efforts!



Reegs @ Mon May 04 said:


> On PC: Midi-ox. http://www.midiox.com/
> On Mac: MidiPipe. http://www.subtlesoft.square7.net/MidiPipe.html (Having never used it since I'm on PC I can't vouch for it but it seems to have the same feature set.)



Thank you. I downloaded MidiPipe but couldn't get it to display any commands, but that might have been my mistake. However, I also found this app:

http://www.macupdate.com/app/mac/9950/midi-monitor

It works well and looks like this:

https://farm9.staticflickr.com/8760/171 ... c236_o.jpg



willbedford @ Mon May 04 said:


> Note off messages (0x8-) and note on messages (0x9-) with 0 velocity should both be detected by Kontakt as a note off; both are interchangeable. It's strange that you are having this problem. However, you might be able to filter out the extra notes by doing something like this:
> 
> ```
> ...snip...
> ...


----------



## Kranich (May 8, 2015)

TotalComposure @ Mon May 04 said:


> My sustain pedal works in the same way 0 = off 127 = on, no in-between values and I don't have any issues, so this is possibly a problem specific to the libraries you are using



Hello David, I thought I'd let you know that your above comment helped me greatly with pinpointing the problem.

I spent a few more hours with experimenting and found that one of my larger libraries, Evolution Rosewood Grand, does not suffer from glitches when played with the Casio keyboard. This means, it clearly is possible to create a CPU-intensive library that is not sensitive to the effects of varying implementations of the sustain on/off command.

I experimented with the settings in Kontakt some more and noticed something else: If I decrease the "DFD Preload Buffer Size" down to a few kB, I can avoid the glitches completely with at least some of my libraries, i.e., Piano in Blue and Alicia's Keys. That's a great relief.

The 8dio 1969 Legacy Piano still glitches occasionally even at the lowest "DFD Preload Buffer Size", so it is not useable in a live context.

I think I will get in touch with NI about this issue, perhaps there's something they can do to permanently fix it. I will also write to 8dio.

This leaves me with the second issue: How can I devide the entire range of an instrument into three segments and route them to different outputs in Kontakt? Could I perhaps hire someone to write a script... Any suggestions?


----------

