Community Forums Archive

Go Back

Subject:Simple script help
Posted by: RTVOK
Date:4/28/2011 8:18:45 AM

Hello, i'm totally new in SF scripting and i need an advice or some directions how to make a script that will delete specified length from beginning and from the end of an sound file and save that file (replace with existing). I wanna do this like a "batch" process. Thanks :)

Subject:RE: Simple script help
Reply by: roblesinge
Date:4/28/2011 1:41:13 PM

Is the length of time constant throughout the batch? Meaning, you want the same amount of time off the F & B of all files?

Does that need to be selectable, or can it just be built into the script?

Rob.

Subject:RE: Simple script help
Reply by: roblesinge
Date:4/28/2011 9:48:26 PM

This is just something I threw together quickly. It has virtually no error handling, so it's easy to break. You have to make sure that all of the files are longer than the amount you're trying to delete from them. It could be cleaned up if needed to handle exceptions like that. All the files you want to batch need to be in one folder, which you select when running the script.


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)
{
//Input section

//Get the folder where the files you want batched are stored.
string strFolder = SfHelpers.ChooseDirectory("Choose the folder containing your files.", @"C:\");

//Get the amount of time you want trimmed from beginning.
string trimFront = SfHelpers.WaitForInputString("How much time (in Seconds) do you want trimmed from the beginning of each file?", "0");

//Get the amt of time you want trimmed from end.
string trimEnd = SfHelpers.WaitForInputString("How much time (in Seconds) do you want trimmed from the end of each file?", "0");


//Where the action starts

//Get list of files to work with
string[] fileHolder = Directory.GetFiles(strFolder);

//Open a reference file to get the sample rate
ISfFileHost syncstat = app.OpenFile(fileHolder[0], true, false);

//figure out samples from the times given.
long fromFront = syncstat.SecondsToPosition(double.Parse(trimFront));
long fromEnd = syncstat.SecondsToPosition(double.Parse(trimEnd));

syncstat.Close(CloseOptions.DiscardChanges);

//loop through the files and crop the audio outside of the desired selection.
for (int x = 0; x < fileHolder.Length; x++)
{
ISfFileHost trim = app.OpenFile(fileHolder[x], false, true);
trim.CropAudio(fromFront, ((trim.Length - fromFront) - fromEnd));
trim.WaitForDoneOrCancel();
trim.Close(CloseOptions.SaveChanges);
}

}

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


Is this what you were trying to do?

-Rob.

Message last edited on4/29/2011 7:43:29 AM byroblesinge.
Subject:RE: Simple script help
Reply by: RTVOK
Date:5/9/2011 8:12:54 AM

Yes sir, length is constant in every file from the beginning and from the end.
i will now check script that you wrote.

Thanks for your reply, Vladimir.

Subject:RE: Simple script help
Reply by: RTVOK
Date:5/9/2011 8:18:47 AM

Sir, you are super duper man :)

That's exactly what i needed. Thank you very, very, very much!

Go Back