mp4tag/mp4tag.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003 copyright            : (C) 2005 by Andy Leadbetter
00004 email                : andrew.leadbetter@gmail.com
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *   This library is free software; you can redistribute it and/or modify  *
00009  *   it  under the terms of the GNU Lesser General Public License version  *
00010  *   2.1 as published by the Free Software Foundation.                     *
00011  *                                                                         *
00012  *   This library is distributed in the hope that it will be useful, but   *
00013  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00015  *   Lesser General Public License for more details.                       *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU Lesser General Public      *
00018  *   License along with this library; if not, write to the Free Software   *
00019  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,            *
00020  *   MA  02110-1301  USA                                                   *
00021  ***************************************************************************/
00022 
00023 #include "mp4tag.h"
00024 
00025 #include <tag.h>
00026 #include <stdint.h>
00027 
00028 using namespace TagLib;
00029 
00030 MP4::Tag::Tag() : TagLib::Tag::Tag() {
00031     m_title = String::null;
00032     m_artist = String::null;
00033     m_album = String::null;
00034     m_comment = String::null;
00035     m_genre = String::null;
00036     m_composer = String::null;
00037     m_year = 0;
00038     m_track = 0;
00039     m_disk = 0;
00040     m_bpm = 0;
00041     m_compilation = Undefined;
00042 }
00043 
00044 MP4::Tag::~Tag() {
00045 }
00046 
00047 bool MP4::Tag::isEmpty() const {
00048     return  m_title == String::null &&
00049         m_artist == String::null &&
00050         m_album == String::null && 
00051         m_comment == String::null &&
00052         m_genre == String::null &&
00053         m_composer == String::null &&
00054         m_year == 0 &&
00055         m_track == 0 &&
00056         m_disk == 0 &&
00057         m_bpm == 0 &&
00058         m_compilation == Undefined &&
00059         m_image.size() == 0;
00060 }
00061 
00062 void MP4::Tag::duplicate(const Tag *source, Tag *target, bool overwrite) {
00063     // Duplicate standard information
00064     Tag::duplicate(source, target, overwrite);
00065 
00066     if (overwrite || target->compilation() == Undefined && source->compilation() != Undefined)
00067         target->setCompilation(source->compilation());
00068 
00069     if (overwrite || target->cover().size() == 0)
00070         target->setCover(source->cover());
00071 }
00072 
00073 void MP4::Tag::readTags( MP4FileHandle mp4file )
00074 {
00075     // Now parse tag.
00076     char *value;
00077     uint8_t boolvalue;
00078     uint16_t numvalue, numvalue2;
00079     uint8_t *image;
00080     uint32_t imageSize;
00081     if (MP4GetMetadataName(mp4file, &value) && value != NULL) {
00082         m_title = String(value, String::UTF8);
00083         free(value);
00084     }
00085     if (MP4GetMetadataArtist(mp4file, &value) && value != NULL) {
00086         m_artist = String(value, String::UTF8);
00087         free(value);
00088     }
00089 
00090     if (MP4GetMetadataComment(mp4file, &value) && value != NULL) {
00091         m_comment = String(value, String::UTF8);
00092         free(value);
00093     }
00094 
00095     if (MP4GetMetadataYear(mp4file, &value) && value != NULL) {
00096         m_year = strtol(value, NULL,0);
00097         free(value);
00098     }
00099     if (MP4GetMetadataAlbum(mp4file, &value) && value != NULL) {
00100         m_album  =  String(value, String::UTF8);
00101         free(value);
00102     }
00103     if (MP4GetMetadataTrack(mp4file, &numvalue, &numvalue2)) {
00104         m_track = numvalue;
00105     }
00106     if (MP4GetMetadataDisk(mp4file, &numvalue, &numvalue2)) {
00107         m_disk = numvalue;
00108     }
00109     if (MP4GetMetadataTempo(mp4file, &numvalue)) {
00110         m_bpm = numvalue;
00111     }
00112     if (MP4GetMetadataCompilation(mp4file, &boolvalue)) {
00113         m_compilation = boolvalue;
00114     }
00115     if (MP4GetMetadataGenre(mp4file, &value) && value != NULL) {
00116         m_genre = String(value, String::UTF8);
00117         free(value);
00118     }
00119     if (MP4GetMetadataWriter(mp4file, &value) && value != NULL) {
00120         m_composer = String(value, String::UTF8);
00121         free(value);
00122     }
00123     if (MP4GetMetadataCoverArt(mp4file, &image, &imageSize) && image && imageSize) {
00124         m_image.setData(reinterpret_cast<const char *>( image ), imageSize);
00125         free(image);
00126     }
00127 }

Generated on Mon Aug 6 21:24:20 2007 for plai by  doxygen 1.5.1