@jetdv sir can u help in this please.
i created it via help of gemini..
It is working good but it is stopping playback..
i want it should run and execute and keep playing the cursor even it freeze frame even unfreeze,,
pls take a look at it sir..
using System;
using System.Collections;
using System.Windows.Forms;
using ScriptPortal.Vegas;
public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
// 1. Check if playback is currently active
bool wasPlaying = vegas.Transport.IsPlaying;
// Get the current cursor position
Timecode cursorTime = vegas.Transport.CursorPosition;
foreach (Track track in vegas.Project.Tracks)
{
if (track.IsVideo())
{
foreach (TrackEvent evnt in track.Events)
{
if (evnt.Selected)
{
// Ensure the event is actually under the cursor
if (evnt.Start <= cursorTime && evnt.End > cursorTime)
{
VideoEvent videoEvent = (VideoEvent)evnt;
ToggleFreezeAtCursor(videoEvent, cursorTime);
}
}
}
}
}
// 2. If it was playing before, ensure it keeps playing (or resumes)
// VEGAS often stops playback when timeline data is modified by a script.
if (wasPlaying)
{
vegas.Transport.Play();
}
}
private void ToggleFreezeAtCursor(VideoEvent evnt, Timecode cursorTime)
{
Envelope velEnv = null;
// Find Velocity envelope
foreach (Envelope env in evnt.Envelopes)
{
if (env.Type == EnvelopeType.Velocity)
{
velEnv = env;
break;
}
}
// Create if missing
if (velEnv == null)
{
velEnv = new Envelope(EnvelopeType.Velocity);
evnt.Envelopes.Add(velEnv);
}
// Calculate time relative to the start of the event
Timecode relCursorTime = cursorTime - evnt.Start;
// Calculate the time for the "next frame"
Timecode oneFrame = Timecode.FromFrames(1);
Timecode nextFrameTime = relCursorTime + oneFrame;
// Get the current velocity value exactly at the cursor
double currentSpeed = velEnv.ValueAt(relCursorTime);
// Determine target speed (Toggle)
// If it is 0, we go to 1. If it is anything else, we go to 0.
double targetSpeed = (currentSpeed == 0.0) ? 1.0 : 0.0;
// 1. Add Anchor Point (Current Speed) at Cursor Position
// This acts as a wall to preserve previous speed
AddPointSafe(velEnv, relCursorTime, currentSpeed);
// 2. Add Toggle Point (New Speed) at Next Frame
// This switches the speed immediately after the cursor frame
AddPointSafe(velEnv, nextFrameTime, targetSpeed);
}
private void AddPointSafe(Envelope env, Timecode time, double value)
{
// Check if a point already exists at this exact time
EnvelopePoint existingPoint = env.Points.GetPointAtX(time);
if (existingPoint != null)
{
// Update existing point
existingPoint.Y = value;
existingPoint.Curve = CurveType.None; // Hold
}
else
{
// Create new point with Hold curve for instant change
EnvelopePoint newPoint = new EnvelopePoint(time, value, CurveType.None);
env.Points.Add(newPoint);
}
}
}
thanks in advance

