Obsolete playing_random state
[disorder] / lib / queue.h
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
5aff007d 3 * Copyright (C) 2004-2008 Richard Kettlewell
460b9539 4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
460b9539 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
460b9539 8 * (at your option) any later version.
e7eb3a27
RK
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
460b9539 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
460b9539 17 */
132a5a4a
RK
18/** @file lib/queue.h
19 * @brief Track queues
20 *
21 * Used for the queue, the recently played list and the currently playing
22 * track, both in the server and in clients.
23 */
460b9539 24#ifndef QUEUE_H
25#define QUEUE_H
26
05b75f8d
RK
27#include <time.h>
28
094e0af7 29/** @brief Possible track states */
460b9539 30enum playing_state {
094e0af7
RK
31 /** @brief Track failed to play */
32 playing_failed,
33
34 /** @brief Track is a scratch and has not been played yet
35 *
36 * Going to become obsolete.
37 */
38 playing_isscratch,
39
40 /** @brief Could not find a player
41 *
42 * Obsolete - nothing sets this any more
43 */
44 playing_no_player,
45
46 /** @brief Play completed successfully
47 *
48 * Currently this actually means it finished decoding - it might still be
49 * buffered in the speaker, RTP player, sound card, etc.
50 *
51 * It might also mean that it's a (short!) track that hasn't been played at
52 * all yet but has been fully decoded ahead of time! (This is very confusing
53 * so might change.)
54 */
55 playing_ok,
56
57 /** @brief Track is playing, but paused */
58 playing_paused,
59
60 /** @brief Track is playing but the server is quitting */
61 playing_quitting,
62
3867fa20 63 /** @brief OBSOLETE
094e0af7 64 *
3867fa20
RK
65 * Formerly this meant a track that was picked at random and has not yet been
66 * played. This situation is now indicated by @p playing_unplayed and @p
67 * origin_random (or @p origin_adopted).
094e0af7
RK
68 */
69 playing_random,
70
71 /** @brief Track was scratched */
72 playing_scratched,
73
74 /** @brief Track is now playing
75 *
76 * This refers to the actual playing track, not something being decoded ahead
77 * of time.
78 */
79 playing_started,
80
81 /** @brief Track has not been played yet */
82 playing_unplayed
460b9539 83};
84
2dc2f478
RK
85extern const char *const playing_states[];
86
87/** @brief Possible track origins
88 *
89 * This is a newly introduced field. The aim is ultimately to separate the
90 * concepts of the track origin and its current state. NB that both are
91 * potentially mutable!
92 */
93enum track_origin {
94 /** @brief Track was picked at random and then adopted by a user
95 *
96 * @c submitter identifies who adopted it. This isn't implemented
97 * yet.
98 */
99 origin_adopted,
100
101 /** @brief Track was picked by a user
102 *
103 * @c submitter identifies who picked it
104 */
105 origin_picked,
106
107 /** @brief Track was picked at random
108 *
109 * @c submitter will be NULL
110 */
111 origin_random,
112
113 /** @brief Track was scheduled by a user
114 *
115 * @c submitter identifies who picked it
116 */
117 origin_scheduled,
118
119 /** @brief Track is a scratch
120 *
121 * @c submitter identifies who did the scratching
122 */
123 origin_scratch
124};
125
126extern const char *const track_origins[];
460b9539 127
094e0af7
RK
128/** @brief One queue/recently played entry
129 *
130 * The queue and recently played list form a doubly linked list with the head
131 * and tail referred to from @ref qhead and @ref phead.
132 */
460b9539 133struct queue_entry {
094e0af7
RK
134 /** @brief Next entry */
135 struct queue_entry *next;
136
137 /** @brief Previous entry */
138 struct queue_entry *prev;
139
140 /** @brief Path to track (a database key) */
141 const char *track;
142
143 /** @brief Submitter or NULL
144 *
145 * Adopter, if @c origin is @ref origin_adopted.
146 */
147 const char *submitter;
148
149 /** @brief When submitted */
150 time_t when;
151
152 /** @brief When played */
153 time_t played;
154
155 /** @brief Current state
156 *
157 * Currently this includes some origin information but this is being phased
158 * out. */
159 enum playing_state state;
160
161 /** @brief Where track came from */
162 enum track_origin origin;
163
164 /** @brief Wait status from player
165 *
166 * Only valid in certain states (TODO).
167 */
168 long wstat;
169
170 /** @brief Who scratched this track or NULL */
171 const char *scratched;
172
173 /** @brief Unique ID string */
174 const char *id;
175
176 /** @brief Estimated starting time */
177 time_t expected;
178
179 /** @brief Type word from plugin (playing/buffered tracks only) */
460b9539 180 unsigned long type; /* type word from plugin */
094e0af7
RK
181
182 /** @brief Plugin for this track (playing/buffered tracks only) */
183 const struct plugin *pl;
184
185 /** @brief Player-specific data (playing/buffered tracks only) */
186 void *data;
187
188 /** @brief How much of track has been played so far (seconds) */
189 long sofar;
190
191 /** @brief True if decoder is connected to speaker */
192 int prepared;
460b9539 193 /* For DISORDER_PLAYER_PAUSES only: */
094e0af7
RK
194
195 /** @brief When last paused or 0 */
196 time_t lastpaused;
197
198 /** @brief When last resumed or 0 */
199 time_t lastresumed;
200
201 /** @brief How much of track was played up to last pause (seconds) */
202 long uptopause;
203
204 /** @brief Owning queue (for Disobedience only) */
205 struct queuelike *ql;
460b9539 206};
207
05b75f8d
RK
208void queue_insert_entry(struct queue_entry *b, struct queue_entry *n);
209void queue_delete_entry(struct queue_entry *node);
210
460b9539 211int queue_unmarshall(struct queue_entry *q, const char *s,
212 void (*error_handler)(const char *, void *),
213 void *u);
214/* unmarshall UTF-8 string @s@ into @q@ */
215
216int queue_unmarshall_vec(struct queue_entry *q, int nvec, char **vec,
217 void (*error_handler)(const char *, void *),
218 void *u);
219/* unmarshall pre-split string @vec@ into @q@ */
220
221char *queue_marshall(const struct queue_entry *q);
222/* marshall @q@ into a UTF-8 string */
223
460b9539 224#endif /* QUEUE_H */
225
226/*
227Local Variables:
228c-basic-offset:2
229comment-column:40
230fill-column:79
231End:
232*/