Community Forums Archive

Go Back

Subject:how to code Ctrl+Shift+Home
Posted by: fescan
Date:11/22/2012 11:46:22 PM

A very nice person wrote a script for me to automate a process and it works really well.
However, I notice that I ALWAYS press Ctrl+Shift+Home ( select from current location to beginning of file) just before I run the script and I did not tell him that was part of the process.

Will someone please write the code to "Select from Current Position to Beginning of File" for me. I can then copy and paste it to the script.

THANK YOU in advance.
Fes Cannady, Denver, Colorado

Subject:RE: how to code Ctrl+Shift+Home
Reply by: roblesinge
Date:11/26/2012 1:51:59 PM

Fes,

Here is the full script with the changes you wanted. It will make a selection using the beginning of the file and your current cursor position as the start and stop points.


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

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

//Get objects to hold the audio data and selection.
ISfDataWnd fileHold = app.ActiveWindow;

//Create our selection from the beginning of the file to the current cursor position.
SfAudioSelection asel = new SfAudioSelection(0, fileHold.Cursor);

if (asel.Length != 0)
{

//The line below is to be used if there is already a selection.
//SfAudioSelection asel = fileHold.Selection;

//Change the part between the quotes to your preferred output folder."
string saveTo = @"C:\Temp\";

//pull render information from the open file.
ISfRenderer rend2 = app.FindRenderer("MP3 Audio", "*.mp3");
ISfGenericPreset preset = rend2.GetTemplate("Default Template");


//populate a new audio object with the selection.
ISfFileHost pasteTo = app.CurrentFile.NewFile(asel);

//create our output filename.
string outFile = saveTo + app.ActiveWindow.Title.ToString() + ".mp3";

DPF(outFile); //testing purposes.

//save our file to the new filename with the renderer we chose earlier.
pasteTo.SaveAs(outFile, rend2.Guid, preset, RenderOptions.WaitForDoneOrCancel);

//close the new file after saving.
pasteTo.Close(CloseOptions.SaveChanges);

//Delete the audio selection from our original window.
app.CurrentFile.DeleteAudio(asel);

//housekeeping.
fileHold = null;
asel = null;
}

else
{
MessageBox.Show("There is no audio selected.");
return;
}

}

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

Go Back