startWriteOutputToFile, stopWriteOutputToFile and other undocumented functions

Recently I tried to experiment with metatables and lua environment in general. So I thought I’d check what global variables are used by Halion.

--print globals
--set Max Lines to 1000
local g = {}
for k in pairs(_G) do table.insert(g, k) end
table.sort(g)
for _, v in ipairs(g) do print(v) end

This should print:

AudioFile
AudioOutput
Bus
Container
DebugLevel
Effect
Element
Event
EventType
Instance
KeySwitchType
Layer
LoadProgress
LuaElement
MessageBoxResult
MessageBoxType
MidiFileFormat
MidiModule
ModulationDestination
ModulationMatrixRow
ModulationSource
NoteExpressionType
ParameterDefinition
Program
QCAssignmentMode
Serializable
Slot
UIScriptModule
UndoContext
Zone
_G
_VERSION
__internal
addLayerPassword
afterTouch
assert
assignAutomation
beat2ms
bit32
changeNoteExpression
changePan
changeTune
changeVolume
changeVolumedB
class
clone
collectgarbage
controlChange
debug
debugFunction
debugger
defineModulation
defineParameter
defineSlotLocal
dofile
endUndoBlock
error
fade
forgetAutomation
getAllocatedMemory
getAutomationIndex
getBarDuration
getBeatDuration
getBeatTime
getBeatTimeInBar
getCC
getContext
getElement
getFreeVoices
getHostName
getHostVersion
getKeyProperties
getKeySwitches
getMsTime
getNoteDuration
getNoteExpression
getNoteExpressionProperties
getProcessedSamples
getProductName
getProductVersion
getSamplingRate
getScriptExecTimeOut
getScriptVersion
getSlotIndex
getTempo
getTime
getTimeSignature
getUndoContext
getUsedMemory
getUsedVoices
getUsedVoicesOfSlot
getUserPresetPath
getVoices
getmetatable
insertEnvelopePoint
insertEvent
ipairs
isKeyDown
isNoteHeld
isOctaveKeyDown
isPlaying
load
loadPreset
loadPresetAsync
loadfile
loadstring
math
messageBox
module
ms2beat
ms2samples
next
openURL
package
pairs
pcall
pitchBend
playNote
playTriggerPad
postEvent
print
printRaw
property
rawequal
rawget
rawlen
rawset
readMidiFile
releaseVoice
removeEnvelopePoint
require
resolveAlternateData
resolveStorageString
runAsync
runSync
samples2ms
savePreset
select
setDebugLevel
setDebugLevelController
setDebugLevelProcessor
setScriptExecTimeOut
setmetatable
sortEvents
spawn
startUndoBlock
startWriteOutputToFile
stopWriteOutputToFile
string
super
table
this
tonumber
tostring
type
unpack
wait
waitBeat
waitForRelease
writeMidiFile
xpcall

Some of the items on the list aren’t documented anywhere. Maybe they are not meant for the end user but it would be great if a developer could comment on that.


I tried some of them (trial and error):

startWriteOutputToFile, stopWriteOutputToFile

--startWriteOutputToFile(filename: string [, append: boolean [, onlyToFile: boolean]])
--stopWriteOutputToFile()
startWriteOutputToFile("D:/Desktop/Halion.txt", false, true)
print("Program name: "..this.program.name)
stopWriteOutputToFile()

savePreset

--savePreset(path: string, layerOrProgram: object [, class ID?])
--returns: boolean
local layers = this.parent:findLayers()
local folder = "D:/Desktop"
for _, layer in ipairs(layers) do
  local saved = savePreset(folder.."/"..layer.name..".vstpreset", layer)
  if saved then print(string.format("Preset %q saved", layer.name)) end
end

Interesting. What was the result of running the two items? Did they both actually create new files?