Community Forums Archive

Go Back

Subject:Need to automate select and copy
Posted by: fescan
Date:11/20/2012 11:09:55 AM

I create 4 GB files that contain songs separated by nice space making it easy to find each song. I then select a song, copy it to another track, save that track, remove that track, then delete the selected song and go to the next one.

Here are my steps after each song has been selected:
[Ctrl+C Ctrl+e Ctrl+S Enter Ctrl+w Delete] then I select the next song and repeat.

What would someone charge me to create a script to do just the steps I do after I manually select a song? That is, the steps shown above within the brackets.

Thank you,
Fes Cannady

Subject:RE: Need to automate select and copy
Reply by: roblesinge
Date:11/20/2012 2:14:50 PM

Are you concerned about the filename of the newly created file, or where it is saved?

Rob.

Subject:RE: Need to automate select and copy
Reply by: fescan
Date:11/20/2012 3:54:13 PM

Thank you for your reply.
NOT concerned at all about where to save it. I always save to the same folder then deal with that later.
Default file name is OK since I rename all the files with another application anyway. So "Sound #.mp3" works fine. Well..... let me take that back. I WOULD like for the word "Sound" to be the letter "Z", like this Z-0001.mp3, Z-0002.mp3 and so on. But not a big deal.

I can program in VBA some but far from being very good at it.

If I just had a clue as to what the start and ending code should look like as well as what editor to use and the code that would create "CTRL+e" etc. I think I could do this and not be a bother to anyone.

Look forward to hearing your ideas.
Thanks again,
Fes

Subject:RE: Need to automate select and copy
Reply by: roblesinge
Date:11/20/2012 5:46:19 PM

This appears to do what you're looking for. The main problem I have with it is that it only saves to MP3, and the default template of that. Sound Forge opens everything as a wav file for editing, so any attempts to match the save format of the original file results in a wav file. You mentioned MP3, so I took a guess that you'd want to save as MP3. Just make sure your default template is a flavor of MP3 that you can live with.

In order to change the new filenames from the default, "Sound #.wav", you'll have to go into the Options-->Preferences-->Labels tab and change the New Window Prefix to whatever you'd prefer.

You'll also need to go into the script where I've marked and change the output folder to your preferred output directory. Note that destructive scripting like this is not what I would normally recommend, but you will have the chance to undo the delete step before moving on if necessary. Let me know if you have any questions or tweaks you'd like done.


//Use the code below this post!


Thanks,
Rob.

Message last edited on11/20/2012 5:55:52 PM byroblesinge.
Subject:RE: Need to automate select and copy
Reply by: roblesinge
Date:11/20/2012 5:55:19 PM

I am not a programmer by trade either. As such, I didn't do a complete test on my exception handling. I changed some things around, and now this script will not run if there is no selection made. Use this instead. Sorry.


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;

if (fileHold.Selection.ccLength != 0)
{
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

Subject:RE: Need to automate select and copy
Reply by: fescan
Date:11/21/2012 10:39:14 AM

Hello Roblesinge,
Thank you so much for your time and effort. I am sorry to say the script did crash when I ran it. I suggest you not put anymore time into it. You certainly gave me an idea of how complicated it is to write scripts for SF so I will give up on automating the process.

If you like, I did post a private listing that you may watch if you like. It is a screen capture of my current manual process. I did not include a capture of what happens when I run the script you wrote because I'm giving up on that idea on using a script at this time. Best regards and thanks again.

http://www.youtube.com/watch?v=My2oXj_0c2o

Subject:RE: Need to automate select and copy
Reply by: fescan
Date:11/22/2012 11:09:47 PM

I got it working now. I have also put a button in the tool bar to make it easy to use.
I just realized I had to redo the line telling the program where to save the new file.
After I did that ALL IS WELL.

Saves me a great deal of time. Thank you !!!

Fes Cannady

Go Back