Added TagLib (with AUTORS and COPYING files)
[someplayer] / src / taglib / riff / wav / wavfile.cpp
1 /***************************************************************************
2     copyright            : (C) 2008 by Scott Wheeler
3     email                : wheeler@kde.org
4  ***************************************************************************/
5
6 /***************************************************************************
7  *   This library is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU Lesser General Public License version   *
9  *   2.1 as published by the Free Software Foundation.                     *
10  *                                                                         *
11  *   This library is distributed in the hope that it will be useful, but   *
12  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
14  *   Lesser General Public License for more details.                       *
15  *                                                                         *
16  *   You should have received a copy of the GNU Lesser General Public      *
17  *   License along with this library; if not, write to the Free Software   *
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19  *   USA                                                                   *
20  *                                                                         *
21  *   Alternatively, this file is available under the Mozilla Public        *
22  *   License Version 1.1.  You may obtain a copy of the License at         *
23  *   http://www.mozilla.org/MPL/                                           *
24  ***************************************************************************/
25
26 #include <tbytevector.h>
27 #include <tdebug.h>
28 #include <id3v2tag.h>
29
30 #include "wavfile.h"
31
32 using namespace TagLib;
33
34 class RIFF::WAV::File::FilePrivate
35 {
36 public:
37   FilePrivate() :
38     properties(0),
39     tag(0)
40   {
41
42   }
43
44   ~FilePrivate()
45   {
46     delete properties;
47     delete tag;
48   }
49
50   Properties *properties;
51   ID3v2::Tag *tag;
52 };
53
54 ////////////////////////////////////////////////////////////////////////////////
55 // public members
56 ////////////////////////////////////////////////////////////////////////////////
57
58 RIFF::WAV::File::File(FileName file, bool readProperties,
59                        Properties::ReadStyle propertiesStyle) : RIFF::File(file, LittleEndian)
60 {
61   d = new FilePrivate;
62   if(isOpen())
63     read(readProperties, propertiesStyle);
64 }
65
66 RIFF::WAV::File::~File()
67 {
68   delete d;
69 }
70
71 ID3v2::Tag *RIFF::WAV::File::tag() const
72 {
73   return d->tag;
74 }
75
76 RIFF::WAV::Properties *RIFF::WAV::File::audioProperties() const
77 {
78   return d->properties;
79 }
80
81 bool RIFF::WAV::File::save()
82 {
83   if(readOnly()) {
84     debug("RIFF::WAV::File::save() -- File is read only.");
85     return false;
86   }
87
88   setChunkData("ID3 ", d->tag->render());
89
90   return true;
91 }
92
93 ////////////////////////////////////////////////////////////////////////////////
94 // private members
95 ////////////////////////////////////////////////////////////////////////////////
96
97 void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
98 {
99   for(uint i = 0; i < chunkCount(); i++) {
100     if(chunkName(i) == "ID3 ")
101       d->tag = new ID3v2::Tag(this, chunkOffset(i));
102     else if(chunkName(i) == "fmt " && readProperties)
103       d->properties = new Properties(chunkData(i), propertiesStyle);
104   }
105
106   if(!d->tag)
107     d->tag = new ID3v2::Tag;
108 }