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

Snapshot Effects


On this page:


It can be useful to save the properties and values of the effects that are used on a bus in a table, for example, if you want to manage effects via a script. The following script takes a snapshot of each effect and prints out a properly formatted Lua table containing the effect properties and values.

  1. Load a Lua Script MIDI module into the branch of the Program Tree which contains the bus and effects that you want to print out as a table.
  2. Load SnapshotEffects.lua with the Lua Script MIDI module.
  3. Go to the Parameter List.
  • Set the WithKeys parameter to On if you want to print out a table with the effect name as the key for the table entries.
  • Set the WithKeys parameter to Off if you want to print out the table entries as an indexed array.
  1. Change the Snapshot parameter to print the table to the Output of the Lua Script MIDI module.
  2. To use the printed table, copy and paste it from the Output into the script that manages the effects.

❕ For an example of using a table like this to manage effects via a script, see Creating an FX Chain or Creating an FX Rack.

Example

effects = {}

-- You can exclude parameters by adding them to this table.
excludedParameters = {"Enable", "Bypass", "Mix", "resetMaxGainRed"}

function excludeParameters(def)
	local exclude = false
	local name = string.lower(def.name)
	for i, parameter in ipairs(excludedParameters) do
		local name2 = string.lower(parameter)
		if name == name2  then
			exclude = true
			break
		end
	end
	return exclude
end

function onSnapshot()
	local bus = assert(this.parent:getBus(), "No bus found in the layer '"..this.parent.name.."'.")
	local foundFx = bus:findEffects()
	assert(foundFx[1], "No effects found on the bus '"..bus.name.."'.")
	effects = {}
	for i, fx in ipairs(foundFx) do
		local defs= fx.parameterDefinitions
		effects[i] = {}
		effects[i].name = fx.name
		effects[i].fxType = fx.moduleType
		effects[i].settings = {}
		for _, def in ipairs(defs) do
			local excluded = excludeParameters(def)
			if not excluded then
				if def.automatable and def.persistent and not def.readOnly then
					effects[i].settings[def.name] = fx:getParameterNormalized(def.name)
				end
			end
		end
	end
	printSnapshot()
	Snapshot = false
end

defineParameter("WithKeys", nil, true)

function printSnapshot()
	print("effects = {")
	for i, effect in ipairs(effects) do
		if WithKeys then
			-- Use the FX name without spaces as key for the table entries.
			local effectKey = string.gsub(effect.name, " ", "")
			printRaw(string.format("\t%s = {\n\t    name = %q,\n\t    fxType = %q,\n\t    settings = {", effectKey, effect.name, effect.fxType))
			for key, value in pairs(effect.settings) do
				key = string.gsub(key, "-", "_")
				printRaw(string.format("\n\t      %s = %s,", key, value))
			end
			print("\n\t  },\n\t},")
		else
			-- Print the table as an indexed array.
			printRaw(string.format("\t{ name = %q,\n\t  fxType = %q,\n\t  settings = {\n", effect.name, effect.fxType))
			for key, value in pairs(effect.settings) do
				key = string.gsub(key, "-", "_")
				printRaw(string.format("\t    %s = %s,\n", key, value))
			end
			print("\t  },\n\t},")
		end
	end
	print("}")
end

defineParameter("Snapshot", nil, false, function() if Snapshot then onSnapshot() end end)