Skip to content

Commit e77a266

Browse files
committed
Reduce dependency on ConsoleHandle in infra.
1 parent 7bbd96d commit e77a266

26 files changed

+99
-75
lines changed

SerialPrograms/Source/CommonFramework/Exceptions/OperationFailedException.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef PokemonAutomation_OperationFailedException_H
88
#define PokemonAutomation_OperationFailedException_H
99

10-
#include "CommonFramework/Tools/ConsoleHandle.h"
10+
#include "CommonFramework/VideoPipeline/VideoStream.h"
1111
#include "ScreenshotException.h"
1212

1313
namespace PokemonAutomation{

SerialPrograms/Source/CommonFramework/Exceptions/ProgramFinishedException.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#include "CommonFramework/ImageTypes/ImageRGB32.h"
88
#include "CommonFramework/Notifications/ProgramNotifications.h"
9-
#include "CommonFramework/Tools/ProgramEnvironment.h"
10-
#include "CommonFramework/Tools/ConsoleHandle.h"
119
#include "ProgramFinishedException.h"
1210

1311
namespace PokemonAutomation{

SerialPrograms/Source/CommonFramework/Exceptions/ProgramFinishedException.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class ImageRGB32;
1717
class EventNotificationOption;
1818
struct ProgramInfo;
1919
class ProgramEnvironment;
20-
class ConsoleHandle;
2120

2221

2322

SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "CommonFramework/ErrorReports/ErrorReports.h"
99
#include "CommonFramework/Notifications/ProgramNotifications.h"
1010
#include "CommonFramework/VideoPipeline/VideoFeed.h"
11-
#include "CommonFramework/Tools/ConsoleHandle.h"
11+
#include "CommonFramework/VideoPipeline/VideoStream.h"
1212
#include "CommonFramework/Tools/ProgramEnvironment.h"
1313
#include "ScreenshotException.h"
1414

SerialPrograms/Source/CommonFramework/Exceptions/ScreenshotException.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace PokemonAutomation{
1515
class ImageViewRGB32;
1616
class ImageRGB32;
1717
class EventNotificationOption;
18-
struct VideoStream;
18+
class VideoStream;
1919
struct ProgramInfo;
2020
class ProgramEnvironment;
2121

SerialPrograms/Source/CommonFramework/Inference/AudioPerSpectrumDetectorBase.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "Common/Cpp/Exceptions.h"
1111
#include "CommonFramework/AudioPipeline/AudioFeed.h"
1212
#include "CommonFramework/Inference/SpectrogramMatcher.h"
13-
#include "CommonFramework/Tools/ConsoleHandle.h"
1413
#include "AudioPerSpectrumDetectorBase.h"
1514

1615
#include <iostream>
@@ -21,13 +20,16 @@ namespace PokemonAutomation{
2120

2221

2322
AudioPerSpectrumDetectorBase::AudioPerSpectrumDetectorBase(
24-
std::string label, std::string audio_name, Color detection_color,
25-
ConsoleHandle& console, DetectedCallback detected_callback
23+
Logger& logger,
24+
std::string label,
25+
std::string audio_name,
26+
Color detection_color,
27+
DetectedCallback detected_callback
2628
)
2729
: AudioInferenceCallback(std::move(label))
2830
, m_audio_name(std::move(audio_name))
2931
, m_detection_color(detection_color)
30-
, m_console(console)
32+
, m_logger(logger)
3133
, m_detected_callback(std::move(detected_callback))
3234
, m_start_timestamp(current_time())
3335
, m_spectrums_processed(0)
@@ -47,14 +49,14 @@ void AudioPerSpectrumDetectorBase::throw_if_no_sound(std::chrono::milliseconds m
4749
if (m_spectrums_processed > 0){
4850
return;
4951
}
50-
throw UserSetupError(m_console, "No sound detected.");
52+
throw UserSetupError(m_logger, "No sound detected.");
5153
}
5254

5355
void AudioPerSpectrumDetectorBase::log_results(){
5456
if (m_last_timestamp != WallClock::min()){
55-
m_console.log(m_audio_name + " detected! Error Coefficient = " + tostr_default(m_lowest_error), COLOR_BLUE);
57+
m_logger.log(m_audio_name + " detected! Error Coefficient = " + tostr_default(m_lowest_error), COLOR_BLUE);
5658
}else{
57-
m_console.log(m_audio_name + " not detected. Error Coefficient = " + tostr_default(m_lowest_error), COLOR_PURPLE);
59+
m_logger.log(m_audio_name + " not detected. Error Coefficient = " + tostr_default(m_lowest_error), COLOR_PURPLE);
5860
}
5961

6062
#if 0
@@ -66,7 +68,7 @@ void AudioPerSpectrumDetectorBase::log_results(){
6668
for (const auto& error : m_errors){
6769
ss << "[" << error.first << ":" << error.second << "]";
6870
}
69-
// m_console.log(ss.str(), COLOR_RED);
71+
// m_logger.log(ss.str(), COLOR_RED);
7072
cout << ss.str() << endl;
7173
}
7274
#endif
@@ -95,7 +97,7 @@ bool AudioPerSpectrumDetectorBase::process_spectrums(
9597
const size_t sample_rate = new_spectrums[0].sample_rate;
9698
// Lazy intialization of the spectrogram matcher.
9799
if (m_matcher == nullptr || m_matcher->sample_rate() != sample_rate){
98-
m_console.log("Loading spectrogram...");
100+
m_logger.log("Loading spectrogram...");
99101
m_matcher = build_spectrogram_matcher(sample_rate);
100102
}
101103

@@ -156,7 +158,7 @@ bool AudioPerSpectrumDetectorBase::process_spectrums(
156158

157159
std::ostringstream os;
158160
os << m_audio_name << " found, score " << matcher_score << "/" << threshold << ", scale: " << m_matcher->lastMatchedScale();
159-
m_console.log(os.str(), COLOR_BLUE);
161+
m_logger.log(os.str(), COLOR_BLUE);
160162
audio_feed.add_overlay(curStamp+1-m_matcher->numMatchedWindows(), curStamp+1, m_detection_color);
161163

162164
// Since the target audio is found, no need to check detection on the rest of the spectrums in `new_spectrums`.

SerialPrograms/Source/CommonFramework/Inference/AudioPerSpectrumDetectorBase.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
namespace PokemonAutomation{
3838

39-
class ConsoleHandle;
39+
class Logger;
4040
class SpectrogramMatcher;
4141

4242
// A virtual base class for audio detectors to match an audio template starting at each incoming
@@ -56,8 +56,11 @@ class AudioPerSpectrumDetectorBase : public AudioInferenceCallback{
5656
// function. If it returns true, the inference session will stop (by returning true from
5757
// AudioPerSpectrumDetectorBase::process_spectrums()).
5858
AudioPerSpectrumDetectorBase(
59-
std::string label, std::string audio_name, Color detection_color,
60-
ConsoleHandle& console, DetectedCallback detected_callback
59+
Logger& logger,
60+
std::string label,
61+
std::string audio_name,
62+
Color detection_color,
63+
DetectedCallback detected_callback
6164
);
6265

6366
virtual ~AudioPerSpectrumDetectorBase();
@@ -93,7 +96,7 @@ class AudioPerSpectrumDetectorBase : public AudioInferenceCallback{
9396
// Color of the box to visualize the detection in the audio spectrogram UI.
9497
Color m_detection_color;
9598

96-
ConsoleHandle& m_console;
99+
Logger& m_logger;
97100
// Callback function to determine whether to stop the inference session when the target audio
98101
// is detected.
99102
DetectedCallback m_detected_callback;

SerialPrograms/Source/CommonFramework/Tools/BlackBorderCheck.cpp

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

77
#include "Common/Cpp/Exceptions.h"
8-
#include "CommonFramework/ImageTypes/ImageRGB32.h"
8+
//#include "CommonFramework/ImageTypes/ImageRGB32.h"
99
#include "CommonFramework/VideoPipeline/VideoFeed.h"
1010
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
1111
#include "CommonFramework/Tools/ConsoleHandle.h"
@@ -15,26 +15,26 @@
1515
namespace PokemonAutomation{
1616

1717

18-
void start_program_video_check(ConsoleHandle& console, FeedbackType feedback){
18+
void start_program_video_check(VideoStream& stream, FeedbackType feedback){
1919
if (feedback == FeedbackType::NONE){
2020
return;
2121
}
2222

23-
VideoSnapshot screen = console.video().snapshot();
23+
VideoSnapshot screen = stream.video.snapshot();
2424

2525
if (!screen){
2626
if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO){
27-
throw UserSetupError(console, "This program requires video feedback. Please make sure the video is working.");
27+
throw UserSetupError(stream.logger, "This program requires video feedback. Please make sure the video is working.");
2828
}
2929
return;
3030
}
3131

3232
BlackBorderDetector detector;
33-
VideoOverlaySet set(console);
33+
VideoOverlaySet set(stream.overlay);
3434
detector.make_overlays(set);
3535

3636
if (detector.detect(screen)){
37-
throw UserSetupError(console, "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
37+
throw UserSetupError(stream.logger, "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
3838
}
3939
}
4040
void start_program_video_check(FixedLimitVector<ConsoleHandle>& consoles, FeedbackType feedback){

SerialPrograms/Source/CommonFramework/Tools/BlackBorderCheck.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212

1313
namespace PokemonAutomation{
1414

15+
class VideoStream;
1516
class ConsoleHandle;
1617

1718

18-
void start_program_video_check(ConsoleHandle& console, FeedbackType feedback);
19+
void start_program_video_check(VideoStream& stream, FeedbackType feedback);
1920
void start_program_video_check(FixedLimitVector<ConsoleHandle>& consoles, FeedbackType feedback);
2021

2122

SerialPrograms/Source/CommonFramework/Tools/ConsoleHandle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ConsoleHandle::ConsoleHandle(
3636
AudioFeed& audio,
3737
const StreamHistorySession& history
3838
)
39-
: VideoStream(logger, audio, video, history)
39+
: VideoStream({logger, audio, video, history, overlay})
4040
, m_index(index)
4141
// , m_logger(logger)
4242
, m_botbase(botbase)

0 commit comments

Comments
 (0)