Community Forums Archive

Go Back

Subject:Batch Fade In & Out
Posted by: rsp
Date:8/1/2005 2:02:34 AM

I asked a question about Batch Fade In & Out in this thread:

http://www.sonymediasoftware.com/forums/ShowMessage.asp?MessageID=400582&Replies=5

Am not very experienced with scripting so i'm hoping someone can help me finishing this one with the code that TJ suggested:

Int64 fadesize = file.SecondsToPosition(1.0);
SfAudioSelection asel = new SfAudioSelection(0, fadesize);
file.DoEffect("Fade In", 0, asel, EffectOptions.EffectOnly);
file.WaitForDoneOrCancel();

asel = new SfAudioSelection(file.Length - fadesize, fadesize);
file.DoEffect("Fade Out", 0, asel, EffectOptions.EffectOnly);
file.WaitForDoneOrCancel();

Have pasted this in a new Jscript template and get this error:
"Compiler error 0x80004005 on Line 9,4 : The list of attributes does not apply to the current context"

Any help would be appreciated

Subject:RE: Batch Fade In & Out
Reply by: jetdv
Date:8/1/2005 6:57:43 AM

Did you set "file"?

Subject:RE: Batch Fade In & Out
Reply by: rsp
Date:8/1/2005 8:38:04 AM

Thanks: I pasted the above code into a new Jscript window - which doesn't have any code for setting a file. Have opened some of the example scripts and seen some leads so will try if i can get any of that to work

Subject:RE: Batch Fade In & Out
Reply by: _TJ
Date:8/2/2005 4:58:09 PM

That's just the body of the code that does fades. You also need to have code to open a file and save it.

If the file is already open in Sound Forge, then you can just set

ISfFileHost file = app.CurrentFile;


Also, this is not jscript code. this is C# code, so you have to use a new C# template or you will get syntax errors.

tj

Subject:RE: Batch Fade In & Out
Reply by: rsp
Date:8/5/2005 5:42:34 AM

Thanks jetdv and TJ - not enough time to learn everything but i got my first script working!

Can i ask another question: is there code that will work on a folder with various files for this batch fade in/out?

Subject:RE: Batch Fade In & Out
Reply by: jetdv
Date:8/5/2005 6:45:47 AM

Certainly. It's just a matter of reading which files and then processing them all. This code will call a routine that will let you select a series of files and will then process all of those files.


private string[] filearray;

filearray = GetFileList("c:\\"); //Change this path to your desired default path
foreach (string file in filearray)
{
//Process the files as needed
}





public string[] GetFileList(string OrgSaveDir)
{
if (OrgSaveDir == null)
{
OrgSaveDir = "";
}
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;
openFileDialog.Title = "Select file(s) to convert";
if (!(OrgSaveDir == ""))
{
string initialDir = OrgSaveDir;
if (Directory.Exists(initialDir))
{
openFileDialog.InitialDirectory = initialDir;
}
}
else
{
openFileDialog.InitialDirectory = "c:\\";
}
if (System.Windows.Forms.DialogResult.OK == openFileDialog.ShowDialog())
{
return openFileDialog.FileNames;
}
else
{
return null;
}
}


Subject:RE: Batch Fade In & Out
Reply by: _TJ
Date:8/5/2005 10:04:57 PM

Thanks jetdv.

I notice that he's using a variable named file but not in the same
way that my sample code. If I may offer a clarification


private string[] filenamearray;

filenamearray = GetFileList("c:\\"); //Change this path to your desired default path
foreach (string filename in filenamearray)
{
ISfFileHost file = app.OpenFile(filename, false, false);

//Process the files as needed

// save back to original file
file.Save(SaveOptions.AndClose);
file.WaitForDoneOrCancel();

// to save to a new file, use file.SaveAs(...) or file.RenderAs(...)
// followed by file.Close(CloseOptions.DiscardChanges);
}


Message last edited on8/5/2005 10:05:33 PM by_TJ.

Go Back