Comments

SP. wrote on 4/11/2023, 2:45 AM

@Al3xanda The full API is described in the help file you can open via the Help menu.

rraud wrote on 4/11/2023, 9:58 AM

Do you need the <.cs> files? They 'should be' in the Sound Forge Pro 12 "Script menu" folder.

Al3xanda wrote on 4/11/2023, 6:51 PM

Thanks for the quick replies guys :)

I now have an issue with a script I have been working on.. Wondering if there are any sf script writers out there who might be able to look over it and get it working! Will pay no problem.

SP. wrote on 4/12/2023, 3:39 AM

@Al3xanda If you show us the script, I can take a look at it.

SP. wrote on 4/14/2023, 2:08 AM

Here is the result of our discussion. This may be useful for others to use, so I post it here as a backup.

The audio file opened in Sound Forge consists out of sounds which are 8 seconds long. After each sound is a silent pause of 8 seconds.

The script will apply a pitch shift effect to each sound, then remove the silence and export the sounds to individual files.

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

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

   string[] preset = new string[4]; //names of all Pitch Shift presets
   preset[0] = "[Sys] Fifth down";
   preset[1] = "[Sys] Fifth up";
   preset[2] = "[Sys] Third down";
   preset[3] = "[Sys] Third up";

   long regionLength = app.CurrentFile.SecondsToPosition(8.0); //region length in seconds
   long pauseLength = app.CurrentFile.SecondsToPosition(8.0); //pause length in seconds
   long positionFrom = app.CurrentFile.Length - regionLength - pauseLength; //begin at the end of the file because pitch shifting changes its length

   int i = preset.Length-1; //begin with the last preset

   while(true){

      app.CurrentFile.DoEffect("Pitch Shift", preset[i], new SfAudioSelection(positionFrom, regionLength), EffectOptions.EffectOnly | EffectOptions.WaitForDoneOrCancel);

      if(positionFrom <= 0){ //exit loop after the file was processed from end to the beginning
        break;
      }
      
      positionFrom = positionFrom - regionLength - pauseLength; //calculate the positions for the next loop
      
      if(positionFrom < 0){ //the starting position cannot be negative
         positionFrom = 0;
      }

      i = ((i-1)%(preset.Length)+(preset.Length))%(preset.Length); //make sure i stays always inside the array boundries for the next loop
   }
   
   //remove all silence with the Auto Trim/Crop function and export the resulting regions
   app.CurrentFile.DoEffect("Process.AutoTrimCrop", "[Sys] Phrase concatenator 1", new SfAudioSelection(0, -1), EffectOptions.EffectOnly | EffectOptions.WaitForDoneOrCancel);
   app.DoMenuAndWait("Tools.ExtractRegions", false);

}

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