Community Forums Archive

Go Back

Subject:Problem running RunBatchJob.cs
Posted by: Antonw
Date:5/11/2010 7:05:51 AM

We're trying to automate the batch conversion (applying a number of presets)
of a large number of samples using the SoundForge ScriptSDK. I now have a test
script running, based on a modified RunBatchJob.cs, and it sort of works, but
only on the second run of the script, and only after first starting SoundForge
in a separate process. Here's what I do:

1. We've created a batch job to do the actual conversion. Right now it just contains
a number of sample presets. Running this batch job manually from within SoundForge
works fine.
2. I've modified RunBatchJob.cs so that it takes the filename of the batchjob and the
filename of the wav file to convert as parameters. See below for
the modified C# source.
3. We start soundforge with the following commandline:
Forge90.exe -SCRIPTARGS:"bj_file=Test.bj & wav_file=Test.wav" -RUNSCRIPT:"RunBatchJob.cs"
(full paths to the various file omitted to keep this line short)

If I run this (with SoundForge not yet running), I get this in the script otput window:
BatchJob is 'Test.bj'
Wavfile is 'Test1.wav'
Batch cancelled on [Check Save tab for errors] for file 'Error '

If I then leave SoundForge running and run the same commandline again it succeeds:
BatchJob is 'Test.bj'
Wavfile is 'Test.wav'
Success on [Process 1: Sony Volume] for file 'Test.wav'
Success on [Process 2: Sony Wave Hammer] for file 'Test.wav'
Success on [Process 3: Reverse] for file 'Test.wav'
Success on [Process 4: Sony Distortion] for file 'Test.wav'
Success on [Process 5: Sony Pitch Shift] for file 'Test.wav'
Success on [Process 6: Resample] for file 'Test.wav'
Success on [Save source file] for file 'Test.wav'
Check status on [Job complete] for file 'Batch Job'

If I start SoundForge before running the script the first time it still fails,
and the second time it again succeeds. Any idea what is going wrong here?
Or is there a better way in which we automate the applying of presets to a large
amount of samples?

**********************************************************************************************

Modified RunBatchJob.cs:


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

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

// clear status fields in preparation for our run.
app.SetStatusField(0, null);
app.SetStatusField(1, null);

String bj_file = GETARG("bj_file", "");
BatchJob bj = Engine.LoadJobFromFile(bj_file);
if (null == bj)
return;
DPF("BatchJob is '{0}'", bj.Filename);

String wav_file = GETARG("wav_file", "");
DPF("Wavfile is '{0}'", wav_file);

FileRegionCollection files = new FileRegionCollection();
files.Add(new FileRegion(wav_file, SfAudioSelection.All));

Engine engine = new Engine();
engine.StatusEvent += new Engine.StatusEventHandler(job_StatusEvent);
engine.TotalEvent += new Engine.TotalEventHandler(job_TotalEvent);
engine.ProgressEvent += new Engine.ProgressEventHandler(job_ProgressEvent);

SfStatus ret = SfStatus.Success;
try
{
engine.Cancel = false;
ret = engine.Run(bj, files);
}
catch (Exception e)
{
DPF(e.ToString());
ret = SfStatus.Fail;
}
finally
{
engine.Clear();
app.SetStatusField(0, ret.ToString());
}
}

private void job_StatusEvent(Object sender, Engine.StatusEventArgs se) {
DPF("{0} on [{1}] for file '{2}'", se.status, se.step, se.filename);
}

private void job_TotalEvent(Object sender, Engine.TotalEventArgs se) {
ForgeApp.SetStatusField(1, String.Format(@"file {0}/{1}", se.index, se.total));
}

private void job_ProgressEvent(Object sender, Engine.ProgressEventArgs se) {
ForgeApp.SetStatusField(0, String.Format("{0:N1} %", se.dPercentDone));
}


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


Go Back