Code

a93db74baf135392acba5ff418bc3f18d2dffc6d
[ncmpc.git] / src / mpdclient.h
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 occured since the last update.
40          */
41         enum mpd_idle events;
42 };
44 /** functions ***************************************************************/
46 bool
47 mpdclient_handle_error(struct mpdclient *c);
49 struct mpdclient *
50 mpdclient_new(void);
52 void mpdclient_free(struct mpdclient *c);
54 static inline bool
55 mpdclient_is_connected(const struct mpdclient *c)
56 {
57         return c->connection != NULL;
58 }
60 G_GNUC_PURE
61 static inline bool
62 mpdclient_is_playing(const struct mpdclient *c)
63 {
64         return c->status != NULL &&
65                 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
66                  mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
67 }
69 static inline const struct mpd_song *
70 mpdclient_get_current_song(const struct mpdclient *c)
71 {
72         return c->song != NULL && mpdclient_is_playing(c)
73                 ? c->song
74                 : NULL;
75 }
77 bool
78 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
79                   gfloat timeout_, const gchar *password);
81 void
82 mpdclient_disconnect(struct mpdclient *c);
84 bool
85 mpdclient_update(struct mpdclient *c);
87 struct mpd_connection *
88 mpdclient_get_connection(struct mpdclient *c);
90 void
91 mpdclient_put_connection(struct mpdclient *c);
93 /**
94  * To be implemented by the application: mpdclient.c calls this to
95  * display an error message.
96  */
97 void
98 mpdclient_ui_error(const char *message);
100 /*** MPD Commands  **********************************************************/
102 bool
103 mpdclient_cmd_crop(struct mpdclient *c);
105 bool
106 mpdclient_cmd_clear(struct mpdclient *c);
108 bool
109 mpdclient_cmd_volume(struct mpdclient *c, gint value);
111 bool
112 mpdclient_cmd_volume_up(struct mpdclient *c);
114 bool
115 mpdclient_cmd_volume_down(struct mpdclient *c);
117 bool
118 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
120 bool
121 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
123 bool
124 mpdclient_cmd_delete(struct mpdclient *c, gint index);
126 bool
127 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
129 bool
130 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
132 /*** playlist functions  **************************************************/
134 /* update the complete playlist */
135 bool
136 mpdclient_playlist_update(struct mpdclient *c);
138 /* get playlist changes */
139 bool
140 mpdclient_playlist_update_changes(struct mpdclient *c);
142 /* add all songs in filelist to the playlist */
143 bool
144 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
146 /* sort by list-format */
147 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
149 #endif