Code

1d4dbc94de6f86da2ace405056756e446dfa306a
[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          * This attribute is incremented whenever the connection changes
19          * (i.e. on disconnection and (re-)connection).
20          */
21         unsigned connection_id;
23         /**
24          * Tracks idle events.  It is automatically called by
25          * mpdclient_get_connection() and mpdclient_put_connection().
26          */
27         struct mpd_glib_source *source;
29         /**
30          * This attribute is true when the connection is currently in
31          * "idle" mode, and the #mpd_glib_source waits for an event.
32          */
33         bool idle;
35         struct mpd_status *status;
36         const struct mpd_song *song;
38         int volume;
40         /**
41          * A bit mask of idle events occurred since the last update.
42          */
43         enum mpd_idle events;
44 };
46 enum {
47         /**
48          * all idle events the version of libmpdclient, ncmpc is compiled
49          * against, supports
50          */
51         MPD_IDLE_ALL = MPD_IDLE_DATABASE
52                 | MPD_IDLE_STORED_PLAYLIST
53                 | MPD_IDLE_QUEUE
54                 | MPD_IDLE_PLAYER
55                 | MPD_IDLE_MIXER
56                 | MPD_IDLE_OUTPUT
57                 | MPD_IDLE_OPTIONS
58                 | MPD_IDLE_UPDATE
59                 | MPD_IDLE_STICKER
60                 | MPD_IDLE_SUBSCRIPTION
61                 | MPD_IDLE_MESSAGE
62 };
64 /** functions ***************************************************************/
66 bool
67 mpdclient_handle_error(struct mpdclient *c);
69 static inline bool
70 mpdclient_finish_command(struct mpdclient *c)
71 {
72         return mpd_response_finish(c->connection)
73                 ? true : mpdclient_handle_error(c);
74 }
76 struct mpdclient *
77 mpdclient_new(void);
79 void mpdclient_free(struct mpdclient *c);
81 gcc_pure
82 static inline bool
83 mpdclient_is_connected(const struct mpdclient *c)
84 {
85         return c->connection != NULL;
86 }
88 gcc_pure
89 static inline bool
90 mpdclient_is_playing(const struct mpdclient *c)
91 {
92         return c->status != NULL &&
93                 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
94                  mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
95 }
97 gcc_pure
98 static inline const struct mpd_song *
99 mpdclient_get_current_song(const struct mpdclient *c)
101         return c->song != NULL && mpdclient_is_playing(c)
102                 ? c->song
103                 : NULL;
106 bool
107 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
108                   unsigned timeout_ms, const gchar *password);
110 void
111 mpdclient_disconnect(struct mpdclient *c);
113 bool
114 mpdclient_update(struct mpdclient *c);
116 struct mpd_connection *
117 mpdclient_get_connection(struct mpdclient *c);
119 void
120 mpdclient_put_connection(struct mpdclient *c);
122 /*** MPD Commands  **********************************************************/
124 bool
125 mpdclient_cmd_crop(struct mpdclient *c);
127 bool
128 mpdclient_cmd_clear(struct mpdclient *c);
130 bool
131 mpdclient_cmd_volume(struct mpdclient *c, gint value);
133 bool
134 mpdclient_cmd_volume_up(struct mpdclient *c);
136 bool
137 mpdclient_cmd_volume_down(struct mpdclient *c);
139 bool
140 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
142 bool
143 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
145 bool
146 mpdclient_cmd_delete(struct mpdclient *c, gint index);
148 bool
149 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
151 bool
152 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
154 bool
155 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
157 bool
158 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
160 bool
161 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
162                            const char *text);
164 bool
165 mpdclient_send_read_messages(struct mpdclient *c);
167 struct mpd_message *
168 mpdclient_recv_message(struct mpdclient *c);
170 /*** playlist functions  **************************************************/
172 /* update the complete playlist */
173 bool
174 mpdclient_playlist_update(struct mpdclient *c);
176 /* get playlist changes */
177 bool
178 mpdclient_playlist_update_changes(struct mpdclient *c);
180 /* add all songs in filelist to the playlist */
181 bool
182 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
184 #endif