8 #include <mpd/client.h>
13 #ifdef ENABLE_ASYNC_CONNECT
15 * These settings are used to connect to MPD asynchronously.
17 struct mpd_settings
*settings
;
21 * A second set of settings, just in case #settings did not
22 * work. This is only used if #settings refers to a local
23 * socket path, and this one is supposed to be a fallback to
24 * IP on the default port (6600).
26 struct mpd_settings
*settings2
;
39 struct mpdclient_playlist playlist
;
41 #ifdef ENABLE_ASYNC_CONNECT
42 struct aconnect
*async_connect
;
45 struct mpd_connection
*connection
;
48 * Tracks idle events. It is automatically called by
49 * mpdclient_get_connection().
51 struct mpd_glib_source
*source
;
53 struct mpd_status
*status
;
54 const struct mpd_song
*song
;
57 * The GLib source id which re-enters MPD idle mode before the
58 * next main loop interation.
60 unsigned enter_idle_source_id
;
63 * This attribute is incremented whenever the connection changes
64 * (i.e. on disconnection and (re-)connection).
66 unsigned connection_id
;
71 * A bit mask of idle events occurred since the last update.
75 #if defined(ENABLE_ASYNC_CONNECT) && !defined(WIN32)
80 * This attribute is true when the connection is currently in
81 * "idle" mode, and the #mpd_glib_source waits for an event.
86 * Is MPD currently playing?
93 * all idle events the version of libmpdclient, ncmpc is compiled
96 MPD_IDLE_ALL
= MPD_IDLE_DATABASE
97 | MPD_IDLE_STORED_PLAYLIST
105 | MPD_IDLE_SUBSCRIPTION
109 /** functions ***************************************************************/
112 mpdclient_handle_error(struct mpdclient
*c
);
115 mpdclient_finish_command(struct mpdclient
*c
)
117 return mpd_response_finish(c
->connection
)
118 ? true : mpdclient_handle_error(c
);
122 mpdclient_new(const gchar
*host
, unsigned port
,
123 unsigned timeout_ms
, const gchar
*password
);
125 void mpdclient_free(struct mpdclient
*c
);
128 * Determine a human-readable "name" of the settings currently used to
131 * @return an allocated string that needs to be freed (with g_free())
135 mpdclient_settings_name(const struct mpdclient
*c
);
139 mpdclient_is_connected(const struct mpdclient
*c
)
141 return c
->connection
!= NULL
;
145 * Is this object "dead"? i.e. not connected and not currently doing
146 * anything to connect.
150 mpdclient_is_dead(const struct mpdclient
*c
)
152 return c
->connection
== NULL
153 #ifdef ENABLE_ASYNC_CONNECT
154 && c
->async_connect
== NULL
161 mpdclient_is_playing(const struct mpdclient
*c
)
163 return c
->status
!= NULL
&&
164 (mpd_status_get_state(c
->status
) == MPD_STATE_PLAY
||
165 mpd_status_get_state(c
->status
) == MPD_STATE_PAUSE
);
169 static inline const struct mpd_song
*
170 mpdclient_get_current_song(const struct mpdclient
*c
)
172 return c
->song
!= NULL
&& mpdclient_is_playing(c
)
178 mpdclient_connect(struct mpdclient
*c
);
181 mpdclient_disconnect(struct mpdclient
*c
);
184 mpdclient_update(struct mpdclient
*c
);
186 struct mpd_connection
*
187 mpdclient_get_connection(struct mpdclient
*c
);
189 /*** MPD Commands **********************************************************/
192 mpdclient_cmd_crop(struct mpdclient
*c
);
195 mpdclient_cmd_clear(struct mpdclient
*c
);
198 mpdclient_cmd_volume(struct mpdclient
*c
, gint value
);
201 mpdclient_cmd_volume_up(struct mpdclient
*c
);
204 mpdclient_cmd_volume_down(struct mpdclient
*c
);
207 mpdclient_cmd_add_path(struct mpdclient
*c
, const gchar
*path
);
210 mpdclient_cmd_add(struct mpdclient
*c
, const struct mpd_song
*song
);
213 mpdclient_cmd_delete(struct mpdclient
*c
, gint index
);
216 mpdclient_cmd_delete_range(struct mpdclient
*c
, unsigned start
, unsigned end
);
219 mpdclient_cmd_move(struct mpdclient
*c
, unsigned dest
, unsigned src
);
222 mpdclient_cmd_subscribe(struct mpdclient
*c
, const char *channel
);
225 mpdclient_cmd_unsubscribe(struct mpdclient
*c
, const char *channel
);
228 mpdclient_cmd_send_message(struct mpdclient
*c
, const char *channel
,
232 mpdclient_send_read_messages(struct mpdclient
*c
);
235 mpdclient_recv_message(struct mpdclient
*c
);
237 /*** playlist functions **************************************************/
239 /* update the complete playlist */
241 mpdclient_playlist_update(struct mpdclient
*c
);
243 /* get playlist changes */
245 mpdclient_playlist_update_changes(struct mpdclient
*c
);
247 /* add all songs in filelist to the playlist */
249 mpdclient_filelist_add_all(struct mpdclient
*c
, struct filelist
*fl
);