Total track and disc times are displayed in the appropriate boxes

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13637 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm 2005-07-11 18:06:02 +00:00
parent 74ef4bcdc4
commit 0ca3e71c1e
6 changed files with 131 additions and 24 deletions

View File

@ -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;

View File

@ -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:

View File

@ -362,8 +362,17 @@ CDDBQuery::ReadFromServer(BDataIO *stream)
BString tmp;
ReadLine(tmp);
if (tmp.FindFirst("200") != 0)
if(tmp.FindFirst("200") != 0)
{
if(tmp.FindFirst("211") == 0)
{
while(tmp.CountChars() > 0)
{
printf("%s\n",tmp.String());
ReadLine(tmp);
}
}
else
printf("Error: %s\n",tmp.String());
return;
}

View File

@ -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)
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;
}

View File

@ -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 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

View File

@ -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);