VEGAS Improvements with audio 5.1

Joelson wrote on 4/11/2023, 2:44 PM

@VEGASDerek

When you and your team have the time and resources, look into this if possible. Thanks!

1.Project does not assume the properties of the file with 5.1 audio, it is always necessary to manually adjust the project properties. What is expected is that the project's properties assume the same properties as the file with 5.1 audio automatically, in the same way as with files with stereo audio.

2.In nested projects the tracks with 5.1 audio are converted into stereo tracks and when returning to the Master project there is only one stereo audio track. What is expected is that in nested projects the tracks with 5.1 audio remain and when returning to the Master project there are all the new 5.1 audio tracks.

3.Add Missing Stream for Selected Events restores only channel 1 of stream 2 to a new 5.1 audio track with all channels enabled. The Add Missing Stream for Selected Events option is expected to restore all 5.1 audio tracks with their respective channels correctly enabled.

Comments

jetdv wrote on 4/11/2023, 3:40 PM

Joelson wrote on 4/11/2023, 4:27 PM

@jetdv Thank you for showing that it is possible to improve item 3. I hope that it is also possible to make improvements to items 1 and 2.

jetdv wrote on 4/11/2023, 4:39 PM

Here's the actual code:
 

using System;
using System.Collections.Generic;
using System.Collections;
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;
        bool ChannelsAddedForTrack;

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

            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                if (myTrack.IsVideo())
                {
                    ChannelsAddedForTrack = false;
                    foreach (TrackEvent evnt in myTrack.Events)
                    {
                        if (evnt.Selected)
                        {
                            Media media = evnt.ActiveTake.Media;

                            int chCount = media.StreamCount(MediaType.Audio);

                            bool found6 = false;
                            for (int i=0; i<chCount; i++)
                            {
                                AudioStream astream = (AudioStream)media.GetAudioStreamByIndex(i);
                                int asChannels = astream.Channels;

                                if (asChannels == 6)
                                {
                                    found6 = true;
                                    AddChannel(myTrack.Index, astream, evnt);
                                }
                            }
                            if (!found6)
                            {
                                MessageBox.Show("No channels above 2 were found.");
                            }
                            else
                            {
                                ChannelsAddedForTrack = true;
                            }
                        }

                    }
                }
            }
        }

        private void AddChannel(int tIndex, AudioStream astream, TrackEvent evnt)
        {
            TrackEventGroup grp = new TrackEventGroup();
            myVegas.Project.Groups.Add(grp);
            grp.Add(evnt);
            addEvent(tIndex + 1, astream, evnt, 0, 2, grp);
            addEvent(tIndex + 2, astream, evnt, 2, 1, grp);
            addEvent(tIndex + 3, astream, evnt, 3, 1, grp);
            addEvent(tIndex + 4, astream, evnt, 4, 2, grp);
        }


        private void addEvent(int tIndex, AudioStream astream, TrackEvent evnt, int FirstChannel, int ChannelCount, TrackEventGroup grp)
        {
            AudioTrack aTrack = null;

            if (!ChannelsAddedForTrack)
            {
                aTrack = new AudioTrack(tIndex);
                myVegas.Project.Tracks.Add(aTrack);
            }
            else
            {
                aTrack = (AudioTrack)myVegas.Project.Tracks[tIndex];
            }

            AudioEvent mynewAEvent = new AudioEvent(evnt.Start, evnt.Length);

            aTrack.Events.Add(mynewAEvent);
            Take myNewtake = new Take(astream);
            mynewAEvent.Takes.Add(myNewtake);
            myNewtake.SetAudioChannels(FirstChannel, ChannelCount);
            myNewtake.Offset = evnt.ActiveTake.Offset;
            grp.Add(mynewAEvent);
        }
    }
}

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