2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 * Codes for the type of a tag item.
38 TAG_ALBUM_ARTIST_SORT
,
49 TAG_MUSICBRAINZ_ARTISTID
,
50 TAG_MUSICBRAINZ_ALBUMID
,
51 TAG_MUSICBRAINZ_ALBUMARTISTID
,
52 TAG_MUSICBRAINZ_TRACKID
,
58 * An array of strings, which map the #tag_type to its machine
59 * readable name (specific to the MPD protocol).
61 extern const char *tag_item_names
[];
64 * One tag value. It is a mapping of #tag_type to am arbitrary string
65 * value. Each tag can have multiple items of one tag type (although
66 * few clients support that).
69 /** the type of this item */
73 * the value of this tag; this is a variable length string
75 char value
[sizeof(long)];
79 * The meta information about a song file. It is a MPD specific
80 * subset of tags (e.g. from ID3, vorbis comments, ...).
84 * The duration of the song (in seconds). A value of zero
85 * means that the length is unknown. If the duration is
86 * really between zero and one second, you should round up to
91 /** an array of tag items */
92 struct tag_item
**items
;
94 /** the total number of tag items in the #items array */
99 * Parse the string, and convert it into a #tag_type. Returns
100 * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized.
103 tag_name_parse(const char *name
);
106 * Parse the string, and convert it into a #tag_type. Returns
107 * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized.
109 * Case does not matter.
112 tag_name_parse_i(const char *name
);
115 * Creates an empty #tag.
117 struct tag
*tag_new(void);
120 * Initializes the tag library.
122 void tag_lib_init(void);
125 * Clear all tag items with the specified type.
127 void tag_clear_items_by_type(struct tag
*tag
, enum tag_type type
);
130 * Frees a #tag object and all its items.
132 void tag_free(struct tag
*tag
);
135 * Gives an optional hint to the tag library that we will now add
136 * several tag items; this is used by the library to optimize memory
137 * allocation. Only one tag may be in this state, and this tag must
138 * not have any items yet. You must call tag_end_add() when you are
141 void tag_begin_add(struct tag
*tag
);
144 * Finishes the operation started with tag_begin_add().
146 void tag_end_add(struct tag
*tag
);
149 * Appends a new tag item.
151 * @param tag the #tag object
152 * @param type the type of the new tag item
153 * @param value the value of the tag item (not null-terminated)
154 * @param len the length of #value
156 void tag_add_item_n(struct tag
*tag
, enum tag_type type
,
157 const char *value
, size_t len
);
160 * Appends a new tag item.
162 * @param tag the #tag object
163 * @param type the type of the new tag item
164 * @param value the value of the tag item (null-terminated)
167 tag_add_item(struct tag
*tag
, enum tag_type type
, const char *value
)
169 tag_add_item_n(tag
, type
, value
, strlen(value
));
173 * Duplicates a #tag object.
175 struct tag
*tag_dup(const struct tag
*tag
);
178 * Merges the data from two tags. If both tags share data for the
179 * same tag_type, only data from "add" is used.
181 * @return a newly allocated tag, which must be freed with tag_free()
184 tag_merge(const struct tag
*base
, const struct tag
*add
);
187 * Merges the data from two tags. Any of the two may be NULL. Both
188 * are freed by this function.
190 * @return a newly allocated tag, which must be freed with tag_free()
193 tag_merge_replace(struct tag
*base
, struct tag
*add
);
196 * Returns true if the tag contains no items. This ignores the "time"
200 tag_is_empty(const struct tag
*tag
)
202 return tag
->num_items
== 0;
206 * Returns true if the tag contains any information.
209 tag_is_defined(const struct tag
*tag
)
211 return !tag_is_empty(tag
) || tag
->time
>= 0;
215 * Returns the first value of the specified tag type, or NULL if none
216 * is present in this tag object.
219 tag_get_value(const struct tag
*tag
, enum tag_type type
);
222 * Checks whether the tag contains one or more items with
223 * the specified type.
225 bool tag_has_type(const struct tag
*tag
, enum tag_type type
);
228 * Compares two tags, including the duration and all tag items. The
229 * order of the tag items matters.
231 bool tag_equal(const struct tag
*tag1
, const struct tag
*tag2
);