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; }
protected override void Execute() { _file = App.CurrentFile; _fileTasks = new FileTasks(_file); _fileTasks.EnforceStereoFileOpen(); _fileTasks.ZoomOutFull(); FileMarkersWrapper markers = new FileMarkersWrapper(_file); TrackMarkerNameBuilder trackMarkerNameBuilder = new TrackMarkerNameBuilder(); TrackMarkerFactory markerAndRegionFactory = new TrackMarkerFactory(markers, Output, trackMarkerNameBuilder); _splitTrackList = new SplitTrackList(markerAndRegionFactory, markerAndRegionFactory, trackMarkerNameBuilder, markers, new TrackMarkerSpecifications(), Output); _vinylRipOptions = new VinylRipOptions(); _noiseprintSelection = _fileTasks.EnforceNoisePrintSelection(App, _vinylRipOptions.NoiseprintLengthSeconds); // TODO: aiming to get this to re-use the initialisation from VinylRip2, then once valid/initialized, throw up the confirm tracks form and do the existing processing/splitting // TODO: validate tracks DialogResult result = ConfirmTrackSplitsForm(Script.Application.Win32Window); if (result == DialogResult.Cancel) { return; } DoFinalAudioClean(); Directory.CreateDirectory(_outputDirectory); _splitTrackList.InitTracks(_vinylRipOptions); _splitTrackList.DumpToScriptWindow(); DoTrackSplitting(_splitTrackList, trackMarkerNameBuilder); }
//TODO: clear console //TODO: come up with a way of saving settings between script runs, and between the 2 scripts (save options to json?) protected override void Execute() { _file = App.CurrentFile; _fileTasks = new FileTasks(_file); _fileTasks.EnforceStereoFileOpen(); _fileTasks.ZoomOutFull(); //TODO: retain marker positions in script and undo NOT working! //_file.UndosAreEnabled = true; //int undoId = _file.BeginUndo("PrepareAudio"); //_file.EndUndo(undoId, true); _vinylRipOptions = new VinylRipOptions(); _noiseprintSelection = _fileTasks.EnforceNoisePrintSelection(App, _vinylRipOptions.NoiseprintLengthSeconds); _file.Markers.Add(new SfAudioMarker(_noiseprintSelection)); CleanVinylRecording(AggressiveCleaningPreset, 3, _noiseprintSelection); //TODO: configure number of noise reduction passes? _vinylRipOptions.StartScanFilePositionInSamples = _file.SecondsToPosition(_vinylRipOptions.NoiseprintLengthSeconds); _trackList = FindTracks(App, _file); App.DoMenuAndWait("Edit.UndoAll", false); FileMarkersWrapper markers = new FileMarkersWrapper(_file); TrackMarkerFactory regionFactory = new TrackMarkerFactory(markers, Output, new TrackMarkerNameBuilder()); foreach (TrackDefinition track in _trackList) { regionFactory.CreateRegion(track.Number, track.StartPosition, track.Length); } }
protected override void Execute() { _file = App.CurrentFile; _fileTasks = new FileTasks(_file); _fileTasks.EnforceStereoFileOpen(); _fileTasks.ZoomOutFull(); FileMarkersWrapper markers = new FileMarkersWrapper(_file); TrackMarkerNameBuilder trackMarkerNameBuilder = new TrackMarkerNameBuilder(); TrackMarkerFactory markerAndRegionFactory = new TrackMarkerFactory(markers, Output, trackMarkerNameBuilder); _splitTrackList = new SplitTrackList(markerAndRegionFactory, markerAndRegionFactory, trackMarkerNameBuilder, markers, new TrackMarkerSpecifications(), Output); _vinylRipOptions = new VinylRipOptions(); // TODO: validate tracks _splitTrackList.InitTracks(_vinylRipOptions); _splitTrackList.DumpToScriptWindow(); EditTracksViewModel viewModel = new EditTracksViewModel(_fileTasks); EditTracksController controller = new EditTracksController(App, new EditTracksFormFactory(), this, Output, _fileTasks); controller.Edit(viewModel, _splitTrackList, _vinylRipOptions); }
public SplitTrackList(ICreateFadeMarkers markerFactory, ICreateTrackRegions regionFactory, ICreateTrackMarkerNames trackMarkerNameBuilder, IFileMarkersWrapper fileMarkers, ITrackMarkerSpecifications markerSpecifications, IOutputHelper output) { _markerFactory = markerFactory; _regionFactory = regionFactory; _trackMarkerNameBuilder = trackMarkerNameBuilder; _fileMarkers = fileMarkers; _file = fileMarkers.File; _markerSpecifications = markerSpecifications; _output = output; }
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); }
private void DoTrackSplitting(SplitTrackList tracks, ICreateTrackMarkerNames trackMarkerNameBuilder) { //App.FindRenderer("FLAC Audio", "flac"); //foreach (ISfRenderer r in App.Renderers) //{ // Output.LineBreakToScriptWindow(); // Output.ToScriptWindow(r.Name); // Output.ToScriptWindow(r.Extension); // Output.ToScriptWindow(r.Guid); // foreach (ISfGenericPreset preset in r.Templates) // { // Output.ToScriptWindow(preset.Name); // } //} //tracks.Clear(); foreach (SplitTrackDefinition track in tracks) { ISfFileHost trackFile = _file.NewFile(track.GetSelectionWithFades()); trackFile.Markers.Clear(); trackFile.Summary.Album = _tbxAlbum.Text; trackFile.Summary.Artist = _tbxArtist.Text; trackFile.Summary.TrackNo = string.Concat(track.Number, "/", tracks.Count); FileTasks trackTasks = new FileTasks(trackFile); if (track.AddFadeIn) { Output.ToScriptWindow("Track {0}: Fade In {1} Samples", track.Number, track.FadeInLength); trackFile.Window.SetSelectionAndScroll(0, track.FadeInLength, DataWndScrollTo.NoMove); App.DoMenuAndWait("Process.FadeIn", false); } if (track.AddFadeOut) { Output.ToScriptWindow("Track {0}: Fade Out {1} Samples", track.Number, track.FadeOutLength); trackFile.Window.SetSelectionAndScroll(track.FadeOutStartPosition, trackFile.Length, DataWndScrollTo.NoMove); App.DoMenuAndWait("Process.FadeOut", false); } trackTasks.ApplyEffectPreset(App, trackTasks.SelectAll(), "iZotope MBIT+ Dither", "Convert to 16 bit (advanced light dither)", EffectOptions.EffectOnly, Output.ToScriptWindow); string savePath = string.Concat(_outputDirectory, Path.DirectorySeparatorChar, trackMarkerNameBuilder.GetRegionMarkerName(track.Number) + ".flac"); trackFile.SaveAs(savePath, "FLAC Audio", "44,100 Hz, 16 Bit, Stereo", RenderOptions.SaveMetadata); trackFile.Close(CloseOptions.QuerySaveIfChanged); Output.ToScriptWindow("Saved '{0}'", savePath); Output.LineBreakToScriptWindow(); } }
public SplitTrackDefinition( SplitTrackList splitTrackList, ISfFileHost file, VinylRipOptions options, ICreateFadeMarkers markerFactory, ICreateTrackRegions regionFactory, IOutputHelper output) { _options = options; _splitTrackList = splitTrackList; _originalFile = file; _markerFactory = markerFactory; _regionFactory = regionFactory; _output = output; _trackRegionMarker = new SfAudioMarker(); _trackRegionMarker.Type = MarkerType.Region; }
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(); }
public Mock <IFileMarkersWrapper> CreateStubMarkerList(ISfFileHost file) { RealMarkerList = new List <SfAudioMarker>(); var markerList = new Mock <IFileMarkersWrapper>(MockBehavior.Default); markerList.Setup(x => x.Remove(It.IsAny <SfAudioMarker>())) .Callback <SfAudioMarker>(m => RealMarkerList.Remove(m)); markerList.Setup(x => x.File).Returns(file); markerList.Setup(x => x.Add(It.IsAny <SfAudioMarker>())) .Returns <SfAudioMarker>(m => { RealMarkerList.Add(m); return(RealMarkerList.IndexOf(m)); }); markerList.Setup(x => x[It.IsAny <int>()]) .Returns <int>(idx => RealMarkerList[idx]); return(markerList); }
public long ScanWindowLengthInSamples(ISfFileHost file) { return(file.SecondsToPosition(ScanWindowLengthInSeconds)); }
public TrackList(VinylRipOptions vinylRipOptions, ISfFileHost file) { _vinylRipOptions = vinylRipOptions; _file = file; }
private void runFadeEffectProcess() { if (isRunning) { return; } try { if (fadeInPresetComboBox.Items.Count <= 0) { MessageBox.Show("Fade in Preset is empty.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); fadeInPresetComboBox.Focus(); return; } if (fadeOutPresetComboBox.Items.Count <= 0) { MessageBox.Show("Fade in Preset is empty.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); fadeOutPresetComboBox.Focus(); return; } isRunning = true; List <string> files = new List <string>(); foreach (DataGridViewRow row in fileList.Rows) { files.Add(Path.Combine((string)row.Cells[1].Value, (string)row.Cells[0].Value)); } if (files.Count <= 0) { return; } progressBar.Maximum = files.Count; int count = 0; foreach (string file in files) { fileList.Rows[count].ErrorText = string.Empty; if (cancelRequest) { break; } ISfFileHost filehost = null; int undo = 0; try { filehost = forgeApp.FindFile(file); if (filehost == null) { filehost = forgeApp.OpenFile(file, false, false); } if (filehost.WaitForDoneOrCancel() == SfStatus.Fail) { fileList.Rows[count].ErrorText = string.Format("{0} can not be opened.", file); continue; } undo = filehost.BeginUndo("Fade In and Out"); SfStatus status = SfStatus.NotAvailable; Int64 fadetime = filehost.SecondsToPosition((double)fadeInTimeNumericUpDown.Value); if (fadetime <= filehost.Length) { filehost.DoEffect(EffectName, fadeInPresetComboBox.Text, new SfAudioSelection(0, fadetime), EffectOptions.EffectOnly); status = filehost.WaitForDoneOrCancel(); if (status == SfStatus.Success) { fadetime = filehost.SecondsToPosition((double)fadeOutTimeNumericUpDown.Value); if (fadetime <= filehost.Length) { filehost.DoEffect(EffectName, fadeOutPresetComboBox.Text, new SfAudioSelection(filehost.Length - fadetime, fadetime), EffectOptions.EffectOnly); status = filehost.WaitForDoneOrCancel(); } else { fileList.Rows[count].ErrorText = string.Format("The fade out time({0}) is longer than total time({1}).", fadetime, filehost.Length); status = SfStatus.Fail; } } } else { fileList.Rows[count].ErrorText = string.Format("The fade in time({0}) is longer than total time({1}).", fadetime, filehost.Length); status = SfStatus.Fail; } filehost.WaitForDoneOrCancel(); if (status != SfStatus.Success) { if (fileList.Rows[count].ErrorText == string.Empty) { fileList.Rows[count].ErrorText = string.Format("error code({0}).", status); } } filehost.EndUndo(undo, (status != SfStatus.Success)); filehost.WaitForDoneOrCancel(); filehost.Save(SaveOptions.WaitForDoneOrCancel); filehost.WaitForDoneOrCancel(); filehost.Close(CloseOptions.SaveChanges); filehost.WaitForDoneOrCancel(); } catch (Exception e) { forgeApp.SetStatusText(e.ToString()); filehost.EndUndo(undo, true); filehost.Close(CloseOptions.DiscardChanges); fileList.Rows[count].ErrorText = e.ToString(); } finally { count++; progressBar.Value++; progressBar.Refresh(); } } } finally { isRunning = false; cancelRequest = false; } }
public FileMarkersWrapper(ISfFileHost file) { File = file; }
public FileTasks(ISfFileHost file) { _file = file; }
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(); }