Changing samples in the zone

I’m brand new to Halion scripting and I’m trying to change a sample zone without changing zone parameters in the macro page. I don’t want to change layers or presets as I want the current settings to stay while the sample is changed. I am also trying to get the waveform display to update the display with the newly loaded sample. Can this be done? I can get it working while Halion is open but when I reload the program it doesn’t work, I’m guessing it’s because the waveform display is looking for the linked zone name that has been changed. Is it also possible to point the display to a folder to change samples instead of a specific named file?

These two entries give a good overview of how the waveform should be connected.

https://developer.steinberg.help/display/HMP/Waveform
https://developer.steinberg.help/display/HMP/Sample+Display

For the wave:
If you tie a pathbrowser template to the SampleOsc.Filename parameter in the Zone parameter list, you can select files and it will swap out the wave without affecting the rest of the zone.

Thank you AposMus for your help,

I think the problem I have with the waveforms has something to do with how i’m trying to change the zones. I assigned “SampleOsc.Filename” to the pathbrowser and it works for a while but if I reopen the program later the zone has been changed to the last file that had been loaded. When that happens all the macro parameters are not linked anymore. Do I just specify “SampleOsc.Filename” by itself, or with a specific wav/aiff file so it looks for whatever sample has been loaded?

Do you have any scripting in the UI. Unconnected parameters are usually a sign of something going wrong in a script and then not making any more connections after the error.
Are your samples on an external drive perhaps? The drive going to sleep might cause issues.

The wave display should connect properly without stipulating wave type etc.

Thanks again,

I don’t have any scripting and I’m using just a few samples on my main drive for testing. I think with all my tinkering I probably have broken something. I’m going to start over to eradicate any errors.I’ll report back.

I got it working AposMus,

Thank you for your guidance. It has uncovered a new issue though. When I change the sample from the browser Halion doesn’t update the sample length and only shows the length range of the previously loaded sample. Is a script possible in Halion that fetches the sample length of the newly loaded sample when you load it?

Paste this script in the UI script section.

Change “Zone 1” to your zone name and connect ‘SampleOsc.Filename’ zone parameter to the UI LoadFile parameter created by the script.
Now every time the filename changes it trigger the UI parameter and it retrieves the relevant information.

function onLoadFile()
	local zone = getElement():findZones(true, 'Zone 1')[1]
	local file = AudioFile.open(LoadFile)
	local length = file.length

	zone:setParameter('SampleOsc.SampleEnd', length)
end

defineParameter('LoadFile', nil, "" , onLoadFile)

Wow!

Thanks again AposMus. I checked out the AudioFile reference in the developers page wondering if that was a good place to start and you brought a script to the table! Thank you very much. I spent 2 weeks starting to build my instrument in Ksp only to find Halion is way better at creating instruments. What a special piece of software Halion is.

This method works really well. However I am trying to implement a fix for the loop. The sample length is changed when the sample is changed but the loop range/end still keeps the previous length. Is it possible to update the loop range or even just send the sample length of the new sample to the loop parameters?

I got the Halion editor to change the length in the loop parameters with “zone:setParameter(‘SampleOsc.SustainLoopEndA’, length)” but the gui slider doesn’t constrain to the new length. When I use the gui slider in my macro page it widely over extends the loop end range. I’m guessing I will have to update the range of the slider with each sample that gets loaded also. Is there a basic function that does this or is it more complicated than it sounds?

I think I am moving into a different territory so I will make a new request on the forum.