How to change Audio Effect Parameter?

Thiago_Sase wrote on 10/18/2024, 11:01 AM

@jetdv Hi Sir, please, could you guide me in this task;

This is the way I add the Volume audio effect to the audio event;
 

public void AddVolume()
        {
            try
            {
                PlugInNode effects = myVegas.AudioFX;

                foreach (Track myTrack in myVegas.Project.Tracks)
                {
                    if (myTrack.IsAudio())
                    {
                        foreach (AudioEvent aEvnt in myTrack.Events)
                        {
                            if (aEvnt.Selected)
                            {
                                Guid effGUID = new Guid("ee38ca88-d78e-4bfb-b05e-577892730c83");
                                PlugInNode thisEff = effects.GetChildByClassID(effGUID);
                                Effect audioEffect = new Effect(thisEff);


                                aEvnt.Effects.Add(audioEffect);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: " + ex.Message, "Error");
            }
        }

But, it would be very nice to add the Volume (db) parameter to be set to 1, automatically, every time that I use the Script. 

In one of yours tutorials, you teach how to find the name of the Video OFX parameters, thank you very much for that. But, how do we find the name of the parameters to the Volume effect and how to change that specific parameter? 

Comments

Thiago_Sase wrote on 10/18/2024, 12:40 PM

@jetdv Sir, I found a solution. I just saved the value that I needed as preset, and then I inserted in the code.

 

        public void AddVolume(Vegas vegas)
        {
            try
            {
                PlugInNode effects = myVegas.AudioFX;

                foreach (Track myTrack in myVegas.Project.Tracks)
                {
                    if (myTrack.IsAudio())
                    {
                        foreach (AudioEvent aEvnt in myTrack.Events)
                        {
                            if (aEvnt.Selected)
                            {
                                Guid effGUID = new Guid("ee38ca88-d78e-4bfb-b05e-577892730c83");
                                PlugInNode thisEff = effects.GetChildByClassID(effGUID);
                                Effect audioEffect = new Effect(thisEff);

                                aEvnt.Effects.Add(audioEffect);

                                int presetCount = 2; 
                                if (audioEffect.Presets.Count > presetCount)
                                {
                                    audioEffect.Preset = audioEffect.Presets[presetCount].Name;
                                }
                                else
                                {
                                    MessageBox.Show("Preset index out of range.", "Error");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: " + ex.Message, "Error");
            }
        }

 

jetdv wrote on 10/18/2024, 1:55 PM

Audio effects are not OFX so you cannot change individual parameters. You can only choose a preset - as you have discovered.

Thiago_Sase wrote on 10/18/2024, 2:06 PM

@jetdv Thank you, Sir. One more information learned.

Iurii-Cojocari wrote on 2/19/2025, 4:04 AM

I managed to enhance the sound only on the entire track. 
I tried to make it like the premiere pro.
But Gain at the event doesn't want to.

using System;
using System.Windows.Forms;
using ScriptPortal.Vegas;

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        // Creating a form for volume input
        Form form = new Form
        {
            Text = "Track Volume Adjustment",
            Width = 300,
            Height = 150
        };

        Label label = new Label
        {
            Text = "Enter volume level (dB):",
            Top = 20,
            Left = 20
        };

        TextBox textBox = new TextBox
        {
            Top = 50,
            Left = 20,
            Width = 100
        };

        Button button = new Button
        {
            Text = "Apply",
            Top = 80,
            Left = 20
        };

        form.Controls.Add(label);
        form.Controls.Add(textBox);
        form.Controls.Add(button);

        button.Click += delegate (object sender, EventArgs args)
        {
            double volumeDb;
            if (double.TryParse(textBox.Text, out volumeDb))
            {
                double volumeFactor = Math.Pow(10, volumeDb / 20); // Convert dB to a factor

                // Apply volume to all selected audio tracks
                foreach (Track track in vegas.Project.Tracks)
                {
                    if (track.Selected && track.IsAudio())
                    {
                        AudioTrack audioTrack = track as AudioTrack;
                        if (audioTrack != null)
                        {
                            audioTrack.Volume = (float)volumeFactor; // Adjust track volume
                        }
                    }
                }
                form.Close();
            }
            else
            {
                MessageBox.Show("Enter a valid number!");
            }
        };

        form.ShowDialog();
    }
}

 

Iurii-Cojocari wrote on 2/19/2025, 4:29 AM

And here's the script that adds Volume 

 

using System;
using System.Windows.Forms;
using ScriptPortal.Vegas;

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        try
        {
            PlugInNode effects = vegas.AudioFX;

            foreach (Track myTrack in vegas.Project.Tracks)
            {
                if (myTrack.IsAudio())
                {
                    foreach (AudioEvent aEvnt in myTrack.Events)
                    {
                        if (aEvnt.Selected)
                        {
                            Guid effGUID = new Guid("ee38ca88-d78e-4bfb-b05e-577892730c83");
                            PlugInNode thisEff = effects.GetChildByClassID(effGUID);

                            if (thisEff != null)
                            {
                                Effect audioEffect = new Effect(thisEff);
                                aEvnt.Effects.Add(audioEffect);

                                int presetCount = 2; 
                                if (audioEffect.Presets.Count > presetCount)
                                {
                                    audioEffect.Preset = audioEffect.Presets[presetCount].Name;
                                }
                                else
                                {
                                    MessageBox.Show("Preset index out of range.", "Error");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Effect not found.", "Error");
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("An error occurred: " + ex.Message, "Error");
        }
    }
}

 

jetdv wrote on 2/19/2025, 9:56 AM

@Iurii-Cojocari you can adjust the gain at the event level as well. Get the audio event you want to adjust and change this:

aEvent.FadeIn.Gain = -3;

Note you can only adjust DOWNWARD and you'll need to see what the top and bottom values are.

You can also set the "normalize" option:

                        aEvent.NormalizeGain = dbLevel;
                        aEvent.Normalize = true;