summaryrefslogtreecommitdiff
path: root/apps/playlist.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2023-01-22 13:35:27 +0000
committerAidan MacDonald <amachronic@protonmail.com>2023-03-23 13:01:23 -0400
commita64cad847e7d24dc4d01d5ab22f6c8dc42f960ae (patch)
tree90bd4418ff3bdfbd03a225aa40e1695032682e09 /apps/playlist.c
parentd40a598970b04bfe3a867a5e12debc45c149b46b (diff)
downloadrockbox-a64cad847e7d24dc4d01d5ab22f6c8dc42f960ae.tar.gz
rockbox-a64cad847e7d24dc4d01d5ab22f6c8dc42f960ae.zip
playlist: Simplify playlist modified detection
Any modifications to the playlist (insert, delete, shuffle, etc) will cause the modified flag to be set. The flag is cleared when the playlist is saved. Code that generates playlists can manually clear the modified flag if appropriate; there is now a proper API for this so the tagcache and pictureflow don't need to resort to hacks. Change-Id: I8d3c723265a41db07a13de3f1d2abb0444528d57
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c64
1 files changed, 23 insertions, 41 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));