Simplify conditions in the manual (should also be done for other features)
[kugel-rb/myfork.git] / apps / gui / gwps.h
blobac1cbad60beab2936fa29281868c098a8a3b32ec
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
93 struct align_pos {
94 char* left;
95 char* center;
96 char* right;
99 #ifdef HAVE_LCD_BITMAP
101 #define MAX_IMAGES (26*2) /* a-z and A-Z */
102 #define MAX_PROGRESSBARS 3
104 /* The image buffer is big enough to store one full-screen native bitmap,
105 plus two full-screen mono bitmaps. */
107 #define IMG_BUFSIZE ((LCD_HEIGHT*LCD_WIDTH*LCD_DEPTH/8) \
108 + (2*LCD_HEIGHT*LCD_WIDTH/8))
110 #define WPS_MAX_VIEWPORTS 24
111 #define WPS_MAX_LINES ((LCD_HEIGHT/5+1) * 2)
112 #define WPS_MAX_SUBLINES (WPS_MAX_LINES*3)
113 #define WPS_MAX_TOKENS 1024
114 #define WPS_MAX_STRINGS 128
115 #define STRING_BUFFER_SIZE 1024
116 #define WPS_MAX_COND_LEVEL 10
118 #else
120 #define WPS_MAX_VIEWPORTS 2
121 #define WPS_MAX_LINES 2
122 #define WPS_MAX_SUBLINES 12
123 #define WPS_MAX_TOKENS 64
124 #define WPS_MAX_STRINGS 32
125 #define STRING_BUFFER_SIZE 64
126 #define WPS_MAX_COND_LEVEL 5
128 #endif
130 #define SUBLINE_RESET -1
132 enum wps_parse_error {
133 PARSE_OK,
134 PARSE_FAIL_UNCLOSED_COND,
135 PARSE_FAIL_INVALID_CHAR,
136 PARSE_FAIL_COND_SYNTAX_ERROR,
137 PARSE_FAIL_COND_INVALID_PARAM,
138 PARSE_FAIL_LIMITS_EXCEEDED,
141 enum wps_token_type {
142 WPS_NO_TOKEN, /* for WPS tags we don't want to save as tokens */
143 WPS_TOKEN_UNKNOWN,
145 /* Markers */
146 WPS_TOKEN_CHARACTER,
147 WPS_TOKEN_STRING,
149 /* Alignment */
150 WPS_TOKEN_ALIGN_LEFT,
151 WPS_TOKEN_ALIGN_CENTER,
152 WPS_TOKEN_ALIGN_RIGHT,
154 /* Sublines */
155 WPS_TOKEN_SUBLINE_TIMEOUT,
157 /* Battery */
158 WPS_TOKEN_BATTERY_PERCENT,
159 WPS_TOKEN_BATTERY_VOLTS,
160 WPS_TOKEN_BATTERY_TIME,
161 WPS_TOKEN_BATTERY_CHARGER_CONNECTED,
162 WPS_TOKEN_BATTERY_CHARGING,
163 WPS_TOKEN_BATTERY_SLEEPTIME,
165 /* Sound */
166 #if (CONFIG_CODEC != MAS3507D)
167 WPS_TOKEN_SOUND_PITCH,
168 #endif
169 #if (CONFIG_CODEC == SWCODEC)
170 WPS_TOKEN_REPLAYGAIN,
171 WPS_TOKEN_CROSSFADE,
172 #endif
174 /* Time */
176 WPS_TOKEN_RTC_PRESENT,
178 /* The begin/end values allow us to know if a token is an RTC one.
179 New RTC tokens should be added between the markers. */
181 WPS_TOKENS_RTC_BEGIN, /* just the start marker, not an actual token */
183 WPS_TOKEN_RTC_DAY_OF_MONTH,
184 WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED,
185 WPS_TOKEN_RTC_12HOUR_CFG,
186 WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED,
187 WPS_TOKEN_RTC_HOUR_24,
188 WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED,
189 WPS_TOKEN_RTC_HOUR_12,
190 WPS_TOKEN_RTC_MONTH,
191 WPS_TOKEN_RTC_MINUTE,
192 WPS_TOKEN_RTC_SECOND,
193 WPS_TOKEN_RTC_YEAR_2_DIGITS,
194 WPS_TOKEN_RTC_YEAR_4_DIGITS,
195 WPS_TOKEN_RTC_AM_PM_UPPER,
196 WPS_TOKEN_RTC_AM_PM_LOWER,
197 WPS_TOKEN_RTC_WEEKDAY_NAME,
198 WPS_TOKEN_RTC_MONTH_NAME,
199 WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON,
200 WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN,
202 WPS_TOKENS_RTC_END, /* just the end marker, not an actual token */
204 /* Conditional */
205 WPS_TOKEN_CONDITIONAL,
206 WPS_TOKEN_CONDITIONAL_START,
207 WPS_TOKEN_CONDITIONAL_OPTION,
208 WPS_TOKEN_CONDITIONAL_END,
210 /* Database */
211 #ifdef HAVE_TAGCACHE
212 WPS_TOKEN_DATABASE_PLAYCOUNT,
213 WPS_TOKEN_DATABASE_RATING,
214 WPS_TOKEN_DATABASE_AUTOSCORE,
215 #endif
217 /* File */
218 WPS_TOKEN_FILE_BITRATE,
219 WPS_TOKEN_FILE_CODEC,
220 WPS_TOKEN_FILE_FREQUENCY,
221 WPS_TOKEN_FILE_FREQUENCY_KHZ,
222 WPS_TOKEN_FILE_NAME,
223 WPS_TOKEN_FILE_NAME_WITH_EXTENSION,
224 WPS_TOKEN_FILE_PATH,
225 WPS_TOKEN_FILE_SIZE,
226 WPS_TOKEN_FILE_VBR,
227 WPS_TOKEN_FILE_DIRECTORY,
229 #ifdef HAVE_LCD_BITMAP
230 /* Image */
231 WPS_TOKEN_IMAGE_BACKDROP,
232 WPS_TOKEN_IMAGE_PROGRESS_BAR,
233 WPS_TOKEN_IMAGE_PRELOAD,
234 WPS_TOKEN_IMAGE_PRELOAD_DISPLAY,
235 WPS_TOKEN_IMAGE_DISPLAY,
236 #endif
238 #ifdef HAVE_ALBUMART
239 /* Albumart */
240 WPS_TOKEN_ALBUMART_DISPLAY,
241 WPS_TOKEN_ALBUMART_FOUND,
242 #endif
244 /* Metadata */
245 WPS_TOKEN_METADATA_ARTIST,
246 WPS_TOKEN_METADATA_COMPOSER,
247 WPS_TOKEN_METADATA_ALBUM_ARTIST,
248 WPS_TOKEN_METADATA_GROUPING,
249 WPS_TOKEN_METADATA_ALBUM,
250 WPS_TOKEN_METADATA_GENRE,
251 WPS_TOKEN_METADATA_DISC_NUMBER,
252 WPS_TOKEN_METADATA_TRACK_NUMBER,
253 WPS_TOKEN_METADATA_TRACK_TITLE,
254 WPS_TOKEN_METADATA_VERSION,
255 WPS_TOKEN_METADATA_YEAR,
256 WPS_TOKEN_METADATA_COMMENT,
258 /* Mode */
259 WPS_TOKEN_REPEAT_MODE,
260 WPS_TOKEN_PLAYBACK_STATUS,
262 WPS_TOKEN_MAIN_HOLD,
264 #ifdef HAS_REMOTE_BUTTON_HOLD
265 WPS_TOKEN_REMOTE_HOLD,
266 #endif
268 /* Progressbar */
269 WPS_TOKEN_PROGRESSBAR,
270 #ifdef HAVE_LCD_CHARCELLS
271 WPS_TOKEN_PLAYER_PROGRESSBAR,
272 #endif
274 #ifdef HAVE_LCD_BITMAP
275 /* Peakmeter */
276 WPS_TOKEN_PEAKMETER,
277 #endif
279 /* Volume level */
280 WPS_TOKEN_VOLUME,
282 /* Current track */
283 WPS_TOKEN_TRACK_ELAPSED_PERCENT,
284 WPS_TOKEN_TRACK_TIME_ELAPSED,
285 WPS_TOKEN_TRACK_TIME_REMAINING,
286 WPS_TOKEN_TRACK_LENGTH,
288 /* Playlist */
289 WPS_TOKEN_PLAYLIST_ENTRIES,
290 WPS_TOKEN_PLAYLIST_NAME,
291 WPS_TOKEN_PLAYLIST_POSITION,
292 WPS_TOKEN_PLAYLIST_SHUFFLE,
294 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
295 /* Virtual LED */
296 WPS_TOKEN_VLED_HDD,
297 #endif
299 /* Viewport display */
300 WPS_VIEWPORT_ENABLE,
302 /* buttons */
303 WPS_TOKEN_BUTTON_VOLUME,
304 WPS_TOKEN_LASTTOUCH,
306 /* Setting option */
307 WPS_TOKEN_SETTING,
310 struct wps_token {
311 unsigned char type; /* enough to store the token type */
313 /* Whether the tag (e.g. track name or the album) refers the
314 current or the next song (false=current, true=next) */
315 bool next;
317 union {
318 char c;
319 unsigned short i;
320 } value;
323 /* Description of a subline on the WPS */
324 struct wps_subline {
326 /* Index of the first token for this subline in the token array.
327 Tokens of this subline end where tokens for the next subline
328 begin. */
329 unsigned short first_token_idx;
331 /* Bit or'ed WPS_REFRESH_xxx */
332 unsigned char line_type;
334 /* How long the subline should be displayed, in 10ths of sec */
335 unsigned char time_mult;
338 /* Description of a line on the WPS. A line is a set of sublines.
339 A subline is displayed for a certain amount of time. After that,
340 the next subline of the line is displayed. And so on. */
341 struct wps_line {
343 /* Number of sublines in this line */
344 signed char num_sublines;
346 /* Number (0-based) of the subline within this line currently being displayed */
347 signed char curr_subline;
349 /* Index of the first subline of this line in the subline array.
350 Sublines for this line end where sublines for the next line begin. */
351 unsigned short first_subline_idx;
353 /* When the next subline of this line should be displayed
354 (absolute time value in ticks) */
355 long subline_expire_time;
358 #define VP_DRAW_HIDEABLE 0x1
359 #define VP_DRAW_HIDDEN 0x2
360 #define VP_DRAW_WASHIDDEN 0x4
361 struct wps_viewport {
362 struct viewport vp; /* The LCD viewport struct */
363 struct progressbar *pb;
364 /* Indexes of the first and last lines belonging to this viewport in the
365 lines[] array */
366 int first_line, last_line;
367 char hidden_flags;
368 char label;
371 #ifdef HAVE_TOUCHSCREEN
372 struct touchregion {
373 struct wps_viewport* wvp;/* The viewport this region is in */
374 short int x; /* x-pos */
375 short int y; /* y-pos */
376 short int width; /* width */
377 short int height; /* height */
378 bool repeat; /* requires the area be held for the action */
379 int action; /* action this button will return */
381 #define MAX_TOUCHREGIONS 12
382 #endif
383 /* wps_data
384 this struct holds all necessary data which describes the
385 viewable content of a wps */
386 struct wps_data
388 #ifdef HAVE_LCD_BITMAP
389 struct gui_img img[MAX_IMAGES];
390 unsigned char img_buf[IMG_BUFSIZE];
391 unsigned char* img_buf_ptr;
392 int img_buf_free;
393 bool wps_sb_tag;
394 bool show_sb_on_wps;
396 struct progressbar progressbar[MAX_PROGRESSBARS];
397 short progressbar_count;
399 bool peak_meter_enabled;
401 #ifdef HAVE_ALBUMART
402 /* Album art support */
403 unsigned char wps_uses_albumart; /* WPS_ALBUMART_NONE, _CHECK, _LOAD */
404 short albumart_x;
405 short albumart_y;
406 unsigned char albumart_xalign; /* WPS_ALBUMART_ALIGN_LEFT, _CENTER, _RIGHT */
407 unsigned char albumart_yalign; /* WPS_ALBUMART_ALIGN_TOP, _CENTER, _BOTTOM */
408 short albumart_max_width;
409 short albumart_max_height;
411 int albumart_cond_index;
412 #endif
414 #else /*HAVE_LCD_CHARCELLS */
415 unsigned short wps_progress_pat[8];
416 bool full_line_progressbar;
417 #endif
419 #ifdef HAVE_TOUCHSCREEN
420 struct touchregion touchregion[MAX_TOUCHREGIONS];
421 short touchregion_count;
422 #endif
424 #ifdef HAVE_REMOTE_LCD
425 bool remote_wps;
426 #endif
428 /* Number of lines in the WPS. During WPS parsing, this is
429 the index of the line being parsed. */
430 int num_lines;
432 /* Number of viewports in the WPS */
433 int num_viewports;
434 struct wps_viewport viewports[WPS_MAX_VIEWPORTS];
436 struct wps_line lines[WPS_MAX_LINES];
438 /* Total number of sublines in the WPS. During WPS parsing, this is
439 the index of the subline where the parsed tokens are added to. */
440 int num_sublines;
441 struct wps_subline sublines[WPS_MAX_SUBLINES];
443 /* Total number of tokens in the WPS. During WPS parsing, this is
444 the index of the token being parsed. */
445 int num_tokens;
446 struct wps_token tokens[WPS_MAX_TOKENS];
448 char string_buffer[STRING_BUFFER_SIZE];
449 char *strings[WPS_MAX_STRINGS];
450 int num_strings;
452 bool wps_loaded;
454 /* tick the volume button was last pressed */
455 unsigned int button_time_volume;
458 /* initial setup of wps_data */
459 void wps_data_init(struct wps_data *wps_data);
461 /* to setup up the wps-data from a format-buffer (isfile = false)
462 from a (wps-)file (isfile = true)*/
463 bool wps_data_load(struct wps_data *wps_data,
464 struct screen *display,
465 const char *buf,
466 bool isfile);
468 /* Redraw statusbars if necessary */
469 void gwps_draw_statusbars(void);
471 /* Returns the index of the subline in the subline array
472 line - 0-based line number
473 subline - 0-based subline number within the line
475 int wps_subline_index(struct wps_data *wps_data, int line, int subline);
477 /* Returns the index of the first subline's token in the token array
478 line - 0-based line number
479 subline - 0-based subline number within the line
481 int wps_first_token_index(struct wps_data *data, int line, int subline);
483 /* Returns the index of the last subline's token in the token array.
484 line - 0-based line number
485 subline - 0-based subline number within the line
487 int wps_last_token_index(struct wps_data *data, int line, int subline);
489 /* wps_data end */
491 /* wps_state
492 holds the data which belongs to the current played track,
493 the track which will be played afterwards, current path to the track
494 and some status infos */
495 struct wps_state
497 bool ff_rewind;
498 bool paused;
499 int ff_rewind_count;
500 bool wps_time_countup;
501 struct mp3entry* id3;
502 struct mp3entry* nid3;
503 bool do_full_update;
507 /* change the ff/rew-status
508 if ff_rew = true then we are in skipping mode
509 else we are in normal mode */
510 /* void wps_state_update_ff_rew(bool ff_rew); Currently unused */
512 /* change the tag-information of the current played track
513 and the following track */
514 /* void wps_state_update_id3_nid3(struct mp3entry *id3, struct mp3entry *nid3); Currently unused */
515 /* wps_state end*/
517 /* gui_wps
518 defines a wps with its data, state,
519 and the screen on which the wps-content should be drawn */
520 struct gui_wps
522 struct screen *display;
523 struct wps_data *data;
524 struct wps_state *state;
527 /* gui_wps end */
529 long gui_wps_show(void);
531 /* currently only on wps_state is needed */
532 extern struct wps_state wps_state;
533 extern struct gui_wps gui_wps[NB_SCREENS];
535 void gui_sync_wps_init(void);
537 #ifdef HAVE_TOUCHSCREEN
538 int wps_get_touchaction(struct wps_data *data);
539 #endif
541 #ifdef HAVE_ALBUMART
542 /* gives back if WPS contains an albumart tag */
543 bool gui_sync_wps_uses_albumart(void);
544 #endif
546 #endif