Skip to content

Instantly share code, notes, and snippets.

@ZZKJInc
Forked from dhilowitz/SFZ Export.lua
Created March 27, 2021 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZZKJInc/807ad582de0352db248adf673c54ba7d to your computer and use it in GitHub Desktop.
Save ZZKJInc/807ad582de0352db248adf673c54ba7d to your computer and use it in GitHub Desktop.
Kontakt 6 Creator Tools LUA script for creating SFZ instruments. Outputs to console.
-- Check for valid instrument
if not instrument then
print("The following error message informs you that the Creator Tools are not "..
"focused on a Kontakt instrument. To solve this, load an instrument in "..
"Kontakt and select it from the instrument dropdown menu on top.")
return
end
print("// SFZ file for Kontakt 6 instrument " .. instrument.name)
print("")
--[[ Of course, all the above printed fields (name, volume and tune), as well as the rest of the
group fields are always displayed in the instrument's tree view.
In a similar way, you can also iterate over the zones of a group or a whole instrument.
--]]
local count = 0
for i,g in pairs(instrument.groups) do
local vol = g.volume
if vol < -144 then
vol = -144
end
print("<group>group_label=" .. g.name .. " volume=" .. vol .. " tune=" .. g.tune)
for n,z in pairs(g.zones) do
local regionText = "<region>sample=" .. z.file ..
" volume=" .. z.volume ..
" tune=" .. string.format("%.2f",z.tune) ..
" pitch_keycenter=" .. z.rootKey ..
" offset=" .. z.sampleStart ..
" end=" .. z.sampleEnd ..
" lokey=" .. z.keyRange.low ..
" hikey=" .. z.keyRange.high ..
" lovel=" .. z.velocityRange.low ..
" hivel=" .. z.velocityRange.high
if z.loops[0].mode == 0 then
regionText = regionText .. " loop_mode=no_loop"
else
regionText = regionText .. " loop_mode=loop_continuous"
local loopEnd = z.loops[0].start + z.loops[0].length - 1
regionText = regionText .. " loop_start=" .. z.loops[0].start .. " loop_end=" .. loopEnd
end
print(regionText)
-- print("")
count = count + 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment