Community Forums Archive

Go Back

Subject:Create Selection
Posted by: Kit
Date:2/23/2010 7:08:04 PM

Hello,

I'd like to know how to create a selection 1 second long from the current position of the cursor. Once the selection has been made I'd like to create a region using the selection. I think this should be easy but I have a hard time getting my head around scripting and Sound Forge. Can anyone help?

Thanks,

Kit

Subject:RE: Create Selection
Reply by: ExSonyTJ
Date:3/13/2010 1:25:18 AM

You get the cursor position of the active window from app.ActiveWindow.Cursor,

You add a marker by calling the Add method of the Markers collection, like this


using System;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;

using SoundForge;
using SoundForge.BatchConverter;

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

long cc = app.ActiveWindow.Cursor;
ISfFileHost fh = app.ActiveWindow.File;

// create a 1 second selection at the current cursor position
SfAudioSelection asel = new SfAudioSelection(cc, fh.SecondsToPosition(1));

// create a marker from that selection
SfAudioMarker mk = new SfAudioMarker(asel);
mk.Name = "name";

// add that marker to the markers of the file.
fh.Markers.Add(mk);

return null; // null for success
}

public void FromSoundForge(IScriptableApp app) {
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
string msg = Begin(app);
app.SetStatusText(msg != null ? msg : 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

Subject:RE: Create Selection
Reply by: Kit
Date:3/15/2010 10:44:15 PM

Thanks very much for the reply. I see the script creating a marker but don't actually see the area selected being highlighted. I don't really want to make a region. I want to cut and past the selection to a new file. I tried amending the script but it rejected my app.do statements. I'd be grateful for some more help.

Best wishes,

Kit

Subject:RE: Create Selection
Reply by: Kit
Date:4/17/2010 3:36:01 PM

Figured it out. Just remembered to post back

Kit


using System;
using System.Windows.Forms;
using SoundForge;

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

/*begin here*/
Int64 ccSelection = app.ActiveWindow.File.SecondsToPosition(2);

// select 1 second AFTER the cursor
app.ActiveWindow.SelectionLength = ccSelection;

app.DoMenuAndWait("Edit.Copy",true);
app.DoMenuAndWait("File.New",true);
app.DoMenuAndWait("Edit.Paste",true);
Do("File.SaveAs");

}

public static void Do(string cmd) { ForgeApp.DoMenuAndWait(cmd,false); }
public static void Do(string cmd, bool fUseLastPreset) { ForgeApp.DoMenuAndWait(cmd,fUseLastPreset); }

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, object o) { ForgeApp.OutputText(String.Format(fmt,o)); }
public static void DPF(string fmt, object o, object o2) { ForgeApp.OutputText(String.Format(fmt,o,o2)); }
} //EntryPoint


Go Back