7cdf7f5da121021f1726fe5a703e3489a944bbcf
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
4 #include "playlist.h"
6 #include <mpd/client.h>
8 struct filelist;
10 struct mpdclient {
11 /* playlist */
12 struct mpdclient_playlist playlist;
14 struct mpd_connection *connection;
16 /**
17 * If this object is non-NULL, it tracks idle events. It is
18 * automatically called by mpdclient_get_connection() and
19 * mpdclient_put_connection(). It is not created by the
20 * mpdclient library; the user of this library has to
21 * initialize it. However, it is freed when the MPD
22 * connection is closed.
23 */
24 struct mpd_glib_source *source;
26 /**
27 * This attribute is true when the connection is currently in
28 * "idle" mode, and the #mpd_glib_source waits for an event.
29 */
30 bool idle;
32 struct mpd_status *status;
33 const struct mpd_song *song;
35 int volume;
36 unsigned update_id;
38 /**
39 * A bit mask of idle events occurred since the last update.
40 */
41 enum mpd_idle events;
42 };
44 enum {
45 /**
46 * all idle events the version of libmpdclient, ncmpc is compiled
47 * against, supports
48 */
49 MPD_IDLE_ALL = MPD_IDLE_DATABASE
50 | MPD_IDLE_STORED_PLAYLIST
51 | MPD_IDLE_QUEUE
52 | MPD_IDLE_PLAYER
53 | MPD_IDLE_MIXER
54 | MPD_IDLE_OUTPUT
55 | MPD_IDLE_OPTIONS
56 | MPD_IDLE_UPDATE
57 #if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
58 | MPD_IDLE_STICKER
59 | MPD_IDLE_SUBSCRIPTION
60 | MPD_IDLE_MESSAGE
61 #endif
62 };
64 /** functions ***************************************************************/
66 bool
67 mpdclient_handle_error(struct mpdclient *c);
69 struct mpdclient *
70 mpdclient_new(void);
72 void mpdclient_free(struct mpdclient *c);
74 static inline bool
75 mpdclient_is_connected(const struct mpdclient *c)
76 {
77 return c->connection != NULL;
78 }
80 G_GNUC_PURE
81 static inline bool
82 mpdclient_is_playing(const struct mpdclient *c)
83 {
84 return c->status != NULL &&
85 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
86 mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
87 }
89 static inline const struct mpd_song *
90 mpdclient_get_current_song(const struct mpdclient *c)
91 {
92 return c->song != NULL && mpdclient_is_playing(c)
93 ? c->song
94 : NULL;
95 }
97 bool
98 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
99 unsigned timeout_ms, const gchar *password);
101 void
102 mpdclient_disconnect(struct mpdclient *c);
104 bool
105 mpdclient_update(struct mpdclient *c);
107 struct mpd_connection *
108 mpdclient_get_connection(struct mpdclient *c);
110 void
111 mpdclient_put_connection(struct mpdclient *c);
113 /**
114 * To be implemented by the application: mpdclient.c calls this to
115 * display an error message.
116 */
117 void
118 mpdclient_ui_error(const char *message);
120 /*** MPD Commands **********************************************************/
122 bool
123 mpdclient_cmd_crop(struct mpdclient *c);
125 bool
126 mpdclient_cmd_clear(struct mpdclient *c);
128 bool
129 mpdclient_cmd_volume(struct mpdclient *c, gint value);
131 bool
132 mpdclient_cmd_volume_up(struct mpdclient *c);
134 bool
135 mpdclient_cmd_volume_down(struct mpdclient *c);
137 bool
138 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
140 bool
141 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
143 bool
144 mpdclient_cmd_delete(struct mpdclient *c, gint index);
146 bool
147 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
149 bool
150 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
152 /*** playlist functions **************************************************/
154 /* update the complete playlist */
155 bool
156 mpdclient_playlist_update(struct mpdclient *c);
158 /* get playlist changes */
159 bool
160 mpdclient_playlist_update_changes(struct mpdclient *c);
162 /* add all songs in filelist to the playlist */
163 bool
164 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
166 /* sort by list-format */
167 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
169 #endif