Creator Tools hanging on push

agoldgeier
agoldgeier Member Posts: 1 Newcomer
edited October 2024 in Scripting Workshop

I've used a script to load a bunch of samples into a new Group, but when I push, it gets stuck on "Assigning instrument". What are some potential reasons for this?

One thing I notice that is different about the zones I've created from my script vs the the zones I create manually is that the filenames begin with "…///Users" instead of "/Users"

I'm using an adapted version of Tutorial 2/7, here is my script:

-- Much of this is stolen from the Kontakt Creator Tools "Tutorial 2" and "Tutorial 7" script

-- 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.")
end


-- From https://stackoverflow.com/questions/1426954/split-string-in-lua
function parseFn (filename)
        local t={}
        for str in string.gmatch(filename, "([^%._]+)") do
            table.insert(t, str)
        end
        return t
end

local dynamicsMapping = {
    ["F"] = {["low"] = 50, ["high"] = 127},
    ["MP"] = {["low"] = 0, ["high"] = 80}
}

local groupNames = {"SUS"}
local basePath = scriptPath .. filesystem.preferred("/Raw Samples/")

-- instrument.groups:reset()
local samples = {}

for _, groupName in ipairs(groupNames) do
    -- Make new group
    local group = Group()
    instrument.groups:insert(0, group)
    group.name = groupName
    groupPath = basePath .. groupName .. "/"

    -- Load files into zones
    for _, filename in filesystem.directoryRecursive(groupPath) do
        if filesystem.isRegularFile(filename) then
            local parts = parseFn(filename)
            -- for a filename like "SUS_F_72.wav", parts should look like {SUS, F, 72, wav}
            local zone = Zone()
            group.zones:add(zone)
            zone.file = groupPath .. "/" .. filename

            local dynamic = parts[2]
            local root = parts[3]

            zone.velocityRange.low = dynamicsMapping[dynamic]["low"]
            zone.velocityRange.high = dynamicsMapping[dynamic]["high"]
            zone.rootKey = root
            zone.keyRange.low = root
            zone.keyRange.high = root

        end
    end
end


This discussion has been closed.
Back To Top