21#include "wmlib_interface.h"
25#include <KLocalizedString>
31 #include "wmlib/include/wm_cdrom.h"
32 #include "wmlib/include/wm_cdtext.h"
33 #include "wmlib/include/wm_helpers.h"
36#define TRACK_VALID(track) ((track) && (track <= m_tracks))
38KWMLibCompactDiscPrivate::KWMLibCompactDiscPrivate(
KCompactDisc *p,
40 KCompactDiscPrivate(p, dev),
42 m_audioSystem(audioSystem),
43 m_audioDevice(audioDevice)
45 m_interface = m_audioSystem;
48KWMLibCompactDiscPrivate::~KWMLibCompactDiscPrivate()
51 wm_cd_destroy(m_handle);
55bool KWMLibCompactDiscPrivate::createInterface()
60 if (qEnvironmentVariableIsSet(
"KCOMPACTDISC_WMLIB_DEBUG")) {
61 wm_cd_set_verbosity(WM_MSG_LEVEL_DEBUG | WM_MSG_CLASS_ALL);
71 if(!WM_CDS_ERROR(
status)) {
74 m_deviceRevision =
QLatin1String(wm_drive_revision(m_handle));
77 Q_EMIT q->discChanged(0);
79 if (m_infoMode == KCompactDisc::Asynchronous) {
91unsigned KWMLibCompactDiscPrivate::trackLength(
unsigned track)
93 return (
unsigned)wm_cd_gettracklen(m_handle, track);
96bool KWMLibCompactDiscPrivate::isTrackAudio(
unsigned track)
98 return !wm_cd_gettrackdata(m_handle, track);
101void KWMLibCompactDiscPrivate::playTrackPosition(
unsigned track,
unsigned position)
103 unsigned firstTrack, lastTrack;
105 firstTrack = TRACK_VALID(track) ? track : 1;
106 lastTrack = firstTrack + 1;
107 lastTrack = TRACK_VALID(lastTrack) ? lastTrack : WM_ENDTRACK;
109 qDebug() <<
"play track " << firstTrack <<
" position "
112 wm_cd_play(m_handle, firstTrack, position, lastTrack);
115void KWMLibCompactDiscPrivate::pause()
117 wm_cd_pause(m_handle);
120void KWMLibCompactDiscPrivate::stop()
122 wm_cd_stop(m_handle);
125void KWMLibCompactDiscPrivate::eject()
127 wm_cd_eject(m_handle);
130void KWMLibCompactDiscPrivate::closetray()
132 wm_cd_closetray(m_handle);
137#define RANGE2PERCENT(x, min, max) (((x) - (min)) * 100)/ ((max) - (min))
138#define PERCENT2RANGE(x, min, max) ((((x) * ((max) - (min))) / 100 ) + (min))
139void KWMLibCompactDiscPrivate::setVolume(
unsigned volume)
142 vol = PERCENT2RANGE(volume, WM_VOLUME_MUTE, WM_VOLUME_MAXIMAL);
143 bal = wm_cd_getbalance(m_handle);
144 wm_cd_volume(m_handle, vol, bal);
147void KWMLibCompactDiscPrivate::setBalance(
unsigned balance)
150 vol = wm_cd_getvolume(m_handle);
151 bal = PERCENT2RANGE(balance, WM_BALANCE_ALL_LEFTS, WM_BALANCE_ALL_RIGHTS);
152 wm_cd_volume(m_handle, vol, bal);
155unsigned KWMLibCompactDiscPrivate::volume()
157 int vol = wm_cd_getvolume(m_handle);
158 unsigned volume = RANGE2PERCENT(vol, WM_VOLUME_MUTE, WM_VOLUME_MAXIMAL);
162unsigned KWMLibCompactDiscPrivate::balance()
164 int bal = wm_cd_getbalance(m_handle);
165 unsigned balance = RANGE2PERCENT(bal, WM_BALANCE_ALL_LEFTS, WM_BALANCE_ALL_RIGHTS);
170void KWMLibCompactDiscPrivate::queryMetadata()
176KCompactDisc::DiscStatus KWMLibCompactDiscPrivate::discStatusTranslate(
int status)
179 case WM_CDM_TRACK_DONE:
182 return KCompactDisc::Playing;
184 return KCompactDisc::Paused;
186 return KCompactDisc::Stopped;
188 return KCompactDisc::Ejected;
191 return KCompactDisc::NoDisc;
192 case WM_CDM_CDDAERROR:
194 case WM_CDM_BUFFERING:
195 return KCompactDisc::NotReady;
197 return KCompactDisc::Error;
201void KWMLibCompactDiscPrivate::timerExpired()
203 KCompactDisc::DiscStatus
status;
207 status = discStatusTranslate(wm_cd_status(m_handle));
210 if(skipStatusChange(
status))
211 goto timerExpiredExit;
216 case KCompactDisc::Ejected:
217 case KCompactDisc::NoDisc:
222 m_tracks = wm_cd_getcountoftracks(m_handle);
224 qDebug() <<
"New disc with " << m_tracks <<
" tracks";
225 m_discId = wm_cddb_discid(m_handle);
227 for(i = 1; i <= m_tracks; ++i) {
228 m_trackStartFrames.append(wm_cd_gettrackstart(m_handle, i));
230 m_trackStartFrames.append(wm_cd_gettrackstart(m_handle, i));
232 m_discLength = FRAMES2SEC(m_trackStartFrames[m_tracks] -
233 m_trackStartFrames[0]);
237 m_trackArtists.append(
i18n(
"Unknown Artist"));
238 m_trackTitles.append(
i18n(
"Unknown Title"));
239 for(i = 1; i <= m_tracks; ++i) {
240 m_trackArtists.append(
i18n(
"Unknown Artist"));
241 m_trackTitles.append(
ki18n(
"Track %1").subs(i, 2).
toString());
244qDebug() <<
"m_tracks " << m_tracks;
245qDebug() <<
"m_trackStartFrames " << m_trackStartFrames;
246qDebug() <<
"m_trackArtists " << m_trackArtists;
247qDebug() <<
"m_trackTitles " << m_trackTitles;
249 Q_EMIT q->discChanged(m_tracks);
260 case KCompactDisc::Playing:
261 m_trackPosition = wm_get_cur_pos_rel(m_handle);
262 m_discPosition = wm_get_cur_pos_abs(m_handle) - FRAMES2SEC(m_trackStartFrames[0]);
265 qDebug() <<
"seek: " << m_seek <<
" trackPosition " << m_trackPosition;
266 if(abs((
long)(m_trackExpectedPosition - m_trackPosition)) > m_seek)
269 m_seek = abs((
long)(m_trackExpectedPosition - m_trackPosition));
273 Q_EMIT q->playoutPositionChanged(m_trackPosition);
278 track = wm_cd_getcurtrack(m_handle);
280 if(m_track != track) {
282 Q_EMIT q->playoutTrackChanged(m_track);
286 case KCompactDisc::Stopped:
300void KWMLibCompactDiscPrivate::cdtext()
302 struct cdtext_info *info;
306 info = wm_cd_get_cdtext(m_handle);
308 if(!info || !info->valid || (
unsigned)info->count_of_entries != (m_tracks + 1)) {
309 qDebug() <<
"no or invalid CDTEXT";
313 m_trackArtists[0] =
QLatin1String(
reinterpret_cast<char*
>(info->blocks[0]->performer[0]) );
314 m_trackTitles[0] =
QLatin1String(
reinterpret_cast<char*
>(info->blocks[0]->name[0]) );
316 for(i = 1; i <= m_tracks; ++i) {
317 m_trackArtists[i] =
QLatin1String(
reinterpret_cast<char*
>(info->blocks[0]->performer[i]) );
318 m_trackTitles[i] =
QLatin1String(
reinterpret_cast<char*
>(info->blocks[0]->name[i]) );
321 qDebug() <<
"CDTEXT";
322 qDebug() <<
"m_trackArtists " << m_trackArtists;
323 qDebug() <<
"m_trackTitles " << m_trackTitles;
325 Q_EMIT q->discInformation(KCompactDisc::Cdtext);
328#include "moc_wmlib_interface.cpp"
KCompactDisc - A CD drive interface for the KDE Project.
static const QUrl cdromDeviceUrl(const QString &)
The Url of named CDROM device for this system.
Q_SCRIPTABLE CaptureState status()
KLocalizedString KI18N_EXPORT ki18n(const char *text)
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
QByteArray toLatin1() const const
QString path(ComponentFormattingOptions options) const const