Community Forums Archive

Go Back

Subject:Simple task, batch or script?
Posted by: WayneM
Date:5/4/2012 2:21:26 PM

Tired of the same repetitive action over and over, I looked at some sample scripts here. What I need to do is pad the head and tail of a bunch of files with some silence. I have done this manually and have pre-sets in Insert Silence. I also believe I could put this in a batch job, but that would make it more complex.

So, I'm running SF 10. Assuming I have a file open, before saving I need to pad the front with a fixed amount of silence and then pad the end with a different amount of silence. I'd like to assign this to a hotkey as I would do this often.

Is this easy to do with scripting? I did some programming in the darker ages, but looking at several scripting examples hasn't helped.

Any suggestions appreciated, especially if there is already a script around that I can just modify for my needs.

Or, is there a way to create a batch task and then convert it to a script?

Wayne

Subject:RE: Simple task, batch or script?
Reply by: roblesinge
Date:5/5/2012 12:05:50 PM

This should be pretty easy to code up. I know you could move a hot button for it onto the toolbar, but I'm not sure about mapping it to a keyboard shortcut. Do the differing silences on the head and tail need to be variable, or are they each static for each run of the script?

Rob.

Subject:RE: Simple task, batch or script?
Reply by: WayneM
Date:5/14/2012 6:49:25 PM

For the current project it is just fixed amounts.

Thanks.

Subject:RE: Simple task, batch or script?
Reply by: roblesinge
Date:6/5/2012 7:40:35 AM

Sorry it has taken so long to respond. The code below should do what you want. You'll need to change the amount of silence (in milliseconds) that gets passed to the SecondsToPosition method for the head and tail. Otherwise, it should do exactly what you asked. Not sure about assigning this to a hotkey, but you could add it to the Sound Forge script menu and then trigger it from the toolbar.


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)
{
//Set variables to lengths of silence you want inserted in samples (argument is silence in milliseconds)
long secToSampHead = app.CurrentFile.SecondsToPosition(.400);
long secToSampTail = app.CurrentFile.SecondsToPosition(.400);

//Insert Silence to head of file.
app.CurrentFile.InsertSilence(0, secToSampHead);

//Insert Silence to tail of file.
app.CurrentFile.InsertSilence(app.CurrentFile.Length, secToSampTail);
}

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



Hope this helps,
Rob.

Subject:RE: Simple task, batch or script?
Reply by: WayneM
Date:6/12/2012 7:06:36 PM

Rob,

Thanks so much! Sorry for the delay and additional thanks for the PM to say you had posted it. Don't understand why Sony doesn't allow us to get a ping so we (I) don't forget to check for replies.

Your well documented code will help me get my feet wet, and maybe even solve my next challenge myself. . .maybe someday even help someone else. That's what this is all about.

Again, Thank You.

Wayne

Go Back