50ab1f8d5fd09f8c7a609d49d77441ed984eded7
[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/VolumeSlider>
31 #include <phonon/Effect>
32 #include <phonon/Path>
33 #include <QStack>
34 #include <QQueue>
35
36 // represents player
37
38 using SomePlayer::DataObjects::Track;
39 using SomePlayer::DataObjects::TrackMetadata;
40 using SomePlayer::DataObjects::Playlist;
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
48                 class Player : public QObject
49                 {
50                         Q_OBJECT
51                 public:
52                         explicit Player(QObject *parent = 0);
53
54                         bool random() {return _random;}
55                         bool repeat() {return _repeat;}
56                         int volume() {return (int)(_output->volume()*100 + 0.5);}
57                         Phonon::MediaObject* mediaObject() {return _player;}
58                         bool equalizerEnabled() {return _equalizer_enabled;}
59                         bool equalizerAvailable() {return _equalizer != NULL;}
60
61                 signals:
62                         void stateChanged (PlayerState);
63                         void trackChanged (Track);
64                         void tick (int, int); // played | all (seconds)
65                         void trackDone(Track);
66
67                 public slots:
68                         void setTrackId(int id);
69                         void enqueue(int id);
70                         void toggle();
71                         void play();
72                         void stop();
73                         void next();
74                         void prev();
75                         void setPlaylist(Playlist);
76                         void toggleRandom();
77                         void toggleRepeat();
78                         void seek(int);
79                         void setVolume(int);
80                         void enableEqualizer();
81                         void disableEqualizer();
82                         void setEqualizerValue(int band, double value);
83                         void equalizerValue(int band, double *);
84                 private slots:
85                         void _stateChanged(Phonon::State, Phonon::State);
86                         void _tick(qint64);
87                 private:
88                         int _current;
89                         Track _track; // current track (workaround)
90                         bool _random;
91                         bool _repeat;
92                         bool _equalizer_enabled;
93                         QStack<int> _history;
94                         QQueue<int> _queue;
95                         QStack<int> _prev_history;
96                         Playlist _playlist;
97                         Phonon::MediaObject *_player;
98                         Phonon::AudioOutput *_output;
99                         Phonon::Path _path;
100                         Phonon::Effect *_equalizer;
101                         PlayerState _state;
102                         Config _config;
103
104                         void _set_source();
105
106                 };
107         };
108 };
109
110 #endif // PLAYER_H