Community Forums Archive

Go Back

Subject:
Batch Convert with Option Acid Properties 
Posted by: jetdv
Date:3/22/2005 10:16:16 PM

Here's the main code for my Batch Convertor with an option to show the Acid Properties box. Note that it assumes varibles and/or GUI controls to be set in order to function properly. However, the basic code is present for opening a file, setting the Acid properties, and saving the file to a new location and/or type.


private void btnConvert_Click(object sender, System.EventArgs e)
{
ISfRenderer rend = (ISfRenderer)forge.Renderers[cmbFormat.SelectedIndex];
foreach (string file in filearray)
{
//remove the original extension
string newFile = Path.GetFileNameWithoutExtension(file);
newFile = destDir + newFile + "." + rend.Extension;
txtStatus.Text = "Converting: " + file + " to " + newFile;
//Open the file
ISfFileHost forgefile = forge.OpenFile(file, true, false);

if (chkEditAcid.Checked)
{
forge.DoMenu("Edit.ACIDProperties", false);
forge.WaitForDoneOrCancel();
}

//Save in the new format
RenderOptions opt = new RenderOptions();
opt = RenderOptions.OverwriteExisting;

forgefile.RenderAs(newFile, rend.Guid, preset, new SfAudioSelection(0,-1), opt);
SfStatus status = forge.WaitForDoneOrCancel();
forgefile.Close(CloseOptions.DiscardChanges);
txtStatus.Text = txtStatus.Text + " Done...";
}
}

Subject:RE:
Batch Convert with Option Acid Properties 
Reply by: _TJ
Date:3/23/2005 12:06:22 PM

Thank you, Edward.

for those looking in, the code above assumes that you have already declared and initialized variables. So somewhere prior to this function, he has some code like this...

ArrayList filearray = new ArrayList();
filearray.Add(@"c:\Loops\Snare 001.wav");
filearray.Add(@"c:\Loops\Snare 002.wav");

in this block

if (chkEditAcid.Checked)
{
forge.DoMenu("Edit.ACIDProperties", false);
forge.WaitForDoneOrCancel();
}

the call to forge.WaitForDoneOrCancel(); isn't strictly necessary when the DoMenu argument is "Edit.ACIDProperties", but it's good practice to have it there anyway so you can safely change what DoMenu does.

this block

RenderOptions opt = new RenderOptions();
opt = RenderOptions.OverwriteExisting;

could also be written as:

RenderOptions opt = RenderOptions.OverwriteExisting;

Subject:RE:
Batch Convert with Option Acid Properties 
Reply by: jetdv
Date:3/23/2005 12:38:29 PM

Yes, previously in the script filearray is filled with the files selected by the user (from a browse box). That was an entirely different segment of code. For those wondering how it gets filled, I am using this line (where "bcDestBox.Text" contains the default directory in which to start looking):

filearray = common.GetFileList(bcDestBox.Text);


The "GetFileList" routine I used is as follows:

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;
}
}




"chkEditAcid.Checked" checks to see if the checkbox on the GUI is selected. That if statment can be removed if you want it to always open the Edit Acid dialog or the whole section simply removed if you don't want the Edit Acid dialog.

I had initially put a "DoMenuAndWait" command but was trying to get around the "can't change the properties" problem. I actually temporarily had some extra code between those two lines and just never got rid of that one.

Yes, I agree that this code:

RenderOptions opt = new RenderOptions();
opt = RenderOptions.OverwriteExisting;
forgefile.RenderAs(newFile, rend.Guid, preset, new SfAudioSelection(0,-1), opt);



could be condensed. Sometimes I think the three lines are a little easier to read than using a single line:

forgefile.RenderAs(newFile, rend.Guid, preset, new SfAudioSelection(0,-1), RenderOptions.OverwriteExisting);


All combined, this should definitely give the basics for creating a home-grown batch rendering application.

Subject:RE:
Batch Convert with Option Acid Properties 
Reply by: luces1
Date:3/30/2005 8:22:00 AM

Hey there jet. I really appreciate you posting this code. I know that at the present time SF8 has a bug and will not save Acid Properties right now. However, with that stated, I would like to ask about this code.

First off, I know NOTHING about scripting so... do I just take this code and paste it into the Script editor and then compile as some type of file and what type of code is this? Is it jscript or C or something else? Also, is it possible to somehow insert a default value for the Acid Properties into the script? For example; if I know that every file is going to be a loop that is 8 beats per loop AND is 4 beats per measure (this way SF I believe automatically selects the tempo info) can I set the script to just apply this info across the board without having a pop up appear for each and every file that prompts the user to manually select the Properties that are to be saved? I hope I have explained accurately what I am thinking. Thanks again!!!!! luces

Subject:RE:
Batch Convert with Option Acid Properties 
Reply by: jetdv
Date:3/30/2005 9:58:41 AM

This is C# code. You would take the snippets of code and place them within a new script in the edit window. You would need to modify it to perform as needed. It will NOT work without being modified to run properly in that environment (i.e. placed in the proper routine and the required variables set in some way)

Currently those Acid properties cannot be set automatically. All that can be done is opening the Acid Properties box and allowing you to manually pick the desired options.

Go Back