Commit 817621f7 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

use a logarithmic scale for the volume in user interfaces

require Qt 5.8

uses a logarithmic scale for the volume in the user interface and
convert when needed in a linear scale for use by Qt APIs
parent 03c58d69
......@@ -5,7 +5,7 @@ project(elisa)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 14)
set(REQUIRED_QT_VERSION "5.7.0")
set(REQUIRED_QT_VERSION "5.8.0")
find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Network Xml Qml Sql Multimedia Svg Gui)
find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG QUIET OPTIONAL_COMPONENTS Quick Widgets Test DBus WebSockets AndroidExtras)
......
......@@ -339,8 +339,8 @@ Item {
Slider {
id: volumeSlider
minimumValue: 0.0
maximumValue: 1.0
minimumValue: 0
maximumValue: 100
value: musicWidget.volume
onValueChanged: musicWidget.volume = value
......
......@@ -137,9 +137,9 @@ ApplicationWindow {
muted: headerBar.playerControl.muted
volume: headerBar.playerControl.volume * 100
volume: headerBar.playerControl.volume
onVolumeChanged: headerBar.playerControl.volume = volume / 100.0
onVolumeChanged: headerBar.playerControl.volume = volume
onMutedChanged: headerBar.playerControl.muted = muted
source: manageAudioPlayer.playerSource
......
......@@ -20,6 +20,7 @@
#include "audiowrapper.h"
#include <QTimer>
#include <QAudio>
#include "config-upnp-qt.h"
......@@ -55,9 +56,13 @@ bool AudioWrapper::muted() const
return d->mPlayer.isMuted();
}
int AudioWrapper::volume() const
qreal AudioWrapper::volume() const
{
return d->mPlayer.volume();
auto realVolume = static_cast<qreal>(d->mPlayer.volume() / 100.0);
auto userVolume = static_cast<qreal>(QAudio::convertVolume(realVolume, QAudio::LinearVolumeScale, QAudio::LogarithmicVolumeScale));
auto decibelVolume = static_cast<qreal>(QAudio::convertVolume(realVolume, QAudio::LinearVolumeScale, QAudio::DecibelVolumeScale));
return userVolume * 100.0;
}
QUrl AudioWrapper::source() const
......@@ -105,9 +110,11 @@ void AudioWrapper::setMuted(bool muted)
d->mPlayer.setMuted(muted);
}
void AudioWrapper::setVolume(int volume)
void AudioWrapper::setVolume(qreal volume)
{
d->mPlayer.setVolume(volume);
auto realVolume = static_cast<qreal>(QAudio::convertVolume(volume / 100.0, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale));
auto decibelVolume = static_cast<qreal>(QAudio::convertVolume(realVolume, QAudio::LinearVolumeScale, QAudio::DecibelVolumeScale));
d->mPlayer.setVolume(qRound(realVolume * 100));
}
void AudioWrapper::setSource(const QUrl &source)
......
......@@ -38,7 +38,7 @@ class AudioWrapper : public QObject
WRITE setMuted
NOTIFY mutedChanged)
Q_PROPERTY(int volume
Q_PROPERTY(qreal volume
READ volume
WRITE setVolume
NOTIFY volumeChanged)
......@@ -86,7 +86,7 @@ public:
bool muted() const;
int volume() const;
qreal volume() const;
QUrl source() const;
......@@ -136,7 +136,7 @@ public Q_SLOTS:
void setMuted(bool muted);
void setVolume(int volume);
void setVolume(qreal volume);
void setSource(const QUrl &source);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment