示例#1
0
void
CDDBQuery::_SetDefaultInfo()
{
	for (int16 i = fCDData.CountTracks(); i >= 0; i--)
		fCDData.RemoveTrack(i);

	vector<CDAudioTime> trackTimes;
	GetTrackTimes(&fSCSIData, trackTimes);
	int32 trackCount = GetTrackCount(&fSCSIData);

	fCDData.SetArtist("Artist");
	fCDData.SetAlbum("Audio CD");
	fCDData.SetGenre("Misc");

	for (int32 i = 0; i < trackCount; i++) {
		BString trackname("Track ");

		if (i < 9)
			trackname << "0";

		trackname << i + 1;

		CDAudioTime time = trackTimes[i + 1] - trackTimes[i];
		fCDData.AddTrack(trackname.String(), time);
	}
}			
status_t
CDDBQuery::_OpenContentFile(const int32 &discID)
{
	// Makes sure that the lookup has a valid file to work with for the CD
	// content. Returns true if there is an existing file, false if a lookup is
	// required.

	BFile file;
	BString predicate;
	predicate << "CD:key == " << discID;
	entry_ref ref;

	BVolumeRoster roster;
	BVolume volume;
	roster.Rewind();
	while (roster.GetNextVolume(&volume) == B_OK) {
		if (volume.IsReadOnly() || !volume.IsPersistent() || !volume.KnowsAttr()
			|| !volume.KnowsQuery())
			continue;

		// make sure the volume we are looking at is indexed right
		fs_create_index(volume.Device(), "CD:key", B_INT32_TYPE, 0);

		BQuery query;
		query.SetVolume(&volume);
		query.SetPredicate(predicate.String());
		if (query.Fetch() != B_OK)
			continue;

		if (query.GetNextRef(&ref) == B_OK) 
			break;
	}

	status_t status = fCDData.Load(ref);
	if (status == B_NO_INIT) {
		// We receive this error when the Load() function couldn't load the
		// track times This just means that we get it from the SCSI data given
		// to us in SetToCD
		vector<CDAudioTime> times;
		GetTrackTimes(&fSCSIData,times);

		for (int32 i = 0; i < fCDData.CountTracks(); i++) {
			CDAudioTime *item = fCDData.TrackTimeAt(i);
			*item = times[i + 1] - times[i];
		}

		status = B_OK;
	}

	return status;
}
示例#3
0
void
CDDBQuery::_ParseData(const BString &data)
{
	// Can't simply call MakeEmpty() because the thread is spawned when the discID kept in fCDData
	// is not the same as what's in the drive and MakeEmpty invalidates *everything* in the object.
	// Considering that we reassign everything here, simply emptying the track list should be sufficient
	for (int16 i = fCDData.CountTracks(); i >= 0; i--)
		fCDData.RemoveTrack(i);

	vector<CDAudioTime> trackTimes;
	GetTrackTimes(&fSCSIData,trackTimes);
	int32 trackCount = GetTrackCount(&fSCSIData);

	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.
		fCDData.SetArtist("Artist");
		fCDData.SetAlbum("Audio CD");
		fCDData.SetGenre("Misc");

		for (int32 i = 0; i < trackCount; i++) 	{
			BString trackname("Track ");

			if (i < 9)
				trackname << "0";

			trackname << i + 1;

			CDAudioTime time = trackTimes[i + 1] - trackTimes[i];
			fCDData.AddTrack(trackname.String(), time);
		}
	}

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

	int32 pos;

	pos = data.FindFirst("DYEAR=");
	if (pos > 0) {
		BString artist,album;
		artist = album = GetLineFromString(data.String() + sizeof("DYEAR") + pos);

		// TODO: finish, once I find an entry which actually has a year in it
		BAlert *alert = new BAlert("SimplyVorbis", "DYEAR entry found\n", "OK");
		alert->Go();
		
	}

	pos = data.FindFirst("DTITLE=");
	if (pos > 0) {
		BString artist,album;
		artist = album = GetLineFromString(data.String() + sizeof("DTITLE") + pos);

		pos = artist.FindFirst(" / ");
		if (pos > 0)
			artist.Truncate(pos);
		fCDData.SetArtist(artist.String());

		album = album.String() + pos + sizeof(" / ") - 1;
		fCDData.SetAlbum(album.String());
	}

	BString category = GetLineFromString(data.String() + 4);
	pos = category.FindFirst(" ");
	if (pos > 0)
		category.Truncate(pos);
	fCDData.SetGenre(category.String());

	pos = data.FindFirst("TTITLE0=");
	if (pos > 0) {
		int32 trackCount = 0;
		BString searchString = "TTITLE0=";

		while (pos > 0) {
			BString trackName = data.String() + pos + searchString.Length();
			trackName.Truncate(trackName.FindFirst("\n"));

			CDAudioTime tracktime = trackTimes[trackCount + 1] - trackTimes[trackCount];
			fCDData.AddTrack(trackName.String(),tracktime);

			trackCount++;
			searchString = "TTITLE";
			searchString << trackCount << "=";
			pos = data.FindFirst(searchString.String(),pos);
		}
	}
}