From 8d5a6609a33f3269bc80975b81e0e859a056d952 Mon Sep 17 00:00:00 2001 From: Brandon Low Date: Sat, 21 Jan 2006 23:43:57 +0000 Subject: AB-repeat mode for software codecs. Accessible through menu as a repeat mode, with buttom mappings much like those on other rockbox targets for now. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8409 a1c6a512-1295-4272-9138-f99709370657 --- apps/abrepeat.c | 108 +++++++++++++++++++++++--------------------------------- 1 file changed, 44 insertions(+), 64 deletions(-) (limited to 'apps/abrepeat.c') diff --git a/apps/abrepeat.c b/apps/abrepeat.c index 3a3d5b394d..b83a7b6aa3 100644 --- a/apps/abrepeat.c +++ b/apps/abrepeat.c @@ -19,16 +19,20 @@ #include "abrepeat.h" -#include "settings.h" -#include "audio.h" -#include "kernel.h" - -#ifdef HAVE_LCD_BITMAP -#include "lcd.h" -#endif - #ifdef AB_REPEAT_ENABLE +unsigned int ab_A_marker IDATA_ATTR = AB_MARKER_NONE; +unsigned int ab_B_marker IDATA_ATTR = AB_MARKER_NONE; + +#if (CONFIG_CODEC == SWCODEC) +void ab_end_of_track_report(void) +{ + if ( ab_A_marker_set() && ! ab_B_marker_set() ) + { + ab_jump_to_A_marker(); + } +} +#else static int ab_audio_event_handler(unsigned short event, unsigned long data) { int rc = AUDIO_EVENT_RC_IGNORED; @@ -38,7 +42,8 @@ static int ab_audio_event_handler(unsigned short event, unsigned long data) { case AUDIO_EVENT_POS_REPORT: { - if ( ! (audio_status() & AUDIO_STATUS_PAUSE) && ab_reached_B_marker(data) ) + if ( ! (audio_status() & AUDIO_STATUS_PAUSE) && + ab_reached_B_marker(data) ) { ab_jump_to_A_marker(); rc = AUDIO_EVENT_RC_HANDLED; @@ -58,6 +63,7 @@ static int ab_audio_event_handler(unsigned short event, unsigned long data) } return rc; } +#endif void ab_repeat_init(void) { @@ -65,30 +71,13 @@ void ab_repeat_init(void) if ( ! ab_initialized ) { ab_initialized = true; +#if (CONFIG_CODEC != SWCODEC) audio_register_event_handler(ab_audio_event_handler, AUDIO_EVENT_POS_REPORT | AUDIO_EVENT_END_OF_TRACK ); +#endif } } -static unsigned int ab_A_marker = AB_MARKER_NONE; -static unsigned int ab_B_marker = AB_MARKER_NONE; - -bool ab_repeat_mode_enabled(void) -{ - extern struct user_settings global_settings; - return global_settings.repeat_mode == REPEAT_AB; -} - -bool ab_A_marker_set(void) -{ - return ab_A_marker != AB_MARKER_NONE; -} - -bool ab_B_marker_set(void) -{ - return ab_B_marker != AB_MARKER_NONE; -} - unsigned int ab_get_A_marker(void) { return ab_A_marker; @@ -99,24 +88,6 @@ unsigned int ab_get_B_marker(void) return ab_B_marker; } -bool ab_reached_B_marker(unsigned int song_position) -{ -/* following is the size of the window in which we'll detect that the B marker -was hit; it must be larger than the frequency (in milliseconds) at which this -function is called otherwise detection of the B marker will be unreliable; -we assume that this function will be called on each system tick and derive -the window size from this with a generous margin of error (note: the number -of ticks per second is given by HZ) */ -#define B_MARKER_DETECT_WINDOW ((1000/HZ)*10) - if (ab_B_marker != AB_MARKER_NONE) - { - if ( (song_position >= ab_B_marker) - && (song_position <= (ab_B_marker+B_MARKER_DETECT_WINDOW)) ) - return true; - } - return false; -} - /* determines if the given song position is earlier than the A mark; intended for use in handling the jump NEXT and PREV commands */ bool ab_before_A_marker(unsigned int song_position) @@ -129,9 +100,9 @@ bool ab_before_A_marker(unsigned int song_position) intended for use in handling the jump PREV command */ bool ab_after_A_marker(unsigned int song_position) { -/* following is the size of the virtual A marker; we pretend that the A marker is -larger than a single instant in order to give the user time to hit PREV again to -jump back to the start of the song; it should be large enough to allow a +/* following is the size of the virtual A marker; we pretend that the A marker +is larger than a single instant in order to give the user time to hit PREV again +to jump back to the start of the song; it should be large enough to allow a reasonable amount of time for the typical user to react */ #define A_MARKER_VIRTUAL_SIZE 1000 return (ab_A_marker != AB_MARKER_NONE) @@ -140,12 +111,16 @@ reasonable amount of time for the typical user to react */ void ab_jump_to_A_marker(void) { +#if (CONFIG_CODEC == SWCODEC) + audio_seamless_seek(ab_A_marker); +#else bool paused = (audio_status() & AUDIO_STATUS_PAUSE) != 0; if ( ! paused ) audio_pause(); audio_ff_rewind(ab_A_marker); if ( ! paused ) audio_resume(); +#endif } void ab_reset_markers(void) @@ -182,37 +157,42 @@ void ab_set_B_marker(unsigned int song_position) #ifdef HAVE_LCD_BITMAP -static int ab_calc_mark_x_pos(int mark, int capacity, int offset, int size) +static inline int ab_calc_mark_x_pos(int mark, int capacity, + int offset, int size) { int w = size - offset; return offset + ( (w * mark) / capacity ); } -static void ab_draw_veritcal_line_mark(int x, int y, int h) +static inline void ab_draw_veritcal_line_mark(struct screen * screen, + int x, int y, int h) { - lcd_set_drawmode(DRMODE_COMPLEMENT); - lcd_vline(x, y, y+h-1); + screen->set_drawmode(DRMODE_COMPLEMENT); + screen->vline(x, y, y+h-1); } #define DIRECTION_RIGHT 1 #define DIRECTION_LEFT -1 -static void ab_draw_arrow_mark(int x, int y, int h, int direction) +static inline void ab_draw_arrow_mark(struct screen * screen, + int x, int y, int h, int direction) { /* draw lines in decreasing size until a height of zero is reached */ - lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); + screen->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); while( h > 0 ) { - lcd_vline(x, y, y+h-1); + screen->vline(x, y, y+h-1); h -= 2; y++; x += direction; - lcd_set_drawmode(DRMODE_COMPLEMENT); + screen->set_drawmode(DRMODE_COMPLEMENT); } } -void ab_draw_markers(int capacity, int x, int y, int w, int h) +void ab_draw_markers(struct screen * screen, int capacity, + int x, int y, int h) { + int w = screen->width; /* if both markers are set, determine if they're far enough apart to draw arrows */ if ( ab_A_marker_set() && ab_B_marker_set() ) @@ -222,13 +202,13 @@ void ab_draw_markers(int capacity, int x, int y, int w, int h) int arrow_width = (h+1) / 2; if ( (xb-xa) < (arrow_width*2) ) { - ab_draw_veritcal_line_mark(xa, y, h); - ab_draw_veritcal_line_mark(xb, y, h); + ab_draw_veritcal_line_mark(screen, xa, y, h); + ab_draw_veritcal_line_mark(screen, xb, y, h); } else { - ab_draw_arrow_mark(xa, y, h, DIRECTION_RIGHT); - ab_draw_arrow_mark(xb, y, h, DIRECTION_LEFT); + ab_draw_arrow_mark(screen, xa, y, h, DIRECTION_RIGHT); + ab_draw_arrow_mark(screen, xb, y, h, DIRECTION_LEFT); } } else @@ -236,12 +216,12 @@ void ab_draw_markers(int capacity, int x, int y, int w, int h) if (ab_A_marker_set()) { int xa = ab_calc_mark_x_pos(ab_A_marker, capacity, x, w); - ab_draw_arrow_mark(xa, y, h, DIRECTION_RIGHT); + ab_draw_arrow_mark(screen, xa, y, h, DIRECTION_RIGHT); } if (ab_B_marker_set()) { int xb = ab_calc_mark_x_pos(ab_B_marker, capacity, x, w); - ab_draw_arrow_mark(xb, y, h, DIRECTION_LEFT); + ab_draw_arrow_mark(screen, xb, y, h, DIRECTION_LEFT); } } } -- cgit v1.2.3