1[CCode (cprefix = "mpd_", cheader_filename = "libmpd/libmpd.h")]
2
3namespace MPD {
4
5    [CCode (cname = "MpdObj",cprefix="mpd_", cheader_filename="libmpd/libmpd.h")]
6    [Compact]
7    public class Server {
8
9        [CCode (cname="mpd_check_connected")]
10        public bool check_connected();
11
12        public bool connected { get { return check_connected();}}
13
14
15        public MPD.Song playlist_get_song(int songid);
16        public unowned MPD.Song playlist_get_current_song();
17        public int player_get_next_song_id();
18        [CCode (cname="mpd_server_get_database_update_time")]
19        public int get_database_update_time();
20        [CCode (cname="mpd_status_db_is_updating")]
21        public bool is_updating_database();
22        [CCode (cname="mpd_server_tag_supported")]
23        public bool tag_supported(MPD.Tag.Type tag);
24    }
25
26
27    [CCode (cname = "mpd_Song",
28    free_function = "mpd_freeSong",
29    copy_function = "mpd_songDup",
30    cheader_filename = "libmpd/libmpdclient.h,libmpd/libmpd.h,misc.h")]
31    [Compact]
32    [Immutable]
33    public class Song {
34        [CCode (cname = "mpd_newSong")]
35        public Song ();
36        public string file;
37        public string artist;
38        public string title;
39        public string album;
40        public string track;
41        public string name;
42        public string date;
43        public string genre;
44        public string performer;
45        public string disc;
46        public string comment;
47        public string albumartist;
48        public int    time;
49        public int    pos;
50        public int    id;
51        [CCode (cname="mpd_songDup0")]
52        public static Song copy (Song? s);
53        [CCode (instance_pos = -1)]
54        public void markup (char[] buffer, int length, string markup);
55    }
56    namespace Sticker {
57        namespace Song {
58            public void     set(MPD.Server connection, string file, string tag, string value);
59            public string   get(MPD.Server connection, string file, string tag);
60        }
61        public bool supported(MPD.Server connection);
62    }
63    namespace Status {
64        [CCode (cname="ChangedStatusType", cprefix = "MPD_CST_",
65            cheader_filename = "libmpd/libmpd.h",
66            has_type_id=false)]
67            public enum Changed {
68                /** The playlist has changed */
69                PLAYLIST      = 0x0001,
70                /** The song position of the playing song has changed*/
71                SONGPOS       = 0x0002,
72                /** The songid of the playing song has changed */
73                SONGID        = 0x0004,
74                /** The database has changed. */
75                DATABASE      = 0x0008,
76                /** the state of updating the database has changed.*/
77                UPDATING      = 0x0010,
78                /** the volume has changed */
79                VOLUME        = 0x0020,
80                /** The total time of the currently playing song has changed*/
81                TOTAL_TIME    = 0x0040,
82                /** The elapsed time of the current song has changed.*/
83                ELAPSED_TIME  = 0x0080,
84                /** The crossfade time has changed. */
85                CROSSFADE     = 0x0100,
86                /** The random state is changed.     */
87                RANDOM        = 0x0200,
88                /** repeat state is changed.     */
89                REPEAT        = 0x0400,
90                /** Not implemented  */
91                AUDIO         = 0x0800,
92                /** The state of the player has changed.*/
93                STATE         = 0x1000,
94                /** The permissions the client has, has changed.*/
95                PERMISSION    = 0x2000,
96                /** The bitrate of the playing song has changed.    */
97                BITRATE       = 0x4000,
98                /** the audio format of the playing song changed.*/
99                AUDIOFORMAT   = 0x8000,
100                /** the queue has changed */
101                STORED_PLAYLIST		  = 0x20000,
102                /** server error */
103                SERVER_ERROR        = 0x40000,
104                /** output changed */
105                OUTPUT              = 0x80000,
106                /** sticker changed */
107                STICKER             = 0x100000,
108                NEXTSONG            = 0x200000,
109                SINGLE_MODE         = 0x400000,
110                CONSUME_MODE        = 0x800000
111            }
112
113            [CCode (cname="mpd_status_get_bitrate")]
114            public int get_bitrate(MPD.Server server);
115            [CCode (cname="mpd_status_get_samplerate")]
116            public int get_samplerate(MPD.Server server);
117            [CCode (cname="mpd_status_get_channels")]
118            public int get_channels(MPD.Server server);
119    }
120    namespace Data{
121        [CCode (cname="MpdDataType", cprefix = "MPD_DATA_TYPE_", cheader_filename = "libmpd/libmpd.h")]
122            public enum Type {
123                NONE,
124                TAG,
125                DIRECTORY,
126                SONG,
127                PLAYLIST,
128                OUTPUT_DEV
129            }
130    [CCode (cname = "mpd_PlaylistFile",
131    free_function = "mpd_freePlaylistFile",
132    copy_function = "mpd_playlistFileDup",
133    cheader_filename = "libmpd/libmpdclient.h,libmpd/libmpd.h")]
134    [Compact]
135    [Immutable]
136    public class Playlist{
137        [CCode (cname="mpd_newPlaylistFile")]
138        public Playlist();
139
140        public string *path;
141        public string *mtime;
142    }
143
144            [CCode (cname = "MpdData",
145                free_function = "mpd_data_free",
146                cheader_filename = "libmpd/libmpd.h")]
147            [Compact]
148            public class Item {
149                public Data.Type type;
150                public MPD.Song  song;
151                public string tag;
152                public Playlist playlist;
153
154                [CCode (cname="mpd_data_get_next")]
155                [ReturnsModifiedPointer ()]
156                public void next_free();
157
158
159                [CCode (cheader_filename="misc.h", cname="misc_sort_mpddata_by_album_disc_track")]
160                [ReturnsModifiedPointer ()]
161                public void sort_album_disc_track();
162
163                [CCode (cname="misc_mpddata_remove_duplicate_songs")]
164                [ReturnsModifiedPointer ()]
165                public void remove_duplicate_songs();
166
167                [CCode (cname="mpd_data_get_next_real", cheader_filename="libmpd/libmpd-internal.h")]
168                [ReturnsModifiedPointer ()]
169                public void next(bool free);
170
171                [CCode (cname="mpd_data_get_first")]
172                public unowned Item? get_first();
173
174                [CCode (cname="mpd_data_get_first")]
175                [ReturnsModifiedPointer ()]
176                public void first();
177
178                [CCode (cname="mpd_data_concatenate")]
179                [ReturnsModifiedPointer ()]
180                public void concatenate(owned MPD.Data.Item b);
181
182                [CCode (cname="mpd_new_data_struct_append")]
183                [ReturnsModifiedPointer ()]
184                public void append_new();
185            }
186    }
187    namespace PlayQueue {
188        [CCode (cname="mpd_playlist_add")]
189        public void add_song(MPD.Server server, string path);
190
191        [CCode (cname="mpd_playlist_queue_add")]
192        public void queue_add_song(MPD.Server server, string path);
193        [CCode (cname="mpd_playlist_queue_commit")]
194        public void queue_commit(MPD.Server server);
195        [CCode (cname="mpd_playlist_clear")]
196        public void clear(MPD.Server server);
197
198        public void add_artist(MPD.Server server, string artist)
199        {
200            MPD.Database.search_start(server,true);
201            MPD.Database.search_add_constraint(server, MPD.Tag.Type.ARTIST, artist);
202            var data = MPD.Database.search_commit(server);
203            if(data != null) {
204                data.sort_album_disc_track();
205                while(data != null){
206                    MPD.PlayQueue.queue_add_song(server, data.song.file);
207                    data.next_free();
208                }
209                MPD.PlayQueue.queue_commit(server);
210            }
211        }
212        public void add_album(MPD.Server server, string? artist, string? album, string? album_artist=null)
213        {
214            MPD.Database.search_start(server,true);
215            if(album_artist != null)
216                MPD.Database.search_add_constraint(server, MPD.Tag.Type.ALBUM_ARTIST, album_artist);
217            else
218                MPD.Database.search_add_constraint(server, MPD.Tag.Type.ARTIST, artist);
219            MPD.Database.search_add_constraint(server, MPD.Tag.Type.ALBUM, album);
220            var data = MPD.Database.search_commit(server);
221            if(data != null) {
222                data.sort_album_disc_track();
223                while(data != null){
224                    MPD.PlayQueue.queue_add_song(server, data.song.file);
225                    data.next_free();
226                }
227                MPD.PlayQueue.queue_commit(server);
228            }
229        }
230    }
231
232    namespace Player {
233        [CCode (cname="mpd_player_play")]
234        public void play(MPD.Server server);
235        public void next(MPD.Server server);
236        public void prev(MPD.Server server);
237        public void pause(MPD.Server server);
238        public void stop(MPD.Server server);
239        public MPD.Player.State get_state(MPD.Server server);
240        [CCode (cprefix="MPD_STATUS_STATE_", cname="int")]
241        public enum State{
242            UNKNOWN = 0,
243            STOP    = 1,
244            PLAY    = 2,
245            PAUSE   = 3
246        }
247    }
248
249    namespace Database {
250        public MPD.Data.Item? get_playlist_content(MPD.Server server, string playlist_name);
251        [CCode (cname="mpd_database_playlist_list")]
252        public MPD.Data.Item? get_playlist_list(MPD.Server server);
253        public void playlist_list_add(MPD.Server server, string playlist_name, string path);
254        public void playlist_list_delete(MPD.Server server, string playlist_name, int pos);
255
256        [CCode (cname="mpd_database_search_field_start")]
257        public void search_field_start(MPD.Server server,MPD.Tag.Type type);
258
259        [CCode (cname="mpd_database_search_start")]
260        public void search_start(MPD.Server server,bool exact);
261        public MPD.Data.Item? search_commit(MPD.Server server);
262
263        [CCode (cname="mpd_database_search_add_constraint")]
264        public void search_add_constraint(MPD.Server server, MPD.Tag.Type type, string value);
265
266    }
267
268    namespace Tag {
269        [CCode (cname="mpd_TagItems", cprefix = "MPD_TAG_ITEM_", cheader_filename = "libmpd/libmpdclient.h")]
270            public enum Type{
271                ARTIST,
272                    ALBUM,
273                    TITLE,
274                    TRACK,
275                    NAME,
276                    GENRE,
277                    DATE,
278                    COMPOSER,
279                    PERFORMER,
280                    COMMENT,
281                    DISC,
282                    FILENAME,
283                    ALBUM_ARTIST,
284                    ANY
285            }
286    }
287
288}
289