<!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/misc_support.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/misc_support.cpp</h1><a href="misc__support_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// $Id: misc_support.cpp,v 1.33 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">// This library is free software; you can redistribute it and/or modify it</font> 00007 <font class="comment">// under the terms of the GNU Library General Public License as published by</font> 00008 <font class="comment">// the Free Software Foundation; either version 2 of the License, or (at your</font> 00009 <font class="comment">// option) any later version.</font> 00010 <font class="comment">//</font> 00011 <font class="comment">// This library is distributed in the hope that it will be useful, but WITHOUT</font> 00012 <font class="comment">// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</font> 00013 <font class="comment">// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public</font> 00014 <font class="comment">// License for more details.</font> 00015 <font class="comment">//</font> 00016 <font class="comment">// You should have received a copy of the GNU Library General Public License</font> 00017 <font class="comment">// along with this library; if not, write to the Free Software Foundation,</font> 00018 <font class="comment">// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</font> 00019 00020 <font class="comment">// The id3lib authors encourage improvements and optimisations to be sent to</font> 00021 <font class="comment">// the id3lib coordinator. Please see the README file for details on where to</font> 00022 <font class="comment">// send such submissions. See the AUTHORS file for a list of people who have</font> 00023 <font class="comment">// contributed to id3lib. See the ChangeLog file for a list of changes to</font> 00024 <font class="comment">// id3lib. These files are distributed with id3lib at</font> 00025 <font class="comment">// http://download.sourceforge.net/id3lib/</font> 00026 00027 <font class="preprocessor">#if defined HAVE_CONFIG_H</font> 00028 <font class="preprocessor"></font><font class="preprocessor">#include <config.h></font> 00029 <font class="preprocessor">#endif</font> 00030 <font class="preprocessor"></font> 00031 00032 00033 <font class="preprocessor">#include <string.h></font> 00034 <font class="preprocessor">#include <stdlib.h></font> 00035 <font class="preprocessor">#include <ctype.h></font> 00036 <font class="preprocessor">#include <stdio.h></font> 00037 00038 <font class="preprocessor">#include "<a class="code" href="misc__support_8h.html">misc_support.h</a>"</font> 00039 <font class="preprocessor">#include "<a class="code" href="field_8h.html">field.h</a>"</font> 00040 <font class="preprocessor">#include "utils.h"</font> 00041 00042 <font class="keyword">using</font> <font class="keyword">namespace </font>dami; 00043 <a name="l00044"></a><a class="code" href="misc__support_8cpp.html#a0">00044</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(<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) 00045 { 00046 <font class="keywordtype">char</font> *text = <a class="code" href="globals_8h.html#a24">NULL</a>; 00047 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> != frame) 00048 { 00049 <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>(fldName); 00050 <a class="code" href="globals_8h.html#a214">ID3_TextEnc</a> enc = fld-><a class="code" href="class_i_d3___field.html#a31">GetEncoding</a>(); 00051 fld-><a class="code" href="class_i_d3___field.html#a30">SetEncoding</a>(<a class="code" href="globals_8h.html#a214a47">ID3TE_ASCII</a>); 00052 size_t nText = fld-><a class="code" href="class_i_d3___field.html#a1">Size</a>(); 00053 text = <font class="keyword">new</font> <font class="keywordtype">char</font>[nText + 1]; 00054 fld-><a class="code" href="class_i_d3___field.html#a6">Get</a>(text, nText + 1); 00055 fld-><a class="code" href="class_i_d3___field.html#a30">SetEncoding</a>(enc); 00056 } 00057 <font class="keywordflow">return</font> text; 00058 } 00059 <a name="l00060"></a><a class="code" href="misc__support_8cpp.html#a1">00060</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(<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, size_t nIndex) 00061 { 00062 <font class="keywordtype">char</font> *text = <a class="code" href="globals_8h.html#a24">NULL</a>; 00063 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> != frame) 00064 { 00065 size_t nText = frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(fldName)-><a class="code" href="class_i_d3___field.html#a1">Size</a>(); 00066 text = <font class="keyword">new</font> <font class="keywordtype">char</font>[nText + 1]; 00067 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(fldName)-><a class="code" href="class_i_d3___field.html#a6">Get</a>(text, nText + 1, nIndex); 00068 } 00069 <font class="keywordflow">return</font> text; 00070 } 00071 <a name="l00072"></a><a class="code" href="misc__support_8cpp.html#a2">00072</a> <font class="keywordtype">void</font> <a class="code" href="misc__support_8h.html#a2">ID3_FreeString</a>(<font class="keywordtype">char</font> *str) 00073 { 00074 <font class="keywordflow">if</font>(str != <a class="code" href="globals_8h.html#a24">NULL</a>) 00075 <font class="keyword">delete</font> [] str; 00076 } 00077 <a name="l00078"></a><a class="code" href="misc__support_8cpp.html#a3">00078</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a3">ID3_GetArtist</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00079 { 00080 <font class="keywordtype">char</font> *sArtist = <a class="code" href="globals_8h.html#a24">NULL</a>; 00081 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00082 { 00083 <font class="keywordflow">return</font> sArtist; 00084 } 00085 00086 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00087 <font class="keywordflow">if</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a143">ID3FID_LEADARTIST</a>)) || 00088 (frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a144">ID3FID_BAND</a>)) || 00089 (frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a145">ID3FID_CONDUCTOR</a>)) || 00090 (frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a121">ID3FID_COMPOSER</a>))) 00091 { 00092 sArtist = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00093 } 00094 <font class="keywordflow">return</font> sArtist; 00095 } 00096 <a name="l00097"></a><a class="code" href="misc__support_8cpp.html#a4">00097</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a4">ID3_AddArtist</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keywordtype">bool</font> replace) 00098 { 00099 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00100 <font class="keywordflow">if</font> (NULL != tag && NULL != text && strlen(text) > 0) 00101 { 00102 <font class="keywordflow">if</font> (replace) 00103 { 00104 <a class="code" href="misc__support_8h.html#a5">ID3_RemoveArtists</a>(tag); 00105 } 00106 <font class="keywordflow">if</font> (replace || 00107 (tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a143">ID3FID_LEADARTIST</a>) == NULL && 00108 tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a144">ID3FID_BAND</a>) == NULL && 00109 tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a145">ID3FID_CONDUCTOR</a>) == NULL && 00110 tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a121">ID3FID_COMPOSER</a>) == NULL)) 00111 { 00112 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#a219a143">ID3FID_LEADARTIST</a>); 00113 <font class="keywordflow">if</font> (frame) 00114 { 00115 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); 00116 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00117 } 00118 } 00119 } 00120 00121 <font class="keywordflow">return</font> frame; 00122 } 00123 <a name="l00124"></a><a class="code" href="misc__support_8cpp.html#a5">00124</a> size_t <a class="code" href="misc__support_8h.html#a5">ID3_RemoveArtists</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00125 { 00126 size_t num_removed = 0; 00127 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00128 00129 <font class="keywordflow">if</font> (NULL == tag) 00130 { 00131 <font class="keywordflow">return</font> num_removed; 00132 } 00133 00134 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a143">ID3FID_LEADARTIST</a>))) 00135 { 00136 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00137 <font class="keyword">delete</font> frame; 00138 num_removed++; 00139 } 00140 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a144">ID3FID_BAND</a>))) 00141 { 00142 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00143 <font class="keyword">delete</font> frame; 00144 num_removed++; 00145 } 00146 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a145">ID3FID_CONDUCTOR</a>))) 00147 { 00148 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00149 <font class="keyword">delete</font> frame; 00150 num_removed++; 00151 } 00152 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a121">ID3FID_COMPOSER</a>))) 00153 { 00154 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00155 <font class="keyword">delete</font> frame; 00156 num_removed++; 00157 } 00158 00159 <font class="keywordflow">return</font> num_removed; 00160 } 00161 <a name="l00162"></a><a class="code" href="misc__support_8cpp.html#a6">00162</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a6">ID3_GetAlbum</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00163 { 00164 <font class="keywordtype">char</font> *sAlbum = <a class="code" href="globals_8h.html#a24">NULL</a>; 00165 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00166 { 00167 <font class="keywordflow">return</font> sAlbum; 00168 } 00169 00170 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a119">ID3FID_ALBUM</a>); 00171 <font class="keywordflow">if</font> (frame != <a class="code" href="globals_8h.html#a24">NULL</a>) 00172 { 00173 sAlbum = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00174 } 00175 <font class="keywordflow">return</font> sAlbum; 00176 } 00177 <a name="l00178"></a><a class="code" href="misc__support_8cpp.html#a7">00178</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a7">ID3_AddAlbum</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keywordtype">bool</font> replace) 00179 { 00180 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00181 <font class="keywordflow">if</font> (NULL != tag && NULL != text && strlen(text) > 0) 00182 { 00183 <font class="keywordflow">if</font> (replace) 00184 { 00185 <a class="code" href="misc__support_8h.html#a8">ID3_RemoveAlbums</a>(tag); 00186 } 00187 <font class="keywordflow">if</font> (replace || tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a119">ID3FID_ALBUM</a>) == NULL) 00188 { 00189 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#a219a119">ID3FID_ALBUM</a>); 00190 <font class="keywordflow">if</font> (frame) 00191 { 00192 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); 00193 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00194 } 00195 } 00196 } 00197 00198 <font class="keywordflow">return</font> frame; 00199 } 00200 <a name="l00201"></a><a class="code" href="misc__support_8cpp.html#a8">00201</a> size_t <a class="code" href="misc__support_8h.html#a8">ID3_RemoveAlbums</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00202 { 00203 size_t num_removed = 0; 00204 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00205 00206 <font class="keywordflow">if</font> (NULL == tag) 00207 { 00208 <font class="keywordflow">return</font> num_removed; 00209 } 00210 00211 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a119">ID3FID_ALBUM</a>))) 00212 { 00213 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00214 <font class="keyword">delete</font> frame; 00215 num_removed++; 00216 } 00217 00218 <font class="keywordflow">return</font> num_removed; 00219 } 00220 <a name="l00221"></a><a class="code" href="misc__support_8cpp.html#a9">00221</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a9">ID3_GetTitle</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00222 { 00223 <font class="keywordtype">char</font> *sTitle = <a class="code" href="globals_8h.html#a24">NULL</a>; 00224 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00225 { 00226 <font class="keywordflow">return</font> sTitle; 00227 } 00228 00229 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a131">ID3FID_TITLE</a>); 00230 <font class="keywordflow">if</font> (frame != <a class="code" href="globals_8h.html#a24">NULL</a>) 00231 { 00232 sTitle = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00233 } 00234 <font class="keywordflow">return</font> sTitle; 00235 } 00236 <a name="l00237"></a><a class="code" href="misc__support_8cpp.html#a10">00237</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a10">ID3_AddTitle</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keywordtype">bool</font> replace) 00238 { 00239 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00240 <font class="keywordflow">if</font> (NULL != tag && NULL != text && strlen(text) > 0) 00241 { 00242 <font class="keywordflow">if</font> (replace) 00243 { 00244 <a class="code" href="misc__support_8h.html#a11">ID3_RemoveTitles</a>(tag); 00245 } 00246 <font class="keywordflow">if</font> (replace || tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a131">ID3FID_TITLE</a>) == NULL) 00247 { 00248 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#a219a131">ID3FID_TITLE</a>); 00249 <font class="keywordflow">if</font> (frame) 00250 { 00251 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); 00252 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00253 } 00254 } 00255 } 00256 00257 <font class="keywordflow">return</font> frame; 00258 } 00259 <a name="l00260"></a><a class="code" href="misc__support_8cpp.html#a11">00260</a> size_t <a class="code" href="misc__support_8h.html#a11">ID3_RemoveTitles</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00261 { 00262 size_t num_removed = 0; 00263 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00264 00265 <font class="keywordflow">if</font> (NULL == tag) 00266 { 00267 <font class="keywordflow">return</font> num_removed; 00268 } 00269 00270 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a131">ID3FID_TITLE</a>))) 00271 { 00272 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00273 <font class="keyword">delete</font> frame; 00274 num_removed++; 00275 } 00276 00277 <font class="keywordflow">return</font> num_removed; 00278 } 00279 <a name="l00280"></a><a class="code" href="misc__support_8cpp.html#a12">00280</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a12">ID3_GetYear</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00281 { 00282 <font class="keywordtype">char</font> *sYear = <a class="code" href="globals_8h.html#a24">NULL</a>; 00283 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00284 { 00285 <font class="keywordflow">return</font> sYear; 00286 } 00287 00288 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a157">ID3FID_YEAR</a>); 00289 <font class="keywordflow">if</font> (frame != <a class="code" href="globals_8h.html#a24">NULL</a>) 00290 { 00291 sYear = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00292 } 00293 <font class="keywordflow">return</font> sYear; 00294 } 00295 <a name="l00296"></a><a class="code" href="misc__support_8cpp.html#a13">00296</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a13">ID3_AddYear</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keywordtype">bool</font> replace) 00297 { 00298 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00299 <font class="keywordflow">if</font> (NULL != tag && NULL != text && strlen(text) > 0) 00300 { 00301 <font class="keywordflow">if</font> (replace) 00302 { 00303 <a class="code" href="misc__support_8h.html#a14">ID3_RemoveYears</a>(tag); 00304 } 00305 <font class="keywordflow">if</font> (replace || tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a157">ID3FID_YEAR</a>) == NULL) 00306 { 00307 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#a219a157">ID3FID_YEAR</a>); 00308 <font class="keywordflow">if</font> (NULL != frame) 00309 { 00310 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); 00311 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00312 } 00313 } 00314 } 00315 00316 <font class="keywordflow">return</font> frame; 00317 } 00318 <a name="l00319"></a><a class="code" href="misc__support_8cpp.html#a14">00319</a> size_t <a class="code" href="misc__support_8h.html#a14">ID3_RemoveYears</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00320 { 00321 size_t num_removed = 0; 00322 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00323 00324 <font class="keywordflow">if</font> (NULL == tag) 00325 { 00326 <font class="keywordflow">return</font> num_removed; 00327 } 00328 00329 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a157">ID3FID_YEAR</a>))) 00330 { 00331 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00332 <font class="keyword">delete</font> frame; 00333 num_removed++; 00334 } 00335 00336 <font class="keywordflow">return</font> num_removed; 00337 } 00338 <a name="l00339"></a><a class="code" href="misc__support_8cpp.html#a15">00339</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a15">ID3_GetComment</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font>* desc) 00340 { 00341 <font class="keywordtype">char</font> *comment = <a class="code" href="globals_8h.html#a24">NULL</a>; 00342 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00343 { 00344 <font class="keywordflow">return</font> comment; 00345 } 00346 00347 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00348 <font class="keywordflow">if</font> (desc) 00349 { 00350 frame = tag-><a class="code" href="class_i_d3___tag.html#a28">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); 00351 } 00352 <font class="keywordflow">else</font> 00353 { 00354 frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>); 00355 <font class="keywordflow">if</font>(frame == tag-><a class="code" href="class_i_d3___tag.html#a28">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>)) 00356 { 00357 frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a98">ID3FID_COMMENT</a>); 00358 } 00359 } 00360 00361 <font class="keywordflow">if</font> (frame) 00362 { 00363 comment = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00364 } 00365 <font class="keywordflow">return</font> comment; 00366 } 00367 <a name="l00368"></a><a class="code" href="misc__support_8cpp.html#a16">00368</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a18">ID3_AddComment</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keywordtype">bool</font> replace) 00369 { 00370 <font class="keywordflow">return</font> <a class="code" href="misc__support_8h.html#a18">ID3_AddComment</a>(tag, text, <font class="stringliteral">""</font>, replace); 00371 } 00372 <a name="l00373"></a><a class="code" href="misc__support_8cpp.html#a17">00373</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a18">ID3_AddComment</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, 00374 <font class="keyword">const</font> <font class="keywordtype">char</font> *desc, <font class="keywordtype">bool</font> replace) 00375 { 00376 <font class="keywordflow">return</font> <a class="code" href="misc__support_8h.html#a18">ID3_AddComment</a>(tag, text, desc, <font class="stringliteral">"XXX"</font>, replace); 00377 } 00378 <a name="l00379"></a><a class="code" href="misc__support_8cpp.html#a18">00379</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a18">ID3_AddComment</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, 00380 <font class="keyword">const</font> <font class="keywordtype">char</font> *desc, <font class="keyword">const</font> <font class="keywordtype">char</font>* lang, <font class="keywordtype">bool</font> replace) 00381 { 00382 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00383 <font class="keywordflow">if</font> (NULL != tag && 00384 NULL != text && 00385 NULL != desc && 00386 strlen(text) > 0) 00387 { 00388 <font class="keywordtype">bool</font> bAdd = <font class="keyword">true</font>; 00389 <font class="keywordflow">if</font> (replace) 00390 { 00391 <a class="code" href="misc__support_8h.html#a19">ID3_RemoveComments</a>(tag, desc); 00392 } 00393 <font class="keywordflow">else</font> 00394 { 00395 <font class="comment">// See if there is already a comment with this description</font> 00396 <a class="code" href="class_i_d3___tag_1_1_iterator.html">ID3_Tag::Iterator</a>* iter = tag-><a class="code" href="class_i_d3___tag.html#a33">CreateIterator</a>(); 00397 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = NULL; 00398 <font class="keywordflow">while</font> ((frame = iter-><a class="code" href="class_i_d3___tag_1_1_iterator.html#a0">GetNext</a>()) != NULL) 00399 { 00400 <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>) 00401 { 00402 <font class="keywordtype">char</font> *tmp_desc = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>); 00403 <font class="keywordflow">if</font> (strcmp(tmp_desc, desc) == 0) 00404 { 00405 bAdd = <font class="keyword">false</font>; 00406 } 00407 <font class="keyword">delete</font> [] tmp_desc; 00408 <font class="keywordflow">if</font> (!bAdd) 00409 { 00410 <font class="keywordflow">break</font>; 00411 } 00412 } 00413 } 00414 <font class="keyword">delete</font> iter; 00415 } 00416 <font class="keywordflow">if</font> (bAdd) 00417 { 00418 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>); 00419 <font class="keywordflow">if</font> (NULL != frame) 00420 { 00421 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); 00422 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); 00423 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); 00424 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00425 } 00426 } 00427 } 00428 <font class="keywordflow">return</font> frame; 00429 } 00430 00431 <font class="comment">// Remove all comments with the given description (remove all comments if</font> 00432 <font class="comment">// desc is NULL)</font> <a name="l00433"></a><a class="code" href="misc__support_8cpp.html#a19">00433</a> size_t <a class="code" href="misc__support_8h.html#a19">ID3_RemoveComments</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *desc) 00434 { 00435 size_t num_removed = 0; 00436 00437 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00438 { 00439 <font class="keywordflow">return</font> num_removed; 00440 } 00441 00442 <a class="code" href="class_i_d3___tag_1_1_iterator.html">ID3_Tag::Iterator</a>* iter = tag-><a class="code" href="class_i_d3___tag.html#a33">CreateIterator</a>(); 00443 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00444 <font class="keywordflow">while</font> ((frame = iter-><a class="code" href="class_i_d3___tag_1_1_iterator.html#a0">GetNext</a>()) != NULL) 00445 { 00446 <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>) 00447 { 00448 <font class="keywordtype">bool</font> remove = <font class="keyword">false</font>; 00449 <font class="comment">// A null description means remove all comments</font> 00450 <font class="keywordflow">if</font> (NULL == desc) 00451 { 00452 remove = <font class="keyword">true</font>; 00453 } 00454 <font class="keywordflow">else</font> 00455 { 00456 <font class="comment">// See if the description we have matches the description of the </font> 00457 <font class="comment">// current comment. If so, set the "remove the comment" flag to true.</font> 00458 <font class="keywordtype">char</font> *tmp_desc = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a75">ID3FN_DESCRIPTION</a>); 00459 remove = (strcmp(tmp_desc, desc) == 0); 00460 <font class="keyword">delete</font> [] tmp_desc; 00461 } 00462 <font class="keywordflow">if</font> (remove) 00463 { 00464 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00465 <font class="keyword">delete</font> frame; 00466 num_removed++; 00467 } 00468 } 00469 } 00470 <font class="keyword">delete</font> iter; 00471 00472 <font class="keywordflow">return</font> num_removed; 00473 } 00474 <a name="l00475"></a><a class="code" href="misc__support_8cpp.html#a20">00475</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a20">ID3_GetTrack</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00476 { 00477 <font class="keywordtype">char</font> *sTrack = <a class="code" href="globals_8h.html#a24">NULL</a>; 00478 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00479 { 00480 <font class="keywordflow">return</font> sTrack; 00481 } 00482 00483 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a149">ID3FID_TRACKNUM</a>); 00484 <font class="keywordflow">if</font> (frame != <a class="code" href="globals_8h.html#a24">NULL</a>) 00485 { 00486 sTrack = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00487 } 00488 <font class="keywordflow">return</font> sTrack; 00489 } 00490 <a name="l00491"></a><a class="code" href="misc__support_8cpp.html#a21">00491</a> size_t <a class="code" href="misc__support_8h.html#a21">ID3_GetTrackNum</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00492 { 00493 <font class="keywordtype">char</font> *sTrack = <a class="code" href="misc__support_8h.html#a20">ID3_GetTrack</a>(tag); 00494 size_t nTrack = 0; 00495 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> != sTrack) 00496 { 00497 nTrack = atoi(sTrack); 00498 <font class="keyword">delete</font> [] sTrack; 00499 } 00500 <font class="keywordflow">return</font> nTrack; 00501 } 00502 <a name="l00503"></a><a class="code" href="misc__support_8cpp.html#a22">00503</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a23">ID3_AddTrack</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <a class="code" href="globals_8h.html#a33">uchar</a> trk, <a class="code" href="globals_8h.html#a33">uchar</a> ttl, <font class="keywordtype">bool</font> replace) 00504 { 00505 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00506 <font class="keywordflow">if</font> (NULL != tag && trk > 0) 00507 { 00508 <font class="keywordflow">if</font> (replace) 00509 { 00510 <a class="code" href="misc__support_8h.html#a23">ID3_RemoveTracks</a>(tag); 00511 } 00512 <font class="keywordflow">if</font> (replace || NULL == tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a149">ID3FID_TRACKNUM</a>)) 00513 { 00514 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#a219a149">ID3FID_TRACKNUM</a>); 00515 <font class="keywordflow">if</font> (frame) 00516 { 00517 <font class="keywordtype">char</font> *sTrack = NULL; 00518 <font class="keywordflow">if</font> (0 == ttl) 00519 { 00520 sTrack = <font class="keyword">new</font> <font class="keywordtype">char</font>[4]; 00521 sprintf(sTrack, <font class="stringliteral">"%lu"</font>, (<a class="code" href="globals_8h.html#a37">luint</a>) trk); 00522 } 00523 <font class="keywordflow">else</font> 00524 { 00525 sTrack = <font class="keyword">new</font> <font class="keywordtype">char</font>[8]; 00526 sprintf(sTrack, <font class="stringliteral">"%lu/%lu"</font>, (<a class="code" href="globals_8h.html#a37">luint</a>) trk, (<a class="code" href="globals_8h.html#a37">luint</a>) ttl); 00527 } 00528 00529 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>(sTrack); 00530 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00531 00532 <font class="keyword">delete</font> [] sTrack; 00533 } 00534 } 00535 } 00536 00537 <font class="keywordflow">return</font> frame; 00538 } 00539 <a name="l00540"></a><a class="code" href="misc__support_8cpp.html#a23">00540</a> size_t <a class="code" href="misc__support_8h.html#a23">ID3_RemoveTracks</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00541 { 00542 size_t num_removed = 0; 00543 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00544 00545 <font class="keywordflow">if</font> (NULL == tag) 00546 { 00547 <font class="keywordflow">return</font> num_removed; 00548 } 00549 00550 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a149">ID3FID_TRACKNUM</a>))) 00551 { 00552 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00553 <font class="keyword">delete</font> frame; 00554 num_removed++; 00555 } 00556 00557 <font class="keywordflow">return</font> num_removed; 00558 } 00559 <a name="l00560"></a><a class="code" href="misc__support_8cpp.html#a24">00560</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a24">ID3_GetGenre</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00561 { 00562 <font class="keywordtype">char</font> *sGenre = <a class="code" href="globals_8h.html#a24">NULL</a>; 00563 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00564 { 00565 <font class="keywordflow">return</font> sGenre; 00566 } 00567 00568 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a122">ID3FID_CONTENTTYPE</a>); 00569 <font class="keywordflow">if</font> (frame != <a class="code" href="globals_8h.html#a24">NULL</a>) 00570 { 00571 sGenre = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00572 } 00573 00574 <font class="keywordflow">return</font> sGenre; 00575 } 00576 <a name="l00577"></a><a class="code" href="misc__support_8cpp.html#a25">00577</a> size_t <a class="code" href="misc__support_8h.html#a25">ID3_GetGenreNum</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00578 { 00579 <font class="keywordtype">char</font> *sGenre = <a class="code" href="misc__support_8h.html#a24">ID3_GetGenre</a>(tag); 00580 size_t ulGenre = 0xFF; 00581 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == sGenre) 00582 { 00583 <font class="keywordflow">return</font> ulGenre; 00584 } 00585 00586 <font class="comment">// If the genre string begins with "(ddd)", where "ddd" is a number, then </font> 00587 <font class="comment">// "ddd" is the genre number---get it</font> 00588 <font class="keywordflow">if</font> (sGenre[0] == <font class="charliteral">'('</font>) 00589 { 00590 <font class="keywordtype">char</font> *pCur = &sGenre[1]; 00591 <font class="keywordflow">while</font> (isdigit(*pCur)) 00592 { 00593 pCur++; 00594 } 00595 <font class="keywordflow">if</font> (*pCur == <font class="charliteral">')'</font>) 00596 { 00597 <font class="comment">// if the genre number is greater than 255, its invalid.</font> 00598 ulGenre = dami::min(0xFF, atoi(&sGenre[1])); 00599 } 00600 } 00601 00602 <font class="keyword">delete</font> [] sGenre; 00603 <font class="keywordflow">return</font> ulGenre; 00604 } 00605 <a name="l00606"></a><a class="code" href="misc__support_8cpp.html#a26">00606</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a26">ID3_AddGenre</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, size_t genre, <font class="keywordtype">bool</font> replace) 00607 { 00608 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00609 <font class="keywordflow">if</font> (NULL != tag && 0xFF != genre) 00610 { 00611 <font class="keywordflow">if</font> (replace) 00612 { 00613 <a class="code" href="misc__support_8h.html#a27">ID3_RemoveGenres</a>(tag); 00614 } 00615 <font class="keywordflow">if</font> (replace || NULL == tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a122">ID3FID_CONTENTTYPE</a>)) 00616 { 00617 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#a219a122">ID3FID_CONTENTTYPE</a>); 00618 <font class="keywordflow">if</font> (NULL != frame) 00619 { 00620 <font class="keywordtype">char</font> sGenre[6]; 00621 sprintf(sGenre, <font class="stringliteral">"(%lu)"</font>, (<a class="code" href="globals_8h.html#a37">luint</a>) genre); 00622 00623 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>(sGenre); 00624 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00625 } 00626 } 00627 } 00628 00629 <font class="keywordflow">return</font> frame; 00630 } 00631 <a name="l00632"></a><a class="code" href="misc__support_8cpp.html#a27">00632</a> size_t <a class="code" href="misc__support_8h.html#a27">ID3_RemoveGenres</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00633 { 00634 size_t num_removed = 0; 00635 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00636 00637 <font class="keywordflow">if</font> (NULL == tag) 00638 { 00639 <font class="keywordflow">return</font> num_removed; 00640 } 00641 00642 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a122">ID3FID_CONTENTTYPE</a>))) 00643 { 00644 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00645 <font class="keyword">delete</font> frame; 00646 num_removed++; 00647 } 00648 00649 <font class="keywordflow">return</font> num_removed; 00650 } 00651 <a name="l00652"></a><a class="code" href="misc__support_8cpp.html#a28">00652</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a28">ID3_GetLyrics</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00653 { 00654 <font class="keywordtype">char</font> *sLyrics = <a class="code" href="globals_8h.html#a24">NULL</a>; 00655 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00656 { 00657 <font class="keywordflow">return</font> sLyrics; 00658 } 00659 00660 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a160">ID3FID_UNSYNCEDLYRICS</a>); 00661 <font class="keywordflow">if</font> (frame != <a class="code" href="globals_8h.html#a24">NULL</a>) 00662 { 00663 sLyrics = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00664 } 00665 <font class="keywordflow">return</font> sLyrics; 00666 } 00667 <a name="l00668"></a><a class="code" href="misc__support_8cpp.html#a29">00668</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a31">ID3_AddLyrics</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keywordtype">bool</font> replace) 00669 { 00670 <font class="keywordflow">return</font> <a class="code" href="misc__support_8h.html#a31">ID3_AddLyrics</a>(tag, text, <font class="stringliteral">""</font>, replace); 00671 } 00672 <a name="l00673"></a><a class="code" href="misc__support_8cpp.html#a30">00673</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a31">ID3_AddLyrics</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keyword">const</font> <font class="keywordtype">char</font>* desc, 00674 <font class="keywordtype">bool</font> replace) 00675 { 00676 <font class="keywordflow">return</font> <a class="code" href="misc__support_8h.html#a31">ID3_AddLyrics</a>(tag, text, desc, <font class="stringliteral">"XXX"</font>, replace); 00677 } 00678 <a name="l00679"></a><a class="code" href="misc__support_8cpp.html#a31">00679</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a31">ID3_AddLyrics</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keyword">const</font> <font class="keywordtype">char</font>* desc, 00680 <font class="keyword">const</font> <font class="keywordtype">char</font>* lang, <font class="keywordtype">bool</font> replace) 00681 { 00682 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00683 <font class="keywordflow">if</font> (NULL != tag && strlen(text) > 0) 00684 { 00685 <font class="keywordflow">if</font> (replace) 00686 { 00687 <a class="code" href="misc__support_8h.html#a32">ID3_RemoveLyrics</a>(tag); 00688 } 00689 <font class="keywordflow">if</font> (replace || tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a160">ID3FID_UNSYNCEDLYRICS</a>) == NULL) 00690 { 00691 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>); 00692 <font class="keywordflow">if</font> (NULL != frame) 00693 { 00694 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); 00695 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); 00696 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); 00697 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00698 } 00699 } 00700 } 00701 00702 <font class="keywordflow">return</font> frame; 00703 } 00704 <a name="l00705"></a><a class="code" href="misc__support_8cpp.html#a32">00705</a> size_t <a class="code" href="misc__support_8h.html#a32">ID3_RemoveLyrics</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00706 { 00707 size_t num_removed = 0; 00708 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00709 00710 <font class="keywordflow">if</font> (NULL == tag) 00711 { 00712 <font class="keywordflow">return</font> num_removed; 00713 } 00714 00715 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a160">ID3FID_UNSYNCEDLYRICS</a>))) 00716 { 00717 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00718 <font class="keyword">delete</font> frame; 00719 num_removed++; 00720 } 00721 00722 <font class="keywordflow">return</font> num_removed; 00723 } 00724 <a name="l00725"></a><a class="code" href="misc__support_8cpp.html#a33">00725</a> <font class="keywordtype">char</font> *<a class="code" href="misc__support_8h.html#a33">ID3_GetLyricist</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00726 { 00727 <font class="keywordtype">char</font> *sLyricist = <a class="code" href="globals_8h.html#a24">NULL</a>; 00728 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == tag) 00729 { 00730 <font class="keywordflow">return</font> sLyricist; 00731 } 00732 00733 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a127">ID3FID_LYRICIST</a>); 00734 <font class="keywordflow">if</font> (frame != <a class="code" href="globals_8h.html#a24">NULL</a>) 00735 { 00736 sLyricist = <a class="code" href="misc__support_8h.html#a1">ID3_GetString</a>(frame, <a class="code" href="globals_8h.html#a218a72">ID3FN_TEXT</a>); 00737 } 00738 <font class="keywordflow">return</font> sLyricist; 00739 } 00740 <a name="l00741"></a><a class="code" href="misc__support_8cpp.html#a34">00741</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a34">ID3_AddLyricist</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keywordtype">bool</font> replace) 00742 { 00743 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00744 <font class="keywordflow">if</font> (NULL != tag && NULL != text && strlen(text) > 0) 00745 { 00746 <font class="keywordflow">if</font> (replace) 00747 { 00748 <a class="code" href="misc__support_8h.html#a35">ID3_RemoveLyricist</a>(tag); 00749 } 00750 <font class="keywordflow">if</font> (replace || (tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a127">ID3FID_LYRICIST</a>) == NULL)) 00751 { 00752 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#a219a127">ID3FID_LYRICIST</a>); 00753 <font class="keywordflow">if</font> (frame) 00754 { 00755 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); 00756 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00757 } 00758 } 00759 } 00760 00761 <font class="keywordflow">return</font> frame; 00762 } 00763 <a name="l00764"></a><a class="code" href="misc__support_8cpp.html#a35">00764</a> size_t <a class="code" href="misc__support_8h.html#a35">ID3_RemoveLyricist</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag) 00765 { 00766 size_t num_removed = 0; 00767 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00768 00769 <font class="keywordflow">if</font> (NULL == tag) 00770 { 00771 <font class="keywordflow">return</font> num_removed; 00772 } 00773 00774 <font class="keywordflow">while</font> ((frame = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a127">ID3FID_LYRICIST</a>))) 00775 { 00776 frame = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a>(frame); 00777 <font class="keyword">delete</font> frame; 00778 num_removed++; 00779 } 00780 00781 <font class="keywordflow">return</font> num_removed; 00782 } 00783 <a name="l00784"></a><a class="code" href="misc__support_8cpp.html#a36">00784</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a39">ID3_AddSyncLyrics</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <a class="code" href="globals_8h.html#a33">uchar</a> *data, size_t datasize, 00785 <a class="code" href="globals_8h.html#a225">ID3_TimeStampFormat</a> format, <font class="keywordtype">bool</font> replace) 00786 { 00787 <font class="keywordflow">return</font> <a class="code" href="misc__support_8h.html#a39">ID3_AddSyncLyrics</a>(tag, data, datasize, format, <font class="stringliteral">""</font>, replace); 00788 } 00789 <a name="l00790"></a><a class="code" href="misc__support_8cpp.html#a37">00790</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a39">ID3_AddSyncLyrics</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <a class="code" href="globals_8h.html#a33">uchar</a> *data, size_t datasize, 00791 <a class="code" href="globals_8h.html#a225">ID3_TimeStampFormat</a> format, <font class="keyword">const</font> <font class="keywordtype">char</font> *desc, 00792 <font class="keywordtype">bool</font> replace) 00793 { 00794 <font class="keywordflow">return</font> <a class="code" href="misc__support_8h.html#a39">ID3_AddSyncLyrics</a>(tag, data, datasize, format, desc, <font class="stringliteral">"XXX"</font>, replace); 00795 } 00796 <a name="l00797"></a><a class="code" href="misc__support_8cpp.html#a38">00797</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a39">ID3_AddSyncLyrics</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <a class="code" href="globals_8h.html#a33">uchar</a> *data, size_t datasize, 00798 <a class="code" href="globals_8h.html#a225">ID3_TimeStampFormat</a> format, <font class="keyword">const</font> <font class="keywordtype">char</font> *desc, 00799 <font class="keyword">const</font> <font class="keywordtype">char</font> *lang, <font class="keywordtype">bool</font> replace) 00800 { 00801 <font class="keywordflow">return</font> <a class="code" href="misc__support_8h.html#a39">ID3_AddSyncLyrics</a>(tag, data, datasize, format, desc, lang, 00802 <a class="code" href="globals_8h.html#a224a206">ID3CT_LYRICS</a>, replace); 00803 } 00804 <a name="l00805"></a><a class="code" href="misc__support_8cpp.html#a39">00805</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="misc__support_8h.html#a39">ID3_AddSyncLyrics</a>(<a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <a class="code" href="globals_8h.html#a33">uchar</a> *data, size_t datasize, 00806 <a class="code" href="globals_8h.html#a225">ID3_TimeStampFormat</a> format, <font class="keyword">const</font> <font class="keywordtype">char</font> *desc, 00807 <font class="keyword">const</font> <font class="keywordtype">char</font> *lang, <a class="code" href="globals_8h.html#a224">ID3_ContentType</a> type, 00808 <font class="keywordtype">bool</font> replace) 00809 { 00810 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>; 00811 <font class="comment">// language and descriptor should be mandatory</font> 00812 <font class="keywordflow">if</font> ((NULL == lang) || (NULL == desc)) 00813 { 00814 <font class="keywordflow">return</font> NULL; 00815 } 00816 00817 <font class="comment">// check if a SYLT frame of this language or descriptor already exists</font> 00818 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frmExist = tag-><a class="code" href="class_i_d3___tag.html#a28">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); 00819 <font class="keywordflow">if</font> (!frmExist) 00820 { 00821 frmExist = tag-><a class="code" href="class_i_d3___tag.html#a28">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); 00822 } 00823 00824 <font class="keywordflow">if</font> (NULL != tag && NULL != data) 00825 { 00826 <font class="keywordflow">if</font> (replace && frmExist) 00827 { 00828 frmExist = tag-><a class="code" href="class_i_d3___tag.html#a16">RemoveFrame</a> (frmExist); 00829 <font class="keyword">delete</font> frmExist; 00830 frmExist = NULL; 00831 } 00832 00833 <font class="comment">// if the frame still exist, cannot continue</font> 00834 <font class="keywordflow">if</font> (frmExist) 00835 { 00836 <font class="keywordflow">return</font> NULL; 00837 } 00838 00839 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* 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>); 00840 00841 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); 00842 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); 00843 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_TIMESTAMPFORMAT)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(format); 00844 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_CONTENTTYPE)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(type); 00845 frame-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_DATA)-><a class="code" href="class_i_d3___field.html#a5">Set</a>(data, datasize); 00846 tag-><a class="code" href="class_i_d3___tag.html#a15">AttachFrame</a>(frame); 00847 } 00848 00849 <font class="keywordflow">return</font> frame; 00850 } 00851 <a name="l00852"></a><a class="code" href="misc__support_8cpp.html#a40">00852</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *<a class="code" href="misc__support_8h.html#a41">ID3_GetSyncLyricsInfo</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *desc, 00853 <font class="keyword">const</font> <font class="keywordtype">char</font> *lang, 00854 <a class="code" href="globals_8h.html#a225">ID3_TimeStampFormat</a>& format, 00855 <a class="code" href="globals_8h.html#a224">ID3_ContentType</a>& type, size_t& size) 00856 { 00857 <font class="comment">// check if a SYLT frame of this language or descriptor exists</font> 00858 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frmExist = <a class="code" href="globals_8h.html#a24">NULL</a>; 00859 <font class="keywordflow">if</font> (NULL != lang) 00860 { 00861 <font class="comment">// search through language</font> 00862 frmExist = tag-><a class="code" href="class_i_d3___tag.html#a28">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); 00863 } 00864 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (NULL != desc) 00865 { 00866 <font class="comment">// search through descriptor</font> 00867 frmExist = tag-><a class="code" href="class_i_d3___tag.html#a28">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); 00868 } 00869 <font class="keywordflow">else</font> 00870 { 00871 <font class="comment">// both language and description not specified, search the first SYLT frame</font> 00872 frmExist = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>); 00873 } 00874 00875 <font class="keywordflow">if</font> (!frmExist) 00876 { 00877 <font class="keywordflow">return</font> NULL; 00878 } 00879 00880 <font class="comment">// get the lyrics time stamp format</font> 00881 format = static_cast<ID3_TimeStampFormat>(frmExist-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_TIMESTAMPFORMAT)-><a class="code" href="class_i_d3___field.html#a6">Get</a> ()); 00882 00883 <font class="comment">// get the lyrics content type</font> 00884 type = static_cast<ID3_ContentType>(frmExist-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_CONTENTTYPE)-><a class="code" href="class_i_d3___field.html#a6">Get</a> ()); 00885 00886 <font class="comment">// get the lyrics size</font> 00887 size = frmExist-><a class="code" href="class_i_d3___frame.html#a6">GetField</a> (ID3FN_DATA)-><a class="code" href="class_i_d3___field.html#a1">Size</a> (); 00888 00889 <font class="comment">// return the frame pointer for further uses</font> 00890 <font class="keywordflow">return</font> frmExist; 00891 } 00892 <a name="l00893"></a><a class="code" href="misc__support_8cpp.html#a41">00893</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *<a class="code" href="misc__support_8h.html#a42">ID3_GetSyncLyrics</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> *tag, <font class="keyword">const</font> <font class="keywordtype">char</font> *lang, 00894 <font class="keyword">const</font> <font class="keywordtype">char</font> *desc, <font class="keyword">const</font> <a class="code" href="globals_8h.html#a33">uchar</a> *pData, size_t& size) 00895 { 00896 <font class="comment">// check if a SYLT frame of this language or descriptor exists</font> 00897 <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frmExist = <a class="code" href="globals_8h.html#a24">NULL</a>; 00898 <font class="keywordflow">if</font> (NULL != lang) 00899 { 00900 <font class="comment">// search through language</font> 00901 frmExist = tag-><a class="code" href="class_i_d3___tag.html#a28">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); 00902 } 00903 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (NULL != desc) 00904 { 00905 <font class="comment">// search through descriptor</font> 00906 frmExist = tag-><a class="code" href="class_i_d3___tag.html#a28">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); 00907 } 00908 <font class="keywordflow">else</font> 00909 { 00910 <font class="comment">// both language and description not specified, search the first SYLT frame</font> 00911 frmExist = tag-><a class="code" href="class_i_d3___tag.html#a28">Find</a>(<a class="code" href="globals_8h.html#a219a117">ID3FID_SYNCEDLYRICS</a>); 00912 } 00913 00914 <font class="keywordflow">if</font> (NULL == frmExist) 00915 { 00916 <font class="keywordflow">return</font> NULL; 00917 } 00918 00919 <font class="comment">// get the lyrics size</font> 00920 size = dami::min(size, frmExist-><a class="code" href="class_i_d3___frame.html#a6">GetField</a>(ID3FN_DATA)-><a class="code" href="class_i_d3___field.html#a1">Size</a>()); 00921 00922 <font class="comment">// get the lyrics data</font> 00923 pData = frmExist-><a class="code" href="class_i_d3___frame.html#a6">GetField</a> (ID3FN_DATA)-><a class="code" href="class_i_d3___field.html#a23">GetRawBinary</a>(); 00924 00925 <font class="comment">// return the frame pointer for further uses</font> 00926 <font class="keywordflow">return</font> frmExist; 00927 } 00928 </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>