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