From 843c7efaf8c953fc3bec40a7da0be3a5da9950df Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Mon, 6 Apr 2009 00:39:43 +0000 Subject: FS9795 - some playback cleanup. * Use events to notify things when the track has changed instead of the nasty has_track_changed() * Event for when the mp3entry for the next track is avilable (which allows alot more tags to be static which means less redrawing in the WPS) * virtually guarentee that the mp3entry sturct returned by audio_current/next_track() is going to be valid for the duration of the current track. The only time it wont be now is during the time between the codec finishing the previous track and the next track actually starting (~2s), but this is not an issue as long as it is called again when the TRACK_CHANGED event happens (or just use the pointer that gives) It is still possible to confuse the WPS with the next tracks id3 info being displayed but this should fix itself up faster than it used to (and be harder to do) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20633 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/gwps-common.c | 39 ++++++-------------------------------- apps/gui/gwps.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++---- apps/gui/gwps.h | 1 + apps/gui/wps_parser.c | 44 +++++++++++++++++++++---------------------- 4 files changed, 76 insertions(+), 59 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index f32b002f69..189fc6fa31 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -348,33 +348,8 @@ bool gui_wps_display(struct gui_wps *gwps) bool gui_wps_update(struct gui_wps *gwps) { - bool track_changed = audio_has_changed_track(); struct mp3entry *id3 = gwps->state->id3; - - gwps->state->nid3 = audio_next_track(); - if (track_changed) - { - gwps->state->id3 = id3 = audio_current_track(); - - if (cuesheet_is_enabled() && id3->cuesheet_type - && strcmp(id3->path, curr_cue->audio_filename)) - { - /* the current cuesheet isn't the right one any more */ - /* We need to parse the new cuesheet */ - - char cuepath[MAX_PATH]; - - if (look_for_cuesheet_file(id3->path, cuepath) && - parse_cuesheet(cuepath, curr_cue)) - { - id3->cuesheet_type = 1; - strcpy(curr_cue->audio_filename, id3->path); - } - - cue_spoof_id3(curr_cue, id3); - } - } - + bool retval; if (cuesheet_is_enabled() && id3->cuesheet_type && (id3->elapsed < curr_cue->curr_track->offset || (curr_cue->curr_track_idx < curr_cue->track_count - 1 @@ -382,17 +357,15 @@ bool gui_wps_update(struct gui_wps *gwps) { /* We've changed tracks within the cuesheet : we need to update the ID3 info and refresh the WPS */ - - track_changed = true; + gwps->state->do_full_update = true; cue_find_current_track(curr_cue, id3->elapsed); cue_spoof_id3(curr_cue, id3); } - if (track_changed) - gwps->display->stop_scroll(); - - return gui_wps_redraw(gwps, 0, - track_changed ? WPS_REFRESH_ALL : WPS_REFRESH_NON_STATIC); + retval = gui_wps_redraw(gwps, 0, + gwps->state->do_full_update ? + WPS_REFRESH_ALL : WPS_REFRESH_NON_STATIC); + return retval; } diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c index 32a27212a4..5474b302f0 100644 --- a/apps/gui/gwps.c +++ b/apps/gui/gwps.c @@ -78,6 +78,8 @@ static struct wps_data wps_datas[NB_SCREENS]; /* initial setup of wps_data */ static void wps_state_init(void); +static void track_changed_callback(void *param); +static void nextid3available_callback(void* param); static void change_dir(int direction) { @@ -246,7 +248,7 @@ long gui_wps_show(void) long restoretimer = RESTORE_WPS_INSTANTLY; /* timer to delay screen redraw temporarily */ bool exit = false; bool bookmark = false; - bool update_track = false; + bool update_track = false, partial_update = false; int i; long last_left = 0, last_right = 0; wps_state_init(); @@ -651,7 +653,7 @@ long gui_wps_show(void) restore = true; break; case ACTION_NONE: /* Timeout */ - update_track = true; + partial_update = true; ffwd_rew(button); /* hopefully fix the ffw/rwd bug */ break; #ifdef HAVE_RECORDING @@ -671,13 +673,21 @@ long gui_wps_show(void) break; } - if (update_track) + if (wps_state.do_full_update || partial_update || update_track) { + if (update_track) + { + wps_state.do_full_update = true; + wps_state.id3 = audio_current_track(); + wps_state.nid3 = audio_next_track(); + } FOR_NB_SCREENS(i) { gui_wps_update(&gui_wps[i]); } + wps_state.do_full_update = false; update_track = false; + partial_update = false; } if (restore && wps_state.id3 && @@ -723,7 +733,36 @@ long gui_wps_show(void) return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */ } -/* needs checking if needed end*/ +/* this is called from the playback thread so NO DRAWING! */ +static void track_changed_callback(void *param) +{ + wps_state.id3 = (struct mp3entry*)param; + wps_state.nid3 = audio_next_track(); + + if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type + && strcmp(wps_state.id3->path, curr_cue->audio_filename)) + { + /* the current cuesheet isn't the right one any more */ + /* We need to parse the new cuesheet */ + char cuepath[MAX_PATH]; + + if (look_for_cuesheet_file(wps_state.id3->path, cuepath) && + parse_cuesheet(cuepath, curr_cue)) + { + wps_state.id3->cuesheet_type = 1; + strcpy(curr_cue->audio_filename, wps_state.id3->path); + } + + cue_spoof_id3(curr_cue, wps_state.id3); + } + wps_state.do_full_update = true; +} +static void nextid3available_callback(void* param) +{ + (void)param; + wps_state.nid3 = audio_next_track(); + wps_state.do_full_update = true; +} /* wps_state */ @@ -733,6 +772,10 @@ static void wps_state_init(void) wps_state.paused = false; wps_state.id3 = NULL; wps_state.nid3 = NULL; + wps_state.do_full_update = true; + /* add the WPS track event callbacks */ + add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback); + add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback); } /* wps_state end*/ diff --git a/apps/gui/gwps.h b/apps/gui/gwps.h index 7888c3944c..1042e1a795 100644 --- a/apps/gui/gwps.h +++ b/apps/gui/gwps.h @@ -478,6 +478,7 @@ struct wps_state bool wps_time_countup; struct mp3entry* id3; struct mp3entry* nid3; + bool do_full_update; }; diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c index ba2e2173f1..390df56cbb 100644 --- a/apps/gui/wps_parser.c +++ b/apps/gui/wps_parser.c @@ -215,16 +215,16 @@ static const struct wps_tag all_tags[] = { parse_dir_level }, /* next file */ - { WPS_TOKEN_FILE_BITRATE, "Fb", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_CODEC, "Fc", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_FREQUENCY, "Ff", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_FREQUENCY_KHZ, "Fk", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_NAME_WITH_EXTENSION, "Fm", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_NAME, "Fn", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_PATH, "Fp", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_SIZE, "Fs", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_VBR, "Fv", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_FILE_DIRECTORY, "D", WPS_REFRESH_DYNAMIC, + { WPS_TOKEN_FILE_BITRATE, "Fb", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_CODEC, "Fc", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_FREQUENCY, "Ff", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_FREQUENCY_KHZ, "Fk", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_NAME_WITH_EXTENSION, "Fm", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_NAME, "Fn", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_PATH, "Fp", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_SIZE, "Fs", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_VBR, "Fv", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_FILE_DIRECTORY, "D", WPS_REFRESH_STATIC, parse_dir_level }, /* current metadata */ @@ -242,18 +242,18 @@ static const struct wps_tag all_tags[] = { { WPS_TOKEN_METADATA_COMMENT, "iC", WPS_REFRESH_STATIC, NULL }, /* next metadata */ - { WPS_TOKEN_METADATA_ARTIST, "Ia", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_COMPOSER, "Ic", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_ALBUM, "Id", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_ALBUM_ARTIST, "IA", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_GROUPING, "IG", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_GENRE, "Ig", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_DISC_NUMBER, "Ik", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_TRACK_NUMBER, "In", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_TRACK_TITLE, "It", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_VERSION, "Iv", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_YEAR, "Iy", WPS_REFRESH_DYNAMIC, NULL }, - { WPS_TOKEN_METADATA_COMMENT, "IC", WPS_REFRESH_DYNAMIC, NULL }, + { WPS_TOKEN_METADATA_ARTIST, "Ia", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_COMPOSER, "Ic", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_ALBUM, "Id", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_ALBUM_ARTIST, "IA", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_GROUPING, "IG", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_GENRE, "Ig", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_DISC_NUMBER, "Ik", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_TRACK_NUMBER, "In", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_TRACK_TITLE, "It", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_VERSION, "Iv", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_YEAR, "Iy", WPS_REFRESH_STATIC, NULL }, + { WPS_TOKEN_METADATA_COMMENT, "IC", WPS_REFRESH_STATIC, NULL }, #if (CONFIG_CODEC != MAS3507D) { WPS_TOKEN_SOUND_PITCH, "Sp", WPS_REFRESH_DYNAMIC, NULL }, -- cgit v1.2.3