A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by wavey@wavey.org
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __PLAYLIST_H__
23#define __PLAYLIST_H__
24
25#include <stdbool.h>
26#include "config.h"
27#include "file.h"
28#include "kernel.h"
29#include "metadata.h"
30#include "rbpaths.h"
31#include "chunk_alloc.h"
32
33#define PLAYLIST_ATTR_QUEUED 0x01
34#define PLAYLIST_ATTR_INSERTED 0x02
35#define PLAYLIST_ATTR_SKIPPED 0x04
36#define PLAYLIST_ATTR_RETRIEVE_ID3_ATTEMPTED 0x08
37#define PLAYLIST_ATTR_RETRIEVE_ID3_SUCCEEDED 0x10
38
39#define PLAYLIST_DISPLAY_COUNT 10
40
41#define PLAYLIST_UNTITLED_PREFIX "Playlist "
42
43#define PLAYLIST_FLAG_MODIFIED (1u << 0) /* playlist was manually modified */
44#define PLAYLIST_FLAG_DIRPLAY (1u << 1) /* enable directory skipping */
45
46enum playlist_command {
47 PLAYLIST_COMMAND_PLAYLIST,
48 PLAYLIST_COMMAND_ADD,
49 PLAYLIST_COMMAND_QUEUE,
50 PLAYLIST_COMMAND_DELETE,
51 PLAYLIST_COMMAND_SHUFFLE,
52 PLAYLIST_COMMAND_UNSHUFFLE,
53 PLAYLIST_COMMAND_RESET,
54 PLAYLIST_COMMAND_FLAGS,
55 PLAYLIST_COMMAND_COMMENT,
56 PLAYLIST_COMMAND_ERROR = PLAYLIST_COMMAND_COMMENT + 1 /* Internal */
57};
58
59enum {
60 PLAYLIST_PREPEND = -1,
61 PLAYLIST_INSERT = -2,
62 PLAYLIST_INSERT_LAST = -3,
63 PLAYLIST_INSERT_FIRST = -4,
64 PLAYLIST_INSERT_SHUFFLED = -5,
65 PLAYLIST_REPLACE = -6,
66 PLAYLIST_INSERT_LAST_SHUFFLED = -7,
67 PLAYLIST_INSERT_LAST_ROTATED = -8
68};
69
70struct playlist_info
71{
72 bool utf8; /* playlist is in .m3u8 format */
73 bool control_created; /* has control file been created? */
74 unsigned int flags; /* flags for misc. state */
75 int fd; /* descriptor of the open playlist file */
76 int control_fd; /* descriptor of the open control file */
77 int max_playlist_size; /* Max number of files in playlist. Mirror of
78 global_settings.max_files_in_playlist */
79 unsigned long *indices; /* array of indices */
80
81 int index; /* index of current playing track */
82 int first_index; /* index of first song in playlist */
83 int amount; /* number of tracks in the index */
84 int last_insert_pos; /* last position we inserted a track */
85 bool started; /* has playlist been started? */
86 int last_shuffled_start; /* number of tracks when insert last
87 shuffled command start */
88 int seed; /* shuffle seed */
89 struct mutex mutex; /* mutex for control file access */
90#ifdef HAVE_DIRCACHE
91 int dcfrefs_handle;
92#endif
93 int dirlen; /* Length of the path to the playlist file */
94 char filename[MAX_PATH]; /* path name of m3u playlist on disk */
95 /* full path of control file (with extra room for extensions) */
96 char control_filename[sizeof(PLAYLIST_CONTROL_FILE) + 8];
97};
98
99struct playlist_track_info
100{
101 char filename[MAX_PATH]; /* path name of mp3 file */
102 int attr; /* playlist attributes for track */
103 int index; /* index of track in playlist */
104 int display_index; /* index of track for display */
105};
106
107struct playlist_insert_context {
108 struct playlist_info* playlist;
109 int position;
110 bool queue;
111 bool progress;
112 bool initialized;
113 int count;
114 int32_t count_langid;
115};
116
117/* Exported functions only for current playlist. */
118void playlist_init(void) INIT_ATTR;
119void playlist_shutdown(void);
120int playlist_create(const char *dir, const char *file);
121int playlist_resume(void);
122int playlist_shuffle(int random_seed, int start_index);
123unsigned int playlist_get_filename_crc32(struct playlist_info *playlist,
124 int index);
125void playlist_resume_track(int start_index, unsigned int crc,
126 unsigned long elapsed, unsigned long offset);
127void playlist_start(int start_index, unsigned long elapsed,
128 unsigned long offset);
129bool playlist_check(int steps);
130const char *playlist_peek(int steps, char* buf, size_t buf_size);
131int playlist_next(int steps);
132bool playlist_next_dir(int direction);
133int playlist_get_resume_info(int *resume_index);
134int playlist_update_resume_info(const struct mp3entry* id3);
135int playlist_get_display_index(void);
136int playlist_amount(void);
137void playlist_set_last_shuffled_start(void);
138struct playlist_info *playlist_get_current(void);
139bool playlist_dynamic_only(void);
140
141/* Exported functions for all playlists. Pass NULL for playlist_info
142 structure to work with current playlist. */
143size_t playlist_get_index_bufsz(size_t max_sz);
144struct playlist_info* playlist_load(const char* dir, const char* file,
145 void* index_buffer, int index_buffer_size,
146 void* temp_buffer, int temp_buffer_size);
147int playlist_set_current(struct playlist_info* playlist);
148void playlist_close(struct playlist_info* playlist);
149void playlist_sync(struct playlist_info* playlist);
150int playlist_insert_track(struct playlist_info* playlist, const char *filename,
151 int position, bool queue, bool sync);
152int playlist_insert_context_create(struct playlist_info* playlist,
153 struct playlist_insert_context *context,
154 int position, bool queue, bool progress);
155int playlist_insert_context_add(struct playlist_insert_context *context,
156 const char *filename);
157void playlist_insert_context_release(struct playlist_insert_context *context);
158int playlist_insert_directory(struct playlist_info* playlist,
159 const char *dirname, int position, bool queue,
160 bool recurse);
161int playlist_insert_playlist(struct playlist_info* playlist, const char *filename,
162 int position, bool queue);
163bool playlist_entries_iterate(const char *filename,
164 struct playlist_insert_context *pl_context,
165 bool (*action_cb)(const char *file_name));
166void playlist_skip_entry(struct playlist_info *playlist, int steps);
167int playlist_delete(struct playlist_info* playlist, int index);
168int playlist_move(struct playlist_info* playlist, int index, int new_index);
169int playlist_randomise(struct playlist_info* playlist, unsigned int seed,
170 bool start_current);
171int playlist_sort(struct playlist_info* playlist, bool start_current);
172bool playlist_modified(const struct playlist_info* playlist);
173void playlist_set_modified(struct playlist_info* playlist, bool modified);
174bool playlist_allow_dirplay(const struct playlist_info* playlist);
175int playlist_get_first_index(const struct playlist_info* playlist);
176int playlist_get_seed(const struct playlist_info* playlist);
177int playlist_amount_ex(const struct playlist_info* playlist);
178char *playlist_name(const struct playlist_info* playlist, char *buf,
179 int buf_size);
180char *playlist_get_name(const struct playlist_info* playlist, char *buf,
181 int buf_size);
182int playlist_get_track_info(struct playlist_info* playlist, int index,
183 struct playlist_track_info* info);
184int playlist_save(struct playlist_info* playlist, char *filename);
185int playlist_directory_tracksearch(const char* dirname, bool recurse,
186 int (*callback)(char*, void*),
187 void* context);
188int playlist_remove_all_tracks(struct playlist_info *playlist);
189
190#endif /* __PLAYLIST_H__ */