Restoring eq after start, checkable fav button
[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                         Track current();
73
74                 signals:
75                         void stateChanged (PlayerState);
76                         void trackChanged (Track);
77                         void tick (int, int); // played | all (seconds)
78                         void trackDone(Track);
79
80                 public slots:
81                         void setTrackId(int id);
82                         void enqueue(int id);
83                         void toggle();
84                         void play();
85                         void stop();
86                         void next();
87                         void prev();
88                         void setPlaylist(Playlist);
89                         void toggleRandom();
90                         void toggleRepeat();
91                         void seek(int);
92                         void enableEqualizer();
93                         void disableEqualizer();
94                         void setEqualizerValue(int band, double value);
95                         void equalizerValue(int band, double *);
96                         QString artist();
97                         QString album();
98                         QString title();
99                 private slots:
100                         void _stateChanged(Phonon::State, Phonon::State);
101                         void _tick(qint64);
102                 private:
103                         Randomizer _randomizer;
104                         int _current;
105                         Track _track; // current track (workaround)
106                         bool _random;
107                         RepeatRule _repeat;
108                         bool _equalizer_enabled;
109                         QStack<int> _history;
110                         QQueue<int> _queue;
111                         QStack<int> _prev_history;
112                         Playlist _playlist;
113                         Phonon::MediaObject *_player;
114                         Phonon::AudioOutput *_output;
115                         Phonon::Path _path;
116                         Phonon::Effect *_equalizer;
117                         PlayerState _state;
118                         Config _config;
119
120                         void _set_source();
121
122                 };
123         };
124 };
125
126 #endif // PLAYER_H