diff options
author | unknown <unknown@localhost.(none)> | 2008-08-17 21:23:21 +0200 |
---|---|---|
committer | unknown <unknown@localhost.(none)> | 2008-08-17 21:23:21 +0200 |
commit | 1c2ef6fc6a72e53f444e40e6d576e2ccecf57487 (patch) | |
tree | 18d5c01db7dc50cc5e8a29cd1935327ca16bb282 /src/mpdpp.h | |
parent | 7a6bd173966d07e811392e4b5ec37ca9dc91cbbb (diff) |
drop libmpd dependency in favor of its own libmpdclient wrapper
Diffstat (limited to 'src/mpdpp.h')
-rw-r--r-- | src/mpdpp.h | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/src/mpdpp.h b/src/mpdpp.h new file mode 100644 index 00000000..1edb033a --- /dev/null +++ b/src/mpdpp.h @@ -0,0 +1,177 @@ +/*************************************************************************** + * Copyright (C) 2008 by Andrzej Rybczak * + * electricityispower@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef HAVE_MPDPP_H +#define HAVE_MPDPP_H + +#include <map> + +#include "ncmpcpp.h" +#include "song.h" + +enum QueueCommandType { qctAdd, qctDelete, qctDeleteID }; +enum ItemType { itSong, itDirectory, itPlaylist }; +enum PlayerState { psUnknown, psStop, psPlay, psPause }; + +struct MPDStatusChanges +{ + MPDStatusChanges() : Playlist(0), SongID(0), Database(0), DBUpdating(0), Volume(0), ElapsedTime(0), Crossfade(0), Random(0), Repeat(0), PlayerState(0) { } + bool Playlist; + bool SongID; + bool Database; + bool DBUpdating; + bool Volume; + bool ElapsedTime; + bool Crossfade; + bool Random; + bool Repeat; + bool PlayerState; +}; + +struct QueueCommand +{ + QueueCommand() : id(0) { } + QueueCommandType type; + string path; + int id; +}; + +struct Item +{ + Item() : song(0) { } + Song *song; + ItemType type; + string name; +}; + +typedef std::vector<Item> ItemList; +typedef std::vector<Song *> SongList; +typedef std::vector<string> TagList; + +void FreeSongList(SongList &); +void FreeItemList(ItemList &); + +class MPDConnection +{ + typedef void (*StatusUpdater) (MPDConnection *, MPDStatusChanges, void *); + typedef void (*ErrorHandler) (MPDConnection *, int, string, void *); + + public: + MPDConnection(); + ~MPDConnection(); + + void Connect(); + bool Connected(); + void Disconnect(); + + void SetHostname(string hostname) { MPD_HOST = hostname; } + void SetPort(int port) { MPD_PORT = port; } + void SetTimeout(int timeout) { MPD_TIMEOUT = timeout; } + void SetPassword(string password) { MPD_PASSWORD = password; } + void SendPassword(); + + void SetStatusUpdater(StatusUpdater, void *); + void SetErrorHandler(ErrorHandler, void *); + void UpdateStatus(); + void UpdateDirectory(const string &) const; + + void Play() const; + void Play(int) const; + void PlayID(int) const; + void Pause() const; + void Stop() const; + void Next() const; + void Prev() const; + void Move(int, int) const; + void Seek(int) const; + void ClearPlaylist() const; + + PlayerState GetState() const { return isConnected && itsCurrentStatus ? (PlayerState)itsCurrentStatus->state : psUnknown; } + bool GetRepeat() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->repeat : 0; } + bool GetRandom() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->random : 0; } + bool GetDBIsUpdating() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->updatingDb : 0; } + int GetVolume() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->volume : 0; } + int GetCrossfade() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->crossfade : 0; } + long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; } + long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; } + int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; } + + unsigned int GetMaxPlaylistLength() { return itsMaxPlaylistLength; } + int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : -1; } + void GetPlaylistChanges(long long, SongList &) const; + + string GetLastErrorMessage() const { return itsLastErrorMessage; } + + Song GetCurrentSong() const; + int GetCurrentSongPos() const; + Song GetSong(const string &) const; + void GetPlaylistContent(const string &, SongList &) const; + + void SetRepeat(bool) const; + void SetRandom(bool) const; + void SetVolume(int) const; + void SetCrossfade(int) const; + + int AddSong(const string &); // returns id of added song + int AddSong(const Song &); // returns id of added song + void QueueAddSong(const string &); + void QueueAddSong(const Song &); + void QueueDeleteSong(int); + void QueueDeleteSongId(int); + void CommitQueue(); + + void StartSearch(bool) const; + void AddSearch(mpd_TagItems, const string &) const; + void CommitSearch(SongList &v) const; + + void GetArtists(TagList &) const; + void GetAlbums(string, TagList &) const; + void GetDirectory(const string &, ItemList &) const; + void GetDirectoryRecursive(const string &, SongList &) const; + + private: + int CheckForErrors(); + string itsLastErrorMessage; + + mpd_Connection *itsConnection; + bool isConnected; + + string MPD_HOST; + int MPD_PORT; + int MPD_TIMEOUT; + string MPD_PASSWORD; + + mpd_Stats *itsOldStats; + mpd_Stats *itsCurrentStats; + mpd_Status *itsCurrentStatus; + mpd_Status *itsOldStatus; + + StatusUpdater itsUpdater; + void *itsStatusUpdaterUserdata; + ErrorHandler itsErrorHandler; + void *itsErrorHandlerUserdata; + + std::map<int, QueueCommand> itsQueue; + int itsQueueIndex; + unsigned int itsMaxPlaylistLength; +}; + +#endif + |