File: mpdclient.h

package info (click to toggle)
ncmpc 0.25-0.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,616 kB
  • sloc: ansic: 12,229; sh: 4,157; makefile: 282; ruby: 28
file content (209 lines) | stat: -rw-r--r-- 4,590 bytes parent folder | download
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef MPDCLIENT_H
#define MPDCLIENT_H

#include "playlist.h"
#include "Compiler.h"

#include <mpd/client.h>

struct filelist;

struct mpdclient {
	/* playlist */
	struct mpdclient_playlist playlist;

	struct mpd_connection *connection;

	/**
	 * This attribute is incremented whenever the connection changes
	 * (i.e. on disconnection and (re-)connection).
	 */
	unsigned connection_id;

	/**
	 * If this object is non-NULL, it tracks idle events.  It is
	 * automatically called by mpdclient_get_connection() and
	 * mpdclient_put_connection().  It is not created by the
	 * mpdclient library; the user of this library has to
	 * initialize it.  However, it is freed when the MPD
	 * connection is closed.
	 */
	struct mpd_glib_source *source;

	/**
	 * This attribute is true when the connection is currently in
	 * "idle" mode, and the #mpd_glib_source waits for an event.
	 */
	bool idle;

	struct mpd_status *status;
	const struct mpd_song *song;

	int volume;
	unsigned update_id;

	/**
	 * A bit mask of idle events occurred since the last update.
	 */
	enum mpd_idle events;
};

enum {
	/**
	 * all idle events the version of libmpdclient, ncmpc is compiled
	 * against, supports
	 */
	MPD_IDLE_ALL = MPD_IDLE_DATABASE
		| MPD_IDLE_STORED_PLAYLIST
		| MPD_IDLE_QUEUE
		| MPD_IDLE_PLAYER
		| MPD_IDLE_MIXER
		| MPD_IDLE_OUTPUT
		| MPD_IDLE_OPTIONS
		| MPD_IDLE_UPDATE
#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
		| MPD_IDLE_STICKER
		| MPD_IDLE_SUBSCRIPTION
		| MPD_IDLE_MESSAGE
#endif
};

/** functions ***************************************************************/

bool
mpdclient_handle_error(struct mpdclient *c);

static inline bool
mpdclient_finish_command(struct mpdclient *c)
{
	if (!c->connection)
		return false;

	return mpd_response_finish(c->connection)
		? true : mpdclient_handle_error(c);
}

struct mpdclient *
mpdclient_new(void);

void mpdclient_free(struct mpdclient *c);

gcc_pure
static inline bool
mpdclient_is_connected(const struct mpdclient *c)
{
	return c->connection != NULL;
}

gcc_pure
static inline bool
mpdclient_is_playing(const struct mpdclient *c)
{
	return c->status != NULL &&
		(mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
		 mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
}

gcc_pure
static inline const struct mpd_song *
mpdclient_get_current_song(const struct mpdclient *c)
{
	return c->song != NULL && mpdclient_is_playing(c)
		? c->song
		: NULL;
}

bool
mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
		  unsigned timeout_ms, const gchar *password);

void
mpdclient_disconnect(struct mpdclient *c);

bool
mpdclient_update(struct mpdclient *c);

struct mpd_connection *
mpdclient_get_connection(struct mpdclient *c);

void
mpdclient_put_connection(struct mpdclient *c);

/**
 * To be implemented by the application: mpdclient.c calls this to
 * display an error message.
 */
void
mpdclient_ui_error(const char *message);

/*** MPD Commands  **********************************************************/

bool
mpdclient_cmd_crop(struct mpdclient *c);

bool
mpdclient_cmd_clear(struct mpdclient *c);

bool
mpdclient_cmd_volume(struct mpdclient *c, gint value);

bool
mpdclient_cmd_volume_up(struct mpdclient *c);

bool
mpdclient_cmd_volume_down(struct mpdclient *c);

bool
mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);

bool
mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);

bool
mpdclient_cmd_delete(struct mpdclient *c, gint index);

bool
mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);

bool
mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);

#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
bool
mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);

bool
mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);

bool
mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
			   const char *text);

bool
mpdclient_send_read_messages(struct mpdclient *c);

struct mpd_message *
mpdclient_recv_message(struct mpdclient *c);
#endif

/*** playlist functions  **************************************************/

/* update the complete playlist */
bool
mpdclient_playlist_update(struct mpdclient *c);

/* get playlist changes */
bool
mpdclient_playlist_update_changes(struct mpdclient *c);

/* add all songs in filelist to the playlist */
bool
mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);

/* sort by song format */
gcc_pure
gint compare_filelistentry_format(gconstpointer filelist_entry1,
				  gconstpointer filelist_entry2,
				  const char *song_format);

#endif