@@ -400,7 +400,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
|
||||
app_->player()->Init();
|
||||
EngineChanged(app_->player()->engine()->type());
|
||||
const uint volume = app_->player()->GetVolume();
|
||||
ui_->volume->SetValueFromVolume(volume);
|
||||
ui_->volume->SetValue(volume);
|
||||
VolumeChanged(volume);
|
||||
|
||||
// Models
|
||||
@@ -583,7 +583,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
|
||||
ui_->stop_button->setMenu(stop_menu);
|
||||
|
||||
// Player connections
|
||||
QObject::connect(ui_->volume, &VolumeSlider::valueChanged, app_->player(), &Player::SetVolumeFromValue);
|
||||
QObject::connect(ui_->volume, &VolumeSlider::valueChanged, app_->player(), &Player::SetVolumeFromSlider);
|
||||
|
||||
QObject::connect(app_->player(), &Player::EngineChanged, this, &MainWindow::EngineChanged);
|
||||
QObject::connect(app_->player(), &Player::Error, this, &MainWindow::ShowErrorDialog);
|
||||
@@ -606,7 +606,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
|
||||
QObject::connect(app_->player(), &Player::Stopped, osd_, &OSDBase::Stopped);
|
||||
QObject::connect(app_->player(), &Player::PlaylistFinished, osd_, &OSDBase::PlaylistFinished);
|
||||
QObject::connect(app_->player(), &Player::VolumeChanged, osd_, &OSDBase::VolumeChanged);
|
||||
QObject::connect(app_->player(), &Player::VolumeChanged, ui_->volume, &VolumeSlider::SetValueFromVolume);
|
||||
QObject::connect(app_->player(), &Player::VolumeChanged, ui_->volume, &VolumeSlider::SetValue);
|
||||
QObject::connect(app_->player(), &Player::ForceShowOSD, this, &MainWindow::ForceShowOSD);
|
||||
|
||||
QObject::connect(app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, this, &MainWindow::SongChanged);
|
||||
@@ -1201,6 +1201,7 @@ void MainWindow::SaveSettings() {
|
||||
|
||||
SaveGeometry();
|
||||
SavePlaybackStatus();
|
||||
app_->player()->SaveVolume();
|
||||
ui_->tabs->SaveSettings(kSettingsGroup);
|
||||
ui_->playlist->view()->SaveSettings();
|
||||
app_->scrobbler()->WriteCache();
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCoreApplication>
|
||||
@@ -175,7 +176,9 @@ void Mpris2::EngineStateChanged(Engine::State newState) {
|
||||
|
||||
}
|
||||
|
||||
void Mpris2::VolumeChanged() { EmitNotification("Volume"); }
|
||||
void Mpris2::VolumeChanged() {
|
||||
EmitNotification("Volume");
|
||||
}
|
||||
|
||||
void Mpris2::ShuffleModeChanged() { EmitNotification("Shuffle"); }
|
||||
|
||||
@@ -411,8 +414,8 @@ double Mpris2::Volume() const {
|
||||
return app_->player()->GetVolume() / 100.0;
|
||||
}
|
||||
|
||||
void Mpris2::SetVolume(const double value) {
|
||||
app_->player()->SetVolume(static_cast<uint>(std::max(std::min(lround(value * 100.0), 100L), 0L)));
|
||||
void Mpris2::SetVolume(const double volume) {
|
||||
app_->player()->SetVolume(static_cast<uint>(qBound(0L, lround(volume * 100.0), 100L)));
|
||||
}
|
||||
|
||||
qint64 Mpris2::Position() const {
|
||||
|
||||
@@ -145,7 +145,7 @@ class Mpris2 : public QObject {
|
||||
void SetShuffle(bool enable);
|
||||
QVariantMap Metadata() const;
|
||||
double Volume() const;
|
||||
void SetVolume(const double value);
|
||||
void SetVolume(const double volume);
|
||||
qint64 Position() const;
|
||||
double MaximumRate() const;
|
||||
double MinimumRate() const;
|
||||
|
||||
@@ -83,29 +83,24 @@ Player::Player(Application *app, QObject *parent)
|
||||
autoscroll_(Playlist::AutoScroll_Maybe),
|
||||
last_state_(Engine::Empty),
|
||||
nb_errors_received_(0),
|
||||
volume_(100),
|
||||
volume_before_mute_(100),
|
||||
last_pressed_previous_(QDateTime::currentDateTime()),
|
||||
continue_on_error_(false),
|
||||
greyout_(true),
|
||||
menu_previousmode_(BehaviourSettingsPage::PreviousBehaviour_DontRestart),
|
||||
seek_step_sec_(10),
|
||||
volume_control_(true),
|
||||
play_offset_nanosec_(0) {
|
||||
|
||||
settings_.beginGroup(kSettingsGroup);
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||
Engine::EngineType enginetype = Engine::EngineTypeFromName(s.value("engine", EngineName(Engine::GStreamer)).toString().toLower());
|
||||
s.endGroup();
|
||||
|
||||
CreateEngine(enginetype);
|
||||
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
settings_.endGroup();
|
||||
}
|
||||
|
||||
Engine::EngineType Player::CreateEngine(Engine::EngineType enginetype) {
|
||||
|
||||
Engine::EngineType use_enginetype(Engine::None);
|
||||
@@ -181,6 +176,7 @@ void Player::Init() {
|
||||
QObject::connect(engine_.get(), &EngineBase::TrackAboutToEnd, this, &Player::TrackAboutToEnd);
|
||||
QObject::connect(engine_.get(), &EngineBase::TrackEnded, this, &Player::TrackEnded);
|
||||
QObject::connect(engine_.get(), &EngineBase::MetaData, this, &Player::EngineMetadataReceived);
|
||||
QObject::connect(engine_.get(), &EngineBase::VolumeChanged, this, &Player::SetVolumeFromEngine);
|
||||
|
||||
// Equalizer
|
||||
QObject::connect(equalizer_, &Equalizer::StereoBalancerEnabledChanged, app_->player()->engine(), &EngineBase::SetStereoBalancerEnabled);
|
||||
@@ -193,17 +189,10 @@ void Player::Init() {
|
||||
engine_->SetEqualizerEnabled(equalizer_->is_equalizer_enabled());
|
||||
engine_->SetEqualizerParameters(equalizer_->preamp_value(), equalizer_->gain_values());
|
||||
|
||||
s.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||
volume_control_ = s.value("volume_control", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
if (volume_control_) {
|
||||
int volume = settings_.value("volume", 100).toInt();
|
||||
SetVolume(volume);
|
||||
}
|
||||
|
||||
ReloadSettings();
|
||||
|
||||
LoadVolume();
|
||||
|
||||
}
|
||||
|
||||
void Player::ReloadSettings() {
|
||||
@@ -220,15 +209,30 @@ void Player::ReloadSettings() {
|
||||
seek_step_sec_ = s.value("seek_step_sec", 10).toInt();
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup(BackendSettingsPage::kSettingsGroup);
|
||||
bool volume_control = s.value("volume_control", true).toBool();
|
||||
if (!volume_control && GetVolume() != 100) SetVolume(100);
|
||||
s.endGroup();
|
||||
|
||||
engine_->ReloadSettings();
|
||||
|
||||
}
|
||||
|
||||
void Player::LoadVolume() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
const uint volume = s.value("volume", 100).toInt();
|
||||
s.endGroup();
|
||||
|
||||
SetVolume(volume);
|
||||
|
||||
}
|
||||
|
||||
void Player::SaveVolume() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
s.setValue("volume", volume_);
|
||||
s.endGroup();
|
||||
|
||||
}
|
||||
|
||||
void Player::HandleLoadResult(const UrlHandler::LoadResult &result) {
|
||||
|
||||
if (loading_async_.contains(result.original_url_)) {
|
||||
@@ -641,23 +645,35 @@ uint Player::GetVolume() const {
|
||||
|
||||
}
|
||||
|
||||
void Player::SetVolumeFromValue(const int value) {
|
||||
void Player::SetVolumeFromSlider(const int value) {
|
||||
|
||||
SetVolume(static_cast<uint>(std::max(0, value)));
|
||||
const uint volume = static_cast<uint>(qBound(0, value, 100));
|
||||
if (volume != volume_) {
|
||||
engine_->SetVolume(volume);
|
||||
emit VolumeChanged(volume_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Player::SetVolumeFromEngine(const uint volume) {
|
||||
|
||||
const uint new_volume = qBound(0U, volume, 100U);
|
||||
if (new_volume != volume_) {
|
||||
volume_ = new_volume;
|
||||
emit VolumeChanged(volume_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Player::SetVolume(const uint volume) {
|
||||
|
||||
uint old_volume = engine_->volume();
|
||||
uint new_volume = qBound(0U, volume, 100U);
|
||||
settings_.setValue("volume", new_volume);
|
||||
engine_->SetVolume(new_volume);
|
||||
|
||||
if (new_volume != old_volume) {
|
||||
emit VolumeChanged(new_volume);
|
||||
const uint new_volume = qBound(0U, volume, 100U);
|
||||
if (new_volume != volume_) {
|
||||
engine_->SetVolume(volume);
|
||||
volume_ = new_volume;
|
||||
emit VolumeChanged(volume_);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Player::VolumeUp() {
|
||||
@@ -794,8 +810,6 @@ PlaylistItemPtr Player::GetItemAt(const int pos) const {
|
||||
|
||||
void Player::Mute() {
|
||||
|
||||
if (!volume_control_) return;
|
||||
|
||||
const uint current_volume = engine_->volume();
|
||||
|
||||
if (current_volume == 0) {
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QSettings>
|
||||
|
||||
#include "urlhandler.h"
|
||||
#include "engine/engine_fwd.h"
|
||||
@@ -71,6 +70,8 @@ class PlayerInterface : public QObject {
|
||||
|
||||
public slots:
|
||||
virtual void ReloadSettings() = 0;
|
||||
virtual void LoadVolume() = 0;
|
||||
virtual void SaveVolume() = 0;
|
||||
|
||||
// Manual track change to the specified track
|
||||
virtual void PlayAt(const int index, const quint64 offset_nanosec, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle, const bool force_inform = false) = 0;
|
||||
@@ -84,7 +85,8 @@ class PlayerInterface : public QObject {
|
||||
virtual void Next() = 0;
|
||||
virtual void Previous() = 0;
|
||||
virtual void PlayPlaylist(const QString &playlist_name) = 0;
|
||||
virtual void SetVolumeFromValue(const int value) = 0;
|
||||
virtual void SetVolumeFromEngine(const uint volume) = 0;
|
||||
virtual void SetVolumeFromSlider(const int value) = 0;
|
||||
virtual void SetVolume(const uint volume) = 0;
|
||||
virtual void VolumeUp() = 0;
|
||||
virtual void VolumeDown() = 0;
|
||||
@@ -133,7 +135,6 @@ class Player : public PlayerInterface {
|
||||
|
||||
public:
|
||||
explicit Player(Application *app, QObject *parent);
|
||||
~Player() override;
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
@@ -159,6 +160,8 @@ class Player : public PlayerInterface {
|
||||
|
||||
public slots:
|
||||
void ReloadSettings() override;
|
||||
void LoadVolume() override;
|
||||
void SaveVolume() override;
|
||||
|
||||
void PlayAt(const int index, const quint64 offset_nanosec, Engine::TrackChangeFlags change, const Playlist::AutoScroll autoscroll, const bool reshuffle, const bool force_inform = false) override;
|
||||
void PlayPause(const quint64 offset_nanosec = 0, const Playlist::AutoScroll autoscroll = Playlist::AutoScroll_Always) override;
|
||||
@@ -167,8 +170,9 @@ class Player : public PlayerInterface {
|
||||
void Next() override;
|
||||
void Previous() override;
|
||||
void PlayPlaylist(const QString &playlist_name) override;
|
||||
void SetVolumeFromValue(const int value) override;
|
||||
void SetVolume(const uint value) override;
|
||||
void SetVolumeFromSlider(const int value) override;
|
||||
void SetVolumeFromEngine(const uint volume) override;
|
||||
void SetVolume(const uint volume) override;
|
||||
void VolumeUp() override;
|
||||
void VolumeDown() override;
|
||||
void SeekTo(const quint64 seconds) override;
|
||||
@@ -225,8 +229,6 @@ class Player : public PlayerInterface {
|
||||
AnalyzerContainer *analyzer_;
|
||||
Equalizer *equalizer_;
|
||||
|
||||
QSettings settings_;
|
||||
|
||||
PlaylistItemPtr current_item_;
|
||||
|
||||
Engine::TrackChangeFlags stream_change_type_;
|
||||
@@ -237,6 +239,7 @@ class Player : public PlayerInterface {
|
||||
QMap<QString, UrlHandler*> url_handlers_;
|
||||
|
||||
QList<QUrl> loading_async_;
|
||||
uint volume_;
|
||||
uint volume_before_mute_;
|
||||
QDateTime last_pressed_previous_;
|
||||
|
||||
@@ -245,8 +248,6 @@ class Player : public PlayerInterface {
|
||||
BehaviourSettingsPage::PreviousBehaviour menu_previousmode_;
|
||||
int seek_step_sec_;
|
||||
|
||||
bool volume_control_;
|
||||
|
||||
QDateTime pause_time_;
|
||||
quint64 play_offset_nanosec_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user