/ HALion Developer Resource / HALion Tutorials & Guidelines / How-tos /

Key Range Limitation

The key range of a layer is usually C-2 to G8. In the following example, a Range Slider and a UI script are used to limit the key range of a layer to a definable range.

Example VST Preset

Key Range with Limitation

The following section describes how to access Templates and edit UI scripts.

To explore the templates in this example:

  1. Open the Macro Page Designer, go to the Templates Tree and select the template that you want to explore.
  2. Click Edit Element Edit Element to examine the template.

To edit the UI script:

  1. Open the Macro Page Designer and select the topmost element in the GUI Tree.
  2. Go to the Properties section and click Edit Script Edit Element to open the internal script editor.

Prerequisites

  • You have a program with a layer, a zone, and a macro page.

How the Elements Interact

Key Range

The Key Range template contains the Range Slider and Text controls that are needed to set and display the key range. The Low Value and High Value of the Range Slider and the corresponding values of the Text controls are exported as template parameters with the same names, LowValue for the low key and HighValue for the high key. The template parameters LowValue and HighValue are connected to the LowKeyLimit and HighKeyLimit parameters of the UI script.

Key Range Template

UI Script

The LowKeyValue and HighKeyValue parameters of the UI script are connected to the Low Key and High Key parameters of the layer, respectively, and they define the key range.

UI Script Connections

The maximum key range is defined by the lowKey and highKey variables in the UI script.

-- Variables and values to be used for the key range.
function setupKeyRangeParams()
	-- Moved into function to keep locals out of global table.
	local lowKey = 36
	local highKey = 96

	local paramDefLow = getElement():getParameterDefinition("LowKey")
	local paramDefHigh = getElement():getParameterDefinition("HighKey")
	local noteNames = {}
	for i = lowKey, highKey do
		noteNames[i - lowKey] = paramDefLow:getDisplayString(i):gsub(' ', '')
	end
	defineParameter("LowKeyValue",  nil, paramDefLow, function()  LowKeyLimit = LowKeyValue - lowKey end)
	defineParameter("HighKeyValue", nil, paramDefHigh, function() HighKeyLimit = HighKeyValue - lowKey end)


	function onLowKeyLimit()
		if LowKeyLimit > HighKeyLimit then
			LowKeyLimit = HighKeyLimit
		end
		LowKeyValue = LowKeyLimit + lowKey
	end
	function onHighKeyLimit()
		if LowKeyLimit > HighKeyLimit then
			HighKeyLimit = LowKeyLimit
		end
		HighKeyValue = HighKeyLimit + lowKey
	end
	defineParameter("LowKeyLimit",  nil, 0, noteNames, onLowKeyLimit)
	defineParameter("HighKeyLimit", nil, highKey - lowKey, noteNames, onHighKeyLimit)
end

setupKeyRangeParams()