# Tuning all notes ?



## r0main (Aug 31, 2010)

Hello from France !
I'm a newbie in Kontakt Scripting and I would like to have the choice of the tune of each note but not obligatory with knobs (i will try this alone).

It's hard for me to understand K scripting, i'm so regular from Max/MSP...

The goal: Max/MSP control Kontakt with Midi, but we can't make quatertone...

Could anyone help me ?

Thank you very much,
It could be a good example for me to begin to script in kontakt.

R0main.


----------



## EvilDragon (Aug 31, 2010)

Kontakt scripting is actually easier than Max/MSP 

So, you need a tuning script for each note of the piano range (88 notes)? That is easy to solve with some easy scripting. Paste this to any slot in Script Editor (preferably the first one):


```
on init
	make_perfview

	declare ui_label $title (2,1)
	declare ui_label $current (2,1)
	declare ui_table %tune[88] (6,4,-100)
	declare ui_button $Clear

	declare $count
	declare $new_id
	declare %copy[88]
	declare !note_names [88]
	declare !notes[12]
	!notes[0] := "C"
	!notes[1] := "C#"
	!notes[2] := "D"
	!notes[3] := "D#"
	!notes[4] := "E"
	!notes[5] := "F"
	!notes[6] := "F#"
	!notes[7] := "G"
	!notes[8] := "G#"
	!notes[9] := "A"
	!notes[10] := "A#"
	!notes[11] := "B"
	
	$count := 0
	while ($count < 88)
		!note_names[$count] := !notes[($count+21) mod 12] & ((($count+21)/12)-2)
		inc ($count)
	end while

	set_text($title,"          Individual Key Microtuning")
	set_text($current,"")
	set_text($Clear,"         Clear")

	move_control($title,3,1)
	move_control($current,3,6)
	move_control($Clear,6,6)

	make_persistent(%tune)
end on

on ui_control($Clear)
	$count := 0
	while ($count < 88)
		%tune[$count] := 0
		inc($count)
	end while
	$Clear := 0
	set_text($current,"         Microtuning table cleared!")
	wait(1500000)
	set_text($current,"")
end on

on ui_control(%tune)
	$count := 0
	while ($count < 88)
		if (%tune[$count] # %copy[$count])
			set_text($current,"Note: " & !note_names[$count] & " detuned " & %tune[$count] & " cents")
		end if
		%copy[$count] := %tune[$count]
		inc($count)
	end while
end on

on note
	if (in_range($EVENT_NOTE,21,108))
		ignore_event($EVENT_ID)
		$new_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
		change_tune($new_id,%tune[$EVENT_NOTE-21]*1000,1)
	end if
end on
```


Didn't have time to comment the script out, but it's fairly easy to grasp if you know basics of programming - and since you're coming from Max, you should know at least a moderate amount of programming.

Enjoy!


----------



## r0main (Aug 31, 2010)

Ok, Greats Thanks for this, it's cool to take time for me.

But, Kontakt say me change_tune, change.... is not allowed in this callback type.

What is it ? Dont understand this problem... Come from the instrument ?

Thanks

Romain


----------



## EvilDragon (Aug 31, 2010)

Which Kontakt version are you using? Did you paste the script correctly? I have tested this in Kontakt 4.1.1 and Kontakt 3.5 and it works without any errors.


----------



## r0main (Aug 31, 2010)

I use kontakt 4 with factory selection, which is on download on the website...

Sorry and thanks.


----------



## r0main (Aug 31, 2010)

And, yes, I paste the script correctly.

It make me the same error on simple scripts


----------



## EvilDragon (Aug 31, 2010)

You mean free Kontakt Player 4? I think you cannot use custom scripts with it, you need to get the full version of Kontakt for this. Or, you can use the Script Editor for 15 minutes, then it closes down.

Anyways, there should be no errors of any kind.


----------



## Jake Johnson (Dec 15, 2010)

Wow, Dragon. Great script. I just used it to retune two notes on the Concert Grand that comes with Kontakt.

Hate to offer suggestions\make requests for a free script, but...:

1. Is there a way to make the diagram show a note name, or light up when one presses a key, as per Select zone with Midi in Kontakt's Mapping editor? Now, it's hit and miss finding the correct bar to drag up or down. Might be easiest to just have the note names along the bottom of the bars?

2. Is there a way to rescale it? Now, dragging one of the bars a very short distance changes the pitch by 7-8 cents, a big change, making it hard to judge smaller increments.

3. Is there a way to let the user enter numeric values, along the lines of double-clicking on a bar and then entering -2, for example, to lower the pitch by 2.3 cents. 

But hats off. This is already good. Saved me a lot of time. Opens the door to microtuning without having to use Scala.


----------



## Mike Greene (Dec 15, 2010)

Very cool script, Mario. It's very elegant in how it's done.

I do wonder, though - In the "on note" callback, why didn't you just use:
change_tune($EVENT_ID,%tune[$EVENT_NOTE-21]*1000,1)
instead of going through the process of making a $new_id note and using change_tune on that? I could be wrong, but I could swear I've done change_tune commands on the $EVENT_ID itself. Am I wrong is there some reason I'm missing?


----------



## EvilDragon (Dec 16, 2010)

Jake Johnson @ 16.12.2010 said:


> Wow, Dragon. Great script. I just used it to retune two notes on the Concert Grand that comes with Kontakt.
> 
> Hate to offer suggestions\make requests for a free script, but...:
> 
> ...



Hello! 

1. Perhaps, I'll see what can be done. For this table, typing names below the table is not an option, at least not for every note. Also, can't add anything below the table if you want it to remain K3 compatible. Might have to rearrange the controls then.

2. Hold Shift when editing the table, that gives you 1 cent increments  Ctrl+click resets the bar to 0!

3. KSP doesn't support fractional values. There MIGHT be a method of doing this (but please tell me to which decimal you want it to be precise, I think 1 or 2 decimals are mighty fine), but it would need a lot more values per bar in the table, which might get unwieldy to input. The script might need a rethink for making that possible, perhaps at a later date. You cannot input table values by keyboard, that's a KSP restriction. 


Mike, you're right, I dunno why I did that! 


Updating the script now...


----------



## EvilDragon (Dec 16, 2010)

Jake, I'm having a breakthrough here, you will be able to set the tuning per note in 2 decimals precision increments, AND you will be able to type in a value, sort of! Brace yourself...


----------



## hakibit (Jan 5, 2012)

It s not working with Mr sax from Sampelmodeling.
Also the own microtune script from Kontakt is not working.
Is their an other way??
Thank you.


----------

