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