Community Forums Archive

Go Back

Subject:Import with SF10
Posted by: Kit
Date:3/18/2014 10:57:50 PM

Hello, is there a way to import one file (eg D:\loops\loop1.wav) into the file in the current data window at the current cursor position? Thanks.

Subject:RE: Import with SF10
Reply by: roblesinge
Date:3/19/2014 8:15:07 AM

You mean like paste a file into another file at the current cursor position?

R.

Subject:RE: Import with SF10
Reply by: Kit
Date:3/19/2014 2:50:58 PM

Thanks for replying, yes, that's exactly what I mean.

Subject:RE: Import with SF10
Reply by: roblesinge
Date:3/19/2014 5:10:00 PM

Yes, that's completely possible. However, you need to explain a little more of what you want the script to do. I mean, the easiest way to accomplish that would be to open the paste file, copy it and paste it in where you want it to go. The advantage to scripting is being able to loop that process over many target files, or being able to quickly paste the same file into any file you happen to have open.

So, to clarify, you want to always paste the same file, or you want to be able to select the file to paste?

Thanks,
R.

Subject:RE: Import with SF10
Reply by: Kit
Date:3/19/2014 5:39:01 PM

Hi, to answer your question, I'll be pasting different files that I will select programmatically. I've been looking through the forum and I found examples of merging two or more files together but they always create a new file rather than work with the existing open file.

What I need is an example of pasting a single file (eg D:\loops\loop1.wav) into the existing open file. I can work out how to choose files later. I'll probably end up with different scripts for different purposes. What I'm having trouble with is working out how to use the current file rather working with a newly created file. I've used other languages but find C# a little tricky to get my head round. Thanks for your interest.

Subject:RE: Import with SF10
Reply by: roblesinge
Date:3/19/2014 8:01:38 PM

To operate on the current open file, one way would be to assign that file to an ISfFileHost object.


ISfFileHost openFile = app.CurrentFile


Then you can operate on the openFile object. Did that point you in the right direction?

R.

Subject:RE: Import with SF10
Reply by: Kit
Date:3/19/2014 8:57:16 PM

Thanks. I don't know how to operate on the openFile object. I keep seeing this kind of error:

"'SoundForge.IScriptableApp.CurrentFile' is a 'property' but is used like a 'method'

Subject:RE: Import with SF10
Reply by: Kit
Date:3/19/2014 9:41:22 PM

I'm making progress. This seems to insert audio once but if the cursor position remains unchanged it won't insert audio a second time. If the cursor position is moved a little backwards then it seems to adjust the position of the first paste rather than paste a fresh. What's wrong?



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

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


string strPaste = @"L:\Numbers\Number 1.wav";

ISfFileHost fileToPasteFrom = app.OpenFile(strPaste, false, false);

if (fileToPasteFrom == null)

return; // just quit if we can't open the paste file.


ISfDataWnd wnd = app.ActiveWindow;
long currentPos = wnd.Cursor;

//ISfFileHost file = app.OpenFile(strFilename, false, false);

ISfFileHost openFile = app.CurrentFile;


openFile.OverwriteAudio(currentPos, 0, fileToPasteFrom, new SfAudioSelection(fileToPasteFrom));

}


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

Subject:RE: Import with SF10
Reply by: Kit
Date:3/19/2014 9:53:02 PM

Got it! This seems to work:

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

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

ISfDataWnd wnd = app.ActiveWindow;
long currentPos = wnd.Cursor;



string strPaste = @"L:\Numbers\Number 1.wav";

ISfFileHost fileToPasteFrom = app.OpenFile(strPaste, false, false);

if (fileToPasteFrom == null)

return; // just quit if we can't open the paste file.

//ISfFileHost file = app.OpenFile(strFilename, false, false);

ISfFileHost openFile = app.CurrentFile;


openFile.ReplaceAudio(new SfAudioSelection(currentPos, 0), fileToPasteFrom, new SfAudioSelection(fileToPasteFrom));

}


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

Subject:RE: Import with SF10
Reply by: Kit
Date:3/19/2014 10:21:49 PM

Nope, I was mistaken. It's not pasting into the open file but into itself.

Subject:RE: Import with SF10
Reply by: roblesinge
Date:3/20/2014 9:59:56 AM

You've got a couple of problems. First, you need to move your openFile assignment above where you open the pasteFrom file.The CurrentFile is the file you have open last, so if you open the PasteFrom last, it will be the CurrentFile.

Also, try using OverwriteAudio() instead of ReplaceAudio(). OverwriteAudio acts like a paste to a cursor position, while ReplaceAudio acts like a paste into a selection. It would look like this:


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

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

ISfDataWnd wnd = app.ActiveWindow;
long currentPos = wnd.Cursor;

string strPaste = @"L:\Numbers\Number 1.wav";

ISfFileHost openFile = app.CurrentFile;

ISfFileHost fileToPasteFrom = app.OpenFile(strPaste, false, false);

if (fileToPasteFrom == null)
return; // just quit if we can't open the paste file.

openFile.ReplaceAudio(new SfAudioSelection(currentPos, 0), fileToPasteFrom, new SfAudioSelection(fileToPasteFrom));

}

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



Message last edited on3/20/2014 10:07:36 AM byroblesinge.

Go Back