aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/DetachedSong.cxx11
-rw-r--r--src/DetachedSong.hxx37
-rw-r--r--src/PlayerThread.cxx20
-rw-r--r--src/SongPrint.cxx4
-rw-r--r--src/SongSave.cxx6
-rw-r--r--src/db/plugins/simple/Song.cxx4
-rw-r--r--src/decoder/DecoderAPI.cxx2
-rw-r--r--src/playlist/cue/CueParser.cxx6
-rw-r--r--src/queue/PlaylistEdit.cxx4
-rw-r--r--src/queue/QueueSave.cxx2
-rw-r--r--test/dump_playlist.cxx4
-rw-r--r--test/test_translate_song.cxx8
12 files changed, 57 insertions, 51 deletions
diff --git a/src/DetachedSong.cxx b/src/DetachedSong.cxx
index eb377e591..752578430 100644
--- a/src/DetachedSong.cxx
+++ b/src/DetachedSong.cxx
@@ -28,11 +28,12 @@ DetachedSong::DetachedSong(const LightSong &other)
real_uri(other.real_uri != nullptr ? other.real_uri : ""),
tag(*other.tag),
mtime(other.mtime),
- start_ms(other.start_ms), end_ms(other.end_ms) {}
+ start_time(SongTime::FromMS(other.start_ms)),
+ end_time(SongTime::FromMS(other.end_ms)) {}
DetachedSong::~DetachedSong()
{
- /* this destructor exists here just so it won't get inlined */
+ /* this destructor exists here just so it won't inlined */
}
bool
@@ -60,8 +61,8 @@ DetachedSong::IsInDatabase() const
double
DetachedSong::GetDuration() const
{
- if (end_ms > 0)
- return (end_ms - start_ms) / 1000.0;
+ if (end_time.IsPositive())
+ return (end_time - start_time).ToDoubleS();
- return tag.time - start_ms / 1000.0;
+ return tag.time - start_time.ToDoubleS();
}
diff --git a/src/DetachedSong.hxx b/src/DetachedSong.hxx
index 7ea0bc8d8..135e9c3cc 100644
--- a/src/DetachedSong.hxx
+++ b/src/DetachedSong.hxx
@@ -22,6 +22,7 @@
#include "check.h"
#include "tag/Tag.hxx"
+#include "Chrono.hxx"
#include "Compiler.h"
#include <string>
@@ -65,15 +66,15 @@ class DetachedSong {
time_t mtime;
/**
- * Start of this sub-song within the file in milliseconds.
+ * Start of this sub-song within the file.
*/
- unsigned start_ms;
+ SongTime start_time;
/**
- * End of this sub-song within the file in milliseconds.
+ * End of this sub-song within the file.
* Unused if zero.
*/
- unsigned end_ms;
+ SongTime end_time;
explicit DetachedSong(const LightSong &other);
@@ -82,21 +83,25 @@ public:
explicit DetachedSong(const char *_uri)
:uri(_uri),
- mtime(0), start_ms(0), end_ms(0) {}
+ mtime(0),
+ start_time(SongTime::zero()), end_time(SongTime::zero()) {}
explicit DetachedSong(const std::string &_uri)
:uri(_uri),
- mtime(0), start_ms(0), end_ms(0) {}
+ mtime(0),
+ start_time(SongTime::zero()), end_time(SongTime::zero()) {}
explicit DetachedSong(std::string &&_uri)
:uri(std::move(_uri)),
- mtime(0), start_ms(0), end_ms(0) {}
+ mtime(0),
+ start_time(SongTime::zero()), end_time(SongTime::zero()) {}
template<typename U>
DetachedSong(U &&_uri, Tag &&_tag)
:uri(std::forward<U>(_uri)),
tag(std::move(_tag)),
- mtime(0), start_ms(0), end_ms(0) {}
+ mtime(0),
+ start_time(SongTime::zero()), end_time(SongTime::zero()) {}
DetachedSong(DetachedSong &&) = default;
@@ -191,20 +196,20 @@ public:
mtime = _value;
}
- unsigned GetStartMS() const {
- return start_ms;
+ SongTime GetStartTime() const {
+ return start_time;
}
- void SetStartMS(unsigned _value) {
- start_ms = _value;
+ void SetStartTime(SongTime _value) {
+ start_time = _value;
}
- unsigned GetEndMS() const {
- return end_ms;
+ SongTime GetEndTime() const {
+ return end_time;
}
- void SetEndMS(unsigned _value) {
- end_ms = _value;
+ void SetEndTime(SongTime _value) {
+ end_time = _value;
}
gcc_pure
diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx
index 0aa8d105d..e527a80ba 100644
--- a/src/PlayerThread.cxx
+++ b/src/PlayerThread.cxx
@@ -291,12 +291,12 @@ Player::StartDecoder(MusicPipe &_pipe)
assert(queued || pc.command == PlayerCommand::SEEK);
assert(pc.next_song != nullptr);
- unsigned start_ms = pc.next_song->GetStartMS();
+ SongTime start_time = pc.next_song->GetStartTime();
if (pc.command == PlayerCommand::SEEK)
- start_ms += pc.seek_time.ToMS();
+ start_time += pc.seek_time;
dc.Start(new DetachedSong(*pc.next_song),
- start_ms, pc.next_song->GetEndMS(),
+ start_time.ToMS(), pc.next_song->GetEndTime().ToMS(),
buffer, _pipe);
}
@@ -376,13 +376,13 @@ real_song_duration(const DetachedSong &song, double decoder_duration)
back to Song::GetDuration() */
return song.GetDuration();
- const unsigned start_ms = song.GetStartMS();
- const unsigned end_ms = song.GetEndMS();
+ const SongTime start_time = song.GetStartTime();
+ const SongTime end_time = song.GetEndTime();
- if (end_ms > 0 && end_ms / 1000.0 < decoder_duration)
- return (end_ms - start_ms) / 1000.0;
+ if (end_time.IsPositive() && end_time.ToDoubleS() < decoder_duration)
+ return (end_time - start_time).ToDoubleS();
- return decoder_duration - start_ms / 1000.0;
+ return decoder_duration - start_time.ToDoubleS();
}
bool
@@ -518,7 +518,7 @@ Player::SeekDecoder()
{
assert(pc.next_song != nullptr);
- const unsigned start_ms = pc.next_song->GetStartMS();
+ const SongTime start_time = pc.next_song->GetStartTime();
if (!dc.LockIsCurrentSong(*pc.next_song)) {
/* the decoder is already decoding the "next" song -
@@ -568,7 +568,7 @@ Player::SeekDecoder()
where = total_time;
}
- if (!dc.Seek(where + SongTime::FromMS(start_ms))) {
+ if (!dc.Seek(where + start_time)) {
/* decoder failure */
player_command_finished(pc);
return false;
diff --git a/src/SongPrint.cxx b/src/SongPrint.cxx
index c2501d037..d14eea417 100644
--- a/src/SongPrint.cxx
+++ b/src/SongPrint.cxx
@@ -97,8 +97,8 @@ song_print_info(Client &client, const DetachedSong &song, bool base)
{
song_print_uri(client, song, base);
- const unsigned start_ms = song.GetStartMS();
- const unsigned end_ms = song.GetEndMS();
+ const unsigned start_ms = song.GetStartTime().ToMS();
+ const unsigned end_ms = song.GetEndTime().ToMS();
if (end_ms > 0)
client_printf(client, "Range: %u.%03u-%u.%03u\n",
diff --git a/src/SongSave.cxx b/src/SongSave.cxx
index 93613e938..d06dabfd6 100644
--- a/src/SongSave.cxx
+++ b/src/SongSave.cxx
@@ -65,7 +65,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song)
{
os.Format(SONG_BEGIN "%s\n", song.GetURI());
- range_save(os, song.GetStartMS(), song.GetEndMS());
+ range_save(os, song.GetStartTime().ToMS(), song.GetEndTime().ToMS());
tag_save(os, song.GetTag());
@@ -113,8 +113,8 @@ song_load(TextFile &file, const char *uri,
? strtoul(endptr + 1, nullptr, 10)
: 0;
- song->SetStartMS(start_ms);
- song->SetEndMS(end_ms);
+ song->SetStartTime(SongTime::FromMS(start_ms));
+ song->SetEndTime(SongTime::FromMS(end_ms));
} else {
delete song;
diff --git a/src/db/plugins/simple/Song.cxx b/src/db/plugins/simple/Song.cxx
index 3bd3d8316..9e62d579e 100644
--- a/src/db/plugins/simple/Song.cxx
+++ b/src/db/plugins/simple/Song.cxx
@@ -59,8 +59,8 @@ Song::NewFrom(DetachedSong &&other, Directory &parent)
Song *song = song_alloc(other.GetURI(), parent);
song->tag = std::move(other.WritableTag());
song->mtime = other.GetLastModified();
- song->start_ms = other.GetStartMS();
- song->end_ms = other.GetEndMS();
+ song->start_ms = other.GetStartTime().ToMS();
+ song->end_ms = other.GetEndTime().ToMS();
return song;
}
diff --git a/src/decoder/DecoderAPI.cxx b/src/decoder/DecoderAPI.cxx
index 939434f83..83acb8a89 100644
--- a/src/decoder/DecoderAPI.cxx
+++ b/src/decoder/DecoderAPI.cxx
@@ -521,7 +521,7 @@ decoder_data(Decoder &decoder,
const auto dest =
chunk->Write(dc.out_audio_format,
decoder.timestamp -
- dc.song->GetStartMS() / 1000.0,
+ dc.song->GetStartTime().ToDoubleS(),
kbit_rate);
if (dest.IsNull()) {
/* the chunk is full, flush it */
diff --git a/src/playlist/cue/CueParser.cxx b/src/playlist/cue/CueParser.cxx
index 10f28b5a1..372c90b78 100644
--- a/src/playlist/cue/CueParser.cxx
+++ b/src/playlist/cue/CueParser.cxx
@@ -267,12 +267,12 @@ CueParser::Feed2(char *p)
return;
if (!last_updated && previous != nullptr &&
- previous->GetStartMS() < (unsigned)position_ms) {
+ previous->GetStartTime().ToMS() < (unsigned)position_ms) {
last_updated = true;
- previous->SetEndMS(position_ms);
+ previous->SetEndTime(SongTime::FromMS(position_ms));
}
- current->SetStartMS(position_ms);
+ current->SetStartTime(SongTime::FromMS(position_ms));
}
}
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index 2ac015f6f..d10edb942 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -479,8 +479,8 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
}
/* edit it */
- song.SetStartMS(start_ms);
- song.SetEndMS(end_ms);
+ song.SetStartTime(SongTime::FromMS(start_ms));
+ song.SetEndTime(SongTime::FromMS(end_ms));
/* announce the change to all interested subsystems */
UpdateQueuedSong(pc, nullptr);
diff --git a/src/queue/QueueSave.cxx b/src/queue/QueueSave.cxx
index 6d871ac19..bc2702572 100644
--- a/src/queue/QueueSave.cxx
+++ b/src/queue/QueueSave.cxx
@@ -53,7 +53,7 @@ static void
queue_save_song(BufferedOutputStream &os, int idx, const DetachedSong &song)
{
if (song.IsInDatabase() &&
- song.GetStartMS() == 0 && song.GetEndMS() == 0)
+ song.GetStartTime().IsZero() && song.GetEndTime().IsZero())
/* use the brief format (just the URI) for "full"
database songs */
queue_save_database_song(os, idx, song);
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index 1262979e9..6205c8a79 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -128,8 +128,8 @@ int main(int argc, char **argv)
while ((song = playlist->NextSong()) != NULL) {
printf("%s\n", song->GetURI());
- const unsigned start_ms = song->GetStartMS();
- const unsigned end_ms = song->GetEndMS();
+ const unsigned start_ms = song->GetStartTime().ToMS();
+ const unsigned end_ms = song->GetEndTime().ToMS();
if (end_ms > 0)
printf("range: %u:%02u..%u:%02u\n",
diff --git a/test/test_translate_song.cxx b/test/test_translate_song.cxx
index 374fd34a2..324a79d29 100644
--- a/test/test_translate_song.cxx
+++ b/test/test_translate_song.cxx
@@ -185,15 +185,15 @@ ToString(const DetachedSong &song)
result.push_back('|');
- if (song.GetStartMS() > 0) {
- sprintf(buffer, "%u", song.GetStartMS());
+ if (song.GetStartTime().IsPositive()) {
+ sprintf(buffer, "%u", song.GetStartTime().ToMS());
result.append(buffer);
}
result.push_back('-');
- if (song.GetEndMS() > 0) {
- sprintf(buffer, "%u", song.GetEndMS());
+ if (song.GetEndTime().IsPositive()) {
+ sprintf(buffer, "%u", song.GetEndTime().ToMS());
result.append(buffer);
}