KVIrc  4.9.2
DeveloperAPIs
MpInterface.h
Go to the documentation of this file.
1 #ifndef _MP_INTERFACE_H_
2 #define _MP_INTERFACE_H_
3 //=============================================================================
4 //
5 // File : MpInterface.h
6 // Creation date : Fri Mar 25 20:01:25 2005 GMT by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2005-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "kvi_settings.h"
28 #include "KviQString.h"
29 #include "KviKvsTypes.h"
30 
32 {
33 public:
34  // don't do any initialization in the constructor
35  // implement lazy initialization in each function instead
37  virtual ~MpInterface(){};
38 
39 protected:
40  QString m_szLastError;
41 
42 public:
43  const QString & lastError() const { return m_szLastError; };
44 
45  //
46  // mandatory interface
47  //
48 
49  // This should attempt to detect if the player is available on the user's system
50  // and returning a score from 0 to 100 depending on how likely the player will work
51  // and how many of its functions are available. 100 means that the interface
52  // is absolutely sure that the player will start and play stuff.
53  // If bStart is true then the function is allowed to explicitly start the player,
54  // otherwise a startup attempt should not be made and different methods should be used.
55  // This function is used for auto-detection and is called twice: the first time
56  // with bStart set to false to determine the players that potentially could run.
57  // If no player returns a reasonably high value by just guessing, then
58  // a second loop may be attempted with the "bStart" parameter set to true.
59  // A level of 0 is considered total failure: in this case detect() should
60  // also set the last error to a descriptive string.
61  virtual int detect(bool bStart) = 0;
62 
63  // play previous media, return false only on communication failure
64  virtual bool prev() = 0;
65  // play next media, return false only on communication failure
66  virtual bool next() = 0;
67  // start playback now, return false only on communication failure (i.e. return true when already playing)
68  virtual bool play() = 0;
69  // stop playback now, return false only on communication failure (i.e. return true when already stopped)
70  virtual bool stop() = 0;
71  // pause playback now (do NOT toggle pause, just pause), return false only on communication failure
72  virtual bool pause() = 0;
73 
74  // current media related
75 
76  // currently played media: it should include AT least the title
77  // but may also include other information.
78  // this string MUST be non-empty when the player is playing something.
79  // If it is empty then either the player is not playing or there are
80  // communication errors.
81  virtual QString nowPlaying() = 0;
82  // currently played media resource locator
83  // file://<filepath> for local files, dvb:// for dvb media, dvd:// for dvd's
84  // http:// for audio streams etc...
85  // empty if player is not playing (or in the tragic case that the player
86  // can't determine the url).
87  virtual QString mrl() = 0;
88 
89  // optional interface
90 
91  // this should play the specified mrl
92  // the mrl may be (or may be not) added to the player's playlist
93  // the function should return false if the player doesn't support
94  // this function or there is a communication error
95  virtual bool playMrl(const QString & mrl);
96  // what is this ? :D
97  virtual bool amipExec(const QString & cmd);
98  virtual QString amipEval(const QString & cmd);
99  // this is functions to hide,show and minimize the player interface
100  virtual bool hide();
101  virtual bool show();
102  virtual bool minimize();
103  // set the volume of mediaplayer (0-255)
104  virtual bool setVol(kvs_int_t & iVol);
105  // get the pvolume value(0-255)
106  virtual int getVol();
107  //mute the volume
108  virtual bool mute();
109  // should quit the player if it's running
110  // return false only on communication failure
111  virtual bool quit();
112  // return the current player status
114  {
119  };
121  // current position in the media (msecs)
122  // 0 if the player isn't playing anything and -1 if unknown
123  virtual int position();
124  // total length of the media (msecs)
125  // 0 if the player isn't playing anyting and -1 if unknown (e.g. a stream)
126  virtual int length();
127  // jump to position
128  virtual bool jumpTo(kvs_int_t & iPos);
129  // interface with a default implementation for certain types of media (read for mp3)
130  // reimplement only if the player knows better
131 
132  // currently played media title (it's player choice if the title
133  // is to be derived from the media file name or from the information
134  // stored inside the file like the ID3 tag...)
135  // If the player is not playing, the returned string should be empty
136  virtual QString title();
137  // currently played media artist's name
138  // If the player is not playing, the returned string should be empty
139  // If the player can't guess the artist it should return the string "unknown"
140  virtual QString artist();
141  // currently plaued media genre
142  // If the player is not playing, the returned string should be empty
143  // If the player can't guess the genre it should return the string "unknown"
144  virtual QString genre();
145  // currently played media comment.
146  // Empty string if the player isn't playing anything or there is no comment
147  virtual QString comment();
148  // currently played media year
149  // Empty string if the player isn't playing anything or the year is unknown
150  virtual QString year();
151  // currently played media album
152  // Empty string if the player isn't playing anything
153  // If the player can't guess the album/collection then this string should be "unknown"
154  virtual QString album();
155  // bit rate in bits/sec, 0 if unknown
156  virtual int bitRate();
157  // sample rate in samples/sec (Hz), 0 if unknown
158  virtual int sampleRate();
159  // number of channels
160  virtual int channels();
161  // frequency
162  // the type of the media (MPEG Layer 3, MPEG Layer 4, OGG Vorbis, AVI Stream etc..)
163  virtual QString mediaType();
164  // get the position in the playlist
165  virtual int getPlayListPos();
166  // set the position in the playlist
167  virtual bool setPlayListPos(kvs_int_t & iPos);
168  // return the list's length
169  virtual int getListLength();
170  // return the Eq(number) value
171  virtual int getEqData(kvs_int_t & i_val);
172  // set the Eq(iPos) to Eq(iVal) value
173  virtual bool setEqData(kvs_int_t & iPos, kvs_int_t & iVal);
174  // get the Repeat bool value
175  virtual bool getRepeat();
176  // get the shuffle bool value
177  virtual bool getShuffle();
178  // set the Repeat bool value
179  virtual bool setRepeat(bool & bVal);
180  // set the shuffle bool value
181  virtual bool setShuffle(bool & bVal);
182  void setLastError(const QString & szLastError) { m_szLastError = szLastError; };
183 protected:
184  void notImplemented();
185  QString getLocalFile();
186 };
187 
189 {
190 public:
193 
194 public:
195  virtual const QString & name() = 0;
196  virtual const QString & description() = 0;
197  virtual MpInterface * instance() = 0;
198 };
199 
200 #define MP_DECLARE_DESCRIPTOR(_interfaceclass) \
201  class _interfaceclass##Descriptor : public MpInterfaceDescriptor \
202  { \
203  public: \
204  _interfaceclass##Descriptor(); \
205  virtual ~_interfaceclass##Descriptor(); \
206  \
207  protected: \
208  _interfaceclass * m_pInstance; \
209  QString m_szName; \
210  QString m_szDescription; \
211  \
212  public: \
213  virtual const QString & name(); \
214  virtual const QString & description(); \
215  virtual MpInterface * instance(); \
216  };
217 
218 #define MP_IMPLEMENT_DESCRIPTOR(_interfaceclass, _name, _description) \
219  _interfaceclass##Descriptor::_interfaceclass##Descriptor() \
220  : MpInterfaceDescriptor() \
221  { \
222  m_pInstance = 0; \
223  m_szName = _name; \
224  m_szDescription = _description; \
225  } \
226  _interfaceclass##Descriptor::~_interfaceclass##Descriptor() \
227  { \
228  if(m_pInstance) \
229  delete m_pInstance; \
230  } \
231  const QString & _interfaceclass##Descriptor::name() \
232  { \
233  return m_szName; \
234  } \
235  const QString & _interfaceclass##Descriptor::description() \
236  { \
237  return m_szDescription; \
238  } \
239  MpInterface * _interfaceclass##Descriptor::instance() \
240  { \
241  if(!m_pInstance) \
242  m_pInstance = new _interfaceclass(); \
243  return m_pInstance; \
244  }
245 
246 #define MP_CREATE_DESCRIPTOR(_interfaceclass) \
247  new _interfaceclass##Descriptor()
248 
249 #endif
PlayerStatus
Definition: MpInterface.h:113
virtual bool minimize()
Definition: MpInterface.cpp:76
virtual bool setShuffle(bool &bVal)
Definition: MpInterface.cpp:263
virtual bool getRepeat()
Definition: MpInterface.cpp:245
MpInterface()
Definition: MpInterface.h:36
Definition: MpInterface.h:188
virtual MpInterface::PlayerStatus status()
Definition: MpInterface.cpp:191
virtual QString amipEval(const QString &cmd)
Definition: MpInterface.cpp:95
virtual bool setEqData(kvs_int_t &iPos, kvs_int_t &iVal)
Definition: MpInterface.cpp:239
virtual bool hide()
Definition: MpInterface.cpp:64
Definition: MpInterface.h:115
QString m_szLastError
Definition: MpInterface.h:37
QString getLocalFile()
Definition: MpInterface.cpp:82
virtual int getListLength()
Definition: MpInterface.cpp:227
virtual int channels()
Definition: MpInterface.cpp:209
virtual bool mute()
Definition: MpInterface.cpp:179
virtual MpInterface * instance()=0
virtual bool play()=0
virtual bool playMrl(const QString &mrl)
Definition: MpInterface.cpp:155
virtual QString comment()
Definition: MpInterface.cpp:136
virtual QString album()
Definition: MpInterface.cpp:149
virtual bool getShuffle()
Definition: MpInterface.cpp:251
virtual QString genre()
Definition: MpInterface.cpp:130
virtual bool setPlayListPos(kvs_int_t &iPos)
Definition: MpInterface.cpp:221
Definition: MpInterface.h:118
virtual bool jumpTo(kvs_int_t &iPos)
Definition: MpInterface.cpp:185
virtual QString mediaType()
Definition: MpInterface.cpp:269
virtual ~MpInterfaceDescriptor()
Definition: MpInterface.h:192
virtual int sampleRate()
Definition: MpInterface.cpp:203
virtual QString title()
Definition: MpInterface.cpp:124
virtual bool setVol(kvs_int_t &iVol)
Definition: MpInterface.cpp:167
virtual bool amipExec(const QString &cmd)
Definition: MpInterface.cpp:161
MpInterfaceDescriptor()
Definition: MpInterface.h:191
virtual bool stop()=0
virtual bool pause()=0
virtual bool setRepeat(bool &bVal)
Definition: MpInterface.cpp:257
virtual QString mrl()=0
virtual QString nowPlaying()=0
Definition: MpInterface.h:116
Definition: MpInterface.h:31
virtual bool quit()
Definition: MpInterface.cpp:58
const QString & lastError() const
Definition: MpInterface.h:43
void notImplemented()
Definition: MpInterface.cpp:41
virtual int bitRate()
Definition: MpInterface.cpp:197
virtual ~MpInterface()
Definition: MpInterface.h:37
void setLastError(const QString &szLastError)
Definition: MpInterface.h:182
virtual bool prev()=0
virtual int length()
Definition: MpInterface.cpp:52
virtual bool show()
Definition: MpInterface.cpp:70
virtual const QString & description()=0
virtual const QString & name()=0
virtual int position()
Definition: MpInterface.cpp:46
Definition: MpInterface.h:117
virtual int getVol()
Definition: MpInterface.cpp:173
This file contains compile time settings.
virtual QString year()
Definition: MpInterface.cpp:142
virtual int getPlayListPos()
Definition: MpInterface.cpp:215
kvi_i64_t kvs_int_t
Definition: KviKvsTypes.h:33
virtual bool next()=0
Helper functions for the QString class.
virtual QString artist()
Definition: MpInterface.cpp:118
virtual int detect(bool bStart)=0
virtual int getEqData(kvs_int_t &i_val)
Definition: MpInterface.cpp:233