Exemplo n.º 1
0
size_t LoadSongList( SongList &songs )
{
    size_t count = 0;

    FILE *fp = fopen( "musicdb.txt", "rt" );

    if (!fp) return 0;

    string artist;
    string fullpath;
    string title;
    char line[6144], *ch;

    while (!feof(fp))
    {
        fgets( line, 6144, fp );
        cleanString( line );

        ch = strtok( line, "\t" );
        if (ch) artist = ch;
        else continue;

        ch = strtok( NULL, "\t" );
        if (ch) title = ch;
        else continue;

        ch = strtok( NULL, "\t" );
        if (ch) fullpath = ch;
        else continue;

        printf ("Artist: %s\nTitle: %s\nFullPath: %s\n",
                artist.c_str(),
                title.c_str(),
                fullpath.c_str() + 60 );
        count++;

        SongList::iterator sli;
        sli = songs.find( artist );
        if (sli == songs.end())
        {
            songs[artist] = std::vector<Song>();
            sli = songs.find( artist );

            assert( sli != songs.end() );
        }

        Song s;
        s.filename = fullpath;
        s.title = title;
        (*sli).second.push_back( s );
    }
    fclose(fp);

    return count;
}
void GetSongNamesForCurrentArtist()
{
	string aname = artistNames[currArtistNdx];
	SongList::iterator ai = songs.find( aname );
	if (ai == songs.end() )
	{
		printf("Could not find %s\n", aname.c_str() );
		return;
	}

	std::vector<Song> &asongs = (*ai).second;

	printf("GetSongNamesForCurrentArtist---\n" );
	printf("%d songs... \n", asongs.size() );

	songNames.clear();
	songPath.clear();
	for ( std::vector<Song>::iterator si = asongs.begin();
		  si != asongs.end(); ++si )
	{		
		songNames.push_back( (*si).title );
		songPath.push_back( (*si).filename );
	}	
}