High numbered keyswitches retuning

Sketch for Kontakt high numbered key switches retuning source code.

Status
This now runs okay and permits high keyswitch retuning of Kontakt instruments.

For the draft of the RPN spec see Tuning RPNs (specification draft). I've modified it here, instead of using the data increment and decrement, I do it using keyswitches

The keyswitches idea
This is the brilliant suggestion of Dr Ozan Yarman, The topmost notes of the midi range are rarely used in instruments - are well beyond the top notes of a piano.

Keyswitches are often used to change playing styles of instruments, but typically they use notes below the natural range of the instrument to do this. The high notes are normally not used for anything.

So the idea is to send the information using the note on velocities of the note numbers 124 to 127. In this script I also use note number 123 to send an extra ultra fine pitch resolution byte.

The instructions used in this script are: where v (note velocity) > 0, because a note on with velocity 0 is treated as a note off in Midi.

The pitch bend follows the same format as a standard midi pitch bend, except that the pitch bend range (just for these messages) is hard coded to +- 50 cents. So there are 16384 steps for the range -50 to 50, giving a pitch bend resolution of 0.0061 cents.

That is good enough for even the most demanding of microtonalists in almost all situations (in theory, you could notice a difference in tuning of less than a hundredth of a cent on a super accurately pitched instrument if you had polyrhythmic beating partials beating at different rates from each other but this situation is likely to be exceedingly rare).

I've added the extra fine pitch bend here mainly so that the numbers can be displayed accurately in Kontakt, and because Kontakt works internally with millicents, or a thousandth of a cent. This divides each of the pitch steps into a further 128 finer steps giving a resolution less than 0.00005 cents.

For v = 0 use

This script applies to all notes received by the instrument, it is multi channel if you load a different copy of the instrument in each midi channel - or else is omni if you load a single instance of the instrument set to receive midi notes on all channels. This script does not permit switching between omni and multi channel tuning mode.

Suggested instructions for synths that do are:

So - synths can be omni only, multi channel only, or optionally both and switchable by these instructions.

This script is for Kontakt only
This script relies on an unusual feature of Kontakt, you can modify the notes with a script AFTER the midi notes are received in the instrument. In this way, Kontakt lets you hack the inner workings of the instrument itself.

You can't do the same thing with a VST plug in because there is no midi message in the standard protocol to change the tuning of an individual note. Any VSTi would need to be reprogrammed to support this feature.

Similarly any software or hardware synths or samplers would need to have their code modified to use this feature.

How to use this
This script adds four knobs to the user interface for your instrument.

To retune any note on the keyboard to anywhere in the midi range, use the first knob to select the input note, second knob to select output note, third note to set pitch bend, and 4th knob to fine adjust the pitch bend in millicents

Later on I plan to release a version of Bounce Metronome able to send high numbered keyswitches to retune these instruments via midi, so e.g. you just need to select a SCALA scale from a drop list to retune all the notes to that scale.

Other programmers of retuning software will probably follow suit.

NOTE - BETA, WORK IN PROGRESS

How to add this script to a Kontakt instrument
Note, this is a BETA script - particularly since the spec itself is work in progress.

You need the full version of Kontakt to install this script. You can't use this with the free Kontakt Player as it doesn't have script editing capabilities (except briefly in demo mode).

However, I plan to create a few Kontakt instruments with this script already installed, for you to try out, using free Kontakt instruments with suitable licenses, or if I can get permission to adapt them. Authors of instruments for Kontakt will also be able to add this script to their instruments.

You can get the script here: kontakt_retune_with_high_keyswitches.txt

To add this script to a Kontakt instrument you click on the wrench icon then on Script Editor, then look for an empty slot labelled Click on tab to select it and then click Edit. Enter any desired title for the script and copy and paste my script into the edit field. Then click Apply and the knobs will appear and your instrument can now be micro-tuned in Kontakt.



Some instruments can't be retuned in this way because all four of the script slots are filled and are password protected. If the script slots are not password protected you might be able to merge my script with the script already there if you have some knowledge of how the scripts work.

So for instance Kontakt instrument designers could merge this script with their instrument scripts to make their instruments micro-tunable

which retunes InputNote to OutputNote + Pitch Bend (in cents, usual format)

see discussion here: Discussion of RPN retuning on facebook

For the undefined controllers method I use the undefined controllers 115 to 118 as follows to retune a note:

where the retuning info gets updated on receipt of the controller 118. So on receipt of controller 118 it uses the current values for controllers 115 to 118 to determine how to retune the input note as set by controller 115.

I also used

Here is the complete script, including diagnostics

Useful external links
http://www.sandymilne.com/category/kontakt-scripting/

http://nilsliberg.se/ksp/

http://www.soniccouture.org/tutorial/scriptorium-manual.pdf

http://www.audiotek.cz/produktyATK/ni/kontakt3_p2.pdf

http://www.soundonsound.com/sos/jul10/articles/kontakt1.htm

bug details
I've actually got this working now, successfully retuned a Kontakt instrument to 120-et using RPN retuning sending the RPN messages from a debug build of Bounce Metronome.

But ran into a curious issue. I have to leave a pause of 40 ms between each change of rpn like this:

RPN coarse: 101 RPN fine: NoteToRetune Data entry coarse 0 Data entry fine: NoteToRetuneTo

Sleep(40)

RPN coarse: 100 RPN fine: NoteToRetune Data entry coarse : Pitch bend MSB Data entry fine: Pitch bend LSB

Sleep(40)

If I set it to less than that e.g. Sleep(10) then it gets mixed up.

It will use e.g. the Pitch bend LSB as the NoteToRetuneTo, as if it never got the intervening RPN coarse and RPN fine messages.

Anyone know why that is necessary and whether there is a work around?

Note - never found a solution to this. Same thing happened with the undefined controllers retuning. Needed to have a sleep of about 10 ms between each controller sent. If sent without sleeps, then I found that the script only received 12 controller messages out of a batch of 512 controllers sent to Kontakt, in a test run.

But - the keyswitches idea solves this. Notes are high priority.