Create Script add audio effects to an event

LOLOGP wrote on 1/22/2024, 6:33 AM

Hi @jetdv I have followed your tutorial to create a script where you can add a sound effect, in this case "Reverb", but I don't know what problem I am having. I can't get it to work. Could you help me?

using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

         public void Main(Vegas vegas)
        {
            myVegas = vegas;

            Track track = myVegas.Project.Tracks[1];
            TrackEvent evnt = track.Events[0];
       
            string plugInName = "Reverb";
            string presetName = "Default";

            PlugInNode effects = myVegas.AudioFX;

            PlugInNode thisEff = effects.GetChildByName("Reverb");
            Effect trackEffect = new Effect(thisEff);
   
            Guid effGUID = new Guid("00000006-0f56-11d2-9887-00a0c969725b");
            thisEff = effects.GetChildByClassID(effGUID);
            Effect eventEffect = new Effect(thisEff);
     
            effGUID = new Guid("00000000-0f56-11d2-9887-00a0c969725b");
            thisEff = effects.GetChildByClassID(effGUID);
            Effect eventEffect2 = new Effect(thisEff);


            AudioEvent aEvent = (AudioEvent)evnt;
            aEvent.Effects.Add(eventEffect);
            aEvent.Effects.Add(eventEffect2);

            AudioTrack aTrack = (AudioTrack)track;
            aTrack.Effects.Add(trackEffect);



                }
            }
        }

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}

Comments

jetdv wrote on 1/22/2024, 8:13 AM

Is Track 2 an audio track?

Does Track 2 have an audio event on it?

LOLOGP wrote on 1/22/2024, 8:47 AM

 

In truth, what I would like to do is much simpler. With the audio event selected, click on the script and have it add the "reverb" effect regardless of the track number. that is, apply the effect to any selected event or events.

jetdv wrote on 1/22/2024, 9:29 AM

That's fine. But that's not what the script as listed above does. It "assumes" track 2 is and audio track and adds the "reverb" effect to that track. It also "assumes" that there is an audio event on track 2 and adds two effects to that audio event.

That sample is to show how to add an audio effect to a track and to an event. It does not "look" for a selected audio event. It *can* with some changes and there are many tutorials that do look for a selected event. So what you're really wanting is something more like (here's the main part):
 

        public Vegas myVegas;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            string plugInName = "Reverb";
            string presetName = "Default";

            PlugInNode effects = myVegas.AudioFX;

            foreach (Track myTrack in myVegas.Project.Tracks) //Go through the tracks
            {
                if (myTrack.IsAudio())  //Is it an audio track?
                {
                    foreach (AudioEvent aEvnt in myTrack.Events) //If yes, go through the audio events
                    {
                        if (aEvnt.Selected) //If the audio event is selected, add the reverb effect
                        {
                            PlugInNode thisEff = effects.GetChildByName(plugInName);
                            Effect reverbEffect = new Effect(thisEff);
                            reverbEffect.Preset = presetName;

                            aEvnt.Effects.Add(reverbEffect);
                        }
                    }
                }
            }
        }

 

LOLOGP wrote on 1/22/2024, 11:04 AM
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

        public void Main(Vegas vegas)
        {
            myVegas = vegas;

            string plugInName = "Reverb";
            string presetName = "Default";

            PlugInNode effects = myVegas.AudioFX;

            foreach (Track myTrack in myVegas.Project.Tracks) //Go through the tracks
            {
                if (myTrack.IsAudio())  //Is it an audio track?
                {
                    foreach (AudioEvent aEvnt in myTrack.Events) //If yes, go through the audio events
                    {
                        if (aEvnt.Selected) //If the audio event is selected, add the reverb effect
                        {
                            PlugInNode thisEff = effects.GetChildByName(plugInName);
                            Effect reverbEffect = new Effect(thisEff);
                            reverbEffect.Preset = presetName;

                            aEvnt.Effects.Add(reverbEffect);
                        }
                    }
                }
            }
        }
     }
  }

public class EntryPoint
{
    public void FromVegas(Vegas vegas)
    {
        Test_Script.Class1 test = new Test_Script.Class1();
        test.Main(vegas);
    }
}
    

I keep having problems. Sorry, I'm totally noob at this.

jetdv wrote on 1/22/2024, 11:33 AM

Do you actually have an effect named "Reverb"? It appears you are using a different language so it's probably a different name on your machine. Instead of using the name, use the GUID instead. First change this line:

            string plugInName = "Reverb";

to

            string plugInName = "607682e0-6e21-11d0-aebc-00a0c9053912";

Then change this line:

            PlugInNode thisEff = effects.GetChildByName(plugInName);

to

            Guid effGUID = new Guid(plugInName);
            PlugInNode thisEff = effects.GetChildByClassID(effGUID);

It's safer to use the GUID as it's the same on every language.