Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libaudcore/drct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ EXPORT void aud_drct_pl_prev()
if (playlist == Playlist())
playlist = Playlist::active_playlist();

playlist.prev_song();
playlist.prev_song(aud_get_bool("repeat"));
}

EXPORT void aud_drct_pl_prev_album()
Expand All @@ -226,7 +226,7 @@ EXPORT void aud_drct_pl_prev_album()
if (playlist == Playlist())
playlist = Playlist::active_playlist();

playlist.prev_album();
playlist.prev_album(aud_get_bool("repeat"));
}

static void add_list(Index<PlaylistAddItem> && items, int at, bool to_temp,
Expand Down
20 changes: 13 additions & 7 deletions src/libaudcore/playlist-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,18 @@ PlaylistData::PosChange PlaylistData::shuffle_pos_random(bool repeat,
return NO_POS;
}

int PlaylistData::pos_before(int ref_pos, bool shuffle) const
int PlaylistData::pos_before(int ref_pos, bool shuffle, bool repeat) const
{
if (shuffle)
return shuffle_pos_before(ref_pos);

return (ref_pos > 0) ? ref_pos - 1 : -1;
if (ref_pos > 0)
return ref_pos - 1;

if (repeat)
return m_entries.len() - 1;

return -1;
}

PlaylistData::PosChange PlaylistData::pos_after(int ref_pos, bool shuffle,
Expand Down Expand Up @@ -1005,10 +1011,10 @@ void PlaylistData::set_position(int entry_num)
queue_position_change();
}

bool PlaylistData::prev_song()
bool PlaylistData::prev_song(bool repeat)
{
bool shuffle = aud_get_bool("shuffle");
int pos = pos_before(position(), shuffle);
int pos = pos_before(position(), shuffle, repeat);
if (pos < 0)
return false;

Expand All @@ -1027,7 +1033,7 @@ bool PlaylistData::next_song(bool repeat)
return true;
}

bool PlaylistData::prev_album()
bool PlaylistData::prev_album(bool repeat)
{
bool shuffle = aud_get_bool("shuffle");
int pos = position();
Expand All @@ -1041,7 +1047,7 @@ bool PlaylistData::prev_album()

while (1)
{
auto prev_entry = entry_at(pos_before(pos, shuffle));
auto prev_entry = entry_at(pos_before(pos, shuffle, repeat));
if (!prev_entry || !same_album(entry->tuple, prev_entry->tuple))
break;

Expand All @@ -1053,7 +1059,7 @@ bool PlaylistData::prev_album()

// we're at the start of the current album
// one more song back puts us in the previous album
pos = pos_before(pos, shuffle);
pos = pos_before(pos, shuffle, repeat);
in_prev_album = true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/libaudcore/playlist-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class PlaylistData

void set_position(int entry_num);

bool prev_song();
bool prev_song(bool repeat);
bool next_song(bool repeat);
bool prev_album();
bool prev_album(bool repeat);
bool next_album(bool repeat);

int next_unscanned_entry(int entry_num) const;
Expand Down Expand Up @@ -159,7 +159,7 @@ class PlaylistData
PosChange shuffle_pos_after(int ref_pos, bool by_album) const;
PosChange shuffle_pos_random(bool repeat, bool by_album) const;

int pos_before(int ref_pos, bool shuffle) const;
int pos_before(int ref_pos, bool shuffle, bool repeat) const;
PosChange pos_after(int ref_pos, bool shuffle, bool by_album) const;
PosChange pos_new(bool repeat, bool shuffle, bool by_album,
int hint_pos) const;
Expand Down
12 changes: 10 additions & 2 deletions src/libaudcore/playlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,19 @@ EXPORT void Playlist::set_position(int entry_num) const
}
EXPORT bool Playlist::prev_song() const
{
SIMPLE_WRAPPER(bool, false, prev_song);
SIMPLE_WRAPPER(bool, false, prev_song, false);
}
EXPORT bool Playlist::prev_song(bool repeat) const
{
SIMPLE_WRAPPER(bool, false, prev_song, repeat);
}
EXPORT bool Playlist::prev_album() const
{
SIMPLE_WRAPPER(bool, false, prev_album);
SIMPLE_WRAPPER(bool, false, prev_album, false);
}
EXPORT bool Playlist::prev_album(bool repeat) const
{
SIMPLE_WRAPPER(bool, false, prev_album, repeat);
}
EXPORT bool Playlist::next_song(bool repeat) const
{
Expand Down
12 changes: 12 additions & 0 deletions src/libaudcore/playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,24 @@ class Playlist
* true on success, false if playlist position was not changed. */
bool prev_song() const;

/* Returns the playlist position to the previous entry in playback order.
* At the beginning of the playlist, wraps around to the end if <repeat>
* is true. Returns true on success, false if playlist position was not
* changed. */
bool prev_song(bool repeat) const;

/* Returns the playlist position to the first entry in playback order where
* the album is not the current album. Does not support wrapping past the
* beginning of the playlist. Returns true on success, false if playlist
* position was not changed. */
bool prev_album() const;

/* Returns the playlist position to the first entry of the previous album
* in playback order, taking current shuffle settings into account. At the
* beginning of the playlist, wraps around to the end if <repeat> is true.
* Returns true on success, false if playlist position was not changed. */
bool prev_album(bool repeat) const;

/* Gets/sets the entry which has keyboard focus (-1 = no entry). */
int get_focus() const;
void set_focus(int entry) const;
Expand Down