Skip to content

Instantly share code, notes, and snippets.

@anderseklov
Forked from dhilowitz/SFZ Export.lua
Created January 28, 2022 18:12
Show Gist options
  • Save anderseklov/38b0d581ce43b2c14b2e5ecebfa89ff9 to your computer and use it in GitHub Desktop.
Save anderseklov/38b0d581ce43b2c14b2e5ecebfa89ff9 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=" .. math.floor(g.tune*100))
for n,z in pairs(g.zones) do
local regionText = "<region>sample=" .. z.file ..
" volume=" .. z.volume ..
" tune=" .. math.floor(z.tune*100) ..
" 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