Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

src/header_frame.cpp

Go to the documentation of this file.
00001 // $Id: header_frame.cpp,v 1.22 2002/07/02 22:13:10 t1mpy Exp $ 00002 00003 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags 00004 // Copyright 1999, 2000 Scott Thomas Haug 00005 00006 // This library is free software; you can redistribute it and/or modify it 00007 // under the terms of the GNU Library General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or (at your 00009 // option) any later version. 00010 // 00011 // This library is distributed in the hope that it will be useful, but WITHOUT 00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 // License for more details. 00015 // 00016 // You should have received a copy of the GNU Library General Public License 00017 // along with this library; if not, write to the Free Software Foundation, 00018 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 // The id3lib authors encourage improvements and optimisations to be sent to 00021 // the id3lib coordinator. Please see the README file for details on where to 00022 // send such submissions. See the AUTHORS file for a list of people who have 00023 // contributed to id3lib. See the ChangeLog file for a list of changes to 00024 // id3lib. These files are distributed with id3lib at 00025 // http://download.sourceforge.net/id3lib/ 00026 00027 00028 #include <memory.h> 00029 #include "header_frame.h" 00030 #include "id3/utils.h" // has <config.h> "id3/id3lib_streams.h" "id3/globals.h" "id3/id3lib_strings.h" 00031 #include "frame_def.h" 00032 #include "field_def.h" 00033 #include "field_impl.h" 00034 #include "io_helpers.h" 00035 00036 using namespace dami; 00037 00038 void ID3_FrameHeader::SetUnknownFrame(const char* id) 00039 { 00040 Clear(); 00041 _frame_def = new ID3_FrameDef; 00042 if (NULL == _frame_def) 00043 { 00044 // log this; 00045 return; 00046 } 00047 _frame_def->eID = ID3FID_NOFRAME; 00048 _frame_def->bTagDiscard = false; 00049 _frame_def->bFileDiscard = false; 00050 _frame_def->aeFieldDefs = ID3_FieldDef::DEFAULT; 00051 _frame_def->sDescription = NULL; 00052 if (strlen(id) <= 3) 00053 { 00054 strcpy(_frame_def->sShortTextID, id); 00055 strcpy(_frame_def->sLongTextID, ""); 00056 } 00057 else 00058 { 00059 strcpy(_frame_def->sLongTextID, id); 00060 strcpy(_frame_def->sShortTextID, ""); 00061 } 00062 _dyn_frame_def = true; 00063 } 00064 00065 bool ID3_FrameHeader::SetFrameID(ID3_FrameID id) 00066 { 00067 if (id == ID3FID_NOFRAME || id == this->GetFrameID()) 00068 { 00069 return false; 00070 } 00071 _frame_def = ID3_FindFrameDef(id); 00072 _flags.set(TAGALTER, _frame_def->bTagDiscard); 00073 _flags.set(FILEALTER, _frame_def->bFileDiscard); 00074 00075 _changed = true; 00076 return true; 00077 } 00078 00079 size_t ID3_FrameHeader::Size() const 00080 { 00081 if (!_info) 00082 { 00083 return 0; 00084 } 00085 return 00086 _info->frame_bytes_id + 00087 _info->frame_bytes_size + 00088 _info->frame_bytes_flags; 00089 } 00090 00091 bool ID3_FrameHeader::Parse(ID3_Reader& reader) 00092 { 00093 ID3D_NOTICE( "ID3_FrameHeader::Parse(): getCur() = " << reader.getCur() ); 00094 io::ExitTrigger et(reader); 00095 if (!_info) 00096 { 00097 return false; 00098 } 00099 if (reader.getEnd() < reader.getCur() + 10) 00100 { 00101 return false; 00102 } 00103 00104 String textID = io::readText(reader, _info->frame_bytes_id); 00105 00106 ID3D_NOTICE( "ID3_FrameHeader::Parse: textID = " << textID ); 00107 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() ); 00108 00109 ID3_FrameID fid = ID3_FindFrameID(textID.c_str()); 00110 if (ID3FID_NOFRAME == fid) 00111 { 00112 this->SetUnknownFrame(textID.c_str()); 00113 ID3D_NOTICE( "ID3_FrameHeader::Parse: unknown frame id" ); 00114 } 00115 else 00116 { 00117 this->SetFrameID(fid); 00118 } 00119 00120 uint32 dataSize = io::readBENumber(reader, _info->frame_bytes_size); 00121 ID3D_NOTICE( "ID3_FrameHeader::Parse: dataSize = " << dataSize ); 00122 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() ); 00123 this->SetDataSize(dataSize); 00124 00125 uint32 flags = io::readBENumber(reader, _info->frame_bytes_flags); 00126 _flags.add(flags); 00127 00128 ID3D_NOTICE( "ID3_FrameHeader::Parse: flags = " << flags ); 00129 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() ); 00130 et.setExitPos(reader.getCur()); 00131 00132 return true; 00133 } 00134 00135 void ID3_FrameHeader::Render(ID3_Writer& writer) const 00136 { 00137 size_t size = 0; 00138 00139 if (NULL == _frame_def) 00140 { 00141 // TODO: log this 00142 ID3D_WARNING( "ID3_FrameHeader::Render(): _frame_def is NULL!" ); 00143 return; 00144 //ID3_THROW(ID3E_InvalidFrameID); 00145 } 00146 char *textID; 00147 if (_info->frame_bytes_id == strlen(_frame_def->sShortTextID)) 00148 { 00149 textID = _frame_def->sShortTextID; 00150 } 00151 else 00152 { 00153 textID = _frame_def->sLongTextID; 00154 } 00155 00156 ID3D_NOTICE( "ID3_FrameHeader::Render(): writing " << textID << ", " << (int) _info->frame_bytes_size << " bytes"); 00157 writer.writeChars((uchar *) textID, _info->frame_bytes_id); 00158 00159 io::writeBENumber(writer, _data_size, _info->frame_bytes_size); 00160 io::writeBENumber(writer, _flags.get(), _info->frame_bytes_flags); 00161 } 00162 00163 const char* ID3_FrameHeader::GetTextID() const 00164 { 00165 char *textID = ""; 00166 if (_info && _frame_def) 00167 { 00168 if (_info->frame_bytes_id == strlen(_frame_def->sShortTextID)) 00169 { 00170 textID = _frame_def->sShortTextID; 00171 } 00172 else 00173 { 00174 textID = _frame_def->sLongTextID; 00175 } 00176 } 00177 return textID; 00178 } 00179 00180 ID3_FrameHeader& ID3_FrameHeader::operator=(const ID3_FrameHeader& hdr) 00181 { 00182 if (this != &hdr) 00183 { 00184 this->Clear(); 00185 this->ID3_Header::operator=(hdr); 00186 if (!hdr._dyn_frame_def) 00187 { 00188 _frame_def = hdr._frame_def; 00189 } 00190 else 00191 { 00192 _frame_def = new ID3_FrameDef; 00193 if (NULL == _frame_def) 00194 { 00195 // TODO: throw something here... 00196 } 00197 _frame_def->eID = hdr._frame_def->eID; 00198 _frame_def->bTagDiscard = hdr._frame_def->bTagDiscard; 00199 _frame_def->bFileDiscard = hdr._frame_def->bFileDiscard; 00200 _frame_def->aeFieldDefs = hdr._frame_def->aeFieldDefs; 00201 strcpy(_frame_def->sShortTextID, hdr._frame_def->sShortTextID); 00202 strcpy(_frame_def->sLongTextID, hdr._frame_def->sLongTextID); 00203 _dyn_frame_def = true; 00204 } 00205 } 00206 return *this; 00207 } 00208 00209 ID3_FrameID ID3_FrameHeader::GetFrameID() const 00210 { 00211 ID3_FrameID eID = ID3FID_NOFRAME; 00212 if (NULL != _frame_def) 00213 { 00214 eID = _frame_def->eID; 00215 } 00216 00217 return eID; 00218 } 00219 00220 const ID3_FrameDef *ID3_FrameHeader::GetFrameDef() const 00221 { 00222 return _frame_def; 00223 } 00224 00225 bool ID3_FrameHeader::Clear() 00226 { 00227 bool changed = this->ID3_Header::Clear(); 00228 if (_dyn_frame_def) 00229 { 00230 delete _frame_def; 00231 _dyn_frame_def = false; 00232 changed = true; 00233 } 00234 if (_frame_def) 00235 { 00236 _frame_def = NULL; 00237 changed = true; 00238 } 00239 return changed; 00240 } 00241

Generated on Thu Jun 3 16:57:08 2004 for id3lib by doxygen 1.3.7