1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by wavey@wavey.org
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef __PLAYLIST_H__
23 #define __PLAYLIST_H__
30 #define PLAYLIST_ATTR_QUEUED 0x01
31 #define PLAYLIST_ATTR_INSERTED 0x02
32 #define PLAYLIST_ATTR_SKIPPED 0x04
33 #define PLAYLIST_MAX_CACHE 16
35 #define PLAYLIST_DISPLAY_COUNT 10
37 #define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8"
39 enum playlist_command
{
40 PLAYLIST_COMMAND_PLAYLIST
,
42 PLAYLIST_COMMAND_QUEUE
,
43 PLAYLIST_COMMAND_DELETE
,
44 PLAYLIST_COMMAND_SHUFFLE
,
45 PLAYLIST_COMMAND_UNSHUFFLE
,
46 PLAYLIST_COMMAND_RESET
,
47 PLAYLIST_COMMAND_COMMENT
51 PLAYLIST_PREPEND
= -1,
53 PLAYLIST_INSERT_LAST
= -3,
54 PLAYLIST_INSERT_FIRST
= -4,
55 PLAYLIST_INSERT_SHUFFLED
= -5,
56 PLAYLIST_REPLACE
= -6,
57 PLAYLIST_INSERT_LAST_SHUFFLED
= -7
61 PLAYLIST_DELETE_CURRENT
= -1
64 struct playlist_control_cache
{
65 enum playlist_command command
;
75 bool current
; /* current playing playlist */
76 char filename
[MAX_PATH
]; /* path name of m3u playlist on disk */
77 char control_filename
[MAX_PATH
]; /* full path of control file */
78 bool utf8
; /* playlist is in .m3u8 format */
79 int fd
; /* descriptor of the open playlist file */
80 int control_fd
; /* descriptor of the open control file */
81 bool control_created
; /* has control file been created? */
82 int dirlen
; /* Length of the path to the playlist file */
83 unsigned long *indices
; /* array of indices */
84 int *filenames
; /* Array of dircache indices */
85 int max_playlist_size
; /* Max number of files in playlist. Mirror of
86 global_settings.max_files_in_playlist */
87 bool in_ram
; /* playlist stored in ram (dirplay) */
90 char *buffer
; /* buffer for in-ram playlists */
91 int *seek_buf
; /* buffer for seeks in real playlists */
93 int buffer_size
; /* size of buffer */
94 int buffer_end_pos
; /* last position where buffer was written */
95 int index
; /* index of current playing track */
96 int first_index
; /* index of first song in playlist */
97 int amount
; /* number of tracks in the index */
98 int last_insert_pos
; /* last position we inserted a track */
99 int seed
; /* shuffle seed */
100 bool shuffle_modified
; /* has playlist been shuffled with
102 bool deleted
; /* have any tracks been deleted? */
103 int num_inserted_tracks
; /* number of tracks inserted */
104 bool started
; /* has playlist been started? */
106 /* cache of playlist control commands waiting to be flushed to
108 struct playlist_control_cache control_cache
[PLAYLIST_MAX_CACHE
];
109 int num_cached
; /* number of cached entries */
110 bool pending_control_sync
; /* control file needs to be synced */
112 struct mutex
*control_mutex
; /* mutex for control file access */
113 int last_shuffled_start
; /* number of tracks when insert last
114 shuffled command start */
117 struct playlist_track_info
119 char filename
[MAX_PATH
]; /* path name of mp3 file */
120 int attr
; /* playlist attributes for track */
121 int index
; /* index of track in playlist */
122 int display_index
; /* index of track for display */
125 /* Exported functions only for current playlist. */
126 void playlist_init(void) INIT_ATTR
;
127 void playlist_shutdown(void);
128 int playlist_create(const char *dir
, const char *file
);
129 int playlist_resume(void);
130 int playlist_add(const char *filename
);
131 int playlist_shuffle(int random_seed
, int start_index
);
132 void playlist_start(int start_index
, int offset
);
133 bool playlist_check(int steps
);
134 const char *playlist_peek(int steps
, char* buf
, size_t buf_size
);
135 int playlist_next(int steps
);
136 bool playlist_next_dir(int direction
);
137 int playlist_get_resume_info(int *resume_index
);
138 int playlist_update_resume_info(const struct mp3entry
* id3
);
139 int playlist_get_display_index(void);
140 int playlist_amount(void);
141 void playlist_set_last_shuffled_start(void);
142 struct playlist_info
*playlist_get_current(void);
144 /* Exported functions for all playlists. Pass NULL for playlist_info
145 structure to work with current playlist. */
146 int playlist_create_ex(struct playlist_info
* playlist
,
147 const char* dir
, const char* file
,
148 void* index_buffer
, int index_buffer_size
,
149 void* temp_buffer
, int temp_buffer_size
);
150 int playlist_set_current(struct playlist_info
* playlist
);
151 void playlist_close(struct playlist_info
* playlist
);
152 void playlist_sync(struct playlist_info
* playlist
);
153 int playlist_insert_track(struct playlist_info
* playlist
, const char *filename
,
154 int position
, bool queue
, bool sync
);
155 int playlist_insert_directory(struct playlist_info
* playlist
,
156 const char *dirname
, int position
, bool queue
,
158 int playlist_insert_playlist(struct playlist_info
* playlist
, const char *filename
,
159 int position
, bool queue
);
160 void playlist_skip_entry(struct playlist_info
*playlist
, int steps
);
161 int playlist_delete(struct playlist_info
* playlist
, int index
);
162 int playlist_move(struct playlist_info
* playlist
, int index
, int new_index
);
163 int playlist_randomise(struct playlist_info
* playlist
, unsigned int seed
,
165 int playlist_sort(struct playlist_info
* playlist
, bool start_current
);
166 bool playlist_modified(const struct playlist_info
* playlist
);
167 int playlist_get_first_index(const struct playlist_info
* playlist
);
168 int playlist_get_seed(const struct playlist_info
* playlist
);
169 int playlist_amount_ex(const struct playlist_info
* playlist
);
170 char *playlist_name(const struct playlist_info
* playlist
, char *buf
,
172 char *playlist_get_name(const struct playlist_info
* playlist
, char *buf
,
174 int playlist_get_track_info(struct playlist_info
* playlist
, int index
,
175 struct playlist_track_info
* info
);
176 int playlist_save(struct playlist_info
* playlist
, char *filename
);
177 int playlist_directory_tracksearch(const char* dirname
, bool recurse
,
178 int (*callback
)(char*, void*),
180 int playlist_remove_all_tracks(struct playlist_info
*playlist
);
182 #endif /* __PLAYLIST_H__ */