blob: d752cb3da58544509347e9662aea730036e92de3 [file] [log] [blame]
Daniel Stenberg09fce702005-11-18 09:03:25 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Jerome Kuptz
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Daniel Stenberg09fce702005-11-18 09:03:25 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Christi Scarboroughf8cc3212005-11-17 20:20:01 +000021#include <stdio.h>
22#include <string.h>
23#include <stdlib.h>
Jonathan Gordon5e5bfab2006-08-16 13:25:45 +000024#include "config.h"
Christi Scarboroughf8cc3212005-11-17 20:20:01 +000025
26#include "system.h"
27#include "file.h"
28#include "lcd.h"
29#include "font.h"
30#include "backlight.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000031#include "action.h"
Christi Scarboroughf8cc3212005-11-17 20:20:01 +000032#include "kernel.h"
Jonathan Gordon36a2e302007-04-18 13:03:01 +000033#include "filetypes.h"
Christi Scarboroughf8cc3212005-11-17 20:20:01 +000034#include "debug.h"
35#include "sprintf.h"
36#include "settings.h"
37#include "gwps.h"
38#include "gwps-common.h"
39#include "audio.h"
40#include "usb.h"
41#include "status.h"
Christi Scarboroughf8cc3212005-11-17 20:20:01 +000042#include "ata.h"
43#include "screens.h"
44#include "playlist.h"
45#ifdef HAVE_LCD_BITMAP
46#include "icons.h"
47#include "peakmeter.h"
48#endif
49#include "action.h"
50#include "lang.h"
51#include "bookmark.h"
52#include "misc.h"
53#include "sound.h"
54#include "onplay.h"
55#include "abrepeat.h"
56#include "playback.h"
Christi Scarboroughf8cc3212005-11-17 20:20:01 +000057#include "splash.h"
Nicolas Pennequin9f4bd872007-02-14 14:40:24 +000058#include "cuesheet.h"
Jonathan Gordond9f7ac22006-11-08 02:23:01 +000059#include "ata_idle_notify.h"
Jonathan Gordon91cb68a2007-03-01 11:14:46 +000060#include "root_menu.h"
Nicolas Pennequin1cf2ec32007-04-25 22:08:00 +000061#include "backdrop.h"
Jonathan Gordonea664e02008-05-03 12:30:40 +000062#include "quickscreen.h"
Nicolas Pennequin1cf2ec32007-04-25 22:08:00 +000063
Christi Scarboroughf8cc3212005-11-17 20:20:01 +000064/* currently only on wps_state is needed */
65struct wps_state wps_state;
Daniel Stenberg09fce702005-11-18 09:03:25 +000066struct gui_wps gui_wps[NB_SCREENS];
67static struct wps_data wps_datas[NB_SCREENS];
Christi Scarboroughf8cc3212005-11-17 20:20:01 +000068
Daniel Stenberg09fce702005-11-18 09:03:25 +000069/* change the path to the current played track */
70static void wps_state_update_ctp(const char *path);
Nils Wallménius20338ca2006-12-13 11:52:21 +000071/* initial setup of wps_data */
72static void wps_state_init(void);
73/* initial setup of a wps */
74static void gui_wps_init(struct gui_wps *gui_wps);
75/* connects a wps with a format-description of the displayed content */
76static void gui_wps_set_data(struct gui_wps *gui_wps, struct wps_data *data);
77/* connects a wps with a screen */
78static void gui_wps_set_disp(struct gui_wps *gui_wps, struct screen *display);
79/* connects a wps with a statusbar*/
80static void gui_wps_set_statusbar(struct gui_wps *gui_wps, struct gui_statusbar *statusbar);
81
Stéphane Doyonab0f7e12008-05-04 13:47:58 +000082static void prev_track(unsigned skip_thresh)
83{
84 if (!wps_state.id3 || (wps_state.id3->elapsed < skip_thresh*1000)) {
85 audio_prev();
86 }
87 else {
88 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
89 {
90 curr_cuesheet_skip(-1, wps_state.id3->elapsed);
91 return;
92 }
93
94 if (!wps_state.paused)
95#if (CONFIG_CODEC == SWCODEC)
96 audio_pre_ff_rewind();
97#else
98 audio_pause();
99#endif
100
101 audio_ff_rewind(0);
102
103#if (CONFIG_CODEC != SWCODEC)
104 if (!wps_state.paused)
105 audio_resume();
106#endif
107 }
108}
109
Bertrik Sikken7835a202008-05-08 20:37:26 +0000110static void next_track(void)
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000111{
112 /* take care of if we're playing a cuesheet */
113 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
114 {
115 if (curr_cuesheet_skip(1, wps_state.id3->elapsed))
116 {
117 /* if the result was false, then we really want
118 to skip to the next track */
119 return;
120 }
121 }
122
123 audio_next();
124}
125
126
Daniel Stenberg09fce702005-11-18 09:03:25 +0000127long gui_wps_show(void)
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000128{
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000129 long button = 0;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000130 bool restore = false;
131 long restoretimer = 0; /* timer to delay screen redraw temporarily */
132 bool exit = false;
Magnus Holmgrena50c2b12007-08-22 16:33:34 +0000133 bool bookmark = false;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000134 bool update_track = false;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000135 int i;
Jonathan Gordon89ed8552006-08-22 07:57:40 +0000136 long last_left = 0, last_right = 0;
Linus Nielsen Feltzing75765df2006-08-16 13:03:50 +0000137
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000138 wps_state_init();
139
140#ifdef HAVE_LCD_CHARCELLS
141 status_set_audio(true);
142 status_set_param(false);
143#else
Jens Arnold02978732006-11-13 00:45:21 +0000144#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000145 show_wps_backdrop();
Jens Arnold02978732006-11-13 00:45:21 +0000146#endif /* LCD_DEPTH > 1 */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000147#endif
148
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000149#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
150 show_remote_wps_backdrop();
151#endif
152
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000153#ifdef AB_REPEAT_ENABLE
154 ab_repeat_init();
155 ab_reset_markers();
156#endif
157
158 if(audio_status() & AUDIO_STATUS_PLAY)
159 {
160 wps_state.id3 = audio_current_track();
161 wps_state.nid3 = audio_next_track();
162 if (wps_state.id3) {
163 if (gui_wps_display())
164 return 0;
165 FOR_NB_SCREENS(i)
Daniel Stenberg09fce702005-11-18 09:03:25 +0000166 gui_wps_refresh(&gui_wps[i], 0, WPS_REFRESH_ALL);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000167 wps_state_update_ctp(wps_state.id3->path);
168 }
169
170 restore = true;
171 }
172 while ( 1 )
173 {
174 bool audio_paused = (audio_status() & AUDIO_STATUS_PAUSE)?true:false;
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000175
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000176 /* did someone else (i.e power thread) change audio pause mode? */
177 if (wps_state.paused != audio_paused) {
178 wps_state.paused = audio_paused;
179
180 /* if another thread paused audio, we are probably in car mode,
181 about to shut down. lets save the settings. */
182 if (wps_state.paused) {
183 settings_save();
Dave Chapman5009c9c2005-12-04 13:05:56 +0000184#if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
Jonathan Gordon4049d442006-11-26 09:53:42 +0000185 call_ata_idle_notifys(true);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000186#endif
187 }
188 }
189
190#ifdef HAVE_LCD_BITMAP
191 /* when the peak meter is enabled we want to have a
192 few extra updates to make it look smooth. On the
193 other hand we don't want to waste energy if it
194 isn't displayed */
195 bool pm=false;
196 FOR_NB_SCREENS(i)
197 {
Daniel Stenberg09fce702005-11-18 09:03:25 +0000198 if(gui_wps[i].data->peak_meter_enabled)
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000199 pm = true;
200 }
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000201
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000202 if (pm) {
203 long next_refresh = current_tick;
204 long next_big_refresh = current_tick + HZ / 5;
205 button = BUTTON_NONE;
206 while (TIME_BEFORE(current_tick, next_big_refresh)) {
Jonathan Gordonf1781312006-08-17 12:33:36 +0000207 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,TIMEOUT_NOBLOCK);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000208 if (button != ACTION_NONE) {
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000209 break;
210 }
211 peak_meter_peek();
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000212 sleep(0); /* Sleep until end of current tick. */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000213
214 if (TIME_AFTER(current_tick, next_refresh)) {
215 FOR_NB_SCREENS(i)
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000216 {
217 if(gui_wps[i].data->peak_meter_enabled)
218 gui_wps_refresh(&gui_wps[i], 0,
219 WPS_REFRESH_PEAK_METER);
220 next_refresh += HZ / PEAK_METER_FPS;
221 }
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000222 }
223 }
224
225 }
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000226
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000227 /* The peak meter is disabled
228 -> no additional screen updates needed */
229 else {
Jonathan Gordonf1781312006-08-17 12:33:36 +0000230 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,HZ/5);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000231 }
232#else
Jonathan Gordonf1781312006-08-17 12:33:36 +0000233 button = get_action(CONTEXT_WPS|ALLOW_SOFTLOCK,HZ/5);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000234#endif
235
236 /* Exit if audio has stopped playing. This can happen if using the
237 sleep timer with the charger plugged or if starting a recording
238 from F1 */
239 if (!audio_status())
240 exit = true;
Jonathan Gordon7258b5e2006-12-22 05:19:56 +0000241#ifdef ACTION_WPSAB_SINGLE
242 if (!global_settings.party_mode && ab_repeat_mode_enabled())
243 {
244 static int wps_ab_state = 0;
245 if (button == ACTION_WPSAB_SINGLE)
246 {
247 switch (wps_ab_state)
248 {
249 case 0: /* set the A spot */
250 button = ACTION_WPS_ABSETA_PREVDIR;
251 break;
252 case 1: /* set the B spot */
253 button = ACTION_WPS_ABSETB_NEXTDIR;
254 break;
255 case 2:
Marcoen Hirschberg5d2b1e32007-04-13 15:42:25 +0000256 button = ACTION_WPS_ABRESET;
Jonathan Gordon7258b5e2006-12-22 05:19:56 +0000257 break;
258 }
259 wps_ab_state = (wps_ab_state+1) % 3;
260 }
261 }
262#endif
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000263 switch(button)
264 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000265 case ACTION_WPS_CONTEXT:
Jens Arnold02978732006-11-13 00:45:21 +0000266#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000267 show_main_backdrop();
Dave Chapmand9e5b672006-02-02 20:42:56 +0000268#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000269#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
270 show_remote_main_backdrop();
271#endif
Jonathan Gordona6f2b822007-11-04 12:40:18 +0000272 /* if music is stopped in the context menu we want to exit the wps */
273 if (onplay(wps_state.id3->path,
274 FILE_ATTR_AUDIO, CONTEXT_WPS) == ONPLAY_MAINMENU
275 || !audio_status())
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000276 return GO_TO_ROOT;
Nicolas Pennequin523f88e2008-02-10 23:07:01 +0000277
278 /* track might have changed */
279 update_track = true;
280
Jens Arnold02978732006-11-13 00:45:21 +0000281#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000282 show_wps_backdrop();
Dave Chapmand9e5b672006-02-02 20:42:56 +0000283#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000284#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
285 show_remote_wps_backdrop();
286#endif
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000287 restore = true;
288 break;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000289
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000290 case ACTION_WPS_BROWSE:
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000291#ifdef HAVE_LCD_CHARCELLS
292 status_set_record(false);
293 status_set_audio(false);
294#endif
295 FOR_NB_SCREENS(i)
Daniel Stenberg09fce702005-11-18 09:03:25 +0000296 gui_wps[i].display->stop_scroll();
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000297 return GO_TO_PREVIOUS_BROWSER;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000298 break;
299
300 /* play/pause */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000301 case ACTION_WPS_PLAY:
Björn Stenbergfc390af2006-03-19 08:40:31 +0000302 if (global_settings.party_mode)
303 break;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000304 if ( wps_state.paused )
305 {
306 wps_state.paused = false;
307 if ( global_settings.fade_on_stop )
Jonathan Gordon4982b872008-06-23 02:45:55 +0000308 fade(true, true);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000309 else
310 audio_resume();
311 }
312 else
313 {
314 wps_state.paused = true;
315 if ( global_settings.fade_on_stop )
Jonathan Gordon4982b872008-06-23 02:45:55 +0000316 fade(false, true);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000317 else
318 audio_pause();
319 settings_save();
Dave Chapman5009c9c2005-12-04 13:05:56 +0000320#if !defined(HAVE_RTC_RAM) && !defined(HAVE_SW_POWEROFF)
Jonathan Gordon4049d442006-11-26 09:53:42 +0000321 call_ata_idle_notifys(true); /* make sure resume info is saved */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000322#endif
323 }
324 break;
325
326 /* volume up */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000327 case ACTION_WPS_VOLUP:
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000328 {
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000329 global_settings.volume++;
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000330 bool res = false;
331 setvol();
332 FOR_NB_SCREENS(i)
333 {
334 if(update_onvol_change(&gui_wps[i]))
335 res = true;
336 }
337 if (res) {
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000338 restore = true;
339 restoretimer = current_tick + HZ;
340 }
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000341 }
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000342 break;
343
344 /* volume down */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000345 case ACTION_WPS_VOLDOWN:
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000346 {
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000347 global_settings.volume--;
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000348 setvol();
349 bool res = false;
350 FOR_NB_SCREENS(i)
351 {
352 if(update_onvol_change(&gui_wps[i]))
353 res = true;
354 }
355 if (res) {
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000356 restore = true;
357 restoretimer = current_tick + HZ;
358 }
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000359 }
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000360 break;
Jonathan Gordon89ed8552006-08-22 07:57:40 +0000361 /* fast forward
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000362 OR next dir if this is straight after ACTION_WPS_SKIPNEXT
363 OR in study mode, next track if straight after SKIPPREV. */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000364 case ACTION_WPS_SEEKFWD:
Jonathan Gordon89ed8552006-08-22 07:57:40 +0000365 if (global_settings.party_mode)
366 break;
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000367 if (!global_settings.study_mode
368 && current_tick -last_right < HZ)
Nicolas Pennequin9f4bd872007-02-14 14:40:24 +0000369 {
370 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
371 {
372 audio_next();
373 }
374 else
375 {
376 audio_next_dir();
377 }
378 }
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000379 else if(global_settings.study_mode
380 && current_tick -last_left < HZ) {
381 next_track();
382 update_track = true;
383 }
Jonathan Gordon89ed8552006-08-22 07:57:40 +0000384 else ffwd_rew(ACTION_WPS_SEEKFWD);
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000385 last_right = last_left = 0;
Jonathan Gordon89ed8552006-08-22 07:57:40 +0000386 break;
387 /* fast rewind
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000388 OR prev dir if this is straight after ACTION_WPS_SKIPPREV,
389 OR in study mode, beg of track or prev track if this is
390 straight after SKIPPREV */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000391 case ACTION_WPS_SEEKBACK:
Björn Stenbergfc390af2006-03-19 08:40:31 +0000392 if (global_settings.party_mode)
393 break;
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000394 if (!global_settings.study_mode
395 && current_tick -last_left < HZ)
Nicolas Pennequin9f4bd872007-02-14 14:40:24 +0000396 {
397 if (cuesheet_is_enabled() && wps_state.id3->cuesheet_type)
398 {
399 if (!wps_state.paused)
400#if (CONFIG_CODEC == SWCODEC)
401 audio_pre_ff_rewind();
402#else
403 audio_pause();
404#endif
405 audio_ff_rewind(0);
406 }
407 else
408 {
409 audio_prev_dir();
410 }
411 }
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000412 else if(global_settings.study_mode
413 && current_tick -last_right < HZ)
414 {
415 prev_track(3+global_settings.study_hop_step);
416 update_track = true;
417 }
Jonathan Gordon89ed8552006-08-22 07:57:40 +0000418 else ffwd_rew(ACTION_WPS_SEEKBACK);
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000419 last_left = last_right = 0;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000420 break;
421
422 /* prev / restart */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000423 case ACTION_WPS_SKIPPREV:
Björn Stenbergfc390af2006-03-19 08:40:31 +0000424 if (global_settings.party_mode)
425 break;
Jonathan Gordon89ed8552006-08-22 07:57:40 +0000426 last_left = current_tick;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000427 update_track = true;
428
429#ifdef AB_REPEAT_ENABLE
430 /* if we're in A/B repeat mode and the current position
431 is past the A marker, jump back to the A marker... */
Brandon Low8d5a6602006-01-21 23:43:57 +0000432 if ( ab_repeat_mode_enabled() )
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000433 {
Brandon Low8d5a6602006-01-21 23:43:57 +0000434 if ( ab_after_A_marker(wps_state.id3->elapsed) )
435 {
436 ab_jump_to_A_marker();
437 break;
438#if (AB_REPEAT_ENABLE == 2)
439 } else {
440 ab_reset_markers();
441#endif
442 }
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000443 }
444 /* ...otherwise, do it normally */
445#endif
446
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000447 if(global_settings.study_mode)
448 play_hop(-1);
449 else prev_track(3);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000450 break;
451
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000452 /* next
453 OR in study mode, hop by predetermined amount. */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000454 case ACTION_WPS_SKIPNEXT:
Björn Stenbergfc390af2006-03-19 08:40:31 +0000455 if (global_settings.party_mode)
456 break;
Jonathan Gordon89ed8552006-08-22 07:57:40 +0000457 last_right = current_tick;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000458 update_track = true;
459
460#ifdef AB_REPEAT_ENABLE
461 /* if we're in A/B repeat mode and the current position is
462 before the A marker, jump to the A marker... */
Brandon Low8d5a6602006-01-21 23:43:57 +0000463 if ( ab_repeat_mode_enabled() )
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000464 {
Brandon Low8d5a6602006-01-21 23:43:57 +0000465 if ( ab_before_A_marker(wps_state.id3->elapsed) )
466 {
467 ab_jump_to_A_marker();
468 break;
469#if (AB_REPEAT_ENABLE == 2)
470 } else {
471 ab_reset_markers();
472#endif
473 }
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000474 }
475 /* ...otherwise, do it normally */
476#endif
Nicolas Pennequin9f4bd872007-02-14 14:40:24 +0000477
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000478 if(global_settings.study_mode)
479 play_hop(1);
480 else next_track();
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000481 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000482 /* next / prev directories */
Jonathan Gordon5e5bfab2006-08-16 13:25:45 +0000483 /* and set A-B markers if in a-b mode */
484 case ACTION_WPS_ABSETB_NEXTDIR:
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000485 if (global_settings.party_mode)
486 break;
Jonathan Gordon5e5bfab2006-08-16 13:25:45 +0000487#if defined(AB_REPEAT_ENABLE)
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000488 if (ab_repeat_mode_enabled())
489 {
490 ab_set_B_marker(wps_state.id3->elapsed);
491 ab_jump_to_A_marker();
492 update_track = true;
493 }
494 else
495#endif
496 {
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000497 if(global_settings.study_mode)
498 next_track();
499 else audio_next_dir();
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000500 }
501 break;
Jonathan Gordon5e5bfab2006-08-16 13:25:45 +0000502 case ACTION_WPS_ABSETA_PREVDIR:
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000503 if (global_settings.party_mode)
504 break;
Jonathan Gordon5e5bfab2006-08-16 13:25:45 +0000505#if defined(AB_REPEAT_ENABLE)
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000506 if (ab_repeat_mode_enabled())
507 ab_set_A_marker(wps_state.id3->elapsed);
508 else
509#endif
510 {
Stéphane Doyonab0f7e12008-05-04 13:47:58 +0000511 if(global_settings.study_mode)
512 prev_track(3);
513 else audio_prev_dir();
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000514 }
515 break;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000516 /* menu key functions */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000517 case ACTION_WPS_MENU:
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000518 FOR_NB_SCREENS(i)
Daniel Stenberg09fce702005-11-18 09:03:25 +0000519 gui_wps[i].display->stop_scroll();
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000520 return GO_TO_ROOT;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000521 break;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000522
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000523
Zakk Roberts2f943b02006-04-10 03:51:17 +0000524#ifdef HAVE_QUICKSCREEN
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000525 case ACTION_WPS_QUICKSCREEN:
Jens Arnold02978732006-11-13 00:45:21 +0000526#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000527 show_main_backdrop();
Dave Chapmand9e5b672006-02-02 20:42:56 +0000528#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000529#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
530 show_remote_main_backdrop();
531#endif
Kevin Ferraref57d0222005-11-22 21:55:05 +0000532 if (quick_screen_quick(button))
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000533 return SYS_USB_CONNECTED;
Jens Arnold02978732006-11-13 00:45:21 +0000534#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000535 show_wps_backdrop();
Dave Chapmand9e5b672006-02-02 20:42:56 +0000536#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000537#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
538 show_remote_wps_backdrop();
539#endif
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000540 restore = true;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000541 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000542#endif /* HAVE_QUICKSCREEN */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000543
544 /* screen settings */
545#ifdef BUTTON_F3
Jonathan Gordoncbcc9db2006-08-22 08:23:24 +0000546 case ACTION_F3:
Jens Arnold02978732006-11-13 00:45:21 +0000547#if LCD_DEPTH > 1
Linus Nielsen Feltzingc26a0852006-07-01 14:03:07 +0000548 show_main_backdrop();
549#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000550#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
551 show_remote_main_backdrop();
552#endif
Jonathan Gordoncbcc9db2006-08-22 08:23:24 +0000553 if (quick_screen_f3(BUTTON_F3))
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000554 return SYS_USB_CONNECTED;
555 restore = true;
556 break;
Jonathan Gordon5e5bfab2006-08-16 13:25:45 +0000557#endif /* BUTTON_F3 */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000558
559 /* pitch screen */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000560#ifdef HAVE_PITCHSCREEN
561 case ACTION_WPS_PITCHSCREEN:
Jens Arnold02978732006-11-13 00:45:21 +0000562#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000563 show_main_backdrop();
Dave Chapmand9e5b672006-02-02 20:42:56 +0000564#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000565#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
566 show_remote_main_backdrop();
567#endif
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000568 if (1 == pitch_screen())
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000569 return SYS_USB_CONNECTED;
Jens Arnold02978732006-11-13 00:45:21 +0000570#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000571 show_wps_backdrop();
Dave Chapmand9e5b672006-02-02 20:42:56 +0000572#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000573#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
574 show_remote_wps_backdrop();
575#endif
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000576 restore = true;
577 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000578#endif /* HAVE_PITCHSCREEN */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000579
580#ifdef AB_REPEAT_ENABLE
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000581 /* reset A&B markers */
Marcoen Hirschberg5d2b1e32007-04-13 15:42:25 +0000582 case ACTION_WPS_ABRESET:
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000583 if (ab_repeat_mode_enabled())
584 {
585 ab_reset_markers();
586 update_track = true;
587 }
588 break;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000589#endif /* AB_REPEAT_ENABLE */
590
591 /* stop and exit wps */
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000592 case ACTION_WPS_STOP:
Björn Stenbergfc390af2006-03-19 08:40:31 +0000593 if (global_settings.party_mode)
594 break;
Magnus Holmgrena50c2b12007-08-22 16:33:34 +0000595 bookmark = true;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000596 exit = true;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000597 break;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000598
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000599 case ACTION_WPS_ID3SCREEN:
Jens Arnold02978732006-11-13 00:45:21 +0000600#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000601 show_main_backdrop();
Linus Nielsen Feltzingab1019a2006-03-21 11:31:53 +0000602#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000603#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
604 show_remote_main_backdrop();
605#endif
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000606 browse_id3();
Jens Arnold02978732006-11-13 00:45:21 +0000607#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000608 show_wps_backdrop();
Linus Nielsen Feltzingab1019a2006-03-21 11:31:53 +0000609#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000610#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
611 show_remote_wps_backdrop();
612#endif
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000613 restore = true;
614 break;
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000615
Jonathan Gordonf1781312006-08-17 12:33:36 +0000616 case ACTION_REDRAW: /* yes are locked, just redraw */
617 restore = true;
618 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000619 case ACTION_NONE: /* Timeout */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000620 update_track = true;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000621 ffwd_rew(button); /* hopefully fix the ffw/rwd bug */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000622 break;
Jonathan Gordon73336e92007-08-02 12:13:20 +0000623#ifdef HAVE_RECORDING
624 case ACTION_WPS_REC:
625 exit = true;
626 break;
627#endif
Linus Nielsen Feltzing313cfc02005-11-18 09:43:42 +0000628 case SYS_POWEROFF:
Jens Arnold02978732006-11-13 00:45:21 +0000629#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000630 show_main_backdrop();
Peter D'Hoye9fe9a4f2006-05-01 14:24:06 +0000631#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000632#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
633 show_remote_main_backdrop();
634#endif
Linus Nielsen Feltzing313cfc02005-11-18 09:43:42 +0000635 default_event_handler(SYS_POWEROFF);
636 break;
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000637
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000638 default:
639 if(default_event_handler(button) == SYS_USB_CONNECTED)
Jonathan Gordona9a99992007-03-01 23:46:01 +0000640 return GO_TO_ROOT;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000641 update_track = true;
642 break;
643 }
644
645 if (update_track)
646 {
Daniel Stenberg09fce702005-11-18 09:03:25 +0000647 FOR_NB_SCREENS(i)
648 {
649 if(update(&gui_wps[i]))
Jens Arnold5070f412007-04-22 12:38:11 +0000650 exit = true;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000651 }
652 update_track = false;
653 }
654
Jens Arnold5070f412007-04-22 12:38:11 +0000655 if (restore &&
656 ((restoretimer == 0) ||
657 (restoretimer < current_tick)))
658 {
659 restore = false;
660 restoretimer = 0;
661 if (gui_wps_display()) {
662 exit = true;
663 }
664 else if (wps_state.id3){
665 FOR_NB_SCREENS(i)
666 gui_wps_refresh(&gui_wps[i], 0, WPS_REFRESH_NON_STATIC);
667 }
668 }
669
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000670 if (exit) {
671#ifdef HAVE_LCD_CHARCELLS
672 status_set_record(false);
673 status_set_audio(false);
674#endif
675 if (global_settings.fade_on_stop)
Jonathan Gordon4982b872008-06-23 02:45:55 +0000676 fade(false, true);
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000677
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000678 FOR_NB_SCREENS(i)
Daniel Stenberg09fce702005-11-18 09:03:25 +0000679 gui_wps[i].display->stop_scroll();
Magnus Holmgrena50c2b12007-08-22 16:33:34 +0000680 if (bookmark)
681 bookmark_autobookmark();
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000682 audio_stop();
683#ifdef AB_REPEAT_ENABLE
684 ab_reset_markers();
685#endif
Jonathan Gordon73336e92007-08-02 12:13:20 +0000686#ifdef HAVE_RECORDING
687 if (button == ACTION_WPS_REC)
688 return GO_TO_RECSCREEN;
689#endif
Jonathan Gordonfad3ad62007-04-08 02:11:33 +0000690 if (global_settings.browse_current)
691 return GO_TO_PREVIOUS_BROWSER;
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000692 return GO_TO_PREVIOUS;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000693 }
Zakk Roberts87afd0b2006-03-21 07:59:23 +0000694
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000695 if ( button )
696 ata_spin();
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000697 }
Jonathan Gordon91cb68a2007-03-01 11:14:46 +0000698 return GO_TO_ROOT; /* unreachable - just to reduce compiler warnings */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000699}
700
701/* needs checking if needed end*/
702
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000703/* wps_state */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000704
Nils Wallménius20338ca2006-12-13 11:52:21 +0000705static void wps_state_init(void)
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000706{
707 wps_state.ff_rewind = false;
708 wps_state.paused = false;
709 wps_state.id3 = NULL;
710 wps_state.nid3 = NULL;
711 wps_state.current_track_path[0] = '\0';
712}
Daniel Stenberg09fce702005-11-18 09:03:25 +0000713
714#if 0
715/* these are obviously not used? */
716
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000717void wps_state_update_ff_rew(bool ff_rew)
718{
719 wps_state.ff_rewind = ff_rew;
720}
Daniel Stenberg09fce702005-11-18 09:03:25 +0000721
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000722void wps_state_update_paused(bool paused)
723{
724 wps_state.paused = paused;
725}
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000726void wps_state_update_id3_nid3(struct mp3entry *id3, struct mp3entry *nid3)
727{
728 wps_state.id3 = id3;
729 wps_state.nid3 = nid3;
730}
Daniel Stenberg09fce702005-11-18 09:03:25 +0000731#endif
732
733static void wps_state_update_ctp(const char *path)
734{
Steve Bavin276ff3b2007-07-06 22:34:18 +0000735 strncpy(wps_state.current_track_path, path,
Daniel Stenberg09fce702005-11-18 09:03:25 +0000736 sizeof(wps_state.current_track_path));
Steve Bavin276ff3b2007-07-06 22:34:18 +0000737 wps_state.current_track_path[sizeof(wps_state.current_track_path)-1] = '\0';
Daniel Stenberg09fce702005-11-18 09:03:25 +0000738}
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000739/* wps_state end*/
740
741/* initial setup of a wps */
Nils Wallménius20338ca2006-12-13 11:52:21 +0000742static void gui_wps_init(struct gui_wps *gui_wps)
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000743{
744 gui_wps->data = NULL;
745 gui_wps->display = NULL;
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000746 gui_wps->statusbar = NULL;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000747 /* Currently no seperate wps_state needed/possible
748 so use the only aviable ( "global" ) one */
749 gui_wps->state = &wps_state;
750}
751
752/* connects a wps with a format-description of the displayed content */
Nils Wallménius20338ca2006-12-13 11:52:21 +0000753static void gui_wps_set_data(struct gui_wps *gui_wps, struct wps_data *data)
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000754{
755 gui_wps->data = data;
756}
757
758/* connects a wps with a screen */
Nils Wallménius20338ca2006-12-13 11:52:21 +0000759static void gui_wps_set_disp(struct gui_wps *gui_wps, struct screen *display)
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000760{
761 gui_wps->display = display;
762}
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000763
Nils Wallménius20338ca2006-12-13 11:52:21 +0000764static void gui_wps_set_statusbar(struct gui_wps *gui_wps, struct gui_statusbar *statusbar)
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000765{
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000766 gui_wps->statusbar = statusbar;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000767}
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000768/* gui_wps end */
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000769
770void gui_sync_wps_screen_init(void)
771{
772 int i;
773 FOR_NB_SCREENS(i)
Daniel Stenberg09fce702005-11-18 09:03:25 +0000774 gui_wps_set_disp(&gui_wps[i], &screens[i]);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000775}
Jonathan Gordonbdbdb972008-06-23 13:20:35 +0000776#ifdef HAVE_LCD_BITMAP
777static void statusbar_toggle_handler(void *data)
778{
779 (void)data;
780 int i;
781 bool draw = global_settings.statusbar;
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000782
Jonathan Gordonbdbdb972008-06-23 13:20:35 +0000783 FOR_NB_SCREENS(i)
784 {
785 struct wps_viewport *vp = &gui_wps[i].data->viewports[0];
786 if (gui_wps[i].data->wps_sb_tag)
787 draw = gui_wps[i].data->show_sb_on_wps;
788 if (!global_settings.statusbar && !draw)
789 {
790 vp->vp.y = 0;
791 vp->vp.height = screens[i].height;
792 }
793 else
794 {
795 vp->vp.y = STATUSBAR_HEIGHT;
796 vp->vp.height = screens[i].height - STATUSBAR_HEIGHT;
797 }
798 }
799}
800#endif
801
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000802void gui_sync_wps_init(void)
803{
804 int i;
805 FOR_NB_SCREENS(i)
806 {
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000807 wps_data_init(&wps_datas[i]);
Nicolas Pennequin2a2b8d82007-04-25 13:09:56 +0000808#ifdef HAVE_REMOTE_LCD
809 wps_datas[i].remote_wps = (i != 0);
810#endif
Daniel Stenberg09fce702005-11-18 09:03:25 +0000811 gui_wps_init(&gui_wps[i]);
812 gui_wps_set_data(&gui_wps[i], &wps_datas[i]);
Kevin Ferrare0d9c7b52005-11-20 22:13:52 +0000813 gui_wps_set_statusbar(&gui_wps[i], &statusbars.statusbars[i]);
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000814 }
Jonathan Gordonbdbdb972008-06-23 13:20:35 +0000815#ifdef HAVE_LCD_BITMAP
816 add_event(STATUSBAR_TOGGLE_EVENT, false, statusbar_toggle_handler);
817#endif
Jens Arnold02978732006-11-13 00:45:21 +0000818#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000819 unload_wps_backdrop();
820#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000821#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
822 unload_remote_wps_backdrop();
823#endif
Christi Scarboroughf8cc3212005-11-17 20:20:01 +0000824}
Nicolas Pennequin9d4bed72007-11-11 12:29:37 +0000825
826#ifdef HAVE_ALBUMART
827/* Returns true if at least one of the gui_wps screens has an album art
828 tag in its wps structure */
829bool gui_sync_wps_uses_albumart(void)
830{
831 int i;
832 FOR_NB_SCREENS(i) {
833 struct gui_wps *gwps = &gui_wps[i];
834 if (gwps->data && (gwps->data->wps_uses_albumart != WPS_ALBUMART_NONE))
835 return true;
836 }
837 return false;
838}
839#endif