summaryrefslogtreecommitdiffstats
path: root/src/modules/mediaplayer/mp_interface.h
blob: f1a5479c01829162ca01eced0a83248b192e1293 (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
#ifndef _MP_INTERFACE_H_
#define _MP_INTERFACE_H_
//=============================================================================
//
//   File : mp_interface.h
//   Creation date : Fri Mar 25 20:01:25 2005 GMT by Szymon Stefanek
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 2005 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "kvi_settings.h"
#include "kvi_qstring.h"
#include "kvi_kvs_types.h"

class KviMediaPlayerInterface
{
public:
	// don't do any initialization in the constructor
	// implement lazy initialization in each function instead
	KviMediaPlayerInterface(){};
	virtual ~KviMediaPlayerInterface(){};
protected:
	TQString m_szLastError;
public:
	const TQString & lastError(){ return m_szLastError; };

	//
	// mandatory interface
	//

	// This should attempt to detect if the player is available on the user's system
	// and returning a score from 0 to 100 depending on how likely the player will work
	// and how many of its functions are available. 100 means that the interface
	// is absolutely sure that the player will start and play stuff.
	// If bStart is true then the function is allowed to explicitly start the player,
	// otherwise a startup attempt should not be made and different methods should be used.
	// This function is used for auto-detection and is called twice: the first time
	// with bStart set to false to determine the players that potentially could run.
	// If no player returns a reasonably high value by just guessing, then
	// a second loop may be attempted with the "bStart" parameter set to true.
	// A level of 0 is considered total failure: in this case detect() should
	// also set the last error to a descriptive string.
	virtual int detect(bool bStart) = 0;

	// play previous media, return false only on communication failure
	virtual bool prev() = 0;
	// play next media, return false only on communication failure
	virtual bool next() = 0;
	// start playback now, return false only on communication failure (i.e. return true when already playing)
	virtual bool play() = 0;
	// stop playback now, return false only on communication failure (i.e. return true when already stopped)
	virtual bool stop() = 0;
	// pause playback now (do NOT toggle pause, just pause), return false only on communication failure
	virtual bool pause() = 0;
	
	// current media related
	
	// currently played media: it should include AT least the title
	// but may also include other informations.
	// this string MUST be non-empty when the player is playing something.
	// If it is empty then either the player is not playing or there are
	// communication errors.
	virtual TQString nowPlaying() = 0;
	// currently played media resource locator
	// file://<filepath> for local files, dvb:// for dvb media , dvd:// for dvd's
	// http:// for audio streams etc...
	// empty if player is not playing (or in the tragic case that the player
	// can't determine the url).
	virtual TQString mrl() = 0;
	
	// optional interface

	// this should play the specified mrl
	// the mrl may be (or may be not) added to the player's playlist
	// the function should return false if the player doesn't support
	// this function or there is a communication error
	virtual bool playMrl(const TQString &mrl);
	// what is this ? :D
	virtual bool amipExec(const TQString &cmd);
	virtual TQString amipEval(const TQString &cmd);
	// this is functions to hide,show and minimize the player interface
	virtual bool hide();
	virtual bool show();
	virtual bool minimize();
	// set the volume of mediaplayer (0-255)
	virtual bool setVol(kvs_int_t &iVol);
	// get the pvolume value(0-255)
	virtual int getVol();
	//mute the volume
	virtual bool mute();
	// should quit the player if it's running
	// return false only on communication failure
	virtual bool quit();
	// return the current player status
	enum PlayerStatus { Unknown, Stopped, Playing, Paused };
	virtual KviMediaPlayerInterface::PlayerStatus status();
	// current position in the media (msecs)
	// 0 if the player isn't playing anything and -1 if unknown
	virtual int position();
	// total length of the media (msecs)
	// 0 if the player isn't playing anyting and -1 if unknown (e.g. a stream)
	virtual int length();
	// jump to position
	virtual bool jumpTo(int &iPos);
	// interface with a default implementation for certain types of media (read for mp3)
	// reimplement only if the player knows better

	// currently played media title (it's player choice if the title
	// is to be derived from the media file name or from the informations
	// stored inside the file like the ID3 tag...)
	// If the player is not playing, the returned string should be empty
	virtual TQString title();
	// currently played media artist's name
	// If the player is not playing, the returned string should be empty
	// If the player can't guess the artist it should return the string "unknown"
	virtual TQString artist();
	// currently plaued media genre
	// If the player is not playing, the returned string should be empty
	// If the player can't guess the genre it should return the string "unknown"
	virtual TQString genre();
	// currently played media comment.
	// Empty string if the player isn't playing anything or there is no comment
	virtual TQString comment();
	// currently played media year
	// Empty string if the player isn't playing anything or the year is unknown
	virtual TQString year();
	// currently played media album
	// Empty string if the player isn't playing anything
	// If the player can't guess the album/collection then this string should be "unknown"
	virtual TQString album();
	// bit rate in bits/sec, 0 if unknown
	virtual int bitRate();
	// sample rate in samples/sec (Hz), 0 if unknown
	virtual int sampleRate();
	// number of channels
	virtual int channels();
	// frequency
	// the type of the media (MPEG Layer 3, MPEG Layer 4, OGG Vorbis, AVI Stream etc..)
	virtual TQString mediaType();
	// get the position in the playlist
	virtual int getPlayListPos();
	// set the position in the playlist
	virtual bool setPlayListPos(int &iPos);
	// return the list's length 
	virtual int getListLength();
	// return the Eq(number) value
	virtual int getEqData(int &i_val);
	// set the  Eq(iPos) to Eq(iVal) value
	virtual bool setEqData(int &iPos, int &iVal);
	// get the   Repeat bool value
	virtual bool getRepeat();
	// get the  shuffle bool value
	virtual bool getShuffle();
	// set the   Repeat bool value
	virtual bool setRepeat(bool &bVal);
	// set the  shuffle bool value
	virtual bool setShuffle(bool &bVal);
	void setLastError(const TQString &szLastError){ m_szLastError = szLastError; };
protected:
	void notImplemented();
	TQString getLocalFile();
};


class KviMediaPlayerInterfaceDescriptor
{
public:
	KviMediaPlayerInterfaceDescriptor(){};
	virtual ~KviMediaPlayerInterfaceDescriptor(){};
public:
	virtual const TQString & name() = 0;
	virtual const TQString & description() = 0;
	virtual KviMediaPlayerInterface * instance() = 0;
};


#define MP_DECLARE_DESCRIPTOR(_interfaceclass) \
	class _interfaceclass ## Descriptor : public KviMediaPlayerInterfaceDescriptor \
	{ \
	public: \
		_interfaceclass ## Descriptor(); \
		virtual ~_interfaceclass ## Descriptor(); \
	protected: \
		_interfaceclass * m_pInstance; \
		TQString m_szName; \
		TQString m_szDescription; \
	public: \
		virtual const TQString & name(); \
		virtual const TQString & description(); \
		virtual KviMediaPlayerInterface * instance(); \
	};

#define MP_IMPLEMENT_DESCRIPTOR(_interfaceclass,_name,_description) \
	_interfaceclass ## Descriptor::_interfaceclass ## Descriptor() \
	: KviMediaPlayerInterfaceDescriptor() \
	{ \
		m_pInstance = 0; \
		m_szName = _name; \
		m_szDescription = _description; \
	} \
	_interfaceclass ## Descriptor::~_interfaceclass ## Descriptor() \
	{ \
		if(m_pInstance)delete m_pInstance; \
	} \
	const TQString & _interfaceclass ## Descriptor::name() \
	{ \
		return m_szName; \
	} \
	const TQString & _interfaceclass ## Descriptor::description() \
	{ \
		return m_szDescription; \
	} \
	KviMediaPlayerInterface * _interfaceclass ## Descriptor::instance() \
	{ \
		if(!m_pInstance)m_pInstance = new _interfaceclass(); \
		return m_pInstance; \
	}

#define MP_CREATE_DESCRIPTOR(_interfaceclass) \
	new _interfaceclass ## Descriptor()

#endif //!_MP_INTERFACE_H_