So, this script is made by jetdv (awesome script by the way, thank you for creating it jetdv). It removes silent areas in the project, but every time I try to execute it, for some reason, it deletes all the audio events. Yes, I've tried adjusting the dB levels to see if there was any change, and incredibly, the script only worked when I set the dB level to -3897.98. I don't know why this error occurs, but I saw a comment from another user saying they had the same issue, and I wanted to know if there's anything I can do to fix this error and make the script work again.
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Drawing;
using System.Runtime;
using System.Xml;
using ScriptPortal.Vegas;
namespace Test_Script
{
public class Class1
{
public Vegas myVegas;
Renderer myRenderer = null;
RenderTemplate rndrTemplate = null;
double QuietLimit = -40.0;
Timecode logOffset = Timecode.FromFrames(10);
Timecode minLength = Timecode.FromSeconds(1.5);
bool[,] trackStatus = new bool[1000, 2];
public void Main(Vegas vegas)
{
myVegas = vegas;
FindRenderers();
string tempFile = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp.mp3";
string tempLog = myVegas.TemporaryFilesPath + Path.DirectorySeparatorChar + "temp_loud.txt";
SaveTrackStatus();
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsAudio() && myTrack.Selected)
{
myTrack.Mute = false;
RenderTempFile(tempFile);
ProcessLog(tempLog, myTrack);
File.Delete(tempFile);
File.Delete(tempLog);
myTrack.Mute = true;
}
}
RecallTrackStatus();
}
public void FindRenderers()
{
try
{
foreach (Renderer renderer in myVegas.Renderers)
{
//MP3
if ("adfa6a4b-a99b-42e3-ae1f-081123ada04b" == renderer.ClassID.ToString())
{
myRenderer = renderer;
try
{
foreach (RenderTemplate renderTemplate in renderer.Templates)
{
if (renderTemplate.IsValid())
{
//192 Kbps, CD Transparent Audio
if ("8ab64a16-81f5-46e6-8155-1611d592088c" == renderTemplate.TemplateGuid.ToString())
{
rndrTemplate = renderTemplate;
}
}
}
}
catch
{
}
}
}
}
catch
{
}
}
public void SaveTrackStatus()
{
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsAudio())
{
int myIndex = myTrack.Index;
trackStatus[myIndex, 0] = myTrack.Mute;
trackStatus[myIndex, 1] = myTrack.Solo;
myTrack.Mute = true;
myTrack.Solo = false;
}
}
}
public void RecallTrackStatus()
{
foreach (Track myTrack in myVegas.Project.Tracks)
{
if (myTrack.IsAudio())
{
int myIndex = myTrack.Index;
myTrack.Mute = trackStatus[myIndex, 0];
myTrack.Solo = trackStatus[myIndex, 1];
}
}
}
public void RenderTempFile(string tempFile)
{
RenderArgs args = new RenderArgs();
args.OutputFile = tempFile;
args.RenderTemplate = rndrTemplate;
args.Start = Timecode.FromFrames(0);
args.Length = myVegas.Project.Length;
args.IncludeMarkers = false;
args.StretchToFill = false;
args.GenerateLoudnessLog = true;
RenderStatus status = myVegas.Render(args);
}
public void ProcessLog(string path, Track myTrack)
{
var lines = File.ReadLines(path);
bool foundfirst = false;
bool FoundQuiet = false;
Timecode QuietStart = Timecode.FromFrames(0);
Timecode QuietEnd = Timecode.FromFrames(0);
Timecode PreviousTC = Timecode.FromFrames(0);
foreach (string line in lines)
{
if (line.StartsWith("------------"))
{
if (FoundQuiet)
{
QuietEnd = PreviousTC;
ProcessSegment(QuietStart, myVegas.Project.Length + logOffset, myTrack);
}
break;
}
if (line.StartsWith(" Pos."))
{
foundfirst = true;
}
else
{
if (foundfirst)
{
if (line.Length > 5)
{
string[] pieces = line.Split('\t');
Timecode trackTime = Timecode.FromString(pieces[1]);
double trackVolume = 0;
if (pieces[2].Contains("Inf"))
{
trackVolume = -100;
}
else
{
trackVolume = Convert.ToDouble(pieces[2]);
}
if (trackVolume < QuietLimit)
{
if (!FoundQuiet)
{
FoundQuiet = true;
QuietStart = trackTime;
}
}
else
{
if (FoundQuiet)
{
FoundQuiet = false;
QuietEnd = PreviousTC;
ProcessSegment(QuietStart, QuietEnd, myTrack);
}
}
PreviousTC = trackTime;
}
}
}
}
}
private void ProcessSegment(Timecode QuietStart, Timecode QuietEnd, Track myTrack)
{
Timecode startTC = QuietStart - logOffset;
if (startTC < Timecode.FromFrames(0))
{
startTC = Timecode.FromFrames(0);
}
Timecode endTC = QuietEnd - logOffset;
Timecode regionLen = endTC - startTC;
if (regionLen > minLength)
{
foreach (TrackEvent evnt in myTrack.Events)
{
if (evnt.Start < startTC && evnt.End > startTC)
{
evnt.Split(startTC - evnt.Start);
}
if (evnt.Start < endTC && evnt.End > endTC)
{
evnt.Split(endTC - evnt.Start);
}
}
for (int i = myTrack.Events.Count - 1; i >= 0; i--)
{
TrackEvent evnt = myTrack.Events[i];
if (evnt.Start >= startTC && evnt.End <= endTC)
{
myTrack.Events.Remove(evnt);
}
}
}
}
}
}
public class EntryPoint
{
public void FromVegas(Vegas vegas)
//public void FromVegas(Vegas vegas, String scriptFile, XmlDocument scriptSettings, ScriptArgs args)
{
Test_Script.Class1 test = new Test_Script.Class1();
test.Main(vegas);
}
}
What a user with the same problem in the script commented ("This workaround doesn't work for me; I already tested it").