Code

b959f5c426d9e36cd70138510354a7739c3ee7e3
[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         /* playlist */
13         struct mpdclient_playlist playlist;
15         struct mpd_connection *connection;
17         /**
18          * Tracks idle events.  It is automatically called by
19          * mpdclient_get_connection() and mpdclient_put_connection().
20          */
21         struct mpd_glib_source *source;
23         struct mpd_status *status;
24         const struct mpd_song *song;
26         /**
27          * This attribute is incremented whenever the connection changes
28          * (i.e. on disconnection and (re-)connection).
29          */
30         unsigned connection_id;
32         int volume;
34         /**
35          * A bit mask of idle events occurred since the last update.
36          */
37         enum mpd_idle events;
39         /**
40          * This attribute is true when the connection is currently in
41          * "idle" mode, and the #mpd_glib_source waits for an event.
42          */
43         bool idle;
45         /**
46          * Is MPD currently playing?
47          */
48         bool playing;
49 };
51 enum {
52         /**
53          * all idle events the version of libmpdclient, ncmpc is compiled
54          * against, supports
55          */
56         MPD_IDLE_ALL = MPD_IDLE_DATABASE
57                 | MPD_IDLE_STORED_PLAYLIST
58                 | MPD_IDLE_QUEUE
59                 | MPD_IDLE_PLAYER
60                 | MPD_IDLE_MIXER
61                 | MPD_IDLE_OUTPUT
62                 | MPD_IDLE_OPTIONS
63                 | MPD_IDLE_UPDATE
64                 | MPD_IDLE_STICKER
65                 | MPD_IDLE_SUBSCRIPTION
66                 | MPD_IDLE_MESSAGE
67 };
69 /** functions ***************************************************************/
71 bool
72 mpdclient_handle_error(struct mpdclient *c);
74 static inline bool
75 mpdclient_finish_command(struct mpdclient *c)
76 {
77         return mpd_response_finish(c->connection)
78                 ? true : mpdclient_handle_error(c);
79 }
81 struct mpdclient *
82 mpdclient_new(void);
84 void mpdclient_free(struct mpdclient *c);
86 gcc_pure
87 static inline bool
88 mpdclient_is_connected(const struct mpdclient *c)
89 {
90         return c->connection != NULL;
91 }
93 /**
94  * Is this object "dead"?  i.e. not connected and not currently doing
95  * anything to connect.
96  */
97 gcc_pure
98 static inline bool
99 mpdclient_is_dead(const struct mpdclient *c)
101         return c->connection == NULL;
104 gcc_pure
105 static inline bool
106 mpdclient_is_playing(const struct mpdclient *c)
108         return c->status != NULL &&
109                 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
110                  mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
113 gcc_pure
114 static inline const struct mpd_song *
115 mpdclient_get_current_song(const struct mpdclient *c)
117         return c->song != NULL && mpdclient_is_playing(c)
118                 ? c->song
119                 : NULL;
122 bool
123 mpdclient_connect(struct mpdclient *c, const gchar *host, unsigned port,
124                   unsigned timeout_ms, const gchar *password);
126 void
127 mpdclient_disconnect(struct mpdclient *c);
129 bool
130 mpdclient_update(struct mpdclient *c);
132 struct mpd_connection *
133 mpdclient_get_connection(struct mpdclient *c);
135 void
136 mpdclient_put_connection(struct mpdclient *c);
138 /*** MPD Commands  **********************************************************/
140 bool
141 mpdclient_cmd_crop(struct mpdclient *c);
143 bool
144 mpdclient_cmd_clear(struct mpdclient *c);
146 bool
147 mpdclient_cmd_volume(struct mpdclient *c, gint value);
149 bool
150 mpdclient_cmd_volume_up(struct mpdclient *c);
152 bool
153 mpdclient_cmd_volume_down(struct mpdclient *c);
155 bool
156 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
158 bool
159 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
161 bool
162 mpdclient_cmd_delete(struct mpdclient *c, gint index);
164 bool
165 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
167 bool
168 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
170 bool
171 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
173 bool
174 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
176 bool
177 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
178                            const char *text);
180 bool
181 mpdclient_send_read_messages(struct mpdclient *c);
183 struct mpd_message *
184 mpdclient_recv_message(struct mpdclient *c);
186 /*** playlist functions  **************************************************/
188 /* update the complete playlist */
189 bool
190 mpdclient_playlist_update(struct mpdclient *c);
192 /* get playlist changes */
193 bool
194 mpdclient_playlist_update_changes(struct mpdclient *c);
196 /* add all songs in filelist to the playlist */
197 bool
198 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
200 #endif