diff options
author | Christi Scarborough <christi@coraline.org> | 2005-11-17 20:20:01 +0000 |
---|---|---|
committer | Christi Scarborough <christi@coraline.org> | 2005-11-17 20:20:01 +0000 |
commit | f8cc3211a60940228dade59436ba7ce2003445a3 (patch) | |
tree | 115c9e57f2545bc8b4d8f9ff72c1608488e8faab /apps/gui/gwps.c | |
parent | 4c0b83f5e913820bbcf203fee1606d9910925946 (diff) | |
download | rockbox-f8cc3211a60940228dade59436ba7ce2003445a3.tar.gz rockbox-f8cc3211a60940228dade59436ba7ce2003445a3.zip |
And the rest of the files too
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7935 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/gwps.c')
-rw-r--r-- | apps/gui/gwps.c | 853 |
1 files changed, 853 insertions, 0 deletions
diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c new file mode 100644 index 0000000000..4fc9acbece --- /dev/null +++ b/apps/gui/gwps.c | |||
@@ -0,0 +1,853 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <string.h> | ||
3 | #include <stdlib.h> | ||
4 | |||
5 | #include "system.h" | ||
6 | #include "file.h" | ||
7 | #include "lcd.h" | ||
8 | #include "font.h" | ||
9 | #include "backlight.h" | ||
10 | #include "button.h" | ||
11 | #include "kernel.h" | ||
12 | #include "tree.h" | ||
13 | #include "debug.h" | ||
14 | #include "sprintf.h" | ||
15 | #include "settings.h" | ||
16 | #include "gwps.h" | ||
17 | #include "gwps-common.h" | ||
18 | #include "audio.h" | ||
19 | #include "usb.h" | ||
20 | #include "status.h" | ||
21 | #include "main_menu.h" | ||
22 | #include "ata.h" | ||
23 | #include "screens.h" | ||
24 | #include "playlist.h" | ||
25 | #ifdef HAVE_LCD_BITMAP | ||
26 | #include "icons.h" | ||
27 | #include "peakmeter.h" | ||
28 | #endif | ||
29 | #include "action.h" | ||
30 | #include "lang.h" | ||
31 | #include "bookmark.h" | ||
32 | #include "misc.h" | ||
33 | #include "sound.h" | ||
34 | #include "onplay.h" | ||
35 | #include "abrepeat.h" | ||
36 | #include "playback.h" | ||
37 | |||
38 | #include "statusbar.h" | ||
39 | #include "splash.h" | ||
40 | |||
41 | #define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps" | ||
42 | #define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps" | ||
43 | /* currently only on wps_state is needed */ | ||
44 | struct wps_state wps_state; | ||
45 | struct gui_syncwps gui_syncwps; | ||
46 | struct wps_data wps_datas[NB_SCREENS]; | ||
47 | |||
48 | bool keys_locked = false; | ||
49 | |||
50 | long gui_wps_show() | ||
51 | { | ||
52 | long button = 0, lastbutton = 0; | ||
53 | bool ignore_keyup = true; | ||
54 | bool restore = false; | ||
55 | long restoretimer = 0; /* timer to delay screen redraw temporarily */ | ||
56 | bool exit = false; | ||
57 | bool update_track = false; | ||
58 | unsigned long right_lastclick = 0; | ||
59 | unsigned long left_lastclick = 0; | ||
60 | int i; | ||
61 | |||
62 | wps_state_init(); | ||
63 | |||
64 | #ifdef HAVE_LCD_CHARCELLS | ||
65 | status_set_audio(true); | ||
66 | status_set_param(false); | ||
67 | #else | ||
68 | FOR_NB_SCREENS(i) | ||
69 | { | ||
70 | if(global_settings.statusbar) | ||
71 | gui_syncwps.gui_wps[i].display->setmargins(0, STATUSBAR_HEIGHT); | ||
72 | else | ||
73 | gui_syncwps.gui_wps[i].display->setmargins(0, 0); | ||
74 | } | ||
75 | #endif | ||
76 | |||
77 | #ifdef AB_REPEAT_ENABLE | ||
78 | ab_repeat_init(); | ||
79 | ab_reset_markers(); | ||
80 | #endif | ||
81 | |||
82 | if(audio_status() & AUDIO_STATUS_PLAY) | ||
83 | { | ||
84 | wps_state.id3 = audio_current_track(); | ||
85 | wps_state.nid3 = audio_next_track(); | ||
86 | if (wps_state.id3) { | ||
87 | if (gui_wps_display()) | ||
88 | return 0; | ||
89 | FOR_NB_SCREENS(i) | ||
90 | gui_wps_refresh(&gui_syncwps.gui_wps[i], 0, WPS_REFRESH_ALL); | ||
91 | wps_state_update_ctp(wps_state.id3->path); | ||
92 | } | ||
93 | |||
94 | restore = true; | ||
95 | } | ||
96 | while ( 1 ) | ||
97 | { | ||
98 | bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false; | ||
99 | |||
100 | /* did someone else (i.e power thread) change audio pause mode? */ | ||
101 | if (wps_state.paused != audio_paused) { | ||
102 | wps_state.paused = audio_paused; | ||
103 | |||
104 | /* if another thread paused audio, we are probably in car mode, | ||
105 | about to shut down. lets save the settings. */ | ||
106 | if (wps_state.paused) { | ||
107 | settings_save(); | ||
108 | #if !defined(HAVE_RTC) && !defined(HAVE_SW_POWEROFF) | ||
109 | ata_flush(); | ||
110 | #endif | ||
111 | } | ||
112 | } | ||
113 | |||
114 | #ifdef HAVE_LCD_BITMAP | ||
115 | /* when the peak meter is enabled we want to have a | ||
116 | few extra updates to make it look smooth. On the | ||
117 | other hand we don't want to waste energy if it | ||
118 | isn't displayed */ | ||
119 | bool pm=false; | ||
120 | FOR_NB_SCREENS(i) | ||
121 | { | ||
122 | if(gui_syncwps.gui_wps[i].data->peak_meter_enabled) | ||
123 | pm = true; | ||
124 | } | ||
125 | |||
126 | if (pm) { | ||
127 | long next_refresh = current_tick; | ||
128 | long next_big_refresh = current_tick + HZ / 5; | ||
129 | button = BUTTON_NONE; | ||
130 | while (TIME_BEFORE(current_tick, next_big_refresh)) { | ||
131 | button = button_get(false); | ||
132 | if (button != BUTTON_NONE) { | ||
133 | break; | ||
134 | } | ||
135 | peak_meter_peek(); | ||
136 | sleep(0); /* Sleep until end of current tick. */ | ||
137 | |||
138 | if (TIME_AFTER(current_tick, next_refresh)) { | ||
139 | FOR_NB_SCREENS(i) | ||
140 | gui_wps_refresh(&gui_syncwps.gui_wps[i], 0, WPS_REFRESH_PEAK_METER); | ||
141 | next_refresh += HZ / PEAK_METER_FPS; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | } | ||
146 | |||
147 | /* The peak meter is disabled | ||
148 | -> no additional screen updates needed */ | ||
149 | else { | ||
150 | button = button_get_w_tmo(HZ/5); | ||
151 | } | ||
152 | #else | ||
153 | button = button_get_w_tmo(HZ/5); | ||
154 | #endif | ||
155 | |||
156 | /* discard first event if it's a button release */ | ||
157 | if (button && ignore_keyup) | ||
158 | { | ||
159 | ignore_keyup = false; | ||
160 | /* Negative events are system events */ | ||
161 | if (button >= 0 && button & BUTTON_REL ) | ||
162 | continue; | ||
163 | } | ||
164 | |||
165 | #ifdef WPS_KEYLOCK | ||
166 | /* ignore non-remote buttons when keys are locked */ | ||
167 | if (keys_locked && | ||
168 | ! ((button < 0) || | ||
169 | (button == BUTTON_NONE) || | ||
170 | ((button & WPS_KEYLOCK) == WPS_KEYLOCK) || | ||
171 | (button & BUTTON_REMOTE) | ||
172 | )) | ||
173 | { | ||
174 | if (!(button & BUTTON_REL)) | ||
175 | display_keylock_text(true); | ||
176 | restore = true; | ||
177 | button = BUTTON_NONE; | ||
178 | } | ||
179 | #endif | ||
180 | |||
181 | /* Exit if audio has stopped playing. This can happen if using the | ||
182 | sleep timer with the charger plugged or if starting a recording | ||
183 | from F1 */ | ||
184 | if (!audio_status()) | ||
185 | exit = true; | ||
186 | |||
187 | switch(button) | ||
188 | { | ||
189 | #ifdef WPS_CONTEXT | ||
190 | case WPS_CONTEXT: | ||
191 | #ifdef WPS_RC_CONTEXT | ||
192 | case WPS_RC_CONTEXT: | ||
193 | #endif | ||
194 | onplay(wps_state.id3->path, TREE_ATTR_MPA, CONTEXT_WPS); | ||
195 | restore = true; | ||
196 | break; | ||
197 | #endif | ||
198 | |||
199 | #ifdef WPS_RC_BROWSE | ||
200 | case WPS_RC_BROWSE: | ||
201 | #endif | ||
202 | case WPS_BROWSE: | ||
203 | #ifdef WPS_BROWSE_PRE | ||
204 | if ((lastbutton != WPS_BROWSE_PRE) | ||
205 | #ifdef WPS_RC_BROWSE_PRE | ||
206 | && (lastbutton != WPS_RC_BROWSE_PRE) | ||
207 | #endif | ||
208 | ) | ||
209 | break; | ||
210 | #endif | ||
211 | #ifdef HAVE_LCD_CHARCELLS | ||
212 | status_set_record(false); | ||
213 | status_set_audio(false); | ||
214 | #endif | ||
215 | FOR_NB_SCREENS(i) | ||
216 | gui_syncwps.gui_wps[i].display->stop_scroll(); | ||
217 | |||
218 | /* set dir browser to current playing song */ | ||
219 | if (global_settings.browse_current && | ||
220 | wps_state.current_track_path[0] != '\0') | ||
221 | set_current_file(wps_state.current_track_path); | ||
222 | |||
223 | return 0; | ||
224 | break; | ||
225 | |||
226 | /* play/pause */ | ||
227 | case WPS_PAUSE: | ||
228 | #ifdef WPS_PAUSE_PRE | ||
229 | if (lastbutton != WPS_PAUSE_PRE) | ||
230 | break; | ||
231 | #endif | ||
232 | #ifdef WPS_RC_PAUSE | ||
233 | case WPS_RC_PAUSE: | ||
234 | #ifdef WPS_RC_PAUSE_PRE | ||
235 | if ((button == WPS_RC_PAUSE) && (lastbutton != WPS_RC_PAUSE_PRE)) | ||
236 | break; | ||
237 | #endif | ||
238 | #endif | ||
239 | if ( wps_state.paused ) | ||
240 | { | ||
241 | wps_state.paused = false; | ||
242 | if ( global_settings.fade_on_stop ) | ||
243 | fade(1); | ||
244 | else | ||
245 | audio_resume(); | ||
246 | } | ||
247 | else | ||
248 | { | ||
249 | wps_state.paused = true; | ||
250 | if ( global_settings.fade_on_stop ) | ||
251 | fade(0); | ||
252 | else | ||
253 | audio_pause(); | ||
254 | settings_save(); | ||
255 | #if !defined(HAVE_RTC) && !defined(HAVE_SW_POWEROFF) | ||
256 | ata_flush(); /* make sure resume info is saved */ | ||
257 | #endif | ||
258 | } | ||
259 | break; | ||
260 | |||
261 | /* volume up */ | ||
262 | case WPS_INCVOL: | ||
263 | case WPS_INCVOL | BUTTON_REPEAT: | ||
264 | #ifdef WPS_RC_INCVOL | ||
265 | case WPS_RC_INCVOL: | ||
266 | case WPS_RC_INCVOL | BUTTON_REPEAT: | ||
267 | #endif | ||
268 | global_settings.volume++; | ||
269 | if (setvol()) { | ||
270 | restore = true; | ||
271 | restoretimer = current_tick + HZ; | ||
272 | } | ||
273 | break; | ||
274 | |||
275 | /* volume down */ | ||
276 | case WPS_DECVOL: | ||
277 | case WPS_DECVOL | BUTTON_REPEAT: | ||
278 | #ifdef WPS_RC_DECVOL | ||
279 | case WPS_RC_DECVOL: | ||
280 | case WPS_RC_DECVOL | BUTTON_REPEAT: | ||
281 | #endif | ||
282 | global_settings.volume--; | ||
283 | if (setvol()) { | ||
284 | restore = true; | ||
285 | restoretimer = current_tick + HZ; | ||
286 | } | ||
287 | break; | ||
288 | |||
289 | /* fast forward / rewind */ | ||
290 | #ifdef WPS_RC_FFWD | ||
291 | case WPS_RC_FFWD: | ||
292 | #endif | ||
293 | case WPS_FFWD: | ||
294 | #ifdef WPS_NEXT_DIR | ||
295 | if (current_tick - right_lastclick < HZ) | ||
296 | { | ||
297 | audio_next_dir(); | ||
298 | right_lastclick = 0; | ||
299 | break; | ||
300 | } | ||
301 | #endif | ||
302 | #ifdef WPS_RC_REW | ||
303 | case WPS_RC_REW: | ||
304 | #endif | ||
305 | case WPS_REW: | ||
306 | #ifdef WPS_PREV_DIR | ||
307 | if (current_tick - left_lastclick < HZ) | ||
308 | { | ||
309 | audio_prev_dir(); | ||
310 | left_lastclick = 0; | ||
311 | break; | ||
312 | } | ||
313 | #endif | ||
314 | ffwd_rew(button); | ||
315 | break; | ||
316 | |||
317 | /* prev / restart */ | ||
318 | case WPS_PREV: | ||
319 | #ifdef WPS_PREV_PRE | ||
320 | if (lastbutton != WPS_PREV_PRE) | ||
321 | break; | ||
322 | #endif | ||
323 | #ifdef WPS_RC_PREV | ||
324 | case WPS_RC_PREV: | ||
325 | #ifdef WPS_RC_PREV_PRE | ||
326 | if ((button == WPS_RC_PREV) && (lastbutton != WPS_RC_PREV_PRE)) | ||
327 | break; | ||
328 | #endif | ||
329 | #endif | ||
330 | left_lastclick = current_tick; | ||
331 | update_track = true; | ||
332 | |||
333 | #ifdef AB_REPEAT_ENABLE | ||
334 | /* if we're in A/B repeat mode and the current position | ||
335 | is past the A marker, jump back to the A marker... */ | ||
336 | if ( ab_repeat_mode_enabled() && ab_after_A_marker(wps_state.id3->elapsed) ) | ||
337 | { | ||
338 | ab_jump_to_A_marker(); | ||
339 | break; | ||
340 | } | ||
341 | /* ...otherwise, do it normally */ | ||
342 | #endif | ||
343 | |||
344 | if (!wps_state.id3 || (wps_state.id3->elapsed < 3*1000)) { | ||
345 | audio_prev(); | ||
346 | } | ||
347 | else { | ||
348 | if (!wps_state.paused) | ||
349 | audio_pause(); | ||
350 | |||
351 | audio_ff_rewind(0); | ||
352 | |||
353 | if (!wps_state.paused) | ||
354 | audio_resume(); | ||
355 | } | ||
356 | break; | ||
357 | |||
358 | #ifdef WPS_NEXT_DIR | ||
359 | #ifdef WPS_RC_NEXT_DIR | ||
360 | case WPS_RC_NEXT_DIR: | ||
361 | #endif | ||
362 | case WPS_NEXT_DIR: | ||
363 | audio_next_dir(); | ||
364 | break; | ||
365 | #endif | ||
366 | #ifdef WPS_PREV_DIR | ||
367 | #ifdef WPS_RC_PREV_DIR | ||
368 | case WPS_RC_PREV_DIR: | ||
369 | #endif | ||
370 | case WPS_PREV_DIR: | ||
371 | audio_prev_dir(); | ||
372 | break; | ||
373 | #endif | ||
374 | |||
375 | /* next */ | ||
376 | case WPS_NEXT: | ||
377 | #ifdef WPS_NEXT_PRE | ||
378 | if (lastbutton != WPS_NEXT_PRE) | ||
379 | break; | ||
380 | #endif | ||
381 | #ifdef WPS_RC_NEXT | ||
382 | case WPS_RC_NEXT: | ||
383 | #ifdef WPS_RC_NEXT_PRE | ||
384 | if ((button == WPS_RC_NEXT) && (lastbutton != WPS_RC_NEXT_PRE)) | ||
385 | break; | ||
386 | #endif | ||
387 | #endif | ||
388 | right_lastclick = current_tick; | ||
389 | update_track = true; | ||
390 | |||
391 | #ifdef AB_REPEAT_ENABLE | ||
392 | /* if we're in A/B repeat mode and the current position is | ||
393 | before the A marker, jump to the A marker... */ | ||
394 | if ( ab_repeat_mode_enabled() && ab_before_A_marker(wps_state.id3->elapsed) ) | ||
395 | { | ||
396 | ab_jump_to_A_marker(); | ||
397 | break; | ||
398 | } | ||
399 | /* ...otherwise, do it normally */ | ||
400 | #endif | ||
401 | |||
402 | audio_next(); | ||
403 | break; | ||
404 | |||
405 | #ifdef WPS_MENU | ||
406 | /* menu key functions */ | ||
407 | case WPS_MENU: | ||
408 | #ifdef WPS_MENU_PRE | ||
409 | if (lastbutton != WPS_MENU_PRE) | ||
410 | break; | ||
411 | #endif | ||
412 | #ifdef WPS_RC_MENU | ||
413 | case WPS_RC_MENU: | ||
414 | #ifdef WPS_RC_MENU_PRE | ||
415 | if ((button == WPS_RC_MENU) && (lastbutton != WPS_RC_MENU_PRE)) | ||
416 | break; | ||
417 | #endif | ||
418 | #endif | ||
419 | FOR_NB_SCREENS(i) | ||
420 | gui_syncwps.gui_wps[i].display->stop_scroll(); | ||
421 | |||
422 | if (main_menu()) | ||
423 | return true; | ||
424 | #ifdef HAVE_LCD_BITMAP | ||
425 | FOR_NB_SCREENS(i) | ||
426 | { | ||
427 | if(global_settings.statusbar) | ||
428 | gui_syncwps.gui_wps[i].display->setmargins(0, STATUSBAR_HEIGHT); | ||
429 | else | ||
430 | gui_syncwps.gui_wps[i].display->setmargins(0, 0); | ||
431 | } | ||
432 | #endif | ||
433 | restore = true; | ||
434 | break; | ||
435 | #endif /* WPS_MENU */ | ||
436 | |||
437 | #ifdef WPS_KEYLOCK | ||
438 | /* key lock */ | ||
439 | case WPS_KEYLOCK: | ||
440 | case WPS_KEYLOCK | BUTTON_REPEAT: | ||
441 | keys_locked = !keys_locked; | ||
442 | display_keylock_text(keys_locked); | ||
443 | restore = true; | ||
444 | waitfor_nokey(); | ||
445 | break; | ||
446 | #endif | ||
447 | |||
448 | #if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD) | ||
449 | /* play settings */ | ||
450 | case WPS_QUICK: | ||
451 | #ifdef WPS_RC_QUICK | ||
452 | case WPS_RC_QUICK: | ||
453 | #endif | ||
454 | if (quick_screen(CONTEXT_WPS, WPS_QUICK)) | ||
455 | return SYS_USB_CONNECTED; | ||
456 | restore = true; | ||
457 | lastbutton = 0; | ||
458 | break; | ||
459 | |||
460 | /* screen settings */ | ||
461 | #ifdef BUTTON_F3 | ||
462 | case BUTTON_F3: | ||
463 | if (quick_screen(CONTEXT_WPS, BUTTON_F3)) | ||
464 | return SYS_USB_CONNECTED; | ||
465 | restore = true; | ||
466 | break; | ||
467 | #endif | ||
468 | |||
469 | /* pitch screen */ | ||
470 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
471 | case BUTTON_ON | BUTTON_UP: | ||
472 | case BUTTON_ON | BUTTON_DOWN: | ||
473 | if (2 == pitch_screen()) | ||
474 | return SYS_USB_CONNECTED; | ||
475 | restore = true; | ||
476 | break; | ||
477 | #endif | ||
478 | #endif | ||
479 | |||
480 | #ifdef AB_REPEAT_ENABLE | ||
481 | |||
482 | #ifdef WPS_AB_SET_A_MARKER | ||
483 | /* set A marker for A-B repeat */ | ||
484 | case WPS_AB_SET_A_MARKER: | ||
485 | if (ab_repeat_mode_enabled()) | ||
486 | ab_set_A_marker(wps_state.id3->elapsed); | ||
487 | break; | ||
488 | #endif | ||
489 | |||
490 | #ifdef WPS_AB_SET_B_MARKER | ||
491 | /* set B marker for A-B repeat and jump to A */ | ||
492 | case WPS_AB_SET_B_MARKER: | ||
493 | if (ab_repeat_mode_enabled()) | ||
494 | { | ||
495 | ab_set_B_marker(wps_state.id3->elapsed); | ||
496 | ab_jump_to_A_marker(); | ||
497 | update_track = true; | ||
498 | } | ||
499 | break; | ||
500 | #endif | ||
501 | |||
502 | #ifdef WPS_AB_RESET_AB_MARKERS | ||
503 | /* reset A&B markers */ | ||
504 | case WPS_AB_RESET_AB_MARKERS: | ||
505 | if (ab_repeat_mode_enabled()) | ||
506 | { | ||
507 | ab_reset_markers(); | ||
508 | update_track = true; | ||
509 | } | ||
510 | break; | ||
511 | #endif | ||
512 | |||
513 | #endif /* AB_REPEAT_ENABLE */ | ||
514 | |||
515 | /* stop and exit wps */ | ||
516 | #ifdef WPS_EXIT | ||
517 | case WPS_EXIT: | ||
518 | # ifdef WPS_EXIT_PRE | ||
519 | if (lastbutton != WPS_EXIT_PRE) | ||
520 | break; | ||
521 | # endif | ||
522 | exit = true; | ||
523 | #ifdef WPS_RC_EXIT | ||
524 | case WPS_RC_EXIT: | ||
525 | #ifdef WPS_RC_EXIT_PRE | ||
526 | if (lastbutton != WPS_RC_EXIT_PRE) | ||
527 | break; | ||
528 | #endif | ||
529 | exit = true; | ||
530 | #endif | ||
531 | break; | ||
532 | #endif | ||
533 | |||
534 | #ifdef WPS_ID3 | ||
535 | case WPS_ID3: | ||
536 | browse_id3(); | ||
537 | restore = true; | ||
538 | break; | ||
539 | #endif | ||
540 | |||
541 | case BUTTON_NONE: /* Timeout */ | ||
542 | update_track = true; | ||
543 | break; | ||
544 | |||
545 | default: | ||
546 | if(default_event_handler(button) == SYS_USB_CONNECTED) | ||
547 | return SYS_USB_CONNECTED; | ||
548 | update_track = true; | ||
549 | break; | ||
550 | } | ||
551 | |||
552 | if (update_track) | ||
553 | { | ||
554 | bool upt = false; | ||
555 | FOR_NB_SCREENS(i){ | ||
556 | if(update(&gui_syncwps.gui_wps[i])) | ||
557 | upt = true; | ||
558 | } | ||
559 | if (upt) | ||
560 | { | ||
561 | /* set dir browser to current playing song */ | ||
562 | if (global_settings.browse_current && | ||
563 | wps_state.current_track_path[0] != '\0') | ||
564 | set_current_file(wps_state.current_track_path); | ||
565 | |||
566 | return 0; | ||
567 | } | ||
568 | update_track = false; | ||
569 | } | ||
570 | |||
571 | if (exit) { | ||
572 | #ifdef HAVE_LCD_CHARCELLS | ||
573 | status_set_record(false); | ||
574 | status_set_audio(false); | ||
575 | #endif | ||
576 | if (global_settings.fade_on_stop) | ||
577 | fade(0); | ||
578 | |||
579 | FOR_NB_SCREENS(i) | ||
580 | gui_syncwps.gui_wps[i].display->stop_scroll(); | ||
581 | bookmark_autobookmark(); | ||
582 | audio_stop(); | ||
583 | #ifdef AB_REPEAT_ENABLE | ||
584 | ab_reset_markers(); | ||
585 | #endif | ||
586 | |||
587 | /* Keys can be locked when exiting, so either unlock here | ||
588 | or implement key locking in tree.c too */ | ||
589 | keys_locked=false; | ||
590 | |||
591 | /* set dir browser to current playing song */ | ||
592 | if (global_settings.browse_current && | ||
593 | wps_state.current_track_path[0] != '\0') | ||
594 | set_current_file(wps_state.current_track_path); | ||
595 | |||
596 | return 0; | ||
597 | } | ||
598 | |||
599 | if ( button ) | ||
600 | ata_spin(); | ||
601 | |||
602 | if (restore && | ||
603 | ((restoretimer == 0) || | ||
604 | (restoretimer < current_tick))) | ||
605 | { | ||
606 | restore = false; | ||
607 | restoretimer = 0; | ||
608 | if (gui_wps_display()) | ||
609 | { | ||
610 | /* set dir browser to current playing song */ | ||
611 | if (global_settings.browse_current && | ||
612 | wps_state.current_track_path[0] != '\0') | ||
613 | set_current_file(wps_state.current_track_path); | ||
614 | |||
615 | return 0; | ||
616 | } | ||
617 | |||
618 | if (wps_state.id3){ | ||
619 | FOR_NB_SCREENS(i) | ||
620 | gui_wps_refresh(&gui_syncwps.gui_wps[i], 0, WPS_REFRESH_NON_STATIC); | ||
621 | } | ||
622 | } | ||
623 | if (button != BUTTON_NONE) | ||
624 | lastbutton = button; | ||
625 | } | ||
626 | return 0; /* unreachable - just to reduce compiler warnings */ | ||
627 | } | ||
628 | |||
629 | /* needs checking if needed end*/ | ||
630 | |||
631 | /* wps_data*/ | ||
632 | /* initial setup of wps_data */ | ||
633 | void wps_data_init(struct wps_data *wps_data) | ||
634 | { | ||
635 | int i; | ||
636 | #ifdef HAVE_LCD_BITMAP | ||
637 | for (i = 0; i < MAX_IMAGES; i++) { | ||
638 | wps_data->img[i].loaded = false; | ||
639 | wps_data->img[i].display = false; | ||
640 | wps_data->img[i].always_display = false; | ||
641 | } | ||
642 | #else /* HAVE_LCD_CHARCELLS */ | ||
643 | for(i = 0; i < 8; i++) | ||
644 | wps_data->wps_progress_pat[i] = 0; | ||
645 | wps_data->full_line_progressbar = 0; | ||
646 | #endif | ||
647 | wps_data->format_buffer[0] = '\0'; | ||
648 | wps_data->wps_loaded = false; | ||
649 | wps_data->peak_meter_enabled = false; | ||
650 | } | ||
651 | |||
652 | #ifdef HAVE_LCD_BITMAP | ||
653 | /* Clear the WPS image cache */ | ||
654 | static void wps_clear(struct wps_data *data ) | ||
655 | { | ||
656 | int i; | ||
657 | /* set images to unloaded and not displayed */ | ||
658 | for (i = 0; i < MAX_IMAGES; i++) { | ||
659 | data->img[i].loaded = false; | ||
660 | data->img[i].display = false; | ||
661 | data->img[i].always_display = false; | ||
662 | } | ||
663 | } | ||
664 | #else | ||
665 | #define wps_clear(a) | ||
666 | #endif | ||
667 | |||
668 | static void wps_reset(struct wps_data *data) | ||
669 | { | ||
670 | data->wps_loaded = false; | ||
671 | memset(&data->format_buffer, 0, sizeof data->format_buffer); | ||
672 | wps_clear(data); | ||
673 | } | ||
674 | |||
675 | /* to setup up the wps-data from a format-buffer (isfile = false) | ||
676 | from a (wps-)file (isfile = true)*/ | ||
677 | bool wps_data_load(struct wps_data *wps_data, const char *buf, bool isfile, bool display) | ||
678 | { | ||
679 | int i, s; | ||
680 | int fd; | ||
681 | if(!wps_data || !buf) return false; | ||
682 | if(!isfile) | ||
683 | { | ||
684 | wps_clear(wps_data); | ||
685 | strncpy(wps_data->format_buffer, buf, sizeof(wps_data->format_buffer)); | ||
686 | wps_data->format_buffer[sizeof(wps_data->format_buffer) - 1] = 0; | ||
687 | gui_wps_format(wps_data, NULL, 0); | ||
688 | return true; | ||
689 | } | ||
690 | else | ||
691 | { | ||
692 | /* | ||
693 | * Hardcode loading WPS_DEFAULTCFG to cause a reset ideally this | ||
694 | * wants to be a virtual file. Feel free to modify dirbrowse() | ||
695 | * if you're feeling brave. | ||
696 | */ | ||
697 | if (! strcmp(buf, WPS_DEFAULTCFG) || !strcmp(buf, RWPS_DEFAULTCFG) ) { | ||
698 | wps_reset(wps_data); | ||
699 | return false; | ||
700 | } | ||
701 | size_t bmpdirlen; | ||
702 | char *bmpdir = strrchr(buf, '.'); | ||
703 | bmpdirlen = bmpdir - buf; | ||
704 | |||
705 | fd = open(buf, O_RDONLY); | ||
706 | |||
707 | if (fd >= 0) | ||
708 | { | ||
709 | int numread = read(fd, wps_data->format_buffer, sizeof(wps_data->format_buffer) - 1); | ||
710 | |||
711 | if (numread > 0) | ||
712 | { | ||
713 | #ifdef HAVE_LCD_BITMAP | ||
714 | wps_clear(wps_data); | ||
715 | #endif | ||
716 | wps_data->format_buffer[numread] = 0; | ||
717 | gui_wps_format(wps_data, buf, bmpdirlen); | ||
718 | } | ||
719 | |||
720 | close(fd); | ||
721 | |||
722 | if ( display ) { | ||
723 | bool any_defined_line; | ||
724 | int z; | ||
725 | FOR_NB_SCREENS(z) | ||
726 | screens[z].clear_display(); | ||
727 | #ifdef HAVE_LCD_BITMAP | ||
728 | FOR_NB_SCREENS(z) | ||
729 | screens[z].setmargins(0,0); | ||
730 | #endif | ||
731 | for (s=0; s<WPS_MAX_SUBLINES; s++) | ||
732 | { | ||
733 | any_defined_line = false; | ||
734 | for (i=0; i<WPS_MAX_LINES; i++) | ||
735 | { | ||
736 | if (wps_data->format_lines[i][s]) | ||
737 | { | ||
738 | if (*(wps_data->format_lines[i][s]) == 0) | ||
739 | { | ||
740 | FOR_NB_SCREENS(z) | ||
741 | screens[z].puts(0,i," "); | ||
742 | } | ||
743 | else | ||
744 | { | ||
745 | FOR_NB_SCREENS(z) | ||
746 | screens[z].puts(0,i,wps_data->format_lines[i][s]); | ||
747 | } | ||
748 | any_defined_line = true; | ||
749 | } | ||
750 | else | ||
751 | { | ||
752 | FOR_NB_SCREENS(z) | ||
753 | screens[z].puts(0,i," "); | ||
754 | } | ||
755 | } | ||
756 | if (any_defined_line) | ||
757 | { | ||
758 | #ifdef HAVE_LCD_BITMAP | ||
759 | FOR_NB_SCREENS(z) | ||
760 | screens[z].update(); | ||
761 | #endif | ||
762 | sleep(HZ/2); | ||
763 | } | ||
764 | } | ||
765 | } | ||
766 | wps_data->wps_loaded = true; | ||
767 | |||
768 | return numread > 0; | ||
769 | } | ||
770 | } | ||
771 | |||
772 | return false; | ||
773 | } | ||
774 | |||
775 | /* wps_data end */ | ||
776 | |||
777 | /* wps_state */ | ||
778 | struct wps_state wps_state; | ||
779 | |||
780 | void wps_state_init(void) | ||
781 | { | ||
782 | wps_state.ff_rewind = false; | ||
783 | wps_state.paused = false; | ||
784 | wps_state.id3 = NULL; | ||
785 | wps_state.nid3 = NULL; | ||
786 | wps_state.current_track_path[0] = '\0'; | ||
787 | } | ||
788 | void wps_state_update_ff_rew(bool ff_rew) | ||
789 | { | ||
790 | wps_state.ff_rewind = ff_rew; | ||
791 | } | ||
792 | void wps_state_update_paused(bool paused) | ||
793 | { | ||
794 | wps_state.paused = paused; | ||
795 | } | ||
796 | void wps_state_update_ctp(const char *path) | ||
797 | { | ||
798 | memcpy(wps_state.current_track_path, path, sizeof(wps_state.current_track_path)); | ||
799 | } | ||
800 | void wps_state_update_id3_nid3(struct mp3entry *id3, struct mp3entry *nid3) | ||
801 | { | ||
802 | wps_state.id3 = id3; | ||
803 | wps_state.nid3 = nid3; | ||
804 | } | ||
805 | /* wps_state end*/ | ||
806 | |||
807 | /* initial setup of a wps */ | ||
808 | void gui_wps_init(struct gui_wps *gui_wps) | ||
809 | { | ||
810 | gui_wps->data = NULL; | ||
811 | gui_wps->display = NULL; | ||
812 | /* Currently no seperate wps_state needed/possible | ||
813 | so use the only aviable ( "global" ) one */ | ||
814 | gui_wps->state = &wps_state; | ||
815 | } | ||
816 | |||
817 | /* connects a wps with a format-description of the displayed content */ | ||
818 | void gui_wps_set_data(struct gui_wps *gui_wps, struct wps_data *data) | ||
819 | { | ||
820 | gui_wps->data = data; | ||
821 | } | ||
822 | |||
823 | /* connects a wps with a screen */ | ||
824 | void gui_wps_set_disp(struct gui_wps *gui_wps, struct screen *display) | ||
825 | { | ||
826 | gui_wps->display = display; | ||
827 | } | ||
828 | /* gui_wps end */ | ||
829 | |||
830 | void gui_sync_data_wps_init(void) | ||
831 | { | ||
832 | int i; | ||
833 | FOR_NB_SCREENS(i) | ||
834 | wps_data_init(&wps_datas[i]); | ||
835 | } | ||
836 | |||
837 | void gui_sync_wps_screen_init(void) | ||
838 | { | ||
839 | int i; | ||
840 | FOR_NB_SCREENS(i) | ||
841 | gui_wps_set_disp(&gui_syncwps.gui_wps[i], &screens[i]); | ||
842 | } | ||
843 | |||
844 | void gui_sync_wps_init(void) | ||
845 | { | ||
846 | int i; | ||
847 | FOR_NB_SCREENS(i) | ||
848 | { | ||
849 | gui_wps_init(&gui_syncwps.gui_wps[i]); | ||
850 | gui_wps_set_data(&gui_syncwps.gui_wps[i], &wps_datas[i]); | ||
851 | } | ||
852 | } | ||
853 | |||