Another wps rework:
[kugel-rb/myfork.git] / apps / gui / gwps.h
blob7888c3944c2cff2e756974b1381d029c3920f422
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Nicolas Pennequin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _WPS_H
22 #define _WPS_H
24 #include "screen_access.h"
25 #include "statusbar.h"
26 #include "metadata.h"
28 /* constants used in line_type and as refresh_mode for wps_refresh */
29 #define WPS_REFRESH_STATIC (1u<<0) /* line doesn't change over time */
30 #define WPS_REFRESH_DYNAMIC (1u<<1) /* line may change (e.g. time flag) */
31 #define WPS_REFRESH_SCROLL (1u<<2) /* line scrolls */
32 #define WPS_REFRESH_PLAYER_PROGRESS (1u<<3) /* line contains a progress bar */
33 #define WPS_REFRESH_PEAK_METER (1u<<4) /* line contains a peak meter */
34 #define WPS_REFRESH_STATUSBAR (1u<<5) /* refresh statusbar */
35 #define WPS_REFRESH_ALL (0xffffffffu) /* to refresh all line types */
37 /* to refresh only those lines that change over time */
38 #define WPS_REFRESH_NON_STATIC (WPS_REFRESH_DYNAMIC| \
39 WPS_REFRESH_PLAYER_PROGRESS| \
40 WPS_REFRESH_PEAK_METER)
41 /* alignments */
42 #define WPS_ALIGN_RIGHT 32
43 #define WPS_ALIGN_CENTER 64
44 #define WPS_ALIGN_LEFT 128
46 #ifdef HAVE_ALBUMART
48 /* albumart definitions */
49 #define WPS_ALBUMART_NONE 0 /* WPS does not contain AA tag */
50 #define WPS_ALBUMART_CHECK 1 /* WPS contains AA conditional tag */
51 #define WPS_ALBUMART_LOAD 2 /* WPS contains AA tag */
53 #define WPS_ALBUMART_ALIGN_RIGHT 1 /* x align: right */
54 #define WPS_ALBUMART_ALIGN_CENTER 2 /* x/y align: center */
55 #define WPS_ALBUMART_ALIGN_LEFT 4 /* x align: left */
56 #define WPS_ALBUMART_ALIGN_TOP 1 /* y align: top */
57 #define WPS_ALBUMART_ALIGN_BOTTOM 4 /* y align: bottom */
59 #endif /* HAVE_ALBUMART */
61 /* wps_data*/
63 #ifdef HAVE_LCD_BITMAP
64 struct gui_img {
65 struct bitmap bm;
66 struct viewport* vp; /* The viewport to display this image in */
67 short int x; /* x-pos */
68 short int y; /* y-pos */
69 short int num_subimages; /* number of sub-images */
70 short int subimage_height; /* height of each sub-image */
71 short int display; /* -1 for no display, 0..n to display a subimage */
72 bool loaded; /* load state */
73 bool always_display; /* not using the preload/display mechanism */
76 struct progressbar {
77 /* regular pb */
78 short x;
79 /* >=0: explicitly set in the tag -> y-coord within the viewport
80 <0 : not set in the tag -> negated 1-based line number within
81 the viewport. y-coord will be computed based on the font height */
82 short y;
83 short width;
84 short height;
85 /*progressbar image*/
86 struct bitmap bm;
87 bool have_bitmap_pb;
89 #endif
91 struct align_pos {
92 char* left;
93 char* center;
94 char* right;
97 #ifdef HAVE_LCD_BITMAP
99 #define MAX_IMAGES (26*2) /* a-z and A-Z */
100 #define MAX_PROGRESSBARS 3
102 /* The image buffer is big enough to store one full-screen native bitmap,
103 plus two full-screen mono bitmaps. */
105 #define IMG_BUFSIZE ((LCD_HEIGHT*LCD_WIDTH*LCD_DEPTH/8) \
106 + (2*LCD_HEIGHT*LCD_WIDTH/8))
108 #define WPS_MAX_VIEWPORTS 24
109 #define WPS_MAX_LINES ((LCD_HEIGHT/5+1) * 2)
110 #define WPS_MAX_SUBLINES (WPS_MAX_LINES*3)
111 #define WPS_MAX_TOKENS 1024
112 #define WPS_MAX_STRINGS 128
113 #define STRING_BUFFER_SIZE 1024
114 #define WPS_MAX_COND_LEVEL 10
116 #else
118 #define WPS_MAX_VIEWPORTS 2
119 #define WPS_MAX_LINES 2
120 #define WPS_MAX_SUBLINES 12
121 #define WPS_MAX_TOKENS 64
122 #define WPS_MAX_STRINGS 32
123 #define STRING_BUFFER_SIZE 64
124 #define WPS_MAX_COND_LEVEL 5
126 #endif
128 #define SUBLINE_RESET -1
130 enum wps_parse_error {
131 PARSE_OK,
132 PARSE_FAIL_UNCLOSED_COND,
133 PARSE_FAIL_INVALID_CHAR,
134 PARSE_FAIL_COND_SYNTAX_ERROR,
135 PARSE_FAIL_COND_INVALID_PARAM,
136 PARSE_FAIL_LIMITS_EXCEEDED,
139 enum wps_token_type {
140 WPS_NO_TOKEN, /* for WPS tags we don't want to save as tokens */
141 WPS_TOKEN_UNKNOWN,
143 /* Markers */
144 WPS_TOKEN_CHARACTER,
145 WPS_TOKEN_STRING,
147 /* Alignment */
148 WPS_TOKEN_ALIGN_LEFT,
149 WPS_TOKEN_ALIGN_CENTER,
150 WPS_TOKEN_ALIGN_RIGHT,
152 /* Sublines */
153 WPS_TOKEN_SUBLINE_TIMEOUT,
155 /* Battery */
156 WPS_TOKEN_BATTERY_PERCENT,
157 WPS_TOKEN_BATTERY_VOLTS,
158 WPS_TOKEN_BATTERY_TIME,
159 WPS_TOKEN_BATTERY_CHARGER_CONNECTED,
160 WPS_TOKEN_BATTERY_CHARGING,
161 WPS_TOKEN_BATTERY_SLEEPTIME,
163 /* Sound */
164 #if (CONFIG_CODEC != MAS3507D)
165 WPS_TOKEN_SOUND_PITCH,
166 #endif
167 #if (CONFIG_CODEC == SWCODEC)
168 WPS_TOKEN_REPLAYGAIN,
169 WPS_TOKEN_CROSSFADE,
170 #endif
172 /* Time */
174 /* The begin/end values allow us to know if a token is an RTC one.
175 New RTC tokens should be added between the markers. */
177 WPS_TOKENS_RTC_BEGIN, /* just the start marker, not an actual token */
179 WPS_TOKEN_RTC_DAY_OF_MONTH,
180 WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED,
181 WPS_TOKEN_RTC_12HOUR_CFG,
182 WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED,
183 WPS_TOKEN_RTC_HOUR_24,
184 WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED,
185 WPS_TOKEN_RTC_HOUR_12,
186 WPS_TOKEN_RTC_MONTH,
187 WPS_TOKEN_RTC_MINUTE,
188 WPS_TOKEN_RTC_SECOND,
189 WPS_TOKEN_RTC_YEAR_2_DIGITS,
190 WPS_TOKEN_RTC_YEAR_4_DIGITS,
191 WPS_TOKEN_RTC_AM_PM_UPPER,
192 WPS_TOKEN_RTC_AM_PM_LOWER,
193 WPS_TOKEN_RTC_WEEKDAY_NAME,
194 WPS_TOKEN_RTC_MONTH_NAME,
195 WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON,
196 WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN,
198 WPS_TOKENS_RTC_END, /* just the end marker, not an actual token */
200 /* Conditional */
201 WPS_TOKEN_CONDITIONAL,
202 WPS_TOKEN_CONDITIONAL_START,
203 WPS_TOKEN_CONDITIONAL_OPTION,
204 WPS_TOKEN_CONDITIONAL_END,
206 /* Database */
207 #ifdef HAVE_TAGCACHE
208 WPS_TOKEN_DATABASE_PLAYCOUNT,
209 WPS_TOKEN_DATABASE_RATING,
210 WPS_TOKEN_DATABASE_AUTOSCORE,
211 #endif
213 /* File */
214 WPS_TOKEN_FILE_BITRATE,
215 WPS_TOKEN_FILE_CODEC,
216 WPS_TOKEN_FILE_FREQUENCY,
217 WPS_TOKEN_FILE_FREQUENCY_KHZ,
218 WPS_TOKEN_FILE_NAME,
219 WPS_TOKEN_FILE_NAME_WITH_EXTENSION,
220 WPS_TOKEN_FILE_PATH,
221 WPS_TOKEN_FILE_SIZE,
222 WPS_TOKEN_FILE_VBR,
223 WPS_TOKEN_FILE_DIRECTORY,
225 #ifdef HAVE_LCD_BITMAP
226 /* Image */
227 WPS_TOKEN_IMAGE_BACKDROP,
228 WPS_TOKEN_IMAGE_PROGRESS_BAR,
229 WPS_TOKEN_IMAGE_PRELOAD,
230 WPS_TOKEN_IMAGE_PRELOAD_DISPLAY,
231 WPS_TOKEN_IMAGE_DISPLAY,
232 #endif
234 #ifdef HAVE_ALBUMART
235 /* Albumart */
236 WPS_TOKEN_ALBUMART_DISPLAY,
237 WPS_TOKEN_ALBUMART_FOUND,
238 #endif
240 /* Metadata */
241 WPS_TOKEN_METADATA_ARTIST,
242 WPS_TOKEN_METADATA_COMPOSER,
243 WPS_TOKEN_METADATA_ALBUM_ARTIST,
244 WPS_TOKEN_METADATA_GROUPING,
245 WPS_TOKEN_METADATA_ALBUM,
246 WPS_TOKEN_METADATA_GENRE,
247 WPS_TOKEN_METADATA_DISC_NUMBER,
248 WPS_TOKEN_METADATA_TRACK_NUMBER,
249 WPS_TOKEN_METADATA_TRACK_TITLE,
250 WPS_TOKEN_METADATA_VERSION,
251 WPS_TOKEN_METADATA_YEAR,
252 WPS_TOKEN_METADATA_COMMENT,
254 /* Mode */
255 WPS_TOKEN_REPEAT_MODE,
256 WPS_TOKEN_PLAYBACK_STATUS,
258 WPS_TOKEN_MAIN_HOLD,
260 #ifdef HAS_REMOTE_BUTTON_HOLD
261 WPS_TOKEN_REMOTE_HOLD,
262 #endif
264 /* Progressbar */
265 WPS_TOKEN_PROGRESSBAR,
266 #ifdef HAVE_LCD_CHARCELLS
267 WPS_TOKEN_PLAYER_PROGRESSBAR,
268 #endif
270 #ifdef HAVE_LCD_BITMAP
271 /* Peakmeter */
272 WPS_TOKEN_PEAKMETER,
273 #endif
275 /* Volume level */
276 WPS_TOKEN_VOLUME,
278 /* Current track */
279 WPS_TOKEN_TRACK_ELAPSED_PERCENT,
280 WPS_TOKEN_TRACK_TIME_ELAPSED,
281 WPS_TOKEN_TRACK_TIME_REMAINING,
282 WPS_TOKEN_TRACK_LENGTH,
284 /* Playlist */
285 WPS_TOKEN_PLAYLIST_ENTRIES,
286 WPS_TOKEN_PLAYLIST_NAME,
287 WPS_TOKEN_PLAYLIST_POSITION,
288 WPS_TOKEN_PLAYLIST_SHUFFLE,
290 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
291 /* Virtual LED */
292 WPS_TOKEN_VLED_HDD,
293 #endif
295 /* Viewport display */
296 WPS_VIEWPORT_ENABLE,
298 /* buttons */
299 WPS_TOKEN_BUTTON_VOLUME,
301 /* Setting option */
302 WPS_TOKEN_SETTING,
305 struct wps_token {
306 unsigned char type; /* enough to store the token type */
308 /* Whether the tag (e.g. track name or the album) refers the
309 current or the next song (false=current, true=next) */
310 bool next;
312 union {
313 char c;
314 unsigned short i;
315 } value;
318 /* Description of a subline on the WPS */
319 struct wps_subline {
321 /* Index of the first token for this subline in the token array.
322 Tokens of this subline end where tokens for the next subline
323 begin. */
324 unsigned short first_token_idx;
326 /* Bit or'ed WPS_REFRESH_xxx */
327 unsigned char line_type;
329 /* How long the subline should be displayed, in 10ths of sec */
330 unsigned char time_mult;
333 /* Description of a line on the WPS. A line is a set of sublines.
334 A subline is displayed for a certain amount of time. After that,
335 the next subline of the line is displayed. And so on. */
336 struct wps_line {
338 /* Number of sublines in this line */
339 signed char num_sublines;
341 /* Number (0-based) of the subline within this line currently being displayed */
342 signed char curr_subline;
344 /* Index of the first subline of this line in the subline array.
345 Sublines for this line end where sublines for the next line begin. */
346 unsigned short first_subline_idx;
348 /* When the next subline of this line should be displayed
349 (absolute time value in ticks) */
350 long subline_expire_time;
353 #define VP_DRAW_HIDEABLE 0x1
354 #define VP_DRAW_HIDDEN 0x2
355 #define VP_DRAW_WASHIDDEN 0x4
356 struct wps_viewport {
357 struct viewport vp; /* The LCD viewport struct */
358 struct progressbar *pb;
359 /* Indexes of the first and last lines belonging to this viewport in the
360 lines[] array */
361 int first_line, last_line;
362 char hidden_flags;
363 char label;
366 /* wps_data
367 this struct holds all necessary data which describes the
368 viewable content of a wps */
369 struct wps_data
371 #ifdef HAVE_LCD_BITMAP
372 struct gui_img img[MAX_IMAGES];
373 unsigned char img_buf[IMG_BUFSIZE];
374 unsigned char* img_buf_ptr;
375 int img_buf_free;
376 bool wps_sb_tag;
377 bool show_sb_on_wps;
379 struct progressbar progressbar[MAX_PROGRESSBARS];
380 short progressbar_count;
382 bool peak_meter_enabled;
384 #ifdef HAVE_ALBUMART
385 /* Album art support */
386 unsigned char wps_uses_albumart; /* WPS_ALBUMART_NONE, _CHECK, _LOAD */
387 short albumart_x;
388 short albumart_y;
389 unsigned char albumart_xalign; /* WPS_ALBUMART_ALIGN_LEFT, _CENTER, _RIGHT */
390 unsigned char albumart_yalign; /* WPS_ALBUMART_ALIGN_TOP, _CENTER, _BOTTOM */
391 short albumart_max_width;
392 short albumart_max_height;
394 int albumart_cond_index;
395 #endif
397 #else /*HAVE_LCD_CHARCELLS */
398 unsigned short wps_progress_pat[8];
399 bool full_line_progressbar;
400 #endif
402 #ifdef HAVE_REMOTE_LCD
403 bool remote_wps;
404 #endif
406 /* Number of lines in the WPS. During WPS parsing, this is
407 the index of the line being parsed. */
408 int num_lines;
410 /* Number of viewports in the WPS */
411 int num_viewports;
412 struct wps_viewport viewports[WPS_MAX_VIEWPORTS];
414 struct wps_line lines[WPS_MAX_LINES];
416 /* Total number of sublines in the WPS. During WPS parsing, this is
417 the index of the subline where the parsed tokens are added to. */
418 int num_sublines;
419 struct wps_subline sublines[WPS_MAX_SUBLINES];
421 /* Total number of tokens in the WPS. During WPS parsing, this is
422 the index of the token being parsed. */
423 int num_tokens;
424 struct wps_token tokens[WPS_MAX_TOKENS];
426 char string_buffer[STRING_BUFFER_SIZE];
427 char *strings[WPS_MAX_STRINGS];
428 int num_strings;
430 bool wps_loaded;
432 /* tick the volume button was last pressed */
433 unsigned int button_time_volume;
436 /* initial setup of wps_data */
437 void wps_data_init(struct wps_data *wps_data);
439 /* to setup up the wps-data from a format-buffer (isfile = false)
440 from a (wps-)file (isfile = true)*/
441 bool wps_data_load(struct wps_data *wps_data,
442 struct screen *display,
443 const char *buf,
444 bool isfile);
446 /* Redraw statusbars if necessary */
447 void gwps_draw_statusbars(void);
449 /* Returns the index of the subline in the subline array
450 line - 0-based line number
451 subline - 0-based subline number within the line
453 int wps_subline_index(struct wps_data *wps_data, int line, int subline);
455 /* Returns the index of the first subline's token in the token array
456 line - 0-based line number
457 subline - 0-based subline number within the line
459 int wps_first_token_index(struct wps_data *data, int line, int subline);
461 /* Returns the index of the last subline's token in the token array.
462 line - 0-based line number
463 subline - 0-based subline number within the line
465 int wps_last_token_index(struct wps_data *data, int line, int subline);
467 /* wps_data end */
469 /* wps_state
470 holds the data which belongs to the current played track,
471 the track which will be played afterwards, current path to the track
472 and some status infos */
473 struct wps_state
475 bool ff_rewind;
476 bool paused;
477 int ff_rewind_count;
478 bool wps_time_countup;
479 struct mp3entry* id3;
480 struct mp3entry* nid3;
484 /* change the ff/rew-status
485 if ff_rew = true then we are in skipping mode
486 else we are in normal mode */
487 /* void wps_state_update_ff_rew(bool ff_rew); Currently unused */
489 /* change the tag-information of the current played track
490 and the following track */
491 /* void wps_state_update_id3_nid3(struct mp3entry *id3, struct mp3entry *nid3); Currently unused */
492 /* wps_state end*/
494 /* gui_wps
495 defines a wps with its data, state,
496 and the screen on which the wps-content should be drawn */
497 struct gui_wps
499 struct screen *display;
500 struct wps_data *data;
501 struct wps_state *state;
504 /* gui_wps end */
506 long gui_wps_show(void);
508 /* currently only on wps_state is needed */
509 extern struct wps_state wps_state;
510 extern struct gui_wps gui_wps[NB_SCREENS];
512 void gui_sync_wps_init(void);
514 #ifdef HAVE_ALBUMART
515 /* gives back if WPS contains an albumart tag */
516 bool gui_sync_wps_uses_albumart(void);
517 #endif
519 #endif