comparison audacious/playlist.c @ 2040:dbe615def81f trunk

[svn] Playlist shuffle behaviour should now be a little more consistant. When queue and manual jump are used, shuffle will remember where you were before jumping. It will use that location for the next/prev shuffle track, and not reshuffle each time.
author nazca
date Mon, 04 Dec 2006 00:57:49 -0800
parents d5a673ad2283
children a3ad15fb0f34
comparison
equal deleted inserted replaced
2039:6ce84abe55ba 2040:dbe615def81f
59 59
60 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b); 60 typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b);
61 typedef void (*PlaylistSaveFunc) (FILE * file); 61 typedef void (*PlaylistSaveFunc) (FILE * file);
62 62
63 PlaylistEntry *playlist_position; 63 PlaylistEntry *playlist_position;
64 /* If we manually change the song, p_p_b_j will show us where to go back to */
65 PlaylistEntry *playlist_position_before_jump = NULL;
64 G_LOCK_DEFINE(playlist); 66 G_LOCK_DEFINE(playlist);
65 67
66 static GList *playlist = NULL; 68 static GList *playlist = NULL;
67 static GList *shuffle_list = NULL; 69 static GList *shuffle_list = NULL;
68 static GList *queued_list = NULL; 70 static GList *queued_list = NULL;
889 PLAYLIST_LOCK(); 891 PLAYLIST_LOCK();
890 if (!playlist) { 892 if (!playlist) {
891 PLAYLIST_UNLOCK(); 893 PLAYLIST_UNLOCK();
892 return; 894 return;
893 } 895 }
896
897 if ((playlist_position_before_jump != NULL) && !queued_list)
898 {
899 playlist_position = playlist_position_before_jump;
900 playlist_position_before_jump = NULL;
901 }
894 902
895 plist_pos_list = find_playlist_position_list(); 903 plist_pos_list = find_playlist_position_list();
896 904
897 if (!cfg.repeat && !g_list_next(plist_pos_list) && !queued_list) { 905 if (!cfg.repeat && !g_list_next(plist_pos_list) && !queued_list) {
898 PLAYLIST_UNLOCK(); 906 PLAYLIST_UNLOCK();
942 PLAYLIST_LOCK(); 950 PLAYLIST_LOCK();
943 if (!playlist) { 951 if (!playlist) {
944 PLAYLIST_UNLOCK(); 952 PLAYLIST_UNLOCK();
945 return; 953 return;
946 } 954 }
955
956 if ((playlist_position_before_jump != NULL) && !queued_list)
957 {
958 playlist_position = playlist_position_before_jump;
959 playlist_position_before_jump = NULL;
960 }
947 961
948 plist_pos_list = find_playlist_position_list(); 962 plist_pos_list = find_playlist_position_list();
949 963
950 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { 964 if (!cfg.repeat && !g_list_previous(plist_pos_list)) {
951 PLAYLIST_UNLOCK(); 965 PLAYLIST_UNLOCK();
995 { 1009 {
996 GList *list = playlist_get_selected(); 1010 GList *list = playlist_get_selected();
997 GList *it = list; 1011 GList *it = list;
998 1012
999 PLAYLIST_LOCK(); 1013 PLAYLIST_LOCK();
1014
1015 if ((cfg.shuffle) && (playlist_position_before_jump == NULL))
1016 {
1017 /* Shuffling and this is our first manual jump. */
1018 playlist_position_before_jump = playlist_position;
1019 }
1000 1020
1001 while (it) { 1021 while (it) {
1002 GList *next = g_list_next(it); 1022 GList *next = g_list_next(it);
1003 GList *tmp; 1023 GList *tmp;
1004 1024
1026 { 1046 {
1027 GList *tmp; 1047 GList *tmp;
1028 PlaylistEntry *entry; 1048 PlaylistEntry *entry;
1029 1049
1030 PLAYLIST_LOCK(); 1050 PLAYLIST_LOCK();
1051
1052 if ((cfg.shuffle) && (playlist_position_before_jump == NULL))
1053 {
1054 /* Shuffling and this is our first manual jump. */
1055 playlist_position_before_jump = playlist_position;
1056 }
1057
1031 entry = g_list_nth_data(playlist, pos); 1058 entry = g_list_nth_data(playlist, pos);
1032 if ((tmp = g_list_find(queued_list, entry))) { 1059 if ((tmp = g_list_find(queued_list, entry))) {
1033 queued_list = g_list_remove_link(queued_list, tmp); 1060 queued_list = g_list_remove_link(queued_list, tmp);
1034 g_list_free_1(tmp); 1061 g_list_free_1(tmp);
1035 } 1062 }
1140 ip_data.stop = FALSE; 1167 ip_data.stop = FALSE;
1141 PLAYLIST_LOCK(); 1168 PLAYLIST_LOCK();
1142 restart_playing = TRUE; 1169 restart_playing = TRUE;
1143 } 1170 }
1144 1171
1172 if ((cfg.shuffle) && (playlist_position_before_jump == NULL))
1173 {
1174 /* Shuffling and this is our first manual jump. */
1175 playlist_position_before_jump = playlist_position;
1176 }
1177
1145 playlist_position = node->data; 1178 playlist_position = node->data;
1146 PLAYLIST_UNLOCK(); 1179 PLAYLIST_UNLOCK();
1147 playlist_check_pos_current(); 1180 playlist_check_pos_current();
1148 1181
1149 if (restart_playing) 1182 if (restart_playing)
1150 bmp_playback_initiate(); 1183 bmp_playback_initiate();
1151 else { 1184 else {
1152 mainwin_set_info_text(); 1185 mainwin_set_info_text();
1153 playlistwin_update_list(); 1186 playlistwin_update_list();
1154 } 1187 }
1155
1156 /*
1157 * Regenerate the shuffle list when the user set a position
1158 * manually
1159 */
1160 playlist_generate_shuffle_list();
1161 playlist_recalc_total_time();
1162 } 1188 }
1163 1189
1164 void 1190 void
1165 playlist_eof_reached(void) 1191 playlist_eof_reached(void)
1166 { 1192 {
1171 bmp_playback_stop(); 1197 bmp_playback_stop();
1172 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) 1198 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong)
1173 ip_data.stop = FALSE; 1199 ip_data.stop = FALSE;
1174 1200
1175 PLAYLIST_LOCK(); 1201 PLAYLIST_LOCK();
1202
1203 if ((playlist_position_before_jump != NULL) && !queued_list)
1204 {
1205 playlist_position = playlist_position_before_jump;
1206 playlist_position_before_jump = NULL;
1207 }
1208
1176 plist_pos_list = find_playlist_position_list(); 1209 plist_pos_list = find_playlist_position_list();
1177 1210
1178 if (cfg.no_playlist_advance) { 1211 if (cfg.no_playlist_advance) {
1179 PLAYLIST_UNLOCK(); 1212 PLAYLIST_UNLOCK();
1180 mainwin_clear_song_info(); 1213 mainwin_clear_song_info();
2695 void 2728 void
2696 playlist_set_shuffle(gboolean shuffle) 2729 playlist_set_shuffle(gboolean shuffle)
2697 { 2730 {
2698 PLAYLIST_LOCK(); 2731 PLAYLIST_LOCK();
2699 2732
2733 playlist_position_before_jump = NULL;
2734
2700 cfg.shuffle = shuffle; 2735 cfg.shuffle = shuffle;
2701 playlist_generate_shuffle_list_nolock(); 2736 playlist_generate_shuffle_list_nolock();
2702 2737
2703 PLAYLIST_UNLOCK(); 2738 PLAYLIST_UNLOCK();
2704 } 2739 }