From b635a9d4a5c1370577d715b2b08f6438b031e8ba Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 31 Aug 2021 00:13:44 +0300 Subject: [PATCH] Changed voice playback speed setting to storage value of speed. --- Telegram/SourceFiles/core/core_settings.cpp | 19 +++++++++++++------ Telegram/SourceFiles/core/core_settings.h | 14 +++++++------- .../media/player/media_player_instance.cpp | 15 +++++++-------- .../media/player/media_player_widget.cpp | 9 +++++---- .../details/storage_settings_scheme.cpp | 4 +++- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index 64aeb2a3f..b7518a788 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -140,7 +140,7 @@ QByteArray Settings::serialize() const { << qint32(_askDownloadPath ? 1 : 0) << _downloadPath.current() << _downloadPathBookmark - << qint32(_voiceMsgPlaybackDoubled ? 1 : 0) + << qint32(0) // Old double voice playback speed. << qint32(_soundNotify ? 1 : 0) << qint32(_desktopNotify ? 1 : 0) << qint32(_flashBounceNotify ? 1 : 0) @@ -219,7 +219,8 @@ QByteArray Settings::serialize() const { << qint32(_hiddenGroupCallTooltips.value()) << qint32(_disableOpenGL ? 1 : 0) << _photoEditorBrush - << qint32(_groupCallNoiseSuppression ? 1 : 0); + << qint32(_groupCallNoiseSuppression ? 1 : 0) + << qint32(_voicePlaybackSpeed * 100); } return result; } @@ -240,7 +241,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 askDownloadPath = _askDownloadPath ? 1 : 0; QString downloadPath = _downloadPath.current(); QByteArray downloadPathBookmark = _downloadPathBookmark; - qint32 voiceMsgPlaybackDoubled = _voiceMsgPlaybackDoubled ? 1 : 0; + qint32 oldVoiceMsgPlaybackDoubled = 0; qint32 soundNotify = _soundNotify ? 1 : 0; qint32 desktopNotify = _desktopNotify ? 1 : 0; qint32 flashBounceNotify = _flashBounceNotify ? 1 : 0; @@ -271,6 +272,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 suggestStickersByEmoji = _suggestStickersByEmoji ? 1 : 0; qint32 spellcheckerEnabled = _spellcheckerEnabled.current() ? 1 : 0; qint32 videoPlaybackSpeed = Core::Settings::SerializePlaybackSpeed(_videoPlaybackSpeed.current()); + qint32 voicePlaybackSpeed = _voicePlaybackSpeed * 100; QByteArray videoPipGeometry = _videoPipGeometry; qint32 dictionariesEnabledCount = 0; std::vector dictionariesEnabled; @@ -312,7 +314,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { >> askDownloadPath >> downloadPath >> downloadPathBookmark - >> voiceMsgPlaybackDoubled + >> oldVoiceMsgPlaybackDoubled >> soundNotify >> desktopNotify >> flashBounceNotify @@ -455,6 +457,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> groupCallNoiseSuppression; } + if (!stream.atEnd()) { + stream >> voicePlaybackSpeed; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); @@ -471,7 +476,6 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _askDownloadPath = (askDownloadPath == 1); _downloadPath = downloadPath; _downloadPathBookmark = downloadPathBookmark; - _voiceMsgPlaybackDoubled = (voiceMsgPlaybackDoubled == 1); _soundNotify = (soundNotify == 1); _desktopNotify = (desktopNotify == 1); _flashBounceNotify = (flashBounceNotify == 1); @@ -525,6 +529,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _suggestStickersByEmoji = (suggestStickersByEmoji == 1); _spellcheckerEnabled = (spellcheckerEnabled == 1); _videoPlaybackSpeed = DeserializePlaybackSpeed(videoPlaybackSpeed); + _voicePlaybackSpeed = oldVoiceMsgPlaybackDoubled + ? 2.0 + : voicePlaybackSpeed / 100.; _videoPipGeometry = (videoPipGeometry); _dictionariesEnabled = std::move(dictionariesEnabled); _autoDownloadDictionaries = (autoDownloadDictionaries == 1); @@ -782,7 +789,6 @@ void Settings::resetOnLastLogout() { _downloadPath = QString(); _downloadPathBookmark = QByteArray(); - _voiceMsgPlaybackDoubled = false; _soundNotify = true; _desktopNotify = true; _flashBounceNotify = true; @@ -826,6 +832,7 @@ void Settings::resetOnLastLogout() { _suggestStickersByEmoji = true; _spellcheckerEnabled = true; _videoPlaybackSpeed = 1.; + _voicePlaybackSpeed = 1.; //_videoPipGeometry = QByteArray(); _dictionariesEnabled = std::vector(); _autoDownloadDictionaries = true; diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 7eac1ff23..89aa33bcc 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -146,12 +146,6 @@ public: void setDownloadPathBookmark(const QByteArray &value) { _downloadPathBookmark = value; } - [[nodiscard]] bool voiceMsgPlaybackDoubled() const { - return _voiceMsgPlaybackDoubled; - } - void setVoiceMsgPlaybackDoubled(bool value) { - _voiceMsgPlaybackDoubled = value; - } [[nodiscard]] bool soundNotify() const { return _soundNotify; } @@ -427,6 +421,12 @@ public: void setVideoPlaybackSpeed(float64 speed) { _videoPlaybackSpeed = speed; } + [[nodiscard]] float64 voicePlaybackSpeed() const { + return _voicePlaybackSpeed; + } + void setVoicePlaybackSpeed(float64 speed) { + _voicePlaybackSpeed = speed; + } [[nodiscard]] QByteArray videoPipGeometry() const { return _videoPipGeometry; } @@ -633,7 +633,6 @@ private: bool _askDownloadPath = false; rpl::variable _downloadPath; QByteArray _downloadPathBookmark; - bool _voiceMsgPlaybackDoubled = false; bool _soundNotify = true; bool _desktopNotify = true; bool _flashBounceNotify = true; @@ -670,6 +669,7 @@ private: bool _suggestStickersByEmoji = true; rpl::variable _spellcheckerEnabled = true; rpl::variable _videoPlaybackSpeed = 1.; + float64 _voicePlaybackSpeed = 1.; QByteArray _videoPipGeometry; rpl::variable> _dictionariesEnabled; rpl::variable _autoDownloadDictionaries = true; diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index 0b55be131..86437fb22 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -36,8 +36,6 @@ namespace { Instance *SingleInstance = nullptr; -constexpr auto kVoicePlaybackSpeedMultiplier = 1.7; - // Preload X message ids before and after current. constexpr auto kIdsLimit = 32; @@ -46,6 +44,10 @@ constexpr auto kIdsPreloadAfter = 28; constexpr auto kMinLengthForSavePosition = 20 * TimeId(60); // 20 minutes. +auto VoicePlaybackSpeed() { + return std::clamp(Core::App().settings().voicePlaybackSpeed(), 0.6, 1.7); +} + } // namespace struct Instance::Streamed { @@ -518,9 +520,8 @@ Streaming::PlaybackOptions Instance::streamingOptions( ? Streaming::Mode::Both : Streaming::Mode::Audio; result.speed = (document - && (document->isVoiceMessage() || document->isVideoMessage()) - && Core::App().settings().voiceMsgPlaybackDoubled()) - ? kVoicePlaybackSpeedMultiplier + && (document->isVoiceMessage() || document->isVideoMessage())) + ? VoicePlaybackSpeed() : 1.; result.audioId = audioId; if (position >= 0) { @@ -678,9 +679,7 @@ void Instance::cancelSeeking(AudioMsgId::Type type) { void Instance::updateVoicePlaybackSpeed() { if (const auto data = getData(AudioMsgId::Type::Voice)) { if (const auto streamed = data->streamed.get()) { - streamed->instance.setSpeed(Core::App().settings().voiceMsgPlaybackDoubled() - ? kVoicePlaybackSpeedMultiplier - : 1.); + streamed->instance.setSpeed(VoicePlaybackSpeed()); } } } diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index d3518fa39..1ba44ca21 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -148,8 +148,9 @@ Widget::Widget(QWidget *parent, not_null session) updatePlaybackSpeedIcon(); _playbackSpeed->setClickedCallback([=] { - const auto doubled = !Core::App().settings().voiceMsgPlaybackDoubled(); - Core::App().settings().setVoiceMsgPlaybackDoubled(doubled); + const auto doubled = (Core::App().settings().voicePlaybackSpeed() + == 2.); + Core::App().settings().setVoicePlaybackSpeed(doubled ? 1. : 2.); instance()->updateVoicePlaybackSpeed(); updatePlaybackSpeedIcon(); Core::App().saveSettingsDelayed(); @@ -396,8 +397,8 @@ void Widget::updateRepeatTrackIcon() { } void Widget::updatePlaybackSpeedIcon() { - const auto doubled = Core::App().settings().voiceMsgPlaybackDoubled(); - const auto isDefaultSpeed = !doubled; + const auto speed = Core::App().settings().voicePlaybackSpeed(); + const auto isDefaultSpeed = (speed == 1.); _playbackSpeed->setIconOverride( isDefaultSpeed ? &st::mediaPlayerSpeedDisabledIcon : nullptr, isDefaultSpeed ? &st::mediaPlayerSpeedDisabledIconOver : nullptr); diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index 4b0bde363..845749767 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -1112,7 +1112,9 @@ bool ReadSetting( stream >> v; if (!CheckStreamStatus(stream)) return false; - Core::App().settings().setVoiceMsgPlaybackDoubled(v == 2); + if (v == 2) { + Core::App().settings().setVoicePlaybackSpeed(2.); + } context.legacyRead = true; } break;