diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2008-10-05 13:01:54 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2008-10-05 13:01:54 +0000 |
commit | 1da2f0112e2ef3142c9da8d8bcaf72f6b07ac932 (patch) | |
tree | 5c991a509f956db1e2d94f7cb221e81c1c83ffe4 | |
parent | ab424ac11cf121be779abdedf1c552bb5b04c791 (diff) | |
download | rockbox-1da2f0112e2ef3142c9da8d8bcaf72f6b07ac932.tar.gz rockbox-1da2f0112e2ef3142c9da8d8bcaf72f6b07ac932.zip |
Accept FS#9231 - viewportify the pitch screen by Thomas Martitz.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18714 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/gui/gwps.c | 3 | ||||
-rw-r--r-- | apps/gui/pitchscreen.c | 205 | ||||
-rw-r--r-- | apps/gui/pitchscreen.h | 27 | ||||
-rw-r--r-- | apps/onplay.c | 3 |
4 files changed, 174 insertions, 64 deletions
diff --git a/apps/gui/gwps.c b/apps/gui/gwps.c index 5fd87ec1db..722dce685e 100644 --- a/apps/gui/gwps.c +++ b/apps/gui/gwps.c | |||
@@ -60,6 +60,7 @@ | |||
60 | #include "root_menu.h" | 60 | #include "root_menu.h" |
61 | #include "backdrop.h" | 61 | #include "backdrop.h" |
62 | #include "quickscreen.h" | 62 | #include "quickscreen.h" |
63 | #include "pitchscreen.h" | ||
63 | 64 | ||
64 | /* currently only on wps_state is needed */ | 65 | /* currently only on wps_state is needed */ |
65 | struct wps_state wps_state; | 66 | struct wps_state wps_state; |
@@ -567,7 +568,7 @@ long gui_wps_show(void) | |||
567 | #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 | 568 | #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 |
568 | show_remote_main_backdrop(); | 569 | show_remote_main_backdrop(); |
569 | #endif | 570 | #endif |
570 | if (1 == pitch_screen()) | 571 | if (1 == gui_syncpitchscreen_run()) |
571 | return SYS_USB_CONNECTED; | 572 | return SYS_USB_CONNECTED; |
572 | #if LCD_DEPTH > 1 | 573 | #if LCD_DEPTH > 1 |
573 | show_wps_backdrop(); | 574 | show_wps_backdrop(); |
diff --git a/apps/gui/pitchscreen.c b/apps/gui/pitchscreen.c index c4f78f4baa..0cdbeb10f2 100644 --- a/apps/gui/pitchscreen.c +++ b/apps/gui/pitchscreen.c | |||
@@ -36,93 +36,156 @@ | |||
36 | #include "icons.h" | 36 | #include "icons.h" |
37 | #include "screen_access.h" | 37 | #include "screen_access.h" |
38 | #include "screens.h" | 38 | #include "screens.h" |
39 | 39 | #include "statusbar.h" | |
40 | #define PITCH_MAX 2000 | 40 | #include "viewport.h" |
41 | #define PITCH_MIN 500 | 41 | #include "pitchscreen.h" |
42 | #define PITCH_SMALL_DELTA 1 | ||
43 | #define PITCH_BIG_DELTA 10 | ||
44 | #define PITCH_NUDGE_DELTA 20 | ||
45 | 42 | ||
46 | #define PITCH_MODE_ABSOLUTE 1 | 43 | #define PITCH_MODE_ABSOLUTE 1 |
47 | #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE | 44 | #define PITCH_MODE_SEMITONE -PITCH_MODE_ABSOLUTE |
45 | #define ICON_BORDER 12 | ||
48 | 46 | ||
49 | static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */ | 47 | static int pitch_mode = PITCH_MODE_ABSOLUTE; /* 1 - absolute, -1 - semitone */ |
48 | enum PITCHSCREEN_VALUES | ||
49 | { | ||
50 | PITCH_SMALL_DELTA = 1, | ||
51 | PITCH_BIG_DELTA = 10, | ||
52 | PITCH_NUDGE_DELTA = 20, | ||
53 | PITCH_MIN = 500, | ||
54 | PITCH_MAX = 2000, | ||
55 | }; | ||
56 | |||
57 | enum PITCHSCREEN_ITEMS | ||
58 | { | ||
59 | PITCH_TOP = 0, | ||
60 | PITCH_MID, | ||
61 | PITCH_BOTTOM, | ||
62 | PITCH_ITEM_COUNT, | ||
63 | }; | ||
64 | |||
65 | static void pitchscreen_fix_viewports(enum screen_type screen, | ||
66 | struct viewport *parent, | ||
67 | struct viewport pitch_viewports[NB_SCREENS][PITCH_ITEM_COUNT]) | ||
68 | { | ||
69 | short n, height; | ||
70 | height = font_get(parent->font)->height; | ||
71 | for (n = 0; n < PITCH_ITEM_COUNT; n++) | ||
72 | { | ||
73 | pitch_viewports[screen][n] = *parent; | ||
74 | pitch_viewports[screen][n].height = height; | ||
75 | } | ||
76 | pitch_viewports[screen][PITCH_TOP].y += ICON_BORDER; | ||
77 | |||
78 | pitch_viewports[screen][PITCH_MID].x += ICON_BORDER; | ||
79 | pitch_viewports[screen][PITCH_MID].width = parent->width - ICON_BORDER*2; | ||
80 | pitch_viewports[screen][PITCH_MID].height = height * 2; | ||
81 | pitch_viewports[screen][PITCH_MID].y += parent->height / 2 - | ||
82 | pitch_viewports[screen][PITCH_MID].height / 2; | ||
83 | pitch_viewports[screen][PITCH_BOTTOM].y += parent->height - height - | ||
84 | ICON_BORDER; | ||
85 | } | ||
50 | 86 | ||
51 | /* returns: | 87 | /* must be called before pitchscreen_draw, or within |
52 | 0 if no key was pressed | 88 | * since it neither clears nor updates the display */ |
53 | 1 if USB was connected */ | 89 | static void pitchscreen_draw_icons (struct screen *display, |
90 | struct viewport *parent) | ||
91 | { | ||
92 | display->set_viewport(parent); | ||
93 | display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow], | ||
94 | parent->width/2 - 3, | ||
95 | 2, 7, 8); | ||
96 | display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], | ||
97 | parent->width /2 - 3, | ||
98 | parent->height - 10, 7, 8); | ||
99 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], | ||
100 | parent->width - 10, | ||
101 | parent->height /2 - 4, 7, 8); | ||
102 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], | ||
103 | 2, | ||
104 | parent->height /2 - 4, 7, 8); | ||
105 | } | ||
54 | 106 | ||
55 | static void pitch_screen_draw(struct screen *display, int pitch, int pitch_mode) | 107 | static void pitchscreen_draw ( |
108 | struct screen *display, | ||
109 | int max_lines, | ||
110 | struct viewport pitch_viewports[PITCH_ITEM_COUNT], | ||
111 | int pitch) | ||
56 | { | 112 | { |
57 | unsigned char* ptr; | 113 | unsigned char* ptr; |
58 | unsigned char buf[32]; | 114 | unsigned char buf[32]; |
59 | int w, h; | 115 | int w, h; |
116 | bool show_lang_pitch; | ||
60 | 117 | ||
61 | display->clear_display(); | 118 | /* Hide "Pitch up/Pitch down" for a small screen */ |
62 | 119 | if (max_lines >= 5) | |
63 | if (display->getnblines() < 4) /* very small screen, just show pitch value*/ | ||
64 | { | 120 | { |
65 | w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_PITCH), | ||
66 | pitch / 10, pitch % 10 ); | ||
67 | display->putsxy((display->lcdwidth-(w*display->getcharwidth()))/2, | ||
68 | display->getnblines()/2,buf); | ||
69 | } | ||
70 | else /* bigger screen, show everything... */ | ||
71 | { | ||
72 | |||
73 | /* UP: Pitch Up */ | 121 | /* UP: Pitch Up */ |
122 | display->set_viewport(&pitch_viewports[PITCH_TOP]); | ||
74 | if (pitch_mode == PITCH_MODE_ABSOLUTE) { | 123 | if (pitch_mode == PITCH_MODE_ABSOLUTE) { |
75 | ptr = str(LANG_PITCH_UP); | 124 | ptr = str(LANG_PITCH_UP); |
76 | } else { | 125 | } else { |
77 | ptr = str(LANG_PITCH_UP_SEMITONE); | 126 | ptr = str(LANG_PITCH_UP_SEMITONE); |
78 | } | 127 | } |
79 | display->getstringsize(ptr,&w,&h); | 128 | display->getstringsize(ptr,&w,&h); |
80 | display->putsxy((display->lcdwidth-w)/2, 0, ptr); | 129 | display->clear_viewport(); |
81 | display->mono_bitmap(bitmap_icons_7x8[Icon_UpArrow], | 130 | /* draw text */ |
82 | display->lcdwidth/2 - 3, h, 7, 8); | 131 | display->putsxy((pitch_viewports[PITCH_TOP].width / 2) - |
132 | (w / 2), 0, ptr); | ||
83 | 133 | ||
84 | /* DOWN: Pitch Down */ | 134 | /* DOWN: Pitch Down */ |
135 | display->set_viewport(&pitch_viewports[PITCH_BOTTOM]); | ||
85 | if (pitch_mode == PITCH_MODE_ABSOLUTE) { | 136 | if (pitch_mode == PITCH_MODE_ABSOLUTE) { |
86 | ptr = str(LANG_PITCH_DOWN); | 137 | ptr = str(LANG_PITCH_DOWN); |
87 | } else { | 138 | } else { |
88 | ptr = str(LANG_PITCH_DOWN_SEMITONE); | 139 | ptr = str(LANG_PITCH_DOWN_SEMITONE); |
89 | } | 140 | } |
90 | display->getstringsize(ptr,&w,&h); | 141 | display->getstringsize(ptr,&w,&h); |
91 | display->putsxy((display->lcdwidth-w)/2, display->lcdheight - h, ptr); | 142 | display->clear_viewport(); |
92 | display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], | 143 | /* draw text */ |
93 | display->lcdwidth/2 - 3, | 144 | display->putsxy((pitch_viewports[PITCH_BOTTOM].width / 2) - |
94 | display->lcdheight - h*2, 7, 8); | 145 | (w / 2), 0, ptr); |
95 | 146 | } | |
147 | display->set_viewport(&pitch_viewports[PITCH_MID]); | ||
148 | |||
149 | snprintf((char *)buf, sizeof(buf), "%s", str(LANG_PITCH)); | ||
150 | display->getstringsize(buf,&w,&h); | ||
151 | /* lets hide LANG_PITCH for smaller screens */ | ||
152 | display->clear_viewport(); | ||
153 | if ((show_lang_pitch = (max_lines >= 3))) | ||
154 | display->putsxy((pitch_viewports[PITCH_MID].width / 2) - (w / 2), | ||
155 | 0, buf); | ||
156 | |||
157 | /* we don't need max_lines any more, reuse it*/ | ||
158 | max_lines = w; | ||
159 | /* "XXX.X%" */ | ||
160 | snprintf((char *)buf, sizeof(buf), "%d.%d%%", | ||
161 | pitch / 10, pitch % 10 ); | ||
162 | display->getstringsize(buf,&w,&h); | ||
163 | display->putsxy((pitch_viewports[PITCH_MID].width / 2) - (w / 2), | ||
164 | (show_lang_pitch? h : h/2), buf); | ||
165 | |||
166 | /* What's wider? LANG_PITCH or the value? | ||
167 | * Only interesting if LANG_PITCH is actually drawn */ | ||
168 | max_lines = (show_lang_pitch ? ((max_lines > w) ? max_lines : w) : w); | ||
169 | |||
170 | /* Let's treat '+' and '-' as equally wide | ||
171 | * This saves a getstringsize call | ||
172 | * Also, it wouldn't look nice if -2% shows up, but +2% not */ | ||
173 | display->getstringsize("+2%",&w,&h); | ||
174 | max_lines += 2*w; | ||
175 | /* hide +2%/-2% for a narrow screens */ | ||
176 | if (max_lines < pitch_viewports[PITCH_MID].width) | ||
177 | { | ||
96 | /* RIGHT: +2% */ | 178 | /* RIGHT: +2% */ |
97 | ptr = "+2%"; | 179 | display->putsxy(pitch_viewports[PITCH_MID].width - w, h /2, "+2%"); |
98 | display->getstringsize(ptr,&w,&h); | ||
99 | display->putsxy(display->lcdwidth-w, (display->lcdheight-h)/2, ptr); | ||
100 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], | ||
101 | display->lcdwidth-w-8, | ||
102 | (display->lcdheight-h)/2, 7, 8); | ||
103 | |||
104 | /* LEFT: -2% */ | 180 | /* LEFT: -2% */ |
105 | ptr = "-2%"; | 181 | display->putsxy(0, h / 2, "-2%"); |
106 | display->getstringsize(ptr,&w,&h); | ||
107 | display->putsxy(0, (display->lcdheight-h)/2, ptr); | ||
108 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], | ||
109 | w+1, (display->lcdheight-h)/2, 7, 8); | ||
110 | |||
111 | /* "Pitch" */ | ||
112 | snprintf((char *)buf, sizeof(buf), "%s", str(LANG_PITCH)); | ||
113 | display->getstringsize(buf,&w,&h); | ||
114 | display->putsxy((display->lcdwidth-w)/2, (display->lcdheight/2)-h, buf); | ||
115 | /* "XX.X%" */ | ||
116 | snprintf((char *)buf, sizeof(buf), "%d.%d%%", | ||
117 | pitch / 10, pitch % 10 ); | ||
118 | display->getstringsize(buf,&w,&h); | ||
119 | display->putsxy((display->lcdwidth-w)/2, display->lcdheight/2, buf); | ||
120 | } | 182 | } |
121 | 183 | /* Lastly, a fullscreen update */ | |
184 | display->set_viewport(NULL); | ||
122 | display->update(); | 185 | display->update(); |
123 | } | 186 | } |
124 | 187 | ||
125 | static int pitch_increase(int pitch, int delta, bool allow_cutoff) | 188 | static int pitch_increase(int pitch, int delta, bool allow_cutoff) |
126 | { | 189 | { |
127 | int new_pitch; | 190 | int new_pitch; |
128 | 191 | ||
@@ -188,25 +251,46 @@ static int pitch_increase_semitone(int pitch, bool up) | |||
188 | return pitch_increase(pitch, tmp - pitch, false); | 251 | return pitch_increase(pitch, tmp - pitch, false); |
189 | } | 252 | } |
190 | 253 | ||
191 | bool pitch_screen(void) | 254 | /* |
255 | returns: | ||
256 | 0 on exit | ||
257 | 1 if USB was connected | ||
258 | */ | ||
259 | |||
260 | int gui_syncpitchscreen_run(void) | ||
192 | { | 261 | { |
193 | int button; | 262 | int button; |
194 | int pitch = sound_get_pitch(); | 263 | int pitch = sound_get_pitch(); |
195 | int new_pitch, delta = 0; | 264 | int new_pitch, delta = 0; |
196 | bool nudged = false; | 265 | bool nudged = false; |
197 | bool exit = false; | 266 | bool exit = false; |
198 | int i; | 267 | short i; |
268 | struct viewport parent[NB_SCREENS]; /* should be a parameter of this function */ | ||
269 | short max_lines[NB_SCREENS]; | ||
270 | struct viewport pitch_viewports[NB_SCREENS][PITCH_ITEM_COUNT]; | ||
199 | 271 | ||
272 | /* initialize pitchscreen vps */ | ||
273 | FOR_NB_SCREENS(i) | ||
274 | { | ||
275 | screens[i].clear_display(); | ||
276 | viewport_set_defaults(&parent[i], i); | ||
277 | max_lines[i] = viewport_get_nb_lines(&parent[i]); | ||
278 | pitchscreen_fix_viewports(i, &parent[i], pitch_viewports); | ||
279 | |||
280 | /* also, draw the icons now, it's only needed once */ | ||
281 | pitchscreen_draw_icons(&screens[i], &parent[i]); | ||
282 | } | ||
200 | #if CONFIG_CODEC == SWCODEC | 283 | #if CONFIG_CODEC == SWCODEC |
201 | pcmbuf_set_low_latency(true); | 284 | pcmbuf_set_low_latency(true); |
202 | #endif | 285 | #endif |
203 | 286 | i = 0; | |
204 | while (!exit) | 287 | while (!exit) |
205 | { | 288 | { |
206 | FOR_NB_SCREENS(i) | 289 | FOR_NB_SCREENS(i) |
207 | pitch_screen_draw(&screens[i], pitch, pitch_mode); | 290 | pitchscreen_draw(&screens[i], max_lines[i], |
208 | 291 | pitch_viewports[i], pitch); | |
209 | button = get_action(CONTEXT_PITCHSCREEN,TIMEOUT_BLOCK); | 292 | gui_syncstatusbar_draw(&statusbars, true); |
293 | button = get_action(CONTEXT_PITCHSCREEN,HZ); | ||
210 | switch (button) { | 294 | switch (button) { |
211 | case ACTION_PS_INC_SMALL: | 295 | case ACTION_PS_INC_SMALL: |
212 | delta = PITCH_SMALL_DELTA; | 296 | delta = PITCH_SMALL_DELTA; |
@@ -268,7 +352,6 @@ bool pitch_screen(void) | |||
268 | return 1; | 352 | return 1; |
269 | break; | 353 | break; |
270 | } | 354 | } |
271 | |||
272 | if(delta) | 355 | if(delta) |
273 | { | 356 | { |
274 | if (pitch_mode == PITCH_MODE_ABSOLUTE) { | 357 | if (pitch_mode == PITCH_MODE_ABSOLUTE) { |
@@ -279,11 +362,9 @@ bool pitch_screen(void) | |||
279 | 362 | ||
280 | delta = 0; | 363 | delta = 0; |
281 | } | 364 | } |
282 | |||
283 | } | 365 | } |
284 | #if CONFIG_CODEC == SWCODEC | 366 | #if CONFIG_CODEC == SWCODEC |
285 | pcmbuf_set_low_latency(false); | 367 | pcmbuf_set_low_latency(false); |
286 | #endif | 368 | #endif |
287 | lcd_setfont(FONT_UI); | ||
288 | return 0; | 369 | return 0; |
289 | } | 370 | } |
diff --git a/apps/gui/pitchscreen.h b/apps/gui/pitchscreen.h new file mode 100644 index 0000000000..41eb1fd415 --- /dev/null +++ b/apps/gui/pitchscreen.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 Thomas Martitz | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _PITCHSCREEN_H_ | ||
23 | #define _PITCHSCREEN_H_ | ||
24 | |||
25 | int gui_syncpitchscreen_run(void); | ||
26 | |||
27 | #endif /* _PITCHSCREEN_H_ */ | ||
diff --git a/apps/onplay.c b/apps/onplay.c index 3e6813b255..fae86cf150 100644 --- a/apps/onplay.c +++ b/apps/onplay.c | |||
@@ -64,6 +64,7 @@ | |||
64 | #endif | 64 | #endif |
65 | #include "cuesheet.h" | 65 | #include "cuesheet.h" |
66 | #include "backdrop.h" | 66 | #include "backdrop.h" |
67 | #include "pitchscreen.h" | ||
67 | 68 | ||
68 | static int context; | 69 | static int context; |
69 | static char* selected_file = NULL; | 70 | static char* selected_file = NULL; |
@@ -1002,7 +1003,7 @@ MENUITEM_FUNCTION(browse_id3_item, 0, ID2P(LANG_MENU_SHOW_ID3_INFO), | |||
1002 | browse_id3, NULL, NULL, Icon_NOICON); | 1003 | browse_id3, NULL, NULL, Icon_NOICON); |
1003 | #ifdef HAVE_PITCHSCREEN | 1004 | #ifdef HAVE_PITCHSCREEN |
1004 | MENUITEM_FUNCTION(pitch_screen_item, 0, ID2P(LANG_PITCH), | 1005 | MENUITEM_FUNCTION(pitch_screen_item, 0, ID2P(LANG_PITCH), |
1005 | pitch_screen, NULL, NULL, Icon_Audio); | 1006 | gui_syncpitchscreen_run, NULL, NULL, Icon_Audio); |
1006 | #endif | 1007 | #endif |
1007 | 1008 | ||
1008 | /* CONTEXT_[TREE|ID3DB] items */ | 1009 | /* CONTEXT_[TREE|ID3DB] items */ |