📄 song_task.c
字号:
{
song_start(); /* start playing song */
disp_clock_start(); /* start clock timer */
print_state_play(); /* display play icon */
song_state = SONG_PLAY;
}
break;
}
case SONG_PLAY:
{
if (Feof() == TRUE)
{ /* end of file reached */
song_stop(); /* stop playing song */
Fclose();
loop = song_loop;
song_state = SONG_NEXT;
gl_key_press = FALSE; /* no key usage */
}
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_PAUSE:
Aud_song_pause(); /* suspend sample request */
disp_clock_stop(); /* suspend clock timer */
print_state_pause(); /* display pause icon */
song_state = SONG_PAUSE;
break;
case KEY_NEXT:
song_pause(); /* pause playing song */
disp_clock_stop(); /* suspend clock timer */
Fclose();
loop = TRUE; /* keypad action so loop */
song_state = SONG_NEXT;
break;
case KEY_PREV:
song_pause(); /* pause playing song */
disp_clock_stop(); /* suspend clock timer */
Fclose();
loop = TRUE;
song_state = SONG_PREV;
break;
case KEY_INC:
song_snd_inc(); /* increment selected control */
print_sound_level(); /* display new level */
break;
case KEY_DEC:
song_snd_dec(); /* decrement selected control */
print_sound_level(); /* display new level */
break;
case KEY_SOUND:
song_snd_select(); /* select next sound control */
print_sound(); /* display selected sound icon */
print_sound_level(); /* display new level */
break;
case KEY_REPEAT:
song_loop = ~song_loop; /* display repeat or not */
print_repeat(song_loop);
break;
case KEY_STOP:
song_stop(); /* stop playing song */
Fclose();
song_state = SONG_STOP;
break;
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
break;
}
case SONG_PAUSE: /* one file openned */
{
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_PLAY:
disp_clock_start(); /* restart clock timer */
Aud_song_play(); /* restart sample request */
print_state_play(); /* display play icon */
song_state = SONG_PLAY;
break;
case KEY_NEXT:
song_pause(); /* pause playing song */
Fclose();
loop = TRUE; /* keypad action so loop */
song_state = SONG_NEXT;
break;
case KEY_PREV:
song_pause(); /* pause playing song */
Fclose();
loop = TRUE; /* keypad action so loop */
song_state = SONG_PREV;
break;
case KEY_INC:
song_snd_inc(); /* increment selected control */
print_sound_level(); /* display new level */
break;
case KEY_DEC:
song_snd_dec(); /* decrement selected control */
print_sound_level(); /* display new level */
break;
case KEY_SOUND:
song_snd_select(); /* select next sound control */
print_sound(); /* display selected sound icon */
print_sound_level(); /* display new level */
break;
case KEY_REPEAT:
song_loop = ~song_loop; /* display repeat or not */
print_repeat(song_loop);
break;
case KEY_STOP:
song_stop(); /* stop playing song */
Fclose();
song_state = SONG_STOP;
break;
default:
break;
}
gl_key_press = FALSE; /* ack key usage */
}
break;
}
case SONG_NEW:
{
#if PLAYER_PLAY_MODE == PLAY_DISK
if (File_type() == FILE_DIR)
{
if (file_entry_dir(FILE_MP3 | FILE_DIR) == OK)
{ /* mp3 or dir in sub-dir */
song_state = SONG_NEW; /* stay in same state */
}
else
{ /* no mp3 or dir in sub-dir */
song_state = SONG_NEXT; /* select next */
}
}
else
{ /* file is MP3 */
song_state = SONG_INIT; /* new song */
print_repeat(song_loop);
print_file_name(); /* display file name */
}
break;
#else /* PLAYER_MODE == PLAY_DIR */
song_state = SONG_INIT; /* new song */
print_repeat(song_loop);
print_file_name(); /* display file name */
break;
#endif
}
case SONG_NEXT:
{
disp_name_stop(); /* stop scrolling */
#if PLAYER_PLAY_MODE == PLAY_DISK
if (file_seek_next(FILE_MP3 | FILE_DIR, FALSE))/* next song or dir */
{ /* mp3 or dir selected */
song_state = SONG_NEW;
}
else
{ /* at end of dir */
if (File_goto_parent(FILE_MP3 | FILE_DIR) == OK)
{ /* parent exists, point on dir */
song_state = SONG_NEXT; /* next will select next file */
}
else
{ /* no parent: end of root dir */
if (loop)
{
song_state = SONG_NEW;
}
else
{
song_stop();
song_state = SONG_STOP;
}
}
}
break;
#else /* PLAYER_MODE == PLAY_DIR */
if (file_seek_next(FILE_MP3, loop)) /* select next song */
{ /* still some file to play */
song_state = SONG_NEW;
}
else
{ /* end of dir: stop */
song_stop();
song_state = SONG_STOP;
}
break;
#endif
}
case SONG_PREV:
{
disp_name_stop(); /* stop scrolling */
#if PLAYER_PLAY_MODE == PLAY_DISK
while( song_state == SONG_PREV )
{ /* prev song or dir */
if( !file_seek_prev(FILE_MP3 | FILE_DIR, FALSE))
{ /* No mp3 or dir selected, at beginning of dir */
if (File_goto_parent(FILE_MP3 | FILE_DIR) != OK)
{ /* no parent: beginning of root dir */
if (loop)
{
if(File_goto_last() != OK) /* goto to the end of dir */
{ /* error system */
song_stop();
song_state = SONG_STOP;
}
}
else
{ /* end of dir: stop */
song_stop();
song_state = SONG_STOP;
}
}
else
{
continue; /* goto to previous file in dir parent */
}
}
while (File_type() == FILE_DIR)
{ /* file found is directory -> enter directory and goto last file */
if (file_entry_dir(FILE_MP3 | FILE_DIR) == OK)
{ /* mp3 or dir in sub-dir */
if(File_goto_last() != OK) /* goto to the end of dir */
{ /* error system */
song_stop();
song_state = SONG_STOP;
}
}
else
{
break; /* directory empty goto search previous file */
}
}
if (File_type() == FILE_MP3)
{ /* mp3 file -> stop research previous file */
song_state = SONG_NEW;
}
/* HERE song_state == SONG_PREV, if select file is empty directory or not mp3 file */
}
break;
#else /* PLAYER_MODE == PLAY_DIR */
if (file_seek_prev(FILE_MP3, loop)) /* select prev song */
{ /* still some file to play */
song_state = SONG_NEW;
}
else
{ /* beginning of dir: stop */
song_stop();
song_state = SONG_STOP;
}
break;
#endif
}
case SONG_STOP:
{
disp_end_of_play(); /* end of music... */
disp_clock_reset(); /* reset clock timer */
print_file_name(); /* display file name */
song_state = SONG_IDLE;
break;
}
case SONG_NO_SONG:
{
if (gl_key_press) /* a key is pressed? */
{
switch (gl_key)
{
case KEY_MEM:
mem_select_next(); /* select next memory */
song_state = SONG_START;
break;
case KEY_MODE:
mode_set_init(); /* exit from song task */
song_state = SONG_START;
break;
}
gl_key_press = FALSE; /* ack key usage */
}
else
{ /* check card presence */
if (mem_check_card() == KO)
{
mem_select_next();
song_state = SONG_START; /* card has been unplugged */
}
}
break;
}
case SONG_ERROR:
{
song_stop(); /* stop playing song */
Fclose(); /* close opened file */
disp_clock_reset(); /* reset clock timer */
print_state_error(); /* display error icon */
disp_name_stop();
song_state = SONG_IDLE;
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -