Skip to content

Instantly share code, notes, and snippets.

@dhilowitz
Last active January 28, 2022 18:12
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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
@dhilowitz
Copy link
Author

I've just updated to translate SFZ tune= opcode correctly.

@anderseklov
Copy link

Thanks for this, will be useful, with no quick tool (and free) around afik otherwise. Many around for EXS24 to SFZ or other formats, but not for Kontakt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment