c2a3c664b6e431b1f196b82d42a539eb442e1462
[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 Player : public QObject
49                 {
50                         Q_OBJECT
51                 public:
52                         explicit Player(QObject *parent = 0);
53                         bool random() {return _random;}
54                         RepeatRule repeat() {return _repeat;}
55                         Phonon::MediaObject* mediaObject() {return _player;}
56                         bool equalizerEnabled() {return _equalizer_enabled;}
57                         bool equalizerAvailable() {return _equalizer != NULL;}
58                         PlayerState state() {return _state;}
59                         Track current();
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); // refactor
70                         void toggle();
71                         void play();
72                         void pause();
73                         void playIfPaused();
74                         void stop();
75                         void next();
76                         void prev();
77                         void setPlaylist(Playlist);
78                         void toggleRandom();
79                         void toggleRepeat();
80                         void seek(int);
81                         void enableEqualizer();
82                         void disableEqualizer();
83                         void setEqualizerValue(int band, double value);
84                         void equalizerValue(int band, double *);
85                         QString artist();
86                         QString album();
87                         QString title();
88                 private slots:
89                         void _stateChanged(Phonon::State, Phonon::State);
90                         void _tick(qint64);
91                 private:
92                         Track _track; // current track
93                         bool _random;
94                         RepeatRule _repeat;
95                         bool _equalizer_enabled;
96                         QList<Track> _history;
97                         QList<Track> _queue;
98                         Playlist _playlist;
99                         Phonon::MediaObject *_player;
100                         Phonon::AudioOutput *_output;
101                         Phonon::Path _path;
102                         Phonon::Effect *_equalizer;
103                         PlayerState _state;
104                         Config _config;
105                         void _set_source();
106                         void _to_history(Track t);
107                         void _truncate_history();
108                 };
109         };
110 };
111
112 #endif // PLAYER_H