-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.c
105 lines (87 loc) · 2.72 KB
/
queue.c
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
#include "queue.h"
#include <mpd/client.h>
#include <stdlib.h>
#include "constants.h"
#include "log.h"
#include "status.h"
#include "util.h"
#define BOLDWHITE "\033[1m\033[37m"
#define RESET "\033[0m"
void clear_queue(struct mpd_connection *connection) {
mpd_run_clear(connection);
mpd_check_error(connection, NULL, NULL);
#ifdef DEBUG
log_info("Cleared queue");
#endif
}
void delete_from_queue(struct mpd_connection *connection, int slot) {
if (slot < 0) {
die(connection, NULL, NULL, REMOVE_NEGATIVE_FAIL);
}
mpd_run_delete(
connection,
(unsigned)slot); /* safe, we check if its greater than 0 above */
mpd_check_error(connection, NULL, NULL);
#ifdef DEBUG
log_info("Deleted slot %d from queue", slot);
#endif
}
void print_queue(struct mpd_connection *connection) {
int pos;
int count;
struct mpd_song *song;
struct mpd_status *status;
count = 0;
status = initialize_status(connection);
pos = mpd_status_get_song_pos(status);
if (pos == -1) {
die(connection, status, NULL, NOTHING_PLAYING_FAIL);
}
mpd_check_error(connection, status, NULL);
mpd_send_list_queue_meta(connection);
mpd_check_error(connection, status, NULL);
while ((song = mpd_recv_song(connection)) != NULL) {
mpd_check_error(connection, status, song);
if (song) {
const char *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
const char *album = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
printf(
"%s%d %s %.50s - %.50s [%.50s]%s\n",
(count == pos) ? BOLDWHITE : "", count,
(count == pos) ? ">" : "-", artist ? artist : NULL_STRING,
title ? title : NULL_STRING, album ? album : NULL_STRING,
RESET); /* character limits to remove clutter with long names */
mpd_song_free(song);
}
count++;
}
mpd_status_free(status);
#ifdef DEBUG
log_info("Printed playlist");
#endif
}
void queue_relative_change(struct mpd_connection *connection, int step) {
while (step != 0) {
if (step > 0) {
mpd_run_next(connection);
mpd_check_error(connection, NULL, NULL);
--step;
}
if (step < 0) {
mpd_run_previous(connection);
mpd_check_error(connection, NULL, NULL);
++step;
}
}
#ifdef DEBUG
log_info("Changed relative queue position by %d", step);
#endif
}
void shuffle_queue(struct mpd_connection *connection) {
mpd_run_shuffle(connection);
mpd_check_error(connection, NULL, NULL);
#ifdef DEBUG
log_info("Shuffled queue");
#endif
}