Community Forums Archive

Go Back

Subject:Switch cursor to opposite end of selection
Posted by: CharlesK
Date:12/11/2014 10:50:46 PM

How can I switch the cursor from the left end of a selection to the right edge of a selection within a script? I need to insure the cursor is at the left edge of the selection. Assume I have an open file with an active selection. (Using the keyboard, I'd press NumPad 5.) Thank you.

Subject:RE: Switch cursor to opposite end of selection
Reply by: roblesinge
Date:12/12/2014 11:31:05 AM

There's a method to set the cursor position. I'll try and look it up when I get home.

Try checking the SDK documentation.

-Rob.

Subject:RE: Switch cursor to opposite end of selection
Reply by: CharlesK
Date:12/12/2014 2:29:22 PM

I've looked at this three different ways:

1) Sending a keystroke to the data window. If I could figure out the ForwardKey method for ISfDataWnd, I'd send the comma keystroke to the data window. That would probably be the simplest way. Unfortunately, I have not figured this out.

2) Using DoMenu(). Looking at the DoMenuCommands.xls, I see this information like this:

IDS_DEFKEYBIND_CURSORTODATAHOME with “CursorTo.DataHome” as the text argument to pass to DoMenu().

Then, I find this:

IDS_DEFKEYBIND_CURSORTOGGLEBETWEEENSELECTIONEDGES

Hot dog! That's what I want. The problem is there is no text string associated with this, so I can't pass it to DoMenu(). The reason is ToggleSelectionEdge is not in the menu structure of Forge.

3) Digging into the SDK help file, I cannot find any reference to toggling which edge of a selection the cursor is located. The SDK says that SelectionLength is negative if the cursor is at the left edge of a selection and is positive if the cursor is at the right edge of a selection. This does not appear to be true.


//Report selection length and cursor position.
using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;
public class EntryPoint
{
public void Begin(IScriptableApp app)
{
ISfDataWnd wnd = app.ActiveWindow;
DPF("Selection length {0}", wnd.SelectionLength);
DPF("Cursor position {0}", wnd.Cursor);
}
public void FromSoundForge(IScriptableApp app)
{
ForgeApp = app;
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)); }
public static void DPF(string fmt, object o, object o2, object o3) { ForgeApp.OutputText(String.Format(fmt, o, o2, o3)); }
}


I can create a region from right to left or left to right and the selection length is always positive.

I'm stumped, as usual.

Message last edited on1/13/2015 11:57:30 PM byCharlesK.
Subject:RE: Switch cursor to opposite end of selection
Reply by: CharlesK
Date:12/13/2014 1:16:58 PM

I finally got it.

//Make sure cursor is at the start of a selection.
using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;
public class EntryPoint
{
public void Begin(IScriptableApp app)
{
ISfDataWnd wnd = app.ActiveWindow;
SfAudioSelection asel = wnd.Selection;
Int64 ccLen = wnd.SelectionLength; // Length of selection
Int64 ccSta = asel.ccStart; // Start of selection
Int64 ccPos = wnd.Cursor; // Cursor position
// If no selection or cursor at start of selection, then nothing happens.
if ( ccPos > ccSta )
{
wnd.SetCursorAndScroll(ccSta, DataWndScrollTo.NoMove);
wnd.SetSelectionAndScroll(ccSta, ccLen, DataWndScrollTo.NoMove);
}
}
public void FromSoundForge(IScriptableApp app)
{
ForgeApp = app;
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;
}

Message last edited on12/13/2014 6:47:58 PM byCharlesK.

Go Back