Help with randomize function

Hello everyone,
I’m new to HALion scripting.

Is it possible to randomize a parameter?
I have a simple instrument and I want to add a button that when clicked randomizes some parameters like pitch, volume, filter cutoff, etc. etc.

I think I need a script for this, is not possible to do it inside the macro page with the available templates…

Thanks in advance for any help!

It is possible but you need to specify which zone/zones and which parameters you want to randomise. Then simply use setParameter or setParameterNormalized

Thanks.
I tried to add this script to my instrument connected to a switch but is not doing anything.
As you can see I have put the script after the one you send me yesterday.
It’s the same script you sent me but I have changed the “function setScope”
Screen Shot 2022-03-21 at 11.27.06 AM

Thanks in advance for any help.

`tlocal layer = this.parent
local zones = layer:findZones()

local zoneNames = {}
for i = 1, #zones do
	zoneNames[i] = zones[i].name
end

 

function setScope()
    this.parent:setParameter("Level", 0) 
     this.parent:setParameter(38, 0)  
end

defineParameter("activeZone", nil, 1, zoneNames, setScope)
defineParameter("scope", nil, "")

setScope()

function onNote(e)
	playNote(e.note, e.velocity, -1, zones[activeZone])
end

What parameters do you want to randomize?

I have several parameters I would like to randomize with a button:
ADSR
LEVEL
PAN
TUNE (Octave)
FILTER CUTOFF and RESONANCE
ZONE

You could try something like this:

-- Randomise parameters
local layer = this.parent
local zones = layer:findZones()

rndTable = {
    -- table 1 elements, table 2 parameters
    {zones, {"Filter.Cutoff", "Filter.Resonance"}},
    {{layer}, {"Level", "Pan"}},
}

function randomiseParameters()
    if Rnd then
        for i = 1, #rndTable do
            local elements = rndTable[i][1]
            local parameters = rndTable[i][2]
            for j, parameter in ipairs(parameters) do
                local rnd = math.random()
                for k, element in ipairs(elements) do
                    element:setParameterNormalized(parameter, rnd)
                end
            end
        end        
        wait(50)
        Rnd = false
    end
end

defineParameter{name = "Rnd", default = false, onChanged = randomiseParameters, persistent = false}

Rnd.vstpreset (8.8 KB)

Thanks, it works, but only for Pan, Volume, Filter Cutoff, and Resonance.

These parameters are not affected by the script:

ADSR
PITCH
ZONE

Maybe is because of my instrument structure?

Thanks a lot again for your help!

Screen Shot 2022-03-21 at 14.56.12 PM

You can add more layer or zone parameters. Just check their names in parameter list. I would change the adsr envelope itself. It would quickly become a mess.

I tried to do it several times but I’m always getting an error code message.
Please can you help me understand what is wrong?

I have added two parameters to your code but It’s not working.

rndTable = {
    -- table 1 elements, table 2 parameters
    {zones, {"Filter.Cutoff", "Filter.Resonance”, “Grain.Position"}},
    {{layer}, {"Level", "Pan" , “Octave”}},

Screen Shot 2022-03-21 at 21.20.49 PM

Sorry, I have to find the problem now is working!

But how I can randomize the zone? I tried several times but I can’t find a solution…

-- Randomise parameters
local layer = this.parent
local zones = layer:findZones()

rndTable = {
    -- table 1 elements, table 2 parameters
    {zones, {"Filter.Cutoff", "Filter.Resonance" , "Grain.Position"}},
    {{layer}, {"Level", "Pan" , "Octave"}},
}

function randomiseParameters()
    if Rnd then
        for i = 1, #rndTable do
            local elements = rndTable[i][1]
            local parameters = rndTable[i][2]
            for j, parameter in ipairs(parameters) do
                local rnd = math.random()
                for k, element in ipairs(elements) do
                    element:setParameterNormalized(parameter, rnd)
                end
            end
        end        
        wait(50)
        Rnd = false
    end
end

defineParameter{name = "Rnd", default = false, onChanged = randomiseParameters, persistent = false}

What do you mean by zone? Are talking about the other script that selects zone?

You would need another variable to get the script module object.
midiModule = this.parent:getMidiModule("Zone Select Grain")
(Name of the module in quotes)

Then add another line to the rndTable:
{{midiModule}, {"activeZone"}},
(Name of the parameter in quotes)

Thanks!! It works perfectly!
Regarding zones I have this question, I tried to look on the developer help page but didn’t find anything.
Is it possible to purge out of RAM the zones that I’m not using?
my instrument is about long textured sounds and I loaded 10 and the Halion ram indicator is already more than 700MB!
I think to do it I need to add a line of code to the 'Zone Select Garin" script:

local layer = this.parent
local zones = layer:findZones()

local zoneNames = {}
for i = 1, #zones do
	zoneNames[i] = zones[i].name
end

function setScope()
	local layerName = layer.name
	local zoneName = zones[activeZone].name
	scope = "@0:"..layerName.."/@0:"..zoneName
end

defineParameter("activeZone", nil, 1, zoneNames, setScope)
defineParameter("scope", nil, "")

setScope()

function onNote(e)
	playNote(e.note, e.velocity, -1, zones[activeZone])
end```

Hello,
I’m trying to randomize some reverb FX parameters I have in the BUS.
Screen Shot 2022-03-22 at 10.40.28 AM

I tried to insert the parameter in the “Layer” but is not working:

{{layer}, {"Level", "Pan" , "Coarse" , "Reverb.Mix"}},```

I think I have to create a variable for the Bus?

Thanks in advance for any help!

No, as far as I know. At least not the same way like in Kontakt.

I would check the plugin options tab. There you can set ram/disk preload balance.

Then there are some zone parameters that might be related to this. Open parameter list and check (probably SampleOsc folder), if you want to experiment😀

Well, yes…
You need variable for the reverb.
Looking at the screenshot it could be:
this.parent:getBus():getEffect("Reverb")