diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-08-31 12:46:10 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-09-04 10:58:24 -0400 |
commit | 34e54b33f790858998de6f224458b93e54424ed9 (patch) | |
tree | 55fd8adf5319285dfbb4620c0c2098e0ed502183 /apps/tagtree.c | |
parent | 87e9ca2d3a378fb55fd84e3e541e8548c21df846 (diff) | |
download | rockbox-34e54b33f790858998de6f224458b93e54424ed9.tar.gz rockbox-34e54b33f790858998de6f224458b93e54424ed9.zip |
codestyle changes on g5911
Change-Id: I8e3b172686fe78d52a8b407193479d3af36ee536
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r-- | apps/tagtree.c | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c index 4a0bff32bd..8f6b1419a9 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -2131,24 +2131,28 @@ int tagtree_get_custom_action(struct tree_context* c) | |||
2131 | return tagtree_get_entry(c, c->selected_item)->customaction; | 2131 | return tagtree_get_entry(c, c->selected_item)->customaction; |
2132 | } | 2132 | } |
2133 | 2133 | ||
2134 | static void swap_array_bool(bool *a, bool *b) { | 2134 | static void swap_array_bool(bool *a, bool *b) |
2135 | { | ||
2135 | bool temp = *a; | 2136 | bool temp = *a; |
2136 | *a = *b; | 2137 | *a = *b; |
2137 | *b = temp; | 2138 | *b = temp; |
2138 | } | 2139 | } |
2139 | 2140 | ||
2140 | /** | 2141 | /** |
2141 | * Randomly shuffle an array using the Fisher-Yates algorithm : https://en.wikipedia.org/wiki/Random_permutation | 2142 | * Randomly shuffle an array using the Fisher-Yates algorithm : https://en.wikipedia.org/wiki/Random_permutation |
2142 | * This algorithm has a linear complexity. Don't forget to srand before call to use it with a relevant seed. | 2143 | * This algorithm has a linear complexity. Don't forget to srand before call to use it with a relevant seed. |
2143 | */ | 2144 | */ |
2144 | static void shuffle_bool_array(bool array[], int size) { | 2145 | static void shuffle_bool_array(bool array[], int size) |
2145 | for (int i = size - 1; i > 0; i--) { | 2146 | { |
2147 | for (int i = size - 1; i > 0; i--) | ||
2148 | { | ||
2146 | int j = rand() % (i + 1); | 2149 | int j = rand() % (i + 1); |
2147 | swap_array_bool(&array[i], &array[j]); | 2150 | swap_array_bool(&array[i], &array[j]); |
2148 | } | 2151 | } |
2149 | } | 2152 | } |
2150 | 2153 | ||
2151 | static bool fill_selective_random_playlist_indexes(int current_segment_n, int current_segment_max_available_space) { | 2154 | static bool fill_selective_random_playlist_indexes(int current_segment_n, int current_segment_max_available_space) |
2155 | { | ||
2152 | if (current_segment_n == 0 || current_segment_max_available_space == 0) | 2156 | if (current_segment_n == 0 || current_segment_max_available_space == 0) |
2153 | return false; | 2157 | return false; |
2154 | if (current_segment_max_available_space > current_segment_n) | 2158 | if (current_segment_max_available_space > current_segment_n) |
@@ -2212,9 +2216,11 @@ static bool insert_all_playlist(struct tree_context *c, | |||
2212 | bool will_exceed = n > playlist_get_current()->max_playlist_size; | 2216 | bool will_exceed = n > playlist_get_current()->max_playlist_size; |
2213 | fill_randomly = will_exceed; | 2217 | fill_randomly = will_exceed; |
2214 | } | 2218 | } |
2215 | if (leftovers_segment_size > 0 && fill_randomly) { | 2219 | if (leftovers_segment_size > 0 && fill_randomly) |
2216 | // We need to re-balance the segments so the randomness will be coherent and balanced the same through all segments | 2220 | { |
2217 | while (leftovers_segment_size + segments_count < segment_size) { | 2221 | /* We need to re-balance the segments so the randomness will be coherent and balanced the same through all segments */ |
2222 | while (leftovers_segment_size + segments_count < segment_size) | ||
2223 | { | ||
2218 | segment_size--; // -1 to all other segments | 2224 | segment_size--; // -1 to all other segments |
2219 | leftovers_segment_size += segments_count; | 2225 | leftovers_segment_size += segments_count; |
2220 | } | 2226 | } |
@@ -2223,14 +2229,19 @@ static bool insert_all_playlist(struct tree_context *c, | |||
2223 | segments_count += 1; | 2229 | segments_count += 1; |
2224 | int max_available_space = playlist_get_current()->max_playlist_size - playlist_get_current()->amount; | 2230 | int max_available_space = playlist_get_current()->max_playlist_size - playlist_get_current()->amount; |
2225 | int max_available_space_per_segment = max_available_space / segments_count; | 2231 | int max_available_space_per_segment = max_available_space / segments_count; |
2226 | if (fill_randomly) { | 2232 | if (fill_randomly) |
2233 | { | ||
2227 | talk_id(LANG_RANDOM_SHUFFLE_RANDOM_SELECTIVE_SONGS_SUMMARY, true); | 2234 | talk_id(LANG_RANDOM_SHUFFLE_RANDOM_SELECTIVE_SONGS_SUMMARY, true); |
2228 | splashf(HZ * 3, str(LANG_RANDOM_SHUFFLE_RANDOM_SELECTIVE_SONGS_SUMMARY), max_available_space_per_segment * segments_count); | 2235 | splashf(HZ * 3, str(LANG_RANDOM_SHUFFLE_RANDOM_SELECTIVE_SONGS_SUMMARY), |
2229 | //splashf(HZ * 5, "sz=%d lsz=%d sc=%d rcps=%d", segment_size, leftovers_segment_size, segments_count, max_available_space_per_segment); | 2236 | max_available_space_per_segment * segments_count); |
2237 | /* logf("sz=%d lsz=%d sc=%d rcps=%d", segment_size, leftovers_segment_size, | ||
2238 | segments_count, max_available_space_per_segment); */ | ||
2230 | } | 2239 | } |
2231 | for (int i = 0; i < segments_count; i++) { | 2240 | for (int i = 0; i < segments_count; i++) |
2241 | { | ||
2232 | bool is_leftovers_segment = leftovers_segment_size > 0 && i + 1 >= segments_count; | 2242 | bool is_leftovers_segment = leftovers_segment_size > 0 && i + 1 >= segments_count; |
2233 | if (fill_randomly) { | 2243 | if (fill_randomly) |
2244 | { | ||
2234 | if (is_leftovers_segment) | 2245 | if (is_leftovers_segment) |
2235 | fill_randomly = fill_selective_random_playlist_indexes(leftovers_segment_size, max_available_space_per_segment); | 2246 | fill_randomly = fill_selective_random_playlist_indexes(leftovers_segment_size, max_available_space_per_segment); |
2236 | else | 2247 | else |
@@ -2243,12 +2254,15 @@ static bool insert_all_playlist(struct tree_context *c, | |||
2243 | cur_segment_end = cur_segment_start + leftovers_segment_size; | 2254 | cur_segment_end = cur_segment_start + leftovers_segment_size; |
2244 | else | 2255 | else |
2245 | cur_segment_end = cur_segment_start + segment_size; | 2256 | cur_segment_end = cur_segment_start + segment_size; |
2246 | for (int j = cur_segment_start; j < cur_segment_end && !exit_loop_now; j++) { | 2257 | for (int j = cur_segment_start; j < cur_segment_end && !exit_loop_now; j++) |
2258 | { | ||
2247 | if (fill_randomly && !selective_random_playlist_indexes[j % segment_size]) | 2259 | if (fill_randomly && !selective_random_playlist_indexes[j % segment_size]) |
2248 | continue; | 2260 | continue; |
2249 | splash_progress(j, n, "%s (%s)", str(LANG_WAIT), str(LANG_OFF_ABORT)); | 2261 | splash_progress(j, n, "%s (%s)", str(LANG_WAIT), str(LANG_OFF_ABORT)); |
2250 | if (TIME_AFTER(current_tick, last_tick + HZ/4)) { | 2262 | if (TIME_AFTER(current_tick, last_tick + HZ/4)) |
2251 | if (action_userabort(TIMEOUT_NOBLOCK)) { | 2263 | { |
2264 | if (action_userabort(TIMEOUT_NOBLOCK)) | ||
2265 | { | ||
2252 | exit_loop_now = true; | 2266 | exit_loop_now = true; |
2253 | break; | 2267 | break; |
2254 | } | 2268 | } |
@@ -2256,13 +2270,16 @@ static bool insert_all_playlist(struct tree_context *c, | |||
2256 | } | 2270 | } |
2257 | if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, j)->extraseek, tcs.type, buf, sizeof buf)) | 2271 | if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, j)->extraseek, tcs.type, buf, sizeof buf)) |
2258 | continue; | 2272 | continue; |
2259 | if (playlist == NULL) { | 2273 | if (playlist == NULL) |
2274 | { | ||
2260 | if (playlist_insert_track(NULL, buf, position, queue, false) < 0) { | 2275 | if (playlist_insert_track(NULL, buf, position, queue, false) < 0) { |
2261 | logf("playlist_insert_track failed"); | 2276 | logf("playlist_insert_track failed"); |
2262 | exit_loop_now = true; | 2277 | exit_loop_now = true; |
2263 | break; | 2278 | break; |
2264 | } | 2279 | } |
2265 | } else if (fdprintf(fd, "%s\n", buf) <= 0) { | 2280 | } |
2281 | else if (fdprintf(fd, "%s\n", buf) <= 0) | ||
2282 | { | ||
2266 | exit_loop_now = true; | 2283 | exit_loop_now = true; |
2267 | break; | 2284 | break; |
2268 | } | 2285 | } |
@@ -2445,10 +2462,11 @@ static int tagtree_play_folder(struct tree_context* c) | |||
2445 | 2462 | ||
2446 | int n = c->filesindir; | 2463 | int n = c->filesindir; |
2447 | bool has_playlist_been_randomized = n > playlist_get_current()->max_playlist_size; | 2464 | bool has_playlist_been_randomized = n > playlist_get_current()->max_playlist_size; |
2448 | if (has_playlist_been_randomized) { | 2465 | if (has_playlist_been_randomized) |
2466 | { | ||
2449 | /* We need to recalculate the start index based on a percentage to put the user | 2467 | /* We need to recalculate the start index based on a percentage to put the user |
2450 | around its desired start position and avoid out of bounds */ | 2468 | around its desired start position and avoid out of bounds */ |
2451 | 2469 | ||
2452 | int percentage_start_index = 100 * start_index / n; | 2470 | int percentage_start_index = 100 * start_index / n; |
2453 | start_index = percentage_start_index * playlist_get_current()->amount / 100; | 2471 | start_index = percentage_start_index * playlist_get_current()->amount / 100; |
2454 | } | 2472 | } |