Community Forums Archive

Go Back

Subject:
 Full Blown Batch convert dropped down to a single CS
Posted by: jetdv
Date:3/23/2005 2:26:26 PM

I have converted everything necessary to let the Batch Convert program run as a single CS file. However, this does impose more limitations when it comes to editing the script - except it can now be edited in the SF8 Script Editor. Just copy all of the following code and either Paste it into the Script Editor or paste it into Notepad. Then save the file as BatchConvert.cs. It should then run fine in SF8.

NOTE: It does NOT display the picture. I removed that part just in case. Also, the version will show as 0.0.0.0 since this has not been compiled.

----------------------------------> Beginning of Script


using System;
using System.Drawing;
using System.Collections;
using System.IO;
using System.ComponentModel;
using System.Windows.Forms;
using System.Reflection;
using Microsoft.Win32;
using SoundForge;



public class EntryPoint
{
private static BatchConvert.BatchConvertForm form;

private static IScriptableApp app;

public void FromSoundForge(IScriptableApp app)
{
EntryPoint.app = app;

// your code begins here.
//
app.SetStatusText("Script Started");

form = new BatchConvert.BatchConvertForm(app);
form.ShowDialog();

app.SetStatusText("Script Complete");
}
}

namespace BatchConvert
{


/// <summary>
/// Summary description for Form1.
/// </summary>
public class BatchConvertForm : System.Windows.Forms.Form
{
private SoundForge.IScriptableApp forge;
private ISfGenericPreset preset;
private string[] filearray;

private System.Windows.Forms.Button btnBrowseDest;
private System.Windows.Forms.TextBox bcDestBox;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox cmbFormat;
private System.Windows.Forms.Button btnPreset;
private System.Windows.Forms.TextBox txtPreset;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Button btnConvert;
private System.Windows.Forms.RichTextBox txtSelFiles;
private System.Windows.Forms.TextBox txtStatus;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label lblVersion;
private System.Windows.Forms.CheckBox chkEditAcid;

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public BatchConvertForm(SoundForge.IScriptableApp app)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
forge = app;

//Load the dialog box with the save types.
int cRend = app.Renderers.Count;

for (int ii = 0; ii <= app.Renderers.Count - 1; ii++)
{
ISfRenderer rend = (ISfRenderer)app.Renderers[ii];
string rName = rend.Name;
string rExt = rend.Extension;

if (rName == null) rName = "{Unknown}";
if (rExt == null) rExt = "???";

cmbFormat.Items.Add(ii + " " + rName + " (" + rExt + ")");
}

cmbFormat.SelectedIndex = 0;

Version version = Assembly.GetExecutingAssembly().GetName().Version;
lblVersion.Text = "Version: " + version;


}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

public string GetSaveDir(string OrgSaveDir)
{
if (OrgSaveDir == null)
{
OrgSaveDir = "";
}
FolderBrowserDialog saveFileDialog = new FolderBrowserDialog();
saveFileDialog.Description = "Select the desired folder";
saveFileDialog.ShowNewFolderButton = true;
if (!(OrgSaveDir == ""))
{
string initialDir = OrgSaveDir;
if (Directory.Exists(initialDir))
{
saveFileDialog.SelectedPath = initialDir;
}
} else {
saveFileDialog.SelectedPath = "c:\\";
}
if (System.Windows.Forms.DialogResult.OK == saveFileDialog.ShowDialog())
{
return Path.GetFullPath(saveFileDialog.SelectedPath) + Path.DirectorySeparatorChar;
} else {
return OrgSaveDir;
}
}


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

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.bcDestBox = new System.Windows.Forms.TextBox();
this.btnBrowseDest = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.cmbFormat = new System.Windows.Forms.ComboBox();
this.btnPreset = new System.Windows.Forms.Button();
this.txtPreset = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.btnConvert = new System.Windows.Forms.Button();
this.txtSelFiles = new System.Windows.Forms.RichTextBox();
this.txtStatus = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.label11 = new System.Windows.Forms.Label();
this.lblVersion = new System.Windows.Forms.Label();
this.chkEditAcid = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// bcDestBox
//
this.bcDestBox.Enabled = false;
this.bcDestBox.Location = new System.Drawing.Point(208, 56);
this.bcDestBox.Name = "bcDestBox";
this.bcDestBox.Size = new System.Drawing.Size(408, 20);
this.bcDestBox.TabIndex = 0;
this.bcDestBox.Text = "";
//
// btnBrowseDest
//
this.btnBrowseDest.Location = new System.Drawing.Point(632, 48);
this.btnBrowseDest.Name = "btnBrowseDest";
this.btnBrowseDest.Size = new System.Drawing.Size(40, 24);
this.btnBrowseDest.TabIndex = 1;
this.btnBrowseDest.Text = "...";
this.btnBrowseDest.Click += new System.EventHandler(this.btnBrowseDest_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(64, 60);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(136, 16);
this.label1.TabIndex = 2;
this.label1.Text = "Select Destination Folder";
//
// label2
//
this.label2.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(16, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(104, 40);
this.label2.TabIndex = 3;
this.label2.Text = "Step 1";
//
// label3
//
this.label3.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.Location = new System.Drawing.Point(16, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(104, 40);
this.label3.TabIndex = 5;
this.label3.Text = "Step 2";
//
// label4
//
this.label4.Location = new System.Drawing.Point(64, 140);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(136, 16);
this.label4.TabIndex = 4;
this.label4.Text = "Select Destination Format";
//
// cmbFormat
//
this.cmbFormat.Location = new System.Drawing.Point(208, 136);
this.cmbFormat.Name = "cmbFormat";
this.cmbFormat.Size = new System.Drawing.Size(408, 21);
this.cmbFormat.TabIndex = 6;
this.cmbFormat.SelectedIndexChanged += new System.EventHandler(this.cmbFormat_SelectedIndexChanged);
//
// btnPreset
//
this.btnPreset.Location = new System.Drawing.Point(208, 176);
this.btnPreset.Name = "btnPreset";
this.btnPreset.Size = new System.Drawing.Size(104, 24);
this.btnPreset.TabIndex = 7;
this.btnPreset.Text = "Choose Preset";
this.btnPreset.Click += new System.EventHandler(this.btnPreset_Click);
//
// txtPreset
//
this.txtPreset.Enabled = false;
this.txtPreset.Location = new System.Drawing.Point(336, 176);
this.txtPreset.Name = "txtPreset";
this.txtPreset.Size = new System.Drawing.Size(232, 20);
this.txtPreset.TabIndex = 8;
this.txtPreset.Text = "(Default)";
//
// label5
//
this.label5.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label5.Location = new System.Drawing.Point(16, 248);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(104, 40);
this.label5.TabIndex = 10;
this.label5.Text = "Step 3";
//
// label6
//
this.label6.Location = new System.Drawing.Point(64, 296);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(136, 16);
this.label6.TabIndex = 9;
this.label6.Text = "Select Source Files";
//
// button1
//
this.button1.Location = new System.Drawing.Point(208, 296);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(152, 24);
this.button1.TabIndex = 11;
this.button1.Text = "Choose Files to Convert";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label7
//
this.label7.Font = new System.Drawing.Font("Times New Roman", 20.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label7.Location = new System.Drawing.Point(16, 336);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(104, 40);
this.label7.TabIndex = 13;
this.label7.Text = "Step 4";
//
// label8
//
this.label8.Location = new System.Drawing.Point(64, 392);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(136, 16);
this.label8.TabIndex = 12;
this.label8.Text = "Convert Files";
//
// btnConvert
//
this.btnConvert.Location = new System.Drawing.Point(208, 392);
this.btnConvert.Name = "btnConvert";
this.btnConvert.Size = new System.Drawing.Size(144, 24);
this.btnConvert.TabIndex = 14;
this.btnConvert.Text = "Convert Selected Files";
this.btnConvert.Click += new System.EventHandler(this.btnConvert_Click);
//
// txtSelFiles
//
this.txtSelFiles.Enabled = false;
this.txtSelFiles.Location = new System.Drawing.Point(384, 280);
this.txtSelFiles.Name = "txtSelFiles";
this.txtSelFiles.Size = new System.Drawing.Size(312, 104);
this.txtSelFiles.TabIndex = 15;
this.txtSelFiles.Text = "";
//
// txtStatus
//
this.txtStatus.Enabled = false;
this.txtStatus.Location = new System.Drawing.Point(16, 512);
this.txtStatus.Multiline = true;
this.txtStatus.Name = "txtStatus";
this.txtStatus.Size = new System.Drawing.Size(472, 56);
this.txtStatus.TabIndex = 16;
this.txtStatus.Text = "";
//
// label9
//
this.label9.Location = new System.Drawing.Point(16, 488);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(160, 16);
this.label9.TabIndex = 17;
this.label9.Text = "Render Status:";
//
// label10
//
this.label10.Location = new System.Drawing.Point(344, 432);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(208, 16);
this.label10.TabIndex = 18;
this.label10.Text = "Copyright 2005 - JETDV Scripts";
this.label10.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// linkLabel1
//
this.linkLabel1.Location = new System.Drawing.Point(344, 448);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(208, 16);
this.linkLabel1.TabIndex = 19;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "http://www.jetdv.com/vegas";
this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// label11
//
this.label11.Location = new System.Drawing.Point(344, 464);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(208, 16);
this.label11.TabIndex = 20;
this.label11.Text = "e-mail: editdv@jetdv.com";
this.label11.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// lblVersion
//
this.lblVersion.Location = new System.Drawing.Point(336, 488);
this.lblVersion.Name = "lblVersion";
this.lblVersion.Size = new System.Drawing.Size(216, 16);
this.lblVersion.TabIndex = 22;
this.lblVersion.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// chkEditAcid
//
this.chkEditAcid.Location = new System.Drawing.Point(208, 208);
this.chkEditAcid.Name = "chkEditAcid";
this.chkEditAcid.Size = new System.Drawing.Size(280, 16);
this.chkEditAcid.TabIndex = 23;
this.chkEditAcid.Text = "Show Edit Acid Properties";
//
// BatchConvertForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(728, 574);
this.Controls.Add(this.chkEditAcid);
this.Controls.Add(this.lblVersion);
this.Controls.Add(this.label11);
this.Controls.Add(this.linkLabel1);
this.Controls.Add(this.label10);
this.Controls.Add(this.label9);
this.Controls.Add(this.txtStatus);
this.Controls.Add(this.txtPreset);
this.Controls.Add(this.bcDestBox);
this.Controls.Add(this.txtSelFiles);
this.Controls.Add(this.btnConvert);
this.Controls.Add(this.label7);
this.Controls.Add(this.label8);
this.Controls.Add(this.button1);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this.btnPreset);
this.Controls.Add(this.cmbFormat);
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnBrowseDest);
this.Name = "BatchConvertForm";
this.Text = "Batch Convert";
this.ResumeLayout(false);

}
#endregion

private void btnBrowseDest_Click(object sender, System.EventArgs e)
{
bcDestBox.Text = GetSaveDir(bcDestBox.Text);

}

private void btnPreset_Click(object sender, System.EventArgs e)
{
ISfRenderer rend = (ISfRenderer)forge.Renderers[cmbFormat.SelectedIndex];
preset = rend.ChooseTemplate((IntPtr)null, 0);
if (preset == null)
{
txtPreset.Text = "{Default}";
}
else
{
txtPreset.Text = preset.Name;
}

}

private void button1_Click(object sender, System.EventArgs e)
{
filearray = GetFileList(bcDestBox.Text);
int cnt = 0;
foreach (string file in filearray)
{
if (cnt == 0)
{
txtSelFiles.Text = file;
cnt++;
}
else
{
txtSelFiles.Text = txtSelFiles.Text + "; " + file;
}
}

}

private void btnConvert_Click(object sender, System.EventArgs e)
{
ISfRenderer rend = (ISfRenderer)forge.Renderers[cmbFormat.SelectedIndex];
foreach (string file in filearray)
{
//Convert the old filename to the new file name
string newFile = Path.GetFileNameWithoutExtension(file);
newFile = bcDestBox.Text + 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);
}

//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.SaveAs(newFile + rend.Extension, rend, preset, opt);
forgefile.Close(CloseOptions.DiscardChanges);
txtStatus.Text = txtStatus.Text + " Done...";
}
}

private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.jetdv.com/vegas");
}

private void cmbFormat_SelectedIndexChanged(object sender, System.EventArgs e)
{
ISfRenderer rend = (ISfRenderer)forge.Renderers[cmbFormat.SelectedIndex];
preset = rend.GetTemplate(0);
}




}
}




------------------> End of Script

Go Back