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.m3u"
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
55 PLAYLIST_DELETE_CURRENT
= -1
58 struct playlist_control_cache
{
59 enum playlist_command command
;
69 bool current
; /* current playing playlist */
70 char filename
[MAX_PATH
]; /* path name of m3u playlist on disk */
71 char control_filename
[MAX_PATH
]; /* full path of control file */
72 int fd
; /* descriptor of the open playlist file */
73 int control_fd
; /* descriptor of the open control file */
74 bool control_created
; /* has control file been created? */
75 int dirlen
; /* Length of the path to the playlist file */
76 unsigned long *indices
; /* array of indices */
77 const struct dircache_entry
**filenames
; /* Entries from dircache */
78 int max_playlist_size
; /* Max number of files in playlist. Mirror of
79 global_settings.max_files_in_playlist */
80 bool in_ram
; /* playlist stored in ram (dirplay) */
81 char *buffer
; /* buffer for in-ram playlists */
82 int buffer_size
; /* size of buffer */
83 int buffer_end_pos
; /* last position where buffer was written */
84 int index
; /* index of current playing track */
85 int first_index
; /* index of first song in playlist */
86 int amount
; /* number of tracks in the index */
87 int last_insert_pos
; /* last position we inserted a track */
88 int seed
; /* shuffle seed */
89 bool shuffle_modified
; /* has playlist been shuffled with
91 bool deleted
; /* have any tracks been deleted? */
92 int num_inserted_tracks
; /* number of tracks inserted */
93 bool started
; /* has playlist been started? */
95 /* cache of playlist control commands waiting to be flushed to
97 struct playlist_control_cache control_cache
[PLAYLIST_MAX_CACHE
];
98 int num_cached
; /* number of cached entries */
99 bool pending_control_sync
; /* control file needs to be synced */
101 struct mutex control_mutex
; /* mutex for control file access */
104 struct playlist_track_info
106 char filename
[MAX_PATH
]; /* path name of mp3 file */
107 int attr
; /* playlist attributes for track */
108 int index
; /* index of track in playlist */
109 int display_index
; /* index of track for display */
112 /* Exported functions only for current playlist. */
113 void playlist_init(void);
114 void playlist_shutdown(void);
115 int playlist_create(const char *dir
, const char *file
);
116 int playlist_resume(void);
117 int playlist_add(const char *filename
);
118 int playlist_shuffle(int random_seed
, int start_index
);
119 int playlist_start(int start_index
, int offset
);
120 bool playlist_check(int steps
);
121 char *playlist_peek(int steps
);
122 int playlist_next(int steps
);
123 bool playlist_next_dir(int direction
);
124 int playlist_get_resume_info(int *resume_index
);
125 int playlist_update_resume_info(const struct mp3entry
* id3
);
126 int playlist_get_display_index(void);
127 int playlist_amount(void);
129 /* Exported functions for all playlists. Pass NULL for playlist_info
130 structure to work with current playlist. */
131 int playlist_create_ex(struct playlist_info
* playlist
,
132 const char* dir
, const char* file
,
133 void* index_buffer
, int index_buffer_size
,
134 void* temp_buffer
, int temp_buffer_size
);
135 int playlist_set_current(struct playlist_info
* playlist
);
136 void playlist_close(struct playlist_info
* playlist
);
137 void playlist_sync(struct playlist_info
* playlist
);
138 int playlist_insert_track(struct playlist_info
* playlist
, const char *filename
,
139 int position
, bool queue
, bool sync
);
140 int playlist_insert_directory(struct playlist_info
* playlist
,
141 const char *dirname
, int position
, bool queue
,
143 int playlist_insert_playlist(struct playlist_info
* playlist
, char *filename
,
144 int position
, bool queue
);
145 void playlist_skip_entry(struct playlist_info
*playlist
, int steps
);
146 int playlist_delete(struct playlist_info
* playlist
, int index
);
147 int playlist_move(struct playlist_info
* playlist
, int index
, int new_index
);
148 int playlist_randomise(struct playlist_info
* playlist
, unsigned int seed
,
150 int playlist_sort(struct playlist_info
* playlist
, bool start_current
);
151 bool playlist_modified(const struct playlist_info
* playlist
);
152 int playlist_get_first_index(const struct playlist_info
* playlist
);
153 int playlist_get_seed(const struct playlist_info
* playlist
);
154 int playlist_amount_ex(const struct playlist_info
* playlist
);
155 char *playlist_name(const struct playlist_info
* playlist
, char *buf
,
157 char *playlist_get_name(const struct playlist_info
* playlist
, char *buf
,
159 int playlist_get_track_info(struct playlist_info
* playlist
, int index
,
160 struct playlist_track_info
* info
);
161 int playlist_save(struct playlist_info
* playlist
, char *filename
);
162 int playlist_directory_tracksearch(const char* dirname
, bool recurse
,
163 int (*callback
)(char*, void*),
166 #endif /* __PLAYLIST_H__ */