Increase update rate of track slider

Increases the refresh rate of the track progress bar to 25fps.
This looks much better with moodbars than the previous 1fps.
All the common code that use to run at 1fps still retains that
rate so the overhead due to this is negligible.
This commit is contained in:
Mark Furneaux 2014-05-19 11:51:40 -04:00
parent 8919b730da
commit b76af5f792
5 changed files with 39 additions and 17 deletions

View File

@ -186,6 +186,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
playlistitem_actions_separator_(nullptr),
library_sort_model_(new QSortFilterProxyModel(this)),
track_position_timer_(new QTimer(this)),
track_slider_timer_(new QTimer(this)),
was_maximized_(false),
saved_playback_position_(0),
saved_playback_state_(Engine::Empty),
@ -252,6 +253,9 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
track_position_timer_->setInterval(1000);
connect(track_position_timer_, SIGNAL(timeout()),
SLOT(UpdateTrackPosition()));
track_slider_timer_->setInterval(40);
connect(track_slider_timer_, SIGNAL(timeout()),
SLOT(UpdateTrackSliderPosition()));
// Start initialising the player
qLog(Debug) << "Initialising player";
@ -508,7 +512,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
connect(ui_->playlist->view(), SIGNAL(BackgroundPropertyChanged()),
SLOT(RefreshStyleSheet()));
connect(ui_->track_slider, SIGNAL(ValueChanged(int)), app_->player(),
connect(ui_->track_slider, SIGNAL(ValueChangedSeconds(int)), app_->player(),
SLOT(SeekTo(int)));
// Library connections
@ -982,6 +986,7 @@ void MainWindow::MediaStopped() {
tray_icon_->LastFMButtonLoveStateChanged(false);
track_position_timer_->stop();
track_slider_timer_->stop();
ui_->track_slider->SetStopped();
tray_icon_->SetProgress(0);
tray_icon_->SetStopped();
@ -996,6 +1001,7 @@ void MainWindow::MediaPaused() {
ui_->action_play_pause->setEnabled(true);
track_position_timer_->stop();
track_slider_timer_->stop();
tray_icon_->SetPaused();
}
@ -1024,6 +1030,7 @@ void MainWindow::MediaPlaying() {
#endif
track_position_timer_->start();
track_slider_timer_->start();
UpdateTrackPosition();
}
@ -1297,9 +1304,6 @@ void MainWindow::UpdateTrackPosition() {
}
}
// Update the slider
ui_->track_slider->SetValue(position, length);
// Update the tray icon every 10 seconds
if (position % 10 == 0) {
qLog(Debug) << "position" << position << "scrobble point" << scrobble_point
@ -1318,6 +1322,17 @@ void MainWindow::UpdateTrackPosition() {
}
}
void MainWindow::UpdateTrackSliderPosition() {
PlaylistItemPtr item(app_->player()->GetCurrentItem());
const int slider_position = std::floor(
float(app_->player()->engine()->position_nanosec()) / kNsecPerMsec);
const int slider_length = item->Metadata().length_nanosec() / kNsecPerMsec;
// Update the slider
ui_->track_slider->SetValue(slider_position, slider_length);
}
#ifdef HAVE_LIBLASTFM
void MainWindow::ScrobbledRadioStream() {
ui_->action_love->setEnabled(true);
@ -1830,7 +1845,7 @@ void MainWindow::AddFolder() {
// Add media
MimeData* data = new MimeData;
data->setUrls(QList<QUrl>() << QUrl::fromLocalFile(
QFileInfo(directory).canonicalFilePath()));
QFileInfo(directory).canonicalFilePath()));
AddToPlaylist(data);
}
@ -2216,7 +2231,7 @@ void MainWindow::PlaylistQueue() {
for (const QModelIndex& proxy_index :
ui_->playlist->view()->selectionModel()->selectedRows()) {
indexes << app_->playlist_manager()->current()->proxy()->mapToSource(
proxy_index);
proxy_index);
}
app_->playlist_manager()->current()->queue()->ToggleTracks(indexes);
@ -2227,7 +2242,7 @@ void MainWindow::PlaylistSkip() {
for (const QModelIndex& proxy_index :
ui_->playlist->view()->selectionModel()->selectedRows()) {
indexes << app_->playlist_manager()->current()->proxy()->mapToSource(
proxy_index);
proxy_index);
}
app_->playlist_manager()->current()->SkipTracks(indexes);

View File

@ -194,6 +194,7 @@ signals:
void Seeked(qlonglong microseconds);
void UpdateTrackPosition();
void UpdateTrackSliderPosition();
// Handle visibility of LastFM icons
void LastFMButtonVisibilityChanged(bool value);
@ -351,6 +352,7 @@ signals:
QSortFilterProxyModel* library_sort_model_;
QTimer* track_position_timer_;
QTimer* track_slider_timer_;
QSettings settings_;
bool was_maximized_;

View File

@ -18,6 +18,7 @@
#include "config.h"
#include "trackslider.h"
#include "ui_trackslider.h"
#include "core/timeconstants.h"
#include "core/utilities.h"
#include <QSettings>
@ -92,7 +93,7 @@ void TrackSlider::SetValue(int elapsed, int total) {
ui_->slider->setValue(elapsed);
setting_value_ = false;
UpdateTimes(elapsed);
UpdateTimes(elapsed / kMsecPerSec);
}
void TrackSlider::UpdateTimes(int elapsed) {
@ -100,12 +101,14 @@ void TrackSlider::UpdateTimes(int elapsed) {
// update normally if showing remaining time
if (show_remaining_time_) {
ui_->remaining->setText(
"-" + Utilities::PrettyTime(ui_->slider->maximum() - elapsed));
"-" + Utilities::PrettyTime((ui_->slider->maximum() / kMsecPerSec) -
elapsed));
} else {
// check if slider maximum value is changed before updating
if (slider_maximum_value_ != ui_->slider->maximum()) {
slider_maximum_value_ = ui_->slider->maximum();
ui_->remaining->setText(Utilities::PrettyTime(ui_->slider->maximum()));
ui_->remaining->setText(
Utilities::PrettyTime((ui_->slider->maximum() / kMsecPerSec)));
}
}
setEnabled(true);
@ -128,14 +131,14 @@ void TrackSlider::SetCanSeek(bool can_seek) {
void TrackSlider::Seek(int gap) {
if (ui_->slider->isEnabled())
ui_->slider->setValue(ui_->slider->value() + gap);
ui_->slider->setValue(ui_->slider->value() + gap * kMsecPerSec);
}
void TrackSlider::ValueMaybeChanged(int value) {
if (setting_value_) return;
UpdateTimes(value);
emit ValueChanged(value);
UpdateTimes(value / kMsecPerSec);
emit ValueChangedSeconds(value / kMsecPerSec);
}
bool TrackSlider::event(QEvent* e) {
@ -156,7 +159,7 @@ void TrackSlider::ToggleTimeDisplay() {
// we set the value to -1 because the label must be updated
slider_maximum_value_ = -1;
}
UpdateTimes(ui_->slider->value());
UpdateTimes(ui_->slider->value() / kMsecPerSec);
// save this setting
QSettings s;

View File

@ -53,6 +53,7 @@ class TrackSlider : public QWidget {
signals:
void ValueChanged(int value);
void ValueChangedSeconds(int value);
private slots:
void ValueMaybeChanged(int value);

View File

@ -17,6 +17,7 @@
#include "tracksliderpopup.h"
#include "tracksliderslider.h"
#include "core/timeconstants.h"
#include "core/utilities.h"
#include <QMouseEvent>
@ -76,8 +77,8 @@ void TrackSliderSlider::mouseMoveEvent(QMouseEvent* e) {
int slider_max = gr.right() - slider_length + 1;
mouse_hover_seconds_ = QStyle::sliderValueFromPosition(
minimum(), maximum(), e->x() - slider_length / 2 - slider_min + 1,
slider_max - slider_min);
minimum() / kMsecPerSec, maximum() / kMsecPerSec,
e->x() - slider_length / 2 - slider_min + 1, slider_max - slider_min);
popup_->SetText(Utilities::PrettyTime(mouse_hover_seconds_));
UpdateDeltaTime();
@ -99,7 +100,7 @@ void TrackSliderSlider::leaveEvent(QEvent* e) {
void TrackSliderSlider::UpdateDeltaTime() {
if (popup_->isVisible()) {
int delta_seconds = mouse_hover_seconds_ - value();
int delta_seconds = mouse_hover_seconds_ - (value() / kMsecPerSec);
popup_->SetSmallText(Utilities::PrettyTimeDelta(delta_seconds));
}
}