Community Forums Archive

Go Back

Subject:Insert silence script does not update Total Length
Posted by: thal
Date:7/22/2014 8:08:06 PM

I am writing a script for Sound Forge 9.0e to pad the length of an audio file to a predetermined length by inserting however much silence I need at File End based on the original length. For example: I have a 30 ms audio file that I wish to pad to 200 ms.

However, after running the script, the Selection Start and Selection End display correctly as 0 and 200 ms respectively, but the Total Length in the Status Bar still shows 30 ms.

Conversely, the built in Insert Silence plug-in lengthens the file AND updates the total length in the status bar. I want my script to update Total Length as well.

using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;
using System.Collections;
using System.Collections.Generic;

public class EntryPoint
{
public void Begin(IScriptableApp app)
{
// how much silence to insert to achieve length
long secToSampTail = app.CurrentFile.SecondsToPosition(.200) - app.CurrentFile.Length;

// InsertSilence at tail
app.CurrentFile.InsertSilence(app.CurrentFile.Length, secToSampTail);
app.ActiveWindow.SelectionLength = app.CurrentFile.Length;
}

public void FromSoundForge(IScriptableApp app)
{
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, params object[] args) { ForgeApp.OutputText(String.Format(fmt, args)); }
} //EntryPoint

Any help would be appreciated.

Subject:RE: Insert silence script does not update Total Length
Reply by: roblesinge
Date:7/23/2014 8:03:25 AM

Just a reminder, if you're going to post code, make sure you put code tags around it.

You'll have to update the statistics on the file for Total Length to be current. You can do this by adding a call to the UpdateStatistics() method on your app.CurrentFile. Code would look like this:


using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;
using System.Collections;
using System.Collections.Generic;

public class EntryPoint
{
public void Begin(IScriptableApp app)
{
// how much silence to insert to achieve length
long secToSampTail = app.CurrentFile.SecondsToPosition(.200) - app.CurrentFile.Length;

// InsertSilence at tail
app.CurrentFile.InsertSilence(app.CurrentFile.Length, secToSampTail);
SfAudioSelection asel = new SfAudioSelection(app.CurrentFile);
app.CurrentFile.UpdateStatistics(asel);
app.ActiveWindow.SelectionLength = app.CurrentFile.Length;
}

public void FromSoundForge(IScriptableApp app)
{
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, params object[] args) { ForgeApp.OutputText(String.Format(fmt, args)); }
} //EntryPoint


-Rob

Subject:RE: Insert silence script does not update Total Length
Reply by: thal
Date:7/23/2014 12:14:03 PM


using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;
using System.Collections;
using System.Collections.Generic;

public class EntryPoint
{
public void Begin(IScriptableApp app)
{
// how much silence to insert to achieve length
long secToSampTail = app.CurrentFile.SecondsToPosition(.200) - app.CurrentFile.Length;

// InsertSilence at tail
app.CurrentFile.InsertSilence(app.CurrentFile.Length, secToSampTail);
app.ActiveWindow.SelectionLength = app.CurrentFile.Length;
}

public void FromSoundForge(IScriptableApp app)
{
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, params object[] args) { ForgeApp.OutputText(String.Format(fmt, args)); }
} //EntryPoint

Go Back