One more try: Fix remaining reds and yellows
[kugel-rb.git] / apps / playlist.h
blobdf3bd6221a1b5d37a57d33e07ff08fca51bf7fcb
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 "file.h"
27 #include "kernel.h"
28 #include "metadata.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,
41 PLAYLIST_COMMAND_ADD,
42 PLAYLIST_COMMAND_QUEUE,
43 PLAYLIST_COMMAND_DELETE,
44 PLAYLIST_COMMAND_SHUFFLE,
45 PLAYLIST_COMMAND_UNSHUFFLE,
46 PLAYLIST_COMMAND_RESET,
47 PLAYLIST_COMMAND_COMMENT
50 enum {
51 PLAYLIST_PREPEND = -1,
52 PLAYLIST_INSERT = -2,
53 PLAYLIST_INSERT_LAST = -3,
54 PLAYLIST_INSERT_FIRST = -4,
55 PLAYLIST_INSERT_SHUFFLED = -5,
56 PLAYLIST_REPLACE = -6
59 enum {
60 PLAYLIST_DELETE_CURRENT = -1
63 struct playlist_control_cache {
64 enum playlist_command command;
65 int i1;
66 int i2;
67 const char* s1;
68 const char* s2;
69 void* data;
72 struct playlist_info
74 bool current; /* current playing playlist */
75 char filename[MAX_PATH]; /* path name of m3u playlist on disk */
76 char control_filename[MAX_PATH]; /* full path of control file */
77 bool utf8; /* playlist is in .m3u8 format */
78 int fd; /* descriptor of the open playlist file */
79 int control_fd; /* descriptor of the open control file */
80 bool control_created; /* has control file been created? */
81 int dirlen; /* Length of the path to the playlist file */
82 unsigned long *indices; /* array of indices */
83 const struct dircache_entry **filenames; /* Entries from dircache */
84 int max_playlist_size; /* Max number of files in playlist. Mirror of
85 global_settings.max_files_in_playlist */
86 bool in_ram; /* playlist stored in ram (dirplay) */
87 char *buffer; /* buffer for in-ram playlists */
88 int buffer_size; /* size of buffer */
89 int buffer_end_pos; /* last position where buffer was written */
90 int index; /* index of current playing track */
91 int first_index; /* index of first song in playlist */
92 int amount; /* number of tracks in the index */
93 int last_insert_pos; /* last position we inserted a track */
94 int seed; /* shuffle seed */
95 bool shuffle_modified; /* has playlist been shuffled with
96 inserted tracks? */
97 bool deleted; /* have any tracks been deleted? */
98 int num_inserted_tracks; /* number of tracks inserted */
99 bool started; /* has playlist been started? */
101 /* cache of playlist control commands waiting to be flushed to
102 to disk */
103 struct playlist_control_cache control_cache[PLAYLIST_MAX_CACHE];
104 int num_cached; /* number of cached entries */
105 bool pending_control_sync; /* control file needs to be synced */
107 struct mutex control_mutex; /* mutex for control file access */
110 struct playlist_track_info
112 char filename[MAX_PATH]; /* path name of mp3 file */
113 int attr; /* playlist attributes for track */
114 int index; /* index of track in playlist */
115 int display_index; /* index of track for display */
118 /* Exported functions only for current playlist. */
119 void playlist_init(void);
120 void playlist_shutdown(void);
121 int playlist_create(const char *dir, const char *file);
122 int playlist_resume(void);
123 int playlist_add(const char *filename);
124 int playlist_shuffle(int random_seed, int start_index);
125 int playlist_start(int start_index, int offset);
126 bool playlist_check(int steps);
127 char *playlist_peek(int steps);
128 int playlist_next(int steps);
129 bool playlist_next_dir(int direction);
130 int playlist_get_resume_info(int *resume_index);
131 int playlist_update_resume_info(const struct mp3entry* id3);
132 int playlist_get_display_index(void);
133 int playlist_amount(void);
135 /* Exported functions for all playlists. Pass NULL for playlist_info
136 structure to work with current playlist. */
137 int playlist_create_ex(struct playlist_info* playlist,
138 const char* dir, const char* file,
139 void* index_buffer, int index_buffer_size,
140 void* temp_buffer, int temp_buffer_size);
141 int playlist_set_current(struct playlist_info* playlist);
142 void playlist_close(struct playlist_info* playlist);
143 void playlist_sync(struct playlist_info* playlist);
144 int playlist_insert_track(struct playlist_info* playlist, const char *filename,
145 int position, bool queue, bool sync);
146 int playlist_insert_directory(struct playlist_info* playlist,
147 const char *dirname, int position, bool queue,
148 bool recurse);
149 int playlist_insert_playlist(struct playlist_info* playlist, const char *filename,
150 int position, bool queue);
151 void playlist_skip_entry(struct playlist_info *playlist, int steps);
152 int playlist_delete(struct playlist_info* playlist, int index);
153 int playlist_move(struct playlist_info* playlist, int index, int new_index);
154 int playlist_randomise(struct playlist_info* playlist, unsigned int seed,
155 bool start_current);
156 int playlist_sort(struct playlist_info* playlist, bool start_current);
157 bool playlist_modified(const struct playlist_info* playlist);
158 int playlist_get_first_index(const struct playlist_info* playlist);
159 int playlist_get_seed(const struct playlist_info* playlist);
160 int playlist_amount_ex(const struct playlist_info* playlist);
161 char *playlist_name(const struct playlist_info* playlist, char *buf,
162 int buf_size);
163 char *playlist_get_name(const struct playlist_info* playlist, char *buf,
164 int buf_size);
165 int playlist_get_track_info(struct playlist_info* playlist, int index,
166 struct playlist_track_info* info);
167 int playlist_save(struct playlist_info* playlist, char *filename);
168 int playlist_directory_tracksearch(const char* dirname, bool recurse,
169 int (*callback)(char*, void*),
170 void* context);
171 int playlist_remove_all_tracks(struct playlist_info *playlist);
173 #endif /* __PLAYLIST_H__ */