The following script (special thanks to Rob - roblesinge - for the initial code) provides an input box for the user and then parses the word typed and pastes in a file for each letter. What I can't work out is why it is pasting the files in reverse order to what is typed. Can anyone see the problem? Thanks.
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using SoundForge;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class EntryPoint
{
public void Begin(IScriptableApp app)
{
string sInput;
DialogResult res = GetInput(app, "Split This:", out sInput);
if (DialogResult.OK != res)
return;
if (sInput == "")
return;
ISfFileHost openFile = app.CurrentFile;
ISfDataWnd wnd = app.ActiveWindow;
long currentPos = wnd.Cursor;
// Calculate the length of the array
int i = 0;
char[] charArr = sInput.ToCharArray();
foreach (char ch in charArr)
{
i++;
}
// Create the array
string[] fileHolder = new String;
// populate the array
int n = 0;
foreach (char ch in charArr)
{
string path = "L:\\ZZ Phonemes\\" + ch + ".wav";
fileHolder[n] = path;
n++;
}
//Sets the amount of silence between files.
double gap = .5;
//Here is the part where we start the Merge!
int fileCount = fileHolder.Length;
for (int x = 0; x < fileCount; x++)
{
ISfFileHost temp = app.OpenFile(fileHolder[x], false, false);
SfStatus status = temp.WaitForDoneOrCancel();
openFile.ReplaceAudio(new SfAudioSelection(currentPos, 0), temp, new SfAudioSelection(temp));
temp.Close(CloseOptions.DiscardChanges);
if (gap != 0)
{
//Inserts requested silence
long addgap = openFile.SecondsToPosition(gap);
openFile.InsertSilence(currentPos, addgap);
}
}
wnd.SetCursorAndScroll(currentPos, DataWndScrollTo.NoMove);
}
public DialogResult GetInput(IScriptableApp app, string sPrompt, out string sInput)
{
IWin32Window hOwner = app.Win32Window;
Form dlg = new Form();
Size sForm = new Size(200, 100);
dlg.Text = Script.Name + " Word";
dlg.FormBorderStyle = FormBorderStyle.FixedDialog;
dlg.MaximizeBox = false;
dlg.MinimizeBox = false;
dlg.StartPosition = FormStartPosition.CenterScreen;
dlg.ClientSize = sForm;
Point pt = new Point(10,10);
Size sOff = new Size(10,10);
if (sPrompt == null || sPrompt == "")
sPrompt = "Type Word To Split";
Label lbl = new Label();
lbl.Text = sPrompt;
lbl.Width = sForm.Width - pt.X - sOff.Width;
lbl.Height = 14;
lbl.Location = pt;
dlg.Controls.Add(lbl);
pt.Y += lbl.Height;
TextBox edt = new TextBox();
edt.Size = sForm - new Size(20, 70);
edt.Location = pt;
dlg.Controls.Add(edt);
// we position the buttons relative to the bottom and left of the form.
pt = (Point)dlg.ClientSize;
pt -= sOff;
Button btn = new Button();
pt -= btn.Size;
btn.Text = "Cancel";
btn.Location = pt;
btn.Click += new EventHandler(OnCancel_Click);
dlg.Controls.Add(btn);
dlg.CancelButton = btn;
pt.X -= (btn.Width + 10);
btn = new Button();
btn.Text = "OK";
btn.Location = pt;
btn.Click += new EventHandler(OnOK_Click);
dlg.Controls.Add(btn);
dlg.AcceptButton = btn;
pt.X -= (btn.Width + 10);
DialogResult res = dlg.ShowDialog(app.Win32Window);
sInput = dlg.Tag as string;
return res;
}
// generic OK button click (sets dialog result and dismisses the form)
private static void OnOK_Click(object sender, System.EventArgs e)
{
Button btn = (Button)sender;
Form form = (Form)btn.Parent;
TextBox edt = (TextBox)form.Controls[1];
form.DialogResult = DialogResult.OK;
form.Tag = edt.Text;
form.Close();
}
// generic Cancel button click (sets dialog result and dismisses the form)
private static void OnCancel_Click(object sender, System.EventArgs e)
{
Button btn = (Button)sender;
Form form = (Form)btn.Parent;
form.DialogResult = DialogResult.Cancel;
form.Tag = null;
form.Close();
}
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, params object[] args) { ForgeApp.OutputText(String.Format(fmt, args)); }
} //EntryPoint