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…
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”
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
-- 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}
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.
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```
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")