diff --git a/src/macro-external/video/area-selection.cpp b/src/macro-external/video/area-selection.cpp index f1fd737d..e42a2b63 100644 --- a/src/macro-external/video/area-selection.cpp +++ b/src/macro-external/video/area-selection.cpp @@ -7,8 +7,9 @@ void advss::Size::Save(obs_data_t *obj, const char *name) const { auto data = obs_data_create(); - obs_data_set_int(data, "width", width); - obs_data_set_int(data, "height", height); + width.Save(data, "width"); + height.Save(data, "height"); + obs_data_set_int(data, "version", 1); obs_data_set_obj(obj, name, data); obs_data_release(data); } @@ -16,8 +17,13 @@ void advss::Size::Save(obs_data_t *obj, const char *name) const void advss::Size::Load(obs_data_t *obj, const char *name) { auto data = obs_data_get_obj(obj, name); - width = obs_data_get_int(data, "width"); - height = obs_data_get_int(data, "height"); + if (!obs_data_has_user_value(data, "version")) { + width = obs_data_get_int(data, "width"); + height = obs_data_get_int(data, "height"); + } else { + width.Load(data, "width"); + height.Load(data, "height"); + } obs_data_release(data); } @@ -29,10 +35,11 @@ cv::Size advss::Size::CV() void advss::Area::Save(obs_data_t *obj, const char *name) const { auto data = obs_data_create(); - obs_data_set_int(data, "x", x); - obs_data_set_int(data, "y", y); - obs_data_set_int(data, "width", width); - obs_data_set_int(data, "height", height); + x.Save(data, "x"); + y.Save(data, "y"); + width.Save(data, "width"); + height.Save(data, "height"); + obs_data_set_int(data, "version", 1); obs_data_set_obj(obj, name, data); obs_data_release(data); } @@ -40,23 +47,32 @@ void advss::Area::Save(obs_data_t *obj, const char *name) const void advss::Area::Load(obs_data_t *obj, const char *name) { auto data = obs_data_get_obj(obj, name); - x = obs_data_get_int(data, "x"); - y = obs_data_get_int(data, "y"); - width = obs_data_get_int(data, "width"); - height = obs_data_get_int(data, "height"); + if (!obs_data_has_user_value(data, "version")) { + x = obs_data_get_int(data, "x"); + y = obs_data_get_int(data, "y"); + width = obs_data_get_int(data, "width"); + height = obs_data_get_int(data, "height"); + } else { + x.Load(data, "x"); + y.Load(data, "y"); + width.Load(data, "width"); + height.Load(data, "height"); + } obs_data_release(data); } SizeSelection::SizeSelection(int min, int max, QWidget *parent) - : QWidget(parent), _x(new QSpinBox), _y(new QSpinBox) + : QWidget(parent), _x(new VariableSpinBox()), _y(new VariableSpinBox()) { _x->setMinimum(min); _y->setMinimum(min); _x->setMaximum(max); _y->setMaximum(max); - connect(_x, SIGNAL(valueChanged(int)), this, SLOT(XChanged(int))); - connect(_y, SIGNAL(valueChanged(int)), this, SLOT(YChanged(int))); + connect(_x, SIGNAL(NumberVariableChanged(const NumberVariable &)), + this, SLOT(XChanged(const NumberVariable &))); + connect(_y, SIGNAL(NumberVariableChanged(const NumberVariable &)), + this, SLOT(YChanged(const NumberVariable &))); auto layout = new QHBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); @@ -67,23 +83,23 @@ SizeSelection::SizeSelection(int min, int max, QWidget *parent) void SizeSelection::SetSize(const advss::Size &s) { - _x->setValue(s.width); - _y->setValue(s.height); + _x->SetValue(s.width); + _y->SetValue(s.height); } advss::Size SizeSelection::Size() { - return advss::Size{_x->value(), _y->value()}; + return advss::Size{_x->Value(), _y->Value()}; } -void SizeSelection::XChanged(int value) +void SizeSelection::XChanged(const NumberVariable &value) { - emit SizeChanged(advss::Size{value, _y->value()}); + emit SizeChanged(advss::Size{value, _y->Value()}); } -void SizeSelection::YChanged(int value) +void SizeSelection::YChanged(const NumberVariable &value) { - emit SizeChanged(advss::Size{_x->value(), value}); + emit SizeChanged(advss::Size{_x->Value(), value}); } AreaSelection::AreaSelection(int min, int max, QWidget *parent) diff --git a/src/macro-external/video/area-selection.hpp b/src/macro-external/video/area-selection.hpp index ea88d1ee..38f93445 100644 --- a/src/macro-external/video/area-selection.hpp +++ b/src/macro-external/video/area-selection.hpp @@ -1,4 +1,6 @@ #pragma once +#include + #include #include #include @@ -11,18 +13,18 @@ struct Size { void Load(obs_data_t *obj, const char *name); cv::Size CV(); - int width; - int height; + NumberVariable width; + NumberVariable height; }; struct Area { void Save(obs_data_t *obj, const char *name) const; void Load(obs_data_t *obj, const char *name); - int x; - int y; - int width; - int height; + NumberVariable x; + NumberVariable y; + NumberVariable width; + NumberVariable height; }; } @@ -36,14 +38,14 @@ public: advss::Size Size(); private slots: - void XChanged(int); - void YChanged(int); + void XChanged(const NumberVariable &); + void YChanged(const NumberVariable &); signals: void SizeChanged(advss::Size value); private: - QSpinBox *_x; - QSpinBox *_y; + VariableSpinBox *_x; + VariableSpinBox *_y; friend class AreaSelection; }; diff --git a/src/macro-external/video/macro-condition-video.cpp b/src/macro-external/video/macro-condition-video.cpp index 42c26638..c0eb40ff 100644 --- a/src/macro-external/video/macro-condition-video.cpp +++ b/src/macro-external/video/macro-condition-video.cpp @@ -157,7 +157,7 @@ bool MacroConditionVideo::Save(obs_data_t *obj) const obs_data_set_string(obj, "filePath", _file.c_str()); obs_data_set_bool(obj, "blockUntilScreenshotDone", _blockUntilScreenshotDone); - obs_data_set_double(obj, "brightness", _brightnessThreshold); + _brightnessThreshold.Save(obj, "brightnessThreshold"); _patternMatchParameters.Save(obj); _objMatchParameters.Save(obj); _ocrParamters.Save(obj); @@ -176,7 +176,12 @@ bool MacroConditionVideo::Load(obs_data_t *obj) _file = obs_data_get_string(obj, "filePath"); _blockUntilScreenshotDone = obs_data_get_bool(obj, "blockUntilScreenshotDone"); - _brightnessThreshold = obs_data_get_double(obj, "brightness"); + // TODO: Remove this fallback in a future version + if (obs_data_has_user_value(obj, "brightness")) { + _brightnessThreshold = obs_data_get_double(obj, "brightness"); + } else { + _brightnessThreshold.Load(obj, "brightnessThreshold"); + } _patternMatchParameters.Load(obj); _objMatchParameters.Load(obj); _ocrParamters.Load(obj); @@ -477,18 +482,27 @@ MacroConditionVideoEdit::MacroConditionVideoEdit( SLOT(ImageBrowseButtonClicked())); QWidget::connect(_usePatternForChangedCheck, SIGNAL(stateChanged(int)), this, SLOT(UsePatternForChangedCheckChanged(int))); - QWidget::connect(_patternThreshold, SIGNAL(DoubleValueChanged(double)), - this, SLOT(PatternThresholdChanged(double))); + QWidget::connect( + _patternThreshold, + SIGNAL(DoubleValueChanged(const NumberVariable &)), + this, + SLOT(PatternThresholdChanged(const NumberVariable &))); QWidget::connect(_useAlphaAsMask, SIGNAL(stateChanged(int)), this, SLOT(UseAlphaAsMaskChanged(int))); QWidget::connect(_patternMatchMode, SIGNAL(currentIndexChanged(int)), this, SLOT(PatternMatchModeChanged(int))); - QWidget::connect(_brightnessThreshold, - SIGNAL(DoubleValueChanged(double)), this, - SLOT(BrightnessThresholdChanged(double))); - QWidget::connect(_objectScaleThreshold, - SIGNAL(DoubleValueChanged(double)), this, - SLOT(ObjectScaleThresholdChanged(double))); + QWidget::connect( + _brightnessThreshold, + SIGNAL(DoubleValueChanged(const NumberVariable &)), + this, + SLOT(BrightnessThresholdChanged( + const NumberVariable &))); + QWidget::connect( + _objectScaleThreshold, + SIGNAL(DoubleValueChanged(const NumberVariable &)), + this, + SLOT(ObjectScaleThresholdChanged( + const NumberVariable &))); QWidget::connect(_minNeighbors, SIGNAL(valueChanged(int)), this, SLOT(MinNeighborsChanged(int))); QWidget::connect(_minSize, SIGNAL(SizeChanged(advss::Size)), this, @@ -854,7 +868,8 @@ void MacroConditionVideoEdit::UsePatternForChangedCheckChanged(int value) SetWidgetVisibility(); } -void MacroConditionVideoEdit::PatternThresholdChanged(double value) +void MacroConditionVideoEdit::PatternThresholdChanged( + const NumberVariable &value) { if (_loading || !_entryData) { return; @@ -903,7 +918,8 @@ void MacroConditionVideoEdit::PatternMatchModeChanged(int idx) _entryData->_patternMatchParameters); } -void MacroConditionVideoEdit::BrightnessThresholdChanged(double value) +void MacroConditionVideoEdit::BrightnessThresholdChanged( + const NumberVariable &value) { if (_loading || !_entryData) { return; @@ -913,7 +929,8 @@ void MacroConditionVideoEdit::BrightnessThresholdChanged(double value) _entryData->_brightnessThreshold = value; } -void MacroConditionVideoEdit::ObjectScaleThresholdChanged(double value) +void MacroConditionVideoEdit::ObjectScaleThresholdChanged( + const NumberVariable &value) { if (_loading || !_entryData) { return; diff --git a/src/macro-external/video/macro-condition-video.hpp b/src/macro-external/video/macro-condition-video.hpp index cec7c30e..83a01c07 100644 --- a/src/macro-external/video/macro-condition-video.hpp +++ b/src/macro-external/video/macro-condition-video.hpp @@ -51,7 +51,7 @@ public: // checked in the next one. // If set both operations will happen in the same interval. bool _blockUntilScreenshotDone = false; - double _brightnessThreshold = 0.5; + NumberVariable _brightnessThreshold = 0.5; PatternMatchParameters _patternMatchParameters; ObjDetectParameters _objMatchParameters; OCRParameters _ocrParamters; @@ -111,14 +111,14 @@ private slots: void ImageBrowseButtonClicked(); void UsePatternForChangedCheckChanged(int value); - void PatternThresholdChanged(double); + void PatternThresholdChanged(const NumberVariable &); void UseAlphaAsMaskChanged(int value); void PatternMatchModeChanged(int value); - void BrightnessThresholdChanged(double); + void BrightnessThresholdChanged(const NumberVariable &); void ModelPathChanged(const QString &text); - void ObjectScaleThresholdChanged(double); + void ObjectScaleThresholdChanged(const NumberVariable &); void MinNeighborsChanged(int value); void MinSizeChanged(advss::Size value); void MaxSizeChanged(advss::Size value); diff --git a/src/macro-external/video/paramerter-wrappers.cpp b/src/macro-external/video/paramerter-wrappers.cpp index 940c23c2..87bb8713 100644 --- a/src/macro-external/video/paramerter-wrappers.cpp +++ b/src/macro-external/video/paramerter-wrappers.cpp @@ -4,9 +4,10 @@ bool PatternMatchParameters::Save(obs_data_t *obj) const { auto data = obs_data_create(); obs_data_set_bool(data, "useForChangedCheck", useForChangedCheck); - obs_data_set_double(data, "threshold", threshold); + threshold.Save(data, "threshold"); obs_data_set_bool(data, "useAlphaAsMask", useAlphaAsMask); obs_data_set_int(data, "matchMode", matchMode); + obs_data_set_int(data, "version", 1); obs_data_set_obj(obj, "patternMatchData", data); obs_data_release(data); return true; @@ -24,7 +25,11 @@ bool PatternMatchParameters::Load(obs_data_t *obj) } auto data = obs_data_get_obj(obj, "patternMatchData"); useForChangedCheck = obs_data_get_bool(data, "useForChangedCheck"); - threshold = obs_data_get_double(data, "threshold"); + threshold.Load(data, "threshold"); + // TODO: Remove this fallback in a future version + if (!obs_data_has_user_value(data, "version")) { + threshold = obs_data_get_double(data, "threshold"); + } useAlphaAsMask = obs_data_get_bool(data, "useAlphaAsMask"); // TODO: Remove this fallback in a future version if (!obs_data_has_user_value(obj, "matchMode")) { @@ -41,11 +46,12 @@ bool ObjDetectParameters::Save(obs_data_t *obj) const { auto data = obs_data_create(); obs_data_set_string(data, "modelPath", modelPath.c_str()); - obs_data_set_double(data, "scaleFactor", scaleFactor); + scaleFactor.Save(data, "scaleFactor"); obs_data_set_int(data, "minNeighbors", minNeighbors); minSize.Save(data, "minSize"); maxSize.Save(data, "maxSize"); obs_data_set_obj(obj, "objectMatchData", data); + obs_data_set_int(data, "version", 1); obs_data_release(data); return true; } @@ -80,8 +86,12 @@ bool ObjDetectParameters::Load(obs_data_t *obj) } auto data = obs_data_get_obj(obj, "objectMatchData"); modelPath = obs_data_get_string(data, "modelPath"); - scaleFactor = obs_data_get_double(data, "scaleFactor"); - if (!isScaleFactorValid(scaleFactor)) { + scaleFactor.Load(data, "scaleFactor"); + // TODO: Remove this fallback in a future version + if (!obs_data_has_user_value(data, "version")) { + scaleFactor = obs_data_get_double(data, "scaleFactor"); + } + if (scaleFactor.IsFixedType() && !isScaleFactorValid(scaleFactor)) { scaleFactor = 1.1; } minNeighbors = obs_data_get_int(data, "minNeighbors"); diff --git a/src/macro-external/video/paramerter-wrappers.hpp b/src/macro-external/video/paramerter-wrappers.hpp index c19385ac..87c5680b 100644 --- a/src/macro-external/video/paramerter-wrappers.hpp +++ b/src/macro-external/video/paramerter-wrappers.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,7 @@ public: bool useForChangedCheck = false; bool useAlphaAsMask = false; cv::TemplateMatchModes matchMode = cv::TM_CCORR_NORMED; - double threshold = 0.8; + NumberVariable threshold = 0.8; }; class ObjDetectParameters { @@ -68,7 +69,7 @@ public: std::string( "/res/cascadeClassifiers/haarcascade_frontalface_alt.xml"); cv::CascadeClassifier cascade; - double scaleFactor = defaultScaleFactor; + NumberVariable scaleFactor = defaultScaleFactor; int minNeighbors = minMinNeighbors; advss::Size minSize{0, 0}; advss::Size maxSize{0, 0}; @@ -89,7 +90,7 @@ public: tesseract::PageSegMode GetPageMode() const { return pageSegMode; } tesseract::TessBaseAPI *GetOCR() const { return ocr.get(); } - VariableString text = obs_module_text("AdvSceneSwitcher.enterText"); + StringVariable text = obs_module_text("AdvSceneSwitcher.enterText"); RegexConfig regex = RegexConfig::PartialMatchRegexConfig(); QColor color = Qt::black;