Skip to main content

Built-in Variables and Constants

General

$CURRENT_SCRIPT_SLOT

This variable returns the script slot of the current script (zero-based, i.e. the first script slot is 0).

%GROUPS_SELECTED[<group-idx>]

Each index of this variable array points to the group with the same index.

If a group is selected for editing, the corresponding array cell contains a 1, otherwise 0.

$NI_ASYNC_EXIT_STATUS

This variable returns a value of 1 if the command that triggered the on async_complete callback has successfully completed its action. 0 if the command could not complete its action, e.g. file not found. 

$NI_ASYNC_ID

This variable returns the ID of the command that triggered the on async_complete callback.

$NI_BUS_OFFSET

This constant is to be used in the <generic> part of the engine parameter commands to point to the instrument bus level. Add the index of the bus you wish to address, e.g. $NI_BUS_OFFSET + 2 will point to instrument bus 3.

$NUM_GROUPS

This variable returns the total amount of groups in an instrument.

$NUM_OUTPUT_CHANNELS

This variable returns the total amount of output channels of the respective Kontakt multi, not counting Aux channels.

$NUM_ZONES

This variable returns the total amount of zones in an instrument.

$PLAYED_VOICES_INST

This variable returns the amount of played voices for the current instrument.

$PLAYED_VOICES_TOTAL

This variable returns the amount of played voices for all instruments.             

$REF_GROUP_IDX

This variable returns the group index of the currently viewed group in Kontakt's instrument edit view.

Path Variables

$GET_FOLDER_LIBRARY_DIR

If used with a Kontakt Player encoded NKI: library folder.

If used with an unencoded NKI: the user content directory.

$GET_FOLDER_FACTORY_DIR

The factory folder of Kontakt, mainly used for loading factory IR samples.

Note: this is not the Kontakt Factory Library folder!

$GET_FOLDER_PATCH_DIR

The directory in which the patch was saved.

If the patch was not saved before, an empty string is returned.

Time Machine Pro Variables

User access for the two voice limits (Standard and High Quality) of the Time Machine Pro, to be used with set_voice_limit() and get_voice_limit().

$NI_VL_TMPRO_STANDARD

$NI_VL_TMRPO_HQ

Events and MIDI

$ALL_GROUPS

This constant addresses all groups in the instrument when used with disallow_group(), allow_group() or set_event_par_arr() functions.

$ALL_EVENTS

This constant addresses all events in functions which deal with an event ID number.

It also works with MIDI object commands that require a MIDI event ID.

$MARK_1 ... $MARK_28

These constants can be used to create a bitmask that is used to group events at will. It is intended to be used with by_marks() , set_event_mark(), get_event_mark(), delete_event_mark(), mf_set_mark() and mf_get_mark() commands.

%CC[<controller-number>]

This variable array contains the current value for the specified MIDI CC (continuous controller) message.

$CC_NUM

This variable contains the MIDI CC (continuous controller) number of the controller which triggered the on controller callback.

%CC_TOUCHED[<controller-number>]

This variable array updates itself whenever a MIDI CC value is changed - 1 if the specified MIDI CC value has changed, 0 otherwise.

$EVENT_ID

This variable contains the unique ID number of the event which triggered the on note or on release callback.

$CURRENT_EVENT

This variable contains the unique ID number of the currently selected MIDI event, i.e. the MIDI event at the position marker.

$EVENT_NOTE

This variable contains the note number of the event which triggered the on note or on release callback.

$EVENT_VELOCITY

This variable contains the velocity of the note which triggered the on note callback.

Event Parameter Constants

Event parameters to be used with set_event_par() and get_event_par():

  • $EVENT_PAR_0 ... $EVENT_PAR_3

  • $EVENT_PAR_VOLUME

  • $EVENT_PAR_PAN

  • $EVENT_PAR_TUNE

  • $EVENT_PAR_NOTE

  • $EVENT_PAR_VELOCITY

  • $EVENT_PAR_MIDI_CHANNEL

Event parameters to be used with set_event_par_arr() and get_event_par_arr():

  • $EVENT_PAR_ALLOW_GROUP

  • $EVENT_PAR_CUSTOM

  • $EVENT_PAR_MOD_VALUE_ID

  • $EVENT_PAR_MOD_VALUE_EX_ID

Event parameters to be used with get_event_par() only:

  • $EVENT_PAR_SOURCE (-1 if event originates from outside, otherwise slot number 0 ... 4)

  • $EVENT_PAR_PLAY_POS (Returns the absolute position of the play cursor within a zone in microseconds)

  • $EVENT_PAR_ZONE_ID (Returns the zone ID of the event- Can only be used with active events. Returns -1 if no zone is triggered. Returns the highest zone ID if more than one zone is triggered by the event. Make sure the voice is running by writing e.g. wait (1) before retrieving the zone ID!)

Event parameters to be used with set_event_par() and get_event_par() in multi scripts only:

  • $EVENT_PAR_MIDI_COMMAND

  • $EVENT_PAR_MIDI_BYTE_1

  • $EVENT_PAR_MIDI_BYTE_2

Event parameters to be used with mf_set_event_par() and mf_get_event_par():

  • $EVENT_PAR_POS

  • $EVENT_PAR_NOTE_LENGTH

  • $EVENT_PAR_ID

  • $EVENT_PAR_TRACK_NR

%EVENT_PAR[<event-par>]

This variable array contains values of $EVENT_PAR_0 ... $EVENT_PAR_3 along with $EVENT_PAR_CUSTOM indices 4-15, valid for $EVENT_ID.

Event Status Constants

These are values returned by event_status() command:

$EVENT_STATUS_INACTIVE

$EVENT_STATUS_NOTE_QUEUE

Multi script only:

$EVENT_STATUS_MIDI_QUEUE

%GROUPS_AFFECTED

This variable array contains indices of those groups that are affected by the current MIDI Note On or Note Off events.

The size of the array changes depending on the number of groups the event affects, so use the num_elements() command to get the correct array size.

The returned indices come before any allow_group() or disallow_group() commands, so it can be used to analyze the mapping of the instrument.

$NOTE_HELD

This variable contains 1 if the key which triggered the callback is still held, 0 otherwise.

%POLY_AT[<note-number>]

This variable array contains current values of MIDI Polyphonic Aftertouch for all MIDI note numbers.

$POLY_AT_NUM

This variable contains the note number of the MIDI Polyphonic Aftertouch event which triggered the on poly_at callback.

$RPN_ADDRESS

This variable contains the address of a received RPN or NRPN message (0 ... 16383).

$RPN_VALUE

This variable contains the value of a received RPN or NRPN message (0 ... 16383).

$VCC_MONO_AT

This constant specifies Virtual Continuous Controller for mono aftertouch (MIDI Channel Pressure message), mainly for use in on controller.

$VCC_PITCH_BEND

This constant specifies Virtual Continuous Controller for MIDI Pitch Bend messages, mainly for use in on controller.

%KEY_DOWN[<note-number>]

This variable array contains the current state of all keys. 1 if the key is held, 0 otherwise.

%KEY_DOWN_OCT[<note-number>]

This variable array contains 1 if a note, independent of the octave, is held. 0 otherwise. Due to this, the note number should be a value between 0 (C) and 11 (B).

Time and Transport

Date And Time Variables

These variables return the current date and time as set by the operating system, in form of integer values.

$NI_DATE_YEAR

$NI_DATE_MONTH (1 ... 12)

$NI_DATE_DAY (1 ... 31)

$NI_TIME_HOUR (0 ... 23)

$NI_TIME_MINUTE (0 ... 59)

$NI_TIME_SECOND (0 ... 59)

$DISTANCE_BAR_START

This variable returns the time of a MIDI Note On message in microseconds from the beginning of the current bar, with respect to the current tempo.

$DURATION_BAR

This variable returns the duration in microseconds of one bar with respect to the current tempo.

It only works if the clock is running, otherwise it will return 0.

You can also retrieve the duration of one bar by using $SIGNATURE_NUM and $SIGNATURE_DENOM in combination with various $DURATION_ constants.

$DURATION_QUARTER

This variable returns the duration of a quarter note in microseconds, with respect to the current tempo. Also available:

$DURATION_EIGHTH

$DURATION_SIXTEENTH

$DURATION_QUARTER_TRIPLET

$DURATION_EIGHTH_TRIPLET

$DURATION_SIXTEENTH_TRIPLET

$ENGINE_UPTIME

This variable returns the time period in milliseconds (not microseconds!) that has passed since the instantiation of Kontakt. The engine uptime is calculated from the sample rate and can thus be used in musical contexts, (eg. building arpeggiators or sequencers) as it remains in sync, even in an offline bounce.

$KSP_TIMER

This variable returns the time period in microseconds that has passed since Kontakt was instantiated.

It can be reset with reset_ksp_timer.

The KSP timer is based on the CPU clock and thus runs at a constant rate, regardless of whether or not Kontakt is being used in real time. As such, it should be used to test the efficiency of scripts and not to make musical calculations.

$NI_SONG_POSITION

This variable returns the host’s current song position at 960 PPQ (pulses per quarter note).

$NI_TRANSPORT_RUNNING

This variable contains 1 if the host's transport is running, 0 otherwise.

$SIGNATURE_NUM

This variable contains the numerator of the current time signature, i.e. 4/4.

$SIGNATURE_DENOM

This variable contains the denominator of the current time signature, i.e. 4/4.

Tempo Unit Constants

These constants are used to control the unit parameter of time-related controls (e.g. Delay Time, Envelope Attack etc.) with engine parameter variables like $ENGINE_PAR_DL_TIME_UNIT.

$NI_SYNC_UNIT_ABS (not synchronized to tempo)

$NI_SYNC_UNIT_WHOLE

$NI_SYNC_UNIT_WHOLE_TRIPLET

$NI_SYNC_UNIT_HALF

$NI_SYNC_UNIT_HALF_TRIPLET

$NI_SYNC_UNIT_QUARTER

$NI_SYNC_UNIT_QUARTER_TRIPLET

$NI_SYNC_UNIT_8TH

$NI_SYNC_UNIT_8TH_TRIPLET

$NI_SYNC_UNIT_16TH

$NI_SYNC_UNIT_16TH_TRIPLET

$NI_SYNC_UNIT_32ND

$NI_SYNC_UNIT_32ND_TRIPLET

$NI_SYNC_UNIT_64TH

$NI_SYNC_UNIT_64TH_TRIPLET

$NI_SYNC_UNIT_256TH

$NI_SYNC_UNIT_ZONE (only applies to the Speed parameter in certain Source module sampler modes)

%NOTE_DURATION[<note-number>]

This variable array contains the duration since note start in microseconds for each key. Mostly only makes sense in on release callback.

$NI_BAR_START_POSITION

This variable returns the start of current bar in ticks (at 960 PPQ) from the start of the host project.

Note: Since the AAX plugin format doesn't provide this information, this variable will return -1 in ProTools!

Callbacks and UI

$NI_CALLBACK_ID

This variable returns the ID number of the callback. Every callback has a unique ID number which remains the same within a user function.

$NI_CALLBACK_TYPE

These constants return the callback type of a specific callback ID. Useful for retrieving the callback type that triggered a specific user function. The following constants are available:

$NI_CB_TYPE_ASYNC_OUT

$NI_CB_TYPE_CONTROLLER

$NI_CB_TYPE_INIT

$NI_CB_TYPE_LISTENER

$NI_CB_TYPE_NOTE

$NI_CB_TYPE_NRPN

$NI_CB_TYPE_PERSISTENCE_CHANGED

$NI_CB_TYPE_PGS

$NI_CB_TYPE_POLY_AT

$NI_CB_TYPE_RELEASE

$NI_CB_TYPE_RPN 

$NI_CB_TYPE_UI_CONTROL

$NI_CB_TYPE_UI_CONTROLS

$NI_CB_TYPE_UI_UPDATE

Multi script only:

$NI_CB_TYPE_MIDI_IN

Knob Unit Mark Constants

These constants are to be used with set_knob_unit() or $CONTROL_PAR_UNIT.

$KNOB_UNIT_NONE

$KNOB_UNIT_DB

$KNOB_UNIT_HZ

$KNOB_UNIT_PERCENT

$KNOB_UNIT_MS

$KNOB_UNIT_ST

$KNOB_UNIT_OCT

$NI_UI_ID

This variable returns the ID of the UI widget which triggered the on ui_control or on ui_controls callbacks.on ui_controls

$NI_SIGNAL_TIMER_BEAT

$NI_SIGNAL_TIMER_MS

$NI_SIGNAL_TRANSP_START

$NI_SIGNAL_TRANSP_STOP

These constants can be used with set_listener() or change_listener_par() to set which signals will trigger the on listener callback.

$NI_SIGNAL_TYPE

This variable can be used in the on listener callback to determine which signal type triggered it.

$NI_KONTAKT_IS_HEADLESS

This variable returns 1 if the GUI of Kontakt is not available or loadable. Currently this is only possible when Kontakt is used in Maschine+. When Kontakt is used in a regular host, it will still return 0 even if the GUI is not visible.

$NI_KONTAKT_IS_STANDALONE

This variable returns 1 if Kontakt is running standalone, 0 if it's loaded as a plugin in a host.

Mathematical Constants

~NI_MATH_PI

This constant returns the value of π (approximately 3.14159…).

~NI_MATH_E

This constant returns the value of e (approximately 2.71828…).