General Commands

disable_logging()

disable_logging(<type>)

Disables emission of messages, warnings or watched variable events to both the KONTAKT status bar and Creator Tools

<type>

The type of event the emission of which is deactivated. Use one of the following: $NI_LOG_MESSAGE, $NI_LOG_WARNING or $NI_LOG_WATCHING.

Remarks

  • Only supported in the init callback

Examples

on init
	disable_logging($NI_LOG_MESSAGE)
	disable_logging($NI_LOG_WARNING)
	disable_logging($NI_LOG_WATCHING)
end on

Keep the lines above commented out while development and bring them back in right before shipping your product to disable any debugging-related content

See Also 

watch_var()

watch_array_idx()

exit

exit

Immediately stops a callback or exits a function

Remarks 

  • exit is a very strong command. Be careful when using it, especially when dealing with larger scripts.

  • If used within a function, exit only quits the function but not the entire callback.

Examples

on note
	if (not(in_range($EVENT_NOTE,60,71)))
		exit
	end if
	{from here on, only notes between C3 to B3 will be processed}
end on

Useful for quickly setting up key ranges to be affected by the script

See Also 

wait()

stop_wait()

ignore_controller

ignore_controller 

Ignore a controller event in a controller callback

Examples

on controller
	if ($CC_NUM = 1)
		ignore_controller
		set_controller($VCC_MONO_AT,%CC[1]
	end if
end on

Transform the mod wheel into aftertouch

See Also 

ignore_event()

set_controller()

on controller

message()

message(<variable/text>) 

Display text in the status line of KONTAKT

Remarks 

  • The message command is intended to be used for debugging and testing while programming a script. Since there is only one status line in KONTAKT, it should not be used as a generic means of communication with the user. Use a label instead.

  • Make it a habit to write message("") at the start of the init callback. You can then be sure that all previous messages (by the script or by the system) are deleted and you see only new messages.

  • Messages defined in the init callback will only be displayed if the user manually applies the script by clicking on the APPLY button. These messages will not be displayed when an instrument loads and initializes the script automatically.

Examples

on init
	message("Hello, world!")
end on

The inevitable implementation of "Hello, world!" in KSP

on note
	message("Note " & $EVENT_NOTE & " received at " & ...
	$ENGINE_UPTIME  & " milliseconds")
end on

Concatenating elements in a message() command

See Also 

reset_ksp_timer

ui_label

set_text()

Transport and Timing: $ENGINE_UPTIME, $KSP_TIMER

note_off()

note_off(<ID-number>)

Send a note off message to a specific note

<ID-number>

The ID number of the note event

Remarks

  • note_off() is equivalent to releasing a key, thus it will always trigger a release callback as well as the release portion of a volume envelope. Notice the difference between note_off() and fade_out(), since fade_out() works on voice level.

Examples

on controller
	if ($CC_NUM = 1)
		note_off($ALL_EVENTS)
	end if
end on

A custom "All Notes Off" implementation triggered by the mod wheel

on init
	declare polyphonic $new_id
end on

on note
	ignore_event($EVENT_ID)
	$new_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,0)
end on

on release
	ignore_event($EVENT_ID)
	wait(200000)
	note_off($new_id)
end on

Delaying the release of each note by 200ms

See Also 

fade_out()

play_note()

play_note()

play_note(<note-number>,<velocity>,<sample-offset>,<duration>)

Generate a note, i.e. generate a note-on message followed by a note-off message

<note-number>

The note number to be generated (0 - 127)

<velocity>

Velocity of the generated note (1 - 127)

<sample-offset>

Sample offset in microseconds

<duration>

Length of the generated note in microseconds

This parameter also accepts two special values:

-1: releasing the note which started the callback stops the sample

0: the entire sample is played

Remarks 

  • In DFD mode, the sample offset is dependent on the Sample Mod (S.Mod) value of the respective zones. Sample offset value greater than the zone's S.Mod setting will be ignored and no sample offset will be applied.

  • You can retrieve the event ID of the played note in a variable by writing:

    <variable> := play_note(<note>, <velocity>, <sample-offset>, <duration>)

Examples 

on note
	play_note($EVENT_NOTE+12,$EVENT_VELOCITY,0,-1)
end on

Harmonizes the played note with the upper octave

on init
	declare $new_id
end on
on controller
	if ($CC_NUM = 64)
		if (%CC[64] = 127)
			$new_id := play_note(60,100,0,0)
		else
			note_off($new_id)
		end if
	end if
end on

Trigger a MIDI note by pressing the sustain pedal

See Also 

note_off()

set_controller()

set_controller(<controller>,<value>)

Send a MIDI CC, pitch bend or channel pressure value

<controller>

This parameter sets the type, and in the case of MIDI CCs, sets the CC number:

• A number from 0 to 127 designates a MIDI CC number

$VCC_PITCH_BEND indicates pitch bend

$VCC_MONO_AT indicates channel pressure (monophonic aftertouch)

<value>

The value of the specified controller:

• MIDI CC and channel pressure values go from 0 to 127

• Pitch bend values go from -8192 to 8191

Remarks

  • set_controller()cannot be used within an init callback. If for some reason you wat to send a controller value upon instrument load, use persistance_changed callback.

on note
	if ($EVENT_NOTE = 36)
		ignore_event($EVENT_ID)
		set_controller($VCC_MONO_AT,$EVENT_VELOCITY)
	end if
end on
on release
	if ($EVENT_NOTE = 36)
		ignore_event($EVENT_ID)
		set_controller($VCC_MONO_AT,0)
	end if
end on

If you have a keyboard with no aftertouch, press C1 instead

See Also

ignore_controller

Events and MIDI: $VCC_PITCH_BEND, $VCC_MONO_AT

set_rpn()/set_nrpn()

set_rpn(<address>,<value>)

Send a RPN or NRPN message

<address>

The RPN or NRPN address (0 - 16383)

<value>

The value of the RPN or NRPN message (0 - 16383)

Remarks

  • KONTAKT cannot handle RPN or NRPN messages as external modulation sources. You can however use these message for simple inter-script communication.

See Also

on rpn/nrpn

set_controller()

msb()

lsb()

Events and MIDI: $RPN_ADDRESS, $RPN_VALUE

set_snapshot_type()

set_snapshot_type(<type>)

Configures the KSP processor behavior of all five slots when a snapshot is saved and recalled

<type>

The available types are:

0: The init callback will always be executed upon snapshot change, afterwards the on persistence_changed callback will be executed (default behavior)

1: the init callback will not be executed upon loading a snapshot, only the on persistence_callback will be executed

2: same as type 0, but only KSP variables are saved with the snapshot

3: same as type 1, but only KSP variables are saved with the snapshot

Remarks

  • This command acts globally, i.e. it can applied in any script slot.

  • In snapshot type 1 and 3, the value of non-persistent and instrument persistence variable is preserved.

  • Loading a snapshot always resets KONTAKT's audio engine, i.e. audio is stopped and all active events are deleted.

Examples

on init
	set_snapshot_type(1)
	
	declare ui_knob $knob_1 (0,127,1)
	set_text($knob_1,"Knob")
	make_persistent($knob_1)
	
	declare ui_button $gui_btn
	set_text($gui_btn,"Page 1")
end on

function show_gui
	if ($gui_btn = 1) 		  												  			
        set_control_par(get_ui_id($knob_1),$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
	else
		set_control_par(get_ui_id($knob_1),$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	end if
end function

on persistence_changed
	call show_gui
end on

on ui_control ($gui_btn)
	call show_gui
end on

Retaining the GUI upon loading snapshots

See Also

on init

on persistence_changed