Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 2c9d30f3cf217a6cae41860ebc0d6704 > files > 203

libid3lib3.8_0-devel-3.8.0-0.pre2.1.1mdk.i586.rpm

<!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/tag_render.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> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>src/tag_render.cpp</h1><a href="tag__render_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// $Id: tag_render.cpp,v 1.39 2001/12/16 09:56:51 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 &lt;config.h&gt;</font>
00029 <font class="preprocessor">#endif</font>
00030 <font class="preprocessor"></font>
00031 
00032 
00033 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00034 <font class="preprocessor">#include &lt;string.h&gt;</font>
00035 <font class="preprocessor">#include &lt;memory.h&gt;</font>
00036 <font class="preprocessor">#include "<a class="code" href="tag__impl_8h.html">tag_impl.h</a>"</font>
00037 <font class="preprocessor">#include "helpers.h"</font>
00038 <font class="preprocessor">#include "utils.h"</font>
00039 <font class="preprocessor">#include "<a class="code" href="writers_8h.html">writers.h</a>"</font>
00040 <font class="preprocessor">#include "io_decorators.h"</font>
00041 <font class="preprocessor">#include "io_helpers.h"</font>
00042 <font class="preprocessor">#include "io_strings.h"</font>
00043 
00044 <font class="preprocessor">#if defined HAVE_SYS_PARAM_H</font>
00045 <font class="preprocessor"></font><font class="preprocessor">#include &lt;sys/param.h&gt;</font>
00046 <font class="preprocessor">#endif</font>
00047 <font class="preprocessor"></font>
00048 <font class="keyword">using</font> <font class="keyword">namespace </font>dami;
00049 
00050 <font class="keywordtype">void</font> id3::v1::render(<a class="code" href="class_i_d3___writer.html">ID3_Writer</a>&amp; writer, <font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>&amp; tag)
00051 {
00052   writer.<a class="code" href="class_i_d3___writer.html#a8">writeChars</a>(<font class="stringliteral">"TAG"</font>, 3);
00053   
00054   io::writeTrailingSpaces(writer, id3::v2::getTitle(tag),  <a class="code" href="globals_8h.html#a220a175">ID3_V1_LEN_TITLE</a>);
00055   io::writeTrailingSpaces(writer, id3::v2::getArtist(tag), <a class="code" href="globals_8h.html#a220a176">ID3_V1_LEN_ARTIST</a>);
00056   io::writeTrailingSpaces(writer, id3::v2::getAlbum(tag),  <a class="code" href="globals_8h.html#a220a177">ID3_V1_LEN_ALBUM</a>);
00057   io::writeTrailingSpaces(writer, id3::v2::getYear(tag),   <a class="code" href="globals_8h.html#a220a178">ID3_V1_LEN_YEAR</a>);
00058   
00059   size_t track = id3::v2::getTrackNum(tag);
00060   String comment = id3::v2::getV1Comment(tag);
00061   <font class="keywordflow">if</font> (track &gt; 0)
00062   {
00063     io::writeTrailingSpaces(writer, comment, <a class="code" href="globals_8h.html#a220a179">ID3_V1_LEN_COMMENT</a> - 2);
00064     writer.<a class="code" href="class_i_d3___writer.html#a7">writeChar</a>(<font class="charliteral">'\0'</font>);
00065     writer.<a class="code" href="class_i_d3___writer.html#a7">writeChar</a>((<font class="keywordtype">char</font>) track);
00066   }
00067   <font class="keywordflow">else</font>
00068   {
00069     io::writeTrailingSpaces(writer, comment, <a class="code" href="globals_8h.html#a220a179">ID3_V1_LEN_COMMENT</a>);
00070   }
00071   writer.<a class="code" href="class_i_d3___writer.html#a7">writeChar</a>((<font class="keywordtype">char</font>) id3::v2::getGenreNum(tag));
00072 }
00073 
00074 <font class="keyword">namespace</font>
00075 <font class="keyword"></font>{
00076   <font class="keywordtype">void</font> renderFrames(<a class="code" href="class_i_d3___writer.html">ID3_Writer</a>&amp; writer, <font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>&amp; tag)
00077   {
00078     <font class="keywordflow">for</font> (<a class="code" href="class_i_d3___tag_impl.html#s1">ID3_TagImpl::const_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)
00079     {
00080       <font class="keyword">const</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = *iter;
00081       <font class="keywordflow">if</font> (frame) frame-&gt;<a class="code" href="class_i_d3___frame.html#a13">Render</a>(writer);
00082     }
00083   }
00084 }
00085 
00086 <font class="keywordtype">void</font> id3::v2::render(<a class="code" href="class_i_d3___writer.html">ID3_Writer</a>&amp; writer, <font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>&amp; tag)
00087 {
00088   <font class="comment">// There has to be at least one frame for there to be a tag...</font>
00089   <font class="keywordflow">if</font> (tag.<a class="code" href="class_i_d3___tag_impl.html#a29">NumFrames</a>() == 0)
00090   {
00091     ID3D_WARNING( <font class="stringliteral">"id3::v2::render(): no frames to render"</font> );
00092     <font class="keywordflow">return</font>;
00093   }
00094   
00095   ID3D_NOTICE( <font class="stringliteral">"id3::v2::render(): rendering"</font> );
00096   <a class="code" href="class_i_d3___tag_header.html">ID3_TagHeader</a> hdr;
00097   hdr.<a class="code" href="class_i_d3___tag_header.html#a3">SetSpec</a>(tag.<a class="code" href="class_i_d3___tag_impl.html#a32">GetSpec</a>());
00098   hdr.<a class="code" href="class_i_d3___tag_header.html#a10">SetExtended</a>(tag.<a class="code" href="class_i_d3___tag_impl.html#a12">GetExtended</a>());
00099   hdr.<a class="code" href="class_i_d3___tag_header.html#a12">SetExperimental</a>(tag.<a class="code" href="class_i_d3___tag_impl.html#a13">GetExperimental</a>());
00100     
00101   <font class="comment">// set up the encryption and grouping IDs</font>
00102 
00103   <font class="comment">// ...</font>
00104   String frms;
00105   io::StringWriter frmWriter(frms);
00106   <font class="keywordflow">if</font> (!tag.<a class="code" href="class_i_d3___tag_impl.html#a11">GetUnsync</a>())
00107   {
00108     ID3D_NOTICE( <font class="stringliteral">"id3::v2::render(): rendering frames"</font> );
00109     renderFrames(frmWriter, tag);
00110     hdr.<a class="code" href="class_i_d3___tag_header.html#a8">SetUnsync</a>(<font class="keyword">false</font>);
00111   }
00112   <font class="keywordflow">else</font>
00113   {
00114     ID3D_NOTICE( <font class="stringliteral">"id3::v2::render(): rendering unsynced frames"</font> );
00115     io::UnsyncedWriter uw(frmWriter);
00116     renderFrames(uw, tag);
00117     uw.flush();
00118     ID3D_NOTICE( <font class="stringliteral">"id3::v2::render(): numsyncs = "</font> &lt;&lt; uw.getNumSyncs() );
00119     hdr.<a class="code" href="class_i_d3___tag_header.html#a8">SetUnsync</a>(uw.getNumSyncs() &gt; 0);
00120   }
00121   size_t frmSize = frms.size();
00122   <font class="keywordflow">if</font> (frmSize == 0)
00123   {
00124     ID3D_WARNING( <font class="stringliteral">"id3::v2::render(): rendered frame size is 0 bytes"</font> );
00125     <font class="keywordflow">return</font>;
00126   }
00127   
00128   <font class="comment">// zero the remainder of the buffer so that our padding bytes are zero</font>
00129   <a class="code" href="globals_8h.html#a37">luint</a> nPadding = tag.<a class="code" href="class_i_d3___tag_impl.html#a45">PaddingSize</a>(frmSize);
00130   ID3D_NOTICE( <font class="stringliteral">"id3::v2::render(): padding size = "</font> &lt;&lt; nPadding );
00131   hdr.<a class="code" href="class_i_d3___header.html#a4">SetDataSize</a>(frmSize + nPadding);
00132   
00133   hdr.<a class="code" href="class_i_d3___tag_header.html#a5">Render</a>(writer);
00134 
00135   writer.<a class="code" href="class_i_d3___writer.html#a8">writeChars</a>(frms.data(), frms.size());
00136 
00137   <font class="keywordflow">for</font> (size_t i = 0; i &lt; nPadding; ++i)
00138   {
00139     <font class="keywordflow">if</font> (writer.<a class="code" href="class_i_d3___writer.html#a7">writeChar</a>(<font class="charliteral">'\0'</font>) == <a class="code" href="class_i_d3___writer.html#p0">ID3_Writer::END_OF_WRITER</a>)
00140     {
00141       <font class="keywordflow">break</font>;
00142     }
00143   }
00144 }
00145 
<a name="l00146"></a><a class="code" href="class_i_d3___tag_impl.html#a6">00146</a> size_t <a class="code" href="class_i_d3___tag_impl.html#a6">ID3_TagImpl::Size</a>()<font class="keyword"> const</font>
00147 <font class="keyword"></font>{
00148   <font class="keywordflow">if</font> (this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a29">NumFrames</a>() == 0)
00149   {
00150     <font class="keywordflow">return</font> 0;
00151   }
00152   <a class="code" href="class_i_d3___tag_header.html">ID3_TagHeader</a> hdr;
00153 
00154   hdr.<a class="code" href="class_i_d3___tag_header.html#a3">SetSpec</a>(this-&gt;GetSpec());
00155   size_t bytesUsed = hdr.<a class="code" href="class_i_d3___tag_header.html#a4">Size</a>();
00156   
00157   size_t frameBytes = 0;
00158   <font class="keywordflow">for</font> (<a class="code" href="class_i_d3___tag_impl.html#s1">const_iterator</a> cur = _frames.begin(); cur != _frames.end(); ++cur)
00159   {
00160     <font class="keywordflow">if</font> (*cur)
00161     {
00162       (*cur)-&gt;SetSpec(this-&gt;GetSpec());
00163       frameBytes += (*cur)-&gt;Size();
00164     }
00165   }
00166   
00167   <font class="keywordflow">if</font> (!frameBytes)
00168   {
00169     <font class="keywordflow">return</font> 0;
00170   }
00171   
00172   bytesUsed += frameBytes;
00173   <font class="comment">// add 30% for sync</font>
00174   <font class="keywordflow">if</font> (this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a11">GetUnsync</a>())
00175   {
00176     bytesUsed += bytesUsed / 3;
00177   }
00178     
00179   bytesUsed += this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a45">PaddingSize</a>(bytesUsed);
00180   <font class="keywordflow">return</font> bytesUsed;
00181 }
00182 
00183 
<a name="l00184"></a><a class="code" href="class_i_d3___tag_impl.html#b2">00184</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___tag_impl.html#b2">ID3_TagImpl::RenderExtHeader</a>(<a class="code" href="globals_8h.html#a33">uchar</a> *buffer)
00185 {
00186   <font class="keywordflow">if</font> (this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a32">GetSpec</a>() == <a class="code" href="globals_8h.html#a216a55">ID3V2_3_0</a>)
00187   {
00188   }
00189   
00190   <font class="keywordflow">return</font> ;
00191 }
00192 
00193 
<a name="l00194"></a><a class="code" href="tag__render_8cpp.html#a0">00194</a> <font class="preprocessor">#define ID3_PADMULTIPLE (2048)</font>
<a name="l00195"></a><a class="code" href="tag__render_8cpp.html#a1">00195</a> <font class="preprocessor"></font><font class="preprocessor">#define ID3_PADMAX  (4096)</font>
00196 <font class="preprocessor"></font>
00197 
<a name="l00198"></a><a class="code" href="class_i_d3___tag_impl.html#a45">00198</a> size_t <a class="code" href="class_i_d3___tag_impl.html#a45">ID3_TagImpl::PaddingSize</a>(size_t curSize)<font class="keyword"> const</font>
00199 <font class="keyword"></font>{
00200   <a class="code" href="globals_8h.html#a37">luint</a> newSize = 0;
00201   
00202   <font class="comment">// if padding is switched off or there is no attached file</font>
00203   <font class="keywordflow">if</font> (! _is_padded || !this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a21">GetPrependedBytes</a>())
00204   {
00205     <font class="keywordflow">return</font> 0;
00206   }
00207     
00208   <font class="comment">// if the old tag was large enough to hold the new tag, then we will simply</font>
00209   <font class="comment">// pad out the difference - that way the new tag can be written without</font>
00210   <font class="comment">// shuffling the rest of the song file around</font>
00211   <font class="keywordflow">if</font> (this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a21">GetPrependedBytes</a>() &amp;&amp; (this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a21">GetPrependedBytes</a>() &gt;= curSize) &amp;&amp; 
00212       (this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a21">GetPrependedBytes</a>() - curSize) &lt; <a class="code" href="tag__render_8cpp.html#a1">ID3_PADMAX</a>)
00213   {
00214     newSize = this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a21">GetPrependedBytes</a>()-<a class="code" href="class_i_d3___tag_header.html#s10s8">ID3_TagHeader::SIZE</a>;
00215   }
00216   <font class="keywordflow">else</font>
00217   {
00218     <a class="code" href="globals_8h.html#a37">luint</a> tempSize = curSize + <a class="code" href="tag__impl_8h.html#a0">ID3_GetDataSize</a>(*<font class="keyword">this</font>);
00219     
00220     <font class="comment">// this method of automatic padding rounds the COMPLETE FILE up to the</font>
00221     <font class="comment">// nearest 2K.  If the file will already be an even multiple of 2K (with</font>
00222     <font class="comment">// the tag included) then we just add another 2K of padding</font>
00223     tempSize = ((tempSize / <a class="code" href="tag__render_8cpp.html#a0">ID3_PADMULTIPLE</a>) + 1) * <a class="code" href="tag__render_8cpp.html#a0">ID3_PADMULTIPLE</a>;
00224     
00225     <font class="comment">// the size of the new tag is the new filesize minus the audio data</font>
00226     newSize = tempSize - <a class="code" href="tag__impl_8h.html#a0">ID3_GetDataSize</a>(*<font class="keyword">this</font>);
00227   }
00228   
00229   <font class="keywordflow">return</font> newSize - curSize;
00230 }
</pre></div><hr><address><small>Generated on Thu Jan 3 07:35:56 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>,
 &copy;&nbsp;1997-2001</small></address>
</body>
</html>