How to check if the voice is running?

playNote has an id. Can I somehow check, using this id, if its voice is running (active) or not? Because a physical key can be still held, while a sample has already ended and its voice stopped.

You can use getUsedVoices but I don’t think it’s possible to check if a specific voice is still active or not.

What is the reason you need this?

You could try to use the id to releaseVoice or fade, as a safety measure. But it won’t help you knowing if the voice is still active.

Getting back to the old thread)) My instrument plays tonal sounds (notes) and mechanical noises. And the latter must sound only if the tonal voices are alive, not faded-out or killed.

You could check the amp envelope and its playback position.

Wow! Five years and seems like five minutes. Kudos!

Thanks for the hint. I’ve written so far a simple script to get PlaybackPos value of an already playing note (between 60 and 71) by pressing key #75.

layers = this.parent:findLayers(true)
layer_to_check=1

function onNote(event)

if (event.note >= 60 and event.note < 72) then
local id = playNote(event.note, event.velocity, 0,layer_to_check)
zones = layers[layer_to_check]:findZones(false)
for i, zone in ipairs(zones) do
if(zone.keyLow<=event.note and zone.keyHigh>=event.note and zone.velLow<=event.velocity and zone.velHigh>=event.velocity) then
found_zone=zone
end
end
end

if (event.note == 75) then
print(found_zone:getParameter(“SampleOsc.Filename”))
print(found_zone:getParameter(“Amp Env.PlaybackPos”))
print(found_zone:getParameter(“Amp Env.SustianIndex”))
end

end

And while the first print gives me correct path to the sounding sample, the other two, addressing Amp Env, return nil like the parameters PlaybackPos or SustianIndex are not found. What could be wrong in the code?

In this example here: removeEnvelopePoint - HALion 7.1.30 the referring to Amp Env is mentioned like in my piece above:
ampEnvPoints = zone:getParameter(“Amp Env.EnvelopePoints”)
ampSustainPoint = zone:getParameter(“Amp Env.SustainIndex”)

Do you have the parameter names correct? Looks like a typo in Sustian and the other may be Playposition. Did you check in parameter list?

Yes, my bad. SustianIndex had a typo, but PlaybackPos seemed ok. Anyway, now they both return the relevant values.

And do I understand correctly that with a note triggered like this:

id = playNote(note, velocity, 0)

I will never be able to retrieve the played note and velocity from the id itself? Using something like id.note or id.velocity

No, you won’t be able to use id like that. Store that information into a global variable if you need it later.