Beispiel #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;
}
Beispiel #2
0
SongList Library::FilterCurrentWMASong(SongList songs, Song* queued) {
  for (SongList::iterator it = songs.begin(); it != songs.end();) {
    if (it->url() == current_wma_song_url_) {
      *queued = *it;
      it = songs.erase(it);
    } else {
      ++it;
    }
  }
  return songs;
}
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 );
	}	
}
int main( int argc, char *argv[] )
{
	// Init fmod
	if (!FSOUND_Init( 44100, 32, 0 ))
	{
		printf("FSound init failed\n" );
	}

	//FSOUND_SetOutput( FSOUND_OUTPUT_WINMM );
	sfx_cowbell = FSOUND_Sample_Load( FSOUND_UNMANAGED, "gamedata/cowbell.wav", FSOUND_NORMAL, 0, 0 );
	sfx_doh = FSOUND_Sample_Load( FSOUND_UNMANAGED, "gamedata/sfxr_doh.wav", FSOUND_NORMAL, 0, 0 );

	srand( time(NULL) );

	// Initialize SDL
	if (SDL_Init( SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO ) < 0 ) 
	{
		fprintf( stderr, "Unable to init SDL: %s\n", SDL_GetError() );
	}

	if (SDL_SetVideoMode( 800, 600, 32, SDL_OPENGL /*| SDL_FULLSCREEN */ ) == 0 ) 
	{
		fprintf(stderr,	"Unable to set video mode: %s\n", SDL_GetError());
        exit(1);
	}

	SDL_WM_SetCaption( "LD11 Focus", NULL );

	// initialize DevIL
	ilInit();
	ilutRenderer( ILUT_OPENGL );

	// Load the song DB
	LoadSongList( songs );
	
	for (SongList::iterator ca = songs.begin(); ca != songs.end(); ++ca )
	{
		printf( ">> %s\n", (*ca).first.c_str() );	
		artistNames.push_back( (*ca).first );
	}	

	// Main Loop
	Uint32 ticks = SDL_GetTicks(), ticks_elapsed, sim_ticks = 0;
	bool beat_sample = false;
	bool done = false;

	world = new World();

	Beatronome nome;

	while(!done)
	{
		SDL_Event event;

		while (SDL_PollEvent( &event ) ) 
		{
			switch (event.type )
			{
				case SDL_KEYDOWN:

					// global keys
					//if (event.key.keysym.sym == SDLK_ESCAPE)
					//{
					//	done = true;
					//}

					if (mode == MODE_TITLE)
					{
						switch( event.key.keysym.sym ) 
						{						
							case SDLK_DOWN:
								menuNdx++;
								if (menuItem[menuNdx] == NULL)
								{
									menuNdx = 0;
								}
								break;

							case SDLK_UP:
								if (menuNdx==0)
								{
									while (menuItem[menuNdx+1]) menuNdx++;
								}
								else
								{
									menuNdx--;
								}
								break;

							case SDLK_RETURN:
							case SDLK_SPACE:

								// bail 
								if (artistNames.size() == 0)
								{
									done = 1;
									break;
								}

								if (!strcmp( menuItem[menuNdx], "Quit" ))
								{
									done = true;
								}								
								else if (!strcmp( menuItem[menuNdx], "Start Game" ))
								{
									if ( (currSong == "RANDOM") || 
										  (currArtist == "RANDOM" ) )
									{
										ChooseRandomSong();
									}
									mode = MODE_GAME;

									// Start playing									
									world->setMusic( currFullPath.c_str() );
										//(string("\"") + currFullPath.c_str() + "\"").c_str() );
									world->playMusic();
									nome.beat_count = 0;
									nome.beat_subcount = 0;
								}
								else if (!strcmp( menuItem[menuNdx], "Choose Song" ))
								{
									mode = MODE_PICKSONG;
								}
								else if (!strcmp( menuItem[menuNdx], "Random Song" ))
								{
									ChooseRandomSong();								
								}
								else if (!strcmp( menuItem[menuNdx], "Difficulty" ))
								{
									nome.easy_mode = !nome.easy_mode;
								}
								break;
							case SDLK_c:
								printf("test cowbell\n" );
								
								FSOUND_PlaySound(FSOUND_FREE, sfx_cowbell );

								break;
							
							case SDLK_ESCAPE:
								done = true;
								break;
							}
						}					
						else if ( mode == MODE_GAME )
						{
							switch( event.key.keysym.sym ) 
							{		
								case SDLK_ESCAPE:
									world->stopMusic();
									mode = MODE_TITLE;
									break;

								case SDLK_LSHIFT:
								case SDLK_RSHIFT:								
									beat_sample = true;
									break;

								case SDLK_c:
								case SDLK_SPACE:
								case SDLK_LALT:
								case SDLK_RALT:
									printf("cowbell\n" );						
									moarCowbell(nome);
									//FSOUND_PlaySound(FSOUND_FREE, sfx_cowbell );
									break;

								case SDLK_r:
									printf("test restart\n" );		
									nome.beat_count = 0;
									nome.beat_subcount = 0;
									break;
							}
						}
						else if (mode == MODE_PICKSONG)
						{
							switch( event.key.keysym.sym ) 
							{
								case SDLK_LEFT:
								case SDLK_RIGHT:
									pickMode = !pickMode;
									break;

								case SDLK_RETURN:
									mode = MODE_TITLE;
									currSong = songNames[currSongNdx];
									currFullPath = songPath[currSongNdx];
									currArtist = artistNames[currArtistNdx];									
									break;								
							}


							if (pickMode == PICK_ARTIST)
							{
								switch( event.key.keysym.sym ) 
								{								
									case SDLK_DOWN:
										currArtistNdx++;
										if (	currArtistNdx == artistNames.size())
										{
											currArtistNdx = 0;
										}
										GetSongNamesForCurrentArtist();
										break;

									case SDLK_UP:
										if (currArtistNdx == 0)
										{
											currArtistNdx = artistNames.size() - 1 ;
										}
										else currArtistNdx--;

										GetSongNamesForCurrentArtist();
										break;
									case SDLK_PAGEUP:
										currArtistNdx = (currArtistNdx - 15) % (artistNames.size()-1);
										GetSongNamesForCurrentArtist();
										break;
									case SDLK_PAGEDOWN:
										currArtistNdx = (currArtistNdx + 15) % (artistNames.size()-1);
										GetSongNamesForCurrentArtist();
										break;									
								}							
							}
							else if (songNames.size() > 0 )
							{

								switch( event.key.keysym.sym ) 
								{								
									case SDLK_DOWN:
										currSongNdx++;
										if (currSongNdx == songNames.size())
										{
											currSongNdx = 0;
										}										
										break;

									case SDLK_UP:
										if (currSongNdx == 0)
										{
											currSongNdx = songNames.size() - 1 ;
										}
										else currSongNdx--;
										break;
									case SDLK_PAGEUP:
										currSongNdx = (currSongNdx - 15) % (songNames.size()-1);
										GetSongNamesForCurrentArtist();
										break;
									case SDLK_PAGEDOWN:
										currSongNdx = (currSongNdx + 15) % (songNames.size()-1);
										GetSongNamesForCurrentArtist();
										break;
									
								}							
							}
						}
						break;
				case SDL_QUIT:
					done = true;
					break;
			}
		}

		// Timing
		ticks_elapsed = SDL_GetTicks() - ticks;
		ticks += ticks_elapsed;

		// update beat counter
		if (beat_sample) 
		{
			nome.beat_sample( ticks );
			beat_sample = false;
		}

		// update beat
		nome.beat_update( ticks_elapsed );

		// fixed sim update
		sim_ticks += ticks_elapsed;
		while (sim_ticks > STEPTIME) 
		{
			sim_ticks -= STEPTIME;			
			//update();

//			printf("update sim_ticks %d ticks_elapsed %d\n", sim_ticks, ticks_elapsed );

			nome.beat_sim_update();
			world->update( nome );

			//if (beat_trigger) beat_trigger = false;
		}	

		// update the graphics as often as possible
		redraw( nome );
		SDL_GL_SwapBuffers();
	}

	SDL_Quit();

	return 0;
}