diff --git a/src/apps/cdplayer/CDAudioDevice.cpp b/src/apps/cdplayer/CDAudioDevice.cpp index a50f6babee..d5220c430b 100644 --- a/src/apps/cdplayer/CDAudioDevice.cpp +++ b/src/apps/cdplayer/CDAudioDevice.cpp @@ -391,6 +391,60 @@ CDAudioDevice::GetTime(cdaudio_time &track, cdaudio_time &disc) return true; } +// The SCSI table of contents consists of a 4-byte header followed by 100 track +// descriptors, which are each 8 bytes. We don't really need the first 5 bytes +// of the track descriptor, so we'll just ignore them. All we really want is the +// length of each track, which happen to be the last 3 bytes of the descriptor. +struct TrackDescriptor +{ + int32 unused; + int8 unused2; + + int8 min; + int8 sec; + int8 frame; +}; + +bool +CDAudioDevice::GetTimeForTrack(const int16 &index, cdaudio_time &track) +{ + scsi_toc toc; + status_t result = ioctl(fFileHandle, B_SCSI_GET_TOC, &toc); + + if (result != B_OK) + return false; + + int16 trackcount = toc.toc_data[3] - toc.toc_data[2] + 1; + + if(index < 1 || index > trackcount) + return false; + + TrackDescriptor *desc = (TrackDescriptor*)&(toc.toc_data[4]); + + track.minutes = desc[index].min - desc[index-1].min; + track.seconds = desc[index].sec - desc[index-1].sec; + + return true; +} + +bool +CDAudioDevice::GetTimeForDisc(cdaudio_time &disc) +{ + scsi_toc toc; + status_t result = ioctl(fFileHandle, B_SCSI_GET_TOC, &toc); + + if (result != B_OK) + return false; + + int16 trackcount = toc.toc_data[3] - toc.toc_data[2] + 1; + TrackDescriptor *desc = (TrackDescriptor*)&(toc.toc_data[4]); + + disc.minutes = desc[trackcount-1].min; + disc.seconds = desc[trackcount-1].sec; + + return true; +} + struct ConvertedToc { int32 min; diff --git a/src/apps/cdplayer/CDAudioDevice.h b/src/apps/cdplayer/CDAudioDevice.h index 2d210ce40c..54be78bb70 100644 --- a/src/apps/cdplayer/CDAudioDevice.h +++ b/src/apps/cdplayer/CDAudioDevice.h @@ -60,6 +60,8 @@ public: const char * GetDrivePath(void) const; bool GetTime(cdaudio_time &track, cdaudio_time &disc); + bool GetTimeForTrack(const int16 &index, cdaudio_time &track); + bool GetTimeForDisc(cdaudio_time &disc); int32 GetDiscID(void); private: diff --git a/src/apps/cdplayer/CDDBSupport.cpp b/src/apps/cdplayer/CDDBSupport.cpp index d73fb4ba89..dc643c6766 100644 --- a/src/apps/cdplayer/CDDBSupport.cpp +++ b/src/apps/cdplayer/CDDBSupport.cpp @@ -362,9 +362,18 @@ CDDBQuery::ReadFromServer(BDataIO *stream) BString tmp; ReadLine(tmp); - if (tmp.FindFirst("200") != 0) + if(tmp.FindFirst("200") != 0) { - printf("Error: %s\n",tmp.String()); + if(tmp.FindFirst("211") == 0) + { + while(tmp.CountChars() > 0) + { + printf("%s\n",tmp.String()); + ReadLine(tmp); + } + } + else + printf("Error: %s\n",tmp.String()); return; } BString category; diff --git a/src/apps/cdplayer/CDEngine.cpp b/src/apps/cdplayer/CDEngine.cpp index f8519ceb4e..6fe311e4e2 100644 --- a/src/apps/cdplayer/CDEngine.cpp +++ b/src/apps/cdplayer/CDEngine.cpp @@ -135,25 +135,38 @@ TimeState::UpdateState() if(sCDDevice.GetTime(track,disc)) { - return CurrentState(disc.minutes, disc.seconds, track.minutes, track.seconds); + cdaudio_time ttrack; + cdaudio_time tdisc; + int16 ctrack = sCDDevice.GetTrack(); + + sCDDevice.GetTimeForDisc(tdisc); + sCDDevice.GetTimeForTrack(ctrack,ttrack); + + return CurrentState(track,ttrack,disc,tdisc); } else { - CurrentState(-1, -1, -1, -1); + track.minutes = -1; + track.seconds = -1; + disc.minutes = -1; + disc.seconds = -1; + CurrentState(disc,disc,track,track); return false; } } -bool -TimeState::CurrentState(int32 dmin, int32 dsec, int32 tmin, int32 tsec) +bool +TimeState::CurrentState(cdaudio_time tracktime, cdaudio_time totaltracktime, + cdaudio_time disctime, cdaudio_time totaldisctime) { - if (dmin == fDiscMinutes && dsec == fDiscSeconds) + if (disctime.minutes == fDiscTime.minutes && disctime.seconds == fDiscTime.seconds) return false; - fDiscMinutes = dmin; - fDiscSeconds = dsec; - fTrackMinutes = tmin; - fTrackSeconds = tsec; + fDiscTime = disctime; + fTotalDiscTime = totaldisctime; + + fTrackTime = tracktime; + fTotalTrackTime = totaltracktime; return true; } @@ -161,15 +174,29 @@ TimeState::CurrentState(int32 dmin, int32 dsec, int32 tmin, int32 tsec) void TimeState::GetDiscTime(int32 &minutes, int32 &seconds) const { - minutes = fDiscMinutes; - seconds = fDiscSeconds; + minutes = fDiscTime.minutes; + seconds = fDiscTime.seconds; +} + +void +TimeState::GetTotalDiscTime(int32 &minutes, int32 &seconds) const +{ + minutes = fTotalDiscTime.minutes; + seconds = fTotalDiscTime.seconds; } void TimeState::GetTrackTime(int32 &minutes, int32 &seconds) const { - minutes = fTrackMinutes; - seconds = fTrackSeconds; + minutes = fTrackTime.minutes; + seconds = fTrackTime.seconds; +} + +void +TimeState::GetTotalTrackTime(int32 &minutes, int32 &seconds) const +{ + minutes = fTotalTrackTime.minutes; + seconds = fTotalTrackTime.seconds; } diff --git a/src/apps/cdplayer/CDEngine.h b/src/apps/cdplayer/CDEngine.h index 9aa85c1fbe..9de0f3711d 100644 --- a/src/apps/cdplayer/CDEngine.h +++ b/src/apps/cdplayer/CDEngine.h @@ -85,17 +85,22 @@ public: TimeState(void) : PeriodicWatcher() { } void GetDiscTime(int32 &minutes, int32 &seconds) const; + void GetTotalDiscTime(int32 &minutes, int32 &seconds) const; + void GetTrackTime(int32 &minutes, int32 &seconds) const; + void GetTotalTrackTime(int32 &minutes, int32 &seconds) const; private: - bool UpdateState(); - bool CurrentState(int32 dmin, int32 dsec, int32 tmin, int32 tsec); + bool UpdateState(); + bool CurrentState(cdaudio_time tracktime, + cdaudio_time totaltracktime, + cdaudio_time disctime, + cdaudio_time totaldisctime); - int32 fDiscMinutes; - int32 fDiscSeconds; - - int32 fTrackMinutes; - int32 fTrackSeconds; + cdaudio_time fDiscTime, + fTotalDiscTime, + fTrackTime, + fTotalTrackTime; }; class CDContentWatcher : public PeriodicWatcher diff --git a/src/apps/cdplayer/CDPlayer.cpp b/src/apps/cdplayer/CDPlayer.cpp index 07b0b7ca87..67809a47c8 100644 --- a/src/apps/cdplayer/CDPlayer.cpp +++ b/src/apps/cdplayer/CDPlayer.cpp @@ -561,14 +561,24 @@ CDPlayer::UpdateTimeInfo(void) engine->TimeStateWatcher()->GetDiscTime(min,sec); if(min >= 0) - sprintf(string,"Disc %ld:%.2ld / --:--",min,sec); + { + int32 tmin,tsec; + engine->TimeStateWatcher()->GetTotalDiscTime(tmin,tsec); + + sprintf(string,"Disc %ld:%.2ld / %ld:%.2ld",min,sec,tmin,tsec); + } else sprintf(string,"Disc --:-- / --:--"); fDiscTime->SetText(string); engine->TimeStateWatcher()->GetTrackTime(min,sec); if(min >= 0) - sprintf(string,"Track %ld:%.2ld / --:--",min,sec); + { + int32 tmin,tsec; + engine->TimeStateWatcher()->GetTotalTrackTime(tmin,tsec); + + sprintf(string,"Track %ld:%.2ld / %ld:%.2ld",min,sec,tmin,tsec); + } else sprintf(string,"Track --:-- / --:--"); fTrackTime->SetText(string);