]> granicus.if.org Git - taglib/commitdiff
TrueAudio support.
authorLukáš Lalinský <lalinsky@gmail.com>
Sat, 10 Nov 2007 22:55:14 +0000 (22:55 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Sat, 10 Nov 2007 22:55:14 +0000 (22:55 +0000)
This is last of the three formats implemented for libtunepimp, now used also by various players.

BUG:114982

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@735116 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

15 files changed:
bindings/c/CMakeLists.txt
bindings/c/Makefile.am
bindings/c/tag_c.cpp
bindings/c/tag_c.h
taglib/CMakeLists.txt
taglib/Makefile.am
taglib/fileref.cpp
taglib/trueaudio/CMakeLists.txt [new file with mode: 0644]
taglib/trueaudio/Makefile.am [new file with mode: 0644]
taglib/trueaudio/trueaudiofile.cpp [new file with mode: 0644]
taglib/trueaudio/trueaudiofile.h [new file with mode: 0644]
taglib/trueaudio/trueaudioproperties.cpp [new file with mode: 0644]
taglib/trueaudio/trueaudioproperties.h [new file with mode: 0644]
tests/data/empty.tta [new file with mode: 0644]
tests/test_fileref.cpp

index 15c33487a4eb9efc94f6e35d3f7af1f01ed701e6..22fc0adb28489ae3503911a4abf588c9405ab8ae 100644 (file)
@@ -9,6 +9,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib
                     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpeg/id3v2
                     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/wavpack
                     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/speex
+                    ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/trueaudio
 )
 
 
index 5416d824af27473195ffe6fb32ebb625d60d242c..33176066f90355993cd38f7cbba13b050c9ec89c 100644 (file)
@@ -10,6 +10,7 @@ INCLUDES = \
        -I$(top_srcdir)/taglib/mpeg/id3v2 \
        -I$(top_srcdir)/taglib/wavpack \
        -I$(top_srcdir)/taglib/speex \
+       -I$(top_srcdir)/taglib/trueaudio \
        $(all_includes)
 
 lib_LTLIBRARIES = libtag_c.la
index fcb2dc312c625ed78d4b4171895d7bdf3f3e609c..abe5d615fe95d75c13b8edb40ed4d92b842f926b 100644 (file)
@@ -31,6 +31,7 @@
 #include <mpcfile.h>
 #include <wavpackfile.h>
 #include <speexfile.h>
+#include <trueaudiofile.h>
 #include <tag.h>
 #include <string.h>
 #include <id3v2framefactory.h>
@@ -77,6 +78,8 @@ TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type)
     return reinterpret_cast<TagLib_File *>(new WavPack::File(filename));
   case TagLib_File_Speex:
     return reinterpret_cast<TagLib_File *>(new Speex::File(filename));
+  case TagLib_File_TrueAudio:
+    return reinterpret_cast<TagLib_File *>(new TrueAudio::File(filename));
   }
 
   return 0;
index 54201710772a74dffc7c7796d74dc25c97cc719b..51ac192e3fe420915a07ca6524e467b0bc2fa1ea 100644 (file)
@@ -88,7 +88,8 @@ typedef enum {
   TagLib_File_MPC,
   TagLib_File_OggFlac,
   TagLib_File_WavPack,
-  TagLib_File_Speex
+  TagLib_File_Speex,
+  TagLib_File_TrueAudio
 } TagLib_File_Type;
 
 /*!
index 559fb9f5b9e6a4e97ae5ed427213aaf9a17effa2..9957458f399a37ba61908695258af98f17c5fb8f 100644 (file)
@@ -13,6 +13,7 @@ INCLUDE_DIRECTORIES(
     ${CMAKE_CURRENT_SOURCE_DIR}/ape
     ${CMAKE_CURRENT_SOURCE_DIR}/wavpack
     ${CMAKE_CURRENT_SOURCE_DIR}/speex
+    ${CMAKE_CURRENT_SOURCE_DIR}/trueaudio
     ${CMAKE_CURRENT_BINARY_DIR}/taglib
     ${CMAKE_CURRENT_BINARY_DIR}/..
 )
@@ -28,6 +29,7 @@ ADD_SUBDIRECTORY( ape )
 ADD_SUBDIRECTORY( mpc )
 ADD_SUBDIRECTORY( wavpack )
 ADD_SUBDIRECTORY( speex )
+ADD_SUBDIRECTORY( trueaudio )
 
 
 
@@ -110,6 +112,11 @@ speex/speexfile.cpp
 speex/speexproperties.cpp
 )
 
+SET(trueaudio_SRCS
+trueaudio/trueaudiofile.cpp
+trueaudio/trueaudioproperties.cpp
+)
+
 SET(toolkit_SRCS
 toolkit/tstring.cpp
 toolkit/tstringlist.cpp
@@ -122,7 +129,7 @@ toolkit/unicode.cpp
 
 SET(tag_LIB_SRCS ${mpeg_SRCS} ${id3v1_SRCS} ${id3v2_SRCS} ${frames_SRCS} ${ogg_SRCS}
                 ${vorbis_SRCS} ${oggflacs_SRCS} ${mpc_SRCS} ${ape_SRCS} ${toolkit_SRCS} ${flacs_SRCS}
-                ${wavpack_SRCS} ${speex_SRCS}
+                ${wavpack_SRCS} ${speex_SRCS} ${trueaudio_SRCS}
                 tag.cpp
                 fileref.cpp
                 audioproperties.cpp
index 7337eb3f840c9eed652977d4a96a19eb803ddff6..8d58ab8903cb4b938a70cee468c413d75dc9c3dd 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = toolkit mpeg ogg flac ape mpc wavpack speex
+SUBDIRS = toolkit mpeg ogg flac ape mpc wavpack speex trueaudio
 
 INCLUDES = \
        -I$(top_srcdir)/taglib \
@@ -11,6 +11,7 @@ INCLUDES = \
        -I$(top_srcdir)/taglib/ogg/vorbis \
        -I$(top_srcdir)/taglib/wavpack \
        -I$(top_srcdir)/taglib/speex \
+       -I$(top_srcdir)/taglib/trueaudio \
        $(all_includes)
 
 lib_LTLIBRARIES = libtag.la
@@ -21,4 +22,5 @@ taglib_includedir = $(includedir)/taglib
 
 libtag_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 5:0:4
 libtag_la_LIBADD = ./mpeg/libmpeg.la ./ogg/libogg.la ./flac/libflac.la ./mpc/libmpc.la \
-       ./ape/libape.la ./toolkit/libtoolkit.la ./wavpack/libwavpack.la ./speex/libspeex.la
+       ./ape/libape.la ./toolkit/libtoolkit.la ./wavpack/libwavpack.la ./speex/libspeex.la \
+       ./trueaudio/libtrueaudio.la
index a708d4ab4d783d8cf37ee038efeefcf1a8d0e9f9..4480cb1a1ac57f5e7e7d9101caee038d8ae781db 100644 (file)
@@ -34,6 +34,7 @@
 #include "mpcfile.h"
 #include "wavpackfile.h"
 #include "speexfile.h"
+#include "trueaudiofile.h"
 
 using namespace TagLib;
 
@@ -119,6 +120,7 @@ StringList FileRef::defaultFileExtensions()
   l.append("mpc");
   l.append("wv");
   l.append("spx");
+  l.append("tta");
 
   return l;
 }
@@ -194,7 +196,9 @@ File *FileRef::create(FileName fileName, bool readAudioProperties,
     if(s.substr(s.size() - 3, 3).upper() == ".WV")
       return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
     if(s.substr(s.size() - 4, 4).upper() == ".SPX")
-      return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
+      return new Speex::File(fileName, readAudioProperties, audioPropertiesStyle);
+    if(s.substr(s.size() - 4, 4).upper() == ".TTA")
+      return new TrueAudio::File(fileName, readAudioProperties, audioPropertiesStyle);
   }
 
   return 0;
diff --git a/taglib/trueaudio/CMakeLists.txt b/taglib/trueaudio/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3a1c3e7
--- /dev/null
@@ -0,0 +1 @@
+INSTALL( FILES  trueaudiofile.h trueaudioproperties.h DESTINATION ${INCLUDE_INSTALL_DIR}/taglib)
diff --git a/taglib/trueaudio/Makefile.am b/taglib/trueaudio/Makefile.am
new file mode 100644 (file)
index 0000000..7c64030
--- /dev/null
@@ -0,0 +1,14 @@
+INCLUDES = \
+       -I$(top_srcdir)/taglib \
+       -I$(top_srcdir)/taglib/toolkit \
+       -I$(top_srcdir)/taglib/mpc \
+       -I$(top_srcdir)/taglib/mpeg/id3v1 \
+       -I$(top_srcdir)/taglib/mpeg/id3v2 \
+       $(all_includes)
+
+noinst_LTLIBRARIES = libtrueaudio.la
+
+libtrueaudio_la_SOURCES = trueaudiofile.cpp trueaudioproperties.cpp
+
+taglib_include_HEADERS = trueaudiofile.h trueaudioproperties.h
+taglib_includedir = $(includedir)/taglib
diff --git a/taglib/trueaudio/trueaudiofile.cpp b/taglib/trueaudio/trueaudiofile.cpp
new file mode 100644 (file)
index 0000000..bcdfea1
--- /dev/null
@@ -0,0 +1,307 @@
+/***************************************************************************
+    copyright            : (C) 2006 by Lukáš Lalinský
+    email                : lalinsky@gmail.com
+    
+    copyright            : (C) 2004 by Allan Sandfeld Jensen
+    email                : kde@carewolf.org
+                           (original MPC 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                                                                   *
+ *                                                                         *
+ *   Alternatively, this file is available under the Mozilla Public        *
+ *   License Version 1.1.  You may obtain a copy of the License at         *
+ *   http://www.mozilla.org/MPL/                                           *
+ ***************************************************************************/
+
+#include <tbytevector.h>
+#include <tstring.h>
+#include <tdebug.h>
+
+#include "trueaudiofile.h"
+#include "id3v1tag.h"
+#include "id3v2tag.h"
+#include "id3v2header.h"
+#include "combinedtag.h"
+
+using namespace TagLib;
+
+class TrueAudio::File::FilePrivate
+{
+public:
+  FilePrivate(const ID3v2::FrameFactory *frameFactory = ID3v2::FrameFactory::instance()) :
+    ID3v2FrameFactory(frameFactory),
+    ID3v2Tag(0),
+    ID3v2Location(-1),
+    ID3v2OriginalSize(0), 
+    ID3v1Tag(0),
+    ID3v1Location(-1),
+    tag(0),
+    properties(0),
+    scanned(false),
+    hasID3v1(false),
+    hasID3v2(false) {}
+
+  ~FilePrivate()
+  {
+    if (tag != ID3v1Tag && tag != ID3v2Tag) delete tag;
+    delete ID3v1Tag;
+    delete ID3v2Tag;
+    delete properties;
+  }
+
+  const ID3v2::FrameFactory *ID3v2FrameFactory;
+  ID3v2::Tag *ID3v2Tag;
+  long ID3v2Location;
+  uint ID3v2OriginalSize; 
+
+  ID3v1::Tag *ID3v1Tag;
+  long ID3v1Location;
+
+  Tag *tag;
+
+  Properties *properties;
+  bool scanned;
+
+  // These indicate whether the file *on disk* has these tags, not if
+  // this data structure does.  This is used in computing offsets.
+
+  bool hasID3v1;
+  bool hasID3v2;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+TrueAudio::File::File(FileName file, bool readProperties,
+                 Properties::ReadStyle propertiesStyle) : TagLib::File(file)
+{
+  d = new FilePrivate;
+  if(isOpen())
+    read(readProperties, propertiesStyle);
+}
+
+TrueAudio::File::File(FileName file, ID3v2::FrameFactory *frameFactory,
+                 bool readProperties, Properties::ReadStyle propertiesStyle) :
+  TagLib::File(file)
+{
+  d = new FilePrivate(frameFactory);
+  if(isOpen())
+    read(readProperties, propertiesStyle);
+} 
+
+TrueAudio::File::~File()
+{
+  delete d;
+}
+
+TagLib::Tag *TrueAudio::File::tag() const
+{
+  return d->tag;
+}
+
+TrueAudio::Properties *TrueAudio::File::audioProperties() const
+{
+  return d->properties;
+}
+
+void TrueAudio::File::setID3v2FrameFactory(const ID3v2::FrameFactory *factory)
+{
+  d->ID3v2FrameFactory = factory;
+}
+bool TrueAudio::File::save()
+{
+  if(readOnly()) {
+    debug("TrueAudio::File::save() -- File is read only.");
+    return false;
+  }
+
+  // Update ID3v2 tag
+
+  if(d->ID3v2Tag) {
+    if(!d->hasID3v2) {
+      d->ID3v2Location = 0;
+      d->ID3v2OriginalSize = 0;
+    }
+    insert(d->ID3v2Tag->render(), d->ID3v2Location, d->ID3v2OriginalSize);
+    d->hasID3v2 = true;
+  }
+  else if(d->hasID3v2) {
+    removeBlock(d->ID3v2Location, d->ID3v2OriginalSize);
+    d->hasID3v2 = false;
+  }
+  
+  // Update ID3v1 tag
+
+  if(d->ID3v1Tag) {
+    if(!d->hasID3v1) {
+      seek(0, End);
+      d->ID3v1Location = tell();
+    }
+    else 
+      seek(d->ID3v1Location);
+    writeBlock(d->ID3v1Tag->render());
+    d->hasID3v1 = true;
+  }
+  else if(d->hasID3v1) {
+    removeBlock(d->ID3v1Location, 128);
+    d->hasID3v1 = false;
+  }
+
+  return true;
+}
+
+ID3v1::Tag *TrueAudio::File::ID3v1Tag(bool create)
+{
+  if(!create || d->ID3v1Tag)
+    return d->ID3v1Tag;
+
+  // no ID3v1 tag exists and we've been asked to create one
+
+  d->ID3v1Tag = new ID3v1::Tag;
+
+  if(d->ID3v2Tag)
+    d->tag = new CombinedTag(d->ID3v2Tag, d->ID3v1Tag);
+  else
+    d->tag = d->ID3v1Tag;
+
+  return d->ID3v1Tag;
+}
+
+ID3v2::Tag *TrueAudio::File::ID3v2Tag(bool create)
+{
+  if(!create || d->ID3v2Tag)
+    return d->ID3v2Tag;
+
+  // no ID3v2 tag exists and we've been asked to create one
+
+  d->ID3v2Tag = new ID3v2::Tag;
+
+  if(d->ID3v1Tag)
+    d->tag = new CombinedTag(d->ID3v2Tag, d->ID3v1Tag);
+  else
+    d->tag = d->ID3v2Tag;
+
+  return d->ID3v2Tag;
+}
+
+void TrueAudio::File::remove(int tags)
+{
+  if(tags & ID3v1) {
+    delete d->ID3v1Tag;
+    d->ID3v1Tag = 0;
+
+    if(d->ID3v2Tag)
+      d->tag = d->ID3v2Tag;
+    else
+      d->tag = d->ID3v2Tag = new ID3v2::Tag;
+  }
+
+  if(tags & ID3v2) {
+    delete d->ID3v2Tag;
+    d->ID3v2Tag = 0;
+    
+    if(d->ID3v1Tag)
+      d->tag = d->ID3v1Tag;
+    else
+      d->tag = d->ID3v2Tag = new ID3v2::Tag;
+  }
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// private members
+////////////////////////////////////////////////////////////////////////////////
+
+void TrueAudio::File::read(bool readProperties, Properties::ReadStyle /* propertiesStyle */)
+{
+  // Look for an ID3v2 tag
+
+  d->ID3v2Location = findID3v2();
+
+  if(d->ID3v2Location >= 0) {
+      
+    d->ID3v2Tag = new ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory);
+    
+    d->ID3v2OriginalSize = d->ID3v2Tag->header()->completeTagSize();
+    
+    if(d->ID3v2Tag->header()->tagSize() <= 0) {
+      delete d->ID3v2Tag;
+      d->ID3v2Tag = 0;
+    }
+    else
+      d->hasID3v2 = true; 
+  }
+
+  // Look for an ID3v1 tag
+
+  d->ID3v1Location = findID3v1();
+
+  if(d->ID3v1Location >= 0) {
+    d->ID3v1Tag = new ID3v1::Tag(this, d->ID3v1Location);
+    d->hasID3v1 = true;
+  }
+  
+  if(d->hasID3v1 && d->hasID3v2)
+    d->tag = new CombinedTag(d->ID3v2Tag, d->ID3v1Tag);
+  else {
+    if(d->hasID3v1)
+      d->tag = d->ID3v1Tag;
+    else {
+      if(d->hasID3v2)
+        d->tag = d->ID3v2Tag;
+      else
+        d->tag = d->ID3v2Tag = new ID3v2::Tag;
+    }
+  }
+
+  // Look for TrueAudio metadata
+
+  if(readProperties) {
+    seek(d->ID3v2Location + d->ID3v2OriginalSize);
+    d->properties = new Properties(readBlock(TrueAudio::HeaderSize),
+                                   length() - d->ID3v2OriginalSize);
+  }
+}
+
+long TrueAudio::File::findID3v1()
+{
+  if(!isValid())
+    return -1;
+
+  seek(-128, End);
+  long p = tell();
+
+  if(readBlock(3) == ID3v1::Tag::fileIdentifier())
+    return p;
+
+  return -1;
+}
+
+long TrueAudio::File::findID3v2()
+{
+  if(!isValid())
+    return -1;
+
+  seek(0);
+
+  if(readBlock(3) == ID3v2::Header::fileIdentifier())
+    return 0;
+  return -1;
+} 
diff --git a/taglib/trueaudio/trueaudiofile.h b/taglib/trueaudio/trueaudiofile.h
new file mode 100644 (file)
index 0000000..4e97655
--- /dev/null
@@ -0,0 +1,180 @@
+/***************************************************************************
+    copyright            : (C) 2006 by Lukáš Lalinský
+    email                : lalinsky@gmail.com
+    
+    copyright            : (C) 2004 by Allan Sandfeld Jensen
+    email                : kde@carewolf.org
+                           (original MPC 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                                                                   *
+ *                                                                         *
+ *   Alternatively, this file is available under the Mozilla Public        *
+ *   License Version 1.1.  You may obtain a copy of the License at         *
+ *   http://www.mozilla.org/MPL/                                           *
+ ***************************************************************************/
+
+#ifndef TAGLIB_TRUEAUDIOFILE_H
+#define TAGLIB_TRUEAUDIOFILE_H
+
+#include <tfile.h>
+#include "trueaudioproperties.h"
+
+namespace TagLib {
+
+  class Tag;
+
+  namespace ID3v2 { class Tag; class FrameFactory; }
+  namespace ID3v1 { class Tag; }
+
+  //! An implementation of TrueAudio metadata
+
+  /*!
+   * This is implementation of TrueAudio metadata.
+   *
+   * This supports ID3v1 and ID3v2 tags as well as reading stream
+   * properties from the file. 
+   */
+
+  namespace TrueAudio {
+
+    //! An implementation of TagLib::File with TrueAudio specific methods
+
+    /*!
+     * This implements and provides an interface for TrueAudio files to the
+     * TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
+     * the abstract TagLib::File API as well as providing some additional
+     * information specific to TrueAudio files.
+     */
+
+    class TAGLIB_EXPORT File : public TagLib::File
+    {
+    public:
+      /*!
+       * This set of flags is used for various operations and is suitable for
+       * being OR-ed together.
+       */
+      enum TagTypes {
+        //! Empty set.  Matches no tag types.
+        NoTags  = 0x0000,
+        //! Matches ID3v1 tags.
+        ID3v1   = 0x0001,
+        //! Matches ID3v2 tags.
+        ID3v2   = 0x0002,
+        //! Matches all tag types.
+        AllTags = 0xffff
+      };
+
+      /*!
+       * Contructs an TrueAudio file from \a file.  If \a readProperties is true the
+       * file's audio properties will also be read using \a propertiesStyle.  If
+       * false, \a propertiesStyle is ignored.
+       */
+      File(FileName file, bool readProperties = true,
+           Properties::ReadStyle propertiesStyle = Properties::Average);
+
+      /*!
+       * Contructs an TrueAudio file from \a file.  If \a readProperties is true the
+       * file's audio properties will also be read using \a propertiesStyle.  If
+       * false, \a propertiesStyle is ignored. The frames will be created using
+       * \a frameFactory. 
+       */
+      File(FileName file, ID3v2::FrameFactory *frameFactory,
+           bool readProperties = true,
+           Properties::ReadStyle propertiesStyle = Properties::Average);
+
+      /*!
+       * Destroys this instance of the File.
+       */
+      virtual ~File();
+
+      /*!
+       * Returns the Tag for this file.
+       */
+      virtual TagLib::Tag *tag() const;
+
+      /*!
+       * Returns the TrueAudio::Properties for this file.  If no audio properties
+       * were read then this will return a null pointer.
+       */
+      virtual Properties *audioProperties() const;
+
+      /*!
+       * Set the ID3v2::FrameFactory to something other than the default.
+       *
+       * \see ID3v2FrameFactory
+       */
+      void setID3v2FrameFactory(const ID3v2::FrameFactory *factory); 
+
+      /*!
+       * Saves the file.
+       */
+      virtual bool save();
+
+      /*!
+       * Returns a pointer to the ID3v2 tag of the file.
+       *
+       * If \a create is false (the default) this will return a null pointer
+       * if there is no valid ID3v2 tag.  If \a create is true it will create
+       * an ID3v1 tag if one does not exist. If there is already an APE tag, the
+       * new ID3v1 tag will be placed after it.
+       *
+       * \note The Tag <b>is still</b> owned by the TrueAudio::File and should not be
+       * deleted by the user.  It will be deleted when the file (object) is
+       * destroyed.
+       */
+      ID3v1::Tag *ID3v1Tag(bool create = false);
+
+      /*!
+       * Returns a pointer to the ID3v1 tag of the file.
+       *
+       * If \a create is false (the default) this will return a null pointer
+       * if there is no valid ID3v1 tag.  If \a create is true it will create
+       * an ID3v1 tag if one does not exist. If there is already an APE tag, the
+       * new ID3v1 tag will be placed after it.
+       *
+       * \note The Tag <b>is still</b> owned by the TrueAudio::File and should not be
+       * deleted by the user.  It will be deleted when the file (object) is
+       * destroyed.
+       */
+      ID3v2::Tag *ID3v2Tag(bool create = false);
+
+      /*!
+       * This will remove the tags that match the OR-ed together TagTypes from the
+       * file.  By default it removes all tags.
+       *
+       * \note This will also invalidate pointers to the tags
+       * as their memory will be freed.
+       * \note In order to make the removal permanent save() still needs to be called
+       */
+      void remove(int tags = AllTags);
+
+    private:
+      File(const File &);
+      File &operator=(const File &);
+
+      void read(bool readProperties, Properties::ReadStyle propertiesStyle);
+      void scan();
+      long findID3v1();
+      long findID3v2();
+
+      class FilePrivate;
+      FilePrivate *d;
+    };
+  }
+}
+
+#endif
diff --git a/taglib/trueaudio/trueaudioproperties.cpp b/taglib/trueaudio/trueaudioproperties.cpp
new file mode 100644 (file)
index 0000000..aaaa958
--- /dev/null
@@ -0,0 +1,136 @@
+/***************************************************************************
+    copyright            : (C) 2006 by Lukáš Lalinský
+    email                : lalinsky@gmail.com
+    
+    copyright            : (C) 2004 by Allan Sandfeld Jensen
+    email                : kde@carewolf.org
+                           (original MPC 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                                                                   *
+ *                                                                         *
+ *   Alternatively, this file is available under the Mozilla Public        *
+ *   License Version 1.1.  You may obtain a copy of the License at         *
+ *   http://www.mozilla.org/MPL/                                           *
+ ***************************************************************************/
+
+#include <tstring.h>
+#include <tdebug.h>
+#include <bitset>
+
+#include "trueaudioproperties.h"
+#include "trueaudiofile.h"
+
+using namespace TagLib;
+
+class TrueAudio::Properties::PropertiesPrivate
+{
+public:
+  PropertiesPrivate(const ByteVector &d, long length, ReadStyle s) :
+    data(d),
+    streamLength(length),
+    style(s),
+    version(0),
+    length(0),
+    bitrate(0),
+    sampleRate(0),
+    channels(0),
+    bitsPerSample(0) {}
+
+  ByteVector data;
+  long streamLength;
+  ReadStyle style;
+  int version;
+  int length;
+  int bitrate;
+  int sampleRate;
+  int channels;
+  int bitsPerSample;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+TrueAudio::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
+{
+  d = new PropertiesPrivate(data, streamLength, style);
+  read();
+}
+
+TrueAudio::Properties::~Properties()
+{
+  delete d;
+}
+
+int TrueAudio::Properties::length() const
+{
+  return d->length;
+}
+
+int TrueAudio::Properties::bitrate() const
+{
+  return d->bitrate;
+}
+
+int TrueAudio::Properties::sampleRate() const
+{
+  return d->sampleRate;
+}
+
+int TrueAudio::Properties::bitsPerSample() const
+{
+  return d->bitsPerSample;
+}
+
+int TrueAudio::Properties::channels() const
+{
+  return d->channels;
+}
+
+int TrueAudio::Properties::ttaVersion() const
+{
+  return d->version;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private members
+////////////////////////////////////////////////////////////////////////////////
+
+void TrueAudio::Properties::read()
+{
+  if(!d->data.startsWith("TrueAudio"))
+    return;
+
+  int pos = 3;
+
+  d->version = d->data[pos] - '0';
+  pos += 1 + 2;
+
+  d->channels = d->data.mid(pos, 2).toShort(false);
+  pos += 2;
+
+  d->bitsPerSample = d->data.mid(pos, 2).toShort(false);
+  pos += 2;
+
+  d->sampleRate = d->data.mid(pos, 4).toUInt(false);
+  pos += 4;
+
+  unsigned long samples = d->data.mid(pos, 4).toUInt(false);
+  d->length = samples / d->sampleRate;
+
+  d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
+}
diff --git a/taglib/trueaudio/trueaudioproperties.h b/taglib/trueaudio/trueaudioproperties.h
new file mode 100644 (file)
index 0000000..7c67bc1
--- /dev/null
@@ -0,0 +1,90 @@
+/***************************************************************************
+    copyright            : (C) 2006 by Lukáš Lalinský
+    email                : lalinsky@gmail.com
+    
+    copyright            : (C) 2004 by Allan Sandfeld Jensen
+    email                : kde@carewolf.org
+                           (original MPC 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                                                                   *
+ *                                                                         *
+ *   Alternatively, this file is available under the Mozilla Public        *
+ *   License Version 1.1.  You may obtain a copy of the License at         *
+ *   http://www.mozilla.org/MPL/                                           *
+ ***************************************************************************/
+
+#ifndef TAGLIB_TRUEAUDIOPROPERTIES_H
+#define TAGLIB_TRUEAUDIOPROPERTIES_H
+
+#include "audioproperties.h"
+
+namespace TagLib {
+
+  namespace TrueAudio {
+
+    class File;
+
+    static const uint HeaderSize = 18;
+
+    //! An implementation of audio property reading for TrueAudio
+
+    /*!
+     * This reads the data from an TrueAudio stream found in the AudioProperties
+     * API.
+     */
+
+    class TAGLIB_EXPORT Properties : public AudioProperties
+    {
+    public:
+      /*!
+       * Create an instance of TrueAudio::Properties with the data read from the
+       * ByteVector \a data.
+       */
+      Properties(const ByteVector &data, long streamLength, ReadStyle style = Average);
+
+      /*!
+       * Destroys this TrueAudio::Properties instance.
+       */
+      virtual ~Properties();
+
+      // Reimplementations.
+
+      virtual int length() const;
+      virtual int bitrate() const;
+      virtual int sampleRate() const;
+      virtual int channels() const;
+
+      /*!
+       * Returns number of bits per sample.
+       */
+      int bitsPerSample() const;
+
+      /*!
+       * Returns the major version number.
+       */
+      int ttaVersion() const;
+
+    private:
+      void read();
+
+      class PropertiesPrivate;
+      PropertiesPrivate *d;
+    };
+  }
+}
+
+#endif
diff --git a/tests/data/empty.tta b/tests/data/empty.tta
new file mode 100644 (file)
index 0000000..9cc00ba
Binary files /dev/null and b/tests/data/empty.tta differ
index c862cdd0b962e9ae975c61fe896b4cbe7a391655..0752c08a4383732e343fb08b44f1e4676d835907 100644 (file)
@@ -16,6 +16,7 @@ class TestFileRef : public CppUnit::TestFixture
   CPPUNIT_TEST(testSpeex);
   CPPUNIT_TEST(testFLAC);
   CPPUNIT_TEST(testMP3);
+  CPPUNIT_TEST(testTrueAudio);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -90,6 +91,11 @@ public:
     fileRefSave("xing", ".mp3");
   }
 
+  void testTrueAudio()
+  {
+    fileRefSave("empty", ".tta");
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestFileRef);