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:
parent
8919b730da
commit
b76af5f792
|
@ -186,6 +186,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
|
||||||
playlistitem_actions_separator_(nullptr),
|
playlistitem_actions_separator_(nullptr),
|
||||||
library_sort_model_(new QSortFilterProxyModel(this)),
|
library_sort_model_(new QSortFilterProxyModel(this)),
|
||||||
track_position_timer_(new QTimer(this)),
|
track_position_timer_(new QTimer(this)),
|
||||||
|
track_slider_timer_(new QTimer(this)),
|
||||||
was_maximized_(false),
|
was_maximized_(false),
|
||||||
saved_playback_position_(0),
|
saved_playback_position_(0),
|
||||||
saved_playback_state_(Engine::Empty),
|
saved_playback_state_(Engine::Empty),
|
||||||
|
@ -252,6 +253,9 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
|
||||||
track_position_timer_->setInterval(1000);
|
track_position_timer_->setInterval(1000);
|
||||||
connect(track_position_timer_, SIGNAL(timeout()),
|
connect(track_position_timer_, SIGNAL(timeout()),
|
||||||
SLOT(UpdateTrackPosition()));
|
SLOT(UpdateTrackPosition()));
|
||||||
|
track_slider_timer_->setInterval(40);
|
||||||
|
connect(track_slider_timer_, SIGNAL(timeout()),
|
||||||
|
SLOT(UpdateTrackSliderPosition()));
|
||||||
|
|
||||||
// Start initialising the player
|
// Start initialising the player
|
||||||
qLog(Debug) << "Initialising player";
|
qLog(Debug) << "Initialising player";
|
||||||
|
@ -508,7 +512,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
|
||||||
connect(ui_->playlist->view(), SIGNAL(BackgroundPropertyChanged()),
|
connect(ui_->playlist->view(), SIGNAL(BackgroundPropertyChanged()),
|
||||||
SLOT(RefreshStyleSheet()));
|
SLOT(RefreshStyleSheet()));
|
||||||
|
|
||||||
connect(ui_->track_slider, SIGNAL(ValueChanged(int)), app_->player(),
|
connect(ui_->track_slider, SIGNAL(ValueChangedSeconds(int)), app_->player(),
|
||||||
SLOT(SeekTo(int)));
|
SLOT(SeekTo(int)));
|
||||||
|
|
||||||
// Library connections
|
// Library connections
|
||||||
|
@ -982,6 +986,7 @@ void MainWindow::MediaStopped() {
|
||||||
tray_icon_->LastFMButtonLoveStateChanged(false);
|
tray_icon_->LastFMButtonLoveStateChanged(false);
|
||||||
|
|
||||||
track_position_timer_->stop();
|
track_position_timer_->stop();
|
||||||
|
track_slider_timer_->stop();
|
||||||
ui_->track_slider->SetStopped();
|
ui_->track_slider->SetStopped();
|
||||||
tray_icon_->SetProgress(0);
|
tray_icon_->SetProgress(0);
|
||||||
tray_icon_->SetStopped();
|
tray_icon_->SetStopped();
|
||||||
|
@ -996,6 +1001,7 @@ void MainWindow::MediaPaused() {
|
||||||
ui_->action_play_pause->setEnabled(true);
|
ui_->action_play_pause->setEnabled(true);
|
||||||
|
|
||||||
track_position_timer_->stop();
|
track_position_timer_->stop();
|
||||||
|
track_slider_timer_->stop();
|
||||||
|
|
||||||
tray_icon_->SetPaused();
|
tray_icon_->SetPaused();
|
||||||
}
|
}
|
||||||
|
@ -1024,6 +1030,7 @@ void MainWindow::MediaPlaying() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
track_position_timer_->start();
|
track_position_timer_->start();
|
||||||
|
track_slider_timer_->start();
|
||||||
UpdateTrackPosition();
|
UpdateTrackPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1297,9 +1304,6 @@ void MainWindow::UpdateTrackPosition() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the slider
|
|
||||||
ui_->track_slider->SetValue(position, length);
|
|
||||||
|
|
||||||
// Update the tray icon every 10 seconds
|
// Update the tray icon every 10 seconds
|
||||||
if (position % 10 == 0) {
|
if (position % 10 == 0) {
|
||||||
qLog(Debug) << "position" << position << "scrobble point" << scrobble_point
|
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
|
#ifdef HAVE_LIBLASTFM
|
||||||
void MainWindow::ScrobbledRadioStream() {
|
void MainWindow::ScrobbledRadioStream() {
|
||||||
ui_->action_love->setEnabled(true);
|
ui_->action_love->setEnabled(true);
|
||||||
|
@ -1830,7 +1845,7 @@ void MainWindow::AddFolder() {
|
||||||
// Add media
|
// Add media
|
||||||
MimeData* data = new MimeData;
|
MimeData* data = new MimeData;
|
||||||
data->setUrls(QList<QUrl>() << QUrl::fromLocalFile(
|
data->setUrls(QList<QUrl>() << QUrl::fromLocalFile(
|
||||||
QFileInfo(directory).canonicalFilePath()));
|
QFileInfo(directory).canonicalFilePath()));
|
||||||
AddToPlaylist(data);
|
AddToPlaylist(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2216,7 +2231,7 @@ void MainWindow::PlaylistQueue() {
|
||||||
for (const QModelIndex& proxy_index :
|
for (const QModelIndex& proxy_index :
|
||||||
ui_->playlist->view()->selectionModel()->selectedRows()) {
|
ui_->playlist->view()->selectionModel()->selectedRows()) {
|
||||||
indexes << app_->playlist_manager()->current()->proxy()->mapToSource(
|
indexes << app_->playlist_manager()->current()->proxy()->mapToSource(
|
||||||
proxy_index);
|
proxy_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
app_->playlist_manager()->current()->queue()->ToggleTracks(indexes);
|
app_->playlist_manager()->current()->queue()->ToggleTracks(indexes);
|
||||||
|
@ -2227,7 +2242,7 @@ void MainWindow::PlaylistSkip() {
|
||||||
for (const QModelIndex& proxy_index :
|
for (const QModelIndex& proxy_index :
|
||||||
ui_->playlist->view()->selectionModel()->selectedRows()) {
|
ui_->playlist->view()->selectionModel()->selectedRows()) {
|
||||||
indexes << app_->playlist_manager()->current()->proxy()->mapToSource(
|
indexes << app_->playlist_manager()->current()->proxy()->mapToSource(
|
||||||
proxy_index);
|
proxy_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
app_->playlist_manager()->current()->SkipTracks(indexes);
|
app_->playlist_manager()->current()->SkipTracks(indexes);
|
||||||
|
|
|
@ -194,6 +194,7 @@ signals:
|
||||||
|
|
||||||
void Seeked(qlonglong microseconds);
|
void Seeked(qlonglong microseconds);
|
||||||
void UpdateTrackPosition();
|
void UpdateTrackPosition();
|
||||||
|
void UpdateTrackSliderPosition();
|
||||||
|
|
||||||
// Handle visibility of LastFM icons
|
// Handle visibility of LastFM icons
|
||||||
void LastFMButtonVisibilityChanged(bool value);
|
void LastFMButtonVisibilityChanged(bool value);
|
||||||
|
@ -351,6 +352,7 @@ signals:
|
||||||
QSortFilterProxyModel* library_sort_model_;
|
QSortFilterProxyModel* library_sort_model_;
|
||||||
|
|
||||||
QTimer* track_position_timer_;
|
QTimer* track_position_timer_;
|
||||||
|
QTimer* track_slider_timer_;
|
||||||
QSettings settings_;
|
QSettings settings_;
|
||||||
|
|
||||||
bool was_maximized_;
|
bool was_maximized_;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "trackslider.h"
|
#include "trackslider.h"
|
||||||
#include "ui_trackslider.h"
|
#include "ui_trackslider.h"
|
||||||
|
#include "core/timeconstants.h"
|
||||||
#include "core/utilities.h"
|
#include "core/utilities.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
@ -92,7 +93,7 @@ void TrackSlider::SetValue(int elapsed, int total) {
|
||||||
ui_->slider->setValue(elapsed);
|
ui_->slider->setValue(elapsed);
|
||||||
setting_value_ = false;
|
setting_value_ = false;
|
||||||
|
|
||||||
UpdateTimes(elapsed);
|
UpdateTimes(elapsed / kMsecPerSec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackSlider::UpdateTimes(int elapsed) {
|
void TrackSlider::UpdateTimes(int elapsed) {
|
||||||
|
@ -100,12 +101,14 @@ void TrackSlider::UpdateTimes(int elapsed) {
|
||||||
// update normally if showing remaining time
|
// update normally if showing remaining time
|
||||||
if (show_remaining_time_) {
|
if (show_remaining_time_) {
|
||||||
ui_->remaining->setText(
|
ui_->remaining->setText(
|
||||||
"-" + Utilities::PrettyTime(ui_->slider->maximum() - elapsed));
|
"-" + Utilities::PrettyTime((ui_->slider->maximum() / kMsecPerSec) -
|
||||||
|
elapsed));
|
||||||
} else {
|
} else {
|
||||||
// check if slider maximum value is changed before updating
|
// check if slider maximum value is changed before updating
|
||||||
if (slider_maximum_value_ != ui_->slider->maximum()) {
|
if (slider_maximum_value_ != ui_->slider->maximum()) {
|
||||||
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);
|
setEnabled(true);
|
||||||
|
@ -128,14 +131,14 @@ void TrackSlider::SetCanSeek(bool can_seek) {
|
||||||
|
|
||||||
void TrackSlider::Seek(int gap) {
|
void TrackSlider::Seek(int gap) {
|
||||||
if (ui_->slider->isEnabled())
|
if (ui_->slider->isEnabled())
|
||||||
ui_->slider->setValue(ui_->slider->value() + gap);
|
ui_->slider->setValue(ui_->slider->value() + gap * kMsecPerSec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackSlider::ValueMaybeChanged(int value) {
|
void TrackSlider::ValueMaybeChanged(int value) {
|
||||||
if (setting_value_) return;
|
if (setting_value_) return;
|
||||||
|
|
||||||
UpdateTimes(value);
|
UpdateTimes(value / kMsecPerSec);
|
||||||
emit ValueChanged(value);
|
emit ValueChangedSeconds(value / kMsecPerSec);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrackSlider::event(QEvent* e) {
|
bool TrackSlider::event(QEvent* e) {
|
||||||
|
@ -156,7 +159,7 @@ void TrackSlider::ToggleTimeDisplay() {
|
||||||
// we set the value to -1 because the label must be updated
|
// we set the value to -1 because the label must be updated
|
||||||
slider_maximum_value_ = -1;
|
slider_maximum_value_ = -1;
|
||||||
}
|
}
|
||||||
UpdateTimes(ui_->slider->value());
|
UpdateTimes(ui_->slider->value() / kMsecPerSec);
|
||||||
|
|
||||||
// save this setting
|
// save this setting
|
||||||
QSettings s;
|
QSettings s;
|
||||||
|
|
|
@ -53,6 +53,7 @@ class TrackSlider : public QWidget {
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ValueChanged(int value);
|
void ValueChanged(int value);
|
||||||
|
void ValueChangedSeconds(int value);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void ValueMaybeChanged(int value);
|
void ValueMaybeChanged(int value);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "tracksliderpopup.h"
|
#include "tracksliderpopup.h"
|
||||||
#include "tracksliderslider.h"
|
#include "tracksliderslider.h"
|
||||||
|
#include "core/timeconstants.h"
|
||||||
#include "core/utilities.h"
|
#include "core/utilities.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
@ -76,8 +77,8 @@ void TrackSliderSlider::mouseMoveEvent(QMouseEvent* e) {
|
||||||
int slider_max = gr.right() - slider_length + 1;
|
int slider_max = gr.right() - slider_length + 1;
|
||||||
|
|
||||||
mouse_hover_seconds_ = QStyle::sliderValueFromPosition(
|
mouse_hover_seconds_ = QStyle::sliderValueFromPosition(
|
||||||
minimum(), maximum(), e->x() - slider_length / 2 - slider_min + 1,
|
minimum() / kMsecPerSec, maximum() / kMsecPerSec,
|
||||||
slider_max - slider_min);
|
e->x() - slider_length / 2 - slider_min + 1, slider_max - slider_min);
|
||||||
|
|
||||||
popup_->SetText(Utilities::PrettyTime(mouse_hover_seconds_));
|
popup_->SetText(Utilities::PrettyTime(mouse_hover_seconds_));
|
||||||
UpdateDeltaTime();
|
UpdateDeltaTime();
|
||||||
|
@ -99,7 +100,7 @@ void TrackSliderSlider::leaveEvent(QEvent* e) {
|
||||||
|
|
||||||
void TrackSliderSlider::UpdateDeltaTime() {
|
void TrackSliderSlider::UpdateDeltaTime() {
|
||||||
if (popup_->isVisible()) {
|
if (popup_->isVisible()) {
|
||||||
int delta_seconds = mouse_hover_seconds_ - value();
|
int delta_seconds = mouse_hover_seconds_ - (value() / kMsecPerSec);
|
||||||
popup_->SetSmallText(Utilities::PrettyTimeDelta(delta_seconds));
|
popup_->SetSmallText(Utilities::PrettyTimeDelta(delta_seconds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue