1 /***************************************************************************
2 * Copyright (C) 2008-2010 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), Outputs(0) { }
69 typedef std::pair
<std::string
, bool> Output
;
71 typedef std::vector
<Item
> ItemList
;
72 typedef std::vector
<Song
*> SongList
;
73 typedef std::vector
<std::string
> TagList
;
74 typedef std::vector
<Output
> OutputList
;
76 void FreeSongList(SongList
&);
77 void FreeItemList(ItemList
&);
81 typedef void (*StatusUpdater
) (Connection
*, StatusChanges
, void *);
82 typedef void (*ErrorHandler
) (Connection
*, int, const char *, void *);
89 bool Connected() const;
92 const std::string
& GetHostname() { return itsHost
; }
93 int GetPort() { return itsPort
; }
95 float Version() const;
97 void SetIdleEnabled(bool val
) { isIdleEnabled
= val
; }
98 bool SupportsIdle() const { return supportsIdle
; }
99 void OrderDataFetching() { hasData
= 1; }
100 int GetFD() const { return itsFD
; }
102 void SetHostname(const std::string
&);
103 void SetPort(int port
) { itsPort
= port
; }
104 void SetTimeout(int timeout
) { itsTimeout
= timeout
; }
105 void SetPassword(const std::string
&password
) { itsPassword
= password
; }
108 void SetStatusUpdater(StatusUpdater
, void *);
109 void SetErrorHandler(ErrorHandler
, void *);
112 bool UpdateDirectory(const std::string
&);
122 void Move(unsigned, unsigned);
123 void Swap(unsigned, unsigned);
126 void ClearPlaylist();
128 bool isPlaying() const { return GetState() > psStop
; }
130 PlayerState
GetState() const { return itsCurrentStatus
? PlayerState(mpd_status_get_state(itsCurrentStatus
)) : psUnknown
; }
131 PlayerState
GetOldState() const { return itsOldStatus
? PlayerState(mpd_status_get_state(itsOldStatus
)) : psUnknown
; }
132 bool GetRepeat() const { return itsCurrentStatus
? mpd_status_get_repeat(itsCurrentStatus
) : 0; }
133 bool GetRandom() const { return itsCurrentStatus
? mpd_status_get_random(itsCurrentStatus
) : 0; }
134 bool GetSingle() const { return itsCurrentStatus
? mpd_status_get_single(itsCurrentStatus
) : 0; }
135 bool GetConsume() const { return itsCurrentStatus
? mpd_status_get_consume(itsCurrentStatus
) : 0; }
136 bool GetDBIsUpdating() const { return itsCurrentStatus
? mpd_status_get_update_id(itsCurrentStatus
) : 0; }
137 int GetVolume() const { return itsCurrentStatus
? mpd_status_get_volume(itsCurrentStatus
) : -1; }
138 unsigned GetCrossfade() const { return itsCurrentStatus
? mpd_status_get_crossfade(itsCurrentStatus
) : 0; }
139 unsigned GetPlaylistID() const { return itsCurrentStatus
? mpd_status_get_queue_version(itsCurrentStatus
) : 0; }
140 unsigned GetOldPlaylistID() const { return itsOldStatus
? mpd_status_get_queue_version(itsOldStatus
) : 0; }
141 unsigned GetElapsedTime() const { return itsCurrentStatus
? itsElapsed
: 0; }
142 int GetTotalTime() const { return itsCurrentStatus
? mpd_status_get_total_time(itsCurrentStatus
) : 0; }
143 unsigned GetBitrate() const { return itsCurrentStatus
? mpd_status_get_kbit_rate(itsCurrentStatus
) : 0; }
145 unsigned NumberOfArtists() const { return itsStats
? mpd_stats_get_number_of_artists(itsStats
) : 0; }
146 unsigned NumberOfAlbums() const { return itsStats
? mpd_stats_get_number_of_albums(itsStats
) : 0; }
147 unsigned NumberOfSongs() const { return itsStats
? mpd_stats_get_number_of_songs(itsStats
) : 0; }
148 unsigned long Uptime() const { return itsStats
? mpd_stats_get_uptime(itsStats
) : 0; }
149 unsigned long DBUpdateTime() const { return itsStats
? mpd_stats_get_db_update_time(itsStats
) : 0; }
150 unsigned long PlayTime() const { return itsStats
? mpd_stats_get_play_time(itsStats
) : 0; }
151 unsigned long DBPlayTime() const { return itsStats
? mpd_stats_get_db_play_time(itsStats
) : 0; }
153 size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength
; }
154 size_t GetPlaylistLength() const { return itsCurrentStatus
? mpd_status_get_queue_length(itsCurrentStatus
) : 0; }
155 void GetPlaylistChanges(unsigned, SongList
&);
157 const std::string
& GetErrorMessage() const { return itsErrorMessage
; }
159 Song
GetCurrentSong();
160 int GetCurrentSongPos() const;
161 Song
GetSong(const std::string
&);
162 void GetPlaylistContent(const std::string
&, SongList
&);
164 void SetRepeat(bool);
165 void SetRandom(bool);
166 void SetSingle(bool);
167 void SetConsume(bool);
168 void SetCrossfade(unsigned);
169 void SetVolume(unsigned);
171 std::string
GetReplayGainMode();
172 void SetReplayGainMode(ReplayGainMode
);
174 int AddSong(const std::string
&, int = -1); // returns id of added song
175 int AddSong(const Song
&, int = -1); // returns id of added song
176 bool AddRandomTag(mpd_tag_type
, size_t);
177 bool AddRandomSongs(size_t);
178 void Add(const std::string
&path
);
179 bool Delete(unsigned);
180 bool DeleteID(unsigned);
181 bool Delete(const std::string
&, unsigned);
182 void StartCommandsList();
183 bool CommitCommandsList();
185 bool DeletePlaylist(const std::string
&);
186 bool SavePlaylist(const std::string
&);
187 void ClearPlaylist(const std::string
&);
188 void AddToPlaylist(const std::string
&, const Song
&);
189 void AddToPlaylist(const std::string
&, const std::string
&);
190 void Move(const std::string
&, int, int);
191 bool Rename(const std::string
&, const std::string
&);
193 void StartSearch(bool);
194 void StartFieldSearch(mpd_tag_type
);
195 void AddSearch(mpd_tag_type
, const std::string
&) const;
196 void AddSearchAny(const std::string
&str
) const;
197 void AddSearchURI(const std::string
&str
) const;
198 void CommitSearch(SongList
&);
199 void CommitSearch(TagList
&);
201 void GetPlaylists(TagList
&);
202 void GetList(TagList
&, mpd_tag_type
);
203 void GetDirectory(const std::string
&, ItemList
&);
204 void GetDirectoryRecursive(const std::string
&, SongList
&);
205 void GetSongs(const std::string
&, SongList
&);
206 void GetDirectories(const std::string
&, TagList
&);
208 void GetOutputs(OutputList
&);
209 bool EnableOutput(int);
210 bool DisableOutput(int);
212 void GetURLHandlers(TagList
&v
);
213 void GetTagTypes(TagList
&v
);
219 int CheckForErrors();
221 mpd_connection
*itsConnection
;
222 bool isCommandsListEnabled
;
224 std::string itsErrorMessage
;
225 size_t itsMaxPlaylistLength
;
236 std::string itsPassword
;
238 mpd_status
*itsCurrentStatus
;
239 mpd_status
*itsOldStatus
;
243 time_t itsElapsedTimer
[2];
245 StatusChanges itsChanges
;
247 StatusUpdater itsUpdater
;
248 void *itsStatusUpdaterUserdata
;
249 ErrorHandler itsErrorHandler
;
250 void *itsErrorHandlerUserdata
;
252 mpd_tag_type itsSearchedField
;
256 extern MPD::Connection Mpd
;