From 14fbefdf390d397a13b31e2b58b4615d794ff709 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sun, 2 Oct 2022 21:05:32 +0100 Subject: Move skin global state to the WPS This state is actually specific to the WPS and it makes more sense to put it there. Change-Id: I5dfee237fdcbae944806501ff3127a930820d68a --- apps/gui/skin_engine/skin_display.c | 6 ++-- apps/gui/skin_engine/skin_engine.c | 6 ---- apps/gui/skin_engine/skin_engine.h | 1 - apps/gui/skin_engine/skin_render.c | 5 ++-- apps/gui/skin_engine/skin_tokens.c | 9 +++--- apps/gui/skin_engine/wps_internals.h | 22 -------------- apps/gui/wps.c | 57 ++++++++++++++++++++---------------- apps/gui/wps.h | 13 ++++++++ apps/radio/radio.c | 6 ++-- 9 files changed, 59 insertions(+), 66 deletions(-) diff --git a/apps/gui/skin_engine/skin_display.c b/apps/gui/skin_engine/skin_display.c index 3e3f203f9a..49375829e6 100644 --- a/apps/gui/skin_engine/skin_display.c +++ b/apps/gui/skin_engine/skin_display.c @@ -65,7 +65,7 @@ #endif #include "root_menu.h" - +#include "wps.h" #include "wps_internals.h" #include "skin_engine.h" #include "statusbar-skinned.h" @@ -83,7 +83,7 @@ void skin_update(enum skinnable_screens skin, enum screen_type screen, struct gui_wps *gwps = skin_get_gwps(skin, screen); /* This maybe shouldnt be here, * This is also safe for skined screen which dont use the id3 */ - struct mp3entry *id3 = skin_get_global_state()->id3; + struct mp3entry *id3 = get_wps_state()->id3; bool cuesheet_update = (id3 != NULL ? cuesheet_subtrack_changed(id3) : false); if (cuesheet_update) skin_request_full_update(skin); @@ -162,7 +162,7 @@ void draw_progressbar(struct gui_wps *gwps, int line, struct progressbar *pb) { struct screen *display = gwps->display; struct viewport *vp = SKINOFFSETTOPTR(get_skin_buffer(gwps->data), pb->vp); - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); struct mp3entry *id3 = state->id3; int x = pb->x, y = pb->y, width = pb->width, height = pb->height; unsigned long length, end; diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c index a3ad85fd6e..c007ed35d4 100644 --- a/apps/gui/skin_engine/skin_engine.c +++ b/apps/gui/skin_engine/skin_engine.c @@ -53,7 +53,6 @@ static bool skins_initialised = false; static char* get_skin_filename(char *buf, size_t buf_size, enum skinnable_screens skin, enum screen_type screen); -struct wps_state wps_state = { .id3 = NULL }; static struct gui_skin_helper { int (*preproccess)(enum screen_type screen, struct wps_data *data); int (*postproccess)(enum screen_type screen, struct wps_data *data); @@ -310,11 +309,6 @@ struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type scre return &skins[skin][screen].gui_wps; } -struct wps_state *skin_get_global_state(void) -{ - return &wps_state; -} - /* This is called to find out if we the screen needs a full update. * if true you MUST do a full update as the next call will return false */ bool skin_do_full_update(enum skinnable_screens skin, diff --git a/apps/gui/skin_engine/skin_engine.h b/apps/gui/skin_engine/skin_engine.h index d7efb5b888..a685f4f072 100644 --- a/apps/gui/skin_engine/skin_engine.h +++ b/apps/gui/skin_engine/skin_engine.h @@ -85,7 +85,6 @@ int skin_wait_for_action(enum skinnable_screens skin, int context, int timeout); void skin_load(enum skinnable_screens skin, enum screen_type screen, const char *buf, bool isfile); struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type screen); -struct wps_state *skin_get_global_state(void); void gui_sync_skin_init(void); void skin_unload_all(void); diff --git a/apps/gui/skin_engine/skin_render.c b/apps/gui/skin_engine/skin_render.c index 2238bd9bec..e5d2078177 100644 --- a/apps/gui/skin_engine/skin_render.c +++ b/apps/gui/skin_engine/skin_render.c @@ -50,6 +50,7 @@ #include "root_menu.h" #include "misc.h" #include "list.h" +#include "wps.h" #define MAX_LINE 1024 @@ -956,8 +957,8 @@ void skin_render_playlistviewer(struct playlistviewer* viewer, else #endif { - struct cuesheet *cue = skin_get_global_state()->id3 ? - skin_get_global_state()->id3->cuesheet : NULL; + struct wps_state *state = get_wps_state(); + struct cuesheet *cue = state->id3 ? state->id3->cuesheet : NULL; cur_pos = playlist_get_display_index(); max = playlist_amount()+1; if (cue) diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 0101a5e01e..a1d0a4b840 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -66,11 +66,10 @@ #include "fixedpoint.h" #endif #include "list.h" +#include "wps.h" #define NOINLINE __attribute__ ((noinline)) -extern struct wps_state wps_state; - static const char* get_codectype(const struct mp3entry* id3) { if (id3 && id3->codectype < AFMT_NUM_CODECS) { @@ -228,7 +227,7 @@ static const char* get_filename_token(struct wps_token *token, char* filename, const char *get_id3_token(struct wps_token *token, struct mp3entry *id3, char *filename, char *buf, int buf_size, int limit, int *intval) { - struct wps_state *state = &wps_state; + struct wps_state *state = get_wps_state(); if (id3) { unsigned long length = id3->length; @@ -540,7 +539,7 @@ const char *get_radio_token(struct wps_token *token, int preset_offset, static struct mp3entry* get_mp3entry_from_offset(int offset, char **filename) { struct mp3entry* pid3 = NULL; - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); struct cuesheet *cue = state->id3 ? state->id3->cuesheet : NULL; const char *fname = NULL; if (cue && cue->curr_track_idx + offset < cue->track_count) @@ -678,7 +677,7 @@ const char *get_token_value(struct gui_wps *gwps, return NULL; struct wps_data *data = gwps->data; - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); struct mp3entry *id3; /* Think very carefully about using this. maybe get_id3_token() is the better place? */ const char *out_text = NULL; diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h index 2aedff752b..0ae2e24235 100644 --- a/apps/gui/skin_engine/wps_internals.h +++ b/apps/gui/skin_engine/wps_internals.h @@ -393,28 +393,6 @@ static inline char* get_skin_buffer(struct wps_data* data) /* wps_data end */ -/* wps_state - holds the data which belongs to the current played track, - the track which will be played afterwards, current path to the track - and some status infos */ -struct wps_state -{ - struct mp3entry* id3; - struct mp3entry* nid3; - int ff_rewind_count; - bool paused; -}; - -/* change the ff/rew-status - if ff_rew = true then we are in skipping mode - else we are in normal mode */ -/* void wps_state_update_ff_rew(bool ff_rew); Currently unused */ - -/* change the tag-information of the current played track - and the following track */ -/* void wps_state_update_id3_nid3(struct mp3entry *id3, struct mp3entry *nid3); Currently unused */ -/* wps_state end*/ - /* gui_wps defines a wps with its data, state, and the screen on which the wps-content should be drawn */ diff --git a/apps/gui/wps.c b/apps/gui/wps.c index 53ece62e9c..2587542b00 100644 --- a/apps/gui/wps.c +++ b/apps/gui/wps.c @@ -70,6 +70,8 @@ /* 3% of 30min file == 54s step size */ #define MIN_FF_REWIND_STEP 500 +static struct wps_state wps_state; + /* initial setup of wps_data */ static void wps_state_init(void); static void track_info_callback(unsigned short id, void *param); @@ -157,6 +159,7 @@ static int skintouch_to_wps(struct wps_data *data) { int offset = 0; struct touchregion *region; + struct wps_state *gstate = get_wps_state(); int button = skin_get_touchaction(data, &offset, ®ion); switch (button) { @@ -179,9 +182,9 @@ static int skintouch_to_wps(struct wps_data *data) return ACTION_WPS_HOTKEY; #endif case ACTION_TOUCH_SCROLLBAR: - skin_get_global_state()->id3->elapsed = skin_get_global_state()->id3->length*offset/1000; + gstate->id3->elapsed = gstate->id3->length*offset/1000; audio_pre_ff_rewind(); - audio_ff_rewind(skin_get_global_state()->id3->elapsed); + audio_ff_rewind(gstate->id3->elapsed); return ACTION_TOUCHSCREEN; case ACTION_TOUCH_VOLUME: { @@ -209,6 +212,7 @@ static bool ffwd_rew(int button) bool usb = false; bool ff_rewind = false; const long ff_rw_accel = (global_settings.ff_rewind_accel + 3); + struct wps_state *gstate = get_wps_state(); if (button == ACTION_NONE) { @@ -228,15 +232,15 @@ static bool ffwd_rew(int button) if (direction == 1) { /* fast forwarding, calc max step relative to end */ - max_step = (skin_get_global_state()->id3->length - - (skin_get_global_state()->id3->elapsed + + max_step = (gstate->id3->length - + (gstate->id3->elapsed + ff_rewind_count)) * FF_REWIND_MAX_PERCENT / 100; } else { /* rewinding, calc max step relative to start */ - max_step = (skin_get_global_state()->id3->elapsed + ff_rewind_count) * + max_step = (gstate->id3->elapsed + ff_rewind_count) * FF_REWIND_MAX_PERCENT / 100; } @@ -253,7 +257,7 @@ static bool ffwd_rew(int button) else { if ( (audio_status() & AUDIO_STATUS_PLAY) && - skin_get_global_state()->id3 && skin_get_global_state()->id3->length ) + gstate->id3 && gstate->id3->length ) { audio_pre_ff_rewind(); if (direction > 0) @@ -270,19 +274,17 @@ static bool ffwd_rew(int button) } if (direction > 0) { - if ((skin_get_global_state()->id3->elapsed + ff_rewind_count) > - skin_get_global_state()->id3->length) - ff_rewind_count = skin_get_global_state()->id3->length - - skin_get_global_state()->id3->elapsed; + if ((gstate->id3->elapsed + ff_rewind_count) > gstate->id3->length) + ff_rewind_count = gstate->id3->length - gstate->id3->elapsed; } else { - if ((int)(skin_get_global_state()->id3->elapsed + ff_rewind_count) < 0) - ff_rewind_count = -skin_get_global_state()->id3->elapsed; + if ((int)(gstate->id3->elapsed + ff_rewind_count) < 0) + ff_rewind_count = -gstate->id3->elapsed; } /* set the wps state ff_rewind_count so the progess info displays corectly */ - skin_get_global_state()->ff_rewind_count = ff_rewind_count; + gstate->ff_rewind_count = ff_rewind_count; FOR_NB_SCREENS(i) { @@ -294,9 +296,9 @@ static bool ffwd_rew(int button) break; case ACTION_WPS_STOPSEEK: - skin_get_global_state()->id3->elapsed = skin_get_global_state()->id3->elapsed+ff_rewind_count; - audio_ff_rewind(skin_get_global_state()->id3->elapsed); - skin_get_global_state()->ff_rewind_count = 0; + gstate->id3->elapsed = gstate->id3->elapsed+ff_rewind_count; + audio_ff_rewind(gstate->id3->elapsed); + gstate->ff_rewind_count = 0; ff_rewind = false; status_set_ffmode(0); exit = true; @@ -328,7 +330,7 @@ static bool ffwd_rew(int button) #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD) static void gwps_caption_backlight(struct wps_state *state) { - if (state && state->id3) + if (state->id3) { #ifdef HAVE_BACKLIGHT if (global_settings.caption_backlight) @@ -383,7 +385,7 @@ static void change_dir(int direction) static void prev_track(unsigned long skip_thresh) { - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); if (state->id3->elapsed < skip_thresh) { audio_prev(); @@ -404,7 +406,7 @@ static void prev_track(unsigned long skip_thresh) static void next_track(void) { - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); /* take care of if we're playing a cuesheet */ if (state->id3->cuesheet) { @@ -421,7 +423,7 @@ static void next_track(void) static void play_hop(int direction) { - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); struct cuesheet *cue = state->id3->cuesheet; long step = global_settings.skip_length*1000; long elapsed = state->id3->elapsed; @@ -571,7 +573,7 @@ static void gwps_enter_wps(void) void wps_do_playpause(bool updatewps) { - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); if ( state->paused ) { state->paused = false; @@ -608,7 +610,7 @@ long gui_wps_show(void) bool update = false; bool vol_changed = false; long last_left = 0, last_right = 0; - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); #ifdef AB_REPEAT_ENABLE ab_repeat_init(); @@ -1021,10 +1023,15 @@ long gui_wps_show(void) return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */ } +struct wps_state *get_wps_state(void) +{ + return &wps_state; +} + /* this is called from the playback thread so NO DRAWING! */ static void track_info_callback(unsigned short id, void *param) { - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); if (id == PLAYBACK_EVENT_TRACK_CHANGE || id == PLAYBACK_EVENT_CUR_TRACK_READY) { @@ -1040,13 +1047,13 @@ static void track_info_callback(unsigned short id, void *param) state->id3 = audio_current_track(); } #endif - skin_get_global_state()->nid3 = audio_next_track(); + state->nid3 = audio_next_track(); skin_request_full_update(WPS); } static void wps_state_init(void) { - struct wps_state *state = skin_get_global_state(); + struct wps_state *state = get_wps_state(); state->paused = false; if(audio_status() & AUDIO_STATUS_PLAY) { diff --git a/apps/gui/wps.h b/apps/gui/wps.h index 75c8138d35..001c112a4d 100644 --- a/apps/gui/wps.h +++ b/apps/gui/wps.h @@ -23,6 +23,17 @@ #include +struct mp3entry; + +/* Please don't add anything else to here... */ +struct wps_state +{ + struct mp3entry *id3; + struct mp3entry *nid3; + int ff_rewind_count; + bool paused; +}; + long gui_wps_show(void); /* fade (if enabled) and pause the audio, optionally rewind a little */ @@ -30,6 +41,8 @@ void pause_action(bool updatewps); void unpause_action(bool updatewps); void wps_do_playpause(bool updatewps); +struct wps_state *get_wps_state(void); + /* in milliseconds */ #define DEFAULT_SKIP_THRESH 3000l diff --git a/apps/radio/radio.c b/apps/radio/radio.c index 1764495c7f..bf8ad865dd 100644 --- a/apps/radio/radio.c +++ b/apps/radio/radio.c @@ -56,7 +56,7 @@ #include "statusbar-skinned.h" #include "playback.h" #include "presets.h" -#include "skin_engine/wps_internals.h" +#include "wps.h" /* for wps_state... */ #if CONFIG_TUNER @@ -364,7 +364,9 @@ void radio_screen(void) { radio_load_presets(global_settings.fmr_file); } - skin_get_global_state()->id3 = NULL; + /* TODO: Can this be moved somewhere else? */ + get_wps_state()->id3 = NULL; + get_wps_state()->nid3 = NULL; #ifdef HAVE_ALBUMART radioart_init(true); #endif -- cgit v1.2.3