MPD 0.17~git
src/tag.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2011 The Music Player Daemon Project
00003  * http://www.musicpd.org
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #ifndef MPD_TAG_H
00021 #define MPD_TAG_H
00022 
00023 #include "gcc.h"
00024 
00025 #include <stdint.h>
00026 #include <stddef.h>
00027 #include <stdbool.h>
00028 #include <string.h>
00029 
00033 enum tag_type {
00034         TAG_ARTIST,
00035         TAG_ARTIST_SORT,
00036         TAG_ALBUM,
00037         TAG_ALBUM_ARTIST,
00038         TAG_ALBUM_ARTIST_SORT,
00039         TAG_TITLE,
00040         TAG_TRACK,
00041         TAG_NAME,
00042         TAG_GENRE,
00043         TAG_DATE,
00044         TAG_COMPOSER,
00045         TAG_PERFORMER,
00046         TAG_COMMENT,
00047         TAG_DISC,
00048 
00049         TAG_MUSICBRAINZ_ARTISTID,
00050         TAG_MUSICBRAINZ_ALBUMID,
00051         TAG_MUSICBRAINZ_ALBUMARTISTID,
00052         TAG_MUSICBRAINZ_TRACKID,
00053 
00054         TAG_NUM_OF_ITEM_TYPES
00055 };
00056 
00061 extern const char *tag_item_names[];
00062 
00068 struct tag_item {
00070         enum tag_type type;
00071 
00075         char value[sizeof(long)];
00076 } gcc_packed;
00077 
00082 struct tag {
00089         int time;
00090 
00092         struct tag_item **items;
00093 
00095         unsigned num_items;
00096 };
00097 
00102 enum tag_type
00103 tag_name_parse(const char *name);
00104 
00111 enum tag_type
00112 tag_name_parse_i(const char *name);
00113 
00117 struct tag *tag_new(void);
00118 
00122 void tag_lib_init(void);
00123 
00127 void tag_clear_items_by_type(struct tag *tag, enum tag_type type);
00128 
00132 void tag_free(struct tag *tag);
00133 
00141 void tag_begin_add(struct tag *tag);
00142 
00146 void tag_end_add(struct tag *tag);
00147 
00156 void tag_add_item_n(struct tag *tag, enum tag_type type,
00157                     const char *value, size_t len);
00158 
00166 static inline void
00167 tag_add_item(struct tag *tag, enum tag_type type, const char *value)
00168 {
00169         tag_add_item_n(tag, type, value, strlen(value));
00170 }
00171 
00175 struct tag *tag_dup(const struct tag *tag);
00176 
00183 struct tag *
00184 tag_merge(const struct tag *base, const struct tag *add);
00185 
00192 struct tag *
00193 tag_merge_replace(struct tag *base, struct tag *add);
00194 
00199 static inline bool
00200 tag_is_empty(const struct tag *tag)
00201 {
00202         return tag->num_items == 0;
00203 }
00204 
00208 static inline bool
00209 tag_is_defined(const struct tag *tag)
00210 {
00211         return !tag_is_empty(tag) || tag->time >= 0;
00212 }
00213 
00218 const char *
00219 tag_get_value(const struct tag *tag, enum tag_type type);
00220 
00225 bool tag_has_type(const struct tag *tag, enum tag_type type);
00226 
00231 bool tag_equal(const struct tag *tag1, const struct tag *tag2);
00232 
00233 #endif