Skip to content

Instantly share code, notes, and snippets.

@dhilowitz
Last active October 25, 2023 16:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dhilowitz/4af789fd36e8a9f8b6b8764ad658828e to your computer and use it in GitHub Desktop.
Save dhilowitz/4af789fd36e8a9f8b6b8764ad658828e 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
@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