diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2004-11-26 13:31:40 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2004-11-26 13:31:40 +0000 |
commit | 569b998c5b251a3effaedd5ae814a60516a2be4b (patch) | |
tree | 55dff8f736595192f89cbf43cc83afb867a20e2a | |
parent | c30dcb8ad189a11286411e41c2feb44b28099ad0 (diff) | |
download | rockbox-569b998c5b251a3effaedd5ae814a60516a2be4b.tar.gz rockbox-569b998c5b251a3effaedd5ae814a60516a2be4b.zip |
Patch #1048937 by Jacob Erlbeck, Metronome tap speed entry
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5468 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/metronome.c | 210 | ||||
-rw-r--r-- | docs/CREDITS | 1 |
2 files changed, 139 insertions, 72 deletions
diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c index cf5113cadf..f980989978 100644 --- a/apps/plugins/metronome.c +++ b/apps/plugins/metronome.c | |||
@@ -26,22 +26,25 @@ | |||
26 | #define METRONOME_PLAYPAUSE BUTTON_PLAY | 26 | #define METRONOME_PLAYPAUSE BUTTON_PLAY |
27 | #define METRONOME_VOL_UP BUTTON_UP | 27 | #define METRONOME_VOL_UP BUTTON_UP |
28 | #define METRONOME_VOL_DOWN BUTTON_DOWN | 28 | #define METRONOME_VOL_DOWN BUTTON_DOWN |
29 | #define METRONOME_TAP BUTTON_ON | ||
29 | #define METRONOME_MSG_START "press play" | 30 | #define METRONOME_MSG_START "press play" |
30 | #define METRONOME_MSG_STOP "press pause" | 31 | #define METRONOME_MSG_STOP "press pause" |
31 | 32 | ||
32 | #elif CONFIG_KEYPAD == ONDIO_PAD | 33 | #elif CONFIG_KEYPAD == ONDIO_PAD |
33 | #define METRONOME_QUIT BUTTON_OFF | 34 | #define METRONOME_QUIT BUTTON_OFF |
34 | #define METRONOME_PLAYPAUSE BUTTON_MENU | 35 | #define METRONOME_PLAY_TAP BUTTON_MENU |
36 | #define METRONOME_PAUSE (BUTTON_MENU | BUTTON_REPEAT) | ||
35 | #define METRONOME_VOL_UP BUTTON_UP | 37 | #define METRONOME_VOL_UP BUTTON_UP |
36 | #define METRONOME_VOL_DOWN BUTTON_DOWN | 38 | #define METRONOME_VOL_DOWN BUTTON_DOWN |
37 | #define METRONOME_MSG_START "start: menu" | 39 | #define METRONOME_MSG_START "start: menu" |
38 | #define METRONOME_MSG_STOP "pause: menu" | 40 | #define METRONOME_MSG_STOP "pause: hold menu" |
39 | 41 | ||
40 | #elif CONFIG_KEYPAD == PLAYER_PAD | 42 | #elif CONFIG_KEYPAD == PLAYER_PAD |
41 | #define METRONOME_QUIT BUTTON_STOP | 43 | #define METRONOME_QUIT BUTTON_STOP |
42 | #define METRONOME_PLAYPAUSE BUTTON_PLAY | 44 | #define METRONOME_PLAYPAUSE BUTTON_PLAY |
43 | #define METRONOME_VOL_UP (BUTTON_ON | BUTTON_RIGHT) | 45 | #define METRONOME_VOL_UP (BUTTON_ON | BUTTON_RIGHT) |
44 | #define METRONOME_VOL_DOWN (BUTTON_ON | BUTTON_LEFT) | 46 | #define METRONOME_VOL_DOWN (BUTTON_ON | BUTTON_LEFT) |
47 | #define METRONOME_TAP BUTTON_ON | ||
45 | 48 | ||
46 | #endif | 49 | #endif |
47 | static struct plugin_api* rb; | 50 | static struct plugin_api* rb; |
@@ -55,6 +58,11 @@ static bool sound_paused = true; | |||
55 | 58 | ||
56 | static char buffer[30]; | 59 | static char buffer[30]; |
57 | 60 | ||
61 | static bool reset_tap = false; | ||
62 | static int tap_count = 0; | ||
63 | static int tap_time = 0; | ||
64 | static int tap_timeout = 0; | ||
65 | |||
58 | /*tick sound from a metronome*/ | 66 | /*tick sound from a metronome*/ |
59 | static unsigned char sound[]={ | 67 | static unsigned char sound[]={ |
60 | 255,251, 80,196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 68 | 255,251, 80,196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
@@ -194,13 +202,19 @@ void change_volume(int delta){ | |||
194 | void timer_callback(void){ | 202 | void timer_callback(void){ |
195 | if(minitick>=period){ | 203 | if(minitick>=period){ |
196 | minitick = 0; | 204 | minitick = 0; |
197 | if(!sound_active && !sound_paused){ | 205 | if(!sound_active && !sound_paused && !tap_count){ |
198 | play_tock(); | 206 | play_tock(); |
199 | } | 207 | } |
200 | } | 208 | } |
201 | else { | 209 | else { |
202 | minitick++; | 210 | minitick++; |
203 | } | 211 | } |
212 | |||
213 | if (tap_count) { | ||
214 | tap_time++; | ||
215 | if (tap_count > 1 && tap_time > tap_timeout) | ||
216 | tap_count = 0; | ||
217 | } | ||
204 | } | 218 | } |
205 | 219 | ||
206 | void cleanup(void *parameter) | 220 | void cleanup(void *parameter) |
@@ -212,8 +226,32 @@ void cleanup(void *parameter) | |||
212 | led(0); | 226 | led(0); |
213 | } | 227 | } |
214 | 228 | ||
215 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ | 229 | void tap(void) |
230 | { | ||
231 | if (tap_count == 0) { | ||
232 | tap_time = 0; | ||
233 | } | ||
234 | else { | ||
235 | if (tap_time > 0) { | ||
236 | bpm = 61440/(tap_time/tap_count); | ||
237 | |||
238 | if (bpm > 400) | ||
239 | bpm = 400; | ||
240 | } | ||
241 | |||
242 | calc_period(); | ||
243 | draw_display(); | ||
244 | |||
245 | tap_timeout = (tap_count+2)*tap_time/tap_count; | ||
246 | } | ||
247 | |||
248 | tap_count++; | ||
249 | minitick = 0; /* sync tock to tapping */ | ||
250 | |||
251 | reset_tap = false; | ||
252 | } | ||
216 | 253 | ||
254 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ | ||
217 | int button; | 255 | int button; |
218 | 256 | ||
219 | TEST_PLUGIN_API(api); | 257 | TEST_PLUGIN_API(api); |
@@ -223,81 +261,109 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ | |||
223 | rb->bitswap(sound, sizeof(sound)); | 261 | rb->bitswap(sound, sizeof(sound)); |
224 | 262 | ||
225 | if (rb->mp3_is_playing()) | 263 | if (rb->mp3_is_playing()) |
226 | rb->mp3_play_stop(); // stop audio ISR | 264 | rb->mp3_play_stop(); // stop audio ISR |
227 | 265 | ||
228 | calc_period(); | 266 | calc_period(); |
229 | rb->plugin_register_timer((FREQ/1024), 1, timer_callback); | 267 | rb->plugin_register_timer((FREQ/1024), 1, timer_callback); |
230 | 268 | ||
231 | draw_display(); | 269 | draw_display(); |
232 | 270 | ||
233 | /* main loop */ | 271 | /* main loop */ |
234 | while (true){ | 272 | while (true){ |
273 | reset_tap = true; | ||
235 | 274 | ||
236 | button = rb->button_get(true); | 275 | button = rb->button_get(true); |
237 | 276 | ||
238 | switch (button) { | 277 | switch (button) { |
239 | 278 | ||
240 | case METRONOME_QUIT: | 279 | case METRONOME_QUIT: |
241 | /* get out of here */ | 280 | /* get out of here */ |
242 | cleanup(NULL); | 281 | cleanup(NULL); |
243 | return PLUGIN_OK; | 282 | return PLUGIN_OK; |
244 | 283 | ||
245 | case METRONOME_PLAYPAUSE: | 284 | #if CONFIG_KEYPAD == ONDIO_PAD |
246 | if(sound_paused) | 285 | case METRONOME_PLAY_TAP: |
247 | sound_paused = false; | 286 | if(sound_paused) { |
248 | else | 287 | sound_paused = false; |
249 | sound_paused = true; | 288 | calc_period(); |
250 | calc_period(); | 289 | draw_display(); |
251 | draw_display(); | 290 | } |
252 | break; | 291 | else |
253 | 292 | tap(); | |
254 | case METRONOME_VOL_UP: | 293 | break; |
255 | case METRONOME_VOL_UP | BUTTON_REPEAT: | 294 | |
256 | change_volume(1); | 295 | case METRONOME_PAUSE: |
257 | calc_period(); | 296 | if(!sound_paused) |
258 | break; | 297 | sound_paused = true; |
259 | 298 | break; | |
260 | case METRONOME_VOL_DOWN: | 299 | #else |
261 | case METRONOME_VOL_DOWN | BUTTON_REPEAT: | 300 | case METRONOME_PLAYPAUSE: |
262 | change_volume(-1); | 301 | if(sound_paused) |
263 | calc_period(); | 302 | sound_paused = false; |
264 | break; | 303 | else |
265 | 304 | sound_paused = true; | |
266 | case BUTTON_LEFT: | 305 | calc_period(); |
267 | if (bpm > 1) | 306 | draw_display(); |
268 | bpm--; | 307 | break; |
269 | calc_period(); | 308 | #endif |
270 | draw_display(); | 309 | |
271 | break; | 310 | case METRONOME_VOL_UP: |
272 | 311 | case METRONOME_VOL_UP | BUTTON_REPEAT: | |
273 | case BUTTON_LEFT | BUTTON_REPEAT: | 312 | change_volume(1); |
274 | if (bpm > 10) | 313 | calc_period(); |
275 | bpm=bpm-10; | 314 | break; |
276 | calc_period(); | 315 | |
277 | draw_display(); | 316 | case METRONOME_VOL_DOWN: |
278 | break; | 317 | case METRONOME_VOL_DOWN | BUTTON_REPEAT: |
279 | 318 | change_volume(-1); | |
280 | case BUTTON_RIGHT: | 319 | calc_period(); |
281 | if(bpm < 400) | 320 | break; |
282 | bpm++; | 321 | |
283 | calc_period(); | 322 | case BUTTON_LEFT: |
284 | draw_display(); | 323 | if (bpm > 1) |
285 | break; | 324 | bpm--; |
286 | 325 | calc_period(); | |
287 | case BUTTON_RIGHT | BUTTON_REPEAT: | 326 | draw_display(); |
288 | if (bpm < 400) | 327 | break; |
289 | bpm=bpm+10; | 328 | |
290 | calc_period(); | 329 | case BUTTON_LEFT | BUTTON_REPEAT: |
291 | draw_display(); | 330 | if (bpm > 10) |
292 | break; | 331 | bpm=bpm-10; |
293 | 332 | calc_period(); | |
294 | default: | 333 | draw_display(); |
295 | if (rb->default_event_handler_ex(button, cleanup, NULL) | 334 | break; |
296 | == SYS_USB_CONNECTED) | 335 | |
297 | return PLUGIN_USB_CONNECTED; | 336 | case BUTTON_RIGHT: |
298 | break; | 337 | if(bpm < 400) |
299 | 338 | bpm++; | |
300 | } | 339 | calc_period(); |
340 | draw_display(); | ||
341 | break; | ||
342 | |||
343 | case BUTTON_RIGHT | BUTTON_REPEAT: | ||
344 | if (bpm < 400) | ||
345 | bpm=bpm+10; | ||
346 | calc_period(); | ||
347 | draw_display(); | ||
348 | break; | ||
349 | |||
350 | #if CONFIG_KEYPAD != ONDIO_PAD | ||
351 | case METRONOME_TAP: | ||
352 | tap(); | ||
353 | break; | ||
354 | #endif | ||
355 | |||
356 | default: | ||
357 | if (rb->default_event_handler_ex(button, cleanup, NULL) | ||
358 | == SYS_USB_CONNECTED) | ||
359 | return PLUGIN_USB_CONNECTED; | ||
360 | reset_tap = false; | ||
361 | break; | ||
362 | |||
363 | } | ||
364 | if (reset_tap) { | ||
365 | tap_count = 0; | ||
366 | } | ||
301 | } | 367 | } |
302 | } | 368 | } |
303 | #endif /* #ifndef SIMULATOR */ | 369 | #endif /* #ifndef SIMULATOR */ |
diff --git a/docs/CREDITS b/docs/CREDITS index d5ebe46f72..0935ea997f 100644 --- a/docs/CREDITS +++ b/docs/CREDITS | |||
@@ -93,3 +93,4 @@ Jan Gajdos | |||
93 | Antoine Cellerier | 93 | Antoine Cellerier |
94 | Brian King | 94 | Brian King |
95 | Jiri Jurecek | 95 | Jiri Jurecek |
96 | Jacob Erlbeck | ||