示例#1
0
        public static CUEToolsUDC GetEncoder(CUEToolsCodecsConfig config, CUEToolsFormat fmt, bool lossless, string chosenEncoder)
        {
            CUEToolsUDC tmpEncoder;

            return(chosenEncoder != null ?
                   (config.encoders.TryGetValue(fmt.extension, lossless, chosenEncoder, out tmpEncoder) ? tmpEncoder : null) :
                   (lossless ? fmt.encoderLossless : fmt.encoderLossy));
        }
示例#2
0
        public static AudioEncoderSettingsViewModel GetEncoder(CUEToolsCodecsConfig config, CUEToolsFormat fmt, bool lossless, string chosenEncoder)
        {
            AudioEncoderSettingsViewModel tmpEncoder;

            return(chosenEncoder != null ?
                   (config.encodersViewModel.TryGetValue(fmt.extension, lossless, chosenEncoder, out tmpEncoder) ? tmpEncoder : null) :
                   (lossless ? fmt.encoderLossless : fmt.encoderLossy));
        }
示例#3
0
        public static IAudioSource GetAudioSource(CUEToolsCodecsConfig config, string path, string chosenDecoder, bool ignore_chunk_sizes)
        {
            if (path == "-")
            {
                return(new WAVReader("", Console.OpenStandardInput(), ignore_chunk_sizes));
            }
            string extension = Path.GetExtension(path).ToLower();
            Stream IO        = null;

            if (extension == ".bin")
            {
                return(new WAVReader(path, IO, AudioPCMConfig.RedBook));
            }
            CUEToolsFormat fmt;

            if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
            {
                throw new Exception("Unsupported audio type: " + path);
            }

            var decoder = fmt.decoder;

            if (chosenDecoder != null && !config.decoders.TryGetValue(fmt.extension, true, chosenDecoder, out decoder))
            {
                throw new Exception("Unknown audio decoder " + chosenDecoder + " or unsupported audio type " + fmt.extension);
            }
            if (decoder == null)
            {
                throw new Exception("Unsupported audio type: " + path);
            }
            if (decoder.path != null)
            {
                return(new UserDefinedReader(path, IO, decoder.path, decoder.parameters));
            }
            if (decoder.type == null)
            {
                throw new Exception("Unsupported audio type: " + path);
            }

            try
            {
                object src = Activator.CreateInstance(decoder.type, path, IO);
                if (src == null || !(src is IAudioSource))
                {
                    throw new Exception("Unsupported audio type: " + path + ": " + decoder.type.FullName);
                }
                return(src as IAudioSource);
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                if (ex.InnerException == null)
                {
                    throw ex;
                }
                throw ex.InnerException;
            }
        }
示例#4
0
 public static void UpdateTags(string path, NameValueCollection tags, CUEToolsCodecsConfig config, bool useId3v24)
 {
     TagLib.UserDefined.AdditionalFileTypes.Config = config;
     TagLib.File fileInfo = TagLib.File.Create(new TagLib.File.LocalFileAbstraction(path));
     if (UpdateTags(fileInfo, tags, config, useId3v24))
     {
         fileInfo.Save();
     }
     //IAudioSource audioSource = AudioReadWrite.GetAudioSource(path, null, config);
     //audioSource.Tags = tags;
     //audioSource.UpdateTags(false);
     //audioSource.Close();
     //audioSource = null;
 }
示例#5
0
        public CUEToolsFormat Clone(CUEToolsCodecsConfig cfg)
        {
            var res = this.MemberwiseClone() as CUEToolsFormat;

            if (decoder != null)
            {
                cfg.decodersViewModel.TryGetValue(decoder.Settings.Extension, decoder.Settings.Name, out res.decoder);
            }
            if (encoderLossy != null)
            {
                cfg.encodersViewModel.TryGetValue(encoderLossy.Settings.Extension, encoderLossy.Lossless, encoderLossy.Settings.Name, out res.encoderLossy);
            }
            if (encoderLossless != null)
            {
                cfg.encodersViewModel.TryGetValue(encoderLossless.Settings.Extension, encoderLossless.Lossless, encoderLossless.Settings.Name, out res.encoderLossless);
            }
            return(res);
        }
示例#6
0
        public CUEToolsFormat Clone(CUEToolsCodecsConfig cfg)
        {
            var res = this.MemberwiseClone() as CUEToolsFormat;

            if (decoder != null)
            {
                cfg.decoders.TryGetValue(decoder.extension, decoder.lossless, decoder.name, out res.decoder);
            }
            if (encoderLossy != null)
            {
                cfg.encoders.TryGetValue(encoderLossy.extension, encoderLossy.lossless, encoderLossy.name, out res.encoderLossy);
            }
            if (encoderLossless != null)
            {
                cfg.encoders.TryGetValue(encoderLossless.extension, encoderLossless.lossless, encoderLossless.name, out res.encoderLossless);
            }
            return(res);
        }
示例#7
0
        public static IAudioSource GetAudioSource(CUEToolsCodecsConfig config, string path, string chosenDecoder, bool ignore_chunk_sizes, Dictionary <string, string> decoderOptions)
        {
            if (path == "-")
            {
                return(new Codecs.WAV.AudioDecoder(new Codecs.WAV.DecoderSettings()
                {
                    IgnoreChunkSizes = true
                }, "", Console.OpenStandardInput()));
            }
            string extension = Path.GetExtension(path).ToLower();
            Stream IO        = null;

            if (extension == ".bin")
            {
                return(new Codecs.WAV.AudioDecoder(new Codecs.WAV.DecoderSettings(), path, IO, AudioPCMConfig.RedBook));
            }
            CUEToolsFormat fmt;

            if (!extension.StartsWith(".") || !config.formats.TryGetValue(extension.Substring(1), out fmt))
            {
                throw new Exception("Unsupported audio type: " + path);
            }

            var decoder = fmt.decoder;

            if (chosenDecoder != null && !config.decodersViewModel.TryGetValue(fmt.extension, chosenDecoder, out decoder))
            {
                throw new Exception("Unknown audio decoder " + chosenDecoder + " or unsupported audio type " + fmt.extension);
            }
            if (decoder == null)
            {
                throw new Exception("Unsupported audio type: " + path);
            }
            var settings = decoder.Settings.Clone();

            foreach (var decOpt in decoderOptions)
            {
                var property = TypeDescriptor.GetProperties(settings).Find(decOpt.Key, true);
                if (property == null)
                {
                    throw new Exception($"{settings.Name} {settings.Extension} decoder settings object (of type {settings.GetType().FullName}) doesn't have a property named {decOpt.Key}.");
                }
                property.SetValue(settings,
                                  TypeDescriptor.GetConverter(property.PropertyType).ConvertFromString(decOpt.Value));
            }
            try
            {
                object src = Activator.CreateInstance(decoder.Settings.DecoderType, settings, path, IO);
                if (src == null || !(src is IAudioSource))
                {
                    throw new Exception("Unsupported audio type: " + path + ": " + decoder.Settings.DecoderType.FullName);
                }
                return(src as IAudioSource);
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                if (ex.InnerException == null)
                {
                    throw ex;
                }
                throw ex.InnerException;
            }
        }
示例#8
0
 public static bool UpdateTags(TagLib.File fileInfo, NameValueCollection tags, CUEToolsCodecsConfig config, bool useId3v24)
 {
     if (fileInfo is TagLib.Riff.File)
     {
         return(false);
     }
     TagLib.Ogg.XiphComment xiph = (TagLib.Ogg.XiphComment)fileInfo.GetTag(TagLib.TagTypes.Xiph);
     if (xiph != null)
     {
         foreach (string tag in tags.AllKeys)
         {
             xiph.SetField(tag, tags.GetValues(tag));
         }
         return(true);
     }
     if (fileInfo is TagLib.Mpeg4.File)
     {
         var mpeg4 = (TagLib.Mpeg4.AppleTag)fileInfo.GetTag(TagLib.TagTypes.Apple, true);
         foreach (string tag in tags.AllKeys)
         {
             mpeg4.SetDashBox("com.apple.iTunes", tag, string.Join(";", tags.GetValues(tag)));
         }
         return(true);
     }
     if (fileInfo is TagLib.Mpeg.AudioFile || (fileInfo is TagLib.UserDefined.File &&
                                               (fileInfo as TagLib.UserDefined.File).Tagger == CUEToolsTagger.ID3v2))
     {
         var id3v2 = (TagLib.Id3v2.Tag)fileInfo.GetTag(TagLib.TagTypes.Id3v2, true);
         id3v2.Version = (byte)(useId3v24 ? 4 : 3);
         foreach (string tag in tags.AllKeys)
         {
             var frame = TagLib.Id3v2.UserTextInformationFrame.Get(id3v2, tag, true);
             frame.Text = tags.GetValues(tag);
         }
         return(true);
     }
     if (fileInfo is TagLib.Asf.File)
     {
         var asf = (TagLib.Asf.Tag)fileInfo.GetTag(TagLib.TagTypes.Asf, true);
         foreach (string tag in tags.AllKeys)
         {
             asf.SetDescriptorStrings(tags.GetValues(tag), "foobar2000/" + tag);
         }
         return(true);
     }
     TagLib.Ape.Tag ape = (TagLib.Ape.Tag)fileInfo.GetTag(TagLib.TagTypes.Ape, true);
     if (ape != null)
     {
         foreach (string tag in tags.AllKeys)
         {
             ape.SetValue(tag, tags.GetValues(tag));
         }
     }
     return(true);
 }