Moving Volume Points.

Thiago_Sase wrote on 11/1/2025, 10:03 AM

@jetdv Hello, sir, could you help me to solve an issue with volume points, if possible, please?

I know how to work with closing gaps and moving from right to cursor position, but this context of moving all selected events to the right direction of the timeline, always forwards by 2 minutes, does not work with the volume points moving together with the events. I tried many approaches, but I failed in all attempts. Where is the possible mistake?

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

namespace Test_Script
{
    public class Class1
    {
        public Vegas myVegas;

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

            // Start an undo block to ensure changes can be undone in VEGAS
            using (new UndoBlock("Move Events Right"))
            {
                // Define the time to move events (2 minutes = 120 seconds)
                Timecode moveTime = Timecode.FromSeconds(120); // 2 minutes in seconds

                // STEP 1: Get all selected events
                var allSelectedEvents = new List<TrackEvent>();
                var processedEvents = new List<TrackEvent>(); // List to keep track of processed events

                // Collect all selected events across all tracks
                foreach (Track track in myVegas.Project.Tracks)
                {
                    if (track.IsVideo() || track.IsAudio()) // Check if it's a video or audio track
                    {
                        foreach (TrackEvent trackEvent in track.Events)
                        {
                            if (trackEvent.Selected)
                            {
                                allSelectedEvents.Add(trackEvent);
                            }
                        }
                    }
                }

                // STEP 2: Move the selected events to the right by 2 minutes
                foreach (TrackEvent trackEvent in allSelectedEvents)
                {
                    Timecode originalStart = trackEvent.Start;
                    trackEvent.Start += moveTime; // Move event to the right by 2 minutes

                    // STEP 3: Move the volume envelope points for audio events
                    Track track = trackEvent.Track;
                    if (track.IsAudio()) // Only for audio tracks
                    {
                        foreach (Envelope envelope in track.Envelopes)
                        {
                            if (envelope.Type == EnvelopeType.Volume)
                            {
                                MoveEnvelopePoints(envelope, originalStart, trackEvent.Length, trackEvent.Start);
                            }
                        }
                    }
                }

                // Refresh the UI to reflect changes
                myVegas.UpdateUI();
            }
        }

        // Method to move envelope points that are within the event's original time range
        private void MoveEnvelopePoints(Envelope envelope, Timecode originalStart, Timecode eventLength, Timecode newStart)
        {
            Timecode originalEnd = originalStart + eventLength;
            Timecode offset = newStart - originalStart;

            foreach (EnvelopePoint point in envelope.Points)
            {
                // Check if the point is within the original event's time range
                if (point.X >= originalStart && point.X <= originalEnd)
                {
                    // Move the point by the same offset as the event
                    point.X += offset;
                }
            }
        }
    }
}

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

 

Comments

jetdv wrote on 11/1/2025, 3:38 PM

@Thiago_Sase, to move right you have to go "backwards" through the list. Instead of:

            foreach (EnvelopePoint point in envelope.Points)
            {

You need:

        for (int i = envelope.Points.Count -1; i >= 0; i--)
        {
            EnvelopePoint point = envelope.Points[i];

If you go forward as you were doing, say points 4, 5, and 6 are within the event range. You find point 4 and move it right, now, point 5 is your new point 4 so when you go to the next point you're actually looking at point 6 and it gets moved. Now point 7 is point 6 so you look at point 8 and then proceed forward (and actually look at the original points 4 and 6 again as some point.)

Basically, whenever you're deleting or moving stuff right, you need to go through the list backwards. Or save them in the script and go through that list instead of the timeline list. I find it easiest to just go backwards.