Skip to content

Commit

Permalink
Pimpl most of the settings in GlobalSettingsPanel to reduce header po…
Browse files Browse the repository at this point in the history
…llution.
  • Loading branch information
Mysticial committed Dec 9, 2024
1 parent 24dfe75 commit d2eeda9
Show file tree
Hide file tree
Showing 60 changed files with 468 additions and 267 deletions.
3 changes: 3 additions & 0 deletions Common/Cpp/Containers/Pimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Pimpl{
public:
operator bool() const{ return m_ptr != nullptr; }

operator const Type&() const{ return *m_ptr; }
operator Type&() { return *m_ptr; }

const Type& operator*() const { return *m_ptr; }
Type& operator*() { return *m_ptr; }

Expand Down
7 changes: 5 additions & 2 deletions Common/Qt/Options/GroupWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ GroupWidget::GroupWidget(QWidget& parent, GroupOption& value)
}

if (value.restore_defaults_button_enabled()){
m_options.back()->widget().setContentsMargins(5, 5, 5, 5);
m_restore_defaults_button = new QPushButton("Restore Defaults", this);
m_options_layout->addWidget(m_restore_defaults_button);
m_restore_defaults_button->setContentsMargins(5, 5, 5, 5);
QHBoxLayout* row = new QHBoxLayout();
m_options_layout->addLayout(row);
row->addWidget(m_restore_defaults_button, 1);
row->addStretch(3);
connect(
m_restore_defaults_button, &QPushButton::clicked,
this, [this](bool on){
Expand Down
3 changes: 3 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ file(GLOB MAIN_SOURCES
Source/CommonFramework/AudioPipeline/AudioOption.cpp
Source/CommonFramework/AudioPipeline/AudioOption.h
Source/CommonFramework/AudioPipeline/AudioPassthroughPair.h
Source/CommonFramework/AudioPipeline/AudioPipelineOptions.h
Source/CommonFramework/AudioPipeline/AudioSession.cpp
Source/CommonFramework/AudioPipeline/AudioSession.h
Source/CommonFramework/AudioPipeline/AudioStream.cpp
Expand Down Expand Up @@ -460,6 +461,7 @@ file(GLOB MAIN_SOURCES
Source/CommonFramework/OCR/OCR_TextMatcher.h
Source/CommonFramework/OCR/OCR_TrainingTools.cpp
Source/CommonFramework/OCR/OCR_TrainingTools.h
Source/CommonFramework/Options/Environment/PerformanceOptions.h
Source/CommonFramework/Options/Environment/ProcessPriorityOption.h
Source/CommonFramework/Options/Environment/ProcessorLevelOption.cpp
Source/CommonFramework/Options/Environment/ProcessorLevelOption.h
Expand Down Expand Up @@ -589,6 +591,7 @@ file(GLOB MAIN_SOURCES
Source/CommonFramework/VideoPipeline/VideoOverlaySession.h
Source/CommonFramework/VideoPipeline/VideoOverlayTypes.cpp
Source/CommonFramework/VideoPipeline/VideoOverlayTypes.h
Source/CommonFramework/VideoPipeline/VideoPipelineOptions.h
Source/CommonFramework/Windows/ButtonDiagram.cpp
Source/CommonFramework/Windows/ButtonDiagram.h
Source/CommonFramework/Windows/DpiScaler.cpp
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ HEADERS += \
Source/CommonFramework/AudioPipeline/AudioInfo.h \
Source/CommonFramework/AudioPipeline/AudioOption.h \
Source/CommonFramework/AudioPipeline/AudioPassthroughPair.h \
Source/CommonFramework/AudioPipeline/AudioPipelineOptions.h \
Source/CommonFramework/AudioPipeline/AudioSession.h \
Source/CommonFramework/AudioPipeline/AudioStream.h \
Source/CommonFramework/AudioPipeline/AudioTemplate.h \
Expand Down Expand Up @@ -1341,6 +1342,7 @@ HEADERS += \
Source/CommonFramework/OCR/OCR_StringNormalization.h \
Source/CommonFramework/OCR/OCR_TextMatcher.h \
Source/CommonFramework/OCR/OCR_TrainingTools.h \
Source/CommonFramework/Options/Environment/PerformanceOptions.h \
Source/CommonFramework/Options/Environment/ProcessPriorityOption.h \
Source/CommonFramework/Options/Environment/ProcessorLevelOption.h \
Source/CommonFramework/Options/Environment/SleepSuppressOption.h \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
#include <map>
#include <QtGlobal>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/Time.h"
#include "Common/Cpp/PrettyPrint.h"
#include "Common/Cpp/Containers/Pimpl.tpp"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Logging/Logger.h"
#include "CommonFramework/AudioPipeline/AudioPipelineOptions.h"
#include "AudioInfo.h"

#include <iostream>
using std::cout;
using std::endl;
//#include <iostream>
//using std::cout;
//using std::endl;


#if QT_VERSION_MAJOR == 5
Expand Down Expand Up @@ -312,7 +315,8 @@ std::vector<AudioDeviceInfo> AudioDeviceInfo::all_input_devices(){
double seconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000.;
global_logger_tagged().log("Done querying audio inputs... " + tostr_fixed(seconds, 3) + " seconds", COLOR_CYAN);

if (GlobalSettings::instance().SHOW_ALL_AUDIO_DEVICES){
bool show_all_devices = GlobalSettings::instance().AUDIO_PIPELINE->SHOW_ALL_DEVICES;
if (show_all_devices){
return list;
}

Expand All @@ -335,7 +339,7 @@ std::vector<AudioDeviceInfo> AudioDeviceInfo::all_input_devices(){
if (device.preferred_format_index() >= 0){
current_score += 100;
}
if (current_score >= best_score || GlobalSettings::instance().SHOW_ALL_AUDIO_DEVICES){
if (current_score >= best_score || show_all_devices){
ret.emplace_back(std::move(device));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* Audio Pipeline Options
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#ifndef PokemonAutomation_AudioPipeline_AudioPipelineOptions_H
#define PokemonAutomation_AudioPipeline_AudioPipelineOptions_H

#include "Common/Cpp/Options/GroupOption.h"
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "Common/Cpp/Options/FloatingPointOption.h"
#include "CommonFramework/GlobalSettingsPanel.h"

namespace PokemonAutomation{


class AudioPipelineOptions : public GroupOption{
public:
AudioPipelineOptions()
: GroupOption(
"Audio Pipeline",
LockMode::LOCK_WHILE_RUNNING,
GroupOption::EnableMode::ALWAYS_ENABLED, true
)
, FILE_VOLUME_SCALE(
"<b>Audio File Input Volume Scale:</b><br>"
"Multiply audio file playback by this factor. (This is linear scale. So each factor of 10 is 20dB.)",
LockMode::UNLOCK_WHILE_RUNNING,
0.31622776601683793320, // -10dB
-10000, 10000
)
, DEVICE_VOLUME_SCALE(
"<b>Audio Device Input Volume Scale:</b><br>"
"Multiply audio device input by this factor. (This is linear scale. So each factor of 10 is 20dB.)",
LockMode::UNLOCK_WHILE_RUNNING,
1.0, -10000, 10000
)
, SHOW_ALL_DEVICES(
"<b>Show all Audio Devices:</b><br>"
"Show all audio devices - including duplicates.",
LockMode::UNLOCK_WHILE_RUNNING,
false
)
, SHOW_RECORD_FREQUENCIES(
"<b>Show Record Frequencies:</b><br>"
"Show option to record audio frequencies.",
LockMode::UNLOCK_WHILE_RUNNING,
false
)
, AUTO_RESET_SECONDS(
"<b>Audio Auto-Reset:</b><br>"
"Attempt to reset the audio if this many seconds has elapsed since the last audio frame (in order to fix issues with RDP disconnection, etc).",
LockMode::UNLOCK_WHILE_RUNNING,
5
)
{
PA_ADD_OPTION(FILE_VOLUME_SCALE);
PA_ADD_OPTION(DEVICE_VOLUME_SCALE);
PA_ADD_OPTION(SHOW_ALL_DEVICES);
if (PreloadSettings::instance().DEVELOPER_MODE){
PA_ADD_OPTION(SHOW_RECORD_FREQUENCIES);
}
PA_ADD_OPTION(AUTO_RESET_SECONDS);
}

public:
FloatingPointOption FILE_VOLUME_SCALE;
FloatingPointOption DEVICE_VOLUME_SCALE;
BooleanCheckBoxOption SHOW_ALL_DEVICES;
BooleanCheckBoxOption SHOW_RECORD_FREQUENCIES;
SimpleIntegerOption<uint8_t> AUTO_RESET_SECONDS;
};



}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "CommonFramework/GlobalServices.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "Backends/AudioPassthroughPairQtThread.h"
#include "AudioPipelineOptions.h"
#include "AudioSession.h"

//#include <iostream>
Expand Down Expand Up @@ -52,7 +53,7 @@ AudioSession::AudioSession(Logger& logger, AudioOption& option)
AudioSession::reset();
m_devices->add_listener(*this);

uint8_t watchdog_timeout = GlobalSettings::instance().AUTO_RESET_AUDIO_SECONDS;
uint8_t watchdog_timeout = GlobalSettings::instance().AUDIO_PIPELINE->AUTO_RESET_SECONDS;
if (watchdog_timeout != 0){
global_watchdog().add(*this, std::chrono::seconds(watchdog_timeout));
}
Expand Down Expand Up @@ -292,7 +293,7 @@ void AudioSession::on_watchdog_timeout(){
return;
}

uint8_t watchdog_timeout = GlobalSettings::instance().AUTO_RESET_AUDIO_SECONDS;
uint8_t watchdog_timeout = GlobalSettings::instance().AUDIO_PIPELINE->AUTO_RESET_SECONDS;
m_logger.log("No audio detected for " + std::to_string(watchdog_timeout) + " seconds...", COLOR_RED);

if (watchdog_timeout == 0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
*/

//#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/AbstractLogger.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/AudioPipeline/AudioPipelineOptions.h"
//#include "CommonFramework/AudioPipeline/AudioConstants.h"
//#include "CommonFramework/AudioPipeline/Tools/AudioFormatUtils.h"
#include "CommonFramework/AudioPipeline/IO/AudioSource.h"
#include "CommonFramework/AudioPipeline/IO/AudioSink.h"
#include "CommonFramework/AudioPipeline/Spectrum/FFTStreamer.h"
#include "AudioPassthroughPairQt.h"

#include <iostream>
using std::cout;
using std::endl;
//#include <iostream>
//using std::cout;
//using std::endl;

namespace PokemonAutomation{

Expand Down Expand Up @@ -99,8 +101,8 @@ AudioPassthroughPairQt::~AudioPassthroughPairQt(){}

AudioPassthroughPairQt::AudioPassthroughPairQt(Logger& logger)
: m_logger(logger)
, m_file_input_multiplier((float)GlobalSettings::instance().AUDIO_FILE_VOLUME_SCALE)
, m_device_input_multiplier((float)GlobalSettings::instance().AUDIO_DEVICE_VOLUME_SCALE)
, m_file_input_multiplier((float)GlobalSettings::instance().AUDIO_PIPELINE->FILE_VOLUME_SCALE)
, m_device_input_multiplier((float)GlobalSettings::instance().AUDIO_PIPELINE->DEVICE_VOLUME_SCALE)
{}

void AudioPassthroughPairQt::reset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "Common/Cpp/Concurrency/SpinPause.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Options/Environment/PerformanceOptions.h"
#include "AudioPassthroughPairQt.h"
#include "AudioPassthroughPairQtThread.h"

Expand Down Expand Up @@ -51,7 +52,7 @@ AudioPassthroughPairQtThread::~AudioPassthroughPairQtThread(){
wait();
}
void AudioPassthroughPairQtThread::run(){
GlobalSettings::instance().REALTIME_THREAD_PRIORITY0.set_on_this_thread();
GlobalSettings::instance().PERFORMANCE->REALTIME_THREAD_PRIORITY.set_on_this_thread();

AudioPassthroughPairQt body(m_logger);
m_body.store(&body, std::memory_order_relaxed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ using NativeAudioSource = QAudioSource;
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/PrettyPrint.h"
#include "Common/Cpp/Time.h"
#include "Common/Cpp/StreamConverters.h"
//#include "Common/Cpp/StreamConverters.h"
#include "CommonFramework/AudioPipeline/AudioStream.h"
#include "CommonFramework/AudioPipeline/Tools/AudioFormatUtils.h"
#include "AudioFileLoader.h"
#include "AudioSource.h"

#include <iostream>
using std::cout;
using std::endl;
//#include <iostream>
//using std::cout;
//using std::endl;

namespace PokemonAutomation{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QFileDialog>
#include "Common/Qt/NoWheelComboBox.h"
#include "CommonFramework/AudioPipeline/AudioSession.h"
#include "CommonFramework/AudioPipeline/AudioPipelineOptions.h"
#include "AudioDisplayWidget.h"
#include "AudioSelectorWidget.h"
#include "CommonFramework/GlobalSettingsPanel.h"
Expand Down Expand Up @@ -80,7 +81,7 @@ AudioSelectorWidget::AudioSelectorWidget(

QHBoxLayout* output_layout = new QHBoxLayout();
row1->addLayout(output_layout, 10);
if (GlobalSettings::instance().SHOW_RECORD_FREQUENCIES){
if (GlobalSettings::instance().AUDIO_PIPELINE->SHOW_RECORD_FREQUENCIES){
m_audio_output_box = new NoWheelComboBox(this);
output_layout->addWidget(m_audio_output_box, 7);
m_record_button = new QPushButton("Record Frequencies", this);
Expand Down Expand Up @@ -186,7 +187,7 @@ AudioSelectorWidget::AudioSelectorWidget(

// only in developer mode:
// record audio
if (GlobalSettings::instance().SHOW_RECORD_FREQUENCIES){
if (GlobalSettings::instance().AUDIO_PIPELINE->SHOW_RECORD_FREQUENCIES){
connect(m_record_button, &QPushButton::clicked, this, [this](bool){
m_record_is_on = !m_record_is_on;
m_session.spectrums().saveAudioFrequenciesToDisk(m_record_is_on);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void send_reports(Logger& logger, const std::vector<std::string>& reports){
}
void send_all_unsent_reports(Logger& logger, bool allow_prompt){
#ifdef PA_OFFICIAL
ErrorReportSendMode mode = GlobalSettings::instance().ERROR_REPORTS.SEND_MODE;
ErrorReportSendMode mode = GlobalSettings::instance().ERROR_REPORTS->SEND_MODE;
if (mode == ErrorReportSendMode::NEVER_SEND_ANYTHING){
return;
}
Expand Down
Loading

0 comments on commit d2eeda9

Please sign in to comment.