1
/*
2
 * Copyright 2008-2011 Various Authors
3
 * Copyright 2004-2005 Timo Hirvonen
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as
7
 * published by the Free Software Foundation; either version 2 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
#ifndef _TRACK_INFO_H
20
#define _TRACK_INFO_H
21
22
#include <time.h>
23
#include <stddef.h>
24
25
struct track_info {
26
	struct keyval *comments;
27
28
	// next track_info in the hash table (cache.c)
29
	struct track_info *next;
30
31
	time_t mtime;
32
	int duration;
33
	long bitrate;
34
	char *codec;
35
	char *codec_profile;
36
	int ref;
37
	char *filename;
38
39
	int tracknumber;
40
	int discnumber;
41
	int date;
42
	int originaldate;
43
	double rg_track_gain;
44
	double rg_track_peak;
45
	double rg_album_gain;
46
	double rg_album_peak;
47
	const char *artist;
48
	const char *album;
49
	const char *title;
50
	const char *genre;
51
	const char *comment;
52
	const char *albumartist;
53
	const char *artistsort;
54
	const char *albumsort;
55
	const char *media;
56
57
	char *collkey_artist;
58
	char *collkey_album;
59
	char *collkey_title;
60
	char *collkey_genre;
61
	char *collkey_comment;
62
	char *collkey_albumartist;
63
64
	int is_va_compilation : 1;
65
};
66
67
typedef size_t sort_key_t;
68
69
#define SORT_ARTIST        offsetof(struct track_info, collkey_artist)
70
#define SORT_ALBUM         offsetof(struct track_info, collkey_album)
71
#define SORT_TITLE         offsetof(struct track_info, collkey_title)
72
#define SORT_TRACKNUMBER   offsetof(struct track_info, tracknumber)
73
#define SORT_DISCNUMBER    offsetof(struct track_info, discnumber)
74
#define SORT_DATE          offsetof(struct track_info, date)
75
#define SORT_ORIGINALDATE  offsetof(struct track_info, originaldate)
76
#define SORT_RG_TRACK_GAIN offsetof(struct track_info, rg_track_gain)
77
#define SORT_RG_TRACK_PEAK offsetof(struct track_info, rg_track_peak)
78
#define SORT_RG_ALBUM_GAIN offsetof(struct track_info, rg_album_gain)
79
#define SORT_RG_ALBUM_PEAK offsetof(struct track_info, rg_album_peak)
80
#define SORT_GENRE         offsetof(struct track_info, collkey_genre)
81
#define SORT_COMMENT       offsetof(struct track_info, collkey_comment)
82
#define SORT_ALBUMARTIST   offsetof(struct track_info, collkey_albumartist)
83
#define SORT_FILENAME      offsetof(struct track_info, filename)
84
#define SORT_FILEMTIME     offsetof(struct track_info, mtime)
85
#define SORT_BITRATE       offsetof(struct track_info, bitrate)
86
#define SORT_CODEC         offsetof(struct track_info, codec)
87
#define SORT_CODEC_PROFILE offsetof(struct track_info, codec_profile)
88
#define SORT_MEDIA         offsetof(struct track_info, media)
89
#define SORT_INVALID       ((sort_key_t) (-1))
90
91
#define TI_MATCH_ARTIST       (1 << 0)
92
#define TI_MATCH_ALBUM        (1 << 1)
93
#define TI_MATCH_TITLE        (1 << 2)
94
#define TI_MATCH_ALBUMARTIST  (1 << 3)
95
#define TI_MATCH_ALL          (~0)
96
97
/* initializes only filename and ref */
98
struct track_info *track_info_new(const char *filename);
99
void track_info_set_comments(struct track_info *ti, struct keyval *comments);
100
101
void track_info_ref(struct track_info *ti);
102
void track_info_unref(struct track_info *ti);
103
104
/*
105
 * returns: 1 if @ti has any of the following tags: artist, album, title
106
 *          0 otherwise
107
 */
108
int track_info_has_tag(const struct track_info *ti);
109
110
/*
111
 * @flags  fields to search in (TI_MATCH_*)
112
 *
113
 * returns: 1 if all words in @text are found to match defined fields (@flags) in @ti
114
 *          0 otherwise
115
 */
116
int track_info_matches(const struct track_info *ti, const char *text, unsigned int flags);
117
118
/*
119
 * @flags            fields to search in (TI_MATCH_*)
120
 * @exclude_flags    fields which must not match (TI_MATCH_*)
121
 * @match_all_words  if true, all words must be found in @ti
122
 *
123
 * returns: 1 if all/any words in @text are found to match defined fields (@flags) in @ti
124
 *          0 otherwise
125
 */
126
int track_info_matches_full(const struct track_info *ti, const char *text, unsigned int flags,
127
		unsigned int exclude_flags, int match_all_words);
128
129
int track_info_cmp(const struct track_info *a, const struct track_info *b, const sort_key_t *keys);
130
131
#endif