diff options
Diffstat (limited to 'apps/playlist.c')
-rw-r--r-- | apps/playlist.c | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 1b6c65245d..13919b2f02 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -172,6 +172,10 @@ static void empty_playlist(bool resume) | |||
172 | playlist.first_index = 0; | 172 | playlist.first_index = 0; |
173 | playlist.amount = 0; | 173 | playlist.amount = 0; |
174 | playlist.last_insert_pos = -1; | 174 | playlist.last_insert_pos = -1; |
175 | playlist.seed = 0; | ||
176 | playlist.shuffle_modified = false; | ||
177 | playlist.deleted = false; | ||
178 | playlist.num_inserted_tracks = 0; | ||
175 | playlist.shuffle_flush = false; | 179 | playlist.shuffle_flush = false; |
176 | 180 | ||
177 | if (!resume) | 181 | if (!resume) |
@@ -412,6 +416,7 @@ static int add_track_to_playlist(char *filename, int position, bool queue, | |||
412 | playlist.indices[insert_position] = flags | seek_pos; | 416 | playlist.indices[insert_position] = flags | seek_pos; |
413 | 417 | ||
414 | playlist.amount++; | 418 | playlist.amount++; |
419 | playlist.num_inserted_tracks++; | ||
415 | 420 | ||
416 | return insert_position; | 421 | return insert_position; |
417 | } | 422 | } |
@@ -528,16 +533,24 @@ static int add_directory_to_playlist(char *dirname, int *position, bool queue, | |||
528 | static int remove_track_from_playlist(int position, bool write) | 533 | static int remove_track_from_playlist(int position, bool write) |
529 | { | 534 | { |
530 | int i; | 535 | int i; |
536 | bool inserted; | ||
531 | 537 | ||
532 | if (playlist.amount <= 0) | 538 | if (playlist.amount <= 0) |
533 | return -1; | 539 | return -1; |
534 | 540 | ||
541 | inserted = playlist.indices[position] & PLAYLIST_INSERT_TYPE_MASK; | ||
542 | |||
535 | /* shift indices now that track has been removed */ | 543 | /* shift indices now that track has been removed */ |
536 | for (i=position; i<playlist.amount; i++) | 544 | for (i=position; i<playlist.amount; i++) |
537 | playlist.indices[i] = playlist.indices[i+1]; | 545 | playlist.indices[i] = playlist.indices[i+1]; |
538 | 546 | ||
539 | playlist.amount--; | 547 | playlist.amount--; |
540 | 548 | ||
549 | if (inserted) | ||
550 | playlist.num_inserted_tracks--; | ||
551 | else | ||
552 | playlist.deleted = true; | ||
553 | |||
541 | /* update stored indices if needed */ | 554 | /* update stored indices if needed */ |
542 | if (position < playlist.index) | 555 | if (position < playlist.index) |
543 | playlist.index--; | 556 | playlist.index--; |
@@ -622,6 +635,10 @@ static int randomise_playlist(unsigned int seed, bool start_current, bool write) | |||
622 | /* indices have been moved so last insert position is no longer valid */ | 635 | /* indices have been moved so last insert position is no longer valid */ |
623 | playlist.last_insert_pos = -1; | 636 | playlist.last_insert_pos = -1; |
624 | 637 | ||
638 | playlist.seed = seed; | ||
639 | if (playlist.num_inserted_tracks > 0 || playlist.deleted) | ||
640 | playlist.shuffle_modified = true; | ||
641 | |||
625 | if (write) | 642 | if (write) |
626 | { | 643 | { |
627 | /* Don't write to disk immediately. Instead, save in settings and | 644 | /* Don't write to disk immediately. Instead, save in settings and |
@@ -652,6 +669,8 @@ static int sort_playlist(bool start_current, bool write) | |||
652 | /* indices have been moved so last insert position is no longer valid */ | 669 | /* indices have been moved so last insert position is no longer valid */ |
653 | playlist.last_insert_pos = -1; | 670 | playlist.last_insert_pos = -1; |
654 | 671 | ||
672 | if (!playlist.num_inserted_tracks && !playlist.deleted) | ||
673 | playlist.shuffle_modified = false; | ||
655 | if (write && playlist.control_fd >= 0) | 674 | if (write && playlist.control_fd >= 0) |
656 | { | 675 | { |
657 | /* Don't write to disk immediately. Instead, save in settings and | 676 | /* Don't write to disk immediately. Instead, save in settings and |
@@ -1898,9 +1917,26 @@ int playlist_next(int steps) | |||
1898 | return index; | 1917 | return index; |
1899 | } | 1918 | } |
1900 | 1919 | ||
1920 | bool playlist_modified(void) | ||
1921 | { | ||
1922 | if ((mpeg_status() & MPEG_STATUS_PLAY)) | ||
1923 | { | ||
1924 | if (playlist.shuffle_modified || | ||
1925 | playlist.deleted || | ||
1926 | playlist.num_inserted_tracks > 0) | ||
1927 | return true; | ||
1928 | } | ||
1929 | return false; | ||
1930 | } | ||
1931 | |||
1932 | int playlist_get_seed(void) | ||
1933 | { | ||
1934 | return playlist.seed; | ||
1935 | } | ||
1936 | |||
1901 | /* Get resume info for current playing song. If return value is -1 then | 1937 | /* Get resume info for current playing song. If return value is -1 then |
1902 | settings shouldn't be saved. */ | 1938 | settings shouldn't be saved. */ |
1903 | int playlist_get_resume_info(short *resume_index) | 1939 | int playlist_get_resume_info(int *resume_index) |
1904 | { | 1940 | { |
1905 | *resume_index = playlist.index; | 1941 | *resume_index = playlist.index; |
1906 | 1942 | ||
@@ -1924,6 +1960,16 @@ int playlist_get_first_index(void) | |||
1924 | return playlist.first_index; | 1960 | return playlist.first_index; |
1925 | } | 1961 | } |
1926 | 1962 | ||
1963 | char *playlist_get_name(char *buf, int buf_size) | ||
1964 | { | ||
1965 | snprintf(buf, buf_size, "%s", playlist.filename); | ||
1966 | |||
1967 | if (!buf[0]) | ||
1968 | return NULL; | ||
1969 | |||
1970 | return buf; | ||
1971 | } | ||
1972 | |||
1927 | /* returns number of tracks in playlist (includes queued/inserted tracks) */ | 1973 | /* returns number of tracks in playlist (includes queued/inserted tracks) */ |
1928 | int playlist_amount(void) | 1974 | int playlist_amount(void) |
1929 | { | 1975 | { |
@@ -1937,14 +1983,14 @@ char *playlist_name(char *buf, int buf_size) | |||
1937 | 1983 | ||
1938 | snprintf(buf, buf_size, "%s", playlist.filename+playlist.dirlen); | 1984 | snprintf(buf, buf_size, "%s", playlist.filename+playlist.dirlen); |
1939 | 1985 | ||
1940 | if (0 == buf[0]) | 1986 | if (!buf[0]) |
1941 | return NULL; | 1987 | return NULL; |
1942 | 1988 | ||
1943 | /* Remove extension */ | 1989 | /* Remove extension */ |
1944 | sep = strrchr(buf, '.'); | 1990 | sep = strrchr(buf, '.'); |
1945 | if (NULL != sep) | 1991 | if (sep) |
1946 | *sep = 0; | 1992 | *sep = 0; |
1947 | 1993 | ||
1948 | return buf; | 1994 | return buf; |
1949 | } | 1995 | } |
1950 | 1996 | ||
@@ -2001,7 +2047,7 @@ int playlist_save(char *filename) | |||
2001 | 2047 | ||
2002 | /* use current working directory as base for pathname */ | 2048 | /* use current working directory as base for pathname */ |
2003 | if (format_track_path(tmp_buf, filename, sizeof(tmp_buf), | 2049 | if (format_track_path(tmp_buf, filename, sizeof(tmp_buf), |
2004 | strlen(filename)+1, getcwd(NULL, -1)) < 0) | 2050 | strlen(filename)+1, getcwd(NULL, -1)) < 0) |
2005 | return -1; | 2051 | return -1; |
2006 | 2052 | ||
2007 | fd = open(tmp_buf, O_CREAT|O_WRONLY|O_TRUNC); | 2053 | fd = open(tmp_buf, O_CREAT|O_WRONLY|O_TRUNC); |
@@ -2043,15 +2089,14 @@ int playlist_save(char *filename) | |||
2043 | 2089 | ||
2044 | if (fprintf(fd, "%s\n", tmp_buf) < 0) | 2090 | if (fprintf(fd, "%s\n", tmp_buf) < 0) |
2045 | { | 2091 | { |
2046 | splash(HZ*2, true, | 2092 | splash(HZ*2, true, str(LANG_PLAYLIST_CONTROL_UPDATE_ERROR)); |
2047 | str(LANG_PLAYLIST_CONTROL_UPDATE_ERROR)); | ||
2048 | result = -1; | 2093 | result = -1; |
2049 | break; | 2094 | break; |
2050 | } | 2095 | } |
2051 | 2096 | ||
2052 | count++; | 2097 | count++; |
2053 | 2098 | ||
2054 | if ((count%PLAYLIST_DISPLAY_COUNT) == 0) | 2099 | if ((count % PLAYLIST_DISPLAY_COUNT) == 0) |
2055 | display_playlist_count(count, str(LANG_PLAYLIST_SAVE_COUNT)); | 2100 | display_playlist_count(count, str(LANG_PLAYLIST_SAVE_COUNT)); |
2056 | 2101 | ||
2057 | yield(); | 2102 | yield(); |