Code

bac33383ab1bc33ccb34a614b5091fda8080f2cf
[ncmpc.git] / src / mpdclient.h
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
4 #include "playlist.h"
5 #include "Compiler.h"
7 #include <mpd/client.h>
9 struct filelist;
11 struct mpdclient {
12         const char *host;
13         unsigned port;
15         unsigned timeout_ms;
17         const char *password;
19         /* playlist */
20         struct mpdclient_playlist playlist;
22         struct mpd_connection *connection;
24         /**
25          * Tracks idle events.  It is automatically called by
26          * mpdclient_get_connection().
27          */
28         struct mpd_glib_source *source;
30         struct mpd_status *status;
31         const struct mpd_song *song;
33         /**
34          * The GLib source id which re-enters MPD idle mode before the
35          * next main loop interation.
36          */
37         unsigned enter_idle_source_id;
39         /**
40          * This attribute is incremented whenever the connection changes
41          * (i.e. on disconnection and (re-)connection).
42          */
43         unsigned connection_id;
45         int volume;
47         /**
48          * A bit mask of idle events occurred since the last update.
49          */
50         enum mpd_idle events;
52         /**
53          * This attribute is true when the connection is currently in
54          * "idle" mode, and the #mpd_glib_source waits for an event.
55          */
56         bool idle;
58         /**
59          * Is MPD currently playing?
60          */
61         bool playing;
62 };
64 enum {
65         /**
66          * all idle events the version of libmpdclient, ncmpc is compiled
67          * against, supports
68          */
69         MPD_IDLE_ALL = MPD_IDLE_DATABASE
70                 | MPD_IDLE_STORED_PLAYLIST
71                 | MPD_IDLE_QUEUE
72                 | MPD_IDLE_PLAYER
73                 | MPD_IDLE_MIXER
74                 | MPD_IDLE_OUTPUT
75                 | MPD_IDLE_OPTIONS
76                 | MPD_IDLE_UPDATE
77                 | MPD_IDLE_STICKER
78                 | MPD_IDLE_SUBSCRIPTION
79                 | MPD_IDLE_MESSAGE
80 };
82 /** functions ***************************************************************/
84 bool
85 mpdclient_handle_error(struct mpdclient *c);
87 static inline bool
88 mpdclient_finish_command(struct mpdclient *c)
89 {
90         return mpd_response_finish(c->connection)
91                 ? true : mpdclient_handle_error(c);
92 }
94 struct mpdclient *
95 mpdclient_new(const gchar *host, unsigned port,
96               unsigned timeout_ms, const gchar *password);
98 void mpdclient_free(struct mpdclient *c);
100 gcc_pure
101 static inline bool
102 mpdclient_is_connected(const struct mpdclient *c)
104         return c->connection != NULL;
107 /**
108  * Is this object "dead"?  i.e. not connected and not currently doing
109  * anything to connect.
110  */
111 gcc_pure
112 static inline bool
113 mpdclient_is_dead(const struct mpdclient *c)
115         return c->connection == NULL;
118 gcc_pure
119 static inline bool
120 mpdclient_is_playing(const struct mpdclient *c)
122         return c->status != NULL &&
123                 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
124                  mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
127 gcc_pure
128 static inline const struct mpd_song *
129 mpdclient_get_current_song(const struct mpdclient *c)
131         return c->song != NULL && mpdclient_is_playing(c)
132                 ? c->song
133                 : NULL;
136 bool
137 mpdclient_connect(struct mpdclient *c);
139 void
140 mpdclient_disconnect(struct mpdclient *c);
142 bool
143 mpdclient_update(struct mpdclient *c);
145 struct mpd_connection *
146 mpdclient_get_connection(struct mpdclient *c);
148 /*** MPD Commands  **********************************************************/
150 bool
151 mpdclient_cmd_crop(struct mpdclient *c);
153 bool
154 mpdclient_cmd_clear(struct mpdclient *c);
156 bool
157 mpdclient_cmd_volume(struct mpdclient *c, gint value);
159 bool
160 mpdclient_cmd_volume_up(struct mpdclient *c);
162 bool
163 mpdclient_cmd_volume_down(struct mpdclient *c);
165 bool
166 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
168 bool
169 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
171 bool
172 mpdclient_cmd_delete(struct mpdclient *c, gint index);
174 bool
175 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
177 bool
178 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
180 bool
181 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
183 bool
184 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
186 bool
187 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
188                            const char *text);
190 bool
191 mpdclient_send_read_messages(struct mpdclient *c);
193 struct mpd_message *
194 mpdclient_recv_message(struct mpdclient *c);
196 /*** playlist functions  **************************************************/
198 /* update the complete playlist */
199 bool
200 mpdclient_playlist_update(struct mpdclient *c);
202 /* get playlist changes */
203 bool
204 mpdclient_playlist_update_changes(struct mpdclient *c);
206 /* add all songs in filelist to the playlist */
207 bool
208 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
210 #endif