private void WriteAudioFilesThread(object o) { object[] p = (object[])o; CUESheet cueSheet = (CUESheet)p[0]; string outDir = (string)p[1]; CUEStyle cueStyle = (CUEStyle)p[2]; try { cueSheet.WriteAudioFiles(outDir, cueStyle, new SetStatus(this.SetStatus)); this.Invoke((MethodInvoker) delegate() { if (_batchPaths.Count == 0) { SetupControls(false); } ShowFinishedMessage(cueSheet.PaddedToFrame); }); } catch (StopException) { _batchPaths.Clear(); this.Invoke((MethodInvoker) delegate() { SetupControls(false); MessageBox.Show("Conversion was stopped.", "Stopped", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }); } catch (Exception ex) { this.Invoke((MethodInvoker) delegate() { if (_batchPaths.Count == 0) { SetupControls(false); } if (!ShowErrorMessage(ex)) { _batchPaths.Clear(); SetupControls(false); } }); } if (_batchPaths.Count != 0) { _batchPaths.RemoveAt(0); this.BeginInvoke((MethodInvoker) delegate() { if (_batchPaths.Count == 0) { SetupControls(false); ShowBatchDoneMessage(); } else { StartConvert(); } }); } }
private int[] CalculateAudioFileLengths(CUEStyle style) { int iTrack, iIndex, iFile; int[] fileLengths; bool htoaToFile = (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0); bool discardOutput; if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) { fileLengths = new int[1]; iFile = 0; } else { fileLengths = new int[TrackCount + (htoaToFile ? 1 : 0)]; iFile = -1; } for (iTrack = 0; iTrack < TrackCount; iTrack++) { if (style == CUEStyle.GapsPrepended || style == CUEStyle.GapsLeftOut) iFile++; for (iIndex = 0; iIndex <= _toc[_toc.FirstAudio + iTrack].LastIndex; iIndex++) { if (style == CUEStyle.GapsAppended && (iIndex == 1 || (iIndex == 0 && iTrack == 0 && htoaToFile))) iFile++; if (style == CUEStyle.GapsAppended && iIndex == 0 && iTrack == 0) discardOutput = !htoaToFile; else discardOutput = (style == CUEStyle.GapsLeftOut && iIndex == 0); if (!discardOutput) fileLengths[iFile] += (int)_toc.IndexLength(_toc.FirstAudio + iTrack, iIndex) * 588; } } return fileLengths; }
public void WriteAudioFilesPass(string dir, CUEStyle style, int[] destLengths, bool htoaToFile, bool noOutput) { int iTrack, iIndex; AudioBuffer sampleBuffer = new AudioBuffer(AudioPCMConfig.RedBook, 0x10000); TrackInfo track; IAudioSource audioSource = null; IAudioDest audioDest = null; bool discardOutput; int iSource = -1; int iDest = -1; int samplesRemSource = 0; ApplyWriteOffset(); int destBPS = 16; hdcdDecoder = null; if (_config.detectHDCD && CUEProcessorPlugins.hdcd != null) { // currently broken verifyThenConvert on HDCD detection!!!! need to check for HDCD results higher try { destBPS = ((_outputLossyWAV && _config.decodeHDCDtoLW16) || !_config.decodeHDCDto24bit) ? 20 : 24; hdcdDecoder = Activator.CreateInstance(CUEProcessorPlugins.hdcd, 2, 44100, destBPS, _config.decodeHDCD) as IAudioDest; } catch { } if (hdcdDecoder == null || !_config.decodeHDCD) destBPS = 16; } if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) { iDest++; if (_isCD && style == CUEStyle.SingleFileWithCUE) _padding += Encoding.UTF8.GetByteCount(GetCUESheetContents(style)); audioDest = GetAudioDest(_destPaths[iDest], destLengths[iDest], destBPS, _padding, noOutput); } int currentOffset = 0, previousOffset = 0; int trackLength = (int)_toc.Pregap * 588; int diskLength = 588 * (int)_toc.AudioLength; int diskOffset = 0; // we init AR before CTDB so that CTDB gets inited with correct TOC if (isUsingAccurateRip || isUsingCUEToolsDB) _arVerify.Init(_toc); if (isUsingCUEToolsDB && !isUsingCUEToolsDBFix) { _CUEToolsDB.TOC = _toc; // This might be unnecessary, because they point to the same structure - if we modify _toc, _CUEToolsDB.TOC gets updated. Unless we set cueSheet.TOC... _CUEToolsDB.Init(_arVerify); } ShowProgress(String.Format("{2} track {0:00} ({1:00}%)...", 0, 0, noOutput ? "Verifying" : "Writing"), 0.0, null, null); #if !DEBUG try #endif { for (iTrack = 0; iTrack < TrackCount; iTrack++) { track = _tracks[iTrack]; if ((style == CUEStyle.GapsPrepended) || (style == CUEStyle.GapsLeftOut)) { iDest++; if (hdcdDecoder != null) (hdcdDecoder as IAudioFilter).AudioDest = null; if (audioDest != null) audioDest.Close(); audioDest = GetAudioDest(_destPaths[iDest], destLengths[iDest], destBPS, _padding, noOutput); } for (iIndex = 0; iIndex <= _toc[_toc.FirstAudio + iTrack].LastIndex; iIndex++) { int samplesRemIndex = (int)_toc.IndexLength(_toc.FirstAudio + iTrack, iIndex) * 588; if (iIndex == 1) { previousOffset = currentOffset; currentOffset = 0; trackLength = (int)_toc[_toc.FirstAudio + iTrack].Length * 588; } if ((style == CUEStyle.GapsAppended) && (iIndex == 1)) { if (hdcdDecoder != null) (hdcdDecoder as IAudioFilter).AudioDest = null; if (audioDest != null) audioDest.Close(); iDest++; audioDest = GetAudioDest(_destPaths[iDest], destLengths[iDest], destBPS, _padding, noOutput); } if ((style == CUEStyle.GapsAppended) && (iIndex == 0) && (iTrack == 0)) { discardOutput = !htoaToFile; if (htoaToFile) { iDest++; audioDest = GetAudioDest(_destPaths[iDest], destLengths[iDest], destBPS, _padding, noOutput); } } else if ((style == CUEStyle.GapsLeftOut) && (iIndex == 0)) { discardOutput = true; } else { discardOutput = false; } while (samplesRemIndex != 0) { if (samplesRemSource == 0) { // if (_isCD && audioSource != null && audioSource is CDDriveReader) // updatedTOC = ((CDDriveReader)audioSource).TOC; if (audioSource != null) audioSource.Close(); audioSource = GetAudioSource(++iSource, _config.separateDecodingThread || _isCD); samplesRemSource = (int)_sources[iSource].Length; } int copyCount = Math.Min(samplesRemIndex, samplesRemSource); if (trackLength > 0 && !_isCD) { double trackPercent = (double)currentOffset / trackLength; ShowProgress(String.Format("{2} track {0:00} ({1:00}%)...", iIndex > 0 ? iTrack + 1 : iTrack, (int)(100 * trackPercent), noOutput ? "Verifying" : "Writing"), (int)diskOffset, (int)diskLength, _isCD ? string.Format("{0}: {1:00} - {2}", audioSource.Path, iTrack + 1, Metadata.Tracks[iTrack].Title) : audioSource.Path, discardOutput ? null : audioDest.Path); } copyCount = audioSource.Read(sampleBuffer, copyCount); if (copyCount == 0) throw new Exception("Unexpected end of file"); if (isUsingCUEToolsDB && isUsingCUEToolsDBFix) _CUEToolsDB.SelectedEntry.repair.Write(sampleBuffer); // we use AR after CTDB fix, so that we can verify what we fixed if (isUsingAccurateRip || isUsingCUEToolsDB) _arVerify.Write(sampleBuffer); if (!discardOutput) { if (!_config.detectHDCD || !_config.decodeHDCD) audioDest.Write(sampleBuffer); if (_config.detectHDCD && hdcdDecoder != null) { if (_config.wait750FramesForHDCD && diskOffset > 750 * 588 && string.Format("{0:s}", hdcdDecoder) == "") { (hdcdDecoder as IAudioFilter).AudioDest = null; hdcdDecoder = null; if (_config.decodeHDCD) { audioSource.Close(); audioDest.Delete(); throw new Exception("HDCD not detected."); } } else { if (_config.decodeHDCD) (hdcdDecoder as IAudioFilter).AudioDest = (discardOutput || noOutput) ? null : audioDest; hdcdDecoder.Write(sampleBuffer); } } } currentOffset += copyCount; diskOffset += copyCount; samplesRemIndex -= copyCount; samplesRemSource -= copyCount; CheckStop(); } } } if (hdcdDecoder != null) (hdcdDecoder as IAudioFilter).AudioDest = null; hdcdDecoder = null; if (audioSource != null) audioSource.Close(); audioSource = null; if (audioDest != null) audioDest.Close(); audioDest = null; } #if !DEBUG catch (Exception ex) { if (hdcdDecoder != null) (hdcdDecoder as IAudioFilter).AudioDest = null; hdcdDecoder = null; if (audioSource != null) try { audioSource.Close(); } catch { } audioSource = null; if (audioDest != null) try { audioDest.Delete(); } catch { } audioDest = null; throw ex; } #endif }
public string GetCUESheetContents(CUEStyle style, bool htoaToFile) { StringWriter sw = new StringWriter(); int i, iTrack, iIndex; uint timeRelativeToFileStart = 0; General.SetCUELine(_attributes, "PERFORMER", Metadata.Artist, true); General.SetCUELine(_attributes, "TITLE", Metadata.Title, true); General.SetCUELine(_attributes, "CATALOG", Metadata.Barcode, false); General.SetCUELine(_attributes, "REM", "DATE", Metadata.Year, false); General.SetCUELine(_attributes, "REM", "DISCNUMBER", Metadata.DiscNumber, false); General.SetCUELine(_attributes, "REM", "TOTALDISCS", Metadata.TotalDiscs, false); General.SetCUELine(_attributes, "REM", "GENRE", Metadata.Genre, true); General.SetCUELine(_attributes, "REM", "COMMENT", Metadata.Comment, true); for (i = 0; i < Tracks.Count; i++) { General.SetCUELine(Tracks[i].Attributes, "PERFORMER", Metadata.Tracks[i].Artist, true); General.SetCUELine(Tracks[i].Attributes, "TITLE", Metadata.Tracks[i].Title, true); General.SetCUELine(Tracks[i].Attributes, "ISRC", Metadata.Tracks[i].ISRC, false); } using (sw) { if (_config.writeArTagsOnEncode) WriteLine(sw, 0, "REM ACCURATERIPID " + (_accurateRipId ?? AccurateRipVerify.CalculateAccurateRipId(_toc))); for (i = 0; i < _attributes.Count; i++) WriteLine(sw, 0, _attributes[i]); if (style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _singleFilename)); if (htoaToFile) WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _htoaFilename)); for (iTrack = 0; iTrack < TrackCount; iTrack++) { if ((style == CUEStyle.GapsPrepended) || (style == CUEStyle.GapsLeftOut) || ((style == CUEStyle.GapsAppended) && ((_toc[_toc.FirstAudio + iTrack].Pregap == 0) || ((iTrack == 0) && !htoaToFile)))) { WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _trackFilenames[iTrack])); timeRelativeToFileStart = 0; } WriteLine(sw, 1, String.Format("TRACK {0:00} AUDIO", iTrack + 1)); for (i = 0; i < _tracks[iTrack].Attributes.Count; i++) WriteLine(sw, 2, _tracks[iTrack].Attributes[i]); if (_toc[_toc.FirstAudio + iTrack].Pregap != 0) { if (((style == CUEStyle.GapsLeftOut) || ((style == CUEStyle.GapsAppended) && (iTrack == 0) && !htoaToFile) || ((style == CUEStyle.SingleFile || style == CUEStyle.SingleFileWithCUE) && (iTrack == 0) && _usePregapForFirstTrackInSingleFile))) WriteLine(sw, 2, "PREGAP " + CDImageLayout.TimeToString(_toc[_toc.FirstAudio + iTrack].Pregap)); else { WriteLine(sw, 2, String.Format("INDEX 00 {0}", CDImageLayout.TimeToString(timeRelativeToFileStart))); timeRelativeToFileStart += _toc[_toc.FirstAudio + iTrack].Pregap; if (style == CUEStyle.GapsAppended) { WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _trackFilenames[iTrack])); timeRelativeToFileStart = 0; } } } for (iIndex = 1; iIndex <= _toc[_toc.FirstAudio + iTrack].LastIndex; iIndex++) { WriteLine(sw, 2, String.Format("INDEX {0:00} {1}", iIndex, CDImageLayout.TimeToString(timeRelativeToFileStart))); timeRelativeToFileStart += _toc.IndexLength(_toc.FirstAudio + iTrack, iIndex); } } } sw.Close(); return sw.ToString(); }
public string GetCUESheetContents(CUEStyle style) { return GetCUESheetContents(style, (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0)); }
public string GetM3UContents(CUEStyle style) { StringWriter sw = new StringWriter(); if (style == CUEStyle.GapsAppended && _config.preserveHTOA && _toc.Pregap != 0) WriteLine(sw, 0, _htoaFilename); for (int iTrack = 0; iTrack < TrackCount; iTrack++) WriteLine(sw, 0, _trackFilenames[iTrack]); sw.Close(); return sw.ToString(); }
public CUEConfig() { fixOffsetMinimumConfidence = 2; fixOffsetMinimumTracksPercent = 51; encodeWhenConfidence = 2; encodeWhenPercent = 100; encodeWhenZeroOffset = false; fixOffset = false; noUnverifiedOutput = false; writeArTagsOnEncode = false; writeArLogOnConvert = true; writeArTagsOnVerify = false; writeArLogOnVerify = false; autoCorrectFilenames = true; preserveHTOA = true; detectGaps = true; keepOriginalFilenames = false; trackFilenameFormat = "%tracknumber%. %title%"; singleFilenameFormat = "%filename%"; removeSpecial = false; specialExceptions = "-()"; replaceSpaces = false; embedLog = true; extractLog = true; fillUpCUE = true; overwriteCUEData = false; filenamesANSISafe = true; bruteForceDTL = false; createEACLOG = true; detectHDCD = true; wait750FramesForHDCD = true; decodeHDCD = false; createM3U = false; createCUEFileWhenEmbedded = true; truncate4608ExtraSamples = true; lossyWAVQuality = 5; decodeHDCDtoLW16 = false; decodeHDCDto24bit = true; oneInstance = true; checkForUpdates = true; writeBasicTagsFromCUEData = true; copyBasicTags = true; copyUnknownTags = true; CopyAlbumArt = true; embedAlbumArt = true; extractAlbumArt = true; maxAlbumArtSize = 300; arLogToSourceFolder = false; arLogVerbose = true; fixOffsetToNearest = true; ArLogFilenameFormat = "%filename%.accurip"; AlArtFilenameFormat = "folder.jpg"; separateDecodingThread = true; gapsHandling = CUEStyle.GapsAppended; advanced = new CUEConfigAdvanced(); language = Thread.CurrentThread.CurrentUICulture.Name; encoders = new CUEToolsUDCList(); foreach (Type type in CUEProcessorPlugins.encs) foreach (AudioEncoderClass enc in Attribute.GetCustomAttributes(type, typeof(AudioEncoderClass))) encoders.Add(new CUEToolsUDC(enc, type)); decoders = new Dictionary<string, CUEToolsUDC>(); foreach (Type type in CUEProcessorPlugins.decs) { AudioDecoderClass dec = Attribute.GetCustomAttribute(type, typeof(AudioDecoderClass)) as AudioDecoderClass; decoders.Add(dec.DecoderName, new CUEToolsUDC(dec, type)); } if (Type.GetType("Mono.Runtime", false) == null) { encoders.Add(new CUEToolsUDC("flake", "flac", true, "0 1 2 3 4 5 6 7 8 9 10 11 12", "8", "flake.exe", "-%M - -o %O -p %P")); encoders.Add(new CUEToolsUDC("takc", "tak", true, "0 1 2 2e 2m 3 3e 3m 4 4e 4m", "2", "takc.exe", "-e -p%M -overwrite - %O")); encoders.Add(new CUEToolsUDC("ffmpeg alac", "m4a", true, "", "", "ffmpeg.exe", "-i - -f ipod -acodec alac -y %O")); encoders.Add(new CUEToolsUDC("VBR (lame.exe)", "mp3", false, "V9 V8 V7 V6 V5 V4 V3 V2 V1 V0", "V2", "lame.exe", "--vbr-new -%M - %O")); encoders.Add(new CUEToolsUDC("CBR (lame.exe)", "mp3", false, "96 128 192 256 320", "256", "lame.exe", "-m s -q 0 -b %M --noreplaygain - %O")); encoders.Add(new CUEToolsUDC("oggenc", "ogg", false, "-1 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8", "3", "oggenc.exe", "-q %M - -o %O")); encoders.Add(new CUEToolsUDC("nero aac", "m4a", false, "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9", "0.4", "neroAacEnc.exe", "-q %M -if - -of %O")); encoders.Add(new CUEToolsUDC("qaac tvbr", "m4a", false, "10 20 30 40 50 60 70 80 90 100 110 127", "80", "qaac.exe", "-s -V %M -q 2 - -o %O")); decoders.Add("takc", new CUEToolsUDC("takc", "tak", true, "", "", "takc.exe", "-d %I -")); decoders.Add("ffmpeg alac", new CUEToolsUDC("ffmpeg alac", "m4a", true, "", "", "ffmpeg.exe", "%I -f wav -")); } else { // !!! } formats = new Dictionary<string, CUEToolsFormat>(); formats.Add("flac", new CUEToolsFormat("flac", CUEToolsTagger.TagLibSharp, true, false, true, true, true, encoders.GetDefault("flac", true), null, GetDefaultDecoder("flac"))); formats.Add("wv", new CUEToolsFormat("wv", CUEToolsTagger.TagLibSharp, true, false, true, true, true, encoders.GetDefault("wv", true), null, GetDefaultDecoder("wv"))); formats.Add("ape", new CUEToolsFormat("ape", CUEToolsTagger.TagLibSharp, true, false, false, true, true, encoders.GetDefault("ape", true), null, GetDefaultDecoder("ape"))); formats.Add("tta", new CUEToolsFormat("tta", CUEToolsTagger.APEv2, true, false, false, false, true, encoders.GetDefault("tta", true), null, GetDefaultDecoder("tta"))); formats.Add("wav", new CUEToolsFormat("wav", CUEToolsTagger.TagLibSharp, true, false, true, false, true, encoders.GetDefault("wav", true), null, GetDefaultDecoder("wav"))); formats.Add("m4a", new CUEToolsFormat("m4a", CUEToolsTagger.TagLibSharp, true, true, false, false, true, encoders.GetDefault("m4a", true), encoders.GetDefault("m4a", false), GetDefaultDecoder("m4a"))); formats.Add("tak", new CUEToolsFormat("tak", CUEToolsTagger.APEv2, true, false, true, true, true, encoders.GetDefault("tak", true), null, "takc")); formats.Add("mp3", new CUEToolsFormat("mp3", CUEToolsTagger.TagLibSharp, false, true, false, false, true, null, encoders.GetDefault("mp3", false), null)); formats.Add("ogg", new CUEToolsFormat("ogg", CUEToolsTagger.TagLibSharp, false, true, false, false, true, null, encoders.GetDefault("ogg", false), null)); scripts = new Dictionary<string, CUEToolsScript>(); scripts.Add("default", new CUEToolsScript("default", true, new CUEAction[] { CUEAction.Verify, CUEAction.Encode }, "return processor.Go();")); scripts.Add("only if found", new CUEToolsScript("only if found", true, new CUEAction[] { CUEAction.Verify }, @"if (processor.ArVerify.AccResult != HttpStatusCode.OK) return processor.WriteReport(); return processor.Go();")); scripts.Add("fix offset", new CUEToolsScript("fix offset", true, new CUEAction[] { CUEAction.Encode }, @"if (processor.ArVerify.AccResult != HttpStatusCode.OK) return processor.WriteReport(); processor.WriteOffset = 0; processor.Action = CUEAction.Verify; string status = processor.Go(); uint tracksMatch; int bestOffset; processor.FindBestOffset(processor.Config.fixOffsetMinimumConfidence, !processor.Config.fixOffsetToNearest, out tracksMatch, out bestOffset); if (tracksMatch * 100 < processor.Config.fixOffsetMinimumTracksPercent * processor.TrackCount) return status; processor.WriteOffset = bestOffset; processor.Action = CUEAction.Encode; //MessageBox.Show(null, processor.AccurateRipLog, " + "\"Done\"" + @"MessageBoxButtons.OK, MessageBoxIcon.Information); return processor.Go(); ")); scripts.Add("encode if verified", new CUEToolsScript("encode if verified", true, new CUEAction[] { CUEAction.Encode }, @"if (processor.ArVerify.AccResult != HttpStatusCode.OK) return processor.WriteReport(); processor.Action = CUEAction.Verify; string status = processor.Go(); uint tracksMatch; int bestOffset; processor.FindBestOffset(processor.Config.encodeWhenConfidence, false, out tracksMatch, out bestOffset); if (tracksMatch * 100 < processor.Config.encodeWhenPercent * processor.TrackCount || (processor.Config.encodeWhenZeroOffset && bestOffset != 0)) return status; processor.Action = CUEAction.Encode; return processor.Go(); ")); scripts.Add("repair", new CUEToolsScript("repair", true, new CUEAction[] { CUEAction.Encode }, @" processor.UseCUEToolsDB(); processor.Action = CUEAction.Verify; if (processor.CTDB.DBStatus != null) return CTDB.DBStatus; processor.Go(); processor.CTDB.DoVerify(); if (!processor.CTDB.Verify.HasErrors) return ""nothing to fix""; if (!processor.CTDB.Verify.CanRecover) return ""cannot fix""; processor._useCUEToolsDBFix = true; processor.Action = CUEAction.Encode; return processor.Go(); ")); defaultVerifyScript = "default"; defaultEncodeScript = "default"; }
public void Load(SettingsReader sr) { int version = sr.LoadInt32("Version", null, null) ?? 202; fixOffsetMinimumConfidence = sr.LoadUInt32("ArFixWhenConfidence", 1, 1000) ?? 2; fixOffsetMinimumTracksPercent = sr.LoadUInt32("ArFixWhenPercent", 1, 100) ?? 51; encodeWhenConfidence = sr.LoadUInt32("ArEncodeWhenConfidence", 1, 1000) ?? 2; encodeWhenPercent = sr.LoadUInt32("ArEncodeWhenPercent", 1, 100) ?? 100; encodeWhenZeroOffset = sr.LoadBoolean("ArEncodeWhenZeroOffset") ?? false; noUnverifiedOutput = sr.LoadBoolean("ArNoUnverifiedOutput") ?? false; fixOffset = sr.LoadBoolean("ArFixOffset") ?? false; writeArTagsOnEncode = sr.LoadBoolean("ArWriteCRC") ?? writeArTagsOnEncode; writeArLogOnConvert = sr.LoadBoolean("ArWriteLog") ?? true; writeArTagsOnVerify = sr.LoadBoolean("ArWriteTagsOnVerify") ?? false; writeArLogOnVerify = sr.LoadBoolean("ArWriteLogOnVerify") ?? false; preserveHTOA = sr.LoadBoolean("PreserveHTOA") ?? true; detectGaps = sr.LoadBoolean("DetectGaps") ?? true; autoCorrectFilenames = sr.LoadBoolean("AutoCorrectFilenames") ?? true; keepOriginalFilenames = sr.LoadBoolean("KeepOriginalFilenames") ?? false; singleFilenameFormat = sr.Load("SingleFilenameFormat") ?? singleFilenameFormat; trackFilenameFormat = sr.Load("TrackFilenameFormat") ?? trackFilenameFormat; removeSpecial = sr.LoadBoolean("RemoveSpecialCharacters") ?? false; specialExceptions = sr.Load("SpecialCharactersExceptions") ?? "-()"; replaceSpaces = sr.LoadBoolean("ReplaceSpaces") ?? false; embedLog = sr.LoadBoolean("EmbedLog") ?? true; extractLog = sr.LoadBoolean("ExtractLog") ?? true; fillUpCUE = sr.LoadBoolean("FillUpCUE") ?? true; overwriteCUEData = sr.LoadBoolean("OverwriteCUEData") ?? false; filenamesANSISafe = sr.LoadBoolean("FilenamesANSISafe") ?? true; bruteForceDTL = sr.LoadBoolean("BruteForceDTL") ?? false; createEACLOG = sr.LoadBoolean("CreateEACLOG") ?? createEACLOG; detectHDCD = sr.LoadBoolean("DetectHDCD") ?? true; wait750FramesForHDCD = sr.LoadBoolean("Wait750FramesForHDCD") ?? true; decodeHDCD = sr.LoadBoolean("DecodeHDCD") ?? false; createM3U = sr.LoadBoolean("CreateM3U") ?? false; createCUEFileWhenEmbedded = sr.LoadBoolean("CreateCUEFileWhenEmbedded") ?? true; truncate4608ExtraSamples = sr.LoadBoolean("Truncate4608ExtraSamples") ?? true; lossyWAVQuality = sr.LoadInt32("LossyWAVQuality", 0, 10) ?? 5; decodeHDCDtoLW16 = sr.LoadBoolean("DecodeHDCDToLossyWAV16") ?? false; decodeHDCDto24bit = sr.LoadBoolean("DecodeHDCDTo24bit") ?? true; oneInstance = sr.LoadBoolean("OneInstance") ?? true; checkForUpdates = sr.LoadBoolean("CheckForUpdates") ?? true; writeBasicTagsFromCUEData = sr.LoadBoolean("WriteBasicTagsFromCUEData") ?? true; copyBasicTags = sr.LoadBoolean("CopyBasicTags") ?? true; copyUnknownTags = sr.LoadBoolean("CopyUnknownTags") ?? true; CopyAlbumArt = sr.LoadBoolean("CopyAlbumArt") ?? true; embedAlbumArt = sr.LoadBoolean("EmbedAlbumArt") ?? true; extractAlbumArt = sr.LoadBoolean("ExtractAlbumArt") ?? true; maxAlbumArtSize = sr.LoadInt32("MaxAlbumArtSize", 100, 10000) ?? maxAlbumArtSize; arLogToSourceFolder = sr.LoadBoolean("ArLogToSourceFolder") ?? arLogToSourceFolder; arLogVerbose = sr.LoadBoolean("ArLogVerbose") ?? arLogVerbose; fixOffsetToNearest = sr.LoadBoolean("FixOffsetToNearest") ?? fixOffsetToNearest; ArLogFilenameFormat = sr.Load("ArLogFilenameFormat") ?? ArLogFilenameFormat; AlArtFilenameFormat = sr.Load("AlArtFilenameFormat") ?? AlArtFilenameFormat; separateDecodingThread = sr.LoadBoolean("SeparateDecodingThread") ?? separateDecodingThread; try { using (TextReader reader = new StringReader(sr.Load("Advanced"))) advanced = CUEConfigAdvanced.serializer.Deserialize(reader) as CUEConfigAdvanced; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } int totalEncoders = sr.LoadInt32("ExternalEncoders", 0, null) ?? 0; for (int nEncoders = 0; nEncoders < totalEncoders; nEncoders++) { string name = sr.Load(string.Format("ExternalEncoder{0}Name", nEncoders)); string extension = sr.Load(string.Format("ExternalEncoder{0}Extension", nEncoders)); string path = sr.Load(string.Format("ExternalEncoder{0}Path", nEncoders)); string parameters = sr.Load(string.Format("ExternalEncoder{0}Parameters", nEncoders)); bool lossless = sr.LoadBoolean(string.Format("ExternalEncoder{0}Lossless", nEncoders)) ?? true; string supported_modes = sr.Load(string.Format("ExternalEncoder{0}Modes", nEncoders)) ?? ""; string default_mode = sr.Load(string.Format("ExternalEncoder{0}Mode", nEncoders)) ?? ""; CUEToolsUDC encoder; if (name == null) continue; if (!encoders.TryGetValue(name, out encoder)) { if (path == null || parameters == null || extension == null) continue; encoders.Add(new CUEToolsUDC(name, extension, lossless, supported_modes, default_mode, path, parameters)); } else if (version == 203) { if (encoder.path != null) { if (path == null || parameters == null || extension == null) continue; encoder.extension = extension; encoder.path = path; encoder.lossless = lossless; encoder.parameters = parameters; } else { if (encoder.settingsSerializer != null && parameters != "") try { using (TextReader reader = new StringReader(parameters)) encoder.settings = encoder.settingsSerializer.Deserialize(reader); } catch { } } encoder.supported_modes = supported_modes; encoder.default_mode = default_mode; } } int totalDecoders = sr.LoadInt32("ExternalDecoders", 0, null) ?? 0; for (int nDecoders = 0; nDecoders < totalDecoders; nDecoders++) { string name = sr.Load(string.Format("ExternalDecoder{0}Name", nDecoders)); string extension = sr.Load(string.Format("ExternalDecoder{0}Extension", nDecoders)); string path = sr.Load(string.Format("ExternalDecoder{0}Path", nDecoders)); string parameters = sr.Load(string.Format("ExternalDecoder{0}Parameters", nDecoders)); CUEToolsUDC decoder; if (!decoders.TryGetValue(name, out decoder)) decoders.Add(name, new CUEToolsUDC(name, extension, true, "", "", path, parameters)); else { decoder.extension = extension; decoder.path = path; decoder.parameters = parameters; } } int totalFormats = sr.LoadInt32("CustomFormats", 0, null) ?? 0; for (int nFormats = 0; nFormats < totalFormats; nFormats++) { string extension = sr.Load(string.Format("CustomFormat{0}Name", nFormats)); string encoderLossless = sr.Load(string.Format("CustomFormat{0}EncoderLossless", nFormats)) ?? ""; string encoderLossy = sr.Load(string.Format("CustomFormat{0}EncoderLossy", nFormats)) ?? ""; string decoder = sr.Load(string.Format("CustomFormat{0}Decoder", nFormats)); CUEToolsTagger tagger = (CUEToolsTagger)(sr.LoadInt32(string.Format("CustomFormat{0}Tagger", nFormats), 0, 2) ?? 0); bool allowLossless = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossless", nFormats)) ?? false; bool allowLossy = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossy", nFormats)) ?? false; bool allowLossyWav = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossyWAV", nFormats)) ?? false; bool allowEmbed = sr.LoadBoolean(string.Format("CustomFormat{0}AllowEmbed", nFormats)) ?? false; CUEToolsFormat format; CUEToolsUDC udcLossless, udcLossy; if (encoderLossless == "" || !encoders.TryGetValue(encoderLossless, out udcLossless)) udcLossless = encoders.GetDefault(extension, true); if (encoderLossy == "" || !encoders.TryGetValue(encoderLossy, out udcLossy)) udcLossy = encoders.GetDefault(extension, false); if (!formats.TryGetValue(extension, out format)) formats.Add(extension, new CUEToolsFormat(extension, tagger, allowLossless, allowLossy, allowLossyWav, allowEmbed, false, udcLossless, udcLossy, decoder)); else { format.encoderLossless = udcLossless; format.encoderLossy = udcLossy; format.decoder = decoder; if (!format.builtin) { format.tagger = tagger; format.allowLossless = allowLossless; format.allowLossy = allowLossy; format.allowLossyWAV = allowLossyWav; format.allowEmbed = allowEmbed; } } } int totalScripts = sr.LoadInt32("CustomScripts", 0, null) ?? 0; for (int nScripts = 0; nScripts < totalScripts; nScripts++) { string name = sr.Load(string.Format("CustomScript{0}Name", nScripts)); string code = sr.Load(string.Format("CustomScript{0}Code", nScripts)); List<CUEAction> conditions = new List<CUEAction>(); int totalConditions = sr.LoadInt32(string.Format("CustomScript{0}Conditions", nScripts), 0, null) ?? 0; for (int nCondition = 0; nCondition < totalConditions; nCondition++) conditions.Add((CUEAction)sr.LoadInt32(string.Format("CustomScript{0}Condition{1}", nScripts, nCondition), 0, null)); CUEToolsScript script; if (!scripts.TryGetValue(name, out script)) { if (name != "submit") scripts.Add(name, new CUEToolsScript(name, false, conditions, code)); } else { if (!script.builtin) { script.code = code; script.conditions = conditions; } } } defaultVerifyScript = sr.Load("DefaultVerifyScript") ?? "default"; defaultEncodeScript = sr.Load("DefaultVerifyAndConvertScript") ?? "default"; gapsHandling = (CUEStyle?)sr.LoadInt32("GapsHandling", null, null) ?? gapsHandling; language = sr.Load("Language") ?? Thread.CurrentThread.CurrentUICulture.Name; if (ArLogFilenameFormat.Contains("%F")) ArLogFilenameFormat = "%filename%.accurip"; if (singleFilenameFormat.Contains("%F")) singleFilenameFormat = "%filename%"; if (trackFilenameFormat.Contains("%N")) trackFilenameFormat = "%tracknumber%. %title%"; }
public void Load(SettingsReader sr) { int version = sr.LoadInt32("Version", null, null) ?? 202; fixOffsetMinimumConfidence = sr.LoadUInt32("ArFixWhenConfidence", 1, 1000) ?? 2; fixOffsetMinimumTracksPercent = sr.LoadUInt32("ArFixWhenPercent", 1, 100) ?? 51; encodeWhenConfidence = sr.LoadUInt32("ArEncodeWhenConfidence", 1, 1000) ?? 2; encodeWhenPercent = sr.LoadUInt32("ArEncodeWhenPercent", 1, 100) ?? 100; encodeWhenZeroOffset = sr.LoadBoolean("ArEncodeWhenZeroOffset") ?? false; noUnverifiedOutput = sr.LoadBoolean("ArNoUnverifiedOutput") ?? false; fixOffset = sr.LoadBoolean("ArFixOffset") ?? false; writeArTagsOnEncode = sr.LoadBoolean("ArWriteCRC") ?? writeArTagsOnEncode; writeArLogOnConvert = sr.LoadBoolean("ArWriteLog") ?? true; writeArTagsOnVerify = sr.LoadBoolean("ArWriteTagsOnVerify") ?? false; writeArLogOnVerify = sr.LoadBoolean("ArWriteLogOnVerify") ?? false; preserveHTOA = sr.LoadBoolean("PreserveHTOA") ?? true; detectGaps = sr.LoadBoolean("DetectGaps") ?? true; autoCorrectFilenames = sr.LoadBoolean("AutoCorrectFilenames") ?? true; keepOriginalFilenames = sr.LoadBoolean("KeepOriginalFilenames") ?? false; singleFilenameFormat = sr.Load("SingleFilenameFormat") ?? singleFilenameFormat; trackFilenameFormat = sr.Load("TrackFilenameFormat") ?? trackFilenameFormat; removeSpecial = sr.LoadBoolean("RemoveSpecialCharacters") ?? false; specialExceptions = sr.Load("SpecialCharactersExceptions") ?? "-()"; replaceSpaces = sr.LoadBoolean("ReplaceSpaces") ?? false; embedLog = sr.LoadBoolean("EmbedLog") ?? true; extractLog = sr.LoadBoolean("ExtractLog") ?? true; fillUpCUE = sr.LoadBoolean("FillUpCUE") ?? true; overwriteCUEData = sr.LoadBoolean("OverwriteCUEData") ?? false; filenamesANSISafe = sr.LoadBoolean("FilenamesANSISafe") ?? true; bruteForceDTL = sr.LoadBoolean("BruteForceDTL") ?? false; createEACLOG = sr.LoadBoolean("CreateEACLOG") ?? createEACLOG; detectHDCD = sr.LoadBoolean("DetectHDCD") ?? true; wait750FramesForHDCD = sr.LoadBoolean("Wait750FramesForHDCD") ?? true; decodeHDCD = sr.LoadBoolean("DecodeHDCD") ?? false; createM3U = sr.LoadBoolean("CreateM3U") ?? false; createCUEFileWhenEmbedded = sr.LoadBoolean("CreateCUEFileWhenEmbedded") ?? true; truncate4608ExtraSamples = sr.LoadBoolean("Truncate4608ExtraSamples") ?? true; decodeHDCDtoLW16 = sr.LoadBoolean("DecodeHDCDToLossyWAV16") ?? false; decodeHDCDto24bit = sr.LoadBoolean("DecodeHDCDTo24bit") ?? true; oneInstance = sr.LoadBoolean("OneInstance") ?? true; checkForUpdates = sr.LoadBoolean("CheckForUpdates") ?? true; writeBasicTagsFromCUEData = sr.LoadBoolean("WriteBasicTagsFromCUEData") ?? true; copyBasicTags = sr.LoadBoolean("CopyBasicTags") ?? true; copyUnknownTags = sr.LoadBoolean("CopyUnknownTags") ?? true; CopyAlbumArt = sr.LoadBoolean("CopyAlbumArt") ?? true; embedAlbumArt = sr.LoadBoolean("EmbedAlbumArt") ?? true; extractAlbumArt = sr.LoadBoolean("ExtractAlbumArt") ?? true; maxAlbumArtSize = sr.LoadInt32("MaxAlbumArtSize", 100, 10000) ?? maxAlbumArtSize; arLogToSourceFolder = sr.LoadBoolean("ArLogToSourceFolder") ?? arLogToSourceFolder; arLogVerbose = sr.LoadBoolean("ArLogVerbose") ?? arLogVerbose; fixOffsetToNearest = sr.LoadBoolean("FixOffsetToNearest") ?? fixOffsetToNearest; ArLogFilenameFormat = sr.Load("ArLogFilenameFormat") ?? ArLogFilenameFormat; AlArtFilenameFormat = sr.Load("AlArtFilenameFormat") ?? AlArtFilenameFormat; separateDecodingThread = sr.LoadBoolean("SeparateDecodingThread") ?? separateDecodingThread; var jsonConfig = sr.Load("Advanced"); if (jsonConfig != null) { var backup = advanced; try { var jsonObject = JsonConvert.DeserializeObject(jsonConfig, typeof(CUEConfigAdvanced), new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate, TypeNameHandling = TypeNameHandling.Auto, Error = (sender, ev) => { System.Diagnostics.Trace.WriteLine(ev.ErrorContext.Error.ToString()); ev.ErrorContext.Handled = true; } }); if (jsonObject as CUEConfigAdvanced == null) { throw new Exception(); } advanced = jsonObject as CUEConfigAdvanced; // Add missing codecs backup.encoders.Where(x => advanced.encoders .FindAll(y => y.Extension == x.Extension && y.Lossless == x.Lossless && y.Name == x.Name).Count == 0) .ToList().ForEach(x => advanced.encoders.Add(x)); backup.decoders.Where(x => advanced.decoders .FindAll(y => y.Extension == x.Extension && y.Name == x.Name).Count == 0) .ToList().ForEach(x => advanced.decoders.Add(x)); // Reset the ViewModel advanced.encodersViewModel = new EncoderListViewModel(advanced.encoders); advanced.decodersViewModel = new DecoderListViewModel(advanced.decoders); // Reset the links in formats foreach (var extension in formats.Keys) { var format = formats[extension]; AudioEncoderSettingsViewModel encoderLossless, encoderLossy; AudioDecoderSettingsViewModel decoder; if (format.encoderLossless == null || !Encoders.TryGetValue(extension, true, format.encoderLossless.Name, out encoderLossless)) { encoderLossless = Encoders.GetDefault(extension, true); } if (format.encoderLossy == null || !Encoders.TryGetValue(extension, false, format.encoderLossy.Name, out encoderLossy)) { encoderLossy = Encoders.GetDefault(extension, false); } if (format.decoder == null || !Decoders.TryGetValue(extension, format.decoder.Name, out decoder)) { decoder = Decoders.GetDefault(extension); } format.encoderLossless = encoderLossless; format.encoderLossy = encoderLossy; format.decoder = decoder; } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); advanced = backup; } } int totalFormats = sr.LoadInt32("CustomFormats", 0, null) ?? 0; for (int nFormats = 0; nFormats < totalFormats; nFormats++) { string extension = sr.Load(string.Format("CustomFormat{0}Name", nFormats)); string encoderLossless = sr.Load(string.Format("CustomFormat{0}EncoderLossless", nFormats)) ?? ""; string encoderLossy = sr.Load(string.Format("CustomFormat{0}EncoderLossy", nFormats)) ?? ""; string decoder = sr.Load(string.Format("CustomFormat{0}Decoder", nFormats)); CUEToolsTagger tagger = (CUEToolsTagger)(sr.LoadInt32(string.Format("CustomFormat{0}Tagger", nFormats), 0, 2) ?? 0); bool allowLossless = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossless", nFormats)) ?? false; bool allowLossy = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossy", nFormats)) ?? false; bool allowEmbed = sr.LoadBoolean(string.Format("CustomFormat{0}AllowEmbed", nFormats)) ?? false; CUEToolsFormat format; AudioEncoderSettingsViewModel udcLossless, udcLossy; AudioDecoderSettingsViewModel udcDecoder; if (encoderLossless == "" || !Encoders.TryGetValue(extension, true, encoderLossless, out udcLossless)) { udcLossless = Encoders.GetDefault(extension, true); } if (encoderLossy == "" || !Encoders.TryGetValue(extension, false, encoderLossy, out udcLossy)) { udcLossy = Encoders.GetDefault(extension, false); } if (decoder == "" || !Decoders.TryGetValue(extension, decoder, out udcDecoder)) { udcDecoder = Decoders.GetDefault(extension); } if (!formats.TryGetValue(extension, out format)) { formats.Add(extension, new CUEToolsFormat(extension, tagger, allowLossless, allowLossy, allowEmbed, false, udcLossless, udcLossy, udcDecoder)); } else { format.encoderLossless = udcLossless; format.encoderLossy = udcLossy; format.decoder = udcDecoder; if (!format.builtin) { format.tagger = tagger; format.allowLossless = allowLossless; format.allowLossy = allowLossy; format.allowEmbed = allowEmbed; } } } defaultVerifyScript = sr.Load("DefaultVerifyScript") ?? "default"; defaultEncodeScript = sr.Load("DefaultVerifyAndConvertScript") ?? "default"; gapsHandling = (CUEStyle?)sr.LoadInt32("GapsHandling", null, null) ?? gapsHandling; language = sr.Load("Language") ?? Thread.CurrentThread.CurrentUICulture.Name; if (ArLogFilenameFormat.Contains("%F")) { ArLogFilenameFormat = "%filename%.accurip"; } if (singleFilenameFormat.Contains("%F")) { singleFilenameFormat = "%filename%"; } if (trackFilenameFormat.Contains("%N")) { trackFilenameFormat = "%tracknumber%. %title%"; } }
public CUEConfig() : base() { fixOffsetMinimumConfidence = 2; fixOffsetMinimumTracksPercent = 51; encodeWhenConfidence = 2; encodeWhenPercent = 100; encodeWhenZeroOffset = false; fixOffset = false; noUnverifiedOutput = false; writeArTagsOnEncode = false; writeArLogOnConvert = true; writeArTagsOnVerify = false; writeArLogOnVerify = false; autoCorrectFilenames = true; preserveHTOA = true; detectGaps = true; keepOriginalFilenames = false; trackFilenameFormat = "%tracknumber%. %title%"; singleFilenameFormat = "%filename%"; removeSpecial = false; specialExceptions = "-()"; replaceSpaces = false; embedLog = true; extractLog = true; fillUpCUE = true; overwriteCUEData = false; filenamesANSISafe = true; bruteForceDTL = false; createEACLOG = true; detectHDCD = true; wait750FramesForHDCD = true; decodeHDCD = false; createM3U = false; createCUEFileWhenEmbedded = true; truncate4608ExtraSamples = true; decodeHDCDtoLW16 = false; decodeHDCDto24bit = true; oneInstance = true; checkForUpdates = true; writeBasicTagsFromCUEData = true; copyBasicTags = true; copyUnknownTags = true; CopyAlbumArt = true; embedAlbumArt = true; extractAlbumArt = true; maxAlbumArtSize = 300; arLogToSourceFolder = false; arLogVerbose = true; fixOffsetToNearest = true; ArLogFilenameFormat = "%filename%.accurip"; AlArtFilenameFormat = "folder.jpg"; separateDecodingThread = true; gapsHandling = CUEStyle.GapsAppended; advanced = new CUEConfigAdvanced(); advanced.Init(); language = Thread.CurrentThread.CurrentUICulture.Name; scripts = new Dictionary <string, CUEToolsScript>(); scripts.Add("default", new CUEToolsScript("default", new CUEAction[] { CUEAction.Verify, CUEAction.Encode })); scripts.Add("only if found", new CUEToolsScript("only if found", new CUEAction[] { CUEAction.Verify })); scripts.Add("fix offset", new CUEToolsScript("fix offset", new CUEAction[] { CUEAction.Encode })); scripts.Add("encode if verified", new CUEToolsScript("encode if verified", new CUEAction[] { CUEAction.Encode })); scripts.Add("repair", new CUEToolsScript("repair", new CUEAction[] { CUEAction.Encode })); defaultVerifyScript = "default"; defaultEncodeScript = "default"; }
public CUEConfig(CUEConfig src) { fixOffsetMinimumConfidence = src.fixOffsetMinimumConfidence; fixOffsetMinimumTracksPercent = src.fixOffsetMinimumTracksPercent; encodeWhenConfidence = src.encodeWhenConfidence; encodeWhenPercent = src.encodeWhenPercent; encodeWhenZeroOffset = src.encodeWhenZeroOffset; fixOffset = src.fixOffset; noUnverifiedOutput = src.noUnverifiedOutput; writeArTagsOnEncode = src.writeArTagsOnEncode; writeArLogOnConvert = src.writeArLogOnConvert; writeArTagsOnVerify = src.writeArTagsOnVerify; writeArLogOnVerify = src.writeArLogOnVerify; autoCorrectFilenames = src.autoCorrectFilenames; preserveHTOA = src.preserveHTOA; detectGaps = src.detectGaps; keepOriginalFilenames = src.keepOriginalFilenames; trackFilenameFormat = src.trackFilenameFormat; singleFilenameFormat = src.singleFilenameFormat; removeSpecial = src.removeSpecial; specialExceptions = src.specialExceptions; replaceSpaces = src.replaceSpaces; embedLog = src.embedLog; extractLog = src.extractLog; fillUpCUE = src.fillUpCUE; overwriteCUEData = src.overwriteCUEData; filenamesANSISafe = src.filenamesANSISafe; bruteForceDTL = src.bruteForceDTL; createEACLOG = src.createEACLOG; detectHDCD = src.detectHDCD; wait750FramesForHDCD = src.wait750FramesForHDCD; decodeHDCD = src.decodeHDCD; createM3U = src.createM3U; createCUEFileWhenEmbedded = src.createCUEFileWhenEmbedded; truncate4608ExtraSamples = src.truncate4608ExtraSamples; decodeHDCDtoLW16 = src.decodeHDCDtoLW16; decodeHDCDto24bit = src.decodeHDCDto24bit; oneInstance = src.oneInstance; checkForUpdates = src.checkForUpdates; writeBasicTagsFromCUEData = src.writeBasicTagsFromCUEData; copyBasicTags = src.copyBasicTags; copyUnknownTags = src.copyUnknownTags; CopyAlbumArt = src.CopyAlbumArt; embedAlbumArt = src.embedAlbumArt; extractAlbumArt = src.extractAlbumArt; maxAlbumArtSize = src.maxAlbumArtSize; arLogToSourceFolder = src.arLogToSourceFolder; arLogVerbose = src.arLogVerbose; fixOffsetToNearest = src.fixOffsetToNearest; ArLogFilenameFormat = src.ArLogFilenameFormat; AlArtFilenameFormat = src.AlArtFilenameFormat; separateDecodingThread = src.separateDecodingThread; gapsHandling = src.gapsHandling; advanced = new CUEConfigAdvanced(src.advanced); language = src.language; scripts = new Dictionary <string, CUEToolsScript>(); scripts.Add("default", new CUEToolsScript("default", new CUEAction[] { CUEAction.Verify, CUEAction.Encode })); scripts.Add("only if found", new CUEToolsScript("only if found", new CUEAction[] { CUEAction.Verify })); scripts.Add("fix offset", new CUEToolsScript("fix offset", new CUEAction[] { CUEAction.Encode })); scripts.Add("encode if verified", new CUEToolsScript("encode if verified", new CUEAction[] { CUEAction.Encode })); scripts.Add("repair", new CUEToolsScript("repair", new CUEAction[] { CUEAction.Encode })); defaultVerifyScript = src.defaultVerifyScript; defaultEncodeScript = src.defaultEncodeScript; }
public void Load(SettingsReader sr) { int version = sr.LoadInt32("Version", null, null) ?? 202; fixOffsetMinimumConfidence = sr.LoadUInt32("ArFixWhenConfidence", 1, 1000) ?? 2; fixOffsetMinimumTracksPercent = sr.LoadUInt32("ArFixWhenPercent", 1, 100) ?? 51; encodeWhenConfidence = sr.LoadUInt32("ArEncodeWhenConfidence", 1, 1000) ?? 2; encodeWhenPercent = sr.LoadUInt32("ArEncodeWhenPercent", 1, 100) ?? 100; encodeWhenZeroOffset = sr.LoadBoolean("ArEncodeWhenZeroOffset") ?? false; noUnverifiedOutput = sr.LoadBoolean("ArNoUnverifiedOutput") ?? false; fixOffset = sr.LoadBoolean("ArFixOffset") ?? false; writeArTagsOnEncode = sr.LoadBoolean("ArWriteCRC") ?? writeArTagsOnEncode; writeArLogOnConvert = sr.LoadBoolean("ArWriteLog") ?? true; writeArTagsOnVerify = sr.LoadBoolean("ArWriteTagsOnVerify") ?? false; writeArLogOnVerify = sr.LoadBoolean("ArWriteLogOnVerify") ?? false; preserveHTOA = sr.LoadBoolean("PreserveHTOA") ?? true; detectGaps = sr.LoadBoolean("DetectGaps") ?? true; autoCorrectFilenames = sr.LoadBoolean("AutoCorrectFilenames") ?? true; keepOriginalFilenames = sr.LoadBoolean("KeepOriginalFilenames") ?? false; singleFilenameFormat = sr.Load("SingleFilenameFormat") ?? singleFilenameFormat; trackFilenameFormat = sr.Load("TrackFilenameFormat") ?? trackFilenameFormat; removeSpecial = sr.LoadBoolean("RemoveSpecialCharacters") ?? false; specialExceptions = sr.Load("SpecialCharactersExceptions") ?? "-()"; replaceSpaces = sr.LoadBoolean("ReplaceSpaces") ?? false; embedLog = sr.LoadBoolean("EmbedLog") ?? true; extractLog = sr.LoadBoolean("ExtractLog") ?? true; fillUpCUE = sr.LoadBoolean("FillUpCUE") ?? true; overwriteCUEData = sr.LoadBoolean("OverwriteCUEData") ?? false; filenamesANSISafe = sr.LoadBoolean("FilenamesANSISafe") ?? true; bruteForceDTL = sr.LoadBoolean("BruteForceDTL") ?? false; createEACLOG = sr.LoadBoolean("CreateEACLOG") ?? createEACLOG; detectHDCD = sr.LoadBoolean("DetectHDCD") ?? true; wait750FramesForHDCD = sr.LoadBoolean("Wait750FramesForHDCD") ?? true; decodeHDCD = sr.LoadBoolean("DecodeHDCD") ?? false; createM3U = sr.LoadBoolean("CreateM3U") ?? false; createCUEFileWhenEmbedded = sr.LoadBoolean("CreateCUEFileWhenEmbedded") ?? true; truncate4608ExtraSamples = sr.LoadBoolean("Truncate4608ExtraSamples") ?? true; decodeHDCDtoLW16 = sr.LoadBoolean("DecodeHDCDToLossyWAV16") ?? false; decodeHDCDto24bit = sr.LoadBoolean("DecodeHDCDTo24bit") ?? true; oneInstance = sr.LoadBoolean("OneInstance") ?? true; checkForUpdates = sr.LoadBoolean("CheckForUpdates") ?? true; writeBasicTagsFromCUEData = sr.LoadBoolean("WriteBasicTagsFromCUEData") ?? true; copyBasicTags = sr.LoadBoolean("CopyBasicTags") ?? true; copyUnknownTags = sr.LoadBoolean("CopyUnknownTags") ?? true; CopyAlbumArt = sr.LoadBoolean("CopyAlbumArt") ?? true; embedAlbumArt = sr.LoadBoolean("EmbedAlbumArt") ?? true; extractAlbumArt = sr.LoadBoolean("ExtractAlbumArt") ?? true; maxAlbumArtSize = sr.LoadInt32("MaxAlbumArtSize", 100, 10000) ?? maxAlbumArtSize; arLogToSourceFolder = sr.LoadBoolean("ArLogToSourceFolder") ?? arLogToSourceFolder; arLogVerbose = sr.LoadBoolean("ArLogVerbose") ?? arLogVerbose; fixOffsetToNearest = sr.LoadBoolean("FixOffsetToNearest") ?? fixOffsetToNearest; ArLogFilenameFormat = sr.Load("ArLogFilenameFormat") ?? ArLogFilenameFormat; AlArtFilenameFormat = sr.Load("AlArtFilenameFormat") ?? AlArtFilenameFormat; separateDecodingThread = sr.LoadBoolean("SeparateDecodingThread") ?? separateDecodingThread; try { using (TextReader reader = new StringReader(sr.Load("Advanced"))) advanced = CUEConfigAdvanced.serializer.Deserialize(reader) as CUEConfigAdvanced; } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } int totalEncoders = sr.LoadInt32("ExternalEncoders", 0, null) ?? 0; for (int nEncoders = 0; nEncoders < totalEncoders; nEncoders++) { string name = sr.Load(string.Format("ExternalEncoder{0}Name", nEncoders)); string extension = sr.Load(string.Format("ExternalEncoder{0}Extension", nEncoders)); string settings = sr.Load(string.Format("ExternalEncoder{0}Settings", nEncoders)); bool lossless = sr.LoadBoolean(string.Format("ExternalEncoder{0}Lossless", nEncoders)) ?? true; CUEToolsUDC encoder; if (name == null || extension == null) { continue; } if (!encoders.TryGetValue(extension, lossless, name, out encoder)) { encoder = new CUEToolsUDC(name, extension, lossless, "", "", "", ""); encoders.Add(encoder); } try { using (TextReader reader = new StringReader(settings)) encoder.settings = encoder.settingsSerializer.Deserialize(reader) as AudioEncoderSettings; if (encoder.settings is UserDefinedEncoderSettings && (encoder.settings as UserDefinedEncoderSettings).Path == "") { throw new Exception(); } } catch { if (version == 203 && encoder.settings is UserDefinedEncoderSettings) { (encoder.settings as UserDefinedEncoderSettings).SupportedModes = sr.Load(string.Format("ExternalEncoder{0}Modes", nEncoders)); (encoder.settings as UserDefinedEncoderSettings).EncoderMode = sr.Load(string.Format("ExternalEncoder{0}Mode", nEncoders)); (encoder.settings as UserDefinedEncoderSettings).Path = sr.Load(string.Format("ExternalEncoder{0}Path", nEncoders)); (encoder.settings as UserDefinedEncoderSettings).Parameters = sr.Load(string.Format("ExternalEncoder{0}Parameters", nEncoders)); } else { encoders.Remove(encoder); } } } int totalDecoders = sr.LoadInt32("ExternalDecoders", 0, null) ?? 0; for (int nDecoders = 0; nDecoders < totalDecoders; nDecoders++) { string name = sr.Load(string.Format("ExternalDecoder{0}Name", nDecoders)); string extension = sr.Load(string.Format("ExternalDecoder{0}Extension", nDecoders)); string path = sr.Load(string.Format("ExternalDecoder{0}Path", nDecoders)); string parameters = sr.Load(string.Format("ExternalDecoder{0}Parameters", nDecoders)); CUEToolsUDC decoder; if (!decoders.TryGetValue(extension, true, name, out decoder)) { decoders.Add(new CUEToolsUDC(name, extension, path, parameters)); } else { decoder.extension = extension; decoder.path = path; decoder.parameters = parameters; } } int totalFormats = sr.LoadInt32("CustomFormats", 0, null) ?? 0; for (int nFormats = 0; nFormats < totalFormats; nFormats++) { string extension = sr.Load(string.Format("CustomFormat{0}Name", nFormats)); string encoderLossless = sr.Load(string.Format("CustomFormat{0}EncoderLossless", nFormats)) ?? ""; string encoderLossy = sr.Load(string.Format("CustomFormat{0}EncoderLossy", nFormats)) ?? ""; string decoder = sr.Load(string.Format("CustomFormat{0}Decoder", nFormats)); CUEToolsTagger tagger = (CUEToolsTagger)(sr.LoadInt32(string.Format("CustomFormat{0}Tagger", nFormats), 0, 2) ?? 0); bool allowLossless = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossless", nFormats)) ?? false; bool allowLossy = sr.LoadBoolean(string.Format("CustomFormat{0}AllowLossy", nFormats)) ?? false; bool allowEmbed = sr.LoadBoolean(string.Format("CustomFormat{0}AllowEmbed", nFormats)) ?? false; CUEToolsFormat format; CUEToolsUDC udcLossless, udcLossy, udcDecoder; if (encoderLossless == "" || !encoders.TryGetValue(extension, true, encoderLossless, out udcLossless)) { udcLossless = encoders.GetDefault(extension, true); } if (encoderLossy == "" || !encoders.TryGetValue(extension, false, encoderLossy, out udcLossy)) { udcLossy = encoders.GetDefault(extension, false); } if (decoder == "" || !decoders.TryGetValue(extension, true, decoder, out udcDecoder)) { udcDecoder = decoders.GetDefault(extension, true); } if (!formats.TryGetValue(extension, out format)) { formats.Add(extension, new CUEToolsFormat(extension, tagger, allowLossless, allowLossy, allowEmbed, false, udcLossless, udcLossy, udcDecoder)); } else { format.encoderLossless = udcLossless; format.encoderLossy = udcLossy; format.decoder = udcDecoder; if (!format.builtin) { format.tagger = tagger; format.allowLossless = allowLossless; format.allowLossy = allowLossy; format.allowEmbed = allowEmbed; } } } defaultVerifyScript = sr.Load("DefaultVerifyScript") ?? "default"; defaultEncodeScript = sr.Load("DefaultVerifyAndConvertScript") ?? "default"; gapsHandling = (CUEStyle?)sr.LoadInt32("GapsHandling", null, null) ?? gapsHandling; language = sr.Load("Language") ?? Thread.CurrentThread.CurrentUICulture.Name; if (ArLogFilenameFormat.Contains("%F")) { ArLogFilenameFormat = "%filename%.accurip"; } if (singleFilenameFormat.Contains("%F")) { singleFilenameFormat = "%filename%"; } if (trackFilenameFormat.Contains("%N")) { trackFilenameFormat = "%tracknumber%. %title%"; } }
private int[] CalculateAudioFileLengths(CUEStyle style) { int iTrack, iIndex, iFile; TrackInfo track; int[] fileLengths; bool htoaToFile = ((style == CUEStyle.GapsAppended) && _preserveHTOA && (_tracks[0].IndexLengths[0] != 0)); bool discardOutput; if (style == CUEStyle.SingleFile) { fileLengths = new int[1]; iFile = 0; } else { fileLengths = new int[TrackCount + (htoaToFile ? 1 : 0)]; iFile = -1; } for (iTrack = 0; iTrack < TrackCount; iTrack++) { track = _tracks[iTrack]; if ((style == CUEStyle.GapsPrepended) || (style == CUEStyle.GapsLeftOut)) { iFile++; } for (iIndex = 0; iIndex <= track.LastIndex; iIndex++) { if ((style == CUEStyle.GapsAppended) && (iIndex == 1)) { iFile++; } if ((style == CUEStyle.GapsAppended) && (iIndex == 0) && (iTrack == 0)) { discardOutput = !htoaToFile; if (htoaToFile) { iFile++; } } else if ((style == CUEStyle.GapsLeftOut) && (iIndex == 0)) { discardOutput = true; } else { discardOutput = false; } if (!discardOutput) { fileLengths[iFile] += track.IndexLengths[iIndex] * 588; } } } return(fileLengths); }
public void WriteAudioFiles(string dir, CUEStyle style, SetStatus statusDel) { const int buffLen = 16384; int iTrack, iIndex, iSource, iDest, i, j, samplesRemIndex, samplesRemSource, copyCount; string[] destPaths; int[] destLengths; byte[] buff = new byte[buffLen * 2 * 2]; TrackInfo track; IAudioSource audioSource = null; IAudioDest audioDest = null; bool htoaToFile = ((style == CUEStyle.GapsAppended) && _preserveHTOA && (_tracks[0].IndexLengths[0] != 0)); bool discardOutput; if (_usePregapForFirstTrackInSingleFile) { throw new Exception("UsePregapForFirstTrackInSingleFile is not supported for writing audio files."); } if (style == CUEStyle.SingleFile) { destPaths = new string[1]; destPaths[0] = Path.Combine(dir, _singleFilename); } else { destPaths = new string[TrackCount + (htoaToFile ? 1 : 0)]; if (htoaToFile) { destPaths[0] = Path.Combine(dir, _htoaFilename); } for (i = 0; i < TrackCount; i++) { destPaths[i + (htoaToFile ? 1 : 0)] = Path.Combine(dir, _trackFilenames[i]); } } for (i = 0; i < destPaths.Length; i++) { for (j = 0; j < _sourcePaths.Count; j++) { if (destPaths[i].ToLower() == _sourcePaths[j].ToLower()) { throw new Exception("Source and destination audio file paths cannot be the same."); } } } if (_writeOffset != 0) { int absOffset = Math.Abs(_writeOffset); SourceInfo sourceInfo; sourceInfo.Path = null; sourceInfo.Offset = 0; sourceInfo.Length = absOffset; if (_writeOffset < 0) { _sources.Insert(0, sourceInfo); int last = _sources.Count - 1; while (absOffset >= _sources[last].Length) { absOffset -= _sources[last].Length; _sources.RemoveAt(last--); } sourceInfo = _sources[last]; sourceInfo.Length -= absOffset; _sources[last] = sourceInfo; } else { _sources.Add(sourceInfo); while (absOffset >= _sources[0].Length) { absOffset -= _sources[0].Length; _sources.RemoveAt(0); } sourceInfo = _sources[0]; sourceInfo.Offset += absOffset; sourceInfo.Length -= absOffset; _sources[0] = sourceInfo; } _appliedWriteOffset = true; } destLengths = CalculateAudioFileLengths(style); iSource = -1; iDest = -1; samplesRemSource = 0; if (style == CUEStyle.SingleFile) { iDest++; audioDest = GetAudioDest(destPaths[iDest], destLengths[iDest]); } for (iTrack = 0; iTrack < TrackCount; iTrack++) { statusDel(String.Format("Writing track {0:00}...", iTrack + 1)); track = _tracks[iTrack]; if ((style == CUEStyle.GapsPrepended) || (style == CUEStyle.GapsLeftOut)) { if (audioDest != null) { audioDest.Close(); } iDest++; audioDest = GetAudioDest(destPaths[iDest], destLengths[iDest]); } for (iIndex = 0; iIndex <= track.LastIndex; iIndex++) { if ((style == CUEStyle.GapsAppended) && (iIndex == 1)) { if (audioDest != null) { audioDest.Close(); } iDest++; audioDest = GetAudioDest(destPaths[iDest], destLengths[iDest]); } samplesRemIndex = track.IndexLengths[iIndex] * 588; if ((style == CUEStyle.GapsAppended) && (iIndex == 0) && (iTrack == 0)) { discardOutput = !htoaToFile; if (htoaToFile) { iDest++; audioDest = GetAudioDest(destPaths[iDest], destLengths[iDest]); } } else if ((style == CUEStyle.GapsLeftOut) && (iIndex == 0)) { discardOutput = true; } else { discardOutput = false; } while (samplesRemIndex != 0) { if (samplesRemSource == 0) { if (audioSource != null) { audioSource.Close(); } audioSource = GetAudioSource(++iSource); samplesRemSource = _sources[iSource].Length; } copyCount = Math.Min(Math.Min(samplesRemIndex, samplesRemSource), buffLen); audioSource.Read(buff, copyCount); if (!discardOutput) { audioDest.Write(buff, copyCount); } samplesRemIndex -= copyCount; samplesRemSource -= copyCount; lock (this) { if (_stop) { audioSource.Close(); try { audioDest.Close(); } catch {} throw new StopException(); } } } } } if (audioSource != null) { audioSource.Close(); } audioDest.Close(); }
public void Write(string path, CUEStyle style) { int i, iTrack, iIndex, timeRelativeToFileStart; TrackInfo track; bool htoaToFile = ((style == CUEStyle.GapsAppended) && _preserveHTOA && (_tracks[0].IndexLengths[0] != 0)); timeRelativeToFileStart = 0; using (StreamWriter sw = new StreamWriter(path, false, CUESheet.Encoding)) { for (i = 0; i < _attributes.Count; i++) { WriteLine(sw, 0, _attributes[i]); } if (style == CUEStyle.SingleFile) { WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _singleFilename)); } if (htoaToFile) { WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _htoaFilename)); } for (iTrack = 0; iTrack < TrackCount; iTrack++) { track = _tracks[iTrack]; if ((style == CUEStyle.GapsPrepended) || (style == CUEStyle.GapsLeftOut) || ((style == CUEStyle.GapsAppended) && ((track.IndexLengths[0] == 0) || ((iTrack == 0) && !htoaToFile)))) { WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _trackFilenames[iTrack])); timeRelativeToFileStart = 0; } WriteLine(sw, 1, String.Format("TRACK {0:00} AUDIO", iTrack + 1)); for (i = 0; i < track.Attributes.Count; i++) { WriteLine(sw, 2, track.Attributes[i]); } for (iIndex = 0; iIndex <= track.LastIndex; iIndex++) { if (track.IndexLengths[iIndex] != 0) { if ((iIndex == 0) && ((style == CUEStyle.GapsLeftOut) || ((style == CUEStyle.GapsAppended) && (iTrack == 0) && !htoaToFile) || ((style == CUEStyle.SingleFile) && (iTrack == 0) && _usePregapForFirstTrackInSingleFile))) { WriteLine(sw, 2, "PREGAP " + General.TimeToString(track.IndexLengths[iIndex])); } else { WriteLine(sw, 2, String.Format("INDEX {0:00} {1}", iIndex, General.TimeToString(timeRelativeToFileStart))); timeRelativeToFileStart += track.IndexLengths[iIndex]; if ((style == CUEStyle.GapsAppended) && (iIndex == 0)) { WriteLine(sw, 0, String.Format("FILE \"{0}\" WAVE", _trackFilenames[iTrack])); timeRelativeToFileStart = 0; } } } } } } }