add volume slider

This commit is contained in:
tGecko 2024-09-28 17:21:40 +02:00
parent bc6c0de76d
commit c073b63b98
8 changed files with 90 additions and 10 deletions

View file

@ -18,11 +18,11 @@
"configurationType": "Debug",
"buildRoot": "${projectDir}\\Build\\${name}",
"installRoot": "${projectDir}\\Install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64_x64" ],
"intelliSenseMode": "windows-clang-x64"
"intelliSenseMode": "windows-clang-x64",
"cmakeCommandArgs": "-DENABLE_QT_GUI=ON -DCMAKE_PREFIX_PATH=C:\\Qt\\6.7.2\\msvc2019_64"
},
{
"name": "x64-Clang-RelWithDebInfo",
@ -30,7 +30,7 @@
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\Build\\${name}",
"installRoot": "${projectDir}\\Install\\${name}",
"cmakeCommandArgs": "",
"cmakeCommandArgs": "-DENABLE_QT_GUI=ON -DCMAKE_PREFIX_PATH=C:\\Qt\\6.7.2\\msvc2019_64",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "clang_cl_x64_x64" ],

View file

@ -32,6 +32,7 @@ namespace Config {
static bool isNeo = false;
static bool isFullscreen = false;
static bool playBGM = false;
static int BGMvolume = 50;
static u32 screenWidth = 1280;
static u32 screenHeight = 720;
static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
@ -89,6 +90,10 @@ bool getPlayBGM() {
return playBGM;
}
int getBGMvolume() {
return BGMvolume;
}
u32 getScreenWidth() {
return screenWidth;
}
@ -249,6 +254,10 @@ void setPlayBGM(bool enable) {
playBGM = enable;
}
void setBGMvolume(int volume) {
BGMvolume = volume;
}
void setLanguage(u32 language) {
m_language = language;
}
@ -412,6 +421,7 @@ void load(const std::filesystem::path& path) {
isNeo = toml::find_or<bool>(general, "isPS4Pro", false);
isFullscreen = toml::find_or<bool>(general, "Fullscreen", false);
playBGM = toml::find_or<bool>(general, "playBGM", false);
BGMvolume = toml::find_or<int>(general, "BGMvolume", 50);
logFilter = toml::find_or<std::string>(general, "logFilter", "");
logType = toml::find_or<std::string>(general, "logType", "sync");
userName = toml::find_or<std::string>(general, "userName", "shadPS4");
@ -513,6 +523,7 @@ void save(const std::filesystem::path& path) {
data["General"]["isPS4Pro"] = isNeo;
data["General"]["Fullscreen"] = isFullscreen;
data["General"]["playBGM"] = playBGM;
data["General"]["BGMvolume"] = BGMvolume;
data["General"]["logFilter"] = logFilter;
data["General"]["logType"] = logType;
data["General"]["userName"] = userName;
@ -565,6 +576,7 @@ void setDefaultValues() {
isNeo = false;
isFullscreen = false;
playBGM = false;
BGMvolume = 50;
screenWidth = 1280;
screenHeight = 720;
logFilter = "";

View file

@ -14,6 +14,8 @@ void save(const std::filesystem::path& path);
bool isNeoMode();
bool isFullscreenMode();
bool getPlayBGM();
int getBGMvolume();
std::string getLogFilter();
std::string getLogType();
std::string getUserName();
@ -49,6 +51,7 @@ void setScreenWidth(u32 width);
void setScreenHeight(u32 height);
void setFullscreenMode(bool enable);
void setPlayBGM(bool enable);
void setBGMvolume(int volume);
void setLanguage(u32 language);
void setNeoMode(bool enable);
void setUserName(const std::string& type);

View file

@ -10,6 +10,12 @@ BackgroundMusicPlayer::BackgroundMusicPlayer(QObject* parent) : QObject(parent)
m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
}
void BackgroundMusicPlayer::setVolume(int volume) {
float linearVolume = QAudio::convertVolume(volume / 100.0f, QAudio::LogarithmicVolumeScale,
QAudio::LinearVolumeScale);
m_audioOutput->setVolume(linearVolume);
}
void BackgroundMusicPlayer::playMusic(const QString& snd0path) {
if (snd0path.isEmpty()) {
stopMusic();

View file

@ -16,6 +16,7 @@ public:
return instance;
}
void setVolume(int volume);
void playMusic(const QString& snd0path);
void stopMusic();
@ -25,4 +26,4 @@ private:
QMediaPlayer* m_mediaPlayer;
QAudioOutput* m_audioOutput;
QUrl m_currentMusic;
};
};

View file

@ -527,7 +527,11 @@ void MainWindow::PlayBackgroundMusic() {
int itemID = isTableList ? m_game_list_frame->currentItem()->row()
: m_game_grid_frame->crtRow * m_game_grid_frame->columnCnt +
m_game_grid_frame->crtColumn;
if (itemID > m_game_info->m_games.size() - 1) {
// Can happen in grid mode
BackgroundMusicPlayer::getInstance().stopMusic();
return;
}
QString snd0path;
Common::FS::PathToQString(snd0path, m_game_info->m_games[itemID].snd0_path);
BackgroundMusicPlayer::getInstance().playMusic(snd0path);
@ -619,6 +623,7 @@ void MainWindow::ConfigureGuiFromSettings() {
} else {
ui->setlistModeGridAct->setChecked(true);
}
BackgroundMusicPlayer::getInstance().setVolume(Config::getBGMvolume());
}
void MainWindow::SaveWindowState() const {

View file

@ -142,6 +142,11 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
connect(ui->playBGMCheckBox, &QCheckBox::stateChanged, this,
[](int val) { Config::setPlayBGM(val); });
connect(ui->BGMVolumeSlider, &QSlider::valueChanged, this,
[](float val) { Config::setBGMvolume(val); });
connect(ui->BGMVolumeSlider, &QSlider::valueChanged, this,
[](float val) { BackgroundMusicPlayer::getInstance().setVolume(val); });
}
// GPU TAB
@ -231,6 +236,7 @@ void SettingsDialog::LoadValuesFromConfig() {
ui->nullGpuCheckBox->setChecked(Config::nullGpu());
ui->dumpPM4CheckBox->setChecked(Config::dumpPM4());
ui->playBGMCheckBox->setChecked(Config::getPlayBGM());
ui->BGMVolumeSlider->setValue((Config::getBGMvolume()));
ui->fullscreenCheckBox->setChecked(Config::isFullscreenMode());
ui->showSplashCheckBox->setChecked(Config::showSplash());
ui->ps4proCheckBox->setChecked(Config::isNeoMode());
@ -371,4 +377,4 @@ bool SettingsDialog::eventFilter(QObject* obj, QEvent* event) {
}
}
return QDialog::eventFilter(obj, event);
}
}

View file

@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
SPDX-License-Identifier: GPL-2.0-or-later -->
<ui version="4.0">
<class>SettingsDialog</class>
<widget class="QDialog" name="SettingsDialog">
@ -52,7 +50,7 @@
<x>0</x>
<y>0</y>
<width>836</width>
<height>442</height>
<height>446</height>
</rect>
</property>
<property name="sizePolicy">
@ -369,7 +367,7 @@
<x>10</x>
<y>30</y>
<width>241</width>
<height>41</height>
<height>71</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -386,6 +384,55 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Volume</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="BGMVolumeSlider">
<property name="toolTip">
<string>Set the volume of the background music.</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="pageStep">
<number>20</number>
</property>
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="invertedControls">
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::TickPosition::NoTicks</enum>
</property>
<property name="tickInterval">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>