/ HALion Developer Resource / HALion Script / Reference /
onLoadSubPreset
onLoadSubPreset(section, data)
Description
This callback function is called when loading a subpreset with a corresponding Preset Browser template. The callback will only be called if the scope of the Preset Browser template is set correctly.
- If the MacroPage with the Preset Browser template is attached to an element other than the script module (e.g., the program), the scope must be set to the script module (e.g., @0:Script Module).
- If the MacroPage with the Preset Browser template is attached to the script module, the scope does not need to be set.
In addition, the Preset Browser Custom template allows you to define a section for the subpreset. When you load a subpreset, the defined section and the data stored in the subpreset will be passed on to the callback. The data is the same data that was returned by onSaveSubPreset when the subpreset was saved. You can manage different subsets of parameters by using the section as condition for an if
statement that restores only the parameters of interest.
❕ Scope and section are template parameters. You can set them in the MacroPage Designer on the properties pane of the Preset Browser and Preset Browser Custom templates.
Available in: Controller.
Arguments
Argument | Description | Value Type |
---|---|---|
section | The section as defined in the Preset Browser Custom template. | string |
data | The data that was returned by onSaveSubPreset. |
Example
--[[
The corresponding MacroPage needs two Preset Browser templates:
One with the section set to Pitch and the other with the section set to Filter.
The Preset Browser template with the section Pitch stores/restores the
parameters Pitch.Coarse and Pitch.Fine.
The Preset Brrowser template with the section Filter stores/restores the
parameters Filter.Cutoff and Filter.Resonance.
--]]
-- Get the values of p1 and p2 from the first zone of the program.
function getZoneData(p1, p2)
local data = {}
local zone = this.program:findZones(true)
if zone[1] then
data.p1 = zone[1]:getParameter(p1)
data.p2 = zone[1]:getParameter(p2)
end
return data
end
-- Set the values of p1 and p2 in the first zone of the program.
function setZoneData(p1, p2, data)
local zone = this.program:findZones(true)
if zone[1] then
zone[1]:setParameter(p1, data.p1)
zone[1]:setParameter(p2, data.p2)
end
end
-- Save data with the subpreset.
function onSaveSubPreset(section)
if section == "Pitch" then
return getZoneData("Pitch.Coarse", "Pitch.Fine" ) -- This is called from the preset template Pitch.
elseif section == "Filter" then
return getZoneData("Filter.Cutoff", "Filter.Resonance") -- This is called from the preset template Filter.
end
end
-- Restore data from the subpreset.
function onLoadSubPreset(section, data)
if section == "Pitch" then
setZoneData("Pitch.Coarse", "Pitch.Fine", data) -- This is called from the preset template Pitch.
elseif section == "Filter" then
setZoneData("Filter.Cutoff", "Filter.Resonance", data) -- This is called from the preset template Filter.
end
end
See also: onSaveSubPreset