f756ac16314415c2b270b51ff29a3978b931d98b
[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::Storage::Config;
41
42 namespace SomePlayer {
43         namespace Playback {
44
45                 enum PlayerState { PLAYER_STOPPED, PLAYER_PLAYING, PLAYER_PAUSED, PLAYER_LOADING, PLAYER_DONE, PLAYER_ERROR };
46                 enum RepeatRule {REPEAT_NO, REPEAT_ALL, REPEAT_ONE};
47
48                 class Randomizer {
49                 public:
50                         void setPlaylist(QList<int>);
51                         int next();
52                         void removeId(int);
53                 private:
54                         QList<int> _playlist;
55                         QList<int> _rand;
56                         void _shuffle();
57                         int _last;
58                 };
59
60                 class Player : public QObject
61                 {
62                         Q_OBJECT
63                 public:
64                         explicit Player(QObject *parent = 0);
65
66                         bool random() {return _random;}
67                         RepeatRule repeat() {return _repeat;}
68                         Phonon::MediaObject* mediaObject() {return _player;}
69                         bool equalizerEnabled() {return _equalizer_enabled;}
70                         bool equalizerAvailable() {return _equalizer != NULL;}
71                         PlayerState state() {return _state;}
72
73                 signals:
74                         void stateChanged (PlayerState);
75                         void trackChanged (Track);
76                         void tick (int, int); // played | all (seconds)
77                         void trackDone(Track);
78
79                 public slots:
80                         void setTrackId(int id);
81                         void enqueue(int id);
82                         void toggle();
83                         void play();
84                         void stop();
85                         void next();
86                         void prev();
87                         void setPlaylist(Playlist);
88                         void toggleRandom();
89                         void toggleRepeat();
90                         void seek(int);
91                         void enableEqualizer();
92                         void disableEqualizer();
93                         void setEqualizerValue(int band, double value);
94                         void equalizerValue(int band, double *);
95                         QString artist();
96                         QString album();
97                         QString title();
98                 private slots:
99                         void _stateChanged(Phonon::State, Phonon::State);
100                         void _tick(qint64);
101                 private:
102                         Randomizer _randomizer;
103                         int _current;
104                         Track _track; // current track (workaround)
105                         bool _random;
106                         RepeatRule _repeat;
107                         bool _equalizer_enabled;
108                         QStack<int> _history;
109                         QQueue<int> _queue;
110                         QStack<int> _prev_history;
111                         Playlist _playlist;
112                         Phonon::MediaObject *_player;
113                         Phonon::AudioOutput *_output;
114                         Phonon::Path _path;
115                         Phonon::Effect *_equalizer;
116                         PlayerState _state;
117                         Config _config;
118
119                         void _set_source();
120
121                 };
122         };
123 };
124
125 #endif // PLAYER_H