···1645916459 *: "禁用主菜单滚动"
1646016460 </voice>
1646116461</phrase>
1646216462+<phrase>
1646316463+ id: LANG_RANDOM_SHUFFLE_RANDOM_SELECTIVE_SONGS_SUMMARY
1646416464+ desc: a summary splash screen that appear on the database browser when you try to create a playlist from the database browser that exceeds your system limit
1646516465+ user: core
1646616466+ <source>
1646716467+ *: "Selection too big, %d random tracks will be picked from it"
1646816468+ </source>
1646916469+ <dest>
1647016470+ *: "选择了太多,将从中随机选取%d首"
1647116471+ </dest>
1647216472+ <voice>
1647316473+ *: "选择了太多,将从中选择更少曲目"
1647416474+ </voice>
1647516475+</phrase>
+3-3
apps/lang/english.lang
···20582058 desc: a summary splash screen that appear on the database browser when you try to create a playlist from the database browser that exceeds your system limit
20592059 user: core
20602060 <source>
20612061- *: "Selection too big, %d random tracks will be picked from it"
20612061+ *: "Selection too big, %d random tracks will be selected"
20622062 </source>
20632063 <dest>
20642064- *: "Selection too big, %d random tracks will be picked from it"
20642064+ *: "Selection too big, %d random tracks will be selected"
20652065 </dest>
20662066 <voice>
20672067- *: "Selection too big, fewer random tracks will be picked from it"
20672067+ *: "Selection too big, fewer random tracks will be selected"
20682068 </voice>
20692069</phrase>
20702070<phrase>
+2-1
apps/onplay.c
···12941294#else
12951295 (void)hotkey;
12961296#endif
12971297- if (customaction == ONPLAY_CUSTOMACTION_SHUFFLE_SONGS) {
12971297+ if (customaction == ONPLAY_CUSTOMACTION_SHUFFLE_SONGS)
12981298+ {
12981299 int returnCode = add_to_playlist(&addtopl_replace_shuffled);
12991300 if (returnCode == 1)
13001301 // User did not want to erase his current playlist, so let's show again the database main menu
+96-45
apps/tagtree.c
···21312131 return tagtree_get_entry(c, c->selected_item)->customaction;
21322132}
2133213321342134-static void swap_array_bool(bool *a, bool *b) {
21342134+static void swap_array_bool(bool *a, bool *b)
21352135+{
21352136 bool temp = *a;
21362137 *a = *b;
21372138 *b = temp;
21382139}
21392139-21402140+21402141/**
21412141- * Randomly shuffle an array using the Fisher-Yates algorithm : https://en.wikipedia.org/wiki/Random_permutation
21422142- * This algorithm has a linear complexity. Don't forget to srand before call to use it with a relevant seed.
21422142+ * Randomly shuffle an array using the Fisher-Yates algorithm :
21432143+ * https://en.wikipedia.org/wiki/Random_permutation
21442144+ * This algorithm has a linear complexity. Don't forget to srand
21452145+ * before call to use it with a relevant seed.
21432146 */
21442144-static void shuffle_bool_array(bool array[], int size) {
21452145- for (int i = size - 1; i > 0; i--) {
21472147+static void shuffle_bool_array(bool array[], int size)
21482148+{
21492149+ for (int i = size - 1; i > 0; i--)
21502150+ {
21462151 int j = rand() % (i + 1);
21472152 swap_array_bool(&array[i], &array[j]);
21482153 }
21492154}
2150215521512151-static bool fill_selective_random_playlist_indexes(int current_segment_n, int current_segment_max_available_space) {
21522152- if (current_segment_n == 0 || current_segment_max_available_space == 0)
21562156+static bool fill_random_playlist_indexes(int current_segment_n,
21572157+ int current_segment_max_space)
21582158+{
21592159+ if (current_segment_n == 0 || current_segment_max_space == 0)
21532160 return false;
21542154- if (current_segment_max_available_space > current_segment_n)
21552155- current_segment_max_available_space = current_segment_n;
21612161+ if (current_segment_max_space > current_segment_n)
21622162+ current_segment_max_space = current_segment_n;
21562163 for (int i = 0; i < current_segment_n; i++)
21572157- selective_random_playlist_indexes[i] = i < current_segment_max_available_space;
21642164+ selective_random_playlist_indexes[i] = i < current_segment_max_space;
21582165 srand(current_tick);
21592166 shuffle_bool_array(selective_random_playlist_indexes, current_segment_n);
21602167 return true;
···22012208 return false;
22022209 }
22032210 }
22112211+22042212 last_tick = current_tick + HZ/2; /* Show splash after 0.5 seconds have passed */
22052213 splash_progress_set_delay(HZ / 2); /* wait 1/2 sec before progress */
22062214 n = c->filesindir;
22152215+22162216+ int max_playlist_size = playlist_get_current()->max_playlist_size;
22172217+ int playlist_amount = playlist_get_current()->amount;
22072218 int segment_size = INSERT_ALL_PLAYLIST_MAX_SEGMENT_SIZE;
22082219 int segments_count = n / segment_size;
22092209- int leftovers_segment_size = n % segment_size;
22202220+ int leftovers_segment_size = n - (segments_count * segment_size);
22102221 bool fill_randomly = false;
22112211- if (playlist == NULL) {
22122212- bool will_exceed = n > playlist_get_current()->max_playlist_size;
22222222+22232223+ if (playlist == NULL)
22242224+ {
22252225+ bool will_exceed = n > max_playlist_size;
22132226 fill_randomly = will_exceed;
22142227 }
22152215- if (leftovers_segment_size > 0 && fill_randomly) {
22162216- // We need to re-balance the segments so the randomness will be coherent and balanced the same through all segments
22172217- while (leftovers_segment_size + segments_count < segment_size) {
22282228+ if (leftovers_segment_size > 0 && fill_randomly)
22292229+ {
22302230+ /* We need to re-balance the segments so the randomness will be
22312231+ * coherent and balanced the same through all segments */
22322232+ while (leftovers_segment_size + segments_count < segment_size)
22332233+ {
22182234 segment_size--; // -1 to all other segments
22192235 leftovers_segment_size += segments_count;
22202236 }
22212237 }
22222238 if (leftovers_segment_size > 0)
22232239 segments_count += 1;
22242224- int max_available_space = playlist_get_current()->max_playlist_size - playlist_get_current()->amount;
22252225- int max_available_space_per_segment = max_available_space / segments_count;
22262226- if (fill_randomly) {
22402240+22412241+ int max_available_space = max_playlist_size - playlist_amount;
22422242+ int max_space_per_segment = max_available_space / segments_count;
22432243+22442244+ int remaining_space =
22452245+ max_available_space - (max_space_per_segment * segments_count);
22462246+22472247+ if (fill_randomly)
22482248+ {
22272249 talk_id(LANG_RANDOM_SHUFFLE_RANDOM_SELECTIVE_SONGS_SUMMARY, true);
22282228- splashf(HZ * 3, str(LANG_RANDOM_SHUFFLE_RANDOM_SELECTIVE_SONGS_SUMMARY), max_available_space_per_segment * segments_count);
22292229- //splashf(HZ * 5, "sz=%d lsz=%d sc=%d rcps=%d", segment_size, leftovers_segment_size, segments_count, max_available_space_per_segment);
22502250+ splashf(HZ * 3, str(LANG_RANDOM_SHUFFLE_RANDOM_SELECTIVE_SONGS_SUMMARY),
22512251+ max_space_per_segment * segments_count + remaining_space);
22522252+ /* logf("sz=%d lsz=%d sc=%d rcps=%d", segment_size, leftovers_segment_size,
22532253+ segments_count, max_available_space_per_segment); */
22302254 }
22312231- for (int i = 0; i < segments_count; i++) {
22322232- bool is_leftovers_segment = leftovers_segment_size > 0 && i + 1 >= segments_count;
22332233- if (fill_randomly) {
22342234- if (is_leftovers_segment)
22352235- fill_randomly = fill_selective_random_playlist_indexes(leftovers_segment_size, max_available_space_per_segment);
22362236- else
22372237- fill_randomly = fill_selective_random_playlist_indexes(segment_size, max_available_space_per_segment);
22382238- }
22392239- bool exit_loop_now = false;
22552255+22562256+ bool exit_loop_now = false;
22572257+ for (int i = 0; i < segments_count; i++)
22582258+ {
22592259+ int cur_segment_size = segment_size;
22402260 int cur_segment_start = i * segment_size;
22412261 int cur_segment_end;
22422242- if (is_leftovers_segment)
22432243- cur_segment_end = cur_segment_start + leftovers_segment_size;
22442244- else
22452245- cur_segment_end = cur_segment_start + segment_size;
22462246- for (int j = cur_segment_start; j < cur_segment_end && !exit_loop_now; j++) {
22472247- if (fill_randomly && !selective_random_playlist_indexes[j % segment_size])
22482248- continue;
22492249- splash_progress(j, n, "%s (%s)", str(LANG_WAIT), str(LANG_OFF_ABORT));
22502250- if (TIME_AFTER(current_tick, last_tick + HZ/4)) {
22512251- if (action_userabort(TIMEOUT_NOBLOCK)) {
22622262+ int space_per_segment = max_space_per_segment;
22632263+22642264+ if (i + 1 >= segments_count && leftovers_segment_size > 0)
22652265+ {
22662266+ /* add any remaining tracks to the last segment */
22672267+ space_per_segment += remaining_space;
22682268+ cur_segment_size = leftovers_segment_size;
22692269+ }
22702270+ else if (fill_randomly)
22712271+ {
22722272+ /* add an extra track to some of the segments */
22732273+ if (remaining_space > 0 && (i & 7) != 7)
22742274+ {
22752275+ space_per_segment++;
22762276+ remaining_space--;
22772277+ }
22782278+ }
22792279+ if (fill_randomly)
22802280+ {
22812281+ fill_randomly = fill_random_playlist_indexes(cur_segment_size,
22822282+ space_per_segment);
22832283+ }
22842284+22852285+ cur_segment_end = cur_segment_start + cur_segment_size;
22862286+22872287+ for (int j = cur_segment_start; j < cur_segment_end && !exit_loop_now; j++)
22882288+ {
22892289+ if (TIME_AFTER(current_tick, last_tick + HZ/4))
22902290+ {
22912291+ splash_progress(j, n, "%s (%s)", str(LANG_WAIT), str(LANG_OFF_ABORT));
22922292+ if (action_userabort(TIMEOUT_NOBLOCK))
22932293+ {
22522294 exit_loop_now = true;
22532295 break;
22542296 }
22552297 last_tick = current_tick;
22562298 }
22992299+23002300+ if (fill_randomly && !selective_random_playlist_indexes[j % segment_size])
23012301+ continue;
23022302+22572303 if (!tagcache_retrieve(&tcs, tagtree_get_entry(c, j)->extraseek, tcs.type, buf, sizeof buf))
22582304 continue;
22592259- if (playlist == NULL) {
23052305+23062306+ if (playlist == NULL)
23072307+ {
22602308 if (playlist_insert_track(NULL, buf, position, queue, false) < 0) {
22612309 logf("playlist_insert_track failed");
22622310 exit_loop_now = true;
22632311 break;
22642312 }
22652265- } else if (fdprintf(fd, "%s\n", buf) <= 0) {
23132313+ }
23142314+ else if (fdprintf(fd, "%s\n", buf) <= 0)
23152315+ {
22662316 exit_loop_now = true;
22672317 break;
22682318 }
···2445249524462496 int n = c->filesindir;
24472497 bool has_playlist_been_randomized = n > playlist_get_current()->max_playlist_size;
24482448- if (has_playlist_been_randomized) {
24982498+ if (has_playlist_been_randomized)
24992499+ {
24492500 /* We need to recalculate the start index based on a percentage to put the user
24502501 around its desired start position and avoid out of bounds */
24512451-25022502+24522503 int percentage_start_index = 100 * start_index / n;
24532504 start_index = percentage_start_index * playlist_get_current()->amount / 100;
24542505 }
+6-3
apps/tree.c
···738738 int customaction = ONPLAY_NO_CUSTOMACTION;
739739 bool do_restore_display = true;
740740 #ifdef HAVE_TAGCACHE
741741- if (id3db && (button == ACTION_STD_OK || button == ACTION_STD_CONTEXT)) {
741741+ if (id3db && (button == ACTION_STD_OK || button == ACTION_STD_CONTEXT))
742742+ {
742743 customaction = tagtree_get_custom_action(&tc);
743743- if (customaction == ONPLAY_CUSTOMACTION_SHUFFLE_SONGS) {
744744- button = ACTION_STD_CONTEXT; /** The code to insert shuffled is on the context branch of the switch so we always go here */
744744+ if (customaction == ONPLAY_CUSTOMACTION_SHUFFLE_SONGS)
745745+ {
746746+ /* The code to insert shuffled is on the context branch of the switch so we always go here */
747747+ button = ACTION_STD_CONTEXT;
745748 do_restore_display = false;
746749 }
747750 }