summaryrefslogtreecommitdiff
path: root/apps/playlist.h
blob: 8698981d261756d418c7b4b8f746c6c9f61314b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2002 by wavey@wavey.org
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#ifndef __PLAYLIST_H__
#define __PLAYLIST_H__

#include <stdbool.h>
#include "file.h"
#include "kernel.h"

/* playlist data */

struct playlist_info
{
    bool current;        /* current playing playlist                */
    char filename[MAX_PATH];  /* path name of m3u playlist on disk  */
    char control_filename[MAX_PATH]; /* full path of control file   */
    int  fd;             /* descriptor of the open playlist file    */
    int  control_fd;     /* descriptor of the open control file     */
    bool control_created; /* has control file been created?         */
    int  dirlen;         /* Length of the path to the playlist file */
    unsigned int *indices; /* array of indices                      */
    int  max_playlist_size; /* Max number of files in playlist. Mirror of
                              global_settings.max_files_in_playlist */
    bool in_ram;         /* playlist stored in ram (dirplay)        */
    char *buffer;        /* buffer for in-ram playlists             */
    int  buffer_size;    /* size of buffer                          */
    int  buffer_end_pos; /* last position where buffer was written  */
    int  index;          /* index of current playing track          */
    int  first_index;    /* index of first song in playlist         */
    int  amount;         /* number of tracks in the index           */
    int  last_insert_pos; /* last position we inserted a track      */
    int  seed;           /* shuffle seed                            */
    bool shuffle_modified; /* has playlist been shuffled with
                              inserted tracks?                      */
    bool deleted;        /* have any tracks been deleted?           */
    int num_inserted_tracks; /* number of tracks inserted           */
    bool shuffle_flush;  /* does shuffle value need to be flushed?  */
    struct mutex control_mutex; /* mutex for control file access    */
};

#define PLAYLIST_ATTR_QUEUED    0x01
#define PLAYLIST_ATTR_INSERTED  0x02

struct playlist_track_info
{
    char filename[MAX_PATH]; /* path name of mp3 file               */
    int  attr;               /* playlist attributes for track       */
    int  index;              /* index of track in playlist          */
    int  display_index;      /* index of track for display          */
};

/* Exported functions only for current playlist. */
void playlist_init(void);
int playlist_create(const char *dir, const char *file);
int playlist_resume(void);
int playlist_add(const char *filename);
int playlist_shuffle(int random_seed, int start_index);
int playlist_start(int start_index, int offset);
bool playlist_check(int steps);
char *playlist_peek(int steps);
int playlist_next(int steps);
int playlist_get_resume_info(int *resume_index);
int playlist_get_display_index(void);
int playlist_amount(void);

/* Exported functions for all playlists.  Pass NULL for playlist_info
   structure to work with current playlist. */
int playlist_create_ex(struct playlist_info* playlist,
                       const char* dir, const char* file,
                       void* index_buffer, int index_buffer_size,
                       void* temp_buffer, int temp_buffer_size);
int playlist_set_current(struct playlist_info* playlist);
void playlist_close(struct playlist_info* playlist);
int playlist_insert_track(struct playlist_info* playlist, const char *filename,
                          int position, bool queue);
int playlist_insert_directory(struct playlist_info* playlist,
                              const char *dirname, int position, bool queue,
                              bool recurse);
int playlist_insert_playlist(struct playlist_info* playlist, char *filename,
                             int position, bool queue);
int playlist_delete(struct playlist_info* playlist, int index);
int playlist_move(struct playlist_info* playlist, int index, int new_index);
int playlist_randomise(struct playlist_info* playlist, unsigned int seed,
                       bool start_current);
int playlist_sort(struct playlist_info* playlist, bool start_current);
bool playlist_modified(const struct playlist_info* playlist);
int playlist_get_first_index(const struct playlist_info* playlist);
int playlist_get_seed(const struct playlist_info* playlist);
int playlist_amount_ex(const struct playlist_info* playlist);
char *playlist_name(const struct playlist_info* playlist, char *buf,
                    int buf_size);
char *playlist_get_name(const struct playlist_info* playlist, char *buf,
                        int buf_size);
int playlist_get_track_info(struct playlist_info* playlist, int index,
                            struct playlist_track_info* info);
int playlist_save(struct playlist_info* playlist, char *filename);

enum {
    PLAYLIST_PREPEND = -1,
    PLAYLIST_INSERT = -2,
    PLAYLIST_INSERT_LAST = -3,
    PLAYLIST_INSERT_FIRST = -4
};

enum {
    PLAYLIST_DELETE_CURRENT = -1
};

#endif /* __PLAYLIST_H__ */