diff --git a/CMakeSettings.json b/CMakeSettings.json index bb522fcfc..c2bdcdd58 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -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" ], diff --git a/src/common/config.cpp b/src/common/config.cpp index 4a8effbdf..0d9ff093d 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -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(general, "isPS4Pro", false); isFullscreen = toml::find_or(general, "Fullscreen", false); playBGM = toml::find_or(general, "playBGM", false); + BGMvolume = toml::find_or(general, "BGMvolume", 50); logFilter = toml::find_or(general, "logFilter", ""); logType = toml::find_or(general, "logType", "sync"); userName = toml::find_or(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 = ""; diff --git a/src/common/config.h b/src/common/config.h index f2b5187f8..eeeff0b2e 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -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); diff --git a/src/qt_gui/background_music_player.cpp b/src/qt_gui/background_music_player.cpp index 37d877098..a40c5bfae 100644 --- a/src/qt_gui/background_music_player.cpp +++ b/src/qt_gui/background_music_player.cpp @@ -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(); diff --git a/src/qt_gui/background_music_player.h b/src/qt_gui/background_music_player.h index 52f44f431..6d70fe68c 100644 --- a/src/qt_gui/background_music_player.h +++ b/src/qt_gui/background_music_player.h @@ -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; -}; \ No newline at end of file +}; diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 759c6992e..18cbdac56 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -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 { diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index e02aeed9e..ea4a45738 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -142,6 +142,11 @@ SettingsDialog::SettingsDialog(std::span 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); -} \ No newline at end of file +} diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index ca71d5ca4..053949f53 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -1,6 +1,4 @@ - SettingsDialog @@ -52,7 +50,7 @@ 0 0 836 - 442 + 446 @@ -369,7 +367,7 @@ 10 30 241 - 41 + 71 @@ -386,6 +384,55 @@ + + + + + + + + Volume + + + + + + + Set the volume of the background music. + + + 100 + + + 10 + + + 20 + + + 50 + + + Qt::Orientation::Horizontal + + + false + + + false + + + QSlider::TickPosition::NoTicks + + + 10 + + + + + + +