1 #ifndef PLAYLIST_H
2 #define PLAYLIST_H
3 
4 #include <sys/types.h>
5 
6 #include "rbtree.h"
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /* Flags for the info decoder function. */
13 enum tags_select
14 {
15 	TAGS_COMMENTS	= 0x01, /* artist, title, etc. */
16 	TAGS_TIME	= 0x02 /* time of the file. */
17 };
18 
19 struct file_tags
20 {
21 	char *title;
22 	char *artist;
23 	char *album;
24 	int track;
25 	int time;
26 	int filled; /* Which tags are filled: TAGS_COMMENTS, TAGS_TIME. */
27 };
28 
29 enum file_type
30 {
31 	F_DIR,
32 	F_SOUND,
33 	F_URL,
34 	F_PLAYLIST,
35 	F_THEME,
36 	F_OTHER
37 };
38 
39 struct plist_item
40 {
41 	char *file;
42 	enum file_type type;	/* type of the file (F_OTHER if not read yet) */
43 	char *title_file;	/* title based on the file name */
44 	char *title_tags;	/* title based on the tags */
45 	struct file_tags *tags;
46 	short deleted;
47 	time_t mtime;		/* modification time */
48 	int queue_pos;		/* position in the queue */
49 };
50 
51 struct plist
52 {
53 	int num;			/* Number of elements on the list */
54 	int allocated;		/* Number of allocated elements */
55 	int not_deleted;	/* Number of non-deleted items */
56 	struct plist_item *items;
57 	int serial;		/* Optional serial number of this playlist */
58 	int total_time;		/* Total time for files on the playlist */
59 	int items_with_time;	/* Number of items for which the time is set. */
60 
61 	struct rb_tree search_tree;
62 };
63 
64 void plist_init (struct plist *plist);
65 int plist_add (struct plist *plist, const char *file_name);
66 int plist_add_from_item (struct plist *plist, const struct plist_item *item);
67 char *plist_get_file (const struct plist *plist, int i);
68 int plist_next (struct plist *plist, int num);
69 int plist_prev (struct plist *plist, int num);
70 void plist_clear (struct plist *plist);
71 void plist_delete (struct plist *plist, const int num);
72 void plist_free (struct plist *plist);
73 void plist_sort_fname (struct plist *plist);
74 int plist_find_fname (struct plist *plist, const char *file);
75 struct file_tags *tags_new ();
76 void tags_clear (struct file_tags *tags);
77 void tags_copy (struct file_tags *dst, const struct file_tags *src);
78 struct file_tags *tags_dup (const struct file_tags *tags);
79 void tags_free (struct file_tags *tags);
80 char *build_title_with_format (const struct file_tags *tags, const char *fmt);
81 char *build_title (const struct file_tags *tags);
82 int plist_count (const struct plist *plist);
83 void plist_set_title_tags (struct plist *plist, const int num,
84 		const char *title);
85 void plist_set_title_file (struct plist *plist, const int num,
86 		const char *title);
87 void plist_set_file (struct plist *plist, const int num, const char *file);
88 int plist_deleted (const struct plist *plist, const int num);
89 void plist_cat (struct plist *a, struct plist *b);
90 void update_file (struct plist_item *item);
91 void plist_set_item_time (struct plist *plist, const int num, const int time);
92 int get_item_time (const struct plist *plist, const int i);
93 int plist_total_time (const struct plist *plisti, int *all_files);
94 void plist_shuffle (struct plist *plist);
95 void plist_swap_first_fname (struct plist *plist, const char *fname);
96 struct plist_item *plist_new_item ();
97 void plist_free_item_fields (struct plist_item *item);
98 void plist_set_serial (struct plist *plist, const int serial);
99 int plist_get_serial (const struct plist *plist);
100 int plist_last (const struct plist *plist);
101 int plist_find_del_fname (const struct plist *plist, const char *file);
102 const char *plist_get_next_dead_entry (const struct plist *plist,
103                                        int *last_index);
104 void plist_item_copy (struct plist_item *dst, const struct plist_item *src);
105 enum file_type plist_file_type (const struct plist *plist, const int num);
106 void plist_remove_common_items (struct plist *a, struct plist *b);
107 void plist_discard_tags (struct plist *plist);
108 void plist_set_tags (struct plist *plist, const int num,
109 		const struct file_tags *tags);
110 struct file_tags *plist_get_tags (const struct plist *plist, const int num);
111 void plist_swap_files (struct plist *plist, const char *file1,
112 		const char *file2);
113 int plist_get_position (const struct plist *plist, int num);
114 
115 #ifdef __cplusplus
116 }
117 #endif
118 
119 #endif
120