838bc409460328a78a45b48b752d83c472e30540
[someplayer] / src / player / player.h
1 /*
2  * SomePlayer - An alternate music player for Maemo 5
3  * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #ifndef PLAYER_H
21 #define PLAYER_H
22
23 #include <QObject>
24 #include "../someplayer.h"
25 #include "../track.h"
26 #include "../trackmetainformation.h"
27 #include "../playlist.h"
28 #include <phonon/MediaObject>
29 #include <phonon/AudioOutput>
30 #include <phonon/Effect>
31 #include <phonon/Path>
32 #include <QStack>
33 #include <QQueue>
34
35 // represents player
36
37 using SomePlayer::DataObjects::Track;
38 using SomePlayer::DataObjects::TrackMetadata;
39 using SomePlayer::DataObjects::Playlist;
40 using SomePlayer::DataObjects::LastPlayed;
41 using SomePlayer::Storage::Config;
42
43 namespace SomePlayer {
44         namespace Playback {
45
46                 enum PlayerState { PLAYER_STOPPED, PLAYER_PLAYING, PLAYER_PAUSED, PLAYER_LOADING, PLAYER_DONE, PLAYER_ERROR };
47                 enum RepeatRule {REPEAT_NO, REPEAT_ALL, REPEAT_ONE};
48
49                 class Player : public QObject
50                 {
51                         Q_OBJECT
52                 public:
53                         explicit Player(QObject *parent = 0);
54                         ~Player();
55                         bool random() {return _random;}
56                         RepeatRule repeat() {return _repeat;}
57                         Phonon::MediaObject* mediaObject() {return _player;}
58                         bool equalizerEnabled() {return _equalizer_enabled;}
59                         bool equalizerAvailable() {return _equalizer != NULL;}
60                         PlayerState state() {return _state;}
61                         Track current();
62                         void setAwaitingSeek(int pos) {_awaiting_seek = true; _awaiting_seek_pos = pos;}
63                 signals:
64                         void stateChanged (PlayerState);
65                         void trackChanged (Track);
66                         void tick (int, int); // played | all (seconds)
67                         void trackDone(Track);
68                         void startPlaylist();
69                         void saveLastPlayed(LastPlayed);
70
71                 public slots:
72                         void setTrackId(int id);
73                         void enqueue(int id); // refactor
74                         void toggle();
75                         void play();
76                         void pause();
77                         void playIfPaused();
78                         void stop();
79                         void next();
80                         void prev();
81                         void setPlaylist(Playlist);
82                         void toggleRandom();
83                         void toggleRepeat();
84                         void seek(int);
85                         void enableEqualizer();
86                         void disableEqualizer();
87                         void setEqualizerValue(int band, double value);
88                         void equalizerValue(int band, double *);
89                         QString artist();
90                         QString album();
91                         QString title();
92                 private slots:
93                         void _stateChanged(Phonon::State, Phonon::State);
94                         void _tick(qint64);
95                 private:
96                         Track _track; // current track
97                         bool _random;
98                         RepeatRule _repeat;
99                         bool _equalizer_enabled;
100                         QList<Track> _history;
101                         QList<Track> _queue;
102                         Playlist _playlist;
103                         Phonon::MediaObject *_player;
104                         Phonon::AudioOutput *_output;
105                         Phonon::Path _path;
106                         Phonon::Effect *_equalizer;
107                         PlayerState _state;
108                         Config _config;
109                         void _set_source();
110                         void _to_history(Track t);
111                         void _truncate_history();
112                         int _awaiting_seek_pos;
113                         bool _awaiting_seek;
114                 };
115         };
116 };
117
118 #endif // PLAYER_H