convert id3 tags, directories and playlist names to current locale if needed
[ncmpcpp/cirrus.git] / src / mpdpp.h
blobff5b412ed6fcb9d1420b9fe39c84ad1ecc05b3bb
1 /***************************************************************************
2 * Copyright (C) 2008 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
21 #ifndef _MPDPP_H
22 #define _MPDPP_H
24 #include <vector>
26 #include "libmpdclient.h"
27 #include "song.h"
29 namespace MPD
31 enum QueueCommandType { qctAdd, qctAddToPlaylist, qctDelete, qctDeleteID, qctMove, qctPlaylistMove, qctDeleteFromPlaylist };
32 enum ItemType { itDirectory, itSong, itPlaylist };
33 enum PlayerState { psUnknown, psStop, psPlay, psPause };
35 struct Item
37 Item() : song(0) { }
38 Song *song;
39 ItemType type;
40 std::string name;
43 struct StatusChanges
45 StatusChanges() : Playlist(0), SongID(0), Database(0), DBUpdating(0), Volume(0), ElapsedTime(0), Crossfade(0), Random(0), Repeat(0), PlayerState(0) { }
46 bool Playlist:1;
47 bool SongID:1;
48 bool Database:1;
49 bool DBUpdating:1;
50 bool Volume:1;
51 bool ElapsedTime:1;
52 bool Crossfade:1;
53 bool Random:1;
54 bool Repeat:1;
55 bool PlayerState:1;
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 &);
65 class Connection
67 struct QueueCommand
69 QueueCommand() : id(0), id2(0) { }
70 QueueCommandType type;
71 std::string playlist_path;
72 std::string item_path;
73 int id;
74 int id2;
77 typedef void (*StatusUpdater) (Connection *, StatusChanges, void *);
78 typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
80 public:
81 Connection();
82 ~Connection();
84 bool Connect();
85 bool Connected() const;
86 void Disconnect();
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 *);
99 void UpdateStatus();
100 void UpdateDirectory(const std::string &) const;
102 void Execute(const std::string &) const;
104 void Play() const;
105 void Play(int) const;
106 void PlayID(int) const;
107 void Pause() const;
108 void Stop() const;
109 void Next() const;
110 void Prev() 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);
154 bool CommitQueue();
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;
179 private:
180 void ClearQueue();
181 int CheckForErrors();
183 mpd_Connection *itsConnection;
184 bool isConnected;
186 std::string itsErrorMessage;
187 int itsErrorCode;
188 size_t itsMaxPlaylistLength;
190 std::string itsHost;
191 int itsPort;
192 int itsTimeout;
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;
212 #endif