71d0b27c180916671a2d3d8390b71c6f3d0358ea
[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 pause();
86                         void playIfPaused();
87                         void stop();
88                         void next();
89                         void prev();
90                         void setPlaylist(Playlist);
91                         void toggleRandom();
92                         void toggleRepeat();
93                         void seek(int);
94                         void enableEqualizer();
95                         void disableEqualizer();
96                         void setEqualizerValue(int band, double value);
97                         void equalizerValue(int band, double *);
98                         QString artist();
99                         QString album();
100                         QString title();
101                 private slots:
102                         void _stateChanged(Phonon::State, Phonon::State);
103                         void _tick(qint64);
104                 private:
105                         Randomizer _randomizer;
106                         int _current;
107                         Track _track; // current track (workaround)
108                         bool _random;
109                         RepeatRule _repeat;
110                         bool _equalizer_enabled;
111                         QStack<int> _history;
112                         QQueue<int> _queue;
113                         QStack<int> _prev_history;
114                         Playlist _playlist;
115                         Phonon::MediaObject *_player;
116                         Phonon::AudioOutput *_output;
117                         Phonon::Path _path;
118                         Phonon::Effect *_equalizer;
119                         PlayerState _state;
120                         Config _config;
121
122                         void _set_source();
123
124                 };
125         };
126 };
127
128 #endif // PLAYER_H