Skip to content

Commit d2eeda9

Browse files
committed
Pimpl most of the settings in GlobalSettingsPanel to reduce header pollution.
1 parent 24dfe75 commit d2eeda9

File tree

60 files changed

+468
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+468
-267
lines changed

Common/Cpp/Containers/Pimpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class Pimpl{
4040
public:
4141
operator bool() const{ return m_ptr != nullptr; }
4242

43+
operator const Type&() const{ return *m_ptr; }
44+
operator Type&() { return *m_ptr; }
45+
4346
const Type& operator*() const { return *m_ptr; }
4447
Type& operator*() { return *m_ptr; }
4548

Common/Qt/Options/GroupWidget.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ GroupWidget::GroupWidget(QWidget& parent, GroupOption& value)
7777
}
7878

7979
if (value.restore_defaults_button_enabled()){
80-
m_options.back()->widget().setContentsMargins(5, 5, 5, 5);
8180
m_restore_defaults_button = new QPushButton("Restore Defaults", this);
82-
m_options_layout->addWidget(m_restore_defaults_button);
81+
m_restore_defaults_button->setContentsMargins(5, 5, 5, 5);
82+
QHBoxLayout* row = new QHBoxLayout();
83+
m_options_layout->addLayout(row);
84+
row->addWidget(m_restore_defaults_button, 1);
85+
row->addStretch(3);
8386
connect(
8487
m_restore_defaults_button, &QPushButton::clicked,
8588
this, [this](bool on){

SerialPrograms/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ file(GLOB MAIN_SOURCES
246246
Source/CommonFramework/AudioPipeline/AudioOption.cpp
247247
Source/CommonFramework/AudioPipeline/AudioOption.h
248248
Source/CommonFramework/AudioPipeline/AudioPassthroughPair.h
249+
Source/CommonFramework/AudioPipeline/AudioPipelineOptions.h
249250
Source/CommonFramework/AudioPipeline/AudioSession.cpp
250251
Source/CommonFramework/AudioPipeline/AudioSession.h
251252
Source/CommonFramework/AudioPipeline/AudioStream.cpp
@@ -460,6 +461,7 @@ file(GLOB MAIN_SOURCES
460461
Source/CommonFramework/OCR/OCR_TextMatcher.h
461462
Source/CommonFramework/OCR/OCR_TrainingTools.cpp
462463
Source/CommonFramework/OCR/OCR_TrainingTools.h
464+
Source/CommonFramework/Options/Environment/PerformanceOptions.h
463465
Source/CommonFramework/Options/Environment/ProcessPriorityOption.h
464466
Source/CommonFramework/Options/Environment/ProcessorLevelOption.cpp
465467
Source/CommonFramework/Options/Environment/ProcessorLevelOption.h
@@ -589,6 +591,7 @@ file(GLOB MAIN_SOURCES
589591
Source/CommonFramework/VideoPipeline/VideoOverlaySession.h
590592
Source/CommonFramework/VideoPipeline/VideoOverlayTypes.cpp
591593
Source/CommonFramework/VideoPipeline/VideoOverlayTypes.h
594+
Source/CommonFramework/VideoPipeline/VideoPipelineOptions.h
592595
Source/CommonFramework/Windows/ButtonDiagram.cpp
593596
Source/CommonFramework/Windows/ButtonDiagram.h
594597
Source/CommonFramework/Windows/DpiScaler.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ HEADERS += \
12211221
Source/CommonFramework/AudioPipeline/AudioInfo.h \
12221222
Source/CommonFramework/AudioPipeline/AudioOption.h \
12231223
Source/CommonFramework/AudioPipeline/AudioPassthroughPair.h \
1224+
Source/CommonFramework/AudioPipeline/AudioPipelineOptions.h \
12241225
Source/CommonFramework/AudioPipeline/AudioSession.h \
12251226
Source/CommonFramework/AudioPipeline/AudioStream.h \
12261227
Source/CommonFramework/AudioPipeline/AudioTemplate.h \
@@ -1341,6 +1342,7 @@ HEADERS += \
13411342
Source/CommonFramework/OCR/OCR_StringNormalization.h \
13421343
Source/CommonFramework/OCR/OCR_TextMatcher.h \
13431344
Source/CommonFramework/OCR/OCR_TrainingTools.h \
1345+
Source/CommonFramework/Options/Environment/PerformanceOptions.h \
13441346
Source/CommonFramework/Options/Environment/ProcessPriorityOption.h \
13451347
Source/CommonFramework/Options/Environment/ProcessorLevelOption.h \
13461348
Source/CommonFramework/Options/Environment/SleepSuppressOption.h \

SerialPrograms/Source/CommonFramework/AudioPipeline/AudioInfo.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
#include <map>
88
#include <QtGlobal>
99
#include "Common/Cpp/Exceptions.h"
10+
#include "Common/Cpp/Time.h"
1011
#include "Common/Cpp/PrettyPrint.h"
1112
#include "Common/Cpp/Containers/Pimpl.tpp"
1213
#include "CommonFramework/GlobalSettingsPanel.h"
14+
#include "CommonFramework/Logging/Logger.h"
15+
#include "CommonFramework/AudioPipeline/AudioPipelineOptions.h"
1316
#include "AudioInfo.h"
1417

15-
#include <iostream>
16-
using std::cout;
17-
using std::endl;
18+
//#include <iostream>
19+
//using std::cout;
20+
//using std::endl;
1821

1922

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

315-
if (GlobalSettings::instance().SHOW_ALL_AUDIO_DEVICES){
318+
bool show_all_devices = GlobalSettings::instance().AUDIO_PIPELINE->SHOW_ALL_DEVICES;
319+
if (show_all_devices){
316320
return list;
317321
}
318322

@@ -335,7 +339,7 @@ std::vector<AudioDeviceInfo> AudioDeviceInfo::all_input_devices(){
335339
if (device.preferred_format_index() >= 0){
336340
current_score += 100;
337341
}
338-
if (current_score >= best_score || GlobalSettings::instance().SHOW_ALL_AUDIO_DEVICES){
342+
if (current_score >= best_score || show_all_devices){
339343
ret.emplace_back(std::move(device));
340344
}
341345
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Audio Pipeline Options
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_AudioPipeline_AudioPipelineOptions_H
8+
#define PokemonAutomation_AudioPipeline_AudioPipelineOptions_H
9+
10+
#include "Common/Cpp/Options/GroupOption.h"
11+
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
12+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
13+
#include "Common/Cpp/Options/FloatingPointOption.h"
14+
#include "CommonFramework/GlobalSettingsPanel.h"
15+
16+
namespace PokemonAutomation{
17+
18+
19+
class AudioPipelineOptions : public GroupOption{
20+
public:
21+
AudioPipelineOptions()
22+
: GroupOption(
23+
"Audio Pipeline",
24+
LockMode::LOCK_WHILE_RUNNING,
25+
GroupOption::EnableMode::ALWAYS_ENABLED, true
26+
)
27+
, FILE_VOLUME_SCALE(
28+
"<b>Audio File Input Volume Scale:</b><br>"
29+
"Multiply audio file playback by this factor. (This is linear scale. So each factor of 10 is 20dB.)",
30+
LockMode::UNLOCK_WHILE_RUNNING,
31+
0.31622776601683793320, // -10dB
32+
-10000, 10000
33+
)
34+
, DEVICE_VOLUME_SCALE(
35+
"<b>Audio Device Input Volume Scale:</b><br>"
36+
"Multiply audio device input by this factor. (This is linear scale. So each factor of 10 is 20dB.)",
37+
LockMode::UNLOCK_WHILE_RUNNING,
38+
1.0, -10000, 10000
39+
)
40+
, SHOW_ALL_DEVICES(
41+
"<b>Show all Audio Devices:</b><br>"
42+
"Show all audio devices - including duplicates.",
43+
LockMode::UNLOCK_WHILE_RUNNING,
44+
false
45+
)
46+
, SHOW_RECORD_FREQUENCIES(
47+
"<b>Show Record Frequencies:</b><br>"
48+
"Show option to record audio frequencies.",
49+
LockMode::UNLOCK_WHILE_RUNNING,
50+
false
51+
)
52+
, AUTO_RESET_SECONDS(
53+
"<b>Audio Auto-Reset:</b><br>"
54+
"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).",
55+
LockMode::UNLOCK_WHILE_RUNNING,
56+
5
57+
)
58+
{
59+
PA_ADD_OPTION(FILE_VOLUME_SCALE);
60+
PA_ADD_OPTION(DEVICE_VOLUME_SCALE);
61+
PA_ADD_OPTION(SHOW_ALL_DEVICES);
62+
if (PreloadSettings::instance().DEVELOPER_MODE){
63+
PA_ADD_OPTION(SHOW_RECORD_FREQUENCIES);
64+
}
65+
PA_ADD_OPTION(AUTO_RESET_SECONDS);
66+
}
67+
68+
public:
69+
FloatingPointOption FILE_VOLUME_SCALE;
70+
FloatingPointOption DEVICE_VOLUME_SCALE;
71+
BooleanCheckBoxOption SHOW_ALL_DEVICES;
72+
BooleanCheckBoxOption SHOW_RECORD_FREQUENCIES;
73+
SimpleIntegerOption<uint8_t> AUTO_RESET_SECONDS;
74+
};
75+
76+
77+
78+
}
79+
#endif

SerialPrograms/Source/CommonFramework/AudioPipeline/AudioSession.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "CommonFramework/GlobalServices.h"
99
#include "CommonFramework/GlobalSettingsPanel.h"
1010
#include "Backends/AudioPassthroughPairQtThread.h"
11+
#include "AudioPipelineOptions.h"
1112
#include "AudioSession.h"
1213

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

55-
uint8_t watchdog_timeout = GlobalSettings::instance().AUTO_RESET_AUDIO_SECONDS;
56+
uint8_t watchdog_timeout = GlobalSettings::instance().AUDIO_PIPELINE->AUTO_RESET_SECONDS;
5657
if (watchdog_timeout != 0){
5758
global_watchdog().add(*this, std::chrono::seconds(watchdog_timeout));
5859
}
@@ -292,7 +293,7 @@ void AudioSession::on_watchdog_timeout(){
292293
return;
293294
}
294295

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

298299
if (watchdog_timeout == 0){

SerialPrograms/Source/CommonFramework/AudioPipeline/Backends/AudioPassthroughPairQt.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
*/
66

77
//#include "Common/Cpp/Exceptions.h"
8+
#include "Common/Cpp/AbstractLogger.h"
89
#include "CommonFramework/GlobalSettingsPanel.h"
10+
#include "CommonFramework/AudioPipeline/AudioPipelineOptions.h"
911
//#include "CommonFramework/AudioPipeline/AudioConstants.h"
1012
//#include "CommonFramework/AudioPipeline/Tools/AudioFormatUtils.h"
1113
#include "CommonFramework/AudioPipeline/IO/AudioSource.h"
1214
#include "CommonFramework/AudioPipeline/IO/AudioSink.h"
1315
#include "CommonFramework/AudioPipeline/Spectrum/FFTStreamer.h"
1416
#include "AudioPassthroughPairQt.h"
1517

16-
#include <iostream>
17-
using std::cout;
18-
using std::endl;
18+
//#include <iostream>
19+
//using std::cout;
20+
//using std::endl;
1921

2022
namespace PokemonAutomation{
2123

@@ -99,8 +101,8 @@ AudioPassthroughPairQt::~AudioPassthroughPairQt(){}
99101

100102
AudioPassthroughPairQt::AudioPassthroughPairQt(Logger& logger)
101103
: m_logger(logger)
102-
, m_file_input_multiplier((float)GlobalSettings::instance().AUDIO_FILE_VOLUME_SCALE)
103-
, m_device_input_multiplier((float)GlobalSettings::instance().AUDIO_DEVICE_VOLUME_SCALE)
104+
, m_file_input_multiplier((float)GlobalSettings::instance().AUDIO_PIPELINE->FILE_VOLUME_SCALE)
105+
, m_device_input_multiplier((float)GlobalSettings::instance().AUDIO_PIPELINE->DEVICE_VOLUME_SCALE)
104106
{}
105107

106108
void AudioPassthroughPairQt::reset(

SerialPrograms/Source/CommonFramework/AudioPipeline/Backends/AudioPassthroughPairQtThread.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "Common/Cpp/Concurrency/SpinPause.h"
88
#include "CommonFramework/GlobalSettingsPanel.h"
9+
#include "CommonFramework/Options/Environment/PerformanceOptions.h"
910
#include "AudioPassthroughPairQt.h"
1011
#include "AudioPassthroughPairQtThread.h"
1112

@@ -51,7 +52,7 @@ AudioPassthroughPairQtThread::~AudioPassthroughPairQtThread(){
5152
wait();
5253
}
5354
void AudioPassthroughPairQtThread::run(){
54-
GlobalSettings::instance().REALTIME_THREAD_PRIORITY0.set_on_this_thread();
55+
GlobalSettings::instance().PERFORMANCE->REALTIME_THREAD_PRIORITY.set_on_this_thread();
5556

5657
AudioPassthroughPairQt body(m_logger);
5758
m_body.store(&body, std::memory_order_relaxed);

SerialPrograms/Source/CommonFramework/AudioPipeline/IO/AudioSource.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ using NativeAudioSource = QAudioSource;
1616
#include "Common/Cpp/Exceptions.h"
1717
#include "Common/Cpp/PrettyPrint.h"
1818
#include "Common/Cpp/Time.h"
19-
#include "Common/Cpp/StreamConverters.h"
19+
//#include "Common/Cpp/StreamConverters.h"
2020
#include "CommonFramework/AudioPipeline/AudioStream.h"
2121
#include "CommonFramework/AudioPipeline/Tools/AudioFormatUtils.h"
2222
#include "AudioFileLoader.h"
2323
#include "AudioSource.h"
2424

25-
#include <iostream>
26-
using std::cout;
27-
using std::endl;
25+
//#include <iostream>
26+
//using std::cout;
27+
//using std::endl;
2828

2929
namespace PokemonAutomation{
3030

0 commit comments

Comments
 (0)