Track order mystery!

VegaMega wrote on 12/4/2023, 10:45 AM

I'd like the flow of my script to match what is happening on the timeline from left to right. So now I got to a point where I needed a new track layer below one that already exists (something happening behind a text).

I tried: project.Tracks.Insert(videoTrack2.Index, newTrack);

But strangely the insert is not supported.....??? So I set out to take a deep dive into the track idexes and how they are ordered. Found a video about it from @jetdv https://www.jetdv.com/2021/08/23/add-new-tracks-to-the-timeline-in-vegas-pro/

But I was still not sure on the order from that. So I setup my own test code:

VideoTrack videotrack0 = new VideoTrack(0, "0");
myVegas.Project.Tracks.Add(videotrack0);
videotrack0.Name = "V0-" + videotrack0.Index.ToString(); // Set name to assigned track # - Gotten track #

AudioTrack audiotrack0 = new AudioTrack(0, "0");
myVegas.Project.Tracks.Add(audiotrack0);
audiotrack0.Name = "A0-" + audiotrack0.Index.ToString();

VideoTrack videotrack1 = new VideoTrack(1, "1");
myVegas.Project.Tracks.Add(videotrack1);
videotrack1.Name = "V1-" + videotrack1.Index.ToString();

VideoTrack videotrack99 = new VideoTrack(99, "99");
myVegas.Project.Tracks.Add(videotrack99);
videotrack99.Name = "V99-" + videotrack99.Index.ToString();

VideoTrack videotrack5 = new VideoTrack(5, "5");
myVegas.Project.Tracks.Add(videotrack5);
videotrack5.Name = "V5-" + videotrack5.Index.ToString();

AudioTrack audiotrack1 = new AudioTrack(1, "1");
myVegas.Project.Tracks.Add(audiotrack1);
audiotrack1.Name = "A1-" + audiotrack1.Index.ToString();

AudioTrack audiotrack99 = new AudioTrack(99, "99");
myVegas.Project.Tracks.Add(audiotrack99);
audiotrack99.Name = "A99-" + audiotrack99.Index.ToString();

AudioTrack audiotrack5 = new AudioTrack(5, "5");
myVegas.Project.Tracks.Add(audiotrack5);
audiotrack5.Name = "A5-" + audiotrack5.Index.ToString();

And the result is: A0-0, A1-1, V1-1, V0-0, V99-3, A5-5, V5-4, A99-6

So first things noteworthy is that the index that I am assigning is not what is actually given to the track! And to me the order does not make any sense...

So if anyone can shine a light on this, please do!

 

Comments

jetdv wrote on 12/4/2023, 11:16 AM
But I was still not sure on the order from that. So I setup my own test code:
VideoTrack videotrack0 = new VideoTrack(0, "0");
myVegas.Project.Tracks.Add(videotrack0);
videotrack0.Name = "V0-" + videotrack0.Index.ToString(); // Set name to assigned track # - Gotten track #

AudioTrack audiotrack0 = new AudioTrack(0, "0");
myVegas.Project.Tracks.Add(audiotrack0);
audiotrack0.Name = "A0-" + audiotrack0.Index.ToString();

VideoTrack videotrack1 = new VideoTrack(1, "1");
myVegas.Project.Tracks.Add(videotrack1);
videotrack1.Name = "V1-" + videotrack1.Index.ToString();

VideoTrack videotrack99 = new VideoTrack(99, "99");
myVegas.Project.Tracks.Add(videotrack99);
videotrack99.Name = "V99-" + videotrack99.Index.ToString();

VideoTrack videotrack5 = new VideoTrack(5, "5");
myVegas.Project.Tracks.Add(videotrack5);
videotrack5.Name = "V5-" + videotrack5.Index.ToString();

AudioTrack audiotrack1 = new AudioTrack(1, "1");
myVegas.Project.Tracks.Add(audiotrack1);
audiotrack1.Name = "A1-" + audiotrack1.Index.ToString();

AudioTrack audiotrack99 = new AudioTrack(99, "99");
myVegas.Project.Tracks.Add(audiotrack99);
audiotrack99.Name = "A99-" + audiotrack99.Index.ToString();

AudioTrack audiotrack5 = new AudioTrack(5, "5");
myVegas.Project.Tracks.Add(audiotrack5);
audiotrack5.Name = "A5-" + audiotrack5.Index.ToString();

And the result is: A0-0, A1-1, V1-1, V0-0, V99-3, A5-5, V5-4, A99-6

So first things noteworthy is that the index that I am assigning is not what is actually given to the track! And to me the order does not make any sense...

So if anyone can shine a light on this, please do!

 

@VegaMega Let's follow your code (remember that all tracks are "zero" based so track 1 is actually index 0):

VideoTrack videotrack0 = new VideoTrack(0, "0"); 
myVegas.Project.Tracks.Add(videotrack0);

Adds a video track at the top of the timeline in the Index 0 position so we now have:

  • V "0" - Index 0
AudioTrack audiotrack0 = new AudioTrack(0, "0"); 
myVegas.Project.Tracks.Add(audiotrack0);

Adds an Audio track at the top of the timeline in the index 0 position so we now have:

  • A "0" - Index 0
  • V "0" - Index 1
VideoTrack videotrack1 = new VideoTrack(1, "1"); 
myVegas.Project.Tracks.Add(videotrack1);

Adds a video track as the Second track (remember the number 1 indicates the second track as 0 is the first track) so we now have:

  • A "0" - Index 0
  • V "1" - Index 1
  • V "0" - Index 2
VideoTrack videotrack99 = new VideoTrack(99, "99"); myVegas.Project.Tracks.Add(videotrack99);

Adds a video track at as track 100 (essentially, the bottom of the timeline so it will become index 3 instead of 99) so we now have:

  • A "0" - Index 0
  • V "1" - Index 1
  • V "0" - Index 2
  • V "99" - Index 3
VideoTrack videotrack5 = new VideoTrack(5, "5"); 
myVegas.Project.Tracks.Add(videotrack5);

Adds a video track at the index 5 position (we currently have 0, 1, 2, 3) so at the bottom (it will become index 4 as there are only 4 tracks above it) so we now have:

  • A "0" - Index 0
  • V "1" - Index 1
  • V "0" - Index 2
  • V "99" - Index 3
  • V "5" - Index 4
AudioTrack audiotrack1 = new AudioTrack(1, "1"); 
myVegas.Project.Tracks.Add(audiotrack1);

Adds an audio track at the index 1 position which will be the second track so we now have:

  • A "0" - Index 0
  • A "1" - Index 1
  • V "1" - Index 2
  • V "0" - Index 3
  • V "99" - Index 4
  • V "5" - Index 5
AudioTrack audiotrack99 = new AudioTrack(99, "99"); myVegas.Project.Tracks.Add(audiotrack99);

Adds an audio track as track 100 (essentially the "bottom" of the timeline so it will become index 6) so we now have:

  • A "0" - Index 0
  • A "1" - Index 1
  • V "1" - Index 2
  • V "0" - Index 3
  • V "99" - Index 4
  • V "5" - Index 5
  • A "99" - Index 6
AudioTrack audiotrack5 = new AudioTrack(5, "5"); 
myVegas.Project.Tracks.Add(audiotrack5);

Adds an audio track at the index 5 location (which now has V "5") so now we have:

  • A "0" - Index 0
  • A "1" - Index 1
  • V "1" - Index 2
  • V "0" - Index 3
  • V "99" - Index 4
  • A "5" - Index 5
  • V "5" - Index 6
  • A "99" - Index 7

So it does appear that everything is properly working in the order you have specified them. It is properly placing the track at the index you stated. If you put two tracks on index zero, the second one will be placed before the first one as it was added later in that position. The index is not a "hard in stone" number. It will change as new tracks are added and by adding a new track to the same index number, you are placing that track above the current track that has that index number.

VegaMega wrote on 12/4/2023, 11:46 AM

@jetdv ah, they keep changing!

So:

// Test track orders:
VideoTrack videotrack0 = new VideoTrack(0, "0");
myVegas.Project.Tracks.Add(videotrack0);            

AudioTrack audiotrack0 = new AudioTrack(0, "0");
myVegas.Project.Tracks.Add(audiotrack0);

VideoTrack videotrack1 = new VideoTrack(1, "1");
myVegas.Project.Tracks.Add(videotrack1);

VideoTrack videotrack99 = new VideoTrack(99, "99");
myVegas.Project.Tracks.Add(videotrack99);

VideoTrack videotrack5 = new VideoTrack(5, "5");
myVegas.Project.Tracks.Add(videotrack5);
videotrack5.Name = "V5-" + videotrack5.Index.ToString();

AudioTrack audiotrack1 = new AudioTrack(1, "1");
myVegas.Project.Tracks.Add(audiotrack1);

AudioTrack audiotrack99 = new AudioTrack(99, "99");
myVegas.Project.Tracks.Add(audiotrack99);

AudioTrack audiotrack5 = new AudioTrack(5, "5");
myVegas.Project.Tracks.Add(audiotrack5);

videotrack0.Name = "V0-" + videotrack0.Index.ToString(); // Set name to assigned track # - Received track #
audiotrack0.Name = "A0-" + audiotrack0.Index.ToString();
videotrack1.Name = "V1-" + videotrack1.Index.ToString();
videotrack99.Name = "V99-" + videotrack99.Index.ToString();
audiotrack1.Name = "A1-" + audiotrack1.Index.ToString();
audiotrack99.Name = "A99-" + audiotrack99.Index.ToString();
audiotrack5.Name = "A5-" + audiotrack5.Index.ToString();

Results in: A0-0, A1-1, V1-2, V0-3, V99-4, A5-5

So, I now need to re-calibrate my thinking of track indexes and how I am going to manage the order. Keeping track of the index that I gave it, is simply not okay. So if I want a track below a certain track, I have to get the index of that track and + 1 it, I guess. If I want it above a certain track, I just use the same index that I have to get first (not store it locally).

Great!

 

jetdv wrote on 12/4/2023, 11:51 AM
So if I want a track below a certain track, I have to get the index of that track and + 1 it, I guess. If I want it above a certain track, I just use the same index that I have to get first (not store it locally).

@VegaMega, yes. If it has to be related to a specific track, you need to locate that track first and use it's "current" index value.

If I need to be able to find specific tracks, I usually give them a specific "name" and then can just loop through until I find that name and get the index from there. But definitely don't rely on the index number not changing.