@@ -177,8 +177,8 @@ bool MacroConditionVideo::Load(obs_data_t *obj)
177
177
{
178
178
MacroCondition::Load (obj);
179
179
_video.Load (obj);
180
- _condition =
181
- static_cast <VideoCondition>( obs_data_get_int (obj, " condition" ));
180
+ SetCondition ( static_cast <VideoCondition>(
181
+ obs_data_get_int (obj, " condition" ) ));
182
182
_file = obs_data_get_string (obj, " filePath" );
183
183
_blockUntilScreenshotDone =
184
184
obs_data_get_bool (obj, " blockUntilScreenshotDone" );
@@ -261,6 +261,12 @@ bool MacroConditionVideo::SetLanguage(const std::string &language)
261
261
return _ocrParameters.SetLanguageCode (language);
262
262
}
263
263
264
+ void MacroConditionVideo::SetCondition (VideoCondition condition)
265
+ {
266
+ _condition = condition;
267
+ SetupTempVars ();
268
+ }
269
+
264
270
bool MacroConditionVideo::ScreenshotContainsPattern ()
265
271
{
266
272
cv::Mat result;
@@ -269,9 +275,12 @@ bool MacroConditionVideo::ScreenshotContainsPattern()
269
275
_patternMatchParameters.useAlphaAsMask ,
270
276
_patternMatchParameters.matchMode );
271
277
if (result.total () == 0 ) {
278
+ SetTempVarValue (" patternCount" , " 0" );
272
279
return false ;
273
280
}
274
- return countNonZero (result) > 0 ;
281
+ const auto count = countNonZero (result);
282
+ SetTempVarValue (" patternCount" , std::to_string (count));
283
+ return count > 0 ;
275
284
}
276
285
277
286
bool MacroConditionVideo::OutputChanged ()
@@ -300,12 +309,15 @@ bool MacroConditionVideo::ScreenshotContainsObject()
300
309
_objMatchParameters.minNeighbors ,
301
310
_objMatchParameters.minSize .CV (),
302
311
_objMatchParameters.maxSize .CV ());
303
- return objects.size () > 0 ;
312
+ const auto count = objects.size ();
313
+ SetTempVarValue (" objectCount" , std::to_string (count));
314
+ return count > 0 ;
304
315
}
305
316
306
317
bool MacroConditionVideo::CheckBrightnessThreshold ()
307
318
{
308
319
_currentBrightness = GetAvgBrightness (_screenshotData.image ) / 255 .;
320
+ SetTempVarValue (" brightness" , std::to_string (_currentBrightness));
309
321
return _currentBrightness > _brightnessThreshold;
310
322
}
311
323
@@ -318,6 +330,7 @@ bool MacroConditionVideo::CheckOCR()
318
330
auto text = RunOCR (_ocrParameters.GetOCR (), _screenshotData.image ,
319
331
_ocrParameters.color , _ocrParameters.colorThreshold );
320
332
SetVariableValue (text);
333
+ SetTempVarValue (" text" , text);
321
334
if (!_ocrParameters.regex .Enabled ()) {
322
335
return text == std::string (_ocrParameters.text );
323
336
}
@@ -332,10 +345,18 @@ bool MacroConditionVideo::CheckOCR()
332
345
333
346
bool MacroConditionVideo::CheckColor ()
334
347
{
335
- return ContainsPixelsInColorRange (_screenshotData.image ,
336
- _colorParameters.color ,
337
- _colorParameters.colorThreshold ,
338
- _colorParameters.matchThreshold );
348
+ const bool ret = ContainsPixelsInColorRange (
349
+ _screenshotData.image , _colorParameters.color ,
350
+ _colorParameters.colorThreshold ,
351
+ _colorParameters.matchThreshold );
352
+ // Way too slow for now
353
+ // SetTempVarValue("dominantColor", GetDominantColor(_screenshotData.image, 3)
354
+ // .name(QColor::HexArgb)
355
+ // .toStdString());
356
+ SetTempVarValue (" color" , GetAverageColor (_screenshotData.image )
357
+ .name (QColor::HexArgb)
358
+ .toStdString ());
359
+ return ret;
339
360
}
340
361
341
362
bool MacroConditionVideo::Compare ()
@@ -378,6 +399,58 @@ bool MacroConditionVideo::Compare()
378
399
return false ;
379
400
}
380
401
402
+ void MacroConditionVideo::SetupTempVars ()
403
+ {
404
+ MacroCondition::SetupTempVars ();
405
+ switch (_condition) {
406
+ case VideoCondition::PATTERN:
407
+ AddTempvar (
408
+ " patternCount" ,
409
+ obs_module_text (
410
+ " AdvSceneSwitcher.tempVar.video.patternCount" ),
411
+ obs_module_text (
412
+ " AdvSceneSwitcher.tempVar.video.patternCount.description" ));
413
+ break ;
414
+ case VideoCondition::OBJECT:
415
+ AddTempvar (
416
+ " objectCount" ,
417
+ obs_module_text (
418
+ " AdvSceneSwitcher.tempVar.video.objectCount" ),
419
+ obs_module_text (
420
+ " AdvSceneSwitcher.tempVar.video.objectCount.description" ));
421
+ break ;
422
+ case VideoCondition::BRIGHTNESS:
423
+ AddTempvar (
424
+ " brightness" ,
425
+ obs_module_text (
426
+ " AdvSceneSwitcher.tempVar.video.brightness" ),
427
+ obs_module_text (
428
+ " AdvSceneSwitcher.tempVar.video.brightness.description" ));
429
+ break ;
430
+ case VideoCondition::OCR:
431
+ AddTempvar (
432
+ " text" ,
433
+ obs_module_text (" AdvSceneSwitcher.tempVar.video.text" ),
434
+ obs_module_text (
435
+ " AdvSceneSwitcher.tempVar.video.text.description" ));
436
+ break ;
437
+ case VideoCondition::COLOR:
438
+ AddTempvar (
439
+ " color" ,
440
+ obs_module_text (" AdvSceneSwitcher.tempVar.video.color" ),
441
+ obs_module_text (
442
+ " AdvSceneSwitcher.tempVar.video.color.description" ));
443
+ break ;
444
+ case VideoCondition::MATCH:
445
+ case VideoCondition::DIFFER:
446
+ case VideoCondition::HAS_NOT_CHANGED:
447
+ case VideoCondition::HAS_CHANGED:
448
+ case VideoCondition::NO_IMAGE:
449
+ default :
450
+ break ;
451
+ }
452
+ }
453
+
381
454
static inline void populateVideoInputSelection (QComboBox *list)
382
455
{
383
456
for (const auto &[_, name] : videoInputTypes) {
@@ -1155,7 +1228,7 @@ void MacroConditionVideoEdit::UpdatePreviewTooltip()
1155
1228
return ;
1156
1229
}
1157
1230
1158
- if (!requiresFileInput (_entryData->_condition )) {
1231
+ if (!requiresFileInput (_entryData->GetCondition () )) {
1159
1232
this ->setToolTip (" " );
1160
1233
return ;
1161
1234
}
@@ -1224,7 +1297,7 @@ void MacroConditionVideoEdit::ConditionChanged(int cond)
1224
1297
}
1225
1298
1226
1299
auto lock = LockContext ();
1227
- _entryData->_condition = static_cast <VideoCondition>(cond);
1300
+ _entryData->SetCondition ( static_cast <VideoCondition>(cond) );
1228
1301
_entryData->ResetLastMatch ();
1229
1302
SetWidgetVisibility ();
1230
1303
@@ -1239,7 +1312,7 @@ void MacroConditionVideoEdit::ConditionChanged(int cond)
1239
1312
_previewDialog.PatternMatchParametersChanged (
1240
1313
_entryData->_patternMatchParameters );
1241
1314
1242
- if (_entryData->_condition == VideoCondition::OBJECT) {
1315
+ if (_entryData->GetCondition () == VideoCondition::OBJECT) {
1243
1316
auto path = _entryData->GetModelDataPath ();
1244
1317
_entryData->_objMatchParameters .cascade =
1245
1318
initObjectCascade (path);
@@ -1482,27 +1555,28 @@ void MacroConditionVideoEdit::SetWidgetVisibility()
1482
1555
_sources->setVisible (_entryData->_video .type ==
1483
1556
VideoInput::Type::SOURCE);
1484
1557
_scenes->setVisible (_entryData->_video .type == VideoInput::Type::SCENE);
1485
- _imagePath->setVisible (requiresFileInput (_entryData->_condition ));
1558
+ _imagePath->setVisible (requiresFileInput (_entryData->GetCondition () ));
1486
1559
_usePatternForChangedCheck->setVisible (
1487
- patternControlIsOptional (_entryData->_condition ));
1488
- _patternThreshold->setVisible (needsThreshold (_entryData->_condition ));
1489
- _useAlphaAsMask->setVisible (_entryData->_condition ==
1560
+ patternControlIsOptional (_entryData->GetCondition ()));
1561
+ _patternThreshold->setVisible (
1562
+ needsThreshold (_entryData->GetCondition ()));
1563
+ _useAlphaAsMask->setVisible (_entryData->GetCondition () ==
1490
1564
VideoCondition::PATTERN);
1491
1565
SetLayoutVisible (_patternMatchModeLayout,
1492
- _entryData->_condition == VideoCondition::PATTERN);
1493
- _brightness->setVisible (_entryData->_condition ==
1566
+ _entryData->GetCondition () == VideoCondition::PATTERN);
1567
+ _brightness->setVisible (_entryData->GetCondition () ==
1494
1568
VideoCondition::BRIGHTNESS);
1495
- _showMatch->setVisible (needsShowMatch (_entryData->_condition ));
1496
- _ocr->setVisible (_entryData->_condition == VideoCondition::OCR);
1497
- _objectDetect->setVisible (_entryData->_condition ==
1569
+ _showMatch->setVisible (needsShowMatch (_entryData->GetCondition () ));
1570
+ _ocr->setVisible (_entryData->GetCondition () == VideoCondition::OCR);
1571
+ _objectDetect->setVisible (_entryData->GetCondition () ==
1498
1572
VideoCondition::OBJECT);
1499
- _color->setVisible (_entryData->_condition == VideoCondition::COLOR);
1573
+ _color->setVisible (_entryData->GetCondition () == VideoCondition::COLOR);
1500
1574
SetLayoutVisible (_throttleControlLayout,
1501
- needsThrottleControls (_entryData->_condition ));
1502
- _area->setVisible (needsAreaControls (_entryData->_condition ));
1575
+ needsThrottleControls (_entryData->GetCondition () ));
1576
+ _area->setVisible (needsAreaControls (_entryData->GetCondition () ));
1503
1577
1504
- if (_entryData->_condition == VideoCondition::HAS_CHANGED ||
1505
- _entryData->_condition == VideoCondition::HAS_NOT_CHANGED) {
1578
+ if (_entryData->GetCondition () == VideoCondition::HAS_CHANGED ||
1579
+ _entryData->GetCondition () == VideoCondition::HAS_NOT_CHANGED) {
1506
1580
_patternThreshold->setVisible (
1507
1581
_entryData->_patternMatchParameters .useForChangedCheck );
1508
1582
SetLayoutVisible (
@@ -1528,7 +1602,7 @@ void MacroConditionVideoEdit::SetupPreviewDialogParams()
1528
1602
_previewDialog.VideoSelectionChanged (_entryData->_video );
1529
1603
_previewDialog.AreaParametersChanged (_entryData->_areaParameters );
1530
1604
_previewDialog.ConditionChanged (
1531
- static_cast <int >(_entryData->_condition ));
1605
+ static_cast <int >(_entryData->GetCondition () ));
1532
1606
}
1533
1607
1534
1608
void MacroConditionVideoEdit::UpdateEntryData ()
@@ -1541,7 +1615,8 @@ void MacroConditionVideoEdit::UpdateEntryData()
1541
1615
static_cast <int >(_entryData->_video .type ));
1542
1616
_scenes->SetScene (_entryData->_video .scene );
1543
1617
_sources->SetSource (_entryData->_video .source );
1544
- _condition->setCurrentIndex (static_cast <int >(_entryData->_condition ));
1618
+ _condition->setCurrentIndex (
1619
+ static_cast <int >(_entryData->GetCondition ()));
1545
1620
_reduceLatency->setChecked (_entryData->_blockUntilScreenshotDone );
1546
1621
_imagePath->SetPath (QString::fromStdString (_entryData->_file ));
1547
1622
_usePatternForChangedCheck->setChecked (
0 commit comments