Merge pull request #1596 from Montellese/jsonrpc_player_onpropertychanged
[vuplus_xbmc] / xbmc / PlayListPlayer.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2012 Team XBMC
4  *      http://www.xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "guilib/IMsgTargetCallback.h"
23 #include <boost/shared_ptr.hpp>
24
25 #define PLAYLIST_NONE    -1
26 #define PLAYLIST_MUSIC   0
27 #define PLAYLIST_VIDEO   1
28 #define PLAYLIST_PICTURE 2
29
30 class CFileItem; typedef boost::shared_ptr<CFileItem> CFileItemPtr;
31 class CFileItemList;
32
33 class CVariant;
34
35 namespace PLAYLIST
36 {
37 /*!
38  \ingroup windows
39  \brief Manages playlist playing.
40  */
41 enum REPEAT_STATE { REPEAT_NONE = 0, REPEAT_ONE, REPEAT_ALL };
42
43 class CPlayList;
44
45 class CPlayListPlayer : public IMsgTargetCallback
46 {
47
48 public:
49   CPlayListPlayer(void);
50   virtual ~CPlayListPlayer(void);
51   virtual bool OnMessage(CGUIMessage &message);
52
53   /*! \brief Play the next (or another) entry in the current playlist
54    \param offset The offset from the current entry (defaults to 1, i.e. the next entry).
55    \param autoPlay Whether we should start playing if not already (defaults to false).
56    */
57   bool PlayNext(int offset = 1, bool autoPlay = false);
58
59   /*! \brief Play the previous entry in the current playlist
60    \sa PlayNext
61    */
62   bool PlayPrevious();
63   bool PlaySongId(int songId);
64   bool Play();
65
66   /*! \brief Start playing a particular entry in the current playlist
67    \param index the index of the item to play. This value is modified to ensure it lies within the current playlist.
68    \param replace whether this item should replace the currently playing item. See CApplication::PlayFile (defaults to false).
69    \param playPreviousOnFail whether to go back to the previous item if playback fails (default to false)
70    */
71   bool Play(int index, bool replace = false, bool playPreviousOnFail = false);
72
73   /*! \brief Returns the index of the current item in active playlist.
74    \return Current item in the active playlist.
75    \sa SetCurrentSong
76    */
77   int GetCurrentSong() const;
78
79   /*! \brief Change the current item in the active playlist.
80    \param index item index in playlist. Set only if the index is within the range of the current playlist.
81    \sa GetCurrentSong
82    */
83   void SetCurrentSong(int index);
84
85   int GetNextSong();
86   
87   /*! \brief Get the index in the playlist that is offset away from the current index in the current playlist.
88    Obeys any repeat settings (eg repeat one will return the current index regardless of offset)
89    \return the index of the entry, or -1 if there is no current playlist. There is no guarantee that the returned index is valid.
90    */
91   int GetNextSong(int offset) const;
92
93   /*! \brief Set the active playlist
94    \param playList Values can be PLAYLIST_NONE, PLAYLIST_MUSIC or PLAYLIST_VIDEO
95    \sa GetCurrentPlaylist
96    */
97   void SetCurrentPlaylist(int playlist);
98
99   /*! \brief Get the currently active playlist
100    \return PLAYLIST_NONE, PLAYLIST_MUSIC or PLAYLIST_VIDEO
101    \sa SetCurrentPlaylist, GetPlaylist
102    */
103   int GetCurrentPlaylist() const;
104
105   /*! \brief Get a particular playlist object
106    \param playList Values can be PLAYLIST_MUSIC or PLAYLIST_VIDEO
107    \return A reference to the CPlayList object.
108    \sa GetCurrentPlaylist
109    */
110   CPlayList& GetPlaylist(int playlist);
111   const CPlayList& GetPlaylist(int iPlaylist) const;
112
113   /*! \brief Removes any item from all playlists located on a removable share
114    \return Number of items removed from PLAYLIST_MUSIC and PLAYLIST_VIDEO
115    */
116   int RemoveDVDItems();
117
118   /*! \brief Resets the current song and unplayable counts.
119    Does not alter the active playlist.
120   */
121   void Reset();
122
123   void ClearPlaylist(int iPlaylist);
124   void Clear();
125
126   /*! \brief Set shuffle state of a playlist.
127    If the shuffle state changes, the playlist is shuffled or unshuffled.
128    Has no effect if Party Mode is enabled.
129    \param playlist the playlist to (un)shuffle, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
130    \param shuffle set true to shuffle, false to unshuffle.
131    \param notify notify the user with a Toast notification (defaults to false)
132    \sa IsShuffled
133    */
134   void SetShuffle(int playlist, bool shuffle, bool notify = false);
135   
136   /*! \brief Return whether a playlist is shuffled.
137    If partymode is enabled, this always returns false.
138    \param playlist the playlist to query for shuffle state, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
139    \return true if the given playlist is shuffled and party mode isn't enabled, false otherwise.
140    \sa SetShuffle
141    */
142   bool IsShuffled(int iPlaylist) const;
143
144   /*! \brief Return whether or not something has been played yet from the current playlist.
145    \return true if something has been played, false otherwise.
146    */
147   bool HasPlayedFirstFile() const;
148
149   /*! \brief Set repeat state of a playlist.
150    If called while in Party Mode, repeat is disabled.
151    \param playlist the playlist to set repeat state for, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
152    \param state set to REPEAT_NONE, REPEAT_ONE or REPEAT_ALL
153    \param notify notify the user with a Toast notification
154    \sa GetRepeat
155    */
156   void SetRepeat(int iPlaylist, REPEAT_STATE state, bool notify = false);
157   REPEAT_STATE GetRepeat(int iPlaylist) const;
158
159   // add items via the playlist player
160   void Add(int iPlaylist, CPlayList& playlist);
161   void Add(int iPlaylist, const CFileItemPtr &pItem);
162   void Add(int iPlaylist, CFileItemList& items);
163   void Insert(int iPlaylist, CPlayList& playlist, int iIndex);
164   void Insert(int iPlaylist, const CFileItemPtr &pItem, int iIndex);
165   void Insert(int iPlaylist, CFileItemList& items, int iIndex);
166   void Remove(int iPlaylist, int iPosition);
167   void Swap(int iPlaylist, int indexItem1, int indexItem2);
168 protected:
169   /*! \brief Returns true if the given is set to repeat all
170    \param playlist Playlist to be query
171    \return true if the given playlist is set to repeat all, false otherwise.
172    */
173   bool Repeated(int playlist) const;
174
175   /*! \brief Returns true if the given is set to repeat one
176    \param playlist Playlist to be query
177    \return true if the given playlist is set to repeat one, false otherwise.
178    */
179   bool RepeatedOne(int playlist) const;
180
181   void ReShuffle(int iPlaylist, int iPosition);
182
183   void AnnouncePropertyChanged(int iPlaylist, const std::string &strProperty, const CVariant &value);
184
185   bool m_bPlayedFirstFile;
186   bool m_bPlaybackStarted;
187   int m_iFailedSongs;
188   unsigned int m_failedSongsStart;
189   int m_iCurrentSong;
190   int m_iCurrentPlayList;
191   CPlayList* m_PlaylistMusic;
192   CPlayList* m_PlaylistVideo;
193   CPlayList* m_PlaylistEmpty;
194   REPEAT_STATE m_repeatState[2];
195 };
196
197 }
198
199 /*!
200  \ingroup windows
201  \brief Global instance of playlist player
202  */
203 extern PLAYLIST::CPlayListPlayer g_playlistPlayer;