MythTV  master
musicplayer.h
Go to the documentation of this file.
1 #ifndef MUSICPLAYER_H_
2 #define MUSICPLAYER_H_
3 
4 // mythtv
5 #include <audiooutput.h>
6 #include <mythobservable.h>
7 
8 // libmythmetadata
9 #include <musicmetadata.h>
10 
11 // mythmusic
12 #include "decoderhandler.h"
13 
14 // how long to wait before updating the lastplay and playcount fields
15 #define LASTPLAY_DELAY 15
16 
17 class AudioOutput;
18 class MainVisual;
19 class Playlist;
20 
22 {
23  public:
24  MusicPlayerEvent(Type type, int id) :
25  MythEvent(type), m_trackID(id) {}
26  MusicPlayerEvent(Type type, uint vol, bool muted) :
27  MythEvent(type), m_trackID(0), m_volume(vol), m_isMuted(muted) {}
28  ~MusicPlayerEvent() = default;
29 
30  MythEvent *clone(void) const override // MythEvent
31  { return new MusicPlayerEvent(*this); }
32 
33  // for track changed/added/deleted/metadata changed/playlist changed events
34  int m_trackID;
35 
36  // for volume changed event
38  bool m_isMuted {false};
39 
40  static Type TrackChangeEvent;
41  static Type VolumeChangeEvent;
42  static Type TrackAddedEvent;
43  static Type TrackRemovedEvent;
44  static Type TrackUnavailableEvent;
45  static Type AllTracksRemovedEvent;
46  static Type MetadataChangedEvent;
48  static Type AlbumArtChangedEvent;
49  static Type CDChangedEvent;
50  static Type PlaylistChangedEvent;
52 };
53 
54 class MusicPlayer : public QObject, public MythObservable
55 {
56  Q_OBJECT
57 
58  public:
59  explicit MusicPlayer(QObject *parent);
60  ~MusicPlayer(void);
61 
62  enum PlayMode
63  {
67  };
68 
69  void setPlayMode(PlayMode mode);
70  PlayMode getPlayMode(void) { return m_playMode; }
71 
72  void playFile(const MusicMetadata &mdata);
73 
74  void addListener(QObject *listener);
75  void removeListener(QObject *listener);
76 
77  void addVisual(MainVisual *visual);
78  void removeVisual(MainVisual *visual);
79 
80  void toggleMute(void);
81  MuteState getMuteState(void) const;
82  bool isMuted(void) const { return getMuteState() == kMuteAll; }
83 
84  void setVolume(int volume);
85  void incVolume(void);
86  void decVolume(void);
87  uint getVolume(void) const;
88 
89  void setSpeed(float speed);
90  void incSpeed();
91  void decSpeed();
92  float getSpeed() { return m_playSpeed; }
93 
94  void play(void);
95  void stop(bool stopAll = false);
96  void pause(void);
97  void next(void);
98  void previous(void);
99 
100  void nextAuto(void);
101 
102  bool isPlaying(void) { return m_isPlaying; }
103  bool isPaused(void) { return getOutput() ? getOutput()->IsPaused() : false; }
104  bool isStopped(void) { return !(isPlaying() || isPaused()); }
105  bool hasClient(void) { return hasListeners(); }
106 
108  void autoShowPlayer(bool autoShow) { m_autoShowPlayer = autoShow; }
109  bool getAutoShowPlayer(void) { return m_autoShowPlayer; }
110 
112  void canShowPlayer(bool canShow) { m_canShowPlayer = canShow; }
113  bool getCanShowPlayer(void) { return m_canShowPlayer; }
114 
117  AudioOutput *getOutput(void) { return m_output; }
118 
119  void loadPlaylist(void);
120  void loadStreamPlaylist(void);
122  StreamList *getStreamList(void);
123 
124  // these add and remove tracks from the active playlist
125  void removeTrack(int trackID);
126  void addTrack(int trackID, bool updateUI);
127 
128  void moveTrackUpDown(bool moveUp, int whichTrack);
129 
130  QList<MusicMetadata*> &getPlayedTracksList(void) { return m_playedList; }
131 
132  int getCurrentTrackPos(void) { return m_currentTrack; }
133  bool setCurrentTrackPos(int pos);
134  void changeCurrentTrack(int trackNo);
135 
136  int getCurrentTrackTime(void) { return m_currentTime; }
137 
138  void activePlaylistChanged(int trackID, bool deleted);
139  void playlistChanged(int playlistID);
140 
141  void savePosition(void);
142  void restorePosition(void);
143  void setAllowRestorePos(bool allow) { m_allowRestorePos = allow; }
144  void seek(int pos);
145 
148  void sendMetadataChangedEvent(int trackID);
149  void sendTrackStatsChangedEvent(int trackID);
150  void sendAlbumArtChangedEvent(int trackID);
151  void sendTrackUnavailableEvent(int trackID);
152  void sendCDChangedEvent(void);
153 
154  void toMap(InfoMap &infoMap);
155 
156  void showMiniPlayer(void);
158  { REPEAT_OFF = 0,
162  };
164  { SHUFFLE_OFF = 0,
170  };
171 
178  };
179 
181  void setRepeatMode(RepeatMode mode) { m_repeatMode = mode; }
183 
185  void setShuffleMode(ShuffleMode mode);
187 
189 
190  void getBufferStatus(int *bufferAvailable, int *bufferSize);
191 
192  public slots:
193  void StartPlayback(void);
194  void StopPlayback(void);
195 
196  protected:
197  void customEvent(QEvent *event) override; // QObject
198 
199  private:
200  void loadSettings(void);
201  void stopDecoder(void);
202  bool openOutputDevice(void);
203  void updateLastplay(void);
204  void updateVolatileMetadata(void);
205  void sendVolumeChangedEvent(void);
206  int getNotificationID(const QString &hostname);
207  void sendNotification(int notificationID, const QString &title, const QString &author, const QString &desc);
208 
209  void setupDecoderHandler(void);
210  void decoderHandlerReady(void);
211 
212  int m_currentTrack {-1};
213  int m_currentTime {0};
214 
216 
217  AudioOutput *m_output {nullptr};
219 
220  QSet<QObject*> m_visualisers;
221 
223  bool m_isPlaying {false};
224  bool m_isAutoplay {false};
225  bool m_canShowPlayer {true};
226  bool m_autoShowPlayer {true};
227  bool m_wasPlaying {false};
228  bool m_updatedLastplay {false};
229  bool m_allowRestorePos {true};
230 
232 
238 
239  float m_playSpeed {1.0F};
240 
241  // notification
243  QMap<QString, int> m_notificationMap;
244 
245  // radio stuff
246  QList<MusicMetadata*> m_playedList;
249  int m_bufferSize {0};
250 
251  int m_errorCount {0};
252 };
253 
257 
258 // This global variable contains the MusicPlayer instance for the application
259 extern MPUBLIC MusicPlayer *gPlayer;
260 
261  // This stores the last MythMediaDevice that was detected:
262 extern MPUBLIC QString gCDdevice;
263 
264 #endif
StreamList * getStreamList(void)
virtual bool IsPaused(void) const =0
void decVolume(void)
bool m_isPlaying
Definition: musicplayer.h:223
int m_errorCount
Definition: musicplayer.h:251
int m_currentTime
Definition: musicplayer.h:213
void setPlayMode(PlayMode mode)
void sendVolumeChangedEvent(void)
QList< MusicMetadata * > StreamList
unsigned int slots[4]
Definition: element.c:38
void setShuffleMode(ShuffleMode mode)
void changeCurrentTrack(int trackNo)
change the current track to the given track
~MusicPlayer(void)
Definition: musicplayer.cpp:86
Decoder * getDecoder(void)
uint getVolume(void) const
static Type MetadataChangedEvent
Definition: musicplayer.h:46
void sendTrackStatsChangedEvent(int trackID)
void sendCDChangedEvent(void)
MusicMetadata * getCurrentMetadata(void)
get the metadata for the current track in the playlist
#define MPUBLIC
Definition: mythexp.h:10
Playlist * getCurrentPlaylist(void)
void playFile(const MusicMetadata &mdata)
RepeatMode toggleRepeatMode(void)
float m_playSpeed
Definition: musicplayer.h:239
void removeListener(QObject *listener)
void removeVisual(MainVisual *visual)
static Type TrackAddedEvent
Definition: musicplayer.h:42
int getCurrentTrackTime(void)
Definition: musicplayer.h:136
bool isStopped(void)
Definition: musicplayer.h:104
bool openOutputDevice(void)
ResumeMode m_resumeModeRadio
Definition: musicplayer.h:237
bool m_isAutoplay
Definition: musicplayer.h:224
MuteState
Definition: volumebase.h:6
bool setCurrentTrackPos(int pos)
bool isPlaying(void)
Definition: musicplayer.h:102
void setupDecoderHandler(void)
void setVolume(int volume)
unsigned int uint
Definition: compat.h:140
void incVolume(void)
void addVisual(MainVisual *visual)
ResumeMode getResumeMode(void)
void stopDecoder(void)
~MusicPlayerEvent()=default
bool m_autoShowPlayer
Definition: musicplayer.h:226
MusicPlayerEvent(Type type, uint vol, bool muted)
Definition: musicplayer.h:26
QMap< QString, int > m_notificationMap
Definition: musicplayer.h:243
RepeatMode getRepeatMode(void)
Definition: musicplayer.h:180
MPUBLIC QString gCDdevice
Definition: musicplayer.cpp:36
bool hasClient(void)
Definition: musicplayer.h:105
Superclass for making an object have a set of listeners.
static Type CDChangedEvent
Definition: musicplayer.h:49
MPUBLIC MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
bool getCanShowPlayer(void)
Definition: musicplayer.h:113
static Type TrackChangeEvent
Definition: musicplayer.h:40
void loadStreamPlaylist(void)
PlayMode m_playMode
Definition: musicplayer.h:222
void savePosition(void)
MuteState getMuteState(void) const
void previous(void)
This class is used as a container for messages.
Definition: mythevent.h:16
void sendMetadataChangedEvent(int trackID)
MythEvent * clone(void) const override
Definition: musicplayer.h:30
DecoderHandler * getDecoderHandler(void)
Definition: musicplayer.h:116
void next(void)
bool m_allowRestorePos
Definition: musicplayer.h:229
RepeatMode m_repeatMode
Definition: musicplayer.h:234
PlayMode getPlayMode(void)
Definition: musicplayer.h:70
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MusicPlayer(QObject *parent)
Definition: musicplayer.cpp:53
void addTrack(int trackID, bool updateUI)
bool hasListeners(void)
int m_lastTrackStart
Definition: musicplayer.h:247
QList< MusicMetadata * > m_playedList
Definition: musicplayer.h:246
int getNotificationID(const QString &hostname)
bool getAutoShowPlayer(void)
Definition: musicplayer.h:109
QList< MusicMetadata * > & getPlayedTracksList(void)
Definition: musicplayer.h:130
void decoderHandlerReady(void)
void getBufferStatus(int *bufferAvailable, int *bufferSize)
bool isMuted(void) const
Definition: musicplayer.h:82
ResumeMode m_resumeModeEditor
Definition: musicplayer.h:236
void seek(int pos)
static Type TrackRemovedEvent
Definition: musicplayer.h:43
bool m_canShowPlayer
Definition: musicplayer.h:225
void setSpeed(float speed)
static Type TrackUnavailableEvent
Definition: musicplayer.h:44
string hostname
Definition: caa.py:17
void pause(void)
void loadSettings(void)
void updateVolatileMetadata(void)
DecoderHandler * m_decoderHandler
Definition: musicplayer.h:218
void showMiniPlayer(void)
ShuffleMode toggleShuffleMode(void)
int m_currentTrack
Definition: musicplayer.h:212
bool m_wasPlaying
Definition: musicplayer.h:227
float getSpeed()
Definition: musicplayer.h:92
void stop(bool stopAll=false)
int m_lastplayDelay
Definition: musicplayer.h:231
void setAllowRestorePos(bool allow)
Definition: musicplayer.h:143
AudioOutput * m_output
Definition: musicplayer.h:217
void sendAlbumArtChangedEvent(int trackID)
void play(void)
MusicMetadata * m_oneshotMetadata
Definition: musicplayer.h:215
void restorePosition(void)
ShuffleMode getShuffleMode(void)
Definition: musicplayer.h:184
static Type AllTracksRemovedEvent
Definition: musicplayer.h:45
void addListener(QObject *listener)
int getCurrentTrackPos(void)
Definition: musicplayer.h:132
bool isPaused(void)
Definition: musicplayer.h:103
void canShowPlayer(bool canShow)
This will allow/disallow the mini player showing even using its jumppoint.
Definition: musicplayer.h:112
void updateLastplay(void)
void StopPlayback(void)
void nextAuto(void)
void sendTrackUnavailableEvent(int trackID)
void StartPlayback(void)
ShuffleMode m_shuffleMode
Definition: musicplayer.h:233
bool m_showScannerNotifications
Definition: musicplayer.h:242
bool m_updatedLastplay
Definition: musicplayer.h:228
static Type PlaylistChangedEvent
Definition: musicplayer.h:50
void toMap(InfoMap &infoMap)
int m_bufferSize
Definition: musicplayer.h:249
Class for starting stream decoding.
MusicPlayerEvent(Type type, int id)
Definition: musicplayer.h:24
Q_DECLARE_METATYPE(MusicPlayer::ResumeMode)
QSet< QObject * > m_visualisers
Definition: musicplayer.h:220
void playlistChanged(int playlistID)
#define LASTPLAY_DELAY
Definition: musicplayer.h:15
static Type PlayedTracksChangedEvent
Definition: musicplayer.h:51
void removeTrack(int trackID)
void sendNotification(int notificationID, const QString &title, const QString &author, const QString &desc)
void moveTrackUpDown(bool moveUp, int whichTrack)
int m_bufferAvailable
Definition: musicplayer.h:248
void toggleMute(void)
Decoder * getDecoder(void)
Definition: musicplayer.h:115
AudioOutput * getOutput(void)
Definition: musicplayer.h:117
static Type VolumeChangeEvent
Definition: musicplayer.h:41
MusicMetadata * getNextMetadata(void)
get the metadata for the next track in the playlist
static Type AlbumArtChangedEvent
Definition: musicplayer.h:48
void customEvent(QEvent *event) override
void activePlaylistChanged(int trackID, bool deleted)
void loadPlaylist(void)
static Type TrackStatsChangedEvent
Definition: musicplayer.h:47
void setRepeatMode(RepeatMode mode)
Definition: musicplayer.h:181
ResumeMode m_resumeModePlayback
Definition: musicplayer.h:235
void autoShowPlayer(bool autoShow)
This will allow/disallow the mini player showing on track changes.
Definition: musicplayer.h:108