1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by wavey@wavey.org
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #ifndef __PLAYLIST_H__
21 #define __PLAYLIST_H__
28 #define PLAYLIST_ATTR_QUEUED 0x01
29 #define PLAYLIST_ATTR_INSERTED 0x02
30 #define PLAYLIST_ATTR_SKIPPED 0x04
31 #define PLAYLIST_MAX_CACHE 16
33 #define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8"
35 enum playlist_command
{
36 PLAYLIST_COMMAND_PLAYLIST
,
38 PLAYLIST_COMMAND_QUEUE
,
39 PLAYLIST_COMMAND_DELETE
,
40 PLAYLIST_COMMAND_SHUFFLE
,
41 PLAYLIST_COMMAND_UNSHUFFLE
,
42 PLAYLIST_COMMAND_RESET
,
43 PLAYLIST_COMMAND_COMMENT
47 PLAYLIST_PREPEND
= -1,
49 PLAYLIST_INSERT_LAST
= -3,
50 PLAYLIST_INSERT_FIRST
= -4,
51 PLAYLIST_INSERT_SHUFFLED
= -5,
56 PLAYLIST_DELETE_CURRENT
= -1
59 struct playlist_control_cache
{
60 enum playlist_command command
;
70 bool current
; /* current playing playlist */
71 char filename
[MAX_PATH
]; /* path name of m3u playlist on disk */
72 char control_filename
[MAX_PATH
]; /* full path of control file */
73 bool utf8
; /* playlist is in .m3u8 format */
74 int fd
; /* descriptor of the open playlist file */
75 int control_fd
; /* descriptor of the open control file */
76 bool control_created
; /* has control file been created? */
77 int dirlen
; /* Length of the path to the playlist file */
78 unsigned long *indices
; /* array of indices */
79 const struct dircache_entry
**filenames
; /* Entries from dircache */
80 int max_playlist_size
; /* Max number of files in playlist. Mirror of
81 global_settings.max_files_in_playlist */
82 bool in_ram
; /* playlist stored in ram (dirplay) */
83 char *buffer
; /* buffer for in-ram playlists */
84 int buffer_size
; /* size of buffer */
85 int buffer_end_pos
; /* last position where buffer was written */
86 int index
; /* index of current playing track */
87 int first_index
; /* index of first song in playlist */
88 int amount
; /* number of tracks in the index */
89 int last_insert_pos
; /* last position we inserted a track */
90 int seed
; /* shuffle seed */
91 bool shuffle_modified
; /* has playlist been shuffled with
93 bool deleted
; /* have any tracks been deleted? */
94 int num_inserted_tracks
; /* number of tracks inserted */
95 bool started
; /* has playlist been started? */
97 /* cache of playlist control commands waiting to be flushed to
99 struct playlist_control_cache control_cache
[PLAYLIST_MAX_CACHE
];
100 int num_cached
; /* number of cached entries */
101 bool pending_control_sync
; /* control file needs to be synced */
103 struct mutex control_mutex
; /* mutex for control file access */
106 struct playlist_track_info
108 char filename
[MAX_PATH
]; /* path name of mp3 file */
109 int attr
; /* playlist attributes for track */
110 int index
; /* index of track in playlist */
111 int display_index
; /* index of track for display */
114 /* Exported functions only for current playlist. */
115 void playlist_init(void);
116 void playlist_shutdown(void);
117 int playlist_create(const char *dir
, const char *file
);
118 int playlist_resume(void);
119 int playlist_add(const char *filename
);
120 int playlist_shuffle(int random_seed
, int start_index
);
121 int playlist_start(int start_index
, int offset
);
122 bool playlist_check(int steps
);
123 char *playlist_peek(int steps
);
124 int playlist_next(int steps
);
125 bool playlist_next_dir(int direction
);
126 int playlist_get_resume_info(int *resume_index
);
127 int playlist_update_resume_info(const struct mp3entry
* id3
);
128 int playlist_get_display_index(void);
129 int playlist_amount(void);
131 /* Exported functions for all playlists. Pass NULL for playlist_info
132 structure to work with current playlist. */
133 int playlist_create_ex(struct playlist_info
* playlist
,
134 const char* dir
, const char* file
,
135 void* index_buffer
, int index_buffer_size
,
136 void* temp_buffer
, int temp_buffer_size
);
137 int playlist_set_current(struct playlist_info
* playlist
);
138 void playlist_close(struct playlist_info
* playlist
);
139 void playlist_sync(struct playlist_info
* playlist
);
140 int playlist_insert_track(struct playlist_info
* playlist
, const char *filename
,
141 int position
, bool queue
, bool sync
);
142 int playlist_insert_directory(struct playlist_info
* playlist
,
143 const char *dirname
, int position
, bool queue
,
145 int playlist_insert_playlist(struct playlist_info
* playlist
, const char *filename
,
146 int position
, bool queue
);
147 void playlist_skip_entry(struct playlist_info
*playlist
, int steps
);
148 int playlist_delete(struct playlist_info
* playlist
, int index
);
149 int playlist_move(struct playlist_info
* playlist
, int index
, int new_index
);
150 int playlist_randomise(struct playlist_info
* playlist
, unsigned int seed
,
152 int playlist_sort(struct playlist_info
* playlist
, bool start_current
);
153 bool playlist_modified(const struct playlist_info
* playlist
);
154 int playlist_get_first_index(const struct playlist_info
* playlist
);
155 int playlist_get_seed(const struct playlist_info
* playlist
);
156 int playlist_amount_ex(const struct playlist_info
* playlist
);
157 char *playlist_name(const struct playlist_info
* playlist
, char *buf
,
159 char *playlist_get_name(const struct playlist_info
* playlist
, char *buf
,
161 int playlist_get_track_info(struct playlist_info
* playlist
, int index
,
162 struct playlist_track_info
* info
);
163 int playlist_save(struct playlist_info
* playlist
, char *filename
);
164 int playlist_directory_tracksearch(const char* dirname
, bool recurse
,
165 int (*callback
)(char*, void*),
167 int playlist_remove_all_tracks(struct playlist_info
*playlist
);
169 #endif /* __PLAYLIST_H__ */