Skip to content

Commit

Permalink
db/LightSong: use std::chrono::duration for start_ms and end_ms
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Aug 28, 2014
1 parent 6ad9339 commit 2efd8ef
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/DetachedSong.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ DetachedSong::DetachedSong(const LightSong &other)
real_uri(other.real_uri != nullptr ? other.real_uri : ""),
tag(*other.tag),
mtime(other.mtime),
start_time(SongTime::FromMS(other.start_ms)),
end_time(SongTime::FromMS(other.end_ms)) {}
start_time(other.start_time),
end_time(other.end_time) {}

DetachedSong::~DetachedSong()
{
Expand Down
19 changes: 11 additions & 8 deletions src/SongPrint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,19 @@ song_print_info(Client &client, const LightSong &song, bool base)
{
song_print_uri(client, song, base);

if (song.end_ms > 0)
const unsigned start_ms = song.start_time.ToMS();
const unsigned end_ms = song.end_time.ToMS();

if (end_ms > 0)
client_printf(client, "Range: %u.%03u-%u.%03u\n",
song.start_ms / 1000,
song.start_ms % 1000,
song.end_ms / 1000,
song.end_ms % 1000);
else if (song.start_ms > 0)
start_ms / 1000,
start_ms % 1000,
end_ms / 1000,
end_ms % 1000);
else if (start_ms > 0)
client_printf(client, "Range: %u.%03u-\n",
song.start_ms / 1000,
song.start_ms % 1000);
start_ms / 1000,
start_ms % 1000);

if (song.mtime > 0)
time_print(client, "Last-Modified", song.mtime);
Expand Down
6 changes: 3 additions & 3 deletions src/db/LightSong.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
double
LightSong::GetDuration() const
{
if (end_ms > 0)
return (end_ms - start_ms) / 1000.0;
if (end_time.IsPositive())
return (end_time - start_time).ToDoubleS();

if (tag->time <= 0)
return 0;

return tag->time - start_ms / 1000.0;
return tag->time - start_time.ToDoubleS();
}
9 changes: 5 additions & 4 deletions src/db/LightSong.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef MPD_LIGHT_SONG_HXX
#define MPD_LIGHT_SONG_HXX

#include "Chrono.hxx"
#include "Compiler.h"

#include <string>
Expand Down Expand Up @@ -64,15 +65,15 @@ struct LightSong {
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;

gcc_pure
std::string GetURI() const {
Expand Down
6 changes: 3 additions & 3 deletions src/db/plugins/ProxyDatabasePlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ ProxySong::ProxySong(const mpd_song *song)
mtime = mpd_song_get_last_modified(song);

#if LIBMPDCLIENT_CHECK_VERSION(2,3,0)
start_ms = mpd_song_get_start(song) * 1000;
end_ms = mpd_song_get_end(song) * 1000;
start_time = SongTime::FromS(mpd_song_get_start(song));
end_time = SongTime::FromS(mpd_song_get_end(song));
#else
start_ms = end_ms = 0;
start_time = end_time = SongTime::zero();
#endif

TagBuilder tag_builder;
Expand Down
4 changes: 2 additions & 2 deletions src/db/plugins/simple/Song.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Song::Export() const
dest.real_uri = nullptr;
dest.tag = &tag;
dest.mtime = mtime;
dest.start_ms = start_ms;
dest.end_ms = end_ms;
dest.start_time = SongTime::FromMS(start_ms);
dest.end_time = SongTime::FromMS(end_ms);
return dest;
}
4 changes: 2 additions & 2 deletions src/db/plugins/upnp/UpnpDatabasePlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class UpnpSong : public LightSong {
real_uri = real_uri2.c_str();
tag = &tag2;
mtime = 0;
start_ms = end_ms = 0;
start_time = end_time = SongTime::zero();
}
};

Expand Down Expand Up @@ -360,7 +360,7 @@ visitSong(const UPnPDirObject &meta, const char *path,
song.real_uri = meta.url.c_str();
song.tag = &meta.tag;
song.mtime = 0;
song.start_ms = song.end_ms = 0;
song.start_time = song.end_time = SongTime::zero();

return !selection.Match(song) || visit_song(song, error);
}
Expand Down

0 comments on commit 2efd8ef

Please sign in to comment.