diff options
Diffstat (limited to 'apps/playlist.c')
-rw-r--r-- | apps/playlist.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index b81aed8763..038e710829 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -66,15 +66,37 @@ int playlist_add(char *filename) | |||
66 | return 0; | 66 | return 0; |
67 | } | 67 | } |
68 | 68 | ||
69 | int playlist_next(int steps) | 69 | static int get_next_index(int steps) |
70 | { | 70 | { |
71 | playlist.index = (playlist.index+steps) % playlist.amount; | 71 | int next_index = -1; |
72 | while ( playlist.index < 0 ) { | 72 | |
73 | if ( global_settings.loop_playlist ) | 73 | switch (global_settings.repeat_mode) |
74 | playlist.index += playlist.amount; | 74 | { |
75 | else | 75 | case REPEAT_OFF: |
76 | playlist.index = 0; | 76 | next_index = playlist.index+steps; |
77 | if ((next_index < 0) || (next_index >= playlist.amount)) | ||
78 | next_index = -1; | ||
79 | break; | ||
80 | |||
81 | case REPEAT_ONE: | ||
82 | next_index = playlist.index; | ||
83 | break; | ||
84 | |||
85 | case REPEAT_ALL: | ||
86 | default: | ||
87 | next_index = (playlist.index+steps) % playlist.amount; | ||
88 | while (next_index < 0) | ||
89 | next_index += playlist.amount; | ||
90 | break; | ||
77 | } | 91 | } |
92 | |||
93 | return next_index; | ||
94 | } | ||
95 | |||
96 | int playlist_next(int steps) | ||
97 | { | ||
98 | playlist.index = get_next_index(steps); | ||
99 | |||
78 | return playlist.index; | 100 | return playlist.index; |
79 | } | 101 | } |
80 | 102 | ||
@@ -93,14 +115,11 @@ char* playlist_peek(int steps) | |||
93 | /* prevent madness when all files are empty/bad */ | 115 | /* prevent madness when all files are empty/bad */ |
94 | return NULL; | 116 | return NULL; |
95 | 117 | ||
96 | index = (playlist.index+steps) % playlist.amount; | 118 | index = get_next_index(steps); |
97 | while ( index < 0 ) { | 119 | if (index >= 0) |
98 | if ( global_settings.loop_playlist ) | ||
99 | index += playlist.amount; | ||
100 | else | ||
101 | index = 0; | ||
102 | } | ||
103 | seek = playlist.indices[index]; | 120 | seek = playlist.indices[index]; |
121 | else | ||
122 | return NULL; | ||
104 | 123 | ||
105 | if(playlist.in_ram) | 124 | if(playlist.in_ram) |
106 | { | 125 | { |