6 #include "util/Compiler.h"
8 #include <mpd/client.h>
12 struct AsyncMpdConnect;
18 #ifdef ENABLE_ASYNC_CONNECT
20 * These settings are used to connect to MPD asynchronously.
22 struct mpd_settings *settings;
26 * A second set of settings, just in case #settings did not
27 * work. This is only used if #settings refers to a local
28 * socket path, and this one is supposed to be a fallback to
29 * IP on the default port (6600).
31 struct mpd_settings *settings2;
39 const unsigned timeout_ms;
41 const char *const password;
46 #ifdef ENABLE_ASYNC_CONNECT
47 AsyncMpdConnect *async_connect = nullptr;
50 struct mpd_connection *connection = nullptr;
53 * Tracks idle events. It is automatically called by
54 * mpdclient_get_connection().
56 MpdIdleSource *source = nullptr;
58 struct mpd_status *status = nullptr;
59 const struct mpd_song *song = nullptr;
62 * The GLib source id which re-enters MPD idle mode before the
63 * next main loop interation.
65 unsigned enter_idle_source_id = 0;
68 * This attribute is incremented whenever the connection changes
69 * (i.e. on disconnection and (re-)connection).
71 unsigned connection_id = 0;
76 * A bit mask of idle events occurred since the last update.
80 enum mpd_state state = MPD_STATE_UNKNOWN;
82 #if defined(ENABLE_ASYNC_CONNECT) && !defined(_WIN32)
87 * This attribute is true when the connection is currently in
88 * "idle" mode, and the #mpd_glib_source waits for an event.
93 * Is MPD currently playing?
98 * Is MPD currently playing or paused?
100 bool playing_or_paused = false;
102 mpdclient(const char *host, unsigned port,
103 unsigned _timeout_ms, const char *_password);
108 #ifdef ENABLE_ASYNC_CONNECT
109 mpd_settings_free(settings);
112 if (settings2 != nullptr)
113 mpd_settings_free(settings2);
119 * Determine a human-readable "name" of the settings currently used to
122 * @return an allocated string that needs to be freed (with g_free())
125 std::string GetSettingsName() const;
127 bool IsConnected() const {
128 return connection != nullptr;
132 * Is this object "dead"? i.e. not connected and not
133 * currently doing anything to connect.
136 bool IsDead() const {
137 return connection == nullptr
138 #ifdef ENABLE_ASYNC_CONNECT
139 && async_connect == nullptr
145 const struct mpd_song *GetCurrentSong() const {
146 return song != nullptr && playing_or_paused
157 struct mpd_connection *GetConnection();
159 bool FinishCommand() {
160 return mpd_response_finish(connection) || HandleError();
167 bool UpdateQueueChanges();
172 * all idle events the version of libmpdclient, ncmpc is compiled
175 MPD_IDLE_ALL = MPD_IDLE_DATABASE
176 | MPD_IDLE_STORED_PLAYLIST
184 | MPD_IDLE_SUBSCRIPTION
188 /*** MPD Commands **********************************************************/
191 mpdclient_cmd_crop(struct mpdclient *c);
194 mpdclient_cmd_clear(struct mpdclient *c);
197 mpdclient_cmd_volume(struct mpdclient *c, int value);
200 mpdclient_cmd_volume_up(struct mpdclient *c);
203 mpdclient_cmd_volume_down(struct mpdclient *c);
206 mpdclient_cmd_add_path(struct mpdclient *c, const char *path);
209 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
212 mpdclient_cmd_delete(struct mpdclient *c, int index);
215 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
218 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
221 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
224 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
227 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,