Community Forums Archive

Go Back

Subject:Cash for Scripts!
Posted by: Huge Headboards
Date:1/21/2015 3:50:33 AM

Hello Everyone,

I need a script creating for me - I'm not a programmer and this is way beyond me, but I'm willing to pay for it if anyone is interested. you can email me at hugh_edwards @ high-score .co.uk.

Judging by what people are creating on here, I think it's relatively simple - I have around 10,000 files in one directory and another 1 file in a different directory. That one file needs to be inserted at the start and at the end of each of the 10,000 files with no gaps inbetween.

If anyone can help please email me on the above!

Hugh.

Subject:RE: Cash for Scripts!
Reply by: roblesinge
Date:1/21/2015 10:47:16 PM

I wrote this a long time ago, but it should do what you want. Just swap out the two starting paths to the directories on your system you want to start the selections in.

NOTE: This makes destructive edits to the files, so you may want to make a copy just in case. It would also be relatively easy to add in a "Save To" portion if you wanted to be able to select a separate output folder.

-Rob.



using System;

using System.IO;

using System.Windows.Forms;

using SoundForge;



public class EntryPoint
{

public void Begin(IScriptableApp app)
{
string fPasteFrom = app.GetOpenFilename(@"S:\Audio");
ISfFileHost pasteFile = app.OpenFile(fPasteFrom, true, false);

string strFolder = SfHelpers.ChooseDirectory("Select folder containing your paste-to files", @"S:\Audio");

foreach (string strFilename in Directory.GetFiles(strFolder, "*.wav"))
{

SfStatus status = ProcessFile(app, strFilename, pasteFile);

if (status != SfStatus.Success)
{

DPF("{0} : {1}", strFilename, status.ToString());

// quit if processing or save failed.

break;

}

}

}



public bool bEnableProcessingLog = true;



public SfStatus ProcessFile(IScriptableApp app, string strFilename, ISfFileHost fPasteFrom)
{

if (bEnableProcessingLog)

DPF("processing {0}", strFilename);



ISfFileHost file = app.OpenFile(strFilename, false, true);

if (null == file)

return SfStatus.Fail;



file.WaitForDoneOrCancel();


// Paste to beginning with ReplaceAudio function.

long ccInsert = 0; // 0 to insert a the beginning of the file.
file.ReplaceAudio(new SfAudioSelection(ccInsert, 0), fPasteFrom, new SfAudioSelection(fPasteFrom));


//Paste same fPasteFrom to the end of the selected file

file.OverwriteAudio(file.Length, 0, fPasteFrom, new SfAudioSelection(fPasteFrom));



// wait for processing to complete, and if it succeeds, save the file

SfStatus status = file.WaitForDoneOrCancel();

if (status == SfStatus.Success)
{

file.Save(SaveOptions.PromptIfNoFilename);

status = file.WaitForDoneOrCancel();

}



file.Close(CloseOptions.DiscardChanges);

return status;

}





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, object o) { ForgeApp.OutputText(String.Format(fmt, o)); }

public static void DPF(string fmt, object o, object o2) { ForgeApp.OutputText(String.Format(fmt, o, o2)); }

public static void DPF(string fmt, object o, object o2, object o3) { ForgeApp.OutputText(String.Format(fmt, o, o2, o3)); }

} //EntryPoint

Message last edited on1/21/2015 10:49:50 PM byroblesinge.

Go Back