summaryrefslogtreecommitdiff
path: root/src/queue
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-08-27 19:11:55 +0200
committerMax Kellermann <max@duempel.org>2014-08-28 06:42:19 +0200
commit39529204925c95c1ae38fee25df334f3c3a1a4a7 (patch)
tree80265280e7557858814158b7ea0a6f5f65be8847 /src/queue
parentc2001a725978b665f0b22a4ad3865293754efd38 (diff)
Playlist: use std::chrono::duration for Seek*()
Diffstat (limited to 'src/queue')
-rw-r--r--src/queue/Playlist.hxx8
-rw-r--r--src/queue/PlaylistControl.cxx20
-rw-r--r--src/queue/PlaylistState.cxx8
3 files changed, 19 insertions, 17 deletions
diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx
index 0f73a0513..75e861a82 100644
--- a/src/queue/Playlist.hxx
+++ b/src/queue/Playlist.hxx
@@ -29,6 +29,8 @@ class DetachedSong;
class Database;
class Error;
class SongLoader;
+class SongTime;
+class SignedSongTime;
struct playlist {
/**
@@ -251,10 +253,10 @@ public:
PlaylistResult SeekSongPosition(PlayerControl &pc,
unsigned song_position,
- float seek_time);
+ SongTime seek_time);
PlaylistResult SeekSongId(PlayerControl &pc,
- unsigned song_id, float seek_time);
+ unsigned song_id, SongTime seek_time);
/**
* Seek within the current song. Fails if MPD is not currently
@@ -265,7 +267,7 @@ public:
* current position
*/
PlaylistResult SeekCurrent(PlayerControl &pc,
- float seek_time, bool relative);
+ SignedSongTime seek_time, bool relative);
bool GetRepeat() const {
return queue.repeat;
diff --git a/src/queue/PlaylistControl.cxx b/src/queue/PlaylistControl.cxx
index 5d4a910b0..e33386e41 100644
--- a/src/queue/PlaylistControl.cxx
+++ b/src/queue/PlaylistControl.cxx
@@ -190,7 +190,8 @@ playlist::PlayPrevious(PlayerControl &pc)
}
PlaylistResult
-playlist::SeekSongPosition(PlayerControl &pc, unsigned song, float seek_time)
+playlist::SeekSongPosition(PlayerControl &pc,
+ unsigned song, SongTime seek_time)
{
if (!queue.IsValidPosition(song))
return PlaylistResult::BAD_RANGE;
@@ -215,8 +216,7 @@ playlist::SeekSongPosition(PlayerControl &pc, unsigned song, float seek_time)
queued_song = nullptr;
}
- if (!pc.Seek(new DetachedSong(queue.GetOrder(i)),
- SongTime::FromS(seek_time))) {
+ if (!pc.Seek(new DetachedSong(queue.GetOrder(i)), seek_time)) {
UpdateQueuedSong(pc, queued_song);
return PlaylistResult::NOT_PLAYING;
@@ -229,7 +229,7 @@ playlist::SeekSongPosition(PlayerControl &pc, unsigned song, float seek_time)
}
PlaylistResult
-playlist::SeekSongId(PlayerControl &pc, unsigned id, float seek_time)
+playlist::SeekSongId(PlayerControl &pc, unsigned id, SongTime seek_time)
{
int song = queue.IdToPosition(id);
if (song < 0)
@@ -239,7 +239,8 @@ playlist::SeekSongId(PlayerControl &pc, unsigned id, float seek_time)
}
PlaylistResult
-playlist::SeekCurrent(PlayerControl &pc, float seek_time, bool relative)
+playlist::SeekCurrent(PlayerControl &pc,
+ SignedSongTime seek_time, bool relative)
{
if (!playing)
return PlaylistResult::NOT_PLAYING;
@@ -251,11 +252,10 @@ playlist::SeekCurrent(PlayerControl &pc, float seek_time, bool relative)
status.state != PlayerState::PAUSE)
return PlaylistResult::NOT_PLAYING;
- seek_time += (int)status.elapsed_time;
+ seek_time += SignedSongTime::FromS(status.elapsed_time);
+ if (seek_time.IsNegative())
+ seek_time = SignedSongTime::zero();
}
- if (seek_time < 0)
- seek_time = 0;
-
- return SeekSongPosition(pc, current, seek_time);
+ return SeekSongPosition(pc, current, SongTime(seek_time));
}
diff --git a/src/queue/PlaylistState.cxx b/src/queue/PlaylistState.cxx
index 18d8c9dc5..316a0767f 100644
--- a/src/queue/PlaylistState.cxx
+++ b/src/queue/PlaylistState.cxx
@@ -132,7 +132,7 @@ playlist_state_restore(const char *line, TextFile &file,
struct playlist &playlist, PlayerControl &pc)
{
int current = -1;
- int seek_time = 0;
+ SongTime seek_time = SongTime::zero();
bool random_mode = false;
if (!StringStartsWith(line, PLAYLIST_STATE_FILE_STATE))
@@ -150,8 +150,8 @@ playlist_state_restore(const char *line, TextFile &file,
while ((line = file.ReadLine()) != nullptr) {
if (StringStartsWith(line, PLAYLIST_STATE_FILE_TIME)) {
- seek_time =
- atoi(&(line[strlen(PLAYLIST_STATE_FILE_TIME)]));
+ unsigned seconds = atoi(&(line[strlen(PLAYLIST_STATE_FILE_TIME)]));
+ seek_time = SongTime::FromS(seconds);
} else if (StringStartsWith(line, PLAYLIST_STATE_FILE_REPEAT)) {
playlist.SetRepeat(pc,
strcmp(&(line[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
@@ -209,7 +209,7 @@ playlist_state_restore(const char *line, TextFile &file,
if (state == PlayerState::STOP /* && config_option */)
playlist.current = current;
- else if (seek_time == 0)
+ else if (seek_time.count() == 0)
playlist.PlayPosition(pc, current);
else
playlist.SeekSongPosition(pc, current, seek_time);