Community Forums Archive

Go Back

Subject:Restoring clipboard
Posted by: sjm
Date:8/23/2006 12:47:37 PM

I have a script which needs to know the location of sample loop markers. Because this information isn't available from the scripting SDK, my script gets that information by selecting the entire file, copying it to the clipboard (with app.DoMenu("Edit.Copy")), getting the clipboard data in WaveAudio format, and parsing the data.

First off, is there a better way to do this using the SDK??

If not... this approach works fine (apart from being rather convoluted), but because it copies to the clipboard, the user will lose whatever they had in the clipboard previously.

I tried this:
IDataObject oldClipboard = Clipboard.GetDataObject();
// .. do some stuff
Clipboard.SetDataObject(oldClipboard);

but it causes an exception (the error code corresponds to "CloseClipboard failed").

I then tried this:
IDataObject oldClipboard = Clipboard.GetDataObject();
DataObject newClipboard = new DataObject();
foreach (string fmt in oldClipboard.GetFormats())
newClipboard.SetData(fmt, oldClipboard.GetData(fmt));
// ... do some stuff
Clipboard.SetDataObject(newClipboard);

This completes without errors, but has some strange effects... sizing or zooming the window causes all my samples to get set to 0, playback no longer works on this or any other file, etc.

Is there a better way to restore the clipboard?

Message last edited on8/23/2006 12:50:51 PM bysjm.
Subject:RE: Restoring clipboard
Reply by: _TJ
Date:8/24/2006 3:18:43 PM

Since you don't have any idea what is in the clipboard, it's somewhat difficult to save and restore it.

Besides, the clipboard is owned by the user, and it's bad form for a script to mess with except when the script is bound to the standard keyboard shortcuts for manipulating the clipboard (Ctrl+C, Ctrl+X).

It's good that you are trying to put it back, but it's not necessary for you to mess with it in the first place. You could instead, render the file to a known filename, then open the file and parse it to get the loop information.

There are lots of ways to do this, but this (off the top of my head) should work.


ISfFileHost file1; // this is the file you want to get loop information for
ISfFileHost fileTemp = file1.NewFile(new SfAudioSelection(file1)); // copy it
fileTemp.SaveAs("Knownfilename.wav", ".wav", "Default Template", RenderOptions.RenderOnly);
fileTemp.WaitForDoneOrCancel();
fileTemp.Close(CloseOptions.DiscardChanges);

// now open up "knownfilename.wav", and parse it to get the loop information,
// just like you are currently doing with the clipboard data.


tj



Message last edited on8/24/2006 3:20:01 PM by_TJ.
Subject:RE: Restoring clipboard
Reply by: sjm
Date:8/28/2006 11:12:39 AM

That seems like a better way, thanks!

Go Back