FS#12553 - Second January update of Czech language
[maemo-rb.git] / apps / playlist.h
blobd19d9a792a63e18841f61075c8a804c2e0c4494f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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__
25 #include <stdbool.h>
26 #include "config.h"
27 #include "file.h"
28 #include "kernel.h"
29 #include "metadata.h"
31 #define PLAYLIST_ATTR_QUEUED 0x01
32 #define PLAYLIST_ATTR_INSERTED 0x02
33 #define PLAYLIST_ATTR_SKIPPED 0x04
34 #define PLAYLIST_MAX_CACHE 16
36 #define PLAYLIST_DISPLAY_COUNT 10
38 #define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8"
40 enum playlist_command {
41 PLAYLIST_COMMAND_PLAYLIST,
42 PLAYLIST_COMMAND_ADD,
43 PLAYLIST_COMMAND_QUEUE,
44 PLAYLIST_COMMAND_DELETE,
45 PLAYLIST_COMMAND_SHUFFLE,
46 PLAYLIST_COMMAND_UNSHUFFLE,
47 PLAYLIST_COMMAND_RESET,
48 PLAYLIST_COMMAND_COMMENT
51 enum {
52 PLAYLIST_PREPEND = -1,
53 PLAYLIST_INSERT = -2,
54 PLAYLIST_INSERT_LAST = -3,
55 PLAYLIST_INSERT_FIRST = -4,
56 PLAYLIST_INSERT_SHUFFLED = -5,
57 PLAYLIST_REPLACE = -6,
58 PLAYLIST_INSERT_LAST_SHUFFLED = -7
61 enum {
62 PLAYLIST_DELETE_CURRENT = -1
65 struct playlist_control_cache {
66 enum playlist_command command;
67 int i1;
68 int i2;
69 const char* s1;
70 const char* s2;
71 void* data;
74 struct playlist_info
76 bool current; /* current playing playlist */
77 char filename[MAX_PATH]; /* path name of m3u playlist on disk */
78 char control_filename[MAX_PATH]; /* full path of control file */
79 bool utf8; /* playlist is in .m3u8 format */
80 int fd; /* descriptor of the open playlist file */
81 int control_fd; /* descriptor of the open control file */
82 bool control_created; /* has control file been created? */
83 int dirlen; /* Length of the path to the playlist file */
84 volatile unsigned long *indices; /* array of indices */
85 volatile int *filenames; /* Array of dircache indices */
86 int max_playlist_size; /* Max number of files in playlist. Mirror of
87 global_settings.max_files_in_playlist */
88 bool in_ram; /* playlist stored in ram (dirplay) */
89 int buffer_handle; /* handle to the below buffer (-1 if non-buflib) */
91 union {
92 volatile char *buffer;/* buffer for in-ram playlists */
93 int *seek_buf; /* buffer for seeks in real playlists */
95 int buffer_size; /* size of buffer */
96 int buffer_end_pos; /* last position where buffer was written */
97 int index; /* index of current playing track */
98 int first_index; /* index of first song in playlist */
99 int amount; /* number of tracks in the index */
100 int last_insert_pos; /* last position we inserted a track */
101 int seed; /* shuffle seed */
102 bool shuffle_modified; /* has playlist been shuffled with
103 inserted tracks? */
104 bool deleted; /* have any tracks been deleted? */
105 int num_inserted_tracks; /* number of tracks inserted */
106 bool started; /* has playlist been started? */
108 /* cache of playlist control commands waiting to be flushed to
109 to disk */
110 struct playlist_control_cache control_cache[PLAYLIST_MAX_CACHE];
111 int num_cached; /* number of cached entries */
112 bool pending_control_sync; /* control file needs to be synced */
114 struct mutex *control_mutex; /* mutex for control file access */
115 int last_shuffled_start; /* number of tracks when insert last
116 shuffled command start */
119 struct playlist_track_info
121 char filename[MAX_PATH]; /* path name of mp3 file */
122 int attr; /* playlist attributes for track */
123 int index; /* index of track in playlist */
124 int display_index; /* index of track for display */
127 /* Exported functions only for current playlist. */
128 void playlist_init(void) INIT_ATTR;
129 void playlist_shutdown(void);
130 int playlist_create(const char *dir, const char *file);
131 int playlist_resume(void);
132 int playlist_add(const char *filename);
133 int playlist_shuffle(int random_seed, int start_index);
134 void playlist_start(int start_index, int offset);
135 bool playlist_check(int steps);
136 const char *playlist_peek(int steps, char* buf, size_t buf_size);
137 int playlist_next(int steps);
138 #if CONFIG_CODEC == SWCODEC
139 bool playlist_next_dir(int direction);
140 #endif
141 int playlist_get_resume_info(int *resume_index);
142 int playlist_update_resume_info(const struct mp3entry* id3);
143 int playlist_get_display_index(void);
144 int playlist_amount(void);
145 void playlist_set_last_shuffled_start(void);
146 struct playlist_info *playlist_get_current(void);
148 /* Exported functions for all playlists. Pass NULL for playlist_info
149 structure to work with current playlist. */
150 int playlist_create_ex(struct playlist_info* playlist,
151 const char* dir, const char* file,
152 void* index_buffer, int index_buffer_size,
153 void* temp_buffer, int temp_buffer_size);
154 int playlist_set_current(struct playlist_info* playlist);
155 void playlist_close(struct playlist_info* playlist);
156 void playlist_sync(struct playlist_info* playlist);
157 int playlist_insert_track(struct playlist_info* playlist, const char *filename,
158 int position, bool queue, bool sync);
159 int playlist_insert_directory(struct playlist_info* playlist,
160 const char *dirname, int position, bool queue,
161 bool recurse);
162 int playlist_insert_playlist(struct playlist_info* playlist, const char *filename,
163 int position, bool queue);
164 #if CONFIG_CODEC == SWCODEC
165 void playlist_skip_entry(struct playlist_info *playlist, int steps);
166 #endif
167 int playlist_delete(struct playlist_info* playlist, int index);
168 int playlist_move(struct playlist_info* playlist, int index, int new_index);
169 int playlist_randomise(struct playlist_info* playlist, unsigned int seed,
170 bool start_current);
171 int playlist_sort(struct playlist_info* playlist, bool start_current);
172 bool playlist_modified(const struct playlist_info* playlist);
173 int playlist_get_first_index(const struct playlist_info* playlist);
174 int playlist_get_seed(const struct playlist_info* playlist);
175 int playlist_amount_ex(const struct playlist_info* playlist);
176 char *playlist_name(const struct playlist_info* playlist, char *buf,
177 int buf_size);
178 char *playlist_get_name(const struct playlist_info* playlist, char *buf,
179 int buf_size);
180 int playlist_get_track_info(struct playlist_info* playlist, int index,
181 struct playlist_track_info* info);
182 int playlist_save(struct playlist_info* playlist, char *filename);
183 int playlist_directory_tracksearch(const char* dirname, bool recurse,
184 int (*callback)(char*, void*),
185 void* context);
186 int playlist_remove_all_tracks(struct playlist_info *playlist);
188 #endif /* __PLAYLIST_H__ */