@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);
}
}