summaryrefslogtreecommitdiffstats
path: root/noatun/library/noatun/player.h
blob: 406f4f1be566e31cd1bedb3f3b056198df296d36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#ifndef PLAYER_H
#define PLAYER_H

#include <tqobject.h>
#include <tqtimer.h>
#include <kurl.h>
#include <noatun/playlist.h>
#include <kdemacros.h>
class Engine;
class Playlist;
class KLibrary;

/**
 * This class has slots for all the common media player buttons
 * The slots are called, and it queries the Playlist for the appropriate
 * file.
 *
 * @short Noatun player backend
 * @author Charles Samuels
 * @version 2.4
 **/
class KDE_EXPORT Player : public TQObject
{
Q_OBJECT
  TQ_OBJECT
friend class Effects;
friend class PlaylistItemData;
friend class PlaylistNotifier;

public:
	/**
	 * "None":     Plays the playlist entries sequentially until the
	 *             end of the playlist.
	 * "Song":     Repeats the current playlist entry indefinitely.
	 * "Playlist": Plays the playlist entries sequentially, until
	 *             end of the playlist. Noatun will then restart
	 *             playback at the first song.
	 * "Random":   Plays the entries of the playlist in a random,
	 *             non-repeating order. Playback will continue
	 *             indefinitely.
	 **/
	enum LoopType { None=0, Song, Playlist, Random };

public:
	Player(TQObject *tqparent=0);
	~Player();

	/**
	 * @return a string with the time that can be used in the UI:
	 * CC:CC/LL:LL (mm:ss)
	 **/
	TQString lengthString(int _position=-1);
	/**
	 * @return LoopType enum
	 **/
	int loopStyle() const { return mLoopStyle; }
	/**
	 * @return the volume from 0-100
	 * use volume() instead
	 **/
	int volume() const;
	/**
	 * @return the position in milliseconds
	 **/
	int getTime() const { return position; }
	/**
	 * @return the track-length in milliseconds
	 **/
	int getLength();
	/**
	 * @return true if we're playing
	 **/
	bool isPlaying();
	/**
	 * @return true if paused
	 **/
	bool isPaused();
	/**
	 * @return true if stopped
	 **/
	bool isStopped();

	/**
	 * get the current playlist
	 * this may be null
	 * And this may not be necessarily an item allocated
	 * by playlist()
	 **/
	PlaylistItem current() const { return mCurrent;} // TODO: uninline

	/**
	 * loads a file and optionally plays it
	 * @param file the file to load
	 * @param purge true to clear the playlist on open
	 * @param autoplay start playing that file after loading it
	 **/
	void openFile(const KURL &file, bool purge=true, bool autoplay=false);

	/**
	 * loads all given files
	 * @param files list of files to load
	 * @param purge true to clear the playlist on open
	 * @param autoplay if true, play the first added item
	 **/
	void openFile(const KURL::List &files, bool purge=true, bool autoplay=false);

	Engine *engine() const { return mEngine; }

public slots:
	/**
	 * show or hide the playlist
	 **/
	void toggleListView();
	/**
	 * force the playing/paused/stopped/playlist shown signals to
	 * be sent out, also, you can send this if you want to
	 * make all the UIs re-display the current item
	 **/
	void handleButtons();
	/**
	 * remove current from playlist
	 **/
	void removeCurrent();

	/**
	 * go back a track
	 **/
	void back();
	/**
	 * stop playing
	 **/
	void stop();
	/**
	 * start playing
	 **/
	void play();

	/**
	 * play the given file
	 **/
	void play(const PlaylistItem &item);
	/**
	 * start playing, or pause if we're currently playing
	 **/
	void playpause();
	/**
	 * go forward a track
	 **/
	void forward(bool allowLoop = true);

	/**
	 * skip to the position, unit is milliseconds
	 **/
	void skipTo(int msec);

	/**
	 * goes to the next type of looping
	 **/
	void loop();

	/**
	 * set the type of looping
	 **/
	void loop(int i);

	void setVolume(int);

public slots:
	/**
	 * @internal
	 * Play the current file
	 **/
	void playCurrent();
	/**
	 * @internal
	 * load the current file
	 **/
	void newCurrent();

private slots:
	void posTimeout();
	void aboutToPlay();
	void slotUpdateStreamMeta(
		const TQString &streamName, const TQString &streamGenre,
		const TQString &streamUrl, const TQString &streamBitrate,
		const TQString &trackTitle, const TQString &trackUrl
	);

signals:
	/**
	 * Tells you to update the seekbar, volume
	 * and title.
	 **/
	void timeout();

	void stopped();

	void playing();

	void paused();

	/**
	 * when the type of looping is
	 * changed
	 **/
	void loopTypeChange(int t);

	/**
	 * the playlist is made visible
	 **/
	void playlistShown();

	/**
	 * the playlist is hidden
	 **/
	void playlistHidden();

	/**
	 * called at the same time as newSong, but
	 * maybe easier to work with
	 **/
	void newSongLen(int mins, int sec);

	/**
	 * when a new song is currently playing
	 **/
	void newSong();

	/**
	 * Called when a new song is about to be played, but
	 * hasn't started.  player->current() is the
	 * next song
	 **/
	void changed();

	/**
	 * called when we're about to load item, but it hasn't been yet
	 *
	 * this is used for implementing new protocols
	 **/
	void aboutToOpen(PlaylistItem item);

	void volumeChanged(int);

	/**
	 * this signal is emitted when the user (or a plugin) seeks 
	 * the song with @sa skipTo
	 **/
	void skipped();

	/**
	 * this signal is emitted when the user (or a plugin) seeks 
	 * the song with @sa skipTo
	 *
	 * @param msec is the position in the song in milliseconds 
	 **/
	void skipped(int msec);

private:
	Engine *mEngine;
	TQTimer filePos;
	int position;
	int mLoopStyle;
	bool firstTimeout;
	PlaylistItem mCurrent; // TODO eliminate
	TQPtrList<PlaylistNotifier> mNotifiers;
};


#endif