<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>src/helpers.cpp Source File</title> <link href="id3lib.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.12 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center> <hr><h1>src/helpers.cpp</h1><a href="helpers_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// $Id: helpers.cpp,v 1.9 2001/11/05 09:55:33 shadrack Exp $</font> 00002 00003 <font class="comment">// id3lib: a C++ library for creating and manipulating id3v1/v2 tags</font> 00004 <font class="comment">// Copyright 1999, 2000 Scott Thomas Haug</font> 00005 00006 <font class="comment">// Lots of hacking added to this file by Scott Wheeler (scott@slackorama.net)</font> 00007 <font class="comment">// 11/02/2001</font> 00008 00009 <font class="comment">// This library is free software; you can redistribute it and/or modify it</font> 00010 <font class="comment">// under the terms of the GNU Library General Public License as published by</font> 00011 <font class="comment">// the Free Software Foundation; either version 2 of the License, or (at your</font> 00012 <font class="comment">// option) any later version.</font> 00013 <font class="comment">//</font> 00014 <font class="comment">// This library is distributed in the hope that it will be useful, but WITHOUT</font> 00015 <font class="comment">// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</font> 00016 <font class="comment">// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public</font> 00017 <font class="comment">// License for more details.</font> 00018 <font class="comment">//</font> 00019 <font class="comment">// You should have received a copy of the GNU Library General Public License</font> 00020 <font class="comment">// along with this library; if not, write to the Free Software Foundation,</font> 00021 <font class="comment">// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</font> 00022 00023 <font class="comment">// The id3lib authors encourage improvements and optimisations to be sent to</font> 00024 <font class="comment">// the id3lib coordinator. Please see the README file for details on where to</font> 00025 <font class="comment">// send such submissions. See the AUTHORS file for a list of people who have</font> 00026 <font class="comment">// contributed to id3lib. See the ChangeLog file for a list of changes to</font> 00027 <font class="comment">// id3lib. These files are distributed with id3lib at</font> 00028 <font class="comment">// http://download.sourceforge.net/id3lib/</font> 00029 00030 <font class="preprocessor">#if defined HAVE_CONFIG_H</font> 00031 <font class="preprocessor"></font><font class="preprocessor">#include <config.h></font> 00032 <font class="preprocessor">#endif</font> 00033 <font class="preprocessor"></font> 00034 00035 00036 <font class="preprocessor">#include <ctype.h></font> 00037 00038 <font class="preprocessor">#include "helpers.h"</font> 00039 <font class="preprocessor">#include "<a class="code" href="tag__impl_8h.html">tag_impl.h</a>"</font> 00040 <font class="preprocessor">#include "<a class="code" href="frame_8h.html">frame.h</a>"</font> 00041 <font class="preprocessor">#include "<a class="code" href="field_8h.html">field.h</a>"</font> 00042 <font class="preprocessor">#include "utils.h"</font> 00043 00044 <font class="keyword">using</font> <font class="keyword">namespace </font>dami; 00045 00046 String id3::v2::getString(<font class="keyword">const</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame, <a class="code" href="globals_8h.html#a218">ID3_FieldID</a> fldName) 00047 { 00048 <font class="keywordflow">if</font> (!frame) 00049 { 00050 <font class="keywordflow">return</font> <font class="stringliteral">""</font>; 00051 } 00052 <a class="code" href="class_i_d3___field.html">ID3_Field</a>* fp = frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(fldName); 00053 <font class="keywordflow">if</font> (!fp) 00054 { 00055 <font class="keywordflow">return</font> <font class="stringliteral">""</font>; 00056 } 00057 <a class="code" href="globals_8h.html#a214">ID3_TextEnc</a> enc = fp-><a class="code" href="class_i_d3___field.html#a31">GetEncoding</a>(); 00058 fp-><a class="code" href="class_i_d3___field.html#a30">SetEncoding</a>(<a class="code" href="globals_8h.html#a214a47">ID3TE_ASCII</a>); 00059 00060 String text(fp-><a class="code" href="class_i_d3___field.html#a11">GetRawText</a>(), fp-><a class="code" href="class_i_d3___field.html#a1">Size</a>()); 00061 00062 fp-><a class="code" href="class_i_d3___field.html#a30">SetEncoding</a>(enc); 00063 <font class="keywordflow">return</font> text; 00064 } 00065 00066 String id3::v2::getStringAtIndex(<font class="keyword">const</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame, <a class="code" href="globals_8h.html#a218">ID3_FieldID</a> fldName, 00067 size_t nIndex) 00068 { 00069 <font class="keywordflow">if</font> (!frame) 00070 { 00071 <font class="keywordflow">return</font> <font class="stringliteral">""</font>; 00072 } 00073 String text; 00074 <a class="code" href="class_i_d3___field.html">ID3_Field</a>* fp = frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(fldName); 00075 <font class="keywordflow">if</font> (fp && fp-><a class="code" href="class_i_d3___field.html#a3">GetNumTextItems</a>() < nIndex) 00076 { 00077 <a class="code" href="globals_8h.html#a214">ID3_TextEnc</a> enc = fp-><a class="code" href="class_i_d3___field.html#a31">GetEncoding</a>(); 00078 fp-><a class="code" href="class_i_d3___field.html#a30">SetEncoding</a>(<a class="code" href="globals_8h.html#a214a47">ID3TE_ASCII</a>); 00079 00080 text = fp-><a class="code" href="class_i_d3___field.html#a12">GetRawTextItem</a>(nIndex); 00081 00082 fp-><a class="code" href="class_i_d3___field.html#a30">SetEncoding</a>(enc); 00083 } 00084 <font class="keywordflow">return</font> text; 00085 } 00086 00087 size_t id3::v2::removeFrames(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, <a class="code" href="globals_8h.html#a219">ID3_FrameID</a> id) 00088 { 00089 size_t numRemoved = 0; 00090 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00091 00092 <font class="keywordflow">while</font> ((frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(id)) != NULL) 00093 { 00094 frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a17">RemoveFrame</a>(frame); 00095 <font class="keyword">delete</font> frame; 00096 numRemoved++; 00097 } 00098 00099 <font class="keywordflow">return</font> numRemoved; 00100 } 00101 00102 String id3::v2::getFrameText(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, <a class="code" href="globals_8h.html#a219">ID3_FrameID</a> id) 00103 { 00104 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(id); 00105 <font class="keywordflow">return</font> getString(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00106 } 00107 00108 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setFrameText(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, <a class="code" href="globals_8h.html#a219">ID3_FrameID</a> id, String text) 00109 { 00110 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(id); 00111 <font class="keywordflow">if</font> (!frame) 00112 { 00113 frame = <font class="keyword">new</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>(id); 00114 tag.<a class="code" href="class_i_d3___tag_impl.html#a16">AttachFrame</a>(frame); 00115 } 00116 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_TEXT)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(text.c_str()); 00117 00118 <font class="keywordflow">return</font> frame; 00119 } 00120 00122 00123 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasArtist(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00124 { 00125 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* fp = <a class="code" href="globals_8h.html#a24">NULL</a>; 00126 (fp = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a143">ID3FID_LEADARTIST</a>)) || 00127 (fp = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a144">ID3FID_BAND</a>)) || 00128 (fp = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a145">ID3FID_CONDUCTOR</a>)) || 00129 (fp = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a121">ID3FID_COMPOSER</a>)); 00130 <font class="keywordflow">return</font> fp; 00131 } 00132 00133 String id3::v2::getArtist(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00134 { 00135 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = hasArtist(tag); 00136 <font class="keywordflow">return</font> getString(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00137 } 00138 00139 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setArtist(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String text) 00140 { 00141 removeArtists(tag); 00142 <font class="keywordflow">return</font> setFrameText(tag, <a class="code" href="globals_8h.html#a219a143">ID3FID_LEADARTIST</a>, text); 00143 } 00144 00145 size_t id3::v2::removeArtists(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00146 { 00147 size_t numRemoved = 0; 00148 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00149 00150 <font class="keywordflow">while</font> ((frame = hasArtist(tag)) != NULL) 00151 { 00152 frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a17">RemoveFrame</a>(frame); 00153 <font class="keyword">delete</font> frame; 00154 numRemoved++; 00155 } 00156 00157 <font class="keywordflow">return</font> numRemoved; 00158 } 00159 00161 00162 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasAlbum(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00163 { 00164 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a119">ID3FID_ALBUM</a>); 00165 <font class="keywordflow">return</font>(frame); 00166 } 00167 00168 String id3::v2::getAlbum(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00169 { 00170 <font class="keywordflow">return</font> getFrameText(tag, <a class="code" href="globals_8h.html#a219a119">ID3FID_ALBUM</a>); 00171 } 00172 00173 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setAlbum(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String text) 00174 { 00175 <font class="keywordflow">return</font> setFrameText(tag, <a class="code" href="globals_8h.html#a219a119">ID3FID_ALBUM</a>, text); 00176 } 00177 00178 size_t id3::v2::removeAlbums(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00179 { 00180 <font class="keywordflow">return</font> removeFrames(tag, <a class="code" href="globals_8h.html#a219a119">ID3FID_ALBUM</a>); 00181 } 00182 00184 00185 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasTitle(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00186 { 00187 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a131">ID3FID_TITLE</a>); 00188 <font class="keywordflow">return</font>(frame); 00189 } 00190 00191 String id3::v2::getTitle(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00192 { 00193 <font class="keywordflow">return</font> getFrameText(tag, <a class="code" href="globals_8h.html#a219a131">ID3FID_TITLE</a>); 00194 } 00195 00196 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setTitle(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String text) 00197 { 00198 <font class="keywordflow">return</font> setFrameText(tag, <a class="code" href="globals_8h.html#a219a131">ID3FID_TITLE</a>, text); 00199 } 00200 00201 size_t id3::v2::removeTitles(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00202 { 00203 <font class="keywordflow">return</font> removeFrames(tag, <a class="code" href="globals_8h.html#a219a131">ID3FID_TITLE</a>); 00204 } 00205 00207 00208 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasYear(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00209 { 00210 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a157">ID3FID_YEAR</a>); 00211 <font class="keywordflow">return</font>(frame); 00212 } 00213 00214 String id3::v2::getYear(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00215 { 00216 <font class="keywordflow">return</font> getFrameText(tag, <a class="code" href="globals_8h.html#a219a157">ID3FID_YEAR</a>); 00217 } 00218 00219 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setYear(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String text) 00220 { 00221 <font class="keywordflow">return</font> setFrameText(tag, <a class="code" href="globals_8h.html#a219a157">ID3FID_YEAR</a>, text); 00222 } 00223 00224 size_t id3::v2::removeYears(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00225 { 00226 <font class="keywordflow">return</font> removeFrames(tag, <a class="code" href="globals_8h.html#a219a157">ID3FID_YEAR</a>); 00227 } 00228 00230 00231 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasV1Comment(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00232 { 00233 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00234 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>, <a class="code" href="globals_8h.html#a6">STR_V1_COMMENT_DESC</a>)) || 00235 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>, <font class="stringliteral">""</font> )) || 00236 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>)); 00237 <font class="keywordflow">return</font>(frame); 00238 } 00239 00240 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasComment(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00241 { 00242 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>); 00243 <font class="keywordflow">return</font>(frame); 00244 } 00245 00246 String id3::v2::getV1Comment(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00247 { 00248 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame; 00249 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>, <a class="code" href="globals_8h.html#a6">STR_V1_COMMENT_DESC</a>)) || 00250 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>, <font class="stringliteral">""</font> )) || 00251 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>)); 00252 <font class="keywordflow">return</font> getString(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00253 } 00254 00255 String id3::v2::getComment(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String desc) 00256 { 00257 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>, desc.c_str()); 00258 <font class="keywordflow">return</font> getString(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00259 } 00260 00261 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setComment(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String text, String desc, 00262 String lang) 00263 { 00264 ID3D_NOTICE( <font class="stringliteral">"id3::v2::setComment: trying to find frame with description = "</font> << desc ); 00265 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00266 <font class="comment">// See if there is already a comment with this description</font> 00267 <font class="keywordflow">for</font> (<a class="code" href="class_i_d3___tag_impl.html#s0">ID3_TagImpl::iterator</a> iter = tag.<a class="code" href="class_i_d3___tag_impl.html#a34">begin</a>(); iter != tag.<a class="code" href="class_i_d3___tag_impl.html#a35">end</a>(); ++iter) 00268 { 00269 frame = *iter; 00270 <font class="keywordflow">if</font> (frame == NULL) 00271 { 00272 <font class="keywordflow">continue</font>; 00273 } 00274 <font class="keywordflow">if</font> (frame-><a class="code" href="class_i_d3___frame.html#a5">GetID</a>() == <a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>) 00275 { 00276 String tmpDesc = getString(frame, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>); 00277 <font class="keywordflow">if</font> (tmpDesc == desc) 00278 { 00279 ID3D_NOTICE( <font class="stringliteral">"id3::v2::setComment: found frame with description = "</font> << desc ); 00280 <font class="keywordflow">break</font>; 00281 } 00282 } 00283 frame = NULL; 00284 } 00285 <font class="keywordflow">if</font> (frame == NULL) 00286 { 00287 ID3D_NOTICE( <font class="stringliteral">"id3::v2::setComment: creating new comment frame"</font> ); 00288 frame = <font class="keyword">new</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>); 00289 tag.<a class="code" href="class_i_d3___tag_impl.html#a16">AttachFrame</a>(frame); 00290 } 00291 <font class="keywordflow">if</font> (!frame) 00292 { 00293 ID3D_WARNING( <font class="stringliteral">"id3::v2::setComment: ack! no frame"</font> ); 00294 } 00295 <font class="keywordflow">else</font> 00296 { 00297 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_LANGUAGE)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(lang.c_str()); 00298 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_DESCRIPTION)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(desc.c_str()); 00299 frame->GetField(ID3FN_TEXT)->Set(text.c_str()); 00300 } 00301 00302 <font class="keywordflow">return</font> frame; 00303 } 00304 00305 <font class="comment">// Remove all comments from the tag</font> 00306 size_t id3::v2::removeAllComments(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00307 { 00308 <font class="keywordflow">return</font> removeFrames(tag, <a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>); 00309 } 00310 00311 <font class="comment">// Remove all comments from the tag with the given description</font> 00312 size_t id3::v2::removeComments(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String desc) 00313 { 00314 size_t numRemoved = 0; 00315 00316 <font class="keywordflow">for</font> (<a class="code" href="class_i_d3___tag_impl.html#s0">ID3_TagImpl::iterator</a> iter = tag.<a class="code" href="class_i_d3___tag_impl.html#a34">begin</a>(); iter != tag.<a class="code" href="class_i_d3___tag_impl.html#a35">end</a>(); ++iter) 00317 { 00318 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = *iter; 00319 <font class="keywordflow">if</font> (frame == <a class="code" href="globals_8h.html#a24">NULL</a>) 00320 { 00321 <font class="keywordflow">continue</font>; 00322 } 00323 <font class="keywordflow">if</font> (frame-><a class="code" href="class_i_d3___frame.html#a5">GetID</a>() == <a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>) 00324 { 00325 <font class="comment">// See if the description we have matches the description of the </font> 00326 <font class="comment">// current comment. If so, remove the comment</font> 00327 String tmpDesc = getString(frame, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>); 00328 <font class="keywordflow">if</font> (tmpDesc == desc) 00329 { 00330 frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a17">RemoveFrame</a>(frame); 00331 <font class="keyword">delete</font> frame; 00332 numRemoved++; 00333 } 00334 } 00335 } 00336 00337 <font class="keywordflow">return</font> numRemoved; 00338 } 00339 00341 00342 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasTrack(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00343 { 00344 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a149">ID3FID_TRACKNUM</a>); 00345 <font class="keywordflow">return</font>(frame); 00346 } 00347 00348 String id3::v2::getTrack(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00349 { 00350 <font class="keywordflow">return</font> getFrameText(tag, <a class="code" href="globals_8h.html#a219a149">ID3FID_TRACKNUM</a>); 00351 } 00352 00353 size_t id3::v2::getTrackNum(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00354 { 00355 String sTrack = getTrack(tag); 00356 return ::atoi(sTrack.c_str()); 00357 } 00358 00359 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setTrack(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, <a class="code" href="globals_8h.html#a33">uchar</a> trk, <a class="code" href="globals_8h.html#a33">uchar</a> ttl) 00360 { 00361 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00362 String track = toString((size_t)trk); 00363 <font class="keywordflow">if</font> (ttl > 0) 00364 { 00365 track += <font class="stringliteral">"/"</font>; 00366 track += toString((size_t)ttl); 00367 } 00368 setFrameText(tag, <a class="code" href="globals_8h.html#a219a149">ID3FID_TRACKNUM</a>, track); 00369 00370 <font class="keywordflow">return</font> frame; 00371 } 00372 00373 size_t id3::v2::removeTracks(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00374 { 00375 <font class="keywordflow">return</font> removeFrames(tag, <a class="code" href="globals_8h.html#a219a149">ID3FID_TRACKNUM</a>); 00376 } 00377 00379 00380 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasGenre(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00381 { 00382 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a122">ID3FID_CONTENTTYPE</a>); 00383 <font class="keywordflow">return</font>(frame); 00384 } 00385 00386 String id3::v2::getGenre(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00387 { 00388 <font class="keywordflow">return</font> getFrameText(tag, <a class="code" href="globals_8h.html#a219a122">ID3FID_CONTENTTYPE</a>); 00389 } 00390 00391 size_t id3::v2::getGenreNum(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00392 { 00393 String sGenre = getGenre(tag); 00394 size_t ulGenre = 0xFF; 00395 size_t size = sGenre.size(); 00396 00397 <font class="comment">// If the genre string begins with "(ddd)", where "ddd" is a number, then </font> 00398 <font class="comment">// "ddd" is the genre number---get it</font> 00399 <a class="code" href="globals_8h.html#a7">index_t</a> i = 0; 00400 <font class="keywordflow">if</font> (i < size && size && sGenre[i] == <font class="charliteral">'('</font>) 00401 { 00402 ++i; 00403 <font class="keywordflow">while</font> (i < size && isdigit(sGenre[i])) 00404 { 00405 ++i; 00406 } 00407 <font class="keywordflow">if</font> (i < size && sGenre[i] == <font class="charliteral">')'</font>) 00408 { 00409 <font class="comment">// if the genre number is greater than 255, its invalid.</font> 00410 ulGenre = min(0xFF, atoi(&sGenre[1])); 00411 } 00412 } 00413 00414 <font class="keywordflow">return</font> ulGenre; 00415 } 00416 00417 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setGenre(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, size_t genre) 00418 { 00419 String sGenre = <font class="stringliteral">"("</font>; 00420 sGenre += toString(genre) + <font class="stringliteral">")"</font>; 00421 <font class="keywordflow">return</font> setFrameText(tag, <a class="code" href="globals_8h.html#a219a122">ID3FID_CONTENTTYPE</a>, sGenre); 00422 } 00423 00424 size_t id3::v2::removeGenres(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00425 { 00426 <font class="keywordflow">return</font> removeFrames(tag, <a class="code" href="globals_8h.html#a219a122">ID3FID_CONTENTTYPE</a>); 00427 } 00428 00430 00431 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasLyrics(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00432 { 00433 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a160">ID3FID_UNSYNCEDLYRICS</a>); 00434 <font class="keywordflow">return</font>(frame); 00435 } 00436 00437 String id3::v2::getLyrics(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00438 { 00439 <font class="keywordflow">return</font> getFrameText(tag, <a class="code" href="globals_8h.html#a219a160">ID3FID_UNSYNCEDLYRICS</a>); 00440 } 00441 00442 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setLyrics(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String text, String desc, 00443 String lang) 00444 { 00445 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = NULL; 00446 <font class="comment">// See if there is already a comment with this description</font> 00447 <font class="keywordflow">for</font> (<a class="code" href="class_i_d3___tag_impl.html#s0">ID3_TagImpl::iterator</a> iter = tag.<a class="code" href="class_i_d3___tag_impl.html#a34">begin</a>(); iter != tag.<a class="code" href="class_i_d3___tag_impl.html#a35">end</a>(); ++iter) 00448 { 00449 frame = *iter; 00450 <font class="keywordflow">if</font> (frame == NULL) 00451 { 00452 <font class="keywordflow">continue</font>; 00453 } 00454 <font class="keywordflow">if</font> (frame-><a class="code" href="class_i_d3___frame.html#a5">GetID</a>() == <a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>) 00455 { 00456 String tmpDesc = getString(frame, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>); 00457 <font class="keywordflow">if</font> (tmpDesc == desc) 00458 { 00459 <font class="keywordflow">break</font>; 00460 } 00461 } 00462 frame = NULL; 00463 } 00464 <font class="keywordflow">if</font> (frame == NULL) 00465 { 00466 frame = <font class="keyword">new</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>(<a class="code" href="globals_8h.html#a219a160">ID3FID_UNSYNCEDLYRICS</a>); 00467 tag.<a class="code" href="class_i_d3___tag_impl.html#a16">AttachFrame</a>(frame); 00468 } 00469 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_LANGUAGE)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(lang.c_str()); 00470 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_DESCRIPTION)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(desc.c_str()); 00471 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_TEXT)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(text.c_str()); 00472 00473 <font class="keywordflow">return</font> frame; 00474 } 00475 00476 size_t id3::v2::removeLyrics(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00477 { 00478 <font class="keywordflow">return</font> removeFrames(tag, <a class="code" href="globals_8h.html#a219a160">ID3FID_UNSYNCEDLYRICS</a>); 00479 } 00480 00481 String id3::v2::getLyricist(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00482 { 00483 <font class="keywordflow">return</font> getFrameText(tag, <a class="code" href="globals_8h.html#a219a127">ID3FID_LYRICIST</a>); 00484 } 00485 00486 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setLyricist(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String text) 00487 { 00488 <font class="keywordflow">return</font> setFrameText(tag, <a class="code" href="globals_8h.html#a219a127">ID3FID_LYRICIST</a>, text); 00489 } 00490 00491 size_t id3::v2::removeLyricists(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag) 00492 { 00493 <font class="keywordflow">return</font> removeFrames(tag, <a class="code" href="globals_8h.html#a219a127">ID3FID_LYRICIST</a>); 00494 } 00495 00497 00498 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::hasSyncLyrics(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String lang, String desc) 00499 { 00500 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame=<a class="code" href="globals_8h.html#a24">NULL</a>; 00501 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>, <a class="code" href="globals_8h.html#a218a80">ID3FN_LANGUAGE</a>, lang)) || 00502 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>, desc)); 00503 <font class="keywordflow">return</font>(frame); 00504 } 00505 00506 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* id3::v2::setSyncLyrics(<a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, BString data, 00507 <a class="code" href="globals_8h.html#a225">ID3_TimeStampFormat</a> format, String desc, 00508 String lang, <a class="code" href="globals_8h.html#a224">ID3_ContentType</a> type) 00509 { 00510 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00511 00512 <font class="comment">// check if a SYLT frame of this language or descriptor already exists</font> 00513 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>, <a class="code" href="globals_8h.html#a218a80">ID3FN_LANGUAGE</a>, lang)) || 00514 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>, desc)); 00515 00516 <font class="keywordflow">if</font> (!frame) 00517 { 00518 frame = <font class="keyword">new</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>); 00519 tag.<a class="code" href="class_i_d3___tag_impl.html#a16">AttachFrame</a>(frame); 00520 } 00521 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_LANGUAGE)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(lang.c_str()); 00522 frame->GetField(ID3FN_DESCRIPTION)->Set(desc.c_str()); 00523 frame->GetField(ID3FN_TIMESTAMPFORMAT)->Set(format); 00524 frame->GetField(ID3FN_CONTENTTYPE)->Set(type); 00525 frame->GetField(ID3FN_DATA)->Set(data.data(), data.size()); 00526 00527 <font class="keywordflow">return</font> frame; 00528 } 00529 00530 BString id3::v2::getSyncLyrics(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>& tag, String lang, String desc) 00531 { 00532 <font class="comment">// check if a SYLT frame of this language or descriptor exists</font> 00533 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00534 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>, <a class="code" href="globals_8h.html#a218a80">ID3FN_LANGUAGE</a>, lang)) || 00535 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>, desc)) || 00536 (frame = tag.<a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>)); 00537 00538 <font class="comment">// get the lyrics size</font> 00539 <a class="code" href="class_i_d3___field.html">ID3_Field</a>* fld = frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(<a class="code" href="globals_8h.html#a218a74">ID3FN_DATA</a>); 00540 <font class="keywordflow">return</font> BString(reinterpret_cast<const BString::value_type *>(fld-><a class="code" href="class_i_d3___field.html#a23">GetRawBinary</a>()), fld-><a class="code" href="class_i_d3___field.html#a1">Size</a>()); 00541 } 00542 </pre></div><hr><address><small>Generated on Thu Jan 3 07:35:55 2002 for id3lib by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.gif" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.12 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, © 1997-2001</small></address> </body> </html>