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
This commit is contained in:
Aidan MacDonald 2022-10-02 21:05:32 +01:00
parent 13da1ba785
commit 14fbefdf39
9 changed files with 59 additions and 66 deletions

View file

@ -65,7 +65,7 @@
#endif #endif
#include "root_menu.h" #include "root_menu.h"
#include "wps.h"
#include "wps_internals.h" #include "wps_internals.h"
#include "skin_engine.h" #include "skin_engine.h"
#include "statusbar-skinned.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); struct gui_wps *gwps = skin_get_gwps(skin, screen);
/* This maybe shouldnt be here, /* This maybe shouldnt be here,
* This is also safe for skined screen which dont use the id3 */ * 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); bool cuesheet_update = (id3 != NULL ? cuesheet_subtrack_changed(id3) : false);
if (cuesheet_update) if (cuesheet_update)
skin_request_full_update(skin); 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 screen *display = gwps->display;
struct viewport *vp = SKINOFFSETTOPTR(get_skin_buffer(gwps->data), pb->vp); 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; struct mp3entry *id3 = state->id3;
int x = pb->x, y = pb->y, width = pb->width, height = pb->height; int x = pb->x, y = pb->y, width = pb->width, height = pb->height;
unsigned long length, end; unsigned long length, end;

View file

@ -53,7 +53,6 @@ static bool skins_initialised = false;
static char* get_skin_filename(char *buf, size_t buf_size, static char* get_skin_filename(char *buf, size_t buf_size,
enum skinnable_screens skin, enum screen_type screen); enum skinnable_screens skin, enum screen_type screen);
struct wps_state wps_state = { .id3 = NULL };
static struct gui_skin_helper { static struct gui_skin_helper {
int (*preproccess)(enum screen_type screen, struct wps_data *data); int (*preproccess)(enum screen_type screen, struct wps_data *data);
int (*postproccess)(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; 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. /* 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 */ * if true you MUST do a full update as the next call will return false */
bool skin_do_full_update(enum skinnable_screens skin, bool skin_do_full_update(enum skinnable_screens skin,

View file

@ -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, void skin_load(enum skinnable_screens skin, enum screen_type screen,
const char *buf, bool isfile); const char *buf, bool isfile);
struct gui_wps *skin_get_gwps(enum skinnable_screens skin, enum screen_type screen); 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 gui_sync_skin_init(void);
void skin_unload_all(void); void skin_unload_all(void);

View file

@ -50,6 +50,7 @@
#include "root_menu.h" #include "root_menu.h"
#include "misc.h" #include "misc.h"
#include "list.h" #include "list.h"
#include "wps.h"
#define MAX_LINE 1024 #define MAX_LINE 1024
@ -956,8 +957,8 @@ void skin_render_playlistviewer(struct playlistviewer* viewer,
else else
#endif #endif
{ {
struct cuesheet *cue = skin_get_global_state()->id3 ? struct wps_state *state = get_wps_state();
skin_get_global_state()->id3->cuesheet : NULL; struct cuesheet *cue = state->id3 ? state->id3->cuesheet : NULL;
cur_pos = playlist_get_display_index(); cur_pos = playlist_get_display_index();
max = playlist_amount()+1; max = playlist_amount()+1;
if (cue) if (cue)

View file

@ -66,11 +66,10 @@
#include "fixedpoint.h" #include "fixedpoint.h"
#endif #endif
#include "list.h" #include "list.h"
#include "wps.h"
#define NOINLINE __attribute__ ((noinline)) #define NOINLINE __attribute__ ((noinline))
extern struct wps_state wps_state;
static const char* get_codectype(const struct mp3entry* id3) static const char* get_codectype(const struct mp3entry* id3)
{ {
if (id3 && id3->codectype < AFMT_NUM_CODECS) { 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, const char *get_id3_token(struct wps_token *token, struct mp3entry *id3,
char *filename, char *buf, int buf_size, int limit, int *intval) 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) if (id3)
{ {
unsigned long length = id3->length; 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) static struct mp3entry* get_mp3entry_from_offset(int offset, char **filename)
{ {
struct mp3entry* pid3 = NULL; 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; struct cuesheet *cue = state->id3 ? state->id3->cuesheet : NULL;
const char *fname = NULL; const char *fname = NULL;
if (cue && cue->curr_track_idx + offset < cue->track_count) 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; return NULL;
struct wps_data *data = gwps->data; 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. struct mp3entry *id3; /* Think very carefully about using this.
maybe get_id3_token() is the better place? */ maybe get_id3_token() is the better place? */
const char *out_text = NULL; const char *out_text = NULL;

View file

@ -393,28 +393,6 @@ static inline char* get_skin_buffer(struct wps_data* data)
/* wps_data end */ /* 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 /* gui_wps
defines a wps with its data, state, defines a wps with its data, state,
and the screen on which the wps-content should be drawn */ and the screen on which the wps-content should be drawn */

View file

@ -70,6 +70,8 @@
/* 3% of 30min file == 54s step size */ /* 3% of 30min file == 54s step size */
#define MIN_FF_REWIND_STEP 500 #define MIN_FF_REWIND_STEP 500
static struct wps_state wps_state;
/* initial setup of wps_data */ /* initial setup of wps_data */
static void wps_state_init(void); static void wps_state_init(void);
static void track_info_callback(unsigned short id, void *param); 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; int offset = 0;
struct touchregion *region; struct touchregion *region;
struct wps_state *gstate = get_wps_state();
int button = skin_get_touchaction(data, &offset, &region); int button = skin_get_touchaction(data, &offset, &region);
switch (button) switch (button)
{ {
@ -179,9 +182,9 @@ static int skintouch_to_wps(struct wps_data *data)
return ACTION_WPS_HOTKEY; return ACTION_WPS_HOTKEY;
#endif #endif
case ACTION_TOUCH_SCROLLBAR: 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_pre_ff_rewind();
audio_ff_rewind(skin_get_global_state()->id3->elapsed); audio_ff_rewind(gstate->id3->elapsed);
return ACTION_TOUCHSCREEN; return ACTION_TOUCHSCREEN;
case ACTION_TOUCH_VOLUME: case ACTION_TOUCH_VOLUME:
{ {
@ -209,6 +212,7 @@ static bool ffwd_rew(int button)
bool usb = false; bool usb = false;
bool ff_rewind = false; bool ff_rewind = false;
const long ff_rw_accel = (global_settings.ff_rewind_accel + 3); const long ff_rw_accel = (global_settings.ff_rewind_accel + 3);
struct wps_state *gstate = get_wps_state();
if (button == ACTION_NONE) if (button == ACTION_NONE)
{ {
@ -228,15 +232,15 @@ static bool ffwd_rew(int button)
if (direction == 1) if (direction == 1)
{ {
/* fast forwarding, calc max step relative to end */ /* fast forwarding, calc max step relative to end */
max_step = (skin_get_global_state()->id3->length - max_step = (gstate->id3->length -
(skin_get_global_state()->id3->elapsed + (gstate->id3->elapsed +
ff_rewind_count)) * ff_rewind_count)) *
FF_REWIND_MAX_PERCENT / 100; FF_REWIND_MAX_PERCENT / 100;
} }
else else
{ {
/* rewinding, calc max step relative to start */ /* 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; FF_REWIND_MAX_PERCENT / 100;
} }
@ -253,7 +257,7 @@ static bool ffwd_rew(int button)
else else
{ {
if ( (audio_status() & AUDIO_STATUS_PLAY) && 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(); audio_pre_ff_rewind();
if (direction > 0) if (direction > 0)
@ -270,19 +274,17 @@ static bool ffwd_rew(int button)
} }
if (direction > 0) { if (direction > 0) {
if ((skin_get_global_state()->id3->elapsed + ff_rewind_count) > if ((gstate->id3->elapsed + ff_rewind_count) > gstate->id3->length)
skin_get_global_state()->id3->length) ff_rewind_count = gstate->id3->length - gstate->id3->elapsed;
ff_rewind_count = skin_get_global_state()->id3->length -
skin_get_global_state()->id3->elapsed;
} }
else { else {
if ((int)(skin_get_global_state()->id3->elapsed + ff_rewind_count) < 0) if ((int)(gstate->id3->elapsed + ff_rewind_count) < 0)
ff_rewind_count = -skin_get_global_state()->id3->elapsed; ff_rewind_count = -gstate->id3->elapsed;
} }
/* set the wps state ff_rewind_count so the progess info /* set the wps state ff_rewind_count so the progess info
displays corectly */ displays corectly */
skin_get_global_state()->ff_rewind_count = ff_rewind_count; gstate->ff_rewind_count = ff_rewind_count;
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
{ {
@ -294,9 +296,9 @@ static bool ffwd_rew(int button)
break; break;
case ACTION_WPS_STOPSEEK: case ACTION_WPS_STOPSEEK:
skin_get_global_state()->id3->elapsed = skin_get_global_state()->id3->elapsed+ff_rewind_count; gstate->id3->elapsed = gstate->id3->elapsed+ff_rewind_count;
audio_ff_rewind(skin_get_global_state()->id3->elapsed); audio_ff_rewind(gstate->id3->elapsed);
skin_get_global_state()->ff_rewind_count = 0; gstate->ff_rewind_count = 0;
ff_rewind = false; ff_rewind = false;
status_set_ffmode(0); status_set_ffmode(0);
exit = true; exit = true;
@ -328,7 +330,7 @@ static bool ffwd_rew(int button)
#if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD) #if defined(HAVE_BACKLIGHT) || defined(HAVE_REMOTE_LCD)
static void gwps_caption_backlight(struct wps_state *state) static void gwps_caption_backlight(struct wps_state *state)
{ {
if (state && state->id3) if (state->id3)
{ {
#ifdef HAVE_BACKLIGHT #ifdef HAVE_BACKLIGHT
if (global_settings.caption_backlight) if (global_settings.caption_backlight)
@ -383,7 +385,7 @@ static void change_dir(int direction)
static void prev_track(unsigned long skip_thresh) 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) if (state->id3->elapsed < skip_thresh)
{ {
audio_prev(); audio_prev();
@ -404,7 +406,7 @@ static void prev_track(unsigned long skip_thresh)
static void next_track(void) 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 */ /* take care of if we're playing a cuesheet */
if (state->id3->cuesheet) if (state->id3->cuesheet)
{ {
@ -421,7 +423,7 @@ static void next_track(void)
static void play_hop(int direction) 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; struct cuesheet *cue = state->id3->cuesheet;
long step = global_settings.skip_length*1000; long step = global_settings.skip_length*1000;
long elapsed = state->id3->elapsed; long elapsed = state->id3->elapsed;
@ -571,7 +573,7 @@ static void gwps_enter_wps(void)
void wps_do_playpause(bool updatewps) void wps_do_playpause(bool updatewps)
{ {
struct wps_state *state = skin_get_global_state(); struct wps_state *state = get_wps_state();
if ( state->paused ) if ( state->paused )
{ {
state->paused = false; state->paused = false;
@ -608,7 +610,7 @@ long gui_wps_show(void)
bool update = false; bool update = false;
bool vol_changed = false; bool vol_changed = false;
long last_left = 0, last_right = 0; 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 #ifdef AB_REPEAT_ENABLE
ab_repeat_init(); ab_repeat_init();
@ -1021,10 +1023,15 @@ long gui_wps_show(void)
return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */ 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! */ /* this is called from the playback thread so NO DRAWING! */
static void track_info_callback(unsigned short id, void *param) 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) 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(); state->id3 = audio_current_track();
} }
#endif #endif
skin_get_global_state()->nid3 = audio_next_track(); state->nid3 = audio_next_track();
skin_request_full_update(WPS); skin_request_full_update(WPS);
} }
static void wps_state_init(void) static void wps_state_init(void)
{ {
struct wps_state *state = skin_get_global_state(); struct wps_state *state = get_wps_state();
state->paused = false; state->paused = false;
if(audio_status() & AUDIO_STATUS_PLAY) if(audio_status() & AUDIO_STATUS_PLAY)
{ {

View file

@ -23,6 +23,17 @@
#include <stdbool.h> #include <stdbool.h>
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); long gui_wps_show(void);
/* fade (if enabled) and pause the audio, optionally rewind a little */ /* 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 unpause_action(bool updatewps);
void wps_do_playpause(bool updatewps); void wps_do_playpause(bool updatewps);
struct wps_state *get_wps_state(void);
/* in milliseconds */ /* in milliseconds */
#define DEFAULT_SKIP_THRESH 3000l #define DEFAULT_SKIP_THRESH 3000l

View file

@ -56,7 +56,7 @@
#include "statusbar-skinned.h" #include "statusbar-skinned.h"
#include "playback.h" #include "playback.h"
#include "presets.h" #include "presets.h"
#include "skin_engine/wps_internals.h" #include "wps.h" /* for wps_state... */
#if CONFIG_TUNER #if CONFIG_TUNER
@ -364,7 +364,9 @@ void radio_screen(void)
{ {
radio_load_presets(global_settings.fmr_file); 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 #ifdef HAVE_ALBUMART
radioart_init(true); radioart_init(true);
#endif #endif