1 /***************************************************************************
2 * Copyright (C) 2008-2009 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
26 #include <mpd/client.h>
33 extern const char *PartOfSongsAdded
;
34 extern const char *FullPlaylist
;
35 extern const char *FunctionDisabledFilteringEnabled
;
38 enum ItemType
{ itDirectory
, itSong
, itPlaylist
};
39 enum PlayerState
{ psUnknown
, psStop
, psPlay
, psPause
};
40 enum ReplayGainMode
{ rgmOff
, rgmTrack
, rgmAlbum
};
52 StatusChanges() : Playlist(0), SongID(0), Database(0), DBUpdating(0), Volume(0), ElapsedTime(0), Crossfade(0), Random(0), Repeat(0), Single(0), Consume(0), PlayerState(0), StatusFlags(0) { }
68 typedef std::pair
<std::string
, bool> Output
;
70 typedef std::vector
<Item
> ItemList
;
71 typedef std::vector
<Song
*> SongList
;
72 typedef std::vector
<std::string
> TagList
;
73 typedef std::vector
<Output
> OutputList
;
75 void FreeSongList(SongList
&);
76 void FreeItemList(ItemList
&);
80 typedef void (*StatusUpdater
) (Connection
*, StatusChanges
, void *);
81 typedef void (*ErrorHandler
) (Connection
*, int, const char *, void *);
88 bool Connected() const;
91 const std::string
& GetHostname() { return itsHost
; }
92 int GetPort() { return itsPort
; }
94 float Version() const;
96 bool SupportsIdle() const { return supportsIdle
; }
97 void OrderDataFetching() { hasData
= 1; }
98 int GetFD() const { return itsFD
; }
100 void SetHostname(const std::string
&);
101 void SetPort(int port
) { itsPort
= port
; }
102 void SetTimeout(int timeout
) { itsTimeout
= timeout
; }
103 void SetPassword(const std::string
&password
) { itsPassword
= password
; }
106 void SetStatusUpdater(StatusUpdater
, void *);
107 void SetErrorHandler(ErrorHandler
, void *);
110 bool UpdateDirectory(const std::string
&);
120 void Move(unsigned, unsigned);
121 void Swap(unsigned, unsigned);
124 void ClearPlaylist();
126 bool isPlaying() const { return GetState() > psStop
; }
128 PlayerState
GetState() const{ return itsCurrentStatus
? PlayerState(mpd_status_get_state(itsCurrentStatus
)) : psUnknown
; }
129 bool GetRepeat() const { return itsCurrentStatus
? mpd_status_get_repeat(itsCurrentStatus
) : 0; }
130 bool GetRandom() const { return itsCurrentStatus
? mpd_status_get_random(itsCurrentStatus
) : 0; }
131 bool GetSingle() const { return itsCurrentStatus
? mpd_status_get_single(itsCurrentStatus
) : 0; }
132 bool GetConsume() const { return itsCurrentStatus
? mpd_status_get_consume(itsCurrentStatus
) : 0; }
133 bool GetDBIsUpdating() const { return itsCurrentStatus
? mpd_status_get_update_id(itsCurrentStatus
) : 0; }
134 int GetVolume() const { return itsCurrentStatus
? mpd_status_get_volume(itsCurrentStatus
) : -1; }
135 unsigned GetCrossfade() const { return itsCurrentStatus
? mpd_status_get_crossfade(itsCurrentStatus
) : 0; }
136 unsigned GetPlaylistID() const { return itsCurrentStatus
? mpd_status_get_queue_version(itsCurrentStatus
) : 0; }
137 unsigned GetOldPlaylistID() const { return itsOldStatus
? mpd_status_get_queue_version(itsOldStatus
) : 0; }
138 unsigned GetElapsedTime() const { return itsCurrentStatus
? itsElapsed
: 0; }
139 int GetTotalTime() const { return itsCurrentStatus
? mpd_status_get_total_time(itsCurrentStatus
) : 0; }
140 unsigned GetBitrate() const { return itsCurrentStatus
? mpd_status_get_kbit_rate(itsCurrentStatus
) : 0; }
142 unsigned NumberOfArtists() const { return itsStats
? mpd_stats_get_number_of_artists(itsStats
) : 0; }
143 unsigned NumberOfAlbums() const { return itsStats
? mpd_stats_get_number_of_albums(itsStats
) : 0; }
144 unsigned NumberOfSongs() const { return itsStats
? mpd_stats_get_number_of_songs(itsStats
) : 0; }
145 unsigned long Uptime() const { return itsStats
? mpd_stats_get_uptime(itsStats
) : 0; }
146 unsigned long DBUpdateTime() const { return itsStats
? mpd_stats_get_db_update_time(itsStats
) : 0; }
147 unsigned long PlayTime() const { return itsStats
? mpd_stats_get_play_time(itsStats
) : 0; }
148 unsigned long DBPlayTime() const { return itsStats
? mpd_stats_get_db_play_time(itsStats
) : 0; }
150 size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength
; }
151 size_t GetPlaylistLength() const { return itsCurrentStatus
? mpd_status_get_queue_length(itsCurrentStatus
) : 0; }
152 void GetPlaylistChanges(unsigned, SongList
&);
154 const std::string
& GetErrorMessage() const { return itsErrorMessage
; }
155 int GetErrorCode() const { return itsErrorCode
; }
157 Song
GetCurrentSong();
158 int GetCurrentSongPos() const;
159 Song
GetSong(const std::string
&);
160 void GetPlaylistContent(const std::string
&, SongList
&);
162 void SetRepeat(bool);
163 void SetRandom(bool);
164 void SetSingle(bool);
165 void SetConsume(bool);
166 void SetCrossfade(unsigned);
167 void SetVolume(unsigned);
169 std::string
GetReplayGainMode();
170 void SetReplayGainMode(ReplayGainMode
);
172 int AddSong(const std::string
&, int = -1); // returns id of added song
173 int AddSong(const Song
&, int = -1); // returns id of added song
174 bool AddRandomSongs(size_t);
175 void Add(const std::string
&path
);
176 void Delete(unsigned);
177 void DeleteID(unsigned);
178 void Delete(const std::string
&, unsigned);
179 void StartCommandsList();
180 bool CommitCommandsList();
182 bool DeletePlaylist(const std::string
&);
183 bool SavePlaylist(const std::string
&);
184 void ClearPlaylist(const std::string
&);
185 void AddToPlaylist(const std::string
&, const Song
&);
186 void AddToPlaylist(const std::string
&, const std::string
&);
187 void Move(const std::string
&, int, int);
188 bool Rename(const std::string
&, const std::string
&);
190 void StartSearch(bool);
191 void StartFieldSearch(mpd_tag_type
);
192 void AddSearch(mpd_tag_type
, const std::string
&);
193 void CommitSearch(SongList
&);
194 void CommitSearch(TagList
&);
196 void GetPlaylists(TagList
&);
197 void GetList(TagList
&, mpd_tag_type
);
198 void GetAlbums(const std::string
&, TagList
&);
199 void GetDirectory(const std::string
&, ItemList
&);
200 void GetDirectoryRecursive(const std::string
&, SongList
&);
201 void GetSongs(const std::string
&, SongList
&);
202 void GetDirectories(const std::string
&, TagList
&);
204 void GetOutputs(OutputList
&);
205 bool EnableOutput(int);
206 bool DisableOutput(int);
208 void GetURLHandlers(TagList
&v
);
209 void GetTagTypes(TagList
&v
);
215 int CheckForErrors();
217 mpd_connection
*itsConnection
;
218 bool isCommandsListEnabled
;
220 std::string itsErrorMessage
;
222 size_t itsMaxPlaylistLength
;
232 std::string itsPassword
;
234 mpd_status
*itsCurrentStatus
;
235 mpd_status
*itsOldStatus
;
239 time_t itsElapsedTimer
[2];
241 StatusChanges itsChanges
;
243 StatusUpdater itsUpdater
;
244 void *itsStatusUpdaterUserdata
;
245 ErrorHandler itsErrorHandler
;
246 void *itsErrorHandlerUserdata
;
248 mpd_tag_type itsSearchedField
;
252 extern MPD::Connection Mpd
;