00001 #ifndef MUSICPLAYER_H_
00002 #define MUSICPLAYER_H_
00003
00004
00005 #include <mythdialogs.h>
00006 #include <audiooutput.h>
00007 #include <mythobservable.h>
00008
00009
00010 #include "metadata.h"
00011 #include "decoderhandler.h"
00012
00013 class AudioOutput;
00014 class MainVisual;
00015 class Playlist;
00016 class CDWatcherThread;
00017
00018 class MusicPlayerEvent : public MythEvent
00019 {
00020 public:
00021 MusicPlayerEvent(Type t, int id) :
00022 MythEvent(t), TrackID(id), Volume(0), IsMuted(false) {}
00023 MusicPlayerEvent(Type t, uint vol, bool muted) :
00024 MythEvent(t), TrackID(0), Volume(vol), IsMuted(muted) {}
00025 ~MusicPlayerEvent() {}
00026
00027 virtual MythEvent *clone(void) const { return new MusicPlayerEvent(*this); }
00028
00029
00030 int TrackID;
00031
00032
00033 uint Volume;
00034 bool IsMuted;
00035
00036 static Type TrackChangeEvent;
00037 static Type VolumeChangeEvent;
00038 static Type TrackAddedEvent;
00039 static Type TrackRemovedEvent;
00040 static Type AllTracksRemovedEvent;
00041 static Type MetadataChangedEvent;
00042 static Type TrackStatsChangedEvent;
00043 static Type AlbumArtChangedEvent;
00044 static Type CDChangedEvent;
00045 static Type PlaylistChangedEvent;
00046 };
00047
00048 class MusicPlayer : public QObject, public MythObservable
00049 {
00050 Q_OBJECT
00051
00052 public:
00053 MusicPlayer(QObject *parent, const QString &dev);
00054 ~MusicPlayer(void);
00055
00056 void switchPlayMode(bool playStreams);
00057
00058 void playFile(const Metadata &meta);
00059
00060 void addListener(QObject *listener);
00061 void removeListener(QObject *listener);
00062
00063 void addVisual(MainVisual *visual);
00064 void removeVisual(MainVisual *visual);
00065
00066 void setCDDevice(const QString &dev) { m_CDdevice = dev; }
00067
00068 void toggleMute(void);
00069 MuteState getMuteState(void) const;
00070 bool isMuted(void) const { return getMuteState() == kMuteAll; }
00071
00072 void setVolume(int volume);
00073 void incVolume(void);
00074 void decVolume(void);
00075 uint getVolume(void) const;
00076
00077 void setSpeed(float speed);
00078 void incSpeed();
00079 void decSpeed();
00080 float getSpeed() { return m_playSpeed; }
00081
00082 void play(void);
00083 void stop(bool stopAll = false);
00084 void pause(void);
00085 void next(void);
00086 void previous(void);
00087
00088 void nextAuto(void);
00089
00090 bool isPlaying(void) { return m_isPlaying; }
00091 bool isPaused(void) { return getOutput() ? getOutput()->IsPaused() : false; }
00092 bool isStopped(void) { return !(isPlaying() || isPaused()); }
00093 bool hasClient(void) { return hasListeners(); }
00094
00096 void autoShowPlayer(bool autoShow) { m_autoShowPlayer = autoShow; }
00097 bool getAutoShowPlayer(void) { return m_autoShowPlayer; }
00098
00100 void canShowPlayer(bool canShow) { m_canShowPlayer = canShow; }
00101 bool getCanShowPlayer(void) { return m_canShowPlayer; }
00102
00103 Decoder *getDecoder(void) { return m_decoderHandler ? m_decoderHandler->getDecoder() : NULL; }
00104 DecoderHandler *getDecoderHandler(void) { return m_decoderHandler; }
00105 AudioOutput *getOutput(void) { return m_output; }
00106
00107 void loadPlaylist(void);
00108 Playlist *getPlaylist(void) { return m_currentPlaylist; }
00109
00110
00111 void removeTrack(int trackID);
00112 void addTrack(int trackID, bool updateUI);
00113
00114 void moveTrackUpDown(bool moveUp, int whichTrack);
00115
00116 QList<Metadata> getPlayedTracksList(void) { return m_playedList; }
00117
00118 int getCurrentTrackPos(void) { return m_currentTrack; }
00119 bool setCurrentTrackPos(int pos);
00120 void changeCurrentTrack(int trackNo);
00121
00122 void activePlaylistChanged(int trackID, bool deleted);
00123 void playlistChanged(int playlistID);
00124
00125 void savePosition(void);
00126 void restorePosition(void);
00127 void setAllowRestorePos(bool allow) { m_allowRestorePos = allow; }
00128 void seek(int pos);
00129
00130 Metadata *getCurrentMetadata(void);
00131 Metadata *getNextMetadata(void);
00132 Metadata *getDisplayMetadata(void) { return &m_displayMetadata; }
00133 void refreshMetadata(void);
00134 void sendMetadataChangedEvent(int trackID);
00135 void sendTrackStatsChangedEvent(int trackID);
00136 void sendAlbumArtChangedEvent(int trackID);
00137 void sendCDChangedEvent(void);
00138
00139 void toMap(QHash<QString, QString> &infoMap);
00140
00141 void showMiniPlayer(void);
00142 enum RepeatMode
00143 { REPEAT_OFF = 0,
00144 REPEAT_TRACK,
00145 REPEAT_ALL,
00146 MAX_REPEAT_MODES
00147 };
00148 enum ShuffleMode
00149 { SHUFFLE_OFF = 0,
00150 SHUFFLE_RANDOM,
00151 SHUFFLE_INTELLIGENT,
00152 SHUFFLE_ALBUM,
00153 SHUFFLE_ARTIST,
00154 MAX_SHUFFLE_MODES
00155 };
00156
00157 enum ResumeMode
00158 { RESUME_OFF,
00159 RESUME_TRACK,
00160 RESUME_EXACT,
00161 MAX_RESUME_MODES
00162 };
00163
00164 RepeatMode getRepeatMode(void) { return m_repeatMode; }
00165 void setRepeatMode(RepeatMode mode) { m_repeatMode = mode; }
00166 RepeatMode toggleRepeatMode(void);
00167
00168 ShuffleMode getShuffleMode(void) { return m_shuffleMode; }
00169 void setShuffleMode(ShuffleMode mode);
00170 ShuffleMode toggleShuffleMode(void);
00171
00172 ResumeMode getResumeMode(void) { return m_resumeMode; }
00173
00174 protected:
00175 void customEvent(QEvent *event);
00176
00177 private:
00178 void loadSettings(void);
00179 void stopDecoder(void);
00180 bool openOutputDevice(void);
00181 void updateLastplay(void);
00182 void updateVolatileMetadata(void);
00183 void sendVolumeChangedEvent(void);
00184
00185 void setupDecoderHandler(void);
00186 void decoderHandlerReady(void);
00187
00188 Playlist *m_currentPlaylist;
00189 int m_currentTrack;
00190 int m_currentTime;
00191
00192 Metadata *m_currentMetadata;
00193 Metadata *m_oneshotMetadata;
00194 Metadata m_displayMetadata;
00195
00196 AudioOutput *m_output;
00197 DecoderHandler *m_decoderHandler;
00198
00199 QSet<QObject*> m_visualisers;
00200
00201 QString m_CDdevice;
00202
00203 bool m_isPlaying;
00204 bool m_isAutoplay;
00205 bool m_canShowPlayer;
00206 bool m_autoShowPlayer;
00207 bool m_wasPlaying;
00208 bool m_updatedLastplay;
00209 bool m_allowRestorePos;
00210
00211 int m_lastplayDelay;
00212
00213 ShuffleMode m_shuffleMode;
00214 RepeatMode m_repeatMode;
00215 ResumeMode m_resumeMode;
00216
00217 float m_playSpeed;
00218
00219
00220 CDWatcherThread *m_cdWatcher;
00221
00222
00223 bool m_isStreaming;
00224 QList<Metadata> m_playedList;
00225 int m_lastTrackStart;
00226 };
00227
00228 Q_DECLARE_METATYPE(MusicPlayer::RepeatMode);
00229 Q_DECLARE_METATYPE(MusicPlayer::ShuffleMode);
00230
00231
00232 extern MPUBLIC MusicPlayer *gPlayer;
00233
00234
00236
00237 class CDWatcherThread : public QThread
00238 {
00239 public:
00240
00241 CDWatcherThread(const QString &dev);
00242 virtual void run(void);
00243 bool statusChanged(void) { return m_cdStatusChanged; }
00244 QMutex *getLock(void) { return &m_musicLock; }
00245 void stop(void) { m_stopped = true; }
00246
00247 private:
00248
00249 bool m_stopped;
00250 QString m_cdDevice;
00251 bool m_cdStatusChanged;
00252 QMutex m_musicLock;
00253 };
00254
00255 #endif