diff options
-rw-r--r-- | apps/playlist.c | 20 | ||||
-rw-r--r-- | apps/playlist.h | 8 | ||||
-rw-r--r-- | apps/settings.c | 10 | ||||
-rw-r--r-- | apps/settings.h | 1 | ||||
-rw-r--r-- | apps/tree.c | 15 |
5 files changed, 38 insertions, 16 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 038e710829..23c3f5d606 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -68,23 +68,30 @@ int playlist_add(char *filename) | |||
68 | 68 | ||
69 | static int get_next_index(int steps) | 69 | static int get_next_index(int steps) |
70 | { | 70 | { |
71 | int next_index = -1; | 71 | int current_index = playlist.index; |
72 | int next_index = -1; | ||
72 | 73 | ||
73 | switch (global_settings.repeat_mode) | 74 | switch (global_settings.repeat_mode) |
74 | { | 75 | { |
75 | case REPEAT_OFF: | 76 | case REPEAT_OFF: |
76 | next_index = playlist.index+steps; | 77 | if (current_index < playlist.first_index) |
78 | current_index += playlist.amount; | ||
79 | current_index -= playlist.first_index; | ||
80 | |||
81 | next_index = current_index+steps; | ||
77 | if ((next_index < 0) || (next_index >= playlist.amount)) | 82 | if ((next_index < 0) || (next_index >= playlist.amount)) |
78 | next_index = -1; | 83 | next_index = -1; |
84 | else | ||
85 | next_index = (next_index+playlist.first_index)%playlist.amount; | ||
79 | break; | 86 | break; |
80 | 87 | ||
81 | case REPEAT_ONE: | 88 | case REPEAT_ONE: |
82 | next_index = playlist.index; | 89 | next_index = current_index; |
83 | break; | 90 | break; |
84 | 91 | ||
85 | case REPEAT_ALL: | 92 | case REPEAT_ALL: |
86 | default: | 93 | default: |
87 | next_index = (playlist.index+steps) % playlist.amount; | 94 | next_index = (current_index+steps) % playlist.amount; |
88 | while (next_index < 0) | 95 | while (next_index < 0) |
89 | next_index += playlist.amount; | 96 | next_index += playlist.amount; |
90 | break; | 97 | break; |
@@ -212,13 +219,15 @@ int play_list(char *dir, /* "current directory" */ | |||
212 | bool shuffled_index, /* if TRUE the specified index is for the | 219 | bool shuffled_index, /* if TRUE the specified index is for the |
213 | playlist AFTER the shuffle */ | 220 | playlist AFTER the shuffle */ |
214 | int start_offset, /* offset in the file */ | 221 | int start_offset, /* offset in the file */ |
215 | int random_seed ) /* used for shuffling */ | 222 | int random_seed, /* used for shuffling */ |
223 | int first_index ) /* first index of playlist */ | ||
216 | { | 224 | { |
217 | char *sep=""; | 225 | char *sep=""; |
218 | int dirlen; | 226 | int dirlen; |
219 | empty_playlist(); | 227 | empty_playlist(); |
220 | 228 | ||
221 | playlist.index = start_index; | 229 | playlist.index = start_index; |
230 | playlist.first_index = first_index; | ||
222 | 231 | ||
223 | #ifdef HAVE_LCD_BITMAP | 232 | #ifdef HAVE_LCD_BITMAP |
224 | if(global_settings.statusbar) | 233 | if(global_settings.statusbar) |
@@ -283,6 +292,7 @@ int play_list(char *dir, /* "current directory" */ | |||
283 | if(seek_pos == playlist.indices[i]) { | 292 | if(seek_pos == playlist.indices[i]) { |
284 | /* here's the start song! yiepee! */ | 293 | /* here's the start song! yiepee! */ |
285 | playlist.index = i; | 294 | playlist.index = i; |
295 | playlist.first_index = i; | ||
286 | break; /* now stop searching */ | 296 | break; /* now stop searching */ |
287 | } | 297 | } |
288 | } | 298 | } |
diff --git a/apps/playlist.h b/apps/playlist.h index a18240db7f..9f66b7f49e 100644 --- a/apps/playlist.h +++ b/apps/playlist.h | |||
@@ -28,10 +28,11 @@ | |||
28 | 28 | ||
29 | struct playlist_info | 29 | struct playlist_info |
30 | { | 30 | { |
31 | char filename[MAX_PATH]; /* path name of m3u playlist on disk */ | 31 | char filename[MAX_PATH]; /* path name of m3u playlist on disk */ |
32 | int dirlen; /* Length of the path to the playlist file */ | 32 | int dirlen; /* Length of the path to the playlist file */ |
33 | int indices[MAX_PLAYLIST_SIZE]; /* array of indices */ | 33 | int indices[MAX_PLAYLIST_SIZE]; /* array of indices */ |
34 | int index; /* index of *NEXT* track to play */ | 34 | int index; /* index of current playing track */ |
35 | int first_index; /* index of first song in playlist */ | ||
35 | int seed; /* random seed */ | 36 | int seed; /* random seed */ |
36 | int amount; /* number of tracks in the index */ | 37 | int amount; /* number of tracks in the index */ |
37 | bool in_ram; /* True if the playlist is RAM-based */ | 38 | bool in_ram; /* True if the playlist is RAM-based */ |
@@ -41,7 +42,8 @@ extern struct playlist_info playlist; | |||
41 | extern bool playlist_shuffle; | 42 | extern bool playlist_shuffle; |
42 | 43 | ||
43 | int play_list(char *dir, char *file, int start_index, | 44 | int play_list(char *dir, char *file, int start_index, |
44 | bool shuffled_index, int start_offset, int random_seed ); | 45 | bool shuffled_index, int start_offset, |
46 | int random_seed, int first_index); | ||
45 | char* playlist_peek(int steps); | 47 | char* playlist_peek(int steps); |
46 | int playlist_next(int steps); | 48 | int playlist_next(int steps); |
47 | void randomise_playlist( unsigned int seed ); | 49 | void randomise_playlist( unsigned int seed ); |
diff --git a/apps/settings.c b/apps/settings.c index 0ba72df110..dab44fe229 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -112,6 +112,7 @@ modified unless the header & checksum test fails. | |||
112 | 112 | ||
113 | Rest of config block, only saved to disk: | 113 | Rest of config block, only saved to disk: |
114 | 114 | ||
115 | 0xF4 (int) Playlist first index | ||
115 | 0xF8 (int) Playlist shuffle seed | 116 | 0xF8 (int) Playlist shuffle seed |
116 | 0xFC (char[260]) Resume playlist (path/to/dir or path/to/playlist.m3u) | 117 | 0xFC (char[260]) Resume playlist (path/to/dir or path/to/playlist.m3u) |
117 | 118 | ||
@@ -316,9 +317,11 @@ int settings_save( void ) | |||
316 | config_block[0x1e] = (unsigned char)global_settings.peak_meter_release; | 317 | config_block[0x1e] = (unsigned char)global_settings.peak_meter_release; |
317 | config_block[0x1f] = (unsigned char)global_settings.repeat_mode; | 318 | config_block[0x1f] = (unsigned char)global_settings.repeat_mode; |
318 | 319 | ||
320 | memcpy(&config_block[0x24], &global_settings.total_uptime, 4); | ||
321 | |||
322 | memcpy(&config_block[0xF4], &global_settings.resume_first_index, 4); | ||
319 | memcpy(&config_block[0xF8], &global_settings.resume_seed, 4); | 323 | memcpy(&config_block[0xF8], &global_settings.resume_seed, 4); |
320 | 324 | ||
321 | memcpy(&config_block[0x24], &global_settings.total_uptime, 4); | ||
322 | strncpy(&config_block[0xFC], global_settings.resume_file, MAX_PATH); | 325 | strncpy(&config_block[0xFC], global_settings.resume_file, MAX_PATH); |
323 | 326 | ||
324 | DEBUGF("+Resume file %s\n",global_settings.resume_file); | 327 | DEBUGF("+Resume file %s\n",global_settings.resume_file); |
@@ -471,11 +474,12 @@ void settings_load(void) | |||
471 | if (config_block[0x1f] != 0xFF) | 474 | if (config_block[0x1f] != 0xFF) |
472 | global_settings.repeat_mode = config_block[0x1f]; | 475 | global_settings.repeat_mode = config_block[0x1f]; |
473 | 476 | ||
474 | memcpy(&global_settings.resume_seed, &config_block[0xF8], 4); | ||
475 | |||
476 | if (config_block[0x24] != 0xFF) | 477 | if (config_block[0x24] != 0xFF) |
477 | memcpy(&global_settings.total_uptime, &config_block[0x24], 4); | 478 | memcpy(&global_settings.total_uptime, &config_block[0x24], 4); |
478 | 479 | ||
480 | memcpy(&global_settings.resume_first_index, &config_block[0xF4], 4); | ||
481 | memcpy(&global_settings.resume_seed, &config_block[0xF8], 4); | ||
482 | |||
479 | strncpy(global_settings.resume_file, &config_block[0xFC], MAX_PATH); | 483 | strncpy(global_settings.resume_file, &config_block[0xFC], MAX_PATH); |
480 | global_settings.resume_file[MAX_PATH]=0; | 484 | global_settings.resume_file[MAX_PATH]=0; |
481 | } | 485 | } |
diff --git a/apps/settings.h b/apps/settings.h index b30d8aa744..d64d00e8cf 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -73,6 +73,7 @@ struct user_settings | |||
73 | int resume_index; /* index in playlist (-1 for no active resume) */ | 73 | int resume_index; /* index in playlist (-1 for no active resume) */ |
74 | int resume_offset; /* byte offset in mp3 file */ | 74 | int resume_offset; /* byte offset in mp3 file */ |
75 | int resume_seed; /* random seed for playlist shuffle */ | 75 | int resume_seed; /* random seed for playlist shuffle */ |
76 | int resume_first_index; /* first index of playlist */ | ||
76 | unsigned char resume_file[MAX_PATH+1]; /* playlist name (or dir) */ | 77 | unsigned char resume_file[MAX_PATH+1]; /* playlist name (or dir) */ |
77 | 78 | ||
78 | /* misc options */ | 79 | /* misc options */ |
diff --git a/apps/tree.c b/apps/tree.c index 653b6afa2a..f4a49a9dce 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -505,7 +505,8 @@ void start_resume(void) | |||
505 | global_settings.resume_index, | 505 | global_settings.resume_index, |
506 | true, /* the index is AFTER shuffle */ | 506 | true, /* the index is AFTER shuffle */ |
507 | global_settings.resume_offset, | 507 | global_settings.resume_offset, |
508 | global_settings.resume_seed ); | 508 | global_settings.resume_seed, |
509 | global_settings.resume_first_index); | ||
509 | *slash='/'; | 510 | *slash='/'; |
510 | } | 511 | } |
511 | else { | 512 | else { |
@@ -523,7 +524,8 @@ void start_resume(void) | |||
523 | global_settings.resume_index, | 524 | global_settings.resume_index, |
524 | true, | 525 | true, |
525 | global_settings.resume_offset, | 526 | global_settings.resume_offset, |
526 | global_settings.resume_seed ); | 527 | global_settings.resume_seed, |
528 | global_settings.resume_first_index); | ||
527 | } | 529 | } |
528 | } | 530 | } |
529 | else { | 531 | else { |
@@ -541,7 +543,8 @@ void start_resume(void) | |||
541 | global_settings.resume_index, | 543 | global_settings.resume_index, |
542 | true, | 544 | true, |
543 | global_settings.resume_offset, | 545 | global_settings.resume_offset, |
544 | global_settings.resume_seed); | 546 | global_settings.resume_seed, |
547 | global_settings.resume_first_index); | ||
545 | } | 548 | } |
546 | 549 | ||
547 | status_set_playmode(STATUS_PLAY); | 550 | status_set_playmode(STATUS_PLAY); |
@@ -775,7 +778,8 @@ bool dirbrowse(char *root) | |||
775 | snprintf(global_settings.resume_file, | 778 | snprintf(global_settings.resume_file, |
776 | MAX_PATH, "%s/%s", | 779 | MAX_PATH, "%s/%s", |
777 | currdir, file->name); | 780 | currdir, file->name); |
778 | play_list(currdir, file->name, 0, false, 0, seed ); | 781 | play_list(currdir, file->name, 0, false, 0, |
782 | seed, 0); | ||
779 | start_index = 0; | 783 | start_index = 0; |
780 | play = true; | 784 | play = true; |
781 | break; | 785 | break; |
@@ -790,7 +794,7 @@ bool dirbrowse(char *root) | |||
790 | the (shuffled) list and stor that */ | 794 | the (shuffled) list and stor that */ |
791 | start_index = play_list(currdir, NULL, | 795 | start_index = play_list(currdir, NULL, |
792 | start_index, false, | 796 | start_index, false, |
793 | 0, seed); | 797 | 0, seed, 0); |
794 | play = true; | 798 | play = true; |
795 | break; | 799 | break; |
796 | 800 | ||
@@ -872,6 +876,7 @@ bool dirbrowse(char *root) | |||
872 | shuffled list in case shuffle is enabled */ | 876 | shuffled list in case shuffle is enabled */ |
873 | global_settings.resume_index = start_index; | 877 | global_settings.resume_index = start_index; |
874 | global_settings.resume_offset = 0; | 878 | global_settings.resume_offset = 0; |
879 | global_settings.resume_first_index = start_index; | ||
875 | global_settings.resume_seed = seed; | 880 | global_settings.resume_seed = seed; |
876 | settings_save(); | 881 | settings_save(); |
877 | } | 882 | } |