Are you using Path Browser or Drop control on your macro page?
Try this script in program tree. Connect the Path Browser or Drop to script parameter Filename.
It should set the sample length, loop points if present and also change the zone name. Be aware of that when setting scope for waveform or Sample Display template.
function filenameChanged()
local zone = this.parent:findZones(true)[1]
local sample = AudioFile.open(Filename)
if sample.valid then
local name = string.sub(string.match(sample.fileName,"[^\\/]+$"),1,-5)
zone:setName(name)
zone:setParameter("SampleOsc.Filename", sample.fileName)
zone:setParameter("SampleOsc.SampleEnd", sample.length)
local rootKey = sample.rootKey
if rootKey then
zone:setParameter("SampleOsc.Rootkey", rootKey)
else
zone:setParameter("SampleOsc.Rootkey", 60)
end
local loops = sample.loops
if loops[1] then
zone:setParameter("SampleOsc.SustainLoopModeA", 1)
zone:setParameter("SampleOsc.SustainLoopStartA", loops[1].loopStart)
zone:setParameter("SampleOsc.SustainLoopEndA", loops[1].loopEnd)
else
zone:setParameter("SampleOsc.SustainLoopModeA", 0)
zone:setParameter("SampleOsc.SustainLoopStartA", 0)
zone:setParameter("SampleOsc.SustainLoopEndA", 0)
end
end
end
defineParameter("Filename", nil, "", filenameChanged)