Community Forums Archive

Go Back

Subject:supress sfl creation
Posted by: GPD
Date:10/11/2007 9:53:51 PM

Is it possible to supress sfl creation during a script?

I've made a script to cut one large source file into several small peices and save these all as seperate files.

The script runs fine but it littlers the output folder with .sfl files. (even though app prefs are to delete temp files on close).

Also is it possible to read the file type (ie wav or aif etc from the orrignal file and use this for the created files?) I am doing this for sample rate, bit depth, channels etc, but my files are saving as .wav even though the source is aif.

Subject:RE: supress sfl creation
Reply by: ForumAdmin
Date:10/12/2007 10:44:50 AM

NewFile and OpenFile both take an "fNoWindow" argument, which is a slight misnomer. There will still be a window, just no data drawn in it, and no peaks generated.

The temp file pref appears to working for me in Forge 9.0c. Note that the files will not be deleted until all references are released and/or the app itself is closed. If you can provide a short script that exhibits the problem, please do so.

You can get the current file's type via ISfFileHost::SaveFormat(), (e.g. ISfRenderer rend = file.SaveFormat). It can be null for certain types, but should be fine for .aif and .wav.

J.

Subject:RE: supress sfl creation
Reply by: GPD
Date:10/12/2007 4:28:36 PM

Thanks!

  
ISfFileHost file1 = app.OpenFile(strFilename1, true, true) ;
ISfFileHost file2 = app.NewFile(file1.DataFormat, false) ;



What are the true, true, false aguments above for and where do insert the "fNoWindow" argument?

I could not find a list of the OpenFile and NewFile arguments in the scirpting SDK help.

Message last edited on10/12/2007 4:40:07 PM byGPD.
Subject:RE: supress sfl creation
Reply by: GPD
Date:10/12/2007 4:41:57 PM

Found it:

ISfFileHost OpenFile(
string pszFileName,
bool fReadOnly,
bool fNoWindow
);


ISfFileHost NewFile(
SfWaveFormat wfx,
bool fNoWindow
);


So, my "false" argument in NewFile should be "true" I believe?

Subject:RE: supress sfl creation
Reply by: GPD
Date:10/12/2007 5:26:58 PM

I changed this to true, but I still get sfl files. Here is the full script:



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

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

string familyName = "My Cool File" ;

string strFilename1 = @"d:\0000 SF Batch Folder\XXXX.aif" ;
ISfFileHost file1 = app.OpenFile(strFilename1, true, true) ;
ISfFileHost file2 = app.NewFile(file1.DataFormat, true) ;






//////////////////////////////////////////////////////////////////////////////////////////////Loop1

const int nPValNum1 = 32 ; // NUMBER OF P VALUES

int iP1 ;
for (iP1 = 0; iP1 < nPValNum1; iP1++)
{

Int64 selOffset = Convert.ToInt64(file1.SampleRate * 0.5) ;
Int64 selStart = Convert.ToInt64(file1.SampleRate * iP1 *4 + selOffset) ;
Int64 selLength = Convert.ToInt64(file1.SampleRate * 2.0) ;
Int64 fileNum = Convert.ToInt64(iP1 + 1) ;

SfAudioSelection Select1 = new SfAudioSelection(selStart, selLength, 0) ; // define selection according to iterations
file2.OverwriteAudio(0, 0, file1, Select1) ; // copy/paste segment from file1 to overwrite file2

string strOutfile = String.Format(@"d:\0000 SF Batch Folder\{0} {1:000}.wav", familyName, fileNum) ; // Auto Create File Names
file2.SaveAs(strOutfile, file1.SaveFormat.Guid, file1.DataFormat , RenderOptions.AndClose) ;
file2.WaitForDoneOrCancel() ;



} // Exit iP1 Loop

//////////////////////////////////////////////////////////////////////////////////////////////


;
file1.Close(CloseOptions.DiscardChanges) ;
file1.WaitForDoneOrCancel() ;
file2.Close(CloseOptions.DiscardChanges) ;
file2.WaitForDoneOrCancel() ;



}




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;

} //EntryPoint



Can you see where the problem is?

Can you also show a rewite of the Save.As line to get the files to save as the same type as the source (aif)? I don't completely follow your suggestions above...

thx.


Message last edited on10/12/2007 5:31:55 PM byGPD.
Subject:RE: supress sfl creation
Reply by: ForumAdmin
Date:10/15/2007 7:55:38 AM

Well, I feel silly. Apparently, I've been addressing the wrong issue.

.sfl files are the extra metadata that cannot be embedded in a file (.aif in this case). These are not treated as temporary files. If you don't want them generated, do a manual Save As of some random test file and uncheck the "Save metadata" checkbox before you click OK.

Alternatively, make sure Options->Prefs->General->"Warn when metadata cannot be saved in the file" is checked, then add a region to an .aif file and click Save. You'll get a dialog asking you whether you want to use an external (.sfl) file for metadata. Just check the "Remember my setting" checkbox and click "No."

I had .sfk stuck in my head, which are the peak files that all the aforementioned wrangling will manage, but that's not what you were talking about in the first place...sorry.

J.

Subject:RE: supress sfl creation
Reply by: GPD
Date:10/16/2007 12:22:42 PM



.sfl files are the extra metadata that cannot be embedded in a file (.aif in this case). These are not treated as temporary files. If you don't want them generated, do a manual Save As of some random test file and uncheck the "Save metadata" checkbox before you click OK.



I did this and stilll get SFL files. (now using 9.c)



Alternatively, make sure Options->Prefs->General->"Warn when metadata cannot be saved in the file" is checked, then add a region to an .aif file and click Save. You'll get a dialog asking you whether you want to use an external (.sfl) file for metadata. Just check the "Remember my setting" checkbox and click "No."



I did these steps, but I do not get a dialog asking about an external file. Maybe I need to reset the prefs somewhow? How?

In summary, I still get this little damn files everywhere... ;-)

Message last edited on10/16/2007 12:28:22 PM byGPD.
Subject:RE: supress sfl creation
Reply by: GPD
Date:10/16/2007 1:14:22 PM

Also, the above script opens an .aif but still is saving .wavs.

Could you show what I have wrong? I want the saved output files to be exactly the same format as the input (whatever it is), AIFF in this case.

This is what I am using without sucess:



file2.SaveAs(strOutfile, file1.SaveFormat.Guid, file1.DataFormat , RenderOptions.AndClose);

Message last edited on10/16/2007 1:20:44 PM byGPD.
Subject:RE: supress sfl creation
Reply by: ForumAdmin
Date:10/17/2007 9:45:23 AM

Try this. Rather than mess with getting the right prefs set, it just deletes the .sfl files.


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

public class EntryPoint
{
public void Begin(IScriptableApp app)
{
string fileName = @"d:\0000 SF Batch Folder\XXXX.aif";
ISfFileHost file = app.OpenFile(fileName, true, true);
//ISfFileHost file = app.CurrentFile;

ISfRenderer familyRend = file.SaveFormat;
string familyName = "My Cool File";
string familyDir = Path.GetDirectoryName(file.Filename);
string familyExt = familyRend.Extension;

// extract 2 second sections, every 4 seconds, starting at 0.5 seconds
//
SfAudioSelection asel = new SfAudioSelection(file.SampleRate/2, 2*file.SampleRate);

uint ccInc = 4*file.SampleRate;
uint cFiles = 0;
const uint cMaxFiles = 32;

while (asel.Start + asel.Length <= file.Length)
{
if (cMaxFiles < ++cFiles)
break;

// generate filename
string name = String.Format("{0} {1:000}.{2}", familyName, cFiles, familyExt);
string path = Path.Combine(familyDir, name);

// render this selection
file.RenderAs(path, familyRend.Guid, "Default Template", asel, RenderOptions.RenderOnly);
SfStatus status = file.WaitForDoneOrCancel();
if (SfStatus.Success != status)
{
DPF("Save {0} failed. Bailing...", path);
break;
}

// manually delete .sfl file (default fourcc tags are external in aif)
app.WaitForDoneOrCancel();
File.Delete(path + ".sfl");

// increment selection for next region
asel.Start += ccInc;
}

file.Close(CloseOptions.DiscardChanges);
}

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



J.

Message last edited on10/17/2007 9:49:27 AM byForumAdmin.
Subject:RE: supress sfl creation
Reply by: GPD
Date:11/15/2007 2:04:10 PM

I get the following error with your script:

Sound Forge Error 0x8004E007 The file could not be opened. Make sure the file exists and that you have access to the file/folder.
while calling SoundForge.ISfGenericPreset RenderAs(System.String, System.String, System.Object, SoundForge.SfAudioSelection, SoundForge.RenderOptions)
--------message----------
You made a method call on a COM+ component that has a transaction that has already committed or aborted. (Exception from HRESULT: 0x8004E007)
--------Stack Trace----------
at SoundForge.ISfFileHost.RenderAs(String strFilename, String strFormatNameorGUID, Object vTemplateNameOrData, SfAudioSelection asel, RenderOptions opt)
at EntryPoint.Begin(IScriptableApp app)
at EntryPoint.FromSoundForge(IScriptableApp app)


The file opens correctly despite the warning. Display is diaabled (correctly) and I can play back the source audio file, but the script does not make it any farther than this...

ideas?

Subject:RE: supress sfl creation
Reply by: ForumAdmin
Date:11/16/2007 7:37:22 AM

Works fine for me in both 8.0d and 9.0c. What is the format of your source file? Have you changed any of the strings? Is the name passed to Render As a valid path?

J.

Message last edited on11/16/2007 7:38:07 AM byForumAdmin.
Subject:RE: supress sfl creation
Reply by: GPD
Date:2/27/2008 9:36:47 AM

HI.

In your example above how would I use "string fileName" from the orriginal file as the "string familyName"?

In other words, instead of using a new family name, I will keep the name of the file I am opening and then just add a version number to it for mulitple variations that I am rendering.

I guess I somehow need to extract the name of orriginal file to exlcude the path and extension since I will add that back later... How would I do this?

thx.

Message last edited on2/27/2008 9:38:10 AM byGPD.
Subject:RE: supress sfl creation
Reply by: GPD
Date:2/27/2008 10:10:54 AM

Go it:


string familyName = Path.GetFileNameWithoutExtension(file.Filename);

Go Back