Merge pull request #1394 from Montellese/gpl_header
[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 namespace PLAYLIST
34 {
35 /*!
36  \ingroup windows
37  \brief Manages playlist playing.
38  */
39 enum REPEAT_STATE { REPEAT_NONE = 0, REPEAT_ONE, REPEAT_ALL };
40
41 class CPlayList;
42
43 class CPlayListPlayer : public IMsgTargetCallback
44 {
45
46 public:
47   CPlayListPlayer(void);
48   virtual ~CPlayListPlayer(void);
49   virtual bool OnMessage(CGUIMessage &message);
50
51   /*! \brief Play the next (or another) entry in the current playlist
52    \param offset The offset from the current entry (defaults to 1, i.e. the next entry).
53    \param autoPlay Whether we should start playing if not already (defaults to false).
54    */
55   bool PlayNext(int offset = 1, bool autoPlay = false);
56
57   /*! \brief Play the previous entry in the current playlist
58    \sa PlayNext
59    */
60   bool PlayPrevious();
61   bool PlaySongId(int songId);
62   bool Play();
63
64   /*! \brief Start playing a particular entry in the current playlist
65    \param index the index of the item to play. This value is modified to ensure it lies within the current playlist.
66    \param replace whether this item should replace the currently playing item. See CApplication::PlayFile (defaults to false).
67    \param playPreviousOnFail whether to go back to the previous item if playback fails (default to false)
68    */
69   bool Play(int index, bool replace = false, bool playPreviousOnFail = false);
70
71   /*! \brief Returns the index of the current item in active playlist.
72    \return Current item in the active playlist.
73    \sa SetCurrentSong
74    */
75   int GetCurrentSong() const;
76
77   /*! \brief Change the current item in the active playlist.
78    \param index item index in playlist. Set only if the index is within the range of the current playlist.
79    \sa GetCurrentSong
80    */
81   void SetCurrentSong(int index);
82
83   int GetNextSong();
84   
85   /*! \brief Get the index in the playlist that is offset away from the current index in the current playlist.
86    Obeys any repeat settings (eg repeat one will return the current index regardless of offset)
87    \return the index of the entry, or -1 if there is no current playlist. There is no guarantee that the returned index is valid.
88    */
89   int GetNextSong(int offset) const;
90
91   /*! \brief Set the active playlist
92    \param playList Values can be PLAYLIST_NONE, PLAYLIST_MUSIC or PLAYLIST_VIDEO
93    \sa GetCurrentPlaylist
94    */
95   void SetCurrentPlaylist(int playlist);
96
97   /*! \brief Get the currently active playlist
98    \return PLAYLIST_NONE, PLAYLIST_MUSIC or PLAYLIST_VIDEO
99    \sa SetCurrentPlaylist, GetPlaylist
100    */
101   int GetCurrentPlaylist() const;
102
103   /*! \brief Get a particular playlist object
104    \param playList Values can be PLAYLIST_MUSIC or PLAYLIST_VIDEO
105    \return A reference to the CPlayList object.
106    \sa GetCurrentPlaylist
107    */
108   CPlayList& GetPlaylist(int playlist);
109   const CPlayList& GetPlaylist(int iPlaylist) const;
110
111   /*! \brief Removes any item from all playlists located on a removable share
112    \return Number of items removed from PLAYLIST_MUSIC and PLAYLIST_VIDEO
113    */
114   int RemoveDVDItems();
115
116   /*! \brief Resets the current song and unplayable counts.
117    Does not alter the active playlist.
118   */
119   void Reset();
120
121   void ClearPlaylist(int iPlaylist);
122   void Clear();
123
124   /*! \brief Set shuffle state of a playlist.
125    If the shuffle state changes, the playlist is shuffled or unshuffled.
126    Has no effect if Party Mode is enabled.
127    \param playlist the playlist to (un)shuffle, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
128    \param shuffle set true to shuffle, false to unshuffle.
129    \param notify notify the user with a Toast notification (defaults to false)
130    \sa IsShuffled
131    */
132   void SetShuffle(int playlist, bool shuffle, bool notify = false);
133   
134   /*! \brief Return whether a playlist is shuffled.
135    If partymode is enabled, this always returns false.
136    \param playlist the playlist to query for shuffle state, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
137    \return true if the given playlist is shuffled and party mode isn't enabled, false otherwise.
138    \sa SetShuffle
139    */
140   bool IsShuffled(int iPlaylist) const;
141
142   /*! \brief Return whether or not something has been played yet from the current playlist.
143    \return true if something has been played, false otherwise.
144    */
145   bool HasPlayedFirstFile() const;
146
147   /*! \brief Set repeat state of a playlist.
148    If called while in Party Mode, repeat is disabled.
149    \param playlist the playlist to set repeat state for, PLAYLIST_MUSIC or PLAYLIST_VIDEO.
150    \param state set to REPEAT_NONE, REPEAT_ONE or REPEAT_ALL
151    \param notify notify the user with a Toast notification
152    \sa GetRepeat
153    */
154   void SetRepeat(int iPlaylist, REPEAT_STATE state, bool notify = false);
155   REPEAT_STATE GetRepeat(int iPlaylist) const;
156
157   // add items via the playlist player
158   void Add(int iPlaylist, CPlayList& playlist);
159   void Add(int iPlaylist, const CFileItemPtr &pItem);
160   void Add(int iPlaylist, CFileItemList& items);
161   void Insert(int iPlaylist, CPlayList& playlist, int iIndex);
162   void Insert(int iPlaylist, const CFileItemPtr &pItem, int iIndex);
163   void Insert(int iPlaylist, CFileItemList& items, int iIndex);
164   void Remove(int iPlaylist, int iPosition);
165   void Swap(int iPlaylist, int indexItem1, int indexItem2);
166 protected:
167   /*! \brief Returns true if the given is set to repeat all
168    \param playlist Playlist to be query
169    \return true if the given playlist is set to repeat all, false otherwise.
170    */
171   bool Repeated(int playlist) const;
172
173   /*! \brief Returns true if the given is set to repeat one
174    \param playlist Playlist to be query
175    \return true if the given playlist is set to repeat one, false otherwise.
176    */
177   bool RepeatedOne(int playlist) const;
178
179   void ReShuffle(int iPlaylist, int iPosition);
180
181   bool m_bPlayedFirstFile;
182   bool m_bPlaybackStarted;
183   int m_iFailedSongs;
184   unsigned int m_failedSongsStart;
185   int m_iCurrentSong;
186   int m_iCurrentPlayList;
187   CPlayList* m_PlaylistMusic;
188   CPlayList* m_PlaylistVideo;
189   CPlayList* m_PlaylistEmpty;
190   REPEAT_STATE m_repeatState[2];
191 };
192
193 }
194
195 /*!
196  \ingroup windows
197  \brief Global instance of playlist player
198  */
199 extern PLAYLIST::CPlayListPlayer g_playlistPlayer;