skin tags: fix the id3 track/disc numbers in conditionals
[maemo-rb.git] / apps / menus / playback_menu.c
blob6beda93991c9ebaaa20c94dbe2018c1df0f7e9ab
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Jonathan Gordon
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 ****************************************************************************/
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <limits.h>
25 #include "config.h"
26 #include "lang.h"
27 #include "action.h"
28 #include "splash.h"
29 #include "settings.h"
30 #include "menu.h"
31 #include "sound_menu.h"
32 #include "kernel.h"
33 #include "playlist.h"
34 #include "scrobbler.h"
35 #include "audio.h"
36 #include "cuesheet.h"
37 #include "misc.h"
38 #if CONFIG_CODEC == SWCODEC
39 #include "playback.h"
40 #endif
43 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_CROSSFADE)
44 static int setcrossfadeonexit_callback(int action,const struct menu_item_ex *this_item)
46 (void)this_item;
47 switch (action)
49 case ACTION_EXIT_MENUITEM: /* on exit */
50 audio_set_crossfade(global_settings.crossfade);
51 break;
53 return action;
56 #endif /* CONFIG_CODEC == SWCODEC */
58 /***********************************/
59 /* PLAYBACK MENU */
60 static int playback_callback(int action,const struct menu_item_ex *this_item);
62 MENUITEM_SETTING(shuffle_item, &global_settings.playlist_shuffle, playback_callback);
63 MENUITEM_SETTING(repeat_mode, &global_settings.repeat_mode, playback_callback);
64 MENUITEM_SETTING(play_selected, &global_settings.play_selected, NULL);
66 MENUITEM_SETTING(ff_rewind_accel, &global_settings.ff_rewind_accel, NULL);
67 MENUITEM_SETTING(ff_rewind_min_step, &global_settings.ff_rewind_min_step, NULL);
68 MAKE_MENU(ff_rewind_settings_menu, ID2P(LANG_WIND_MENU), 0, Icon_NOICON,
69 &ff_rewind_min_step, &ff_rewind_accel);
70 #ifdef HAVE_DISK_STORAGE
71 #if CONFIG_CODEC == SWCODEC
72 static int buffermargin_callback(int action,const struct menu_item_ex *this_item)
74 (void)this_item;
75 switch (action)
77 case ACTION_EXIT_MENUITEM: /* on exit */
78 audio_set_buffer_margin(global_settings.buffer_margin);
79 break;
81 return action;
83 #else
84 # define buffermargin_callback NULL
85 #endif
86 MENUITEM_SETTING(buffer_margin, &global_settings.buffer_margin,
87 buffermargin_callback);
88 #endif /*HAVE_DISK_STORAGE */
89 MENUITEM_SETTING(fade_on_stop, &global_settings.fade_on_stop, NULL);
90 MENUITEM_SETTING(party_mode, &global_settings.party_mode, NULL);
92 #if CONFIG_CODEC == SWCODEC
93 #ifdef HAVE_CROSSFADE
94 /* crossfade submenu */
95 MENUITEM_SETTING(crossfade, &global_settings.crossfade, setcrossfadeonexit_callback);
96 MENUITEM_SETTING(crossfade_fade_in_delay,
97 &global_settings.crossfade_fade_in_delay, NULL);
98 MENUITEM_SETTING(crossfade_fade_in_duration,
99 &global_settings.crossfade_fade_in_duration, NULL);
100 MENUITEM_SETTING(crossfade_fade_out_delay,
101 &global_settings.crossfade_fade_out_delay, setcrossfadeonexit_callback);
102 MENUITEM_SETTING(crossfade_fade_out_duration,
103 &global_settings.crossfade_fade_out_duration, setcrossfadeonexit_callback);
104 MENUITEM_SETTING(crossfade_fade_out_mixmode,
105 &global_settings.crossfade_fade_out_mixmode,NULL);
106 MAKE_MENU(crossfade_settings_menu,ID2P(LANG_CROSSFADE),0, Icon_NOICON,
107 &crossfade, &crossfade_fade_in_delay, &crossfade_fade_in_duration,
108 &crossfade_fade_out_delay, &crossfade_fade_out_duration,
109 &crossfade_fade_out_mixmode);
110 #endif
112 /* replay gain submenu */
114 static int replaygain_callback(int action,const struct menu_item_ex *this_item)
116 (void)this_item;
117 switch (action)
119 case ACTION_EXIT_MENUITEM: /* on exit */
120 replaygain_update();
121 break;
123 return action;
125 MENUITEM_SETTING(replaygain_noclip,
126 &global_settings.replaygain_settings.noclip,
127 replaygain_callback);
128 MENUITEM_SETTING(replaygain_type,
129 &global_settings.replaygain_settings.type,
130 replaygain_callback);
131 MENUITEM_SETTING(replaygain_preamp,
132 &global_settings.replaygain_settings.preamp,
133 replaygain_callback);
134 MAKE_MENU(replaygain_settings_menu,ID2P(LANG_REPLAYGAIN),0, Icon_NOICON,
135 &replaygain_type, &replaygain_noclip, &replaygain_preamp);
137 MENUITEM_SETTING(beep, &global_settings.beep ,NULL);
138 #endif /* CONFIG_CODEC == SWCODEC */
140 #ifdef HAVE_SPDIF_POWER
141 MENUITEM_SETTING(spdif_enable, &global_settings.spdif_enable, NULL);
142 #endif
143 MENUITEM_SETTING(next_folder, &global_settings.next_folder, NULL);
144 MENUITEM_SETTING(constrain_next_folder,
145 &global_settings.constrain_next_folder, NULL);
146 static int audioscrobbler_callback(int action,const struct menu_item_ex *this_item)
148 (void)this_item;
149 switch (action)
151 case ACTION_EXIT_MENUITEM: /* on exit */
152 if (!scrobbler_is_enabled() && global_settings.audioscrobbler)
153 scrobbler_init();
155 if(scrobbler_is_enabled() && !global_settings.audioscrobbler)
156 scrobbler_shutdown();
157 break;
159 return action;
161 MENUITEM_SETTING(audioscrobbler, &global_settings.audioscrobbler, audioscrobbler_callback);
164 static int cuesheet_callback(int action,const struct menu_item_ex *this_item)
166 (void)this_item;
167 switch (action)
169 case ACTION_EXIT_MENUITEM: /* on exit */
170 #if CONFIG_CODEC == SWCODEC
171 audio_set_cuesheet(global_settings.cuesheet);
172 #else
173 if (global_settings.cuesheet)
174 splash(HZ*2, ID2P(LANG_PLEASE_REBOOT));
175 break;
176 #endif
178 return action;
180 MENUITEM_SETTING(cuesheet, &global_settings.cuesheet, cuesheet_callback);
182 #ifdef HAVE_HEADPHONE_DETECTION
183 MENUITEM_SETTING(unplug_mode, &global_settings.unplug_mode, NULL);
184 MENUITEM_SETTING(unplug_autoresume, &global_settings.unplug_autoresume, NULL);
185 MAKE_MENU(unplug_menu, ID2P(LANG_HEADPHONE_UNPLUG), 0, Icon_NOICON,
186 &unplug_mode, &unplug_autoresume);
187 #endif
189 MENUITEM_SETTING(skip_length, &global_settings.skip_length, NULL);
190 MENUITEM_SETTING(prevent_skip, &global_settings.prevent_skip, NULL);
191 #if CONFIG_CODEC == SWCODEC
192 MENUITEM_SETTING(resume_rewind, &global_settings.resume_rewind, NULL);
193 #endif
194 MENUITEM_SETTING(pause_rewind, &global_settings.pause_rewind, NULL);
196 MAKE_MENU(playback_settings,ID2P(LANG_PLAYBACK),0,
197 Icon_Playback_menu,
198 &shuffle_item, &repeat_mode, &play_selected,
199 &ff_rewind_settings_menu,
200 #ifdef HAVE_DISK_STORAGE
201 &buffer_margin,
202 #endif
203 &fade_on_stop, &party_mode,
205 #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_CROSSFADE)
206 &crossfade_settings_menu,
207 #endif
209 #if CONFIG_CODEC == SWCODEC
210 &replaygain_settings_menu, &beep,
211 #endif
213 #ifdef HAVE_SPDIF_POWER
214 &spdif_enable,
215 #endif
216 &next_folder, &constrain_next_folder, &audioscrobbler, &cuesheet
217 #ifdef HAVE_HEADPHONE_DETECTION
218 ,&unplug_menu
219 #endif
220 ,&skip_length, &prevent_skip,
222 #if CONFIG_CODEC == SWCODEC
223 &resume_rewind,
224 #endif
225 &pause_rewind,
228 static int playback_callback(int action,const struct menu_item_ex *this_item)
230 static bool old_shuffle = false;
231 static int old_repeat = 0;
232 switch (action)
234 case ACTION_ENTER_MENUITEM:
235 if (this_item == &shuffle_item)
237 old_shuffle = global_settings.playlist_shuffle;
239 else if (this_item == &repeat_mode)
241 old_repeat = global_settings.repeat_mode;
243 break;
245 case ACTION_EXIT_MENUITEM: /* on exit */
246 if (!(audio_status() & AUDIO_STATUS_PLAY))
247 break;
249 if (this_item == &shuffle_item)
251 if (old_shuffle == global_settings.playlist_shuffle)
252 break;
254 replaygain_update();
256 if (global_settings.playlist_shuffle)
258 playlist_randomise(NULL, current_tick, true);
260 else
262 playlist_sort(NULL, true);
265 else if (this_item == &repeat_mode)
267 if (old_repeat == global_settings.repeat_mode)
268 break;
270 audio_flush_and_reload_tracks();
273 break;
275 return action;
277 /* PLAYBACK MENU */
278 /***********************************/