Settings work
This commit is contained in:
48
src/frontend/AudioSettings.cpp
Normal file
48
src/frontend/AudioSettings.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <AudioSettings.hpp>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
AudioSettings::AudioSettings(nlohmann::json& settings) : settings(settings), QWidget(nullptr) {
|
||||
lockChannels->setChecked(JSONGetField<bool>(settings, "audio", "lock"));
|
||||
volumeL->setValue(JSONGetField<float>(settings, "audio", "volumeL") * 100);
|
||||
volumeR->setValue(JSONGetField<float>(settings, "audio", "volumeR") * 100);
|
||||
volumeL->setRange(0, 100);
|
||||
volumeR->setRange(0, 100);
|
||||
|
||||
connect(lockChannels, &QCheckBox::stateChanged, this, [&]() {
|
||||
JSONSetField(settings, "audio", "lock", lockChannels->isChecked());
|
||||
emit modified();
|
||||
});
|
||||
|
||||
connect(volumeL, &QSlider::valueChanged, this, [&]() {
|
||||
JSONSetField(settings, "audio", "volumeL", float(volumeL->value()) / 100.f);
|
||||
if (lockChannels->isChecked()) {
|
||||
volumeR->setValue(volumeL->value());
|
||||
JSONSetField(settings, "audio", "volumeR", float(volumeL->value()) / 100.f);
|
||||
}
|
||||
emit modified();
|
||||
});
|
||||
|
||||
connect(volumeR, &QSlider::valueChanged, this, [&]() {
|
||||
if (!lockChannels->isChecked()) {
|
||||
JSONSetField(settings, "audio", "volumeR", float(volumeR->value()) / 100.f);
|
||||
}
|
||||
emit modified();
|
||||
});
|
||||
|
||||
QLabel* labelLock = new QLabel("Lock channels:");
|
||||
QLabel* labelL = new QLabel("Volume L");
|
||||
QLabel* labelR = new QLabel("Volume R");
|
||||
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||
QHBoxLayout* volLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(labelLock);
|
||||
mainLayout->addWidget(lockChannels);
|
||||
volLayout->addWidget(labelL);
|
||||
volLayout->addWidget(volumeL);
|
||||
volLayout->addWidget(labelR);
|
||||
volLayout->addWidget(volumeR);
|
||||
mainLayout->addLayout(volLayout);
|
||||
mainLayout->addStretch();
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
16
src/frontend/AudioSettings.hpp
Normal file
16
src/frontend/AudioSettings.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QSlider>
|
||||
#include <QCheckBox>
|
||||
#include <JSONUtils.hpp>
|
||||
|
||||
class AudioSettings : public QWidget {
|
||||
QCheckBox* lockChannels = new QCheckBox;
|
||||
Q_OBJECT
|
||||
public:
|
||||
QSlider* volumeL = new QSlider(Qt::Horizontal), * volumeR = new QSlider(Qt::Horizontal);
|
||||
AudioSettings(nlohmann::json&);
|
||||
nlohmann::json& settings;
|
||||
Q_SIGNALS:
|
||||
void modified();
|
||||
};
|
||||
@@ -64,7 +64,9 @@ add_executable(kaizen-qt
|
||||
SettingsWindow.cpp
|
||||
CPUSettings.hpp
|
||||
CPUSettings.cpp
|
||||
JSONUtils.hpp)
|
||||
JSONUtils.hpp
|
||||
AudioSettings.hpp
|
||||
AudioSettings.cpp)
|
||||
|
||||
target_link_libraries(kaizen-qt PUBLIC Qt6::Core Qt6::Gui Qt6::Widgets fmt mio nlohmann_json nfd parallel-rdp backend)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ EmuThread::EmuThread(std::unique_ptr<QtInstanceFactory>&& instance, std::unique_
|
||||
n64::InitAudio();
|
||||
while (true) {
|
||||
if (!core->pause) {
|
||||
core->Run(0.5, 0.5);
|
||||
core->Run(settings->getVolumeL(), settings->getVolumeR());
|
||||
if(core->render) {
|
||||
UpdateScreenParallelRdp(core->cpu->mem.mmio.vi);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <QThread>
|
||||
#include <Core.hpp>
|
||||
#include <SettingsWindow.hpp>
|
||||
|
||||
struct QtInstanceFactory;
|
||||
struct ParallelRdpWindowInfo;
|
||||
@@ -20,6 +21,7 @@ public:
|
||||
[[noreturn]] void run() noexcept override;
|
||||
|
||||
n64::Core* core;
|
||||
SettingsWindow* settings;
|
||||
bool running = false;
|
||||
|
||||
void TogglePause()
|
||||
|
||||
@@ -16,8 +16,10 @@ static inline nlohmann::json JSONOpenOrCreate(const std::string& path) {
|
||||
} else {
|
||||
auto file = std::fstream(path, std::fstream::in | std::fstream::out | std::fstream::trunc);
|
||||
nlohmann::json json;
|
||||
json["audio"]["volume"] = 0.5;
|
||||
json["cpu"]["type"] = std::string("interpreter");
|
||||
json["audio"]["volumeL"] = 0.5;
|
||||
json["audio"]["volumeR"] = 0.5;
|
||||
json["audio"]["lock"] = true;
|
||||
json["cpu"]["type"] = "interpreter";
|
||||
|
||||
file << json;
|
||||
file.close();
|
||||
@@ -32,6 +34,6 @@ static inline void JSONSetField(nlohmann::json& json, const std::string& field1,
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline const T& JSONGetField(nlohmann::json& json, const std::string& field1, const std::string& field2) {
|
||||
return json[field1][field2];
|
||||
static inline T JSONGetField(nlohmann::json& json, const std::string& field1, const std::string& field2) {
|
||||
return json[field1][field2].get<T>();
|
||||
}
|
||||
@@ -22,6 +22,7 @@ KaizenQt::KaizenQt() noexcept : QWidget(nullptr) {
|
||||
settingsWindow = new SettingsWindow;
|
||||
settingsWindow->hide();
|
||||
emuThread->core = new n64::Core();
|
||||
emuThread->settings = settingsWindow;
|
||||
}
|
||||
|
||||
void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept {
|
||||
|
||||
@@ -13,10 +13,11 @@ SettingsWindow::SettingsWindow() : QWidget(nullptr) {
|
||||
setWindowTitle("Settings");
|
||||
|
||||
cpuSettings = new CPUSettings(settings);
|
||||
audioSettings = new AudioSettings(settings);
|
||||
|
||||
auto* tabs = new QTabWidget;
|
||||
tabs->addTab(cpuSettings, tr("CPU"));
|
||||
//tabs->addTab(new PermissionsTab, tr("Audio"));
|
||||
tabs->addTab(audioSettings, tr("Audio"));
|
||||
|
||||
apply->setEnabled(false);
|
||||
|
||||
@@ -24,6 +25,10 @@ SettingsWindow::SettingsWindow() : QWidget(nullptr) {
|
||||
apply->setEnabled(true);
|
||||
});
|
||||
|
||||
connect(audioSettings, &AudioSettings::modified, this, [&]() {
|
||||
apply->setEnabled(true);
|
||||
});
|
||||
|
||||
connect(apply, &QPushButton::pressed, this, [&]() {
|
||||
apply->setEnabled(false);
|
||||
std::ofstream file("resources/settings.json");
|
||||
|
||||
@@ -3,13 +3,17 @@
|
||||
#include <QTabWidget>
|
||||
#include <QPushButton>
|
||||
#include <CPUSettings.hpp>
|
||||
#include <AudioSettings.hpp>
|
||||
|
||||
class SettingsWindow : public QWidget {
|
||||
QPushButton* cancel = new QPushButton("Cancel");
|
||||
QPushButton* apply = new QPushButton("Apply");
|
||||
Q_OBJECT
|
||||
public:
|
||||
float getVolumeL() { return float(audioSettings->volumeL->value()) / 100.f; }
|
||||
float getVolumeR() { return float(audioSettings->volumeR->value()) / 100.f; }
|
||||
SettingsWindow();
|
||||
nlohmann::json settings;
|
||||
CPUSettings* cpuSettings;
|
||||
AudioSettings* audioSettings;
|
||||
};
|
||||
Reference in New Issue
Block a user