Halion Script Math Limitation?

Post topics about HALion scripting.
Post Reply
User avatar
abject39
Member
Posts: 317
Joined: Sat Jan 17, 2015 8:20 pm
Location: Ventura, Ca
Contact:

Halion Script Math Limitation?

Post by abject39 » Wed Jan 31, 2018 7:42 am

I am trying to create a parameter from the Sample Rate Reduction parameter of in the distortion audio FX. By default it goes from 20hz to 96000hz. I want my created parameter to instead to go from 0 to 100. I also want it to move in reverse so that 0 = 96000hz and 100 = 20hz. In order to do that I wrote this code that I am pretty sure is right but Halion doesn't seem to respond to it and I assume it's because the numbers I am using are too large. Anyone able to help with this?

Code: Select all

bus = this.parent:getBus("Internal FX")

if bus then
    effect2 = bus:getEffect("Distortion")
    if effect2 then
        function onSampleCrushChange()
            effect2:setParameter(3, 96000-SampleCrush*.00096)
        end
        defineParameter("SampleCrush", "SampleCrush", 0, 0, 100, 1, onSampleCrushChange)
    end
end
My vision is uncompromising: to transcend my clients dreams by mesmerizing their audience with the world's finest audio arrangements and products.

misohoza
Member
Posts: 860
Joined: Sun Oct 05, 2014 12:18 am
Contact:

Re: Halion Script Math Limitation?

Post by misohoza » Thu Feb 01, 2018 12:07 am

You could try that with setParameterNormalized, which is using normalized range from 0 to 1.

As your parameter has range from 0 to 100, it should be easier to calculate. Just divide by 100 and you get the range needed for setParameterNormalized. To invert the range subtract the range from 1.

Code: Select all

bus = this.parent:getBus("Internal FX")

if bus then
    effect2 = bus:getEffect("Distortion")
    if effect2 then
        function onSampleCrushChange()
            effect2:setParameterNormalized(3, 1-SampleCrush/100)
        end
        defineParameter("SampleCrush", "SampleCrush", 0, 0, 100, 1, onSampleCrushChange)
    end
end
Another thing to think about is that the Rate parameter has a range of 20 to 96000Hz but the range is not linear. If you connect a knob to it and you get about halfway it has a value about 1400Hz (not 48000Hz).

This might be another reason to use the setParameterNormalized because it will keep the behaviour (curve) of the parameter you want to control. So when you get halfway it will have the same value as if connected directly.
Win 10 Home, 64 bit, 8 gb ram,
Cubase Pro 9, Wavelab Pro 9, Halion 6, Dorico,
NI Komplete 10 Ultimate, Ozone 7,
UR 44

User avatar
abject39
Member
Posts: 317
Joined: Sat Jan 17, 2015 8:20 pm
Location: Ventura, Ca
Contact:

Re: Halion Script Math Limitation?

Post by abject39 » Thu Feb 01, 2018 6:40 am

misohoza wrote:
Thu Feb 01, 2018 12:07 am
You could try that with setParameterNormalized, which is using normalized range from 0 to 1.

As your parameter has range from 0 to 100, it should be easier to calculate. Just divide by 100 and you get the range needed for setParameterNormalized. To invert the range subtract the range from 1.

Code: Select all

bus = this.parent:getBus("Internal FX")

if bus then
    effect2 = bus:getEffect("Distortion")
    if effect2 then
        function onSampleCrushChange()
            effect2:setParameterNormalized(3, 1-SampleCrush/100)
        end
        defineParameter("SampleCrush", "SampleCrush", 0, 0, 100, 1, onSampleCrushChange)
    end
end
Another thing to think about is that the Rate parameter has a range of 20 to 96000Hz but the range is not linear. If you connect a knob to it and you get about halfway it has a value about 1400Hz (not 48000Hz).

This might be another reason to use the setParameterNormalized because it will keep the behaviour (curve) of the parameter you want to control. So when you get halfway it will have the same value as if connected directly.
I had no idea you could just normalize a parameter while setting it. That's a very useful thing to know now. I will use it for now on. There's a few places where it would've been helpful in my code to have known it before lol. I was searching and searching in the lua reference for some sort of math function and it turns out it was built into halion script the entire time. Thanks! Did you just read every function in the developers manual to find this? I'm curious if I'm going about reading the developers manual wrong. Should I just sit down and read it completely from end to end. I usually just read the parts that I feel apply to what I need to do.
My vision is uncompromising: to transcend my clients dreams by mesmerizing their audience with the world's finest audio arrangements and products.

Post Reply

Return to “Halion Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest