Community Forums Archive

Go Back

Subject:STRING a bunch of files into one
Posted by: errhuman
Date:4/6/2006 8:18:36 AM

TJ,
Hope you get his one.. super simple, but yet, I cant seem to make it happen.

I have X number of individual files to string together into one output file... yep thats it... I read the DESPERATLEY NEED HELP to extract some of the code from there, but I cant get it to compile. I not very familiar with C#. Jscript preferable, but at this point. I dont care, any script will work just fine. PLEASE HELP ME OUT>. I am on a serious time constraint... thanks in advance...

errhuman.

Subject:RE: STRING a bunch of files into one
Reply by: _TJ
Date:4/8/2006 2:45:30 PM

Ok. this one is pretty easy. But as always, much of the compexity in a script has to do with telling it which files to process.

Since I dont know how you are going to identify the files to process, I'm going to assume that you have a list of filenames somewhere that you are just going to put right into the script.

And I'm going to assume that you want your final file to be in the same format as the first file you want to string together. With those caveats, here's a script that will append a bunch of files together.


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

public class EntryPoint {
public void Begin(IScriptableApp app) {

// the list of filenames to string together
//
string[] astrFilenames = {
@"c:\filename1.wav",
@"c:\filename2.wav",
@"c:\filename3.wav"
};

// open the first file (so we know what sample rate and channels to use)
//
string strFirstFile = astrFilenames[0];
ISfFileHost fileSrc = app.OpenFile(strFirstFile, true, true);
if (null == fileSrc)
{
DPF("Could not open {0}", strFirstFile);
return;
}

// create an output file in the same format as the first file.
//
ISfFileHost fileOut = app.NewFile(fileSrc.DataFormat, true);
if (null == fileOut)
{
DPF("Could not create output file");
}

// now open each file in the list and paste each onto the end of the output file
//
foreach (string strFilename in astrFilenames)
{
fileSrc = app.OpenFile(strFilename, true, true);
fileOut.OverwriteAudio(fileOut.Length, 0, fileSrc, new SfAudioSelection(fileSrc));
fileSrc.Close(CloseOptions.DiscardChanges);
}

// now ask the user where to save the output file.
//
fileOut.Save(SaveOptions.PromptIfNoFilename);

}

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)); }
public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; }
public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); }
public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); }
} //EntryPoint



Subject:RE: STRING a bunch of files into one
Reply by: errhuman
Date:4/10/2006 8:09:23 AM

TJ,

thanks again for your help, we are almost there. This is where I keep getting hung up. I was able to almost write the script on my own with the example from the other post, however, I cant seem to make it prompt me for the save.

Here is the error.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at SoundForge.ISfFileHost.Save(SaveOptions opt)
at EntryPoint.Begin(IScriptableApp app)
at EntryPoint.FromSoundForge(IScriptableApp app)
--- End of inner exception stack trace ---


I ran into the same problem on my own. Thanks again for you assistance.
errhuman

Subject:RE: STRING a bunch of files into one
Reply by: errhuman
Date:4/10/2006 8:12:39 AM

sorry forgot to add that this error was with your script as well. I created sample files just to test the script.

btw, your caveots are all correct, and acceptable.

errhuman

Subject:RE: STRING a bunch of files into one
Reply by: _TJ
Date:4/11/2006 1:22:15 PM

It turns out that there is a bug in app.NewFile(SfWaveFomat wfx, bool fNoWindow). If you use fNoWindow == true, then you end up with a temp file that cannot be Save()'d ! I've used this in the past with RenderAs().

Sorry. I was writing that script off of the top of my head, and I ended up writing one that didn't work.

So, there are two possible fixes. Either change fNoWindow in the app.NewFile() call from true to false, or change the fileOut.Save() call to a fileOut.RenderAs() call.

The easy fix is to change

ISfFileHost fileOut = app.NewFile(file1.DataFormat, true); // this file can't be saved

to

ISfFileHost fileOut = app.NewFile(file1.DataFormat, false); // this file can be saved


tj



Message last edited on4/11/2006 1:23:14 PM by_TJ.
Subject:RE: STRING a bunch of files into one
Reply by: errhuman
Date:4/18/2006 9:40:19 AM

TJ,

thanks a million, i was going out of my mind triple checking everything. Got it, works like a charm.

Best.

errhuman

Go Back