示例#1
1
 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));
 }
示例#2
1
 public void Begin(IScriptableApp app)
 {
     Form1 theForm = new Form1();
     theForm.InitializeComponent();
     theForm.Appl = app;
     theForm.ShowDialog();
 }
示例#3
1
    public void Begin(IScriptableApp app)
    {
        Form1 theForm = new Form1();
        theForm.InitializeComponent();
        theForm.addSfApp(app);
        theForm.ShowDialog();

        //Perform script operations here.
    }
示例#4
1
    public double FindSegsLength(List<string> filePaths, IScriptableApp zApp)
    {
        double total = 0.000;
        foreach (string s in filePaths)
        {
            ISfFileHost file = zApp.OpenFile(s, true, true);
            total += file.PositionToSeconds(file.Length);
            file.Close(CloseOptions.DiscardChanges);
        }

        return total;
    }
    public string Begin(IScriptableApp app)
    {
        //start MODIFY HERE-----------------------------------------------
           string szType  = GETARG("type", ".mp3"); //choose any valid extension: .avi  .wav  .w64 .mpg .mp3 .wma .mov .rm .aif .ogg .raw .au .dig .ivc .vox .pca
           object vPreset = GETARG("preset", ""); //put the name of the template between the quotes, or leave blank to pop the Template chooser.
           string szDir   = GETARG("dir", ""); //hardcode a target path here

           // GETARG is a function that defines the default script settings. You can use the Script Args field to over-ride
           // the values within GETARG().
           // Example: To over-ride GETARG(Key, valueA), type Key=valueB in the Script Args field.
           //          Use an ampersand (&) to separate different Script Args: KeyOne=valueB&KeyTwo=valueC

           //Example Script Args: type=.wav&dir=f:\RegionFiles

           //end MODIFY HERE -----------------------------------

           ISfFileHost file = app.CurrentFile;
           if (null == file)
          return "Open a file containing regions before running this script. Script stopped.";
           if (null == file.Markers || file.Markers.Count <= 0)
          return "The file does not have any markers.";

           bool showMsg = true;
           if (szDir == null || szDir.Length <= 0)
           {
          szDir = SfHelpers.ChooseDirectory("Select the target folder for saved files:", @"C:\");
          showMsg = false;
           }
           if (szDir == null || szDir.Length <= 0)
          return "no output directory";

           //make sure the directory exists
           if(!Path.IsPathRooted(szDir))
           {
          string szBase2 = Path.GetDirectoryName(file.Filename);
          szDir = Path.Combine(szBase2, szDir);
           }

           Directory.CreateDirectory(szDir);

           ISfRenderer rend = null;
           if (szType.StartsWith("."))
           rend = app.FindRenderer(null, szType);
           else
           rend = app.FindRenderer(szType, null);

           if (null == rend)
          return String.Format("renderer for {0} not found.", szType);

           // if the preset parses as a valid integer, then use it as such, otherwise assume it's a string.
           try {
           int iPreset = int.Parse((string)vPreset);
           vPreset = iPreset;
           } catch (FormatException) {}

           ISfGenericPreset template = null;
           if ((string)vPreset != "")
          template = rend.GetTemplate(vPreset);
           else
          template = rend.ChooseTemplate((IntPtr)null, vPreset);
           if (null == template)
          return "Template not found. Script stopped.";

           string szBase = file.Window.Title;
           //check to see if the window title contains a file extension. If so, remove it for save name. Remove this if you want that extension.
           if (szBase.Contains("."))
           {
           int indexOf = szBase.LastIndexOf('.');
           szBase = szBase.Remove(indexOf, (szBase.Length - indexOf));
           }

           // JH adding this counter in order to keep track of count for naming files which is not always consecutive when having markers and regions in file
           int counter = 1;

           // calculate the number of regions
           // wish I could do this without two loops
           int numberOfRegions = 0;
           foreach (SfAudioMarker mk in file.Markers)
           {
          if (mk.Length <= 0)
         continue;
          numberOfRegions++;
           }

           // loop through all markers and generate files from regions
           foreach (SfAudioMarker mk in file.Markers)
           {
          if (mk.Length <= 0)
         continue;

          // set filename to TwoDigitTrackNumber-originalFileTitle-RegionName.mp3
          string szName = String.Format("{0}-{1}-{2}.{3}", counter.ToString("00"), szBase, mk.Name, rend.Extension);

          szName = SfHelpers.CleanForFilename(szName);
          DPF("Queueing: '{0}'", szName);

          string szFullName = Path.Combine(szDir, szName);
          if (File.Exists(szFullName))
          File.Delete(szFullName);

          SfAudioSelection  range = new SfAudioSelection(mk.Start, mk.Length);

          // set the name and track metadata for the output mp3
          // all other mp3 metadata will come from the template; which the user selected
          file.Summary.Title = mk.Name;
          file.Summary.TrackNo = String.Format("{0}/{1}",counter.ToString(), numberOfRegions.ToString());

          file.RenderAs(szFullName, rend.Guid, template, range, RenderOptions.RenderOnly);
          DPF("Path: '{0}'", szFullName);

          // increment the track number counter
          counter++;
           }

           // remove the summary info we set on the file
           file.Summary.Title = "";
           file.Summary.TrackNo = "";

           if(showMsg)
          MessageBox.Show(String.Format("Files are saving to: {0}", szDir), "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);

           return null;
    }
示例#6
1
    public ISfFileHost ResampleAndMono(ISfFileHost inFile, IScriptableApp appl, uint rate)
    {
        inFile.DoResample(rate, 4, EffectOptions.WaitForDoneOrCancel | EffectOptions.EffectOnly);
        if (inFile.Channels > 1)
        {
            double[,] aGainMap = new double[1, 2] { { 0.5, 0.5 } };
            inFile.DoConvertChannels(1, 0, aGainMap, EffectOptions.WaitForDoneOrCancel | EffectOptions.EffectOnly);
        }

        return inFile;
    }
示例#7
1
    public ISfGenericPreset GetNormPreset(IScriptableApp appl, int level, bool rms)
    {
        //takes in a integer level and a bool for rms and creates a norm preset
        //----Example call: ISfGenericPreset normNeg4 = GetNormPreset(app, -4, false);-----

        ISfGenericEffect fx = appl.FindEffect("Normalize");
        ISfGenericPreset preset0 = fx.GetPreset(0);
        byte[] abData = preset0.Bytes;
        string levelString = level.ToString();

        ISfGenericPreset normPreset = new SoundForge.SfGenericPreset(levelString, fx, abData);
        Fields_Normalize field1 = Fields_Normalize.FromPreset(normPreset);

        //If 0dB or a positive dB was requested, set the NormTo field as 0.
        if (level >= 0)
        {
            field1.NormalizeTo = 0;
        }
        else
            field1.NormalizeTo = SfHelpers.dBToRatio(level);

        field1.RMS = rms;
        if (rms)
        {
            field1.IfClip = Fields_Normalize.ClipAction.Compress;
        }

        field1.ToPreset(normPreset);

        return normPreset;
    }
    public string Begin(IScriptableApp app)
    {
        //start MODIFY HERE-----------------------------------------------
           string szType  = GETARG("type", ".flac"); //choose any valid extension: .avi  .wav  .w64 .mpg .mp3 .wma .mov .rm .aif .ogg .raw .au .dig .ivc .vox .pca
           object vPreset = GETARG("preset", "44,100 Hz, 16 Bit, Stereo Highest Compression"); //put the name of the template between the quotes, or leave blank to pop the Template chooser.
           string szDir   = GETARG("dir", ""); //hardcode a target path here

           // GETARG is a function that defines the default script settings. You can use the Script Args field to over-ride
           // the values within GETARG().
           // Example: To over-ride GETARG(Key, valueA), type Key=valueB in the Script Args field.
           //          Use an ampersand (&) to separate different Script Args: KeyOne=valueB&KeyTwo=valueC

           //Example Script Args: type=.wav&dir=f:\RegionFiles

           //end MODIFY HERE -----------------------------------

           ISfFileHost file = app.CurrentFile;
           if (null == file)
          return "Open a file containing regions before running this script. Script stopped.";
           if (null == file.Markers || file.Markers.Count <= 0)
          return "The file does not have any markers.";

           bool showMsg = true;
           if (szDir == null || szDir.Length <= 0)
           {
          szDir = SfHelpers.ChooseDirectory("Select the target folder for saved files:", @"C:\");
          showMsg = false;
           }
           if (szDir == null || szDir.Length <= 0)
          return "no output directory";

           //make sure the directory exists
           if(!Path.IsPathRooted(szDir))
           {
          string szBase2 = Path.GetDirectoryName(file.Filename);
          szDir = Path.Combine(szBase2, szDir);
           }

           Directory.CreateDirectory(szDir);

           ISfRenderer rend = null;
           if (szType.StartsWith("."))
           rend = app.FindRenderer(null, szType);
           else
           rend = app.FindRenderer(szType, null);
           if (null == rend)
          return String.Format("renderer for {0} not found.", szType);

           // if the preset parses as a valid integer, then use it as such, otherwise assume it's a string.
           try {
           int iPreset = int.Parse((string)vPreset);
           vPreset = iPreset;
           } catch (FormatException) {}

           ISfGenericPreset template = null;
           if ((string)vPreset != "")
          template = rend.GetTemplate(vPreset);
           else
          template = rend.ChooseTemplate((IntPtr)null, vPreset);
           if (null == template)
          return "Template not found. Script stopped.";

           string szBase = file.Window.Title;
           int count = 1;

           foreach (SfAudioMarker mk in file.Markers)
           {
          if (mk.Length <= 0)
         continue;

          string szName = String.Format("{0}d1t{1}.{2}", szBase, count.ToString("00"), rend.Extension);
          szName = SfHelpers.CleanForFilename(szName);
          DPF("Queueing: '{0}'", szName);

          string szFullName = Path.Combine(szDir, szName);
          if (File.Exists(szFullName))
          File.Delete(szFullName);

          SfAudioSelection  range = new SfAudioSelection(mk.Start, mk.Length);
          file.RenderAs(szFullName, rend.Guid, template, range, RenderOptions.RenderOnly);
          DPF("Path: '{0}'", szFullName);

          count++;

           }

           if(showMsg)
          MessageBox.Show(String.Format("Files are saving to: {0}", szDir), "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);

           return null;
    }
示例#9
0
 public void CopySelectionToStart(IScriptableApp app, SfAudioSelection selection)
 {
     _file.Window.SetSelectionAndScroll(selection.Start, selection.Length, DataWndScrollTo.NoMove);
     app.DoMenuAndWait("Edit.Copy", false);
     _file.Window.SetCursorAndScroll(0, DataWndScrollTo.NoMove);
     app.DoMenuAndWait("Edit.Paste", false);
 }
示例#10
0
        public bool IsCurrentSelectionGreaterThan(IScriptableApp app, double minimumLengthInSeconds)
        {
            ISfDataWnd window = _file.Window;
            double     selectionLengthSeconds = _file.PositionToSeconds(window.Selection.Length);

            return(selectionLengthSeconds >= minimumLengthInSeconds);
        }
示例#11
0
        public void ApplyEffectPreset(IScriptableApp app, SfAudioSelection selection, string effectName, string presetName, EffectOptions effectOption, OutputHelper.MessageLogger logger)
        {
            if (effectOption == EffectOptions.ReturnPreset || effectOption == EffectOptions.WaitForDoneOrCancel)
            {
                throw new ScriptAbortedException("Invalid EffectOptions option: " + effectOption);
            }

            ISfGenericEffect effect = app.FindEffect(effectName);

            if (effect == null)
            {
                throw new ScriptAbortedException(String.Format("Effect '{0}' was not found.", effectName));
            }

            ISfGenericPreset preset = effect.GetPreset(presetName);

            if (preset == null)
            {
                throw new ScriptAbortedException(String.Format("Preset '{0}' was not found for effect '{1}'.", presetName, effectName));
            }

            if (logger != null)
            {
                logger("Applying Effect '{0}', Preset '{1}'...", effect.Name, preset.Name);
            }

            _file.DoEffect(effectName, presetName, selection, effectOption | EffectOptions.WaitForDoneOrCancel | EffectOptions.ReturnPreset);
        }
示例#12
0
 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));
 }
示例#13
0
 public EditTracksController(IScriptableApp app, EditTracksFormFactory formFactory, EntryPointBase entryPoint, OutputHelper output, FileTasks fileTasks)
 {
     _app         = app;
     _formFactory = formFactory;
     _entryPoint  = entryPoint;
     _output      = output;
     _fileTasks   = fileTasks;
 }
示例#14
0
 public GraphicFadeBatchForm(IScriptableApp forge)
 {
     InitializeComponent();
     initializeExtensions();
     forgeApp = forge;
     updatePresets();
     errorStyle           = new DataGridViewCellStyle(fileList.DefaultCellStyle);
     errorStyle.BackColor = System.Drawing.Color.Red;
 }
示例#15
0
        private TrackList FindTracks(IScriptableApp app, ISfFileHost file)
        {
            _vinylRipOptions.Validate();

            ScriptTimer.Reset();
            List <ScanResult> results = DoFirstPassStatisticsScan();

            TrackList tracks               = new TrackList(_vinylRipOptions, file);
            int       trackCount           = 1;
            bool      currentResultIsTrack = false;

            foreach (ScanResult scanResult in results)
            {
                if (scanResult.RmsLevelExceeds(_vinylRipOptions.GapNoisefloorThresholdInDecibels))
                {
                    //Output.ToScriptWindow("{0} above threshold", scanResult.WindowNumber);
                    if (!currentResultIsTrack && tracks.CanAddNextTrack(scanResult.SelectionStart))
                    {
                        tracks.AddNew();
                        tracks.LastAdded.StartPosition = scanResult.SelectionStart;
                        tracks.LastAdded.Number        = trackCount++;
                        currentResultIsTrack           = true;
                    }
                    tracks.LastAdded.EndPosition = scanResult.SelectionEnd;
                }
                else if (tracks.CanSetTrackBreak())
                {
                    currentResultIsTrack = false;
                }
                Output.ToScriptWindow("{0}\t{1}\t{2}\t{3}",
                                      scanResult.WindowNumber,
                                      OutputHelper.FormatToTimeSpan(file.PositionToSeconds(scanResult.SelectionStart)),
                                      OutputHelper.FormatToTimeSpan(file.PositionToSeconds(scanResult.SelectionEnd)),
                                      scanResult.GetMaxRmsLevel());
            }

            Output.ToScriptWindow("FindTracks Finished scanning:\r\n- Scanned: {0} windows\r\n- Window Length: {1}s\r\n- Scan Duration: {2}", results.Count, _vinylRipOptions.ScanWindowLengthInSeconds, ScriptTimer.Time());
            Output.LineBreakToScriptWindow();
            OutputTrackDetails(tracks);

            ScriptTimer.Reset();
            RefineTrackDefinitionsByScanning(tracks);
            Output.LineBreakToScriptWindow();

            Output.ToScriptWindow("RefineTrackDefinitionsByScanning Finished scanning:\r\n- Scan Duration: {0}", ScriptTimer.Time());
            Output.LineBreakToScriptWindow();
            OutputTrackDetails(tracks);

            return(tracks);
        }
示例#16
0
        public SfAudioSelection EnforceNoisePrintSelection(IScriptableApp app, double noiseprintLength)
        {
            if (!IsCurrentSelectionGreaterThan(app, noiseprintLength))
            {
                throw new ScriptAbortedException("A noise selection of {0} seconds or more must be made before running this script.", noiseprintLength);
            }

            ISfDataWnd window = _file.Window;

            WindowTasks.SelectBothChannels(window);

            long             noiseprintSampleLength = _file.SecondsToPosition(noiseprintLength);
            SfAudioSelection selection = new SfAudioSelection(window.Selection.Start, noiseprintSampleLength, 0);

            return(selection);
        }
示例#17
0
    public void Begin(IScriptableApp app)
    {
        string strFile1   = GETARG("file1", "");
        string strFile2   = GETARG("file2", "");
        string strOutFile = GETARG("outfile", "");

        if ("" == strFile1 || "" == strFile2 || "" == strOutFile)
        {
            MessageBox.Show("useage\nfile1=path\\filename&file2=path\\filename&outfile=path\\filename", "invald arguments");
            return;
        }
        ISfFileHost fhOne = app.OpenFile(strFile1, true, true);

        if (null == fhOne)
        {
            return;
        }
        ISfFileHost fhTwo = app.OpenFile(strFile2, true, true);

        if (null == fhTwo)
        {
            fhOne.Close(CloseOptions.DiscardChanges);
            return;
        }
        ISfFileHost fhOut = app.NewFile(fhOne.DataFormat, false);

        fhOut.ReplaceAudio(new SfAudioSelection(0, 0), fhOne, new SfAudioSelection(fhOne));
        fhOut.DoEffect("Invert/Flip", 0, new SfAudioSelection(fhOut), EffectOptions.EffectOnly);
        fhOut.WaitForDoneOrCancel();
        fhOut.MixAudio(new SfAudioSelection(fhOut), 1.0, 1.0, fhTwo, new SfAudioSelection(fhTwo));
        fhOut.WaitForDoneOrCancel();
        fhOut.SaveAs(strOutFile, fhOne.SaveFormat.Guid, "Default Template", RenderOptions.RenderOnly);
        fhOut.WaitForDoneOrCancel();

        fhOne.Close(CloseOptions.DiscardChanges);
        fhTwo.Close(CloseOptions.DiscardChanges);
        fhOut.Close(CloseOptions.DiscardChanges);

        // Close Sound Forge.
        System.Diagnostics.Process curr = System.Diagnostics.Process.GetCurrentProcess();
        curr.CloseMainWindow();
    }
示例#18
0
        public void FromSoundForge(IScriptableApp app)
        {
            _app          = app;
            _outputHelper = new OutputHelper(this);
            const string aborted = "Script Aborted";

            try
            {
                Execute();
                Output.ToStatusBar(ScriptTitle + " Finished.");
            }
            catch (ScriptAbortedException ex)
            {
                string msgText = string.IsNullOrEmpty(ex.Message) ? aborted  : ex.Message;
                Output.ToMessageBox(MessageBoxIcon.Error, MessageBoxButtons.OK, msgText);
                Output.ToStatusBar(aborted);
                Output.ToScriptWindow(ErrorFormatter.Format(ex));
            }
            catch (Exception ex)
            {
                Output.ToStatusBar("Script Terminated: An unhandled exception occurred while executing {0}!", ScriptTitle);
                Output.ToScriptWindow(ErrorFormatter.Format(ex));
            }
        }
    public void Begin(IScriptableApp app)
    {
        string strOutFile = GETARG("outfile", "path to save file at");

        if ("" == strOutFile)
        {
            MessageBox.Show("invald output path");
            return;
        }
        OpenFileDialog openFile = new OpenFileDialog();

        openFile.Title = "Open the input file.";
        ////string to hold the path of input file.
        String strFile1 = String.Empty;

        if (openFile.ShowDialog() == DialogResult.OK)
        {
            strFile1 = openFile.FileName.ToString();
        }
        OpenFileDialog openOutputFile = new OpenFileDialog();

        openOutputFile.Title = "Open the output file.";
        ////string to hold the path of output file.
        String strFile2 = String.Empty;

        if (openOutputFile.ShowDialog() == DialogResult.OK)
        {
            strFile2 = openOutputFile.FileName.ToString();
        }
        ISfFileHost fhOne = app.OpenFile(strFile1, true, true);

        if (null == fhOne)
        {
            return;
        }
        ISfFileHost fhTwo = app.OpenFile(strFile2, true, true);

        if (null == fhTwo)
        {
            fhOne.Close(CloseOptions.DiscardChanges);
            return;
        }
        ISfFileHost fhOut = app.NewFile(fhOne.DataFormat, false);

        fhOut.ReplaceAudio(new SfAudioSelection(0, 0), fhOne, new SfAudioSelection(fhOne));
        fhOut.DoEffect("Invert/Flip", 0, new SfAudioSelection(fhOut), EffectOptions.EffectOnly);
        fhOut.WaitForDoneOrCancel();
        fhOut.MixAudio(new SfAudioSelection(fhOut), 1.0, 1.0, fhTwo, new SfAudioSelection(fhTwo));
        fhOut.WaitForDoneOrCancel();
        fhOut.SaveAs(strOutFile, fhOne.SaveFormat.Guid, "Default Template", RenderOptions.RenderOnly);
        fhOut.WaitForDoneOrCancel();
        fhOne.Close(CloseOptions.DiscardChanges);
        fhTwo.Close(CloseOptions.DiscardChanges);
        SfAudioStatistics[] stat = new SfAudioStatistics[fhOut.Channels];
        fhOut.UpdateStatistics(SfAudioSelection.All);
        stat[0] = fhOut.GetStatistics(0);
        stat[1] = fhOut.GetStatistics(1);
        stat[2] = fhOut.GetStatistics(2);
        stat[3] = fhOut.GetStatistics(3);
        stat[4] = fhOut.GetStatistics(4);
        stat[5] = fhOut.GetStatistics(5);
        stat[6] = fhOut.GetStatistics(6);
        stat[7] = fhOut.GetStatistics(7);
        MessageBox.Show(String.Format("Max Sample Value Channel 1 - {0},Channel 2 - {1},Channel 3 - {2},Channel 4 - {3},Channel 5 - {4},Channel 6 - {5},Channel 7 - {6},Channel 8 - {7}", stat[0].MaxValue, stat[1].MaxValue, stat[2].MaxValue, stat[3].MaxValue, stat[4].MaxValue, stat[5].MaxValue, stat[6].MaxValue, stat[7].MaxValue));
        MessageBox.Show(String.Format("Min Sample Value Channel 1 - {0},Channel 2 - {1},Channel 3 - {2},Channel 4 - {3},Channel 5 - {4},Channel 6 - {5}, Channel 7 - {6}, Channel 8 - {7}", stat[0].MinValue, stat[1].MinValue, stat[2].MinValue, stat[3].MinValue, stat[4].MaxValue, stat[5].MinValue, stat[6].MinValue, stat[7].MinValue));

        System.Diagnostics.Process curr = System.Diagnostics.Process.GetCurrentProcess();
    }
示例#20
0
    private void addSilence(string audioFileName, double[] silences, IScriptableApp appl, string outPutDir)
    {
        formApp.OutputText(string.Format("Adding {0}ms to front and {1} to the back of {2}", silences[0], silences[1], Path.GetFileName(audioFileName)));

        ISfFileHost oldFile = appl.OpenFile(audioFileName, true, true);
        ISfFileHost newFile = appl.NewFile(oldFile.DataFormat, true);

        newFile.OverwriteAudio(0, 0, oldFile, new SfAudioSelection(oldFile));

        long leadSilence = newFile.SecondsToPosition(silences[0]);
        long trailSilence = newFile.SecondsToPosition(silences[1]);

        if (leadSilence > 0)
            newFile.InsertSilence(0, leadSilence);
        if (trailSilence > 0)
            newFile.InsertSilence(newFile.Length, trailSilence);

        //next line could fail if user does not have permission to create directory. Implement try/catch
        string outName = Path.Combine(outPutDir, Path.GetFileName(audioFileName));
        newFile.SaveAs(outName, oldFile.SaveFormat.Guid, "Default Template", RenderOptions.WaitForDoneOrCancel);

        oldFile.Close(CloseOptions.DiscardChanges);
        newFile.Close(CloseOptions.SaveChanges);
    }
示例#21
0
 public void addSfApp(IScriptableApp appIn)
 {
     // add sound Forge app to the form
     this.formApp = appIn;
 }
示例#22
0
 public SfAudioSelection EnforceNoisePrintSelection(IScriptableApp app)
 {
     return(EnforceNoisePrintSelection(app, 2.0d));
 }
示例#23
0
 public OutputHelper(IEntryPoint entryPoint)
 {
     _entryPoint = entryPoint;
     _app        = entryPoint.App;
 }