Code

mpdclient: added function mpdclient_get_current_song()
[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);
83 gint mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
85 gint mpdclient_cmd_save_playlist(struct mpdclient *c, const gchar *filename);
86 gint mpdclient_cmd_load_playlist(struct mpdclient *c, const gchar *filename_utf8);
87 gint mpdclient_cmd_delete_playlist(struct mpdclient *c, const gchar *filename_utf8);
89 /* list functions */
90 GList *mpdclient_get_artists(struct mpdclient *c);
91 GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8);
94 /*** error callbacks *****************************************************/
96 #define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8)
98 /*** playlist functions  **************************************************/
100 /* update the complete playlist */
101 bool
102 mpdclient_playlist_update(struct mpdclient *c);
104 /* get playlist changes */
105 bool
106 mpdclient_playlist_update_changes(struct mpdclient *c);
109 /*** filelist functions  ***************************************************/
111 struct filelist *
112 mpdclient_filelist_get(struct mpdclient *c, const gchar *path);
114 struct filelist *
115 mpdclient_filelist_search(struct mpdclient *c, int exact_match,
116                           enum mpd_tag_type tag,
117                           gchar *filter_utf8);
119 /* add all songs in filelist to the playlist */
120 int
121 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
123 /* sort by list-format */
124 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
126 #endif