Add constants and variable units

Scrobble point constants are now defined as the minimum and maximum time last.fm requires for a scrobble to be valid.
This commit is contained in:
Mark Furneaux 2015-05-18 13:22:55 -04:00
parent 50ff5f5b0e
commit fde8ae0f30
2 changed files with 15 additions and 9 deletions

View File

@ -95,6 +95,9 @@ const char* Playlist::kWriteMetadata = "write_metadata";
const int Playlist::kUndoStackSize = 20;
const int Playlist::kUndoItemLimit = 500;
const qint64 Playlist::kMinScrobblePointNsecs = 31ll * kNsecPerSec;
const qint64 Playlist::kMaxScrobblePointNsecs = 240ll * kNsecPerSec;
Playlist::Playlist(PlaylistBackend* backend, TaskManager* task_manager,
LibraryBackend* library, int id, const QString& special_type,
bool favorite, QObject* parent)
@ -1705,24 +1708,24 @@ Song Playlist::current_item_metadata() const {
return current_item()->Metadata();
}
void Playlist::UpdateScrobblePoint(qint64 seek_point) {
void Playlist::UpdateScrobblePoint(qint64 seek_point_nanosec) {
const qint64 length = current_item_metadata().length_nanosec();
if (seek_point == 0) {
if (seek_point_nanosec == 0) {
if (length == 0) {
scrobble_point_ = 240ll * kNsecPerSec; // 4 minutes
scrobble_point_ = kMaxScrobblePointNsecs; // 4 minutes
} else {
scrobble_point_ =
qBound(31ll * kNsecPerSec, length / 2, 240ll * kNsecPerSec);
qBound(kMinScrobblePointNsecs, length / 2, kMaxScrobblePointNsecs);
}
} else {
if (length == 0) {
// current time + 4 minutes
scrobble_point_ = seek_point + (240ll * kNsecPerSec);
scrobble_point_ = seek_point_nanosec + kMaxScrobblePointNsecs;
} else {
scrobble_point_ =
qBound(seek_point + (31ll * kNsecPerSec), seek_point + (length / 2),
seek_point + (240ll * kNsecPerSec));
scrobble_point_ = qBound(seek_point_nanosec + kMinScrobblePointNsecs,
seek_point_nanosec + (length / 2),
seek_point_nanosec + kMaxScrobblePointNsecs);
}
}

View File

@ -160,6 +160,9 @@ class Playlist : public QAbstractListModel {
static const int kUndoStackSize;
static const int kUndoItemLimit;
static const qint64 kMinScrobblePointNsecs;
static const qint64 kMaxScrobblePointNsecs;
static bool CompareItems(int column, Qt::SortOrder order, PlaylistItemPtr a,
PlaylistItemPtr b);
@ -227,7 +230,7 @@ class Playlist : public QAbstractListModel {
}
void set_lastfm_status(LastFMStatus status) { lastfm_status_ = status; }
void set_have_incremented_playcount() { have_incremented_playcount_ = true; }
void UpdateScrobblePoint(qint64 seek_point = 0);
void UpdateScrobblePoint(qint64 seek_point_nanosec = 0);
// Changing the playlist
void InsertItems(const PlaylistItemList& items, int pos = -1,