diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2007-02-10 07:08:25 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2007-02-10 07:08:25 +0000 |
commit | c7a1cec2198815b695cdda927cdda73a5249e5a2 (patch) | |
tree | 28b799aec4c49aea87e85e4a021d8f7bed75f112 | |
parent | 69c40d7e84eef3aba68321bf8c3e6196ff04a926 (diff) | |
download | rockbox-c7a1cec2198815b695cdda927cdda73a5249e5a2.tar.gz rockbox-c7a1cec2198815b695cdda927cdda73a5249e5a2.zip |
Recording Menus: Make statusbar update correctly when exiting an encoder setting.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12251 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/enc_config.c | 93 |
1 files changed, 51 insertions, 42 deletions
diff --git a/apps/enc_config.c b/apps/enc_config.c index f4ea1cc4b5..2fc9fb74e7 100644 --- a/apps/enc_config.c +++ b/apps/enc_config.c | |||
@@ -43,8 +43,9 @@ | |||
43 | if (fn) fn(__VA_ARGS__) | 43 | if (fn) fn(__VA_ARGS__) |
44 | 44 | ||
45 | static bool enc_run_menu(int m, const struct menu_item items[], | 45 | static bool enc_run_menu(int m, const struct menu_item items[], |
46 | struct encoder_config *cfg); | 46 | struct encoder_config *cfg, bool global); |
47 | static bool enc_no_config_menu(struct encoder_config *cfg); | 47 | static bool enc_no_config_menu(struct encoder_config *cfg, bool global); |
48 | static void enc_rec_settings_changed(struct encoder_config *cfg); | ||
48 | 49 | ||
49 | /** Function definitions for each codec - add these to enc_data | 50 | /** Function definitions for each codec - add these to enc_data |
50 | list following the definitions **/ | 51 | list following the definitions **/ |
@@ -98,20 +99,20 @@ static void mp3_enc_default_config(struct encoder_config *cfg) | |||
98 | } /* mp3_enc_default_config */ | 99 | } /* mp3_enc_default_config */ |
99 | 100 | ||
100 | static void mp3_enc_convert_config(struct encoder_config *cfg, | 101 | static void mp3_enc_convert_config(struct encoder_config *cfg, |
101 | bool to_encoder) | 102 | bool global) |
102 | { | 103 | { |
103 | if (to_encoder) | 104 | if (global) |
104 | { | ||
105 | if ((unsigned)global_settings.mp3_enc_config.bitrate > MP3_ENC_NUM_BITR) | ||
106 | global_settings.mp3_enc_config.bitrate = MP3_ENC_BITRATE_CFG_DEFAULT; | ||
107 | cfg->mp3_enc.bitrate = mp3_enc_bitr[global_settings.mp3_enc_config.bitrate]; | ||
108 | } | ||
109 | else | ||
110 | { | 105 | { |
111 | global_settings.mp3_enc_config.bitrate = | 106 | global_settings.mp3_enc_config.bitrate = |
112 | round_value_to_list32(cfg->mp3_enc.bitrate, mp3_enc_bitr, | 107 | round_value_to_list32(cfg->mp3_enc.bitrate, mp3_enc_bitr, |
113 | MP3_ENC_NUM_BITR, false); | 108 | MP3_ENC_NUM_BITR, false); |
114 | } | 109 | } |
110 | else | ||
111 | { | ||
112 | if ((unsigned)global_settings.mp3_enc_config.bitrate > MP3_ENC_NUM_BITR) | ||
113 | global_settings.mp3_enc_config.bitrate = MP3_ENC_BITRATE_CFG_DEFAULT; | ||
114 | cfg->mp3_enc.bitrate = mp3_enc_bitr[global_settings.mp3_enc_config.bitrate]; | ||
115 | } | ||
115 | } /* mp3_enc_convert_config */ | 116 | } /* mp3_enc_convert_config */ |
116 | 117 | ||
117 | /* mp3_enc: show the bitrate setting options */ | 118 | /* mp3_enc: show the bitrate setting options */ |
@@ -175,7 +176,7 @@ static bool mp3_enc_bitrate(struct encoder_config *cfg) | |||
175 | } /* mp3_enc_bitrate */ | 176 | } /* mp3_enc_bitrate */ |
176 | 177 | ||
177 | /* mp3_enc: show the configuration menu */ | 178 | /* mp3_enc: show the configuration menu */ |
178 | static bool mp3_enc_menu(struct encoder_config *cfg) | 179 | static bool mp3_enc_menu(struct encoder_config *cfg, bool global) |
179 | { | 180 | { |
180 | static const struct menu_item items[] = | 181 | static const struct menu_item items[] = |
181 | { | 182 | { |
@@ -184,7 +185,7 @@ static bool mp3_enc_menu(struct encoder_config *cfg) | |||
184 | 185 | ||
185 | bool result; | 186 | bool result; |
186 | int m = menu_init(items, ARRAYLEN(items), NULL, NULL, NULL, NULL); | 187 | int m = menu_init(items, ARRAYLEN(items), NULL, NULL, NULL, NULL); |
187 | result = enc_run_menu(m, items, cfg); | 188 | result = enc_run_menu(m, items, cfg, global); |
188 | menu_exit(m); | 189 | menu_exit(m); |
189 | return result; | 190 | return result; |
190 | } /* mp3_enc_menu */ | 191 | } /* mp3_enc_menu */ |
@@ -192,23 +193,23 @@ static bool mp3_enc_menu(struct encoder_config *cfg) | |||
192 | /** wav_enc.codec **/ | 193 | /** wav_enc.codec **/ |
193 | /* wav_enc: show the configuration menu */ | 194 | /* wav_enc: show the configuration menu */ |
194 | #if 0 | 195 | #if 0 |
195 | static bool wav_enc_menu(struct encoder_config *cfg); | 196 | static bool wav_enc_menu(struct encoder_config *cfg, bool global); |
196 | #endif | 197 | #endif |
197 | 198 | ||
198 | /** wavpack_enc.codec **/ | 199 | /** wavpack_enc.codec **/ |
199 | /* wavpack_enc: show the configuration menu */ | 200 | /* wavpack_enc: show the configuration menu */ |
200 | #if 0 | 201 | #if 0 |
201 | static bool wavpack_enc_menu(struct encoder_config *cfg); | 202 | static bool wavpack_enc_menu(struct encoder_config *cfg, bool global); |
202 | #endif | 203 | #endif |
203 | 204 | ||
204 | /** config function pointers and/or data for each codec **/ | 205 | /** config function pointers and/or data for each codec **/ |
205 | static const struct encoder_data | 206 | static const struct encoder_data |
206 | { | 207 | { |
207 | void (*get_caps)(const struct encoder_config *, struct encoder_caps *, | 208 | void (*get_caps)(const struct encoder_config *cfg, |
208 | bool); | 209 | struct encoder_caps *caps, bool for_config); |
209 | void (*default_cfg)(struct encoder_config *); | 210 | void (*default_cfg)(struct encoder_config *cfg); |
210 | void (*convert_cfg)(struct encoder_config *, bool to_encoder); | 211 | void (*convert_cfg)(struct encoder_config *cfg , bool global); |
211 | bool (*menu)(struct encoder_config *); | 212 | bool (*menu)(struct encoder_config *cfg , bool global); |
212 | } enc_data[REC_NUM_FORMATS] = | 213 | } enc_data[REC_NUM_FORMATS] = |
213 | { | 214 | { |
214 | /* aiff_enc.codec */ | 215 | /* aiff_enc.codec */ |
@@ -247,12 +248,13 @@ static inline bool rec_format_ok(int rec_format) | |||
247 | } | 248 | } |
248 | 249 | ||
249 | static bool enc_run_menu(int m, const struct menu_item items[], | 250 | static bool enc_run_menu(int m, const struct menu_item items[], |
250 | struct encoder_config *cfg) | 251 | struct encoder_config *cfg, bool global) |
251 | { | 252 | { |
252 | int selected; | ||
253 | while (1) | 253 | while (1) |
254 | { | 254 | { |
255 | switch (selected=menu_show(m)) | 255 | int selected = menu_show(m); |
256 | |||
257 | switch (selected) | ||
256 | { | 258 | { |
257 | case MENU_SELECTED_EXIT: | 259 | case MENU_SELECTED_EXIT: |
258 | return false; | 260 | return false; |
@@ -261,16 +263,31 @@ static bool enc_run_menu(int m, const struct menu_item items[], | |||
261 | return true; | 263 | return true; |
262 | 264 | ||
263 | default: | 265 | default: |
264 | if (items[selected].function && | 266 | if (items[selected].function == NULL) |
265 | ENC_MENU_ITEM_FN(items[selected].function)(cfg)) | 267 | break; |
266 | return true; | 268 | |
269 | /* If the setting being configured is global, it must be placed | ||
270 | in global_settings before updating the status bar for the | ||
271 | change to show upon exiting the item. */ | ||
272 | if (global) | ||
273 | global_to_encoder_config(cfg); | ||
274 | |||
275 | if (ENC_MENU_ITEM_FN(items[selected].function)(cfg)) | ||
276 | return true; | ||
277 | |||
278 | if (global) | ||
279 | { | ||
280 | enc_rec_settings_changed(cfg); | ||
281 | encoder_config_to_global(cfg); | ||
282 | } | ||
283 | |||
267 | gui_syncstatusbar_draw(&statusbars, true); | 284 | gui_syncstatusbar_draw(&statusbars, true); |
268 | } | 285 | } |
269 | } | 286 | } |
270 | } /* enc_run_menu */ | 287 | } /* enc_run_menu */ |
271 | 288 | ||
272 | /* menu created when encoder has no configuration options */ | 289 | /* menu created when encoder has no configuration options */ |
273 | static bool enc_no_config_menu(struct encoder_config *cfg) | 290 | static bool enc_no_config_menu(struct encoder_config *cfg, bool global) |
274 | { | 291 | { |
275 | static const struct menu_item items[] = | 292 | static const struct menu_item items[] = |
276 | { | 293 | { |
@@ -280,11 +297,12 @@ static bool enc_no_config_menu(struct encoder_config *cfg) | |||
280 | bool result; | 297 | bool result; |
281 | 298 | ||
282 | m = menu_init(items, ARRAYLEN(items), NULL, NULL, NULL, NULL); | 299 | m = menu_init(items, ARRAYLEN(items), NULL, NULL, NULL, NULL); |
283 | result = enc_run_menu(m, items, NULL); | 300 | result = enc_run_menu(m, items, NULL, false); |
284 | menu_exit(m); | 301 | menu_exit(m); |
285 | 302 | ||
286 | return result; | 303 | return result; |
287 | (void)cfg; | 304 | (void)cfg; |
305 | (void)global; | ||
288 | } /* enc_no_config_menu */ | 306 | } /* enc_no_config_menu */ |
289 | 307 | ||
290 | /* update settings dependent upon encoder settings */ | 308 | /* update settings dependent upon encoder settings */ |
@@ -333,13 +351,13 @@ static void enc_rec_settings_changed(struct encoder_config *cfg) | |||
333 | void global_to_encoder_config(struct encoder_config *cfg) | 351 | void global_to_encoder_config(struct encoder_config *cfg) |
334 | { | 352 | { |
335 | const struct encoder_data *data = &enc_data[cfg->rec_format]; | 353 | const struct encoder_data *data = &enc_data[cfg->rec_format]; |
336 | CALL_FN_(data->convert_cfg, cfg, true); | 354 | CALL_FN_(data->convert_cfg, cfg, false); |
337 | } /* global_to_encoder_config */ | 355 | } /* global_to_encoder_config */ |
338 | 356 | ||
339 | void encoder_config_to_global(const struct encoder_config *cfg) | 357 | void encoder_config_to_global(const struct encoder_config *cfg) |
340 | { | 358 | { |
341 | const struct encoder_data *data = &enc_data[cfg->rec_format]; | 359 | const struct encoder_data *data = &enc_data[cfg->rec_format]; |
342 | CALL_FN_(data->convert_cfg, (struct encoder_config *)cfg, false); | 360 | CALL_FN_(data->convert_cfg, (struct encoder_config *)cfg, true); |
343 | } /* encoder_config_to_global */ | 361 | } /* encoder_config_to_global */ |
344 | 362 | ||
345 | bool enc_get_caps(const struct encoder_config *cfg, | 363 | bool enc_get_caps(const struct encoder_config *cfg, |
@@ -376,12 +394,14 @@ bool enc_init_config(struct encoder_config *cfg) | |||
376 | } /* enc_init_config */ | 394 | } /* enc_init_config */ |
377 | 395 | ||
378 | /** Encoder Menus **/ | 396 | /** Encoder Menus **/ |
397 | #if 0 | ||
379 | bool enc_config_menu(struct encoder_config *cfg) | 398 | bool enc_config_menu(struct encoder_config *cfg) |
380 | { | 399 | { |
381 | if (!rec_format_ok(cfg->rec_format)) | 400 | if (!rec_format_ok(cfg->rec_format)) |
382 | return false; | 401 | return false; |
383 | return enc_data[cfg->rec_format].menu(cfg); | 402 | return enc_data[cfg->rec_format].menu(cfg, false); |
384 | } /* enc_config_menu */ | 403 | } /* enc_config_menu */ |
404 | #endif | ||
385 | 405 | ||
386 | /** Global Settings **/ | 406 | /** Global Settings **/ |
387 | 407 | ||
@@ -421,21 +441,10 @@ bool enc_global_config_menu(void) | |||
421 | { | 441 | { |
422 | struct encoder_config cfg; | 442 | struct encoder_config cfg; |
423 | 443 | ||
424 | bool res; | ||
425 | |||
426 | if (!rec_format_ok(global_settings.rec_format)) | 444 | if (!rec_format_ok(global_settings.rec_format)) |
427 | global_settings.rec_format = REC_FORMAT_DEFAULT; | 445 | global_settings.rec_format = REC_FORMAT_DEFAULT; |
428 | 446 | ||
429 | cfg.rec_format = global_settings.rec_format; | 447 | cfg.rec_format = global_settings.rec_format; |
430 | 448 | ||
431 | global_to_encoder_config(&cfg); | 449 | return enc_data[cfg.rec_format].menu(&cfg, true); |
432 | |||
433 | res = enc_config_menu(&cfg); | ||
434 | if (!res) | ||
435 | { | ||
436 | enc_rec_settings_changed(&cfg); | ||
437 | encoder_config_to_global(&cfg); | ||
438 | } | ||
439 | |||
440 | return res; | ||
441 | } /* enc_global_config_menu */ | 450 | } /* enc_global_config_menu */ |