1 /***************************************************************************
2 * Copyright (C) 2008 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 #include "libmpdclient.h"
31 enum QueueCommandType
{ qctAdd
, qctAddToPlaylist
, qctDelete
, qctDeleteID
, qctMove
, qctPlaylistMove
, qctDeleteFromPlaylist
};
32 enum ItemType
{ itDirectory
, itSong
, itPlaylist
};
33 enum PlayerState
{ psUnknown
, psStop
, psPlay
, psPause
};
45 StatusChanges() : Playlist(0), SongID(0), Database(0), DBUpdating(0), Volume(0), ElapsedTime(0), Crossfade(0), Random(0), Repeat(0), PlayerState(0) { }
58 typedef std::vector
<Item
> ItemList
;
59 typedef std::vector
<Song
*> SongList
;
60 typedef std::vector
<std::string
> TagList
;
62 void FreeSongList(SongList
&);
63 void FreeItemList(ItemList
&);
69 QueueCommand() : id(0), id2(0) { }
70 QueueCommandType type
;
71 std::string playlist_path
;
72 std::string item_path
;
77 typedef void (*StatusUpdater
) (Connection
*, StatusChanges
, void *);
78 typedef void (*ErrorHandler
) (Connection
*, int, const char *, void *);
85 bool Connected() const;
88 const std::string
& GetHostname() { return itsHost
; }
89 int GetPort() { return itsPort
; }
91 void SetHostname(const std::string
&);
92 void SetPort(int port
) { itsPort
= port
; }
93 void SetTimeout(int timeout
) { itsTimeout
= timeout
; }
94 void SetPassword(const std::string
&password
) { itsPassword
= password
; }
95 void SendPassword() const;
97 void SetStatusUpdater(StatusUpdater
, void *);
98 void SetErrorHandler(ErrorHandler
, void *);
100 void UpdateDirectory(const std::string
&) const;
102 void Execute(const std::string
&) const;
105 void Play(int) const;
106 void PlayID(int) const;
111 void Move(int, int) const;
112 void Seek(int) const;
113 void Shuffle() const;
114 void ClearPlaylist() const;
116 PlayerState
GetState() const { return isConnected
&& itsCurrentStatus
? (PlayerState
)itsCurrentStatus
->state
: psUnknown
; }
117 bool GetRepeat() const { return isConnected
&& itsCurrentStatus
? itsCurrentStatus
->repeat
: 0; }
118 bool GetRandom() const { return isConnected
&& itsCurrentStatus
? itsCurrentStatus
->random
: 0; }
119 bool GetDBIsUpdating() const { return isConnected
&& itsCurrentStatus
? itsCurrentStatus
->updatingDb
: 0; }
120 int GetVolume() const { return isConnected
&& itsCurrentStatus
? itsCurrentStatus
->volume
: -1; }
121 int GetCrossfade() const { return isConnected
&& itsCurrentStatus
? itsCurrentStatus
->crossfade
: -1; }
122 long long GetPlaylistID() const { return isConnected
&& itsCurrentStatus
? itsCurrentStatus
->playlist
: -1; }
123 long long GetOldPlaylistID() const { return isConnected
&& itsOldStatus
? itsOldStatus
->playlist
: -1; }
124 int GetElapsedTime() const { return isConnected
&& itsCurrentStatus
? itsCurrentStatus
->elapsedTime
: -1; }
126 size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength
; }
127 size_t GetPlaylistLength() const { return isConnected
&& itsCurrentStatus
? itsCurrentStatus
->playlistLength
: 0; }
128 void GetPlaylistChanges(long long, SongList
&) const;
130 const std::string
& GetErrorMessage() const { return itsErrorMessage
; }
131 int GetErrorCode() const { return itsErrorCode
; }
133 Song
GetCurrentSong() const;
134 int GetCurrentSongPos() const;
135 Song
GetSong(const std::string
&) const;
136 void GetPlaylistContent(const std::string
&, SongList
&) const;
138 void SetRepeat(bool) const;
139 void SetRandom(bool) const;
140 void SetVolume(int) const;
141 void SetCrossfade(int) const;
143 int AddSong(const std::string
&); // returns id of added song
144 int AddSong(const Song
&); // returns id of added song
145 void QueueAddSong(const std::string
&);
146 void QueueAddSong(const Song
&);
147 void QueueAddToPlaylist(const std::string
&, const std::string
&);
148 void QueueAddToPlaylist(const std::string
&, const Song
&);
149 void QueueDeleteSong(int);
150 void QueueDeleteSongId(int);
151 void QueueMove(int, int);
152 void QueueMove(const std::string
&, int, int);
153 void QueueDeleteFromPlaylist(const std::string
&, int);
156 void DeletePlaylist(const std::string
&) const;
157 bool SavePlaylist(const std::string
&) const;
158 void ClearPlaylist(const std::string
&) const;
159 void AddToPlaylist(const std::string
&, const Song
&) const;
160 void AddToPlaylist(const std::string
&, const std::string
&) const;
161 void Move(const std::string
&, int, int) const;
162 void Rename(const std::string
&, const std::string
&) const;
164 void StartSearch(bool) const;
165 void StartFieldSearch(mpd_TagItems
);
166 void AddSearch(mpd_TagItems
, const std::string
&) const;
167 void CommitSearch(SongList
&) const;
168 void CommitSearch(TagList
&) const;
170 void GetPlaylists(TagList
&) const;
171 void GetList(TagList
&, mpd_TagItems
) const;
172 void GetArtists(TagList
&) const;
173 void GetAlbums(std::string
, TagList
&) const;
174 void GetDirectory(const std::string
&, ItemList
&) const;
175 void GetDirectoryRecursive(const std::string
&, SongList
&) const;
176 void GetSongs(const std::string
&, SongList
&) const;
177 void GetDirectories(const std::string
&, TagList
&) const;
181 int CheckForErrors();
183 mpd_Connection
*itsConnection
;
186 std::string itsErrorMessage
;
188 size_t itsMaxPlaylistLength
;
193 std::string itsPassword
;
195 mpd_Stats
*itsOldStats
;
196 mpd_Stats
*itsCurrentStats
;
197 mpd_Status
*itsCurrentStatus
;
198 mpd_Status
*itsOldStatus
;
200 StatusChanges itsChanges
;
202 StatusUpdater itsUpdater
;
203 void *itsStatusUpdaterUserdata
;
204 ErrorHandler itsErrorHandler
;
205 void *itsErrorHandlerUserdata
;
207 mpd_TagItems itsSearchedField
;
208 std::vector
<QueueCommand
*> itsQueue
;