-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.c
68 lines (55 loc) · 1.82 KB
/
player.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
#include "player.h"
#include <mpd/client.h>
#include "constants.h"
#include "log.h"
#include "status.h"
#include "util.h"
void toggle_repeat_mode(struct mpd_connection *connection) {
bool old_status;
struct mpd_status *status;
status = initialize_status(connection);
old_status = mpd_status_get_repeat(status);
mpd_check_error(connection, status, NULL);
/* do the opposite of current status */
mpd_run_repeat(connection, !old_status);
mpd_check_error(connection, status, NULL);
mpd_status_free(status);
#ifdef DEBUG
log_info("Toggled repeat mode from %d to %d", old_status, !old_status);
#endif
}
void toggle_playing(struct mpd_connection *connection) {
enum mpd_state playing_state;
struct mpd_status *status;
status = initialize_status(connection);
playing_state = mpd_status_get_state(status);
mpd_check_error(connection, status, NULL);
if (playing_state == MPD_STATE_PLAY) {
mpd_run_pause(connection, true);
} else {
mpd_run_play(connection);
}
mpd_check_error(connection, status, NULL);
mpd_status_free(status);
#ifdef DEBUG
log_info("Toggled playing state");
#endif
}
void song_set_position(struct mpd_connection *connection, int position) {
if (position < 0) {
die(connection, NULL, NULL, REMOVE_NEGATIVE_FAIL);
}
/* safe, we check if negative above */
mpd_send_seek_current(connection, (float)position, false);
mpd_check_error(connection, NULL, NULL);
#ifdef DEBUG
log_info("Set position to %d", position);
#endif
}
void song_set_relative_position(struct mpd_connection *connection, int relative_offset) {
mpd_send_seek_current(connection, (float)relative_offset, true);
mpd_check_error(connection, NULL, NULL);
#ifdef DEBUG
log_info("Changed relative position by %d", relative_offset);
#endif
}