summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/playlist.c64
-rw-r--r--apps/playlist.h6
-rw-r--r--apps/playlist_viewer.c1
-rw-r--r--apps/plugin.c1
-rw-r--r--apps/plugin.h1
-rw-r--r--apps/plugins/pictureflow/pictureflow.c2
-rw-r--r--apps/tagtree.c2
7 files changed, 30 insertions, 47 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index f2b0bb197f..c755aca9fd 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -576,20 +576,18 @@ static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume)
576 playlist->utf8 = true; 576 playlist->utf8 = true;
577 playlist->control_created = false; 577 playlist->control_created = false;
578 playlist->in_ram = false; 578 playlist->in_ram = false;
579 playlist->modified = false;
579 580
580 playlist->fd = -1; 581 playlist->fd = -1;
581 playlist->control_fd = -1; 582 playlist->control_fd = -1;
582 playlist->num_inserted_tracks = 0;
583 583
584 playlist->index = 0; 584 playlist->index = 0;
585 playlist->first_index = 0; 585 playlist->first_index = 0;
586 playlist->amount = 0; 586 playlist->amount = 0;
587 playlist->last_insert_pos = -1; 587 playlist->last_insert_pos = -1;
588 588
589 playlist->deleted = false;
590 playlist->started = false; 589 playlist->started = false;
591 playlist->pending_control_sync = false; 590 playlist->pending_control_sync = false;
592 playlist->shuffle_modified = false;
593 591
594 if (!resume && playlist == &current_playlist) 592 if (!resume && playlist == &current_playlist)
595 { 593 {
@@ -810,9 +808,7 @@ static int recreate_control_unlocked(struct playlist_info* playlist)
810 } 808 }
811 809
812 playlist->seed = 0; 810 playlist->seed = 0;
813 playlist->shuffle_modified = false; 811 playlist->modified = true;
814 playlist->deleted = false;
815 playlist->num_inserted_tracks = 0;
816 812
817 for (i=0; i<playlist->amount; i++) 813 for (i=0; i<playlist->amount; i++)
818 { 814 {
@@ -841,8 +837,6 @@ static int recreate_control_unlocked(struct playlist_info* playlist)
841 837
842 if (result < 0) 838 if (result < 0)
843 break; 839 break;
844
845 playlist->num_inserted_tracks++;
846 } 840 }
847 } 841 }
848 842
@@ -1373,18 +1367,11 @@ static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write
1373#endif 1367#endif
1374 1368
1375 /* Update playlist state as if by remove_track_unlocked() */ 1369 /* Update playlist state as if by remove_track_unlocked() */
1376 bool inserted = playlist->indices[0] & PLAYLIST_INSERT_TYPE_MASK;
1377
1378 playlist->index = 0; 1370 playlist->index = 0;
1371 playlist->first_index = 0;
1379 playlist->amount = 1; 1372 playlist->amount = 1;
1380 playlist->indices[0] |= PLAYLIST_QUEUED; 1373 playlist->indices[0] |= PLAYLIST_QUEUED;
1381 1374 playlist->modified = true;
1382 if (inserted)
1383 playlist->num_inserted_tracks = 1;
1384 else
1385 playlist->deleted = true;
1386
1387 playlist->first_index = 0;
1388 1375
1389 if (playlist->last_insert_pos == 0) 1376 if (playlist->last_insert_pos == 0)
1390 playlist->last_insert_pos = -1; 1377 playlist->last_insert_pos = -1;
@@ -1558,7 +1545,7 @@ static int add_track_to_playlist_unlocked(struct playlist_info* playlist,
1558 dc_init_filerefs(playlist, insert_position, 1); 1545 dc_init_filerefs(playlist, insert_position, 1);
1559 1546
1560 playlist->amount++; 1547 playlist->amount++;
1561 playlist->num_inserted_tracks++; 1548 playlist->modified = true;
1562 1549
1563 return insert_position; 1550 return insert_position;
1564} 1551}
@@ -1614,13 +1601,10 @@ static int remove_track_unlocked(struct playlist_info* playlist,
1614{ 1601{
1615 int i; 1602 int i;
1616 int result = 0; 1603 int result = 0;
1617 bool inserted;
1618 1604
1619 if (playlist->amount <= 0) 1605 if (playlist->amount <= 0)
1620 return -1; 1606 return -1;
1621 1607
1622 inserted = playlist->indices[position] & PLAYLIST_INSERT_TYPE_MASK;
1623
1624#ifdef HAVE_DIRCACHE 1608#ifdef HAVE_DIRCACHE
1625 struct dircache_fileref *dcfrefs = NULL; 1609 struct dircache_fileref *dcfrefs = NULL;
1626 if (playlist->dcfrefs_handle) 1610 if (playlist->dcfrefs_handle)
@@ -1638,11 +1622,7 @@ static int remove_track_unlocked(struct playlist_info* playlist,
1638 } 1622 }
1639 1623
1640 playlist->amount--; 1624 playlist->amount--;
1641 1625 playlist->modified = true;
1642 if (inserted)
1643 playlist->num_inserted_tracks--;
1644 else
1645 playlist->deleted = true;
1646 1626
1647 /* update stored indices if needed */ 1627 /* update stored indices if needed */
1648 if (position < playlist->index) 1628 if (position < playlist->index)
@@ -1735,8 +1715,7 @@ static int randomise_playlist_unlocked(struct playlist_info* playlist,
1735 playlist->last_insert_pos = -1; 1715 playlist->last_insert_pos = -1;
1736 1716
1737 playlist->seed = seed; 1717 playlist->seed = seed;
1738 if (playlist->num_inserted_tracks > 0 || playlist->deleted) 1718 playlist->modified = true;
1739 playlist->shuffle_modified = true;
1740 1719
1741 if (write) 1720 if (write)
1742 { 1721 {
@@ -1800,9 +1779,8 @@ static int sort_playlist_unlocked(struct playlist_info* playlist,
1800 1779
1801 /* indices have been moved so last insert position is no longer valid */ 1780 /* indices have been moved so last insert position is no longer valid */
1802 playlist->last_insert_pos = -1; 1781 playlist->last_insert_pos = -1;
1782 playlist->modified = true;
1803 1783
1804 if (!playlist->num_inserted_tracks && !playlist->deleted)
1805 playlist->shuffle_modified = false;
1806 if (write && playlist->control_fd >= 0) 1784 if (write && playlist->control_fd >= 0)
1807 { 1785 {
1808 playlist->first_index = 0; 1786 playlist->first_index = 0;
@@ -2905,20 +2883,25 @@ int playlist_insert_track(struct playlist_info* playlist, const char *filename,
2905 return result; 2883 return result;
2906} 2884}
2907 2885
2908/* returns true if playlist has been modified */ 2886/* returns true if playlist has been modified by the user */
2909bool playlist_modified(const struct playlist_info* playlist) 2887bool playlist_modified(const struct playlist_info* playlist)
2910{ 2888{
2911 if (!playlist) 2889 if (!playlist)
2912 playlist = &current_playlist; 2890 playlist = &current_playlist;
2913 2891
2914 if (playlist->shuffle_modified || 2892 return playlist->modified;
2915 playlist->deleted || 2893}
2916 playlist->num_inserted_tracks > 0) 2894
2917 { 2895/*
2918 return true; 2896 * Set the playlist modified status. Useful for clearing the modified status
2919 } 2897 * after dynamically building a playlist.
2898 */
2899void playlist_set_modified(struct playlist_info *playlist, bool modified)
2900{
2901 if (!playlist)
2902 playlist = &current_playlist;
2920 2903
2921 return false; 2904 playlist->modified = modified;
2922} 2905}
2923 2906
2924/* 2907/*
@@ -3938,6 +3921,7 @@ int playlist_save(struct playlist_info* playlist, char *filename,
3938 if (fd >= 0) 3921 if (fd >= 0)
3939 close(fd); 3922 close(fd);
3940 3923
3924 playlist->modified = false;
3941 cpu_boost(false); 3925 cpu_boost(false);
3942 3926
3943 return result; 3927 return result;
@@ -3996,9 +3980,7 @@ int playlist_set_current(struct playlist_info* playlist)
3996 current_playlist.amount = playlist->amount; 3980 current_playlist.amount = playlist->amount;
3997 current_playlist.last_insert_pos = playlist->last_insert_pos; 3981 current_playlist.last_insert_pos = playlist->last_insert_pos;
3998 current_playlist.seed = playlist->seed; 3982 current_playlist.seed = playlist->seed;
3999 current_playlist.shuffle_modified = playlist->shuffle_modified; 3983 current_playlist.modified = playlist->modified;
4000 current_playlist.deleted = playlist->deleted;
4001 current_playlist.num_inserted_tracks = playlist->num_inserted_tracks;
4002 3984
4003 memcpy(current_playlist.control_cache, playlist->control_cache, 3985 memcpy(current_playlist.control_cache, playlist->control_cache,
4004 sizeof(current_playlist.control_cache)); 3986 sizeof(current_playlist.control_cache));
diff --git a/apps/playlist.h b/apps/playlist.h
index d56a6fd659..cb79eea96c 100644
--- a/apps/playlist.h
+++ b/apps/playlist.h
@@ -75,11 +75,11 @@ struct playlist_info
75 bool utf8; /* playlist is in .m3u8 format */ 75 bool utf8; /* playlist is in .m3u8 format */
76 bool control_created; /* has control file been created? */ 76 bool control_created; /* has control file been created? */
77 bool in_ram; /* playlist stored in ram (dirplay) */ 77 bool in_ram; /* playlist stored in ram (dirplay) */
78 bool modified; /* has playlist been modified by the user? */
78 int fd; /* descriptor of the open playlist file */ 79 int fd; /* descriptor of the open playlist file */
79 int control_fd; /* descriptor of the open control file */ 80 int control_fd; /* descriptor of the open control file */
80 int max_playlist_size; /* Max number of files in playlist. Mirror of 81 int max_playlist_size; /* Max number of files in playlist. Mirror of
81 global_settings.max_files_in_playlist */ 82 global_settings.max_files_in_playlist */
82 int num_inserted_tracks; /* number of tracks inserted */
83 unsigned long *indices; /* array of indices */ 83 unsigned long *indices; /* array of indices */
84 84
85 struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for 85 struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for
@@ -89,11 +89,8 @@ struct playlist_info
89 int first_index; /* index of first song in playlist */ 89 int first_index; /* index of first song in playlist */
90 int amount; /* number of tracks in the index */ 90 int amount; /* number of tracks in the index */
91 int last_insert_pos; /* last position we inserted a track */ 91 int last_insert_pos; /* last position we inserted a track */
92 bool deleted; /* have any tracks been deleted? */
93 bool started; /* has playlist been started? */ 92 bool started; /* has playlist been started? */
94 bool pending_control_sync; /* control file needs to be synced */ 93 bool pending_control_sync; /* control file needs to be synced */
95 bool shuffle_modified; /* has playlist been shuffled with
96 inserted tracks? */
97 int last_shuffled_start; /* number of tracks when insert last 94 int last_shuffled_start; /* number of tracks when insert last
98 shuffled command start */ 95 shuffled command start */
99 int seed; /* shuffle seed */ 96 int seed; /* shuffle seed */
@@ -166,6 +163,7 @@ int playlist_randomise(struct playlist_info* playlist, unsigned int seed,
166 bool start_current); 163 bool start_current);
167int playlist_sort(struct playlist_info* playlist, bool start_current); 164int playlist_sort(struct playlist_info* playlist, bool start_current);
168bool playlist_modified(const struct playlist_info* playlist); 165bool playlist_modified(const struct playlist_info* playlist);
166void playlist_set_modified(struct playlist_info* playlist, bool modified);
169int playlist_get_first_index(const struct playlist_info* playlist); 167int playlist_get_first_index(const struct playlist_info* playlist);
170int playlist_get_seed(const struct playlist_info* playlist); 168int playlist_get_seed(const struct playlist_info* playlist);
171int playlist_amount_ex(const struct playlist_info* playlist); 169int playlist_amount_ex(const struct playlist_info* playlist);
diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c
index 4328a6de1d..8761f0dbc9 100644
--- a/apps/playlist_viewer.c
+++ b/apps/playlist_viewer.c
@@ -975,6 +975,7 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename,
975 if (global_settings.playlist_shuffle) 975 if (global_settings.playlist_shuffle)
976 start_index = playlist_shuffle(current_tick, start_index); 976 start_index = playlist_shuffle(current_tick, start_index);
977 playlist_start(start_index, 0, 0); 977 playlist_start(start_index, 0, 0);
978 playlist_set_modified(NULL, false);
978 979
979 if (viewer.initial_selection) 980 if (viewer.initial_selection)
980 *(viewer.initial_selection) = viewer.selected_track; 981 *(viewer.initial_selection) = viewer.selected_track;
diff --git a/apps/plugin.c b/apps/plugin.c
index 1a0aedf3cc..3db4bb2d80 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -829,6 +829,7 @@ static const struct plugin_api rockbox_api = {
829 tagtree_subentries_do_action, 829 tagtree_subentries_do_action,
830#endif 830#endif
831 adjust_volume, 831 adjust_volume,
832 playlist_set_modified,
832}; 833};
833 834
834static int plugin_buffer_handle; 835static int plugin_buffer_handle;
diff --git a/apps/plugin.h b/apps/plugin.h
index cf6a1bc4e4..c54ef180ec 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -954,6 +954,7 @@ struct plugin_api {
954 bool (*tagtree_subentries_do_action)(bool (*action_cb)(const char *file_name)); 954 bool (*tagtree_subentries_do_action)(bool (*action_cb)(const char *file_name));
955#endif 955#endif
956 void (*adjust_volume)(int steps); 956 void (*adjust_volume)(int steps);
957 void (*playlist_set_modified)(struct playlist_info *playlist, bool modified);
957}; 958};
958 959
959/* plugin header */ 960/* plugin header */
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index 45c4e0fcda..67c26a7dc8 100644
--- a/apps/plugins/pictureflow/pictureflow.c
+++ b/apps/plugins/pictureflow/pictureflow.c
@@ -4246,7 +4246,7 @@ static bool start_playback(bool return_to_WPS)
4246 start_index = rb->playlist_shuffle(*rb->current_tick, pf_tracks.sel); 4246 start_index = rb->playlist_shuffle(*rb->current_tick, pf_tracks.sel);
4247 } 4247 }
4248 rb->playlist_start(start_index, 0, 0); 4248 rb->playlist_start(start_index, 0, 0);
4249 rb->playlist_get_current()->num_inserted_tracks = 0; /* prevent warn_on_pl_erase */ 4249 rb->playlist_set_modified(NULL, false);
4250 old_shuffle = shuffle; 4250 old_shuffle = shuffle;
4251#ifdef USEGSLIB 4251#ifdef USEGSLIB
4252 if (!return_to_WPS) 4252 if (!return_to_WPS)
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 72eec1494c..e715d4518b 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -2359,7 +2359,7 @@ static int tagtree_play_folder(struct tree_context* c)
2359 } 2359 }
2360 2360
2361 playlist_start(start_index, 0, 0); 2361 playlist_start(start_index, 0, 0);
2362 playlist_get_current()->num_inserted_tracks = 0; /* make warn on playlist erase work */ 2362 playlist_set_modified(NULL, false);
2363 return 0; 2363 return 0;
2364} 2364}
2365 2365