Added handling code for when CDDB lookup fails
Changed the way logging is set in CDDBQuery Fixed a bug which caused some funky behavior in Shuffle mode Missed adjusting Loop and Shuffle buttons when AdjustButtonState was introduced. Fixed. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13922 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
8733b7318d
commit
6d41bc18b1
@ -26,6 +26,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//#define DEBUG_CDDB
|
||||
|
||||
#ifdef DEBUG_CDDB
|
||||
#define STRACE(x) printf x
|
||||
#else
|
||||
#define STRACE(x) /* nothing */
|
||||
#endif
|
||||
|
||||
const int kTerminatingSignal = SIGINT; // SIGCONT;
|
||||
|
||||
// The SCSI table of contents consists of a 4-byte header followed by 100 track
|
||||
@ -68,9 +76,8 @@ ThrowIfNotSize(ssize_t size)
|
||||
}
|
||||
|
||||
|
||||
CDDBQuery::CDDBQuery(const char *server, int32 port, bool log)
|
||||
: fLog(log),
|
||||
fServerName(server),
|
||||
CDDBQuery::CDDBQuery(const char *server, int32 port)
|
||||
: fServerName(server),
|
||||
fPort(port),
|
||||
fConnected(false),
|
||||
fState(kInitial),
|
||||
@ -177,8 +184,7 @@ CDDBQuery::GetSites(bool (*eachFunc)(const char *site, int port, const char *lat
|
||||
BString tmp;
|
||||
|
||||
tmp = "sites\n";
|
||||
if (fLog)
|
||||
printf(">%s", tmp.String());
|
||||
STRACE((">%s", tmp.String()));
|
||||
|
||||
ThrowIfNotSize( fSocket.Send(tmp.String(), tmp.Length()) );
|
||||
ReadLine(tmp);
|
||||
@ -325,7 +331,7 @@ CDDBQuery::GetTrackTimes(const scsi_toc *toc, vector<cdaudio_time> ×)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
status_t
|
||||
CDDBQuery::ReadFromServer(BString &data)
|
||||
{
|
||||
// This function queries the given CDDB server for the existence of the disc's data and
|
||||
@ -339,8 +345,7 @@ CDDBQuery::ReadFromServer(BString &data)
|
||||
query << "cddb query " << idString << ' ' << fTrackCount << ' '
|
||||
<< fFrameOffsetString << ' ' << fDiscLength << '\n';
|
||||
|
||||
if (fLog)
|
||||
printf(">%s", query.String());
|
||||
STRACE((">%s", query.String()));
|
||||
|
||||
ThrowIfNotSize( fSocket.Send(query.String(), query.Length()) );
|
||||
|
||||
@ -378,8 +383,10 @@ CDDBQuery::ReadFromServer(BString &data)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: %s\n",tmp.String());
|
||||
return;
|
||||
// We get here for any time the CDDB server does not recognize the CD, amongst other things
|
||||
STRACE(("CDDB lookup error: %s\n",tmp.String()));
|
||||
fCategory = "misc";
|
||||
return B_NAME_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -404,6 +411,8 @@ CDDBQuery::ReadFromServer(BString &data)
|
||||
|
||||
data << tmp << '\n';
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
void
|
||||
@ -447,8 +456,7 @@ CDDBQuery::ReadLine(BString &buffer)
|
||||
if (ch == '\n')
|
||||
break;
|
||||
}
|
||||
if (fLog)
|
||||
printf("<%s\n", buffer.String());
|
||||
STRACE(("<%s\n", buffer.String()));
|
||||
}
|
||||
|
||||
void
|
||||
@ -465,8 +473,7 @@ CDDBQuery::IdentifySelf()
|
||||
BString tmp;
|
||||
tmp << "cddb hello " << username << " " << hostname << " Haiku_CD_Player v1.0\n";
|
||||
|
||||
if (fLog)
|
||||
printf(">%s", tmp.String());
|
||||
STRACE((">%s", tmp.String()));
|
||||
ThrowIfNotSize( fSocket.Send(tmp.String(), tmp.Length()) );
|
||||
|
||||
ReadLine(tmp);
|
||||
@ -564,6 +571,7 @@ CDDBQuery::QueryThread(void *owner)
|
||||
// new content file, read it in from the server
|
||||
Connector connection(query);
|
||||
BString data;
|
||||
|
||||
query->ReadFromServer(data);
|
||||
query->ParseData(data);
|
||||
query->WriteFile();
|
||||
@ -594,6 +602,9 @@ CDDBQuery::WriteFile(void)
|
||||
BString filename(path.Path());
|
||||
filename << "/" << fArtist << " - " << fTitle;
|
||||
|
||||
if(filename.Compare("Artist")==0)
|
||||
filename << "." << fDiscID;
|
||||
|
||||
BFile file(filename.String(), B_READ_WRITE | B_CREATE_FILE | B_FAIL_IF_EXISTS);
|
||||
if(file.InitCheck() != B_OK)
|
||||
return;
|
||||
@ -629,12 +640,34 @@ CDDBQuery::WriteFile(void)
|
||||
void
|
||||
CDDBQuery::ParseData(const BString &data)
|
||||
{
|
||||
fTitle = "";
|
||||
fTrackNames.clear();
|
||||
|
||||
if(data.CountChars()<1)
|
||||
{
|
||||
// This case occurs when the CDDB lookup fails. On these occasions, we need to generate
|
||||
// the file ourselves. This is actually pretty easy.
|
||||
fArtist = "Artist";
|
||||
fTitle = "Audio CD";
|
||||
fCategory = "misc";
|
||||
|
||||
for(int32 i=0; i<fTrackCount; i++)
|
||||
{
|
||||
BString trackname("Track ");
|
||||
|
||||
if(i<9)
|
||||
trackname << "0";
|
||||
|
||||
trackname << i+1;
|
||||
fTrackNames.push_back(trackname.String());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO: This function is dog slow, but it works. Optimize.
|
||||
|
||||
// Ideally, the search should be done sequentially using GetLineFromString() and strchr().
|
||||
// Order: genre(category), frame offsets, disc length, artist/album, track titles
|
||||
fTitle = "";
|
||||
fTrackNames.clear();
|
||||
|
||||
int32 pos;
|
||||
|
||||
|
@ -12,8 +12,7 @@
|
||||
class CDDBQuery
|
||||
{
|
||||
public:
|
||||
CDDBQuery(const char *server, int32 port = 888,
|
||||
bool log = false);
|
||||
CDDBQuery(const char *server, int32 port = 888);
|
||||
~CDDBQuery(void);
|
||||
void SetToSite(const char *server, int32 port);
|
||||
void GetSites(bool (*)(const char *site, int port,
|
||||
@ -80,7 +79,7 @@ private:
|
||||
|
||||
bool OpenContentFile(const int32 &discID);
|
||||
|
||||
void ReadFromServer(BString &data);
|
||||
status_t ReadFromServer(BString &data);
|
||||
void ParseData(const BString &data);
|
||||
void WriteFile(void);
|
||||
|
||||
@ -90,8 +89,6 @@ private:
|
||||
|
||||
const char * GetToken(const char *, BString &);
|
||||
|
||||
bool fLog;
|
||||
|
||||
// state data
|
||||
BString fServerName;
|
||||
BNetEndpoint fSocket;
|
||||
|
@ -73,9 +73,19 @@ PlayState::UpdateState(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
sPlayList.SetTrackCount(gCDDevice.CountTracks());
|
||||
sPlayList.SetStartingTrack(gCDDevice.GetTrack());
|
||||
return CurrentState(kPlaying);
|
||||
int16 count = gCDDevice.CountTracks();
|
||||
if(count != sPlayList.TrackCount())
|
||||
sPlayList.SetTrackCount(count);
|
||||
|
||||
// TODO: Is this correct?
|
||||
|
||||
/*
|
||||
int16 start = gCDDevice.GetTrack();
|
||||
if(start != sPlayList.StartingTrack())
|
||||
sPlayList.SetStartingTrack(start);
|
||||
*/
|
||||
|
||||
return CurrentState(kStopped);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +137,6 @@ TrackState::UpdateState()
|
||||
// It's possible that the state of the cd drive was changed by outside means
|
||||
// As a result, we want to make sure this hasn't happened. If it has, then we
|
||||
// need to update the playlist's position.
|
||||
|
||||
int16 cdTrack, count;
|
||||
|
||||
if(gCDDevice.GetState() == kPlaying)
|
||||
@ -239,7 +248,7 @@ TimeState::GetTotalTrackTime(int32 &minutes, int32 &seconds) const
|
||||
|
||||
|
||||
CDContentWatcher::CDContentWatcher(void)
|
||||
: cddbQuery("us.freedb.org", 888, true),
|
||||
: cddbQuery("us.freedb.org", 888),
|
||||
discID(-1)
|
||||
{
|
||||
}
|
||||
@ -488,6 +497,12 @@ CDEngine::ToggleShuffle(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CDEngine::IsShuffled(void)
|
||||
{
|
||||
return sPlayList.IsShuffled();
|
||||
}
|
||||
|
||||
void
|
||||
CDEngine::ToggleRepeat(void)
|
||||
{
|
||||
@ -497,6 +512,11 @@ CDEngine::ToggleRepeat(void)
|
||||
sPlayList.SetLoop(true);
|
||||
}
|
||||
|
||||
bool
|
||||
CDEngine::IsRepeated(void)
|
||||
{
|
||||
return sPlayList.IsLoop();
|
||||
}
|
||||
|
||||
void
|
||||
CDEngine::DoPulse()
|
||||
|
@ -163,8 +163,11 @@ public:
|
||||
void SetVolume(uint8 value);
|
||||
|
||||
void ToggleShuffle(void);
|
||||
bool IsShuffled(void);
|
||||
|
||||
void ToggleRepeat(void);
|
||||
|
||||
bool IsRepeated(void);
|
||||
|
||||
CDState GetState(void) const { return fEngineState; }
|
||||
|
||||
// to find the current Track, you may call the GetTrack function
|
||||
|
@ -294,7 +294,6 @@ CDPlayer::MessageReceived(BMessage *msg)
|
||||
|
||||
case M_FFWD:
|
||||
{
|
||||
// TODO: Implement
|
||||
if(fFastFwd->Value() == B_CONTROL_ON)
|
||||
engine->StartSkippingForward();
|
||||
else
|
||||
@ -303,7 +302,6 @@ CDPlayer::MessageReceived(BMessage *msg)
|
||||
}
|
||||
case M_REWIND:
|
||||
{
|
||||
// TODO: Implement
|
||||
if(fRewind->Value() == B_CONTROL_ON)
|
||||
engine->StartSkippingBackward();
|
||||
else
|
||||
@ -319,11 +317,30 @@ CDPlayer::MessageReceived(BMessage *msg)
|
||||
case M_SHUFFLE:
|
||||
{
|
||||
engine->ToggleShuffle();
|
||||
|
||||
if(engine->IsShuffled() && fShuffle->GetState()==0)
|
||||
{
|
||||
fShuffle->SetState(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fShuffle->GetState()==1)
|
||||
fShuffle->SetState(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case M_REPEAT:
|
||||
{
|
||||
engine->ToggleRepeat();
|
||||
if(engine->IsRepeated() && fRepeat->GetState()==0)
|
||||
{
|
||||
fRepeat->SetState(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fRepeat->GetState()==1)
|
||||
fRepeat->SetState(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -363,6 +380,7 @@ CDPlayer::NoticeChange(Notifier *notifier)
|
||||
else
|
||||
if(trs)
|
||||
{
|
||||
|
||||
if(fTrackMenu->CountItems() != engine->TrackStateWatcher()->GetNumTracks())
|
||||
fTrackMenu->SetItemCount(engine->TrackStateWatcher()->GetNumTracks());
|
||||
|
||||
|
@ -3,6 +3,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define DEBUG_PLAYLIST
|
||||
|
||||
#ifdef DEBUG_PLAYLIST
|
||||
#include <stdio.h>
|
||||
#define STRACE(x) printf x
|
||||
#else
|
||||
#define STRACE(x) /* nothing */
|
||||
#endif
|
||||
|
||||
PlayList::PlayList(int16 count, int16 start)
|
||||
: fTrackCount(count),
|
||||
fTrackIndex(0),
|
||||
@ -10,6 +19,8 @@ PlayList::PlayList(int16 count, int16 start)
|
||||
fRandom(false),
|
||||
fLoop(false)
|
||||
{
|
||||
STRACE(("PlayList(count=%d,start=%d)\n",count,start));
|
||||
|
||||
srand(real_time_clock_usecs());
|
||||
|
||||
if(fTrackCount < 0)
|
||||
@ -25,6 +36,7 @@ PlayList::PlayList(int16 count, int16 start)
|
||||
fStartingTrack = 1;
|
||||
|
||||
memset(fTrackList,-1,500);
|
||||
|
||||
Unrandomize();
|
||||
}
|
||||
|
||||
@ -33,6 +45,8 @@ PlayList::SetTrackCount(const int16 &count)
|
||||
{
|
||||
fLocker.Lock();
|
||||
|
||||
STRACE(("PlayList::SetTrackCount(%d)\n",count));
|
||||
|
||||
if(count < 0)
|
||||
fTrackCount = 0;
|
||||
else
|
||||
@ -52,6 +66,8 @@ PlayList::SetStartingTrack(const int16 &start)
|
||||
{
|
||||
fLocker.Lock();
|
||||
|
||||
STRACE(("PlayList::SetStartingTrack(%d)\n",start));
|
||||
|
||||
if(start >= TrackCount())
|
||||
fStartingTrack = TrackCount() - 1;
|
||||
else
|
||||
@ -66,6 +82,7 @@ PlayList::SetStartingTrack(const int16 &start)
|
||||
void
|
||||
PlayList::Rewind(void)
|
||||
{
|
||||
STRACE(("PlayList::Rewind()\n"));
|
||||
fLocker.Lock();
|
||||
|
||||
fTrackIndex = 0;
|
||||
@ -76,6 +93,7 @@ PlayList::Rewind(void)
|
||||
void
|
||||
PlayList::SetShuffle(const bool &random)
|
||||
{
|
||||
STRACE(("PlayList::SetShuffle(%s)\n",random ? "random" : "sequential"));
|
||||
fLocker.Lock();
|
||||
|
||||
if(random)
|
||||
@ -91,6 +109,7 @@ PlayList::SetShuffle(const bool &random)
|
||||
void
|
||||
PlayList::SetLoop(const bool &loop)
|
||||
{
|
||||
STRACE(("PlayList::SetLoop(%s)\n",loop ? "loop" : "non-loop"));
|
||||
fLocker.Lock();
|
||||
|
||||
fLoop = loop;
|
||||
@ -101,6 +120,8 @@ PlayList::SetLoop(const bool &loop)
|
||||
void
|
||||
PlayList::SetCurrentTrack(const int16 &track)
|
||||
{
|
||||
STRACE(("PlayList::SetCurrentTrack(%d)\n",track));
|
||||
|
||||
if(track < 0 || track > fTrackCount)
|
||||
return;
|
||||
|
||||
@ -124,6 +145,7 @@ PlayList::GetCurrentTrack(void)
|
||||
fLocker.Lock();
|
||||
|
||||
int16 value = fTrackList[fTrackIndex];
|
||||
STRACE(("PlayList::GetCurrentTrack()=%d\n",value));
|
||||
|
||||
fLocker.Unlock();
|
||||
return value;
|
||||
@ -137,6 +159,7 @@ PlayList::GetNextTrack(void)
|
||||
if(fTrackCount < 1)
|
||||
{
|
||||
fLocker.Unlock();
|
||||
STRACE(("PlayList::GetNextTrack()=-1 (no tracks)\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -147,6 +170,7 @@ PlayList::GetNextTrack(void)
|
||||
else
|
||||
{
|
||||
fLocker.Unlock();
|
||||
STRACE(("PlayList::GetNextTrack()=-1 (track index out of range)\n"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -154,6 +178,8 @@ PlayList::GetNextTrack(void)
|
||||
fTrackIndex++;
|
||||
|
||||
int16 value = fTrackList[fTrackIndex];
|
||||
STRACE(("PlayList::GetNextTrack()=%d\n",value));
|
||||
|
||||
fLocker.Unlock();
|
||||
return value;
|
||||
}
|
||||
@ -166,6 +192,7 @@ PlayList::GetPreviousTrack(void)
|
||||
if(fTrackCount < 1)
|
||||
{
|
||||
fLocker.Unlock();
|
||||
STRACE(("PlayList::GetPreviousTrack()=-1 (no tracks)\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -176,6 +203,7 @@ PlayList::GetPreviousTrack(void)
|
||||
else
|
||||
{
|
||||
fLocker.Unlock();
|
||||
STRACE(("PlayList::GetPreviousTrack()=-1 (track index out of range)\n"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -183,6 +211,7 @@ PlayList::GetPreviousTrack(void)
|
||||
fTrackIndex--;
|
||||
|
||||
int16 value = fTrackList[fTrackIndex];
|
||||
STRACE(("PlayList::GetPreviousTrack()=%d\n",value));
|
||||
fLocker.Unlock();
|
||||
return value;
|
||||
}
|
||||
@ -195,11 +224,13 @@ PlayList::GetLastTrack(void)
|
||||
if(fTrackCount < 1)
|
||||
{
|
||||
fLocker.Unlock();
|
||||
STRACE(("PlayList::GetLastTrack()=-1 (no tracks)\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
fTrackIndex = fTrackCount - 1;
|
||||
int16 value = fTrackList[fTrackIndex];
|
||||
STRACE(("PlayList::GetLastTrack()=%d\n",value));
|
||||
fLocker.Unlock();
|
||||
return value;
|
||||
}
|
||||
@ -212,12 +243,13 @@ PlayList::GetFirstTrack(void)
|
||||
if(fTrackCount < 1)
|
||||
{
|
||||
fLocker.Unlock();
|
||||
STRACE(("PlayList::GetFirstTrack()=-1 (no tracks)\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
fTrackIndex = 0;
|
||||
int16 value = fTrackList[fTrackIndex];
|
||||
|
||||
STRACE(("PlayList::GetFirstTrack()=%d\n",value));
|
||||
fLocker.Unlock();
|
||||
return value;
|
||||
}
|
||||
@ -225,6 +257,8 @@ PlayList::GetFirstTrack(void)
|
||||
void
|
||||
PlayList::Randomize(void)
|
||||
{
|
||||
STRACE(("PlayList::Randomize()\n"));
|
||||
|
||||
// Reinitialize the count
|
||||
for(int16 i=fStartingTrack; i<=fTrackCount; i++)
|
||||
fTrackList[i - fStartingTrack] = i;
|
||||
@ -249,11 +283,17 @@ PlayList::Randomize(void)
|
||||
fTrackList[first] = fTrackList[second];
|
||||
fTrackList[second] = temp;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PLAYLIST
|
||||
for(int16 i=fStartingTrack; i<=fTrackCount; i++)
|
||||
printf("\tSlot %d: track %d\n",i,fTrackList[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
PlayList::Unrandomize(void)
|
||||
{
|
||||
STRACE(("PlayList::Unrandomize()\n"));
|
||||
for(int16 i=fStartingTrack; i<=fTrackCount; i++)
|
||||
fTrackList[i - fStartingTrack] = i;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user