// // File.cs: Provides tagging and properties support for WavPack files. // // Author: // Brian Nickel (brian.nickel@gmail.com) // // Original Source: // wvfile.cpp from libtunepimp // // Copyright (C) 2006-2007 Brian Nickel // Copyright (C) 2006 by Lukáš Lalinský (Original Implementation) // Copyright (C) 2004 by Allan Sandfeld Jensen (Original Implementation) // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License version // 2.1 as published by the Free Software Foundation. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA // using System; using TagLib; namespace TagLib.UserDefined { /// /// This class extends to /// provide tagging and properties support for user defined format files. /// /// /// A will be added automatically to /// any file that doesn't contain one. This change does not effect /// the file and can be reversed using the following method: /// file.RemoveTags (file.TagTypes & ~file.TagTypesOnDisk); /// [SupportedMimeType("taglib/misc", "misc")] public class File : TagLib.NonContainer.File { #region Private Fields private bool _supportsAPEv2 = true; #endregion #region Constructors /// /// Constructs and initializes a new instance of for a specified path in the local file /// system and specified read style. /// /// /// A object containing the path of the /// file to use in the new instance. /// /// /// A value specifying at what level /// of accuracy to read the media properties, or to ignore the properties. /// /// /// is . /// public File (string path, ReadStyle propertiesStyle, bool supportsAPEv2) : base (path, propertiesStyle) { _supportsAPEv2 = supportsAPEv2; } /// /// Constructs and initializes a new instance of for a specified path in the local file /// system with an average read style. /// /// /// A object containing the path of the /// file to use in the new instance. /// /// /// is . /// public File (string path, bool supportsAPEv2) : base (path) { _supportsAPEv2 = supportsAPEv2; } /// /// Constructs and initializes a new instance of for a specified file abstraction and /// specified read style. /// /// /// A object to use when /// reading from and writing to the file. /// /// /// A value specifying at what level /// of accuracy to read the media properties, or to ignore the properties. /// /// /// is . /// public File (File.IFileAbstraction abstraction, ReadStyle propertiesStyle, bool supportsAPEv2) : base (abstraction, propertiesStyle) { _supportsAPEv2 = supportsAPEv2; } /// /// Constructs and initializes a new instance of for a specified file abstraction with an /// average read style. /// /// /// A object to use when /// reading from and writing to the file. /// /// /// is . /// public File (File.IFileAbstraction abstraction, bool supportsAPEv2) : base (abstraction) { _supportsAPEv2 = supportsAPEv2; } #endregion #region Public Methods public bool SupportsAPEv2 { get { return _supportsAPEv2; } } /// /// Gets a tag of a specified type from the current instance, /// optionally creating a new tag if possible. /// /// /// A value indicating the /// type of tag to read. /// /// /// A value specifying whether or not to /// try and create the tag if one is not found. /// /// /// A object containing the tag that was /// found in or added to the current instance. If no /// matching tag was found and none was created, is returned. /// /// /// If a is added to the /// current instance, it will be placed at the start of the /// file. On the other hand, /// will be added to the end of /// the file. All other tag types will be ignored. /// public override TagLib.Tag GetTag (TagTypes type, bool create) { Tag t = (Tag as TagLib.NonContainer.Tag).GetTag (type); if (t != null || !create) return t; switch (type) { case TagTypes.Id3v1: return EndTag.AddTag (type, Tag); case TagTypes.Id3v2: return StartTag.AddTag (type, Tag); case TagTypes.Ape: return EndTag.AddTag (type, Tag); default: return null; } } #endregion #region Protected Methods /// /// Reads format specific information at the start of the /// file. /// /// /// A value containing the seek position /// at which the tags end and the media data begins. /// /// /// A value specifying at what level /// of accuracy to read the media properties, or to ignore the properties. /// protected override void ReadStart (long start, ReadStyle propertiesStyle) { } /// /// Reads format specific information at the end of the /// file. /// /// /// A value containing the seek position /// at which the media data ends and the tags begin. /// /// /// A value specifying at what level /// of accuracy to read the media properties, or to ignore the properties. /// protected override void ReadEnd (long end, ReadStyle propertiesStyle) { // Make sure we have an APE tag. if (_supportsAPEv2) GetTag (TagTypes.Ape, true); } /// /// Reads the audio properties from the file represented by /// the current instance. /// /// /// A value containing the seek position /// at which the tags end and the media data begins. /// /// /// A value containing the seek position /// at which the media data ends and the tags begin. /// /// /// A value specifying at what level /// of accuracy to read the media properties, or to ignore the properties. /// /// /// A object describing the /// media properties of the file represented by the current /// instance. /// protected override Properties ReadProperties (long start, long end, ReadStyle propertiesStyle) { return new Properties (); } #endregion } public static class AdditionalFileTypes { private static bool inited = false; private static CUETools.Processor.CUEConfig _config; public static CUETools.Processor.CUEConfig Config { set { Init(); _config = value; } } private static TagLib.File UserDefinedResolver(TagLib.File.IFileAbstraction abstraction, string mimetype, TagLib.ReadStyle style) { if (mimetype == "taglib/flac" || mimetype == "taglib/wv" || mimetype == "taglib/ape" || mimetype == "taglib/wav") return null; if (mimetype == "taglib/tta") return new File(abstraction, style, true); if (mimetype == "taglib/" + _config.udc1Extension) return new File(abstraction, style, _config.udc1APEv2); return null; } static AdditionalFileTypes () { Init(); } internal static void Init() { if (inited) return; TagLib.File.AddFileTypeResolver(new TagLib.File.FileTypeResolver(UserDefinedResolver)); //FileTypes.Register(typeof(TagLib.NonContainer.File)); inited = true; } } }