Code

b06c7a042679d97dde9e6e059057cfb8bb5b4c7f
[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;
15         struct mpd_status *status;
16         const struct mpd_song *song;
18         int volume;
19         unsigned update_id;
21         /**
22          * A bit mask of idle events occured since the last update.
23          */
24         enum mpd_idle events;
25 };
27 /** functions ***************************************************************/
29 gint
30 mpdclient_handle_error(struct mpdclient *c);
32 struct mpdclient *
33 mpdclient_new(void);
35 void mpdclient_free(struct mpdclient *c);
37 static inline bool
38 mpdclient_is_connected(const struct mpdclient *c)
39 {
40         return c->connection != NULL;
41 }
43 static inline const struct mpd_song *
44 mpdclient_get_current_song(const struct mpdclient *c)
45 {
46         return c->song != NULL && c->status != NULL &&
47                 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
48                  mpd_status_get_state(c->status) == MPD_STATE_PAUSE)
49                 ? c->song
50                 : NULL;
51 }
53 bool
54 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
55                   gfloat timeout_, const gchar *password);
57 void
58 mpdclient_disconnect(struct mpdclient *c);
60 bool
61 mpdclient_update(struct mpdclient *c);
63 /**
64  * To be implemented by the application: mpdclient.c calls this to
65  * display an error message.
66  */
67 void
68 mpdclient_ui_error(const char *message);
70 /*** MPD Commands  **********************************************************/
71 gint mpdclient_cmd_play(struct mpdclient *c, gint index);
72 gint
73 mpdclient_cmd_crop(struct mpdclient *c);
74 gint mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end);
75 gint mpdclient_cmd_clear(struct mpdclient *c);
76 gint mpdclient_cmd_volume(struct mpdclient *c, gint value);
77 gint mpdclient_cmd_volume_up(struct mpdclient *c);
78 gint mpdclient_cmd_volume_down(struct mpdclient *c);
79 gint mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
81 gint mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
82 gint mpdclient_cmd_delete(struct mpdclient *c, gint index);
84 gint
85 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
87 gint mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
89 gint mpdclient_cmd_save_playlist(struct mpdclient *c, const gchar *filename);
90 gint mpdclient_cmd_load_playlist(struct mpdclient *c, const gchar *filename_utf8);
91 gint mpdclient_cmd_delete_playlist(struct mpdclient *c, const gchar *filename_utf8);
93 /* list functions */
94 GList *mpdclient_get_artists(struct mpdclient *c);
95 GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8);
98 /*** error callbacks *****************************************************/
100 #define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8)
102 /*** playlist functions  **************************************************/
104 /* update the complete playlist */
105 bool
106 mpdclient_playlist_update(struct mpdclient *c);
108 /* get playlist changes */
109 bool
110 mpdclient_playlist_update_changes(struct mpdclient *c);
113 /*** filelist functions  ***************************************************/
115 struct filelist *
116 mpdclient_filelist_get(struct mpdclient *c, const gchar *path);
118 struct filelist *
119 mpdclient_filelist_search(struct mpdclient *c, int exact_match,
120                           enum mpd_tag_type tag,
121                           gchar *filter_utf8);
123 /* add all songs in filelist to the playlist */
124 int
125 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
127 /* sort by list-format */
128 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
130 #endif