Exemple #1
0
static void
cd_get_tracks (cdda_t *cd, cddb_disc_t *disc)
{
    cddb_track_t *track;
    int i = 0;

    if (!cd || !disc)
        return;

    for (track = cddb_disc_get_track_first (disc); track;
         track = cddb_disc_get_track_next (disc))
    {
        char name[128];
        int length;

        length = cddb_track_get_length (track);
        snprintf (name, 128, "%02d. %s (%02d:%02d)",
                  cddb_track_get_number (track),
                  cddb_track_get_title (track),
                  (length / 60), (length % 60));

        cd->tracks[i]->name = strdup (name);
        i++;
    }
}
static CdAlbum toAlbum(cddb_disc_t *disc, const CdAlbum &initial=CdAlbum())
{
    CdAlbum album;
    if (!disc) {
        return album;
    }
    album.name=QString::fromUtf8(cddb_disc_get_title(disc));
    album.artist=QString::fromUtf8(cddb_disc_get_artist(disc));
    album.genre=QString::fromUtf8(cddb_disc_get_genre(disc));
    album.year=cddb_disc_get_year(disc);
    int numTracks=cddb_disc_get_track_count(disc);
    if (numTracks>0) {
        for (int t=0; t<numTracks; ++t) {
            cddb_track_t *trk=cddb_disc_get_track(disc, t);
            if (!trk) {
                continue;
            }

            Song track;
            track.track=cddb_track_get_number(trk);
            track.title=QString::fromUtf8(cddb_track_get_title(trk));
            track.artist=QString::fromUtf8(cddb_track_get_artist(trk));
            track.albumartist=album.artist;
            track.album=album.name;
            track.id=track.track;
            track.file=QString("%1.wav").arg(track.track);
            track.year=album.year;

            if (initial.isNull()) {
                track.time=cddb_track_get_length(trk);
                if (CddbInterface::dataTrack()==track.title) {
                    // Adjust last track length...
                    if (album.tracks.count()) {
                        Song last=album.tracks.takeLast();
                        last.time-=FRAMES_TO_SECONDS(11400);
                        album.tracks.append(last);
                    }
                } else {
                    album.tracks.append(track);
                }
            } else if (t>=initial.tracks.count()) {
                break;
            } else {
                track.time=initial.tracks.at(t).time;
                album.tracks.append(track);
            }
        }
    }

    // Ensure we always have same number of tracks...
    if (!initial.isNull() && album.tracks.count()<initial.tracks.count()) {
        for (int i=album.tracks.count(); i<initial.tracks.count(); ++i) {
            album.tracks.append(initial.tracks.at(i));
        }
    }
    return album;
}