/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2002 by wavey@wavey.org * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #include #include #include #include "playlist.h" #include #include "sprintf.h" #include "debug.h" #include "mpeg.h" #include "lcd.h" #include "kernel.h" #include "settings.h" #include "status.h" #ifdef HAVE_LCD_BITMAP #define LINE_Y (global_settings.statusbar&&statusbar_enabled?1:0) /* Y position the entry-list starts at */ #else /* HAVE_LCD_BITMAP */ #define LINE_Y 0 /* Y position the entry-list starts at */ #endif /* HAVE_LCD_BITMAP */ playlist_info_t playlist; #define PLAYLIST_BUFFER_SIZE (MAX_PATH*200) unsigned char playlist_buffer[PLAYLIST_BUFFER_SIZE]; static int playlist_end_pos = 0; char now_playing[MAX_PATH+1]; void playlist_clear(void) { playlist_end_pos = 0; playlist_buffer[0] = 0; } int playlist_add(char *filename) { int len = strlen(filename); if(len+2 > PLAYLIST_BUFFER_SIZE - playlist_end_pos) return -1; strcpy(&playlist_buffer[playlist_end_pos], filename); playlist_end_pos += len; playlist_buffer[playlist_end_pos++] = '\n'; playlist_buffer[playlist_end_pos] = '\0'; return 0; } char* playlist_next(int steps) { int seek; int max; int fd; int i; char *buf; char dir_buf[MAX_PATH+1]; char *dir_end; playlist.index = (playlist.index+steps) % playlist.amount; while ( playlist.index < 0 ) { if ( global_settings.loop_playlist ) playlist.index += playlist.amount; else playlist.index = 0; } seek = playlist.indices[playlist.index]; if(playlist.in_ram) { buf = playlist_buffer + seek; max = playlist_end_pos - seek; } else { fd = open(playlist.filename, O_RDONLY); if(-1 != fd) { buf = playlist_buffer; lseek(fd, seek, SEEK_SET); max = read(fd, buf, MAX_PATH); close(fd); } else return NULL; } /* Zero-terminate the file name */ seek=0; while((buf[seek] != '\n') && (buf[seek] != '\r') && (seek < max)) seek++; /* Now work back killing white space */ while((buf[seek-1] == ' ') || (buf[seek-1] == '\t')) seek--; buf[seek]=0; /* replace backslashes with forward slashes */ for ( i=0; i= MAX_PLAYLIST_SIZE ) { if(!playlist.in_ram) close(fd); lcd_clear_display(); lcd_puts(0,0,"10000 file"); lcd_puts(0,1,"limit reached"); lcd_update(); sleep(HZ*2); lcd_clear_display(); return; } store_index = 0; /* Update the screen if it takes very long */ if(!playlist.in_ram) { if ( current_tick >= next_tick ) { next_tick = current_tick + HZ; snprintf(line, sizeof line, "%d files", playlist.amount); lcd_puts(0,LINE_Y+1,line); status_draw(); lcd_update(); } } } } i+= count; if(playlist.in_ram) break; } if(!playlist.in_ram) { snprintf(line, sizeof line, "%d files", playlist.amount); lcd_puts(0,LINE_Y+1,line); status_draw(); lcd_update(); close(fd); } } /* * randomly rearrange the array of indices for the playlist */ void randomise_playlist( unsigned int seed ) { int count; int candidate; int store; /* seed with the given seed */ srand( seed ); /* randomise entire indices list */ for(count = playlist.amount - 1; count >= 0; count--) { /* the rand is from 0 to RAND_MAX, so adjust to our value range */ candidate = rand() % (count + 1); /* now swap the values at the 'count' and 'candidate' positions */ store = playlist.indices[candidate]; playlist.indices[candidate] = playlist.indices[count]; playlist.indices[count] = store; } } static int compare(const void* p1, const void* p2) { int* e1 = (int*) p1; int* e2 = (int*) p2; return *e1 - *e2; } /* * sort the array of indices for the playlist */ void sort_playlist(void) { if (playlist.amount > 0) { qsort(&playlist.indices, playlist.amount, sizeof(playlist.indices[0]), compare); } } /* ----------------------------------------------------------------- * local variables: * eval: (load-file "../firmware/rockbox-mode.el") * end: */