summaryrefslogtreecommitdiff
path: root/apps/playlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c110
1 files changed, 93 insertions, 17 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 2646a27040..9ab1ad9f4a 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -162,6 +162,8 @@ static int compare(const void* p1, const void* p2);
162static int get_filename(struct playlist_info* playlist, int seek, 162static int get_filename(struct playlist_info* playlist, int seek,
163 bool control_file, char *buf, int buf_length); 163 bool control_file, char *buf, int buf_length);
164static int get_next_directory(char *dir); 164static int get_next_directory(char *dir);
165static int get_next_dir(char *dir, bool is_forward, bool recursion);
166static int get_previous_directory(char *dir);
165static int check_subdir_for_music(char *dir, char *subdir); 167static int check_subdir_for_music(char *dir, char *subdir);
166static int format_track_path(char *dest, char *src, int buf_length, int max, 168static int format_track_path(char *dest, char *src, int buf_length, int max,
167 char *dir); 169 char *dir);
@@ -1098,26 +1100,53 @@ static int get_filename(struct playlist_info* playlist, int seek,
1098 return (format_track_path(buf, tmp_buf, buf_length, max, dir_buf)); 1100 return (format_track_path(buf, tmp_buf, buf_length, max, dir_buf));
1099} 1101}
1100 1102
1103static int get_next_directory(char *dir){
1104 return get_next_dir(dir,true,false);
1105}
1106
1107static int get_previous_directory(char *dir){
1108 return get_next_dir(dir,false,false);
1109}
1110
1101/* 1111/*
1102 * search through all the directories (starting with the current) to find 1112 * search through all the directories (starting with the current) to find
1103 * one that has tracks to play 1113 * one that has tracks to play
1104 */ 1114 */
1105static int get_next_directory(char *dir) 1115static int get_next_dir(char *dir, bool is_forward, bool recursion)
1106{ 1116{
1107 struct playlist_info* playlist = &current_playlist; 1117 struct playlist_info* playlist = &current_playlist;
1108 int result = -1; 1118 int result = -1;
1109 int dirfilter = global_settings.dirfilter; 1119 int dirfilter = global_settings.dirfilter;
1120 int sort_dir = global_settings.sort_dir;
1110 char *start_dir = NULL; 1121 char *start_dir = NULL;
1111 bool exit = false; 1122 bool exit = false;
1112 struct tree_context* tc = tree_get_context(); 1123 struct tree_context* tc = tree_get_context();
1113 1124
1114 /* start with current directory */ 1125 if (recursion){
1115 strncpy(dir, playlist->filename, playlist->dirlen-1); 1126 /* start with root */
1116 dir[playlist->dirlen-1] = '\0'; 1127 dir[0] = '\0';
1128 }
1129 else{
1130 /* start with current directory */
1131 strncpy(dir, playlist->filename, playlist->dirlen-1);
1132 dir[playlist->dirlen-1] = '\0';
1133 }
1117 1134
1118 /* use the tree browser dircache to load files */ 1135 /* use the tree browser dircache to load files */
1119 global_settings.dirfilter = SHOW_ALL; 1136 global_settings.dirfilter = SHOW_ALL;
1120 1137
1138 /* sort in another direction if previous dir is requested */
1139 if(!is_forward){
1140 if ((global_settings.sort_dir == 0) || (global_settings.sort_dir == 3))
1141 global_settings.sort_dir = 4;
1142 else if (global_settings.sort_dir == 1)
1143 global_settings.sort_dir = 2;
1144 else if (global_settings.sort_dir == 2)
1145 global_settings.sort_dir = 1;
1146 else if (global_settings.sort_dir == 4)
1147 global_settings.sort_dir = 0;
1148 }
1149
1121 while (!exit) 1150 while (!exit)
1122 { 1151 {
1123 struct entry *files; 1152 struct entry *files;
@@ -1180,8 +1209,14 @@ static int get_next_directory(char *dir)
1180 reloaded */ 1209 reloaded */
1181 reload_directory(); 1210 reload_directory();
1182 1211
1183 /* restore dirfilter */ 1212 /* restore dirfilter & sort_dir */
1184 global_settings.dirfilter = dirfilter; 1213 global_settings.dirfilter = dirfilter;
1214 global_settings.sort_dir = sort_dir;
1215
1216 /* special case if nothing found: try start searching again from root */
1217 if (result == -1 && !recursion){
1218 result = get_next_dir(dir,is_forward, true);
1219 }
1185 1220
1186 return result; 1221 return result;
1187} 1222}
@@ -1922,13 +1957,14 @@ int playlist_start(int start_index, int offset)
1922bool playlist_check(int steps) 1957bool playlist_check(int steps)
1923{ 1958{
1924 struct playlist_info* playlist = &current_playlist; 1959 struct playlist_info* playlist = &current_playlist;
1960
1961 /* always allow folder navigation */
1962 if (global_settings.next_folder && playlist->in_ram)
1963 return true;
1964
1925 int index = get_next_index(playlist, steps, -1); 1965 int index = get_next_index(playlist, steps, -1);
1926 1966
1927 if (index < 0 && steps >= 0 && 1967 if (index < 0 && steps >= 0 && global_settings.repeat_mode == REPEAT_SHUFFLE)
1928 (global_settings.repeat_mode == REPEAT_SHUFFLE ||
1929 (global_settings.next_folder && playlist->in_ram)))
1930 /* shuffle repeat and move to next folder are the same as repeat all
1931 for check purposes */
1932 index = get_next_index(playlist, steps, REPEAT_ALL); 1968 index = get_next_index(playlist, steps, REPEAT_ALL);
1933 1969
1934 return (index >= 0); 1970 return (index >= 0);
@@ -2031,23 +2067,40 @@ int playlist_next(int steps)
2031 playlist_start(0, 0); 2067 playlist_start(0, 0);
2032 index = 0; 2068 index = 0;
2033 } 2069 }
2034 else if (global_settings.next_folder && playlist->in_ram) 2070 else if (playlist->in_ram && global_settings.next_folder)
2035 { 2071 {
2036 char dir[MAX_PATH+1]; 2072 char dir[MAX_PATH+1];
2037 2073
2038 if (!get_next_directory(dir)) 2074 if (steps > 0)
2039 { 2075 {
2040 /* start playing new directory */ 2076 if (!get_next_directory(dir))
2077 {
2078 /* start playing next directory */
2079 if (playlist_create(dir, NULL) != -1)
2080 {
2081 ft_build_playlist(tree_get_context(), 0);
2082 if (global_settings.playlist_shuffle)
2083 playlist_shuffle(current_tick, -1);
2084 playlist_start(0, 0);
2085 index = 0;
2086 }
2087 }
2088 }
2089 else
2090 {
2091 if (!get_previous_directory(dir))
2092 {
2093 /* start playing previous directory */
2041 if (playlist_create(dir, NULL) != -1) 2094 if (playlist_create(dir, NULL) != -1)
2042 { 2095 {
2043 ft_build_playlist(tree_get_context(), 0); 2096 ft_build_playlist(tree_get_context(), 0);
2044 if (global_settings.playlist_shuffle) 2097 if (global_settings.playlist_shuffle)
2045 playlist_shuffle(current_tick, -1); 2098 playlist_shuffle(current_tick, -1);
2046 2099 playlist_start(current_playlist.amount-1,0);
2047 playlist_start(0, 0); 2100 index = current_playlist.amount-1;
2048 index = 0;
2049 } 2101 }
2050 } 2102 }
2103 }
2051 } 2104 }
2052 2105
2053 return index; 2106 return index;
@@ -2096,6 +2149,29 @@ int playlist_next(int steps)
2096 return index; 2149 return index;
2097} 2150}
2098 2151
2152/* try playing next or previous folder */
2153bool playlist_next_dir(int direction)
2154{
2155 char dir[MAX_PATH+1];
2156
2157 if (((direction > 0) && !get_next_directory(dir)) ||
2158 ((direction < 0) && !get_previous_directory(dir)))
2159 {
2160 if (playlist_create(dir, NULL) != -1)
2161 {
2162 ft_build_playlist(tree_get_context(), 0);
2163 if (global_settings.playlist_shuffle)
2164 playlist_shuffle(current_tick, -1);
2165 playlist_start(0,0);
2166 return true;
2167 }
2168 else
2169 return false;
2170 }
2171 else
2172 return false;
2173}
2174
2099/* Get resume info for current playing song. If return value is -1 then 2175/* Get resume info for current playing song. If return value is -1 then
2100 settings shouldn't be saved. */ 2176 settings shouldn't be saved. */
2101int playlist_get_resume_info(int *resume_index) 2177int playlist_get_resume_info(int *resume_index)