Skip to content

Instantly share code, notes, and snippets.

@wiiaboo
Created July 13, 2014 22:51
Show Gist options
  • Save wiiaboo/272d2ada7ee6a9643a31 to your computer and use it in GitHub Desktop.
Save wiiaboo/272d2ada7ee6a9643a31 to your computer and use it in GitHub Desktop.
// versao 3.0
using System.Collections.Generic;
using Sony.Vegas;
using System;
using System.Windows.Forms;
public class EntryPoint
{
CurveType MainCurveType = CurveType.Smooth;
EnvelopeType envType = EnvelopeType.Volume;
Timecode prePoint = Timecode.FromMilliseconds(-120);
public void FromVegas(Vegas vegas)
{
TransportControl transport = vegas.Transport;
Timecode selectionStart = transport.SelectionStart;
Timecode selectionLength = transport.SelectionLength;
if (selectionLength != Timecode.FromSeconds(0)) {
prePoint = selectionLength;
}
Tracks allTracks = vegas.Project.Tracks;
List<int> selectedTracks = new List<int>();
foreach (Track track in allTracks) {
if (track.Selected) selectedTracks.Add(track.Index);
}
if (selectedTracks.Count >= 2) {
foreach (int trackIdx in selectedTracks) {
Track track = allTracks[trackIdx];
AddPoint(selectionStart+prePoint, selectionStart, track);
}
} else {
foreach (Track track in allTracks) {
AddPoint(selectionStart+prePoint, selectionStart, track);
}
}
}
void AddPoint(Timecode selStart, Timecode selEnd, Track track) {
Envelope env = track.Envelopes.FindByType(envType);
if (env != null) {
double valueIn = env.ValueAt(selStart);
List<EnvelopePoint> points = GetPoints(selStart, selEnd, env);
if (points.Count != 0) {
RemovePoints(points, env);
// ZeroPoints(points);
} else {
env.Points.Add(new EnvelopePoint(selStart, valueIn, MainCurveType));
env.Points.Add(new EnvelopePoint(selEnd, valueIn, MainCurveType));
}
}
}
void RemovePoints (List<EnvelopePoint> points, Envelope env) {
foreach (EnvelopePoint point in points) {
env.Points.Remove(point);
}
}
void ZeroPoints(List<EnvelopePoint> points) {
foreach (EnvelopePoint point in points.GetRange(1,points.Count-2)) {
point.Y = 0;
}
}
List<EnvelopePoint> GetPoints(Timecode selStart, Timecode selEnd, Envelope env) {
Timecode currentTime = Timecode.FromSeconds(0);
List<EnvelopePoint> points = new List<EnvelopePoint>();
Timecode start;
Timecode end;
if (selStart > selEnd) {
start = selEnd;
end = selStart;
} else {
start = selStart;
end = selEnd;
}
for (int counter = env.Points.Count-1; counter >= 0; counter--) {
currentTime = env.Points[counter].X;
if (currentTime >= start && currentTime <= end) {
if (currentTime.ToMilliseconds() != 0) points.Add(env.Points[counter]);
}
if (currentTime < start) break;
}
return points;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment